pinehearstNEAR Local Government - User Staking Status
Updated 2022-08-28
99
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
›
⌄
with stake AS (
SELECT
tx_signer,
count(distinct tx_hash) as stake_count,
min(date(block_timestamp)) as first_stake,
max(date(block_timestamp)) as last_stake,
sum(tx:actions[0]:FunctionCall:deposit/pow(10,24)) as near_staked
FROM near.core.fact_transactions
WHERE tx_hash IN ( SELECT tx_hash
FROM near.core.fact_actions_events_function_call
WHERE method_name = 'deposit_and_stake')
GROUP BY 1
),
unstake_raw AS (
SELECT
a.block_timestamp as block_timestamp_unstake,
a.tx_hash as unstake_tx,
tx_receiver, -- validators
tx_signer,
replace(args, '\\') as logs, -- remove // | convert variant | parse json
try_parse_json(logs):amount as amount,
case when args::string LIKE '%,%' then 1 else 0 end as commas
FROM near.core.fact_actions_events_function_call a
LEFT JOIN near.core.fact_transactions b ON a.tx_hash = b.tx_hash
WHERE method_name = 'unstake' AND tx_receiver LIKE '%.pool%'
),
unstake AS (
SELECT
tx_signer as unstaker,
count(distinct unstake_tx) as unstake_count,
min(date(block_timestamp_unstake)) as first_unstake,
max(date(block_timestamp_unstake)) as last_unstake,
sum(amount/pow(10,24)) as near_unstaked
FROM unstake_raw
WHERE commas = 0
GROUP BY 1
Run a query to Download Data