-
Notifications
You must be signed in to change notification settings - Fork 1.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 #2197 from Plunderswap/master
add plunderswap dex volume
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import fetchURL from "../../utils/fetchURL" | ||
import { ChainBlocks, FetchOptions, SimpleAdapter } from "../../adapters/types"; | ||
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume"; | ||
|
||
const historicalVolumeEndpoint = "https://static.plunderswap.com/volume-history" | ||
|
||
interface IVolumeall { | ||
value: string; | ||
time: string; | ||
} | ||
|
||
const fetch = async (timestamp: number, _: ChainBlocks, { createBalances, startOfDay, }: FetchOptions) => { | ||
const dailyVolume = createBalances() | ||
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000)) | ||
const historicalVolume: IVolumeall[] = (await fetchURL(historicalVolumeEndpoint)); | ||
|
||
// Format the timestamp without milliseconds | ||
const targetTime = new Date(dayTimestamp * 1000).toISOString().replace('.000Z', 'Z'); | ||
|
||
// Filter entries to find exact 00:00 UTC entry of the current day | ||
const dayEntries = historicalVolume.filter(entry => { | ||
return entry.time === targetTime; | ||
}); | ||
|
||
if (dayEntries.length > 0) { | ||
dailyVolume.addCGToken("zilliqa", Number(dayEntries[0].value)); | ||
} | ||
|
||
return { dailyVolume, timestamp: startOfDay, }; | ||
}; | ||
|
||
const adapter: SimpleAdapter = { | ||
adapter: { | ||
zilliqa: { | ||
fetch, | ||
runAtCurrTime: true, | ||
start: '2024-12-10', | ||
meta: { | ||
methodology: { | ||
Volume: "Volume of trades on Plunderswap at the start of the day (00:00:00 UTC) for the previous day" | ||
} | ||
} | ||
}, | ||
}, | ||
}; | ||
|
||
export default adapter; |