CryptoIcicleNear-Report-Weekly - Decentralisation Metrics Over Time
Updated 2023-01-14
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 staking_tx AS (
SELECT
block_timestamp,
tx_hash,
tx_receiver,
tx_signer,
tx:actions[0]:FunctionCall:deposit/pow(10,24) near_staked,
tx:receipt[0]:outcome:executor_id as executor_id,
tx:receipt[0]:outcome:logs as logs,
regexp_substr(logs, 'Contract total staked balance is\\W+\\w+') as result,
TRIM(REGEXP_REPLACE(result, '[a-z/-/A-z/./#/*"]', '')) as validator_stake_pre,
try_to_numeric(validator_stake_pre) as amount
FROM near.core.fact_transactions
WHERE tx_hash IN ( SELECT tx_hash FROM near.core.fact_actions_events_function_call WHERE method_name IN ('deposit_and_stake'))
AND block_timestamp::date >= '{{start_date}}' AND block_timestamp::date <= '{{end_date}}'
),
near_validator AS (
SELECT
date_trunc('day', block_timestamp) as date,
tx_hash,
tx_receiver,
amount,
amount/pow(10,24) as near
FROM staking_tx
WHERE amount is not null
AND block_timestamp::date >= '{{start_date}}' AND block_timestamp::date <= '{{end_date}}'
),
VALIDATORS_RANKED AS (
SELECT
date,
tx_receiver,
count(distinct tx_hash) as tx_count, -- no of tx per validator
median(near) as "NEAR Staked", -- median amount staked monthly
sum("NEAR Staked") over (partition by date order by "NEAR Staked" DESC) as cumulative_near_month, -- count cumulative NEAR ordered by top validators
row_number() over (partition by date order by "NEAR Staked" DESC) as rank -- rank for GINI calculation
FROM near_validator
Run a query to Download Data