Merge pull request #41 from eevui/governance-votes

Governance votes
This commit is contained in:
Godwin 2022-11-02 10:32:17 +01:00 committed by GitHub
commit 26dfd40f4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 361 additions and 0 deletions

View File

@ -0,0 +1,21 @@
{{ config(
materialized = 'view'
) }}
with governance_votes as (
select
tx_id,
block_id,
block_timestamp,
blockchain,
chain_id,
voter,
proposal_id,
vote_option,
vote_option_text,
vote_weight,
tx_succeeded
from {{ ref('silver__governance_votes') }}
)
select * from governance_votes

View File

@ -0,0 +1,126 @@
version: 2
models:
- name: core__fact_governance_votes
description: |-
This table contains votes cast on governance proposals.
columns:
- name: tx_id
description: "{{ doc('tx_id') }}"
tests:
- unique
- not_null
- relationships:
to: ref('silver__transactions')
field: tx_id
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- string
- varchar
- name: block_id
description: "{{ doc('block_id') }}"
tests:
- not_null
- relationships:
to: ref('silver__blocks')
field: block_id
- 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_column_values_to_be_in_type_list:
column_type_list:
- timestamp_ntz
- name: blockchain
description: "{{ doc('blockchain') }}"
tests:
- not_null
- accepted_values:
values:
- 'terra'
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- string
- varchar
- name: chain_id
description: "{{ doc('chain_id') }}"
tests:
- not_null
- accepted_values:
values:
- 'phoenix-1'
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- string
- varchar
- name: voter
description: "{{ doc('voter') }}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- string
- varchar
- name: proposal_id
description: "{{ doc('proposal_id') }}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- number
- name: vote_option
description: "{{ doc('vote_option') }}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_between:
min_value: 1
max_value: 4
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- number
- name: vote_option_text
description: "{{ doc('vote_option_text') }}"
tests:
- not_null
- accepted_values:
values:
- 'Yes'
- 'Abstain'
- 'No'
- 'NoWithVeto'
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- string
- varchar
- name: vote_weight
description: "{{ doc('vote_weight') }}"
tests:
- not_null
- accepted_values:
values:
- 1
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- number
- name: tx_succeeded
description: "{{ doc('tx_succeeded') }}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- boolean

View File

@ -0,0 +1,5 @@
{% docs vote_option %}
The numerical vote option cast by the voter.
{% enddocs %}

View File

@ -0,0 +1,5 @@
{% docs vote_option_text %}
The human-readable vote option cast by the voter.
{% enddocs %}

View File

@ -0,0 +1,5 @@
{% docs vote_weight %}
The weight of the vote cast by the voter. For now, it's always a full vote: `1`.
{% enddocs %}

View File

@ -0,0 +1,5 @@
{% docs voter %}
The address of the validator or delegator who casted this vote.
{% enddocs %}

View File

@ -0,0 +1,61 @@
{{ config(
materialized = 'incremental',
unique_key = 'tx_id',
incremental_strategy = 'delete+insert'
) }}
with base_votes as (
select
tx_id,
block_id,
block_timestamp,
tx_succeeded,
chain_id,
attributes,
_inserted_timestamp
from {{ ref('silver__messages') }}
where message_type = '/cosmos.gov.v1beta1.MsgVote'
and {{ incremental_load_filter('_inserted_timestamp') }}
),
parsed_votes as (
select
tx_id,
block_id,
block_timestamp,
tx_succeeded,
chain_id,
attributes:message:sender::text as voter,
attributes:proposal_vote:proposal_id::number as proposal_id,
parse_json(attributes:proposal_vote:option) as parsed_vote_option,
parsed_vote_option:option::number as vote_option,
case vote_option
when 1 then 'Yes'
when 2 then 'Abstain'
when 3 then 'No'
when 4 then 'NoWithVeto'
end as vote_option_text,
parsed_vote_option:weight::number as vote_weight,
'terra' as blockchain,
_inserted_timestamp
from base_votes
),
final as (
select
tx_id,
block_id,
block_timestamp,
blockchain,
chain_id,
voter,
proposal_id,
vote_option,
vote_option_text,
vote_weight,
tx_succeeded,
_inserted_timestamp
from parsed_votes
)
select * from final

View File

@ -0,0 +1,133 @@
version: 2
models:
- name: silver__governance_votes
description: |-
This table contains votes cast on governance proposals.
columns:
- name: tx_id
description: "{{ doc('tx_id') }}"
tests:
- unique
- not_null
- relationships:
to: ref('silver__transactions')
field: tx_id
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- string
- varchar
- name: block_id
description: "{{ doc('block_id') }}"
tests:
- not_null
- relationships:
to: ref('silver__blocks')
field: block_id
- 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_column_values_to_be_in_type_list:
column_type_list:
- timestamp_ntz
- name: blockchain
description: "{{ doc('blockchain') }}"
tests:
- not_null
- accepted_values:
values:
- 'terra'
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- string
- varchar
- name: chain_id
description: "{{ doc('chain_id') }}"
tests:
- not_null
- accepted_values:
values:
- 'phoenix-1'
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- string
- varchar
- name: voter
description: "{{ doc('voter') }}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- string
- varchar
- name: proposal_id
description: "{{ doc('proposal_id') }}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- number
- name: vote_option
description: "{{ doc('vote_option') }}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_between:
min_value: 1
max_value: 4
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- number
- name: vote_option_text
description: "{{ doc('vote_option_text') }}"
tests:
- not_null
- accepted_values:
values:
- 'Yes'
- 'Abstain'
- 'No'
- 'NoWithVeto'
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- string
- varchar
- name: vote_weight
description: "{{ doc('vote_weight') }}"
tests:
- not_null
- accepted_values:
values:
- 1
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- number
- name: tx_succeeded
description: "{{ doc('tx_succeeded') }}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- boolean
- 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