From 513239b994d1f62f1400ba277c587d97084929bc Mon Sep 17 00:00:00 2001 From: eric-laurello <102970824+eric-laurello@users.noreply.github.com> Date: Tue, 15 Oct 2024 12:55:30 -0400 Subject: [PATCH] add address mapping from on chain (#62) --- models/descriptions/__overview__.md | 1 + .../gold/core/core__dim_address_mapping.sql | 60 +++++++++++++++++++ .../gold/core/core__dim_address_mapping.yml | 31 ++++++++++ 3 files changed, 92 insertions(+) create mode 100644 models/gold/core/core__dim_address_mapping.sql create mode 100644 models/gold/core/core__dim_address_mapping.yml diff --git a/models/descriptions/__overview__.md b/models/descriptions/__overview__.md index 92aa3be..b576fe5 100644 --- a/models/descriptions/__overview__.md +++ b/models/descriptions/__overview__.md @@ -24,6 +24,7 @@ There is more information on how to use dbt docs in the last section of this doc ### EVM Tables (`SEI`.`CORE_EVM`.``) **Core Dimension Tables:** +- [dim_address_mapping](#!/model/model.sei_models.core__dim_address_mapping) - [dim_labels](#!/model/model.sei_models.core__dim_labels) - [dim_tokens](#!/model/model.sei_models.core__dim_tokens) diff --git a/models/gold/core/core__dim_address_mapping.sql b/models/gold/core/core__dim_address_mapping.sql new file mode 100644 index 0000000..da8b2b2 --- /dev/null +++ b/models/gold/core/core__dim_address_mapping.sql @@ -0,0 +1,60 @@ +{{ config( + materialized = 'incremental', + unique_key = "sei_address", + incremental_strategy = 'merge', + merge_exclude_columns = ["block_timestamp_associated","block_id_associated","inserted_timestamp"], + cluster_by = ['block_timestamp_associated::DATE'], + post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION ON EQUALITY(sei_address, evm_address);", + tags = ['core','full_test'] +) }} + +WITH base AS ( + + SELECT + block_timestamp, + block_id, + tx_id, + msg_index, + OBJECT_AGG( + attribute_key :: STRING, + attribute_value :: variant + ) AS j, + j :sei_addr :: STRING AS sei_address, + j :evm_addr :: STRING AS evm_address + FROM + {{ ref('silver__msg_attributes') }} A + WHERE + tx_succeeded + AND msg_type = 'address_associated' + +{% if is_incremental() %} +AND modified_timestamp >= ( + SELECT + MAX( + modified_timestamp + ) + FROM + {{ this }} +) +{% endif %} +GROUP BY + block_timestamp, + block_id, + tx_id, + msg_index +) +SELECT + block_timestamp AS block_timestamp_associated, + block_id AS block_id_associated, + sei_address, + LOWER(evm_address) AS evm_address, + {{ dbt_utils.generate_surrogate_key( + ['sei_address'] + ) }} AS dim_address_mapping_id, + SYSDATE() AS inserted_timestamp, + SYSDATE() AS modified_timestamp, + '{{ invocation_id }}' AS _invocation_id +FROM + base qualify(ROW_NUMBER() over(PARTITION BY sei_address +ORDER BY + block_timestamp) = 1) diff --git a/models/gold/core/core__dim_address_mapping.yml b/models/gold/core/core__dim_address_mapping.yml new file mode 100644 index 0000000..ccb6cae --- /dev/null +++ b/models/gold/core/core__dim_address_mapping.yml @@ -0,0 +1,31 @@ +version: 2 +models: + - name: core__dim_address_mapping + description: 'A dimension table that maps the sei cosmos address to the corresponding sei evm address' + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - sei_address + columns: + - name: block_timestamp_associated + description: "The block timestamp associated with the first mapping transaction" + tests: + - dbt_expectations.expect_column_to_exist + - name: block_id_associated + description: "The tx_id associated with the first mapping transaction" + tests: + - dbt_expectations.expect_column_to_exist + - name: sei_address + description: "{{ doc('address') }}" + tests: + - dbt_expectations.expect_column_to_exist + - name: evm_address + description: "The corresponding evm address" + tests: + - dbt_expectations.expect_column_to_exist + - name: dim_address_mapping_id + description: '{{ doc("pk") }}' + - name: INSERTED_TIMESTAMP + description: '{{ doc("inserted_timestamp") }}' + - name: MODIFIED_TIMESTAMP + description: '{{ doc("modified_timestamp") }}' \ No newline at end of file