Query editor
WITH all_fee_vaults AS (SELECT DISTINCTb.account_bankMint as mint,tk.symbol,tk.decimals,lp.account_feeVault as fee_vaultFROM marginfi_solana.marginfi_call_lendingPoolCollectBankFees lpJOIN marginfi_solana.marginfi_call_lendingPoolAddBank bON b.account_bank = lp.account_bankJOIN tokens_solana.fungible tkON tk.token_mint_address = b.account_bankMintWHERE b.account_marginfiGroup = '4qp6Fx6tnZkY5Wropq9wUYgtFxXKwE6viZxFHg3rdAG8'),transfers_monthly AS (SELECTDATE_TRUNC('month', block_time) as month,to_token_account as fee_vault,SUM(amount) as total_amountFROM tokens_solana.transfersWHERE block_time >= TIMESTAMP '2024-01-01'AND block_time < TIMESTAMP '2025-01-01'GROUP BY 1, 2),monthly_prices AS (SELECTDATE_TRUNC('month', minute) as month,contract_address,AVG(price) as priceFROM prices.usdWHERE blockchain = 'solana'AND minute >= TIMESTAMP '2024-01-01'AND minute < TIMESTAMP '2025-01-01'GROUP BY 1, 2)SELECTt.month,SUM(t.total_amount/POWER(10, fv.decimals) * COALESCE(p.price, dp.price)) as monthly_fees_usd,SUM(SUM(t.total_amount/POWER(10, fv.decimals) * COALESCE(p.price, dp.price)))OVER (ORDER BY t.month) as cumulative_fees_usdFROM transfers_monthly tJOIN all_fee_vaults fv ON fv.fee_vault = t.fee_vaultLEFT JOIN monthly_prices pON toBase58(p.contract_address) = fv.mintAND t.month = p.monthLEFT JOIN (SELECTDATE_TRUNC('month', day) as month,token_mint_address,AVG(median_price) as priceFROM dune.dune.result_dex_prices_solanaWHERE day >= TIMESTAMP '2024-01-01'AND day < TIMESTAMP '2025-01-01'GROUP BY 1, 2) dp ON dp.token_mint_address = fv.mintAND t.month = dp.monthGROUP BY 1ORDER BY 1 DESC;