add address mapping from on chain (#62)

This commit is contained in:
eric-laurello 2024-10-15 12:55:30 -04:00 committed by GitHub
parent 22e3dec758
commit 513239b994
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 92 additions and 0 deletions

View File

@ -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`.`<table_name>`)
**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)

View File

@ -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)

View File

@ -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") }}'