MadiNew validators
    Updated 2022-12-22
    WITH df as (
    select date_trunc('week', a.BLOCK_TIMESTAMP) as date,
    POOL_ADDRESS,
    a.tx_hash, b.tx_signer as staker, b.tx_receiver as validator,
    stake_amount/pow(10,24) as amount, GAS_USED/pow(10,8) as gas_used, --Ggas
    TRANSACTION_FEE/pow(10,24) as tx_fee -- near
    from near.core.dim_staking_actions a join near.core.fact_transactions b on a.tx_hash = b.tx_hash
    where action = 'Stake' and date >= '2022-01-01' and tx_status = 'Success'
    ),

    joindate as (
    SELECT
    validator as new_user,
    min(date) as min_date
    FROM df
    GROUP BY 1 ORDER by 2
    )


    (select min_date as Date, 'New validators' as grroup,
    COUNT(DISTINCT new_user) as count_users
    FROM
    joindate
    GROUP BY 1)

    UNION ALL

    (
    select
    date, 'Total validators' as grroup,
    count(DISTINCT validator) as count_users
    FROM
    df
    GROUP BY 1
    )


    Run a query to Download Data