mirror of
https://github.com/FlipsideCrypto/terra-models.git
synced 2026-02-06 13:36:43 +00:00
one labels view
This commit is contained in:
parent
b2b9dd474f
commit
302f252b2c
@ -3,18 +3,70 @@
|
||||
secure = true
|
||||
) }}
|
||||
|
||||
WITH labels AS (
|
||||
|
||||
SELECT
|
||||
blockchain,
|
||||
address,
|
||||
creator,
|
||||
l1_label AS label_type,
|
||||
l2_label AS label_subtype,
|
||||
address_name AS label,
|
||||
project_name
|
||||
FROM
|
||||
{{ source(
|
||||
'labels',
|
||||
'address_labels'
|
||||
) }}
|
||||
WHERE
|
||||
blockchain = 'terra'
|
||||
),
|
||||
tokens AS (
|
||||
SELECT
|
||||
blockchain,
|
||||
'token_deployment' AS creator,
|
||||
tx_id,
|
||||
label,
|
||||
symbol,
|
||||
address,
|
||||
decimals
|
||||
FROM
|
||||
{{ ref('silver__token_labels') }}
|
||||
),
|
||||
FINAL AS (
|
||||
SELECT
|
||||
COALESCE(
|
||||
t.blockchain,
|
||||
l.blockchain
|
||||
) AS blockchain,
|
||||
COALESCE(
|
||||
t.address,
|
||||
l.address
|
||||
) AS address,
|
||||
COALESCE(
|
||||
t.creator,
|
||||
l.creator
|
||||
) AS creator,
|
||||
l.label_type,
|
||||
l.label_subtype,
|
||||
COALESCE(
|
||||
t.symbol,
|
||||
l.label
|
||||
) AS label,
|
||||
COALESCE(
|
||||
t.label,
|
||||
l.project_name
|
||||
) AS project_name,
|
||||
t.decimals,
|
||||
t.tx_id AS deployment_tx_id
|
||||
FROM
|
||||
labels l full
|
||||
JOIN tokens t USING (
|
||||
blockchain,
|
||||
address
|
||||
)
|
||||
)
|
||||
SELECT
|
||||
blockchain,
|
||||
address,
|
||||
creator,
|
||||
l1_label AS label_type,
|
||||
l2_label AS label_subtype,
|
||||
address_name AS label,
|
||||
project_name
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'labels',
|
||||
'address_labels'
|
||||
) }}
|
||||
WHERE
|
||||
blockchain = 'terra'
|
||||
FINAL
|
||||
|
||||
@ -1,37 +1,28 @@
|
||||
version: 2
|
||||
|
||||
models:
|
||||
version: 2
|
||||
models:
|
||||
- name: core__dim_tokens
|
||||
- name: core__dim_address_labels
|
||||
descriptions: |-
|
||||
This table contains Terra2 blockchain's list of tokens and their labels.
|
||||
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- contract_address
|
||||
- address
|
||||
|
||||
columns:
|
||||
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: "{{ doc('block_timestamp') }}"
|
||||
|
||||
|
||||
- name: BLOCKCHAIN
|
||||
description: "{{ doc('blockchain') }}"
|
||||
|
||||
- name: TX_ID
|
||||
description: "{{ doc('tx_id') }}"
|
||||
- name: DEPLOYMENT_TX_ID
|
||||
description: "{{ doc('deployment_tx_id') }}"
|
||||
|
||||
- name: LABEL
|
||||
description: "{{ doc('label') }}"
|
||||
|
||||
- name: CONTRACT_ADDRESS
|
||||
description: "{{ doc('contract_address') }}"
|
||||
|
||||
|
||||
- name: SYMBOL
|
||||
description: "{{ doc('symbol') }}"
|
||||
- name: ADDRESS
|
||||
description: "{{ doc('address') }}"
|
||||
|
||||
- name: DECIMALS
|
||||
description: "{{ doc('decimal') }}"
|
||||
@ -1,27 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = true
|
||||
) }}
|
||||
|
||||
|
||||
WITH token_labels AS (
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ ref('silver__dim_tokens') }}
|
||||
)
|
||||
|
||||
select
|
||||
blockchain,
|
||||
block_timestamp,
|
||||
tx_id,
|
||||
label,
|
||||
symbol,
|
||||
contract_address,
|
||||
decimals,
|
||||
creator,
|
||||
label_type,
|
||||
label_subtype,
|
||||
project_name
|
||||
from token_labels
|
||||
5
models/descriptions/address.md
Normal file
5
models/descriptions/address.md
Normal file
@ -0,0 +1,5 @@
|
||||
{% docs address %}
|
||||
|
||||
The chain address of the account, token, or contract.
|
||||
|
||||
{% enddocs %}
|
||||
5
models/descriptions/deployment_tx_id.md
Normal file
5
models/descriptions/deployment_tx_id.md
Normal file
@ -0,0 +1,5 @@
|
||||
{% docs deployment_tx_id %}
|
||||
|
||||
The transaction id for the deployment of this token or contract.
|
||||
|
||||
{% enddocs %}
|
||||
@ -1,47 +0,0 @@
|
||||
{{
|
||||
config(
|
||||
materialized="incremental",
|
||||
cluster_by=["_inserted_timestamp::DATE"],
|
||||
unique_key = "contract_address",
|
||||
)
|
||||
}}
|
||||
|
||||
with
|
||||
token_labels as (
|
||||
select
|
||||
block_timestamp,
|
||||
tx_id,
|
||||
message_value:msg:name::string as label,
|
||||
message_value:msg:symbol::string as symbol,
|
||||
iff(
|
||||
attributes:instantiate:_contract_address is not null,
|
||||
attributes:instantiate:_contract_address,
|
||||
attributes:reply:_contract_address
|
||||
)::string as contract_address,
|
||||
message_value:msg:decimals::int as decimals,
|
||||
_ingested_at,
|
||||
_inserted_timestamp
|
||||
from {{ ref("silver__messages") }}
|
||||
where message_value:msg:decimals is not null
|
||||
and {{ incremental_load_filter("_inserted_timestamp") }}
|
||||
),
|
||||
address_labels as (select * from {{ ref('core__dim_address_labels')}})
|
||||
|
||||
|
||||
select
|
||||
'terra' as blockchain,
|
||||
token_labels.block_timestamp,
|
||||
token_labels.tx_id,
|
||||
token_labels.label,
|
||||
token_labels.symbol,
|
||||
token_labels.contract_address,
|
||||
token_labels.decimals,
|
||||
address_labels.creator,
|
||||
address_labels.label_type,
|
||||
address_labels.label_subtype,
|
||||
address_labels.project_name,
|
||||
token_labels._ingested_at,
|
||||
token_labels._inserted_timestamp
|
||||
from token_labels
|
||||
left join
|
||||
address_labels on token_labels.contract_address = address_labels.address
|
||||
39
models/silver/silver__token_labels.sql
Normal file
39
models/silver/silver__token_labels.sql
Normal file
@ -0,0 +1,39 @@
|
||||
{{ config(
|
||||
materialized = "incremental",
|
||||
cluster_by = ["_inserted_timestamp::DATE"],
|
||||
unique_key = "contract_address",
|
||||
) }}
|
||||
|
||||
WITH token_labels AS (
|
||||
|
||||
SELECT
|
||||
block_timestamp,
|
||||
tx_id,
|
||||
message_value :msg :name :: STRING AS label,
|
||||
message_value :msg :symbol :: STRING AS symbol,
|
||||
IFF(
|
||||
attributes :instantiate :_contract_address IS NOT NULL,
|
||||
attributes :instantiate :_contract_address,
|
||||
attributes :reply :_contract_address
|
||||
) :: STRING AS address,
|
||||
message_value :msg :decimals :: INT AS decimals,
|
||||
_ingested_at,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
{{ ref("silver__messages") }}
|
||||
WHERE
|
||||
message_value :msg :decimals IS NOT NULL
|
||||
AND {{ incremental_load_filter("_inserted_timestamp") }}
|
||||
)
|
||||
SELECT
|
||||
'terra' as blockchain,
|
||||
block_timestamp,
|
||||
tx_id,
|
||||
label,
|
||||
symbol,
|
||||
address,
|
||||
decimals,
|
||||
_ingested_at,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
token_labels
|
||||
@ -1,15 +1,14 @@
|
||||
version: 2
|
||||
|
||||
models:
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__dim_tokens
|
||||
- name: silver__token_labels
|
||||
descriptions: |-
|
||||
This table contains Terra2 blockchain's list of tokens and their labels.
|
||||
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- contract_address
|
||||
- address
|
||||
|
||||
columns:
|
||||
|
||||
@ -48,8 +47,8 @@ models:
|
||||
- STRING
|
||||
- VARCHAR
|
||||
|
||||
- name: CONTRACT_ADDRESS
|
||||
description: "{{ doc('contract_address') }}"
|
||||
- name: ADDRESS
|
||||
description: "{{ doc('address') }}"
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
Loading…
Reference in New Issue
Block a user