Skip to content

Commit c88506d

Browse files
committed
add mode and bob
1 parent f524d2a commit c88506d

File tree

5 files changed

+190
-2
lines changed

5 files changed

+190
-2
lines changed

dexs/velodrome/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { FetchOptions, SimpleAdapter } from "../../adapters/types";
22
import { DEFAULT_DAILY_VOLUME_FIELD, DEFAULT_TOTAL_VOLUME_FIELD, getChainVolume } from "../../helpers/getUniSubgraphVolume";
33
import { CHAIN } from "../../helpers/chains";
44
import { Chain } from "@defillama/sdk/build/general";
5+
import { fetchV2Volume } from "./v2"
56

67
const endpoints = {
78
[CHAIN.OPTIMISM]: "https://api.thegraph.com/subgraphs/name/dmihal/velodrome",
@@ -20,6 +21,7 @@ const graphs = getChainVolume({
2021
});
2122

2223

24+
2325
const fetch = (chain: Chain) => {
2426
return async (options: FetchOptions) => {
2527
const [v1] = await Promise.all([graphs(chain)(options)])
@@ -37,6 +39,14 @@ const adapter: SimpleAdapter = {
3739
fetch: fetch(CHAIN.OPTIMISM),
3840
start: 1677110400
3941
},
42+
[CHAIN.MODE]: {
43+
fetch: fetchV2Volume,
44+
start: 1715763701
45+
},
46+
[CHAIN.BOB]: {
47+
fetch: fetchV2Volume,
48+
start: 1715763701
49+
}
4050
},
4151
};
4252

dexs/velodrome/v2.ts

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import { FetchOptions, FetchResult, FetchResultV2, SimpleAdapter } from "../../adapters/types"
2+
import { CHAIN } from "../../helpers/chains"
3+
4+
const sugars = {
5+
[CHAIN.MODE]: "0x207DfB36A449fd10d9c3bA7d75e76290a0c06731",
6+
[CHAIN.BOB]: "0x3e71CCdf495d9628D3655A600Bcad3afF2ddea98"
7+
}
8+
const abis: any = {
9+
"forSwaps": "function forSwaps(uint256 _limit, uint256 _offset) view returns ((address lp, int24 type, address token0, address token1, address factory, uint256 pool_fee)[])"
10+
}
11+
12+
interface IForSwap {
13+
lp: string;
14+
type: string;
15+
token0: string;
16+
token1: string;
17+
pool_fee: string;
18+
}
19+
20+
interface ILog {
21+
address: string;
22+
data: string;
23+
transactionHash: string;
24+
topics: string[];
25+
}
26+
const event_swap = 'event Swap(address indexed sender,address indexed to,uint256 amount0In,uint256 amount1In,uint256 amount0Out,uint256 amount1Out)'
27+
const event_swap_slipstream = 'event Swap(address indexed sender, address indexed recipient, int256 amount0, int256 amount1, uint160 sqrtPriceX96, uint128 liquidity, int24 tick)'
28+
29+
const fetchV2Volume = async ({ api, getLogs, createBalances, chain }: FetchOptions): Promise<FetchResultV2> => {
30+
const dailyVolume = createBalances()
31+
const dailyFees = createBalances()
32+
const chunkSize = 400;
33+
let currentOffset = 0;
34+
const allForSwaps: IForSwap[] = [];
35+
let unfinished = true;
36+
37+
while (unfinished) {
38+
const forSwaps: IForSwap[] = (await api.call({
39+
target: sugars[chain],
40+
params: [chunkSize, currentOffset],
41+
abi: abis.forSwaps,
42+
chain: chain,
43+
})).filter(t => Number(t.type) >= -1).map((e: any) => {
44+
return {
45+
lp: e.lp,
46+
type: e.type,
47+
token0: e.token0,
48+
token1: e.token1,
49+
pool_fee: e.pool_fee,
50+
}
51+
});
52+
53+
unfinished = forSwaps.length !== 0;
54+
currentOffset += chunkSize;
55+
allForSwaps.push(...forSwaps);
56+
}
57+
58+
const targets = allForSwaps.map((forSwap: IForSwap) => forSwap.lp)
59+
60+
const logs: ILog[][] = await getLogs({
61+
targets,
62+
eventAbi: event_swap,
63+
flatten: false,
64+
})
65+
66+
logs.forEach((logs: ILog[], idx: number) => {
67+
const { token0, token1, pool_fee } = allForSwaps[idx]
68+
logs.forEach((log: any) => {
69+
dailyVolume.add(token0, BigInt(Math.abs(Number(log.amount0In))))
70+
dailyVolume.add(token1, BigInt(Math.abs(Number(log.amount1In))))
71+
dailyFees.add(token0, BigInt( Math.round((((Math.abs(Number(log.amount0In))) * Number(pool_fee)) / 10000)))) // 1% fee represented as pool_fee=100
72+
dailyFees.add(token1, BigInt( Math.round((((Math.abs(Number(log.amount1In))) * Number(pool_fee)) / 10000))))
73+
})
74+
})
75+
76+
const slipstreamLogs: ILog[][] = await getLogs({
77+
targets,
78+
eventAbi: event_swap_slipstream,
79+
flatten: false,
80+
})
81+
82+
slipstreamLogs.forEach((logs: ILog[], idx: number) => {
83+
const { token1, pool_fee } = allForSwaps[idx]
84+
logs.forEach((log: any) => {
85+
dailyVolume.add(token1, BigInt(Math.abs(Number(log.amount1))))
86+
dailyFees.add(token1, BigInt( Math.round((((Math.abs(Number(log.amount1))) * Number(pool_fee)) / 1000000)))) // 1% fee represented as pool_fee=10000 for Slipstream
87+
})
88+
})
89+
90+
return { dailyVolume, dailyFees, dailyRevenue: dailyFees, dailyHoldersRevenue: dailyFees }
91+
}
92+
93+
export {
94+
fetchV2Volume
95+
}

fees/velodrome/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Adapter, FetchOptions, FetchResultFees } from '../../adapters/types';
2-
import { OPTIMISM } from '../../helpers/chains';
2+
import { CHAIN, OPTIMISM } from '../../helpers/chains';
33
import { fetchV1 } from './velodrome';
4+
import { fetchFees } from "./v2"
45

56

67
const getFees = async (options: FetchOptions) => {
@@ -22,6 +23,14 @@ const adapter: Adapter = {
2223
fetch: getFees,
2324
start: 1677110400, // TODO: Add accurate timestamp
2425
},
26+
[CHAIN.MODE]: {
27+
fetch: fetchFees,
28+
start: 1715763701
29+
},
30+
[CHAIN.BOB]: {
31+
fetch: fetchFees,
32+
start: 1715763701
33+
}
2534
},
2635
};
2736
export default adapter;

fees/velodrome/v2.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { Balances } from "@defillama/sdk";
2+
import { FetchOptions, FetchResultFees } from "../../adapters/types";
3+
import { CHAIN } from "../../helpers/chains";
4+
import { getDexFees } from "../../helpers/dexVolumeLogs";
5+
6+
const event_notify_reward = 'event NotifyReward(address indexed from,uint256 amount)';
7+
const event_geuge_created = 'event StakingRewardsCreated(address indexed pool,address indexed rewardToken,address indexed stakingRewards,address creator)'
8+
9+
const abis: any = {
10+
"forSwaps": "function forSwaps(uint256 _limit, uint256 _offset) view returns ((address lp, int24 type, address token0, address token1, address factory, uint256 pool_fee)[])"
11+
}
12+
const sugars: any = {
13+
[CHAIN.MODE]: "0x207DfB36A449fd10d9c3bA7d75e76290a0c06731",
14+
[CHAIN.BOB]: "0x3e71CCdf495d9628D3655A600Bcad3afF2ddea98"
15+
}
16+
17+
const stakingRewards = {
18+
[CHAIN.MODE]: "0xD2F998a46e4d9Dd57aF1a28EBa8C34E7dD3851D7",
19+
[CHAIN.BOB]: "0x8Eb6838B4e998DA08aab851F3d42076f21530389"
20+
}
21+
const rewardTokens = {
22+
[CHAIN.MODE]: "0xDfc7C877a950e49D2610114102175A06C2e3167a",
23+
[CHAIN.BOB]: "0x4200000000000000000000000000000000000006"
24+
}
25+
26+
export const fees_bribes = async ({ getLogs, createBalances, getToBlock, chain }: FetchOptions): Promise<Balances> => {
27+
const stakingRewardsFactory = stakingRewards[chain] ;
28+
const rewardToken = rewardTokens[chain];
29+
const dailyFees = createBalances()
30+
const logs_geuge_created = (await getLogs({
31+
target: stakingRewardsFactory,
32+
fromBlock: 7797181,
33+
toBlock: await getToBlock(),
34+
eventAbi: event_geuge_created,
35+
}))
36+
const bribes_contract: string[] = logs_geuge_created.map((e: any) => e.stakingRewards.toLowerCase());
37+
if (bribes_contract.length === 0) {
38+
return dailyFees;
39+
}
40+
const logs = await getLogs({
41+
targets: bribes_contract,
42+
eventAbi: event_notify_reward,
43+
})
44+
logs.map((e: any) => {
45+
dailyFees.add(rewardToken, e.amount)
46+
})
47+
return dailyFees;
48+
}
49+
50+
const fetchFees = async (options: FetchOptions): Promise<FetchResultFees> => {
51+
const chunkSize = 500;
52+
let currentOffset = 0;
53+
let unfinished = true;
54+
const allPools: any[] = [];
55+
56+
if (options.startOfDay > 1715763701) { // Sugar pools data helper contract created at this timestamp
57+
while (unfinished) {
58+
const allPoolsChunk = await options.api.call({ target: sugars[options.chain], abi: abis.forSwaps, params: [chunkSize, currentOffset], chain: options.chain})
59+
unfinished = allPoolsChunk.length !== 0;
60+
currentOffset += chunkSize;
61+
allPools.push(...allPoolsChunk);
62+
}
63+
}
64+
65+
const pools = allPools.map((e: any) => e.lp)
66+
const res: any = await getDexFees({ chain: options.chain, fromTimestamp: options.fromTimestamp, toTimestamp: options.toTimestamp, pools, timestamp: options.startOfDay, fetchOptions: options })
67+
res.dailyBribesRevenue = await fees_bribes(options);
68+
return res;
69+
}
70+
71+
export {
72+
fetchFees
73+
}

helpers/chains.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ export enum CHAIN {
149149
BITLAYER = "bitlayer",
150150
XLAYER = "xlayer",
151151
MERLIN = "merlin",
152-
CHILIZ = "chiliz"
152+
CHILIZ = "chiliz",
153+
BOB = "bob",
153154
}
154155

155156
// Don´t use

0 commit comments

Comments
 (0)