Query editor
WITH protocol_revenue AS (-- Get the total fees earned by BalancerSELECTDATE_TRUNC('month', block_date) AS month,blockchain,SUM(fee_amount_usd) AS total_revenue_usdFROM balancer.pools_metrics_dailyWHERE blockchain = 'ethereum'AND version = '2'GROUP BY 1, 2),network_costs AS (-- Get the total gas cost spent interacting with BalancerSELECTblock_month AS month,blockchain,SUM(tx_fee_usd) AS total_gas_cost_usdFROM gas.feesWHERE blockchain = 'ethereum'AND tx_to = 0xBA12222222228d8Ba445958a75a0704d566BF2C8 -- Balancer VaultGROUP BY 1, 2)SELECTr.month,r.blockchain,r.total_revenue_usd AS protocol_revenue,COALESCE(c.total_gas_cost_usd, 0) AS network_cost,r.total_revenue_usd - COALESCE(c.total_gas_cost_usd, 0) AS net_profitFROM protocol_revenue rLEFT JOIN network_costs cON r.month = c.monthAND r.blockchain = c.blockchainORDER BY 1 DESC;