Moe2 opdex
    Updated 2022-10-26
    with base as (select
    tx_hash
    from optimism.core.fact_event_logs
    where origin_to_address in ('0xe592427a0aece92de3edee1f18e0157c05861564','0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45')
    and event_name = 'Swap'
    and tx_status = 'SUCCESS'
    )

    , prices as (
    select
    HOUR::date as days,
    symbol,TOKEN_ADDRESS,
    avg(price) as price
    from optimism.core.fact_hourly_token_prices
    group by 1,2,3
    ) ,

    fin as (select
    b.SYMBOL,decimals,EVENT_INPUTS:value as raw_amount,price,(price*raw_amount)/pow(10,decimals) as amount_usd,l.*
    from
    optimism.core.fact_event_logs l,optimism.core.dim_contracts b, prices p
    where
    event_name = 'Transfer' and tx_hash in (select tx_hash from base) and EVENT_INDEX=2
    and CONTRACT_ADDRESS = b.address and BLOCK_TIMESTAMP::date = days and CONTRACT_ADDRESS = p.TOKEN_ADDRESS
    )

    select

    count (distinct tx_hash) as num_swaps,
    count (distinct origin_from_address) as num_swappers,
    sum (amount_usd) as swap_vol_usd,
    avg (amount_usd) as Average_swap_vol_usd,
    median (amount_usd) Median_swap_vol_usd,
    min (amount_usd) as Minimum_swap_vol_usd,
    max (amount_usd) as Maximum_swap_vol_usd,

    Run a query to Download Data