0xHaM-dNEAR Tournament Round 2: Local Government
Updated 2022-08-03Copy Reference Fork
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_tx AS (
SELECT tx_hash
FROM near.core.fact_actions_events_function_call
WHERE method_name IN ('deposit_and_stake', 'unstake', 'unstake_all')
)
, prs_log as (
SELECT
block_timestamp,
tx_hash,
tx_receiver,
tx_signer,
tx:receipt[0]:outcome:logs as logs,
SUBSTRING(logs, CHARINDEX('Total number of shares ', logs), LEN(logs)) as Validator_shares,
TRIM(REGEXP_REPLACE(Validator_shares, '[a-z/-/A-z/./#/*"]', '')) as raw_staked,
try_to_numeric(raw_staked) as amount
FROM near.core.fact_transactions
WHERE tx_hash IN (SELECT tx_hash from stake_tx)
AND block_timestamp::date < CURRENT_DATE - 1
)
, validator AS (
SELECT
block_timestamp as date,
tx_hash,
tx_receiver,
amount,
amount/1e24 as staked_amt
FROM prs_log
WHERE amount is not null
)
, lst_info AS ( SELECT
date,
tx_receiver as validator,
staked_amt,
row_number() over (partition by validator order by date DESC) as rank
FROM validator
WHERE tx_receiver like '%pool%'
Run a query to Download Data