Skip to content

Commit

Permalink
feat: add velo superchain bribes, volume/fees
Browse files Browse the repository at this point in the history
  • Loading branch information
ethzoomer committed Jan 15, 2025
1 parent 5468349 commit 6db8148
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 17 deletions.
52 changes: 47 additions & 5 deletions dexs/velodrome-slipstream/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,34 @@ import { FetchOptions, FetchResultV2, SimpleAdapter } from "../../adapters/types
import { CHAIN } from "../../helpers/chains";

const sugarOld = '0x3e532BC1998584fe18e357B5187897ad0110ED3A'; // old Sugar version doesn't properly support pagination
const sugar = '0xdE2aE25FB984dd60C77dcF6489Be9ee6438eC195';
const abis: any = {
"forSwaps": "function forSwaps(uint256 _limit, uint256 _offset) view returns ((address lp, int24 type, address token0, address token1, address factory, uint256 pool_fee)[])"
}

const superchainConfig = {
[CHAIN.OPTIMISM]: {
sugar: '0xdE2aE25FB984dd60C77dcF6489Be9ee6438eC195',
},
[CHAIN.MODE]: {
sugar: '0x8A5e97184E8850064805fAc2427ce7728689De5B',
},
[CHAIN.LISK]: {
sugar: '0x0F5B7D59690F99f34081E24557f022d06d580BB6',
},
[CHAIN.INK]: {
sugar: '0xD938B20f40505e33b7C131e6aDD6C6FF7380094A',
},
[CHAIN.SONEIUM]: {
sugar: '0xB1d0DFFe6260982164B53EdAcD3ccd58B081889d',
},
[CHAIN.FRAXTAL]: {
sugar: '0xB1d0DFFe6260982164B53EdAcD3ccd58B081889d',
}
}

interface IForSwap {
lp: string;
type: number;
token0: string;
token1: string;
pool_fee: string;
Expand All @@ -29,10 +50,10 @@ const fetch = async (options: FetchOptions): Promise<FetchResultV2> => {
let currentOffset = 0;
const allForSwaps: IForSwap[] = [];
let unfinished = true;
let sugarContract = sugar;
let sugarContract = superchainConfig[options.chain]['sugar'];

// before the new Sugar is deployed, we must use the old Sugar contract, and make one large Sugar call
if (options.startOfDay < 1715160600) {
if (options.chain === CHAIN.OPTIMISM && options.startOfDay < 1715160600) {
chunkSize = 1800;
sugarContract = sugarOld;
}
Expand All @@ -42,12 +63,13 @@ const fetch = async (options: FetchOptions): Promise<FetchResultV2> => {
target: sugarContract,
params: [chunkSize, currentOffset],
abi: abis.forSwaps,
chain: CHAIN.OPTIMISM,
chain: options.chain,
}));

const forSwaps: IForSwap[] = forSwapsUnfiltered.filter(t => Number(t.type) > 0).map((e: any) => {
return {
lp: e.lp,
type: e.type,
token0: e.token0,
token1: e.token1,
pool_fee: e.pool_fee,
Expand Down Expand Up @@ -99,7 +121,27 @@ const adapters: SimpleAdapter = {
[CHAIN.OPTIMISM]: {
fetch: fetch as any,
start: '2024-03-06',
}
},
[CHAIN.MODE]: {
fetch: fetch as any,
start: '2024-11-13',
},
[CHAIN.LISK]: {
fetch: fetch as any,
start: '2024-11-13',
},
[CHAIN.FRAXTAL]: {
fetch: fetch as any,
start: '2024-11-19',
},
// [CHAIN.INK]: {
// fetch: fetch as any,
// start: '2025-01-14',
// },
// [CHAIN.SONEIUM]: {
// fetch: fetch as any,
// start: '2025-01-14',
// },
}
}
export default adapters;
5 changes: 5 additions & 0 deletions dexs/velodrome-v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ const swapEvent = 'event Swap(address indexed sender, address indexed to, uint25

export default uniV2Exports({
[CHAIN.OPTIMISM]: { factory: '0xF1046053aa5682b4F9a81b5481394DA16BE5FF5a', swapEvent, },
[CHAIN.MODE]: { factory: '0x31832f2a97Fd20664D76Cc421207669b55CE4BC0', swapEvent, },
[CHAIN.LISK]: { factory: '0x31832f2a97Fd20664D76Cc421207669b55CE4BC0', swapEvent, },
[CHAIN.FRAXTAL]: { factory: '0x31832f2a97Fd20664D76Cc421207669b55CE4BC0', swapEvent, },
//[CHAIN.INK]: { factory: '0x31832f2a97Fd20664D76Cc421207669b55CE4BC0', swapEvent, },
//[CHAIN.SONEIUM]: { factory: '0x31832f2a97Fd20664D76Cc421207669b55CE4BC0', swapEvent, },
})
64 changes: 52 additions & 12 deletions fees/velodrome-v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const notifyRewardEvent = 'event NotifyReward(address indexed from,uint256 amoun

const event_notify_reward_op = 'event NotifyReward(address indexed from,address indexed reward,uint256 indexed epoch,uint256 amount)';
const event_gauge_created = 'event GaugeCreated(address indexed poolFactory,address indexed votingRewardsFactory,address indexed gaugeFactory,address pool,address bribeVotingReward,address feeVotingReward,address gauge,address creator)'
const leaf_gauge_created = 'event GaugeCreated(address indexed poolFactory,address indexed votingRewardsFactory,address indexed gaugeFactory,address pool,address incentiveVotingReward,address feeVotingReward,address gauge)'
const leaf_voter = '0x97cDBCe21B6fd0585d29E539B1B99dAd328a1123'
const leaf_pool_factory = '0x31832f2a97Fd20664D76Cc421207669b55CE4BC0'

const config = {
[CHAIN.MODE]: {
Expand All @@ -18,13 +21,32 @@ const config = {
}
}

const superchainConfig = {
[CHAIN.MODE]: {
start_block: 15405187,
},
[CHAIN.LISK]: {
start_block: 8339180,
},
[CHAIN.INK]: {
start_block: 3448692,
},
[CHAIN.SONEIUM]: {
start_block: 1906595,
},
[CHAIN.FRAXTAL]: {
start_block: 12603117,
}
}


const customLogic = async ({ dailyFees, fetchOptions, filteredPairs, }: any) => {
const { createBalances, getLogs, chain, api, getToBlock, } = fetchOptions
const dailyBribes = createBalances()

// handle native OP Mainnet bribes
if (chain === CHAIN.OPTIMISM) {
let voter = '0x41C914ee0c7E1A5edCD0295623e6dC557B5aBf3C'
const dailyBribes = createBalances()
const logs_gauge_created = (await getLogs({
target: voter,
fromBlock: 105896852,
Expand All @@ -41,30 +63,48 @@ const customLogic = async ({ dailyFees, fetchOptions, filteredPairs, }: any) =>
logs.map((e: any) => {
dailyBribes.add(e.reward, e.amount)
})

return { dailyBribesRevenue: dailyBribes } as any
}
else {
// handle Superchain beta "staking rewards" bribes on Mode and Bob
if (chain in config) {
const { stakingRewards, rewardToken, } = config[chain]
const pairs = Object.keys(filteredPairs)
const gauges = await api.multiCall({ target: stakingRewards, abi: 'function gauges(address) view returns (address)', calls: pairs })
const dailyBribesRevenue = createBalances()
let logs = await getLogs({ targets: gauges, eventAbi: notifyRewardEvent })

logs.forEach(log => {
dailyBribesRevenue.add(rewardToken, log.amount)
dailyBribes.add(rewardToken, log.amount)
})
}

// handle Superchain 1.0 L2 bribes
if (chain in superchainConfig) {
const leaf_gauge_logs = (await getLogs({
target: leaf_voter,
fromBlock: superchainConfig[chain]['start_block'],
toBlock: await getToBlock(),
eventAbi: leaf_gauge_created,
cacheInCloud: true,
}))
const incentive_contracts: string[] = leaf_gauge_logs.map((e: any) => e.incentiveVotingReward.toLowerCase());

let logs = await getLogs({
targets: incentive_contracts,
eventAbi: event_notify_reward_op,
})
logs.map((e: any) => {
dailyBribes.add(e.reward, e.amount)
})
return {
dailyFees,
dailyRevenue: dailyFees,
dailyHoldersRevenue: dailyFees,
dailyBribesRevenue,
};
}

return { dailyBribesRevenue: dailyBribes } as any
}

export default uniV2Exports({
[CHAIN.OPTIMISM]: { factory: '0xF1046053aa5682b4F9a81b5481394DA16BE5FF5a', swapEvent, voter: '0x41c914ee0c7e1a5edcd0295623e6dc557b5abf3c', maxPairSize: 500, customLogic, },
[CHAIN.MODE]: { factory: '0x31832f2a97Fd20664D76Cc421207669b55CE4BC0', customLogic },
[CHAIN.BOB]: { factory: '0x31832f2a97Fd20664D76Cc421207669b55CE4BC0', swapEvent, customLogic, },
[CHAIN.LISK]: {factory: leaf_pool_factory, customLogic},
[CHAIN.FRAXTAL]: {factory: leaf_pool_factory, customLogic},
//[CHAIN.INK]: {factory: leaf_pool_factory, customLogic},
//[CHAIN.SONEIUM]: {factory: leaf_pool_factory, customLogic},
})

0 comments on commit 6db8148

Please sign in to comment.