From d2dc7a826034f596d56e0b16f47a21020cc9ffa8 Mon Sep 17 00:00:00 2001 From: 0xgnek <0xgnek@gmail.com> Date: Wed, 31 Jul 2024 17:13:36 +0000 Subject: [PATCH] fix meteora volume --- dexs/meteora/index.ts | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/dexs/meteora/index.ts b/dexs/meteora/index.ts index 9f8ad5e67a..741f360d68 100644 --- a/dexs/meteora/index.ts +++ b/dexs/meteora/index.ts @@ -1,19 +1,47 @@ import { CHAIN } from '../../helpers/chains'; import { httpGet } from '../../utils/fetchURL'; -const meteoraStatsEndpoint = "https://met-stats.meteora.ag/defillama/stats"; +const meteoraStatsEndpoint = 'https://amm-v2.meteora.ag/pools/v2'; interface Stats24H { dailyVolume: number timestamp: number }; +interface Pool { + total_count: number + data: Array<{ + trading_volume: number + }> +} + async function fetch(timestamp: number): Promise { - let response: Stats24H = await httpGet(meteoraStatsEndpoint); - return { - dailyVolume: response.dailyVolume, - timestamp: timestamp - }; + let dailyVolume = 0; + let page = 0; + try { + while (true) { + const url = `${meteoraStatsEndpoint}?page=${page}&size=500`; + const response:Pool = (await httpGet(url)); + response.data.forEach(pool => { + dailyVolume += pool.trading_volume; + }) + if (response.data.length < 500) { + break; + } + if (page > 50) break; + page++; + } + return { + dailyVolume: dailyVolume, + timestamp: timestamp + } + } catch (error) { + return { + dailyVolume: dailyVolume, + timestamp: timestamp + } + } + } export default {