|
| 1 | +import { FetchOptions, SimpleAdapter } from "../../adapters/types"; |
| 2 | +import { CHAIN } from "../../helpers/chains"; |
| 3 | +import ADDRESSES from "../../helpers/coreAssets.json"; |
| 4 | +import { ethers } from "ethers"; |
| 5 | + |
| 6 | +// Configuration |
| 7 | +const CONFIG = { |
| 8 | + TOKENS: { |
| 9 | + USDN: "0xde17a000ba631c5d7c2bd9fb692efea52d90dee2", |
| 10 | + WSTETH: ADDRESSES.ethereum.WSTETH, |
| 11 | + }, |
| 12 | + CONTRACTS: { |
| 13 | + USDN: "0x656cb8c6d154aad29d8771384089be5b5141f01a", |
| 14 | + DIP_ACCUMULATOR: "0xaebcc85a5594e687f6b302405e6e92d616826e03", |
| 15 | + }, |
| 16 | +}; |
| 17 | + |
| 18 | +// ABIs |
| 19 | +const usdnAbi = { |
| 20 | + vaultDepositEvent: "event ValidatedDeposit(address indexed to, address indexed validator, uint256 amountAfterFees, uint256 usdnMinted, uint256 timestamp)", |
| 21 | + vaultWithdrawalEvent: "event ValidatedWithdrawal(address indexed to, address indexed validator, uint256 amountWithdrawnAfterFees, uint256 usdnBurned, uint256 timestamp)", |
| 22 | + longOpenPositionEvent: "event InitiatedOpenPosition(address indexed owner, address indexed validator, uint40 timestamp, uint128 totalExpo, uint128 amount, uint128 startPrice, tuple(int24 tick, uint256 tickVersion, uint256 index) posId)", |
| 23 | + longClosePositionEvent: "event ValidatedClosePosition(address indexed validator, address indexed to, tuple(int24 tick, uint256 tickVersion, uint256 index) posId, uint256 amountReceived, int256 profit)", |
| 24 | + rebalancerDepositEvent: "event AssetsDeposited(address indexed user, uint256 amount, uint256 positionVersion)", |
| 25 | + rebalancerWithdrawalEvent: "event AssetsWithdrawn(address indexed user, address indexed to, uint256 amount)", |
| 26 | + liquidatedTickEvent: "event LiquidatedTick(int24 indexed tick, uint256 indexed oldTickVersion, uint256 liquidationPrice, uint256 effectiveTickPrice, int256 remainingCollateral)", |
| 27 | + liquidatorRewarded: "event LiquidatorRewarded (address indexed liquidator, uint256 rewards)", |
| 28 | +}; |
| 29 | + |
| 30 | +const eventConfigs = [ |
| 31 | + { |
| 32 | + abi: usdnAbi.longOpenPositionEvent, |
| 33 | + token: CONFIG.TOKENS.WSTETH, |
| 34 | + valueIndex: 4, |
| 35 | + contract: CONFIG.CONTRACTS.USDN, |
| 36 | + }, |
| 37 | + { |
| 38 | + abi: usdnAbi.longClosePositionEvent, |
| 39 | + token: CONFIG.TOKENS.WSTETH, |
| 40 | + valueIndex: 3, |
| 41 | + contract: CONFIG.CONTRACTS.USDN, |
| 42 | + }, |
| 43 | +]; |
| 44 | + |
| 45 | +const fetch = async (options: FetchOptions) => { |
| 46 | + const dailyVolume = options.createBalances(); |
| 47 | + |
| 48 | + for (const config of eventConfigs) { |
| 49 | + const logs = await options.getLogs({ |
| 50 | + eventAbi: config.abi, |
| 51 | + target: config.contract, |
| 52 | + entireLog: true, |
| 53 | + }); |
| 54 | + |
| 55 | + const iface = new ethers.Interface([config.abi]); |
| 56 | + for (const log of logs) { |
| 57 | + const parsedLog = iface.parseLog(log) |
| 58 | + const valueDecoded = parsedLog!.args[config.valueIndex] as bigint; |
| 59 | + dailyVolume.add(config.token, Number(valueDecoded)); |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + return { |
| 64 | + dailyVolume |
| 65 | + }; |
| 66 | +}; |
| 67 | + |
| 68 | +const adapter: SimpleAdapter = { |
| 69 | + version: 2, |
| 70 | + adapter: { |
| 71 | + [CHAIN.ETHEREUM]: { |
| 72 | + fetch, |
| 73 | + start: '2025-01-22', |
| 74 | + }, |
| 75 | + }, |
| 76 | +}; |
| 77 | + |
| 78 | +export default adapter; |
0 commit comments