mirror of
https://github.com/FlipsideCrypto/near-models.git
synced 2026-02-06 11:26:52 +00:00
Merge pull request #112 from eevui/delegation-actions
Delegation actions
This commit is contained in:
commit
fd5f648aa6
12
models/core/core__dim_staking_actions.sql
Normal file
12
models/core/core__dim_staking_actions.sql
Normal file
@ -0,0 +1,12 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = true
|
||||
) }}
|
||||
|
||||
with staking_actions as (
|
||||
select
|
||||
*
|
||||
from {{ ref('silver__staking_actions') }}
|
||||
)
|
||||
|
||||
select * from staking_actions
|
||||
73
models/core/core__dim_staking_actions.yml
Normal file
73
models/core/core__dim_staking_actions.yml
Normal file
@ -0,0 +1,73 @@
|
||||
version: 2
|
||||
|
||||
models:
|
||||
- name: core__dim_staking_actions
|
||||
description: |-
|
||||
This table records all the staking and delegation transactions occurring in NEAR.
|
||||
|
||||
Be aware, however, not all transactions here necessarily actually contribute to securing the NEAR network.
|
||||
Each epoch can have a different set of validators.
|
||||
|
||||
columns:
|
||||
- name: tx_hash
|
||||
description: "{{ doc('tx_hash') }}"
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- STRING
|
||||
- VARCHAR
|
||||
|
||||
- name: block_timestamp
|
||||
description: "{{ doc('block_timestamp') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- TIMESTAMP_NTZ
|
||||
|
||||
- name: pool_address
|
||||
description: "{{ doc('staking_pool_address') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- STRING
|
||||
- VARCHAR
|
||||
|
||||
- name: tx_signer
|
||||
description: "{{ doc('tx_signer') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- STRING
|
||||
- VARCHAR
|
||||
|
||||
- name: stake_amount
|
||||
description: "{{ doc('staking_stake_amount') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- NUMBER
|
||||
|
||||
- name: action
|
||||
description: "{{ doc('staking_action') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- STRING
|
||||
- VARCHAR
|
||||
- dbt_expectations.expect_column_values_to_be_in_set:
|
||||
value_set: ['Stake', 'Unstake']
|
||||
|
||||
- name: _inserted_timestamp
|
||||
description: "{{ doc('_inserted_timestamp') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- TIMESTAMP_NTZ
|
||||
5
models/descriptions/staking_action.md
Normal file
5
models/descriptions/staking_action.md
Normal file
@ -0,0 +1,5 @@
|
||||
{% docs staking_action %}
|
||||
|
||||
The staking action performed in this transaction. Can be `"Stake"` or `"Unstake"`.
|
||||
|
||||
{% enddocs %}
|
||||
@ -1,5 +1,5 @@
|
||||
{% docs staking_pool_address %}
|
||||
|
||||
The address of the staking pool.
|
||||
The pool address delegated into.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
5
models/descriptions/staking_stake_amount.md
Normal file
5
models/descriptions/staking_stake_amount.md
Normal file
@ -0,0 +1,5 @@
|
||||
{% docs staking_stake_amount %}
|
||||
|
||||
The amount staked or delegated toward securing the NEAR network.
|
||||
|
||||
{% enddocs %}
|
||||
141
models/silver/silver__staking_actions.sql
Normal file
141
models/silver/silver__staking_actions.sql
Normal file
@ -0,0 +1,141 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental = 'merge',
|
||||
cluster_by = ['block_timestamp'],
|
||||
unique_key = 'tx_hash'
|
||||
) }}
|
||||
|
||||
with actions_events_function_call as (
|
||||
select
|
||||
tx_hash,
|
||||
method_name,
|
||||
_inserted_timestamp
|
||||
from {{ ref('silver__actions_events_function_call') }}
|
||||
where {{ incremental_load_filter('_inserted_timestamp') }}
|
||||
and method_name in (
|
||||
'deposit_and_stake',
|
||||
'stake',
|
||||
'unstake',
|
||||
'unstake_all'
|
||||
)
|
||||
),
|
||||
|
||||
base_txs as (
|
||||
select
|
||||
*
|
||||
from {{ ref('silver__transactions') }}
|
||||
where {{ incremental_load_filter('_inserted_timestamp') }}
|
||||
),
|
||||
|
||||
txs as (
|
||||
select
|
||||
*
|
||||
from base_txs
|
||||
where (tx_receiver like '%.pool.near' or tx_receiver like '%.poolv1.near')
|
||||
),
|
||||
|
||||
pool_txs as (
|
||||
select
|
||||
txs.tx_hash as tx_hash,
|
||||
block_timestamp,
|
||||
tx_receiver,
|
||||
tx_signer,
|
||||
tx,
|
||||
method_name,
|
||||
txs._inserted_timestamp as _inserted_timestamp
|
||||
from txs
|
||||
inner join actions_events_function_call
|
||||
on txs.tx_hash = actions_events_function_call.tx_hash
|
||||
),
|
||||
|
||||
deposit_and_stake_txs as (
|
||||
select
|
||||
tx_hash,
|
||||
block_timestamp,
|
||||
tx_receiver as pool_address,
|
||||
tx_signer,
|
||||
regexp_substr(array_to_string(tx:receipt[0]:outcome:logs, ','), 'staking (\\d+)', 1, 1, 'e')::number as stake_amount,
|
||||
'Stake' as action,
|
||||
_inserted_timestamp
|
||||
from pool_txs
|
||||
where method_name = 'deposit_and_stake'
|
||||
and tx:receipt[0]:outcome:status:SuccessValue is not null
|
||||
),
|
||||
|
||||
stake_txs as (
|
||||
select
|
||||
tx_hash,
|
||||
block_timestamp,
|
||||
tx_receiver as pool_address,
|
||||
tx_signer,
|
||||
regexp_substr(array_to_string(tx:receipt[0]:outcome:logs, ','), 'staking (\\d+)', 1, 1, 'e')::number as stake_amount,
|
||||
'Stake' as action,
|
||||
_inserted_timestamp
|
||||
from pool_txs
|
||||
where method_name = 'stake'
|
||||
and tx:receipt[0]:outcome:status:SuccessValue is not null
|
||||
),
|
||||
|
||||
stake_all_txs as (
|
||||
select
|
||||
tx_hash,
|
||||
block_timestamp,
|
||||
tx_receiver as pool_address,
|
||||
tx_signer,
|
||||
regexp_substr(array_to_string(tx:receipt[0]:outcome:logs, ','), 'staking (\\d+)', 1, 1, 'e')::number as stake_amount,
|
||||
'Stake' as action,
|
||||
_inserted_timestamp
|
||||
from pool_txs
|
||||
where method_name = 'stake_all'
|
||||
and tx:receipt[0]:outcome:status:SuccessValue is not null
|
||||
),
|
||||
|
||||
unstake_txs as (
|
||||
select
|
||||
tx_hash,
|
||||
block_timestamp,
|
||||
tx_receiver as pool_address,
|
||||
tx_signer,
|
||||
regexp_substr(array_to_string(tx:receipt[0]:outcome:logs, ','), 'unstaking (\\d+)', 1, 1, 'e')::number as stake_amount,
|
||||
'Unstake' as action,
|
||||
_inserted_timestamp
|
||||
from pool_txs
|
||||
where method_name = 'unstake'
|
||||
and tx:receipt[0]:outcome:status:SuccessValue is not null
|
||||
),
|
||||
|
||||
unstake_all_txs as (
|
||||
select
|
||||
tx_hash,
|
||||
block_timestamp,
|
||||
tx_receiver as pool_address,
|
||||
tx_signer,
|
||||
regexp_substr(array_to_string(tx:receipt[0]:outcome:logs, ','), 'unstaking (\\d+)', 1, 1, 'e')::number as stake_amount,
|
||||
'Unstake' as action,
|
||||
_inserted_timestamp
|
||||
from pool_txs
|
||||
where method_name = 'unstake_all'
|
||||
and tx:receipt[0]:outcome:status:SuccessValue is not null
|
||||
),
|
||||
|
||||
final as (
|
||||
select
|
||||
*
|
||||
from deposit_and_stake_txs
|
||||
union
|
||||
select
|
||||
*
|
||||
from stake_all_txs
|
||||
union
|
||||
select
|
||||
*
|
||||
from unstake_txs
|
||||
union
|
||||
select
|
||||
*
|
||||
from unstake_all_txs
|
||||
)
|
||||
|
||||
select
|
||||
*
|
||||
from final
|
||||
75
models/silver/silver__staking_actions.yml
Normal file
75
models/silver/silver__staking_actions.yml
Normal file
@ -0,0 +1,75 @@
|
||||
version: 2
|
||||
|
||||
models:
|
||||
- name: silver__staking_actions
|
||||
description: |-
|
||||
This table records all the staking and delegation transactions occurring in NEAR.
|
||||
|
||||
Be aware, however, not all transactions here necessarily actually contribute to securing the NEAR network.
|
||||
Each epoch can have a different set of validators.
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- tx_hash
|
||||
|
||||
columns:
|
||||
- name: tx_hash
|
||||
description: "{{ doc('tx_hash') }}"
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- STRING
|
||||
- VARCHAR
|
||||
|
||||
- name: block_timestamp
|
||||
description: "{{ doc('block_timestamp') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- TIMESTAMP_NTZ
|
||||
|
||||
- name: pool_address
|
||||
description: "{{ doc('staking_pool_address') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- STRING
|
||||
- VARCHAR
|
||||
|
||||
- name: tx_signer
|
||||
description: "{{ doc('tx_signer') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- STRING
|
||||
- VARCHAR
|
||||
|
||||
- name: stake_amount
|
||||
description: "{{ doc('staking_stake_amount') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- NUMBER
|
||||
|
||||
- name: action
|
||||
description: "{{ doc('staking_action') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- STRING
|
||||
- VARCHAR
|
||||
|
||||
- name: _inserted_timestamp
|
||||
description: "{{ doc('_inserted_timestamp') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- TIMESTAMP_NTZ
|
||||
Loading…
Reference in New Issue
Block a user