Skip to content

Commit

Permalink
fix meteora volume
Browse files Browse the repository at this point in the history
  • Loading branch information
dtmkeng committed Jul 31, 2024
1 parent 8223f2b commit d2dc7a8
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions dexs/meteora/index.ts
Original file line number Diff line number Diff line change
@@ -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<Stats24H> {
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 {
Expand Down

0 comments on commit d2dc7a8

Please sign in to comment.