Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/controllers/TokenStatsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,13 @@ export class TokenStatsController extends ControllerBase implements IControllerB
*/
try {
res.json(
await this._statsService.getTokenStatsExtended(req.params.network as NetworkType, ['usd', 'krw']),
await this._statsService.getTokenStatsExtended(req.params.network as NetworkType, [
'usd',
'krw',
'sgd',
'idr',
'thb',
]),
);
} catch (err) {
this.handleError(res, err as Error);
Expand Down
17 changes: 11 additions & 6 deletions src/services/StatsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export interface IStatsService {
getTotalIssuanceHistory(network: NetworkType): Promise<TotalSupply[]>;
}

const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));

@injectable()
/**
* Token statistics calculation service.
Expand All @@ -49,7 +51,7 @@ export class StatsService extends DappStakingV3IndexerBase implements IStatsServ
}

/**
* Calculates token circulation supply by substracting sum of all token holder accounts
* Calculates token circulation supply by subtracting sum of all token holder accounts
* not in circulation from total token supply.
* @param network NetworkType (astar or shiden) to calculate token supply for.
* @returns Token statistics including total supply and circulating supply.
Expand Down Expand Up @@ -79,7 +81,7 @@ export class StatsService extends DappStakingV3IndexerBase implements IStatsServ
}

/**
* Calculates token circulation supply by substracting sum of all token holder accounts
* Calculates token circulation supply by subtracting sum of all token holder accounts
* not in circulation from total token supply.
* @param network NetworkType (astar or shiden) to calculate token supply for.
* @param currencies
Expand All @@ -96,16 +98,19 @@ export class StatsService extends DappStakingV3IndexerBase implements IStatsServ

const chainTokens = apiClient.registry.chainTokens;
const tokenSymbol = chainTokens[0];
const priceRequests = currencies.map((currency) => {
return this._priceProvider.getPrice(tokenSymbol.toLowerCase(), currency);
});

const [chainDecimals, totalSupply, balancesToExclude] = await Promise.all([
api.getChainDecimals(),
api.getTotalSupply(),
api.getBalances(addressesToExclude),
]);
const prices = await Promise.all(priceRequests);

const prices: number[] = [];
for (const currency of currencies) {
const price = await this._priceProvider.getPrice(tokenSymbol.toLowerCase(), currency);
prices.push(price);
await delay(1000); // To avoid hitting the API rate limit
}

const totalBalancesToExclude = this.getTotalBalanceToExclude(balancesToExclude);
const circulatingSupplyWei = totalSupply.sub(totalBalancesToExclude);
Expand Down