Eman-RazSwaps Over time
    Updated 2024-05-29
    with tab1 as (select date_trunc('{{Time_Frame}}',block_timestamp) as date, sum(amount_in)/pow(10,6) as selling_volume,
    count(distinct tx_id) as selling_count, count(distinct swapper) as seller_count
    from sei.defi.fact_dex_swaps
    where currency_in='usei' and tx_succeeded='true'
    group by 1),

    tab2 as (select date_trunc('{{Time_Frame}}',block_timestamp) as date, sum(amount_out)/pow(10,6) as buying_volume,
    count(distinct tx_id) as buying_count, count(distinct swapper) as buyer_count
    from sei.defi.fact_dex_swaps
    where currency_out='usei' and tx_succeeded='true'
    group by 1)

    select tab1.date as "Date", selling_volume+buying_volume as "Swap Volume",
    sum("Swap Volume") over (order by "Date" asc) as "Total Swap Volume",
    -selling_volume AS "Selling Volume", buying_volume AS "Buying Volume",
    buying_volume-selling_volume as "Net Volume(SEI)", SELLING_COUNT AS "Selling Count",
    buying_count as "Buying Count", selling_count+buying_count as "Swap Count",
    seller_count as "Seller Count", buyer_count as "Buyer Count"
    from tab1 left join tab2 on tab1.date=tab2.date
    order by 1
    QueryRunArchived: QueryRun has been archived