forked from DefiLlama/dimension-adapters
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
232 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { FetchOptions, FetchResult, SimpleAdapter } from "../../adapters/types" | ||
import { CHAIN } from "../../helpers/chains" | ||
|
||
const gurar = '0xe521fc2C55AF632cdcC3D69E7EFEd93d56c89015'; | ||
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)[])" | ||
} | ||
|
||
interface IForSwap { | ||
lp: string; | ||
token0: string; | ||
token1: string; | ||
pool_fee: string; | ||
} | ||
|
||
interface ILog { | ||
address: string; | ||
data: string; | ||
transactionHash: string; | ||
topics: string[]; | ||
} | ||
const event_swap = 'event Swap(address indexed sender, address indexed recipient, int256 amount0, int256 amount1, uint160 sqrtPriceX96, uint128 liquidity, int24 tick)' | ||
|
||
const fetch = async (timestamp: number, _: any, { api, getLogs, createBalances, }: FetchOptions): Promise<FetchResult> => { | ||
const dailyVolume = createBalances() | ||
const dailyFees = createBalances() | ||
const chunkSize = 400; | ||
let currentOffset = 965; // Slipstream launched after ~970 v2 pools were already created | ||
const allForSwaps: IForSwap[] = []; | ||
let unfinished = true; | ||
|
||
while (unfinished) { | ||
const forSwaps: IForSwap[] = (await api.call({ | ||
target: gurar, | ||
params: [chunkSize, currentOffset], | ||
abi: abis.forSwaps, | ||
chain: CHAIN.BASE, | ||
})).filter(t => Number(t.type) > 0).map((e: any) => { | ||
return { | ||
lp: e.lp, | ||
token0: e.token0, | ||
token1: e.token1, | ||
pool_fee: e.pool_fee, | ||
} | ||
}) | ||
|
||
unfinished = forSwaps.length !== 0; | ||
currentOffset += chunkSize; | ||
allForSwaps.push(...forSwaps); | ||
} | ||
|
||
const targets = allForSwaps.map((forSwap: IForSwap) => forSwap.lp) | ||
|
||
const logs: ILog[][] = await getLogs({ | ||
targets, | ||
eventAbi: event_swap, | ||
flatten: false, | ||
}) | ||
|
||
logs.forEach((logs: ILog[], idx: number) => { | ||
const { token1, pool_fee } = allForSwaps[idx] | ||
logs.forEach((log: any) => { | ||
dailyVolume.add(token1, BigInt(Math.abs(Number(log.amount1)))) | ||
dailyFees.add(token1, BigInt( Math.round((((Math.abs(Number(log.amount1))) * Number(pool_fee)) / 1000000)))) // 1% fee represented as pool_fee=10000 | ||
}) | ||
}) | ||
|
||
return { dailyVolume, timestamp, dailyFees, dailyRevenue: dailyFees, dailyHoldersRevenue: dailyFees } | ||
} | ||
const adapters: SimpleAdapter = { | ||
adapter: { | ||
[CHAIN.BASE]: { | ||
fetch: fetch as any, | ||
start: 1714743000, | ||
} | ||
} | ||
} | ||
export default adapters; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,27 @@ | ||
import ADDRESSES from '../../helpers/coreAssets.json' | ||
import * as sdk from "@defillama/sdk"; | ||
import { FetchOptions } from '../../adapters/types'; | ||
|
||
const event_notify_reward = 'event NotifyReward(address indexed from,address indexed reward,uint256 indexed epoch,uint256 amount)'; | ||
const event_geuge_created = 'event GaugeCreated(address indexed poolFactory,address indexed votingRewardsFactory,address indexed gaugeFactory,address pool,address bribeVotingReward,address feeVotingReward,address gauge,address creator)' | ||
|
||
const gurar = '0x2073D8035bB2b0F2e85aAF5a8732C6f397F9ff9b'; | ||
|
||
const abis: any = { | ||
"all": "function all(uint256 _limit, uint256 _offset, address _account) view returns ((address lp, string symbol, uint8 decimals, bool stable, uint256 total_supply, address token0, uint256 reserve0, uint256 claimable0, address token1, uint256 reserve1, uint256 claimable1, address gauge, uint256 gauge_total_supply, bool gauge_alive, address fee, address bribe, address factory, uint256 emissions, address emissions_token, uint256 account_balance, uint256 account_earned, uint256 account_staked, uint256 pool_fee, uint256 token0_fees, uint256 token1_fees)[])" | ||
} | ||
|
||
export const fees_bribes = async ({ getLogs, api, createBalances }: FetchOptions)=> { | ||
export const fees_bribes = async ({ getLogs, createBalances, getToBlock }: FetchOptions): Promise<sdk.Balances> => { | ||
const voter = '0x16613524e02ad97eDfeF371bC883F2F5d6C480A5'; | ||
const dailyFees = createBalances() | ||
const bribeVotingReward: string[] = (await api.call({ | ||
target: gurar, | ||
params: [1000, 0, ADDRESSES.null], | ||
abi: abis.all, | ||
})).map((e: any) => { | ||
return e.bribe; | ||
}).filter((e: string) => e !== ADDRESSES.null); | ||
const bribe_contracct = [...new Set(bribeVotingReward)]; | ||
const logs_geuge_created = (await getLogs({ | ||
target: voter, | ||
fromBlock: 3200601, | ||
toBlock: await getToBlock(), | ||
eventAbi: event_geuge_created, | ||
cacheInCloud: true, | ||
})) | ||
const bribes_contract: string[] = logs_geuge_created.map((e: any) => e.bribeVotingReward.toLowerCase()); | ||
|
||
const logs = await getLogs({ | ||
targets: bribe_contracct, | ||
targets: bribes_contract, | ||
eventAbi: event_notify_reward, | ||
}) | ||
logs.map((e: any) => { | ||
dailyFees.add(e.reward, e.amount) | ||
}) | ||
return dailyFees; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters