Afonso_Diaz2023-05-04 06:05 PM
    Updated 2023-05-04
    with t as (
    select
    hour::date as date,
    decimals,
    token_address,
    avg(price) as price_usd
    from avalanche.core.fact_hourly_token_prices
    group by 1, 2, 3
    ),

    t2 as (
    select
    tx_hash,
    block_timestamp,
    case
    when amount_in_usd is not null then amount_in_usd
    when token_address = null then null
    else (amount_in / pow(10, decimals)) * price_usd
    end as amount_usd,
    origin_from_address as user
    from avalanche.core.ez_dex_swaps
    left join t on date = block_timestamp::date and token_in = token_address
    where amount_usd is not null
    and platform in ('{{ platform }}')
    ),

    t3 as (
    select date_trunc('week', min_date)::date as week,
    count(distinct user) as new_swappers
    from (
    select
    user,
    min(block_timestamp)::date as min_date
    from t2
    group by 1
    )
    Run a query to Download Data