Skip to content

Commit

Permalink
Merge pull request #584 from DefiLlama/raydium-volume-fix
Browse files Browse the repository at this point in the history
fix volume raydium
  • Loading branch information
dtmkeng committed Jul 3, 2023
2 parents e340a65 + d51fd2c commit c2f4e2d
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions dexs/raydium/index.ts
Original file line number Diff line number Diff line change
@@ -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<FetchResultVolume> => {
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,
Expand Down

0 comments on commit c2f4e2d

Please sign in to comment.