mirror of
https://github.com/FlipsideCrypto/sei-models.git
synced 2026-02-06 15:36:45 +00:00
add address mapping from on chain (#62)
This commit is contained in:
parent
22e3dec758
commit
513239b994
@ -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)
|
||||
|
||||
|
||||
60
models/gold/core/core__dim_address_mapping.sql
Normal file
60
models/gold/core/core__dim_address_mapping.sql
Normal 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)
|
||||
31
models/gold/core/core__dim_address_mapping.yml
Normal file
31
models/gold/core/core__dim_address_mapping.yml
Normal 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") }}'
|
||||
Loading…
Reference in New Issue
Block a user