Query editor
with date_filter as (select (casewhen '{{date_period}}' = '30 Days' then now() - interval '30' daywhen '{{date_period}}' = '3 Months' then now() - interval '3' monthwhen '{{date_period}}' = '6 Months' then now() - interval '6' monthwhen '{{date_period}}' = '1 Year' then now() - interval '1' yearelse date('2021-01-01')end) as start_date),daily_transaction as (select date_trunc('day', block_time) as block_date,"to" as contract_address,sum(cast(effective_gas_price as double) * gas_used) / 1e18 as gas_feefrom arbitrum.transactionsinner join date_filter on truewhere success = trueand block_time >= date_filter.start_dategroup by 1, 2),top_contract_by_gas_fee as (select contract_address,sum(gas_fee) as gas_fee_consumedfrom daily_transactiongroup by contract_addressorder by sum(gas_fee) desclimit 20),daily_eth_price as (select date_trunc('day', minute) as block_date,avg(price) as pricefrom prices.usd pinner join date_filter on truewhere blockchain = 'arbitrum'and symbol = 'WETH'and p.minute >= date_filter.start_dategroup by 1),top_contracts_daily_summary as (select date_trunc('day', block_time) as block_date,avg(cast(effective_gas_price as double) * gas_used) as avg_gas_fee,approx_percentile(cast(effective_gas_price as double) * gas_used, 0.10) as ten_percent_gas_fee,approx_percentile(cast(effective_gas_price as double) * gas_used, 0.50) as median_gas_fee,approx_percentile(cast(effective_gas_price as double) * gas_used, 0.90) as ninety_percent_gas_feefrom arbitrum.transactionsinner join date_filter on truewhere success = trueand block_time >= date_filter.start_dateand "to" in (select contract_address from top_contract_by_gas_fee)group by 1)select t.block_date,avg_gas_fee * p.price / 1e18 as avg_gas_fee,ten_percent_gas_fee * p.price / 1e18 as ten_percent_gas_fee,