|
| 1 | +import { FetchOptions, SimpleAdapter } from '../../adapters/types'; |
| 2 | +import { CHAIN } from '../../helpers/chains'; |
| 3 | + |
| 4 | +const ACCOUNTING = '0xa436c5Dd1Ba62c55D112C10cd10E988bb3355102'; |
| 5 | +const USDE = '0x4c9EDD5852cd905f086C759E8383e09bff1E68B3'; |
| 6 | + |
| 7 | +const FEE_ACCRUED_EVENT = "event FeeAccrued(bool isJrt, uint256 amountToReserve, uint256 amountToTranche)"; |
| 8 | + |
| 9 | +const fetch = async (options: FetchOptions) => { |
| 10 | + const dailyFees = options.createBalances(); |
| 11 | + const dailyRevenue = options.createBalances(); |
| 12 | + const dailyProtocolRevenue = options.createBalances(); |
| 13 | + const dailySupplySideRevenue = options.createBalances(); |
| 14 | + |
| 15 | + const [startBlock, endBlock] = await Promise.all([ |
| 16 | + options.getStartBlock(), |
| 17 | + options.getEndBlock(), |
| 18 | + ]); |
| 19 | + |
| 20 | + let totalAmountToReserve = 0; |
| 21 | + let totalExitFees = 0; |
| 22 | + let performanceFees = 0; |
| 23 | + |
| 24 | + // Get NAV and reserveBps |
| 25 | + const [navT0, navT1, reserveBps] = await Promise.all([ |
| 26 | + options.api.call({ |
| 27 | + target: ACCOUNTING, |
| 28 | + abi: "function nav() view returns (uint256)", |
| 29 | + block: startBlock, |
| 30 | + }), |
| 31 | + options.api.call({ |
| 32 | + target: ACCOUNTING, |
| 33 | + abi: "function nav() view returns (uint256)", |
| 34 | + block: endBlock, |
| 35 | + }), |
| 36 | + options.api.call({ |
| 37 | + target: ACCOUNTING, |
| 38 | + abi: "function reserveBps() view returns (uint256)", |
| 39 | + block: endBlock, |
| 40 | + }), |
| 41 | + ]); |
| 42 | + |
| 43 | + // Calculate NAV change (gains/losses) |
| 44 | + const navGrowth = Number(navT1) - Number(navT0); |
| 45 | + |
| 46 | + // Calculate performance fees from gains (only if there are gains) |
| 47 | + if (navGrowth > 0 && reserveBps > 0) { |
| 48 | + // Reserve gets a portion of gains: gain * reserveBps / 1e18 |
| 49 | + performanceFees = Number(navGrowth * reserveBps / 1e18); |
| 50 | + } |
| 51 | + const logs = await options.getLogs({ |
| 52 | + target: ACCOUNTING, |
| 53 | + eventAbi: FEE_ACCRUED_EVENT, |
| 54 | + }); |
| 55 | + logs.forEach((log: any) => { |
| 56 | + const amountToReserve = log.amountToReserve; |
| 57 | + const amountToTranche = log.amountToTranche; |
| 58 | + const totalFee = Number(amountToReserve) + Number(amountToTranche); |
| 59 | + totalExitFees += Number(totalFee); |
| 60 | + totalAmountToReserve += Number(amountToReserve); |
| 61 | + }); |
| 62 | + |
| 63 | + // Calculate fee distribution |
| 64 | + const trancheFees = totalExitFees - totalAmountToReserve; |
| 65 | + const protocolRevenue = totalAmountToReserve + performanceFees; |
| 66 | + const totalFees = totalExitFees + performanceFees; |
| 67 | + |
| 68 | + dailyFees.add(USDE, totalFees); |
| 69 | + dailyRevenue.add(USDE, protocolRevenue); |
| 70 | + dailyProtocolRevenue.add(USDE, protocolRevenue); |
| 71 | + dailySupplySideRevenue.add(USDE, Number(trancheFees)); |
| 72 | + |
| 73 | + return { |
| 74 | + dailyFees, |
| 75 | + dailyRevenue, |
| 76 | + dailyProtocolRevenue, |
| 77 | + dailySupplySideRevenue, |
| 78 | + } |
| 79 | +}; |
| 80 | + |
| 81 | +const methodology = { |
| 82 | + Fees: "Includes performance fees (5% of yield generated from pooled collateral) and redemption fees.", |
| 83 | + Revenue: "Protocol treasury receives performance fees and a portion of redemption fees.", |
| 84 | + ProtocolRevenue: "Protocol treasury receives performance fees and a portion of redemption fees.", |
| 85 | + SupplySideRevenue: "Redemption fees distributed to senior and junior tranche holders." |
| 86 | +} |
| 87 | + |
| 88 | +const adapter: SimpleAdapter = { |
| 89 | + version: 2, |
| 90 | + fetch, |
| 91 | + chains: [CHAIN.ETHEREUM], |
| 92 | + start: '2025-10-05', |
| 93 | + methodology, |
| 94 | +} |
| 95 | + |
| 96 | +export default adapter; |
0 commit comments