gigiokobaTotal on Ref copy
    Updated 2024-11-03
    -- forked from Masi / Total on Ref @ https://flipsidecrypto.xyz/Masi/q/EH2Q5go__5wE/total-on-ref

    with tb1 as ( select trunc(block_timestamp,'hour') as hourly,
    platform,
    tx_hash,
    trader,
    amount_in_usd,
    amount_out_usd,
    SYMBOL_OUT,
    amount_in,
    amount_out,
    symbol_in,
    TOKEN_OUT_CONTRACT,
    TOKEN_IN_CONTRACT,
    case when amount_in_usd is null then amount_out_usd else amount_in_usd end as vol
    from near.defi.ez_dex_swaps
    where block_timestamp::date >= '2024-01-01'
    and platform in ('v1.jumbo_exchange.near')
    )
    ,
    tb2 as ( select hour,
    token_address,
    symbol,
    avg(price) as avg_price
    from crosschain.price.ez_prices_hourly
    where blockchain = 'near'
    group by 1,2,3
    UNION
    select HOUR,
    'wrap.near' as token_address,
    'wNEAR' as symbol,
    avg(price) as avg_price
    from near.price.ez_prices_hourly
    where symbol = 'WNEAR'
    group by 1,2,3 )
    ,
    QueryRunArchived: QueryRun has been archived