mirror of
https://github.com/FlipsideCrypto/optimism-models.git
synced 2026-02-06 11:01:44 +00:00
AN-6419/consolidate-curated-lending-models (#388)
* remove lending models * update overview doc * tag * update to new tag
This commit is contained in:
parent
63042028e2
commit
ad18fdd111
@ -109,6 +109,8 @@ models:
|
||||
+enabled: true
|
||||
dex:
|
||||
+enabled: true
|
||||
lending:
|
||||
+enabled: true
|
||||
scores_package:
|
||||
+enabled: true
|
||||
|
||||
|
||||
@ -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/optimism-models/#!/model/model.fsc_evm.defi__ez_bridge_activity)
|
||||
- [ez_dex_swaps](https://flipsidecrypto.github.io/optimism-models/#!/model/model.fsc_evm.defi__ez_dex_swaps)
|
||||
- [dim_dex_liquidity_pools](https://flipsidecrypto.github.io/optimism-models/#!/model/model.fsc_evm.defi__dim_dex_liquidity_pools)
|
||||
- [ez_lending_borrows](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.defi__ez_lending_borrows)
|
||||
- [ez_lending_deposits](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.defi__ez_lending_deposits)
|
||||
- [ez_lending_flashloans](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.defi__ez_lending_flashloans)
|
||||
- [ez_lending_liquidations](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.defi__ez_lending_liquidations)
|
||||
- [ez_lending_repayments](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.defi__ez_lending_repayments)
|
||||
- [ez_lending_withdraws](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.defi__ez_lending_withdraws)
|
||||
- [ez_lending_borrows](https://flipsidecrypto.github.io/optimism-models/#!/model/model.fsc_evm.defi__ez_lending_borrows)
|
||||
- [ez_lending_deposits](https://flipsidecrypto.github.io/optimism-models/#!/model/model.fsc_evm.defi__ez_lending_deposits)
|
||||
- [ez_lending_flashloans](https://flipsidecrypto.github.io/optimism-models/#!/model/model.fsc_evm.defi__ez_lending_flashloans)
|
||||
- [ez_lending_liquidations](https://flipsidecrypto.github.io/optimism-models/#!/model/model.fsc_evm.defi__ez_lending_liquidations)
|
||||
- [ez_lending_repayments](https://flipsidecrypto.github.io/optimism-models/#!/model/model.fsc_evm.defi__ez_lending_repayments)
|
||||
- [ez_lending_withdraws](https://flipsidecrypto.github.io/optimism-models/#!/model/model.fsc_evm.defi__ez_lending_withdraws)
|
||||
|
||||
### NFT Tables (optimism.nft)
|
||||
- [ez_nft_transfers](https://flipsidecrypto.github.io/optimism-models/#!/model/model.fsc_evm.nft__ez_nft_transfers)
|
||||
|
||||
@ -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('0x794a61358D6845594F94dc1DB02A252b5b4814aD') 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('0x794a61358D6845594F94dc1DB02A252b5b4814aD')
|
||||
AND tx_succeeded --excludes failed txs
|
||||
),
|
||||
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,
|
||||
'optimism' 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
|
||||
@ -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
|
||||
@ -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('0x794a61358D6845594F94dc1DB02A252b5b4814aD') 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('0x794a61358D6845594F94dc1DB02A252b5b4814aD')
|
||||
AND tx_succeeded --excludes failed txs
|
||||
),
|
||||
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,
|
||||
'optimism' 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
|
||||
@ -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
|
||||
@ -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('0x794a61358D6845594F94dc1DB02A252b5b4814aD') 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('0x794a61358D6845594F94dc1DB02A252b5b4814aD')
|
||||
AND tx_succeeded --excludes failed txs
|
||||
),
|
||||
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,
|
||||
'optimism' 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
|
||||
@ -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
|
||||
@ -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('0x794a61358D6845594F94dc1DB02A252b5b4814aD') 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('0x794a61358D6845594F94dc1DB02A252b5b4814aD')
|
||||
AND tx_succeeded --excludes failed txs
|
||||
),
|
||||
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,
|
||||
'optimism' 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
|
||||
@ -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
|
||||
@ -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('0x794a61358D6845594F94dc1DB02A252b5b4814aD') 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('0x794a61358D6845594F94dc1DB02A252b5b4814aD')
|
||||
AND tx_succeeded --excludes failed txs
|
||||
),
|
||||
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,
|
||||
'optimism' 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
|
||||
@ -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
|
||||
@ -1,142 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
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 = '0xb2289e329d2f85f1ed31adbb30ea345278f21bcf'
|
||||
),
|
||||
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,
|
||||
aave_version_pool,
|
||||
treasury_address,
|
||||
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
|
||||
@ -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
|
||||
@ -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('0x794a61358D6845594F94dc1DB02A252b5b4814aD') 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('0x794a61358D6845594F94dc1DB02A252b5b4814aD')
|
||||
AND tx_succeeded --excludes failed txs
|
||||
),
|
||||
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,
|
||||
'optimism' 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
|
||||
@ -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
|
||||
@ -1,419 +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,
|
||||
'optimism' 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,
|
||||
'optimism' 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 %}
|
||||
),
|
||||
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,
|
||||
'optimism' 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 %}
|
||||
),
|
||||
exactly 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,
|
||||
'optimism' AS blockchain,
|
||||
A._LOG_ID,
|
||||
A._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__exactly_borrows') }} A
|
||||
|
||||
{% if is_incremental() and 'exactly' 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,
|
||||
'optimism' 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 %}
|
||||
),
|
||||
tarot 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,
|
||||
'optimism' AS blockchain,
|
||||
A._LOG_ID,
|
||||
A._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__tarot_borrows') }} A
|
||||
|
||||
{% if is_incremental() and 'tarot' 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
|
||||
granary
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
comp
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
exactly
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
sonne
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
tarot
|
||||
),
|
||||
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,
|
||||
'Borrow' AS event_name,
|
||||
borrower,
|
||||
protocol_market,
|
||||
b.token_address,
|
||||
b.token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
ROUND(
|
||||
amount * price,
|
||||
2
|
||||
) AS amount_usd,
|
||||
platform,
|
||||
b.blockchain,
|
||||
b._LOG_ID,
|
||||
b._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
borrow_union b
|
||||
LEFT JOIN {{ ref('price__ez_prices_hourly') }}
|
||||
p
|
||||
ON b.token_address = p.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
),
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
heal_model AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
t0.contract_address,
|
||||
event_name,
|
||||
borrower,
|
||||
protocol_market,
|
||||
t0.token_address,
|
||||
t0.token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
ROUND(
|
||||
amount * p.price,
|
||||
2
|
||||
) AS amount_usd_heal,
|
||||
platform,
|
||||
t0.blockchain,
|
||||
t0._LOG_ID,
|
||||
t0._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ this }}
|
||||
t0
|
||||
LEFT JOIN {{ ref('price__ez_prices_hourly') }}
|
||||
p
|
||||
ON t0.token_address = p.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
WHERE
|
||||
CONCAT(
|
||||
t0.block_number,
|
||||
'-',
|
||||
t0.platform
|
||||
) IN (
|
||||
SELECT
|
||||
CONCAT(
|
||||
t1.block_number,
|
||||
'-',
|
||||
t1.platform
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
t1
|
||||
WHERE
|
||||
t1.amount_usd IS NULL
|
||||
AND t1._inserted_timestamp < (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT
|
||||
1
|
||||
FROM
|
||||
{{ ref('silver__complete_token_prices') }}
|
||||
p
|
||||
WHERE
|
||||
p._inserted_timestamp > DATEADD('DAY', -14, SYSDATE())
|
||||
AND p.price IS NOT NULL
|
||||
AND p.token_address = t1.token_address
|
||||
AND p.hour = DATE_TRUNC(
|
||||
'hour',
|
||||
t1.block_timestamp
|
||||
)
|
||||
)
|
||||
GROUP BY
|
||||
1
|
||||
)
|
||||
),
|
||||
{% endif %}
|
||||
|
||||
FINAL AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
complete_lending_borrows
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
UNION ALL
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
event_name,
|
||||
borrower,
|
||||
protocol_market,
|
||||
token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
amount_usd_heal AS amount_usd,
|
||||
platform,
|
||||
blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
heal_model
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
*,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash','event_index']
|
||||
) }} AS complete_lending_borrows_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
FINAL qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,55 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__complete_lending_borrows
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- TX_HASH
|
||||
- EVENT_INDEX
|
||||
columns:
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 30
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: BORROWER
|
||||
tests:
|
||||
- not_null
|
||||
- name: PROTOCOL_MARKET
|
||||
tests:
|
||||
- not_null
|
||||
- name: TOKEN_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: TOKEN_SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT_UNADJ
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT_USD
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: PLATFORM
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCKCHAIN
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
@ -1,414 +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,
|
||||
'optimism' 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,
|
||||
'optimism' 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 %}
|
||||
),
|
||||
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,
|
||||
'optimism' 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 %}
|
||||
),
|
||||
exactly 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,
|
||||
'optimism' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__exactly_deposits') }}
|
||||
|
||||
{% if is_incremental() and 'exactly' 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,
|
||||
'optimism' 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 %}
|
||||
),
|
||||
tarot 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,
|
||||
'optimism' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__tarot_deposits') }}
|
||||
|
||||
{% if is_incremental() and 'tarot' 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
|
||||
exactly
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
sonne
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
tarot
|
||||
),
|
||||
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 (
|
||||
'Tarot',
|
||||
'Sonne'
|
||||
) THEN 'Mint'
|
||||
WHEN platform = 'Aave V3' THEN 'Supply'
|
||||
ELSE 'Deposit'
|
||||
END AS event_name,
|
||||
protocol_market,
|
||||
depositor_address AS depositor,
|
||||
A.token_address,
|
||||
A.token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
ROUND(
|
||||
amount * price,
|
||||
2
|
||||
) AS amount_usd,
|
||||
platform,
|
||||
A.blockchain,
|
||||
A._LOG_ID,
|
||||
A._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
deposit_union A
|
||||
LEFT JOIN {{ ref('price__ez_prices_hourly') }}
|
||||
p
|
||||
ON A.token_address = p.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
),
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
heal_model AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
t0.contract_address,
|
||||
event_name,
|
||||
protocol_market,
|
||||
depositor,
|
||||
t0.token_address,
|
||||
t0.token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
ROUND(
|
||||
amount * p.price,
|
||||
2
|
||||
) AS amount_usd_heal,
|
||||
platform,
|
||||
t0.blockchain,
|
||||
t0._LOG_ID,
|
||||
t0._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ this }}
|
||||
t0
|
||||
LEFT JOIN {{ ref('price__ez_prices_hourly') }}
|
||||
p
|
||||
ON t0.token_address = p.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
WHERE
|
||||
CONCAT(
|
||||
t0.block_number,
|
||||
'-',
|
||||
t0.platform
|
||||
) IN (
|
||||
SELECT
|
||||
CONCAT(
|
||||
t1.block_number,
|
||||
'-',
|
||||
t1.platform
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
t1
|
||||
WHERE
|
||||
t1.amount_usd IS NULL
|
||||
AND t1._inserted_timestamp < (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT
|
||||
1
|
||||
FROM
|
||||
{{ ref('silver__complete_token_prices') }}
|
||||
p
|
||||
WHERE
|
||||
p._inserted_timestamp > DATEADD('DAY', -14, SYSDATE())
|
||||
AND p.price IS NOT NULL
|
||||
AND p.token_address = t1.token_address
|
||||
AND p.hour = DATE_TRUNC(
|
||||
'hour',
|
||||
t1.block_timestamp
|
||||
)
|
||||
)
|
||||
GROUP BY
|
||||
1
|
||||
)
|
||||
),
|
||||
{% endif %}
|
||||
|
||||
FINAL AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
complete_lending_deposits
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
UNION ALL
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
event_name,
|
||||
protocol_market,
|
||||
depositor,
|
||||
token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
amount_usd_heal AS amount_usd,
|
||||
platform,
|
||||
blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
heal_model
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
*,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash','event_index']
|
||||
) }} AS complete_lending_deposits_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
FINAL qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,55 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__complete_lending_deposits
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- TX_HASH
|
||||
- EVENT_INDEX
|
||||
columns:
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 30
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: PROTOCOL_MARKET
|
||||
tests:
|
||||
- not_null
|
||||
- name: DEPOSITOR
|
||||
tests:
|
||||
- not_null
|
||||
- name: TOKEN_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: TOKEN_SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT_UNADJ
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT_USD
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: PLATFORM
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCKCHAIN
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
@ -1,321 +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,
|
||||
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,
|
||||
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 %}
|
||||
),
|
||||
flashloan_union AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
aave
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
granary
|
||||
),
|
||||
complete_lending_flashloans AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
f.contract_address,
|
||||
'FlashLoan' AS event_name,
|
||||
protocol_token AS protocol_market,
|
||||
initiator_address AS initiator,
|
||||
target_address AS target,
|
||||
f.token_address AS flashloan_token,
|
||||
f.symbol AS flashloan_token_symbol,
|
||||
flashloan_amount_unadj,
|
||||
flashloan_amount,
|
||||
ROUND(
|
||||
flashloan_amount * price,
|
||||
2
|
||||
) AS flashloan_amount_usd,
|
||||
premium_amount_unadj,
|
||||
premium_amount,
|
||||
ROUND(
|
||||
premium_amount * price,
|
||||
2
|
||||
) AS premium_amount_usd,
|
||||
platform,
|
||||
f.blockchain,
|
||||
f._LOG_ID,
|
||||
f._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
flashloan_union f
|
||||
LEFT JOIN {{ ref('price__ez_prices_hourly') }}
|
||||
p
|
||||
ON f.token_address = p.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
),
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
heal_model AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
t0.contract_address,
|
||||
event_name,
|
||||
protocol_market,
|
||||
initiator,
|
||||
target,
|
||||
flashloan_token,
|
||||
flashloan_token_symbol,
|
||||
flashloan_amount_unadj,
|
||||
flashloan_amount,
|
||||
ROUND(
|
||||
flashloan_amount * p.price,
|
||||
2
|
||||
) AS flashloan_amount_usd_heal,
|
||||
premium_amount_unadj,
|
||||
premium_amount,
|
||||
ROUND(
|
||||
premium_amount * p.price,
|
||||
2
|
||||
) AS premium_amount_usd_heal,
|
||||
platform,
|
||||
t0.blockchain,
|
||||
t0._LOG_ID,
|
||||
t0._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ this }}
|
||||
t0
|
||||
LEFT JOIN {{ ref('price__ez_prices_hourly') }}
|
||||
p
|
||||
ON t0.flashloan_token = p.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
WHERE
|
||||
CONCAT(
|
||||
t0.block_number,
|
||||
'-',
|
||||
t0.platform
|
||||
) IN (
|
||||
SELECT
|
||||
CONCAT(
|
||||
t1.block_number,
|
||||
'-',
|
||||
t1.platform
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
t1
|
||||
WHERE
|
||||
t1.flashloan_amount_usd IS NULL
|
||||
AND t1._inserted_timestamp < (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT
|
||||
1
|
||||
FROM
|
||||
{{ ref('silver__complete_token_prices') }}
|
||||
p
|
||||
WHERE
|
||||
p._inserted_timestamp > DATEADD('DAY', -14, SYSDATE())
|
||||
AND p.price IS NOT NULL
|
||||
AND p.token_address = t1.flashloan_token
|
||||
AND p.hour = DATE_TRUNC(
|
||||
'hour',
|
||||
t1.block_timestamp
|
||||
)
|
||||
)
|
||||
GROUP BY
|
||||
1
|
||||
)
|
||||
OR CONCAT(
|
||||
t0.block_number,
|
||||
'-',
|
||||
t0.platform
|
||||
) IN (
|
||||
SELECT
|
||||
CONCAT(
|
||||
t2.block_number,
|
||||
'-',
|
||||
t2.platform
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
t2
|
||||
WHERE
|
||||
t2.premium_amount_usd IS NULL
|
||||
AND t2._inserted_timestamp < (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT
|
||||
1
|
||||
FROM
|
||||
{{ ref('silver__complete_token_prices') }}
|
||||
p
|
||||
WHERE
|
||||
p._inserted_timestamp > DATEADD('DAY', -14, SYSDATE())
|
||||
AND p.price IS NOT NULL
|
||||
AND p.token_address = t2.flashloan_token
|
||||
AND p.hour = DATE_TRUNC(
|
||||
'hour',
|
||||
t2.block_timestamp
|
||||
)
|
||||
)
|
||||
GROUP BY
|
||||
1
|
||||
)
|
||||
),
|
||||
{% endif %}
|
||||
|
||||
FINAL AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
complete_lending_flashloans
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
UNION ALL
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
event_name,
|
||||
protocol_market,
|
||||
initiator,
|
||||
target,
|
||||
flashloan_token,
|
||||
flashloan_token_symbol,
|
||||
flashloan_amount_unadj,
|
||||
flashloan_amount,
|
||||
flashloan_amount_usd_heal AS flashloan_amount_usd,
|
||||
premium_amount_unadj,
|
||||
premium_amount,
|
||||
premium_amount_usd_heal AS premium_amount_usd,
|
||||
platform,
|
||||
blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
heal_model
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
*,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash','event_index']
|
||||
) }} AS complete_lending_flashloans_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
FINAL qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,54 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__complete_lending_flashloans
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- TX_HASH
|
||||
- EVENT_INDEX
|
||||
columns:
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 60
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: PROTOCOL_MARKET
|
||||
tests:
|
||||
- not_null
|
||||
# - name: INITIATOR
|
||||
# tests:
|
||||
# - not_null
|
||||
- name: TARGET
|
||||
tests:
|
||||
- not_null
|
||||
- name: FLASHLOAN_AMOUNT_UNADJ
|
||||
tests:
|
||||
- not_null
|
||||
- name: FLASHLOAN_AMOUNT
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: FLASHLOAN_AMOUNT_USD
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: PLATFORM
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCKCHAIN
|
||||
tests:
|
||||
- not_null
|
||||
@ -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, 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,
|
||||
'optimism' 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,
|
||||
'optimism' 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 %}
|
||||
),
|
||||
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,
|
||||
'optimism' 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 %}
|
||||
),
|
||||
exactly 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,
|
||||
'optimism' AS blockchain,
|
||||
l._LOG_ID,
|
||||
l._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__exactly_liquidations') }}
|
||||
l
|
||||
|
||||
{% if is_incremental() and 'exactly' 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,
|
||||
'optimism' 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 %}
|
||||
),
|
||||
tarot 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,
|
||||
'optimism' AS blockchain,
|
||||
l._LOG_ID,
|
||||
l._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__tarot_liquidations') }}
|
||||
l
|
||||
|
||||
{% if is_incremental() and 'tarot' 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
|
||||
comp
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
exactly
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
sonne
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
tarot
|
||||
),
|
||||
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 = 'Sonne' THEN 'LiquidateBorrow'
|
||||
WHEN platform IN (
|
||||
'Tarot',
|
||||
'Exactly'
|
||||
) THEN 'Liquidate'
|
||||
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,
|
||||
ROUND(
|
||||
liquidated_amount * p.price,
|
||||
2
|
||||
) 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,
|
||||
ROUND(
|
||||
amount * p.price,
|
||||
2
|
||||
) AS amount_usd_heal,
|
||||
debt_token,
|
||||
debt_token_symbol,
|
||||
platform,
|
||||
t0.blockchain,
|
||||
t0._LOG_ID,
|
||||
t0._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ this }}
|
||||
t0
|
||||
LEFT JOIN {{ ref('price__ez_prices_hourly') }}
|
||||
p
|
||||
ON t0.collateral_token = p.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
WHERE
|
||||
CONCAT(
|
||||
t0.block_number,
|
||||
'-',
|
||||
t0.platform
|
||||
) IN (
|
||||
SELECT
|
||||
CONCAT(
|
||||
t1.block_number,
|
||||
'-',
|
||||
t1.platform
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
t1
|
||||
WHERE
|
||||
t1.amount_usd IS NULL
|
||||
AND t1._inserted_timestamp < (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT
|
||||
1
|
||||
FROM
|
||||
{{ ref('silver__complete_token_prices') }}
|
||||
p
|
||||
WHERE
|
||||
p._inserted_timestamp > DATEADD('DAY', -14, SYSDATE())
|
||||
AND p.price IS NOT NULL
|
||||
AND p.token_address = t1.collateral_token
|
||||
AND p.hour = DATE_TRUNC(
|
||||
'hour',
|
||||
t1.block_timestamp
|
||||
)
|
||||
)
|
||||
GROUP BY
|
||||
1
|
||||
)
|
||||
),
|
||||
{% endif %}
|
||||
|
||||
FINAL AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
complete_lending_liquidations
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
UNION ALL
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
event_name,
|
||||
liquidator,
|
||||
borrower,
|
||||
protocol_market,
|
||||
collateral_token,
|
||||
collateral_token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
amount_usd_heal AS amount_usd,
|
||||
debt_token,
|
||||
debt_token_symbol,
|
||||
platform,
|
||||
blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
heal_model
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
*,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash','event_index']
|
||||
) }} AS complete_lending_liquidations_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
FINAL qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,58 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__complete_lending_liquidations
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- TX_HASH
|
||||
- EVENT_INDEX
|
||||
columns:
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 60
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: LIQUIDATOR
|
||||
tests:
|
||||
- not_null
|
||||
- name: BORROWER
|
||||
tests:
|
||||
- not_null
|
||||
- name: PROTOCOL_MARKET
|
||||
tests:
|
||||
- not_null
|
||||
- name: COLLATERAL_TOKEN
|
||||
tests:
|
||||
- not_null
|
||||
- name: COLLATERAL_TOKEN_SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT_UNADJ
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT_USD
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: PLATFORM
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCKCHAIN
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
@ -1,419 +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,
|
||||
'optimism' 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,
|
||||
'optimism' 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 %}
|
||||
),
|
||||
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,
|
||||
'optimism' 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 %}
|
||||
),
|
||||
exactly 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,
|
||||
'optimism' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__exactly_repayments') }}
|
||||
|
||||
{% if is_incremental() and 'exactly' 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,
|
||||
'optimism' 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 %}
|
||||
),
|
||||
tarot 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,
|
||||
'optimism' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__tarot_repayments') }}
|
||||
|
||||
{% if is_incremental() and 'tarot' 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
|
||||
exactly
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
sonne
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
tarot
|
||||
),
|
||||
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 = 'Sonne' THEN 'RepayBorrow'
|
||||
ELSE 'Repay'
|
||||
END AS event_name,
|
||||
protocol_market,
|
||||
payer_address AS payer,
|
||||
borrower,
|
||||
A.token_address,
|
||||
A.token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
ROUND(
|
||||
amount * price,
|
||||
2
|
||||
) AS amount_usd,
|
||||
platform,
|
||||
A.blockchain,
|
||||
A._LOG_ID,
|
||||
A._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
repayments_union A
|
||||
LEFT JOIN {{ ref('price__ez_prices_hourly') }}
|
||||
p
|
||||
ON A.token_address = p.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
),
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
heal_model AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
t0.contract_address,
|
||||
event_name,
|
||||
protocol_market,
|
||||
payer,
|
||||
borrower,
|
||||
t0.token_address,
|
||||
t0.token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
ROUND(
|
||||
amount * p.price,
|
||||
2
|
||||
) AS amount_usd_heal,
|
||||
platform,
|
||||
t0.blockchain,
|
||||
t0._LOG_ID,
|
||||
t0._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ this }}
|
||||
t0
|
||||
LEFT JOIN {{ ref('price__ez_prices_hourly') }}
|
||||
p
|
||||
ON t0.token_address = p.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
WHERE
|
||||
CONCAT(
|
||||
t0.block_number,
|
||||
'-',
|
||||
t0.platform
|
||||
) IN (
|
||||
SELECT
|
||||
CONCAT(
|
||||
t1.block_number,
|
||||
'-',
|
||||
t1.platform
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
t1
|
||||
WHERE
|
||||
t1.amount_usd IS NULL
|
||||
AND t1._inserted_timestamp < (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT
|
||||
1
|
||||
FROM
|
||||
{{ ref('silver__complete_token_prices') }}
|
||||
p
|
||||
WHERE
|
||||
p._inserted_timestamp > DATEADD('DAY', -14, SYSDATE())
|
||||
AND p.price IS NOT NULL
|
||||
AND p.token_address = t1.token_address
|
||||
AND p.hour = DATE_TRUNC(
|
||||
'hour',
|
||||
t1.block_timestamp
|
||||
)
|
||||
)
|
||||
GROUP BY
|
||||
1
|
||||
)
|
||||
),
|
||||
{% endif %}
|
||||
|
||||
FINAL AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
complete_lending_repayments
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
UNION ALL
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
event_name,
|
||||
protocol_market,
|
||||
payer,
|
||||
borrower,
|
||||
token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
amount_usd_heal AS amount_usd,
|
||||
platform,
|
||||
blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
heal_model
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
*,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash','event_index']
|
||||
) }} AS complete_lending_repayments_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
FINAL qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,58 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__complete_lending_repayments
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- TX_HASH
|
||||
- EVENT_INDEX
|
||||
columns:
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 30
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: PROTOCOL_MARKET
|
||||
tests:
|
||||
- not_null
|
||||
- name: PAYER
|
||||
tests:
|
||||
- not_null:
|
||||
where: PLATFORM <> 'Silo'
|
||||
- name: BORROWER
|
||||
tests:
|
||||
- not_null
|
||||
- name: TOKEN_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: TOKEN_SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT_UNADJ
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT_USD
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: PLATFORM
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCKCHAIN
|
||||
tests:
|
||||
- not_null
|
||||
@ -1,425 +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,
|
||||
'optimism' 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,
|
||||
'optimism' 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 %}
|
||||
),
|
||||
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,
|
||||
'optimism' 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 %}
|
||||
),
|
||||
exactly 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 token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
redeemer AS depositor_address,
|
||||
platform,
|
||||
'optimism' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__exactly_withdraws') }}
|
||||
|
||||
{% if is_incremental() and 'exactly' 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 token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
redeemer AS depositor_address,
|
||||
platform,
|
||||
'optimism' 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 %}
|
||||
),
|
||||
tarot 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 token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
redeemer AS depositor_address,
|
||||
platform,
|
||||
'optimism' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__tarot_withdraws') }}
|
||||
|
||||
{% if is_incremental() and 'tarot' 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
|
||||
granary
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
comp
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
exactly
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
sonne
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
tarot
|
||||
),
|
||||
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 (
|
||||
'Tarot',
|
||||
'Sonne'
|
||||
) THEN 'Redeem'
|
||||
ELSE 'Withdraw'
|
||||
END AS event_name,
|
||||
protocol_market,
|
||||
depositor_address AS depositor,
|
||||
A.token_address,
|
||||
A.token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
ROUND(
|
||||
amount * price,
|
||||
2
|
||||
) AS amount_usd,
|
||||
platform,
|
||||
A.blockchain,
|
||||
a._log_id,
|
||||
a._inserted_timestamp
|
||||
FROM
|
||||
withdraws_union a
|
||||
LEFT JOIN {{ ref('price__ez_prices_hourly') }}
|
||||
p
|
||||
ON a.token_address = p.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
),
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
heal_model AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
t0.contract_address,
|
||||
event_name,
|
||||
protocol_market,
|
||||
depositor,
|
||||
t0.token_address,
|
||||
t0.token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
ROUND(
|
||||
amount * p.price,
|
||||
2
|
||||
) AS amount_usd_heal,
|
||||
platform,
|
||||
t0.blockchain,
|
||||
t0._log_id,
|
||||
t0._inserted_timestamp
|
||||
FROM
|
||||
{{ this }}
|
||||
t0
|
||||
LEFT JOIN {{ ref('price__ez_prices_hourly') }}
|
||||
p
|
||||
ON t0.token_address = p.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
WHERE
|
||||
CONCAT(
|
||||
t0.block_number,
|
||||
'-',
|
||||
t0.platform
|
||||
) IN (
|
||||
SELECT
|
||||
CONCAT(
|
||||
t1.block_number,
|
||||
'-',
|
||||
t1.platform
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
t1
|
||||
WHERE
|
||||
t1.amount_usd IS NULL
|
||||
AND t1._inserted_timestamp < (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("lookback", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT
|
||||
1
|
||||
FROM
|
||||
{{ ref('silver__complete_token_prices') }}
|
||||
p
|
||||
WHERE
|
||||
p._inserted_timestamp > DATEADD('day', -14, SYSDATE())
|
||||
AND p.price IS NOT NULL
|
||||
AND p.token_address = t1.token_address
|
||||
AND p.hour = DATE_TRUNC(
|
||||
'hour',
|
||||
t1.block_timestamp
|
||||
)
|
||||
)
|
||||
GROUP BY
|
||||
1
|
||||
)
|
||||
),
|
||||
{% endif %}
|
||||
|
||||
FINAL AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
complete_lending_withdraws
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
UNION ALL
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
event_name,
|
||||
protocol_market,
|
||||
depositor,
|
||||
token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
amount_usd_heal AS amount_usd,
|
||||
platform,
|
||||
blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
heal_model
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
*,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash','event_index']
|
||||
) }} AS complete_lending_withdraws_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
FINAL qualify(ROW_NUMBER() over(PARTITION BY _LOG_ID
|
||||
ORDER BY
|
||||
_INSERTED_TIMESTAMP DESC)) = 1
|
||||
@ -1,56 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__complete_lending_withdraws
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- TX_HASH
|
||||
- EVENT_INDEX
|
||||
columns:
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 30
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: PROTOCOL_MARKET
|
||||
tests:
|
||||
- not_null
|
||||
- name: DEPOSITOR
|
||||
tests:
|
||||
- not_null
|
||||
- name: TOKEN_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: TOKEN_SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT_UNADJ
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT_USD
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: PLATFORM
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCKCHAIN
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
|
||||
@ -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/optimism/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
|
||||
@ -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,
|
||||
'optimism' 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
|
||||
@ -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
|
||||
@ -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,
|
||||
'optimism' 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
|
||||
@ -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
|
||||
@ -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,
|
||||
'optimism' 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
|
||||
@ -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
|
||||
@ -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,
|
||||
'optimism' 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
|
||||
@ -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
|
||||
|
||||
@ -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,
|
||||
'optimism' 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
|
||||
@ -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
|
||||
@ -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 log_pull AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
contract_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] :: STRING = '0x7902cd1307c545e3f5782172612372bf997a93698917ced12b2f83d86e347d0c'
|
||||
AND origin_from_address = LOWER('0xe61bdef3fff4c3cf7a07996dcb8802b5c85b665a')
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_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
|
||||
)
|
||||
AND TYPE = 'STATICCALL'
|
||||
UNION ALL
|
||||
--Market USDC does not have a staticcall trace with underlying asset information
|
||||
SELECT
|
||||
'0x6926b434cce9b5b7966ae1bfeef6d0a7dcf3a8bb' AS token_address,
|
||||
'0x0b2c639c533813f4aa9d7837caf62653d097ff85' AS underlying_asset
|
||||
),
|
||||
contracts AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ ref('silver__contracts') }}
|
||||
),
|
||||
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
|
||||
underlying_asset IS NOT NULL
|
||||
AND l.token_name IS NOT NULL
|
||||
@ -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
|
||||
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__exactly_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(topics [3] :: STRING, 27, 40)) AS borrower,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
) :: INTEGER AS loan_amount_raw,
|
||||
0 AS accountBorrows,
|
||||
0 AS totalBorrows,
|
||||
contract_address AS token,
|
||||
'Exactly' 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 = '0x96558a334f4759f0e7c423d68c84721860bd8fbf94ddc4e55158ecb125ad04b5'
|
||||
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 %}
|
||||
),
|
||||
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
|
||||
@ -1,42 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__exactly_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
|
||||
@ -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__exactly_asset_details') }}
|
||||
),
|
||||
exactly_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,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS supplier,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [1] :: STRING
|
||||
) :: INTEGER AS minttokens_raw,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
) :: INTEGER AS mintAmount_raw,
|
||||
'Exactly' 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 = '0xdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d7'
|
||||
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 %}
|
||||
),
|
||||
exactly_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
|
||||
exactly_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
|
||||
exactly_combine qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,50 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__exactly_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
|
||||
@ -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']
|
||||
) }}
|
||||
-- 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__exactly_asset_details') }}
|
||||
),
|
||||
exactly_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(topics [2] :: STRING, 27, 40)) AS borrower,
|
||||
contract_address AS token,
|
||||
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS liquidator,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [2] :: STRING
|
||||
) :: INTEGER AS seizeTokens_raw,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [1] :: STRING
|
||||
) :: INTEGER AS repayAmount_raw,
|
||||
CONCAT('0x', SUBSTR(topics [3] :: STRING, 27, 40)) AS tokenCollateral,
|
||||
'Exactly' 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 = '0x67bb48f97d82192848c24158abf58ec614777328e19655e0a219652b773fd1db'
|
||||
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 %}
|
||||
),
|
||||
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
|
||||
exactly_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
|
||||
@ -1,56 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__exactly_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
|
||||
@ -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']
|
||||
) }}
|
||||
-- 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__exactly_asset_details') }}
|
||||
),
|
||||
exactly_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(topics [2] :: STRING, 27, 40)) AS borrower,
|
||||
contract_address AS token,
|
||||
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS payer,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [1] :: STRING
|
||||
) :: INTEGER AS repayed_amount_raw,
|
||||
'Exactly' 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 = '0xe4a1ae657f49cb1fb1c7d3a94ae6093565c4c8c0e03de488f79c377c3c3a24e0'
|
||||
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 %}
|
||||
),
|
||||
exactly_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
|
||||
exactly_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,
|
||||
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
|
||||
exactly_combine qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,44 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__exactly_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
|
||||
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
|
||||
@ -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']
|
||||
) }}
|
||||
-- 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__exactly_asset_details') }}
|
||||
),
|
||||
exactly_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 [0] :: STRING
|
||||
) :: INTEGER AS received_amount_raw,
|
||||
0 AS redeemed_token_raw,
|
||||
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS redeemer,
|
||||
'Exactly' 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 = '0xfbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db'
|
||||
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 %}
|
||||
),
|
||||
exactly_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
|
||||
exactly_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,
|
||||
redeemer,
|
||||
platform,
|
||||
_inserted_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
exactly_combine ee qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,47 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__exactly_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
|
||||
@ -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 granary 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 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,
|
||||
CASE
|
||||
WHEN contract_address = LOWER('0x8FD4aF47E4E63d1D2D45582c3286b4BD9Bb95DfE') THEN 'Granary'
|
||||
ELSE 'ERROR'
|
||||
END AS granary_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 = '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 = LOWER('0x8FD4aF47E4E63d1D2D45582c3286b4BD9Bb95DfE')
|
||||
AND tx_succeeded --excludes failed txs
|
||||
),
|
||||
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__granary_tokens') }}
|
||||
)
|
||||
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,
|
||||
'optimism' 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
|
||||
@ -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
|
||||
@ -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 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,
|
||||
CASE
|
||||
WHEN contract_address = LOWER('0x8FD4aF47E4E63d1D2D45582c3286b4BD9Bb95DfE') THEN 'Granary'
|
||||
ELSE 'ERROR'
|
||||
END 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 = LOWER('0x8FD4aF47E4E63d1D2D45582c3286b4BD9Bb95DfE')
|
||||
AND tx_succeeded --excludes failed txs
|
||||
),
|
||||
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__granary_tokens') }}
|
||||
)
|
||||
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,
|
||||
'optimism' 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
|
||||
@ -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
|
||||
@ -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 [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,
|
||||
CASE
|
||||
WHEN contract_address = LOWER('0x8FD4aF47E4E63d1D2D45582c3286b4BD9Bb95DfE') THEN 'Granary'
|
||||
ELSE 'ERROR'
|
||||
END 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 = LOWER('0x8FD4aF47E4E63d1D2D45582c3286b4BD9Bb95DfE')
|
||||
AND tx_succeeded --excludes failed txs
|
||||
),
|
||||
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__granary_tokens') }}
|
||||
)
|
||||
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,
|
||||
'optimism' 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
|
||||
@ -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
|
||||
@ -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('0x8FD4aF47E4E63d1D2D45582c3286b4BD9Bb95DfE') THEN 'Granary'
|
||||
ELSE 'ERROR'
|
||||
END 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 = LOWER('0x8FD4aF47E4E63d1D2D45582c3286b4BD9Bb95DfE')
|
||||
AND tx_succeeded --excludes failed txs
|
||||
),
|
||||
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__granary_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_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,
|
||||
'optimism' 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
|
||||
@ -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
|
||||
@ -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 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,
|
||||
CASE
|
||||
WHEN contract_address = LOWER('0x8FD4aF47E4E63d1D2D45582c3286b4BD9Bb95DfE') THEN 'Granary'
|
||||
ELSE 'ERROR'
|
||||
END 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 = LOWER('0x8FD4aF47E4E63d1D2D45582c3286b4BD9Bb95DfE')
|
||||
AND tx_succeeded --excludes failed txs
|
||||
),
|
||||
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__granary_tokens') }}
|
||||
)
|
||||
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,
|
||||
'optimism' 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
|
||||
@ -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
|
||||
@ -1,142 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
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') }}
|
||||
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,
|
||||
granary_version_pool,
|
||||
treasury_address,
|
||||
atoken_decimals,
|
||||
atoken_name,
|
||||
atoken_symbol,
|
||||
_inserted_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
DECODE
|
||||
WHERE
|
||||
treasury_address in ('0xb2289e329d2f85f1ed31adbb30ea345278f21bcf', '0xc01a7ad7fb8a085a3cc16be8eaa10302c78a1783')
|
||||
),
|
||||
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,
|
||||
granary_version_pool,
|
||||
atoken_decimals,
|
||||
atoken_name,
|
||||
atoken_symbol,
|
||||
_inserted_timestamp,
|
||||
_log_id,
|
||||
'Granary' AS protocol
|
||||
FROM
|
||||
a_token_step_1
|
||||
)
|
||||
SELECT
|
||||
A.atoken_created_block,
|
||||
A.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
|
||||
@ -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
|
||||
@ -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 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,
|
||||
CASE
|
||||
WHEN contract_address = LOWER('0x8FD4aF47E4E63d1D2D45582c3286b4BD9Bb95DfE') THEN 'Granary'
|
||||
ELSE 'ERROR'
|
||||
END 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 = LOWER('0x8FD4aF47E4E63d1D2D45582c3286b4BD9Bb95DfE')
|
||||
AND tx_succeeded --excludes failed txs
|
||||
),
|
||||
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__granary_tokens') }}
|
||||
)
|
||||
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,
|
||||
'optimism' 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
|
||||
@ -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
|
||||
@ -1,104 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['silver','defi','lending','curated']
|
||||
) }}
|
||||
|
||||
WITH log_pull AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
contract_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] :: STRING = '0x7ac369dbd14fa5ea3f473ed67cc9d598964a77501540ba6751eb0b3decf5870d'
|
||||
AND origin_from_address = LOWER('0xFb59Ce8986943163F14C590755b29dB2998F2322')
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_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
|
||||
)
|
||||
AND concat_ws(
|
||||
'_',
|
||||
TYPE,
|
||||
trace_address
|
||||
) = 'STATICCALL_2'
|
||||
),
|
||||
contracts AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ ref('silver__contracts') }}
|
||||
),
|
||||
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
|
||||
underlying_asset IS NOT NULL
|
||||
AND l.token_name IS NOT NULL
|
||||
@ -1,124 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['silver','defi','lending','curated']
|
||||
) }}
|
||||
-- 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 }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% 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
|
||||
@ -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
|
||||
@ -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__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 }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% 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
|
||||
@ -1,47 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__sonne_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
|
||||
- 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
|
||||
@ -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 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_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,
|
||||
'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 = '0x298637f684da70674f26509b10f07ec2fbc77a335ab1e7d6215a4b2484d8bb52'
|
||||
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 %}
|
||||
),
|
||||
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
|
||||
sonne_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
|
||||
@ -1,56 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__sonne_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
|
||||
@ -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']
|
||||
) }}
|
||||
-- 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_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,
|
||||
'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 = '0x1a2a22cb034d26d1854bdc6666a5b91fe25efbbb5dcad3b0355478d6f5c362a1'
|
||||
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 %}
|
||||
),
|
||||
sonne_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
|
||||
sonne_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
|
||||
sonne_combine qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,44 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__sonne_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
|
||||
@ -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__sonne_asset_details') }}
|
||||
),
|
||||
sonne_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,
|
||||
'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 = '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 %}
|
||||
),
|
||||
sonne_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
|
||||
sonne_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
|
||||
sonne_combine ee qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,47 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__sonne_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
|
||||
@ -1,106 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['silver','defi','lending','curated']
|
||||
) }}
|
||||
|
||||
WITH asset_details AS (
|
||||
|
||||
SELECT
|
||||
borrowable1 AS token_address,
|
||||
token0 AS underlying_asset_address,
|
||||
token0_name AS underlying_asset_name,
|
||||
token0_symbol AS underlying_asset_symbol,
|
||||
token0_decimals AS underlying_decimals
|
||||
FROM
|
||||
{{ ref('silver__tarot_liquidity_pools') }}
|
||||
GROUP BY
|
||||
ALL
|
||||
UNION ALL
|
||||
SELECT
|
||||
borrowable2 AS token_address,
|
||||
token1 AS underlying_asset_address,
|
||||
token1_name AS underlying_asset_name,
|
||||
token1_symbol AS underlying_asset_symbol,
|
||||
token1_decimals AS underlying_decimals
|
||||
FROM
|
||||
{{ ref('silver__tarot_liquidity_pools') }}
|
||||
GROUP BY
|
||||
ALL
|
||||
),
|
||||
log_pull 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 [2] :: STRING, 25, 40)) AS borrower,
|
||||
TRY_TO_NUMBER(
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
)) AS loan_amount_raw,
|
||||
modified_timestamp AS _inserted_timestamp,
|
||||
CONCAT(
|
||||
tx_hash :: STRING,
|
||||
'-',
|
||||
event_index :: STRING
|
||||
) AS _log_id
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
l
|
||||
WHERE
|
||||
contract_address IN (
|
||||
SELECT
|
||||
token_address
|
||||
FROM
|
||||
asset_details
|
||||
)
|
||||
AND topics [0] :: STRING = '0x33f3048bd4e6af45e53afb722adfd57dbde82da7e93e44db921fb4b8c6a70c4b'
|
||||
AND tx_succeeded
|
||||
AND loan_amount_raw > 0 --borrow and repay in same log event, value in segmented data determines if borrow or repay
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
borrower,
|
||||
underlying_asset_address AS borrows_contract_address,
|
||||
underlying_asset_symbol AS borrows_contract_symbol,
|
||||
a.token_address AS token_address,
|
||||
'bTAROT' AS token_symbol,
|
||||
loan_amount_raw AS amount_unadj,
|
||||
loan_amount_raw / pow(
|
||||
10,
|
||||
underlying_decimals
|
||||
) AS amount,
|
||||
'Tarot' AS platform,
|
||||
_inserted_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
log_pull l
|
||||
LEFT JOIN asset_details A
|
||||
ON A.token_address = l.contract_address qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,42 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__tarot_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
|
||||
@ -1,103 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['silver','defi','lending','curated']
|
||||
) }}
|
||||
|
||||
WITH asset_details AS (
|
||||
|
||||
SELECT
|
||||
borrowable1 AS token_address,
|
||||
token0 AS underlying_asset_address,
|
||||
token0_symbol AS underlying_asset_symbol,
|
||||
token0_decimals AS underlying_decimals
|
||||
FROM
|
||||
{{ ref('silver__tarot_liquidity_pools') }}
|
||||
GROUP BY
|
||||
ALL
|
||||
UNION ALL
|
||||
SELECT
|
||||
borrowable2 AS token_address,
|
||||
token1 AS underlying_asset_address,
|
||||
token1_symbol AS underlying_asset_symbol,
|
||||
token1_decimals AS underlying_decimals
|
||||
FROM
|
||||
{{ ref('silver__tarot_liquidity_pools') }}
|
||||
GROUP BY
|
||||
ALL
|
||||
),
|
||||
log_pull 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, 25, 40)) AS sender,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 25, 40)) AS supplier,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
) :: INTEGER AS mintAmount_raw,
|
||||
modified_timestamp AS _inserted_timestamp,
|
||||
CONCAT(
|
||||
tx_hash :: STRING,
|
||||
'-',
|
||||
event_index :: STRING
|
||||
) AS _log_id
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
l
|
||||
WHERE
|
||||
contract_address IN (
|
||||
SELECT
|
||||
token_address
|
||||
FROM
|
||||
asset_details
|
||||
)
|
||||
AND topics [0] :: STRING = '0x2f00e3cdd69a77be7ed215ec7b2a36784dd158f921fca79ac29deffa353fe6ee'
|
||||
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 %}
|
||||
)
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
A.token_address,
|
||||
'bTAROT' AS token_symbol,
|
||||
mintAmount_raw AS amount_unadj,
|
||||
mintAmount_raw / pow(
|
||||
10,
|
||||
underlying_decimals
|
||||
) AS amount,
|
||||
underlying_asset_address AS supplied_contract_addr,
|
||||
underlying_asset_symbol AS supplied_symbol,
|
||||
supplier,
|
||||
'Tarot' AS platform,
|
||||
_inserted_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
log_pull l
|
||||
LEFT JOIN asset_details A
|
||||
ON A.token_address = l.contract_address qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,47 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__tarot_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
|
||||
- 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
|
||||
@ -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 asset_details as (
|
||||
|
||||
select
|
||||
borrowable1 as token_address,
|
||||
token0 as underlying_asset_address,
|
||||
token0_symbol as underlying_asset_symbol,
|
||||
token0_decimals as underlying_decimals,
|
||||
ctarot,
|
||||
lp_token_address,
|
||||
lp_token_name,
|
||||
lp_token_symbol,
|
||||
lp_token_decimals
|
||||
from
|
||||
{{ ref('silver__tarot_liquidity_pools') }}
|
||||
group by all
|
||||
UNION ALL
|
||||
select
|
||||
borrowable2 as token_address,
|
||||
token1 as underlying_asset_address,
|
||||
token1_symbol as underlying_asset_symbol,
|
||||
token1_decimals as underlying_decimals,
|
||||
ctarot,
|
||||
lp_token_address,
|
||||
lp_token_name,
|
||||
lp_token_symbol,
|
||||
lp_token_decimals
|
||||
from
|
||||
{{ ref('silver__tarot_liquidity_pools') }}
|
||||
group by all
|
||||
|
||||
),
|
||||
log_pull 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 sender,
|
||||
CONCAT('0x', SUBSTR(topics[2] :: STRING, 27, 40)) AS borrower,
|
||||
CONCAT('0x', SUBSTR(topics[3] :: STRING, 27, 40)) AS liquidator,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
) :: INTEGER AS seizeTokens_raw,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [1] :: STRING
|
||||
) :: INTEGER AS repayAmount_raw,
|
||||
modified_timestamp AS _inserted_timestamp,
|
||||
CONCAT(
|
||||
tx_hash :: STRING,
|
||||
'-',
|
||||
event_index :: STRING
|
||||
) AS _log_id
|
||||
from
|
||||
{{ ref('core__fact_event_logs') }} l
|
||||
WHERE
|
||||
contract_address IN (SELECT TOKEN_ADDRESS FROM asset_details)
|
||||
AND
|
||||
topics [0] :: STRING = '0xb0dbe18c6ffdf0da655dd690e77211d379205c497be44c64447c3f5f021b5167'
|
||||
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 %}
|
||||
)
|
||||
select
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
borrower,
|
||||
a.token_address as token,
|
||||
'bTarot' AS token_symbol,
|
||||
liquidator,
|
||||
seizeTokens_raw / pow(
|
||||
10,
|
||||
18
|
||||
) AS tokens_seized,--cTarot amount, which is based on the amount of LP tokens deposited
|
||||
contract_address as protocol_market,
|
||||
'cTarot' AS collateral_token_symbol,
|
||||
a.lp_token_address AS collateral_token,
|
||||
a.lp_token_symbol AS collateral_symbol,
|
||||
repayAmount_raw AS amount_unadj,
|
||||
repayAmount_raw / pow(
|
||||
10,
|
||||
a.underlying_decimals
|
||||
) AS amount,
|
||||
a.underlying_asset_address as liquidation_contract_address,
|
||||
a.underlying_asset_symbol as liquidation_contract_symbol,
|
||||
'Tarot' as platform,
|
||||
_inserted_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
log_pull l
|
||||
LEFT JOIN
|
||||
asset_details a
|
||||
ON
|
||||
a.token_address = l.contract_address qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,56 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__tarot_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
|
||||
@ -1,111 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['silver','defi','lending','curated']
|
||||
) }}
|
||||
|
||||
WITH factory_pull AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS vtarot,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS token0,
|
||||
CONCAT('0x', SUBSTR(topics [3] :: STRING, 27, 40)) AS token1,
|
||||
CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS ctarot,
|
||||
CONCAT('0x', SUBSTR(segmented_data [1] :: STRING, 25, 40)) AS borrowable1,
|
||||
CONCAT('0x', SUBSTR(segmented_data [2] :: STRING, 25, 40)) AS borrowable2,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [3] :: STRING
|
||||
) :: INTEGER AS lendingpoolId,
|
||||
modified_timestamp AS _inserted_timestamp,
|
||||
CONCAT(
|
||||
tx_hash :: STRING,
|
||||
'-',
|
||||
event_index :: STRING
|
||||
) AS _log_id
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
WHERE
|
||||
contract_address = LOWER('0xD7cABeF2c1fD77a31c5ba97C724B82d3e25fC83C')
|
||||
AND topics [0] = '0x4c3ab495dc8ebd1b2f3232d7632e54411bc7e4d111475e7fbbd5547d9a28c495'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
),
|
||||
lp_token_pull AS (
|
||||
SELECT
|
||||
t.tx_hash,
|
||||
C.*
|
||||
FROM
|
||||
{{ ref('core__fact_traces') }}
|
||||
t
|
||||
LEFT JOIN {{ ref('silver__contracts') }} C
|
||||
ON to_address = contract_address
|
||||
WHERE
|
||||
block_timestamp >= (
|
||||
SELECT
|
||||
MIN(block_timestamp)
|
||||
FROM
|
||||
factory_pull
|
||||
)
|
||||
AND t.tx_hash IN (
|
||||
SELECT
|
||||
tx_hash
|
||||
FROM
|
||||
factory_pull
|
||||
)
|
||||
AND concat_ws(
|
||||
'_',
|
||||
TYPE,
|
||||
trace_address
|
||||
) = 'STATICCALL_3_1_0'
|
||||
)
|
||||
SELECT
|
||||
l.tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
lp.contract_address AS lp_token_address,
|
||||
lp.token_name AS lp_token_name,
|
||||
lp.token_symbol AS lp_token_symbol,
|
||||
lp.token_decimals AS lp_token_decimals,
|
||||
vtarot,
|
||||
token0,
|
||||
c1.token_name AS token0_name,
|
||||
c1.token_symbol AS token0_symbol,
|
||||
c1.token_decimals AS token0_decimals,
|
||||
token1,
|
||||
c2.token_name AS token1_name,
|
||||
c2.token_symbol AS token1_symbol,
|
||||
c2.token_decimals AS token1_decimals,
|
||||
ctarot,
|
||||
borrowable1,
|
||||
borrowable2,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [3] :: STRING
|
||||
) :: INTEGER AS lendingpoolId,
|
||||
l._inserted_timestamp,
|
||||
l._log_id
|
||||
FROM
|
||||
factory_pull l
|
||||
LEFT JOIN {{ ref('silver__contracts') }}
|
||||
c1
|
||||
ON l.token0 = c1.contract_address
|
||||
LEFT JOIN {{ ref('silver__contracts') }}
|
||||
c2
|
||||
ON l.token1 = c2.contract_address
|
||||
LEFT JOIN lp_token_pull lp
|
||||
ON l.tx_hash = lp.tx_hash
|
||||
WHERE
|
||||
borrowable2 <> lower('0xdf0157559D0eED9e5feC814084f159Ae35b9F3Bb') --likely some dev token
|
||||
@ -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 asset_details AS (
|
||||
|
||||
SELECT
|
||||
borrowable1 AS token_address,
|
||||
token0 AS underlying_asset_address,
|
||||
token0_name AS underlying_asset_name,
|
||||
token0_symbol AS underlying_asset_symbol,
|
||||
token0_decimals AS underlying_decimals
|
||||
FROM
|
||||
{{ ref('silver__tarot_liquidity_pools') }}
|
||||
GROUP BY
|
||||
ALL
|
||||
UNION ALL
|
||||
SELECT
|
||||
borrowable2 AS token_address,
|
||||
token1 AS underlying_asset_address,
|
||||
token1_name AS underlying_asset_name,
|
||||
token1_symbol AS underlying_asset_symbol,
|
||||
token1_decimals AS underlying_decimals
|
||||
FROM
|
||||
{{ ref('silver__tarot_liquidity_pools') }}
|
||||
GROUP BY
|
||||
ALL
|
||||
),
|
||||
log_pull 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 [2] :: STRING, 25, 40)) AS borrower,
|
||||
CONCAT('0x', SUBSTR(topics [3] :: STRING, 25, 40)) AS payer,
|
||||
TRY_TO_NUMBER(
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [1] :: STRING
|
||||
)) AS repay_amount_raw,
|
||||
modified_timestamp AS _inserted_timestamp,
|
||||
CONCAT(
|
||||
tx_hash :: STRING,
|
||||
'-',
|
||||
event_index :: STRING
|
||||
) AS _log_id
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
l
|
||||
WHERE
|
||||
contract_address IN (
|
||||
SELECT
|
||||
token_address
|
||||
FROM
|
||||
asset_details
|
||||
)
|
||||
AND topics [0] :: STRING = '0x33f3048bd4e6af45e53afb722adfd57dbde82da7e93e44db921fb4b8c6a70c4b'
|
||||
AND tx_succeeded
|
||||
AND repay_amount_raw > 0 --borrow and repay in same log event, value in segmented data determines what kind of event
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
borrower,
|
||||
A.token_address AS token_address,
|
||||
'bTAROT' AS token_symbol,
|
||||
underlying_asset_address AS repay_contract_address,
|
||||
underlying_asset_symbol AS repay_contract_symbol,
|
||||
repay_amount_raw AS amount_unadj,
|
||||
repay_amount_raw / pow(
|
||||
10,
|
||||
underlying_decimals
|
||||
) AS amount,
|
||||
payer,
|
||||
'Tarot' AS platform,
|
||||
_inserted_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
log_pull l
|
||||
LEFT JOIN asset_details A
|
||||
ON A.token_address = l.contract_address qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,44 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__tarot_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
|
||||
@ -1,98 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['silver','defi','lending','curated']
|
||||
) }}
|
||||
|
||||
with asset_details as (
|
||||
|
||||
select
|
||||
borrowable1 as token_address,
|
||||
token0 as underlying_asset_address,
|
||||
token0_symbol as underlying_asset_symbol,
|
||||
token0_decimals as underlying_decimals
|
||||
from
|
||||
{{ ref('silver__tarot_liquidity_pools') }}
|
||||
group by all
|
||||
UNION ALL
|
||||
select
|
||||
borrowable2 as token_address,
|
||||
token1 as underlying_asset_address,
|
||||
token1_symbol as underlying_asset_symbol,
|
||||
token1_decimals as underlying_decimals
|
||||
from
|
||||
{{ ref('silver__tarot_liquidity_pools') }}
|
||||
group by all
|
||||
|
||||
),
|
||||
log_pull 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, 25, 40)) AS sender,
|
||||
CONCAT('0x', SUBSTR(topics[2] :: STRING, 25, 40)) AS redeemer,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
) :: INTEGER AS redeemAmount_raw,
|
||||
modified_timestamp AS _inserted_timestamp,
|
||||
CONCAT(
|
||||
tx_hash :: STRING,
|
||||
'-',
|
||||
event_index :: STRING
|
||||
) AS _log_id
|
||||
from
|
||||
{{ ref('core__fact_event_logs') }} l
|
||||
WHERE
|
||||
contract_address IN (SELECT TOKEN_ADDRESS FROM asset_details)
|
||||
AND
|
||||
topics [0] :: STRING = '0x3f693fff038bb8a046aa76d9516190ac7444f7d69cf952c4cbdc086fdef2d6fc'
|
||||
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 %}
|
||||
)
|
||||
select
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
a.token_address,
|
||||
'bTAROT' AS token_symbol,
|
||||
redeemAmount_raw AS amount_unadj,
|
||||
redeemAmount_raw / pow(
|
||||
10,
|
||||
underlying_decimals
|
||||
) AS amount,
|
||||
underlying_asset_address as received_contract_address,
|
||||
underlying_asset_symbol as received_contract_symbol,
|
||||
redeemer,
|
||||
'Tarot' as platform,
|
||||
_inserted_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
log_pull l
|
||||
LEFT JOIN
|
||||
asset_details a
|
||||
ON
|
||||
a.token_address = l.contract_address qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,47 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__tarot_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
|
||||
@ -1,3 +1,3 @@
|
||||
packages:
|
||||
- git: https://github.com/FlipsideCrypto/fsc-evm.git
|
||||
revision: v4.22.1
|
||||
revision: v4.25.0
|
||||
|
||||
Loading…
Reference in New Issue
Block a user