Afonso_Diaz2023-05-11 03:06 PM
    Updated 2023-05-11
    with t0 as (
    select
    hour::date as date,
    symbol,
    token_address,
    avg(price) as price_usd
    from optimism.core.fact_hourly_token_prices
    group by 1, 2, 3
    ),

    t as (
    select
    origin_from_address,
    min(block_timestamp)::date as min_date
    from optimism.core.ez_dex_swaps
    where platform like 'uniswap%'
    group by 1
    ),

    t2 as (
    select
    date_trunc('month', min_date)::date as month,
    count(distinct origin_from_address) as new_users
    from t
    where min_date > current_date - interval '12 months'
    group by 1
    ),

    t3 as (
    select
    date_trunc('month', block_timestamp)::date as month,
    count(distinct tx_hash) as swaps,
    count(distinct origin_from_address) as users,
    sum(iff(amount_in_usd is not null, amount_in_usd, nvl(amount_in * price_usd, 0))) as volume_usd,
    avg(iff(amount_in_usd is not null, amount_in_usd, nvl(amount_in * price_usd, 0))) as average_volume_usd
    from optimism.core.ez_dex_swaps
    Run a query to Download Data