Skip to content

Commit

Permalink
fix get diff total value
Browse files Browse the repository at this point in the history
  • Loading branch information
dtmkeng committed Mar 14, 2024
1 parent 83f6dde commit 8722835
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
3 changes: 1 addition & 2 deletions dexs/balancer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 0 additions & 2 deletions dexs/clipper/index.ts
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -33,7 +32,6 @@ const adapter: SimpleAdapter = {
[chain]: {
fetch: graphs(chain as Chain),
start: 1657437036,
customBackfill: customBackfill(chain, graphs),
}
}
}, {})
Expand Down
5 changes: 3 additions & 2 deletions helpers/customBackfill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<FetchResultGeneric> => {
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
Expand All @@ -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
Expand Down
15 changes: 14 additions & 1 deletion helpers/getUniSubgraphVolume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 8722835

Please sign in to comment.