Skip to content

Commit

Permalink
Merge pull request #1659 from DefiLlama/split-dexalot
Browse files Browse the repository at this point in the history
split dexalot by chaib
  • Loading branch information
dtmkeng committed Jul 9, 2024
2 parents 3551c52 + 9a96aea commit 0f09692
Showing 1 changed file with 24 additions and 32 deletions.
56 changes: 24 additions & 32 deletions dexs/dexalot/index.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,41 @@
import { Chain } from "@defillama/sdk/build/general";
import { SimpleAdapter } from "../../adapters/types";
import { FetchOptions, SimpleAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import customBackfill from "../../helpers/customBackfill";
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";
import { httpGet } from "../../utils/fetchURL";

const historicalVolumeEndpoint = "https://api.dexalot.com/api/stats/dailyvolumes"

interface IVolumeall {
volumeusd: string;
date: number;
}

const fetch = async (timestamp: number) => {
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000))
const historicalVolume: IVolumeall[] = (await httpGet(historicalVolumeEndpoint, { headers: {
'origin': 'https://app.dexalot.com'
}}))
const totalVolume = historicalVolume
.filter(volItem => (new Date(volItem.date).getTime() / 1000) <= dayTimestamp)
.reduce((acc, { volumeusd }) => acc + Number(volumeusd), 0)

const dailyVolume = historicalVolume
.find(dayItem => (new Date(dayItem.date).getTime() / 1000) === dayTimestamp)?.volumeusd
const address: any = {
[CHAIN.ARBITRUM]: "0x010224949cCa211Fb5dDfEDD28Dc8Bf9D2990368",
[CHAIN.AVAX]: "0xEed3c159F3A96aB8d41c8B9cA49EE1e5071A7cdD"
}

return {
totalVolume: `${totalVolume}`,
dailyVolume: dailyVolume ? `${dailyVolume}` : undefined,
timestamp: dayTimestamp,
};
const event = "event SwapExecuted(uint256 indexed nonceAndMeta,address taker,address destTrader,uint256 destChainId,address srcAsset,address destAsset,uint256 srcAmount,uint256 destAmount)"

const fetch = async (options: FetchOptions) => {
const dailyVolume = options.createBalances();
const logs = await options.getLogs({
target: address[options.chain],
eventAbi: event
})
logs.forEach(log => {
dailyVolume.add(log.destAsset, log.destAmount)
})
return { dailyVolume }
};

const getStartTimestamp = async () => {
const historicalVolume: IVolumeall[] = (await httpGet(historicalVolumeEndpoint, { headers: {
'origin': 'https://app.dexalot.com'
}}))
return (new Date(historicalVolume[0].date).getTime()) / 1000
}

const adapter: SimpleAdapter = {
version: 2,
adapter: {
[CHAIN.AVAX]: {
fetch,
start: getStartTimestamp,
customBackfill: customBackfill(CHAIN.AVAX as Chain, (_chian: string) => fetch)
fetch: fetch,
start: 0,
},
[CHAIN.ARBITRUM]: {
fetch: fetch,
start: 0,
},
},
};
Expand Down

0 comments on commit 0f09692

Please sign in to comment.