Skip to content

Commit

Permalink
Merge pull request #248 from dappradar/pankaceswap_fixing
Browse files Browse the repository at this point in the history
pancakeswap update
  • Loading branch information
Sonmezturk committed Jan 31, 2024
2 parents f276f66 + 4a88bc6 commit f8cac0b
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions src/util/calculators/pancakeswapV3subgraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const TOKENS = gql`
}
}
`;
const MAX_SKIP = 5000;
const MAX_SKIP = 3000;

/**
* Gets TVL of Pancakeswap V3 using subgraph
Expand All @@ -28,24 +28,22 @@ async function getTvlFromSubgraph(
): Promise<IBalances> {
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;
Expand Down

0 comments on commit f8cac0b

Please sign in to comment.