|
| 1 | +import { Adapter, FetchOptions, ProtocolType } from "../../adapters/types"; |
| 2 | +import { CHAIN } from "../../helpers/chains"; |
| 3 | +import { METRIC } from "../../helpers/metrics"; |
| 4 | +import { queryIndexer } from '../../helpers/indexer'; |
| 5 | + |
| 6 | +const fetch = async (options: FetchOptions) => { |
| 7 | + const toBlock = await options.getToBlock() |
| 8 | + const fromBlock = await options.getFromBlock() |
| 9 | + const monadTx: any = await queryIndexer(` |
| 10 | + SELECT |
| 11 | + SUM( |
| 12 | + CASE WHEN (TYPE = 0 |
| 13 | + OR TYPE = 1 |
| 14 | + OR TYPE = 4) THEN |
| 15 | + gas_price * t.gas_limit / 1e18 |
| 16 | + WHEN TYPE = 2 |
| 17 | + AND base_fee_per_gas + t.max_priority_fee_per_gas <= t.max_fee_per_gas THEN |
| 18 | + (base_fee_per_gas + t.max_priority_fee_per_gas) * t.gas_limit / 1e18 |
| 19 | + WHEN TYPE = 2 |
| 20 | + AND base_fee_per_gas + max_priority_fee_per_gas > max_fee_per_gas THEN |
| 21 | + ((max_fee_per_gas) * (t.gas_limit)) / 1e18 |
| 22 | + END) AS txn_fees |
| 23 | + FROM |
| 24 | + monad.transactions t |
| 25 | + LEFT JOIN monad.blocks b ON block_number = number |
| 26 | + WHERE t.block_time BETWEEN llama_replace_date_range;`, options); |
| 27 | + const monadTxBurn: any = await queryIndexer(` |
| 28 | + SELECT |
| 29 | + SUM(eb.base_fee_per_gas * eb.gas_limit/1e18) AS daily_mon_burned |
| 30 | + FROM monad.blocks AS eb |
| 31 | + WHERE eb.base_fee_per_gas IS NOT NULL |
| 32 | + AND eb.gas_limit IS NOT NULL |
| 33 | + and eb.number > ${fromBlock} and eb.number < ${toBlock}`, options); |
| 34 | + |
| 35 | + const dailyFees = options.createBalances() |
| 36 | + const dailyRevenue = options.createBalances() |
| 37 | + |
| 38 | + const totalFees = Number(monadTx[0].txn_fees) |
| 39 | + const baseFees = Number(monadTxBurn[0]['daily_mon_burned']) |
| 40 | + const priorityFees = totalFees - baseFees |
| 41 | + |
| 42 | + dailyFees.addGasToken(baseFees * 10 ** 18, METRIC.TRANSACTION_BASE_FEES) |
| 43 | + dailyFees.addGasToken(priorityFees * 10 ** 18, METRIC.TRANSACTION_PRIORITY_FEES) |
| 44 | + |
| 45 | + dailyRevenue.addGasToken(baseFees * 10 ** 18, METRIC.TRANSACTION_BASE_FEES) |
| 46 | + |
| 47 | + return { |
| 48 | + dailyFees, |
| 49 | + dailyRevenue, |
| 50 | + dailyHoldersRevenue: dailyRevenue, |
| 51 | + }; |
| 52 | +}; |
| 53 | + |
| 54 | +const adapter: Adapter = { |
| 55 | + version: 2, |
| 56 | + adapter: { |
| 57 | + [CHAIN.MONAD]: { |
| 58 | + fetch, |
| 59 | + start: '2025-11-24', |
| 60 | + }, |
| 61 | + }, |
| 62 | + protocolType: ProtocolType.CHAIN, |
| 63 | + methodology: { |
| 64 | + Fees: 'Total MON gas fees (including base fees and priority fees) paid by users', |
| 65 | + Revenue: 'Amount of MON base fees that were burned', |
| 66 | + HoldersRevenue: 'Amount of MON base fees that were burned', |
| 67 | + }, |
| 68 | + breakdownMethodology: { |
| 69 | + Fees: { |
| 70 | + [METRIC.TRANSACTION_BASE_FEES]: 'Total MON base fees paid by users', |
| 71 | + [METRIC.TRANSACTION_PRIORITY_FEES]: 'Total MON priority fees paid by users', |
| 72 | + }, |
| 73 | + Revenue: { |
| 74 | + [METRIC.TRANSACTION_BASE_FEES]: 'Total MON base fees will be burned', |
| 75 | + }, |
| 76 | + HoldersRevenue: { |
| 77 | + [METRIC.TRANSACTION_BASE_FEES]: 'Total MON base fees will be burned', |
| 78 | + }, |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +export default adapter; |
0 commit comments