Query editor
-- CL: rewards (net of penalties, excl. deposits/withdrawals) over start balance of active validators-- staked ETH = actual balance (not effective balance) of active validators at start of dayWITH cl AS (SELECTblock_date AS day,sum(start_balance) / 1e9 AS eth_staked_eth,sum(reward_change) / 1e9 AS staking_rewards_cl_ethFROM beacon.validator_day_summariesWHERE block_date >= current_date - interval '{{days}}' dayAND block_date < current_date - interval '{{end_days}}' dayAND start_effective_balance > 0GROUP BY 1),-- EL: per block, proposer gets the MEV-boost payment (last tx sent by the fee recipient/builder) or else the priority feesblk AS (SELECT number, date AS day, miner, base_fee_per_gasFROM ethereum.blocksWHERE date >= greatest(current_date - interval '{{days}}' day, DATE '2022-09-15')AND date < current_date - interval '{{end_days}}' dayAND number >= 15537394 -- merge block),tx AS (SELECTt.block_number,sum(cast(t.gas_used AS double) * (cast(t.gas_price AS double) - cast(b.base_fee_per_gas AS double))) / 1e18 AS priority_fees_eth,max_by(t."from", t.index) AS last_from,max_by(t.value, t.index) / 1e18 AS last_value_ethFROM ethereum.transactions tJOIN blk b ON b.number = t.block_numberWHERE t.block_date >= greatest(current_date - interval '{{days}}' day, DATE '2022-09-15')AND t.block_date < current_date - interval '{{end_days}}' dayGROUP BY 1),-- per block split of the proposer's EL reward:-- local block: everything is tips (priority fees)-- MEV-boost block: payment covers the block's priority fees first (tips), the excess is MEVel_block AS (SELECTb.day,CASE WHEN tx.last_from = b.miner THEN tx.last_value_eth ELSE tx.priority_fees_eth END AS el_eth,CASE WHEN tx.last_from = b.miner THEN least(greatest(tx.priority_fees_eth, 0), tx.last_value_eth) ELSE tx.priority_fees_eth END AS tips_ethFROM blk bJOIN tx ON tx.block_number = b.number),el AS (SELECTday,sum(el_eth) AS staking_rewards_el_eth,sum(tips_eth) AS staking_rewards_tips_eth,sum(el_eth - tips_eth) AS staking_rewards_mev_ethFROM el_blockGROUP BY 1)SELECTcl.day,'ethereum' AS origin_key,cl.eth_staked_eth,cl.staking_rewards_cl_eth,coalesce(el.staking_rewards_el_eth, 0) AS staking_rewards_el_eth,coalesce(el.staking_rewards_tips_eth, 0) AS staking_rewards_tips_eth,