Ali3NDistribution of Swappers By Their AVAX Balance and Number of Swaps on Pangolin (Avalanche Pharaoh)
    Updated 2025-03-24
    -- forked from Distribution of Swappers By Their AVAX Balance and Number of Swaps on Pangolin (Avalanche Pangolin) @ https://flipsidecrypto.xyz/studio/queries/650a3c78-4d2b-4e40-8a5f-554f3c93d8c4

    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