From 465c53111a7bb0035a1a338ca518b479755c67ab Mon Sep 17 00:00:00 2001 From: waynebruce0x Date: Tue, 17 Sep 2024 14:06:42 +0100 Subject: [PATCH] migrate to v2 --- fees/babydogeswap.ts | 7 ++----- fees/biswap.ts | 11 ++++------- fees/elk.ts | 7 ++----- fees/ferro.ts | 9 ++------- fees/honeyswap.ts | 7 ++----- fees/mimo.ts | 9 ++------- fees/mojitoswap.ts | 4 ++-- fees/pangolin.ts | 11 ++++------- fees/vvs-finance.ts | 7 ++----- fees/wigoswap.ts | 11 ++++------- helpers/getUniSubgraph/index.ts | 27 +++++++++++++++++++++++++++ protocols/alita-finance/index.ts | 9 ++++----- 12 files changed, 57 insertions(+), 62 deletions(-) diff --git a/fees/babydogeswap.ts b/fees/babydogeswap.ts index 6dbb935de0..5ffbc0fb4c 100644 --- a/fees/babydogeswap.ts +++ b/fees/babydogeswap.ts @@ -1,17 +1,14 @@ import { CHAIN } from "../helpers/chains"; -import { univ2DimensionAdapter } from "../helpers/getUniSubgraph"; +import { univ2DimensionAdapter2 } from "../helpers/getUniSubgraph"; // 0.2% to LP providers // 0.05% to treasury // 0.05% to buy back and burn BabyDoge! -const adapters = univ2DimensionAdapter({ +const adapters = univ2DimensionAdapter2({ graphUrls: { [CHAIN.BSC]: "https://graph-bsc-mainnet.babydoge.com/subgraphs/name/babydoge/exchange" }, - dailyVolume: { - factory: "factoryDayData" - }, totalVolume: { factory: "babyDogeFactories" }, diff --git a/fees/biswap.ts b/fees/biswap.ts index 39a85e9f6b..8c9ee5629c 100644 --- a/fees/biswap.ts +++ b/fees/biswap.ts @@ -1,13 +1,10 @@ -import * as sdk from "@defillama/sdk"; +import { graph } from "@defillama/sdk"; import { CHAIN } from "../helpers/chains"; -import { univ2DimensionAdapter } from "../helpers/getUniSubgraph"; +import { univ2DimensionAdapter2 } from "../helpers/getUniSubgraph"; -const adapters = univ2DimensionAdapter({ +const adapters = univ2DimensionAdapter2({ graphUrls: { - [CHAIN.BSC]: sdk.graph.modifyEndpoint('2D9rXpMTvAgofWngsyRE17jKr5ywrU4W3Eaa71579qkd') - }, - dailyVolume: { - factory: "pancakeDayData" + [CHAIN.BSC]: graph.modifyEndpoint('2D9rXpMTvAgofWngsyRE17jKr5ywrU4W3Eaa71579qkd') }, totalVolume: { factory: "pancakeFactories" diff --git a/fees/elk.ts b/fees/elk.ts index 9c04ac9722..59c9eed33a 100644 --- a/fees/elk.ts +++ b/fees/elk.ts @@ -1,8 +1,8 @@ import * as sdk from "@defillama/sdk"; import { CHAIN } from "../helpers/chains"; -import { univ2DimensionAdapter } from "../helpers/getUniSubgraph"; +import { univ2DimensionAdapter2 } from "../helpers/getUniSubgraph"; -const adapter = univ2DimensionAdapter({ +const adapter = univ2DimensionAdapter2({ graphUrls: { [CHAIN.ARBITRUM]: sdk.graph.modifyEndpoint('B8TGNwQ8xMoeFCdsv9dPkciRBpEYAy1UxmXDr7nc9fpE'), [CHAIN.AVAX]: sdk.graph.modifyEndpoint('2dyce92CewvhV17C8BMFoMCgaXdPTtwBzaz8AReQR3YV'), @@ -22,9 +22,6 @@ const adapter = univ2DimensionAdapter({ // [CHAIN.IOTEX]: "https://iotex-graph.elk.finance/subgraphs/name/elkfinance/elkdex-iotex", // [CHAIN.TELOS]: "https://telos-graph2.elk.finance/subgraphs/name/elkfinance/elkdex-telos" }, - dailyVolume: { - factory: "elkDayData" - }, totalVolume: { factory: "elkFactories" }, diff --git a/fees/ferro.ts b/fees/ferro.ts index 7c0e16e84c..765babd80d 100644 --- a/fees/ferro.ts +++ b/fees/ferro.ts @@ -1,15 +1,10 @@ import { CHAIN } from "../helpers/chains"; -import { univ2DimensionAdapter } from "../helpers/getUniSubgraph"; +import { univ2DimensionAdapter2 } from "../helpers/getUniSubgraph"; -const adapters = univ2DimensionAdapter({ +const adapters = univ2DimensionAdapter2({ graphUrls: { [CHAIN.CRONOS]: "https://graph.cronoslabs.com/subgraphs/name/ferro/swap", }, - dailyVolume: { - factory: "dailyVolume", - field: "volume", - dateField: "timestamp" - }, totalVolume: { factory: "tradeVolumes", field: "volume" diff --git a/fees/honeyswap.ts b/fees/honeyswap.ts index 5a3a9f0f41..ff81768b53 100644 --- a/fees/honeyswap.ts +++ b/fees/honeyswap.ts @@ -1,14 +1,11 @@ import { CHAIN } from "../helpers/chains"; -import { univ2DimensionAdapter } from "../helpers/getUniSubgraph"; +import { univ2DimensionAdapter2 } from "../helpers/getUniSubgraph"; -const adapters = univ2DimensionAdapter({ +const adapters = univ2DimensionAdapter2({ graphUrls: { [CHAIN.POLYGON]: " https://api.thegraph.com/subgraphs/name/1hive/honeyswap-polygon", [CHAIN.XDAI]: "https://api.thegraph.com/subgraphs/name/1hive/honeyswap-xdai" }, - dailyVolume: { - factory: "honeyswapDayData" - }, totalVolume: { factory: "honeyswapFactories" }, diff --git a/fees/mimo.ts b/fees/mimo.ts index fd2f3f7eda..9482aa1f96 100644 --- a/fees/mimo.ts +++ b/fees/mimo.ts @@ -1,7 +1,7 @@ import { CHAIN } from "../helpers/chains"; -import { univ2DimensionAdapter } from "../helpers/getUniSubgraph"; +import { univ2DimensionAdapter2 } from "../helpers/getUniSubgraph"; -const adapter = univ2DimensionAdapter({ +const adapter = univ2DimensionAdapter2({ graphUrls: { [CHAIN.IOTEX]: "https://graph.mimo.exchange/subgraphs/name/mimo/mainnet" }, @@ -9,11 +9,6 @@ const adapter = univ2DimensionAdapter({ factory: "uniswapFactories", field: "totalVolumeUSD", }, - dailyVolume: { - factory: "uniswapDayData", - field: "dailyVolumeUSD", - dateField: "date" - }, feesPercent: { type: "volume", UserFees: 0.3, diff --git a/fees/mojitoswap.ts b/fees/mojitoswap.ts index ba557f54b2..ef63df4122 100644 --- a/fees/mojitoswap.ts +++ b/fees/mojitoswap.ts @@ -1,11 +1,11 @@ import { CHAIN } from "../helpers/chains"; -import { univ2DimensionAdapter } from "../helpers/getUniSubgraph"; +import { univ2DimensionAdapter2 } from "../helpers/getUniSubgraph"; const graphUrls = { [CHAIN.KCC]: "https://thegraph.kcc.network/subgraphs/name/mojito/swap", }; -const adapter = univ2DimensionAdapter({ +const adapter = univ2DimensionAdapter2({ graphUrls, feesPercent: { type: "volume", diff --git a/fees/pangolin.ts b/fees/pangolin.ts index f433eef1f9..729b00595a 100644 --- a/fees/pangolin.ts +++ b/fees/pangolin.ts @@ -1,13 +1,10 @@ -import * as sdk from "@defillama/sdk"; +import { graph } from "@defillama/sdk"; import { CHAIN } from "../helpers/chains"; -import { univ2DimensionAdapter } from "../helpers/getUniSubgraph"; +import { univ2DimensionAdapter2 } from "../helpers/getUniSubgraph"; -const adapter = univ2DimensionAdapter({ +const adapter = univ2DimensionAdapter2({ graphUrls: { - [CHAIN.AVAX]: sdk.graph.modifyEndpoint('CPXTDcwh6tVP88QvFWW7pdvZJsCN4hSnfMmYeF1sxCLq') - }, - dailyVolume: { - factory: "pangolinDayData" + [CHAIN.AVAX]: graph.modifyEndpoint('CPXTDcwh6tVP88QvFWW7pdvZJsCN4hSnfMmYeF1sxCLq') }, totalVolume: { factory: "pangolinFactories" diff --git a/fees/vvs-finance.ts b/fees/vvs-finance.ts index 96409080ab..c9d04ec4c3 100644 --- a/fees/vvs-finance.ts +++ b/fees/vvs-finance.ts @@ -1,13 +1,10 @@ import { CHAIN } from "../helpers/chains"; -import { univ2DimensionAdapter } from "../helpers/getUniSubgraph"; +import { univ2DimensionAdapter2 } from "../helpers/getUniSubgraph"; -const adapters = univ2DimensionAdapter({ +const adapters = univ2DimensionAdapter2({ graphUrls: { [CHAIN.CRONOS]: "https://graph.cronoslabs.com/subgraphs/name/vvs/exchange" }, - dailyVolume: { - factory: "vvsDayData" - }, totalVolume: { factory: "vvsFactories" }, diff --git a/fees/wigoswap.ts b/fees/wigoswap.ts index 8a28536226..79a6f5f925 100644 --- a/fees/wigoswap.ts +++ b/fees/wigoswap.ts @@ -1,13 +1,10 @@ -import * as sdk from "@defillama/sdk"; +import { graph } from "@defillama/sdk"; import { CHAIN } from "../helpers/chains"; -import { univ2DimensionAdapter } from "../helpers/getUniSubgraph"; +import { univ2DimensionAdapter2 } from "../helpers/getUniSubgraph"; -const adapters = univ2DimensionAdapter({ +const adapters = univ2DimensionAdapter2({ graphUrls: { - [CHAIN.FANTOM]: sdk.graph.modifyEndpoint('71os49womDk3DFcNRCAFYzATxxMgWpSMKhRn5ih6aWF1') - }, - dailyVolume: { - factory: "wigoDayData" + [CHAIN.FANTOM]: graph.modifyEndpoint('71os49womDk3DFcNRCAFYzATxxMgWpSMKhRn5ih6aWF1') }, totalVolume: { factory: "wigoswapFactories" diff --git a/helpers/getUniSubgraph/index.ts b/helpers/getUniSubgraph/index.ts index 19cbfa1086..dad74e5f23 100644 --- a/helpers/getUniSubgraph/index.ts +++ b/helpers/getUniSubgraph/index.ts @@ -449,6 +449,32 @@ function univ2DimensionAdapter(params: IGetChainVolumeParams, meta: BaseAdapter[ return adapter; } +function univ2DimensionAdapter2(params: IGetChainVolumeParams, meta: BaseAdapter[string]['meta']) { + const graphs = getGraphDimensions2(params); + + const adapter: SimpleAdapter = { + adapter: Object.keys(params.graphUrls).reduce((acc, chain) => { + return { + ...acc, + [chain]: { + fetch: graphs(chain as Chain), + start: getStartTimestamp({ + endpoints: params.graphUrls, + chain, + volumeField: params.dailyVolume?.field, + dailyDataField: params.dailyVolume?.factory + "s", + dateField: params.dailyVolume?.dateField, + }), + meta, + }, + }; + }, {} as BaseAdapter), + version: 2 + }; + + return adapter; +} + function wrapGraphError(e: Error) { const message = (e as any).response?.errors?.[0]?.message ?? e.message; return new Error(shortenString(message)); @@ -463,6 +489,7 @@ export { getGraphDimensions, getGraphDimensions2, univ2DimensionAdapter, + univ2DimensionAdapter2, DEFAULT_TOTAL_VOLUME_FACTORY, DEFAULT_TOTAL_VOLUME_FIELD, DEFAULT_DAILY_VOLUME_FACTORY, diff --git a/protocols/alita-finance/index.ts b/protocols/alita-finance/index.ts index 16b2ff8cfa..15a38b9a56 100644 --- a/protocols/alita-finance/index.ts +++ b/protocols/alita-finance/index.ts @@ -1,11 +1,10 @@ -import * as sdk from "@defillama/sdk"; -import { univ2Adapter } from "../../helpers/getUniSubgraphVolume"; +import { graph } from "@defillama/sdk"; import { CHAIN } from "../../helpers/chains"; -import { univ2DimensionAdapter } from "../../helpers/getUniSubgraph"; +import { univ2DimensionAdapter2 } from "../../helpers/getUniSubgraph"; -const adapter = univ2DimensionAdapter({ +const adapter = univ2DimensionAdapter2({ graphUrls: { - [CHAIN.BSC]: sdk.graph.modifyEndpoint('FBPHPJNE1jX18Lz8rgscvsigfxAUXakUC8w9KMid4dDz') + [CHAIN.BSC]: graph.modifyEndpoint('FBPHPJNE1jX18Lz8rgscvsigfxAUXakUC8w9KMid4dDz') }, feesPercent: { type: "volume",