omer93Torneig R5 3
    Updated 2022-12-06
    --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 distinct swapper as wallet,
    sum(swap_to_amount*price_usd) as total_amount,
    count(distinct tx_group_id) as transactions
    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
    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,
    avg(price_usd) as price_usd
    from flow.core.fact_prices
    group by 1,2
    ),
    flow as (
    select distinct trader as wallet,
    sum(token_out_amount*price_usd) as total_amount,
    count(distinct tx_id) as transactions
    from flow.core.ez_swaps x
    join flow_prices y on trunc(x.block_timestamp,'day')=y.days and x.TOKEN_OUT_CONTRACT=y.token_contract
    where token_out_amount != 0
    and block_timestamp::date >= current_date - INTERVAL '{{Number}} {{Period}}' group by 1
    ),
    near_prices as (
    SELECT
    Run a query to Download Data