AN-6419/consolidate-curated-lending-models (#364)

* remove lending models and enable lending package

* remove granary

* tag
This commit is contained in:
Matt Romano 2025-09-15 11:20:08 -07:00 committed by GitHub
parent 964aba8601
commit b694969aee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
108 changed files with 9 additions and 10681 deletions

View File

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

View File

@ -1,49 +0,0 @@
{{ config(
materialized = 'view',
persist_docs ={ "relation": true,
"columns": true },
meta={
'database_tags':{
'table': {
'PROTOCOL': 'SONNE, AAVE, GRANARY, MOONWELL, MORPHO, SEAMLESS, 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,
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') }}

View File

@ -1,49 +0,0 @@
{{ config(
materialized = 'view',
persist_docs ={ "relation": true,
"columns": true },
meta={
'database_tags':{
'table': {
'PROTOCOL': 'SONNE, AAVE, GRANARY, MOONWELL, MORPHO, SEAMLESS, 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,
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') }}

View File

@ -1,53 +0,0 @@
{{ config(
materialized = 'view',
persist_docs ={ "relation": true,
"columns": true },
meta={
'database_tags':{
'table': {
'PROTOCOL': 'AAVE, MORPHO, GRANARY, SEAMLESS',
'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,
COALESCE (
complete_lending_flashloans_id,
{{ dbt_utils.generate_surrogate_key(
['tx_hash', 'event_index']
) }}
) AS ez_lending_flashloans_id,
COALESCE(
inserted_timestamp,
'2000-01-01'
) AS inserted_timestamp,
COALESCE(
modified_timestamp,
'2000-01-01'
) AS modified_timestamp
FROM
{{ ref('silver__complete_lending_flashloans') }}

View File

@ -1,52 +0,0 @@
{{ config(
materialized = 'view',
persist_docs ={ "relation": true,
"columns": true },
meta={
'database_tags':{
'table': {
'PROTOCOL': 'SONNE, AAVE, GRANARY, MOONWELL, MORPHO, SEAMLESS, 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,
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') }}

View File

@ -1,50 +0,0 @@
{{ config(
materialized = 'view',
persist_docs ={ "relation": true,
"columns": true },
meta={
'database_tags':{
'table': {
'PROTOCOL': 'SONNE, AAVE, GRANARY, MOONWELL, MORPHO, SEAMLESS, 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,
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') }}

View File

@ -1,49 +0,0 @@
{{ config(
materialized = 'view',
persist_docs ={ "relation": true,
"columns": true },
meta={
'database_tags':{
'table': {
'PROTOCOL': 'SONNE, AAVE, GRANARY, MOONWELL, MORPHO, SEAMLESS, 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,
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') }}

View File

@ -44,12 +44,12 @@ There is more information on how to use dbt docs in the last section of this doc
- [ez_bridge_activity](https://flipsidecrypto.github.io/base-models/#!/model/model.fsc_evm.defi__ez_bridge_activity)
- [ez_dex_swaps](https://flipsidecrypto.github.io/base-models/#!/model/model.fsc_evm.defi__ez_dex_swaps)
- [dim_dex_liquidity_pools](https://flipsidecrypto.github.io/base-models/#!/model/model.fsc_evm.defi__dim_dex_liquidity_pools)
- [ez_lending_borrows](https://flipsidecrypto.github.io/base-models/#!/model/model.base_models.defi__ez_lending_borrows)
- [ez_lending_deposits](https://flipsidecrypto.github.io/base-models/#!/model/model.base_models.defi__ez_lending_deposits)
- [ez_lending_flashloans](https://flipsidecrypto.github.io/base-models/#!/model/model.base_models.defi__ez_lending_flashloans)
- [ez_lending_liquidations](https://flipsidecrypto.github.io/base-models/#!/model/model.base_models.defi__ez_lending_liquidations)
- [ez_lending_repayments](https://flipsidecrypto.github.io/base-models/#!/model/model.base_models.defi__ez_lending_repayments)
- [ez_lending_withdraws](https://flipsidecrypto.github.io/base-models/#!/model/model.base_models.defi__ez_lending_withdraws)
- [ez_lending_borrows](https://flipsidecrypto.github.io/base-models/#!/model/model.fsc_evm.defi__ez_lending_borrows)
- [ez_lending_deposits](https://flipsidecrypto.github.io/base-models/#!/model/model.fsc_evm.defi__ez_lending_deposits)
- [ez_lending_flashloans](https://flipsidecrypto.github.io/base-models/#!/model/model.fsc_evm.defi__ez_lending_flashloans)
- [ez_lending_liquidations](https://flipsidecrypto.github.io/base-models/#!/model/model.fsc_evm.defi__ez_lending_liquidations)
- [ez_lending_repayments](https://flipsidecrypto.github.io/base-models/#!/model/model.fsc_evm.defi__ez_lending_repayments)
- [ez_lending_withdraws](https://flipsidecrypto.github.io/base-models/#!/model/model.fsc_evm.defi__ez_lending_withdraws)
### NFT Tables (base.nft)
- [ez_nft_transfers](https://flipsidecrypto.github.io/base-models/#!/model/model.fsc_evm.nft__ez_nft_transfers)

View File

@ -1,119 +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
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 = LOWER('0xa238dd80c259a72e81d7e4664a9801593f98d1c5') THEN 'Aave V3'
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 = '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 = LOWER('0xa238dd80c259a72e81d7e4664a9801593f98d1c5')
AND tx_succeeded
),
atoken_meta AS (
SELECT
atoken_address,
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') }}
)
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,
'base' 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,107 +0,0 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_number",
cluster_by = ['block_timestamp::DATE'],
tags = ['silver','defi','lending','curated']
) }}
WITH 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 = LOWER('0xa238dd80c259a72e81d7e4664a9801593f98d1c5') THEN 'Aave V3'
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 = '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 = LOWER('0xa238dd80c259a72e81d7e4664a9801593f98d1c5')
AND tx_succeeded
),
atoken_meta AS (
SELECT
atoken_address,
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') }}
)
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,
'base' 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,114 +0,0 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_number",
cluster_by = ['block_timestamp::DATE'],
tags = ['silver','defi','lending','curated']
) }}
WITH 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,
origin_to_address AS initiator_address,
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS aave_market,
utils.udf_hex_to_int(
segmented_data [1] :: STRING
) :: INTEGER AS flashloan_quantity,
utils.udf_hex_to_int(
segmented_data [3] :: STRING
) :: INTEGER AS premium_quantity,
utils.udf_hex_to_int(
topics [3] :: STRING
) :: INTEGER AS refferalCode,
COALESCE(
origin_to_address,
contract_address
) AS lending_pool_contract,
CASE
WHEN contract_address = LOWER('0xa238dd80c259a72e81d7e4664a9801593f98d1c5') THEN 'Aave V3'
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 = '0xefefaba5e921573100900a3ad9cf29f222d995fb3b6045797eaea7521bd8d6f0'
{% 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 = LOWER('0xa238dd80c259a72e81d7e4664a9801593f98d1c5')
AND tx_succeeded
),
atoken_meta AS (
SELECT
atoken_address,
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') }}
)
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,
'base' 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,112 +0,0 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_number",
cluster_by = ['block_timestamp::DATE'],
tags = ['silver','defi','lending','curated']
) }}
WITH 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 = LOWER('0xa238dd80c259a72e81d7e4664a9801593f98d1c5') THEN 'Aave V3'
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 = '0xe413a321e8681d831f4dbccbca790d2952b56f977908e45be37335533e005286'
{% 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 = LOWER('0xa238dd80c259a72e81d7e4664a9801593f98d1c5')
AND tx_succeeded
),
atoken_meta AS (
SELECT
atoken_address,
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') }}
)
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,
'base' 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,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 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 = LOWER('0xa238dd80c259a72e81d7e4664a9801593f98d1c5') THEN 'Aave V3'
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 = '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 = LOWER('0xa238dd80c259a72e81d7e4664a9801593f98d1c5')
AND tx_succeeded
),
atoken_meta AS (
SELECT
atoken_address,
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') }}
)
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,
'base' 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,144 +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 = '0xba9424d650a4f5c80a0da641254d1acce2a37057'
),
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,
segmented_data,
underlying_asset,
treasury_address,
aave_version_pool,
atoken_decimals,
atoken_name,
atoken_symbol,
_inserted_timestamp,
_log_id,
'Aave V3' AS protocol
FROM
a_token_step_1
)
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,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 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 = LOWER('0xa238dd80c259a72e81d7e4664a9801593f98d1c5') THEN 'Aave V3'
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 = '0x3115d1449a7b732c986cba18244e897a450f61e1bb8d589cd2e69e6c8924f9f7'
{% 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 = LOWER('0xa238dd80c259a72e81d7e4664a9801593f98d1c5')
AND tx_succeeded
),
atoken_meta AS (
SELECT
atoken_address,
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') }}
)
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,
'base' 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,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 = ['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,
'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

View File

@ -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

View File

@ -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 = ['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,
'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

View File

@ -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

View File

@ -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 = ['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,
'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

View File

@ -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

View File

@ -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 = ['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,
'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

View File

@ -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

View File

@ -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 = ['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,
'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

View File

@ -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

View File

@ -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 = ['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,
'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

View File

@ -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

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/base/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,
'base' 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,
'base' 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,
'base' 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,
'base' 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,
'base' 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

View File

@ -1,122 +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 granary LendingPool contracts
atoken_meta AS (
SELECT
atoken_address,
granary_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__granary_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 granary_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,
origin_from_address AS borrower_address,
COALESCE(
origin_to_address,
contract_address
) AS lending_pool_contract,
'Granary' AS granary_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 = '0xc6a898309e823ee50bac64e45ca8adba6690e99e7841c45d754e2a38e9019d9b'
{% 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
granary_version_pool
FROM
atoken_meta
)
AND tx_succeeded
)
SELECT
tx_hash,
block_number,
block_timestamp,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
granary_market,
atoken_meta.atoken_address AS granary_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,
granary_version AS platform,
atoken_meta.underlying_symbol AS symbol,
atoken_meta.underlying_decimals AS underlying_decimals,
'base' AS blockchain,
_log_id,
_inserted_timestamp
FROM
borrow
LEFT JOIN atoken_meta
ON borrow.granary_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__granary_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: granary_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,110 +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,
granary_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__granary_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 granary_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,
'Granary' AS granary_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 = '0xde6857219544bb5b7746f48ed30be6386fefc61b2f864cacf559893bf50fd951'
{% 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
granary_version_pool
FROM
atoken_meta
)
AND tx_succeeded
)
SELECT
tx_hash,
block_number,
block_timestamp,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
granary_market,
atoken_meta.atoken_address AS granary_token,
deposit_quantity AS amount_unadj,
deposit_quantity / pow(
10,
atoken_meta.underlying_decimals
) AS amount,
depositor_address,
lending_pool_contract,
granary_version AS platform,
atoken_meta.underlying_symbol AS symbol,
'base' AS blockchain,
_log_id,
_inserted_timestamp
FROM
deposits
LEFT JOIN atoken_meta
ON deposits.granary_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__granary_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: granary_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,117 +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,
granary_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__granary_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,
origin_to_address AS initiator_address,
CONCAT('0x', SUBSTR(topics [3] :: STRING, 27, 40)) AS granary_market,
utils.udf_hex_to_int(
segmented_data [0] :: STRING
) :: INTEGER AS flashloan_quantity,
utils.udf_hex_to_int(
segmented_data [1] :: STRING
) :: INTEGER AS premium_quantity,
utils.udf_hex_to_int(
topics [2] :: STRING
) :: INTEGER AS refferalCode,
COALESCE(
origin_to_address,
contract_address
) AS lending_pool_contract,
'Granary' AS granary_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 = '0x631042c832b07452973831137f2d73e395028b44b250dedc5abb0ee766e168ac'
{% 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
granary_version_pool
FROM
atoken_meta
)
AND tx_succeeded
)
SELECT
tx_hash,
block_number,
block_timestamp,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
granary_market,
atoken_meta.atoken_address AS granary_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,
granary_version AS platform,
atoken_meta.underlying_symbol AS symbol,
'base' AS blockchain,
_log_id,
_inserted_timestamp
FROM
flashloan
LEFT JOIN atoken_meta
ON flashloan.granary_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__granary_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: granary_MARKET
tests:
- not_null
- name: granary_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,115 +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,
granary_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__granary_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,
'Granary' AS granary_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 = '0xe413a321e8681d831f4dbccbca790d2952b56f977908e45be37335533e005286'
{% 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
granary_version_pool
FROM
atoken_meta
)
AND tx_succeeded
)
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_granary_token,
liquidated_amount AS amount_unadj,
liquidated_amount / pow(
10,
amc.atoken_decimals
) AS amount,
debt_asset,
amd.atoken_address AS debt_granary_token,
liquidator_address AS liquidator,
borrower_address AS borrower,
granary_version AS platform,
amc.underlying_symbol AS collateral_token_symbol,
amd.underlying_symbol AS debt_token_symbol,
'base' 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__granary_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_granary_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_granary_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,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,
granary_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__granary_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 granary_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,
'Granary' AS granary_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 = '0x4cdde6e09bb755c9a5589ebaec640bbfedff1362d4b255ebf8339782b9942faa'
{% 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
granary_version_pool
FROM
atoken_meta
)
AND tx_succeeded
)
SELECT
tx_hash,
block_number,
block_timestamp,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
granary_market,
atoken_meta.atoken_address AS granary_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,
granary_version AS platform,
atoken_meta.underlying_symbol AS symbol,
'base' AS blockchain,
_log_id,
_inserted_timestamp
FROM
repay
LEFT JOIN atoken_meta
ON repay.granary_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__granary_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: granary_MARKET
tests:
- not_null
- name: granary_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,144 +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 granary_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') }}
l
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 block_timestamp >= SYSDATE() - INTERVAL '7 days'
{% endif %}
),
a_token_step_1 AS (
SELECT
atoken_created_block,
a_token_address,
segmented_data,
underlying_asset,
granary_version_pool,
treasury_address,
atoken_decimals,
atoken_name,
atoken_symbol,
_inserted_timestamp,
_log_id
FROM
DECODE
WHERE
treasury_address = '0xd93e25a8b1d645b15f8c736e1419b4819ff9e6ef'
),
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,
segmented_data,
underlying_asset,
granary_version_pool,
treasury_address,
atoken_decimals,
atoken_name,
atoken_symbol,
_inserted_timestamp,
_log_id,
'Granary' AS protocol
FROM
a_token_step_1
)
SELECT
A.atoken_created_block,
granary_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__granary_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,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 atoken_meta AS (
SELECT
atoken_address,
granary_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__granary_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 granary_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,
'Granary' AS granary_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 = '0x3115d1449a7b732c986cba18244e897a450f61e1bb8d589cd2e69e6c8924f9f7'
{% 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
granary_version_pool
FROM
atoken_meta
)
AND tx_succeeded
)
SELECT
tx_hash,
block_number,
block_timestamp,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
granary_market,
atoken_meta.atoken_address AS granary_token,
withdraw_amount AS amount_unadj,
withdraw_amount / pow(
10,
atoken_meta.underlying_decimals
) AS amount,
depositor depositor_address,
granary_version AS platform,
atoken_meta.underlying_symbol AS symbol,
'base' AS blockchain,
_log_id,
_inserted_timestamp
FROM
withdraw
LEFT JOIN atoken_meta
ON withdraw.granary_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__granary_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: granary_MARKET
tests:
- not_null
- name: granary_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,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 contracts AS (
SELECT
*
FROM
{{ ref('silver__contracts') }}
),
log_pull AS (
SELECT
l.tx_hash,
l.block_number,
l.block_timestamp,
l.contract_address,
C.token_name,
C.token_symbol,
C.token_decimals,
l.modified_timestamp AS _inserted_timestamp,
CONCAT(
tx_hash :: STRING,
'-',
event_index :: STRING
) AS _log_id
FROM
{{ ref('core__fact_event_logs') }}
l
LEFT JOIN contracts C
ON C.contract_address = l.contract_address
WHERE
topics [0] :: STRING = '0x7ac369dbd14fa5ea3f473ed67cc9d598964a77501540ba6751eb0b3decf5870d'
AND C.token_name LIKE '%Moonwell%'
{% if is_incremental() %}
AND l.modified_timestamp >= (
SELECT
MAX(
_inserted_timestamp
) - INTERVAL '12 hours'
FROM
{{ this }}
)
AND l.contract_address NOT IN (
SELECT
token_address
FROM
{{ this }}
)
AND l.modified_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
),
traces_pull AS (
SELECT
t.from_address AS token_address,
t.to_address AS underlying_asset,
CASE
WHEN TYPE = 'STATICCALL'
AND trace_address = '0_2' THEN 1
ELSE NULL
END AS asset_identifier
FROM
{{ ref('core__fact_traces') }}
t
WHERE
tx_hash IN (
SELECT
tx_hash
FROM
log_pull
)
),
underlying_details AS (
SELECT
l.tx_hash,
l.block_number,
l.block_timestamp,
l.contract_address,
l.token_name,
l.token_symbol,
l.token_decimals,
t.underlying_asset,
l._inserted_timestamp,
l._log_id
FROM
log_pull l
LEFT JOIN traces_pull t
ON l.contract_address = t.token_address
WHERE
t.asset_identifier = 1 qualify(ROW_NUMBER() over(PARTITION BY l.contract_address
ORDER BY
block_timestamp ASC)) = 1
)
SELECT
l.tx_hash,
l.block_number,
l.block_timestamp,
l.contract_address AS token_address,
l.token_name,
l.token_symbol,
l.token_decimals,
l.underlying_asset AS underlying_asset_address,
C.token_name AS underlying_name,
C.token_symbol AS underlying_symbol,
C.token_decimals AS underlying_decimals,
l._inserted_timestamp,
l._log_id
FROM
underlying_details l
LEFT JOIN contracts C
ON C.contract_address = l.underlying_asset
WHERE
l.token_name IS 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']
) }}
-- pull all token addresses and corresponding name
WITH asset_details AS (
SELECT
token_address,
token_symbol,
token_name,
token_decimals,
underlying_asset_address,
underlying_name,
underlying_symbol,
underlying_decimals
FROM
{{ ref('silver__moonwell_asset_details') }}
),
moonwell_borrows AS (
SELECT
block_number,
block_timestamp,
tx_hash,
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(segmented_data [0] :: STRING, 25, 40)) AS borrower,
utils.udf_hex_to_int(
segmented_data [1] :: STRING
) :: INTEGER AS loan_amount_raw,
utils.udf_hex_to_int(
segmented_data [2] :: STRING
) :: INTEGER AS accountBorrows,
utils.udf_hex_to_int(
segmented_data [3] :: STRING
) :: INTEGER AS totalBorrows,
contract_address AS token,
'Moonwell' AS platform,
modified_timestamp AS _inserted_timestamp,
CONCAT(
tx_hash :: STRING,
'-',
event_index :: STRING
) AS _log_id
FROM
{{ ref('core__fact_event_logs') }}
WHERE
contract_address IN (
SELECT
token_address
FROM
asset_details
)
AND topics [0] :: STRING = '0x13ed6866d4e1ee6da46f845c46d7e54120883d75c5ea9a2dacc1c4ca8984ab80'
AND tx_succeeded
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(
_inserted_timestamp
) - INTERVAL '12 hours'
FROM
{{ this }}
)
{% endif %}
),
moonwell_combine AS (
SELECT
block_number,
block_timestamp,
tx_hash,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
borrower,
loan_amount_raw,
C.underlying_asset_address AS borrows_contract_address,
C.underlying_symbol AS borrows_contract_symbol,
token,
C.token_symbol,
C.underlying_decimals,
b.platform,
b._log_id,
b._inserted_timestamp
FROM
moonwell_borrows b
LEFT JOIN asset_details C
ON b.token = C.token_address
)
SELECT
block_number,
block_timestamp,
tx_hash,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
borrower,
borrows_contract_address,
borrows_contract_symbol,
token AS token_address,
token_symbol,
loan_amount_raw AS amount_unadj,
loan_amount_raw / pow(
10,
underlying_decimals
) AS amount,
platform,
_inserted_timestamp,
_log_id
FROM
moonwell_combine qualify(ROW_NUMBER() over(PARTITION BY _log_id
ORDER BY
_inserted_timestamp DESC)) = 1

View File

@ -1,42 +0,0 @@
version: 2
models:
- name: silver__moonwell_borrows
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
- name: BORROWER
tests:
- not_null
- name: BORROWS_CONTRACT_ADDRESS
tests:
- not_null
- name: BORROWS_CONTRACT_SYMBOL
tests:
- not_null
- name: TOKEN_ADDRESS
tests:
- not_null
- name: TOKEN_SYMBOL
tests:
- not_null
- name: AMOUNT
tests:
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- decimal
- float
- name: TX_HASH
tests:
- not_null
- name: EVENT_INDEX
tests:
- not_null

View File

@ -1,128 +0,0 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_number",
cluster_by = ['block_timestamp::DATE'],
tags = ['silver','defi','lending','curated']
) }}
-- pull all token addresses and corresponding name
WITH asset_details AS (
SELECT
token_address,
token_symbol,
token_name,
token_decimals,
underlying_asset_address,
underlying_name,
underlying_symbol,
underlying_decimals
FROM
{{ ref('silver__moonwell_asset_details') }}
),
moonwell_deposits AS (
SELECT
block_number,
block_timestamp,
tx_hash,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
contract_address AS token_address,
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
utils.udf_hex_to_int(
segmented_data [2] :: STRING
) :: INTEGER AS minttokens_raw,
utils.udf_hex_to_int(
segmented_data [1] :: STRING
) :: INTEGER AS mintAmount_raw,
CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS supplier,
'Moonwell' AS platform,
modified_timestamp AS _inserted_timestamp,
CONCAT(
tx_hash :: STRING,
'-',
event_index :: STRING
) AS _log_id
FROM
{{ ref('core__fact_event_logs') }}
WHERE
contract_address IN (
SELECT
token_address
FROM
asset_details
)
AND topics [0] :: STRING = '0x4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f'
AND tx_succeeded
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(
_inserted_timestamp
) - INTERVAL '12 hours'
FROM
{{ this }}
)
{% endif %}
),
moonwell_combine AS (
SELECT
block_number,
block_timestamp,
tx_hash,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
supplier,
minttokens_raw,
mintAmount_raw,
C.underlying_asset_address AS supplied_contract_addr,
C.underlying_symbol AS supplied_symbol,
C.token_address,
C.token_symbol,
C.token_decimals,
C.underlying_decimals,
b.platform,
b._log_id,
b._inserted_timestamp
FROM
moonwell_deposits b
LEFT JOIN asset_details C
ON b.token_address = C.token_address
)
SELECT
block_number,
block_timestamp,
tx_hash,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
token_address,
token_symbol,
minttokens_raw / pow(
10,
token_decimals
) AS issued_tokens,
mintAmount_raw AS amount_unadj,
mintAmount_raw / pow(
10,
underlying_decimals
) AS amount,
supplied_contract_addr,
supplied_symbol,
supplier,
platform,
_inserted_timestamp,
_log_id
FROM
moonwell_combine qualify(ROW_NUMBER() over(PARTITION BY _log_id
ORDER BY
_inserted_timestamp DESC)) = 1

View File

@ -1,50 +0,0 @@
version: 2
models:
- name: silver__moonwell_deposits
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: 3
- name: TOKEN_ADDRESS
tests:
- not_null
- name: TOKEN_SYMBOL
tests:
- not_null
- name: ISSUED_TOKENS
tests:
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- decimal
- float
- name: AMOUNT
tests:
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- decimal
- float
- name: SUPPLIED_CONTRACT_ADDR
tests:
- not_null
- name: SUPPLIED_SYMBOL
tests:
- not_null
- name: SUPPLIER
tests:
- not_null
- name: TX_HASH
tests:
- not_null
- name: EVENT_INDEX
tests:
- not_null

View File

@ -1,120 +0,0 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_number",
cluster_by = ['block_timestamp::DATE'],
tags = ['silver','defi','lending','curated']
) }}
-- pull all token addresses and corresponding name
-- add the collateral liquidated here
WITH asset_details AS (
SELECT
token_address,
token_symbol,
token_name,
token_decimals,
underlying_asset_address,
underlying_name,
underlying_symbol,
underlying_decimals
FROM
{{ ref('silver__moonwell_asset_details') }}
),
moonwell_liquidations AS (
SELECT
block_number,
block_timestamp,
tx_hash,
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(segmented_data [1] :: STRING, 25, 40)) AS borrower,
contract_address AS token,
CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS liquidator,
utils.udf_hex_to_int(
segmented_data [4] :: STRING
) :: INTEGER AS seizeTokens_raw,
utils.udf_hex_to_int(
segmented_data [2] :: STRING
) :: INTEGER AS repayAmount_raw,
CONCAT('0x', SUBSTR(segmented_data [3] :: STRING, 25, 40)) AS tokenCollateral,
'Moonwell' AS platform,
modified_timestamp AS _inserted_timestamp,
CONCAT(
tx_hash :: STRING,
'-',
event_index :: STRING
) AS _log_id
FROM
{{ ref('core__fact_event_logs') }}
WHERE
contract_address IN (
SELECT
token_address
FROM
asset_details
)
AND topics [0] :: STRING = '0x298637f684da70674f26509b10f07ec2fbc77a335ab1e7d6215a4b2484d8bb52'
AND tx_succeeded
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(
_inserted_timestamp
) - INTERVAL '12 hours'
FROM
{{ this }}
)
{% endif %}
),
liquidation_union AS (
SELECT
block_number,
block_timestamp,
tx_hash,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
borrower,
token,
asd1.token_symbol AS token_symbol,
liquidator,
seizeTokens_raw / pow(
10,
asd2.token_decimals
) AS tokens_seized,
tokenCollateral AS protocol_market,
asd2.token_symbol AS collateral_token_symbol,
asd2.underlying_asset_address AS collateral_token,
asd2.underlying_symbol AS collateral_symbol,
repayAmount_raw AS amount_unadj,
repayAmount_raw / pow(
10,
asd1.underlying_decimals
) AS amount,
asd1.underlying_decimals,
asd1.underlying_asset_address AS liquidation_contract_address,
asd1.underlying_symbol AS liquidation_contract_symbol,
l.platform,
l._inserted_timestamp,
l._log_id
FROM
moonwell_liquidations l
LEFT JOIN asset_details asd1
ON l.token = asd1.token_address
LEFT JOIN asset_details asd2
ON l.tokenCollateral = asd2.token_address
)
SELECT
*
FROM
liquidation_union 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__moonwell_liquidations
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
- name: BORROWER
tests:
- not_null
- name: TOKEN
tests:
- not_null
- name: TOKEN_SYMBOL
tests:
- not_null
- name: LIQUIDATOR
tests:
- not_null
- name: TOKENS_SEIZED
tests:
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- decimal
- float
- name: AMOUNT
tests:
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- decimal
- float
- name: LIQUIDATION_CONTRACT_ADDRESS
tests:
- not_null
- name: LIQUIDATION_CONTRACT_SYMBOL
tests:
- not_null
- name: TX_HASH
tests:
- not_null
# - name: COLLATERAL_TOKEN
# tests:
# - not_null
# - name: COLLATERAL_SYMBOL
# tests:
# - not_null
- name: EVENT_INDEX
tests:
- not_null

View File

@ -1,122 +0,0 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_number",
cluster_by = ['block_timestamp::DATE'],
tags = ['silver','defi','lending','curated']
) }}
-- pull all token addresses and corresponding name
WITH asset_details AS (
SELECT
token_address,
token_symbol,
token_name,
token_decimals,
underlying_asset_address,
underlying_name,
underlying_symbol,
underlying_decimals
FROM
{{ ref('silver__moonwell_asset_details') }}
),
moonwell_repayments AS (
SELECT
block_number,
block_timestamp,
tx_hash,
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(segmented_data [1] :: STRING, 25, 40)) AS borrower,
contract_address AS token,
CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS payer,
utils.udf_hex_to_int(
segmented_data [2] :: STRING
) :: INTEGER AS repayed_amount_raw,
'Moonwell' AS platform,
modified_timestamp AS _inserted_timestamp,
CONCAT(
tx_hash :: STRING,
'-',
event_index :: STRING
) AS _log_id
FROM
{{ ref('core__fact_event_logs') }}
WHERE
contract_address IN (
SELECT
token_address
FROM
asset_details
)
AND topics [0] :: STRING = '0x1a2a22cb034d26d1854bdc6666a5b91fe25efbbb5dcad3b0355478d6f5c362a1'
AND tx_succeeded
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(
_inserted_timestamp
) - INTERVAL '12 hours'
FROM
{{ this }}
)
{% endif %}
),
moonwell_combine AS (
SELECT
block_number,
block_timestamp,
tx_hash,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
borrower,
token,
C.token_symbol,
payer,
repayed_amount_raw,
C.underlying_asset_address AS repay_contract_address,
C.underlying_symbol AS repay_contract_symbol,
C.underlying_decimals,
b.platform,
b._log_id,
b._inserted_timestamp
FROM
moonwell_repayments b
LEFT JOIN asset_details C
ON b.token = C.token_address
)
SELECT
block_number,
block_timestamp,
tx_hash,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
borrower,
token AS token_address,
token_symbol,
payer,
repay_contract_address,
repay_contract_symbol,
repayed_amount_raw AS amount_unadj,
repayed_amount_raw / pow(
10,
underlying_decimals
) AS amount,
platform,
_inserted_timestamp,
_log_id
FROM
moonwell_combine qualify(ROW_NUMBER() over(PARTITION BY _log_id
ORDER BY
_inserted_timestamp DESC)) = 1

View File

@ -1,44 +0,0 @@
version: 2
models:
- name: silver__moonwell_repayments
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
- name: BORROWER
tests:
- not_null
- name: TOKEN_ADDRESS
tests:
- not_null
- name: TOKEN_SYMBOL
tests:
- not_null
- name: PAYER
tests:
- not_null
- name: REPAY_CONTRACT_ADDRESS
tests:
- not_null
- name: REPAY_CONTRACT_SYMBOL
tests:
- not_null
- name: AMOUNT
tests:
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- decimal
- float
- name: TX_HASH
tests:
- not_null
- name: EVENT_INDEX
tests:
- not_null

View File

@ -1,127 +0,0 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_number",
cluster_by = ['block_timestamp::DATE'],
tags = ['silver','defi','lending','curated']
) }}
-- pull all token addresses and corresponding name
WITH asset_details AS (
SELECT
token_address,
token_symbol,
token_name,
token_decimals,
underlying_asset_address,
underlying_name,
underlying_symbol,
underlying_decimals
FROM
{{ ref('silver__moonwell_asset_details') }}
),
moonwell_redemptions AS (
SELECT
block_number,
block_timestamp,
tx_hash,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
contract_address AS token,
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
utils.udf_hex_to_int(
segmented_data [1] :: STRING
) :: INTEGER AS received_amount_raw,
utils.udf_hex_to_int(
segmented_data [3] :: STRING
) :: INTEGER AS redeemed_token_raw,
CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS redeemer,
'Moonwell' AS platform,
modified_timestamp AS _inserted_timestamp,
CONCAT(
tx_hash :: STRING,
'-',
event_index :: STRING
) AS _log_id
FROM
{{ ref('core__fact_event_logs') }}
WHERE
contract_address IN (
SELECT
token_address
FROM
asset_details
)
AND topics [0] :: STRING = '0xe5b754fb1abb7f01b499791d0b820ae3b6af3424ac1c59768edb53f4ec31a929'
AND tx_succeeded
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp) - INTERVAL '12 hours'
FROM
{{ this }}
)
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
),
moonwell_combine AS (
SELECT
block_number,
block_timestamp,
tx_hash,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
token,
redeemer,
received_amount_raw,
redeemed_token_raw,
C.underlying_asset_address AS received_contract_address,
C.underlying_symbol AS received_contract_symbol,
C.token_symbol,
C.token_decimals,
C.underlying_decimals,
b.platform,
b._log_id,
b._inserted_timestamp
FROM
moonwell_redemptions b
LEFT JOIN asset_details C
ON b.token = C.token_address
)
SELECT
block_number,
block_timestamp,
tx_hash,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
token AS token_address,
token_symbol,
received_amount_raw AS amount_unadj,
received_amount_raw / pow(
10,
underlying_decimals
) AS amount,
received_contract_address,
received_contract_symbol,
redeemed_token_raw / pow(
10,
token_decimals
) AS redeemed_token,
redeemer,
platform,
_inserted_timestamp,
_log_id
FROM
moonwell_combine ee 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__moonwell_withdraws
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
- name: TOKEN_ADDRESS
tests:
- not_null
- name: TOKEN_SYMBOL
tests:
- not_null
- name: AMOUNT
tests:
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- decimal
- float
- name: RECEIVED_CONTRACT_ADDRESS
tests:
- not_null
- name: RECEIVED_CONTRACT_SYMBOL
tests:
- not_null
- name: REDEEMED_TOKEN
tests:
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- decimal
- float
- name: REDEEMER
tests:
- not_null
- name: TX_HASH
tests:
- not_null
- name: EVENT_INDEX
tests:
- not_null

View File

@ -1,122 +0,0 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_number",
cluster_by = ['block_timestamp::DATE'],
tags = ['silver','defi','lending','curated']
) }}
WITH traces AS (
SELECT
block_number,
tx_hash,
block_timestamp,
from_address,
to_address,
LEFT(
input,
10
) AS function_sig,
regexp_substr_all(SUBSTR(input, 11), '.{64}') AS segmented_input,
CONCAT('0x', SUBSTR(segmented_input [0] :: STRING, 25)) AS loan_token,
CONCAT('0x', SUBSTR(segmented_input [1] :: STRING, 25)) AS collateral_token,
CONCAT('0x', SUBSTR(segmented_input [2] :: STRING, 25)) AS oracle_address,
CONCAT('0x', SUBSTR(segmented_input [3] :: STRING, 25)) AS irm_address,
TRY_TO_NUMBER(
utils.udf_hex_to_int(
segmented_input [4] :: STRING
)
) AS lltv,
TRY_TO_NUMBER(
utils.udf_hex_to_int(
segmented_input [5] :: STRING
)
) AS amount,
TRY_TO_NUMBER(
utils.udf_hex_to_int(
segmented_input [6] :: STRING
)
) AS shares,
CONCAT('0x', SUBSTR(segmented_input [7] :: STRING, 25)) AS on_behalf_address,
CONCAT('0x', SUBSTR(segmented_input [8] :: STRING, 25)) AS receiver_address,
concat_ws(
'-',
block_number,
tx_position,
CONCAT(
TYPE,
'_',
trace_address
)
) AS _call_id,
modified_timestamp AS _inserted_timestamp,
origin_from_address,
origin_to_address,
origin_function_signature
FROM
{{ ref('core__fact_traces') }}
t
WHERE
to_address = '0xbbbbbbbbbb9cc5e90e3b3af64bdaf62c37eeffcb' --Morpho Blue
AND function_sig = '0x50d8cd4b'
AND trace_succeeded
AND tx_succeeded
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp) - INTERVAL '12 hours'
FROM
{{ this }}
)
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
),
tx_join AS (
SELECT
block_number,
tx_hash,
block_timestamp,
origin_from_address,
origin_to_address,
origin_function_signature,
from_address,
to_address AS contract_address,
origin_from_address AS borrower_address,
loan_token,
collateral_token,
amount,
on_behalf_address,
receiver_address,
_call_id,
_inserted_timestamp
FROM
traces
)
SELECT
tx_hash,
block_number,
block_timestamp,
origin_from_address,
origin_to_address,
origin_function_signature,
t.contract_address,
loan_token AS market,
amount AS amount_unadj,
amount / pow(
10,
C.token_decimals
) AS amount,
C.token_symbol,
C.token_decimals,
borrower_address,
t.contract_address AS lending_pool_contract,
'Morpho Blue' AS platform,
'base' AS blockchain,
_call_id AS _id,
t._inserted_timestamp
FROM
tx_join t
LEFT JOIN {{ ref('silver__contracts') }} C
ON C.contract_address = t.loan_token

View File

@ -1,41 +0,0 @@
version: 2
models:
- name: silver__morpho_borrows
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- _ID
columns:
- name: TX_HASH
tests:
- not_null
- name: BLOCK_NUMBER
tests:
- not_null
- name: BLOCK_TIMESTAMP
tests:
- not_null
- name: MARKET
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: BORROWER_ADDRESS
tests:
- not_null
- name: LENDING_POOL_CONTRACT
tests:
- not_null
- name: PLATFORM
tests:
- not_null
- name: BLOCKCHAIN
tests:
- not_null

View File

@ -1,122 +0,0 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_number",
cluster_by = ['block_timestamp::DATE'],
tags = ['silver','defi','lending','curated']
) }}
WITH traces AS (
SELECT
block_number,
tx_hash,
block_timestamp,
from_address,
to_address,
LEFT(
input,
10
) AS function_sig,
regexp_substr_all(SUBSTR(input, 11), '.{64}') AS segmented_input,
CONCAT('0x', SUBSTR(segmented_input [0] :: STRING, 25)) AS loan_token,
CONCAT('0x', SUBSTR(segmented_input [1] :: STRING, 25)) AS collateral_token,
CONCAT('0x', SUBSTR(segmented_input [2] :: STRING, 25)) AS oracle_address,
CONCAT('0x', SUBSTR(segmented_input [3] :: STRING, 25)) AS irm_address,
TRY_TO_NUMBER(
utils.udf_hex_to_int(
segmented_input [4] :: STRING
)
) AS lltv,
TRY_TO_NUMBER(
utils.udf_hex_to_int(
segmented_input [5] :: STRING
)
) AS amount,
TRY_TO_NUMBER(
utils.udf_hex_to_int(
segmented_input [6] :: STRING
)
) AS shares,
CONCAT('0x', SUBSTR(segmented_input [7] :: STRING, 25)) AS on_behalf_address,
CONCAT('0x', SUBSTR(segmented_input [8] :: STRING, 25)) AS receiver_address,
concat_ws(
'-',
block_number,
tx_position,
CONCAT(
TYPE,
'_',
trace_address
)
) AS _call_id,
modified_timestamp AS _inserted_timestamp,
origin_from_address,
origin_to_address,
origin_function_signature
FROM
{{ ref('core__fact_traces') }}
t
WHERE
to_address = '0xbbbbbbbbbb9cc5e90e3b3af64bdaf62c37eeffcb' --Morpho Blue
AND function_sig = '0xa99aad89'
AND trace_succeeded
AND tx_succeeded
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp) - INTERVAL '12 hours'
FROM
{{ this }}
)
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
),
tx_join AS (
SELECT
block_number,
tx_hash,
block_timestamp,
origin_from_address,
origin_to_address,
origin_function_signature,
from_address,
to_address AS contract_address,
origin_from_address AS depositor_address,
loan_token,
collateral_token,
amount,
on_behalf_address,
receiver_address,
_call_id,
_inserted_timestamp
FROM
traces
)
SELECT
tx_hash,
block_number,
block_timestamp,
origin_from_address,
origin_to_address,
origin_function_signature,
t.contract_address,
loan_token AS market,
amount AS amount_unadj,
amount / pow(
10,
C.token_decimals
) AS amount,
C.token_symbol,
C.token_decimals,
depositor_address,
t.contract_address AS lending_pool_contract,
'Morpho Blue' AS platform,
'base' AS blockchain,
_call_id AS _id,
t._inserted_timestamp
FROM
tx_join t
LEFT JOIN {{ ref('silver__contracts') }} C
ON C.contract_address = t.loan_token

View File

@ -1,41 +0,0 @@
version: 2
models:
- name: silver__morpho_deposits
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- _ID
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: MARKET
tests:
- not_null
- name: DEPOSITOR_ADDRESS
tests:
- not_null
- name: LENDING_POOL_CONTRACT
tests:
- not_null
- name: PLATFORM
tests:
- not_null

View File

@ -1,75 +0,0 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_number",
cluster_by = ['block_timestamp::DATE'],
tags = ['silver','defi','lending','curated']
) }}
WITH flashloan AS(
SELECT
l.tx_hash,
l.block_number,
l.block_timestamp,
l.event_index,
l.origin_from_address,
l.origin_to_address,
l.origin_function_signature,
l.contract_address,
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS caller,
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS token,
TRY_TO_NUMBER(
utils.udf_hex_to_int(
segmented_data [0] :: STRING
)
) AS flashloan_quantity,
CONCAT(
tx_hash :: STRING,
'-',
event_index :: STRING
) AS _log_id,
modified_timestamp AS _inserted_timestamp
FROM
{{ ref('core__fact_event_logs') }}
l
WHERE
topics [0] :: STRING = '0xc76f1b4fe4396ac07a9fa55a415d4ca430e72651d37d3401f3bed7cb13fc4f12'
AND contract_address = '0xbbbbbbbbbb9cc5e90e3b3af64bdaf62c37eeffcb'
{% 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,
f.contract_address,
caller AS initiator_address,
token AS market,
C.token_symbol,
flashloan_quantity AS flashloan_amount_unadj,
flashloan_quantity / pow(
10,
C.token_decimals
) AS flashloan_amount,
'Morpho Blue' AS platform,
'base' AS blockchain,
f._log_id,
f._inserted_timestamp
FROM
flashloan f
LEFT JOIN {{ ref('silver__contracts') }} C
ON f.token = C.contract_address

View File

@ -1,41 +0,0 @@
version: 2
models:
- name: silver__morpho_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
- name: EVENT_INDEX
tests:
- not_null
- name: TX_HASH
tests:
- not_null
- name: MARKET
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: INITIATOR_ADDRESS
tests:
- not_null
- name: PLATFORM
tests:
- not_null
- name: BLOCKCHAIN
tests:
- not_null

View File

@ -1,158 +0,0 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_number",
cluster_by = ['block_timestamp::DATE'],
tags = ['silver','defi','lending','curated']
) }}
WITH traces AS (
SELECT
block_number,
tx_hash,
block_timestamp,
from_address,
to_address,
LEFT(
input,
10
) AS function_sig,
len(input) AS segmented_input_len,
regexp_substr_all(SUBSTR(input, 11), '.{64}') AS segmented_input,
CONCAT('0x', SUBSTR(segmented_input [0] :: STRING, 25)) AS loan_token,
CONCAT('0x', SUBSTR(segmented_input [1] :: STRING, 25)) AS collateral_token,
CONCAT('0x', SUBSTR(segmented_input [2] :: STRING, 25)) AS oracle_address,
CONCAT('0x', SUBSTR(segmented_input [3] :: STRING, 25)) AS irm_address,
CONCAT('0x', SUBSTR(segmented_input [5] :: STRING, 25)) AS borrower,
ROW_NUMBER() over (
PARTITION BY tx_hash
ORDER BY
trace_index
) AS trace_index_order,
concat_ws(
'-',
block_number,
tx_position,
CONCAT(
TYPE,
'_',
trace_address
)
) AS _call_id,
modified_timestamp AS _inserted_timestamp
FROM
{{ ref('core__fact_traces') }}
WHERE
to_address = '0xbbbbbbbbbb9cc5e90e3b3af64bdaf62c37eeffcb' --Morpho Blue
AND function_sig = '0xd8eabcb8'
AND trace_succeeded
AND tx_succeeded
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp) - INTERVAL '12 hours'
FROM
{{ this }}
)
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
),
logs AS(
SELECT
l.tx_hash,
l.block_number,
l.block_timestamp,
l.event_index,
ROW_NUMBER() over (
PARTITION BY l.tx_hash
ORDER BY
l.event_index
) AS event_index_order,
l.origin_from_address,
l.origin_to_address,
l.origin_function_signature,
l.contract_address,
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS caller,
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS borrower,
utils.udf_hex_to_int(
segmented_data [0] :: STRING
) :: INTEGER AS repay_assets,
utils.udf_hex_to_int(
segmented_data [2] :: STRING
) :: INTEGER AS seized_assets,
COALESCE(
l.origin_to_address,
l.contract_address
) AS lending_pool_contract,
CONCAT(
tx_hash :: STRING,
'-',
event_index :: STRING
) AS _log_id,
modified_timestamp AS _inserted_timestamp
FROM
{{ ref('core__fact_event_logs') }}
l
WHERE
topics [0] :: STRING = '0xa4946ede45d0c6f06a0f5ce92c9ad3b4751452d2fe0e25010783bcab57a67e41'
AND l.contract_address = '0xbbbbbbbbbb9cc5e90e3b3af64bdaf62c37eeffcb'
AND tx_hash IN (
SELECT
tx_hash
FROM
traces
)
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp) - INTERVAL '12 hours'
FROM
{{ this }}
)
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
)
SELECT
l.tx_hash,
l.block_number,
l.block_timestamp,
l.event_index,
l.origin_from_address,
l.origin_to_address,
l.origin_function_signature,
l.contract_address,
l.caller AS liquidator,
l.borrower,
t.loan_token AS debt_asset,
c0.token_symbol AS debt_asset_symbol,
l.repay_assets AS repayed_amount_unadj,
l.repay_assets / pow(
10,
c0.token_decimals
) AS repayed_amount,
t.collateral_token AS collateral_asset,
c1.token_symbol AS collateral_asset_symbol,
l.seized_assets AS amount_unadj,
l.seized_assets / pow(
10,
c1.token_decimals
) AS amount,
'Morpho Blue' AS platform,
'base' AS blockchain,
t._call_id AS _id,
t._inserted_timestamp
FROM
traces t
INNER JOIN logs l
ON l.tx_hash = t.tx_hash
AND l.event_index_order = t.trace_index_order
LEFT JOIN {{ ref('silver__contracts') }}
c0
ON c0.contract_address = t.loan_token
LEFT JOIN {{ ref('silver__contracts') }}
c1
ON c1.contract_address = t.collateral_token

View File

@ -1,54 +0,0 @@
version: 2
models:
- name: silver__morpho_liquidations
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- _ID
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: REPAYED_AMOUNT_UNADJ
tests:
- not_null
- name: REPAYED_AMOUNT
tests:
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- decimal
- float
- 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: LIQUIDATOR
tests:
- not_null
- name: BORROWER
tests:
- not_null
- name: PLATFORM
tests:
- not_null

View File

@ -1,122 +0,0 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_number",
cluster_by = ['block_timestamp::DATE'],
tags = ['silver','defi','lending','curated']
) }}
WITH traces AS (
SELECT
block_number,
tx_hash,
block_timestamp,
from_address,
to_address,
LEFT(
input,
10
) AS function_sig,
regexp_substr_all(SUBSTR(input, 11), '.{64}') AS segmented_input,
CONCAT('0x', SUBSTR(segmented_input [0] :: STRING, 25)) AS loan_token,
CONCAT('0x', SUBSTR(segmented_input [1] :: STRING, 25)) AS collateral_token,
CONCAT('0x', SUBSTR(segmented_input [2] :: STRING, 25)) AS oracle_address,
CONCAT('0x', SUBSTR(segmented_input [3] :: STRING, 25)) AS irm_address,
TRY_TO_NUMBER(
utils.udf_hex_to_int(
segmented_input [4] :: STRING
)
) AS lltv,
TRY_TO_NUMBER(
utils.udf_hex_to_int(
segmented_input [5] :: STRING
)
) AS amount,
TRY_TO_NUMBER(
utils.udf_hex_to_int(
segmented_input [6] :: STRING
)
) AS shares,
CONCAT('0x', SUBSTR(segmented_input [7] :: STRING, 25)) AS on_behalf_address,
CONCAT('0x', SUBSTR(segmented_input [8] :: STRING, 25)) AS receiver_address,
concat_ws(
'-',
block_number,
tx_position,
CONCAT(
TYPE,
'_',
trace_address
)
) AS _call_id,
modified_timestamp AS _inserted_timestamp,
origin_from_address,
origin_to_address,
origin_function_signature
FROM
{{ ref('core__fact_traces') }}
WHERE
to_address = '0xbbbbbbbbbb9cc5e90e3b3af64bdaf62c37eeffcb' --Morpho Blue
AND function_sig = '0x20b76e81'
AND trace_succeeded
AND tx_succeeded
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp) - INTERVAL '12 hours'
FROM
{{ this }}
)
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
),
tx_join AS (
SELECT
block_number,
tx_hash,
block_timestamp,
origin_from_address,
origin_to_address,
origin_function_signature,
from_address,
to_address AS contract_address,
origin_from_address AS borrower_address,
loan_token,
collateral_token,
amount,
on_behalf_address,
receiver_address,
_call_id,
_inserted_timestamp
FROM
traces
)
SELECT
tx_hash,
block_number,
block_timestamp,
origin_from_address,
origin_to_address,
origin_function_signature,
t.contract_address,
loan_token AS market,
amount AS amount_unadj,
amount / pow(
10,
C.token_decimals
) AS amount,
on_behalf_address AS payer,
borrower_address,
t.contract_address AS lending_pool_contract,
C.token_symbol,
C.token_decimals,
'Morpho Blue' AS platform,
'base' AS blockchain,
t._call_id AS _id,
t._inserted_timestamp
FROM
tx_join t
LEFT JOIN {{ ref('silver__contracts') }} C
ON C.contract_address = t.loan_token

View File

@ -1,41 +0,0 @@
version: 2
models:
- name: silver__morpho_repayments
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- _ID
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: MARKET
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: PAYER
tests:
- not_null
- name: BORROWER_ADDRESS
tests:
- not_null
- name: PLATFORM
tests:
- not_null

View File

@ -1,121 +0,0 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_number",
cluster_by = ['block_timestamp::DATE'],
tags = ['silver','defi','lending','curated']
) }}
WITH traces AS (
SELECT
block_number,
tx_hash,
block_timestamp,
from_address,
to_address,
LEFT(
input,
10
) AS function_sig,
regexp_substr_all(SUBSTR(input, 11), '.{64}') AS segmented_input,
CONCAT('0x', SUBSTR(segmented_input [0] :: STRING, 25)) AS loan_token,
CONCAT('0x', SUBSTR(segmented_input [1] :: STRING, 25)) AS collateral_token,
CONCAT('0x', SUBSTR(segmented_input [2] :: STRING, 25)) AS oracle_address,
CONCAT('0x', SUBSTR(segmented_input [3] :: STRING, 25)) AS irm_address,
TRY_TO_NUMBER(
utils.udf_hex_to_int(
segmented_input [4] :: STRING
)
) AS lltv,
TRY_TO_NUMBER(
utils.udf_hex_to_int(
segmented_input [5] :: STRING
)
) AS amount,
TRY_TO_NUMBER(
utils.udf_hex_to_int(
segmented_input [6] :: STRING
)
) AS shares,
CONCAT('0x', SUBSTR(segmented_input [7] :: STRING, 25)) AS on_behalf_address,
CONCAT('0x', SUBSTR(segmented_input [8] :: STRING, 25)) AS receiver_address,
concat_ws(
'-',
block_number,
tx_position,
CONCAT(
TYPE,
'_',
trace_address
)
) AS _call_id,
modified_timestamp AS _inserted_timestamp,
origin_from_address,
origin_to_address,
origin_function_signature
FROM
{{ ref('core__fact_traces') }}
WHERE
to_address = '0xbbbbbbbbbb9cc5e90e3b3af64bdaf62c37eeffcb' --Morpho Blue
AND function_sig = '0x5c2bea49'
AND trace_succeeded
AND tx_succeeded
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp) - INTERVAL '12 hours'
FROM
{{ this }}
)
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
),
tx_join AS (
SELECT
block_number,
tx_hash,
block_timestamp,
origin_from_address,
origin_to_address,
origin_function_signature,
from_address,
to_address AS contract_address,
origin_from_address AS depositor_address,
loan_token,
collateral_token,
amount,
on_behalf_address,
receiver_address,
_call_id,
_inserted_timestamp
FROM
traces
)
SELECT
tx_hash,
block_number,
block_timestamp,
origin_from_address,
origin_to_address,
origin_function_signature,
t.contract_address,
loan_token AS market,
amount AS amount_unadj,
amount / pow(
10,
C.token_decimals
) AS amount,
depositor_address,
t.contract_address AS lending_pool_contract,
C.token_symbol,
C.token_decimals,
'Morpho Blue' AS platform,
'base' AS blockchain,
t._call_id AS _id,
t._inserted_timestamp
FROM
tx_join t
LEFT JOIN {{ ref('silver__contracts') }} C
ON C.contract_address = t.loan_token

View File

@ -1,38 +0,0 @@
version: 2
models:
- name: silver__morpho_withdraws
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- _ID
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: MARKET
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: DEPOSITOR_ADDRESS
tests:
- not_null
- name: PLATFORM
tests:
- not_null

View File

@ -1,122 +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 seamless LendingPool contracts
atoken_meta AS (
SELECT
atoken_address,
seamless_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__seamless_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 seamless_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,
origin_from_address AS borrower_address,
COALESCE(
origin_to_address,
contract_address
) AS lending_pool_contract,
'Seamless' AS seamless_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 = '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
seamless_version_pool
FROM
atoken_meta
)
AND tx_succeeded
)
SELECT
tx_hash,
block_number,
block_timestamp,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
seamless_market,
atoken_meta.atoken_address AS seamless_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,
seamless_version AS platform,
atoken_meta.underlying_symbol AS symbol,
atoken_meta.underlying_decimals AS underlying_decimals,
'base' AS blockchain,
_log_id,
_inserted_timestamp
FROM
borrow
LEFT JOIN atoken_meta
ON borrow.seamless_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__seamless_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: seamless_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,110 +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,
seamless_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__seamless_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 seamless_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,
'Seamless' AS seamless_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 = '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
seamless_version_pool
FROM
atoken_meta
)
AND tx_succeeded
)
SELECT
tx_hash,
block_number,
block_timestamp,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
seamless_market,
atoken_meta.atoken_address AS seamless_token,
deposit_quantity AS amount_unadj,
deposit_quantity / pow(
10,
atoken_meta.underlying_decimals
) AS amount,
depositor_address,
lending_pool_contract,
seamless_version AS platform,
atoken_meta.underlying_symbol AS symbol,
'base' AS blockchain,
_log_id,
_inserted_timestamp
FROM
deposits
LEFT JOIN atoken_meta
ON deposits.seamless_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__seamless_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: seamless_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,117 +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,
seamless_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__seamless_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,
origin_to_address AS initiator_address,
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS seamless_market,
utils.udf_hex_to_int(
segmented_data [1] :: STRING
) :: INTEGER AS flashloan_quantity,
utils.udf_hex_to_int(
segmented_data [3] :: STRING
) :: INTEGER AS premium_quantity,
utils.udf_hex_to_int(
topics [3] :: STRING
) :: INTEGER AS refferalCode,
COALESCE(
origin_to_address,
contract_address
) AS lending_pool_contract,
'Seamless' AS seamless_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 = '0xefefaba5e921573100900a3ad9cf29f222d995fb3b6045797eaea7521bd8d6f0'
{% 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
seamless_version_pool
FROM
atoken_meta
)
AND tx_succeeded
)
SELECT
tx_hash,
block_number,
block_timestamp,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
seamless_market,
atoken_meta.atoken_address AS seamless_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,
seamless_version AS platform,
atoken_meta.underlying_symbol AS symbol,
'base' AS blockchain,
_log_id,
_inserted_timestamp
FROM
flashloan
LEFT JOIN atoken_meta
ON flashloan.seamless_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__seamless_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: seamless_MARKET
tests:
- not_null
- name: seamless_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,115 +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,
seamless_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__seamless_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,
'Seamless' AS seamless_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 = '0xe413a321e8681d831f4dbccbca790d2952b56f977908e45be37335533e005286'
{% 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
seamless_version_pool
FROM
atoken_meta
)
AND tx_succeeded
)
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_seamless_token,
liquidated_amount AS amount_unadj,
liquidated_amount / pow(
10,
amc.atoken_decimals
) AS amount,
debt_asset,
amd.atoken_address AS debt_seamless_token,
liquidator_address AS liquidator,
borrower_address AS borrower,
seamless_version AS platform,
amc.underlying_symbol AS collateral_token_symbol,
amd.underlying_symbol AS debt_token_symbol,
'base' 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__seamless_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_seamless_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_seamless_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,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,
seamless_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__seamless_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 seamless_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,
'Seamless' AS seamless_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 = '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
seamless_version_pool
FROM
atoken_meta
)
AND tx_succeeded
)
SELECT
tx_hash,
block_number,
block_timestamp,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
seamless_market,
atoken_meta.atoken_address AS seamless_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,
seamless_version AS platform,
atoken_meta.underlying_symbol AS symbol,
'base' AS blockchain,
_log_id,
_inserted_timestamp
FROM
repay
LEFT JOIN atoken_meta
ON repay.seamless_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__seamless_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: seamless_MARKET
tests:
- not_null
- name: seamless_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,144 +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 seamless_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') }}
l
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,
seamless_version_pool,
treasury_address,
atoken_decimals,
atoken_name,
atoken_symbol,
_inserted_timestamp,
_log_id
FROM
DECODE
WHERE
treasury_address = '0x982f3a0e3183896f9970b8a9ea6b69cd53af1089'
),
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,
segmented_data,
underlying_asset,
seamless_version_pool,
treasury_address,
atoken_decimals,
atoken_name,
atoken_symbol,
_inserted_timestamp,
_log_id,
'Seamless' AS protocol
FROM
a_token_step_1
)
SELECT
A.atoken_created_block,
seamless_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__seamless_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,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 atoken_meta AS (
SELECT
atoken_address,
seamless_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__seamless_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 seamless_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,
'Seamless' AS seamless_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 = '0x3115d1449a7b732c986cba18244e897a450f61e1bb8d589cd2e69e6c8924f9f7'
{% 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
seamless_version_pool
FROM
atoken_meta
)
AND tx_succeeded
)
SELECT
tx_hash,
block_number,
block_timestamp,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
seamless_market,
atoken_meta.atoken_address AS seamless_token,
withdraw_amount AS amount_unadj,
withdraw_amount / pow(
10,
atoken_meta.underlying_decimals
) AS amount,
depositor depositor_address,
seamless_version AS platform,
atoken_meta.underlying_symbol AS symbol,
'base' AS blockchain,
_log_id,
_inserted_timestamp
FROM
withdraw
LEFT JOIN atoken_meta
ON withdraw.seamless_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__seamless_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: seamless_MARKET
tests:
- not_null
- name: seamless_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,112 +0,0 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_number",
cluster_by = ['block_timestamp::DATE'],
tags = ['silver','defi','lending','curated']
) }}
WITH contracts AS (
SELECT
*
FROM
{{ ref('silver__contracts') }}
),
log_pull AS (
SELECT
l.tx_hash,
l.block_number,
l.block_timestamp,
l.contract_address,
C.token_name,
C.token_symbol,
C.token_decimals,
l.modified_timestamp AS _inserted_timestamp,
CONCAT(
tx_hash :: STRING,
'-',
event_index :: STRING
) AS _log_id
FROM
{{ ref('core__fact_event_logs') }}
l
LEFT JOIN contracts C
ON C.contract_address = l.contract_address
WHERE
topics [0] :: STRING = '0x7ac369dbd14fa5ea3f473ed67cc9d598964a77501540ba6751eb0b3decf5870d'
AND C.token_name LIKE '%SonneBase%'
{% if is_incremental() %}
AND l.modified_timestamp >= (
SELECT
MAX(
_inserted_timestamp
) - INTERVAL '12 hours'
FROM
{{ this }}
)
AND l.contract_address NOT IN (
SELECT
token_address
FROM
{{ this }}
)
AND l.modified_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
),
traces_pull AS (
SELECT
from_address AS token_address,
to_address AS underlying_asset
FROM
{{ ref('core__fact_traces') }}
WHERE
tx_hash IN (
SELECT
tx_hash
FROM
log_pull
)
),
contract_pull AS (
SELECT
l.tx_hash,
l.block_number,
l.block_timestamp,
l.contract_address,
C.token_name,
C.token_symbol,
C.token_decimals,
t.underlying_asset,
l._inserted_timestamp,
l._log_id
FROM
log_pull l
LEFT JOIN traces_pull t
ON l.contract_address = t.token_address
LEFT JOIN contracts C
ON C.contract_address = l.contract_address qualify(ROW_NUMBER() over(PARTITION BY l.contract_address
ORDER BY
block_timestamp ASC)) = 1
)
SELECT
l.tx_hash,
l.block_number,
l.block_timestamp,
l.contract_address AS token_address,
l.token_name,
l.token_symbol,
l.token_decimals,
l.underlying_asset AS underlying_asset_address,
C.token_name AS underlying_name,
C.token_symbol AS underlying_symbol,
C.token_decimals AS underlying_decimals,
l._inserted_timestamp,
l._log_id
FROM
contract_pull l
LEFT JOIN contracts C
ON C.contract_address = l.underlying_asset
WHERE
l.token_name IS 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']
) }}
-- pull all token addresses and corresponding name
WITH asset_details AS (
SELECT
token_address,
token_symbol,
token_name,
token_decimals,
underlying_asset_address,
underlying_name,
underlying_symbol,
underlying_decimals
FROM
{{ ref('silver__sonne_asset_details') }}
),
sonne_borrows AS (
SELECT
block_number,
block_timestamp,
tx_hash,
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(segmented_data [0] :: STRING, 25, 40)) AS borrower,
utils.udf_hex_to_int(
segmented_data [1] :: STRING
) :: INTEGER AS loan_amount_raw,
utils.udf_hex_to_int(
segmented_data [2] :: STRING
) :: INTEGER AS accountBorrows,
utils.udf_hex_to_int(
segmented_data [3] :: STRING
) :: INTEGER AS totalBorrows,
contract_address AS token,
'Sonne' AS platform,
modified_timestamp AS _inserted_timestamp,
CONCAT(
tx_hash :: STRING,
'-',
event_index :: STRING
) AS _log_id
FROM
{{ ref('core__fact_event_logs') }}
WHERE
contract_address IN (
SELECT
token_address
FROM
asset_details
)
AND topics [0] :: STRING = '0x13ed6866d4e1ee6da46f845c46d7e54120883d75c5ea9a2dacc1c4ca8984ab80'
AND tx_succeeded
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(
_inserted_timestamp
) - INTERVAL '12 hours'
FROM
{{ this }}
)
{% endif %}
),
sonne_combine AS (
SELECT
block_number,
block_timestamp,
tx_hash,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
borrower,
loan_amount_raw,
C.underlying_asset_address AS borrows_contract_address,
C.underlying_symbol AS borrows_contract_symbol,
token,
C.token_symbol,
C.underlying_decimals,
b.platform,
b._log_id,
b._inserted_timestamp
FROM
sonne_borrows b
LEFT JOIN asset_details C
ON b.token = C.token_address
)
SELECT
block_number,
block_timestamp,
tx_hash,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
borrower,
borrows_contract_address,
borrows_contract_symbol,
token AS token_address,
token_symbol,
loan_amount_raw AS amount_unadj,
loan_amount_raw / pow(
10,
underlying_decimals
) AS amount,
platform,
_inserted_timestamp,
_log_id
FROM
sonne_combine qualify(ROW_NUMBER() over(PARTITION BY _log_id
ORDER BY
_inserted_timestamp DESC)) = 1

View File

@ -1,42 +0,0 @@
version: 2
models:
- name: silver__sonne_borrows
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
- name: BORROWER
tests:
- not_null
- name: BORROWS_CONTRACT_ADDRESS
tests:
- not_null
- name: BORROWS_CONTRACT_SYMBOL
tests:
- not_null
- name: TOKEN_ADDRESS
tests:
- not_null
- name: TOKEN_SYMBOL
tests:
- not_null
- name: AMOUNT
tests:
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- decimal
- float
- name: TX_HASH
tests:
- not_null
- name: EVENT_INDEX
tests:
- not_null

View File

@ -1,128 +0,0 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_number",
cluster_by = ['block_timestamp::DATE'],
tags = ['silver','defi','lending','curated']
) }}
-- pull all token addresses and corresponding name
WITH asset_details AS (
SELECT
token_address,
token_symbol,
token_name,
token_decimals,
underlying_asset_address,
underlying_name,
underlying_symbol,
underlying_decimals
FROM
{{ ref('silver__sonne_asset_details') }}
),
sonne_deposits AS (
SELECT
block_number,
block_timestamp,
tx_hash,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
contract_address AS token_address,
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
utils.udf_hex_to_int(
segmented_data [2] :: STRING
) :: INTEGER AS minttokens_raw,
utils.udf_hex_to_int(
segmented_data [1] :: STRING
) :: INTEGER AS mintAmount_raw,
CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS supplier,
'Sonne' AS platform,
modified_timestamp AS _inserted_timestamp,
CONCAT(
tx_hash :: STRING,
'-',
event_index :: STRING
) AS _log_id
FROM
{{ ref('core__fact_event_logs') }}
WHERE
contract_address IN (
SELECT
token_address
FROM
asset_details
)
AND topics [0] :: STRING = '0x4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f'
AND tx_succeeded
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(
_inserted_timestamp
) - INTERVAL '12 hours'
FROM
{{ this }}
)
{% endif %}
),
sonne_combine AS (
SELECT
block_number,
block_timestamp,
tx_hash,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
supplier,
minttokens_raw,
mintAmount_raw,
C.underlying_asset_address AS supplied_contract_addr,
C.underlying_symbol AS supplied_symbol,
C.token_address,
C.token_symbol,
C.token_decimals,
C.underlying_decimals,
b.platform,
b._log_id,
b._inserted_timestamp
FROM
sonne_deposits b
LEFT JOIN asset_details C
ON b.token_address = C.token_address
)
SELECT
block_number,
block_timestamp,
tx_hash,
event_index,
origin_from_address,
origin_to_address,
origin_function_signature,
contract_address,
token_address,
token_symbol,
minttokens_raw / pow(
10,
token_decimals
) AS issued_tokens,
mintAmount_raw AS amount_unadj,
mintAmount_raw / pow(
10,
underlying_decimals
) AS amount,
supplied_contract_addr,
supplied_symbol,
supplier,
platform,
_inserted_timestamp,
_log_id
FROM
sonne_combine qualify(ROW_NUMBER() over(PARTITION BY _log_id
ORDER BY
_inserted_timestamp DESC)) = 1

Some files were not shown because too many files have changed in this diff Show More