Skip to content

Commit

Permalink
AN-5209/Upd staking model (#358)
Browse files Browse the repository at this point in the history
* Upd staking model

* drop _s suffix

* rm event_data col

* upd desc
  • Loading branch information
forgxyz authored Sep 13, 2024
1 parent ccf595e commit 9a7151b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 10 deletions.
4 changes: 2 additions & 2 deletions models/descriptions/delegator.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% docs delegator %}

The Flow account address for the wallet delegating to a node.
The Flow account address for the wallet delegating to a node. This is derived from the first authorizer on the transaction and may be inaccurate if the transaction was signed by an EOA. Refer to delegator_id as the unique identifier for the delegator, taken directly from the emitted event data.

{% enddocs %}
{% enddocs %}
3 changes: 2 additions & 1 deletion models/gold/gov/gov__ez_staking_actions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ SELECT
block_height,
tx_succeeded,
delegator,
delegator_id,
action,
amount,
node_id,
Expand All @@ -21,4 +22,4 @@ SELECT
inserted_timestamp,
modified_timestamp
FROM
{{ ref('silver__staking_actions_s') }}
{{ ref('silver__staking_actions') }}
6 changes: 5 additions & 1 deletion models/gold/gov/gov__ez_staking_actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,16 @@ models:
- name: delegator
description: "{{ doc('delegator') }}"
tests:
- not_null
- not_null:
where: delegator_id is not null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- VARCHAR
- STRING

- name: delegator_id
description: "{{ doc('delegator') }}"

- name: action
description: "{{ doc('action') }}"
tests:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ flow_staking AS (
tx_succeeded,
event_contract,
event_type AS action,
event_data :amount :: FLOAT AS amount,
COALESCE(
event_data :amount :: FLOAT,
-- amount for event NewNodeCreated rep initial stake
event_data :amountCommitted :: FLOAT
) AS amount,
event_data :delegatorID :: STRING AS delegator_id,
event_data :nodeID :: STRING AS node_id,
_inserted_timestamp,
Expand All @@ -63,11 +67,33 @@ flow_staking AS (
event_contract = 'A.8624b52f9ddcd04a.FlowIDTableStaking'
AND event_type IN (
'DelegatorTokensCommitted',
'DelegatorRewardTokensWithdrawn',
'DelegatorUnstakedTokensWithdrawn',
'TokensCommitted',

'DelegatorTokensStaked',
'TokensStaked',

'DelegatorTokensRequestedToUnstake',

'DelegatorTokensUnstaking',
'TokensUnstaking',

'DelegatorTokensUnstaked',
'TokensUnstaked',

'DelegatorUnstakedTokensWithdrawn',
'UnstakedTokensWithdrawn',

'DelegatorRewardTokensWithdrawn',
'RewardTokensWithdrawn',
'UnstakedTokensWithdrawn'

-- important additions to include
-- initial stake, any self-unstake, refund
'NewNodeCreated',
'NodeTokensRequestedToUnstake',
'NodeRemovedAndRefunded',

'RewardsPaid',
'DelegatorRewardsPaid'
)
),
add_auth AS (
Expand Down Expand Up @@ -114,7 +140,8 @@ FINAL AS (
block_timestamp,
block_height,
tx_succeeded,
primary_authorizer AS delegator,
IFF(delegator_id IS NOT NULL, primary_authorizer, null) AS delegator,
delegator_id,
action,
amount,
node_id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 2

models:
- name: silver__staking_actions_s
- name: silver__staking_actions
description: |-
This table provides transaction-level info on FLOW staking activities.
Expand Down

0 comments on commit 9a7151b

Please sign in to comment.