mirror of
https://github.com/FlipsideCrypto/flow-models.git
synced 2026-02-06 19:16:43 +00:00
AN-1780/staking (#50)
* delegators * staking events * docs and core view * date filter
This commit is contained in:
parent
417f5df20d
commit
779baa4122
31
models/core/core__ez_staking_actions.sql
Normal file
31
models/core/core__ez_staking_actions.sql
Normal file
@ -0,0 +1,31 @@
|
||||
{{ config(
|
||||
materialized = 'view'
|
||||
) }}
|
||||
|
||||
WITH staking_actions AS (
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ ref('silver__staking_actions') }}
|
||||
WHERE
|
||||
block_timestamp :: DATE >= '2022-04-20'
|
||||
),
|
||||
FINAL AS (
|
||||
SELECT
|
||||
tx_id,
|
||||
event_index,
|
||||
block_timestamp,
|
||||
block_height,
|
||||
tx_succeeded,
|
||||
delegator,
|
||||
action,
|
||||
amount,
|
||||
node_id
|
||||
FROM
|
||||
staking_actions
|
||||
)
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
FINAL
|
||||
82
models/core/core__ez_staking_actions.yml
Normal file
82
models/core/core__ez_staking_actions.yml
Normal file
@ -0,0 +1,82 @@
|
||||
version: 2
|
||||
|
||||
models:
|
||||
- name: core__ez_staking_actions
|
||||
description: |-
|
||||
This table provides transaction-level info on FLOW staking activities.
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- tx_id
|
||||
- event_index
|
||||
|
||||
columns:
|
||||
- name: tx_id
|
||||
description: "{{ doc('tx_id') }}"
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: block_timestamp
|
||||
description: "{{ doc('block_timestamp') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 1
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- TIMESTAMP_NTZ
|
||||
|
||||
- name: block_height
|
||||
description: "{{ doc('block_height') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- NUMBER
|
||||
- FLOAT
|
||||
|
||||
- name: tx_succeeded
|
||||
description: "{{ doc('tx_succeeded') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- BOOLEAN
|
||||
|
||||
- name: delegator
|
||||
description: "{{ doc('delegator') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- VARCHAR
|
||||
- STRING
|
||||
|
||||
- name: action
|
||||
description: "{{ doc('action') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- VARCHAR
|
||||
- STRING
|
||||
|
||||
- name: amount
|
||||
description: "{{ doc('amount') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- NUMBER
|
||||
- FLOAT
|
||||
- DOUBLE
|
||||
|
||||
- name: node_id
|
||||
description: "{{ doc('node_id') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- VARCHAR
|
||||
- STRING
|
||||
5
models/descriptions/action.md
Normal file
5
models/descriptions/action.md
Normal file
@ -0,0 +1,5 @@
|
||||
{% docs action %}
|
||||
|
||||
The action occurring in this record, as derived from `event_type` in the transaction.
|
||||
|
||||
{% enddocs %}
|
||||
5
models/descriptions/delegator.md
Normal file
5
models/descriptions/delegator.md
Normal file
@ -0,0 +1,5 @@
|
||||
{% docs delegator %}
|
||||
|
||||
The Flow account address for the wallet delegating to a node.
|
||||
|
||||
{% enddocs %}
|
||||
96
models/silver/silver__staking_actions.sql
Normal file
96
models/silver/silver__staking_actions.sql
Normal file
@ -0,0 +1,96 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
cluster_by = ['_inserted_timestamp::DATE'],
|
||||
unique_key = 'tx_id'
|
||||
) }}
|
||||
|
||||
WITH silver_events AS (
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ ref('silver__events_final') }}
|
||||
|
||||
{% if is_incremental() %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
flow_staking AS (
|
||||
SELECT
|
||||
tx_id,
|
||||
event_index,
|
||||
block_timestamp,
|
||||
block_height,
|
||||
tx_succeeded,
|
||||
event_contract,
|
||||
event_type AS action,
|
||||
event_data :amount :: FLOAT AS amount,
|
||||
event_data :delegatorID :: STRING AS delegator_id,
|
||||
event_data :nodeID :: STRING AS node_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
silver_events
|
||||
WHERE
|
||||
event_contract = 'A.8624b52f9ddcd04a.FlowIDTableStaking'
|
||||
AND event_type IN (
|
||||
'DelegatorTokensCommitted',
|
||||
'DelegatorRewardTokensWithdrawn',
|
||||
'DelegatorUnstakedTokensWithdrawn',
|
||||
'TokensCommitted',
|
||||
'RewardTokensWithdrawn',
|
||||
'UnstakedTokensWithdrawn'
|
||||
)
|
||||
),
|
||||
add_auth AS (
|
||||
SELECT
|
||||
tx_id,
|
||||
COALESCE(
|
||||
authorizers [1],
|
||||
authorizers [0]
|
||||
) :: STRING AS primary_authorizer
|
||||
FROM
|
||||
{{ ref('silver__transactions') }}
|
||||
WHERE
|
||||
tx_id IN (
|
||||
SELECT
|
||||
tx_id
|
||||
FROM
|
||||
flow_staking
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
FINAL AS (
|
||||
SELECT
|
||||
s.tx_id,
|
||||
event_index,
|
||||
block_timestamp,
|
||||
block_height,
|
||||
tx_succeeded,
|
||||
primary_authorizer AS delegator,
|
||||
action,
|
||||
amount,
|
||||
node_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
flow_staking s
|
||||
LEFT JOIN add_auth A USING (tx_id)
|
||||
)
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
FINAL
|
||||
98
models/silver/silver__staking_actions.yml
Normal file
98
models/silver/silver__staking_actions.yml
Normal file
@ -0,0 +1,98 @@
|
||||
version: 2
|
||||
|
||||
models:
|
||||
- name: silver__staking_actions
|
||||
description: |-
|
||||
This table provides transaction-level info on FLOW staking activities.
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- tx_id
|
||||
- event_index
|
||||
|
||||
columns:
|
||||
- name: tx_id
|
||||
description: "{{ doc('tx_id') }}"
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: event_index
|
||||
description: "{{ doc('event_index') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- NUMBER
|
||||
|
||||
- name: block_timestamp
|
||||
description: "{{ doc('block_timestamp') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 1
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- TIMESTAMP_NTZ
|
||||
|
||||
- name: block_height
|
||||
description: "{{ doc('block_height') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- NUMBER
|
||||
- FLOAT
|
||||
|
||||
- name: tx_succeeded
|
||||
description: "{{ doc('tx_succeeded') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- BOOLEAN
|
||||
|
||||
- name: delegator
|
||||
description: "{{ doc('delegator') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- VARCHAR
|
||||
- STRING
|
||||
|
||||
- name: action
|
||||
description: "{{ doc('action') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- VARCHAR
|
||||
- STRING
|
||||
|
||||
- name: amount
|
||||
description: "{{ doc('amount') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- NUMBER
|
||||
- FLOAT
|
||||
- DOUBLE
|
||||
|
||||
- name: node_id
|
||||
description: "{{ doc('node_id') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- VARCHAR
|
||||
- STRING
|
||||
|
||||
- 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