From fe889def55d30cf0ff219033c7209031cb9de9dc Mon Sep 17 00:00:00 2001 From: 0xgnek <0xgnek@gmail.com> Date: Wed, 14 Feb 2024 11:59:09 +0000 Subject: [PATCH] fix combince --- dexs/demex-perp/index.ts | 39 --------------------------------- dexs/demex/index.ts | 47 +++++++++++++++++++++++++--------------- 2 files changed, 29 insertions(+), 57 deletions(-) delete mode 100644 dexs/demex-perp/index.ts diff --git a/dexs/demex-perp/index.ts b/dexs/demex-perp/index.ts deleted file mode 100644 index 385c535f4a..0000000000 --- a/dexs/demex-perp/index.ts +++ /dev/null @@ -1,39 +0,0 @@ -import fetchURL from "../../utils/fetchURL" -import { SimpleAdapter } from "../../adapters/types"; -import { CHAIN } from "../../helpers/chains"; -import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume"; - -const START_TIME = 1659312000; -const historicalVolumeEndpoint = () => `https://api.carbon.network/carbon/marketstats/v1/stats` - -interface IVolumeall { - market_type: string; - day_quote_volume: string; - date: string; -} - -const fetch = async (timestamp: number) => { - const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000)) - const historicalVolume: IVolumeall[] = (await fetchURL(historicalVolumeEndpoint()))?.data.marketstats; - - const volume = historicalVolume - .filter((e: IVolumeall) => e.market_type === "futures") - .reduce((a: number, b: IVolumeall) => a + Number(b.day_quote_volume), 0) / 1e18; - - return { - dailyVolume: volume ? `${volume}` : undefined, - timestamp: dayTimestamp, - }; -}; - -const adapter: SimpleAdapter = { - adapter: { - [CHAIN.CARBON]: { - fetch, - runAtCurrTime: true, - start: async () => 1707004800, - }, - }, -}; - -export default adapter; diff --git a/dexs/demex/index.ts b/dexs/demex/index.ts index e0f97c96f2..e5f5ab59a6 100644 --- a/dexs/demex/index.ts +++ b/dexs/demex/index.ts @@ -1,10 +1,10 @@ -import fetchURL from "../../utils/fetchURL" -import { SimpleAdapter } from "../../adapters/types"; +import fetchURL from "../../utils/fetchURL"; +import { BreakdownAdapter, SimpleAdapter } from "../../adapters/types"; import { CHAIN } from "../../helpers/chains"; import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume"; const START_TIME = 1659312000; -const historicalVolumeEndpoint = () => `https://api.carbon.network/carbon/marketstats/v1/stats` +const historicalVolumeEndpoint = () => `https://api.carbon.network/carbon/marketstats/v1/stats`; interface IVolumeall { market_type: string; @@ -12,27 +12,38 @@ interface IVolumeall { date: string; } -const fetch = async (timestamp: number) => { - const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000)) - const historicalVolume: IVolumeall[] = (await fetchURL(historicalVolumeEndpoint()))?.marketstats; +const fetch = (market_type: string) => { + return async (timestamp: number) => { + const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000)); + const historicalVolume: IVolumeall[] = (await fetchURL(historicalVolumeEndpoint()))?.marketstats; - const volume = historicalVolume - .filter((e: IVolumeall) => e.market_type === "spot") - .reduce((a: number, b: IVolumeall) => a + Number(b.day_quote_volume), 0) / 1e18; + const volume = + historicalVolume + .filter((e: IVolumeall) => e.market_type === market_type) + .reduce((a: number, b: IVolumeall) => a + Number(b.day_quote_volume), 0) / 1e18; - return { - dailyVolume: volume ? `${volume}` : undefined, - timestamp: dayTimestamp, + return { + dailyVolume: volume ? `${volume}` : undefined, + timestamp: dayTimestamp, + }; }; }; -const adapter: SimpleAdapter = { - adapter: { - [CHAIN.CARBON]: { - fetch, - start: START_TIME, +const adapters: BreakdownAdapter = { + breakdown: { + demex: { + [CHAIN.CARBON]: { + fetch: fetch("spot"), + start: START_TIME, + }, }, + "demex-perp": { + [CHAIN.CARBON]: { + fetch: fetch("futures"), + start: START_TIME, + }, + } }, }; -export default adapter; +export default adapters;