with delegated_txns as (
SELECT
COUNT(DISTINCT tx_signer) as count_of_stakers,
COUNT(DISTINCT events.TX_HASH) as count_of_txns,
SUM(txns.tx:actions[0]:FunctionCall:deposit/pow(10,24)) volume_of_staked_near,
SUM(txns.tx:actions[0]:FunctionCall:deposit/pow(10,24))/COUNT(DISTINCT tx_signer) as per_staker_near_value
FROM near.core.fact_actions_events_function_call events
JOIN near.core.fact_transactions txns
ON events.tx_hash = txns.tx_hash
WHERE method_name = 'deposit_and_stake'
AND events.block_timestamp::date < CURRENT_DATE
AND txns.block_timestamp::date < CURRENT_DATE
)
select * from delegated_txns