Ali3NDistribution of Swappers By Their AVAX Balance (Avalanche Pharaoh)
    Updated 2025-03-24
    -- forked from Distribution of Swappers By Their AVAX Balance (Avalanche Pangolin) @ https://flipsidecrypto.xyz/studio/queries/56075730-6a8c-4f9f-b2fe-6b52d281a3ba

    with timetable as (
    select case when '{{TimeFrame}}' = 'Last 7 Days' then 7
    when '{{TimeFrame}}' = 'Last 30 Days' then 30
    when '{{TimeFrame}}' = 'Last 60 Days' then 60
    when '{{TimeFrame}}' = 'Last 90 Days' then 90
    when '{{TimeFrame}}' = 'Last 180 Days' then 180
    when '{{TimeFrame}}' = 'Last 365 Days' then 365
    when '{{TimeFrame}}' = 'All Time' then 5000
    else 5000 end as timeframe),

    maintable as (
    select origin_from_address,
    count (distinct tx_hash) as Swaps_Count
    from avalanche.defi.ez_dex_swaps t1
    join timetable
    where platform ilike '%pharaoh%'
    and block_timestamp >= CURRENT_DATE - timeframe
    group by 1),

    receivetable as (
    select to_address as receiver,
    sum (amount) as Received_Volume
    from avalanche.core.ez_native_transfers
    where to_address in (select distinct origin_from_address from maintable)
    group by 1),

    sendtable as (
    select from_address as sender,
    sum (amount) as sent_volume
    from avalanche.core.ez_native_transfers
    where from_address in (select distinct origin_from_address from maintable)
    group by 1),

    balancetable as (
    Auto-refreshes every 12 hours
    QueryRunArchived: QueryRun has been archived