From 0c5fc271f06ca14931b0faee2148d7b5764db9b2 Mon Sep 17 00:00:00 2001 From: LukasDeco Date: Tue, 20 Aug 2024 21:33:24 -0600 Subject: [PATCH] fix: calc jup quote decimals swapped around --- .../jupiter/jupiter-quotes-indexer.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/indexer/src/indexers/jupiter/jupiter-quotes-indexer.ts b/packages/indexer/src/indexers/jupiter/jupiter-quotes-indexer.ts index 68a98582..8a62c1a3 100644 --- a/packages/indexer/src/indexers/jupiter/jupiter-quotes-indexer.ts +++ b/packages/indexer/src/indexers/jupiter/jupiter-quotes-indexer.ts @@ -74,11 +74,11 @@ const convertJupTokenPrice = ( const convertJupBaseOutTokenPrice = ( data: JupTokenQuoteRes, - inputTokenDecimals: number, - outputTokenDecimals: number + quoteTokenDecimals: number, + baseTokenDecimals: number ): number => { - const inPrice = Number(data.inAmount ?? "0") / 10 ** inputTokenDecimals; - const outPrice = Number(data.outAmount ?? "0") / 10 ** outputTokenDecimals; + const inPrice = Number(data.inAmount ?? "0") / 10 ** quoteTokenDecimals; + const outPrice = Number(data.outAmount ?? "0") / 10 ** baseTokenDecimals; return inPrice / outPrice; }; @@ -174,10 +174,17 @@ export const fetchQuoteFromJupe = async ( const bidPrice = convertJupBaseOutTokenPrice( bidJson, - baseToken[0].decimals, - quoteToken[0].decimals + quoteToken[0].decimals, + baseToken[0].decimals ); + if (!askPrice) { + return [bidPrice, askJson.contextSlot]; + } + if (!bidPrice) { + return [askPrice, askJson.contextSlot]; + } + // Calculate the mid-price const midPrice = (askPrice + bidPrice) / 2;