kiacryptoUsers who swapped stETH to ETH, gained or loss?
    Updated 2022-06-15
    with amount as (
    select date_trunc('day', block_timestamp) as date, sum(amount_out) as swap_amount
    from ethereum.core.ez_dex_swaps
    where token_in = '0xae7ab96520de3a18e5e111b5eaab095312d7fe84' and token_out = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
    group by 1
    ),

    steth as (
    select date_trunc('day', hour) as date, avg(price) as steth
    from ethereum.token_prices_hourly
    where token_address = '0xae7ab96520de3a18e5e111b5eaab095312d7fe84'
    group by 1
    ),

    eth as (
    select date_trunc('day', hour) as date, avg(price) as eth
    from ethereum.token_prices_hourly
    where token_address = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
    group by 1
    ),
    alll as (
    select a.date as date, swap_amount, eth/steth as ratio, ratio * swap_amount as new_amount, new_amount - swap_amount as gain_in_eth
    from amount a, steth s, eth e
    where a.date = s.date and s.date = e.date
    )

    select case when gain_in_eth >= 0 then 'Gain' else 'loss' end as dis, count(*)
    from alll
    group by 1
    Run a query to Download Data