From 19d045cabb31765b67b5b05bf220fa869164e265 Mon Sep 17 00:00:00 2001 From: eric-laurello <102970824+eric-laurello@users.noreply.github.com> Date: Tue, 30 Jan 2024 14:14:50 -0500 Subject: [PATCH] lables update (#49) --- models/descriptions/table_dim_labels.md | 5 +++ models/gold/core/core__dim_labels.sql | 18 +++++++- models/gold/core/core__dim_labels.yml | 6 ++- models/silver/core/silver__address_labels.sql | 41 +++++++++++++++++++ models/sources.yml | 1 + 5 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 models/descriptions/table_dim_labels.md create mode 100644 models/silver/core/silver__address_labels.sql diff --git a/models/descriptions/table_dim_labels.md b/models/descriptions/table_dim_labels.md new file mode 100644 index 0000000..10e72c4 --- /dev/null +++ b/models/descriptions/table_dim_labels.md @@ -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 %} \ No newline at end of file diff --git a/models/gold/core/core__dim_labels.sql b/models/gold/core/core__dim_labels.sql index cf3aec5..e2b684f 100644 --- a/models/gold/core/core__dim_labels.sql +++ b/models/gold/core/core__dim_labels.sql @@ -26,7 +26,7 @@ SELECT ) AS modified_timestamp FROM {{ ref('core__dim_tokens') }} -UNION +UNION ALL SELECT blockchain, creator, @@ -51,3 +51,19 @@ SELECT ) AS modified_timestamp FROM {{ ref('gov__fact_validators') }} +UNION ALL +SELECT + blockchain, + creator, + address, + label_type, + label_subtype, + address_name AS label, + project_name, + labels_combined_id AS dim_labels_id, + inserted_timestamp, + modified_timestamp +FROM + {{ ref('silver__address_labels') }} +WHERE + label_subtype <> 'validator' diff --git a/models/gold/core/core__dim_labels.yml b/models/gold/core/core__dim_labels.yml index c02d528..13fcbca 100644 --- a/models/gold/core/core__dim_labels.yml +++ b/models/gold/core/core__dim_labels.yml @@ -1,7 +1,11 @@ version: 2 models: - name: core__dim_labels - description: Contains all Flipside sourced labels for the Cosmos blockchain. + description: '{{ doc("table_dim_labels") }}' + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - ADDRESS columns: - name: ADDRESS description: "{{ doc('address') }}" diff --git a/models/silver/core/silver__address_labels.sql b/models/silver/core/silver__address_labels.sql new file mode 100644 index 0000000..a974f44 --- /dev/null +++ b/models/silver/core/silver__address_labels.sql @@ -0,0 +1,41 @@ +{{ config( + materialized = 'incremental', + 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 = ['daily'] +) }} + +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 + {{ source( + 'crosschain_silver', + 'labels_combined' + ) }} +WHERE + blockchain = 'cosmos' + +{% if is_incremental() %} +AND modified_timestamp >= ( + SELECT + MAX(modified_timestamp) + FROM + {{ this }} +) +{% endif %} diff --git a/models/sources.yml b/models/sources.yml index 5416de2..f09e97b 100644 --- a/models/sources.yml +++ b/models/sources.yml @@ -35,6 +35,7 @@ sources: schema: silver tables: - name: number_sequence + - name: labels_combined - name: github_actions database: cosmos schema: github_actions