MLDZMNusers4
    Updated 2023-03-31
    with t1 as (select
    distinct SIGNERS[0] as u_zeta
    from solana.core.fact_events
    where SUCCEEDED='TRUE'
    and BLOCK_TIMESTAMP >='2023-01-01'
    and PROGRAM_ID in ('ZETAxsqBRek56DhiGXrn75yj2NHU3aYUnxvHXpkf3aD')
    ),

    t2 as (select
    distinct SIGNERS[0] as u_drift
    from solana.core.fact_events
    where SUCCEEDED='TRUE'
    and BLOCK_TIMESTAMP >= '2023-01-01'
    and PROGRAM_ID in ('dammHkt7jmytvbS3nHTxQNEcP59aE57nxwV21YdqEDNm','dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH')
    )

    select
    case
    when Swapper in (select u_zeta from t1) then 'Zeta'
    when Swapper in (select u_drift from t2) then 'Drift'
    end as users,
    CONCAT(q.ADDRESS_NAME,' - ',z.ADDRESS_NAME) as asset_pairs,
    count(distinct tx_id) as no_swaps,
    count(distinct SWAPPER) as no_trader
    from solana.core.fact_swaps x
    left join solana.core.dim_labels z on x.SWAP_TO_MINT=z.ADDRESS
    join solana.core.dim_labels q on x.SWAP_from_MINT=q.ADDRESS

    where SUCCEEDED='TRUE'
    and asset_pairs is not null
    and BLOCK_TIMESTAMP>='2023-01-01'
    group by 1,2 having users is not null
    QUALIFY DENSE_RANK() OVER (partition by users ORDER BY no_trader DESC) <= 5
    Run a query to Download Data