Query editor
WITH block_data AS (SELECTtime as block_time,number as block_number,base_fee_per_gasFROM base.blocks blWHERE bl.time >= DATE('2024-04-01')),transactions AS (SELECTt.block_number,t.block_time,t.hash as tx_hash,t."from" as sender,t."to" as receiver,t.index as tx_index,t.gas_price,t.gas_used,b.base_fee_per_gas,t.gas_price - b.base_fee_per_gas as priority_fee_per_gas,(t.gas_price - b.base_fee_per_gas) * t.gas_used / 1e18 as priority_fees_ethFROM base.transactions tJOIN block_data b ON b.block_time = t.block_timeWHERE t.block_time >= DATE('2024-04-01')AND gas_price > 0),daily_metrics AS (SELECTDATE_TRUNC('week', t.block_time) as dt,-- Transaction countsCOUNT(*) as total_txns,COUNT(CASE WHEN tx_index = 1 THEN 1 END) as top1_txns,-- Priority fee metrics (in ETH)SUM(priority_fees_eth) as total_priority_fees_eth,SUM(CASE WHEN tx_index = 1 THEN priority_fees_eth ELSE 0 END) as top1_priority_fees_eth,-- Average priority fees in gwei for different positionsAVG(CASE WHEN tx_index = 1 THEN priority_fee_per_gas/1e9 END) as avg_top1_fee_gwei,MAX(CASE WHEN tx_index = 1 THEN priority_fee_per_gas/1e9 END) as max_top1_fee_gwei,AVG(priority_fee_per_gas/1e9) as avg_priority_fee_gwei,AVG(base_fee_per_gas/1e9) as avg_base_fee_gwei,-- DEX metricsCOUNT(DISTINCT d.tx_hash) as dex_txns,SUM(d.amount_usd) as dex_volume_usd,SUM(CASE WHEN tx_index = 1 THEN d.amount_usd ELSE 0 END) as dex_top1_volume_usd,-- Top 1 transaction prioritization premiumAVG(CASE WHEN tx_index = 1 THEN priority_fee_per_gas/1e9 END) /NULLIF(AVG(CASE WHEN tx_index > 1 THEN priority_fee_per_gas/1e9 END), 0) as top1_fee_premium,-- Revenue concentrationSUM(CASE WHEN tx_index <= 5 THEN priority_fees_eth ELSE 0 END) /NULLIF(SUM(priority_fees_eth), 0) as top5_fee_share,-- Average ETH price for the dayAVG(p.price) as eth_priceFROM transactions tLEFT JOIN dex.trades dON t.tx_hash = d.tx_hashAND d.blockchain = 'base'LEFT JOIN prices.usd pON DATE_TRUNC('minute', t.block_time) = p.minute