Sbhn_NPtop 20 whales transfer activity
    Updated 2023-02-16
    with receive as (select
    distinct TX_RECEIVER as user1,
    sum(DEPOSIT/pow(10,24)) as total_recieved
    from near.core.fact_transfers
    where STATUS = 'TRUE'
    group by 1),

    send as (select
    distinct TX_SIGNER as user2,
    sum(DEPOSIT/pow(10,24)) as total_sent
    from near.core.fact_transfers
    where STATUS = 'TRUE'
    and TX_SIGNER in (select user1 from receive)
    group by 1),

    final as (select
    distinct user1 as whales,
    total_recieved - total_sent as balance
    from receive s left join send b on s.user1 = b.user2
    where total_recieved>total_sent
    order by 2 DESC
    limit 20
    )

    select date_trunc('month',block_timestamp) as date,
    project_name,
    count(DISTINCT tx_hash) as transfers,
    count(DISTINCT tx_signer) as users,
    sum(deposit/pow(10,24)) as volume,
    rank() over (partition by date order by transfers desc) as r
    from near.core.fact_transfers
    join near.core.dim_address_labels on tx_receiver=address
    where status = 'TRUE'
    and tx_signer in (select whales from final)
    group by 1,2
    qualify r<=5
    Run a query to Download Data