Skip to content

Commit

Permalink
Merge pull request #2025 from jup-ag/feature/update-jupiter-aggregate…
Browse files Browse the repository at this point in the history
…r-to-use-dune

use dune for jupiter aggregator data.
  • Loading branch information
0xngmi authored Oct 22, 2024
2 parents be26631 + a29f15c commit b36e69e
Showing 1 changed file with 26 additions and 36 deletions.
62 changes: 26 additions & 36 deletions aggregators/jupiter-aggregator/index.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,37 @@
import fetchURL from "../../utils/fetchURL"
import { Chain } from "@defillama/sdk/build/general";
import { SimpleAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import customBackfill from "../../helpers/customBackfill";
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";


const historicalVolumeEndpoint = "https://cache.jup.ag/stats/day"

interface IVolumeall {
groupTimestamp: string;
amount: string;
}

const fetch = async (timestamp: number) => {
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000))
const historicalVolume: IVolumeall[] = (await fetchURL(historicalVolumeEndpoint))?.volumeInUSD;
const totalVolume = historicalVolume
.filter(volItem => (new Date(volItem.groupTimestamp).getTime() / 1000) <= dayTimestamp)
.reduce((acc, { amount }) => acc + Number(amount), 0)

const dailyVolume = historicalVolume
.find(dayItem => (new Date(dayItem.groupTimestamp).getTime() / 1000) === dayTimestamp)?.amount

import { FetchOptions } from "../../adapters/types";
import { queryDune } from "../../helpers/dune";

const fetch = async (options: FetchOptions) => {
const start = options.startOfDay;
const data = await queryDune("4187430", {
start: start,
end: start + 24 * 60 * 60,
});
const chainData = data[0];
if (!chainData) throw new Error(`Dune query failed: ${JSON.stringify(data)}`);
return {
totalVolume: `${totalVolume}`,
dailyVolume: dailyVolume ? `${dailyVolume}` : undefined,
timestamp: dayTimestamp,
dailyVolume: chainData.volume_24,
totalVolume: chainData.volume,
};
};

const getStartTimestamp = async () => {
const historicalVolume: IVolumeall[] = (await fetchURL(historicalVolumeEndpoint))?.volumeInUSD;
return (new Date(historicalVolume[historicalVolume.length - 1].groupTimestamp).getTime() / 1000);
}
const adapter: SimpleAdapter = {
const adapter: any = {
adapter: {
[CHAIN.SOLANA]: {
fetch: fetch,
start: getStartTimestamp,
customBackfill: customBackfill(CHAIN.BSC as Chain, () => fetch)
}
fetch: (_t: any, _tt: any, options: FetchOptions) => fetch(options),
start: 1681599600,
meta: {
methodology: {
totalVolume:
"Volume is calculated by summing the token volume of all trades settled on the protocol since launch.",
dailyVolume:
"Volume is calculated by summing the token volume of all trades settled on the protocol that day.",
},
},
},
},
isExpensiveAdapter: true,
};

export default adapter;

0 comments on commit b36e69e

Please sign in to comment.