Class: Leaderboard
The swap backend's trading-competition reads: seasons (GET /leaderboard/seasons) and a
season's rankings (GET /leaderboard?seasonId=). Public reads: no signer, no wallet. A row that
is not usable is skipped and reported to onInvalidEntry; an answer that is not the expected
list is INVALID_CHAIN_RESPONSE.
season id on invalid entry chain response
Constructors
Constructor
new Leaderboard(
dexBackendBaseUrl,httpClient,options?):Leaderboard
Creates a leaderboard service. options.onInvalidEntry is told about every season or entry
row that was skipped as unusable.
Parameters
| Parameter | Type |
|---|---|
dexBackendBaseUrl | string |
httpClient | HttpClient |
options? | { onInvalidEntry?: InvalidEntryHandler; } |
options.onInvalidEntry? | InvalidEntryHandler |
Returns
Leaderboard
Example
const leaderboard = new Leaderboard('https://dex-backend-prod1.defi.gala.com', httpClient);
dex backend base url http client on invalid entry handler
Methods
getCurrentLeaderboard()
getCurrentLeaderboard(
options?):Promise<SeasonLeaderboard|null>
The rankings of the season running at options.now (see
Leaderboard.getCurrentSeason), or null between seasons.
Parameters
| Parameter | Type |
|---|---|
options? | CurrentSeasonOptions |
Returns
Promise<SeasonLeaderboard | null>
Example
const current = await gSwap.leaderboard.getCurrentLeaderboard();
if (current !== null) console.log(current.seasonId, current.entries.length);
get current leaderboard season options
getCurrentSeason()
getCurrentSeason(
options?):Promise<LeaderboardSeason|null>
The season running at options.now (default: now; start and end both count as inside),
or null between seasons. When seasons overlap, the first in the backend's order.
Parameters
| Parameter | Type |
|---|---|
options? | CurrentSeasonOptions |
Returns
Promise<LeaderboardSeason | null>
Example
const season = await gSwap.leaderboard.getCurrentSeason();
console.log(season === null ? 'no season running' : season.name);
get current season leaderboard options
getLeaderboard()
getLeaderboard(
seasonId,options?):Promise<SeasonLeaderboard>
A season's rankings (the backend's top 100 wallets). seasonId must be an integer of at
least 1 (INVALID_SEASON_ID before anything is sent); a season with no rankings, or none at
all, is an empty list.
Parameters
| Parameter | Type |
|---|---|
seasonId | number |
options? | LeaderboardReadOptions |
Returns
Promise<SeasonLeaderboard>
Example
const { entries } = await gSwap.leaderboard.getLeaderboard(1);
console.log(entries[0]?.wallet, entries[0]?.totalXp);
get leaderboard season id invalid read options
getSeasons()
getSeasons(
options?):Promise<LeaderboardSeason[]>
Every active season, in the backend's order (newest first).
Parameters
| Parameter | Type |
|---|---|
options? | LeaderboardReadOptions |
Returns
Promise<LeaderboardSeason[]>
Example
const seasons = await gSwap.leaderboard.getSeasons();
console.log(seasons.map((season) => season.name));
get seasons leaderboard season read options