|
| 1 | +/** |
| 2 | + * FlareBank Fees Adapter for DefiLlama |
| 3 | + * |
| 4 | + * FlareBank is a dividend-paying token protocol on Flare Network with multiple fee sources. |
| 5 | + * |
| 6 | + * FEE STRUCTURE: |
| 7 | + * ┌─────────────┬───────────────┬────────────────────────────────┐ |
| 8 | + * │ Action │ Fee │ Distribution │ |
| 9 | + * ├─────────────┼───────────────┼────────────────────────────────┤ |
| 10 | + * │ Mint (buy) │ 10% of WFLR │ 80% holders, 15% team, 5% DAO │ |
| 11 | + * │ Burn (sell) │ 10% of WFLR │ 80% holders, 15% team, 5% DAO │ |
| 12 | + * │ Transfer │ 1% │ 80% holders, 15% team, 5% DAO │ |
| 13 | + * │ LP Swap │ 1% │ 80% holders, 15% team, 5% DAO │ |
| 14 | + * └─────────────┴───────────────┴────────────────────────────────┘ |
| 15 | + * |
| 16 | + * METRICS: |
| 17 | + * - dailyFees: All fees collected (mint/burn/transfer/swap fees) |
| 18 | + * - dailyUserFees: Same as dailyFees (users pay all fees) |
| 19 | + * - dailyRevenue: Protocol revenue (team + DAO = 20%) |
| 20 | + * - dailyProtocolRevenue: Team (15%) + DAO (5%) = 20% |
| 21 | + * - dailyHoldersRevenue: 80% of fees to BANK holders |
| 22 | + * |
| 23 | + * Submit to: https://github.com/DefiLlama/dimension-adapters/tree/master/fees |
| 24 | + */ |
| 25 | + |
| 26 | +import { FetchOptions, SimpleAdapter } from "../../adapters/types"; |
| 27 | +import { CHAIN } from "../../helpers/chains"; |
| 28 | +import { METRIC } from "../../helpers/metrics" |
| 29 | + |
| 30 | +// Contracts |
| 31 | +const FLAREBANK_ADDRESS = "0x194726F6C2aE988f1Ab5e1C943c17e591a6f6059"; |
| 32 | +const WFLR_ADDRESS = "0x1D80c49BbBCd1C0911346656B529DF9E5c2F783d"; |
| 33 | + |
| 34 | +// V2 LP addresses for swap detection |
| 35 | +const LP_ADDRESSES = [ |
| 36 | + "0x5f29c8d049e47dd180c2b83e3560e8e271110335", // Enosys V2 BANK/WFLR |
| 37 | + "0x0f574fc895c1abf82aeff334fa9d8ba43f866111", // SparkDex V2 BANK/WFLR |
| 38 | +]; |
| 39 | + |
| 40 | +// Event ABIs |
| 41 | +const EVENTS = { |
| 42 | + onTokenPurchase: "event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount)", |
| 43 | + onTokenSell: "event TokenSell(address indexed user, uint256 burned, uint256 ethEarned)", |
| 44 | + |
| 45 | + // Standard ERC20 Transfer for transfer/swap detection |
| 46 | + Transfer: "event Transfer(address indexed from, address indexed to, uint256 value)", |
| 47 | +}; |
| 48 | + |
| 49 | +// Fee rates |
| 50 | +const MINT_BURN_FEE = 10n; // 10% |
| 51 | + |
| 52 | +const fetch = async (options: FetchOptions) => { |
| 53 | + const dailyFees = options.createBalances(); |
| 54 | + |
| 55 | + const bankAddressLower = FLAREBANK_ADDRESS.toLowerCase(); |
| 56 | + |
| 57 | + // ═══════════════════════════════════════════════════════════════════════ |
| 58 | + // 1. MINT FEES (10% of incoming WFLR) |
| 59 | + // ═══════════════════════════════════════════════════════════════════════ |
| 60 | + const mintLogs = await options.getLogs({ |
| 61 | + target: FLAREBANK_ADDRESS, |
| 62 | + eventAbi: EVENTS.onTokenPurchase, |
| 63 | + }); |
| 64 | + mintLogs.forEach((log: any) => { |
| 65 | + const incomingWFLR = BigInt(log.value); |
| 66 | + const fee = incomingWFLR * MINT_BURN_FEE / 100n; |
| 67 | + dailyFees.add(WFLR_ADDRESS, fee, METRIC.MINT_REDEEM_FEES); |
| 68 | + }); |
| 69 | + |
| 70 | + // ═══════════════════════════════════════════════════════════════════════ |
| 71 | + // 2. BURN FEES (10% of WFLR withdrawn) |
| 72 | + // ═══════════════════════════════════════════════════════════════════════ |
| 73 | + const burnLogs = await options.getLogs({ |
| 74 | + target: FLAREBANK_ADDRESS, |
| 75 | + eventAbi: EVENTS.onTokenSell, |
| 76 | + }); |
| 77 | + burnLogs.forEach((log: any) => { |
| 78 | + // const ethereumEarned = BigInt(log.ethEarned); |
| 79 | + // ethereumEarned is AFTER 10% fee, so original = earned / 0.9 |
| 80 | + // fee = original * 0.1 = earned / 9 |
| 81 | + const fee = log.ethEarned / 9n; |
| 82 | + dailyFees.add(WFLR_ADDRESS, fee, METRIC.MINT_REDEEM_FEES); |
| 83 | + }); |
| 84 | + |
| 85 | + // ═══════════════════════════════════════════════════════════════════════ |
| 86 | + // 3. TRANSFER + SWAP FEES (1% fee) |
| 87 | + // ═══════════════════════════════════════════════════════════════════════ |
| 88 | + const transferLogs = await options.getLogs({ |
| 89 | + target: FLAREBANK_ADDRESS, |
| 90 | + eventAbi: EVENTS.Transfer, |
| 91 | + }); |
| 92 | + |
| 93 | + transferLogs.forEach((log: any) => { |
| 94 | + const from = log.from.toLowerCase(); |
| 95 | + const to = log.to.toLowerCase(); |
| 96 | + const value = BigInt(log.value); |
| 97 | + |
| 98 | + // Skip mints (from = 0x0) and burns (to = 0x0 or to = contract) |
| 99 | + if (from === "0x0000000000000000000000000000000000000000") return; |
| 100 | + if (to === "0x0000000000000000000000000000000000000000") return; |
| 101 | + if (to === bankAddressLower) return; |
| 102 | + // Transfer/Swap: 1% fee (1% also burned but burns not counted as fee per reviewer) |
| 103 | + const feeAmount = value / 100n; // 1% fee |
| 104 | + |
| 105 | + // Add the 1% fee to dailyFees (in BANK token) with label |
| 106 | + dailyFees.add(FLAREBANK_ADDRESS, feeAmount, METRIC.TRADING_FEES); |
| 107 | + }); |
| 108 | + |
| 109 | + const dailyHoldersRevenue = dailyFees.clone(0.8) |
| 110 | + const dailyProtocolRevenue = dailyFees.clone(0.2) |
| 111 | + const dailyRevenue = dailyHoldersRevenue.clone() |
| 112 | + dailyRevenue.addBalances(dailyProtocolRevenue) |
| 113 | + |
| 114 | + return { |
| 115 | + dailyFees, // All fees collected (with labels) |
| 116 | + dailyUserFees: dailyFees, // Users pay all fees |
| 117 | + dailyRevenue: dailyRevenue, // Team + DAO (20%) + Holders Revenue |
| 118 | + dailyProtocolRevenue, // Team (15%) + DAO (5%) |
| 119 | + dailyHoldersRevenue, // 80% to BANK holders as dividends |
| 120 | + }; |
| 121 | +}; |
| 122 | + |
| 123 | +const adapter: SimpleAdapter = { |
| 124 | + version: 2, |
| 125 | + methodology: { |
| 126 | + Fees: "10% fee on mints and burns (WFLR), 1% fee on transfers and LP swaps (BANK).", |
| 127 | + UserFees: "Users pay all fees: 10% on mint/burn, 1% on transfer/swap.", |
| 128 | + Revenue: "20% of fees go to protocol (15% team, 5% DAO treasury).", |
| 129 | + ProtocolRevenue: "15% to team wallet, 5% to DAO treasury.", |
| 130 | + HoldersRevenue: "80% of all fees distributed as dividends to BANK token holders.", |
| 131 | + }, |
| 132 | + breakdownMethodology: { |
| 133 | + Fees: { |
| 134 | + [METRIC.MINT_REDEEM_FEES]: "A 10% fee is charged when minting and redeeming WFLR", |
| 135 | + [METRIC.SWAP_FEES]: "A 1% fee is charged on swaps and transfers" |
| 136 | + }, |
| 137 | + Revenue: { |
| 138 | + [METRIC.MINT_REDEEM_FEES]: "A 10% fee is charged when minting and redeeming WFLR", |
| 139 | + [METRIC.SWAP_FEES]: "A 1% fee is charged on swaps and transfers" |
| 140 | + }, |
| 141 | + ProtocolRevenue: { |
| 142 | + [METRIC.MINT_REDEEM_FEES]: "15% of fees go to the team and 5% to the DAO", |
| 143 | + [METRIC.SWAP_FEES]: "15% of fees go to the team and 5% to the DAO" |
| 144 | + }, |
| 145 | + HoldersRevenue: { |
| 146 | + [METRIC.MINT_REDEEM_FEES]: "80% of the fees are paid as dividends to BANK holders", |
| 147 | + [METRIC.SWAP_FEES]: "80% of the fees are paid as dividends to BANK holders" |
| 148 | + } |
| 149 | + }, |
| 150 | + adapter: { |
| 151 | + [CHAIN.FLARE]: { |
| 152 | + fetch, |
| 153 | + start: "2025-02-13", |
| 154 | + }, |
| 155 | + }, |
| 156 | +}; |
| 157 | + |
| 158 | +export default adapter; |
0 commit comments