diff --git a/fees/moneyfi/index.ts b/fees/moneyfi/index.ts index 02a0da15b3..fd22068ca1 100644 --- a/fees/moneyfi/index.ts +++ b/fees/moneyfi/index.ts @@ -3,85 +3,141 @@ import { CHAIN } from "../../helpers/chains"; import fetchURL from "../../utils/fetchURL"; const CHAINS_CONFIG: Record = { + [CHAIN.ETHEREUM]: { contracts: [ - { address: "0x6Df81526F93cd5C66B2B509baeB91bDB832C9a85", decimals: 6 }, - { address: "0x5FD182547BDAbd26e2e2465c5602B0Ec99180cdd", decimals: 6 }, + { + address: "0x6Df81526F93cd5C66B2B509baeB91bDB832C9a85", + decimals: 6, + }, + { + address: "0x5FD182547BDAbd26e2e2465c5602B0Ec99180cdd", + decimals: 6, + }, ], }, [CHAIN.BASE]: { contracts: [ - { address: "0x201E3c8BCcBB6e23710fEdAB9a28E806ef3240eb", decimals: 6 }, - { address: "0x2DF1200660Fbb6AE1b3D64BcB88988ceaCcb0FD3", decimals: 6 }, + { + address: "0x201E3c8BCcBB6e23710fEdAB9a28E806ef3240eb", + decimals: 6, + }, { + address: "0x2DF1200660Fbb6AE1b3D64BcB88988ceaCcb0FD3", + decimals: 6, + }, + ], }, [CHAIN.CORE]: { contracts: [ - { address: "0xf9139312E668EE8011F6c594ba24271eE5C913d5", decimals: 6 }, - { address: "0x5ADB96e1728Eb6493C2E0033eC70F829CaD83b1b", decimals: 6 }, + { + address: "0xf9139312E668EE8011F6c594ba24271eE5C913d5", + decimals: 6, + }, + { + address: "0x5ADB96e1728Eb6493C2E0033eC70F829CaD83b1b", + decimals: 6, + }, ], }, [CHAIN.ARBITRUM]: { contracts: [ - { address: "0x2daa2dc0651f9e019f1860f0BF04B77C3Fad6110", decimals: 6 }, - { address: "0x291521205f8dEaf167118efC03279C8cF80DB684", decimals: 6 }, + { + address: "0x2daa2dc0651f9e019f1860f0BF04B77C3Fad6110", + decimals: 6, + }, + { + address: "0x291521205f8dEaf167118efC03279C8cF80DB684", + decimals: 6, + }, ], }, [CHAIN.POLYGON]: { contracts: [ - { address: "0x8BE37856993A4758e07F59Cd26651942dD948310", decimals: 6 }, - { address: "0x2D363A4Ed846fa0eaA3884C25922a6552aAE96D6", decimals: 6 }, + { + address: "0x8BE37856993A4758e07F59Cd26651942dD948310", + decimals: 6, + }, + { + address: "0x2D363A4Ed846fa0eaA3884C25922a6552aAE96D6", + decimals: 6, + }, ], }, [CHAIN.BSC]: { contracts: [ - { address: "0xB17a12fEBcFc3a22086e50D4bEC480540fb2A30F", decimals: 18 }, - { address: "0x531Fdc85267838690d66443847A9fb759D2813C3", decimals: 18 }, + { + address: "0xB17a12fEBcFc3a22086e50D4bEC480540fb2A30F", + decimals: 18, + }, + { + address: "0x531Fdc85267838690d66443847A9fb759D2813C3", + decimals: 18, + }, ], }, [CHAIN.OPTIMISM]: { contracts: [ - { address: "0xB4e0C6A1542197f06514c111b6F3DCE7B250897F", decimals: 6 }, - { address: "0xD79683499F50a9e8D1aa3F9980b9bcdDdd553e8e", decimals: 6 }, + { + address: "0xB4e0C6A1542197f06514c111b6F3DCE7B250897F", + decimals: 6, + }, + { + address: "0xD79683499F50a9e8D1aa3F9980b9bcdDdd553e8e", + decimals: 6, + }, ], }, [CHAIN.SONEIUM]: { contracts: [ - { address: "0x03afBc04c44d648DD59fC9CafB2B00730Bf42593", decimals: 6 }, - { address: "0xb17ED50d2D5C3CACaf5b81e89C15b95B7Ce2CfB5", decimals: 6 }, + { + address: "0x03afBc04c44d648DD59fC9CafB2B00730Bf42593", + decimals: 6, + }, + { + address: "0xb17ED50d2D5C3CACaf5b81e89C15b95B7Ce2CfB5", + decimals: 6, + }, ], } }; -const abiWithdraw = "event WithdrawFundCrossChainFromOperator(address indexed receiver,address indexed tokenOut,bytes transportMsg,uint256 totalAmountOut,uint256 protocolFee,uint256 referralFee,uint256 withdrawFee,uint256 withdrawAt)"; +const abiWithdraw = + "event WithdrawFundCrossChainFromOperator(address indexed receiver,address indexed tokenOut,bytes transportMsg,uint256 totalAmountOut,uint256 protocolFee,uint256 referralFee,uint256 withdrawFee,uint256 withdrawAt)"; -const abiRebalance = "event RebalanceFundSameChain(address indexed strategyAddress,address indexed userAddress,address indexed underlyingAsset,uint256 receivedAmount,int256 receivedReward,uint256 protocolFee,uint256 referralFee,uint256 rebalanceFee,uint256 rebalancedAt)"; +const abiRebalance = + "event RebalanceFundSameChain(address indexed strategyAddress,address indexed userAddress,address indexed underlyingAsset,uint256 receivedAmount,int256 receivedReward,uint256 protocolFee,uint256 referralFee,uint256 rebalanceFee,uint256 rebalancedAt)"; -const fetch = async (options: FetchOptions) => { - const dailyRevenue = options.createBalances(); - const dailySupplySideRevenue = options.createBalances(); +const fetchMoneyFi = async (chain: string, options: FetchOptions) => { + const dailyProtocolRevenue = options.createBalances(); + const userRev = options.createBalances(); - const cfg = CHAINS_CONFIG[options.chain]; + const cfg = CHAINS_CONFIG[chain]; for (const { address, decimals } of cfg.contracts) { + + const withdrawLogs = await options.getLogs({ target: address, eventAbi: abiWithdraw, }); + + if (withdrawLogs.length > 0) { withdrawLogs.forEach((ev: any) => { const protocolFee = ev[4]; const scale = 10n ** BigInt(decimals); const normalizedFee = Number(protocolFee) / Number(scale); - dailyRevenue.addUSDValue(normalizedFee); - dailySupplySideRevenue.addUSDValue(normalizedFee * 4); + dailyProtocolRevenue.addUSDValue(normalizedFee); + userRev.addUSDValue(normalizedFee * 4); }); } + const rebalanceLogs = await options.getLogs({ target: address, eventAbi: abiRebalance, @@ -92,21 +148,18 @@ const fetch = async (options: FetchOptions) => { const protocolFee = ev[5]; const scale = 10n ** BigInt(decimals); const normalizedFee = Number(protocolFee) / Number(scale); - dailyRevenue.addUSDValue(normalizedFee); - dailySupplySideRevenue.addUSDValue(normalizedFee * 4); + dailyProtocolRevenue.addUSDValue(normalizedFee); + userRev.addUSDValue(normalizedFee * 4); }); } } - const dailyFees = dailyRevenue.clone(); - dailyFees.addBalances(dailySupplySideRevenue); + const totalRevenue = await dailyProtocolRevenue.getUSDValue() + await userRev.getUSDValue(); + return { - dailyFees, - dailyUserFees: dailyFees, - dailyRevenue, - dailyProtocolRevenue: dailyRevenue, - dailySupplySideRevenue, + dailyFees: totalRevenue, + dailyRevenue: dailyProtocolRevenue, }; }; @@ -118,9 +171,6 @@ const fetchAptos = async () => { return { dailyFees: daily * 5, dailyRevenue: daily, - dailyProtocolRevenue: daily, - dailySupplySideRevenue: daily * 4, - dailyUserFees: daily * 5, }; }; @@ -128,21 +178,21 @@ const fetchAptos = async () => { const adapter: SimpleAdapter = { version: 2, methodology: { - Fees:"Total fees generated by the MoneyFi protocol", - ProtocolRevenue: "Revenue share from total fees going to treasury", - SupplySideRevenue: "Yield earned by users through MoneyFi strategies" + dailyFees: "Total value earned by the MoneyFi system, including both the yield generated for users and the portion captured as protocol revenue.", + dailyRevenue: "Revenue earned by the MoneyFi protocol. The protocol captures 20% of the yield generated by users — this captured portion represents MoneyFi's actual revenue across all chains.", }, adapter: { ...Object.fromEntries( Object.keys(CHAINS_CONFIG).map(chain => [ chain, { - fetch, + fetch: (options: FetchOptions) => fetchMoneyFi(chain, options), start: "2025-05-27", }, ]) ), - [CHAIN.APTOS]: { + + aptos: { fetch: fetchAptos, start: "2025-05-27", }