RayyykNEAR Staked 1
    Updated 2023-05-18
    with table_1 as (select date_trunc ('day', block_timestamp) as day,
    sum(stake_amount/1e24) as near_staked,
    sum(near_staked) over (order by day) as cumu_near_staked,
    count(distinct(tx_hash)) as stake_tx,
    sum(stake_tx) over (order by day) as cumu_stake_tx,
    count(distinct(tx_signer)) as stake_wallets
    from near.core.dim_staking_actions
    where action = 'Stake'
    and block_timestamp >= '2022-11-01'
    group by 1),

    table_2 as (select date_trunc ('day', block_timestamp) as day,
    sum(stake_amount/1e24) as near_unstaked,
    sum(near_unstaked) over (order by day) as cumu_near_unstaked,
    count(distinct(tx_hash)) as unstake_tx,
    sum(unstake_tx) over (order by day) as cumu_unstake_tx,
    count(distinct(tx_signer)) as unstake_wallets
    from near.core.dim_staking_actions
    where action = 'Unstake'
    and block_timestamp >= '2022-11-01'
    group by 1)

    select a.day,
    near_staked,
    near_unstaked,
    near_staked - near_unstaked as net_staked,
    cumu_near_staked,
    cumu_near_unstaked,
    cumu_near_staked - cumu_near_unstaked as cumu_net_staked,
    case
    when net_staked > 0 then 'Stake'
    else 'Unstake'
    end as net_action
    from table_1 a
    join table_2 b on a.day = b.day
    order by 1 desc
    Run a query to Download Data