Skip to content

Commit

Permalink
update cloudflare token price indexer (#4235)
Browse files Browse the repository at this point in the history
  • Loading branch information
callensm authored Jun 26, 2023
1 parent 30e79c4 commit d36a9ac
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions backend/workers/price-indexer/src/scheduled.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {
BitcoinToken,
EclipseTokenList,
EthereumTokenList,
PolygonTokenList,
SolanaTokenList,
} from "@coral-xyz/common/src/tokens";

Expand All @@ -20,23 +22,26 @@ function chunk<T>(items: T[], size: number): T[][] {
export const scheduledHandler: ExportedHandlerScheduledHandler<
Environment
> = async (_event, env, _ctx) => {
const allTokensToRequest = chunk(
[
BitcoinToken,
...Object.values(SolanaTokenList),
...Object.values(EthereumTokenList),
],
50
);
const mergedTokenLists = [
BitcoinToken,
...Object.values(EclipseTokenList),
...Object.values(EthereumTokenList),
...Object.values(PolygonTokenList),
...Object.values(SolanaTokenList),
];

for (const tokens of allTokensToRequest) {
const ids = tokens
.filter((t) => t.coingeckoId !== undefined)
.map((t) => t.coingeckoId)
.join(",");
const uniqueTokenIds = mergedTokenLists.reduce<Set<string>>((acc, curr) => {
if (curr.coingeckoId && !acc.has(curr.coingeckoId)) {
acc.add(curr.coingeckoId);
}
return acc;
}, new Set());

const allTokensToRequest = chunk([...uniqueTokenIds.values()], 50);

for (const tokens of allTokensToRequest) {
const params = new URLSearchParams({
ids,
ids: tokens.join(","),
page: "1",
per_page: "100",
price_change_percentage: "24h",
Expand Down

1 comment on commit d36a9ac

@vercel
Copy link

@vercel vercel bot commented on d36a9ac Jun 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.