This commit is contained in:
Eric Laurello 2024-01-31 09:14:47 -05:00
parent 2f3c3e8931
commit bd5a30c872
8 changed files with 46 additions and 374 deletions

View File

@ -0,0 +1,5 @@
{% docs table_dim_labels %}
The labels table is a store of one-to-one address identifiers, or an address name. Labels are broken out into a "type" (such as cex, dex, dapp, games, etc.) and a "subtype" (ex: contract_deployer, hot_wallet, token_contract, etc.) in order to help classify each address name into similar groups. Our labels are sourced from many different places, but can primarily be grouped into two categories: automatic and manual. Automatic labels are continuously labeled based on certain criteria, such as a known contract deploying another contract, behavior based algorithms for finding deposit wallets, and consistent data pulls of custom protocol APIs. Manual labels are done periodically to find addresses that cannot be found programmatically such as finding new protocol addresses, centralized exchange hot wallets, or trending addresses. Labels can also be added by our community by using our add-a-label tool (https://science.flipsidecrypto.xyz/add-a-label/) or on-chain with near (https://near.social/lord1.near/widget/Form) and are reviewed by our labels team. A label can be removed by our labels team if it is found to be incorrect or no longer relevant; this generally will only happen for mislabeled deposit wallets.
{% enddocs %}

View File

@ -9,25 +9,12 @@ SELECT
creator,
label_type,
label_subtype,
label,
address_name AS label,
project_name,
decimals,
deployment_tx_id,
COALESCE (
address_labels_id,
{{ dbt_utils.generate_surrogate_key(
['address']
) }}
) AS dim_address_labels_id,
COALESCE(
inserted_timestamp,
'2000-01-01'
) AS inserted_timestamp,
COALESCE(
modified_timestamp,
'2000-01-01'
) AS modified_timestamp
NULL AS decimals,
NULL AS deployment_tx_id,
labels_combined_id AS dim_labels_id,
inserted_timestamp,
modified_timestamp
FROM
{{ ref('silver__address_labels') }}
WHERE
address IS NOT NULL

View File

@ -2,8 +2,7 @@ version: 2
models:
- name: core__dim_address_labels
descriptions: |-
This table contains Terra2 blockchain's list of tokens and their labels.
description: '{{ doc("table_dim_labels") }}'
tests:
- dbt_utils.unique_combination_of_columns:
@ -15,17 +14,11 @@ models:
- name: BLOCKCHAIN
description: "{{ doc('blockchain') }}"
- name: DEPLOYMENT_TX_ID
description: "{{ doc('deployment_tx_id') }}"
- name: LABEL
description: "{{ doc('label') }}"
- name: ADDRESS
description: "{{ doc('address') }}"
- name: DECIMALS
description: "{{ doc('decimal') }}"
- name: CREATOR
description: "{{ doc('creator') }}"

View File

@ -1,101 +1,41 @@
{{ config(
materialized = 'incremental',
unique_key = 'address',
unique_key = ['address', 'blockchain'],
incremental_strategy = 'merge',
merge_exclude_columns = ["inserted_timestamp"],
cluster_by = 'modified_timestamp::DATE',
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION ON EQUALITY(address); DELETE FROM {{ this }} WHERE _is_deleted = TRUE;",
tags = ['noncore']
) }}
WITH labels AS (
SELECT
blockchain,
address,
creator,
label_type,
label_subtype,
address_name AS label,
project_name,
system_created_at AS _inserted_timestamp
FROM
{{ source(
'crosschain_silver',
'address_labels'
) }}
WHERE
blockchain = 'terra'
AND delete_flag IS NULL
AND {{ incremental_load_filter('_inserted_timestamp') }}
qualify ROW_NUMBER() over (
PARTITION BY address
ORDER BY
creator DESC
) = 1
),
tokens AS (
SELECT
blockchain,
'token_deployment' AS creator,
tx_id,
label,
symbol,
address,
decimals,
_inserted_timestamp
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,
IFF(
l.label_type IS NOT NULL,
l.label_type,
'token'
) AS label_type,
IFF(
l.label_subtype IS NOT NULL,
l.label_subtype,
'token_contract'
) AS 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,
GREATEST(
l._inserted_timestamp,
t._inserted_timestamp
) AS _inserted_timestamp,
{{ dbt_utils.generate_surrogate_key(
['COALESCE( t.address, l.address )']
) }} AS address_labels_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp,
'{{ invocation_id }}' AS _invocation_id
FROM
labels l full
JOIN tokens t USING (
blockchain,
address
)
)
SELECT
*
system_created_at,
insert_date,
blockchain,
address,
creator,
label_type,
label_subtype,
address_name,
project_name,
_is_deleted,
labels_combined_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp,
'{{ invocation_id }}' AS _invocation_id
FROM
FINAL
{{ source(
'crosschain_silver',
'labels_combined'
) }}
WHERE
blockchain = 'terra'
{% if is_incremental() %}
AND modified_timestamp >= (
SELECT
MAX(modified_timestamp)
FROM
{{ this }}
)
{% endif %}

View File

@ -1,37 +0,0 @@
version: 2
models:
- name: silver__address_labels
descriptions: |-
This table contains Terra2 blockchain's list of tokens and their labels.
columns:
- name: BLOCKCHAIN
description: "{{ doc('blockchain') }}"
- name: DEPLOYMENT_TX_ID
description: "{{ doc('deployment_tx_id') }}"
- name: LABEL
description: "{{ doc('label') }}"
- name: ADDRESS
description: "{{ doc('address') }}"
- name: DECIMALS
description: "{{ doc('decimal') }}"
- name: CREATOR
description: "{{ doc('creator') }}"
- name: LABEL_TYPE
description: "{{ doc('label_type') }}"
- name: LABEL_SUBTYPE
description: "{{ doc('label_subtype') }}"
- name: PROJECT_NAME
description: "{{ doc('project_name') }}"
- name: _INSERTED_TIMESTAMP
description: "{{ doc('_inserted_timestamp') }}"

View File

@ -1,47 +0,0 @@
{{ config(
materialized = "incremental",
cluster_by = ["_inserted_timestamp::DATE"],
unique_key = "address",
merge_exclude_columns = ["inserted_timestamp"],
tags = ['noncore']
) }}
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,
{{ dbt_utils.generate_surrogate_key(
['address']
) }} AS token_labels_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp,
'{{ invocation_id }}' AS _invocation_id
FROM
token_labels

View File

@ -1,116 +0,0 @@
version: 2
models:
- 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:
- address
columns:
- 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
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- STRING
- VARCHAR
- 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: LABEL
description: "{{ doc('label') }}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- STRING
- VARCHAR
- name: ADDRESS
description: "{{ doc('address') }}"
tests:
- unique
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- STRING
- VARCHAR
- name: SYMBOL
description: "{{ doc('symbol') }}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- STRING
- VARCHAR
- name: DECIMALS
description: "{{ doc('decimal') }}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- decimal
- float
- NUMBER
- name: CREATOR
description: "{{ doc('creator') }}"
tests:
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- STRING
- VARCHAR
- name: LABEL_TYPE
description: "{{ doc('label_type') }}"
tests:
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- STRING
- VARCHAR
- name: LABEL_SUBTYPE
description: "{{ doc('label_subtype') }}"
tests:
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- STRING
- VARCHAR
- name: PROJECT_NAME
description: "{{ doc('project_name') }}"
tests:
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- STRING
- VARCHAR
- name: _INGESTED_AT
description: "{{ doc('_ingested_at') }}"
- name: _INSERTED_TIMESTAMP
description: "{{ doc('_inserted_timestamp') }}"

View File

@ -4,69 +4,16 @@ sources:
- name: chainwalkers
schema: prod
database: chainwalkers
freshness: # default freshness
warn_after: { count: 12, period: hour }
error_after: { count: 24, period: hour }
loaded_at_field: _inserted_timestamp
tables:
- name: terra2_blocks
description: "Blocks from the Terra chain. Note always use the latest inserted timestamp as duplicates can exist in this table!"
columns:
- name: record_id
description: A unique id for the record generated by Chainwalkers
- name: offset_id
description: Synonmous with block_id for Terra
- name: block_id
description: The height of the chain this block corresponds with
- name: block_timestamp
description: The time the block was minted
- name: network
description: The blockchain network (i.e. mainnet, testnet, etc.)
- name: chain_id
description: Synonmous with blockchain name for Terra
- name: tx_count
description: The number of transactions in the block
- name: header
description: A json column containing the blocks header information
- name: ingested_at
description: The time this row was ingested by Chainwalkers
- name: _inserted_timestamp
description: The time this row was inserted into Snowflake
- name: terra2_txs
description: "Txs from the Terra chain. Note always use the latest inserted timestamp as duplicates can exist in this table!"
columns:
- name: record_id
description: A unique id for the record generated by Chainwalkers
- name: tx_id
description: Synonmous with transaction hash, a unique on chain identifier for the transaction
- name: tx_block_index
description: The index of the transaction within the block. Starts at 0.
- name: offset_id
description: Synonmous with block_id for Terra
- name: block_id
description: The height of the chain this block corresponds with
- name: block_timestamp
description: The time the block was minted
- name: network
description: The blockchain network (i.e. mainnet, testnet, etc.)
- name: chain_id
description: Synonmous with blockchain name for Terra
- name: tx_count
description: The number of transactions in the block
- name: header
description: A json column containing the blocks header information
- name: tx
description: A json object containing the tx and any decoded logs
- name: ingested_at
description: The time this row was ingested by Chainwalkers
- name: _inserted_timestamp
description: The time this row was inserted into Snowflake
- name: crosschain_silver
schema: silver
database: crosschain
tables:
- name: address_labels
- name: number_sequence
- name: labels_combined
- name: bronze
schema: bronze
database: terra