remove lending models

This commit is contained in:
mattromano 2025-08-19 08:06:15 -07:00
parent db479177b1
commit 3a820d42a1
44 changed files with 2 additions and 4268 deletions

View File

@ -109,6 +109,8 @@ models:
+enabled: true
dex:
+enabled: true
lending:
+enabled: true
scores_package:
+enabled: true

View File

@ -1,38 +0,0 @@
{{ config(
materialized = 'view',
persist_docs ={ "relation": true,
"columns": true },
meta={
'database_tags':{
'table': {
'PROTOCOL': 'AAVE, COMPOUND',
'PURPOSE': 'LENDING, BORROWS'
}
}
},
tags = ['gold','defi','lending','curated','ez']
) }}
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,
complete_lending_borrows_id AS ez_lending_borrows_id,
inserted_timestamp,
modified_timestamp
FROM
{{ ref('silver__complete_lending_borrows') }}

View File

@ -1,38 +0,0 @@
{{ config(
materialized = 'view',
persist_docs ={ "relation": true,
"columns": true },
meta={
'database_tags':{
'table': {
'PROTOCOL': 'AAVE, COMPOUND',
'PURPOSE': 'LENDING, DEPOSITS'
}
}
},
tags = ['gold','defi','lending','curated','ez']
) }}
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,
complete_lending_deposits_id AS ez_lending_deposits_id,
inserted_timestamp,
modified_timestamp
FROM
{{ ref('silver__complete_lending_deposits') }}

View File

@ -1,42 +0,0 @@
{{ config(
materialized = 'view',
persist_docs ={ "relation": true,
"columns": true },
meta={
'database_tags':{
'table': {
'PROTOCOL': 'AAVE',
'PURPOSE': 'LENDING, FLASHLOANS'
}
}
},
tags = ['gold','defi','lending','curated','ez']
) }}
SELECT
block_number,
block_timestamp,
tx_hash,
contract_address,
event_name,
event_index,
origin_function_signature,
origin_from_address,
origin_to_address,
platform,
initiator,
target,
protocol_market,
flashloan_token,
flashloan_token_symbol,
flashloan_amount_unadj,
flashloan_amount,
flashloan_amount_usd,
premium_amount_unadj,
premium_amount,
premium_amount_usd,
complete_lending_flashloans_id AS ez_lending_flashloans_id,
inserted_timestamp,
modified_timestamp
FROM
{{ ref('silver__complete_lending_flashloans') }}

View File

@ -1,41 +0,0 @@
{{ config(
materialized = 'view',
persist_docs ={ "relation": true,
"columns": true },
meta={
'database_tags':{
'table': {
'PROTOCOL': 'AAVE, COMPOUND',
'PURPOSE': 'LENDING, LIQUIDATIONS'
}
}
},
tags = ['gold','defi','lending','curated','ez']
) }}
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,
complete_lending_liquidations_id AS ez_lending_liquidations_id,
inserted_timestamp,
modified_timestamp
FROM
{{ ref('silver__complete_lending_liquidations') }}

View File

@ -1,39 +0,0 @@
{{ config(
materialized = 'view',
persist_docs ={ "relation": true,
"columns": true },
meta={
'database_tags':{
'table': {
'PROTOCOL': 'AAVE, COMPOUND',
'PURPOSE': 'LENDING, REPAYMENTS'
}
}
},
tags = ['gold','defi','lending','curated','ez']
) }}
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,
complete_lending_repayments_id AS ez_lending_repayments_id,
inserted_timestamp,
modified_timestamp
FROM
{{ ref('silver__complete_lending_repayments') }}

View File

@ -1,38 +0,0 @@
{{ config(
materialized = 'view',
persist_docs ={ "relation": true,
"columns": true },
meta={
'database_tags':{
'table': {
'PROTOCOL': 'AAVE, COMPOUND',
'PURPOSE': 'LENDING, WITHDRAWS'
}
}
},
tags = ['gold','defi','lending','curated','ez']
) }}
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,
complete_lending_withdraws_id AS ez_lending_withdraws_id,
inserted_timestamp,
modified_timestamp
FROM
{{ ref('silver__complete_lending_withdraws') }}

View File

@ -1,124 +0,0 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_number",
cluster_by = ['block_timestamp::DATE'],
tags = ['silver','defi','lending','curated']
) }}
WITH --borrows from Aave LendingPool contracts
atoken_meta AS (
SELECT
atoken_address,
aave_version_pool,
atoken_symbol,
atoken_name,
atoken_decimals,
underlying_address,
underlying_symbol,
underlying_name,
underlying_decimals,
atoken_version,
atoken_created_block,
atoken_stable_debt_address,
atoken_variable_debt_address
FROM
{{ ref('silver__aave_tokens') }}
),
borrow AS (
SELECT
tx_hash,
block_number,
block_timestamp,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS aave_market,
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS onBehalfOf,
utils.udf_hex_to_int(
topics [3] :: STRING
) :: INTEGER AS refferal,
CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS userAddress,
utils.udf_hex_to_int(
segmented_data [1] :: STRING
) :: INTEGER AS borrow_quantity,
utils.udf_hex_to_int(
segmented_data [2] :: STRING
) :: INTEGER AS borrow_rate_mode,
utils.udf_hex_to_int(
segmented_data [3] :: STRING
) :: INTEGER AS borrowrate,
CASE
WHEN contract_address = '0x794a61358d6845594f94dc1db02a252b5b4814ad' THEN 'Aave V3'
WHEN contract_address = '0x8dff5e27ea6b7ac08ebfdf9eb090f32ee9a30fcf' THEN 'Aave V2'
ELSE 'ERROR'
END AS aave_version,
origin_from_address AS borrower_address,
COALESCE(
origin_to_address,
contract_address
) AS lending_pool_contract,
modified_timestamp AS _inserted_timestamp,
CONCAT(
tx_hash :: STRING,
'-',
event_index :: STRING
) AS _log_id
FROM
{{ ref('core__fact_event_logs') }}
WHERE
topics [0] :: STRING IN (
'0xc6a898309e823ee50bac64e45ca8adba6690e99e7841c45d754e2a38e9019d9b',
'0xb3d084820fb1a9decffb176436bd02558d15fac9b0ddfed8c465bc7359d7dce0'
)
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp) - INTERVAL '12 hours'
FROM
{{ this }}
)
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
AND contract_address IN (SELECT distinct(aave_version_pool) from atoken_meta)
AND tx_succeeded --excludes failed txs
)
SELECT
tx_hash,
block_number,
block_timestamp,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
aave_market,
atoken_meta.atoken_address AS aave_token,
borrow_quantity AS amount_unadj,
borrow_quantity / pow(
10,
atoken_meta.underlying_decimals
) AS amount,
borrower_address,
CASE
WHEN borrow_rate_mode = 2 THEN 'Variable Rate'
ELSE 'Stable Rate'
END AS borrow_rate_mode,
lending_pool_contract,
aave_version AS platform,
atoken_meta.underlying_symbol AS symbol,
atoken_meta.underlying_decimals AS underlying_decimals,
'polygon' AS blockchain,
_log_id,
_inserted_timestamp
FROM
borrow
LEFT JOIN atoken_meta
ON borrow.aave_market = atoken_meta.underlying_address qualify(ROW_NUMBER() over(PARTITION BY _log_id
ORDER BY
_inserted_timestamp DESC)) = 1

View File

@ -1,52 +0,0 @@
version: 2
models:
- name: silver__aave_borrows
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- TX_HASH
- EVENT_INDEX
columns:
- name: TX_HASH
tests:
- not_null
- name: BLOCK_NUMBER
tests:
- not_null
- name: BLOCK_TIMESTAMP
tests:
- not_null
- name: EVENT_INDEX
tests:
- not_null
- name: AAVE_MARKET
tests:
- not_null
- name: AMOUNT_UNADJ
tests:
- not_null
- name: AMOUNT
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- decimal
- float
- name: BORROWER_ADDRESS
tests:
- not_null
- name: BORROW_RATE_MODE
tests:
- not_null
- name: LENDING_POOL_CONTRACT
tests:
- not_null
- name: PLATFORM
tests:
- not_null
- name: SYMBOL
tests:
- not_null
- name: BLOCKCHAIN
tests:
- not_null

View File

@ -1,113 +0,0 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_number",
cluster_by = ['block_timestamp::DATE'],
tags = ['silver','defi','lending','curated']
) }}
WITH
atoken_meta AS (
SELECT
atoken_address,
aave_version_pool,
atoken_symbol,
atoken_name,
atoken_decimals,
underlying_address,
underlying_symbol,
underlying_name,
underlying_decimals,
atoken_version,
atoken_created_block,
atoken_stable_debt_address,
atoken_variable_debt_address
FROM
{{ ref('silver__aave_tokens') }}
),
deposits AS(
SELECT
tx_hash,
block_number,
block_timestamp,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS aave_market,
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS onBehalfOf,
utils.udf_hex_to_int(
topics [3] :: STRING
) :: INTEGER AS refferal,
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 42)) AS userAddress,
utils.udf_hex_to_int(
segmented_data [1] :: STRING
) :: INTEGER AS deposit_quantity,
CASE
WHEN contract_address = '0x794a61358d6845594f94dc1db02a252b5b4814ad' THEN 'Aave V3'
WHEN contract_address = '0x8dff5e27ea6b7ac08ebfdf9eb090f32ee9a30fcf' THEN 'Aave V2'
ELSE 'ERROR'
END AS aave_version,
origin_from_address AS depositor_address,
COALESCE(
origin_to_address,
contract_address
) AS lending_pool_contract,
modified_timestamp AS _inserted_timestamp,
CONCAT(
tx_hash :: STRING,
'-',
event_index :: STRING
) AS _log_id
FROM
{{ ref('core__fact_event_logs') }}
WHERE
topics [0] :: STRING IN (
'0xde6857219544bb5b7746f48ed30be6386fefc61b2f864cacf559893bf50fd951',
'0x2b627736bca15cd5381dcf80b0bf11fd197d01a037c52b927a881a10fb73ba61'
)
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp) - INTERVAL '12 hours'
FROM
{{ this }}
)
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
AND contract_address IN (SELECT distinct(aave_version_pool) from atoken_meta)
AND tx_succeeded --excludes failed txs
)
SELECT
tx_hash,
block_number,
block_timestamp,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
aave_market,
atoken_meta.atoken_address AS aave_token,
deposit_quantity AS amount_unadj,
deposit_quantity / pow(
10,
atoken_meta.underlying_decimals
) AS amount,
depositor_address,
lending_pool_contract,
aave_version AS platform,
atoken_meta.underlying_symbol AS symbol,
'polygon' AS blockchain,
_log_id,
_inserted_timestamp
FROM
deposits
LEFT JOIN atoken_meta
ON deposits.aave_market = atoken_meta.underlying_address qualify(ROW_NUMBER() over(PARTITION BY _log_id
ORDER BY
_inserted_timestamp DESC)) = 1

View File

@ -1,48 +0,0 @@
version: 2
models:
- name: silver__aave_deposits
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- TX_HASH
- EVENT_INDEX
columns:
- name: BLOCKCHAIN
tests:
- not_null
- name: BLOCK_NUMBER
tests:
- not_null
- name: BLOCK_TIMESTAMP
tests:
- not_null
- name: TX_HASH
tests:
- not_null
- 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: EVENT_INDEX
tests:
- not_null
- name: AAVE_MARKET
tests:
- not_null
- name: DEPOSITOR_ADDRESS
tests:
- not_null
- name: LENDING_POOL_CONTRACT
tests:
- not_null
- name: PLATFORM
tests:
- not_null
- name: SYMBOL
tests:
- not_null

View File

@ -1,125 +0,0 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_number",
cluster_by = ['block_timestamp::DATE'],
tags = ['silver','defi','lending','curated']
) }}
WITH
atoken_meta AS (
SELECT
atoken_address,
aave_version_pool,
atoken_symbol,
atoken_name,
atoken_decimals,
underlying_address,
underlying_symbol,
underlying_name,
underlying_decimals,
atoken_version,
atoken_created_block,
atoken_stable_debt_address,
atoken_variable_debt_address
FROM
{{ ref('silver__aave_tokens') }}
),
flashloan AS (
SELECT
tx_hash,
block_number,
block_timestamp,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS target_address,
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS initiator_address,
CASE
WHEN contract_address = '0x794a61358d6845594f94dc1db02a252b5b4814ad' THEN CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40))
WHEN contract_address = '0x8dff5e27ea6b7ac08ebfdf9eb090f32ee9a30fcf' THEN CONCAT('0x', SUBSTR(topics [3] :: STRING, 27, 40))
ELSE NULL
END AS aave_market,
CASE
WHEN contract_address = '0x794a61358d6845594f94dc1db02a252b5b4814ad' THEN utils.udf_hex_to_int(segmented_data [1] :: STRING) :: INTEGER
WHEN contract_address = '0x8dff5e27ea6b7ac08ebfdf9eb090f32ee9a30fcf' THEN utils.udf_hex_to_int(segmented_data [0] :: STRING) :: INTEGER
ELSE NULL
END AS flashloan_quantity,
CASE
WHEN contract_address = '0x794a61358d6845594f94dc1db02a252b5b4814ad' THEN utils.udf_hex_to_int(segmented_data [2] :: STRING) :: INTEGER
WHEN contract_address = '0x8dff5e27ea6b7ac08ebfdf9eb090f32ee9a30fcf' THEN utils.udf_hex_to_int(segmented_data [1] :: STRING) :: INTEGER
ELSE NULL
END AS premium_quantity,
COALESCE(
origin_to_address,
contract_address
) AS lending_pool_contract,
CASE
WHEN contract_address = '0x794a61358d6845594f94dc1db02a252b5b4814ad' THEN 'Aave V3'
WHEN contract_address = '0x8dff5e27ea6b7ac08ebfdf9eb090f32ee9a30fcf' THEN 'Aave V2'
ELSE 'ERROR'
END AS aave_version,
modified_timestamp AS _inserted_timestamp,
CONCAT(
tx_hash :: STRING,
'-',
event_index :: STRING
) AS _log_id
FROM
{{ ref('core__fact_event_logs') }}
WHERE
topics [0] :: STRING IN (
'0xefefaba5e921573100900a3ad9cf29f222d995fb3b6045797eaea7521bd8d6f0', --v3
'0x631042c832b07452973831137f2d73e395028b44b250dedc5abb0ee766e168ac' --v2
)
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp) - INTERVAL '12 hours'
FROM
{{ this }}
)
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
AND contract_address IN (SELECT distinct(aave_version_pool) from atoken_meta)
AND tx_succeeded --excludes failed txs
)
SELECT
tx_hash,
block_number,
block_timestamp,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
aave_market,
atoken_meta.atoken_address AS aave_token,
flashloan_quantity AS flashloan_amount_unadj,
flashloan_quantity / pow(
10,
atoken_meta.underlying_decimals
) AS flashloan_amount,
premium_quantity AS premium_amount_unadj,
premium_quantity / pow(
10,
atoken_meta.underlying_decimals
) AS premium_amount,
initiator_address AS initiator_address,
target_address AS target_address,
aave_version AS platform,
atoken_meta.underlying_symbol AS symbol,
'polygon' AS blockchain,
_log_id,
_inserted_timestamp
FROM
flashloan
LEFT JOIN atoken_meta
ON flashloan.aave_market = atoken_meta.underlying_address qualify(ROW_NUMBER() over(PARTITION BY _log_id
ORDER BY
_inserted_timestamp DESC)) = 1

View File

@ -1,49 +0,0 @@
version: 2
models:
- name: silver__aave_flashloans
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- TX_HASH
- EVENT_INDEX
columns:
- name: BLOCKCHAIN
tests:
- not_null
- name: BLOCK_NUMBER
tests:
- not_null
- name: BLOCK_TIMESTAMP
tests:
- not_null
- name: EVENT_INDEX
tests:
- not_null
- name: TX_HASH
tests:
- not_null
- name: AAVE_MARKET
tests:
- not_null
- name: AAVE_TOKEN
- 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: INITIATOR_ADDRESS
tests:
- not_null
- name: TARGET_ADDRESS
tests:
- not_null
- name: PLATFORM
tests:
- not_null
- name: SYMBOL
tests:
- not_null

View File

@ -1,118 +0,0 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_number",
cluster_by = ['block_timestamp::DATE'],
tags = ['silver','defi','lending','curated']
) }}
WITH
atoken_meta AS (
SELECT
atoken_address,
aave_version_pool,
atoken_symbol,
atoken_name,
atoken_decimals,
underlying_address,
underlying_symbol,
underlying_name,
underlying_decimals,
atoken_version,
atoken_created_block,
atoken_stable_debt_address,
atoken_variable_debt_address
FROM
{{ ref('silver__aave_tokens') }}
),
liquidation AS(
SELECT
tx_hash,
block_number,
block_timestamp,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS collateral_asset,
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS debt_asset,
CONCAT('0x', SUBSTR(topics [3] :: STRING, 27, 40)) AS borrower_address,
utils.udf_hex_to_int(
segmented_data [0] :: STRING
) :: INTEGER AS debt_to_cover_amount,
utils.udf_hex_to_int(
segmented_data [1] :: STRING
) :: INTEGER AS liquidated_amount,
CONCAT('0x', SUBSTR(segmented_data [2] :: STRING, 25, 40)) AS liquidator_address,
CASE
WHEN contract_address = '0x794a61358d6845594f94dc1db02a252b5b4814ad' THEN 'Aave V3'
WHEN contract_address = '0x8dff5e27ea6b7ac08ebfdf9eb090f32ee9a30fcf' THEN 'Aave V2'
ELSE 'ERROR'
END AS aave_version,
COALESCE(
origin_to_address,
contract_address
) AS lending_pool_contract,
modified_timestamp AS _inserted_timestamp,
CONCAT(
tx_hash :: STRING,
'-',
event_index :: STRING
) AS _log_id
FROM
{{ ref('core__fact_event_logs') }}
WHERE
topics [0] :: STRING IN (
'0xe413a321e8681d831f4dbccbca790d2952b56f977908e45be37335533e005286',
'0x56864757fd5b1fc9f38f5f3a981cd8ae512ce41b902cf73fc506ee369c6bc237'
)
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp) - INTERVAL '12 hours'
FROM
{{ this }}
)
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
AND contract_address IN (SELECT distinct(aave_version_pool) from atoken_meta)
AND tx_succeeded --excludes failed txs
)
SELECT
tx_hash,
block_number,
block_timestamp,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
collateral_asset,
amc.atoken_address AS collateral_aave_token,
liquidated_amount AS amount_unadj,
liquidated_amount / pow(
10,
amc.atoken_decimals
) AS amount,
debt_asset,
amd.atoken_address AS debt_aave_token,
liquidator_address AS liquidator,
borrower_address AS borrower,
aave_version AS platform,
amc.underlying_symbol AS collateral_token_symbol,
amd.underlying_symbol AS debt_token_symbol,
'polygon' AS blockchain,
_log_id,
_inserted_timestamp
FROM
liquidation
LEFT JOIN atoken_meta amc
ON liquidation.collateral_asset = amc.underlying_address
LEFT JOIN atoken_meta amd
ON liquidation.debt_asset = amd.underlying_address qualify(ROW_NUMBER() over(PARTITION BY _log_id
ORDER BY
_inserted_timestamp DESC)) = 1

View File

@ -1,53 +0,0 @@
version: 2
models:
- name: silver__aave_liquidations
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- TX_HASH
- EVENT_INDEX
columns:
- name: BLOCKCHAIN
tests:
- not_null
- name: BLOCK_NUMBER
tests:
- not_null
- name: BLOCK_TIMESTAMP
tests:
- not_null
- name: EVENT_INDEX
tests:
- not_null
- name: TX_HASH
tests:
- not_null
- name: COLLATERAL_ASSET
tests:
- not_null
- name: COLLATERAL_AAVE_TOKEN
- 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: DEBT_AAVE_TOKEN
- name: LIQUIDATOR
tests:
- not_null
- name: BORROWER
tests:
- not_null
- name: PLATFORM
tests:
- not_null
- name: COLLATERAL_TOKEN_SYMBOL
tests:
- not_null
- name: DEBT_TOKEN_SYMBOL
tests:
- not_null

View File

@ -1,111 +0,0 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_number",
cluster_by = ['block_timestamp::DATE'],
tags = ['silver','defi','lending','curated']
) }}
WITH
atoken_meta AS (
SELECT
atoken_address,
aave_version_pool,
atoken_symbol,
atoken_name,
atoken_decimals,
underlying_address,
underlying_symbol,
underlying_name,
underlying_decimals,
atoken_version,
atoken_created_block,
atoken_stable_debt_address,
atoken_variable_debt_address
FROM
{{ ref('silver__aave_tokens') }}
),
repay AS(
SELECT
tx_hash,
block_number,
block_timestamp,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS aave_market,
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS borrower_address,
CONCAT('0x', SUBSTR(topics [3] :: STRING, 27, 40)) AS repayer,
utils.udf_hex_to_int(
segmented_data [0] :: STRING
) :: INTEGER AS repayed_amount,
CASE
WHEN contract_address = '0x794a61358d6845594f94dc1db02a252b5b4814ad' THEN 'Aave V3'
WHEN contract_address = '0x8dff5e27ea6b7ac08ebfdf9eb090f32ee9a30fcf' THEN 'Aave V2'
ELSE 'ERROR'
END AS aave_version,
COALESCE(
origin_to_address,
contract_address
) AS lending_pool_contract,
origin_from_address AS repayer_address,
CONCAT(
tx_hash :: STRING,
'-',
event_index :: STRING
) AS _log_id,
modified_timestamp AS _inserted_timestamp
FROM
{{ ref('core__fact_event_logs') }}
WHERE
topics [0] :: STRING IN (
'0x4cdde6e09bb755c9a5589ebaec640bbfedff1362d4b255ebf8339782b9942faa',
'0xa534c8dbe71f871f9f3530e97a74601fea17b426cae02e1c5aee42c96c784051'
)
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp) - INTERVAL '12 hours'
FROM
{{ this }}
)
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
AND contract_address IN (SELECT distinct(aave_version_pool) from atoken_meta)
AND tx_succeeded --excludes failed txs
)
SELECT
tx_hash,
block_number,
block_timestamp,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
aave_market,
atoken_meta.atoken_address AS aave_token,
repayed_amount AS amount_unadj,
repayed_amount / pow(
10,
atoken_meta.underlying_decimals
) AS amount,
repayer_address AS payer,
borrower_address AS borrower,
lending_pool_contract,
aave_version AS platform,
atoken_meta.underlying_symbol AS symbol,
'polygon' AS blockchain,
_log_id,
_inserted_timestamp
FROM
repay
LEFT JOIN atoken_meta
ON repay.aave_market = atoken_meta.underlying_address qualify(ROW_NUMBER() over(PARTITION BY _log_id
ORDER BY
_inserted_timestamp DESC)) = 1

View File

@ -1,52 +0,0 @@
version: 2
models:
- name: silver__aave_repayments
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- TX_HASH
- EVENT_INDEX
columns:
- name: BLOCKCHAIN
tests:
- not_null
- name: BLOCK_NUMBER
tests:
- not_null
- name: TX_HASH
tests:
- not_null
- name: BLOCK_TIMESTAMP
tests:
- not_null
- name: EVENT_INDEX
tests:
- not_null
- name: AAVE_MARKET
tests:
- not_null
- name: AAVE_TOKEN
- 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: PAYER
tests:
- not_null
- name: BORROWER
tests:
- not_null
- name: LENDING_POOL_CONTRACT
tests:
- not_null
- name: PLATFORM
tests:
- not_null
- name: SYMBOL
tests:
- not_null

View File

@ -1,151 +0,0 @@
{{ config(
materialized = 'incremental',
unique_key = "atoken_address",
tags = ['silver','defi','lending','curated']
) }}
WITH DECODE AS (
SELECT
block_number AS atoken_created_block,
contract_address AS a_token_address,
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS underlying_asset,
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS aave_version_pool,
CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS treasury_address,
utils.udf_hex_to_int(
SUBSTR(
segmented_data [2] :: STRING,
27,
40
)
) :: INTEGER AS atoken_decimals,
utils.udf_hex_to_string (
segmented_data [7] :: STRING
) :: STRING AS atoken_name,
utils.udf_hex_to_string (
segmented_data [9] :: STRING
) :: STRING AS atoken_symbol,
modified_timestamp AS _inserted_timestamp,
CONCAT(
tx_hash :: STRING,
'-',
event_index :: STRING
) AS _log_id
FROM
{{ ref('core__fact_event_logs') }}
WHERE
topics [0] = '0xb19e051f8af41150ccccb3fc2c2d8d15f4a4cf434f32a559ba75fe73d6eea20b'
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(
_inserted_timestamp
) - INTERVAL '12 hours'
FROM
{{ this }}
)
AND contract_address NOT IN (
SELECT
atoken_address
FROM
{{ this }}
)
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
),
a_token_step_1 AS (
SELECT
atoken_created_block,
a_token_address,
segmented_data,
underlying_asset,
aave_version_pool,
treasury_address,
atoken_decimals,
atoken_name,
atoken_symbol,
_inserted_timestamp,
_log_id
FROM
DECODE
WHERE
treasury_address IN ('0xe8599f3cc5d38a9ad6f3684cd5cea72f10dbc383','0x7734280a4337f37fbf4651073db7c28c80b339e9')
AND
aave_version_pool IN ('0x794a61358d6845594f94dc1db02a252b5b4814ad','0x8dff5e27ea6b7ac08ebfdf9eb090f32ee9a30fcf')
),
debt_tokens AS (
SELECT
block_number AS atoken_created_block,
contract_address AS a_token_address,
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS underlying_asset,
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS atoken_address,
CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 27, 40)) :: STRING AS atoken_stable_debt_address,
CONCAT('0x', SUBSTR(segmented_data [1] :: STRING, 27, 40)) :: STRING AS atoken_variable_debt_address,
modified_timestamp AS _inserted_timestamp,
CONCAT(
tx_hash :: STRING,
'-',
event_index :: STRING
) AS _log_id
FROM
{{ ref('core__fact_event_logs') }}
WHERE
topics [0] = '0x3a0ca721fc364424566385a1aa271ed508cc2c0949c2272575fb3013a163a45f'
AND CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) IN (
SELECT
a_token_address
FROM
a_token_step_1
)
),
a_token_step_2 AS (
SELECT
atoken_created_block,
a_token_address,
treasury_address,
segmented_data,
underlying_asset,
aave_version_pool,
atoken_decimals,
atoken_name,
atoken_symbol,
_inserted_timestamp,
_log_id,
CASE
WHEN aave_version_pool = '0x794a61358d6845594f94dc1db02a252b5b4814ad' THEN 'Aave V3'
WHEN aave_version_pool = '0x8dff5e27ea6b7ac08ebfdf9eb090f32ee9a30fcf' THEN 'Aave V2'
ELSE NULL
END AS protocol
FROM
a_token_step_1
WHERE
protocol IS NOT NULL
)
SELECT
A.atoken_created_block,
A.aave_version_pool,
A.treasury_address,
A.atoken_symbol AS atoken_symbol,
A.a_token_address AS atoken_address,
b.atoken_stable_debt_address,
b.atoken_variable_debt_address,
A.atoken_decimals AS atoken_decimals,
A.protocol AS atoken_version,
atoken_name AS atoken_name,
C.token_symbol AS underlying_symbol,
A.underlying_asset AS underlying_address,
C.token_decimals AS underlying_decimals,
C.token_name AS underlying_name,
A._inserted_timestamp,
A._log_id
FROM
a_token_step_2 A
INNER JOIN debt_tokens b
ON A.a_token_address = b.atoken_address
INNER JOIN {{ ref('silver__contracts') }} C
ON contract_address = A.underlying_asset qualify(ROW_NUMBER() over(PARTITION BY atoken_address
ORDER BY
A.atoken_created_block DESC)) = 1

View File

@ -1,45 +0,0 @@
version: 2
models:
- name: silver__aave_tokens
tests:
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- ATOKEN_ADDRESS
columns:
- name: ATOKEN_CREATED_BLOCK
tests:
- not_null
- name: ATOKEN_SYMBOL
tests:
- not_null
- name: ATOKEN_ADDRESS
tests:
- not_null
- name: ATOKEN_STABLE_DEBT_ADDRESS
tests:
- not_null
- name: ATOKEN_VARIABLE_DEBT_ADDRESS
tests:
- not_null
- name: ATOKEN_DECIMALS
tests:
- not_null
- name: ATOKEN_VERSION
tests:
- not_null
- name: ATOKEN_NAME
tests:
- not_null
- name: UNDERLYING_SYMBOL
tests:
- not_null
- name: UNDERLYING_ADDRESS
tests:
- not_null
- name: UNDERLYING_DECIMALS
tests:
- not_null
- name: UNDERLYING_NAME
tests:
- not_null

View File

@ -1,108 +0,0 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_number",
cluster_by = ['block_timestamp::DATE'],
tags = ['silver','defi','lending','curated']
) }}
WITH
atoken_meta AS (
SELECT
atoken_address,
aave_version_pool,
atoken_symbol,
atoken_name,
atoken_decimals,
underlying_address,
underlying_symbol,
underlying_name,
underlying_decimals,
atoken_version,
atoken_created_block,
atoken_stable_debt_address,
atoken_variable_debt_address
FROM
{{ ref('silver__aave_tokens') }}
),
withdraw AS(
SELECT
block_number,
block_timestamp,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS aave_market,
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS useraddress,
CONCAT('0x', SUBSTR(topics [3] :: STRING, 27, 40)) AS depositor,
utils.udf_hex_to_int(
segmented_data [0] :: STRING
) :: INTEGER AS withdraw_amount,
tx_hash,
CASE
WHEN contract_address = '0x794a61358d6845594f94dc1db02a252b5b4814ad' THEN 'Aave V3'
WHEN contract_address = '0x8dff5e27ea6b7ac08ebfdf9eb090f32ee9a30fcf' THEN 'Aave V2'
ELSE 'ERROR'
END AS aave_version,
COALESCE(
origin_to_address,
contract_address
) AS lending_pool_contract,
modified_timestamp AS _inserted_timestamp,
CONCAT(
tx_hash :: STRING,
'-',
event_index :: STRING
) AS _log_id
FROM
{{ ref('core__fact_event_logs') }}
WHERE
topics [0] :: STRING IN (
'0x3115d1449a7b732c986cba18244e897a450f61e1bb8d589cd2e69e6c8924f9f7',
'0x9c4ed599cd8555b9c1e8cd7643240d7d71eb76b792948c49fcb4d411f7b6b3c6'
)
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp) - INTERVAL '12 hours'
FROM
{{ this }}
)
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
AND contract_address IN (SELECT distinct(aave_version_pool) from atoken_meta)
AND tx_succeeded --excludes failed txs
)
SELECT
tx_hash,
block_number,
block_timestamp,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
aave_market,
atoken_meta.atoken_address AS aave_token,
withdraw_amount AS amount_unadj,
withdraw_amount / pow(
10,
atoken_meta.underlying_decimals
) AS amount,
depositor depositor_address,
aave_version AS platform,
atoken_meta.underlying_symbol AS symbol,
'polygon' AS blockchain,
_log_id,
_inserted_timestamp
FROM
withdraw
LEFT JOIN atoken_meta
ON withdraw.aave_market = atoken_meta.underlying_address qualify(ROW_NUMBER() over(PARTITION BY _log_id
ORDER BY
_inserted_timestamp DESC)) = 1

View File

@ -1,46 +0,0 @@
version: 2
models:
- name: silver__aave_withdraws
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- TX_HASH
- EVENT_INDEX
columns:
- name: BLOCKCHAIN
tests:
- not_null
- name: TX_HASH
tests:
- not_null
- name: BLOCK_NUMBER
tests:
- not_null
- name: BLOCK_TIMESTAMP
tests:
- not_null
- name: EVENT_INDEX
tests:
- not_null
- name: AAVE_MARKET
tests:
- not_null
- name: AAVE_TOKEN
- 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: DEPOSITOR_ADDRESS
tests:
- not_null
- name: PLATFORM
tests:
- not_null
- name: SYMBOL
tests:
- not_null

View File

@ -1,262 +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 = ['silver','defi','lending','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,
'polygon' 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 %}
),
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,
'polygon' 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 %}
),
borrow_union AS (
SELECT
*
FROM
aave
UNION ALL
SELECT
*
FROM
comp
),
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(
['tx_hash','event_index']
) }} 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

View File

@ -1,55 +0,0 @@
version: 2
models:
- name: silver__complete_lending_borrows
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- TX_HASH
- EVENT_INDEX
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
- name: BORROWER
tests:
- not_null
- name: PROTOCOL_MARKET
tests:
- not_null
- name: TOKEN_ADDRESS
tests:
- not_null
- name: TOKEN_SYMBOL
tests:
- not_null
- name: AMOUNT_UNADJ
tests:
- not_null
- name: AMOUNT
tests:
- not_null
- 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

View File

@ -1,259 +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 = ['silver','defi','lending','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,
'polygon' 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 %}
),
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,
'polygon' 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 %}
),
deposit_union AS (
SELECT
*
FROM
aave
UNION ALL
SELECT
*
FROM
comp
),
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 = '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(
['tx_hash','event_index']
) }} 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

View File

@ -1,55 +0,0 @@
version: 2
models:
- name: silver__complete_lending_deposits
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- TX_HASH
- EVENT_INDEX
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
- name: PROTOCOL_MARKET
tests:
- not_null
- name: DEPOSITOR
tests:
- not_null
- name: TOKEN_ADDRESS
tests:
- not_null
- name: TOKEN_SYMBOL
tests:
- not_null
- name: AMOUNT_UNADJ
tests:
- not_null
- name: AMOUNT
tests:
- not_null
- 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

View File

@ -1,280 +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 = ['silver','defi','lending','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,
platform,
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 %}
),
flashloan_union AS (
SELECT
*
FROM
aave
),
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.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(
['tx_hash','event_index']
) }} 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

View File

@ -1,54 +0,0 @@
version: 2
models:
- name: silver__complete_lending_flashloans
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- TX_HASH
- EVENT_INDEX
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
- name: TX_HASH
tests:
- not_null
- name: PROTOCOL_MARKET
tests:
- not_null
- name: INITIATOR
tests:
- not_null
- name: TARGET
tests:
- not_null
- 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

View File

@ -1,288 +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 = ['silver','defi','lending','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,
platform,
'polygon' 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 %}
),
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,
'polygon' 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 %}
),
liquidation_union AS (
SELECT
*
FROM
aave
UNION ALL
SELECT
*
FROM
comp
),
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 = '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(
['tx_hash','event_index']
) }} 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

View File

@ -1,58 +0,0 @@
version: 2
models:
- name: silver__complete_lending_liquidations
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- TX_HASH
- EVENT_INDEX
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
- name: LIQUIDATOR
tests:
- not_null
- name: BORROWER
tests:
- not_null
- name: PROTOCOL_MARKET
tests:
- not_null
- name: COLLATERAL_TOKEN
tests:
- not_null
- name: COLLATERAL_TOKEN_SYMBOL
tests:
- not_null
- name: AMOUNT_UNADJ
tests:
- not_null
- name: AMOUNT
tests:
- not_null
- 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

View File

@ -1,263 +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 = ['silver','defi','lending','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,
platform,
'polygon' 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 %}
),
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,
'polygon' 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 %}
),
repayments_union AS (
SELECT
*
FROM
aave
UNION ALL
SELECT
*
FROM
comp
),
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 = '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(
['tx_hash','event_index']
) }} 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

View File

@ -1,58 +0,0 @@
version: 2
models:
- name: silver__complete_lending_repayments
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- TX_HASH
- EVENT_INDEX
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
- 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
tests:
- not_null
- name: AMOUNT_UNADJ
tests:
- not_null
- name: AMOUNT
tests:
- not_null
- 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

View File

@ -1,262 +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 = ['silver','defi','lending','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,
platform,
'polygon' 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 %}
),
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,
'polygon' 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 %}
),
withdraws_union AS (
SELECT
*
FROM
aave
UNION ALL
SELECT
*
FROM
comp
),
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 = '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(
['tx_hash','event_index']
) }} 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

View File

@ -1,56 +0,0 @@
version: 2
models:
- name: silver__complete_lending_withdraws
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- TX_HASH
- EVENT_INDEX
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
- name: PROTOCOL_MARKET
tests:
- not_null
- name: DEPOSITOR
tests:
- not_null
- name: TOKEN_ADDRESS
tests:
- not_null
- name: TOKEN_SYMBOL
tests:
- not_null
- name: AMOUNT_UNADJ
tests:
- not_null
- name: AMOUNT
tests:
- not_null
- 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

View File

@ -1,114 +0,0 @@
{{ config(
materialized = 'incremental',
unique_key = "compound_market_address",
tags = ['silver','defi','lending','curated','asset_details']
) }}
WITH contracts_dim AS (
SELECT
address,
name,
symbol,
decimals
FROM
{{ ref('core__dim_contracts') }}
),
comp_v3_base AS (
SELECT
contract_address,
block_number,
live.udf_api(
'POST',
'{URL}',
OBJECT_CONSTRUCT(
'Content-Type', 'application/json',
'fsc-quantum-state', 'livequery'
),
utils.udf_json_rpc_call(
'eth_call',
[
{
'to': contract_address,
'from': null,
'data': RPAD('0xc55dae63', 64, '0')
},
utils.udf_int_to_hex(block_number)
],
concat_ws('-', contract_address, '0xc55dae63', block_number)
),
'Vault/prod/evm/quicknode/polygon/mainnet'
) AS api_response
FROM
{{ ref('core__fact_event_logs') }}
WHERE
topic_0 = '0xbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b'
AND origin_from_address IN (
LOWER('0x6103DB328d4864dc16BD2F0eE1B9A92e3F87f915'),
LOWER('0x2501713A67a3dEdde090E42759088A7eF37D4EAb')
)
{% if is_incremental() %}
AND modified_timestamp >= (
SELECT MAX(modified_timestamp) - INTERVAL '12 hours' FROM {{ this }}
)
AND modified_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
QUALIFY ROW_NUMBER() OVER (
PARTITION BY contract_address
ORDER BY block_number ASC
) = 1
),
comp_v3_data AS (
SELECT
l.contract_address AS ctoken_address,
c1.symbol AS ctoken_symbol,
c1.name AS ctoken_name,
c1.decimals AS ctoken_decimals,
LOWER(
CONCAT(
'0x',
SUBSTR(
l.api_response:data:result :: STRING,
-40
)
)
) AS underlying_address,
c2.name AS underlying_name,
c2.symbol AS underlying_symbol,
c2.decimals AS underlying_decimals,
l.block_number AS created_block,
'Compound V3' AS compound_version
FROM comp_v3_base l
LEFT JOIN contracts_dim c1 ON l.contract_address = c1.address
LEFT JOIN contracts_dim c2 ON LOWER(
CONCAT(
'0x',
SUBSTR(
l.api_response:data:result :: STRING,
-40
)
)
) = c2.address
WHERE c1.name IS NOT NULL
)
SELECT
ctoken_address AS compound_market_address,
ctoken_symbol AS compound_market_symbol,
ctoken_name AS compound_market_name,
ctoken_decimals AS compound_market_decimals,
underlying_address AS underlying_asset_address,
underlying_name AS underlying_asset_name,
underlying_symbol AS underlying_asset_symbol,
underlying_decimals AS underlying_asset_decimals,
created_block AS created_block_number,
compound_version,
{{ dbt_utils.generate_surrogate_key(['compound_market_address']) }} AS comp_asset_details_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp,
'{{ invocation_id }}' AS _invocation_id
FROM
comp_v3_data

View File

@ -1,105 +0,0 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_number",
cluster_by = ['block_timestamp::DATE'],
tags = ['silver','defi','lending','curated']
) }}
WITH comp_assets AS (
SELECT
compound_market_address,
compound_market_name,
compound_market_symbol,
compound_market_decimals,
underlying_asset_address,
underlying_asset_name,
underlying_asset_symbol,
underlying_asset_decimals
FROM
{{ ref('silver__comp_asset_details') }}
),
borrow AS (
SELECT
tx_hash,
block_number,
block_timestamp,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
contract_address AS asset,
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS src_address,
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS to_address,
utils.udf_hex_to_int(
segmented_data [0] :: STRING
) :: INTEGER AS borrow_amount,
origin_from_address AS borrower_address,
'Compound V3' AS compound_version,
C.compound_market_name AS NAME,
C.compound_market_symbol AS symbol,
C.compound_market_decimals AS decimals,
C.underlying_asset_address,
C.underlying_asset_symbol,
'polygon' AS blockchain,
CONCAT(
tx_hash :: STRING,
'-',
event_index :: STRING
) AS _log_id,
modified_timestamp AS _inserted_timestamp
FROM
{{ ref('core__fact_event_logs') }}
l
LEFT JOIN comp_assets C
ON asset = C.compound_market_address
WHERE
topics [0] = '0x9b1bfa7fa9ee420a16e124f794c35ac9f90472acc99140eb2f6447c714cad8eb' --withdrawl
AND l.contract_address IN (
SELECT
DISTINCT(compound_market_address)
FROM
comp_assets
)
AND tx_succeeded
{% if is_incremental() %}
AND l.modified_timestamp >= (
SELECT
MAX(_inserted_timestamp) - INTERVAL '12 hours'
FROM
{{ this }}
)
AND l.modified_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
)
SELECT
tx_hash,
block_number,
block_timestamp,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
w.asset AS compound_market,
borrower_address AS borrower,
w.underlying_asset_address AS token_address,
w.underlying_asset_symbol AS token_symbol,
borrow_amount AS amount_unadj,
borrow_amount / pow(
10,
w.decimals
) AS amount,
w.symbol AS itoken_symbol,
compound_version,
blockchain,
_log_id,
_inserted_timestamp
FROM
borrow w qualify(ROW_NUMBER() over(PARTITION BY _log_id
ORDER BY
_inserted_timestamp DESC)) = 1

View File

@ -1,47 +0,0 @@
version: 2
models:
- name: silver__comp_borrows
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- TX_HASH
- EVENT_INDEX
columns:
- name: TX_HASH
tests:
- not_null
- name: BLOCK_NUMBER
tests:
- not_null
- name: BLOCK_TIMESTAMP
tests:
- not_null
- name: EVENT_INDEX
tests:
- not_null
- name: COMPOUND_MARKET
tests:
- dbt_expectations.expect_column_values_to_match_regex:
regex: 0[xX][0-9a-fA-F]+
- name: BORROWER
tests:
- dbt_expectations.expect_column_values_to_match_regex:
regex: 0[xX][0-9a-fA-F]+
- name: TOKEN_ADDRESS
tests:
- not_null
- name: TOKEN_SYMBOL
tests:
- not_null
- name: AMOUNT_UNADJ
tests:
- not_null
- name: AMOUNT
tests:
- not_null
- name: COMPOUND_VERSION
tests:
- not_null
- name: BLOCKCHAIN
tests:
- not_null

View File

@ -1,102 +0,0 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_number",
cluster_by = ['block_timestamp::DATE'],
tags = ['silver','defi','lending','curated']
) }}
WITH comp_assets AS (
SELECT
compound_market_address,
compound_market_name,
compound_market_symbol,
compound_market_decimals,
underlying_asset_address,
underlying_asset_name,
underlying_asset_symbol,
underlying_asset_decimals
FROM
{{ ref('silver__comp_asset_details') }}
),
supply AS (
SELECT
tx_hash,
block_number,
block_timestamp,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
l.contract_address,
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
l.contract_address AS compound_market,
CONCAT('0x', SUBSTR(topics [3] :: STRING, 27, 40)) AS asset,
utils.udf_hex_to_int(
segmented_data [0] :: STRING
) :: INTEGER AS supply_amount,
origin_from_address AS depositor_address,
'Compound V3' AS compound_version,
C.contract_address AS underlying_asset_address,
C.token_name,
C.token_symbol,
C.token_decimals,
'polygon' AS blockchain,
CONCAT(
tx_hash :: STRING,
'-',
event_index :: STRING
) AS _log_id,
l.modified_timestamp AS _inserted_timestamp
FROM
{{ ref('core__fact_event_logs') }}
l
LEFT JOIN {{ ref('silver__contracts') }} C
ON asset = C.contract_address
WHERE
topics [0] = '0xfa56f7b24f17183d81894d3ac2ee654e3c26388d17a28dbd9549b8114304e1f4' --SupplyCollateral
AND l.contract_address IN (
SELECT
DISTINCT(compound_market_address)
FROM
comp_assets
)
AND tx_succeeded
{% if is_incremental() %}
AND l.modified_timestamp >= (
SELECT
MAX(_inserted_timestamp) - INTERVAL '12 hours'
FROM
{{ this }}
)
AND l.modified_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
)
SELECT
tx_hash,
block_number,
block_timestamp,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
compound_market,
depositor_address,
asset AS token_address,
token_symbol AS token_symbol,
supply_amount AS amount_unadj,
supply_amount / pow(
10,
w.token_decimals
) AS amount,
compound_version,
blockchain,
_log_id,
_inserted_timestamp
FROM
supply w qualify(ROW_NUMBER() over(PARTITION BY _log_id
ORDER BY
_inserted_timestamp DESC)) = 1

View File

@ -1,46 +0,0 @@
version: 2
models:
- name: silver__comp_deposits
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- TX_HASH
- EVENT_INDEX
columns:
- name: BLOCK_NUMBER
tests:
- not_null
- name: BLOCK_TIMESTAMP
tests:
- not_null
- name: TX_HASH
tests:
- not_null
- name: EVENT_INDEX
tests:
- not_null
- name: COMPOUND_MARKET
tests:
- dbt_expectations.expect_column_values_to_match_regex:
regex: 0[xX][0-9a-fA-F]+
- name: DEPOSITOR_ADDRESS
tests:
- dbt_expectations.expect_column_values_to_match_regex:
regex: 0[xX][0-9a-fA-F]+
- name: TOKEN_ADDRESS
tests:
- not_null
- name: TOKEN_SYMBOL
tests:
- not_null
- name: AMOUNT_UNADJ
tests:
- not_null
- name: AMOUNT
tests:
- not_null
- name: COMPOUND_VERSION
tests:
- not_null
- name: SYMBOL
- not_null

View File

@ -1,116 +0,0 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_number",
cluster_by = ['block_timestamp::DATE'],
tags = ['silver','defi','lending','curated']
) }}
WITH comp_assets AS (
SELECT
compound_market_address,
compound_market_name,
compound_market_symbol,
compound_market_decimals,
underlying_asset_address,
underlying_asset_name,
underlying_asset_symbol,
underlying_asset_decimals
FROM
{{ ref('silver__comp_asset_details') }}
),
liquidations AS (
SELECT
tx_hash,
block_number,
block_timestamp,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
l.contract_address,
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
l.contract_address AS compound_market,
CONCAT('0x', SUBSTR(topics [3] :: STRING, 27, 40)) AS asset,
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS absorber,
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS borrower,
utils.udf_hex_to_int(
segmented_data [0] :: STRING
) :: INTEGER AS collateral_absorbed,
utils.udf_hex_to_int(
segmented_data [1] :: STRING
) :: INTEGER AS usd_value,
origin_from_address AS depositor_address,
'Compound V3' AS compound_version,
C.token_name,
C.token_symbol,
C.token_decimals,
'polygon' AS blockchain,
CONCAT(
tx_hash :: STRING,
'-',
event_index :: STRING
) AS _log_id,
l.modified_timestamp AS _inserted_timestamp
FROM
{{ ref('core__fact_event_logs') }}
l
LEFT JOIN {{ ref('silver__contracts') }} C
ON asset = C.contract_address
WHERE
topics [0] = '0x9850ab1af75177e4a9201c65a2cf7976d5d28e40ef63494b44366f86b2f9412e' --AbsorbCollateral
AND l.contract_address IN (
SELECT
DISTINCT(compound_market_address)
FROM
comp_assets
)
AND tx_succeeded
{% if is_incremental() %}
AND l.modified_timestamp >= (
SELECT
MAX(_inserted_timestamp) - INTERVAL '12 hours'
FROM
{{ this }}
)
AND l.modified_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
)
SELECT
tx_hash,
block_number,
block_timestamp,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
l.contract_address,
compound_market,
absorber,
borrower,
depositor_address,
asset AS token_address,
token_symbol,
collateral_absorbed AS amount_unadj,
collateral_absorbed / pow(
10,
token_decimals
) AS amount,
usd_value / pow(
10,
8
) AS amount_usd,
A.underlying_asset_address AS debt_asset,
A.underlying_asset_symbol AS debt_asset_symbol,
compound_version,
blockchain,
l._log_id,
l._inserted_timestamp
FROM
liquidations l
LEFT JOIN comp_assets A
ON l.compound_market = A.compound_market_address qualify(ROW_NUMBER() over(PARTITION BY _log_id
ORDER BY
_inserted_timestamp DESC)) = 1

View File

@ -1,61 +0,0 @@
version: 2
models:
- name: silver__comp_liquidations
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- TX_HASH
- EVENT_INDEX
columns:
- name: BLOCKCHAIN
tests:
- not_null
- name: BLOCK_NUMBER
tests:
- not_null
- name: BLOCK_TIMESTAMP
tests:
- not_null
- name: EVENT_INDEX
tests:
- not_null
- name: TX_HASH
tests:
- not_null
- name: COMPOUND_MARKET
tests:
- dbt_expectations.expect_column_values_to_match_regex:
regex: 0[xX][0-9a-fA-F]+
- name: ABSORBER
tests:
- dbt_expectations.expect_column_values_to_match_regex:
regex: 0[xX][0-9a-fA-F]+
- name: BORROWER
tests:
- dbt_expectations.expect_column_values_to_match_regex:
regex: 0[xX][0-9a-fA-F]+
- name: DEPOSITOR_ADDRESS
tests:
- dbt_expectations.expect_column_values_to_match_regex:
regex: 0[xX][0-9a-fA-F]+
- name: TOKEN_ADDRESS
tests:
- not_null
- name: TOKEN_SYMBOL
tests:
- not_null
- name: AMOUNT_UNADJ
tests:
- not_null
- name: AMOUNT
tests:
- not_null
- name: DEBT_ASSET
tests:
- not_null
- name: DEBT_ASSET_SYMBOL
tests:
- not_null
- name: COMPOUND_VERSION
tests:
- not_null

View File

@ -1,109 +0,0 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_number",
cluster_by = ['block_timestamp::DATE'],
tags = ['silver','defi','lending','curated']
) }}
WITH comp_assets AS (
SELECT
compound_market_address,
compound_market_name,
compound_market_symbol,
compound_market_decimals,
underlying_asset_address,
underlying_asset_name,
underlying_asset_symbol,
underlying_asset_decimals
FROM
{{ ref('silver__comp_asset_details') }}
),
repayments AS (
SELECT
tx_hash,
block_number,
block_timestamp,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
l.contract_address,
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
l.contract_address AS asset,
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS repayer,
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS borrower,
utils.udf_hex_to_int(
segmented_data [0] :: STRING
) :: INTEGER AS amount,
utils.udf_hex_to_int(
segmented_data [1] :: STRING
) :: INTEGER AS usd_value,
origin_from_address AS depositor,
'Compound V3' AS compound_version,
compound_market_name,
compound_market_symbol,
compound_market_decimals,
C.underlying_asset_address AS underlying_asset,
C.underlying_asset_symbol,
'polygon' AS blockchain,
CONCAT(
tx_hash :: STRING,
'-',
event_index :: STRING
) AS _log_id,
l.modified_timestamp AS _inserted_timestamp
FROM
{{ ref('core__fact_event_logs') }}
l
LEFT JOIN comp_assets C
ON contract_address = C.compound_market_address
WHERE
topics [0] = '0xd1cf3d156d5f8f0d50f6c122ed609cec09d35c9b9fb3fff6ea0959134dae424e' --Supply
AND l.contract_address IN (
SELECT
DISTINCT(compound_market_address)
FROM
comp_assets
)
AND tx_succeeded
{% if is_incremental() %}
AND l.modified_timestamp >= (
SELECT
MAX(_inserted_timestamp) - INTERVAL '12 hours'
FROM
{{ this }}
)
AND l.modified_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
)
SELECT
tx_hash,
block_number,
block_timestamp,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
w.asset AS compound_market,
repayer,
borrower,
depositor,
underlying_asset AS token_address,
w.underlying_asset_symbol AS token_symbol,
amount AS amount_unadj,
amount / pow(
10,
w.compound_market_decimals
) AS amount,
compound_version,
blockchain,
_log_id,
_inserted_timestamp
FROM
repayments w qualify(ROW_NUMBER() over(PARTITION BY _log_id
ORDER BY
_inserted_timestamp DESC)) = 1

View File

@ -1,46 +0,0 @@
version: 2
models:
- name: silver__comp_repayments
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- TX_HASH
- EVENT_INDEX
columns:
- name: BLOCK_NUMBER
tests:
- not_null
- name: TX_HASH
tests:
- not_null
- name: BLOCK_TIMESTAMP
tests:
- not_null
- name: EVENT_INDEX
tests:
- not_null
- name: COMPOUND_MARKET
tests:
- not_null
- name: REPAYER
tests:
- not_null
- name: BORROWER
tests:
- not_null
- name: TOKEN_ADDRESS
tests:
- not_null
- name: TOKEN_SYMBOL
tests:
- not_null
- name: AMOUNT_UNADJ
tests:
- not_null
- name: AMOUNT
tests:
- not_null
- name: COMPOUND_VERSION
tests:
- not_null

View File

@ -1,101 +0,0 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_number",
cluster_by = ['block_timestamp::DATE'],
tags = ['silver','defi','lending','curated']
) }}
WITH comp_assets AS (
SELECT
compound_market_address,
compound_market_name,
compound_market_symbol,
compound_market_decimals,
underlying_asset_address,
underlying_asset_name,
underlying_asset_symbol,
underlying_asset_decimals
FROM
{{ ref('silver__comp_asset_details') }}
),
withdraw AS (
SELECT
tx_hash,
block_number,
block_timestamp,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
l.contract_address,
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
l.contract_address AS compound_market,
CONCAT('0x', SUBSTR(topics [3] :: STRING, 27, 40)) AS token_address,
utils.udf_hex_to_int(
segmented_data [0] :: STRING
) :: INTEGER AS withdraw_amount,
origin_from_address AS depositor_address,
'Compound V3' AS compound_version,
C.token_name,
C.token_symbol,
C.token_decimals,
'polygon' AS blockchain,
CONCAT(
tx_hash :: STRING,
'-',
event_index :: STRING
) AS _log_id,
l.modified_timestamp AS _inserted_timestamp
FROM
{{ ref('core__fact_event_logs') }}
l
LEFT JOIN {{ ref('silver__contracts') }} C
ON token_address = C.contract_address
WHERE
topics [0] = '0xd6d480d5b3068db003533b170d67561494d72e3bf9fa40a266471351ebba9e16' --WithdrawCollateral
AND l.contract_address IN (
SELECT
DISTINCT(compound_market_address)
FROM
comp_assets
)
AND tx_succeeded
{% if is_incremental() %}
AND l.modified_timestamp >= (
SELECT
MAX(_inserted_timestamp) - INTERVAL '12 hours'
FROM
{{ this }}
)
AND l.modified_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
)
SELECT
tx_hash,
block_number,
block_timestamp,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
compound_market,
depositor_address,
w.token_address,
w.token_symbol,
withdraw_amount AS amount_unadj,
withdraw_amount / pow(
10,
w.token_decimals
) AS amount,
compound_version,
blockchain,
_log_id,
_inserted_timestamp
FROM
withdraw w qualify(ROW_NUMBER() over(PARTITION BY _log_id
ORDER BY
_inserted_timestamp DESC)) = 1

View File

@ -1,40 +0,0 @@
version: 2
models:
- name: silver__comp_withdraws
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- TX_HASH
- EVENT_INDEX
columns:
- name: TX_HASH
tests:
- not_null
- name: BLOCK_NUMBER
tests:
- not_null
- name: BLOCK_TIMESTAMP
tests:
- not_null
- name: EVENT_INDEX
tests:
- not_null
- name: COMPOUND_MARKET
tests:
- not_null
- name: DEPOSITOR_ADDRESS
- name: TOKEN_ADDRESS
tests:
- not_null
- name: TOKEN_SYMBOL
tests:
- not_null
- name: AMOUNT_UNADJ
tests:
- not_null
- name: AMOUNT
tests:
- not_null
- name: COMPOUND_VERSION
tests:
- not_null