Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for base volume, backfill fix #2081

Merged
merged 4 commits into from
Nov 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 66 additions & 34 deletions dexs/nabla/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,32 @@ import { CHAIN } from "../../helpers/chains";
const config = {
[CHAIN.ARBITRUM]: {
registry: "0xcB94Eee869a2041F3B44da423F78134aFb6b676B",
backfill: {
routers : ["0x7bcFc8b8ff61456ad7C5E2be8517D01df006d18d"],
pools : [
"0xE70292D6054B753214D555930e0F11CD7206Efeb",
"0x058a0875DB2168AF97bbf01043C3e8F751cCd9A8",
"0xcC5544C63392952B6f94a695f8f9e153F4284A87",
"0x411eF79fE9Df8Ba82A09c7e93FdE85AF5732BF12",
"0x272dF896f4D0c97F65e787f861bb6e882776a155"
],
assets : [
"0x912ce59144191c1204e64559fe8253a0e49e6548",
"0xaf88d065e77c8cc2239327c5edb3a432268e5831",
"0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9",
"0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f",
"0x82af49447d8a07e3bd95bd0d56f35241523fbab1"
],
}
},
// [CHAIN.BASE]: {
// registry: "0xcB94Eee869a2041F3B44da423F78134aFb6b676B",
// }
[CHAIN.BASE]: {
registry: "0xd24d145f5E351de52934A7E1f8cF55b907E67fFF",
backfill: {
routers : ["0x791Fee7b66ABeF59630943194aF17B029c6F487B"],
pools : ["0xa83a20F4dCaB1a63a9118E9E432932c8BEB39b85", "0x123456C6C27bb57013F4b943A0f032a0ab9c12eB"],
assets : ["0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf", "0x4200000000000000000000000000000000000006"],
}
}
}

const abis = {
Expand All @@ -32,27 +54,21 @@ const methodology = {
Fees: "All fees comes from the user."
}

function addToBalances(balances: any, token: any, amount: any) {
if (!balances[token]) {
balances[token] = 0
}
balances[token] += amount
}

export default {
adapter: {
[CHAIN.ARBITRUM]: {
fetch: (async ({ getLogs, createBalances, api}) => {
const {registry} = config[CHAIN.ARBITRUM];
const routers = await api.call({abi: abis.portal.routers, target: registry, block: "latest"})
async function getAddresses(chain, api) {
const {registry} = config[chain];
let routers;
let pools;
let assets;
try {
routers = await api.call({abi: abis.portal.routers, target: registry, block: "latest"});
const assetsResponse = await api.multiCall({
abi: abis.portal.routerAssets,
calls: routers.map((router: any) => ({
target: registry,
params: router
}))
});
const assets = assetsResponse.reduce((acc, a: any[]) => [...acc,...a], [])
assets = assetsResponse.reduce((acc, a: any[]) => [...acc,...a], [])
const poolsCalls: any[] = [];
routers.forEach((router: any, i) => {
assetsResponse[i].forEach((asset: any) => {
Expand All @@ -62,12 +78,26 @@ export default {
})
});
});
const pools = await api.multiCall({
pools = await api.multiCall({
abi: abis.router.poolByAsset,
calls: poolsCalls
});

} catch (e) {
routers = config[chain].backfill.routers;
pools = config[chain].backfill.pools;
assets = config[chain].backfill.assets;

}
return {routers, pools, assets}
}

export default {
adapter: {
[CHAIN.ARBITRUM]: {
fetch: (async ({ getLogs, createBalances, api}) => {
const {routers, pools, assets} = await getAddresses(CHAIN.ARBITRUM, api)


const dailyVolume = createBalances()
const volumeLogs = await Promise.all(routers.map(router => getLogs({
Expand Down Expand Up @@ -105,38 +135,40 @@ export default {
start: '2024-08-15',
},
[CHAIN.BASE]: {
fetch: (async ({ getLogs, createBalances}) => {
fetch: (async ({ getLogs, createBalances, api}) => {

const router = "0x791Fee7b66ABeF59630943194aF17B029c6F487B";
const pools = ["0xa83a20F4dCaB1a63a9118E9E432932c8BEB39b85", "0x123456C6C27bb57013F4b943A0f032a0ab9c12eB"];
const assets = ["0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf", "0x4200000000000000000000000000000000000006"];
const {routers, pools, assets} = await getAddresses(CHAIN.BASE, api)

const dailyVolume = createBalances()
const volumeLogs = await getLogs({
const volumeLogs = await Promise.all(routers.map(router => getLogs({
target: router,
eventAbi: abis.router.swapEvent
});
})
));

volumeLogs.forEach((e, i) => {
dailyVolume.add(e.tokenIn, e.amountIn)
volumeLogs.forEach((logs, i) => {
logs.forEach((e: any) => {
dailyVolume.add(e.tokenOut, e.amountOut)
})
})

const dailyFees = createBalances()
const dailyUserFees = createBalances()
const dailyRevenue = createBalances()
const dailyProtocolRevenue = createBalances()
const logs = await Promise.all(pools.map(pool => getLogs({
target: pool,
eventAbi: abis.swapPool.chargedSwapFeesEvent
})
target: pool,
eventAbi: abis.swapPool.chargedSwapFeesEvent
})
));
logs.forEach((log, i) => {
log.forEach((e: any) => {
dailyFees.add(assets[i], e.lpFees+e.backstopFees+e.protocolFees)
dailyUserFees.add(assets[i], e.lpFees+e.backstopFees+e.protocolFees)
dailyRevenue.add(assets[i], e.protocolFees)
dailyFees.add(assets[i], e.lpFees+e.backstopFees+e.protocolFees)
dailyUserFees.add(assets[i], e.lpFees+e.backstopFees+e.protocolFees)
dailyProtocolRevenue.add(assets[i], e.protocolFees)

})
})
return { dailyFees, dailyRevenue, dailyUserFees, dailyVolume }
return { dailyFees, dailyProtocolRevenue, dailyUserFees, dailyVolume }
}) as FetchV2,
start: '2024-09-12',
meta: {
Expand Down
Loading