adriaparcerisasavax stable
    Updated 2024-11-25
    with
    ins as (
    SELECT
    trunc(block_timestamp,'day') as date,
    'Avalanche' as blockchain,
    symbol_in as stablecoin,
    count(distinct tx_hash) as swaps,
    count(distinct origin_from_address) as swappers,
    sum(amount_in_usd) as volume_swapped_usd,
    avg(amount_in_usd) as avg_volume_swapped_usd
    from avalanche.defi.ez_dex_swaps
    where symbol_in in ('AMUSDC','BUSD','DAI','PUSD','TUSD','USDC','USDT','UST','alUSD','cDAI','sUSD','sUSD','USDD','USDN', 'USDT.e','USDC.e')
    and amount_in_usd is not null
    group by 1,2,3
    ),
    outs as (
    SELECT
    trunc(block_timestamp,'day') as date,
    'Avalanche' as blockchain,
    symbol_out as stablecoin,
    count(distinct tx_hash) as swaps,
    count(distinct origin_from_address) as swappers,
    sum(amount_out_usd) as volume_swapped_usd,
    avg(amount_out_usd) as avg_volume_swapped_usd
    from avalanche.defi.ez_dex_swaps
    where symbol_out in ('AMUSDC','BUSD','DAI','PUSD','TUSD','USDC','USDT','UST','alUSD','cDAI','sUSD','sUSD','USDD','USDN', 'USDT.e','USDC.e')
    and amount_out_usd is not null
    group by 1,2,3
    ),

    nets as (
    SELECT
    ifnull(x.date,y.date) as date,
    ifnull(x.blockchain,y.blockchain) as blockchain,
    ifnull(x.stablecoin,y.stablecoin) as stablecoin,
    ifnull(x.swaps,0)-ifnull(y.swaps,0) as net_swaps,
    QueryRunArchived: QueryRun has been archived