From 9432acb4d12799aebaaf9d2e971ae24e7969164d Mon Sep 17 00:00:00 2001 From: zielvna Date: Wed, 16 Oct 2024 13:13:39 +0200 Subject: [PATCH] update jup api and snap script for svm --- svm/snap.sh | 2 ++ svm/src/utils.ts | 27 +++++++++++++-------------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/svm/snap.sh b/svm/snap.sh index 819708442c..80ecdadc95 100755 --- a/svm/snap.sh +++ b/svm/snap.sh @@ -1,3 +1,5 @@ +export NODE_OPTIONS="--max-old-space-size=8192" + ts-node ./src/snap.ts ts-node ./src/ticks.ts ts-node ./src/pool_apy.ts diff --git a/svm/src/utils.ts b/svm/src/utils.ts index ccef25dd80..4fc356ff49 100644 --- a/svm/src/utils.ts +++ b/svm/src/utils.ts @@ -95,7 +95,7 @@ export const getJupPricesData = async ( const requests = chunkedIds.map( async (idsChunk) => await axios.get( - `https://price.jup.ag/v4/price?ids=${idsChunk.join(",")}` + `https://api.jup.ag/price/v2?ids=${idsChunk.join(",")}` ) ); @@ -443,10 +443,7 @@ interface RawJupApiResponse { string, { id: string; - mintSymbol: string; - vsToken: string; - vsTokenSymbol: string; - price: number; + price: string; } >; timeTaken: number; @@ -465,20 +462,22 @@ export const getJupPricesData2 = async ( const requests = chunkedIds.map( async (idsChunk) => await axios.get( - `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>( - (acc, { id, price }) => { - acc[id] = { price: price ?? 0 }; - return acc; - }, - {} - ); + return concatRes.reduce>((acc, tokenData) => { + if (tokenData?.id) { + acc[tokenData.id] = { price: Number(tokenData.price ?? 0) }; + } + return acc; + }, {}); };