mirror of
https://github.com/FlipsideCrypto/blast-models.git
synced 2026-02-06 14:11:55 +00:00
add gold
This commit is contained in:
parent
870e29576a
commit
cb55dec2b3
@ -1,460 +0,0 @@
|
||||
-- depends_on: {{ ref('silver__complete_token_prices') }}
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = ['block_number','platform'],
|
||||
cluster_by = ['block_timestamp::DATE','platform'],
|
||||
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION ON EQUALITY(tx_hash, origin_from_address, origin_to_address, origin_function_signature, contract_address, event_name, token_address, token_symbol, borrower, protocol_market), SUBSTRING(origin_function_signature, event_name, token_address, token_symbol, borrower, protocol_market)",
|
||||
tags = ['reorg','curated','heal']
|
||||
) }}
|
||||
|
||||
WITH aave AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
borrower_address AS borrower,
|
||||
aave_token AS protocol_market,
|
||||
aave_market AS token_address,
|
||||
symbol AS token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
platform,
|
||||
'base' AS blockchain,
|
||||
A._LOG_ID,
|
||||
A._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__aave_borrows') }} A
|
||||
|
||||
{% if is_incremental() and 'aave' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
A._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
granary AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
borrower_address AS borrower,
|
||||
granary_token AS protocol_market,
|
||||
granary_market AS token_address,
|
||||
symbol AS token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
platform,
|
||||
'base' AS blockchain,
|
||||
A._LOG_ID,
|
||||
A._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__granary_borrows') }} A
|
||||
|
||||
{% if is_incremental() and 'granary' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
A._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
morpho AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
NULL AS event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
borrower_address AS borrower,
|
||||
contract_address AS protocol_market,
|
||||
market AS token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
platform,
|
||||
'base' AS blockchain,
|
||||
A._ID AS _log_id,
|
||||
A._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__morpho_borrows') }} A
|
||||
|
||||
{% if is_incremental() and 'morpho' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
A._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
comp AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
borrower,
|
||||
compound_market AS protocol_market,
|
||||
token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
compound_version AS platform,
|
||||
'base' AS blockchain,
|
||||
A._LOG_ID,
|
||||
A._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__comp_borrows') }} A
|
||||
|
||||
{% if is_incremental() and 'comp' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
A._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
sonne AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
borrower,
|
||||
token_address AS protocol_market,
|
||||
borrows_contract_address AS token_address,
|
||||
borrows_contract_symbol AS token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
platform,
|
||||
'base' AS blockchain,
|
||||
A._LOG_ID,
|
||||
A._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__sonne_borrows') }} A
|
||||
|
||||
{% if is_incremental() and 'sonne' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
A._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
seamless AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
borrower_address AS borrower,
|
||||
seamless_token AS protocol_market,
|
||||
seamless_market AS token_address,
|
||||
symbol AS token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
platform,
|
||||
'base' AS blockchain,
|
||||
A._LOG_ID,
|
||||
A._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__seamless_borrows') }} A
|
||||
|
||||
{% if is_incremental() and 'seamless' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
A._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
moonwell AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
borrower,
|
||||
token_address AS protocol_market,
|
||||
borrows_contract_address AS token_address,
|
||||
borrows_contract_symbol AS token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
platform,
|
||||
'base' AS blockchain,
|
||||
A._LOG_ID,
|
||||
A._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__moonwell_borrows') }} A
|
||||
|
||||
{% if is_incremental() and 'moonwell' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
A._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
borrow_union AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
aave
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
morpho
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
granary
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
comp
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
sonne
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
seamless
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
moonwell
|
||||
),
|
||||
complete_lending_borrows AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
b.contract_address,
|
||||
CASE
|
||||
WHEN platform = 'Compound V3' THEN 'Withdraw'
|
||||
ELSE 'Borrow'
|
||||
END AS event_name,
|
||||
borrower,
|
||||
protocol_market,
|
||||
b.token_address,
|
||||
b.token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
ROUND(
|
||||
amount * price,
|
||||
2
|
||||
) AS amount_usd,
|
||||
platform,
|
||||
b.blockchain,
|
||||
b._LOG_ID,
|
||||
b._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
borrow_union b
|
||||
LEFT JOIN {{ ref('price__ez_prices_hourly') }}
|
||||
p
|
||||
ON b.token_address = p.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
),
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
heal_model AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
t0.contract_address,
|
||||
event_name,
|
||||
borrower,
|
||||
protocol_market,
|
||||
t0.token_address,
|
||||
t0.token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
ROUND(
|
||||
amount * p.price,
|
||||
2
|
||||
) AS amount_usd_heal,
|
||||
platform,
|
||||
t0.blockchain,
|
||||
t0._LOG_ID,
|
||||
t0._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ this }}
|
||||
t0
|
||||
LEFT JOIN {{ ref('price__ez_prices_hourly') }}
|
||||
p
|
||||
ON t0.token_address = p.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
WHERE
|
||||
CONCAT(
|
||||
t0.block_number,
|
||||
'-',
|
||||
t0.platform
|
||||
) IN (
|
||||
SELECT
|
||||
CONCAT(
|
||||
t1.block_number,
|
||||
'-',
|
||||
t1.platform
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
t1
|
||||
WHERE
|
||||
t1.amount_usd IS NULL
|
||||
AND t1._inserted_timestamp < (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT
|
||||
1
|
||||
FROM
|
||||
{{ ref('silver__complete_token_prices') }}
|
||||
p
|
||||
WHERE
|
||||
p._inserted_timestamp > DATEADD('DAY', -14, SYSDATE())
|
||||
AND p.price IS NOT NULL
|
||||
AND p.token_address = t1.token_address
|
||||
AND p.hour = DATE_TRUNC(
|
||||
'hour',
|
||||
t1.block_timestamp
|
||||
)
|
||||
)
|
||||
GROUP BY
|
||||
1
|
||||
)
|
||||
),
|
||||
{% endif %}
|
||||
|
||||
FINAL AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
complete_lending_borrows
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
UNION ALL
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
event_name,
|
||||
borrower,
|
||||
protocol_market,
|
||||
token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
amount_usd_heal AS amount_usd,
|
||||
platform,
|
||||
blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
heal_model
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
*,
|
||||
{{ dbt_utils.generate_surrogate_key(['_log_id']) }} AS complete_lending_borrows_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
FINAL qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,56 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__complete_lending_borrows
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
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
|
||||
|
||||
@ -1,451 +0,0 @@
|
||||
-- depends_on: {{ ref('silver__complete_token_prices') }}
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = ['block_number','platform'],
|
||||
cluster_by = ['block_timestamp::DATE','platform'],
|
||||
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION ON EQUALITY(tx_hash, origin_from_address, origin_to_address, origin_function_signature, contract_address, event_name, token_address, token_symbol, depositor, protocol_market), SUBSTRING(origin_function_signature, event_name, token_address, token_symbol, depositor, protocol_market)",
|
||||
tags = ['reorg','curated','heal']
|
||||
) }}
|
||||
|
||||
WITH aave AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
depositor_address,
|
||||
aave_token AS protocol_market,
|
||||
aave_market AS token_address,
|
||||
symbol AS token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
platform,
|
||||
'base' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__aave_deposits') }}
|
||||
|
||||
{% if is_incremental() and 'aave' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
granary AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
depositor_address,
|
||||
granary_token AS protocol_market,
|
||||
granary_market AS token_address,
|
||||
symbol AS token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
platform,
|
||||
'base' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__granary_deposits') }}
|
||||
|
||||
{% if is_incremental() and 'granary' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
morpho AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
NULL AS event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
depositor_address,
|
||||
contract_address AS protocol_market,
|
||||
market AS token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
platform,
|
||||
'base' AS blockchain,
|
||||
_ID AS _LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__morpho_deposits') }}
|
||||
|
||||
{% if is_incremental() and 'morpho' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
seamless AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
depositor_address,
|
||||
seamless_token AS protocol_market,
|
||||
seamless_market AS token_address,
|
||||
symbol AS token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
platform,
|
||||
'base' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__seamless_deposits') }}
|
||||
|
||||
{% if is_incremental() and 'seamless' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
comp AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
depositor_address,
|
||||
compound_market AS protocol_market,
|
||||
token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
compound_version AS platform,
|
||||
'base' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__comp_deposits') }}
|
||||
|
||||
{% if is_incremental() and 'comp' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
sonne AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
supplier AS depositor_address,
|
||||
token_address AS protocol_market,
|
||||
supplied_contract_addr AS token_address,
|
||||
supplied_symbol AS token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
platform,
|
||||
'base' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__sonne_deposits') }}
|
||||
|
||||
{% if is_incremental() and 'sonne' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
moonwell AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
supplier AS depositor_address,
|
||||
token_address AS protocol_market,
|
||||
supplied_contract_addr AS token_address,
|
||||
supplied_symbol AS token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
platform,
|
||||
'base' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__moonwell_deposits') }}
|
||||
|
||||
{% if is_incremental() and 'moonwell' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
deposit_union AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
aave
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
granary
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
comp
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
sonne
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
morpho
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
seamless
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
moonwell
|
||||
),
|
||||
complete_lending_deposits AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
A.contract_address,
|
||||
CASE
|
||||
WHEN platform IN (
|
||||
'Moonwell',
|
||||
'Sonne'
|
||||
) THEN 'Mint'
|
||||
WHEN platform = 'Compound V3' THEN 'SupplyCollateral'
|
||||
WHEN platform = 'Aave V3' THEN 'Supply'
|
||||
ELSE 'Deposit'
|
||||
END AS event_name,
|
||||
protocol_market,
|
||||
depositor_address AS depositor,
|
||||
A.token_address,
|
||||
A.token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
ROUND(
|
||||
amount * price,
|
||||
2
|
||||
) AS amount_usd,
|
||||
platform,
|
||||
A.blockchain,
|
||||
A._LOG_ID,
|
||||
A._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
deposit_union A
|
||||
LEFT JOIN {{ ref('price__ez_prices_hourly') }}
|
||||
p
|
||||
ON A.token_address = p.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
),
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
heal_model AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
t0.contract_address,
|
||||
event_name,
|
||||
protocol_market,
|
||||
depositor,
|
||||
t0.token_address,
|
||||
t0.token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
ROUND(
|
||||
amount * p.price,
|
||||
2
|
||||
) AS amount_usd_heal,
|
||||
platform,
|
||||
t0.blockchain,
|
||||
t0._LOG_ID,
|
||||
t0._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ this }}
|
||||
t0
|
||||
LEFT JOIN {{ ref('price__ez_prices_hourly') }}
|
||||
p
|
||||
ON t0.token_address = p.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
WHERE
|
||||
CONCAT(
|
||||
t0.block_number,
|
||||
'-',
|
||||
t0.platform
|
||||
) IN (
|
||||
SELECT
|
||||
CONCAT(
|
||||
t1.block_number,
|
||||
'-',
|
||||
t1.platform
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
t1
|
||||
WHERE
|
||||
t1.amount_usd IS NULL
|
||||
AND t1._inserted_timestamp < (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT
|
||||
1
|
||||
FROM
|
||||
{{ ref('silver__complete_token_prices') }}
|
||||
p
|
||||
WHERE
|
||||
p._inserted_timestamp > DATEADD('DAY', -14, SYSDATE())
|
||||
AND p.price IS NOT NULL
|
||||
AND p.token_address = t1.token_address
|
||||
AND p.hour = DATE_TRUNC(
|
||||
'hour',
|
||||
t1.block_timestamp
|
||||
)
|
||||
)
|
||||
GROUP BY
|
||||
1
|
||||
)
|
||||
),
|
||||
{% endif %}
|
||||
|
||||
FINAL AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
complete_lending_deposits
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
UNION ALL
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
event_name,
|
||||
protocol_market,
|
||||
depositor,
|
||||
token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
amount_usd_heal AS amount_usd,
|
||||
platform,
|
||||
blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
heal_model
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
*,
|
||||
{{ dbt_utils.generate_surrogate_key(['_log_id']) }} AS complete_lending_deposits_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
FINAL qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,56 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__complete_lending_deposits
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
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
|
||||
|
||||
@ -1,402 +0,0 @@
|
||||
-- depends_on: {{ ref('silver__complete_token_prices') }}
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = ['block_number','platform'],
|
||||
cluster_by = ['block_timestamp::DATE','platform'],
|
||||
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION ON EQUALITY(tx_hash, origin_from_address, origin_to_address, origin_function_signature, contract_address, event_name, flashloan_token, flashloan_token_symbol, protocol_market), SUBSTRING(origin_function_signature, event_name, flashloan_token, flashloan_token_symbol, protocol_market)",
|
||||
tags = ['reorg','curated','heal']
|
||||
) }}
|
||||
|
||||
WITH aave AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
aave_market AS token_address,
|
||||
aave_token AS protocol_token,
|
||||
flashloan_amount_unadj,
|
||||
flashloan_amount,
|
||||
premium_amount_unadj,
|
||||
premium_amount,
|
||||
initiator_address,
|
||||
target_address,
|
||||
'Aave V3' AS platform,
|
||||
symbol AS token_symbol,
|
||||
blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__aave_flashloans') }}
|
||||
|
||||
{% if is_incremental() and 'aave' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
granary AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
granary_market AS token_address,
|
||||
granary_token AS protocol_token,
|
||||
flashloan_amount_unadj,
|
||||
flashloan_amount,
|
||||
premium_amount_unadj,
|
||||
premium_amount,
|
||||
initiator_address,
|
||||
target_address,
|
||||
platform,
|
||||
symbol AS token_symbol,
|
||||
blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__granary_flashloans') }}
|
||||
|
||||
{% if is_incremental() and 'granary' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
morpho AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
market AS token_address,
|
||||
contract_address AS protocol_token,
|
||||
flashloan_amount_unadj,
|
||||
flashloan_amount,
|
||||
NULL AS premium_amount_unadj,
|
||||
NULL AS premium_amount,
|
||||
initiator_address,
|
||||
NULL AS target_address,
|
||||
platform,
|
||||
token_symbol,
|
||||
blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__morpho_flashloans') }}
|
||||
|
||||
{% if is_incremental() and 'morpho' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
|
||||
seamless AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
seamless_market AS token_address,
|
||||
seamless_token AS protocol_token,
|
||||
flashloan_amount_unadj,
|
||||
flashloan_amount,
|
||||
premium_amount_unadj,
|
||||
premium_amount,
|
||||
initiator_address,
|
||||
target_address,
|
||||
platform,
|
||||
symbol AS token_symbol,
|
||||
blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__seamless_flashloans') }}
|
||||
|
||||
{% if is_incremental() and 'seamless' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
flashloan_union AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
aave
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
morpho
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
granary
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
seamless
|
||||
),
|
||||
complete_lending_flashloans AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
f.contract_address,
|
||||
'FlashLoan' AS event_name,
|
||||
protocol_token AS protocol_market,
|
||||
initiator_address AS initiator,
|
||||
target_address AS target,
|
||||
f.token_address AS flashloan_token,
|
||||
f.token_symbol AS flashloan_token_symbol,
|
||||
flashloan_amount_unadj,
|
||||
flashloan_amount,
|
||||
ROUND(
|
||||
flashloan_amount * price,
|
||||
2
|
||||
) AS flashloan_amount_usd,
|
||||
premium_amount_unadj,
|
||||
premium_amount,
|
||||
ROUND(
|
||||
premium_amount * price,
|
||||
2
|
||||
) AS premium_amount_usd,
|
||||
platform,
|
||||
f.blockchain,
|
||||
f._LOG_ID,
|
||||
f._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
flashloan_union f
|
||||
LEFT JOIN {{ ref('price__ez_prices_hourly') }}
|
||||
p
|
||||
ON f.token_address = p.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
),
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
heal_model AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
t0.contract_address,
|
||||
event_name,
|
||||
protocol_market,
|
||||
initiator,
|
||||
target,
|
||||
flashloan_token,
|
||||
flashloan_token_symbol,
|
||||
flashloan_amount_unadj,
|
||||
flashloan_amount,
|
||||
ROUND(
|
||||
flashloan_amount * p.price,
|
||||
2
|
||||
) AS flashloan_amount_usd_heal,
|
||||
premium_amount_unadj,
|
||||
premium_amount,
|
||||
ROUND(
|
||||
premium_amount * p.price,
|
||||
2
|
||||
) AS premium_amount_usd_heal,
|
||||
platform,
|
||||
t0.blockchain,
|
||||
t0._LOG_ID,
|
||||
t0._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ this }}
|
||||
t0
|
||||
LEFT JOIN {{ ref('price__ez_prices_hourly') }}
|
||||
p
|
||||
ON t0.flashloan_token = p.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
WHERE
|
||||
CONCAT(
|
||||
t0.block_number,
|
||||
'-',
|
||||
t0.platform
|
||||
) IN (
|
||||
SELECT
|
||||
CONCAT(
|
||||
t1.block_number,
|
||||
'-',
|
||||
t1.platform
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
t1
|
||||
WHERE
|
||||
t1.flashloan_amount_usd IS NULL
|
||||
AND t1._inserted_timestamp < (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT
|
||||
1
|
||||
FROM
|
||||
{{ ref('silver__complete_token_prices') }}
|
||||
p
|
||||
WHERE
|
||||
p._inserted_timestamp > DATEADD('DAY', -14, SYSDATE())
|
||||
AND p.price IS NOT NULL
|
||||
AND p.token_address = t1.flashloan_token
|
||||
AND p.hour = DATE_TRUNC(
|
||||
'hour',
|
||||
t1.block_timestamp
|
||||
)
|
||||
)
|
||||
GROUP BY
|
||||
1
|
||||
)
|
||||
OR CONCAT(
|
||||
t0.block_number,
|
||||
'-',
|
||||
t0.platform
|
||||
) IN (
|
||||
SELECT
|
||||
CONCAT(
|
||||
t2.block_number,
|
||||
'-',
|
||||
t2.platform
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
t2
|
||||
WHERE
|
||||
t2.premium_amount_usd IS NULL
|
||||
AND t2._inserted_timestamp < (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT
|
||||
1
|
||||
FROM
|
||||
{{ ref('silver__complete_token_prices') }}
|
||||
p
|
||||
WHERE
|
||||
p._inserted_timestamp > DATEADD('DAY', -14, SYSDATE())
|
||||
AND p.price IS NOT NULL
|
||||
AND p.token_address = t2.flashloan_token
|
||||
AND p.hour = DATE_TRUNC(
|
||||
'hour',
|
||||
t2.block_timestamp
|
||||
)
|
||||
)
|
||||
GROUP BY
|
||||
1
|
||||
)
|
||||
),
|
||||
{% endif %}
|
||||
|
||||
FINAL AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
complete_lending_flashloans
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
UNION ALL
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
event_name,
|
||||
protocol_market,
|
||||
initiator,
|
||||
target,
|
||||
flashloan_token,
|
||||
flashloan_token_symbol,
|
||||
flashloan_amount_unadj,
|
||||
flashloan_amount,
|
||||
flashloan_amount_usd_heal AS flashloan_amount_usd,
|
||||
premium_amount_unadj,
|
||||
premium_amount,
|
||||
premium_amount_usd_heal AS premium_amount_usd,
|
||||
platform,
|
||||
blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
heal_model
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
*,
|
||||
{{ dbt_utils.generate_surrogate_key(['_log_id']) }} AS complete_lending_flashloans_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
FINAL qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,55 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__complete_lending_flashloans
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- _LOG_ID
|
||||
columns:
|
||||
- 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: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: PROTOCOL_MARKET
|
||||
tests:
|
||||
- not_null
|
||||
- name: INITIATOR
|
||||
tests:
|
||||
- not_null
|
||||
- name: TARGET
|
||||
tests:
|
||||
- not_null:
|
||||
where: PLATFORM <> 'Morpho Blue'
|
||||
- name: FLASHLOAN_AMOUNT_UNADJ
|
||||
tests:
|
||||
- not_null
|
||||
- name: FLASHLOAN_AMOUNT
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: FLASHLOAN_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
|
||||
@ -1,502 +0,0 @@
|
||||
-- depends_on: {{ ref('silver__complete_token_prices') }}
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = ['block_number','platform'],
|
||||
cluster_by = ['block_timestamp::DATE','platform'],
|
||||
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION ON EQUALITY(tx_hash, origin_from_address, origin_to_address, origin_function_signature, contract_address, event_name, liquidator, borrower, collateral_token, collateral_token_symbol, debt_token, debt_token_symbol, protocol_market), SUBSTRING(origin_function_signature, event_name, liquidator, borrower, collateral_token, collateral_token_symbol, debt_token, debt_token_symbol, protocol_market)",
|
||||
tags = ['reorg','curated','heal']
|
||||
) }}
|
||||
|
||||
WITH aave AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
liquidator,
|
||||
borrower,
|
||||
amount_unadj,
|
||||
amount AS liquidated_amount,
|
||||
NULL AS liquidated_amount_usd,
|
||||
collateral_aave_token AS protocol_collateral_asset,
|
||||
collateral_asset,
|
||||
collateral_token_symbol AS collateral_asset_symbol,
|
||||
debt_asset,
|
||||
debt_token_symbol AS debt_asset_symbol,
|
||||
'Aave V3' AS platform,
|
||||
'base' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__aave_liquidations') }}
|
||||
|
||||
{% if is_incremental() and 'aave' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
granary AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
liquidator,
|
||||
borrower,
|
||||
amount_unadj,
|
||||
amount AS liquidated_amount,
|
||||
NULL AS liquidated_amount_usd,
|
||||
collateral_granary_token AS protocol_collateral_asset,
|
||||
collateral_asset,
|
||||
collateral_token_symbol AS collateral_asset_symbol,
|
||||
debt_asset,
|
||||
debt_token_symbol AS debt_asset_symbol,
|
||||
'Granary' AS platform,
|
||||
'base' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__granary_liquidations') }}
|
||||
|
||||
{% if is_incremental() and 'granary' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
morpho AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
liquidator,
|
||||
borrower,
|
||||
amount_unadj,
|
||||
amount AS liquidated_amount,
|
||||
NULL AS liquidated_amount_usd,
|
||||
NULL AS protocol_collateral_asset,
|
||||
collateral_asset,
|
||||
collateral_asset_symbol,
|
||||
debt_asset,
|
||||
debt_asset_symbol,
|
||||
platform,
|
||||
'base' AS blockchain,
|
||||
_id as _LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__morpho_liquidations') }}
|
||||
|
||||
{% if is_incremental() and 'morpho' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
seamless AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
liquidator,
|
||||
borrower,
|
||||
amount_unadj,
|
||||
amount AS liquidated_amount,
|
||||
NULL AS liquidated_amount_usd,
|
||||
collateral_seamless_token AS protocol_collateral_asset,
|
||||
collateral_asset,
|
||||
collateral_token_symbol AS collateral_asset_symbol,
|
||||
debt_asset,
|
||||
debt_token_symbol AS debt_asset_symbol,
|
||||
'Granary' AS platform,
|
||||
'base' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__seamless_liquidations') }}
|
||||
|
||||
{% if is_incremental() and 'seamless' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
comp AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
absorber AS liquidator,
|
||||
borrower,
|
||||
amount_unadj,
|
||||
amount AS liquidated_amount,
|
||||
amount_usd AS liquidated_amount_usd,
|
||||
compound_market AS protocol_collateral_asset,
|
||||
token_address AS collateral_asset,
|
||||
token_symbol AS collateral_asset_symbol,
|
||||
debt_asset,
|
||||
debt_asset_symbol,
|
||||
l.compound_version AS platform,
|
||||
'base' AS blockchain,
|
||||
l._LOG_ID,
|
||||
l._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__comp_liquidations') }}
|
||||
l
|
||||
|
||||
{% if is_incremental() and 'comp' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
l._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
sonne AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
liquidator,
|
||||
borrower,
|
||||
amount_unadj,
|
||||
amount AS liquidated_amount,
|
||||
NULL AS liquidated_amount_usd,
|
||||
token AS protocol_collateral_asset,
|
||||
liquidation_contract_address AS debt_asset,
|
||||
liquidation_contract_symbol AS debt_asset_symbol,
|
||||
collateral_token AS collateral_asset,
|
||||
collateral_symbol AS collateral_asset_symbol,
|
||||
platform,
|
||||
'base' AS blockchain,
|
||||
l._LOG_ID,
|
||||
l._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__sonne_liquidations') }}
|
||||
l
|
||||
|
||||
{% if is_incremental() and 'sonne' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
l._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
moonwell AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
liquidator,
|
||||
borrower,
|
||||
amount_unadj,
|
||||
amount AS liquidated_amount,
|
||||
NULL AS liquidated_amount_usd,
|
||||
token AS protocol_collateral_asset,
|
||||
liquidation_contract_address AS debt_asset,
|
||||
liquidation_contract_symbol AS debt_asset_symbol,
|
||||
collateral_token AS collateral_asset,
|
||||
collateral_symbol AS collateral_asset_symbol,
|
||||
platform,
|
||||
'base' AS blockchain,
|
||||
l._LOG_ID,
|
||||
l._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__moonwell_liquidations') }}
|
||||
l
|
||||
|
||||
{% if is_incremental() and 'moonwell' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
l._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
liquidation_union AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
aave
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
granary
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
morpho
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
comp
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
sonne
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
seamless
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
moonwell
|
||||
),
|
||||
complete_lending_liquidations AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
A.contract_address,
|
||||
CASE
|
||||
WHEN platform IN (
|
||||
'Sonne',
|
||||
'Moonwell'
|
||||
) THEN 'LiquidateBorrow'
|
||||
WHEN platform = 'Compound V3' THEN 'AbsorbCollateral'
|
||||
ELSE 'LiquidationCall'
|
||||
END AS event_name,
|
||||
liquidator,
|
||||
borrower,
|
||||
protocol_collateral_asset AS protocol_market,
|
||||
collateral_asset AS collateral_token,
|
||||
collateral_asset_symbol AS collateral_token_symbol,
|
||||
amount_unadj,
|
||||
liquidated_amount AS amount,
|
||||
CASE
|
||||
WHEN platform <> 'Compound V3' THEN ROUND(
|
||||
liquidated_amount * p.price,
|
||||
2
|
||||
)
|
||||
ELSE ROUND(
|
||||
liquidated_amount_usd,
|
||||
2
|
||||
)
|
||||
END AS amount_usd,
|
||||
debt_asset AS debt_token,
|
||||
debt_asset_symbol AS debt_token_symbol,
|
||||
platform,
|
||||
A.blockchain,
|
||||
A._LOG_ID,
|
||||
A._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
liquidation_union A
|
||||
LEFT JOIN {{ ref('price__ez_prices_hourly') }}
|
||||
p
|
||||
ON collateral_asset = p.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
),
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
heal_model AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
t0.contract_address,
|
||||
event_name,
|
||||
liquidator,
|
||||
borrower,
|
||||
protocol_market,
|
||||
collateral_token,
|
||||
collateral_token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
CASE
|
||||
WHEN platform <> 'Compound V3' THEN ROUND(
|
||||
amount * p.price,
|
||||
2
|
||||
)
|
||||
ELSE ROUND(
|
||||
amount_usd,
|
||||
2
|
||||
)
|
||||
END AS amount_usd_heal,
|
||||
debt_token,
|
||||
debt_token_symbol,
|
||||
platform,
|
||||
t0.blockchain,
|
||||
t0._LOG_ID,
|
||||
t0._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ this }}
|
||||
t0
|
||||
LEFT JOIN {{ ref('price__ez_prices_hourly') }}
|
||||
p
|
||||
ON t0.collateral_token = p.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
WHERE
|
||||
CONCAT(
|
||||
t0.block_number,
|
||||
'-',
|
||||
t0.platform
|
||||
) IN (
|
||||
SELECT
|
||||
CONCAT(
|
||||
t1.block_number,
|
||||
'-',
|
||||
t1.platform
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
t1
|
||||
WHERE
|
||||
t1.amount_usd IS NULL
|
||||
AND t1._inserted_timestamp < (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT
|
||||
1
|
||||
FROM
|
||||
{{ ref('silver__complete_token_prices') }}
|
||||
p
|
||||
WHERE
|
||||
p._inserted_timestamp > DATEADD('DAY', -14, SYSDATE())
|
||||
AND p.price IS NOT NULL
|
||||
AND p.token_address = t1.collateral_token
|
||||
AND p.hour = DATE_TRUNC(
|
||||
'hour',
|
||||
t1.block_timestamp
|
||||
)
|
||||
)
|
||||
GROUP BY
|
||||
1
|
||||
)
|
||||
),
|
||||
{% endif %}
|
||||
|
||||
FINAL AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
complete_lending_liquidations
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
UNION ALL
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
event_name,
|
||||
liquidator,
|
||||
borrower,
|
||||
protocol_market,
|
||||
collateral_token,
|
||||
collateral_token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
amount_usd_heal AS amount_usd,
|
||||
debt_token,
|
||||
debt_token_symbol,
|
||||
platform,
|
||||
blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
heal_model
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
*,
|
||||
{{ dbt_utils.generate_surrogate_key(['_log_id']) }} AS complete_lending_liquidations_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
FINAL qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,60 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__complete_lending_liquidations
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
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
|
||||
|
||||
@ -1,455 +0,0 @@
|
||||
-- depends_on: {{ ref('silver__complete_token_prices') }}
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = ['block_number','platform'],
|
||||
cluster_by = ['block_timestamp::DATE','platform'],
|
||||
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION ON EQUALITY(tx_hash, origin_from_address, origin_to_address, origin_function_signature, contract_address, event_name, token_address, token_symbol, payer, borrower, protocol_market), SUBSTRING(origin_function_signature, event_name, token_address, token_symbol, payer, borrower, protocol_market)",
|
||||
tags = ['reorg','curated','heal']
|
||||
) }}
|
||||
|
||||
WITH aave AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
aave_market AS token_address,
|
||||
aave_token AS protocol_market,
|
||||
amount_unadj,
|
||||
amount,
|
||||
symbol AS token_symbol,
|
||||
payer AS payer_address,
|
||||
borrower,
|
||||
'Aave V3' AS platform,
|
||||
'base' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__aave_repayments') }}
|
||||
|
||||
{% if is_incremental() and 'aave' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
granary AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
granary_market AS token_address,
|
||||
granary_token AS protocol_market,
|
||||
amount_unadj,
|
||||
amount,
|
||||
symbol AS token_symbol,
|
||||
payer AS payer_address,
|
||||
borrower,
|
||||
platform,
|
||||
'base' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__granary_repayments') }}
|
||||
|
||||
{% if is_incremental() and 'granary' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
morpho AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
NULL AS event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
market AS token_address,
|
||||
contract_address AS protocol_market,
|
||||
amount_unadj,
|
||||
amount,
|
||||
token_symbol,
|
||||
payer AS payer_address,
|
||||
borrower_address AS borrower,
|
||||
platform,
|
||||
'base' AS blockchain,
|
||||
_ID AS _LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__morpho_repayments') }}
|
||||
|
||||
{% if is_incremental() and 'morpho' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
seamless AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
seamless_market AS token_address,
|
||||
seamless_token AS protocol_market,
|
||||
amount_unadj,
|
||||
amount,
|
||||
symbol AS token_symbol,
|
||||
payer AS payer_address,
|
||||
borrower,
|
||||
platform,
|
||||
'base' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__seamless_repayments') }}
|
||||
|
||||
{% if is_incremental() and 'seameless' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
comp AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
token_address,
|
||||
compound_market AS protocol_market,
|
||||
amount_unadj,
|
||||
amount,
|
||||
token_symbol,
|
||||
repayer AS payer_address,
|
||||
borrower,
|
||||
compound_version AS platform,
|
||||
'base' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__comp_repayments') }}
|
||||
|
||||
{% if is_incremental() and 'comp' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
sonne AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
repay_contract_address AS token_address,
|
||||
token_address AS protocol_market,
|
||||
amount_unadj,
|
||||
amount,
|
||||
repay_contract_symbol AS token_symbol,
|
||||
payer AS payer_address,
|
||||
borrower,
|
||||
platform,
|
||||
'base' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__sonne_repayments') }}
|
||||
|
||||
{% if is_incremental() and 'sonne' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
moonwell AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
repay_contract_address AS token_address,
|
||||
token_address AS protocol_market,
|
||||
amount_unadj,
|
||||
amount,
|
||||
repay_contract_symbol AS token_symbol,
|
||||
payer AS payer_address,
|
||||
borrower,
|
||||
platform,
|
||||
'base' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__moonwell_repayments') }}
|
||||
|
||||
{% if is_incremental() and 'moonwell' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
repayments_union AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
aave
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
granary
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
comp
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
sonne
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
seamless
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
moonwell
|
||||
),
|
||||
complete_lending_repayments AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
A.contract_address,
|
||||
CASE
|
||||
WHEN platform IN (
|
||||
'Sonne',
|
||||
'Moonwell'
|
||||
) THEN 'RepayBorrow'
|
||||
WHEN platform = 'Compound V3' THEN 'Supply'
|
||||
ELSE 'Repay'
|
||||
END AS event_name,
|
||||
protocol_market,
|
||||
payer_address AS payer,
|
||||
borrower,
|
||||
A.token_address,
|
||||
A.token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
ROUND(
|
||||
amount * price,
|
||||
2
|
||||
) AS amount_usd,
|
||||
platform,
|
||||
A.blockchain,
|
||||
A._LOG_ID,
|
||||
A._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
repayments_union A
|
||||
LEFT JOIN {{ ref('price__ez_prices_hourly') }}
|
||||
p
|
||||
ON A.token_address = p.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
),
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
heal_model AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
t0.contract_address,
|
||||
event_name,
|
||||
protocol_market,
|
||||
payer,
|
||||
borrower,
|
||||
t0.token_address,
|
||||
t0.token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
ROUND(
|
||||
amount * p.price,
|
||||
2
|
||||
) AS amount_usd_heal,
|
||||
platform,
|
||||
t0.blockchain,
|
||||
t0._LOG_ID,
|
||||
t0._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ this }}
|
||||
t0
|
||||
LEFT JOIN {{ ref('price__ez_prices_hourly') }}
|
||||
p
|
||||
ON t0.token_address = p.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
WHERE
|
||||
CONCAT(
|
||||
t0.block_number,
|
||||
'-',
|
||||
t0.platform
|
||||
) IN (
|
||||
SELECT
|
||||
CONCAT(
|
||||
t1.block_number,
|
||||
'-',
|
||||
t1.platform
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
t1
|
||||
WHERE
|
||||
t1.amount_usd IS NULL
|
||||
AND t1._inserted_timestamp < (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT
|
||||
1
|
||||
FROM
|
||||
{{ ref('silver__complete_token_prices') }}
|
||||
p
|
||||
WHERE
|
||||
p._inserted_timestamp > DATEADD('DAY', -14, SYSDATE())
|
||||
AND p.price IS NOT NULL
|
||||
AND p.token_address = t1.token_address
|
||||
AND p.hour = DATE_TRUNC(
|
||||
'hour',
|
||||
t1.block_timestamp
|
||||
)
|
||||
)
|
||||
GROUP BY
|
||||
1
|
||||
)
|
||||
),
|
||||
{% endif %}
|
||||
|
||||
FINAL AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
complete_lending_repayments
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
UNION ALL
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
event_name,
|
||||
protocol_market,
|
||||
payer,
|
||||
borrower,
|
||||
token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
amount_usd_heal AS amount_usd,
|
||||
platform,
|
||||
blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
heal_model
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
*,
|
||||
{{ dbt_utils.generate_surrogate_key(['_log_id']) }} AS complete_lending_repayments_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
FINAL qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,59 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__complete_lending_repayments
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
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: PAYER
|
||||
tests:
|
||||
- not_null:
|
||||
where: PLATFORM <> 'Silo'
|
||||
- name: BORROWER
|
||||
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
|
||||
@ -1,464 +0,0 @@
|
||||
-- depends_on: {{ ref('silver__complete_token_prices') }}
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = ['block_number','platform'],
|
||||
cluster_by = ['block_timestamp::DATE','platform'],
|
||||
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION ON EQUALITY(tx_hash, origin_from_address, origin_to_address, origin_function_signature, contract_address, event_name, token_address, token_symbol, depositor, protocol_market), SUBSTRING(origin_function_signature, event_name, token_address, token_symbol, depositor, protocol_market)",
|
||||
tags = ['reorg','curated','heal']
|
||||
) }}
|
||||
|
||||
WITH aave AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
aave_token AS protocol_market,
|
||||
aave_market AS token_address,
|
||||
symbol AS token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
depositor_address,
|
||||
'Aave V3' AS platform,
|
||||
'base' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__aave_withdraws') }}
|
||||
|
||||
{% if is_incremental() and 'aave' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
granary AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
granary_token AS protocol_market,
|
||||
granary_market AS token_address,
|
||||
symbol AS token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
depositor_address,
|
||||
platform,
|
||||
'base' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__granary_withdraws') }}
|
||||
|
||||
{% if is_incremental() and 'granary' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
morpho AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
NULL AS event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
contract_address AS protocol_market,
|
||||
market AS token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
depositor_address,
|
||||
platform,
|
||||
'base' AS blockchain,
|
||||
_id AS _LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__morpho_withdraws') }}
|
||||
|
||||
{% if is_incremental() and 'morpho' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
seamless AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
seamless_token AS protocol_market,
|
||||
seamless_market AS token_address,
|
||||
symbol AS token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
depositor_address,
|
||||
platform,
|
||||
'base' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__seamless_withdraws') }}
|
||||
|
||||
{% if is_incremental() and 'seamless' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
comp AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
compound_market AS protocol_market,
|
||||
token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
depositor_address,
|
||||
compound_version AS platform,
|
||||
'base' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__comp_withdraws') }}
|
||||
|
||||
{% if is_incremental() and 'comp' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
sonne AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
token_address AS protocol_market,
|
||||
received_contract_address AS token_address,
|
||||
received_contract_symbol AS token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
redeemer AS depositor_address,
|
||||
platform,
|
||||
'base' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__sonne_withdraws') }}
|
||||
|
||||
{% if is_incremental() and 'sonne' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
moonwell AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
token_address AS protocol_market,
|
||||
received_contract_address AS token_address,
|
||||
received_contract_symbol AS token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
redeemer AS depositor_address,
|
||||
platform,
|
||||
'base' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__moonwell_withdraws') }}
|
||||
|
||||
{% if is_incremental() and 'moonwell' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
withdraws_union AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
aave
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
morpho
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
granary
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
comp
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
sonne
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
seamless
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
moonwell
|
||||
),
|
||||
complete_lending_withdraws AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
A.contract_address,
|
||||
CASE
|
||||
WHEN platform IN (
|
||||
'Moonwell',
|
||||
'Sonne'
|
||||
) THEN 'Redeem'
|
||||
WHEN platform = 'Compound V3' THEN 'WithdrawCollateral'
|
||||
ELSE 'Withdraw'
|
||||
END AS event_name,
|
||||
protocol_market,
|
||||
depositor_address AS depositor,
|
||||
A.token_address,
|
||||
A.token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
ROUND(
|
||||
amount * price,
|
||||
2
|
||||
) AS amount_usd,
|
||||
platform,
|
||||
A.blockchain,
|
||||
A._log_id,
|
||||
A._inserted_timestamp
|
||||
FROM
|
||||
withdraws_union A
|
||||
LEFT JOIN {{ ref('price__ez_prices_hourly') }}
|
||||
p
|
||||
ON A.token_address = p.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
),
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
heal_model AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
t0.contract_address,
|
||||
event_name,
|
||||
protocol_market,
|
||||
depositor,
|
||||
t0.token_address,
|
||||
t0.token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
ROUND(
|
||||
amount * p.price,
|
||||
2
|
||||
) AS amount_usd_heal,
|
||||
platform,
|
||||
t0.blockchain,
|
||||
t0._log_id,
|
||||
t0._inserted_timestamp
|
||||
FROM
|
||||
{{ this }}
|
||||
t0
|
||||
LEFT JOIN {{ ref('price__ez_prices_hourly') }}
|
||||
p
|
||||
ON t0.token_address = p.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
WHERE
|
||||
CONCAT(
|
||||
t0.block_number,
|
||||
'-',
|
||||
t0.platform
|
||||
) IN (
|
||||
SELECT
|
||||
CONCAT(
|
||||
t1.block_number,
|
||||
'-',
|
||||
t1.platform
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
t1
|
||||
WHERE
|
||||
t1.amount_usd IS NULL
|
||||
AND t1._inserted_timestamp < (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT
|
||||
1
|
||||
FROM
|
||||
{{ ref('silver__complete_token_prices') }}
|
||||
p
|
||||
WHERE
|
||||
p._inserted_timestamp > DATEADD('DAY', -14, SYSDATE())
|
||||
AND p.price IS NOT NULL
|
||||
AND p.token_address = t1.token_address
|
||||
AND p.hour = DATE_TRUNC(
|
||||
'hour',
|
||||
t1.block_timestamp
|
||||
)
|
||||
)
|
||||
GROUP BY
|
||||
1
|
||||
)
|
||||
),
|
||||
{% endif %}
|
||||
|
||||
FINAL AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
complete_lending_withdraws
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
UNION ALL
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
event_name,
|
||||
protocol_market,
|
||||
depositor,
|
||||
token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
amount_usd_heal AS amount_usd,
|
||||
platform,
|
||||
blockchain,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
heal_model
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
*,
|
||||
{{ dbt_utils.generate_surrogate_key(['_log_id']) }} AS complete_lending_withdraws_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
FINAL qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,57 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__complete_lending_withdraws
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
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
|
||||
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
{% docs complete_lending_borrows_table_doc %}
|
||||
|
||||
This table contains transactions where users borrowed assets across AAVE, COMPOUND, SILO, DFORCE, RADIANT, and LODESTAR protocols. In order to borrow assets, a user must first deposit their preferred asset and amount as collateral.
|
||||
This table contains transactions where users borrowed assets across ORBIT, JUICE AND INIT protocols. In order to borrow assets, a user must first deposit their preferred asset and amount as collateral.
|
||||
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_deposits_table_doc %}
|
||||
|
||||
This table contains deposit transactions across AAVE, COMPOUND, SILO, DFORCE, RADIANT, and LODESTAR protocols. A user deposits their preferred asset and amount. After depositing, users earn passive income based on the market borrowing demand. Additionally, depositing allows users to borrow by using their deposited assets as a collateral. Any interest earned by depositing funds helps offset the interest rate accumulated by borrowing.
|
||||
This table contains deposit transactions across ORBIT, JUICE AND INIT protocols. A user deposits their preferred asset and amount. After depositing, users earn passive income based on the market borrowing demand. Additionally, depositing allows users to borrow by using their deposited assets as a collateral. Any interest earned by depositing funds helps offset the interest rate accumulated by borrowing.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
@ -19,18 +19,18 @@ This table contains flash loan transactions across AAVE and RADIANT protocols. F
|
||||
|
||||
{% docs complete_lending_liquidations_table_doc %}
|
||||
|
||||
This table contains transactions in which a borrower's collateral asset is liquidated across AAVE, COMPOUND, SILO, DFORCE, RADIANT, and LODESTAR protocols. Liquidations occur when a borrower's health factor goes below 1 due to their collateral value not properly covering their loan/debt value. This might happen when the collateral decreases in value or the borrowed debt increases in value against each other. This collateral vs loan value ratio is shown in the health factor. In a liquidation, up to 50% of a borrower's debt is repaid and that value + liquidation fee is taken from the collateral available, so after a liquidation the amount liquidated from one's debt is repaid.
|
||||
This table contains transactions in which a borrower's collateral asset is liquidated across ORBIT, JUICE AND INIT protocols. Liquidations occur when a borrower's health factor goes below 1 due to their collateral value not properly covering their loan/debt value. This might happen when the collateral decreases in value or the borrowed debt increases in value against each other. This collateral vs loan value ratio is shown in the health factor. In a liquidation, up to 50% of a borrower's debt is repaid and that value + liquidation fee is taken from the collateral available, so after a liquidation the amount liquidated from one's debt is repaid.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_repayments_table_doc %}
|
||||
|
||||
This table contains transactions in which a borrower repays their loan (debt) across the AAVE, COMPOUND, SILO, DFORCE, RADIANT, and LODESTAR protocols. Loans are repaid in the same asset borrowed, plus accrued interest. Borrowers can pay back their loan based on the USD price as they can borrow any of the available stable coins (USDC, DAI, USDT, etc.).
|
||||
This table contains transactions in which a borrower repays their loan (debt) across the ORBIT, JUICE AND INIT protocols. Loans are repaid in the same asset borrowed, plus accrued interest. Borrowers can pay back their loan based on the USD price as they can borrow any of the available stable coins (USDC, DAI, USDT, etc.).
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_withdraws_table_doc %}
|
||||
|
||||
This table contains transactions in which a user withdraws liquidity across the AAVE, COMPOUND, SILO, DFORCE, RADIANT, and LODESTAR protocols. Users need to make sure there is enough liquidity (not borrowed) in order to withdraw, if this is not the case, users need to wait for more liquidity from depositors or borrowers repaying.
|
||||
This table contains transactions in which a user withdraws liquidity across the ORBIT, JUICE AND INIT protocols. Users need to make sure there is enough liquidity (not borrowed) in order to withdraw, if this is not the case, users need to wait for more liquidity from depositors or borrowers repaying.
|
||||
|
||||
{% enddocs %}
|
||||
48
models/gold/defi/lending/defi__ez_lending_borrows.sql
Normal file
48
models/gold/defi/lending/defi__ez_lending_borrows.sql
Normal file
@ -0,0 +1,48 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
persist_docs ={ "relation": true,
|
||||
"columns": true },
|
||||
meta={
|
||||
'database_tags':{
|
||||
'table': {
|
||||
'PROTOCOL': 'INIT, ORBIT, JUICE',
|
||||
'PURPOSE': 'LENDING, BORROWS'
|
||||
}
|
||||
}
|
||||
}
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
contract_address,
|
||||
event_name,
|
||||
event_index,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
platform,
|
||||
protocol_market,
|
||||
borrower,
|
||||
token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
amount_usd,
|
||||
COALESCE (
|
||||
complete_lending_borrows_id,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash', 'event_index']
|
||||
) }}
|
||||
) AS ez_lending_borrows_id,
|
||||
COALESCE(
|
||||
inserted_timestamp,
|
||||
'2000-01-01'
|
||||
) AS inserted_timestamp,
|
||||
COALESCE(
|
||||
modified_timestamp,
|
||||
'2000-01-01'
|
||||
) AS modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver__complete_lending_borrows') }}
|
||||
46
models/gold/defi/lending/defi__ez_lending_borrows.yml
Normal file
46
models/gold/defi/lending/defi__ez_lending_borrows.yml
Normal file
@ -0,0 +1,46 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: defi__ez_lending_borrows
|
||||
description: '{{ doc("complete_lending_borrows_table_doc") }}'
|
||||
|
||||
columns:
|
||||
- name: BLOCK_NUMBER
|
||||
description: '{{ doc("blast_block_number") }}'
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: '{{ doc("blast_block_timestamp") }}'
|
||||
- name: TX_HASH
|
||||
description: '{{ doc("blast_logs_tx_hash") }}'
|
||||
- name: CONTRACT_ADDRESS
|
||||
description: '{{ doc("blast_logs_contract_address") }}'
|
||||
- name: EVENT_NAME
|
||||
description: '{{ doc("blast_event_name") }}'
|
||||
- name: EVENT_INDEX
|
||||
description: '{{ doc("blast_event_index") }}'
|
||||
- name: ORIGIN_FUNCTION_SIGNATURE
|
||||
description: '{{ doc("nft_origin_sig") }}'
|
||||
- name: ORIGIN_FROM_ADDRESS
|
||||
description: '{{ doc("blast_origin_from") }}'
|
||||
- name: ORIGIN_TO_ADDRESS
|
||||
description: '{{ doc("blast_origin_to") }}'
|
||||
- name: PLATFORM
|
||||
description: '{{ doc("complete_lending_platform") }}'
|
||||
- name: PROTOCOL_MARKET
|
||||
description: '{{ doc("complete_lending_protocol_token") }}'
|
||||
- name: BORROWER
|
||||
description: '{{ doc("complete_lending_borrower") }}'
|
||||
- name: TOKEN_ADDRESS
|
||||
description: '{{ doc("complete_lending_token_address") }}'
|
||||
- name: TOKEN_SYMBOL
|
||||
description: '{{ doc("blast_symbol") }}'
|
||||
- name: AMOUNT_UNADJ
|
||||
description: '{{ doc("complete_lending_amount_unadj") }}'
|
||||
- name: AMOUNT
|
||||
description: '{{ doc("complete_lending_amount") }}'
|
||||
- name: AMOUNT_USD
|
||||
description: '{{ doc("complete_lending_amount_usd") }}'
|
||||
- name: EZ_LENDING_BORROWS_ID
|
||||
description: '{{ doc("pk") }}'
|
||||
- name: INSERTED_TIMESTAMP
|
||||
description: '{{ doc("inserted_timestamp") }}'
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
description: '{{ doc("modified_timestamp") }}'
|
||||
48
models/gold/defi/lending/defi__ez_lending_deposits.sql
Normal file
48
models/gold/defi/lending/defi__ez_lending_deposits.sql
Normal file
@ -0,0 +1,48 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
persist_docs ={ "relation": true,
|
||||
"columns": true },
|
||||
meta={
|
||||
'database_tags':{
|
||||
'table': {
|
||||
'PROTOCOL': 'INIT, ORBIT, JUICE',
|
||||
'PURPOSE': 'LENDING, DEPOSITS'
|
||||
}
|
||||
}
|
||||
}
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
contract_address,
|
||||
event_name,
|
||||
event_index,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
platform,
|
||||
protocol_market,
|
||||
depositor,
|
||||
token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
amount_usd,
|
||||
COALESCE (
|
||||
complete_lending_deposits_id,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash', 'event_index']
|
||||
) }}
|
||||
) AS ez_lending_deposits_id,
|
||||
COALESCE(
|
||||
inserted_timestamp,
|
||||
'2000-01-01'
|
||||
) AS inserted_timestamp,
|
||||
COALESCE(
|
||||
modified_timestamp,
|
||||
'2000-01-01'
|
||||
) AS modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver__complete_lending_deposits') }}
|
||||
46
models/gold/defi/lending/defi__ez_lending_deposits.yml
Normal file
46
models/gold/defi/lending/defi__ez_lending_deposits.yml
Normal file
@ -0,0 +1,46 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: defi__ez_lending_deposits
|
||||
description: '{{ doc("complete_lending_deposits_table_doc") }}'
|
||||
|
||||
columns:
|
||||
- name: BLOCK_NUMBER
|
||||
description: '{{ doc("blast_block_number") }}'
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: '{{ doc("blast_block_timestamp") }}'
|
||||
- name: TX_HASH
|
||||
description: '{{ doc("blast_logs_tx_hash") }}'
|
||||
- name: CONTRACT_ADDRESS
|
||||
description: '{{ doc("blast_logs_contract_address") }}'
|
||||
- name: EVENT_NAME
|
||||
description: '{{ doc("blast_event_name") }}'
|
||||
- name: EVENT_INDEX
|
||||
description: '{{ doc("blast_event_index") }}'
|
||||
- name: ORIGIN_FUNCTION_SIGNATURE
|
||||
description: '{{ doc("nft_origin_sig") }}'
|
||||
- name: ORIGIN_FROM_ADDRESS
|
||||
description: '{{ doc("blast_origin_from") }}'
|
||||
- name: ORIGIN_TO_ADDRESS
|
||||
description: '{{ doc("blast_origin_to") }}'
|
||||
- name: PLATFORM
|
||||
description: '{{ doc("complete_lending_platform") }}'
|
||||
- name: PROTOCOL_MARKET
|
||||
description: '{{ doc("complete_lending_protocol_token") }}'
|
||||
- name: DEPOSITOR
|
||||
description: '{{ doc("complete_lending_depositor") }}'
|
||||
- name: TOKEN_ADDRESS
|
||||
description: '{{ doc("complete_lending_token_address") }}'
|
||||
- name: TOKEN_SYMBOL
|
||||
description: '{{ doc("blast_symbol") }}'
|
||||
- name: AMOUNT_UNADJ
|
||||
description: '{{ doc("complete_lending_amount_unadj") }}'
|
||||
- name: AMOUNT
|
||||
description: '{{ doc("complete_lending_amount") }}'
|
||||
- name: AMOUNT_USD
|
||||
description: '{{ doc("complete_lending_amount_usd") }}'
|
||||
- name: EZ_LENDING_DEPOSITS_ID
|
||||
description: '{{ doc("pk") }}'
|
||||
- name: INSERTED_TIMESTAMP
|
||||
description: '{{ doc("inserted_timestamp") }}'
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
description: '{{ doc("modified_timestamp") }}'
|
||||
52
models/gold/defi/lending/defi__ez_lending_liquidations.sql
Normal file
52
models/gold/defi/lending/defi__ez_lending_liquidations.sql
Normal file
@ -0,0 +1,52 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
enabled = false,
|
||||
persist_docs ={ "relation": true,
|
||||
"columns": true },
|
||||
meta={
|
||||
'database_tags':{
|
||||
'table': {
|
||||
'PROTOCOL': 'INIT, ORBIT, JUICE',
|
||||
'PURPOSE': 'LENDING, LIQUIDATIONS'
|
||||
}
|
||||
}
|
||||
}
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
contract_address,
|
||||
event_name,
|
||||
event_index,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
platform,
|
||||
liquidator,
|
||||
borrower,
|
||||
protocol_market,
|
||||
collateral_token,
|
||||
collateral_token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
amount_usd,
|
||||
debt_token,
|
||||
debt_token_symbol,
|
||||
COALESCE (
|
||||
complete_lending_liquidations_id,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash', 'event_index']
|
||||
) }}
|
||||
) AS ez_lending_liquidations_id,
|
||||
COALESCE(
|
||||
inserted_timestamp,
|
||||
'2000-01-01'
|
||||
) AS inserted_timestamp,
|
||||
COALESCE(
|
||||
modified_timestamp,
|
||||
'2000-01-01'
|
||||
) AS modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver__complete_lending_liquidations') }}
|
||||
52
models/gold/defi/lending/defi__ez_lending_liquidations.yml
Normal file
52
models/gold/defi/lending/defi__ez_lending_liquidations.yml
Normal file
@ -0,0 +1,52 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: defi__ez_lending_liquidations
|
||||
description: '{{ doc("complete_lending_liquidations_table_doc") }}'
|
||||
|
||||
columns:
|
||||
- name: BLOCK_NUMBER
|
||||
description: '{{ doc("blast_block_number") }}'
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: '{{ doc("blast_block_timestamp") }}'
|
||||
- name: TX_HASH
|
||||
description: '{{ doc("blast_logs_tx_hash") }}'
|
||||
- name: CONTRACT_ADDRESS
|
||||
description: '{{ doc("blast_logs_contract_address") }}'
|
||||
- name: EVENT_NAME
|
||||
description: '{{ doc("blast_event_name") }}'
|
||||
- name: EVENT_INDEX
|
||||
description: '{{ doc("blast_event_index") }}'
|
||||
- name: ORIGIN_FUNCTION_SIGNATURE
|
||||
description: '{{ doc("nft_origin_sig") }}'
|
||||
- name: ORIGIN_FROM_ADDRESS
|
||||
description: '{{ doc("blast_origin_from") }}'
|
||||
- name: ORIGIN_TO_ADDRESS
|
||||
description: '{{ doc("blast_origin_to") }}'
|
||||
- name: PLATFORM
|
||||
description: '{{ doc("complete_lending_platform") }}'
|
||||
- name: LIQUIDATOR
|
||||
description: '{{ doc("complete_lending_liquidator") }}'
|
||||
- name: BORROWER
|
||||
description: '{{ doc("complete_lending_borrower") }}'
|
||||
- name: PROTOCOL_MARKET
|
||||
description: '{{ doc("complete_lending_protocol_token") }}'
|
||||
- name: COLLATERAL_TOKEN
|
||||
description: '{{ doc("complete_lending_collateral_asset") }}'
|
||||
- name: COLLATERAL_TOKEN_SYMBOL
|
||||
description: '{{ doc("blast_symbol") }}'
|
||||
- name: AMOUNT_UNADJ
|
||||
description: '{{ doc("complete_lending_amount_unadj") }}'
|
||||
- name: AMOUNT
|
||||
description: '{{ doc("complete_lending_amount") }}'
|
||||
- name: AMOUNT_USD
|
||||
description: '{{ doc("complete_lending_amount_usd") }}'
|
||||
- name: DEBT_TOKEN
|
||||
description: '{{ doc("complete_lending_debt_asset") }}'
|
||||
- name: DEBT_TOKEN_SYMBOL
|
||||
description: '{{ doc("blast_symbol") }}'
|
||||
- name: EZ_LENDING_LIQUDATIONS_ID
|
||||
description: '{{ doc("pk") }}'
|
||||
- name: INSERTED_TIMESTAMP
|
||||
description: '{{ doc("inserted_timestamp") }}'
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
description: '{{ doc("modified_timestamp") }}'
|
||||
49
models/gold/defi/lending/defi__ez_lending_repayments.sql
Normal file
49
models/gold/defi/lending/defi__ez_lending_repayments.sql
Normal file
@ -0,0 +1,49 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
persist_docs ={ "relation": true,
|
||||
"columns": true },
|
||||
meta={
|
||||
'database_tags':{
|
||||
'table': {
|
||||
'PROTOCOL': 'INIT, ORBIT, JUICE',
|
||||
'PURPOSE': 'LENDING, REPAYMENTS'
|
||||
}
|
||||
}
|
||||
}
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
tx_hash,
|
||||
event_index,
|
||||
contract_address,
|
||||
event_name,
|
||||
platform,
|
||||
payer,
|
||||
borrower,
|
||||
protocol_market,
|
||||
token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
amount_usd,
|
||||
COALESCE (
|
||||
complete_lending_repayments_id,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash', 'event_index']
|
||||
) }}
|
||||
) AS ez_lending_repayments_id,
|
||||
COALESCE(
|
||||
inserted_timestamp,
|
||||
'2000-01-01'
|
||||
) AS inserted_timestamp,
|
||||
COALESCE(
|
||||
modified_timestamp,
|
||||
'2000-01-01'
|
||||
) AS modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver__complete_lending_repayments') }}
|
||||
48
models/gold/defi/lending/defi__ez_lending_repayments.yml
Normal file
48
models/gold/defi/lending/defi__ez_lending_repayments.yml
Normal file
@ -0,0 +1,48 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: defi__ez_lending_repayments
|
||||
description: '{{ doc("complete_lending_repayments_table_doc") }}'
|
||||
|
||||
columns:
|
||||
- name: BLOCK_NUMBER
|
||||
description: '{{ doc("blast_block_number") }}'
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: '{{ doc("blast_block_timestamp") }}'
|
||||
- name: TX_HASH
|
||||
description: '{{ doc("blast_logs_tx_hash") }}'
|
||||
- name: CONTRACT_ADDRESS
|
||||
description: '{{ doc("blast_logs_contract_address") }}'
|
||||
- name: EVENT_NAME
|
||||
description: '{{ doc("blast_event_name") }}'
|
||||
- name: EVENT_INDEX
|
||||
description: '{{ doc("blast_event_index") }}'
|
||||
- name: ORIGIN_FUNCTION_SIGNATURE
|
||||
description: '{{ doc("nft_origin_sig") }}'
|
||||
- name: ORIGIN_FROM_ADDRESS
|
||||
description: '{{ doc("blast_origin_from") }}'
|
||||
- name: ORIGIN_TO_ADDRESS
|
||||
description: '{{ doc("blast_origin_to") }}'
|
||||
- name: PLATFORM
|
||||
description: '{{ doc("complete_lending_platform") }}'
|
||||
- name: PAYER
|
||||
description: '{{ doc("complete_lending_payer") }}'
|
||||
- name: BORROWER
|
||||
description: '{{ doc("complete_lending_borrower") }}'
|
||||
- name: PROTOCOL_MARKET
|
||||
description: '{{ doc("complete_lending_protocol_token") }}'
|
||||
- name: TOKEN_ADDRESS
|
||||
description: '{{ doc("complete_lending_token_address") }}'
|
||||
- name: TOKEN_SYMBOL
|
||||
description: '{{ doc("complete_lending_token_symbol") }}'
|
||||
- name: AMOUNT_UNADJ
|
||||
description: '{{ doc("complete_lending_amount_unadj") }}'
|
||||
- name: AMOUNT
|
||||
description: '{{ doc("complete_lending_amount") }}'
|
||||
- name: AMOUNT_USD
|
||||
description: '{{ doc("complete_lending_amount_usd") }}'
|
||||
- name: EZ_LENDING_REPAYMENTS_ID
|
||||
description: '{{ doc("pk") }}'
|
||||
- name: INSERTED_TIMESTAMP
|
||||
description: '{{ doc("inserted_timestamp") }}'
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
description: '{{ doc("modified_timestamp") }}'
|
||||
48
models/gold/defi/lending/defi__ez_lending_withdraws.sql
Normal file
48
models/gold/defi/lending/defi__ez_lending_withdraws.sql
Normal file
@ -0,0 +1,48 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
persist_docs ={ "relation": true,
|
||||
"columns": true },
|
||||
meta={
|
||||
'database_tags':{
|
||||
'table': {
|
||||
'PROTOCOL': 'INIT, ORBIT, JUICE',
|
||||
'PURPOSE': 'LENDING, WITHDRAWS'
|
||||
}
|
||||
}
|
||||
}
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
contract_address,
|
||||
event_name,
|
||||
event_index,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
platform,
|
||||
depositor,
|
||||
protocol_market,
|
||||
token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
amount_usd,
|
||||
COALESCE (
|
||||
complete_lending_withdraws_id,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash', 'event_index']
|
||||
) }}
|
||||
) AS ez_lending_withdraws_id,
|
||||
COALESCE(
|
||||
inserted_timestamp,
|
||||
'2000-01-01'
|
||||
) AS inserted_timestamp,
|
||||
COALESCE(
|
||||
modified_timestamp,
|
||||
'2000-01-01'
|
||||
) AS modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver__complete_lending_withdraws') }}
|
||||
46
models/gold/defi/lending/defi__ez_lending_withdraws.yml
Normal file
46
models/gold/defi/lending/defi__ez_lending_withdraws.yml
Normal file
@ -0,0 +1,46 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: defi__ez_lending_withdraws
|
||||
description: '{{ doc("complete_lending_withdraws_table_doc") }}'
|
||||
|
||||
columns:
|
||||
- name: BLOCK_NUMBER
|
||||
description: '{{ doc("blast_block_number") }}'
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: '{{ doc("blast_block_timestamp") }}'
|
||||
- name: TX_HASH
|
||||
description: '{{ doc("blast_logs_tx_hash") }}'
|
||||
- name: CONTRACT_ADDRESS
|
||||
description: '{{ doc("blast_logs_contract_address") }}'
|
||||
- name: EVENT_NAME
|
||||
description: '{{ doc("blast_event_name") }}'
|
||||
- name: EVENT_INDEX
|
||||
description: '{{ doc("blast_event_index") }}'
|
||||
- name: ORIGIN_FUNCTION_SIGNATURE
|
||||
description: '{{ doc("nft_origin_sig") }}'
|
||||
- name: ORIGIN_FROM_ADDRESS
|
||||
description: '{{ doc("blast_origin_from") }}'
|
||||
- name: ORIGIN_TO_ADDRESS
|
||||
description: '{{ doc("blast_origin_to") }}'
|
||||
- name: PLATFORM
|
||||
description: '{{ doc("complete_lending_platform") }}'
|
||||
- name: DEPOSITOR
|
||||
description: '{{ doc("borrower") }}'
|
||||
- name: PROTOCOL_MARKET
|
||||
description: '{{ doc("complete_lending_protocol_token") }}'
|
||||
- name: TOKEN_ADDRESS
|
||||
description: '{{ doc("complete_lending_token_address") }}'
|
||||
- name: TOKEN_SYMBOL
|
||||
description: '{{ doc("complete_lending_token_symbol") }}'
|
||||
- name: AMOUNT_UNADJ
|
||||
description: '{{ doc("complete_lending_amount_unadj") }}'
|
||||
- name: AMOUNT
|
||||
description: '{{ doc("complete_lending_amount") }}'
|
||||
- name: AMOUNT_USD
|
||||
description: '{{ doc("complete_lending_amount_usd") }}'
|
||||
- name: EZ_LENDING_WITHDRAWS_ID
|
||||
description: '{{ doc("pk") }}'
|
||||
- name: INSERTED_TIMESTAMP
|
||||
description: '{{ doc("inserted_timestamp") }}'
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
description: '{{ doc("modified_timestamp") }}'
|
||||
@ -1,6 +1,7 @@
|
||||
-- depends_on: {{ ref('silver__complete_token_prices') }}
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
enabled = false,
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = ['block_number','platform'],
|
||||
cluster_by = ['block_timestamp::DATE','platform'],
|
||||
@ -46,79 +47,12 @@ WHERE
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
moonwell AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
liquidator,
|
||||
borrower,
|
||||
amount_unadj,
|
||||
amount AS liquidated_amount,
|
||||
NULL AS liquidated_amount_usd,
|
||||
token AS protocol_collateral_asset,
|
||||
liquidation_contract_address AS debt_asset,
|
||||
liquidation_contract_symbol AS debt_asset_symbol,
|
||||
collateral_token AS collateral_asset,
|
||||
collateral_symbol AS collateral_asset_symbol,
|
||||
platform,
|
||||
'base' AS blockchain,
|
||||
l._LOG_ID,
|
||||
l._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__moonwell_liquidations') }}
|
||||
l
|
||||
|
||||
{% if is_incremental() and 'moonwell' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
l._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
liquidation_union AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
aave
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
granary
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
morpho
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
comp
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
sonne
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
seamless
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
moonwell
|
||||
init
|
||||
),
|
||||
complete_lending_liquidations AS (
|
||||
SELECT
|
||||
|
||||
Loading…
Reference in New Issue
Block a user