kidaConnext Bridge Fee (Optimism)
    Updated 2023-01-14
    with
    weth_prices as (
    select
    date(block_timestamp) as date,
    replace(feed_name, ' / USD') as symbol,
    median(coalesce(latest_answer_adj, latest_answer_unadj / pow(10,8))) as price --using median cause there will be some nulls / zeroes
    from ethereum.chainlink.ez_oracle_feeds
    where feed_category = 'Cryptocurrency (USD pairs)'
    and feed_name in ('ETH / USD')
    group by 1,2
    order by 1
    ),
    decimals as (
    select
    token_in as contract_address,
    median(case when event_inputs:amount1In::decimal < event_inputs:amount0In::decimal then event_inputs:amount0In else event_inputs:amount1In end / amount_in) as decimals
    from bsc.sushi.ez_swaps s
    join bsc.core.fact_event_logs t
    on t.event_index = s.event_index and s.tx_hash = t.tx_hash
    group by 1
    ),

    prices as (
    select
    date(hour) as date,
    decimals,
    symbol,
    token_address,
    avg(price) as price
    from optimism.core.fact_hourly_token_prices
    group by date, decimals, symbol, token_address
    ),
    origin_deposits as (
    select
    Run a query to Download Data