Ali3NDately Thorchain Assets Swaps Stats Specific Chain Over Time
    Updated 2024-10-07
    -- Credit: https://flipsidecrypto.xyz/Rayyyk/q/BH8Jf0qCGZTF/top-5-largest-swap-last-week

    with maintable as (
    select split(from_asset, '-')[0] as from_assets,
    case when from_assets ilike '%/%' then split(from_assets, '/')[1]
    else split(from_assets, '.')[1] end as from_asset_names,
    split(to_asset, '-')[0] as to_assets,
    case when to_assets ilike '%/%' then split(to_assets, '/')[1]
    else split(to_assets, '.')[1] end as to_asset_names,
    *
    from thorchain.defi.fact_swaps
    where block_timestamp >= '{{Start_Date}}' and block_timestamp <= '{{End_Date}}'
    and blockchain ilike '{{Blockchain}}')

    /*avapricet as (
    select hour::date as day,
    symbol,
    avg (price) as usdprice
    from avalanche.price.ez_prices_hourly
    group by 1,2)*/


    select date_Trunc ({{Time_Interval}},block_timestamp) as date,
    concat (from_asset_names,' => ',to_asset_names) as Swap_Pair,
    count (Distinct tx_Id) as Swaps,
    count (distinct from_address) as Swappers,
    sum (from_amount_usd) as Volume,
    avg (from_amount_usd) as Average_Volume,
    round (swaps / swappers) as Swaps_Per_Trader,
    volume / swappers as Swap_Volume_Per_Trader,
    sum (swaps) over (partition by swap_pair order by date) as Cumulative_Swaps,
    sum (Volume) over (partition by swap_pair order by date) as Cumulative_Volume
    from maintable
    group by 1,2
    order by 1 desc
    QueryRunArchived: QueryRun has been archived