binhachonSwap Increase on May 11 + 12 - #4
    Updated 2022-06-09
    with swap_stats as (
    select
    date_trunc('hour', block_timestamp) as time,
    swap_from_asset_id,
    swap_to_asset_id,
    sum(swap_from_amount) as swap_from_amount,
    sum(swap_to_amount) as swap_to_amount,
    count(*) as number_of_swaps
    from flipside_prod_db.algorand.swaps
    where time >= '2022-05-09'
    and time <= '2022-05-14'
    group by 1, 2 , 3
    ),
    swap_stats_1 as (
    select
    swap_stats.*,
    p1.asset_name as swap_from_asset_name,
    p1.price_usd as swap_from_price,
    swap_from_amount * swap_from_price as swap_from_amount_usd,
    p2.asset_name as swap_to_asset_name,
    p2.price_usd as swap_to_price,
    swap_to_amount * swap_to_price as swap_to_amount_usd,
    case
    when (swap_from_price is not null and swap_to_price is not null) then (swap_from_amount_usd + swap_to_amount_usd)/2
    when (swap_from_price is not null and swap_to_price is null) then swap_from_amount_usd
    else swap_to_amount_usd end
    as volume_usd
    from swap_stats
    left join flipside_prod_db.algorand.prices_swap p1 on (p1.block_hour = time and swap_from_asset_id = p1.asset_id)
    left join flipside_prod_db.algorand.prices_swap p2 on (p2.block_hour = time and swap_to_asset_id = p2.asset_id)
    ),
    swap_stats_2 as (
    select
    time,
    swap_from_asset_name as asset,
    swap_from_amount_usd as selling_volume,
    Run a query to Download Data