cyphernear net delegations
    Updated 2023-04-13
    with staked as (select
    date_trunc('day', block_timestamp) as date,
    sum(stake_amount/1e24) as delegations,
    count(distinct(tx_signer)) as distinct_delegators
    from near.core.dim_staking_actions
    where action = 'Stake'
    group by date
    ),

    unstaked as (select
    date_trunc('day', block_timestamp) as date,
    sum(stake_amount/1e24) as undelegations,
    count(distinct(tx_signer)) as distinct_undelegators
    from near.core.dim_staking_actions
    where action = 'Unstake'
    group by date )

    select
    date(s.date) as date,
    s.distinct_delegators,
    u.distinct_undelegators,
    s.distinct_delegators - u.distinct_undelegators as net_n_delegators,
    s.delegations,
    u.undelegations * (-1) as undelegations,
    s.delegations - u.undelegations as net_delegations
    from staked s, unstaked u
    where s.date = u.date
    Run a query to Download Data