add interest accrued euler model

This commit is contained in:
mattromano 2026-01-26 17:18:14 -08:00
parent b19a991d0d
commit afbbbfc748

View File

@ -0,0 +1,97 @@
{# Get variables #}
{% set vars = return_vars() %}
{# Log configuration details #}
{{ log_model_details() }}
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_number",
cluster_by = ['block_timestamp::DATE'],
tags = ['silver','defi','lending','curated','euler']
) }}
WITH token_meta AS (
SELECT
contract_address,
token_name,
token_symbol,
token_decimals,
underlying_address,
underlying_name,
underlying_symbol,
underlying_decimals,
protocol,
version,
dToken
FROM
{{ ref('silver_lending__euler_tokens') }}
),
base AS (
SELECT
tx_hash,
block_number,
block_timestamp,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS account,
utils.udf_hex_to_int(
segmented_data [0] :: STRING
) :: INTEGER AS interest_amount,
modified_timestamp,
CONCAT(
tx_hash :: STRING,
'-',
event_index :: STRING
) AS _log_id
FROM
{{ ref('core__fact_event_logs') }}
WHERE
topics [0] :: STRING = '0x5e804d42ae3b860f881d11cb44a4bb1f2f0d5b3d081f5539a32d6f97b629d978'
AND contract_address IN (
SELECT
DISTINCT(contract_address)
FROM
token_meta
)
{% if is_incremental() %}
AND modified_timestamp >= (
SELECT
MAX(modified_timestamp) - INTERVAL '{{ vars.CURATED_LOOKBACK_HOURS }}'
FROM
{{ this }}
)
AND modified_timestamp >= SYSDATE() - INTERVAL '{{ vars.CURATED_LOOKBACK_DAYS }}'
{% endif %}
AND tx_succeeded
)
SELECT
tx_hash,
block_number,
block_timestamp,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
d.contract_address,
t.dToken AS protocol_market,
t.underlying_address AS token_address,
interest_amount AS amount_unadj,
account,
t.protocol || '-' || t.version AS platform,
t.protocol,
t.version,
d._log_id,
d.modified_timestamp,
'InterestAccrued' AS event_name
FROM
base d
LEFT JOIN token_meta t
ON d.contract_address = t.contract_address
QUALIFY (ROW_NUMBER() OVER (PARTITION BY d._log_id ORDER BY d.modified_timestamp DESC)) = 1