diff --git a/dexs/raydium/index.ts b/dexs/raydium/index.ts index 1cfea79bc6..fc3aa304c6 100644 --- a/dexs/raydium/index.ts +++ b/dexs/raydium/index.ts @@ -1,31 +1,34 @@ -import { SimpleAdapter } from "../../adapters/types"; +import { FetchResultVolume, SimpleAdapter } from "../../adapters/types"; import fetchURL from "../../utils/fetchURL" -const endpoints = { - solana: "https://api.raydium.io/v2/main/info", -}; - -const graphs = (chain: string) => async () => { - let res; - switch (chain) { - case "solana": - res = await fetchURL(endpoints.solana); - default: - res = await fetchURL(endpoints.solana); - } +const urlAmmPool = "https://api.raydium.io/v2/main/info"; +const urlAmmPoolStandard = "https://api.raydium.io/v2/ammV3/ammPools" + +interface IAmmPoool { + totalvolume: string; + volume24h: number; +} +interface IAmmPooolStandar { + volume: number; +} +const graphs = async (timestamp: number): Promise => { + const ammPool: IAmmPoool = (await fetchURL(urlAmmPool)).data; + const ammPoolStandard: any[] = (await fetchURL(urlAmmPoolStandard)).data.data;; + const ammPoolStandardVolume: IAmmPooolStandar[] = ammPoolStandard.map((e: any) => e.day); + const dailyVolumeAmmPool = ammPoolStandardVolume.reduce((a: number, b: IAmmPooolStandar) => a + b.volume, 0) return { - totalVolume: res?.data?.totalvolume, - dailyVolume: res?.data?.volume24h, - timestamp: Math.trunc(Date.now() / 1000) + dailyVolume: ammPool?.volume24h ? `${ammPool?.volume24h + dailyVolumeAmmPool}`: undefined, + // totalVolume: ammPool?.totalvolume ? `${ammPool?.totalvolume}`: undefined, + timestamp: timestamp }; }; const adapter: SimpleAdapter = { adapter: { solana: { - fetch: graphs("solana"), + fetch: graphs, runAtCurrTime: true, customBackfill: undefined, start: async () => 0,