diff --git a/dexs/balancer/index.ts b/dexs/balancer/index.ts index 422002420a..b363a07ed2 100644 --- a/dexs/balancer/index.ts +++ b/dexs/balancer/index.ts @@ -80,8 +80,7 @@ const adapter: BreakdownAdapter = { v1: { [CHAIN.ETHEREUM]: { fetch: v1graphs(CHAIN.ETHEREUM), - start: 1582761600, - customBackfill: customBackfill(CHAIN.ETHEREUM, v1graphs) + start: 1582761600 }, }, v2: Object.keys(endpoints).reduce((acc, chain) => { diff --git a/dexs/clipper/index.ts b/dexs/clipper/index.ts index cf50cae129..3fc78d5b04 100644 --- a/dexs/clipper/index.ts +++ b/dexs/clipper/index.ts @@ -1,7 +1,6 @@ import { Chain } from "@defillama/sdk/build/general"; import { SimpleAdapter } from "../../adapters/types"; import { CHAIN } from "../../helpers/chains"; -import customBackfill from "../../helpers/customBackfill"; const { getChainVolume, } = require("../../helpers/getUniSubgraphVolume"); @@ -33,7 +32,6 @@ const adapter: SimpleAdapter = { [chain]: { fetch: graphs(chain as Chain), start: 1657437036, - customBackfill: customBackfill(chain, graphs), } } }, {}) diff --git a/helpers/customBackfill.ts b/helpers/customBackfill.ts index 77693c573c..9f1fab8096 100644 --- a/helpers/customBackfill.ts +++ b/helpers/customBackfill.ts @@ -11,8 +11,8 @@ export type IGraphs = (chain: Chain) => (options: FetchOptions|number, chainBloc export default (chain: Chain, graphs: any): Fetch|FetchV2 => async (options: FetchOptions|number, chainBlocks: ChainBlocks): Promise => { const fetchGetVolume = graphs(chain) - let resultPreviousDayN - let resultDayN + let resultPreviousDayN: any = {} + let resultDayN: any = {} if (typeof options == 'number') { resultDayN = await fetchGetVolume(options, chainBlocks) const timestampPreviousDay = options - ONE_DAY_IN_SECONDS @@ -22,6 +22,7 @@ export default (chain: Chain, graphs: any): Fetch|FetchV2 => async (options: Fet resultPreviousDayN = await fetchGetVolume(timestampPreviousDay, chainBlocksPreviousDay) } else { resultDayN = await fetchGetVolume(options) + options.endTimestamp = options.endTimestamp - ONE_DAY_IN_SECONDS; resultPreviousDayN = await fetchGetVolume(options) } const response: FetchResultGeneric = resultDayN diff --git a/helpers/getUniSubgraphVolume.ts b/helpers/getUniSubgraphVolume.ts index 83bdf60e0a..79aeb6aed7 100644 --- a/helpers/getUniSubgraphVolume.ts +++ b/helpers/getUniSubgraphVolume.ts @@ -94,7 +94,7 @@ function getChainVolume({ return (chain: Chain) => { return async (options: FetchOptions) => { - const { endTimestamp, getEndBlock } = options; + const { endTimestamp, getEndBlock, getFromBlock, getToBlock } = options; const customBlockFunc = getCustomBlock ? getCustomBlock : getEndBlock; const block = (await customBlockFunc(endTimestamp).catch((e: any) => console.log(wrapGraphError(e).message), @@ -126,6 +126,19 @@ function getChainVolume({ const factory = dailyVolume.factory.toLowerCase().charAt(dailyVolume.factory.length - 1) === 's' ? dailyVolume.factory : `${dailyVolume.factory}s` dailyVolumeValue = graphResDaily ? graphResDaily[`${factory}`].reduce((p: any, c: any) => p + Number(c[`${dailyVolume.field}`]), 0) : undefined; } + if (!hasDailyVolume) { + const fromBlock = await getFromBlock() + const toBlock = await getToBlock(); + try { + const [yesterdayResult, todayResult] = await Promise.all([request(graphUrls[chain], graphQueryTotalVolume, { block: fromBlock }), request(graphUrls[chain], graphQueryTotalVolume, { block: toBlock })]) + const todayVolume = todayResult[totalVolume.factory].reduce((p: any, c: any) => p + Number(c[`${totalVolume.field}`]), 0) + const yesterdayVolume = yesterdayResult[totalVolume.factory].reduce((p: any, c: any) => p + Number(c[`${totalVolume.field}`]), 0) + const volume24H = todayVolume - yesterdayVolume; + dailyVolumeValue = volume24H; + } catch (e: any) { + console.error(`Failed to get daily volume via alternative query on ${graphUrls[chain]} ${chain}: ${wrapGraphError(e).message}`) + } + } return { timestamp: endTimestamp,