Afonso_DiazBy Swap Pair
    Updated 2025-04-14
    with

    main as (
    select
    tx_hash,
    block_timestamp,
    trader as swapper,
    symbol_in,
    symbol_out,
    platform,
    iff(amount_in_usd < 1e6, amount_in_usd, amount_out_usd) as amount_usd
    from
    near.defi.ez_dex_swaps a
    where
    tx_hash in (
    select distinct tx_hash
    from near.core.fact_actions_events_function_call b
    where try_parse_json(args:msg):referral_id = 'owner.herewallet.near'
    and a.tx_hash = b.tx_hash and a.block_timestamp = b.block_timestamp
    )
    )

    select
    symbol_in || ' -> ' || symbol_out as token_pair,
    COUNT(DISTINCT tx_hash) AS unique_swaps,
    COUNT(DISTINCT swapper) AS unique_swappers,
    SUM(amount_usd) AS total_swapped_volume,
    AVG(amount_usd) AS avg_swapped_volume
    from
    main
    where
    amount_usd > 0
    and token_pair is not null
    group by 1
    order by total_swapped_volume desc
    limit 10
    QueryRunArchived: QueryRun has been archived