nsa2000OPTOP1
    Updated 2023-02-23
    with ethpricet as (
    select hour::date as day,
    avg (price) as ETHPrice
    from ethereum.core.fact_hourly_token_prices
    where symbol = 'WETH'
    and day >= '2023-01-01'
    group by 1)

    select 'Optimism' as blockchain,
    date_trunc(day,block_timestamp) as date,
    count (distinct tx_hash) as TX_Count,
    count (distinct from_address) as Users_Count,
    sum (tx_fee) as Total_ETH_Fee,
    avg (tx_fee) as Average_ETH_Fee,
    max (tx_fee) as Maximum_ETH_Fee,
    median (tx_fee) as Median_ETH_fee,
    sum (tx_fee*ethprice) as Total_USD_Fee,
    avg (tx_fee*ethprice) as Average_USD_Fee,
    max (tx_fee*ethprice) as Maximum_USD_Fee,
    median (tx_fee*ethprice) as Median_USD_Fee,
    sum (tx_count) over (order by date) as Cumulative_TX_Count,
    sum (total_eth_fee) over (order by date) as Cumulative_ETH_fee,
    sum (total_usd_fee) over (order by date) as Cumulative_USD_Fee
    from optimism.core.fact_transactions t1 join ethpricet t2 on t1.block_timestamp::date = t2.day
    where block_timestamp >= '2023-01-01'
    group by 1,2

    union all

    select 'Ethereum' as blockchain,
    date_trunc(day,block_timestamp) as date,
    count (distinct tx_hash) as TX_Count,
    count (distinct from_address) as Users_Count,
    sum (tx_fee) as Total_ETH_Fee,
    avg (tx_fee) as Average_ETH_Fee,
    max (tx_fee) as Maximum_ETH_Fee,
    Run a query to Download Data