pinehearstSweat Economy - 3. Staking Metrics Overtime
    Updated 2025-02-03
    with logs AS (
    SELECT
    block_timestamp,
    tx_hash,
    status_value,
    replace(value, 'EVENT_JSON:') as json,
    regexp_substr(status_value, 'Success') as reg_success,
    try_parse_json(json):standard as standard,
    try_parse_json(json):event as event,
    try_parse_json(json):data as data_logs
    FROM near.core.fact_receipts,
    table(flatten(input => logs))
    WHERE 1=1
    AND receiver_id = 'token.sweat'
    AND reg_success is not null
    -- AND tx_hash = '4nhKMTp6e6cv4tqbCNXAZuHUuidU7pUvgSmxVZS6EzUB' -- ft_transfer
    -- AND tx_hash = '4Wr1y27zQsEoCK7pCwemfABxe3nccE8cve4SWGS4gsHJ' -- ft_mint
    ),
    sweat_transfer AS (
    SELECT
    block_timestamp,
    tx_hash,
    standard,
    event,
    value:amount/pow(10,18) as amount,
    value:owner_id as owner_id,
    value:old_owner_id as old_owner_id, -- ft_transfer
    value:new_owner_id as new_owner_id, -- ft_transfer
    -- case when event = 'ft_mint' then 'mint' when event = 'ft_transfer' then old_owner_id else 'null' end as from_address,
    nvl(old_owner_id, 'mint') as from_address,
    nvl(new_owner_id, owner_id) as to_address
    FROM logs,
    table(flatten(input => data_logs))
    WHERE amount > 0
    ),
    new_stakers AS (
    QueryRunArchived: QueryRun has been archived