diff --git a/src/util/calculators/pancakeswapV3subgraph.ts b/src/util/calculators/pancakeswapV3subgraph.ts index 9690040f..53c93bf2 100644 --- a/src/util/calculators/pancakeswapV3subgraph.ts +++ b/src/util/calculators/pancakeswapV3subgraph.ts @@ -12,7 +12,7 @@ const TOKENS = gql` } } `; -const MAX_SKIP = 5000; +const MAX_SKIP = 3000; /** * Gets TVL of Pancakeswap V3 using subgraph @@ -28,24 +28,22 @@ async function getTvlFromSubgraph( ): Promise { const balances = {}; - let skip = 0; - - while (skip <= MAX_SKIP) { - const requestResult = await request(endpoint, TOKENS, { - block, - skip, - }); + const promises = []; + for (let i = 0; i <= MAX_SKIP; i += QUERY_SIZE) { + promises.push( + request(endpoint, TOKENS, { + block, + skip: i, + }), + ); + } - for (const token of requestResult.tokens) { + const results = await Promise.all(promises); + for (const result of results) { + for (const token of result.tokens) { balances[token.id.toLowerCase()] = BigNumber(token._totalSupply); } - - if (requestResult.tokens.length < QUERY_SIZE) { - break; - } - skip += QUERY_SIZE; } - formatter.convertBalancesToFixed(balances); return balances;