Skip to content

Commit

Permalink
Merge pull request #61 from invariant-labs/update-jup-api
Browse files Browse the repository at this point in the history
update jup api and snap script for svm
  • Loading branch information
wojciech-cichocki authored Oct 31, 2024
2 parents af8d0c5 + 9432acb commit 56a24f4
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions svm/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const getJupPricesData = async (
const requests = chunkedIds.map(
async (idsChunk) =>
await axios.get<JupApiPriceData>(
`https://price.jup.ag/v4/price?ids=${idsChunk.join(",")}`
`https://api.jup.ag/price/v2?ids=${idsChunk.join(",")}`
)
);

Expand Down Expand Up @@ -476,10 +476,7 @@ interface RawJupApiResponse {
string,
{
id: string;
mintSymbol: string;
vsToken: string;
vsTokenSymbol: string;
price: number;
price: string;
}
>;
timeTaken: number;
Expand All @@ -498,22 +495,24 @@ export const getJupPricesData2 = async (
const requests = chunkedIds.map(
async (idsChunk) =>
await axios.get<RawJupApiResponse>(
`https://price.jup.ag/v4/price?ids=${idsChunk.join(",")}`
`https://api.jup.ag/price/v2?ids=${idsChunk.join(",")}`
)
);

const responses = await Promise.all(requests);
const concatRes = responses.flatMap((response) =>
Object.values(response.data.data).map(({ id, price }) => ({ id, price }))
Object.values(response.data.data).map((tokenData) => ({
id: tokenData?.id ? tokenData.id : "",
price: tokenData?.price ? tokenData.price : "0",
}))
);

return concatRes.reduce<Record<string, TokenPriceData>>(
(acc, { id, price }) => {
acc[id] = { price: price ?? 0 };
return acc;
},
{}
);
return concatRes.reduce<Record<string, TokenPriceData>>((acc, tokenData) => {
if (tokenData?.id) {
acc[tokenData.id] = { price: Number(tokenData.price ?? 0) };
}
return acc;
}, {});
};

export type CoinGeckoAPIData = CoinGeckoAPIPriceData[];
Expand Down

0 comments on commit 56a24f4

Please sign in to comment.