From 9a7151bfc18d0d37c617b8beb75428eb640ffc47 Mon Sep 17 00:00:00 2001 From: Jack Forgash <58153492+forgxyz@users.noreply.github.com> Date: Fri, 13 Sep 2024 11:07:37 -0600 Subject: [PATCH] AN-5209/Upd staking model (#358) * Upd staking model * drop _s suffix * rm event_data col * upd desc --- models/descriptions/delegator.md | 4 +- models/gold/gov/gov__ez_staking_actions.sql | 3 +- models/gold/gov/gov__ez_staking_actions.yml | 6 ++- ...ions_s.sql => silver__staking_actions.sql} | 37 ++++++++++++++++--- ...ions_s.yml => silver__staking_actions.yml} | 2 +- 5 files changed, 42 insertions(+), 10 deletions(-) rename models/silver/staking/{silver__staking_actions_s.sql => silver__staking_actions.sql} (77%) rename models/silver/staking/{silver__staking_actions_s.yml => silver__staking_actions.yml} (97%) diff --git a/models/descriptions/delegator.md b/models/descriptions/delegator.md index 08b7838b..82b010b5 100644 --- a/models/descriptions/delegator.md +++ b/models/descriptions/delegator.md @@ -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 %} \ No newline at end of file +{% enddocs %} diff --git a/models/gold/gov/gov__ez_staking_actions.sql b/models/gold/gov/gov__ez_staking_actions.sql index 68e1c5e8..394f4264 100644 --- a/models/gold/gov/gov__ez_staking_actions.sql +++ b/models/gold/gov/gov__ez_staking_actions.sql @@ -11,6 +11,7 @@ SELECT block_height, tx_succeeded, delegator, + delegator_id, action, amount, node_id, @@ -21,4 +22,4 @@ SELECT inserted_timestamp, modified_timestamp FROM - {{ ref('silver__staking_actions_s') }} + {{ ref('silver__staking_actions') }} diff --git a/models/gold/gov/gov__ez_staking_actions.yml b/models/gold/gov/gov__ez_staking_actions.yml index 5bbec952..1037f1ca 100644 --- a/models/gold/gov/gov__ez_staking_actions.yml +++ b/models/gold/gov/gov__ez_staking_actions.yml @@ -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: diff --git a/models/silver/staking/silver__staking_actions_s.sql b/models/silver/staking/silver__staking_actions.sql similarity index 77% rename from models/silver/staking/silver__staking_actions_s.sql rename to models/silver/staking/silver__staking_actions.sql index a94a3f22..53f526c5 100644 --- a/models/silver/staking/silver__staking_actions_s.sql +++ b/models/silver/staking/silver__staking_actions.sql @@ -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, @@ -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 ( @@ -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, diff --git a/models/silver/staking/silver__staking_actions_s.yml b/models/silver/staking/silver__staking_actions.yml similarity index 97% rename from models/silver/staking/silver__staking_actions_s.yml rename to models/silver/staking/silver__staking_actions.yml index 9f0d5761..5ed28f50 100644 --- a/models/silver/staking/silver__staking_actions_s.yml +++ b/models/silver/staking/silver__staking_actions.yml @@ -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.