From 4a88bc66f9c25162e701e22478e81e6986e97ee2 Mon Sep 17 00:00:00 2001 From: osman sonmezturk Date: Wed, 31 Jan 2024 16:56:49 +0300 Subject: [PATCH] pancakeswap update --- src/util/calculators/pancakeswapV3subgraph.ts | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) 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;