Ali3NDately Number and Share of Stablecoins vs Nonstablecoin Swaps on Sushi Over Time (Avalanche) - Last X
    Updated 2023-03-14
    with timetable as (
    select case when '{{Time_Frame}}' = 'Last Month' then 30
    when '{{Time_Frame}}' = 'Last 2 Months' then 60
    when '{{Time_Frame}}' = 'Last 3 Months' then 90
    when '{{Time_Frame}}' = 'Last 6 Months' then 180
    when '{{Time_Frame}}' = 'Last Year' then 365
    when '{{Time_Frame}}' = 'All Time' then 5000
    else 5000 end as timeframe),

    maintable as (
    select 'Arbitrum' as chain,
    date_trunc ({{Date_Trunc}},block_timestamp) as date,
    case when (symbol_in in ('DAI','FRAX','LUSD','MAI','TUSD','USD+','USDC','USDT','USX','agEUR','alUSD','hUSDC','jEUR','sUSD','USDD','USDF','PAXG','RSV','XAUT','DGX','MIM') or symbol_in ilike '%usd%')
    and (symbol_out in ('DAI','FRAX','LUSD','MAI','TUSD','USD+','USDC','USDT','USX','agEUR','alUSD','hUSDC','jEUR','sUSD','USDD','USDF','PAXG','RSV','XAUT','DGX','MIM') or symbol_out ilike '%usd%') then 'Stablecoins Pair Swaps'
    when (symbol_in in ('DAI','FRAX','LUSD','MAI','TUSD','USD+','USDC','USDT','USX','agEUR','alUSD','hUSDC','jEUR','sUSD','USDD','USDF','PAXG','RSV','XAUT','DGX','MIM') or symbol_in ilike '%usd%')
    and (symbol_out not in ('DAI','FRAX','LUSD','MAI','TUSD','USD+','USDC','USDT','USX','agEUR','alUSD','hUSDC','jEUR','sUSD','USDD','USDF','PAXG','RSV','XAUT','DGX','MIM') or symbol_out not ilike '%usd%') then 'Swaps From Stablecoins'
    when (symbol_out in ('DAI','FRAX','LUSD','MAI','TUSD','USD+','USDC','USDT','USX','agEUR','alUSD','hUSDC','jEUR','sUSD','USDD','USDF','PAXG','RSV','XAUT','DGX','MIM') or symbol_out ilike '%usd%')
    and (symbol_in not in ('DAI','FRAX','LUSD','MAI','TUSD','USD+','USDC','USDT','USX','agEUR','alUSD','hUSDC','jEUR','sUSD','USDD','USDF','PAXG','RSV','XAUT','DGX','MIM') or symbol_in not ilike '%usd%') then 'Swaps To Stablecoins'
    else 'Non-Stablecoin Swaps' end as swap_type,
    count (distinct tx_hash) as Swaps_Count,
    count (distinct origin_from_address) as Swappers_Count,
    sum (amount_in_usd) as Volume,
    avg (amount_in_usd) as Average_Volume
    from arbitrum.sushi.ez_swaps t1 join timetable t2
    where block_timestamp >= current_date - timeframe
    group by 1,2,3

    union ALL

    select 'Avalanche' as chain,
    date_trunc ({{Date_Trunc}},block_timestamp) as date,
    case when (symbol_in in ('DAI','FRAX','LUSD','MAI','TUSD','USD+','USDC','USDT','USX','agEUR','alUSD','hUSDC','jEUR','sUSD','USDD','USDF','PAXG','RSV','XAUT','DGX','MIM') or symbol_in ilike '%usd%')
    and (symbol_out in ('DAI','FRAX','LUSD','MAI','TUSD','USD+','USDC','USDT','USX','agEUR','alUSD','hUSDC','jEUR','sUSD','USDD','USDF','PAXG','RSV','XAUT','DGX','MIM') or symbol_out ilike '%usd%') then 'Stablecoins Pair Swaps'
    when (symbol_in in ('DAI','FRAX','LUSD','MAI','TUSD','USD+','USDC','USDT','USX','agEUR','alUSD','hUSDC','jEUR','sUSD','USDD','USDF','PAXG','RSV','XAUT','DGX','MIM') or symbol_in ilike '%usd%')
    and (symbol_out not in ('DAI','FRAX','LUSD','MAI','TUSD','USD+','USDC','USDT','USX','agEUR','alUSD','hUSDC','jEUR','sUSD','USDD','USDF','PAXG','RSV','XAUT','DGX','MIM') or symbol_out not ilike '%usd%') then 'Swaps From Stablecoins'
    when (symbol_out in ('DAI','FRAX','LUSD','MAI','TUSD','USD+','USDC','USDT','USX','agEUR','alUSD','hUSDC','jEUR','sUSD','USDD','USDF','PAXG','RSV','XAUT','DGX','MIM') or symbol_out ilike '%usd%')
    Run a query to Download Data