omer93Torneig R5 1.3
    Updated 2022-12-08
    --USD volume, # of swaps volume, # of wallets swapping, size of swaps
    --Users should also be able to understand the popularity of swap programs(what exchange) on each change and how the swap programs compare across chains
    --The % of market share in defi swaps each chain holds
    --What percent of a chain's DeFi swap volume is stablecoins
    --Most popular times to perform swaps
    -- Flow, Ethereum, Solana, Algorand, Osmosis, NEAR, and THORChain

    WITH
    algo as (
    select
    case when asset_name in ('AMUSDC','BUSD','DAI','PUSD','TUSD','USDC','USDT','UST','alUSD','cDAI','sUSD','sUSD','STBL')
    then 'Stablecoin' else 'Others' end as type,
    --collection_name as collection,
    count(distinct swapper) as total_unique_swapper,
    count(distinct TX_GROUP_ID) as total_swaps,
    sum(swap_to_amount*price_usd) as total_volume,
    avg(swap_to_amount*price_usd) average_volume_swapped,
    median(swap_to_amount*price_usd) median_volume_swapped,
    min(swap_to_amount*price_usd) min_volume_swapped,
    max(swap_to_amount*price_usd) max_volume_swapped
    from algorand.defi.fact_swap x
    join algorand.defi.ez_price_swap y on trunc(x.block_timestamp,'hour')=y.block_hour and x.SWAP_TO_ASSET_ID=y.asset_id
    --join algorand.nft.ez_nft_asset y on x.nft_asset_id=y.nft_asset_id
    where swap_to_amount != 0
    and block_timestamp::date >= current_date - INTERVAL '{{Number}} {{Period}}' group by 1
    ),
    flow_prices as (
    SELECT
    date_trunc('day',timestamp) as days,
    token_contract,symbol,
    avg(price_usd) as price_usd
    from flow.core.fact_prices
    group by 1,2,3
    ),
    flow as (
    select
    Run a query to Download Data