clean up asset detail models

This commit is contained in:
mattromano 2025-01-15 14:32:31 -08:00
parent fdefd3485b
commit abc5ae25d7
10 changed files with 319 additions and 313 deletions

View File

@ -6,51 +6,9 @@ models:
combination_of_columns:
- _LOG_ID
columns:
- name: TX_HASH
tests:
- not_null
- name: BLOCK_NUMBER
tests:
- not_null
- name: BLOCK_TIMESTAMP
tests:
- not_null
- dbt_expectations.expect_row_values_to_have_recent_data:
datepart: day
interval: 30
- name: EVENT_INDEX
tests:
- not_null:
where: PLATFORM <> 'Morpho Blue'
- name: BORROWER
tests:
- not_null
- name: PROTOCOL_MARKET
tests:
- not_null
- name: TOKEN_ADDRESS
tests:
- not_null
- name: TOKEN_SYMBOL
- name: AMOUNT_UNADJ
tests:
- not_null
- name: AMOUNT
tests:
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- decimal
- float
- name: AMOUNT_USD
tests:
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- decimal
- float
- name: PLATFORM
tests:
- not_null
- name: BLOCKCHAIN
tests:
- not_null
interval: 30

View File

@ -6,51 +6,9 @@ models:
combination_of_columns:
- _LOG_ID
columns:
- name: TX_HASH
tests:
- not_null
- name: BLOCK_NUMBER
tests:
- not_null
- name: BLOCK_TIMESTAMP
tests:
- not_null
- dbt_expectations.expect_row_values_to_have_recent_data:
datepart: day
interval: 30
- name: EVENT_INDEX
tests:
- not_null:
where: PLATFORM <> 'Morpho Blue'
- name: PROTOCOL_MARKET
tests:
- not_null
- name: DEPOSITOR
tests:
- not_null
- name: TOKEN_ADDRESS
tests:
- not_null
- name: TOKEN_SYMBOL
- name: AMOUNT_UNADJ
tests:
- not_null
- name: AMOUNT
tests:
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- decimal
- float
- name: AMOUNT_USD
tests:
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- decimal
- float
- name: PLATFORM
tests:
- not_null
- name: BLOCKCHAIN
tests:
- not_null
interval: 30

View File

@ -6,55 +6,9 @@ models:
combination_of_columns:
- _LOG_ID
columns:
- name: TX_HASH
tests:
- not_null
- name: BLOCK_NUMBER
tests:
- not_null
- name: BLOCK_TIMESTAMP
tests:
- not_null
- dbt_expectations.expect_row_values_to_have_recent_data:
datepart: day
interval: 60
- name: EVENT_INDEX
tests:
- not_null:
where: PLATFORM <> 'Morpho Blue'
- name: LIQUIDATOR
tests:
- not_null
- name: BORROWER
tests:
- not_null
- name: PROTOCOL_MARKET
tests:
- not_null:
where: PLATFORM <> 'Morpho Blue'
- name: COLLATERAL_TOKEN
tests:
- not_null
- name: COLLATERAL_TOKEN_SYMBOL
- name: AMOUNT_UNADJ
tests:
- not_null
- name: AMOUNT
tests:
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- decimal
- float
- name: AMOUNT_USD
tests:
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- decimal
- float
- name: PLATFORM
tests:
- not_null
- name: BLOCKCHAIN
tests:
- not_null
interval: 30

View File

@ -20,8 +20,7 @@ models:
interval: 30
- name: EVENT_INDEX
tests:
- not_null:
where: PLATFORM <> 'Morpho Blue'
- not_null
- name: PROTOCOL_MARKET
tests:
- not_null

View File

@ -6,52 +6,9 @@ models:
combination_of_columns:
- _LOG_ID
columns:
- name: TX_HASH
tests:
- not_null
- name: BLOCK_NUMBER
tests:
- not_null
- name: BLOCK_TIMESTAMP
tests:
- not_null
- dbt_expectations.expect_row_values_to_have_recent_data:
datepart: day
interval: 30
- name: EVENT_INDEX
tests:
- not_null:
where: PLATFORM <> 'Morpho Blue'
- name: PROTOCOL_MARKET
tests:
- not_null
- name: DEPOSITOR
tests:
- not_null
- name: TOKEN_ADDRESS
tests:
- not_null
- name: TOKEN_SYMBOL
- name: AMOUNT_UNADJ
tests:
- not_null
- name: AMOUNT
tests:
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- decimal
- float
- name: AMOUNT_USD
tests:
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- decimal
- float
- name: PLATFORM
tests:
- not_null
- name: BLOCKCHAIN
tests:
- not_null
interval: 30

View File

@ -9,21 +9,36 @@
WITH blast_contracts AS (
SELECT
*
address,
symbol,
NAME,
decimals,
modified_timestamp
FROM
{{ ref('silver__contracts') }}
{{ ref('core__dim_contracts') }}
WHERE
token_name LIKE 'INIT%'
NAME LIKE 'INIT%'
{% if is_incremental() %}
AND _inserted_timestamp > (
AND modified_timestamp > (
SELECT
max(_inserted_timestamp)
max(modified_timestamp)
FROM
{{ this }}
)
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
AND modified_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
),
contracts AS (
SELECT
address,
symbol,
NAME,
decimals,
modified_timestamp
FROM
{{ ref('core__dim_contracts') }}
),
underlying AS (
SELECT
tx_hash,
@ -42,7 +57,7 @@ underlying AS (
AND trace_status = 'SUCCESS'
AND from_address IN (
SELECT
contract_address
address
FROM
blast_contracts
)
@ -72,24 +87,24 @@ SELECT
A.block_number,
A.tx_hash,
token_address,
b.token_name,
b.token_symbol,
b.token_decimals,
b.name AS token_name,
b.symbol AS token_symbol,
b.decimals AS token_decimals,
underlying_asset_address,
C.token_name AS underlying_name,
C.token_symbol AS underlying_symbol,
C.token_decimals AS underlying_decimals,
C.name AS underlying_name,
C.symbol AS underlying_symbol,
C.decimals AS underlying_decimals,
d.underlying_unwrap_address,
e.token_name AS underlying_unwrap_name,
e.token_symbol AS underlying_unwrap_symbol,
e.token_decimals AS underlying_unwrap_decimals,
b._inserted_timestamp
e.name AS underlying_unwrap_name,
e.symbol AS underlying_unwrap_symbol,
e.decimals AS underlying_unwrap_decimals,
b.modified_timestamp
FROM
underlying A
INNER JOIN blast_contracts b
ON b.contract_address = token_address
ON b.address = token_address
LEFT JOIN unwrapped d USING(underlying_asset_address)
INNER JOIN contracts C
ON C.contract_address = underlying_asset_address
ON C.address = underlying_asset_address
LEFT JOIN contracts e
ON e.contract_address = underlying_unwrap_address
ON e.address = underlying_unwrap_address

View File

@ -66,7 +66,7 @@ init_borrows AS (
{% endif %}
),
token_transfer AS (
-- token transfer checks for withdrawal/deposits in usdb/weth(for hooks leveraging)/blast
SELECT
tx_hash,
contract_address,
@ -107,7 +107,7 @@ token_transfer AS (
)
),
native_transfer AS (
-- native transfer checks for withdrawal/deposits as eth
SELECT
tx_hash,
from_address AS wrapped_address,
@ -119,7 +119,7 @@ native_transfer AS (
FROM
{{ ref('core__fact_traces') }}
WHERE
from_address IN ('0xf683ce59521aa464066783d78e40cd9412f33d21') -- hard code wweth contract here
from_address IN ('0xf683ce59521aa464066783d78e40cd9412f33d21')
AND tx_hash IN (
SELECT
tx_hash
@ -144,7 +144,6 @@ init_combine AS (
pool,
loan_amount_raw,
C.underlying_decimals AS underlying_wrap_decimals,
-- this does the filtering for if not eth(native) -> if not token(USDB/WETH/BLAST) -> then underlying token (eg. ezETH/weETH/etc)
COALESCE(
eth_value,
underlying_amount_raw
@ -176,7 +175,7 @@ init_combine AS (
LEFT JOIN asset_details C
ON b.pool = C.token_address
LEFT JOIN token_transfer d
ON b.tx_hash = d.tx_hash -- AND b.pool = d.from_address
ON b.tx_hash = d.tx_hash
LEFT JOIN native_transfer e
ON b.tx_hash = e.tx_hash
)

View File

@ -4,38 +4,117 @@ models:
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- _log_id
- _LOG_ID
columns:
- name: BLOCK_NUMBER
tests:
- not_null
- not_null:
error_if: ">10"
warn_if: "<10"
- name: BLOCK_TIMESTAMP
tests:
- not_null
- not_null:
error_if: ">10"
warn_if: "<10"
- dbt_expectations.expect_row_values_to_have_recent_data:
datepart: day
interval: 3
warn_if: ">3"
error_if: ">14"
- name: TX_HASH
tests:
- not_null:
error_if: ">10"
warn_if: "<10"
- name: EVENT_INDEX
tests:
- not_null:
error_if: ">10"
warn_if: "<10"
- name: ORIGIN_FROM_ADDRESS
tests:
- not_null:
error_if: ">10"
warn_if: "<10"
- name: ORIGIN_TO_ADDRESS
tests:
- not_null:
error_if: ">10"
warn_if: "<10"
- name: ORIGIN_FUNCTION_SIGNATURE
tests:
- not_null:
error_if: ">10"
warn_if: "<10"
- name: CONTRACT_ADDRESS
tests:
- not_null:
error_if: ">10"
warn_if: "<10"
- name: BORROWER
tests:
- not_null
- not_null:
error_if: ">10"
warn_if: "<10"
- name: BORROWS_CONTRACT_ADDRESS
tests:
- not_null
- not_null:
error_if: ">10"
warn_if: "<10"
- name: BORROWS_SYMBOL
tests:
- not_null
- not_null:
error_if: ">10"
warn_if: "<10"
- name: TOKEN_ADDRESS
tests:
- not_null
- not_null:
error_if: ">10"
warn_if: "<10"
- name: TOKEN_SYMBOL
tests:
- not_null
- name: LOAN_AMOUNT
- not_null:
error_if: ">10"
warn_if: "<10"
- name: UNDERLYING_SYMBOL
tests:
- dbt_expectations.expect_column_values_to_be_in_type_list:
- not_null:
error_if: ">10"
warn_if: "<10"
- name: AMOUNT_UNADJ
tests:
- not_null:
error_if: ">10"
warn_if: "<10"
- name: AMOUNT
tests:
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- decimal
- float
- name: TX_HASH
tests:
- not_null
- name: EVENT_INDEX
tests:
- not_null
- float
- name: UNDERLYING_AMOUNT_RAW
tests:
- not_null:
error_if: ">10"
warn_if: "<10"
- name: UNDERLYING_AMOUNT
tests:
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- decimal
- float
- name: PLATFORM
tests:
- not_null:
error_if: ">10"
warn_if: "<10"
- name: MODIFIED_TIMESTAMP
tests:
- not_null:
error_if: ">10"
warn_if: "<10"
- name: _LOG_ID
tests:
- not_null:
error_if: ">10"
warn_if: "<10"

View File

@ -21,17 +21,32 @@ WITH asset_list AS (
),
contracts AS (
SELECT
*
address,
symbol,
NAME,
decimals
FROM
{{ ref('core__dim_contracts') }}
),
juice_contracts AS (
SELECT
*
address,
symbol,
NAME,
decimals
FROM
contracts
{{ ref('core__dim_contracts') }}
WHERE
NAME LIKE 'Juice%Collateral%'
NAME LIKE 'Juice%'
{% if is_incremental() %}
AND modified_timestamp > (
SELECT
max(modified_timestamp)
FROM
{{ this }}
)
AND modified_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
),
collateral_tokens AS (
SELECT
@ -60,7 +75,22 @@ collateral_tokens AS (
),
tx_pull AS (
SELECT
*
block_number,
block_timestamp,
tx_hash,
origin_function_signature,
origin_from_address,
origin_to_address,
event_index,
contract_address,
topics,
DATA,
event_removed,
tx_status,
_log_id,
fact_event_logs_id,
inserted_timestamp,
modified_timestamp
FROM
{{ ref('core__fact_event_logs') }}
WHERE
@ -84,7 +114,29 @@ tx_pull AS (
),
trace_pull AS (
SELECT
*
tx_hash,
block_number,
block_timestamp,
from_address,
to_address,
VALUE,
value_precise_raw,
value_precise,
gas,
gas_used,
input,
output,
TYPE,
identifier,
DATA,
tx_status,
sub_traces,
trace_status,
error_reason,
trace_index,
fact_traces_id,
inserted_timestamp,
modified_timestamp
FROM
{{ ref('core__fact_traces') }}
WHERE
@ -98,15 +150,6 @@ trace_pull AS (
'CREATE_0_5',
'CREATE_0_4'
)
{% if is_incremental() %}
AND modified_timestamp > (
SELECT
max(modified_timestamp)
FROM
{{ this }}
)
AND modified_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
),
debt_token AS (
SELECT
@ -144,9 +187,24 @@ token AS (
),
underlying AS (
SELECT
*,
block_number,
block_timestamp,
tx_hash,
origin_function_signature,
origin_from_address,
origin_to_address,
event_index,
contract_address,
topics,
DATA,
event_removed,
tx_status,
_log_id,
fact_event_logs_id,
inserted_timestamp,
modified_timestamp
FROM
{{ ref('core__fact_event_logs') }}
tx_pull
WHERE
tx_hash IN (
SELECT
@ -154,15 +212,6 @@ underlying AS (
FROM
tx_pull
)
{% if is_incremental() %}
AND modified_timestamp > (
SELECT
max(modified_timestamp)
FROM
{{ this }}
)
AND modified_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
),
underlying_asset AS (
SELECT
@ -200,19 +249,25 @@ logs_pull AS (
FROM
juice_contracts
)
{% if is_incremental() %}
AND modified_timestamp > (
SELECT
max(modified_timestamp)
FROM
{{ this }}
)
AND modified_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
),
get_underlying AS (
SELECT
*
block_number,
block_timestamp,
tx_hash,
origin_function_signature,
origin_from_address,
origin_to_address,
event_index,
contract_address,
topics,
DATA,
event_removed,
tx_status,
_log_id,
fact_event_logs_id,
inserted_timestamp,
modified_timestamp
FROM
{{ ref('core__fact_event_logs') }}
WHERE
@ -223,15 +278,6 @@ get_underlying AS (
logs_pull
)
AND topics [0] = '0xcaa97ab28bae75adcb5a02786c64b44d0d3139aa521bf831cdfbe280ef246e36'
{% if is_incremental() %}
AND modified_timestamp > (
SELECT
max(modified_timestamp)
FROM
{{ this }}
)
AND modified_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
),
collateral_base AS (
SELECT
@ -323,6 +369,24 @@ combine_asset AS (
collateral_list
)
SELECT
*
block_timestamp,
block_number,
tx_hash,
contract_address,
underlying_asset_address,
underlying_name,
underlying_decimals,
underlying_symbol,
pool_address,
token_address,
token_name,
token_decimals,
token_symbol,
debt_address,
debt_name,
debt_decimals,
debt_symbol,
modified_timestamp,
_log_id
FROM
combine_asset

View File

@ -6,11 +6,70 @@
tags = ['reorg','curated']
) }}
WITH contracts AS (
WITH log_pull_1 AS (
SELECT
*
l.tx_hash,
l.block_number,
l.block_timestamp,
l.contract_address,
l.modified_timestamp,
l._log_id
FROM
{{ ref('silver__contracts') }}
{{ ref('core__fact_event_logs') }}
l
WHERE
topics [0] :: STRING = '0x7ac369dbd14fa5ea3f473ed67cc9d598964a77501540ba6751eb0b3decf5870d'
AND origin_from_address = '0x6315f65843e7582508e4f0aac20a7203e7b09f02'
{% if is_incremental() %}
AND l.modified_timestamp > (
SELECT
MAX(modified_timestamp)
FROM
{{ this }}
)
AND l.modified_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
),
traces_pull AS (
SELECT
t.from_address AS token_address,
t.to_address AS underlying_asset
FROM
{{ ref('core__fact_traces') }}
t
WHERE
tx_hash IN (
SELECT
tx_hash
FROM
log_pull_1
)
AND input = '0x18160ddd'
AND TYPE = 'STATICCALL'
),
contracts AS (
SELECT
address AS contract_address,
symbol AS token_symbol,
NAME AS token_name,
decimals AS token_decimals
FROM
{{ ref('core__dim_contracts') }}
WHERE
address IN (
SELECT
token_address
FROM
traces_pull
)
OR address IN (
SELECT
underlying_asset
FROM
traces_pull
)
),
log_pull AS (
SELECT
@ -24,46 +83,10 @@ log_pull AS (
l.modified_timestamp,
l._log_id
FROM
{{ ref('core__fact_event_logs') }} l
{{ ref('core__fact_event_logs') }}
l
LEFT JOIN contracts C
ON C.contract_address = l.contract_address
WHERE
topics [0] :: STRING = '0x7ac369dbd14fa5ea3f473ed67cc9d598964a77501540ba6751eb0b3decf5870d'
AND origin_from_address='0x6315f65843e7582508e4f0aac20a7203e7b09f02'
{% if is_incremental() %}
AND l.modified_timestamp > (
SELECT
max(modified_timestamp)
FROM
{{ this }}
)
AND l.modified_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
),
traces_pull AS (
SELECT
t.from_address AS token_address,
t.to_address AS underlying_asset
FROM
{{ ref('core__fact_traces') }} t
WHERE
tx_hash IN (
SELECT
tx_hash
FROM
log_pull
)
AND input = '0x18160ddd'
AND type = 'STATICCALL'
{% if is_incremental() %}
AND t.modified_timestamp > (
SELECT
max(modified_timestamp)
FROM
{{ this }}
)
AND t.modified_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
),
underlying_details AS (
SELECT
@ -74,16 +97,16 @@ underlying_details AS (
l.token_name,
l.token_symbol,
l.token_decimals,
CASE WHEN t.underlying_asset IS NULL THEN '0x4300000000000000000000000000000000000004'
ELSE t.underlying_asset
CASE
WHEN t.underlying_asset IS NULL THEN '0x4300000000000000000000000000000000000004'
ELSE t.underlying_asset
END AS underlying_asset,
l.modified_timestamp,
l._log_id
FROM
log_pull l
LEFT JOIN traces_pull t
ON l.contract_address = t.token_address
QUALIFY(ROW_NUMBER() OVER(PARTITION BY l.contract_address
ON l.contract_address = t.token_address qualify(ROW_NUMBER() over(PARTITION BY l.contract_address
ORDER BY
block_timestamp ASC)) = 1
)
@ -106,4 +129,4 @@ FROM
LEFT JOIN contracts C
ON C.contract_address = l.underlying_asset
WHERE
l.token_name IS NOT NULL
l.token_name IS NOT NULL