Afonso_Diazsushiswap-gnosis
    Updated 2023-03-18
    with t as (
    select
    origin_from_address as new_swapper,
    min(block_timestamp::date) as min_date
    from gnosis.sushi.ez_swaps
    where (
    symbol_in in ('FRAX', 'LUSD', 'BUSD', 'TUSD', 'USDN', 'GUSD', 'USDC', 'DAI', 'USDP', 'FEI', 'sUSD', 'AMUSDC', 'USDD', 'USDT', 'MIM') or
    symbol_out in ('FRAX', 'LUSD', 'BUSD', 'TUSD', 'USDN', 'GUSD', 'USDC', 'DAI', 'USDP', 'FEI', 'sUSD', 'AMUSDC', 'USDD', 'USDT', 'MIM')
    )
    group by 1
    ),

    t2 as (
    select
    min_date,
    count(distinct new_swapper) as new_swappers
    from t
    group by 1
    )

    select
    block_timestamp::date as day,
    count(distinct tx_hash) as swaps,
    count(distinct origin_from_address) as swappers,
    new_swappers,
    sum(iff(symbol_in in ('FRAX', 'LUSD', 'BUSD', 'TUSD', 'USDN', 'GUSD', 'USDC', 'DAI', 'USDP', 'FEI', 'sUSD', 'AMUSDC', 'USDD', 'USDT', 'MIM'), amount_in, amount_out)) as swap_volume_usd,
    sum(swaps) over (order by day) as cumulative_swaps,
    sum(tx_fee) as fee_xdai,
    avg(tx_fee) as average_fee_xdai,
    sum(swap_volume_usd) over (order by day) as cumulative_swap_volume_usd,
    sum(new_swappers) over (order by day) as cumulative_new_swappers
    from gnosis.sushi.ez_swaps a
    join gnosis.core.fact_transactions b
    using (tx_hash)
    join t2 on block_timestamp::date = min_date
    where (
    Run a query to Download Data