|
| 1 | +import { Adapter, FetchOptions, FetchResultV2 } from '../adapters/types' |
| 2 | +import { CHAIN } from '../helpers/chains' |
| 3 | +import { METRIC } from '../helpers/metrics' |
| 4 | + |
| 5 | +interface ChainConfig { |
| 6 | + token: string |
| 7 | + start: string |
| 8 | +} |
| 9 | + |
| 10 | +interface BfUSDConfig extends ChainConfig { |
| 11 | + instantRedeemer: string |
| 12 | +} |
| 13 | + |
| 14 | +const bfBTCConfigs: Record<string, ChainConfig> = { |
| 15 | + [CHAIN.ETHEREUM]: { |
| 16 | + token: '0xCdFb58c8C859Cb3F62ebe9Cf2767F9e036C7fb15', |
| 17 | + start: '2024-09-17', |
| 18 | + }, |
| 19 | + [CHAIN.BSC]: { |
| 20 | + token: '0x623F2774d9f27B59bc6b954544487532CE79d9DF', |
| 21 | + start: '2024-12-26', |
| 22 | + }, |
| 23 | + [CHAIN.BASE]: { |
| 24 | + token: '0x623F2774d9f27B59bc6b954544487532CE79d9DF', |
| 25 | + start: '2025-05-21', |
| 26 | + }, |
| 27 | + [CHAIN.BITLAYER]: { |
| 28 | + token: '0xcdfb58c8c859cb3f62ebe9cf2767f9e036c7fb15', |
| 29 | + start: '2025-01-03', |
| 30 | + }, |
| 31 | + [CHAIN.HEMI]: { |
| 32 | + token: '0x623F2774d9f27B59bc6b954544487532CE79d9DF', |
| 33 | + start: '2025-03-14', |
| 34 | + }, |
| 35 | + [CHAIN.CORE]: { |
| 36 | + token: '0xCdFb58c8C859Cb3F62ebe9Cf2767F9e036C7fb15', |
| 37 | + start: '2025-06-18', |
| 38 | + }, |
| 39 | + [CHAIN.GOAT]: { |
| 40 | + token: '0x623F2774d9f27B59bc6b954544487532CE79d9DF', |
| 41 | + start: '2025-06-24', |
| 42 | + }, |
| 43 | +} |
| 44 | + |
| 45 | +const bfUSDConfig: Record<string, BfUSDConfig> = { |
| 46 | + [CHAIN.ETHEREUM]: { |
| 47 | + token: '0xa3eB7A9e57FCa4e40b79E394eD5eB37fEd205A24', |
| 48 | + instantRedeemer: '0x0971cB672b4eF3E19284Aa64717aFb154A6fbeDF', |
| 49 | + start: '2025-11-03', |
| 50 | + }, |
| 51 | +} |
| 52 | + |
| 53 | +async function fetchBfBTC(options: FetchOptions): Promise<FetchResultV2> { |
| 54 | + const dailyFees = options.createBalances() |
| 55 | + const { token } = bfBTCConfigs[options.chain] |
| 56 | + |
| 57 | + const feeCollectedLogs = await options.getLogs({ |
| 58 | + target: token, |
| 59 | + eventAbi: 'event FeeCollected(address indexed user, uint8 indexed feeType, uint256 id, uint256 amount, uint256 percentageFee, uint256 fixedFee)', |
| 60 | + }) |
| 61 | + |
| 62 | + for (const log of feeCollectedLogs) { |
| 63 | + dailyFees.add(token, log.amount, METRIC.DEPOSIT_WITHDRAW_FEES) |
| 64 | + } |
| 65 | + |
| 66 | + return { |
| 67 | + dailyFees, |
| 68 | + dailyUserFees: dailyFees, |
| 69 | + dailyRevenue: dailyFees, |
| 70 | + dailyProtocolRevenue: dailyFees, |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +async function fetchBfUSD(options: FetchOptions): Promise<FetchResultV2> { |
| 75 | + const dailyFees = options.createBalances() |
| 76 | + const { token, instantRedeemer } = bfUSDConfig[options.chain] |
| 77 | + |
| 78 | + const crossChainFeeLogs = await options.getLogs({ |
| 79 | + target: token, |
| 80 | + eventAbi: 'event CrossChainFeeCollected(address indexed user, uint256 amount, uint256 fee)', |
| 81 | + }) |
| 82 | + |
| 83 | + for (const log of crossChainFeeLogs) { |
| 84 | + dailyFees.add(token, log.fee, METRIC.DEPOSIT_WITHDRAW_FEES) |
| 85 | + } |
| 86 | + |
| 87 | + const instantRedemptionLogs = await options.getLogs({ |
| 88 | + target: instantRedeemer, |
| 89 | + eventAbi: 'event InstantRedemption(address indexed user, address indexed to, uint256 bfUSDAmount, uint256 underlyingAmount, uint256 feeAmount)', |
| 90 | + }) |
| 91 | + |
| 92 | + for (const log of instantRedemptionLogs) { |
| 93 | + dailyFees.add(token, log.feeAmount, METRIC.MINT_REDEEM_FEES) |
| 94 | + } |
| 95 | + |
| 96 | + return { |
| 97 | + dailyFees, |
| 98 | + dailyUserFees: dailyFees, |
| 99 | + dailyRevenue: dailyFees, |
| 100 | + dailyProtocolRevenue: dailyFees, |
| 101 | + } |
| 102 | +} |
| 103 | + |
| 104 | +async function fetchEthereum(options: FetchOptions): Promise<FetchResultV2> { |
| 105 | + const dailyFees = options.createBalances() |
| 106 | + |
| 107 | + const bfBTCToken = bfBTCConfigs[CHAIN.ETHEREUM].token |
| 108 | + const feeCollectedLogs = await options.getLogs({ |
| 109 | + target: bfBTCToken, |
| 110 | + eventAbi: 'event FeeCollected(address indexed user, uint8 indexed feeType, uint256 id, uint256 amount, uint256 percentageFee, uint256 fixedFee)', |
| 111 | + }) |
| 112 | + |
| 113 | + for (const log of feeCollectedLogs) { |
| 114 | + dailyFees.add(bfBTCToken, log.amount, METRIC.DEPOSIT_WITHDRAW_FEES) |
| 115 | + } |
| 116 | + |
| 117 | + const bfUSDToken = bfUSDConfig[CHAIN.ETHEREUM].token |
| 118 | + const instantRedeemer = bfUSDConfig[CHAIN.ETHEREUM].instantRedeemer |
| 119 | + |
| 120 | + const crossChainFeeLogs = await options.getLogs({ |
| 121 | + target: bfUSDToken, |
| 122 | + eventAbi: 'event CrossChainFeeCollected(address indexed user, uint256 amount, uint256 fee)', |
| 123 | + }) |
| 124 | + |
| 125 | + for (const log of crossChainFeeLogs) { |
| 126 | + dailyFees.add(bfUSDToken, log.fee, METRIC.DEPOSIT_WITHDRAW_FEES) |
| 127 | + } |
| 128 | + |
| 129 | + const instantRedemptionLogs = await options.getLogs({ |
| 130 | + target: instantRedeemer, |
| 131 | + eventAbi: 'event InstantRedemption(address indexed user, address indexed to, uint256 bfUSDAmount, uint256 underlyingAmount, uint256 feeAmount)', |
| 132 | + }) |
| 133 | + |
| 134 | + for (const log of instantRedemptionLogs) { |
| 135 | + dailyFees.add(bfUSDToken, log.feeAmount, METRIC.MINT_REDEEM_FEES) |
| 136 | + } |
| 137 | + |
| 138 | + return { |
| 139 | + dailyFees, |
| 140 | + dailyUserFees: dailyFees, |
| 141 | + dailyRevenue: dailyFees, |
| 142 | + dailyProtocolRevenue: dailyFees, |
| 143 | + } |
| 144 | +} |
| 145 | + |
| 146 | +const adapter: Adapter = { |
| 147 | + adapter: { |
| 148 | + [CHAIN.ETHEREUM]: { |
| 149 | + fetch: fetchEthereum, |
| 150 | + start: '2024-09-17', |
| 151 | + }, |
| 152 | + ...Object.fromEntries( |
| 153 | + Object.entries(bfBTCConfigs) |
| 154 | + .filter(([chain]) => chain !== CHAIN.ETHEREUM) |
| 155 | + .map(([chain, config]) => [ |
| 156 | + chain, |
| 157 | + { |
| 158 | + fetch: fetchBfBTC, |
| 159 | + start: config.start, |
| 160 | + }, |
| 161 | + ]) |
| 162 | + ), |
| 163 | + }, |
| 164 | + version: 2, |
| 165 | + methodology: { |
| 166 | + Fees: 'Withdrawal fees from bfBTC (on EVM chains and Bitcoin network) and instant redemption + cross-chain transfer fees from bfUSD paid by users.', |
| 167 | + UserFees: 'Withdrawal fees from bfBTC (on EVM chains and Bitcoin network) and instant redemption + cross-chain transfer fees from bfUSD paid by users.', |
| 168 | + Revenue: 'All fees collected are sent to BitFi protocol fee receiver address.', |
| 169 | + ProtocolRevenue: 'All fees collected are sent to BitFi protocol fee receiver address.', |
| 170 | + }, |
| 171 | +} |
| 172 | + |
| 173 | +export default adapter |
0 commit comments