Query editor
-- Join the #analytics channel in the Optimism Discord to ask questions!-- A lot going on here.WITH max_bt AS (SELECT MIN(mt) AS mtFROM (SELECT MAX(time) mt FROM optimism.blocks WHERE time> NOW() - interval '7' dayUNION ALLSELECT MAX(time) mt FROM ethereum.blocks WHERE time> NOW() - interval '7' day) a), l2_rev AS (SELECTDATE_TRUNC('{{Time Granularity}}',block_time) AS dt,CASE WHEN DATE_TRUNC('{{Time Granularity}}',block_time) = DATE_TRUNC('{{Time Granularity}}',NOW())THEN DATE_DIFF('second', DATE_TRUNC('{{Time Granularity}}',NOW()), NOW() )/ (60.0*60.0*24.0* CASE '{{Time Granularity}}' WHEN 'Week' THEN 7 WHEN 'Month' THEN 31 END)ELSE NULLEND AS share_elapsed,cast(SUM(case when gas_price > cast(0 as uint256) THEN 1 ELSE 0 END) as double) AS txs, cast( COUNT(DISTINCT "from") as double) AS addr,cast(SUM(CASE WHEN gas_price = cast(0 as uint256) THEN 0 ELSE --deposits & gas oraclecast(l1_fee + t.gas_used*gas_price as double)/1e18END) as double) AS l2_eth_rev,AVG(cast(l1_fee + t.gas_used*gas_price as double)/1e18) AS avg_l2_tx_fee,SUM(price*cast(l1_fee + t.gas_used*gas_price as double)/1e18) AS l2_eth_rev_usd,AVG(price*cast(l1_fee + t.gas_used*gas_price as double)/1e18) AS avg_l2_tx_fee_usd,cast(SUM((l1_gas_used)) as double) AS l1_gas_used_on_l2,cast(SUM(t.gas_used) as double) AS l2_gas_used,cast(SUM(gas_price) as double) AS sum_l2_gas_price,AVG(cast(gas_price as double)/1e9) AS avg_l2_gas_price,AVG(cast(l1_gas_price as double)/1e9) AS avg_l1_gas_price_on_l2,SUM(-- 16 * ( length( replace( decode(unhex(substring(data,3)), 'US-ASCII') , chr(0), '')) ) --16 * nonzero bytes-- + 4 * ( length( decode(unhex(substring(data,3)), 'US-ASCII') ) - length(replace( decode(unhex(substring(data,3)), 'US-ASCII') , chr(0), '')) ) --4 * zero bytescast(l1_gas_used-( --subtract fixed overhead to get calldata & noncalldata of each txCASEWHEN block_number <= 2071714 THEN 2750.0WHEN block_time <= cast('2023-06-06 16:30:00' as timestamp) THEN 2100.0 --bedrock at 16:00, but set a bufferELSE 188-- todo add bedrockEND)as double)) AS calldata_gas_l2, SUM(cast(l1_fee as double) / 1e18 ) AS l2_eth_rev_l1_contrib, SUM(cast(gas_price*t.gas_used as double) / 1e18 ) AS l2_eth_rev_l2_contrib, SUM(cast(COALESCE(base_fee_per_gas,cast(gas_price as double) )*t.gas_used as double) / 1e18 ) AS l2_eth_rev_l2_contrib_base --if no base fee (legacy), take gas price, SUM(case when gas_price = cast(0 as uint256) then 0 elsecast( (cast(gas_price as double)-base_fee_per_gas)*t.gas_used as double) / 1e18 end) AS l2_eth_rev_l2_contrib_priority, SUM(price* (cast(l1_fee as double) / 1e18 ) ) AS l2_eth_rev_l1_contrib_usd, SUM(price* (cast(gas_price*t.gas_used as double) / 1e18 ) ) AS l2_eth_rev_l2_contrib_usd, SUM(price* cast(COALESCE(base_fee_per_gas,cast(gas_price as double) )*t.gas_used as double) / 1e18 ) AS l2_eth_rev_l2_contrib_base_usd --if no base fee (legacy), take gas price, SUM(price* (case when gas_price = cast(0 as uint256) then 0 else