Skip to content

Commit

Permalink
Merge pull request #1747 from jaimi-io/update-dexalot-volumes
Browse files Browse the repository at this point in the history
Add Dexalot chain volumes to dexalot
  • Loading branch information
dtmkeng committed Aug 7, 2024
2 parents ae4b3a8 + 79897db commit 238e3ec
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 26 deletions.
77 changes: 51 additions & 26 deletions dexs/dexalot/index.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,68 @@
import { FetchOptions, SimpleAdapter } from "../../adapters/types";
import { BaseAdapter, FetchOptions, FetchResultV2, SimpleAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import { httpGet } from "../../utils/fetchURL";

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

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

const address: any = {
[CHAIN.ARBITRUM]: "0x010224949cCa211Fb5dDfEDD28Dc8Bf9D2990368",
[CHAIN.AVAX]: "0xEed3c159F3A96aB8d41c8B9cA49EE1e5071A7cdD"
const supportedChains = [CHAIN.DEXALOT, CHAIN.AVAX, CHAIN.ARBITRUM, CHAIN.BASE]

const chainToEnv = (chain: CHAIN) => {
switch (chain) {
case CHAIN.AVAX:
return "production-multi-avax"
case CHAIN.ARBITRUM:
return "production-multi-arb"
case CHAIN.BASE:
return "production-multi-base"
default:
return "production-multi-subnet"
}
}

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 fetchFromChain = (chain: CHAIN) => {
const endpoint = `${historicalVolumeEndpoint}?env=${chainToEnv(chain)}`

return async (options: FetchOptions): Promise<FetchResultV2> => {
const dayTimestamp = new Date(options.startOfDay * 1000)
const historicalVolume: IVolumeall[] = await httpGet(endpoint)

const totalVolume = historicalVolume
.filter(volItem => new Date(volItem.date) <= dayTimestamp)
.reduce((acc, { volumeusd }) => acc + Number(volumeusd), 0)
const dailyVolume = historicalVolume
.find(dayItem => new Date(dayItem.date) === dayTimestamp)?.volumeusd

return {
totalVolume: `${totalVolume}`,
dailyVolume: dailyVolume ? `${dailyVolume}` : undefined,
};
}
};

const getStartTimestamp = (chain: CHAIN) => {
const endpoint = `${historicalVolumeEndpoint}?env=${chainToEnv(chain)}`
return async () => {
const historicalVolume: IVolumeall[] = await httpGet(endpoint)
return (new Date(historicalVolume[0].date).getTime()) / 1000
}
}

const adapter: SimpleAdapter = {
version: 2,
adapter: {
[CHAIN.AVAX]: {
fetch: fetch,
start: 0,
},
[CHAIN.ARBITRUM]: {
fetch: fetch,
start: 0,
},
},
adapter: supportedChains.reduce((acc, chain) => {
return {
...acc,
[chain]: {
fetch: fetchFromChain(chain),
start: getStartTimestamp(chain),
}
}
}, {} as BaseAdapter),
};

export default adapter;
1 change: 1 addition & 0 deletions helpers/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export enum CHAIN {
SKALE_EUROPA = "skale_europa",
IOTAEVM = "iotaevm",
ZKLINK = "zklink",
DEXALOT = "dexalot",
}

// Don´t use
Expand Down

0 comments on commit 238e3ec

Please sign in to comment.