Query editor
-- RAAC Protocol Revenue: Monthly breakdown-- All amounts in native token (ETH for lending, pmUSD for treasury, NFT price unit for minting)WITH minting_revenue AS (SELECTDATE_TRUNC('month', evt_block_time) AS month,COUNT(*) AS mint_count,SUM(CAST(mintFee AS DOUBLE) / 1e18) AS total_mint_fee_native,SUM(CAST(price AS DOUBLE) / 1e18) AS total_nft_price_native,SUM(CAST(mintFee AS DOUBLE) / 1e18 * 10000 / NULLIF(CAST(price AS DOUBLE) / 1e18, 0)) AS implied_fee_bpsFROM raac_ethereum.raacnft_evt_nftmintedGROUP BY 1),lending_interest_revenue AS (SELECTDATE_TRUNC('month', evt_block_time) AS month,COUNT(*) AS repayment_count,SUM(CAST(interest AS DOUBLE) / 1e18) AS total_interest_eth,SUM(CAST(payment AS DOUBLE) / 1e18) AS total_payment_eth,SUM(CAST(principal AS DOUBLE) / 1e18) AS total_principal_eth,SUM(CAST(payment AS DOUBLE) / 1e18 - CAST(principal AS DOUBLE) / 1e18) AS net_interest_ethFROM pumpx_ethereum.lending_evt_loanrepaidWHERE contract_address = 0x9267cff7720439457d16679c839f62984017672eGROUP BY 1),lending_liquidations AS (SELECTDATE_TRUNC('month', evt_block_time) AS month,COUNT(*) AS liquidation_count,SUM(CAST(principal AS DOUBLE) / 1e18) AS liquidated_principal_ethFROM pumpx_ethereum.lending_evt_loanclosedWHERE contract_address = 0x9267cff7720439457d16679c839f62984017672eAND status = 5GROUP BY 1),treasury_inflows AS (SELECTDATE_TRUNC('month', evt_block_time) AS month,COUNT(*) AS inflow_tx_count,SUM(CAST(value AS DOUBLE) / 1e18) AS treasury_inflow_pmusdFROM erc20_ethereum.evt_transferWHERE "to" = 0x51c4348af0c6066a2fd31bd968bc0c039fe27342AND contract_address = 0x7a7f847fb60b0000e24cce07298dc73df8b8e56aGROUP BY 1)SELECTCOALESCE(m.month, l.month, li.month, t.month) AS month,m.mint_count,ROUND(COALESCE(m.total_mint_fee_native, 0), 6) AS mint_fee_native,ROUND(COALESCE(m.total_nft_price_native, 0), 4) AS total_nft_price_native,COALESCE(l.repayment_count, 0) AS lending_repayments,ROUND(COALESCE(l.total_interest_eth, 0), 6) AS lending_interest_eth,COALESCE(li.liquidation_count, 0) AS liquidations,ROUND(COALESCE(li.liquidated_principal_eth, 0), 4) AS liquidated_principal_eth,COALESCE(t.inflow_tx_count, 0) AS treasury_inflow_txs,