cypherNEAR daily Staked
Updated 2023-03-15
999
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
›
⌄
-- select validators
with validators as (SELECT
distinct(pool_address) as validator
from near.core.dim_staking_actions
),
-- select all staking updates for every validator
stakes as (select
tx_hash,
block_timestamp,
date_trunc('day', block_timestamp) as date,
receiver_id,
regexp_substr_all(to_varchar(logs), 'is(.{50})') as balance_array,
balance_array[array_size(balance_array)-1] as dirty_amount,
regexp_substr(dirty_amount, '[0-9]+') as clean_amount,
clean_amount::int/1e24 as total_staked
from near.core.fact_receipts
where receiver_id in (select validator from validators)
and receipt_index = '0'
and contains(to_varchar(logs), 'Contract total staked balance is')),
-- select the latest update for every validator
max_time as (select
receiver_id as validator,
max(block_timestamp) as max
from stakes
group by receiver_id
),
-- calculate the current amount staked based on the latest updates
max_time_balance as (
select m.*,
s.total_staked,
sum(s.total_staked) over () as total_stake
from max_time m, stakes s
where m.max = s.block_timestamp
Run a query to Download Data