diff --git a/dexs/anyhedge/index.ts b/dexs/anyhedge/index.ts index fd87b976f3..88be091da0 100644 --- a/dexs/anyhedge/index.ts +++ b/dexs/anyhedge/index.ts @@ -1,10 +1,12 @@ -import { SimpleAdapter } from "../../adapters/types"; +import { FetchOptions, SimpleAdapter } from "../../adapters/types"; import fetchURL from "../../utils/fetchURL"; import { CHAIN } from "../../helpers/chains"; import { getTimestampAtStartOfNextDayUTC } from "../../utils/date"; const methodology = { - DailyVolume: "Scan the blockchain for AnyHedge input pattern, add up all such inputs BCH value. The daily volume is the volume of all settled contracts for the day." + Volume: "Scan the blockchain for AnyHedge input pattern, add up all such inputs BCH value. The daily volume is the volume of all settled contracts for the day. Indexer: https://gitlab.com/0353F40E/anyhedge-stats", + Fees: "N/A", + Revenue: "N/A", } interface IAnyhedgeVolumeResponse { @@ -12,34 +14,21 @@ interface IAnyhedgeVolumeResponse { total_volume: number; } -// endDay formatted as 2011-12-13 -export const anyhedgeVolumeEndpoint = (endDay: string) => { +// day formatted as 2011-12-13 +export const anyhedgeVolumeEndpoint = (day: string) => { // Data & calculation method is fully reproducible, see: // https://gitlab.com/0353F40E/anyhedge-stats/-/blob/master/readme.md - return "https://gitlab.com/0353F40E/anyhedge-stats/-/raw/master/stats_daily/" + endDay + ".csv"; + return "https://gitlab.com/0353F40E/anyhedge-stats/-/raw/master/stats_daily/" + day + ".csv"; } -const adapter: SimpleAdapter = { - adapter: { - [CHAIN.BITCOIN_CASH]: { - fetch: fetchAnyhedgeVolumeData, - start: 1654787405, - meta: { - methodology - } - }, - }, -}; - -export async function fetchAnyhedgeVolumeData( - /** Timestamp representing the end of the 24 hour period */ - timestamp: number -) { +const fetchAnyhedgeVolumeData: Fetch = async (timestamp: number, _: ChainBlocks, options: FetchOptions) => { const dayString = new Date(timestamp * 1000).toISOString().slice(0,10); const anyhedgeVolumeData = await getAnyhedgeVolumeData(anyhedgeVolumeEndpoint(dayString)); - - const dailyVolume = Number(anyhedgeVolumeData?.daily_volume); - const totalVolume = Number(anyhedgeVolumeData?.total_volume); + + const dailyVolume = options.createBalances(); + const totalVolume = options.createBalances(); + dailyVolume.addCGToken('bitcoin-cash', Number(anyhedgeVolumeData?.daily_volume)); + totalVolume.addCGToken('bitcoin-cash', Number(anyhedgeVolumeData?.total_volume)); return { timestamp, @@ -76,4 +65,15 @@ function toObject(keys, values) { return res } +const adapter: SimpleAdapter = { + adapter: { + [CHAIN.BITCOIN_CASH]: { + fetch: fetchAnyhedgeVolumeData, + start: 1654787405, + meta: { + methodology + } + }, + }, +}; export default adapter;