Skip to content

Commit

Permalink
Merge pull request #2245 from ngfam/master
Browse files Browse the repository at this point in the history
[PENDLE] Fix getWhitelistedAssets caching
  • Loading branch information
dtmkeng authored Dec 21, 2024
2 parents dd79405 + f771ec0 commit 8d6b8f8
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions fees/pendle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,23 @@ async function getWhitelistedAssets(api: ChainApi): Promise<{
sys: string[];
marketToSy: Map<string, string>;
}> {
const { results } = await getConfig(
"pendle/v2/revenue-" + api.chain,
`https://api-v2.pendle.finance/core/v1/${api.chainId!}/markets?order_by=name%3A1&skip=0&limit=100&select=all`
);
// Should only cache api by week
const weekId = Math.floor(Date.now() / 1000 / 60 / 60 / 24 / 7);

let results: any[] = [];
let skip = 0;
let hasMore = true;

while (hasMore) {
const { results: newResults } = await getConfig(
`pendle/v2/revenue-${api.chainId!}-${skip}-${weekId}`,
`https://api-v2.pendle.finance/core/v1/${api.chainId!}/markets?order_by=name%3A1&skip=${skip}&limit=100&select=all`
);
results = results.concat(newResults);
skip += 100;
hasMore = newResults.length === 100;
}

const markets = results.map((d: any) => d.lp.address);
const sySet: Set<string> = new Set(results.map((d: any) => d.sy.address));
const sys = Array.from(sySet);
Expand Down

0 comments on commit 8d6b8f8

Please sign in to comment.