ZSaed2.6 Staking data Top Users
    Updated 2023-03-29
    -- forked from 8bdf6de0-b6b1-4857-810a-ae557df0fa72


    with users as (select
    TX_HASH, actions:predecessor_id as TX_SIGNER , BLOCK_TIMESTAMP
    from
    near.core.fact_receipts
    where
    BLOCK_TIMESTAMP::date > '2022-12-18'
    and RECEIVER_ID = 'nethmap.near'
    and ACTIONS:receipt:Action:actions[0]:FunctionCall:method_name::string = 'set'
    )
    , receipts as (
    select a.*, a.actions:predecessor_id as TX_SIGNER
    from near.core.fact_receipts a JOIN users b on (a.actions:predecessor_id = b.TX_SIGNER or a.RECEIVER_ID= b.TX_SIGNER)
    where
    a.BLOCK_TIMESTAMP::date> '2022-12-18'
    )
    ,fail as (
    select * from near.core.fact_receipts
    where tx_hash in (select tx_hash from receipts )
    and STATUS_VALUE:Failure is not null
    ),
    success_receipts as (
    select * from receipts where tx_hash not in (select tx_hash from fail )
    )
    , call as (
    select a.*, b.RECEIVER_ID,b.TX_SIGNER
    from near.core.fact_actions_events_function_call a JOIN success_receipts b on a.tx_hash = b.tx_hash
    where a.BLOCK_TIMESTAMP::date> '2022-12-18'
    )
    -- find date of add_key tarnsaction for each users
    ,add_key as (--find wallet that hava add key
    select
    TX_HASH, BLOCK_TIMESTAMP,RECEIVER_ID
    Run a query to Download Data