-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2025 from jup-ag/feature/update-jupiter-aggregate…
…r-to-use-dune use dune for jupiter aggregator data.
- Loading branch information
Showing
1 changed file
with
26 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |