afonsorETH by by type
    Updated 2023-01-14
    with t as (
    select
    a.hour::date as day,
    avg (a.price) as weth_price_usd,
    avg (b.price) as token_price_usd
    from ethereum.core.fact_hourly_token_prices a
    join ethereum.core.fact_hourly_token_prices b
    on a.hour::date = b.hour::date
    where a.token_address = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' --WETH
    and b.token_address = '0xae78736cd615f374d3085123a210448e74fc6393' --rETH
    group by 1
    ),

    t2 as (
    select day,
    avg(weth_price_usd) as weth_price_usd,
    avg(token_price_usd) as token_price_usd,
    avg(token_price_usd / weth_price_usd) as diff_ratio
    from t
    group by day
    )

    select
    case
    when diff_ratio > 1 then 'Depeg: Higher Than Weth'
    when diff_ratio < 1 then 'Depeg: Lower Than Weth'
    else 'Peg'
    end as type,
    count(day) as total_dates
    from t2
    group by type
    Run a query to Download Data