diff --git a/adapters/types.ts b/adapters/types.ts index 475e856242..fa1cb4bb4c 100644 --- a/adapters/types.ts +++ b/adapters/types.ts @@ -72,7 +72,7 @@ export type BaseAdapter = { start: IStartTimestamp | number fetch: Fetch|FetchV2; runAtCurrTime?: boolean; - customBackfill?: Fetch; + customBackfill?: Fetch|FetchV2; meta?: { methodology?: string | IJSON hallmarks?: [number, string][] diff --git a/cli/testAdapter.ts b/cli/testAdapter.ts index 28c727649d..438510e10f 100644 --- a/cli/testAdapter.ts +++ b/cli/testAdapter.ts @@ -34,7 +34,7 @@ const passedFile = path.resolve(process.cwd(), `./${adapterType}/${process.argv[ const adapterVersion = module.version let timestamp = endCleanDayTimestamp if (adapterVersion === 2) { - timestamp = process.argv[4] ? +process.argv[4] : getTimestamp30MinutesAgo() + timestamp = (process.argv[4] ? +process.argv[4] : getTimestamp30MinutesAgo()) - 86400 // 1 day; } console.info(`${upperCaseFirst(adapterType)} for ${formatTimestampAsDate(String(getUniqStartOfTodayTimestamp(new Date(timestamp * 1000))))}`) console.info(`_______________________________________\n`) diff --git a/dexs/3xcalibur/index.ts b/dexs/3xcalibur/index.ts index 279b09af12..df7b06c750 100644 --- a/dexs/3xcalibur/index.ts +++ b/dexs/3xcalibur/index.ts @@ -20,6 +20,7 @@ const graphs = getChainVolume({ }); const adapter: SimpleAdapter = { + version: 2, adapter: { [CHAIN.ARBITRUM]: { fetch: graphs(CHAIN.ARBITRUM), diff --git a/dexs/ArbitrumExchange/index.ts b/dexs/ArbitrumExchange/index.ts index 947ae22ea9..7c72ca2016 100644 --- a/dexs/ArbitrumExchange/index.ts +++ b/dexs/ArbitrumExchange/index.ts @@ -66,6 +66,7 @@ const startTimeV3:TStartTime = { [CHAIN.ARBITRUM]: 1683590400, } const adapter: BreakdownAdapter = { + version: 2, breakdown: { v2: { [CHAIN.ARBITRUM]: { diff --git a/dexs/DerpDEX/index.ts b/dexs/DerpDEX/index.ts index 69d4718321..7f47fa594e 100644 --- a/dexs/DerpDEX/index.ts +++ b/dexs/DerpDEX/index.ts @@ -3,9 +3,17 @@ import { CHAIN } from "../../helpers/chains"; import { getGraphDimensions } from "../../helpers/getUniSubgraph"; const endpoints = { - [CHAIN.ERA]: "https://api.studio.thegraph.com/query/49147/derpdex-v3-amm/v0.0.10", - [CHAIN.BASE]: "https://api.thegraph.com/subgraphs/name/geckocoding/derpdex-amm-base", - [CHAIN.OP_BNB]: "https://opbnb.subgraph.derpdex.com/subgraphs/name/geckocoding/derpdex-opbnb" + [CHAIN.ERA]: + "https://api.studio.thegraph.com/query/49147/derpdex-v3-amm/v0.0.10", + [CHAIN.BASE]: + "https://api.thegraph.com/subgraphs/name/geckocoding/derpdex-amm-base", + [CHAIN.OP_BNB]: + "https://opbnb.subgraph.derpdex.com/subgraphs/name/geckocoding/derpdex-opbnb", +}; +const v3StartTimes = { + [CHAIN.ERA]: 1688515200, + [CHAIN.BASE]: 1692296100, + [CHAIN.OP_BNB]: 1695275237, }; const v3Graphs = getGraphDimensions({ @@ -17,7 +25,7 @@ const v3Graphs = getGraphDimensions({ dailyVolume: { factory: "uniswapDayData", field: "volumeUSD", - dateField: "date" + dateField: "date", }, dailyFees: { factory: "uniswapDayData", @@ -29,25 +37,17 @@ const v3Graphs = getGraphDimensions({ HoldersRevenue: 0, UserFees: 100, // User fees are 0% of collected fees SupplySideRevenue: 100, // 100% of fees are going to LPs - Revenue: 0 // Revenue is 0% of collected fees - } + Revenue: 0, // Revenue is 0% of collected fees + }, }); -const adapter: Adapter = { - adapter: { - [CHAIN.ERA]: { - fetch: v3Graphs(CHAIN.ERA), - start: 1688515200 - }, - [CHAIN.BASE]: { - fetch: v3Graphs(CHAIN.BASE), - start: 1692296100 - }, - [CHAIN.OP_BNB]: { - fetch: v3Graphs(CHAIN.OP_BNB), - start: 1695275237 - } - } -}; +const adapter: Adapter = { adapter: {}, version: 2 }; + +Object.keys(endpoints).map((chain: string) => { + adapter.adapter[chain] = { + fetch: v3Graphs(chain), + start: v3StartTimes[chain], + }; +}); export default adapter; diff --git a/dexs/SmarDex/index.ts b/dexs/SmarDex/index.ts index fe070ffdc6..7bc1ae13a0 100644 --- a/dexs/SmarDex/index.ts +++ b/dexs/SmarDex/index.ts @@ -39,6 +39,14 @@ const graphRequestHeaders:IMap = { [CHAIN.POLYGON]: defaultHeaders, }; +const startTimes = { + [CHAIN.ARBITRUM]: 1689582249, + [CHAIN.BASE]: 1691491872, + [CHAIN.BSC]: 1689581494, + [CHAIN.ETHEREUM]: 1678404995, + [CHAIN.POLYGON]: 1689582144, +} + /** * @note We are using this method that allow us to use http headers * The method `getGraphDimensions` try returns daily fees and total fees @@ -58,29 +66,13 @@ const graphs = getGraphDimensions({ }, }); -const adapter: SimpleAdapter = { - adapter: { - [CHAIN.ETHEREUM]: { - fetch: graphs(CHAIN.ETHEREUM), - start: 1678404995, // birthBlock timestamp - }, - [CHAIN.BSC]: { - fetch: graphs(CHAIN.BSC), - start: 1689581494, - }, - [CHAIN.POLYGON]: { - fetch: graphs(CHAIN.POLYGON), - start: 1689582144, - }, - [CHAIN.ARBITRUM]: { - fetch: graphs(CHAIN.ARBITRUM), - start: 1689582249, - }, - [CHAIN.BASE]: { - fetch: graphs(CHAIN.BASE), - start: 1691491872, - }, - }, -}; +const adapter: SimpleAdapter = { adapter: {}, version: 2 } + +Object.keys(graphUrls).map((chain: string) => { + adapter.adapter[chain] = { + fetch: graphs(chain), + start: startTimes[chain] + } +}) export default adapter; diff --git a/dexs/agni-fi/index.ts b/dexs/agni-fi/index.ts index 9fbfa25c80..9262673b16 100644 --- a/dexs/agni-fi/index.ts +++ b/dexs/agni-fi/index.ts @@ -34,6 +34,7 @@ const v3Graphs = getGraphDimensions({ }); const adapter: SimpleAdapter = { + version: 2, adapter: { [CHAIN.MANTLE]: { fetch: v3Graphs(CHAIN.MANTLE), diff --git a/dexs/archly-finance/index.ts b/dexs/archly-finance/index.ts index 755b578d01..e8b48b3d57 100644 --- a/dexs/archly-finance/index.ts +++ b/dexs/archly-finance/index.ts @@ -27,6 +27,7 @@ const graphFetch = getGraphDimensions({ }); const adapter: Adapter = { + version: 2, adapter: { [CHAIN.TELOS]: { fetch: graphFetch(CHAIN.TELOS), diff --git a/dexs/ascent/index.ts b/dexs/ascent/index.ts index a4cee08c5e..7eef0dc886 100644 --- a/dexs/ascent/index.ts +++ b/dexs/ascent/index.ts @@ -41,6 +41,7 @@ const graphsV3 = getChainVolume({ const adapter: BreakdownAdapter = { + version: 2, breakdown: { v2: { [CHAIN.EON]: { diff --git a/dexs/auragi/index.ts b/dexs/auragi/index.ts index 97164ab902..26ee709ebc 100644 --- a/dexs/auragi/index.ts +++ b/dexs/auragi/index.ts @@ -20,6 +20,7 @@ const graphs = getChainVolume({ }); const adapter: SimpleAdapter = { + version: 2, adapter: { [CHAIN.ARBITRUM]: { fetch: graphs(CHAIN.ARBITRUM), diff --git a/dexs/balancer/index.ts b/dexs/balancer/index.ts index bda454de3e..422002420a 100644 --- a/dexs/balancer/index.ts +++ b/dexs/balancer/index.ts @@ -1,6 +1,6 @@ import { Chain } from "@defillama/sdk/build/general"; import request, { gql } from "graphql-request"; -import { BaseAdapter, BreakdownAdapter, ChainEndpoints, FetchResultVolume } from "../../adapters/types"; +import { BaseAdapter, BreakdownAdapter, ChainEndpoints, FetchResultV2, FetchResultVolume, FetchV2 } from "../../adapters/types"; import { CHAIN } from "../../helpers/chains"; import customBackfill from "../../helpers/customBackfill"; import { getStartTimestamp } from "../../helpers/getStartTimestamp"; @@ -37,8 +37,8 @@ interface IPoolSnapshot { const v2Graphs = (chain: Chain) => { - return async (timestamp: number): Promise => { - const startTimestamp = getTimestampAtStartOfDayUTC(timestamp) + return async ({ endTimestamp }): Promise => { + const startTimestamp = getTimestampAtStartOfDayUTC(endTimestamp) const fromTimestamp = startTimestamp - 60 * 60 * 24 const toTimestamp = startTimestamp const graphQuery = gql @@ -62,7 +62,6 @@ const v2Graphs = (chain: Chain) => { return { dailyVolume: `${dailyVolume}`, - timestamp, }; }; }; @@ -76,6 +75,7 @@ const v1graphs = getChainVolume({ }); const adapter: BreakdownAdapter = { + version: 2, breakdown: { v1: { [CHAIN.ETHEREUM]: { diff --git a/dexs/baseswap/index.ts b/dexs/baseswap/index.ts index 3997bd6246..b52df5505e 100644 --- a/dexs/baseswap/index.ts +++ b/dexs/baseswap/index.ts @@ -78,6 +78,7 @@ const startTimeV3 = { }; const adapter: BreakdownAdapter = { + version: 2, breakdown: { v2: Object.keys(v2Endpoints).reduce((acc, chain) => { return { diff --git a/dexs/beamswap-v3/index.ts b/dexs/beamswap-v3/index.ts index 428b809bfd..7fd34e6a12 100644 --- a/dexs/beamswap-v3/index.ts +++ b/dexs/beamswap-v3/index.ts @@ -40,6 +40,7 @@ const methodologyv3 = { }; const adapter: BreakdownAdapter = { + version: 2, breakdown: { v3: { [CHAIN.MOONBEAN]: { diff --git a/dexs/beamswap/index.ts b/dexs/beamswap/index.ts index cab000b1d5..715308ab6a 100644 --- a/dexs/beamswap/index.ts +++ b/dexs/beamswap/index.ts @@ -77,6 +77,7 @@ const methodologyStable = { }; const adapter: BreakdownAdapter = { + version: 2, breakdown: { classic: { [CHAIN.MOONBEAN]: { diff --git a/dexs/butterxyz/index.ts b/dexs/butterxyz/index.ts index a11ff6c622..793a5c8ea7 100644 --- a/dexs/butterxyz/index.ts +++ b/dexs/butterxyz/index.ts @@ -30,6 +30,7 @@ const dimensions = getGraphDimensions({ }); export default { + version: 2, adapter: { [CHAIN.MANTLE]: { fetch: dimensions(CHAIN.MANTLE), diff --git a/dexs/carthage/index.ts b/dexs/carthage/index.ts index 576b76ad83..4d5de83f59 100644 --- a/dexs/carthage/index.ts +++ b/dexs/carthage/index.ts @@ -33,6 +33,7 @@ const v3Graphs = getChainVolume({ }); const adapter: BreakdownAdapter = { + version: 2, breakdown: { v3: { [CANDLE]: { diff --git a/dexs/champagneswap/index.ts b/dexs/champagneswap/index.ts index 480c7938a4..9e432d3f78 100644 --- a/dexs/champagneswap/index.ts +++ b/dexs/champagneswap/index.ts @@ -29,6 +29,7 @@ const graphs = getChainVolume({ }); const adapter: SimpleAdapter = { + version: 2, adapter: { [DISABLED_ADAPTER_KEY]: disabledAdapter, [BSC]: { diff --git a/dexs/cherryswap/index.ts b/dexs/cherryswap/index.ts index 1908294c87..eea87da652 100644 --- a/dexs/cherryswap/index.ts +++ b/dexs/cherryswap/index.ts @@ -56,6 +56,7 @@ const graphs = getChainVolume({ }); const adapter: SimpleAdapter = { + version: 2, adapter: { [CHAIN.OKEXCHAIN]: { fetch: graphs(CHAIN.OKEXCHAIN), diff --git a/dexs/clipper/index.ts b/dexs/clipper/index.ts index 546b4d3ec6..cf50cae129 100644 --- a/dexs/clipper/index.ts +++ b/dexs/clipper/index.ts @@ -26,6 +26,7 @@ const graphs = getChainVolume({ const adapter: SimpleAdapter = { + version: 2, adapter: Object.keys(endpoints).reduce((acc, chain: any) => { return { ...acc, diff --git a/dexs/crescent-swap/index.ts b/dexs/crescent-swap/index.ts index 5bc0e73a8f..200a407275 100644 --- a/dexs/crescent-swap/index.ts +++ b/dexs/crescent-swap/index.ts @@ -19,6 +19,7 @@ const graphs = getChainVolume({ }); const adapter: SimpleAdapter = { + version: 2, adapter: { [CHAIN.ARBITRUM]: { fetch: graphs(CHAIN.ARBITRUM), diff --git a/dexs/cryptoswap/index.ts b/dexs/cryptoswap/index.ts index 41009b24f3..de8f4963ee 100644 --- a/dexs/cryptoswap/index.ts +++ b/dexs/cryptoswap/index.ts @@ -27,6 +27,7 @@ const graphs = getChainVolume({ }); const adapter: SimpleAdapter = { + version: 2, adapter: { [CHAIN.BSC]: { fetch: graphs(CHAIN.BSC), diff --git a/dexs/dackieswap-v2/index.ts b/dexs/dackieswap-v2/index.ts index ce39b804fd..e9e3dec49b 100644 --- a/dexs/dackieswap-v2/index.ts +++ b/dexs/dackieswap-v2/index.ts @@ -47,6 +47,7 @@ const methodology = { }; const adapter: SimpleAdapter = { + version: 2, adapter: Object.keys(endpoints).reduce((acc, chain) => { return { ...acc, diff --git a/dexs/dackieswap/index.ts b/dexs/dackieswap/index.ts index 7e5a2406f6..f813b72b19 100644 --- a/dexs/dackieswap/index.ts +++ b/dexs/dackieswap/index.ts @@ -9,7 +9,7 @@ const v3Endpoint = { [CHAIN.OPTIMISM]: "https://api.studio.thegraph.com/query/50473/v3-optimism/version/latest", [CHAIN.ARBITRUM]: - "https://api.studio.thegraph.com/query/50473/v3-arbitrum/version/latest", + "https://api.studio.thegraph.com/query/50473/v3-arbitrum/version/latest", }; const VOLUME_USD = "volumeUSD"; @@ -23,12 +23,12 @@ const v3Graph = getGraphDimensions({ factory: "pancakeDayData", field: VOLUME_USD, }, - totalFees:{ + totalFees: { factory: "factories", }, dailyFees: { factory: "pancakeDayData", - field: "feesUSD" + field: "feesUSD", }, }); @@ -38,21 +38,13 @@ const v3StartTimes = { [CHAIN.ARBITRUM]: 1707885300, } as IJSON; -const adapter: SimpleAdapter = { - adapter: { - [CHAIN.BASE]: { - fetch: v3Graph(CHAIN.BASE), - start: async () => v3StartTimes[CHAIN.BASE] - }, - [CHAIN.OPTIMISM]: { - fetch: v3Graph(CHAIN.OPTIMISM), - start: async () => v3StartTimes[CHAIN.OPTIMISM] - }, - [CHAIN.ARBITRUM]: { - fetch: v3Graph(CHAIN.ARBITRUM), - start: async () => v3StartTimes[CHAIN.ARBITRUM] - }, - }, -}; +const adapter: SimpleAdapter = { adapter: {}, version: 2 }; + +Object.keys(v3StartTimes).map((chain: string) => { + adapter.adapter[chain] = { + fetch: v3Graph(chain), + start: v3StartTimes[chain], + }; +}); export default adapter; diff --git a/dexs/doveswap/index.ts b/dexs/doveswap/index.ts index 18be32c56f..266e95c726 100644 --- a/dexs/doveswap/index.ts +++ b/dexs/doveswap/index.ts @@ -55,6 +55,7 @@ const startTimeV3:TStartTime = { } const adapter: BreakdownAdapter = { + version: 2, breakdown: { v3: Object.keys(v3Endpoints).reduce((acc, chain) => { acc[chain] = { diff --git a/dexs/dragonswap/index.ts b/dexs/dragonswap/index.ts index 5860ea9e3f..9c86871dc5 100644 --- a/dexs/dragonswap/index.ts +++ b/dexs/dragonswap/index.ts @@ -73,6 +73,7 @@ const v3Graph = getGraphDimensions({ }); const adapter: BreakdownAdapter = { + version: 2, breakdown: { v2: Object.keys(endpoints).reduce((acc, chain) => { acc[chain] = { @@ -86,14 +87,7 @@ const adapter: BreakdownAdapter = { }, {} as BaseAdapter), v3: Object.keys(v3Endpoint).reduce((acc, chain) => { acc[chain] = { - fetch: async (timestamp: number) => { - const v3stats = await v3Graph(chain)(timestamp, {}) - return { - ...v3stats, - timestamp - } - - }, + fetch: v3Graph(chain), start: v3StartTimes[chain], } return acc diff --git a/dexs/elektrik/index.ts b/dexs/elektrik/index.ts index 799229d408..b7f0e0f974 100644 --- a/dexs/elektrik/index.ts +++ b/dexs/elektrik/index.ts @@ -19,6 +19,7 @@ const graphs = getChainVolume({ }); const adapter: SimpleAdapter = { + version: 2, adapter: { [CHAIN.LIGHTLINK_PHOENIX]: { fetch: graphs(CHAIN.LIGHTLINK_PHOENIX), diff --git a/dexs/fairyswap/index.ts b/dexs/fairyswap/index.ts index 7a95960946..22c14d3349 100644 --- a/dexs/fairyswap/index.ts +++ b/dexs/fairyswap/index.ts @@ -56,6 +56,7 @@ const graphs = getChainVolume({ }); const adapter: SimpleAdapter = { + version: 2, adapter: { [CHAIN.FINDORA]: { fetch: graphs(CHAIN.FINDORA), diff --git a/dexs/ferro/index.ts b/dexs/ferro/index.ts index 672344e266..9a8925d1d0 100644 --- a/dexs/ferro/index.ts +++ b/dexs/ferro/index.ts @@ -21,6 +21,7 @@ const graphs = getChainVolume({ }); const adapter: SimpleAdapter = { + version: 2, adapter: { [CHAIN.CRONOS]: { fetch: graphs(CHAIN.CRONOS), diff --git a/dexs/forge/index.ts b/dexs/forge/index.ts index 27aab5e22c..a41be4dc7b 100644 --- a/dexs/forge/index.ts +++ b/dexs/forge/index.ts @@ -22,6 +22,7 @@ const v1Graph = getChainVolume({ const adapter: SimpleAdapter = { + version: 2, adapter: { [CHAIN.EVMOS]: { fetch: v1Graph(CHAIN.EVMOS), diff --git a/dexs/fusionx-v2/index.ts b/dexs/fusionx-v2/index.ts index e871b210ef..0ec617436f 100644 --- a/dexs/fusionx-v2/index.ts +++ b/dexs/fusionx-v2/index.ts @@ -28,6 +28,7 @@ const v2Graphs = getGraphDimensions({ }); const adapter: SimpleAdapter = { + version: 2, adapter: { [CHAIN.MANTLE]: { fetch: v2Graphs(CHAIN.MANTLE), diff --git a/dexs/fusionx-v3/index.ts b/dexs/fusionx-v3/index.ts index 9cb028c967..de797f05fd 100644 --- a/dexs/fusionx-v3/index.ts +++ b/dexs/fusionx-v3/index.ts @@ -34,6 +34,7 @@ const v3Graphs = getGraphDimensions({ }); const adapter: SimpleAdapter = { + version: 2, adapter: { [CHAIN.MANTLE]: { fetch: v3Graphs(CHAIN.MANTLE), diff --git a/dexs/hadouken-amm/index.ts b/dexs/hadouken-amm/index.ts index 8a3282276f..1656f2ee32 100644 --- a/dexs/hadouken-amm/index.ts +++ b/dexs/hadouken-amm/index.ts @@ -24,6 +24,7 @@ const v1graphs = getChainVolume({ const adapter: SimpleAdapter = { + version: 2, adapter: { [CHAIN.GODWOKEN_V1]: { fetch: v1graphs(CHAIN.GODWOKEN_V1 as Chain), diff --git a/dexs/holdr/index.ts b/dexs/holdr/index.ts index 135ea7495a..87f32a937a 100644 --- a/dexs/holdr/index.ts +++ b/dexs/holdr/index.ts @@ -23,6 +23,7 @@ const v1graphs = getChainVolume({ const adapter: SimpleAdapter = { + version: 2, adapter: { [CHAIN.AURORA]: { fetch: v1graphs(CHAIN.AURORA as Chain), diff --git a/dexs/horiza/index.ts b/dexs/horiza/index.ts index d84a44b2d6..ef1f305ec5 100644 --- a/dexs/horiza/index.ts +++ b/dexs/horiza/index.ts @@ -27,6 +27,7 @@ const v3Graphs = getGraphDimensions({ }); const adapters: SimpleAdapter = { + version: 2, adapter: { [CHAIN.ARBITRUM]: { fetch: v3Graphs(CHAIN.ARBITRUM), diff --git a/dexs/hydradex/index.ts b/dexs/hydradex/index.ts index e422a69461..b0b3fe33c2 100644 --- a/dexs/hydradex/index.ts +++ b/dexs/hydradex/index.ts @@ -118,6 +118,7 @@ const methodology = { }; const adapter: BreakdownAdapter = { + version: 2, breakdown: { v2: { [DISABLED_ADAPTER_KEY]: disabledAdapter, diff --git a/dexs/integral/index.ts b/dexs/integral/index.ts index 977a4f31b5..0cdcf0eaa7 100644 --- a/dexs/integral/index.ts +++ b/dexs/integral/index.ts @@ -32,6 +32,7 @@ const graphs = getChainVolume({ }); const adapter: SimpleAdapter = { + version: 2, adapter: chains.reduce((acc, chain) => { return { ...acc, diff --git a/dexs/jswap/index.ts b/dexs/jswap/index.ts index 303d9a80a7..9048810a9f 100644 --- a/dexs/jswap/index.ts +++ b/dexs/jswap/index.ts @@ -57,6 +57,7 @@ const graphs = getGraphDimensions({ }); const adapter: SimpleAdapter = { + version: 2, adapter: { [DISABLED_ADAPTER_KEY]: disabledAdapter, [CHAIN.OKEXCHAIN]: { diff --git a/dexs/katana/index.ts b/dexs/katana/index.ts index 932313b640..86d1260100 100644 --- a/dexs/katana/index.ts +++ b/dexs/katana/index.ts @@ -64,6 +64,7 @@ const graphs = getChainVolume({ }); const adapter: SimpleAdapter = { + version: 2, adapter: { [RONIN]: { fetch: graphs(RONIN), diff --git a/dexs/kinetix-v3/index.ts b/dexs/kinetix-v3/index.ts index 50f0ad489b..99b46ae329 100644 --- a/dexs/kinetix-v3/index.ts +++ b/dexs/kinetix-v3/index.ts @@ -55,6 +55,7 @@ const v3 = Object.keys(endpointsV3).reduce( ); const adapter: BreakdownAdapter = { + version: 2, breakdown: { v3: v3, }, diff --git a/dexs/klex-finance/index.ts b/dexs/klex-finance/index.ts index f33904fc51..c95bff5e4a 100644 --- a/dexs/klex-finance/index.ts +++ b/dexs/klex-finance/index.ts @@ -25,6 +25,7 @@ const graphs = getChainVolume({ }); const adapter: SimpleAdapter = { + version: 2, adapter: Object.keys(endpoints).reduce((acc, chain: any) => { return { ...acc, diff --git a/dexs/knightswap-finance/index.ts b/dexs/knightswap-finance/index.ts index 1473ad90b7..97fa01d267 100644 --- a/dexs/knightswap-finance/index.ts +++ b/dexs/knightswap-finance/index.ts @@ -23,6 +23,7 @@ const v2Graph = getChainVolume({ const adapter: SimpleAdapter = { + version: 2, adapter: { [CHAIN.BSC]: { fetch: v2Graph(CHAIN.BSC), diff --git a/dexs/koyo/index.ts b/dexs/koyo/index.ts index ff4812bb77..fa6b8d074a 100644 --- a/dexs/koyo/index.ts +++ b/dexs/koyo/index.ts @@ -18,6 +18,7 @@ const graphs = getChainVolume({ }); const adapter: SimpleAdapter = { + version: 2, adapter: { [CHAIN.BOBA]: { fetch: graphs(CHAIN.BOBA), diff --git a/dexs/kyberswap/index.ts b/dexs/kyberswap/index.ts index 1de592c7ee..2de8e244d3 100644 --- a/dexs/kyberswap/index.ts +++ b/dexs/kyberswap/index.ts @@ -1,6 +1,6 @@ import ADDRESSES from '../../helpers/coreAssets.json' import request from "graphql-request"; -import { BaseAdapter, BreakdownAdapter, FetchResultVolume } from "../../adapters/types"; +import { BaseAdapter, BreakdownAdapter, FetchOptions, FetchResultVolume } from "../../adapters/types"; import { CHAIN } from "../../helpers/chains"; import { getStartTimestamp } from "../../helpers/getStartTimestamp"; import { @@ -210,15 +210,14 @@ const customeElasicVolumeFunctions: {[s: Chain]: any} = { function buildFromEndpoints(endpoints: typeof classicEndpoints, graphs: typeof classicGraphs, volumeField:string, dailyDataField:string, isElastic: boolean){ return Object.keys(endpoints).reduce((acc, chain) => { acc[chain] = { - fetch: async (timestamp: number) => { - const a = (customeElasicVolumeFunctions[chain] !== undefined) && isElastic ? await customeElasicVolumeFunctions[chain](timestamp) : (await graphs(chain as any)(timestamp, {})) - const elasticV2 = (kyberswapElasticV2.adapter[chain as Chain]?.fetch != undefined && isElastic) ? (await kyberswapElasticV2.adapter[chain as Chain]?.fetch(timestamp, {})) : {} as FetchResultVolume; + fetch: async (options: FetchOptions) => { + const a = (customeElasicVolumeFunctions[chain] !== undefined) && isElastic ? await customeElasicVolumeFunctions[chain](options.endTimestamp) : (await graphs(chain as any)(options)) + const elasticV2 = (kyberswapElasticV2.adapter[chain as Chain]?.fetch != undefined && isElastic) ? (await kyberswapElasticV2.adapter[chain as Chain]?.fetch(options as any, {}, options)) : {} as FetchResultVolume; const dailyVolume = Number(a.dailyVolume) + Number(elasticV2?.dailyVolume || 0) const totalVolume = Number(a.totalVolume) + Number(elasticV2?.totalVolume || 0) return { dailyVolume: `${dailyVolume}`, totalVolume: chain === CHAIN.ARBITRUM ? undefined : `${totalVolume}`, - timestamp }; }, start: getStartTimestamp({ @@ -233,6 +232,7 @@ function buildFromEndpoints(endpoints: typeof classicEndpoints, graphs: typeof c } const adapter: BreakdownAdapter = { + version: 2, breakdown: { classic: buildFromEndpoints(classicEndpoints, classicGraphs, DEFAULT_DAILY_VOLUME_FIELD, "dmmDayDatas", false), elastic: buildFromEndpoints(elasticEndpoints, elasticGraphs, "volumeUSD", "kyberSwapDayDatas", true) diff --git a/dexs/maia-v3/index.ts b/dexs/maia-v3/index.ts index e816a089d8..09d40286bd 100644 --- a/dexs/maia-v3/index.ts +++ b/dexs/maia-v3/index.ts @@ -42,6 +42,7 @@ const methodology = { } const adapter: SimpleAdapter = { + version: 2, adapter: { [CHAIN.METIS]: { fetch: v3Graphs(CHAIN.METIS), diff --git a/dexs/metavault-v3/index.ts b/dexs/metavault-v3/index.ts index b6dd42a8c2..0a529b07f6 100644 --- a/dexs/metavault-v3/index.ts +++ b/dexs/metavault-v3/index.ts @@ -57,6 +57,7 @@ const v3 = Object.keys(endpointsV3).reduce( ); const adapter: BreakdownAdapter = { + version: 2, breakdown: { v3: v3, }, diff --git a/dexs/miaswap/index.ts b/dexs/miaswap/index.ts index 335f43b31a..da01785875 100644 --- a/dexs/miaswap/index.ts +++ b/dexs/miaswap/index.ts @@ -34,6 +34,7 @@ const v3Graphs = getGraphDimensions({ }); const adapter: SimpleAdapter = { + version: 2, adapter: { [CHAIN.ONUS]: { fetch: v3Graphs(CHAIN.ONUS), diff --git a/dexs/mimo/index.ts b/dexs/mimo/index.ts index b0a49e34b1..7e92afd004 100644 --- a/dexs/mimo/index.ts +++ b/dexs/mimo/index.ts @@ -24,6 +24,7 @@ const graphs = getChainVolume({ const adapter: SimpleAdapter = { + version: 2, adapter: Object.keys(endpoints).reduce((acc, chain: any) => { return { ...acc, diff --git a/dexs/mobius-money/index.ts b/dexs/mobius-money/index.ts index 62716277cb..b82ecc5107 100644 --- a/dexs/mobius-money/index.ts +++ b/dexs/mobius-money/index.ts @@ -22,6 +22,7 @@ const graphs = getChainVolume({ }); const adapter: SimpleAdapter = { + version: 2, adapter: { [CHAIN.CELO]: { fetch: graphs(CHAIN.CELO), diff --git a/dexs/monocerus/index.ts b/dexs/monocerus/index.ts index 3d5e9b6420..3b5b4ec443 100644 --- a/dexs/monocerus/index.ts +++ b/dexs/monocerus/index.ts @@ -33,6 +33,7 @@ const v3Graphs = getGraphDimensions({ }); const adapter: Adapter = { + version: 2, adapter: { [DISABLED_ADAPTER_KEY]: disabledAdapter, [CHAIN.MANTA]: { diff --git a/dexs/mooniswap/index.ts b/dexs/mooniswap/index.ts index 9eda0ad558..a4cfaf84a9 100644 --- a/dexs/mooniswap/index.ts +++ b/dexs/mooniswap/index.ts @@ -25,6 +25,7 @@ const graphs = getChainVolume({ }); const adapter: SimpleAdapter = { + version: 2, adapter: { [ETHEREUM]: { fetch: graphs(ETHEREUM), diff --git a/dexs/nomiswap/index.ts b/dexs/nomiswap/index.ts index 29ed48eba9..bfed4ade50 100644 --- a/dexs/nomiswap/index.ts +++ b/dexs/nomiswap/index.ts @@ -1,7 +1,7 @@ import { univ2Adapter } from "../../helpers/getUniSubgraphVolume"; import { CHAIN } from "../../helpers/chains"; import { getGraphDimensions } from "../../helpers/getUniSubgraph"; -import { SimpleAdapter } from "../../adapters/types"; +import { FetchOptions, SimpleAdapter } from "../../adapters/types"; import { time } from "console"; const endpoints = { @@ -28,10 +28,11 @@ const graphsClassic = getGraphDimensions({ }); const adapters: SimpleAdapter = { + version: 2, adapter: { [CHAIN.BSC]: { - fetch: async (timestamp: number) => { - const data = await graphsClassic(CHAIN.BSC)(timestamp, {}); + fetch: async (options: FetchOptions) => { + const data = await graphsClassic(CHAIN.BSC)(options); const removeSpike = Number(data.totalVolume) - 2035654137.527446631277942307129497; data.totalVolume = removeSpike > 0 ? removeSpike : data.totalVolume; return { diff --git a/dexs/okcswap/index.ts b/dexs/okcswap/index.ts index a3c6e271b3..000558e8a0 100644 --- a/dexs/okcswap/index.ts +++ b/dexs/okcswap/index.ts @@ -55,6 +55,7 @@ const graphs = getChainVolume({ }); const adapter: SimpleAdapter = { + version: 2, adapter: { [CHAIN.OKEXCHAIN]: { fetch: graphs(CHAIN.OKEXCHAIN), diff --git a/dexs/pegasys-v3/index.ts b/dexs/pegasys-v3/index.ts index c8b7257fa5..34927e4626 100644 --- a/dexs/pegasys-v3/index.ts +++ b/dexs/pegasys-v3/index.ts @@ -19,6 +19,7 @@ const graphs = getChainVolume({ }); // rollux const adapter: SimpleAdapter = { + version: 2, adapter: { [CHAIN.ROLLUX]: { fetch: graphs(CHAIN.ROLLUX), diff --git a/dexs/quickswap/index.ts b/dexs/quickswap/index.ts index a873d09f94..91ec9a8903 100644 --- a/dexs/quickswap/index.ts +++ b/dexs/quickswap/index.ts @@ -84,6 +84,7 @@ const fetchLiquidityHub = async (timestamp: number) => { const adapter: BreakdownAdapter = { + version: 2, breakdown: { v2: { [CHAIN.POLYGON]: { diff --git a/dexs/radioshack/index.ts b/dexs/radioshack/index.ts index 6122343855..9b7ef01513 100644 --- a/dexs/radioshack/index.ts +++ b/dexs/radioshack/index.ts @@ -24,6 +24,7 @@ const graphs = getChainVolume({ }); const adapter: SimpleAdapter = { + version: 2, adapter: { [CHAIN.POLYGON]: { fetch: graphs(CHAIN.POLYGON), diff --git a/dexs/reax-one-dex/index.ts b/dexs/reax-one-dex/index.ts index 392352c72c..167d73dca9 100644 --- a/dexs/reax-one-dex/index.ts +++ b/dexs/reax-one-dex/index.ts @@ -24,6 +24,7 @@ const graphs = getChainVolume({ }); const adapter: SimpleAdapter = { + version: 2, adapter: Object.keys(endpoints).reduce((acc, chain: any) => { return { ...acc, diff --git a/dexs/retro/index.ts b/dexs/retro/index.ts index 38797f1c8b..103a65b215 100644 --- a/dexs/retro/index.ts +++ b/dexs/retro/index.ts @@ -27,6 +27,7 @@ const v3Graphs = getGraphDimensions({ }); const adapters: SimpleAdapter = { + version: 2, adapter: { [CHAIN.POLYGON]: { fetch: v3Graphs(CHAIN.POLYGON), diff --git a/dexs/saddle-finance/index.ts b/dexs/saddle-finance/index.ts index d952a8cc8b..70634220cd 100644 --- a/dexs/saddle-finance/index.ts +++ b/dexs/saddle-finance/index.ts @@ -22,6 +22,7 @@ const graphs = getChainVolume({ }); const adapter: SimpleAdapter = { + version: 2, adapter: { [CHAIN.ARBITRUM]: { fetch: graphs(CHAIN.ARBITRUM), diff --git a/dexs/shimmersea/index.ts b/dexs/shimmersea/index.ts index 14cd66008e..c837061bc7 100644 --- a/dexs/shimmersea/index.ts +++ b/dexs/shimmersea/index.ts @@ -27,6 +27,7 @@ const v3Graphs = getGraphDimensions({ }); const adapter: SimpleAdapter = { + version: 2, adapter: Object.keys(v3Endpoints).reduce((acc, chain) => { return { ...acc, diff --git a/dexs/sobal/index.ts b/dexs/sobal/index.ts index 94deb2599f..b34281f9e5 100644 --- a/dexs/sobal/index.ts +++ b/dexs/sobal/index.ts @@ -23,6 +23,7 @@ const graphs = getChainVolume({ }); const adapter: SimpleAdapter = { + version: 2, adapter: { [CHAIN.NEON]: { fetch: graphs(CHAIN.NEON), diff --git a/dexs/soulswap/index.ts b/dexs/soulswap/index.ts index fe4a658be1..19838476a9 100644 --- a/dexs/soulswap/index.ts +++ b/dexs/soulswap/index.ts @@ -45,6 +45,7 @@ const volume = Object.keys(endpoints).reduce( ); const adapter: SimpleAdapter = { + version: 2, adapter: volume, }; diff --git a/dexs/spiritswap/index.ts b/dexs/spiritswap/index.ts index deacfecce3..572b1f7248 100644 --- a/dexs/spiritswap/index.ts +++ b/dexs/spiritswap/index.ts @@ -25,6 +25,7 @@ const graphs = getChainVolumeWithGasToken({ }); const adapter: SimpleAdapter = { + version: 2, adapter: { fantom: { fetch: graphs("fantom"), diff --git a/dexs/spookyswap/index.ts b/dexs/spookyswap/index.ts index 0635d1441d..0f9dde0882 100644 --- a/dexs/spookyswap/index.ts +++ b/dexs/spookyswap/index.ts @@ -32,6 +32,7 @@ const graphsV3 = getChainVolume({ }); const adapter: SimpleAdapter = { + version: 2, adapter: { [FANTOM]: { fetch: graphs(FANTOM), diff --git a/dexs/squadswap-v2/index.ts b/dexs/squadswap-v2/index.ts index 60c6843f9f..cfad7ffd19 100644 --- a/dexs/squadswap-v2/index.ts +++ b/dexs/squadswap-v2/index.ts @@ -29,6 +29,7 @@ const v2Graph = getGraphDimensions({ }); const adapter: SimpleAdapter = { + version: 2, adapter: { [CHAIN.BSC]: { fetch: v2Graph(CHAIN.BSC), diff --git a/dexs/squadswap-v3/index.ts b/dexs/squadswap-v3/index.ts index c65dd3f019..4598f8920f 100644 --- a/dexs/squadswap-v3/index.ts +++ b/dexs/squadswap-v3/index.ts @@ -33,6 +33,7 @@ const v3Graphs = getGraphDimensions({ }); const adapter: SimpleAdapter = { + version: 2, adapter: { [CHAIN.BSC]: { fetch: v3Graphs(CHAIN.BSC), diff --git a/dexs/supswap-v2/index.ts b/dexs/supswap-v2/index.ts index 7efae4a30f..4642869cf6 100644 --- a/dexs/supswap-v2/index.ts +++ b/dexs/supswap-v2/index.ts @@ -28,6 +28,7 @@ const v2Graphs = getGraphDimensions({ }); const adapter: SimpleAdapter = { + version: 2, adapter: { [CHAIN.MODE]: { fetch: v2Graphs(CHAIN.MODE), diff --git a/dexs/supswap-v3/index.ts b/dexs/supswap-v3/index.ts index d09a6cb0f7..1d0569a1bf 100644 --- a/dexs/supswap-v3/index.ts +++ b/dexs/supswap-v3/index.ts @@ -34,6 +34,7 @@ const v3Graphs = getGraphDimensions({ }); const adapter: SimpleAdapter = { + version: 2, adapter: { [CHAIN.MODE]: { fetch: v3Graphs(CHAIN.MODE), diff --git a/dexs/surfswap/index.ts b/dexs/surfswap/index.ts index 661b7f624a..ad2dccdb8e 100644 --- a/dexs/surfswap/index.ts +++ b/dexs/surfswap/index.ts @@ -67,6 +67,7 @@ const v1graphs = getGraphDimensions({ }); const adapter: BreakdownAdapter = { + version: 2, breakdown: { classic: { [CHAIN.KAVA]: { diff --git a/dexs/sushiswap/classic.ts b/dexs/sushiswap/classic.ts index dd67edfb45..7130c329dd 100644 --- a/dexs/sushiswap/classic.ts +++ b/dexs/sushiswap/classic.ts @@ -7,6 +7,7 @@ import { getGraphDimensions } from "../../helpers/getUniSubgraph"; import { getChainVolumeWithGasToken, } from "../../helpers/getUniSubgraphVolume"; +import { FetchOptions } from "../../adapters/types"; const blacklistTokens = { [CHAIN.ARBITRUM]: [ @@ -150,8 +151,8 @@ const fantomGraphs = getChainVolumeWithGasToken({ priceToken: "coingecko:fantom" } as any); classic[CHAIN.FANTOM] = { - fetch: async (timestamp: number) => { - const values = await fantomGraphs(CHAIN.FANTOM)(timestamp, {}); + fetch: async (options: FetchOptions) => { + const values = await fantomGraphs(CHAIN.FANTOM)(options); const vol = Number(values.dailyVolume) return { ...values, diff --git a/dexs/sushiswap/index.ts b/dexs/sushiswap/index.ts index 13967b4393..c8469b769e 100644 --- a/dexs/sushiswap/index.ts +++ b/dexs/sushiswap/index.ts @@ -4,6 +4,7 @@ import classic from './classic' import v3 from './v3' const adapter: BreakdownAdapter = { + version: 2, breakdown: { classic: classic, trident: trident, diff --git a/dexs/sushiswap/v3.ts b/dexs/sushiswap/v3.ts index a0cce49c6d..b3bac22b94 100644 --- a/dexs/sushiswap/v3.ts +++ b/dexs/sushiswap/v3.ts @@ -1,6 +1,7 @@ import { Chain } from "@defillama/sdk/build/general"; import { CHAIN } from "../../helpers/chains"; import { getGraphDimensions } from "../../helpers/getUniSubgraph"; +import { Adapter, SimpleAdapter } from "../../adapters/types"; const endpointsV3 = { [CHAIN.ARBITRUM_NOVA]: 'https://subgraphs.sushi.com/subgraphs/name/sushi-v3/v3-arbitrum-nova', diff --git a/dexs/swaap/index.ts b/dexs/swaap/index.ts index 226e586837..5b238513a1 100644 --- a/dexs/swaap/index.ts +++ b/dexs/swaap/index.ts @@ -143,6 +143,7 @@ const v1graphs = getChainVolume({ }); const adapter: BreakdownAdapter = { + version: 2, breakdown: { v1: { [CHAIN.POLYGON]: { diff --git a/dexs/swapbased/index.ts b/dexs/swapbased/index.ts index 3e18398fb6..189458f6fd 100644 --- a/dexs/swapbased/index.ts +++ b/dexs/swapbased/index.ts @@ -1,7 +1,17 @@ import customBackfill from "../../helpers/customBackfill"; -import { DEFAULT_TOTAL_VOLUME_FACTORY, DEFAULT_TOTAL_VOLUME_FIELD, DEFAULT_DAILY_VOLUME_FACTORY, DEFAULT_DAILY_VOLUME_FIELD, getChainVolume } from "../../helpers/getUniSubgraphVolume"; +import { + DEFAULT_TOTAL_VOLUME_FACTORY, + DEFAULT_TOTAL_VOLUME_FIELD, + DEFAULT_DAILY_VOLUME_FACTORY, + DEFAULT_DAILY_VOLUME_FIELD, + getChainVolume, +} from "../../helpers/getUniSubgraphVolume"; import { CHAIN } from "../../helpers/chains"; -import type { Fetch, ChainEndpoints, BreakdownAdapter } from "../../adapters/types"; +import type { + Fetch, + ChainEndpoints, + BreakdownAdapter, +} from "../../adapters/types"; import { getGraphDimensions } from "../../helpers/getUniSubgraph"; import request, { gql } from "graphql-request"; import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume"; @@ -24,16 +34,17 @@ const graphs = getGraphDimensions({ }, feesPercent: { type: "volume", - UserFees: 0.30, + UserFees: 0.3, SupplySideRevenue: 0.25, ProtocolRevenue: 0.05, Revenue: 0.25, - Fees: 0.30, - } + Fees: 0.3, + }, }); const endpointsV3 = { - [CHAIN.BASE]: "https://api.thegraph.com/subgraphs/name/chimpydev/swapbased-algebra-core", + [CHAIN.BASE]: + "https://api.thegraph.com/subgraphs/name/chimpydev/swapbased-algebra-core", }; const graphsV3 = getChainVolume({ graphUrls: endpointsV3, @@ -44,7 +55,7 @@ const graphsV3 = getChainVolume({ dailyVolume: { factory: "algebraDayData", field: "volumeUSD", - dateField: "date" + dateField: "date", }, }); @@ -59,85 +70,128 @@ const methodology = { /* PERPS */ const endpointsPerps: { [key: string]: string } = { - [CHAIN.BASE]: "https://api.thegraph.com/subgraphs/name/chimpydev/swapbased-perps-core", -} + [CHAIN.BASE]: + "https://api.thegraph.com/subgraphs/name/chimpydev/swapbased-perps-core", +}; const historicalDataSwap = gql` query get_volume($period: String!, $id: String!) { - volumeStats(where: {period: $period, id: $id}) { - liquidation - margin - } + volumeStats(where: { period: $period, id: $id }) { + liquidation + margin + } } -` +`; const historicalOI = gql` query get_trade_stats($period: String!, $id: String!) { - tradingStats(where: {period: $period, id: $id}) { + tradingStats(where: { period: $period, id: $id }) { id longOpenInterest shortOpenInterest } } -` - +`; interface IGraphResponse { volumeStats: Array<{ - burn: string, - liquidation: string, - margin: string, - mint: string, - swap: string, - }> + burn: string; + liquidation: string; + margin: string; + mint: string; + swap: string; + }>; } interface IGraphResponseOI { tradingStats: Array<{ - id: string, - longOpenInterest: string, - shortOpenInterest: string, - }> + id: string; + longOpenInterest: string; + shortOpenInterest: string; + }>; } -const getFetch = (query: string)=> (chain: string): any => async (timestamp: number) => { - const dayTimestamp = getUniqStartOfTodayTimestamp(new Date((timestamp * 1000))) - const dailyData: IGraphResponse = await request(endpointsPerps[chain], query, { - id: String(dayTimestamp) + ':daily', - period: 'daily', - }) - const totalData: IGraphResponse = await request(endpointsPerps[chain], query, { - id: 'total', - period: 'total', - }) - - const tradingStats: IGraphResponseOI = await request(endpointsPerps[chain], historicalOI, { - id: String(dayTimestamp) + ':daily', - period: 'daily', - }) - - const dailyOpenInterest = Number(tradingStats.tradingStats[0]?.longOpenInterest || 0) + Number(tradingStats.tradingStats[0]?.shortOpenInterest || 0); - const dailyLongOpenInterest = Number(tradingStats.tradingStats[0]?.longOpenInterest || 0); - const dailyShortOpenInterest = Number(tradingStats.tradingStats[0]?.shortOpenInterest || 0); - - return { - timestamp: dayTimestamp, - dailyLongOpenInterest: dailyLongOpenInterest ? String(dailyLongOpenInterest * 10 ** -30) : undefined, - dailyShortOpenInterest: dailyShortOpenInterest ? String(dailyShortOpenInterest * 10 ** -30) : undefined, - dailyOpenInterest: dailyOpenInterest ? String(dailyOpenInterest * 10 ** -30) : undefined, - dailyVolume: - dailyData.volumeStats.length == 1 - ? String(Number(Object.values(dailyData.volumeStats[0]).reduce((sum, element) => String(Number(sum) + Number(element)))) * 10 ** -30) +const getFetch = + (query: string) => + (chain: string): any => + async (timestamp: number) => { + const dayTimestamp = getUniqStartOfTodayTimestamp( + new Date(timestamp * 1000), + ); + const dailyData: IGraphResponse = await request( + endpointsPerps[chain], + query, + { + id: String(dayTimestamp) + ":daily", + period: "daily", + }, + ); + const totalData: IGraphResponse = await request( + endpointsPerps[chain], + query, + { + id: "total", + period: "total", + }, + ); + + const tradingStats: IGraphResponseOI = await request( + endpointsPerps[chain], + historicalOI, + { + id: String(dayTimestamp) + ":daily", + period: "daily", + }, + ); + + const dailyOpenInterest = + Number(tradingStats.tradingStats[0]?.longOpenInterest || 0) + + Number(tradingStats.tradingStats[0]?.shortOpenInterest || 0); + const dailyLongOpenInterest = Number( + tradingStats.tradingStats[0]?.longOpenInterest || 0, + ); + const dailyShortOpenInterest = Number( + tradingStats.tradingStats[0]?.shortOpenInterest || 0, + ); + + return { + timestamp: dayTimestamp, + dailyLongOpenInterest: dailyLongOpenInterest + ? String(dailyLongOpenInterest * 10 ** -30) : undefined, - totalVolume: - totalData.volumeStats.length == 1 - ? String(Number(Object.values(totalData.volumeStats[0]).reduce((sum, element) => String(Number(sum) + Number(element)))) * 10 ** -30) + dailyShortOpenInterest: dailyShortOpenInterest + ? String(dailyShortOpenInterest * 10 ** -30) : undefined, - - } -} + dailyOpenInterest: dailyOpenInterest + ? String(dailyOpenInterest * 10 ** -30) + : undefined, + dailyVolume: + dailyData.volumeStats.length == 1 + ? String( + Number( + Object.values(dailyData.volumeStats[0]).reduce((sum, element) => + String(Number(sum) + Number(element)), + ), + ) * + 10 ** -30, + ) + : undefined, + totalVolume: + totalData.volumeStats.length == 1 + ? String( + Number( + Object.values(totalData.volumeStats[0]).reduce((sum, element) => + String(Number(sum) + Number(element)), + ), + ) * + 10 ** -30, + ) + : undefined, + }; + }; const adapter: BreakdownAdapter = { + version: 2, breakdown: { v2: { [CHAIN.BASE]: { @@ -145,20 +199,20 @@ const adapter: BreakdownAdapter = { start: 1690495200, customBackfill: customBackfill(CHAIN.BASE, graphs), meta: { methodology }, - } + }, }, v3: { [CHAIN.BASE]: { fetch: graphsV3(CHAIN.BASE), start: 1690443269, - } + }, }, perps: { [CHAIN.BASE]: { fetch: getFetch(historicalDataSwap)(CHAIN.BASE), start: 1688913853, - } - } + }, + }, }, }; diff --git a/dexs/tangleswap/index.ts b/dexs/tangleswap/index.ts index d4bb141392..6354b59383 100644 --- a/dexs/tangleswap/index.ts +++ b/dexs/tangleswap/index.ts @@ -24,6 +24,7 @@ const v3Graphs = getGraphDimensions({ }); const adapter: SimpleAdapter = { + version: 2, adapter: Object.keys(v3Endpoints).reduce((acc, chain) => { return { ...acc, diff --git a/dexs/templedao-trade/index.ts b/dexs/templedao-trade/index.ts index a09339c6c0..ba0d01019a 100644 --- a/dexs/templedao-trade/index.ts +++ b/dexs/templedao-trade/index.ts @@ -22,6 +22,7 @@ const graphs = getChainVolume({ const adapter: SimpleAdapter = { + version: 2, adapter: Object.keys(endpoints).reduce((acc, chain: any) => { return { ...acc, diff --git a/dexs/throne-v3/index.ts b/dexs/throne-v3/index.ts index 2df22f6b8c..87d959a8b3 100644 --- a/dexs/throne-v3/index.ts +++ b/dexs/throne-v3/index.ts @@ -33,6 +33,7 @@ const v3StartTimes = { } as IJSON; const adapter: SimpleAdapter = { + version: 2, adapter: { [CHAIN.BASE]: { fetch: v3Graph(CHAIN.BASE), diff --git a/dexs/traderjoe/index.ts b/dexs/traderjoe/index.ts index 376566db99..0c1c879b25 100644 --- a/dexs/traderjoe/index.ts +++ b/dexs/traderjoe/index.ts @@ -68,6 +68,7 @@ const graphsV2 = getChainVolume({ }); const adapter: BreakdownAdapter = { + version: 2, breakdown: { v1: { [CHAIN.AVAX]: { diff --git a/dexs/vapordex/index.ts b/dexs/vapordex/index.ts index d71f45f1d0..b995877c01 100644 --- a/dexs/vapordex/index.ts +++ b/dexs/vapordex/index.ts @@ -3,6 +3,7 @@ import v2 from "./v2"; import { BreakdownAdapter } from "../../adapters/types"; const adapter: BreakdownAdapter = { + version: 2, breakdown: { v1: v1, v2: v2, diff --git a/dexs/vapordex/v2.ts b/dexs/vapordex/v2.ts index 5bab677215..63e6bd52bb 100644 --- a/dexs/vapordex/v2.ts +++ b/dexs/vapordex/v2.ts @@ -43,7 +43,7 @@ const v2 = Object.keys(endpointsV2).reduce( start: startTimeV2[chain], }, }), - {} + { } ); export default v2; diff --git a/dexs/velodrome/index.ts b/dexs/velodrome/index.ts index 79619e8d73..233394147a 100644 --- a/dexs/velodrome/index.ts +++ b/dexs/velodrome/index.ts @@ -1,4 +1,4 @@ -import { SimpleAdapter } from "../../adapters/types"; +import { FetchOptions, SimpleAdapter } from "../../adapters/types"; import { DEFAULT_DAILY_VOLUME_FIELD, DEFAULT_TOTAL_VOLUME_FIELD, getChainVolume } from "../../helpers/getUniSubgraphVolume"; import { CHAIN } from "../../helpers/chains"; import { Chain } from "@defillama/sdk/build/general"; @@ -19,18 +19,19 @@ const graphs = getChainVolume({ }, }); + const fetch = (chain: Chain) => { - return async (timestamp: number) => { - const [v1] = await Promise.all([graphs(chain)(timestamp, {})]) + return async (options: FetchOptions) => { + const [v1] = await Promise.all([graphs(chain)(options)]) const dailyVolume = Number(v1.dailyVolume); return { dailyVolume: `${dailyVolume}`, - timestamp } } } const adapter: SimpleAdapter = { + version: 2, adapter: { [CHAIN.OPTIMISM]: { fetch: fetch(CHAIN.OPTIMISM), diff --git a/dexs/verse/index.ts b/dexs/verse/index.ts index b293ad6bf0..eaa5dc7887 100644 --- a/dexs/verse/index.ts +++ b/dexs/verse/index.ts @@ -31,6 +31,7 @@ const volumeAdapter: BaseAdapter = { } const adapter: SimpleAdapter = { + version: 2, adapter: volumeAdapter, } diff --git a/dexs/viperswap/index.ts b/dexs/viperswap/index.ts index 3196836015..08d2467051 100644 --- a/dexs/viperswap/index.ts +++ b/dexs/viperswap/index.ts @@ -56,6 +56,7 @@ const graphs = getChainVolume({ }); const adapter: SimpleAdapter = { + version: 2, adapter: { [DISABLED_ADAPTER_KEY]: disabledAdapter, [CHAIN.HARMONY]: { diff --git a/dexs/voltswap/index.ts b/dexs/voltswap/index.ts index 6fbb381413..4ea7d9699c 100644 --- a/dexs/voltswap/index.ts +++ b/dexs/voltswap/index.ts @@ -26,6 +26,7 @@ const graphs = getChainVolume({ }); const adapter: BreakdownAdapter = { + version: 2, breakdown: { v1: { [DISABLED_ADAPTER_KEY]: disabledAdapter, diff --git a/dexs/wardenswap/index.ts b/dexs/wardenswap/index.ts index e547013e41..4dd2cc7a67 100644 --- a/dexs/wardenswap/index.ts +++ b/dexs/wardenswap/index.ts @@ -30,6 +30,7 @@ const graphs = getChainVolume({ const adapter: SimpleAdapter = { + version: 2, adapter: Object.keys(endpoints).reduce((acc, chain: any) => { return { ...acc, diff --git a/dexs/wavelength-dao/index.ts b/dexs/wavelength-dao/index.ts index 48c426ec91..9aab70f54c 100644 --- a/dexs/wavelength-dao/index.ts +++ b/dexs/wavelength-dao/index.ts @@ -49,6 +49,7 @@ const graphs = getChainVolume({ }); const adapter: SimpleAdapter = { + version: 2, adapter: { [CHAIN.VELAS]: { fetch: graphs(CHAIN.VELAS), diff --git a/dexs/whaleswap/index.ts b/dexs/whaleswap/index.ts index a087b00bf4..7598c16549 100644 --- a/dexs/whaleswap/index.ts +++ b/dexs/whaleswap/index.ts @@ -30,6 +30,7 @@ const graphs = getChainVolume({ }); const adapter: SimpleAdapter = { + version: 2, adapter: { [BSC]: { fetch: graphs(BSC), diff --git a/dexs/wojak-finance/index.ts b/dexs/wojak-finance/index.ts index b556b6a315..8d017cbc7f 100644 --- a/dexs/wojak-finance/index.ts +++ b/dexs/wojak-finance/index.ts @@ -61,6 +61,7 @@ const graphs = getChainVolume({ }); const adapter: SimpleAdapter = { + version: 2, adapter: { [DISABLED_ADAPTER_KEY]: disabledAdapter, [CHAIN.DOGECHAIN]: { diff --git a/dexs/woofi/index.ts b/dexs/woofi/index.ts index ed2071f30a..f6b3429281 100644 --- a/dexs/woofi/index.ts +++ b/dexs/woofi/index.ts @@ -78,6 +78,7 @@ const volume = Object.keys(endpoints).reduce( ); const adapter: SimpleAdapter = { + version: 2, adapter: volume, }; export default adapter; diff --git a/dexs/xswap-protocol/index.ts b/dexs/xswap-protocol/index.ts index f00e3083c6..6daa99921a 100644 --- a/dexs/xswap-protocol/index.ts +++ b/dexs/xswap-protocol/index.ts @@ -17,6 +17,7 @@ const graphs = getGraphDimensions({ }); const adapters: SimpleAdapter = { + version: 2, adapter: { [CHAIN.XDC]: { fetch: graphs(CHAIN.XDC), diff --git a/dexs/yieldfields/index.ts b/dexs/yieldfields/index.ts index 6337a35770..e82c815f8d 100644 --- a/dexs/yieldfields/index.ts +++ b/dexs/yieldfields/index.ts @@ -29,6 +29,7 @@ const graphs = getChainVolume({ }); const adapter: SimpleAdapter = { + version: 2, adapter: { [BSC]: { fetch: graphs(BSC), diff --git a/dexs/zkswap/index.ts b/dexs/zkswap/index.ts index 481d6fc0db..7ab3d543b8 100644 --- a/dexs/zkswap/index.ts +++ b/dexs/zkswap/index.ts @@ -1,5 +1,5 @@ import { time } from "console"; -import { SimpleAdapter } from "../../adapters/types"; +import { FetchOptions, SimpleAdapter } from "../../adapters/types"; import { CHAIN } from "../../helpers/chains"; import { getGraphDimensions } from "../../helpers/getUniSubgraph"; @@ -27,10 +27,11 @@ const graph = getGraphDimensions({ }); const adapters: SimpleAdapter = { + version: 2, adapter: { [CHAIN.ERA]: { - fetch: async (timestamp: number) => { - const data = await graph(CHAIN.ERA)(timestamp, {}); + fetch: async (options: FetchOptions) => { + const data = await graph(CHAIN.ERA)(options); data.totalVolume = undefined; return { ...data diff --git a/dexs/zyberswap/index.ts b/dexs/zyberswap/index.ts index ad4aa2b261..c5297cec94 100644 --- a/dexs/zyberswap/index.ts +++ b/dexs/zyberswap/index.ts @@ -54,6 +54,7 @@ const graphsStable = getChainVolume({ const adapter: BreakdownAdapter = { + version: 2, breakdown: { v2: { [CHAIN.ARBITRUM]: { diff --git a/fees/ascent-v3.ts b/fees/ascent-v3.ts index 8a80a3c633..1d26faf801 100644 --- a/fees/ascent-v3.ts +++ b/fees/ascent-v3.ts @@ -45,6 +45,7 @@ const v3Graphs = getGraphDimensions({ }); const adapter: SimpleAdapter = { + version: 2, adapter: { [CHAIN.EON]: { fetch: v3Graphs(CHAIN.EON), diff --git a/fees/cleopatra-exchange.ts b/fees/cleopatra-exchange.ts index 5af83abbbc..1243220066 100644 --- a/fees/cleopatra-exchange.ts +++ b/fees/cleopatra-exchange.ts @@ -1,64 +1,65 @@ import { SimpleAdapter, FetchResultFees, BaseAdapter } from "../adapters/types"; import { MANTLE, CHAIN } from "../helpers/chains"; - import { - getGraphDimensions, - DEFAULT_DAILY_VOLUME_FACTORY, - DEFAULT_TOTAL_VOLUME_FIELD, - } from "../helpers/getUniSubgraph" + getGraphDimensions, + DEFAULT_DAILY_VOLUME_FACTORY, + DEFAULT_TOTAL_VOLUME_FIELD, +} from "../helpers/getUniSubgraph"; type TStartTime = { -[key: string]: number; -} -const startTimeV2:TStartTime = { -[CHAIN.MANTLE]: 1704326400, -} - + [key: string]: number; +}; +const startTimeV2: TStartTime = { + [CHAIN.MANTLE]: 1704326400, +}; const v2Endpoints = { - [CHAIN.MANTLE]: "https://subgraph-api.mantle.xyz/subgraphs/name/cleoexchange/cl-subgraph", - }; + [CHAIN.MANTLE]: + "https://subgraph-api.mantle.xyz/subgraphs/name/cleoexchange/cl-subgraph", +}; const VOLUME_USD = "volumeUSD"; const v2Graphs = getGraphDimensions({ - graphUrls: v2Endpoints, - totalVolume: { - factory: "factories", - field: DEFAULT_TOTAL_VOLUME_FIELD, - }, - dailyVolume: { - factory: DEFAULT_DAILY_VOLUME_FACTORY, - field: VOLUME_USD, - }, - feesPercent: { - type: "fees", - HoldersRevenue: 50, - UserFees: 100, // User fees are 100% of collected fees - Revenue: 50, // Revenue is 50% of collected fees - SupplySideRevenue: 50, - } - }); + graphUrls: v2Endpoints, + totalVolume: { + factory: "factories", + field: DEFAULT_TOTAL_VOLUME_FIELD, + }, + dailyVolume: { + factory: DEFAULT_DAILY_VOLUME_FACTORY, + field: VOLUME_USD, + }, + feesPercent: { + type: "fees", + HoldersRevenue: 50, + UserFees: 100, // User fees are 100% of collected fees + Revenue: 50, // Revenue is 50% of collected fees + SupplySideRevenue: 50, + }, +}); - const methodology = { - UserFees: "User pays 0.3% fees on each swap.", - ProtocolRevenue: "Revenue going to the protocol.", - HoldersRevenue: "User fees are distributed among holders." - } +const methodology = { + UserFees: "User pays 0.3% fees on each swap.", + ProtocolRevenue: "Revenue going to the protocol.", + HoldersRevenue: "User fees are distributed among holders.", +}; - const adapter: SimpleAdapter = { - adapter: { - [CHAIN.MANTLE]: {fetch: v2Graphs(MANTLE), - start: startTimeV2[CHAIN.MANTLE], - meta: { - methodology: { - ...methodology, - UserFees: "User pays 0.05%, 0.30%, or 1% on each swap." - } - } - }, - } - }; +const adapter: SimpleAdapter = { + version: 2, + adapter: { + [CHAIN.MANTLE]: { + fetch: v2Graphs(MANTLE), + start: startTimeV2[CHAIN.MANTLE], + meta: { + methodology: { + ...methodology, + UserFees: "User pays 0.05%, 0.30%, or 1% on each swap.", + }, + }, + }, + }, +}; export default adapter; diff --git a/fees/dragonswap/index.ts b/fees/dragonswap/index.ts index 5860ea9e3f..9648b3661c 100644 --- a/fees/dragonswap/index.ts +++ b/fees/dragonswap/index.ts @@ -1,5 +1,5 @@ import { Chain } from "@defillama/sdk/build/types"; -import { BaseAdapter, BreakdownAdapter, IJSON } from "../../adapters/types"; +import { BaseAdapter, BreakdownAdapter, FetchOptions, IJSON } from "../../adapters/types"; import { CHAIN } from "../../helpers/chains"; import { getGraphDimensions } from "../../helpers/getUniSubgraph"; @@ -73,6 +73,7 @@ const v3Graph = getGraphDimensions({ }); const adapter: BreakdownAdapter = { + version: 2, breakdown: { v2: Object.keys(endpoints).reduce((acc, chain) => { acc[chain] = { @@ -86,14 +87,7 @@ const adapter: BreakdownAdapter = { }, {} as BaseAdapter), v3: Object.keys(v3Endpoint).reduce((acc, chain) => { acc[chain] = { - fetch: async (timestamp: number) => { - const v3stats = await v3Graph(chain)(timestamp, {}) - return { - ...v3stats, - timestamp - } - - }, + fetch: v3Graph(chain), start: v3StartTimes[chain], } return acc diff --git a/fees/gmx.ts b/fees/gmx.ts index c12349b003..736998eb0e 100644 --- a/fees/gmx.ts +++ b/fees/gmx.ts @@ -1,8 +1,7 @@ import { Adapter } from "../adapters/types"; import { ARBITRUM, AVAX } from "../helpers/chains"; import { request, gql } from "graphql-request"; -import type { ChainEndpoints } from "../adapters/types" -import { Chain } from '@defillama/sdk/build/general'; +import type { ChainEndpoints, FetchV2 } from "../adapters/types" import { getTimestampAtStartOfDayUTC } from "../utils/date"; const endpoints = { @@ -20,9 +19,8 @@ const methodology = { } const graphs = (graphUrls: ChainEndpoints) => { - return (chain: Chain) => { - return async (timestamp: number) => { - const todaysTimestamp = getTimestampAtStartOfDayUTC(timestamp) + const fetch: FetchV2 = async ({ chain, startTimestamp }) => { + const todaysTimestamp = getTimestampAtStartOfDayUTC(startTimestamp) const searchTimestamp = chain == "arbitrum" ? todaysTimestamp : todaysTimestamp + ":daily" const graphQuery = gql @@ -43,7 +41,6 @@ const graphs = (graphUrls: ChainEndpoints) => { const finalUserFee = (userFee / 1e30); return { - timestamp, dailyFees: finalDailyFee.toString(), dailyUserFees: finalUserFee.toString(), dailyRevenue: (finalDailyFee * 0.3).toString(), @@ -53,21 +50,22 @@ const graphs = (graphUrls: ChainEndpoints) => { dailySupplySideRevenue: (finalDailyFee * 0.7).toString(), }; }; - }; + return fetch }; const adapter: Adapter = { + version: 2, adapter: { [ARBITRUM]: { - fetch: graphs(endpoints)(ARBITRUM), + fetch: graphs(endpoints), start: 1630468800, meta: { methodology } }, [AVAX]: { - fetch: graphs(endpoints)(AVAX), + fetch: graphs(endpoints), start: 1641445200, meta: { methodology diff --git a/fees/instadapp/index.ts b/fees/instadapp/index.ts index e2f9ab7206..a3c84d6a20 100644 --- a/fees/instadapp/index.ts +++ b/fees/instadapp/index.ts @@ -5,7 +5,6 @@ import { SimpleAdapter, } from "../../adapters/types"; import { Balances } from "@defillama/sdk"; -import { call } from "@defillama/sdk/build/abi/abi2"; const instaFlashAggregators: { [chain: Chain]: { address: string; deployedAt: number }; diff --git a/fees/kyotoswap.ts b/fees/kyotoswap.ts index 7b89cdee87..1f597c37f7 100644 --- a/fees/kyotoswap.ts +++ b/fees/kyotoswap.ts @@ -46,6 +46,7 @@ const methodology = { }; const adapter: Adapter = { + version: 2, adapter: Object.keys(endpoints).reduce((acc, chain) => { acc[chain] = { fetch: graphs(chain as Chain), diff --git a/fees/osmosis.ts b/fees/osmosis.ts index dc32919601..2b93e7ea5c 100644 --- a/fees/osmosis.ts +++ b/fees/osmosis.ts @@ -1,25 +1,28 @@ -import { Adapter } from "../adapters/types"; +import { Adapter, FetchV2 } from "../adapters/types"; import { getTimestampAtStartOfPreviousDayUTC } from "../utils/date"; import fetchURL from "../utils/fetchURL"; import { CHAIN } from "../helpers/chains"; -const feeEndpoint = "https://api-osmosis.imperator.co/fees/v1/total/historical" +const feeEndpoint = "https://api-osmosis.imperator.co/fees/v1/total/historical"; interface IChartItem { - time: string - fees_spent: number + time: string; + fees_spent: number; } -const fetch = async (timestamp: number) => { - const dayTimestamp = getTimestampAtStartOfPreviousDayUTC(timestamp) - const historicalFees: IChartItem[] = (await fetchURL(feeEndpoint)) +const fetch: FetchV2 = async ({ endTimestamp }) => { + const dayTimestamp = getTimestampAtStartOfPreviousDayUTC(endTimestamp); + const historicalFees: IChartItem[] = await fetchURL(feeEndpoint); const totalFee = historicalFees - .filter(feeItem => (new Date(feeItem.time).getTime() / 1000) <= dayTimestamp) - .reduce((acc, { fees_spent }) => acc + fees_spent, 0) + .filter( + (feeItem) => new Date(feeItem.time).getTime() / 1000 <= dayTimestamp, + ) + .reduce((acc, { fees_spent }) => acc + fees_spent, 0); - const dailyFee = historicalFees - .find(dayItem => (new Date(dayItem.time).getTime() / 1000) === dayTimestamp)?.fees_spent + const dailyFee = historicalFees.find( + (dayItem) => new Date(dayItem.time).getTime() / 1000 === dayTimestamp, + )?.fees_spent; return { timestamp: dayTimestamp, @@ -31,13 +34,14 @@ const fetch = async (timestamp: number) => { }; const adapter: Adapter = { + version: 2, adapter: { [CHAIN.COSMOS]: { fetch, runAtCurrTime: true, start: 1665964800, }, - } -} + }, +}; export default adapter; diff --git a/fees/pharaoh-exchange.ts b/fees/pharaoh-exchange.ts index c00c818e5b..bffdda48ec 100644 --- a/fees/pharaoh-exchange.ts +++ b/fees/pharaoh-exchange.ts @@ -1,64 +1,65 @@ import { SimpleAdapter, FetchResultFees, BaseAdapter } from "../adapters/types"; import { AVAX, CHAIN } from "../helpers/chains"; - import { - getGraphDimensions, - DEFAULT_DAILY_VOLUME_FACTORY, - DEFAULT_TOTAL_VOLUME_FIELD, - } from "../helpers/getUniSubgraph" + getGraphDimensions, + DEFAULT_DAILY_VOLUME_FACTORY, + DEFAULT_TOTAL_VOLUME_FIELD, +} from "../helpers/getUniSubgraph"; type TStartTime = { -[key: string]: number; -} -const startTimeV2:TStartTime = { -[CHAIN.AVAX]: 1702339200, -} - + [key: string]: number; +}; +const startTimeV2: TStartTime = { + [CHAIN.AVAX]: 1702339200, +}; const v2Endpoints = { - [CHAIN.AVAX]: "https://api.thegraph.com/subgraphs/name/ramsesexchange/pharaoh-cl-subgraph", - }; + [CHAIN.AVAX]: + "https://api.thegraph.com/subgraphs/name/ramsesexchange/pharaoh-cl-subgraph", +}; const VOLUME_USD = "volumeUSD"; const v2Graphs = getGraphDimensions({ - graphUrls: v2Endpoints, - totalVolume: { - factory: "factories", - field: DEFAULT_TOTAL_VOLUME_FIELD, - }, - dailyVolume: { - factory: DEFAULT_DAILY_VOLUME_FACTORY, - field: VOLUME_USD, - }, - feesPercent: { - type: "fees", - HoldersRevenue: 50, - UserFees: 100, // User fees are 100% of collected fees - Revenue: 50, // Revenue is 50% of collected fees - SupplySideRevenue: 50, - } - }); + graphUrls: v2Endpoints, + totalVolume: { + factory: "factories", + field: DEFAULT_TOTAL_VOLUME_FIELD, + }, + dailyVolume: { + factory: DEFAULT_DAILY_VOLUME_FACTORY, + field: VOLUME_USD, + }, + feesPercent: { + type: "fees", + HoldersRevenue: 50, + UserFees: 100, // User fees are 100% of collected fees + Revenue: 50, // Revenue is 50% of collected fees + SupplySideRevenue: 50, + }, +}); - const methodology = { - UserFees: "User pays 0.3% fees on each swap.", - ProtocolRevenue: "Revenue going to the protocol.", - HoldersRevenue: "User fees are distributed among holders." - } +const methodology = { + UserFees: "User pays 0.3% fees on each swap.", + ProtocolRevenue: "Revenue going to the protocol.", + HoldersRevenue: "User fees are distributed among holders.", +}; - const adapter: SimpleAdapter = { - adapter: { - [CHAIN.AVAX]: {fetch: v2Graphs(AVAX), - start: startTimeV2[CHAIN.AVAX], - meta: { - methodology: { - ...methodology, - UserFees: "User pays 0.05%, 0.30%, or 1% on each swap." - } - } - }, - } - }; +const adapter: SimpleAdapter = { + version: 2, + adapter: { + [CHAIN.AVAX]: { + fetch: v2Graphs(AVAX), + start: startTimeV2[CHAIN.AVAX], + meta: { + methodology: { + ...methodology, + UserFees: "User pays 0.05%, 0.30%, or 1% on each swap.", + }, + }, + }, + }, +}; export default adapter; diff --git a/fees/quickswap.ts b/fees/quickswap.ts index b4b914de1d..bafac82a51 100644 --- a/fees/quickswap.ts +++ b/fees/quickswap.ts @@ -75,6 +75,7 @@ const methodology = { } const adapter: BreakdownAdapter = { + version: 2, breakdown: { v2: { [CHAIN.POLYGON]: { diff --git a/fees/ramses-exchange-v2/index.ts b/fees/ramses-exchange-v2/index.ts index 361876e250..523d7fdcbb 100644 --- a/fees/ramses-exchange-v2/index.ts +++ b/fees/ramses-exchange-v2/index.ts @@ -61,10 +61,11 @@ const methodology = { } const adapter: Adapter = { + version: 2, adapter: { [CHAIN.ARBITRUM]: { - fetch: async (timestamp: number, chainBlocks: any, options: FetchOptions) => { - const v2Result = await v2Graphs(ARBITRUM)(timestamp, chainBlocks); // Pass chainBlocks as the second argument + fetch: async (options: FetchOptions) => { + const v2Result = await v2Graphs(ARBITRUM)(options) const bribesResult = await getBribes(options); v2Result.dailyBribesRevenue = bribesResult.dailyBribesRevenue; diff --git a/fees/zyberswap.ts b/fees/zyberswap.ts index ef25180e3d..722c284641 100644 --- a/fees/zyberswap.ts +++ b/fees/zyberswap.ts @@ -107,6 +107,7 @@ const methodologyStable = { } const adapter: BreakdownAdapter = { + version: 2, breakdown: { v2: { [CHAIN.ARBITRUM]: { diff --git a/helpers/customBackfill.ts b/helpers/customBackfill.ts index 74ba31f2bf..77693c573c 100644 --- a/helpers/customBackfill.ts +++ b/helpers/customBackfill.ts @@ -1,4 +1,4 @@ -import { ChainBlocks, Fetch, FetchResultGeneric } from "../adapters/types" +import { FetchOptions, FetchResultGeneric, Fetch, FetchV2, ChainBlocks } from "../adapters/types" import { getBlock } from "./getBlock" import { util } from '@defillama/sdk'; import { Chain } from "@defillama/sdk/build/general"; @@ -7,16 +7,23 @@ import BigNumber from "bignumber.js"; const { blocks: { chainsForBlocks } } = util const ONE_DAY_IN_SECONDS = 60 * 60 * 24 -export type IGraphs = (chain: Chain) => (timestamp: number, chainBlocks: ChainBlocks) => Promise +export type IGraphs = (chain: Chain) => (options: FetchOptions|number, chainBlocks: ChainBlocks) => Promise -export default (chain: Chain, graphs: IGraphs): Fetch => async (timestamp: number, chainBlocks: ChainBlocks): Promise => { +export default (chain: Chain, graphs: any): Fetch|FetchV2 => async (options: FetchOptions|number, chainBlocks: ChainBlocks): Promise => { const fetchGetVolume = graphs(chain) - const resultDayN = await fetchGetVolume(timestamp, chainBlocks) - const timestampPreviousDay = timestamp - ONE_DAY_IN_SECONDS - let chainBlocksPreviousDay = {} - if (chainsForBlocks.includes(chain) || chain === "ethereum") - chainBlocksPreviousDay = { [chain]: await getBlock(timestampPreviousDay, chain, {}).catch(() => { }) } - const resultPreviousDayN = await fetchGetVolume(timestampPreviousDay, chainBlocksPreviousDay) + let resultPreviousDayN + let resultDayN + if (typeof options == 'number') { + resultDayN = await fetchGetVolume(options, chainBlocks) + const timestampPreviousDay = options - ONE_DAY_IN_SECONDS + let chainBlocksPreviousDay = {} + if (chainsForBlocks.includes(chain) || chain === "ethereum") + chainBlocksPreviousDay = { [chain]: await getBlock(timestampPreviousDay, chain, {}).catch(() => { }) } + resultPreviousDayN = await fetchGetVolume(timestampPreviousDay, chainBlocksPreviousDay) + } else { + resultDayN = await fetchGetVolume(options) + resultPreviousDayN = await fetchGetVolume(options) + } const response: FetchResultGeneric = resultDayN Object.keys(resultPreviousDayN).filter((key) => key.includes('total')).forEach(key => { const dimension = `daily${key.slice(5)}` diff --git a/helpers/getUniSubgraph/index.ts b/helpers/getUniSubgraph/index.ts index 4127a9f8b8..d3e322595b 100644 --- a/helpers/getUniSubgraph/index.ts +++ b/helpers/getUniSubgraph/index.ts @@ -1,10 +1,9 @@ import { Chain } from "@defillama/sdk/build/general"; import { request, gql } from "graphql-request"; -import { getBlock } from "../getBlock"; -import { BaseAdapter, ChainBlocks, FetchResultGeneric, IJSON, SimpleAdapter } from "../../adapters/types"; +import { BaseAdapter, FetchOptions, FetchResultGeneric, IJSON, SimpleAdapter } from "../../adapters/types"; import { DEFAULT_DAILY_FEES_FACTORY, DEFAULT_DAILY_FEES_FIELD, DEFAULT_TOTAL_FEES_FACTORY, DEFAULT_TOTAL_FEES_FIELD } from "../getUniSubgraphFees"; import BigNumber from "bignumber.js"; -import { getUniqStartOfTodayTimestamp, getUniswapDateId, handle200Errors } from "./utils"; +import { getUniswapDateId, handle200Errors } from "./utils"; import { getStartTimestamp } from "../getStartTimestamp"; const DEFAULT_TOTAL_VOLUME_FACTORY = "uniswapFactories"; @@ -13,7 +12,7 @@ const DEFAULT_TOTAL_VOLUME_FIELD = "totalVolumeUSD"; const DEFAULT_DAILY_VOLUME_FACTORY = "uniswapDayData"; const DEFAULT_DAILY_VOLUME_FIELD = "dailyVolumeUSD"; const DEFAULT_DAILY_DATE_FIELD = "date"; -const DEFAULT_DAILY_PAIR_FACTORY = "pairDayDatas" +const DEFAULT_DAILY_PAIR_FACTORY = "pairDayDatas"; const DEFAULT_ID_TYPE = 'ID!' const DEFAULT_BLOCK_TYPE = 'Int' @@ -181,26 +180,49 @@ function getGraphDimensions({ ${graphFieldsDailyVolume.field} } } - `: undefined - return async (timestamp: number, chainBlocks: ChainBlocks) => { + ` + : undefined; + return async (options: FetchOptions) => { + const { endTimestamp, getEndBlock } = options; + // ts-node --transpile-only cli/testAdapter.ts protocols uniswap + const customBlockFunc = getCustomBlock ? getCustomBlock : getEndBlock; + const block = + (await customBlockFunc(endTimestamp).catch((e: any) => + console.log(wrapGraphError(e).message), + )) ?? undefined; // Get params - const id = String(getUniswapDateId(new Date(timestamp * 1000))); - const cleanTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000)) - const customBlockFunc = getCustomBlock ? getCustomBlock : chainBlocks?.[chain] ? async (_: number) => chainBlocks[chain] : getBlock - const block = await customBlockFunc(timestamp, chain, chainBlocks).catch(e => console.log(wrapGraphError(e).message)) ?? undefined + const id = String(getUniswapDateId(new Date(endTimestamp * 1000))); // Execute queries // DAILY VOLUME - let graphResDailyVolume - let dailyVolume: any + let graphResDailyVolume; + let dailyVolume: any; if (dailyVolumePairsQuery) { - console.info("Calculating volume excluding blacklisted tokens...") - graphResDailyVolume = await request(graphUrls[chain], dailyVolumePairsQuery, { - timestamp_gt: timestamp - 3600 * 24, - timestamp_lte: timestamp - }, graphRequestHeaders?.[chain]).catch(handle200Errors).catch(e => console.error(`GraphFetchError: Failed to get daily volume on ${chain} with graph ${graphUrls[chain]}: ${wrapGraphError(e).message}`)) - dailyVolume = graphResDailyVolume?.[graphFieldsDailyVolume.pairs]?.reduce((acc: number | undefined, current: pair) => { - if (blacklistTokens[chain].includes(current.token0.id) || blacklistTokens[chain].includes(current.token1.id)) - return acc + console.info("Calculating volume excluding blacklisted tokens..."); + graphResDailyVolume = await request( + graphUrls[chain], + dailyVolumePairsQuery, + { + timestamp_gt: endTimestamp - 3600 * 24, + timestamp_lte: endTimestamp, + }, + graphRequestHeaders?.[chain], + ) + .catch(handle200Errors) + .catch((e) => + console.error( + `GraphFetchError: Failed to get daily volume on ${chain} with graph ${ + graphUrls[chain] + }: ${wrapGraphError(e).message}`, + ), + ); + dailyVolume = graphResDailyVolume?.[ + graphFieldsDailyVolume.pairs + ]?.reduce((acc: number | undefined, current: pair) => { + if ( + blacklistTokens[chain].includes(current.token0.id) || + blacklistTokens[chain].includes(current.token1.id) + ) + return acc; if (current?.[graphFieldsDailyVolume.field]) { if (acc) return acc += +current?.[graphFieldsDailyVolume.field] return +current?.[graphFieldsDailyVolume.field] @@ -212,7 +234,7 @@ function getGraphDimensions({ dailyVolume = graphResDailyVolume?.[graphFieldsDailyVolume.factory]?.[graphFieldsDailyVolume.field] if (!graphResDailyVolume || !dailyVolume) { console.info("Attempting with alternative query...") - graphResDailyVolume = await request(graphUrls[chain], alternativeDailyQuery, { timestamp: cleanTimestamp }, graphRequestHeaders?.[chain]).catch(handle200Errors).catch(e => console.error(`Failed to get alternative daily volume on ${chain} with graph ${graphUrls[chain]}: ${wrapGraphError(e).message}`)) + graphResDailyVolume = await request(graphUrls[chain], alternativeDailyQuery, { timestamp: endTimestamp }, graphRequestHeaders?.[chain]).catch(handle200Errors).catch(e => console.error(`Failed to get alternative daily volume on ${chain} with graph ${graphUrls[chain]}: ${wrapGraphError(e).message}`)) const factory = graphFieldsDailyVolume.factory.toLowerCase().charAt(graphFieldsDailyVolume.factory.length - 1) === 's' ? graphFieldsDailyVolume.factory : `${graphFieldsDailyVolume.factory}s` dailyVolume = graphResDailyVolume?.[factory].reduce((p: any, c: any) => p + Number(c[graphFieldsDailyVolume.field]), 0); } @@ -237,7 +259,7 @@ function getGraphDimensions({ const totalFees = graphResTotalFees?.[graphFieldsTotalFees.factory]?.reduce((total: number, factory: any) => total + Number(factory[graphFieldsTotalFees.field]), 0) const response: FetchResultGeneric = { - timestamp, + timestamp: endTimestamp, block, totalVolume, dailyVolume, @@ -276,23 +298,23 @@ function univ2DimensionAdapter(params: IGetChainVolumeParams, meta: BaseAdapter[ chain, volumeField: params.dailyVolume?.field, dailyDataField: params.dailyVolume?.factory + "s", - dateField: params.dailyVolume?.dateField + dateField: params.dailyVolume?.dateField, }), - meta - } - } - }, {} as BaseAdapter) + meta, + }, + }; + }, {} as BaseAdapter), }; return adapter; } function wrapGraphError(e: Error) { - const message = (e as any).response?.errors?.[0]?.message ?? e.message - return new Error(shortenString(message)) + const message = (e as any).response?.errors?.[0]?.message ?? e.message; + return new Error(shortenString(message)); function shortenString(str: string, maxLength: number = 420) { - return str.length > maxLength ? str.slice(0, maxLength) + '...' : str + return str.length > maxLength ? str.slice(0, maxLength) + "..." : str; } } diff --git a/helpers/getUniSubgraphVolume.ts b/helpers/getUniSubgraphVolume.ts index 7991c680fe..2761ffcc52 100644 --- a/helpers/getUniSubgraphVolume.ts +++ b/helpers/getUniSubgraphVolume.ts @@ -1,7 +1,7 @@ import { Chain } from "@defillama/sdk/build/general"; import { request, gql } from "graphql-request"; import { getBlock } from "./getBlock"; -import { BaseAdapter, ChainBlocks } from "../adapters/types"; +import { BaseAdapter, ChainBlocks, FetchOptions } from "../adapters/types"; import { SimpleAdapter } from "../adapters/types"; import { DEFAULT_DATE_FIELD, getStartTimestamp } from "./getStartTimestamp"; import { Balances } from "@defillama/sdk"; @@ -50,7 +50,7 @@ interface IGetChainVolumeParams { hasTotalVolume?: boolean getCustomBlock?: (timestamp: number) => Promise } - +// HERE function getChainVolume({ graphUrls, totalVolume = { @@ -93,12 +93,13 @@ function getChainVolume({ const graphQueryDailyVolume = gql`${hasDailyVolume ? `query get_daily_volume($id: Int) { ${dailyVolumeQuery} }` : ""}`; return (chain: Chain) => { - return async (timestamp: number, chainBlocks: ChainBlocks) => { - const block = - (getCustomBlock ? - await getCustomBlock(timestamp).catch(e => console.log(e.message)) : - await getBlock(timestamp, chain, chainBlocks).catch(e => console.log(e.message))) ?? undefined; - const id = getUniswapDateId(new Date(timestamp * 1000)); + return async (options: FetchOptions) => { + const { endTimestamp, getEndBlock } = options; + const customBlockFunc = getCustomBlock ? getCustomBlock : getEndBlock; + const block = (await customBlockFunc(endTimestamp).catch((e: any) => + console.log(wrapGraphError(e).message), + )) ?? undefined; + const id = getUniswapDateId(new Date(endTimestamp * 1000)); const graphResTotal = hasTotalVolume ? await request(graphUrls[chain], graphQueryTotalVolume, { block }).catch(e => { try { return JSON.parse(e.response.error).data @@ -115,7 +116,7 @@ function getChainVolume({ }) : undefined; let dailyVolumeValue = graphResDaily ? graphResDaily[dailyVolume.factory]?.[dailyVolume.field] : undefined if (hasDailyVolume && !dailyVolumeValue) { - graphResDaily = await request(graphUrls[chain], alternativeDaily(getUniqStartOfTodayTimestamp(new Date(timestamp * 1000)))).catch(e => { + graphResDaily = await request(graphUrls[chain], alternativeDaily(getUniqStartOfTodayTimestamp(new Date(endTimestamp * 1000)))).catch(e => { try { return JSON.parse(e.response.error).data } catch (error) { @@ -127,7 +128,7 @@ function getChainVolume({ } return { - timestamp, + timestamp: endTimestamp, block, totalVolume: graphResTotal ? graphResTotal[totalVolume.factory]?.reduce((total: number, factory: any) => total + Number(factory[totalVolume.field]), 0) : undefined, dailyVolume: dailyVolumeValue, @@ -155,14 +156,15 @@ function getChainVolumeWithGasToken({ }: IGetChainVolumeParams & {priceToken:string}) { const basic = getChainVolume({graphUrls, totalVolume, dailyVolume, customDailyVolume, hasDailyVolume, hasTotalVolume, getCustomBlock}) return (chain: Chain) => { - return async (timestamp: number, chainBlocks: ChainBlocks) => { + return async (options: FetchOptions) => { const { block, totalVolume, dailyVolume, - } = await basic(chain)(timestamp, chainBlocks); + } = await basic(chain)(options); - const balances = new Balances({ chain, timestamp}) + const timestamp = options.endTimestamp + const balances = new Balances({ chain, timestamp }) balances.add(priceToken, Number(dailyVolume).toFixed(0), { skipChain: true }) return { diff --git a/options/lyra/index.ts b/options/lyra/index.ts index 26e5224d05..ade2020a01 100644 --- a/options/lyra/index.ts +++ b/options/lyra/index.ts @@ -14,6 +14,7 @@ const subgraph = getChainVolume({ }); const adapters: SimpleAdapter = { + version: 2, adapter: Object.keys(endpoints).reduce((acc, chain) => { return { ...acc, diff --git a/protocols/pancakeswap/index.ts b/protocols/pancakeswap/index.ts index 13a73de495..01d2d9a9d1 100644 --- a/protocols/pancakeswap/index.ts +++ b/protocols/pancakeswap/index.ts @@ -1,5 +1,4 @@ -import { Chain } from "@defillama/sdk/build/general"; -import { BaseAdapter, BreakdownAdapter, DISABLED_ADAPTER_KEY, FetchResultVolume, IJSON } from "../../adapters/types"; +import { BaseAdapter, BreakdownAdapter, DISABLED_ADAPTER_KEY, FetchOptions, FetchV2, IJSON } from "../../adapters/types"; import { CHAIN } from "../../helpers/chains"; import disabledAdapter from "../../helpers/disabledAdapter"; @@ -161,7 +160,7 @@ const getResources = async (account: string): Promise => { return data } -const fetchVolume = async (timestamp: number) => { +const fetchVolume: FetchV2 = async ({ endTimestamp: timestamp, createBalances }) => { const fromTimestamp = timestamp - 86400; const toTimestamp = timestamp; const account_resource: any[] = (await getResources(account)) @@ -192,7 +191,7 @@ const fetchVolume = async (timestamp: number) => { numberOfTrade[e]['count'] = 0; numberOfTrade[e]['volume'] = 0; }) - const balances = new sdk.Balances({ chain: CHAIN.APTOS, timestamp }) + const balances: sdk.Balances = createBalances() logs_swap.map((e: ISwapEventData) => { const [token0, token1] = getToken(e.type); balances.add(token0, e.amount_x_out) @@ -200,7 +199,6 @@ const fetchVolume = async (timestamp: number) => { }) return { - timestamp, dailyVolume: await balances.getUSDString(), dailyFees: "0", } @@ -247,15 +245,16 @@ const getSwapEvent = async (pool: any, fromTimestamp: number, toTimestamp: numbe const toUnixTime = (timestamp: string) => Number((Number(timestamp) / 1e6).toString().split('.')[0]) const adapter: BreakdownAdapter = { + version: 2, breakdown: { v1: { [DISABLED_ADAPTER_KEY]: disabledAdapter, [CHAIN.BSC]: { - fetch: async (timestamp: number) => { + fetch: async ({ startTimestamp }) => { const totalVolume = 103394400000; return { totalVolume: `${totalVolume}`, - timestamp: timestamp + timestamp: startTimestamp } }, start: 1680307200, @@ -263,7 +262,7 @@ const adapter: BreakdownAdapter = { }, v2: Object.keys(endpoints).reduce((acc, chain) => { acc[chain] = { - fetch: graphs(chain as Chain), + fetch: graphs(chain), start: startTimes[chain], meta: { methodology @@ -273,14 +272,10 @@ const adapter: BreakdownAdapter = { }, {} as BaseAdapter), v3: Object.keys(v3Endpoint).reduce((acc, chain) => { acc[chain] = { - fetch: async (timestamp: number) => { - const v3stats = await v3Graph(chain)(timestamp, {}) + fetch: async (options: FetchOptions) => { + const v3stats = await v3Graph(chain)(options) if (chain === CHAIN.ETHEREUM) v3stats.totalVolume = (Number(v3stats.totalVolume) - 7385565913).toString() - return { - ...v3stats, - timestamp - } - + return v3stats }, start: v3StartTimes[chain], } @@ -288,7 +283,7 @@ const adapter: BreakdownAdapter = { }, {} as BaseAdapter), stableswap: Object.keys(stablesSwapEndpoints).reduce((acc, chain) => { acc[chain] = { - fetch: graphsStableSwap(chain as Chain), + fetch: graphsStableSwap(chain), start: stableTimes[chain], meta: { methodology: { diff --git a/protocols/smbswap/index.ts b/protocols/smbswap/index.ts index 4b0ed19bd1..3e0c0b4201 100644 --- a/protocols/smbswap/index.ts +++ b/protocols/smbswap/index.ts @@ -1,5 +1,5 @@ import { Chain } from "@defillama/sdk/build/general"; -import { BaseAdapter, BreakdownAdapter, DISABLED_ADAPTER_KEY, IJSON } from "../../adapters/types"; +import { BaseAdapter, BreakdownAdapter, DISABLED_ADAPTER_KEY, FetchOptions, IJSON } from "../../adapters/types"; import { CHAIN } from "../../helpers/chains"; import disabledAdapter from "../../helpers/disabledAdapter"; @@ -109,6 +109,7 @@ const methodology = { } const adapter: BreakdownAdapter = { + version: 2, breakdown: { v1: { [DISABLED_ADAPTER_KEY]: disabledAdapter, @@ -116,10 +117,9 @@ const adapter: BreakdownAdapter = { }, v2: { [CHAIN.BSC]: { - fetch: async (timestamp: number) => { - const volume = await graphs(CHAIN.BSC)(timestamp, {}) + fetch: async (options: FetchOptions) => { + const volume = await graphs(CHAIN.BSC)(options) return { - timestamp, dailyFees: volume.dailyFees, dailyVolume: volume.dailyVolume, } diff --git a/protocols/uniswap/index.ts b/protocols/uniswap/index.ts index 6318300f7e..e07b9199ae 100644 --- a/protocols/uniswap/index.ts +++ b/protocols/uniswap/index.ts @@ -157,12 +157,20 @@ const startTimeV3:TStartTime = { [CHAIN.ERA]: 1693440000 } const adapter: BreakdownAdapter = { + version: 2, breakdown: { v1: { [CHAIN.ETHEREUM]: { - fetch: async (timestamp, chainBlocks) => { - const response = await v1Graph(CHAIN.ETHEREUM)(timestamp, chainBlocks) - const keys = ["dailyUserFees", "dailyProtocolRevenue", "dailySupplySideRevenue", "dailyHoldersRevenue", "dailyRevenue", "dailyFees"] + fetch: async (options) => { + const response = await v1Graph(options.chain)(options); + const keys = [ + "dailyUserFees", + "dailyProtocolRevenue", + "dailySupplySideRevenue", + "dailyHoldersRevenue", + "dailyRevenue", + "dailyFees", + ]; for (const key of keys) { if (typeof response[key] === 'string') { response[key] = await sdk.Balances.getUSDString({ @@ -180,9 +188,10 @@ const adapter: BreakdownAdapter = { }, v2: { [CHAIN.ETHEREUM]: { - fetch: async (timestamp, chainBlocks) => { - const response = await v2Graph(CHAIN.ETHEREUM)(timestamp, chainBlocks) - response.totalVolume = Number(response.dailyVolume) + 1079453198606.2229; + fetch: async (options) => { + const response = await v2Graph(options.chain)(options); + response.totalVolume = + Number(response.dailyVolume) + 1079453198606.2229; response.totalFees = Number(response.totalVolume) * 0.003; response.totalUserFees = Number(response.totalVolume) * 0.003; response.totalSupplySideRevenue = Number(response.totalVolume) * 0.003; @@ -214,8 +223,8 @@ const adapter: BreakdownAdapter = { }, {} as BaseAdapter) } } -// adapter.breakdown.v3.bsc.fetch = async (timestamp, chainBlocks) => { -// const response = await v3Graphs(CHAIN.BSC)(timestamp, chainBlocks) +// adapter.breakdown.v3.bsc.fetch = async ({ endTimestamp, getEndBlock }) => { +// const response = await v3Graphs(CHAIN.BSC)(endTimestamp, getEndBlock); // const totalVolume = Number(response.totalVolume) - 10_000_000_000; // return { // ...response,