diff --git a/models/descriptions/vote_option.md b/models/descriptions/vote_option.md new file mode 100644 index 0000000..6408db1 --- /dev/null +++ b/models/descriptions/vote_option.md @@ -0,0 +1,5 @@ +{% docs vote_option %} + +How the delegator voted on the proposal. + +{% enddocs %} \ No newline at end of file diff --git a/models/descriptions/vote_weight.md b/models/descriptions/vote_weight.md new file mode 100644 index 0000000..e83f47e --- /dev/null +++ b/models/descriptions/vote_weight.md @@ -0,0 +1,5 @@ +{% docs vote_weight %} + +Denotes what portion of a user's stake is put toward the voting option. If "1", 100% of the voter's voting power is put toward the selected option. + +{% enddocs %} \ No newline at end of file diff --git a/models/descriptions/voter.md b/models/descriptions/voter.md new file mode 100644 index 0000000..ff8c0f3 --- /dev/null +++ b/models/descriptions/voter.md @@ -0,0 +1,5 @@ +{% docs voter %} + +Address of the delegator that voted on the proposal. + +{% enddocs %} \ No newline at end of file diff --git a/models/silver/silver__governance_proposal_deposits.yml b/models/silver/silver__governance_proposal_deposits.yml index f9537fb..bc91fb2 100644 --- a/models/silver/silver__governance_proposal_deposits.yml +++ b/models/silver/silver__governance_proposal_deposits.yml @@ -43,7 +43,7 @@ models: tests: - not_null - name: PROPOSAL_ID - description: "Description goes here" + description: "{{ doc('proposal_id') }}" tests: - not_null - name: DEPOSIT_AMOUNT diff --git a/models/silver/silver__governance_submit_proposal.yml b/models/silver/silver__governance_submit_proposal.yml index 8d4cb91..382ee12 100644 --- a/models/silver/silver__governance_submit_proposal.yml +++ b/models/silver/silver__governance_submit_proposal.yml @@ -1,7 +1,7 @@ version: 2 models: - name: silver__governance_submit_proposal - description: Records of all transactions that have occurred on Osmosis, dating back to the genesis block. + description: Records of all proposal submissions on Osmosis, dating back to the Genesis block. tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: @@ -39,7 +39,7 @@ models: tests: - not_null - name: PROPOSER - description: "{{ doc('tx_code') }}" + description: "{{ doc('proposer') }}" tests: - not_null - name: PROPOSAL_ID diff --git a/models/silver/silver__governance_votes.sql b/models/silver/silver__governance_votes.sql new file mode 100644 index 0000000..662e9ee --- /dev/null +++ b/models/silver/silver__governance_votes.sql @@ -0,0 +1,85 @@ +{{ config( + materialized = 'incremental', + unique_key = "tx_id", + incremental_strategy = 'delete+insert', + cluster_by = ['_ingested_at::DATE'], +) }} + +WITH vote_options AS ( + SELECT + tx_id, + msg_index, + CASE + WHEN attribute_value::string = 'VOTE_OPTION_YES' THEN + 1 + WHEN attribute_value::string = 'VOTE_OPTION_ABSTAIN' THEN + 2 + WHEN attribute_value::string = 'VOTE_OPTION_NO' THEN + 3 + WHEN attribute_value::string = 'VOTE_OPTION_NO_WITH_VETO' THEN + 4 + ELSE + TRY_PARSE_JSON(attribute_value):option + END AS vote_option, + TRY_PARSE_JSON(attribute_value):weight :: INTEGER AS vote_weight + FROM {{ ref('silver__msg_attributes') }} + WHERE msg_type = 'proposal_vote' + AND attribute_key = 'option' + + {% if is_incremental() %} + AND _ingested_at :: DATE >= CURRENT_DATE - 2 + {% endif %} +), + +proposal_id AS ( + SELECT + tx_id, + msg_index, + attribute_value AS proposal_id + FROM {{ ref('silver__msg_attributes') }} + WHERE msg_type = 'proposal_vote' + AND attribute_key = 'proposal_id' + + {% if is_incremental() %} + AND _ingested_at :: DATE >= CURRENT_DATE - 2 + {% endif %} +), + +voter AS ( + SELECT + tx_id, + split_part(attribute_value, '/', 0) as voter + FROM {{ ref('silver__msg_attributes') }} + WHERE attribute_key = 'acc_seq' + + {% if is_incremental() %} + AND _ingested_at :: DATE >= CURRENT_DATE - 2 + {% endif %} +) + +SELECT + block_id, + block_timestamp, + blockchain, + chain_id, + o.tx_id, + tx_status, + v.voter, + p.proposal_id, + vote_option, + vote_weight, + _ingested_at +FROM vote_options o + +LEFT OUTER JOIN proposal_id p +ON o.tx_id = p.tx_id AND o.msg_index = p.msg_index + +LEFT OUTER JOIN voter v +ON o.tx_id = v.tx_id + +LEFT OUTER JOIN {{ ref('silver__transactions') }} t +ON o.tx_id = t.tx_id + +{% if is_incremental() %} +WHERE _ingested_at :: DATE >= CURRENT_DATE - 2 +{% endif %} \ No newline at end of file diff --git a/models/silver/silver__governance_votes.yml b/models/silver/silver__governance_votes.yml new file mode 100644 index 0000000..37b5b75 --- /dev/null +++ b/models/silver/silver__governance_votes.yml @@ -0,0 +1,60 @@ +version: 2 +models: + - name: silver__governance_votes + description: Records of all votes on proposals. + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - TX_ID + - PROPOSAL_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: BLOCKCHAIN + description: "{{ doc('blockchain') }}" + tests: + - not_null + - name: CHAIN_ID + description: "{{ doc('chain_id') }}" + tests: + - not_null + - name: TX_ID + description: "{{ doc('tx_id') }}" + tests: + - not_null + - name: TX_STATUS + description: "{{ doc('tx_status') }}" + tests: + - not_null + - name: VOTER + description: "{{ doc('voter') }}" + tests: + - not_null + - name: PROPOSAL_ID + description: "{{ doc('proposal_id') }}" + tests: + - not_null + - name: VOTE_OPTION + description: "{{ doc('vote_option') }}" + tests: + - not_null + - name: _INGESTED_AT + description: "{{ doc('ingested_at') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - TIMESTAMP_NTZ \ No newline at end of file