This commit is contained in:
Eric Laurello 2024-01-12 08:16:55 -05:00
parent 8221873056
commit bd3fc9ced2
4 changed files with 133 additions and 105 deletions

View File

@ -8,22 +8,43 @@ SELECT
module,
pool_created_block_timestamp,
pool_created_block_id,
pool_id,
pool_address,
assets,
A.pool_id,
COALESCE(
b.address,
A.pool_address
) AS pool_address,
COALESCE(
b.assets,
A.assets
) AS assets,
COALESCE(
pool_metadata_id,
{{ dbt_utils.generate_surrogate_key(
['_unique_key']
) }}
) AS dim_liquidity_pools_id,
COALESCE(
inserted_timestamp,
'2000-01-01'
GREATEST(
COALESCE(
A.inserted_timestamp,
'2000-01-01'
),
COALESCE(
b.inserted_timestamp,
'2000-01-01'
)
) AS inserted_timestamp,
COALESCE(
modified_timestamp,
'2000-01-01'
GREATEST(
COALESCE(
A.modified_timestamp,
'2000-01-01'
),
COALESCE(
b.modified_timestamp,
'2000-01-01'
)
) AS modified_timestamp
FROM
{{ ref('silver__pool_metadata') }}
{{ ref('silver__pool_metadata') }} A
LEFT JOIN {{ ref('silver__concentrated_liquidity_pools_latest') }}
b
ON A.pool_id = b.pool_id

View File

@ -1,109 +1,18 @@
version: 2
models:
- name: silver__concentrated_liquidity_pools
description: Includes all actions entering and exiting liquidity pools
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- TX_ID
- MSG_INDEX
- CURRENCY
- POOL_ID
- _INSERTED_TIMESTAMP
columns:
- name: BLOCK_ID
description: "{{ doc('block_id') }}"
- name: TYPE
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- NUMBER
- FLOAT
- name: BLOCK_TIMESTAMP
description: "{{ doc('block_timestamp') }}"
- name: address
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- TIMESTAMP_NTZ
- 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: TX_SUCCEEDED
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- BOOLEAN
- name: MSG_GROUP
description: "{{ doc('silver_msg_group') }}"
tests:
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- NUMBER
- FLOAT
- name: MSG_SUB_GROUP
description: "{{ doc('msg_sub_group') }}"
tests:
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- NUMBER
- FLOAT
- name: MSG_INDEX
description: "{{ doc('msg_index') }}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- NUMBER
- FLOAT
- name: LIQUIDITY_PROVIDER_ADDRESS
description: "{{ doc('liquidity_provider_address') }}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- STRING
- VARCHAR
- dbt_expectations.expect_column_values_to_match_regex:
regex: osmo1[0-9a-z]{38,38}
- name: ACTION
description: "{{ doc('action') }}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- STRING
- VARCHAR
- name: POOL_ID
description: "{{ doc('pool_id') }}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- NUMBER
- FLOAT
- name: AMOUNT
description: "{{ doc('amount') }}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- NUMBER
- FLOAT
- name: CURRENCY
description: "{{ doc('currency') }}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- STRING
- VARCHAR
- name: DECIMAL
description: "{{ doc('decimal') }}"
- name: _INSERTED_TIMESTAMP
description: "{{ doc('inserted_timestamp') }}"
tests:

View File

@ -0,0 +1,80 @@
{{ config(
materialized = 'incremental',
unique_key = 'pool_id',
incremental_strategy = 'merge',
merge_exclude_columns = ["inserted_timestamp"],
tags = ['noncore']
) }}
WITH base AS (
SELECT
resp,
_inserted_timestamp
FROM
{{ ref(
'bronze_api__concentrated_liquidity_pools'
) }}
{% if is_incremental() %}
WHERE
_inserted_timestamp >= (
SELECT
MAX(
_inserted_timestamp
)
FROM
{{ this }}
)
{% endif %}
)
SELECT
TYPE,
address,
incentives_address,
spread_rewards_address,
pool_id,
current_tick_liquidity,
token0,
token1,
token2,
token3,
token4,
ARRAY_CONSTRUCT_COMPACT (OBJECT_CONSTRUCT('asset_addres', token0),CASE
WHEN token1 IS NOT NULL THEN OBJECT_CONSTRUCT('asset_addres', token1)END,CASE
WHEN token2 IS NOT NULL THEN OBJECT_CONSTRUCT('asset_addres', token2)END,CASE
WHEN token3 IS NOT NULL THEN OBJECT_CONSTRUCT('asset_addres', token3)END,CASE
WHEN token4 IS NOT NULL THEN OBJECT_CONSTRUCT('asset_addres', token4)END) AS assets,
current_sqrt_price,
current_tick,
tick_spacing,
exponent_at_price_one,
spread_factor,
last_liquidity_update,
{{ dbt_utils.generate_surrogate_key(
['pool_id']
) }} AS concentrated_liquidity_pools_latest_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp,
_inserted_timestamp,
'{{ invocation_id }}' AS _invocation_id
FROM
{{ ref(
'silver__concentrated_liquidity_pools'
) }}
{% if is_incremental() %}
WHERE
_inserted_timestamp >= (
SELECT
MAX(
_inserted_timestamp
)
FROM
{{ this }}
)
{% endif %}
qualify(ROW_NUMBER() over(PARTITION BY pool_id
ORDER BY
_inserted_timestamp DESC)) = 1

View File

@ -0,0 +1,18 @@
version: 2
models:
- name: silver__concentrated_liquidity_pools_latest
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- POOL_ID
columns:
- name: TYPE
tests:
- not_null
- name: address
tests:
- not_null
- name: _INSERTED_TIMESTAMP
description: "{{ doc('inserted_timestamp') }}"
tests:
- not_null