Moetp DIST
    Updated 2024-03-18
    with price as (
    select
    HOUR :: Date as day,
    avg(PRICE) as price
    from
    ethereum.price.ez_hourly_token_prices
    where
    token_address ilike '0x576e2BeD8F7b46D34016198911Cdf9886f78bea7'
    group by
    1
    ),
    mid as (
    select
    a.*,
    case
    when amount_out_usd is null then amount_out * c.price
    else amount_out_usd
    end as buy_usd
    from
    ethereum.defi.ez_dex_swaps a
    left outer join price c on a.BLOCK_TIMESTAMP :: date = c.day
    where
    token_out ilike '0x576e2BeD8F7b46D34016198911Cdf9886f78bea7'
    and amount_out_usd is not null
    and amount_out_usd > 0
    and block_timestamp :: date >= CURRENT_DATE - 90
    ),
    middle as (
    select
    tx_hash,
    sender as swapper,
    buy_usd as USD_Volume
    from
    mid
    )
    select
    QueryRunArchived: QueryRun has been archived