An 1246 governance votes (#20)

* silver governance votes table

* testing file, descriptions, and changes to incorrect descriptions in another yml file

* changes to logic to handle old votes

* switch to correct vote options
This commit is contained in:
Jessica Huhnke 2022-05-16 09:51:44 -05:00 committed by GitHub
parent ed955d6036
commit eb72fd18db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 163 additions and 3 deletions

View File

@ -0,0 +1,5 @@
{% docs vote_option %}
How the delegator voted on the proposal.
{% enddocs %}

View File

@ -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 %}

View File

@ -0,0 +1,5 @@
{% docs voter %}
Address of the delegator that voted on the proposal.
{% enddocs %}

View File

@ -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

View File

@ -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

View File

@ -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 %}

View File

@ -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