From 4037dcef54067dab119e11f621e9bd599504d2b9 Mon Sep 17 00:00:00 2001 From: Eric Laurello Date: Tue, 23 May 2023 11:46:19 -0400 Subject: [PATCH] tests --- models/descriptions/action.md | 6 + models/descriptions/chain_id.md | 5 + models/descriptions/completion_time.md | 5 + .../delegator_address.md | 0 models/descriptions/depositor.md | 5 + .../inserted_timestamp.md | 0 models/descriptions/msg_index.md | 5 + models/descriptions/msg_sub_group.md | 5 + models/descriptions/msg_type.md | 5 + models/descriptions/proposal_description.md | 5 + models/descriptions/proposal_id.md | 5 + models/descriptions/proposal_title.md | 5 + models/descriptions/proposal_type.md | 5 + models/descriptions/proposer.md | 5 + models/descriptions/proposer_address.md | 5 + models/descriptions/receiver.md | 5 + .../redelegate_source_validator_address.md | 5 + models/descriptions/sender.md | 5 + models/descriptions/transfer_type.md | 5 + models/descriptions/tx_count.md | 5 + models/descriptions/validator_hash.md | 5 + models/silver/silver__blocks.yml | 66 +++ .../silver__governance_proposal_deposits.sql | 2 +- .../silver__governance_proposal_deposits.yml | 79 ++++ .../silver__governance_submit_proposal.sql | 2 + .../silver__governance_submit_proposal.yml | 87 ++++ models/silver/silver__msg_attributes.yml | 96 +++++ models/silver/silver__msgs.yml | 77 ++++ models/silver/silver__staking.yml | 137 +++++++ models/silver/silver__staking_rewards.sql | 377 ++++-------------- models/silver/silver__staking_rewards.yml | 106 +++++ models/silver/silver__transfers.sql | 22 +- models/silver/silver__transfers.yml | 94 +++++ 33 files changed, 921 insertions(+), 320 deletions(-) create mode 100644 models/descriptions/action.md create mode 100644 models/descriptions/chain_id.md create mode 100644 models/descriptions/completion_time.md rename models/{silver => descriptions}/delegator_address.md (100%) create mode 100644 models/descriptions/depositor.md rename models/{silver => descriptions}/inserted_timestamp.md (100%) create mode 100644 models/descriptions/msg_index.md create mode 100644 models/descriptions/msg_sub_group.md create mode 100644 models/descriptions/msg_type.md create mode 100644 models/descriptions/proposal_description.md create mode 100644 models/descriptions/proposal_id.md create mode 100644 models/descriptions/proposal_title.md create mode 100644 models/descriptions/proposal_type.md create mode 100644 models/descriptions/proposer.md create mode 100644 models/descriptions/proposer_address.md create mode 100644 models/descriptions/receiver.md create mode 100644 models/descriptions/redelegate_source_validator_address.md create mode 100644 models/descriptions/sender.md create mode 100644 models/descriptions/transfer_type.md create mode 100644 models/descriptions/tx_count.md create mode 100644 models/descriptions/validator_hash.md create mode 100644 models/silver/silver__blocks.yml create mode 100644 models/silver/silver__governance_proposal_deposits.yml create mode 100644 models/silver/silver__governance_submit_proposal.yml create mode 100644 models/silver/silver__msg_attributes.yml create mode 100644 models/silver/silver__msgs.yml create mode 100644 models/silver/silver__staking.yml create mode 100644 models/silver/silver__staking_rewards.yml create mode 100644 models/silver/silver__transfers.yml diff --git a/models/descriptions/action.md b/models/descriptions/action.md new file mode 100644 index 0000000..f6725a4 --- /dev/null +++ b/models/descriptions/action.md @@ -0,0 +1,6 @@ +{% docs action %} + + +The action taken in the msg group. For staking this includes delegate, undelegate, redelegate, withdraw_rewards. + +{% enddocs %} \ No newline at end of file diff --git a/models/descriptions/chain_id.md b/models/descriptions/chain_id.md new file mode 100644 index 0000000..7f87bfc --- /dev/null +++ b/models/descriptions/chain_id.md @@ -0,0 +1,5 @@ +{% docs chain_id %} + +The name and version of the blockchain + +{% enddocs %} \ No newline at end of file diff --git a/models/descriptions/completion_time.md b/models/descriptions/completion_time.md new file mode 100644 index 0000000..83699d0 --- /dev/null +++ b/models/descriptions/completion_time.md @@ -0,0 +1,5 @@ +{% docs completion_time %} + +The time at which the undelegate or redelegate staking action is completed. + +{% enddocs %} \ No newline at end of file diff --git a/models/silver/delegator_address.md b/models/descriptions/delegator_address.md similarity index 100% rename from models/silver/delegator_address.md rename to models/descriptions/delegator_address.md diff --git a/models/descriptions/depositor.md b/models/descriptions/depositor.md new file mode 100644 index 0000000..864a7a3 --- /dev/null +++ b/models/descriptions/depositor.md @@ -0,0 +1,5 @@ +{% docs depositor %} + +The wallet address of the individual who deposited funds into the proposal + +{% enddocs %} \ No newline at end of file diff --git a/models/silver/inserted_timestamp.md b/models/descriptions/inserted_timestamp.md similarity index 100% rename from models/silver/inserted_timestamp.md rename to models/descriptions/inserted_timestamp.md diff --git a/models/descriptions/msg_index.md b/models/descriptions/msg_index.md new file mode 100644 index 0000000..8af9065 --- /dev/null +++ b/models/descriptions/msg_index.md @@ -0,0 +1,5 @@ +{% docs msg_index %} + +Short for "message index," the position in which messages occur in a transaction. + +{% enddocs %} \ No newline at end of file diff --git a/models/descriptions/msg_sub_group.md b/models/descriptions/msg_sub_group.md new file mode 100644 index 0000000..8b5a36c --- /dev/null +++ b/models/descriptions/msg_sub_group.md @@ -0,0 +1,5 @@ +{% docs msg_sub_group %} + +Silver only -- Numeric value grouping different messages together to represent a single action within a group. This is relevent for exec actions that contain mutiple underlying actions. NULL sub group means messages are related to the header (overall transaction) + +{% enddocs %} \ No newline at end of file diff --git a/models/descriptions/msg_type.md b/models/descriptions/msg_type.md new file mode 100644 index 0000000..e16302b --- /dev/null +++ b/models/descriptions/msg_type.md @@ -0,0 +1,5 @@ +{% docs msg_type %} + +A string containing information about the type of message occurring. + +{% enddocs %} \ No newline at end of file diff --git a/models/descriptions/proposal_description.md b/models/descriptions/proposal_description.md new file mode 100644 index 0000000..5c37c56 --- /dev/null +++ b/models/descriptions/proposal_description.md @@ -0,0 +1,5 @@ +{% docs proposal_description %} + +The description or body of the governance proposal. + +{% enddocs %} \ No newline at end of file diff --git a/models/descriptions/proposal_id.md b/models/descriptions/proposal_id.md new file mode 100644 index 0000000..5c355c2 --- /dev/null +++ b/models/descriptions/proposal_id.md @@ -0,0 +1,5 @@ +{% docs proposal_id %} + +Numeric ID that corresponds to the proposal. + +{% enddocs %} \ No newline at end of file diff --git a/models/descriptions/proposal_title.md b/models/descriptions/proposal_title.md new file mode 100644 index 0000000..7c04919 --- /dev/null +++ b/models/descriptions/proposal_title.md @@ -0,0 +1,5 @@ +{% docs proposal_title %} + +The title of the governance proposal that was submitted on-chain. + +{% enddocs %} \ No newline at end of file diff --git a/models/descriptions/proposal_type.md b/models/descriptions/proposal_type.md new file mode 100644 index 0000000..7300147 --- /dev/null +++ b/models/descriptions/proposal_type.md @@ -0,0 +1,5 @@ +{% docs proposal_type %} + +The type of proposal that was submitted. + +{% enddocs %} \ No newline at end of file diff --git a/models/descriptions/proposer.md b/models/descriptions/proposer.md new file mode 100644 index 0000000..8cf193d --- /dev/null +++ b/models/descriptions/proposer.md @@ -0,0 +1,5 @@ +{% docs proposer %} + +The address of the validator that submitted the proposal. + +{% enddocs %} \ No newline at end of file diff --git a/models/descriptions/proposer_address.md b/models/descriptions/proposer_address.md new file mode 100644 index 0000000..0dcaa94 --- /dev/null +++ b/models/descriptions/proposer_address.md @@ -0,0 +1,5 @@ +{% docs proposer_address %} + +The address of the validator that proposed the block. + +{% enddocs %} \ No newline at end of file diff --git a/models/descriptions/receiver.md b/models/descriptions/receiver.md new file mode 100644 index 0000000..e82f2da --- /dev/null +++ b/models/descriptions/receiver.md @@ -0,0 +1,5 @@ +{% docs receiver %} + +The wallet address of the individual received tokens in the transfer. + +{% enddocs %} \ No newline at end of file diff --git a/models/descriptions/redelegate_source_validator_address.md b/models/descriptions/redelegate_source_validator_address.md new file mode 100644 index 0000000..01c0460 --- /dev/null +++ b/models/descriptions/redelegate_source_validator_address.md @@ -0,0 +1,5 @@ +{% docs redelegate_source_validator_address %} + +The wallet address of the source alidator in a redelegation staking action. + +{% enddocs %} \ No newline at end of file diff --git a/models/descriptions/sender.md b/models/descriptions/sender.md new file mode 100644 index 0000000..1b55aab --- /dev/null +++ b/models/descriptions/sender.md @@ -0,0 +1,5 @@ +{% docs sender %} + +The wallet address of the individual sent tokens in the transfer. + +{% enddocs %} \ No newline at end of file diff --git a/models/descriptions/transfer_type.md b/models/descriptions/transfer_type.md new file mode 100644 index 0000000..856eed2 --- /dev/null +++ b/models/descriptions/transfer_type.md @@ -0,0 +1,5 @@ +{% docs transfer_type %} + +Details on the type of transfer occurring during the transaction. "IBC_Transfer_In" = depositing tokens onto Sei. "IBC_transfer_out" = withdrawing tokens from Sei. "Sei" = wallet to wallet transfer on Sei. + +{% enddocs %} \ No newline at end of file diff --git a/models/descriptions/tx_count.md b/models/descriptions/tx_count.md new file mode 100644 index 0000000..750dccb --- /dev/null +++ b/models/descriptions/tx_count.md @@ -0,0 +1,5 @@ +{% docs tx_count %} + +The number of transactions that occurred during a block. + +{% enddocs %} \ No newline at end of file diff --git a/models/descriptions/validator_hash.md b/models/descriptions/validator_hash.md new file mode 100644 index 0000000..4536422 --- /dev/null +++ b/models/descriptions/validator_hash.md @@ -0,0 +1,5 @@ +{% docs validator_hash %} + +The root hash of the new validator set. + +{% enddocs %} \ No newline at end of file diff --git a/models/silver/silver__blocks.yml b/models/silver/silver__blocks.yml new file mode 100644 index 0000000..d02d708 --- /dev/null +++ b/models/silver/silver__blocks.yml @@ -0,0 +1,66 @@ +version: 2 +models: + - name: silver__blocks + description: Records of all blocks that have occurred on Sei, dating back to the genesis block. + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - CHAIN_ID + - BLOCK_ID + columns: + - name: BLOCK_ID + description: "{{ doc('block_id') }}" + 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: CHAIN_ID + description: "{{ doc('chain_id') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - STRING + - VARCHAR + - name: TX_COUNT + description: "{{ doc('tx_count') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - NUMBER + - FLOAT + - name: PROPOSER_ADDRESS + description: "{{ doc('proposer_address') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - STRING + - VARCHAR + - name: VALIDATOR_HASH + description: "{{ doc('validator_hash') }}" + 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 diff --git a/models/silver/silver__governance_proposal_deposits.sql b/models/silver/silver__governance_proposal_deposits.sql index 0c803e8..cb77c9c 100644 --- a/models/silver/silver__governance_proposal_deposits.sql +++ b/models/silver/silver__governance_proposal_deposits.sql @@ -109,7 +109,7 @@ SELECT tx_succeeded, d.depositor, p.proposal_id :: NUMBER AS proposal_id, - v.amount, + v.amount :: FLOAT AS amount, v.currency, _inserted_timestamp FROM diff --git a/models/silver/silver__governance_proposal_deposits.yml b/models/silver/silver__governance_proposal_deposits.yml new file mode 100644 index 0000000..0faa9a3 --- /dev/null +++ b/models/silver/silver__governance_proposal_deposits.yml @@ -0,0 +1,79 @@ +version: 2 +models: + - name: silver__governance_proposal_deposits + description: Records of all proposal deposits that have occurred on Sei, dating back to the genesis block + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - TX_ID + columns: + - name: BLOCK_ID + description: "{{ doc('block_id') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - NUMBER + - FLOAT + - 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: TX_ID + description: "{{ doc('tx_id') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - STRING + - VARCHAR + - name: TX_SUCCEEDED + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - BOOLEAN + - name: DEPOSITOR + description: "{{ doc('depositor') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - STRING + - VARCHAR + - dbt_expectations.expect_column_values_to_match_regex: + regex: sei1[0-9a-z]{38,38} + - name: PROPOSAL_ID + description: "{{ doc('proposal_id') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - NUMBER + - FLOAT + - name: AMOUNT + description: "{{ doc('amount') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - NUMBER + - FLOAT + - name: CURRENCY + description: "{{ doc('currency') }}" + 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 diff --git a/models/silver/silver__governance_submit_proposal.sql b/models/silver/silver__governance_submit_proposal.sql index f6f078f..6f3574c 100644 --- a/models/silver/silver__governance_submit_proposal.sql +++ b/models/silver/silver__governance_submit_proposal.sql @@ -101,6 +101,8 @@ SELECT proposer, p.proposal_id :: NUMBER AS proposal_id, y.proposal_type, + NULL AS proposal_title, + NULL AS proposal_description, {# COALESCE( tx_body :messages [0] :content :title, tx_body :messages [0] :msgs [0] :content :title diff --git a/models/silver/silver__governance_submit_proposal.yml b/models/silver/silver__governance_submit_proposal.yml new file mode 100644 index 0000000..bdac34f --- /dev/null +++ b/models/silver/silver__governance_submit_proposal.yml @@ -0,0 +1,87 @@ +version: 2 +models: + - name: silver__governance_submit_proposal + description: Records of all proposal submissions on Sei, dating back to the genesis block. + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - TX_ID + columns: + - name: BLOCK_ID + description: "{{ doc('block_id') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - NUMBER + - FLOAT + - 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: TX_ID + description: "{{ doc('tx_id') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - STRING + - VARCHAR + - name: TX_SUCCEEDED + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - BOOLEAN + - name: PROPOSER + description: "{{ doc('proposer') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - STRING + - VARCHAR + - dbt_expectations.expect_column_values_to_match_regex: + regex: sei1[0-9a-z]{38,38} + - name: PROPOSAL_ID + description: "{{ doc('proposal_id') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - NUMBER + - FLOAT + - name: PROPOSAL_TYPE + description: "{{ doc('proposal_type') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - STRING + - VARCHAR + - name: PROPOSAL_TITLE + description: "{{ doc('proposal_title') }}" + tests: + # - not_null --pending tx body + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - STRING + - VARCHAR + - name: PROPOSAL_DESCRIPTION + description: "{{ doc('proposal_description') }}" + tests: + # - not_null --pending tx body + - 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 \ No newline at end of file diff --git a/models/silver/silver__msg_attributes.yml b/models/silver/silver__msg_attributes.yml new file mode 100644 index 0000000..2f29a3a --- /dev/null +++ b/models/silver/silver__msg_attributes.yml @@ -0,0 +1,96 @@ +version: 2 +models: + - name: silver__msg_attributes + description: Records of all message attributes associated to messages that have occurred on Sei, dating back to the genesis block. + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - TX_ID + - MSG_INDEX + - ATTRIBUTE_INDEX + columns: + - name: BLOCK_ID + description: "{{ doc('block_id') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - NUMBER + - FLOAT + - 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: TX_ID + description: "{{ doc('tx_id') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - STRING + - VARCHAR + - name: TX_SUCCEEDED + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - BOOLEAN + - name: MSG_GROUP + description: "{{ doc('msg_group') }}" + tests: + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - NUMBER + - FLOAT + - name: MSG_SUB_GROUP + description: "{{ doc('msg_sub_group') }}" + tests: + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - NUMBER + - FLOAT + - name: MSG_INDEX + description: "{{ doc('msg_index') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - NUMBER + - FLOAT + - name: MSG_TYPE + description: "{{ doc('msg_type') }}" + 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 + - name: ATTRIBUTE_KEY + description: "They key from the key-value pair from the message attribute" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - STRING + - VARCHAR + - name: ATTRIBUTE_VALUE + description: "They value from the key-value pair from the message attribute" + tests: + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - STRING + - VARCHAR + diff --git a/models/silver/silver__msgs.yml b/models/silver/silver__msgs.yml new file mode 100644 index 0000000..53ce8eb --- /dev/null +++ b/models/silver/silver__msgs.yml @@ -0,0 +1,77 @@ +version: 2 +models: + - name: silver__msgs + description: Records of all messages associated to transactions that have occurred on Sei, dating back to the genesis block. + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - TX_ID + - MSG_INDEX + columns: + - name: BLOCK_ID + description: "{{ doc('block_id') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - NUMBER + - FLOAT + - 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: TX_ID + description: "{{ doc('tx_id') }}" + tests: + - not_null + - name: TX_SUCCEEDED + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - BOOLEAN + - name: MSG_GROUP + description: "{{ doc('msg_group') }}" + tests: + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - NUMBER + - FLOAT + - name: MSG_SUB_GROUP + description: "{{ doc('msg_sub_group') }}" + tests: + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - NUMBER + - FLOAT + - name: MSG_INDEX + description: "{{ doc('msg_index') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - NUMBER + - FLOAT + - name: MSG_TYPE + description: "{{ doc('msg_type') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - STRING + - VARCHAR + - name: MSG + description: "The underlying json from the message or event within the transactions" + - 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 diff --git a/models/silver/silver__staking.yml b/models/silver/silver__staking.yml new file mode 100644 index 0000000..44efee3 --- /dev/null +++ b/models/silver/silver__staking.yml @@ -0,0 +1,137 @@ +version: 2 +models: + - name: silver__staking + description: Records of all staking related transactions that have occurred on Sei, dating back to the genesis block. These actions include delegate, undelegate, and redelegate. + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - TX_ID + - MSG_GROUP + - MSG_SUB_GROUP + - ACTION + - CURRENCY + - DELEGATOR_ADDRESS + - VALIDATOR_ADDRESS + columns: + - name: BLOCK_ID + description: "{{ doc('block_id') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - NUMBER + - FLOAT + - 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: TX_ID + description: "{{ doc('tx_id') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - STRING + - VARCHAR + - name: TX_SUCCEEDED + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - BOOLEAN + - name: TX_CALLER_ADDRESS + description: "{{ doc('tx_caller_address') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - STRING + - VARCHAR + - dbt_expectations.expect_column_values_to_match_regex: + regex: sei1[0-9a-z]{38,38} + - name: ACTION + description: "{{ doc('action') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - STRING + - VARCHAR + - name: MSG_GROUP + description: "{{ doc('msg_group') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - NUMBER + - FLOAT + - name: MSG_SUB_GROUP + description: "{{ doc('msg_sub_group') }}" + tests: + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - NUMBER + - FLOAT + - name: DELEGATOR_ADDRESS + description: "{{ doc('delegator_address') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - STRING + - VARCHAR + - dbt_expectations.expect_column_values_to_match_regex: + regex: sei1[0-9a-z]{38,38} + - name: AMOUNT + description: "{{ doc('amount') }}" + tests: + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - NUMBER + - FLOAT + - name: CURRENCY + description: "{{ doc('currency') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - STRING + - VARCHAR + - name: VALIDATOR_ADDRESS + description: "{{ doc('validator_address') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - STRING + - VARCHAR + - dbt_expectations.expect_column_values_to_match_regex: + regex: seivaloper1[0-9a-z]{38,38} + - name: REDELEGATE_SOURCE_VALIDATOR_ADDRESS + description: "{{ doc('redelegate_source_validator_address') }}" + tests: + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - STRING + - VARCHAR + - dbt_expectations.expect_column_values_to_match_regex: + regex: seivaloper1[0-9a-z]{38,38} + - name: COMPLETION_TIME + description: "{{ doc('completion_time') }}" + tests: + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - TIMESTAMP_NTZ + - 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 diff --git a/models/silver/silver__staking_rewards.sql b/models/silver/silver__staking_rewards.sql index aeea424..adff5f8 100644 --- a/models/silver/silver__staking_rewards.sql +++ b/models/silver/silver__staking_rewards.sql @@ -4,10 +4,8 @@ incremental_strategy = 'merge', cluster_by = ['block_timestamp::DATE'], ) }} - -select 1 a -{# -WITH msg_attributes_cte AS ( +{# select 1 a #} +WITH msg_attributes AS ( SELECT tx_id, @@ -24,14 +22,11 @@ WITH msg_attributes_cte AS ( FROM {{ ref('silver__msg_attributes') }} A WHERE - msg_type IN ( + msg_type IN( 'withdraw_rewards', 'transfer', 'message', - 'tx', - 'delegate', - 'redelegate', - 'unbond' + 'tx' ) {% if is_incremental() %} @@ -45,290 +40,63 @@ AND _inserted_timestamp >= ( ) {% endif %} ), -reward_combo AS ( +reroll_msg AS ( SELECT tx_id, + msg_type, msg_group, msg_sub_group, + msg_index, OBJECT_AGG( attribute_key :: STRING, attribute_value :: variant - ) AS j, - j :validator :: STRING AS validator_address, - j :amount :: STRING AS amount, - j :sender :: STRING AS delegator_address + ) AS attributes FROM - msg_attr_rewards - WHERE - attribute_key IN ( - 'sender', - 'amount', - 'validator' - ) + msg_attributes GROUP BY tx_id, + msg_type, msg_group, - msg_sub_group + msg_sub_group, + msg_index ), -claim_base AS ( - SELECT - A.tx_id, - A.msg_type, - A.msg_index, - msg_group - FROM - msg_attributes_cte A - INNER JOIN ( - SELECT - DISTINCT tx_id - FROM - msg_attributes_cte - WHERE - msg_type IN ( - 'delegate', - 'redelegate' - ) - ) b - ON A.tx_id = b.tx_id - WHERE - msg_type = 'claim' -), -claim_combo AS ( +flat AS ( SELECT tx_id, msg_group, msg_sub_group, - OBJECT_AGG( - CASE - WHEN msg_type IN ( - 'message', - 'claim' - ) THEN msg_type || '__' - ELSE '' - END || attribute_key :: STRING, - attribute_value :: variant - ) AS j, - COALESCE( - j :validator :: STRING, - j :source_validator :: STRING - ) AS validator_address, - j :claim__amount :: STRING AS amount, - j :message__sender :: STRING AS delegator_address + msg_type, + attributes :amount :: STRING AS amount, + attributes :validator :: STRING AS validator_address, + attributes :recipient :: STRING AS delegator_address, + attributes :recipient :: STRING AS rewards_recipient FROM - msg_attr_claim + reroll_msg WHERE - msg_type || '__' || attribute_key IN ( - 'message__sender', - 'claim__amount' + msg_type IN ( + 'withdraw_rewards', + 'transfer' ) - OR attribute_key IN ( - 'validator', - 'source_validator' - ) - GROUP BY - tx_id, - msg_group, - msg_sub_group ), -tran_base AS ( - SELECT - DISTINCT tx_id, - msg_group, - msg_sub_group, - delegator_address - FROM - {{ ref('silver__staking') }} A - -{% if is_incremental() %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX( - _inserted_timestamp - ) - FROM - max_date - ) -{% endif %} -), -tran_tran AS ( +combo AS ( SELECT A.tx_id, - A.msg_type, - A.msg_index, A.msg_group, - attribute_key, - attribute_value + A.msg_sub_group, + A.amount, + A.validator_address, + b.delegator_address, + b.rewards_recipient FROM - msg_attributes_cte A - INNER JOIN tran_base b + flat A + JOIN flat b ON A.tx_id = b.tx_id AND A.msg_group = b.msg_group - AND A.attribute_value = b.delegator_address - LEFT JOIN ( - SELECT - DISTINCT tx_id - FROM - msg_attributes_cte - WHERE - msg_type IN ( - 'claim', - 'withdraw_rewards' - ) - ) C - ON A.tx_id = C.tx_id + AND A.msg_sub_group = b.msg_sub_group + AND A.amount = b.amount WHERE - A.msg_type = 'transfer' - AND A.attribute_key = 'recipient' - AND C.tx_id IS NULL -), -msg_attr_trans AS ( - SELECT - A.tx_id, - A.msg_group, - A.msg_index, - A.msg_type, - A.attribute_key, - A.attribute_value, - DENSE_RANK() over( - PARTITION BY A.tx_id, - A.msg_group - ORDER BY - A.msg_index - ) change_index - FROM - tran_tran b - JOIN msg_attributes_cte A - ON A.tx_ID = b.tx_ID - AND A.msg_group = b.msg_group - WHERE - A.msg_type IN ( - 'delegate', - 'redelegate', - 'unbond' - ) - OR ( - A.msg_index = b.msg_index - AND A.msg_type = 'transfer' - ) -), -tran_combo AS ( - SELECT - A.tx_id, - A.msg_group, - A.msg_index group_id, - COALESCE( - b.j :validator :: STRING, - b.j :source_validator :: STRING - ) AS validator_address, - A.j :amount :: STRING AS amount, - A.j :recipient :: STRING AS delegator_address - FROM - ( - SELECT - tx_id, - msg_group, - msg_index, - change_index + 1 group_id, - OBJECT_AGG( - attribute_key :: STRING, - attribute_value :: variant - ) AS j - FROM - ( - SELECT - DISTINCT tx_id, - msg_group, - msg_index, - change_index, - attribute_key, - attribute_value - FROM - msg_attr_trans - WHERE - msg_type = 'transfer' - AND attribute_key IN ( - 'amount', - 'recipient' - ) - ) x - GROUP BY - tx_id, - msg_group, - msg_index, - group_id - ) A - JOIN ( - SELECT - tx_id, - msg_group, - msg_index, - change_index group_id, - OBJECT_AGG( - attribute_key :: STRING, - attribute_value :: variant - ) AS j - FROM - ( - SELECT - DISTINCT tx_id, - msg_group, - msg_index, - change_index, - attribute_key, - attribute_value - FROM - msg_attr_trans - WHERE - msg_type <> 'transfer' - AND attribute_key IN ( - 'validator', - 'source_validator' - ) - ) x - GROUP BY - tx_id, - msg_group, - msg_index, - group_id - ) b - ON A.tx_id = b.tx_id - AND A.msg_group = b.msg_group - AND A.group_id = b.group_id -), -combo_all AS ( - SELECT - tx_id, - msg_group, - group_id, - validator_address, - amount, - delegator_address, - 'claim' AS action - FROM - tran_combo - UNION ALL - SELECT - tx_id, - msg_group, - group_id, - validator_address, - amount, - delegator_address, - 'withdraw_rewards' AS action - FROM - reward_combo - UNION ALL - SELECT - tx_id, - msg_group, - group_id, - validator_address, - amount, - delegator_address, - 'claim' AS action - FROM - claim_combo + A.msg_type = 'withdraw_rewards' + AND b.msg_type = 'transfer' ), tx_address AS ( SELECT @@ -344,7 +112,7 @@ tx_address AS ( 1 ) AS acc_seq_index FROM - msg_attributes_cte A + msg_attributes A WHERE attribute_key = 'acc_seq' qualify(ROW_NUMBER() over (PARTITION BY tx_id ORDER BY @@ -357,9 +125,10 @@ prefinal AS ( A.tx_id, b.tx_succeeded, C.tx_caller_address, - A.action, A.msg_group, + A.msg_sub_group, A.delegator_address, + A.rewards_recipient, SUM( CASE WHEN A.split_amount LIKE '%usei' THEN REPLACE( @@ -382,14 +151,15 @@ prefinal AS ( FROM ( SELECT - p.tx_Id, - p.action, + p.tx_id, p.msg_group, + p.msg_sub_group, p.delegator_address, p.validator_address, + p.rewards_recipient, am.value AS split_amount FROM - combo_all p, + combo p, LATERAL SPLIT_TO_TABLE( p.amount, ',' @@ -397,45 +167,35 @@ prefinal AS ( ) A JOIN ( SELECT - tx_ID, + DISTINCT tx_id, block_id, block_timestamp, tx_succeeded, _inserted_timestamp FROM - {{ ref('silver__transactions') }} A - -{% if is_incremental() %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX( - _inserted_timestamp - ) - FROM - max_date - ) -{% endif %} -) b -ON A.tx_Id = b.tx_ID -JOIN tx_address C -ON A.tx_id = C.tx_id -GROUP BY - b.block_id, - b.block_timestamp, - A.tx_id, - b.tx_succeeded, - C.tx_caller_address, - A.action, - A.msg_group, - A.delegator_address,CASE - WHEN A.split_amount LIKE '%usei' THEN 'usei' - WHEN A.split_amount LIKE '%pool%' THEN SUBSTRING(A.split_amount, CHARINDEX('g', A.split_amount), 99) - WHEN A.split_amount LIKE '%ibc%' THEN SUBSTRING(A.split_amount, CHARINDEX('i', A.split_amount), 99) - ELSE 'usei' - END, - A.validator_address, - b._inserted_timestamp + msg_attributes + ) b + ON A.tx_id = b.tx_id + JOIN tx_address C + ON A.tx_id = C.tx_id + GROUP BY + b.block_id, + b.block_timestamp, + A.tx_id, + b.tx_succeeded, + C.tx_caller_address, + A.msg_group, + A.msg_sub_group, + A.delegator_address, + A.rewards_recipient, + CASE + WHEN A.split_amount LIKE '%usei' THEN 'usei' + WHEN A.split_amount LIKE '%pool%' THEN SUBSTRING(A.split_amount, CHARINDEX('g', A.split_amount), 99) + WHEN A.split_amount LIKE '%ibc%' THEN SUBSTRING(A.split_amount, CHARINDEX('i', A.split_amount), 99) + ELSE 'usei' + END, + A.validator_address, + b._inserted_timestamp ) SELECT block_id, @@ -443,9 +203,10 @@ SELECT A.tx_id, A.tx_succeeded, A.tx_caller_address, - A.action, A.msg_group, + A.msg_sub_group, A.delegator_address, + A.rewards_recipient, A.amount, A.currency, A.validator_address, @@ -454,10 +215,10 @@ SELECT '-', A.tx_id, A.msg_group, - A.action, + A.msg_sub_group, A.currency, A.delegator_address, A.validator_address ) AS _unique_key FROM - prefinal A #} + prefinal A diff --git a/models/silver/silver__staking_rewards.yml b/models/silver/silver__staking_rewards.yml new file mode 100644 index 0000000..e661cb8 --- /dev/null +++ b/models/silver/silver__staking_rewards.yml @@ -0,0 +1,106 @@ +version: 2 +models: + - name: silver__staking_rewards + description: Records of all claimed rewards earned from staking that have occurred on Sei, dating back to the genesis block. These actions include claim and withdrawal_rewards. + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - TX_ID + - MSG_GROUP + - MSG_SUB_GROUP + - CURRENCY + - DELEGATOR_ADDRESS + - VALIDATOR_ADDRESS + columns: + - name: BLOCK_ID + description: "{{ doc('block_id') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - NUMBER + - FLOAT + - 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: TX_ID + description: "{{ doc('tx_id') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - STRING + - VARCHAR + - name: TX_SUCCEEDED + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - BOOLEAN + - name: TX_CALLER_ADDRESS + description: "{{ doc('tx_caller_address') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - STRING + - VARCHAR + - dbt_expectations.expect_column_values_to_match_regex: + regex: sei1[0-9a-z]{38,38} + - name: MSG_GROUP + description: "{{ doc('msg_group') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - NUMBER + - FLOAT + - name: DELEGATOR_ADDRESS + description: "{{ doc('delegator_address') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - STRING + - VARCHAR + - dbt_expectations.expect_column_values_to_match_regex: + regex: sei1[0-9a-z]{38,38} + - name: AMOUNT + description: "{{ doc('amount') }}" + tests: + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - NUMBER + - FLOAT + - name: CURRENCY + description: "{{ doc('currency') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - STRING + - VARCHAR + - name: VALIDATOR_ADDRESS + description: "{{ doc('validator_address') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - STRING + - VARCHAR + - dbt_expectations.expect_column_values_to_match_regex: + regex: seivaloper1[0-9a-z]{38,38} + - 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 diff --git a/models/silver/silver__transfers.sql b/models/silver/silver__transfers.sql index bd41deb..8c2cd68 100644 --- a/models/silver/silver__transfers.sql +++ b/models/silver/silver__transfers.sql @@ -143,7 +143,7 @@ receiver_ibc AS ( msg_group, msg_sub_group ), -osmo_tx_ids AS ( +sei_tx_ids AS ( SELECT DISTINCT tx_id FROM @@ -156,13 +156,13 @@ osmo_tx_ids AS ( ) OR msg_type = 'claim' ), -message_indexes_osmo AS ( +message_indexes_sei AS ( SELECT v.tx_id, attribute_key, m.msg_index FROM - osmo_tx_ids v + sei_tx_ids v LEFT OUTER JOIN base_atts m ON v.tx_id = m.tx_id INNER JOIN sender s @@ -172,24 +172,24 @@ message_indexes_osmo AS ( AND attribute_key = 'amount' AND m.msg_index > s.msg_index ), -osmo_receiver AS ( +sei_receiver AS ( SELECT o.tx_id, m.msg_group, m.msg_index, attribute_value AS receiver FROM - osmo_tx_ids o + sei_tx_ids o LEFT OUTER JOIN base_atts m ON o.tx_id = m.tx_id - LEFT OUTER JOIN message_indexes_osmo idx + LEFT OUTER JOIN message_indexes_sei idx ON idx.tx_id = m.tx_id WHERE m.msg_type = 'transfer' AND m.attribute_key = 'recipient' AND idx.msg_index = m.msg_index ), -osmo_amount AS ( +sei_amount AS ( SELECT o.tx_id, m.msg_index, @@ -206,10 +206,10 @@ osmo_amount AS ( ) AS amount, RIGHT(attribute_value, LENGTH(attribute_value) - LENGTH(SPLIT_PART(TRIM(REGEXP_REPLACE(attribute_value, '[^[:digit:]]', ' ')), ' ', 0))) AS currency FROM - osmo_tx_ids o + sei_tx_ids o LEFT OUTER JOIN base_atts m ON o.tx_id = m.tx_id - LEFT OUTER JOIN message_indexes_osmo idx + LEFT OUTER JOIN message_indexes_sei idx ON idx.tx_id = m.tx_id WHERE m.msg_type = 'transfer' @@ -298,8 +298,8 @@ fin AS ( currency ) AS _unique_key FROM - osmo_receiver r - LEFT OUTER JOIN osmo_amount C + sei_receiver r + LEFT OUTER JOIN sei_amount C ON r.tx_id = C.tx_id AND r.msg_index = C.msg_index LEFT OUTER JOIN sender s diff --git a/models/silver/silver__transfers.yml b/models/silver/silver__transfers.yml new file mode 100644 index 0000000..d0f5ffc --- /dev/null +++ b/models/silver/silver__transfers.yml @@ -0,0 +1,94 @@ +version: 2 +models: + - name: silver__transfers + description: Records of all transfers on Sei, including IBC transfers as on- and off-ramps to Sei and wallet to wallet transfers + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - TX_ID + - MSG_INDEX + - CURRENCY + columns: + - name: BLOCK_ID + description: "{{ doc('block_id') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - NUMBER + - FLOAT + - 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: TX_ID + description: "{{ doc('tx_id') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - STRING + - VARCHAR + - name: TX_SUCCEEDED + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - BOOLEAN + - name: TRANSFER_TYPE + description: "{{ doc('transfer_type') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - STRING + - VARCHAR + - name: SENDER + description: "{{ doc('sender') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - STRING + - VARCHAR + - name: AMOUNT + description: "{{ doc('amount') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - NUMBER + - FLOAT + - name: CURRENCY + description: "{{ doc('currency') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - STRING + - VARCHAR + - name: RECEIVER + description: "{{ doc('receiver') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - STRING + - VARCHAR + # - name: FOREIGN_ADDRESS + # description: "{{ doc('foreign_address') }}" + # - name: FOREIGN_CHAIN + # description: "{{ doc('foreign_chain') }}" + - 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 \ No newline at end of file