mirror of
https://github.com/FlipsideCrypto/ethereum-models.git
synced 2026-02-06 14:06:53 +00:00
AN-6419/fsc-evm-lending-consolidation (#1136)
* remove repo models * update nft model ref * update package * remove fusion package * revert git ignore
This commit is contained in:
parent
92a7cb8520
commit
62540ca4cb
2
.gitignore
vendored
2
.gitignore
vendored
@ -17,4 +17,4 @@ logs/
|
||||
.env
|
||||
.user.yml
|
||||
dbt-env/
|
||||
/package-lock.yml
|
||||
/package-lock.yml
|
||||
|
||||
@ -113,6 +113,8 @@ models:
|
||||
+enabled: true
|
||||
dex:
|
||||
+enabled: true
|
||||
lending:
|
||||
+enabled: true
|
||||
stats:
|
||||
+enabled: true
|
||||
scores_package:
|
||||
|
||||
@ -1,38 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
persist_docs ={ "relation": true,
|
||||
"columns": true },
|
||||
meta={
|
||||
'database_tags':{
|
||||
'table': {
|
||||
'PROTOCOL': 'AAVE, COMPOUND, CREAM, FLUX, FRAXLEND, MORPHO, RADIANT, SILO, SPARK, STRIKE, STURDY, UWU',
|
||||
'PURPOSE': 'LENDING, BORROWS'
|
||||
}
|
||||
}
|
||||
},
|
||||
tags = ['gold','defi','lending','curated','ez']
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
contract_address,
|
||||
event_name,
|
||||
event_index,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
platform,
|
||||
protocol_market,
|
||||
borrower,
|
||||
token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
amount_usd,
|
||||
complete_lending_borrows_id AS ez_lending_borrows_id,
|
||||
inserted_timestamp,
|
||||
modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver__complete_lending_borrows') }}
|
||||
@ -1,38 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
persist_docs ={ "relation": true,
|
||||
"columns": true },
|
||||
meta={
|
||||
'database_tags':{
|
||||
'table': {
|
||||
'PROTOCOL': 'AAVE, COMPOUND, CREAM, FLUX, FRAXLEND, MORPHO, RADIANT, SILO, SPARK, STRIKE, STURDY, UWU',
|
||||
'PURPOSE': 'LENDING, DEPOSITS'
|
||||
}
|
||||
}
|
||||
},
|
||||
tags = ['gold','defi','lending','curated','ez']
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
contract_address,
|
||||
event_name,
|
||||
event_index,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
platform,
|
||||
protocol_market,
|
||||
depositor,
|
||||
token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
amount_usd,
|
||||
complete_lending_deposits_id AS ez_lending_deposits_id,
|
||||
inserted_timestamp,
|
||||
modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver__complete_lending_deposits') }}
|
||||
@ -1,42 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
persist_docs ={ "relation": true,
|
||||
"columns": true },
|
||||
meta={
|
||||
'database_tags':{
|
||||
'table': {
|
||||
'PROTOCOL': 'AAVE, RADIANT, MORPHO, SPARK, UWU',
|
||||
'PURPOSE': 'LENDING, FLASHLOANS'
|
||||
}
|
||||
}
|
||||
},
|
||||
tags = ['gold','defi','lending','curated','ez']
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
contract_address,
|
||||
event_name,
|
||||
event_index,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
platform,
|
||||
initiator,
|
||||
target,
|
||||
protocol_market,
|
||||
flashloan_token,
|
||||
flashloan_token_symbol,
|
||||
flashloan_amount_unadj,
|
||||
flashloan_amount,
|
||||
flashloan_amount_usd,
|
||||
premium_amount_unadj,
|
||||
premium_amount,
|
||||
premium_amount_usd,
|
||||
complete_lending_flashloans_id AS ez_lending_flashloans_id,
|
||||
inserted_timestamp,
|
||||
modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver__complete_lending_flashloans') }}
|
||||
@ -1,41 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
persist_docs ={ "relation": true,
|
||||
"columns": true },
|
||||
meta={
|
||||
'database_tags':{
|
||||
'table': {
|
||||
'PROTOCOL': 'AAVE, COMPOUND, CREAM, FLUX, FRAXLEND, MORPHO, RADIANT, SILO, SPARK, STRIKE, STURDY, UWU',
|
||||
'PURPOSE': 'LENDING, LIQUIDATIONS'
|
||||
}
|
||||
}
|
||||
},
|
||||
tags = ['gold','defi','lending','curated','ez']
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
contract_address,
|
||||
event_name,
|
||||
event_index,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
platform,
|
||||
liquidator,
|
||||
borrower,
|
||||
protocol_market,
|
||||
collateral_token,
|
||||
collateral_token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
amount_usd,
|
||||
debt_token,
|
||||
debt_token_symbol,
|
||||
complete_lending_liquidations_id AS ez_lending_liquidations_id,
|
||||
inserted_timestamp,
|
||||
modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver__complete_lending_liquidations') }}
|
||||
@ -1,39 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
persist_docs ={ "relation": true,
|
||||
"columns": true },
|
||||
meta={
|
||||
'database_tags':{
|
||||
'table': {
|
||||
'PROTOCOL': 'AAVE, COMPOUND, CREAM, FLUX, FRAXLEND, MORPHO, RADIANT, SILO, SPARK, STRIKE, STURDY, UWU',
|
||||
'PURPOSE': 'LENDING, REPAYMENTS'
|
||||
}
|
||||
}
|
||||
},
|
||||
tags = ['gold','defi','lending','curated','ez']
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
tx_hash,
|
||||
event_index,
|
||||
contract_address,
|
||||
event_name,
|
||||
platform,
|
||||
payer,
|
||||
borrower,
|
||||
protocol_market,
|
||||
token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
amount_usd,
|
||||
complete_lending_repayments_id AS ez_lending_repayments_id,
|
||||
inserted_timestamp,
|
||||
modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver__complete_lending_repayments') }}
|
||||
@ -1,38 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
persist_docs ={ "relation": true,
|
||||
"columns": true },
|
||||
meta={
|
||||
'database_tags':{
|
||||
'table': {
|
||||
'PROTOCOL': 'AAVE, COMPOUND, CREAM, FLUX, FRAXLEND, MORPHO, RADIANT, SILO, SPARK, STRIKE, STURDY, UWU',
|
||||
'PURPOSE': 'LENDING, WITHDRAWS'
|
||||
}
|
||||
}
|
||||
},
|
||||
tags = ['gold','defi','lending','curated','ez']
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
contract_address,
|
||||
event_name,
|
||||
event_index,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
platform,
|
||||
depositor,
|
||||
protocol_market,
|
||||
token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
amount_usd,
|
||||
complete_lending_withdraws_id AS ez_lending_withdraws_id,
|
||||
inserted_timestamp,
|
||||
modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver__complete_lending_withdraws') }}
|
||||
@ -1,239 +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,
|
||||
CASE
|
||||
WHEN topics [0] :: STRING = '0xc6a898309e823ee50bac64e45ca8adba6690e99e7841c45d754e2a38e9019d9b' THEN CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40))
|
||||
WHEN topics [0] :: STRING = '0x1e77446728e5558aa1b7e81e0cdab9cc1b075ba893b740600c76a315c2caa553' THEN CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40))
|
||||
WHEN topics [0] :: STRING = '0xb3d084820fb1a9decffb176436bd02558d15fac9b0ddfed8c465bc7359d7dce0' THEN CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40))
|
||||
END AS reserve_1,
|
||||
CASE
|
||||
WHEN topics [0] :: STRING = '0xc6a898309e823ee50bac64e45ca8adba6690e99e7841c45d754e2a38e9019d9b' THEN CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40))
|
||||
WHEN topics [0] :: STRING = '0x1e77446728e5558aa1b7e81e0cdab9cc1b075ba893b740600c76a315c2caa553' THEN CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40))
|
||||
WHEN topics [0] :: STRING = '0xb3d084820fb1a9decffb176436bd02558d15fac9b0ddfed8c465bc7359d7dce0' THEN CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40))
|
||||
END AS onBehalfOf,
|
||||
CASE
|
||||
WHEN topics [0] :: STRING = '0xc6a898309e823ee50bac64e45ca8adba6690e99e7841c45d754e2a38e9019d9b' THEN utils.udf_hex_to_int(
|
||||
topics [3] :: STRING
|
||||
) :: INTEGER
|
||||
WHEN topics [0] :: STRING = '0x1e77446728e5558aa1b7e81e0cdab9cc1b075ba893b740600c76a315c2caa553' THEN utils.udf_hex_to_int(
|
||||
topics [3] :: STRING
|
||||
) :: INTEGER
|
||||
WHEN topics [0] :: STRING = '0xb3d084820fb1a9decffb176436bd02558d15fac9b0ddfed8c465bc7359d7dce0' THEN utils.udf_hex_to_int(
|
||||
topics [3] :: STRING
|
||||
) :: INTEGER
|
||||
END AS refferal,
|
||||
CASE
|
||||
WHEN topics [0] :: STRING = '0xc6a898309e823ee50bac64e45ca8adba6690e99e7841c45d754e2a38e9019d9b' THEN CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40))
|
||||
WHEN topics [0] :: STRING = '0xb3d084820fb1a9decffb176436bd02558d15fac9b0ddfed8c465bc7359d7dce0' THEN CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40))
|
||||
END AS userAddress,
|
||||
CASE
|
||||
WHEN topics [0] :: STRING = '0xc6a898309e823ee50bac64e45ca8adba6690e99e7841c45d754e2a38e9019d9b' THEN utils.udf_hex_to_int(
|
||||
segmented_data [1] :: STRING
|
||||
) :: INTEGER
|
||||
WHEN topics [0] :: STRING = '0x1e77446728e5558aa1b7e81e0cdab9cc1b075ba893b740600c76a315c2caa553' THEN utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
) :: INTEGER
|
||||
WHEN topics [0] :: STRING = '0xb3d084820fb1a9decffb176436bd02558d15fac9b0ddfed8c465bc7359d7dce0' THEN utils.udf_hex_to_int(
|
||||
segmented_data [1] :: STRING
|
||||
) :: INTEGER
|
||||
END AS borrow_quantity,
|
||||
CASE
|
||||
WHEN topics [0] :: STRING = '0xc6a898309e823ee50bac64e45ca8adba6690e99e7841c45d754e2a38e9019d9b' THEN utils.udf_hex_to_int(
|
||||
segmented_data [2] :: STRING
|
||||
) :: INTEGER
|
||||
WHEN topics [1] :: STRING = '0x1e77446728e5558aa1b7e81e0cdab9cc1b075ba893b740600c76a315c2caa553' THEN utils.udf_hex_to_int(
|
||||
segmented_data [1] :: STRING
|
||||
) :: INTEGER
|
||||
WHEN topics [1] :: STRING = '0xb3d084820fb1a9decffb176436bd02558d15fac9b0ddfed8c465bc7359d7dce0' THEN utils.udf_hex_to_int(
|
||||
segmented_data [2] :: STRING
|
||||
) :: INTEGER
|
||||
END AS borrow_rate_mode,
|
||||
CASE
|
||||
WHEN topics [0] :: STRING = '0xc6a898309e823ee50bac64e45ca8adba6690e99e7841c45d754e2a38e9019d9b' THEN utils.udf_hex_to_int(
|
||||
segmented_data [3] :: STRING
|
||||
) :: INTEGER
|
||||
WHEN topics [0] :: STRING = '0x1e77446728e5558aa1b7e81e0cdab9cc1b075ba893b740600c76a315c2caa553' THEN utils.udf_hex_to_int(
|
||||
segmented_data [2] :: STRING
|
||||
) :: INTEGER
|
||||
WHEN topics [0] :: STRING = '0xb3d084820fb1a9decffb176436bd02558d15fac9b0ddfed8c465bc7359d7dce0' THEN utils.udf_hex_to_int(
|
||||
segmented_data [3] :: STRING
|
||||
) :: INTEGER
|
||||
END AS borrowrate,
|
||||
modified_timestamp AS _inserted_timestamp,
|
||||
CONCAT(
|
||||
tx_hash :: STRING,
|
||||
'-',
|
||||
event_index :: STRING
|
||||
) AS _log_id,
|
||||
CASE
|
||||
WHEN contract_address = LOWER('0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9') THEN 'Aave V2'
|
||||
WHEN contract_address = LOWER('0x398eC7346DcD622eDc5ae82352F02bE94C62d119') THEN 'Aave V1'
|
||||
WHEN contract_address = LOWER('0x7937d4799803fbbe595ed57278bc4ca21f3bffcb') THEN 'Aave AMM'
|
||||
WHEN contract_address = LOWER('0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2') 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,
|
||||
CASE
|
||||
WHEN reserve_1 = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' THEN '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
|
||||
ELSE reserve_1
|
||||
END AS aave_market
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
WHERE
|
||||
topics [0] :: STRING IN (
|
||||
'0xc6a898309e823ee50bac64e45ca8adba6690e99e7841c45d754e2a38e9019d9b',
|
||||
'0x1e77446728e5558aa1b7e81e0cdab9cc1b075ba893b740600c76a315c2caa553',
|
||||
'0xb3d084820fb1a9decffb176436bd02558d15fac9b0ddfed8c465bc7359d7dce0'
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
AND contract_address IN(
|
||||
--Aave V2 LendingPool contract address
|
||||
LOWER('0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9'),
|
||||
--V2
|
||||
LOWER('0x398eC7346DcD622eDc5ae82352F02bE94C62d119'),
|
||||
--V1
|
||||
LOWER('0x7937d4799803fbbe595ed57278bc4ca21f3bffcb'),
|
||||
--AMM
|
||||
LOWER('0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2') --v3
|
||||
)
|
||||
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') }}
|
||||
),
|
||||
atoken_prices AS (
|
||||
SELECT
|
||||
HOUR as prices_hour,
|
||||
token_address as underlying_address,
|
||||
symbol,
|
||||
NAME,
|
||||
decimals,
|
||||
price as hourly_price,
|
||||
blockchain,
|
||||
is_native,
|
||||
is_imputed,
|
||||
is_deprecated,
|
||||
inserted_timestamp,
|
||||
modified_timestamp
|
||||
FROM
|
||||
{{ ref('price__ez_prices_hourly') }}
|
||||
WHERE
|
||||
HOUR :: DATE IN (
|
||||
SELECT
|
||||
DISTINCT block_timestamp :: DATE
|
||||
FROM
|
||||
borrow
|
||||
)
|
||||
AND
|
||||
token_address IN (
|
||||
SELECT
|
||||
aave_market
|
||||
FROM
|
||||
borrow
|
||||
)
|
||||
|
||||
)
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
borrow_quantity AS borrowed_tokens_unadj,
|
||||
LOWER(
|
||||
aave_market
|
||||
) AS aave_market,
|
||||
LOWER(
|
||||
atoken_meta.atoken_address
|
||||
) AS aave_token,
|
||||
borrow_quantity / pow(
|
||||
10,
|
||||
atoken_meta.underlying_decimals
|
||||
) AS borrowed_tokens,
|
||||
borrow_quantity * hourly_price / pow(
|
||||
10,
|
||||
atoken_meta.underlying_decimals
|
||||
) AS borrowed_usd,
|
||||
LOWER(
|
||||
borrower_address
|
||||
) AS borrower_address,
|
||||
CASE
|
||||
WHEN borrow_rate_mode = 2 THEN 'Variable Rate'
|
||||
ELSE 'Stable Rate'
|
||||
END AS borrow_rate_mode,
|
||||
LOWER(
|
||||
lending_pool_contract
|
||||
) AS lending_pool_contract,
|
||||
aave_version,
|
||||
hourly_price AS token_price,
|
||||
atoken_meta.underlying_symbol AS symbol,
|
||||
'ethereum' AS blockchain,
|
||||
_log_id,
|
||||
_inserted_timestamp,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash', 'event_index']
|
||||
) }} AS aave_borrows_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
borrow
|
||||
LEFT JOIN atoken_meta
|
||||
ON borrow.aave_market = atoken_meta.underlying_address
|
||||
AND atoken_version = aave_version
|
||||
LEFT JOIN atoken_prices
|
||||
ON DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = prices_hour
|
||||
AND borrow.aave_market = atoken_prices.underlying_address qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,58 +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
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 3
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: AAVE_MARKET
|
||||
tests:
|
||||
- not_null
|
||||
# - name: BORROWED_TOKENS
|
||||
# tests:
|
||||
# - not_null
|
||||
- name: BORROWED_USD
|
||||
tests:
|
||||
- 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: AAVE_VERSION
|
||||
tests:
|
||||
- not_null
|
||||
- name: TOKEN_PRICE
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: SYMBOL
|
||||
- name: BLOCKCHAIN
|
||||
tests:
|
||||
- not_null
|
||||
@ -1,199 +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 reserve_1,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS onBehalfOf,
|
||||
utils.udf_hex_to_int(
|
||||
topics [3] :: STRING
|
||||
) :: INTEGER AS refferal,
|
||||
CASE
|
||||
WHEN topics [0] :: STRING = '0xde6857219544bb5b7746f48ed30be6386fefc61b2f864cacf559893bf50fd951' THEN CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40))
|
||||
WHEN topics [0] :: STRING = '0xc12c57b1c73a2c3a2ea4613e9476abb3d8d146857aab7329e24243fb59710c82' THEN CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40))
|
||||
WHEN topics [0] :: STRING = '0x2b627736bca15cd5381dcf80b0bf11fd197d01a037c52b927a881a10fb73ba61' THEN CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 42))
|
||||
END AS userAddress,
|
||||
CASE
|
||||
WHEN topics [0] :: STRING = '0xde6857219544bb5b7746f48ed30be6386fefc61b2f864cacf559893bf50fd951' THEN utils.udf_hex_to_int(
|
||||
segmented_data [1] :: STRING
|
||||
) :: INTEGER
|
||||
WHEN topics [0] :: STRING = '0xc12c57b1c73a2c3a2ea4613e9476abb3d8d146857aab7329e24243fb59710c82' THEN utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
) :: INTEGER
|
||||
WHEN topics [0] :: STRING = '0x2b627736bca15cd5381dcf80b0bf11fd197d01a037c52b927a881a10fb73ba61' THEN utils.udf_hex_to_int(
|
||||
segmented_data [1] :: STRING
|
||||
) :: INTEGER
|
||||
END AS deposit_quantity,
|
||||
CASE
|
||||
WHEN contract_address = LOWER('0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9') THEN 'Aave V2'
|
||||
WHEN contract_address = LOWER('0x398eC7346DcD622eDc5ae82352F02bE94C62d119') THEN 'Aave V1'
|
||||
WHEN contract_address = LOWER('0x7937d4799803fbbe595ed57278bc4ca21f3bffcb') THEN 'Aave AMM'
|
||||
WHEN contract_address = LOWER('0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2') 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,
|
||||
CASE
|
||||
WHEN reserve_1 = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' THEN '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
|
||||
ELSE reserve_1
|
||||
END AS aave_market,
|
||||
CONCAT(
|
||||
tx_hash :: STRING,
|
||||
'-',
|
||||
event_index :: STRING
|
||||
) AS _log_id,
|
||||
modified_timestamp AS _inserted_timestamp
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
WHERE
|
||||
topics [0] :: STRING IN (
|
||||
'0xde6857219544bb5b7746f48ed30be6386fefc61b2f864cacf559893bf50fd951',
|
||||
'0xc12c57b1c73a2c3a2ea4613e9476abb3d8d146857aab7329e24243fb59710c82',
|
||||
'0x2b627736bca15cd5381dcf80b0bf11fd197d01a037c52b927a881a10fb73ba61'
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
AND contract_address IN(
|
||||
--Aave V2 LendingPool contract address
|
||||
LOWER('0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9'),
|
||||
--V2
|
||||
LOWER('0x398eC7346DcD622eDc5ae82352F02bE94C62d119'),
|
||||
--V1
|
||||
LOWER('0x7937d4799803fbbe595ed57278bc4ca21f3bffcb'),
|
||||
--AMM
|
||||
LOWER('0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2') --v3
|
||||
)
|
||||
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') }}
|
||||
),
|
||||
atoken_prices AS (
|
||||
SELECT
|
||||
HOUR as prices_hour,
|
||||
token_address as underlying_address,
|
||||
symbol,
|
||||
NAME,
|
||||
decimals,
|
||||
price as hourly_price,
|
||||
blockchain,
|
||||
is_native,
|
||||
is_imputed,
|
||||
is_deprecated,
|
||||
inserted_timestamp,
|
||||
modified_timestamp
|
||||
FROM
|
||||
{{ ref('price__ez_prices_hourly') }}
|
||||
WHERE
|
||||
HOUR :: DATE IN (
|
||||
SELECT
|
||||
DISTINCT block_timestamp :: DATE
|
||||
FROM
|
||||
deposits
|
||||
)
|
||||
AND
|
||||
token_address IN (
|
||||
SELECT
|
||||
aave_market
|
||||
FROM
|
||||
deposits
|
||||
)
|
||||
|
||||
)
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
LOWER(
|
||||
aave_market
|
||||
) AS aave_market,
|
||||
LOWER(
|
||||
atoken_meta.atoken_address
|
||||
) AS aave_token,
|
||||
deposit_quantity AS issued_tokens_unadj,
|
||||
deposit_quantity / pow(
|
||||
10,
|
||||
atoken_meta.underlying_decimals
|
||||
) AS issued_tokens,
|
||||
(
|
||||
deposit_quantity * hourly_price
|
||||
) / pow(
|
||||
10,
|
||||
atoken_meta.underlying_decimals
|
||||
) AS supplied_usd,
|
||||
LOWER(
|
||||
depositor_address
|
||||
) AS depositor_address,
|
||||
LOWER(
|
||||
lending_pool_contract
|
||||
) AS lending_pool_contract,
|
||||
aave_version,
|
||||
hourly_price AS token_price,
|
||||
atoken_meta.underlying_symbol AS symbol,
|
||||
'ethereum' AS blockchain,
|
||||
_log_id,
|
||||
_inserted_timestamp,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash', 'event_index']
|
||||
) }} AS aave_deposits_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
deposits
|
||||
LEFT JOIN atoken_meta
|
||||
ON deposits.aave_market = atoken_meta.underlying_address
|
||||
AND atoken_version = aave_version
|
||||
LEFT JOIN atoken_prices
|
||||
ON DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = prices_hour
|
||||
AND deposits.aave_market = atoken_prices.underlying_address qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,59 +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
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 3
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: SUPPLIED_USD
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: ISSUED_TOKENS
|
||||
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:
|
||||
where: block_number <> 18018450
|
||||
- name: AAVE_VERSION
|
||||
tests:
|
||||
- not_null
|
||||
- name: TOKEN_PRICE
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: SYMBOL
|
||||
@ -1,217 +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,
|
||||
CASE
|
||||
WHEN topics [0] :: STRING = '0x631042c832b07452973831137f2d73e395028b44b250dedc5abb0ee766e168ac' THEN CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40))
|
||||
WHEN topics [0] :: STRING = '0xefefaba5e921573100900a3ad9cf29f222d995fb3b6045797eaea7521bd8d6f0'
|
||||
AND origin_to_address IS NULL THEN CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 27, 40))
|
||||
WHEN topics [0] :: STRING = '0xefefaba5e921573100900a3ad9cf29f222d995fb3b6045797eaea7521bd8d6f0' THEN origin_to_address
|
||||
ELSE origin_from_address
|
||||
END AS initiator_address,
|
||||
CASE
|
||||
WHEN topics [0] :: STRING = '0x631042c832b07452973831137f2d73e395028b44b250dedc5abb0ee766e168ac' THEN CONCAT('0x', SUBSTR(topics [3] :: STRING, 27, 40))
|
||||
WHEN topics [0] :: STRING = '0x5b8f46461c1dd69fb968f1a003acee221ea3e19540e350233b612ddb43433b55' THEN CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40))
|
||||
WHEN topics [0] :: STRING = '0xefefaba5e921573100900a3ad9cf29f222d995fb3b6045797eaea7521bd8d6f0' THEN CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40))
|
||||
END AS asset_1,
|
||||
CASE
|
||||
WHEN topics [0] :: STRING = '0xefefaba5e921573100900a3ad9cf29f222d995fb3b6045797eaea7521bd8d6f0' THEN utils.udf_hex_to_int(
|
||||
segmented_data [1] :: STRING
|
||||
) :: INTEGER
|
||||
ELSE utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
) :: INTEGER
|
||||
END AS flashloan_quantity,
|
||||
CASE
|
||||
WHEN topics [0] :: STRING = '0xefefaba5e921573100900a3ad9cf29f222d995fb3b6045797eaea7521bd8d6f0' THEN utils.udf_hex_to_int(
|
||||
segmented_data [3] :: STRING
|
||||
) :: INTEGER
|
||||
ELSE utils.udf_hex_to_int(
|
||||
segmented_data [1] :: STRING
|
||||
) :: INTEGER
|
||||
END AS premium_quantity,
|
||||
CASE
|
||||
WHEN topics [0] :: STRING = '0xefefaba5e921573100900a3ad9cf29f222d995fb3b6045797eaea7521bd8d6f0' THEN utils.udf_hex_to_int(
|
||||
topics [3] :: STRING
|
||||
) :: INTEGER
|
||||
ELSE utils.udf_hex_to_int(
|
||||
segmented_data [2] :: STRING
|
||||
) :: INTEGER
|
||||
END AS refferalCode,
|
||||
CONCAT(
|
||||
tx_hash :: STRING,
|
||||
'-',
|
||||
event_index :: STRING
|
||||
) AS _log_id,
|
||||
modified_timestamp AS _inserted_timestamp,
|
||||
COALESCE(
|
||||
origin_to_address,
|
||||
contract_address
|
||||
) AS lending_pool_contract,
|
||||
CASE
|
||||
WHEN contract_address = LOWER('0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9') THEN 'Aave V2'
|
||||
WHEN contract_address = LOWER('0x398eC7346DcD622eDc5ae82352F02bE94C62d119') THEN 'Aave V1'
|
||||
WHEN contract_address = LOWER('0x7937d4799803fbbe595ed57278bc4ca21f3bffcb') THEN 'Aave AMM'
|
||||
WHEN contract_address = LOWER('0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2') THEN 'Aave V3'
|
||||
ELSE 'ERROR'
|
||||
END AS aave_version,
|
||||
CASE
|
||||
WHEN asset_1 = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' THEN '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
|
||||
ELSE asset_1
|
||||
END AS aave_market
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
WHERE
|
||||
topics [0] :: STRING IN (
|
||||
'0x631042c832b07452973831137f2d73e395028b44b250dedc5abb0ee766e168ac',
|
||||
'0x5b8f46461c1dd69fb968f1a003acee221ea3e19540e350233b612ddb43433b55',
|
||||
'0xefefaba5e921573100900a3ad9cf29f222d995fb3b6045797eaea7521bd8d6f0'
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
AND contract_address IN(
|
||||
--Aave V2 LendingPool contract address
|
||||
LOWER('0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9'),
|
||||
--V2
|
||||
LOWER('0x398eC7346DcD622eDc5ae82352F02bE94C62d119'),
|
||||
--V1
|
||||
LOWER('0x7937d4799803fbbe595ed57278bc4ca21f3bffcb'),
|
||||
--AMM
|
||||
LOWER('0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2') --v3
|
||||
)
|
||||
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') }}
|
||||
),
|
||||
atoken_prices AS (
|
||||
SELECT
|
||||
HOUR as prices_hour,
|
||||
token_address as underlying_address,
|
||||
symbol,
|
||||
NAME,
|
||||
decimals,
|
||||
price as hourly_price,
|
||||
blockchain,
|
||||
is_native,
|
||||
is_imputed,
|
||||
is_deprecated,
|
||||
inserted_timestamp,
|
||||
modified_timestamp
|
||||
FROM
|
||||
{{ ref('price__ez_prices_hourly') }}
|
||||
WHERE
|
||||
HOUR :: DATE IN (
|
||||
SELECT
|
||||
DISTINCT block_timestamp :: DATE
|
||||
FROM
|
||||
flashloan
|
||||
)
|
||||
AND
|
||||
token_address IN (
|
||||
SELECT
|
||||
aave_market
|
||||
FROM
|
||||
flashloan
|
||||
)
|
||||
|
||||
)
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
LOWER(
|
||||
aave_market
|
||||
) AS aave_market,
|
||||
LOWER(
|
||||
atoken_meta.atoken_address
|
||||
) AS aave_token,
|
||||
flashloan_quantity AS flashloan_amount_unadj,
|
||||
flashloan_quantity / pow(
|
||||
10,
|
||||
atoken_meta.underlying_decimals
|
||||
) AS flashloan_amount,
|
||||
flashloan_quantity * hourly_price / pow(
|
||||
10,
|
||||
atoken_meta.underlying_decimals
|
||||
) AS flashloan_amount_usd,
|
||||
premium_quantity AS premium_amount_unadj,
|
||||
premium_quantity / pow(
|
||||
10,
|
||||
atoken_meta.underlying_decimals
|
||||
) AS premium_amount,
|
||||
premium_quantity * hourly_price / pow(
|
||||
10,
|
||||
atoken_meta.underlying_decimals
|
||||
) AS premium_amount_usd,
|
||||
LOWER(initiator_address) AS initiator_address,
|
||||
LOWER(target_address) AS target_address,
|
||||
aave_version,
|
||||
hourly_price AS token_price,
|
||||
atoken_meta.underlying_symbol AS symbol,
|
||||
'ethereum' AS blockchain,
|
||||
_log_id,
|
||||
_inserted_timestamp,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash', 'event_index']
|
||||
) }} AS aave_flashloans_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
flashloan
|
||||
LEFT JOIN atoken_meta
|
||||
ON flashloan.aave_market = atoken_meta.underlying_address
|
||||
AND atoken_version = aave_version
|
||||
LEFT JOIN atoken_prices
|
||||
ON DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = prices_hour
|
||||
AND flashloan.aave_market = atoken_prices.underlying_address qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,71 +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
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 3
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: AAVE_MARKET
|
||||
tests:
|
||||
- not_null
|
||||
- name: AAVE_TOKEN
|
||||
- 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: PREMIUM_AMOUNT
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: PREMIUM_AMOUNT_USD
|
||||
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: AAVE_VERSION
|
||||
tests:
|
||||
- not_null
|
||||
- name: TOKEN_PRICE
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: SYMBOL
|
||||
@ -1,217 +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 collateralAsset_1,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS debtAsset_1,
|
||||
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,
|
||||
CASE
|
||||
WHEN topics [0] :: STRING = '0xe413a321e8681d831f4dbccbca790d2952b56f977908e45be37335533e005286' THEN CONCAT('0x', SUBSTR(segmented_data [2] :: STRING, 25, 40))
|
||||
ELSE CONCAT('0x', SUBSTR(segmented_data [3] :: STRING, 25, 40))
|
||||
END AS liquidator_address,
|
||||
CONCAT(
|
||||
tx_hash :: STRING,
|
||||
'-',
|
||||
event_index :: STRING
|
||||
) AS _log_id,
|
||||
modified_timestamp AS _inserted_timestamp,
|
||||
CASE
|
||||
WHEN contract_address = LOWER('0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9') THEN 'Aave V2'
|
||||
WHEN contract_address = LOWER('0x398eC7346DcD622eDc5ae82352F02bE94C62d119') THEN 'Aave V1'
|
||||
WHEN contract_address = LOWER('0x7937d4799803fbbe595ed57278bc4ca21f3bffcb') THEN 'Aave AMM'
|
||||
WHEN contract_address = LOWER('0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2') THEN 'Aave V3'
|
||||
ELSE 'ERROR'
|
||||
END AS aave_version,
|
||||
COALESCE(
|
||||
origin_to_address,
|
||||
contract_address
|
||||
) AS lending_pool_contract,
|
||||
CASE
|
||||
WHEN debtAsset_1 = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' THEN '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
|
||||
ELSE debtAsset_1
|
||||
END AS debt_asset,
|
||||
CASE
|
||||
WHEN collateralAsset_1 = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' THEN '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
|
||||
ELSE collateralAsset_1
|
||||
END AS collateral_asset
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
WHERE
|
||||
topics [0] :: STRING IN (
|
||||
'0xe413a321e8681d831f4dbccbca790d2952b56f977908e45be37335533e005286',
|
||||
'0x56864757fd5b1fc9f38f5f3a981cd8ae512ce41b902cf73fc506ee369c6bc237'
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
AND contract_address IN(
|
||||
--Aave V2 LendingPool contract address
|
||||
LOWER('0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9'),
|
||||
--V2
|
||||
LOWER('0x398eC7346DcD622eDc5ae82352F02bE94C62d119'),
|
||||
--V1
|
||||
LOWER('0x7937d4799803fbbe595ed57278bc4ca21f3bffcb'),
|
||||
--AMM
|
||||
LOWER('0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2') --v3
|
||||
)
|
||||
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') }}
|
||||
),
|
||||
atoken_prices AS (
|
||||
SELECT
|
||||
HOUR as prices_hour,
|
||||
token_address as underlying_address,
|
||||
symbol,
|
||||
NAME,
|
||||
decimals,
|
||||
price as hourly_price,
|
||||
blockchain,
|
||||
is_native,
|
||||
is_imputed,
|
||||
is_deprecated,
|
||||
inserted_timestamp,
|
||||
modified_timestamp
|
||||
FROM
|
||||
{{ ref('price__ez_prices_hourly') }}
|
||||
WHERE
|
||||
HOUR :: DATE IN (
|
||||
SELECT
|
||||
DISTINCT block_timestamp :: DATE
|
||||
FROM
|
||||
liquidation
|
||||
)
|
||||
AND
|
||||
token_address IN (
|
||||
SELECT
|
||||
DISTINCT collateral_asset
|
||||
FROM
|
||||
liquidation
|
||||
union all
|
||||
SELECT
|
||||
DISTINCT debt_asset
|
||||
FROM
|
||||
liquidation
|
||||
)
|
||||
|
||||
)
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
LOWER(
|
||||
collateral_asset
|
||||
) AS collateral_asset,
|
||||
LOWER(
|
||||
amc.atoken_address
|
||||
) AS collateral_aave_token,
|
||||
liquidated_amount AS liquidated_amount_unadj,
|
||||
liquidated_amount / pow(
|
||||
10,
|
||||
amc.atoken_decimals
|
||||
) AS liquidated_amount,
|
||||
liquidated_amount * collat.hourly_price / pow(
|
||||
10,
|
||||
amc.atoken_decimals
|
||||
) AS liquidated_amount_usd,
|
||||
LOWER(
|
||||
debt_asset
|
||||
) AS debt_asset,
|
||||
LOWER(
|
||||
amd.atoken_address
|
||||
) AS debt_aave_token,
|
||||
debt_to_cover_amount / pow(
|
||||
10,
|
||||
amd.underlying_decimals
|
||||
) AS debt_to_cover_amount,
|
||||
debt_to_cover_amount * debt.hourly_price / pow(
|
||||
10,
|
||||
amd.underlying_decimals
|
||||
) AS debt_to_cover_amount_usd,
|
||||
liquidator_address AS liquidator,
|
||||
borrower_address AS borrower,
|
||||
aave_version,
|
||||
collat.hourly_price AS collateral_token_price,
|
||||
amc.underlying_symbol AS collateral_token_symbol,
|
||||
debt.hourly_price AS debt_token_price,
|
||||
amd.underlying_symbol AS debt_token_symbol,
|
||||
'ethereum' AS blockchain,
|
||||
_log_id,
|
||||
_inserted_timestamp,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash', 'event_index']
|
||||
) }} AS aave_liquidations_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
liquidation
|
||||
LEFT JOIN atoken_meta amc
|
||||
ON liquidation.collateral_asset = amc.underlying_address
|
||||
AND liquidation.aave_version = amc.atoken_version
|
||||
LEFT JOIN atoken_prices collat
|
||||
ON DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = collat.prices_hour
|
||||
AND liquidation.collateral_asset = collat.underlying_address
|
||||
LEFT JOIN atoken_meta amd
|
||||
ON liquidation.debt_asset = amd.underlying_address
|
||||
AND liquidation.aave_version = amd.atoken_version
|
||||
LEFT JOIN atoken_prices debt
|
||||
ON DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = debt.prices_hour
|
||||
AND liquidation.debt_asset = debt.underlying_address qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,79 +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: LIQUIDATED_AMOUNT
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: LIQUIDATED_AMOUNT_USD
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: DEBT_ASSET
|
||||
tests:
|
||||
- not_null
|
||||
- name: DEBT_AAVE_TOKEN
|
||||
- name: DEBT_TO_COVER_AMOUNT
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: DEBT_TO_COVER_AMOUNT_USD
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: LIQUIDATOR
|
||||
tests:
|
||||
- not_null
|
||||
- name: BORROWER
|
||||
tests:
|
||||
- not_null
|
||||
- name: AAVE_VERSION
|
||||
tests:
|
||||
- not_null
|
||||
- name: COLLATERAL_TOKEN_PRICE
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: COLLATERAL_TOKEN_SYMBOL
|
||||
- name: DEBT_TOKEN_PRICE
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: DEBT_TOKEN_SYMBOL
|
||||
@ -1,181 +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 reserve_1,
|
||||
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,
|
||||
CONCAT(
|
||||
tx_hash :: STRING,
|
||||
'-',
|
||||
event_index :: STRING
|
||||
) AS _log_id,
|
||||
modified_timestamp AS _inserted_timestamp,
|
||||
CASE
|
||||
WHEN contract_address = LOWER('0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9') THEN 'Aave V2'
|
||||
WHEN contract_address = LOWER('0x398eC7346DcD622eDc5ae82352F02bE94C62d119') THEN 'Aave V1'
|
||||
WHEN contract_address = LOWER('0x7937d4799803fbbe595ed57278bc4ca21f3bffcb') THEN 'Aave AMM'
|
||||
WHEN contract_address = LOWER('0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2') 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,
|
||||
CASE
|
||||
WHEN reserve_1 = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' THEN '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
|
||||
ELSE reserve_1
|
||||
END AS aave_market
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
WHERE
|
||||
topics [0] :: STRING IN (
|
||||
'0x4cdde6e09bb755c9a5589ebaec640bbfedff1362d4b255ebf8339782b9942faa',
|
||||
'0xb718f0b14f03d8c3adf35b15e3da52421b042ac879e5a689011a8b1e0036773d',
|
||||
'0xa534c8dbe71f871f9f3530e97a74601fea17b426cae02e1c5aee42c96c784051'
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
AND contract_address IN(
|
||||
--Aave V2 LendingPool contract address
|
||||
LOWER('0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9'),
|
||||
--V2
|
||||
LOWER('0x398eC7346DcD622eDc5ae82352F02bE94C62d119'),
|
||||
--V1
|
||||
LOWER('0x7937d4799803fbbe595ed57278bc4ca21f3bffcb'),
|
||||
--AMM
|
||||
LOWER('0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2') --v3
|
||||
)
|
||||
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') }}
|
||||
),
|
||||
atoken_prices AS (
|
||||
SELECT
|
||||
HOUR as prices_hour,
|
||||
token_address as underlying_address,
|
||||
symbol,
|
||||
NAME,
|
||||
decimals,
|
||||
price as hourly_price,
|
||||
blockchain,
|
||||
is_native,
|
||||
is_imputed,
|
||||
is_deprecated,
|
||||
inserted_timestamp,
|
||||
modified_timestamp
|
||||
FROM
|
||||
{{ ref('price__ez_prices_hourly') }}
|
||||
WHERE
|
||||
HOUR :: DATE IN (
|
||||
SELECT
|
||||
DISTINCT block_timestamp :: DATE
|
||||
FROM
|
||||
repay
|
||||
)
|
||||
AND
|
||||
token_address IN (
|
||||
SELECT
|
||||
aave_market
|
||||
FROM
|
||||
repay
|
||||
)
|
||||
|
||||
)
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
LOWER(
|
||||
aave_market
|
||||
) AS aave_market,
|
||||
LOWER(
|
||||
atoken_meta.atoken_address
|
||||
) AS aave_token,
|
||||
repayed_amount AS repayed_tokens_unadj,
|
||||
repayed_amount / pow(
|
||||
10,
|
||||
atoken_meta.underlying_decimals
|
||||
) AS repayed_tokens,
|
||||
repayed_amount * hourly_price / pow(
|
||||
10,
|
||||
atoken_meta.underlying_decimals
|
||||
) AS repayed_usd,
|
||||
repayer_address AS payer,
|
||||
borrower_address AS borrower,
|
||||
LOWER(
|
||||
lending_pool_contract
|
||||
) AS lending_pool_contract,
|
||||
aave_version,
|
||||
hourly_price AS token_price,
|
||||
atoken_meta.underlying_symbol AS symbol,
|
||||
'ethereum' AS blockchain,
|
||||
_log_id,
|
||||
_inserted_timestamp,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash', 'event_index']
|
||||
) }} AS aave_repayments_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
repay
|
||||
LEFT JOIN atoken_meta
|
||||
ON repay.aave_market = atoken_meta.underlying_address
|
||||
AND atoken_version = aave_version
|
||||
LEFT JOIN atoken_prices
|
||||
ON DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = prices_hour
|
||||
AND repay.aave_market = atoken_prices.underlying_address qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,63 +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
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 3
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: AAVE_MARKET
|
||||
tests:
|
||||
- not_null
|
||||
- name: AAVE_TOKEN
|
||||
- name: REPAYED_TOKENS
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: REPAYED_USD
|
||||
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:
|
||||
where: BLOCK_NUMBER <> 18018450
|
||||
- name: AAVE_VERSION
|
||||
tests:
|
||||
- not_null
|
||||
- name: TOKEN_PRICE
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: SYMBOL
|
||||
@ -1,39 +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
|
||||
- name: ATOKEN_VARIABLE_DEBT_ADDRESS
|
||||
- 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
|
||||
- name: UNDERLYING_NAME
|
||||
tests:
|
||||
- not_null
|
||||
@ -18,6 +18,7 @@ aave_token_pull AS (
|
||||
|
||||
SELECT
|
||||
block_number AS atoken_created_block,
|
||||
contract_address as pool_address,
|
||||
C.symbol AS a_token_symbol,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS a_token_address,
|
||||
@ -70,6 +71,7 @@ aave_token_pull AS (
|
||||
UNION ALL
|
||||
SELECT
|
||||
block_number AS atoken_created_block,
|
||||
contract_address as pool_address,
|
||||
C.symbol AS a_token_symbol,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS a_token_address,
|
||||
@ -1,180 +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 reserve_1,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS useraddress,
|
||||
CASE
|
||||
WHEN topics [0] :: STRING = '0x3115d1449a7b732c986cba18244e897a450f61e1bb8d589cd2e69e6c8924f9f7' THEN CONCAT('0x', SUBSTR(topics [3] :: STRING, 27, 40))
|
||||
ELSE origin_from_address
|
||||
END AS depositor,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
) :: INTEGER AS withdraw_amount,
|
||||
modified_timestamp AS _inserted_timestamp,
|
||||
CONCAT(
|
||||
tx_hash :: STRING,
|
||||
'-',
|
||||
event_index :: STRING
|
||||
) AS _log_id,
|
||||
tx_hash,
|
||||
CASE
|
||||
WHEN contract_address = LOWER('0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9') THEN 'Aave V2'
|
||||
WHEN contract_address = LOWER('0x398eC7346DcD622eDc5ae82352F02bE94C62d119') THEN 'Aave V1'
|
||||
WHEN contract_address = LOWER('0x7937d4799803fbbe595ed57278bc4ca21f3bffcb') THEN 'Aave AMM'
|
||||
WHEN contract_address = LOWER('0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2') THEN 'Aave V3'
|
||||
ELSE 'ERROR'
|
||||
END AS aave_version,
|
||||
COALESCE(
|
||||
origin_to_address,
|
||||
contract_address
|
||||
) AS lending_pool_contract,
|
||||
CASE
|
||||
WHEN reserve_1 = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' THEN '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
|
||||
ELSE reserve_1
|
||||
END AS aave_market
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
WHERE
|
||||
topics [0] :: STRING IN (
|
||||
'0x3115d1449a7b732c986cba18244e897a450f61e1bb8d589cd2e69e6c8924f9f7',
|
||||
'0x9c4ed599cd8555b9c1e8cd7643240d7d71eb76b792948c49fcb4d411f7b6b3c6'
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
AND contract_address IN(
|
||||
--Aave V2 LendingPool contract address
|
||||
LOWER('0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9'),
|
||||
--V2
|
||||
LOWER('0x398eC7346DcD622eDc5ae82352F02bE94C62d119'),
|
||||
--V1
|
||||
LOWER('0x7937d4799803fbbe595ed57278bc4ca21f3bffcb'),
|
||||
--AMM
|
||||
LOWER('0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2') --v3
|
||||
)
|
||||
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') }}
|
||||
),
|
||||
atoken_prices AS (
|
||||
SELECT
|
||||
HOUR as prices_hour,
|
||||
token_address as underlying_address,
|
||||
symbol,
|
||||
NAME,
|
||||
decimals,
|
||||
price as hourly_price,
|
||||
blockchain,
|
||||
is_native,
|
||||
is_imputed,
|
||||
is_deprecated,
|
||||
inserted_timestamp,
|
||||
modified_timestamp
|
||||
FROM
|
||||
{{ ref('price__ez_prices_hourly') }}
|
||||
WHERE
|
||||
HOUR :: DATE IN (
|
||||
SELECT
|
||||
DISTINCT block_timestamp :: DATE
|
||||
FROM
|
||||
withdraw
|
||||
)
|
||||
AND
|
||||
token_address IN (
|
||||
SELECT
|
||||
aave_market
|
||||
FROM
|
||||
withdraw
|
||||
)
|
||||
|
||||
)
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
LOWER(
|
||||
aave_market
|
||||
) AS aave_market,
|
||||
LOWER(
|
||||
atoken_meta.atoken_address
|
||||
) AS aave_token,
|
||||
withdraw_amount AS withdrawn_tokens_unadj,
|
||||
withdraw_amount / pow(
|
||||
10,
|
||||
atoken_meta.underlying_decimals
|
||||
) AS withdrawn_tokens,
|
||||
withdraw_amount * hourly_price / pow(
|
||||
10,
|
||||
atoken_meta.underlying_decimals
|
||||
) AS withdrawn_usd,
|
||||
LOWER(
|
||||
depositor
|
||||
) AS depositor_address,
|
||||
aave_version,
|
||||
hourly_price AS token_price,
|
||||
atoken_meta.underlying_symbol AS symbol,
|
||||
'ethereum' AS blockchain,
|
||||
_log_id,
|
||||
_inserted_timestamp,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash', 'event_index']
|
||||
) }} AS aave_withdraws_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
withdraw
|
||||
LEFT JOIN atoken_meta
|
||||
ON withdraw.aave_market = atoken_meta.underlying_address
|
||||
AND atoken_version = aave_version
|
||||
LEFT JOIN atoken_prices
|
||||
ON DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = prices_hour
|
||||
AND withdraw.aave_market = atoken_prices.underlying_address qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,54 +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
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 3
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: AAVE_MARKET
|
||||
tests:
|
||||
- not_null
|
||||
- name: AAVE_TOKEN
|
||||
- name: WITHDRAWN_TOKENS
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: WITHDRAWN_USD
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: DEPOSITOR_ADDRESS
|
||||
- name: AAVE_VERSION
|
||||
tests:
|
||||
- not_null
|
||||
- name: TOKEN_PRICE
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: SYMBOL
|
||||
@ -1,683 +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,
|
||||
borrowed_tokens_unadj AS amount_unadj,
|
||||
borrowed_tokens AS amount,
|
||||
borrowed_usd AS amount_usd,
|
||||
aave_version AS platform,
|
||||
'ethereum' 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 %}
|
||||
),
|
||||
morpho AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
NULL AS event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
borrower_address AS borrower,
|
||||
contract_address AS protocol_market,
|
||||
market AS token_address,
|
||||
symbol AS token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
NULL AS amount_usd,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
A._ID AS _log_id,
|
||||
A._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__morpho_borrows') }} A
|
||||
|
||||
{% if is_incremental() and 'morpho' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
A._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
spark 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,
|
||||
spark_token AS protocol_market,
|
||||
spark_market AS token_address,
|
||||
symbol AS token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
NULL AS amount_usd,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
A._LOG_ID,
|
||||
A._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__spark_borrows') }} A
|
||||
|
||||
{% if is_incremental() and 'spark' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
A._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
radiant 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,
|
||||
radiant_token AS protocol_market,
|
||||
radiant_market AS token_address,
|
||||
symbol AS token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
NULL AS amount_usd,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
A._LOG_ID,
|
||||
A._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__radiant_borrows') }} A
|
||||
|
||||
{% if is_incremental() and 'radiant' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
A._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
sturdy 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,
|
||||
sturdy_token AS protocol_market,
|
||||
sturdy_market AS token_address,
|
||||
symbol AS token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
NULL AS amount_usd,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
A._LOG_ID,
|
||||
A._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__sturdy_borrows') }} A
|
||||
|
||||
{% if is_incremental() and 'sturdy' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
A._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
uwu 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,
|
||||
uwu_token AS protocol_market,
|
||||
uwu_market AS token_address,
|
||||
symbol AS token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
NULL AS amount_usd,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
A._LOG_ID,
|
||||
A._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__uwu_borrows') }} A
|
||||
|
||||
{% if is_incremental() and 'uwu' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
A._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
flux 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,
|
||||
NULL AS amount_usd,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
A._LOG_ID,
|
||||
A._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__flux_borrows') }} A
|
||||
|
||||
{% if is_incremental() and 'flux' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
A._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
cream 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,
|
||||
NULL AS amount_usd,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
A._LOG_ID,
|
||||
A._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__cream_borrows') }} A
|
||||
|
||||
{% if is_incremental() and 'cream' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
A._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
strike 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,
|
||||
NULL AS amount_usd,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
A._LOG_ID,
|
||||
A._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__strike_borrows') }} A
|
||||
|
||||
{% if is_incremental() and 'strike' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
A._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
silo AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
borrower,
|
||||
silo_market AS protocol_market,
|
||||
token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
NULL AS amount_usd,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
l._LOG_ID,
|
||||
l._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__silo_borrows') }}
|
||||
l
|
||||
|
||||
{% if is_incremental() and 'silo' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
l._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
fraxlend AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
borrower,
|
||||
frax_market_address AS protocol_market,
|
||||
borrow_asset AS token_address,
|
||||
borrow_symbol AS symbol,
|
||||
borrow_amount_unadj AS amount_unadj,
|
||||
borrow_amount AS amount,
|
||||
NULL AS amount_usd,
|
||||
'Fraxlend' AS platform,
|
||||
'ethereum' AS blockchain,
|
||||
A._LOG_ID,
|
||||
A._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__fraxlend_borrows') }} A
|
||||
|
||||
{% if is_incremental() and 'fraxlend' 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,
|
||||
ctoken AS protocol_market,
|
||||
CASE
|
||||
WHEN ctoken_symbol = 'cETH' THEN '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
|
||||
ELSE borrows_contract_address
|
||||
END AS token_address,
|
||||
borrows_contract_symbol AS token_symbol,
|
||||
loan_amount_raw AS amount_unadj,
|
||||
loan_amount AS amount,
|
||||
loan_amount_usd AS amount_usd,
|
||||
compound_version AS platform,
|
||||
'ethereum' AS blockchain,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
{{ ref('silver__comp_borrows') }}
|
||||
|
||||
{% 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 %}
|
||||
),
|
||||
borrow_union AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
aave
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
morpho
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
comp
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
cream
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
flux
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
fraxlend
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
radiant
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
silo
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
spark
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
strike
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
sturdy
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
uwu
|
||||
),
|
||||
complete_lending_borrows AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
borrower,
|
||||
CASE
|
||||
WHEN platform = 'Fraxlend' THEN 'BorrowAsset'
|
||||
WHEN platform = 'Compound V3' THEN 'Withdraw'
|
||||
ELSE 'Borrow'
|
||||
END AS event_name,
|
||||
protocol_market,
|
||||
b.token_address,
|
||||
b.token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
CASE
|
||||
WHEN platform NOT IN (
|
||||
'Aave',
|
||||
'Compound'
|
||||
) THEN ROUND((amount * price), 2)
|
||||
ELSE amount_usd
|
||||
END 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,
|
||||
contract_address,
|
||||
borrower,
|
||||
event_name,
|
||||
protocol_market,
|
||||
t0.token_address,
|
||||
t0.token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
CASE
|
||||
WHEN platform NOT IN (
|
||||
'Aave',
|
||||
'Compound'
|
||||
) THEN ROUND((amount * price), 2)
|
||||
ELSE amount_usd
|
||||
END 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,
|
||||
borrower,
|
||||
event_name,
|
||||
protocol_market,
|
||||
token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
amount_usd_heal AS amount_usd,
|
||||
platform,
|
||||
blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
heal_model
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
*,
|
||||
{{ dbt_utils.generate_surrogate_key(['_log_id']) }} AS complete_lending_borrows_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
FINAL qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,57 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__complete_lending_borrows
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- _LOG_ID
|
||||
columns:
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 1
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null:
|
||||
where: PLATFORM <> 'Morpho Blue'
|
||||
- name: BORROWER
|
||||
tests:
|
||||
- not_null
|
||||
- name: PROTOCOL_MARKET
|
||||
tests:
|
||||
- not_null:
|
||||
where: PLATFORM <> 'Aave V1' AND TOKEN_SYMBOL <> 'WETH'
|
||||
- name: TOKEN_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: TOKEN_SYMBOL
|
||||
- name: AMOUNT_UNADJ
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: AMOUNT_USD
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: PLATFORM
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCKCHAIN
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
@ -1,673 +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,
|
||||
issued_tokens_unadj AS amount_unadj,
|
||||
issued_tokens AS amount,
|
||||
supplied_usd AS amount_usd,
|
||||
aave_version AS platform,
|
||||
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 %}
|
||||
),
|
||||
radiant AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
depositor_address,
|
||||
radiant_token AS protocol_market,
|
||||
radiant_market AS token_address,
|
||||
symbol AS token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
NULL AS amount_usd,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__radiant_deposits') }}
|
||||
|
||||
{% if is_incremental() and 'radiant' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
morpho AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
NULL AS event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
depositor_address,
|
||||
contract_address AS protocol_market,
|
||||
market AS token_address,
|
||||
symbol AS token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
NULL AS amount_usd,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
_ID AS _LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__morpho_deposits') }}
|
||||
|
||||
{% if is_incremental() and 'morpho' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
spark AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
depositor_address,
|
||||
spark_token AS protocol_market,
|
||||
spark_market AS token_address,
|
||||
symbol AS token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
NULL AS amount_usd,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__spark_deposits') }}
|
||||
|
||||
{% if is_incremental() and 'spark' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
sturdy AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
depositor_address,
|
||||
sturdy_token AS protocol_market,
|
||||
sturdy_market AS token_address,
|
||||
symbol AS token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
NULL AS amount_usd,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__sturdy_deposits') }}
|
||||
|
||||
{% if is_incremental() and 'sturdy' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
uwu AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
depositor_address,
|
||||
uwu_token AS protocol_market,
|
||||
uwu_market AS token_address,
|
||||
symbol AS token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
NULL AS amount_usd,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__uwu_deposits') }}
|
||||
|
||||
{% if is_incremental() and 'uwu' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
cream 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,
|
||||
NULL AS amount_usd,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__cream_deposits') }}
|
||||
|
||||
{% if is_incremental() and 'cream' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
flux 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,
|
||||
NULL AS amount_usd,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__flux_deposits') }}
|
||||
|
||||
{% if is_incremental() and 'flux' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
strike 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,
|
||||
NULL AS amount_usd,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__strike_deposits') }}
|
||||
|
||||
{% if is_incremental() and 'strike' 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,
|
||||
supplier AS depositor_address,
|
||||
ctoken AS protocol_market,
|
||||
CASE
|
||||
WHEN supplied_symbol = 'ETH' THEN '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
|
||||
ELSE supplied_contract_addr
|
||||
END AS token_address,
|
||||
supplied_symbol AS token_symbol,
|
||||
supplied_base_asset_unadj AS amount_unadj,
|
||||
supplied_base_asset AS amount,
|
||||
supplied_base_asset_usd AS amount_usd,
|
||||
compound_version AS platform,
|
||||
'ethereum' 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 %}
|
||||
),
|
||||
fraxlend AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
caller AS depositor_address,
|
||||
frax_market_address AS protocol_market,
|
||||
deposit_asset AS token_address,
|
||||
underlying_symbol AS token_symbol,
|
||||
deposit_amount_unadj AS amount_unadj,
|
||||
deposit_amount AS amount,
|
||||
NULL AS amount_usd,
|
||||
'Fraxlend' AS platform,
|
||||
'ethereum' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__fraxlend_deposits') }}
|
||||
|
||||
{% if is_incremental() and 'fraxlend' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
silo AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
depositor_address,
|
||||
silo_market AS protocol_market,
|
||||
token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
NULL AS amount_usd,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__silo_deposits') }}
|
||||
|
||||
{% if is_incremental() and 'silo' 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
|
||||
morpho
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
comp
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
cream
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
flux
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
fraxlend
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
radiant
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
silo
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
spark
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
strike
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
sturdy
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
uwu
|
||||
),
|
||||
complete_lending_deposits AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
CASE
|
||||
WHEN platform = 'Fraxlend' THEN 'AddCollateral'
|
||||
WHEN platform = 'Compound V3' THEN 'SupplyCollateral'
|
||||
WHEN platform IN (
|
||||
'Compound V2',
|
||||
'Cream',
|
||||
'Flux',
|
||||
'Strike'
|
||||
) THEN 'Mint'
|
||||
WHEN platform IN (
|
||||
'Spark',
|
||||
'Aave V3',
|
||||
'Radiant',
|
||||
'Sturdy',
|
||||
'UwU'
|
||||
) THEN 'Supply'
|
||||
ELSE 'Deposit'
|
||||
END AS event_name,
|
||||
depositor_address AS depositor,
|
||||
protocol_market,
|
||||
A.token_address,
|
||||
A.token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
CASE
|
||||
WHEN platform NOT IN (
|
||||
'Aave',
|
||||
'Compound'
|
||||
) THEN ROUND((amount * price), 2)
|
||||
ELSE amount_usd
|
||||
END 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,
|
||||
contract_address,
|
||||
event_name,
|
||||
depositor,
|
||||
protocol_market,
|
||||
t0.token_address,
|
||||
t0.token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
CASE
|
||||
WHEN platform NOT IN (
|
||||
'Aave',
|
||||
'Compound'
|
||||
) THEN ROUND((amount * price), 2)
|
||||
ELSE amount_usd
|
||||
END 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,
|
||||
depositor,
|
||||
protocol_market,
|
||||
token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
amount_usd_heal AS amount_usd,
|
||||
platform,
|
||||
blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
heal_model
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
*,
|
||||
{{ dbt_utils.generate_surrogate_key(['_log_id']) }} AS complete_lending_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,54 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__complete_lending_deposits
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- _LOG_ID
|
||||
columns:
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 1
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null:
|
||||
where: PLATFORM <> 'Morpho Blue'
|
||||
- name: PROTOCOL_MARKET
|
||||
- name: DEPOSITOR
|
||||
tests:
|
||||
- not_null
|
||||
- name: TOKEN_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: TOKEN_SYMBOL
|
||||
- name: AMOUNT_UNADJ
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: AMOUNT_USD
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: PLATFORM
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCKCHAIN
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
@ -1,452 +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,
|
||||
flashloan_amount_usd,
|
||||
premium_amount_unadj,
|
||||
premium_amount,
|
||||
premium_amount_usd,
|
||||
initiator_address,
|
||||
target_address,
|
||||
aave_version AS platform,
|
||||
symbol AS token_symbol,
|
||||
blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__aave_flashloans') }}
|
||||
|
||||
{% if is_incremental() and 'aave' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
spark AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
spark_market AS token_address,
|
||||
spark_token AS protocol_token,
|
||||
flashloan_amount_unadj,
|
||||
flashloan_amount,
|
||||
NULL AS flashloan_amount_usd,
|
||||
premium_amount_unadj,
|
||||
premium_amount,
|
||||
NULL AS premium_amount_usd,
|
||||
initiator_address,
|
||||
target_address,
|
||||
platform,
|
||||
symbol AS token_symbol,
|
||||
blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__spark_flashloans') }}
|
||||
|
||||
{% if is_incremental() and 'spark' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
morpho AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
market AS token_address,
|
||||
contract_address AS protocol_token,
|
||||
flashloan_amount_unadj,
|
||||
flashloan_amount,
|
||||
NULL AS flashloan_amount_usd,
|
||||
NULL AS premium_amount_unadj,
|
||||
NULL AS premium_amount,
|
||||
NULL AS premium_amount_usd,
|
||||
initiator_address,
|
||||
NULL AS target_address,
|
||||
platform,
|
||||
symbol AS token_symbol,
|
||||
blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__morpho_flashloans') }}
|
||||
|
||||
{% if is_incremental() and 'morpho' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
radiant AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
radiant_market AS token_address,
|
||||
radiant_token AS protocol_token,
|
||||
flashloan_amount_unadj,
|
||||
flashloan_amount,
|
||||
NULL AS flashloan_amount_usd,
|
||||
premium_amount_unadj,
|
||||
premium_amount,
|
||||
NULL AS premium_amount_usd,
|
||||
initiator_address,
|
||||
target_address,
|
||||
platform,
|
||||
symbol AS token_symbol,
|
||||
blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__radiant_flashloans') }}
|
||||
|
||||
{% if is_incremental() and 'radiant' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
uwu AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
uwu_market AS token_address,
|
||||
uwu_token AS protocol_token,
|
||||
flashloan_amount_unadj,
|
||||
flashloan_amount,
|
||||
NULL AS flashloan_amount_usd,
|
||||
premium_amount_unadj,
|
||||
premium_amount,
|
||||
NULL AS premium_amount_usd,
|
||||
initiator_address,
|
||||
target_address,
|
||||
platform,
|
||||
symbol AS token_symbol,
|
||||
blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__uwu_flashloans') }}
|
||||
|
||||
{% if is_incremental() and 'uwu' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
flashloan_union AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
aave
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
morpho
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
radiant
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
spark
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
uwu
|
||||
),
|
||||
complete_lending_flashloans AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
'FlashLoan' AS event_name,
|
||||
protocol_token AS protocol_market,
|
||||
A.token_address AS flashloan_token,
|
||||
token_symbol AS flashloan_token_symbol,
|
||||
flashloan_amount_unadj,
|
||||
flashloan_amount,
|
||||
CASE
|
||||
WHEN platform <> 'Aave' THEN ROUND((flashloan_amount * price), 2)
|
||||
ELSE flashloan_amount_usd
|
||||
END AS flashloan_amount_usd,
|
||||
premium_amount_unadj,
|
||||
premium_amount,
|
||||
CASE
|
||||
WHEN platform <> 'Aave' THEN ROUND((premium_amount * price), 2)
|
||||
ELSE premium_amount_usd
|
||||
END AS premium_amount_usd,
|
||||
initiator_address AS initiator,
|
||||
target_address AS target,
|
||||
platform,
|
||||
A.blockchain,
|
||||
A._LOG_ID,
|
||||
A._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
flashloan_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,
|
||||
contract_address,
|
||||
event_name,
|
||||
protocol_market,
|
||||
flashloan_token,
|
||||
flashloan_token_symbol,
|
||||
flashloan_amount_unadj,
|
||||
flashloan_amount,
|
||||
CASE
|
||||
WHEN platform <> 'Aave' THEN ROUND((flashloan_amount * price), 2)
|
||||
ELSE flashloan_amount_usd
|
||||
END AS flashloan_amount_usd_heal,
|
||||
premium_amount_unadj,
|
||||
premium_amount,
|
||||
CASE
|
||||
WHEN platform <> 'Aave' THEN ROUND((premium_amount * price), 2)
|
||||
ELSE premium_amount_usd
|
||||
END AS premium_amount_usd_heal,
|
||||
initiator,
|
||||
target,
|
||||
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,
|
||||
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,
|
||||
initiator,
|
||||
target,
|
||||
platform,
|
||||
blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
heal_model
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
*,
|
||||
{{ dbt_utils.generate_surrogate_key(['_log_id']) }} AS complete_lending_flashloans_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
FINAL qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,55 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__complete_lending_flashloans
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- _LOG_ID
|
||||
columns:
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 14
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null:
|
||||
where: PLATFORM <> 'Morpho Blue'
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
# - name: PROTOCOL_MARKET
|
||||
# tests:
|
||||
# - not_null
|
||||
- name: INITIATOR
|
||||
tests:
|
||||
- not_null
|
||||
- name: TARGET
|
||||
tests:
|
||||
- not_null:
|
||||
where: PLATFORM <> 'Morpho Blue'
|
||||
- name: FLASHLOAN_AMOUNT_UNADJ
|
||||
tests:
|
||||
- not_null
|
||||
- name: FLASHLOAN_AMOUNT
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: FLASHLOAN_AMOUNT_USD
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: PLATFORM
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCKCHAIN
|
||||
tests:
|
||||
- not_null
|
||||
@ -1,716 +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,
|
||||
liquidated_amount_unadj,
|
||||
liquidated_amount,
|
||||
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_version AS platform,
|
||||
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 %}
|
||||
),
|
||||
radiant 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_radiant_token AS protocol_collateral_asset,
|
||||
collateral_asset,
|
||||
collateral_token_symbol AS collateral_asset_symbol,
|
||||
debt_asset,
|
||||
debt_token_symbol AS debt_asset_symbol,
|
||||
'Radiant' AS platform,
|
||||
'ethereum' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__radiant_liquidations') }}
|
||||
|
||||
{% if is_incremental() and 'radiant' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
morpho AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
liquidator,
|
||||
borrower,
|
||||
amount_unadj,
|
||||
amount AS liquidated_amount,
|
||||
NULL AS liquidated_amount_usd,
|
||||
NULL AS protocol_collateral_asset,
|
||||
collateral_asset,
|
||||
collateral_asset_symbol,
|
||||
debt_asset,
|
||||
debt_asset_symbol,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
_id as _LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__morpho_liquidations') }}
|
||||
|
||||
{% if is_incremental() and 'morpho' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
spark 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_spark_token AS protocol_collateral_asset,
|
||||
collateral_asset,
|
||||
collateral_token_symbol AS collateral_asset_symbol,
|
||||
debt_asset,
|
||||
debt_token_symbol AS debt_asset_symbol,
|
||||
'Spark' AS platform,
|
||||
'ethereum' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__spark_liquidations') }}
|
||||
|
||||
{% if is_incremental() and 'spark' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
sturdy 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_sturdy_token AS protocol_collateral_asset,
|
||||
collateral_asset,
|
||||
collateral_token_symbol AS collateral_asset_symbol,
|
||||
debt_asset,
|
||||
debt_token_symbol AS debt_asset_symbol,
|
||||
'Sturdy' AS platform,
|
||||
'ethereum' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__sturdy_liquidations') }}
|
||||
|
||||
{% if is_incremental() and 'sturdy' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
uwu 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_uwu_token AS protocol_collateral_asset,
|
||||
collateral_asset,
|
||||
collateral_token_symbol AS collateral_asset_symbol,
|
||||
debt_asset,
|
||||
debt_token_symbol AS debt_asset_symbol,
|
||||
'UwU' AS platform,
|
||||
'ethereum' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__uwu_liquidations') }}
|
||||
|
||||
{% if is_incremental() and 'uwu' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
cream 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,
|
||||
'ethereum' AS blockchain,
|
||||
l._LOG_ID,
|
||||
l._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__cream_liquidations') }}
|
||||
l
|
||||
|
||||
{% if is_incremental() and 'cream' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
l._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
flux 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,
|
||||
'ethereum' AS blockchain,
|
||||
l._LOG_ID,
|
||||
l._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__flux_liquidations') }}
|
||||
l
|
||||
|
||||
{% if is_incremental() and 'flux' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
l._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
strike 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,
|
||||
'ethereum' AS blockchain,
|
||||
l._LOG_ID,
|
||||
l._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__strike_liquidations') }}
|
||||
l
|
||||
|
||||
{% if is_incremental() and 'strike' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
l._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,
|
||||
liquidator,
|
||||
borrower,
|
||||
liquidation_amount_unadj AS amount_unadj,
|
||||
liquidation_amount AS amount,
|
||||
liquidation_amount_usd,
|
||||
l.ctoken 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,
|
||||
l.compound_version AS platform,
|
||||
'ethereum' 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 %}
|
||||
),
|
||||
fraxlend AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
liquidator,
|
||||
borrower,
|
||||
collateral_for_liquidator_unadj AS amount_unadj,
|
||||
collateral_for_liquidator AS amount,
|
||||
NULL AS liquidated_amount_usd,
|
||||
NULL AS protocol_collateral_asset,
|
||||
underlying_asset AS collateral_asset,
|
||||
underlying_symbol AS collateral_asset_symbol,
|
||||
debt_asset,
|
||||
'FRAX' AS debt_asset_symbol,
|
||||
'Fraxlend' AS platform,
|
||||
'ethereum' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__fraxlend_liquidations') }}
|
||||
|
||||
{% if is_incremental() and 'fraxlend' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
silo AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
receiver_address AS liquidator,
|
||||
depositor_address AS borrower,
|
||||
amount_unadj,
|
||||
amount AS liquidated_amount,
|
||||
NULL AS liquidated_amount_usd,
|
||||
protocol_collateral_token AS protocol_collateral_asset,
|
||||
token_address AS collateral_asset,
|
||||
token_symbol AS collateral_asset_symbol,
|
||||
debt_asset,
|
||||
debt_asset_symbol,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__silo_liquidations') }}
|
||||
|
||||
{% if is_incremental() and 'silo' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
liquidation_union AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
aave
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
comp
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
cream
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
morpho
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
flux
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
fraxlend
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
radiant
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
silo
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
spark
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
strike
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
sturdy
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
uwu
|
||||
),
|
||||
complete_lending_liquidations AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
CASE
|
||||
WHEN platform IN ('Fraxlend','Morpho Blue') THEN 'Liquidate'
|
||||
WHEN platform = 'Compound V3' THEN 'AbsorbCollateral'
|
||||
WHEN platform IN (
|
||||
'Compound V2',
|
||||
'Cream',
|
||||
'Flux',
|
||||
'Strike'
|
||||
) THEN 'LiquidateBorrow'
|
||||
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,
|
||||
liquidated_amount_unadj AS amount_unadj,
|
||||
liquidated_amount AS amount,
|
||||
CASE
|
||||
WHEN platform NOT LIKE '%Aave%'
|
||||
OR platform NOT LIKE '%Compound%' THEN ROUND((liquidated_amount * p.price), 2)
|
||||
ELSE ROUND(
|
||||
liquidated_amount_usd,
|
||||
2
|
||||
)
|
||||
END AS amount_usd,
|
||||
debt_asset AS debt_token,
|
||||
debt_asset_symbol AS debt_token_symbol,
|
||||
platform,
|
||||
A.blockchain,
|
||||
A._LOG_ID,
|
||||
A._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
liquidation_union A
|
||||
LEFT JOIN {{ ref('price__ez_prices_hourly') }}
|
||||
p
|
||||
ON A.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,
|
||||
contract_address,
|
||||
event_name,
|
||||
liquidator,
|
||||
borrower,
|
||||
protocol_market,
|
||||
collateral_token,
|
||||
collateral_token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
CASE
|
||||
WHEN platform NOT LIKE '%Aave%'
|
||||
OR platform NOT LIKE '%Compound%' THEN ROUND((amount * p.price), 2)
|
||||
ELSE ROUND(
|
||||
amount_usd,
|
||||
2
|
||||
)
|
||||
END AS amount_usd_heal,
|
||||
debt_token,
|
||||
debt_token_symbol,
|
||||
platform,
|
||||
t0.blockchain,
|
||||
t0._LOG_ID,
|
||||
t0._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ this }}
|
||||
t0
|
||||
LEFT JOIN {{ ref('price__ez_prices_hourly') }}
|
||||
p
|
||||
ON t0.collateral_token = p.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
WHERE
|
||||
CONCAT(
|
||||
t0.block_number,
|
||||
'-',
|
||||
t0.platform
|
||||
) IN (
|
||||
SELECT
|
||||
CONCAT(
|
||||
t1.block_number,
|
||||
'-',
|
||||
t1.platform
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
t1
|
||||
WHERE
|
||||
t1.amount_usd IS NULL
|
||||
AND t1._inserted_timestamp < (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT
|
||||
1
|
||||
FROM
|
||||
{{ ref('silver__complete_token_prices') }}
|
||||
p
|
||||
WHERE
|
||||
p._inserted_timestamp > DATEADD('DAY', -14, SYSDATE())
|
||||
AND p.price IS NOT NULL
|
||||
AND p.token_address = t1.collateral_token
|
||||
AND p.hour = DATE_TRUNC(
|
||||
'hour',
|
||||
t1.block_timestamp
|
||||
)
|
||||
)
|
||||
GROUP BY
|
||||
1
|
||||
)
|
||||
),
|
||||
{% endif %}
|
||||
|
||||
FINAL AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
complete_lending_liquidations
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
UNION ALL
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
event_name,
|
||||
liquidator,
|
||||
borrower,
|
||||
protocol_market,
|
||||
collateral_token,
|
||||
collateral_token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
amount_usd_heal AS amount_usd,
|
||||
debt_token,
|
||||
debt_token_symbol,
|
||||
platform,
|
||||
blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
heal_model
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
*,
|
||||
{{
|
||||
dbt_utils.generate_surrogate_key(['_log_id'])
|
||||
}} AS complete_lending_liquidations_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
FINAL qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,55 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__complete_lending_liquidations
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- _LOG_ID
|
||||
columns:
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 5
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: LIQUIDATOR
|
||||
tests:
|
||||
- not_null
|
||||
- name: BORROWER
|
||||
tests:
|
||||
- not_null
|
||||
- name: PROTOCOL_MARKET
|
||||
- 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,683 +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_token,
|
||||
repayed_tokens_unadj AS amount_unadj,
|
||||
repayed_tokens AS amount,
|
||||
repayed_usd AS amount_usd,
|
||||
symbol AS token_symbol,
|
||||
payer AS payer_address,
|
||||
borrower,
|
||||
aave_version AS platform,
|
||||
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 %}
|
||||
),
|
||||
radiant AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
radiant_market AS token_address,
|
||||
radiant_token AS protocol_market,
|
||||
amount_unadj,
|
||||
amount,
|
||||
NULL AS amount_usd,
|
||||
symbol AS token_symbol,
|
||||
payer AS payer_address,
|
||||
borrower,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__radiant_repayments') }}
|
||||
|
||||
{% if is_incremental() and 'radiant' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
morpho AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
NULL AS event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
market AS token_address,
|
||||
contract_address AS protocol_market,
|
||||
amount_unadj,
|
||||
amount,
|
||||
NULL AS amount_usd,
|
||||
symbol AS token_symbol,
|
||||
payer AS payer_address,
|
||||
borrower_address AS borrower,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
_ID AS _LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__morpho_repayments') }}
|
||||
|
||||
{% if is_incremental() and 'morpho' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
spark AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
spark_market AS token_address,
|
||||
spark_token AS protocol_market,
|
||||
amount_unadj,
|
||||
amount,
|
||||
NULL AS amount_usd,
|
||||
symbol AS token_symbol,
|
||||
payer AS payer_address,
|
||||
borrower,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__spark_repayments') }}
|
||||
|
||||
{% if is_incremental() and 'spark' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
sturdy AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
sturdy_market AS token_address,
|
||||
sturdy_token AS protocol_market,
|
||||
amount_unadj,
|
||||
amount,
|
||||
NULL AS amount_usd,
|
||||
symbol AS token_symbol,
|
||||
payer AS payer_address,
|
||||
borrower,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__sturdy_repayments') }}
|
||||
|
||||
{% if is_incremental() and 'sturdy' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
uwu AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
uwu_market AS token_address,
|
||||
uwu_token AS protocol_market,
|
||||
amount_unadj,
|
||||
amount,
|
||||
NULL AS amount_usd,
|
||||
symbol AS token_symbol,
|
||||
payer AS payer_address,
|
||||
borrower,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__uwu_repayments') }}
|
||||
|
||||
{% if is_incremental() and 'uwu' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
cream 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,
|
||||
NULL AS amount_usd,
|
||||
repay_contract_symbol AS token_symbol,
|
||||
payer AS payer_address,
|
||||
borrower,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__cream_repayments') }}
|
||||
|
||||
{% if is_incremental() and 'cream' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
flux 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,
|
||||
NULL AS amount_usd,
|
||||
repay_contract_symbol AS token_symbol,
|
||||
payer AS payer_address,
|
||||
borrower,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__flux_repayments') }}
|
||||
|
||||
{% if is_incremental() and 'flux' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
strike 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,
|
||||
NULL AS amount_usd,
|
||||
repay_contract_symbol AS token_symbol,
|
||||
payer AS payer_address,
|
||||
borrower,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__strike_repayments') }}
|
||||
|
||||
{% if is_incremental() and 'strike' 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,
|
||||
CASE
|
||||
WHEN repay_contract_symbol = 'ETH' THEN '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
|
||||
ELSE repay_contract_address
|
||||
END AS token_address,
|
||||
ctoken AS protocol_market,
|
||||
repayed_amount_unadj AS amount_unadj,
|
||||
repayed_amount AS amount,
|
||||
repayed_amount_usd AS amount_usd,
|
||||
repay_contract_symbol AS token_symbol,
|
||||
payer AS payer_address,
|
||||
borrower AS borrower,
|
||||
compound_version AS platform,
|
||||
'ethereum' 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 %}
|
||||
),
|
||||
fraxlend AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
repay_asset AS tokem_address,
|
||||
frax_market_address AS protocol_token,
|
||||
repay_amount_unadj AS amount_unadj,
|
||||
repay_amount AS amount,
|
||||
NULL AS amount_usd,
|
||||
repay_symbol token_symbol,
|
||||
payer AS payer_address,
|
||||
borrower AS borrower,
|
||||
'Fraxlend' AS platform,
|
||||
'ethereum' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__fraxlend_repayments') }}
|
||||
|
||||
{% if is_incremental() and 'fraxlend' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
silo AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
token_address,
|
||||
silo_market AS protocol_market,
|
||||
amount_unadj,
|
||||
amount,
|
||||
NULL AS amount_usd,
|
||||
token_symbol,
|
||||
NULL AS payer_address,
|
||||
depositor_address AS borrower,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__silo_repayments') }}
|
||||
|
||||
{% if is_incremental() and 'silo' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
repay_union AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
aave
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
morpho
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
comp
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
cream
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
flux
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
fraxlend
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
radiant
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
silo
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
spark
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
strike
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
sturdy
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
uwu
|
||||
),
|
||||
complete_lending_repayments AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
CASE
|
||||
WHEN platform = 'Fraxlend' THEN 'RepayAsset'
|
||||
WHEN platform = 'Compound V3' THEN 'Supply'
|
||||
WHEN platform IN (
|
||||
'Compound V2',
|
||||
'Cream',
|
||||
'Flux',
|
||||
'Strike'
|
||||
) THEN 'RepayBorrow'
|
||||
ELSE 'Repay'
|
||||
END AS event_name,
|
||||
protocol_token AS protocol_market,
|
||||
A.token_address,
|
||||
amount_unadj,
|
||||
amount,
|
||||
CASE
|
||||
WHEN platform NOT LIKE '%Aave%'
|
||||
OR platform NOT LIKE '%Compound%' THEN ROUND((amount * price), 2)
|
||||
ELSE ROUND(
|
||||
amount_usd,
|
||||
2
|
||||
)
|
||||
END AS amount_usd,
|
||||
token_symbol,
|
||||
payer_address AS payer,
|
||||
borrower,
|
||||
platform,
|
||||
A.blockchain,
|
||||
A._LOG_ID,
|
||||
A._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
repay_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,
|
||||
contract_address,
|
||||
event_name,
|
||||
protocol_market,
|
||||
t0.token_address,
|
||||
amount_unadj,
|
||||
amount,
|
||||
CASE
|
||||
WHEN platform NOT LIKE '%Aave%'
|
||||
OR platform NOT LIKE '%Compound%' THEN ROUND((amount * price), 2)
|
||||
ELSE ROUND(
|
||||
amount_usd,
|
||||
2
|
||||
)
|
||||
END AS amount_usd_heal,
|
||||
token_symbol,
|
||||
payer,
|
||||
borrower,
|
||||
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,
|
||||
token_address,
|
||||
amount_unadj,
|
||||
amount,
|
||||
amount_usd_heal AS amount_usd,
|
||||
token_symbol,
|
||||
payer,
|
||||
borrower,
|
||||
platform,
|
||||
blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
heal_model
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
*,
|
||||
{{ dbt_utils.generate_surrogate_key(['_log_id']) }} AS complete_lending_repayments_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
FINAL qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,56 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__complete_lending_repayments
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- _LOG_ID
|
||||
columns:
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 3
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null:
|
||||
where: PLATFORM <> 'Morpho Blue'
|
||||
# - name: PROTOCOL_MARKET
|
||||
# tests:
|
||||
# - not_null
|
||||
- name: TOKEN_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
# - name: AMOUNT
|
||||
# tests:
|
||||
# - dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
# column_type_list:
|
||||
# - decimal
|
||||
# - float
|
||||
# - not_null
|
||||
- name: AMOUNT_USD
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: TOKEN_SYMBOL
|
||||
- not_null
|
||||
- name: PAYER_ADDRESS
|
||||
- name: BORROWER
|
||||
tests:
|
||||
- not_null
|
||||
- name: PLATFORM
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCKCHAIN
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
@ -1,691 +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_token,
|
||||
aave_market AS token_address,
|
||||
symbol AS token_symbol,
|
||||
withdrawn_tokens_unadj AS amount_unadj,
|
||||
withdrawn_tokens AS amount,
|
||||
withdrawn_usd AS amount_usd,
|
||||
depositor_address,
|
||||
aave_version AS platform,
|
||||
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 %}
|
||||
),
|
||||
radiant AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
radiant_token AS protocol_market,
|
||||
radiant_market AS token_address,
|
||||
symbol AS token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
NULL AS amount_usd,
|
||||
depositor_address,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__radiant_withdraws') }}
|
||||
|
||||
{% if is_incremental() and 'radiant' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
morpho AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
NULL AS event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
contract_address AS protocol_market,
|
||||
market AS token_address,
|
||||
symbol AS token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
NULL AS amount_usd,
|
||||
depositor_address,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
_id AS _LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__morpho_withdraws') }}
|
||||
|
||||
{% if is_incremental() and 'morpho' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
spark AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
spark_token AS protocol_market,
|
||||
spark_market AS token_address,
|
||||
symbol AS token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
NULL AS amount_usd,
|
||||
depositor_address,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__spark_withdraws') }}
|
||||
|
||||
{% if is_incremental() and 'spark' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
sturdy AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
sturdy_token AS protocol_market,
|
||||
sturdy_market AS token_address,
|
||||
symbol AS token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
NULL AS amount_usd,
|
||||
depositor_address,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__sturdy_withdraws') }}
|
||||
|
||||
{% if is_incremental() and 'sturdy' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
uwu AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
uwu_token AS protocol_market,
|
||||
uwu_market AS token_address,
|
||||
symbol AS token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
NULL AS amount_usd,
|
||||
depositor_address,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__uwu_withdraws') }}
|
||||
|
||||
{% if is_incremental() and 'uwu' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
cream AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
token_address AS protocol_market,
|
||||
received_contract_address AS token_address,
|
||||
received_contract_symbol AS token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
NULL AS amount_usd,
|
||||
redeemer AS depositor_address,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__cream_withdraws') }}
|
||||
|
||||
{% if is_incremental() and 'cream' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
flux AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
token_address AS protocol_market,
|
||||
received_contract_address AS token_address,
|
||||
received_contract_symbol AS token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
NULL AS amount_usd,
|
||||
redeemer AS depositor_address,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__flux_withdraws') }}
|
||||
|
||||
{% if is_incremental() and 'flux' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
strike AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
token_address AS protocol_market,
|
||||
received_contract_address AS token_address,
|
||||
received_contract_symbol AS token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
NULL AS amount_usd,
|
||||
redeemer AS depositor_address,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__strike_withdraws') }}
|
||||
|
||||
{% if is_incremental() and 'strike' 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,
|
||||
ctoken AS protocol_token,
|
||||
CASE
|
||||
WHEN received_contract_symbol = 'ETH' THEN '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
|
||||
ELSE received_contract_address
|
||||
END AS token_address,
|
||||
received_contract_symbol AS token_symbol,
|
||||
received_amount_unadj AS amount_unadj,
|
||||
received_amount AS amount,
|
||||
received_amount_usd AS amount_usd,
|
||||
redeemer AS depositor_address,
|
||||
compound_version AS platform,
|
||||
'ethereum' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__comp_redemptions') }}
|
||||
|
||||
{% 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 %}
|
||||
),
|
||||
fraxlend AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
frax_market_address AS protocol_token,
|
||||
underlying_asset AS token_address,
|
||||
underlying_symbol AS token_symbol,
|
||||
withdraw_amount_unadj AS amount_unadj,
|
||||
withdraw_amount AS amount,
|
||||
NULL AS amount_usd,
|
||||
caller AS depositor_address,
|
||||
'Fraxlend' AS platform,
|
||||
'ethereum' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__fraxlend_withdraws') }}
|
||||
|
||||
{% if is_incremental() and 'fraxlend' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
silo AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
silo_market AS protocol_market,
|
||||
token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
NULL AS amount_usd,
|
||||
depositor_address,
|
||||
platform,
|
||||
'ethereum' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__silo_withdraws') }}
|
||||
|
||||
{% if is_incremental() and 'silo' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
withdraw_union AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
aave
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
comp
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
cream
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
flux
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
fraxlend
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
morpho
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
radiant
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
silo
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
spark
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
strike
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
sturdy
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
uwu
|
||||
),
|
||||
complete_lending_withdraws AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
CASE
|
||||
WHEN platform = 'Fraxlend' THEN 'RemoveCollateral'
|
||||
WHEN platform = 'Compound V3' THEN 'WithdrawCollateral'
|
||||
WHEN platform IN (
|
||||
'Compound V2',
|
||||
'Cream',
|
||||
'Flux',
|
||||
'Strike'
|
||||
) THEN 'Redeem'
|
||||
WHEN platform = 'Aave V1' THEN 'RedeemUnderlying'
|
||||
ELSE 'Withdraw'
|
||||
END AS event_name,
|
||||
protocol_token AS protocol_market,
|
||||
A.token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
CASE
|
||||
WHEN platform NOT LIKE '%Aave%'
|
||||
OR platform NOT LIKE '%Compound%' THEN ROUND((amount * p.price), 2)
|
||||
ELSE ROUND(
|
||||
amount_usd,
|
||||
2
|
||||
)
|
||||
END AS amount_usd,
|
||||
depositor_address AS depositor,
|
||||
platform,
|
||||
A.blockchain,
|
||||
A._log_id,
|
||||
A._inserted_timestamp
|
||||
FROM
|
||||
withdraw_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,
|
||||
contract_address,
|
||||
event_name,
|
||||
protocol_market,
|
||||
t0.token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
CASE
|
||||
WHEN platform NOT LIKE '%Aave%'
|
||||
OR platform NOT LIKE '%Compound%' THEN ROUND((amount * p.price), 2)
|
||||
ELSE ROUND(
|
||||
amount_usd,
|
||||
2
|
||||
)
|
||||
END AS amount_usd_heal,
|
||||
depositor,
|
||||
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,
|
||||
token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
amount_usd_heal AS amount_usd,
|
||||
depositor,
|
||||
platform,
|
||||
blockchain,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
heal_model
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
*,
|
||||
{{ dbt_utils.generate_surrogate_key(['_log_id']) }} AS complete_lending_withdraws_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
FINAL qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,50 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__complete_lending_withdraws
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- _LOG_ID
|
||||
columns:
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 3
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null:
|
||||
where: PLATFORM <> 'Morpho Blue'
|
||||
- name: PROTOCOL_MARKET
|
||||
- name: DEPOSITOR
|
||||
tests:
|
||||
- not_null
|
||||
- name: TOKEN_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: TOKEN_SYMBOL
|
||||
- name: AMOUNT_UNADJ
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT
|
||||
- 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,277 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
unique_key = "ctoken_address",
|
||||
tags = ['silver','defi','lending','curated','asset_details']
|
||||
) }}
|
||||
|
||||
WITH contracts_dim AS (
|
||||
SELECT
|
||||
address,
|
||||
name,
|
||||
symbol,
|
||||
decimals
|
||||
FROM
|
||||
{{ ref('core__dim_contracts') }}
|
||||
),
|
||||
|
||||
ctoken_addresses AS (
|
||||
SELECT address FROM (
|
||||
VALUES
|
||||
(LOWER('0xe65cdB6479BaC1e22340E4E755fAE7E509EcD06c')), --cAAVE
|
||||
(LOWER('0x6C8c6b02E7b2BE14d4fA6022Dfd6d75921D90E4E')), --cBAT
|
||||
(LOWER('0x70e36f6BF80a52b3B46b3aF8e106CC0ed743E8e4')), --cCOMP
|
||||
(LOWER('0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643')), --cDAI
|
||||
(LOWER('0x4Ddc2D193948926D02f9B1fE9e1daa0718270ED5')), --cETH
|
||||
(LOWER('0x7713DD9Ca933848F6819F38B8352D9A15EA73F67')), --cFEI
|
||||
(LOWER('0xFAce851a4921ce59e912d19329929CE6da6EB0c7')), --cLINK
|
||||
(LOWER('0x95b4eF2869eBD94BEb4eEE400a99824BF5DC325b')), --cMKR
|
||||
(LOWER('0x158079Ee67Fce2f58472A96584A73C7Ab9AC95c1')), --cREP
|
||||
(LOWER('0xF5DCe57282A584D2746FaF1593d3121Fcac444dC')), --cSAI
|
||||
(LOWER('0x4B0181102A0112A2ef11AbEE5563bb4a3176c9d7')), --cSUSHI
|
||||
(LOWER('0x12392F67bdf24faE0AF363c24aC620a2f67DAd86')), --cTUSD
|
||||
(LOWER('0x35A18000230DA775CAc24873d00Ff85BccdeD550')), --cUNI
|
||||
(LOWER('0x39AA39c021dfbaE8faC545936693aC917d5E7563')), --cUSDC
|
||||
(LOWER('0x041171993284df560249B57358F931D9eB7b925D')), --cUSDP
|
||||
(LOWER('0xf650C3d88D12dB855b8bf7D11Be6C55A4e07dCC9')), --cUSDT
|
||||
(LOWER('0xC11b1268C1A384e55C48c2391d8d480264A3A7F4')), --cWBTC
|
||||
(LOWER('0xccF4429DB6322D5C611ee964527D42E5d685DD6a')), --cWBTC2
|
||||
(LOWER('0x80a2AE356fc9ef4305676f7a3E2Ed04e12C33946')), --cYFI
|
||||
(LOWER('0xB3319f5D18Bc0D84dD1b4825Dcde5d5f7266d407')) --cZRX
|
||||
) AS t(address)
|
||||
),
|
||||
|
||||
comp_v2_logs AS (
|
||||
SELECT
|
||||
l.tx_hash,
|
||||
l.block_number,
|
||||
l.block_timestamp,
|
||||
l.contract_address,
|
||||
CASE
|
||||
WHEN l.contract_address = '0xf5dce57282a584d2746faf1593d3121fcac444dc' THEN 'Compound SAI'
|
||||
ELSE c.name
|
||||
END AS token_name,
|
||||
CASE
|
||||
WHEN l.contract_address = '0xf5dce57282a584d2746faf1593d3121fcac444dc' THEN 'cSAI'
|
||||
ELSE c.symbol
|
||||
END AS token_symbol,
|
||||
CASE
|
||||
WHEN l.contract_address = '0xf5dce57282a584d2746faf1593d3121fcac444dc' THEN 8
|
||||
ELSE c.decimals
|
||||
END AS token_decimals,
|
||||
l.modified_timestamp,
|
||||
CONCAT(l.tx_hash, '-', l.event_index) AS _log_id
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }} l
|
||||
LEFT JOIN contracts_dim c ON l.contract_address = c.address
|
||||
JOIN ctoken_addresses ca ON l.contract_address = ca.address
|
||||
WHERE
|
||||
topics[0] :: STRING = '0x7ac369dbd14fa5ea3f473ed67cc9d598964a77501540ba6751eb0b3decf5870d'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND l.modified_timestamp >= (
|
||||
SELECT MAX(modified_timestamp) - INTERVAL '12 hours' FROM {{ this }}
|
||||
)
|
||||
AND l.modified_timestamp >= CURRENT_DATE() - 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 comp_v2_logs)
|
||||
AND input = '0x18160ddd'
|
||||
),
|
||||
|
||||
contract_pull AS (
|
||||
SELECT
|
||||
l.tx_hash,
|
||||
l.block_number,
|
||||
l.block_timestamp,
|
||||
l.contract_address,
|
||||
l.token_name,
|
||||
l.token_symbol,
|
||||
l.token_decimals,
|
||||
CASE
|
||||
WHEN l.token_symbol = 'cETH' THEN LOWER('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2')
|
||||
ELSE t.underlying_asset
|
||||
END AS underlying_asset,
|
||||
l.modified_timestamp,
|
||||
l._log_id
|
||||
FROM
|
||||
comp_v2_logs l
|
||||
LEFT JOIN traces_pull t ON l.contract_address = t.token_address
|
||||
QUALIFY ROW_NUMBER() OVER(
|
||||
PARTITION BY l.contract_address
|
||||
ORDER BY l.block_timestamp ASC
|
||||
) = 1
|
||||
),
|
||||
|
||||
comp_v2_join AS (
|
||||
SELECT
|
||||
l.contract_address AS ctoken_address,
|
||||
l.token_symbol AS ctoken_symbol,
|
||||
l.token_name AS ctoken_name,
|
||||
l.token_decimals AS ctoken_decimals,
|
||||
l.underlying_asset AS underlying_address,
|
||||
u.name AS underlying_name,
|
||||
u.symbol AS underlying_symbol,
|
||||
u.decimals AS underlying_decimals,
|
||||
l.block_number AS created_block,
|
||||
'Compound V2' AS compound_version
|
||||
FROM
|
||||
contract_pull l
|
||||
LEFT JOIN contracts_dim u ON l.underlying_asset = u.address
|
||||
WHERE
|
||||
l.underlying_asset IS NOT NULL
|
||||
AND l.token_name IS NOT NULL
|
||||
),
|
||||
|
||||
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(22541338) -- dummy block number
|
||||
],
|
||||
concat_ws('-', contract_address, '0xc55dae63', 22541338)
|
||||
),
|
||||
'Vault/prod/evm/quicknode/ethereum/mainnet'
|
||||
) AS api_response
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
WHERE
|
||||
topic_0 = '0xbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b'
|
||||
AND origin_from_address IN (
|
||||
LOWER('0x343715FA797B8e9fe48b9eFaB4b54f01CA860e78'),
|
||||
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
|
||||
),
|
||||
|
||||
comp_union AS (
|
||||
SELECT
|
||||
ctoken_address,
|
||||
ctoken_symbol,
|
||||
ctoken_name,
|
||||
ctoken_decimals,
|
||||
underlying_address,
|
||||
underlying_name,
|
||||
underlying_symbol,
|
||||
underlying_decimals,
|
||||
created_block,
|
||||
compound_version
|
||||
FROM comp_v2_join
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT
|
||||
ctoken_address,
|
||||
ctoken_symbol,
|
||||
ctoken_name,
|
||||
ctoken_decimals,
|
||||
underlying_address,
|
||||
underlying_name,
|
||||
underlying_symbol,
|
||||
underlying_decimals,
|
||||
created_block,
|
||||
compound_version
|
||||
FROM comp_v3_data
|
||||
)
|
||||
|
||||
SELECT
|
||||
ctoken_address,
|
||||
ctoken_symbol,
|
||||
ctoken_name,
|
||||
ctoken_decimals,
|
||||
underlying_address as underlying_asset_address,
|
||||
CASE
|
||||
WHEN underlying_asset_address = '0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2' THEN 'Maker'
|
||||
WHEN underlying_asset_address = '0x1985365e9f78359a9b6ad760e32412f4a445e862' THEN 'Reputation'
|
||||
WHEN underlying_asset_address = '0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359' THEN 'SAI Stablecoin'
|
||||
ELSE underlying_name :: STRING
|
||||
END AS underlying_name,
|
||||
CASE
|
||||
WHEN underlying_asset_address = '0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2' THEN 'MKR'
|
||||
WHEN underlying_asset_address = '0x1985365e9f78359a9b6ad760e32412f4a445e862' THEN 'REP'
|
||||
WHEN underlying_asset_address = '0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359' THEN 'SAI'
|
||||
ELSE underlying_symbol :: STRING
|
||||
END AS underlying_symbol,
|
||||
CASE
|
||||
WHEN underlying_asset_address = '0x1985365e9f78359a9b6ad760e32412f4a445e862' THEN 18
|
||||
ELSE underlying_decimals :: INTEGER
|
||||
END AS underlying_decimals,
|
||||
created_block,
|
||||
compound_version,
|
||||
{{ dbt_utils.generate_surrogate_key(['ctoken_address']) }} AS comp_asset_details_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
comp_union
|
||||
QUALIFY ROW_NUMBER() OVER(
|
||||
PARTITION BY ctoken_address
|
||||
ORDER BY created_block DESC
|
||||
) = 1
|
||||
@ -1,12 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__comp_asset_details
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- CTOKEN_ADDRESS
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,235 +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 ctoken addresses and corresponding name
|
||||
WITH asset_details AS (
|
||||
|
||||
SELECT
|
||||
ctoken_address,
|
||||
ctoken_symbol,
|
||||
ctoken_name,
|
||||
ctoken_decimals,
|
||||
underlying_asset_address,
|
||||
underlying_name,
|
||||
underlying_symbol,
|
||||
underlying_decimals,
|
||||
compound_version
|
||||
FROM
|
||||
{{ ref('silver__comp_asset_details') }}
|
||||
|
||||
),
|
||||
compv2_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 ctoken,
|
||||
'Compound V2' AS compound_version,
|
||||
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
|
||||
ctoken_address
|
||||
FROM
|
||||
asset_details
|
||||
)
|
||||
AND topics [0] :: STRING = '0x13ed6866d4e1ee6da46f845c46d7e54120883d75c5ea9a2dacc1c4ca8984ab80'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
),
|
||||
compv3_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 [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 loan_amount_raw,
|
||||
origin_from_address AS borrower,
|
||||
contract_address AS ctoken,
|
||||
'Compound V3' AS compound_version,
|
||||
CONCAT(
|
||||
l.tx_hash,
|
||||
'-',
|
||||
l.event_index
|
||||
) AS _log_id,
|
||||
l.modified_timestamp AS _inserted_timestamp
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
l
|
||||
WHERE
|
||||
topics [0] = '0x9b1bfa7fa9ee420a16e124f794c35ac9f90472acc99140eb2f6447c714cad8eb' --withdrawl
|
||||
AND contract_address IN (
|
||||
SELECT
|
||||
ctoken_address
|
||||
FROM
|
||||
asset_details
|
||||
WHERE
|
||||
compound_version = 'Compound V3'
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND l.modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '36 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
comp_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,
|
||||
ctoken,
|
||||
C.ctoken_symbol,
|
||||
C.underlying_decimals,
|
||||
b.compound_version,
|
||||
b._log_id,
|
||||
b._inserted_timestamp
|
||||
FROM
|
||||
compv2_borrows b
|
||||
LEFT JOIN {{ ref('silver__comp_asset_details') }} C
|
||||
ON b.ctoken = C.ctoken_address
|
||||
UNION ALL
|
||||
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,
|
||||
ctoken,
|
||||
C.ctoken_symbol,
|
||||
C.underlying_decimals,
|
||||
b.compound_version,
|
||||
b._log_id,
|
||||
b._inserted_timestamp
|
||||
FROM
|
||||
compv3_borrows b
|
||||
LEFT JOIN {{ ref('silver__comp_asset_details') }} C
|
||||
ON b.ctoken = C.ctoken_address
|
||||
),
|
||||
--pull hourly prices for each undelrying
|
||||
prices AS (
|
||||
SELECT
|
||||
HOUR AS block_hour,
|
||||
token_address AS token_contract,
|
||||
ctoken_address,
|
||||
AVG(price) AS token_price
|
||||
FROM
|
||||
{{ ref('price__ez_prices_hourly') }}
|
||||
INNER JOIN {{ ref('silver__comp_asset_details') }}
|
||||
ON token_address = underlying_asset_address
|
||||
WHERE
|
||||
HOUR :: DATE IN (
|
||||
SELECT
|
||||
block_timestamp :: DATE
|
||||
FROM
|
||||
comp_combine
|
||||
)
|
||||
GROUP BY
|
||||
1,
|
||||
2,
|
||||
3
|
||||
)
|
||||
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,
|
||||
ctoken,
|
||||
ctoken_symbol,
|
||||
loan_amount_raw,
|
||||
loan_amount_raw / pow(
|
||||
10,
|
||||
underlying_decimals
|
||||
) AS loan_amount,
|
||||
ROUND((loan_amount_raw * p.token_price) / pow(10, underlying_decimals), 2) AS loan_amount_usd,
|
||||
compound_version,
|
||||
_inserted_timestamp,
|
||||
_log_id,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash', 'event_index']
|
||||
) }} AS comp_borrows_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
comp_combine
|
||||
LEFT JOIN prices p
|
||||
ON DATE_TRUNC(
|
||||
'hour',
|
||||
comp_combine.block_timestamp
|
||||
) = p.block_hour
|
||||
AND comp_combine.ctoken = p.ctoken_address qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,52 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__comp_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
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 3
|
||||
- name: BORROWER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BORROWS_CONTRACT_ADDRESS
|
||||
tests:
|
||||
- not_null:
|
||||
where: BORROWS_CONTRACT_SYMBOL <> 'ETH'
|
||||
- name: BORROWS_CONTRACT_SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
- name: CTOKEN
|
||||
tests:
|
||||
- not_null
|
||||
- name: CTOKEN_SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
- name: LOAN_AMOUNT
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: LOAN_AMOUNT_USD
|
||||
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,251 +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 ctoken addresses and corresponding name
|
||||
WITH asset_details AS (
|
||||
|
||||
SELECT
|
||||
ctoken_address,
|
||||
ctoken_symbol,
|
||||
ctoken_name,
|
||||
ctoken_decimals,
|
||||
underlying_asset_address,
|
||||
underlying_name,
|
||||
underlying_symbol,
|
||||
underlying_decimals,
|
||||
compound_version
|
||||
FROM
|
||||
{{ ref('silver__comp_asset_details') }}
|
||||
|
||||
),
|
||||
compv2_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 ctoken,
|
||||
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,
|
||||
'Compound V2' AS compound_version,
|
||||
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
|
||||
ctoken_address
|
||||
FROM
|
||||
asset_details
|
||||
where compound_version = 'Compound V2'
|
||||
)
|
||||
AND topics [0] :: STRING = '0x4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
),
|
||||
compv3_deposits AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
contract_address AS ctoken,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
CONCAT('0x', SUBSTR(topics [3] :: STRING, 27, 40)) AS asset,
|
||||
NULL AS mintTokens_raw,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
) :: INTEGER AS mintAmount_raw,
|
||||
origin_from_address AS supplier,
|
||||
'Compound V3' AS compound_version,
|
||||
CONCAT(
|
||||
tx_hash,
|
||||
'-',
|
||||
event_index
|
||||
) AS _log_id,
|
||||
modified_timestamp AS _inserted_timestamp
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
l
|
||||
WHERE
|
||||
contract_address IN (
|
||||
SELECT
|
||||
ctoken_address
|
||||
FROM
|
||||
asset_details
|
||||
where compound_version = 'Compound V3'
|
||||
)
|
||||
AND
|
||||
topics [0] = '0xfa56f7b24f17183d81894d3ac2ee654e3c26388d17a28dbd9549b8114304e1f4' --SupplyCollateral
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '36 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
comp_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,
|
||||
ctoken,
|
||||
C.ctoken_symbol,
|
||||
c.ctoken_decimals,
|
||||
C.underlying_decimals,
|
||||
b.compound_version,
|
||||
b._log_id,
|
||||
b._inserted_timestamp
|
||||
FROM
|
||||
compv2_deposits b
|
||||
LEFT JOIN asset_details C
|
||||
ON b.ctoken = C.ctoken_address
|
||||
UNION ALL
|
||||
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,
|
||||
b.asset AS supplied_contract_addr,
|
||||
c.symbol AS supplied_symbol,
|
||||
ctoken,
|
||||
a.ctoken_symbol,
|
||||
a.ctoken_decimals,
|
||||
c.decimals as underlying_decimals,
|
||||
b.compound_version,
|
||||
b._log_id,
|
||||
b._inserted_timestamp
|
||||
FROM
|
||||
compv3_deposits b
|
||||
LEFT JOIN {{ ref('core__dim_contracts') }} C
|
||||
ON b.asset = C.address
|
||||
LEFT JOIN asset_details a
|
||||
ON b.ctoken = a.ctoken_address
|
||||
),
|
||||
--pull hourly prices for each undelrying
|
||||
prices AS (
|
||||
SELECT
|
||||
HOUR AS block_hour,
|
||||
token_address AS token_contract,
|
||||
ctoken_address,
|
||||
AVG(price) AS token_price
|
||||
FROM
|
||||
{{ ref('price__ez_prices_hourly') }}
|
||||
LEFT JOIN asset_details
|
||||
ON token_address = underlying_asset_address
|
||||
WHERE
|
||||
HOUR :: DATE IN (
|
||||
SELECT
|
||||
block_timestamp :: DATE
|
||||
FROM
|
||||
comp_combine
|
||||
)
|
||||
AND token_address in (
|
||||
SELECT
|
||||
supplied_contract_addr
|
||||
FROM
|
||||
comp_combine
|
||||
)
|
||||
GROUP BY
|
||||
1,
|
||||
2,
|
||||
3
|
||||
)
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
ctoken,
|
||||
ctoken_symbol,
|
||||
mintTokens_raw / pow(
|
||||
10,
|
||||
ctoken_decimals
|
||||
) AS issued_ctokens,
|
||||
mintAmount_raw AS supplied_base_asset_unadj,
|
||||
mintAmount_raw / pow(
|
||||
10,
|
||||
underlying_decimals
|
||||
) AS supplied_base_asset,
|
||||
ROUND((mintAmount_raw * p.token_price) / pow(10, underlying_decimals), 2) AS supplied_base_asset_usd,
|
||||
supplied_contract_addr,
|
||||
supplied_symbol,
|
||||
supplier,
|
||||
compound_version,
|
||||
_inserted_timestamp,
|
||||
_log_id,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash', 'event_index']
|
||||
) }} AS comp_deposits_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
comp_combine
|
||||
LEFT JOIN prices p
|
||||
ON DATE_TRUNC(
|
||||
'hour',
|
||||
comp_combine.block_timestamp
|
||||
) = p.block_hour
|
||||
AND comp_combine.supplied_contract_addr = p.token_contract qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
|
||||
@ -1,57 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__comp_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: CTOKEN
|
||||
tests:
|
||||
- not_null
|
||||
- name: CTOKEN_SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
- name: ISSUED_CTOKENS
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: SUPPLIED_BASE_ASSET
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: SUPPLIED_BASE_ASSET_USD
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: SUPPLIED_CONTRACT_ADDR
|
||||
tests:
|
||||
- not_null:
|
||||
where: SUPPLIED_SYMBOL <> 'ETH'
|
||||
- name: SUPPLIED_SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
- name: SUPPLIER
|
||||
tests:
|
||||
- not_null
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
@ -1,258 +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 ctoken addresses and corresponding name
|
||||
-- add the collateral liquidated here
|
||||
WITH asset_details AS (
|
||||
|
||||
SELECT
|
||||
ctoken_address,
|
||||
ctoken_symbol,
|
||||
ctoken_name,
|
||||
ctoken_decimals,
|
||||
underlying_asset_address,
|
||||
underlying_name,
|
||||
underlying_symbol,
|
||||
underlying_decimals,
|
||||
compound_version
|
||||
FROM
|
||||
{{ ref('silver__comp_asset_details') }}
|
||||
|
||||
),
|
||||
compv2_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 ctoken,
|
||||
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 cTokenCollateral,
|
||||
'Compound V2' AS compound_version,
|
||||
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
|
||||
ctoken_address
|
||||
FROM
|
||||
asset_details
|
||||
WHERE
|
||||
compound_version = 'Compound V2'
|
||||
)
|
||||
AND topics [0] :: STRING = '0x298637f684da70674f26509b10f07ec2fbc77a335ab1e7d6215a4b2484d8bb52'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
),
|
||||
compv3_liquidations 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 [3] :: STRING, 27, 40)) AS asset,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS borrower,
|
||||
contract_address AS ctoken,
|
||||
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS liquidator,
|
||||
NULL AS seizeTokens_raw,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
) :: INTEGER AS repayAmount_raw,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [1] :: STRING
|
||||
) :: INTEGER AS liquidated_amount_usd,
|
||||
'Compound V3' AS compound_version,
|
||||
C.name,
|
||||
C.symbol,
|
||||
C.decimals,
|
||||
CONCAT(
|
||||
l.tx_hash,
|
||||
'-',
|
||||
l.event_index
|
||||
) AS _log_id,
|
||||
l.modified_timestamp AS _inserted_timestamp
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
l
|
||||
LEFT JOIN
|
||||
{{ ref('core__dim_contracts') }} C
|
||||
ON
|
||||
CONCAT('0x', SUBSTR(topics [3] :: STRING, 27, 40)) = C.address
|
||||
WHERE
|
||||
topics [0] = '0x9850ab1af75177e4a9201c65a2cf7976d5d28e40ef63494b44366f86b2f9412e' --AbsorbCollateral
|
||||
AND contract_address IN (
|
||||
SELECT
|
||||
ctoken_address
|
||||
FROM
|
||||
asset_details
|
||||
WHERE
|
||||
compound_version = 'Compound V3'
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND l.modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
--pull hourly prices for each undelrying
|
||||
prices AS (
|
||||
SELECT
|
||||
HOUR AS block_hour,
|
||||
token_address AS token_contract,
|
||||
ctoken_address,
|
||||
AVG(price) AS token_price
|
||||
FROM
|
||||
{{ ref('price__ez_prices_hourly') }}
|
||||
INNER JOIN asset_details
|
||||
ON token_address = underlying_asset_address
|
||||
WHERE
|
||||
HOUR :: DATE IN (
|
||||
SELECT
|
||||
block_timestamp :: DATE
|
||||
FROM
|
||||
compv2_liquidations
|
||||
)
|
||||
GROUP BY
|
||||
1,
|
||||
2,
|
||||
3
|
||||
),
|
||||
liquidation_union as (
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
borrower,
|
||||
ctoken,
|
||||
asd1.ctoken_symbol AS ctoken_symbol,
|
||||
liquidator,
|
||||
seizeTokens_raw / pow(
|
||||
10,
|
||||
asd2.ctoken_decimals
|
||||
) AS ctokens_seized,
|
||||
cTokenCollateral AS collateral_ctoken,
|
||||
asd2.ctoken_symbol AS collateral_ctoken_symbol,
|
||||
asd2.underlying_asset_address AS collateral_token,
|
||||
asd2.underlying_symbol AS collateral_symbol,
|
||||
repayAmount_raw AS liquidation_amount_unadj,
|
||||
repayAmount_raw / pow(
|
||||
10,
|
||||
asd1.underlying_decimals
|
||||
) AS liquidation_amount,
|
||||
ROUND((repayAmount_raw * p.token_price) / pow(10, asd1.underlying_decimals), 2) AS liquidation_amount_usd,
|
||||
asd1.underlying_asset_address AS liquidation_contract_address,
|
||||
asd1.underlying_symbol AS liquidation_contract_symbol,
|
||||
l.compound_version,
|
||||
l._inserted_timestamp,
|
||||
l._log_id
|
||||
FROM
|
||||
compv2_liquidations l
|
||||
LEFT JOIN prices p
|
||||
ON DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.block_hour
|
||||
AND l.ctoken = p.ctoken_address
|
||||
LEFT JOIN asset_details asd1
|
||||
ON l.ctoken = asd1.ctoken_address
|
||||
LEFT JOIN asset_details asd2
|
||||
ON l.cTokenCollateral = asd2.ctoken_address
|
||||
UNION ALL
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
borrower,
|
||||
ctoken,
|
||||
A.ctoken_symbol,
|
||||
liquidator,
|
||||
NULL AS ctokens_seized,
|
||||
NULL AS collateral_ctoken,
|
||||
NULL AS collateral_ctoken_symbol,
|
||||
A.underlying_asset_address AS collateral_token,
|
||||
A.underlying_symbol AS collateral_symbol,
|
||||
repayAmount_raw AS liquidation_amount_unadj,
|
||||
repayAmount_raw / pow(
|
||||
10,
|
||||
l.decimals
|
||||
) AS liquidation_amount,
|
||||
liquidated_amount_usd / pow(
|
||||
10,
|
||||
8
|
||||
) AS liquidation_amount_usd,
|
||||
asset AS liquidation_contract_address,
|
||||
c.symbol AS liquidation_contract_symbol,
|
||||
l.compound_version,
|
||||
l._inserted_timestamp,
|
||||
l._log_id
|
||||
FROM
|
||||
compv3_liquidations l
|
||||
LEFT JOIN {{ ref('silver__comp_asset_details') }} A
|
||||
ON l.ctoken = A.ctoken_address
|
||||
LEFT JOIN {{ ref('core__dim_contracts') }} c
|
||||
ON l.asset = c.address
|
||||
)
|
||||
SELECT
|
||||
*,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash', 'event_index']
|
||||
) }} AS comp_liquidations_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
liquidation_union qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
|
||||
@ -1,66 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__comp_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
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 14
|
||||
- name: BORROWER
|
||||
tests:
|
||||
- not_null
|
||||
- name: CTOKEN
|
||||
tests:
|
||||
- not_null
|
||||
- name: CTOKEN_SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
- name: LIQUIDATOR
|
||||
tests:
|
||||
- not_null
|
||||
- name: CTOKENS_SEIZED
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: LIQUIDATION_AMOUNT
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: LIQUIDATION_AMOUNT_USD
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: LIQUIDATION_CONTRACT_ADDRESS
|
||||
tests:
|
||||
- not_null:
|
||||
where: LIQUIDATION_CONTRACT_SYMBOL <> 'ETH'
|
||||
- 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,251 +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 ctoken addresses and corresponding name
|
||||
WITH asset_details AS (
|
||||
|
||||
SELECT
|
||||
ctoken_address,
|
||||
ctoken_symbol,
|
||||
ctoken_name,
|
||||
ctoken_decimals,
|
||||
underlying_asset_address,
|
||||
underlying_name,
|
||||
underlying_symbol,
|
||||
underlying_decimals,
|
||||
compound_version
|
||||
FROM
|
||||
{{ ref('silver__comp_asset_details') }}
|
||||
|
||||
),
|
||||
compv2_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 ctoken,
|
||||
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 [2] :: STRING
|
||||
) :: INTEGER AS redeemed_ctoken_raw,
|
||||
CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS redeemer,
|
||||
'Compound V2' AS compound_version,
|
||||
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
|
||||
ctoken_address
|
||||
FROM
|
||||
asset_details
|
||||
WHERE compound_version = 'Compound V2'
|
||||
)
|
||||
AND topics [0] :: STRING = '0xe5b754fb1abb7f01b499791d0b820ae3b6af3424ac1c59768edb53f4ec31a929'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
),
|
||||
compv3_redemptions 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 ctoken,
|
||||
CONCAT('0x', SUBSTR(topics [3] :: STRING, 27, 40)) AS asset,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
) :: INTEGER AS received_amount_raw,
|
||||
NULL AS redeemed_ctoken_raw,
|
||||
origin_from_address AS redeemer,
|
||||
'Compound V3' AS compound_version,
|
||||
CONCAT(
|
||||
tx_hash :: STRING,
|
||||
'-',
|
||||
event_index :: STRING
|
||||
) AS _log_id,
|
||||
modified_timestamp AS _inserted_timestamp
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
WHERE
|
||||
topics [0] = '0xd6d480d5b3068db003533b170d67561494d72e3bf9fa40a266471351ebba9e16' --WithdrawCollateral
|
||||
AND contract_address IN (
|
||||
SELECT
|
||||
ctoken_address
|
||||
FROM
|
||||
asset_details
|
||||
WHERE
|
||||
compound_version = 'Compound V3'
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '36 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
comp_combine AS (
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
ctoken,
|
||||
redeemer,
|
||||
received_amount_raw,
|
||||
redeemed_ctoken_raw,
|
||||
C.underlying_asset_address AS received_contract_address,
|
||||
C.underlying_symbol AS received_contract_symbol,
|
||||
C.ctoken_symbol,
|
||||
C.ctoken_decimals,
|
||||
C.underlying_decimals,
|
||||
b.compound_version,
|
||||
b._log_id,
|
||||
b._inserted_timestamp
|
||||
FROM
|
||||
compv2_redemptions b
|
||||
LEFT JOIN {{ ref('silver__comp_asset_details') }} C
|
||||
ON b.ctoken = C.ctoken_address
|
||||
UNION ALL
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
ctoken,
|
||||
redeemer,
|
||||
received_amount_raw,
|
||||
redeemed_ctoken_raw,
|
||||
b.asset AS received_contract_address,
|
||||
c.symbol AS recieved_contract_symbol,
|
||||
a.ctoken_symbol,
|
||||
a.ctoken_decimals,
|
||||
c.decimals as underlying_decimals,
|
||||
b.compound_version,
|
||||
b._log_id,
|
||||
b._inserted_timestamp
|
||||
FROM
|
||||
compv3_redemptions b
|
||||
LEFT JOIN {{ ref('core__dim_contracts') }} C
|
||||
ON b.asset = C.address
|
||||
LEFT JOIN {{ ref('silver__comp_asset_details') }} a
|
||||
ON b.ctoken = a.ctoken_address
|
||||
),
|
||||
--pull hourly prices for each underlying
|
||||
prices AS (
|
||||
SELECT
|
||||
HOUR AS block_hour,
|
||||
token_address AS token_contract,
|
||||
ctoken_address,
|
||||
AVG(price) AS token_price
|
||||
FROM
|
||||
{{ ref('price__ez_prices_hourly') }}
|
||||
LEFT JOIN asset_details
|
||||
ON token_address = underlying_asset_address
|
||||
WHERE
|
||||
HOUR :: DATE IN (
|
||||
SELECT
|
||||
block_timestamp :: DATE
|
||||
FROM
|
||||
comp_combine
|
||||
)
|
||||
AND token_address in (
|
||||
SELECT
|
||||
received_contract_address
|
||||
FROM
|
||||
comp_combine
|
||||
)
|
||||
GROUP BY
|
||||
1,
|
||||
2,
|
||||
3
|
||||
)
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
ctoken,
|
||||
ctoken_symbol,
|
||||
received_amount_raw AS received_amount_unadj,
|
||||
received_amount_raw / pow(
|
||||
10,
|
||||
underlying_decimals
|
||||
) AS received_amount,
|
||||
ROUND(
|
||||
received_amount * p.token_price,
|
||||
2
|
||||
) AS received_amount_usd,
|
||||
received_contract_address,
|
||||
received_contract_symbol,
|
||||
redeemed_ctoken_raw / pow(
|
||||
10,
|
||||
ctoken_decimals
|
||||
) AS redeemed_ctoken,
|
||||
redeemer,
|
||||
compound_version,
|
||||
_inserted_timestamp,
|
||||
_log_id,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash', 'event_index']
|
||||
) }} AS comp_redemptions_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
comp_combine ee
|
||||
LEFT JOIN prices p
|
||||
ON DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.block_hour
|
||||
AND ee.received_contract_address = p.token_contract qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,57 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__comp_redemptions
|
||||
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: CTOKEN
|
||||
tests:
|
||||
- not_null
|
||||
- name: CTOKEN_SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
- name: RECEIVED_AMOUNT
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: RECEIVED_AMOUNT_USD
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: RECEIVED_CONTRACT_ADDRESS
|
||||
tests:
|
||||
- not_null:
|
||||
where: RECEIVED_CONTRACT_SYMBOL <> 'ETH'
|
||||
- name: RECEIVED_CONTRACT_SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
- name: REDEEMED_CTOKEN
|
||||
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,239 +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 ctoken addresses and corresponding name
|
||||
WITH asset_details AS (
|
||||
|
||||
SELECT
|
||||
ctoken_address,
|
||||
ctoken_symbol,
|
||||
ctoken_name,
|
||||
ctoken_decimals,
|
||||
underlying_asset_address,
|
||||
underlying_name,
|
||||
underlying_symbol,
|
||||
underlying_decimals,
|
||||
compound_version
|
||||
FROM
|
||||
{{ ref('silver__comp_asset_details') }}
|
||||
|
||||
),
|
||||
comp_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 ctoken,
|
||||
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,
|
||||
'Compound V2' as compound_version,
|
||||
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
|
||||
ctoken_address
|
||||
FROM
|
||||
asset_details
|
||||
WHERE compound_version = 'Compound V2'
|
||||
)
|
||||
AND topics [0] :: STRING = '0x1a2a22cb034d26d1854bdc6666a5b91fe25efbbb5dcad3b0355478d6f5c362a1'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
),
|
||||
v3_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 ctoken,
|
||||
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS payer,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
) :: INTEGER AS repayed_amount_raw,
|
||||
'Compound V3' AS compound_version,
|
||||
CONCAT(
|
||||
tx_hash,
|
||||
'-',
|
||||
event_index
|
||||
) AS _log_id,
|
||||
modified_timestamp AS _inserted_timestamp
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
l
|
||||
WHERE
|
||||
topics [0] = '0xd1cf3d156d5f8f0d50f6c122ed609cec09d35c9b9fb3fff6ea0959134dae424e' --Supply
|
||||
AND contract_address IN (
|
||||
SELECT
|
||||
ctoken_address
|
||||
FROM
|
||||
asset_details
|
||||
WHERE
|
||||
compound_version = 'Compound V3'
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND l.modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '36 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
comp_combine AS (
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
borrower,
|
||||
ctoken,
|
||||
C.ctoken_symbol,
|
||||
payer,
|
||||
repayed_amount_raw,
|
||||
C.underlying_asset_address AS repay_contract_address,
|
||||
C.underlying_symbol AS repay_contract_symbol,
|
||||
C.underlying_decimals,
|
||||
b.compound_version,
|
||||
b._log_id,
|
||||
b._inserted_timestamp
|
||||
FROM
|
||||
comp_repayments b
|
||||
LEFT JOIN {{ ref('silver__comp_asset_details') }} C
|
||||
ON b.ctoken = C.ctoken_address
|
||||
UNION ALL
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
borrower,
|
||||
ctoken,
|
||||
C.ctoken_symbol,
|
||||
payer,
|
||||
repayed_amount_raw,
|
||||
C.underlying_asset_address AS repay_contract_address,
|
||||
C.underlying_symbol AS repay_contract_symbol,
|
||||
C.underlying_decimals,
|
||||
b.compound_version,
|
||||
b._log_id,
|
||||
b._inserted_timestamp
|
||||
FROM
|
||||
v3_repayments b
|
||||
LEFT JOIN {{ ref('silver__comp_asset_details') }} C
|
||||
ON b.ctoken = C.ctoken_address
|
||||
),
|
||||
|
||||
--pull hourly prices for each undelrying
|
||||
prices AS (
|
||||
SELECT
|
||||
HOUR AS block_hour,
|
||||
token_address AS token_contract,
|
||||
ctoken_address,
|
||||
AVG(price) AS token_price
|
||||
FROM
|
||||
{{ ref('price__ez_prices_hourly') }}
|
||||
INNER JOIN asset_details
|
||||
ON token_address = underlying_asset_address
|
||||
WHERE
|
||||
HOUR :: DATE IN (
|
||||
SELECT
|
||||
block_timestamp :: DATE
|
||||
FROM
|
||||
comp_combine
|
||||
)
|
||||
GROUP BY
|
||||
1,
|
||||
2,
|
||||
3
|
||||
)
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
borrower,
|
||||
ctoken,
|
||||
ctoken_symbol,
|
||||
payer,
|
||||
repay_contract_address,
|
||||
repay_contract_symbol,
|
||||
repayed_amount_raw AS repayed_amount_unadj,
|
||||
repayed_amount_raw / pow(
|
||||
10,
|
||||
underlying_decimals
|
||||
) AS repayed_amount,
|
||||
ROUND(
|
||||
repayed_amount * p.token_price,
|
||||
2
|
||||
) AS repayed_amount_usd,
|
||||
compound_version,
|
||||
_inserted_timestamp,
|
||||
_log_id,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash', 'event_index']
|
||||
) }} AS comp_repayments_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
comp_combine
|
||||
LEFT JOIN prices p
|
||||
ON DATE_TRUNC(
|
||||
'hour',
|
||||
comp_combine.block_timestamp
|
||||
) = p.block_hour
|
||||
AND comp_combine.ctoken = p.ctoken_address qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
|
||||
@ -1,54 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__comp_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
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 3
|
||||
- name: BORROWER
|
||||
tests:
|
||||
- not_null
|
||||
- name: CTOKEN
|
||||
tests:
|
||||
- not_null
|
||||
- name: CTOKEN_SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
- name: PAYER
|
||||
tests:
|
||||
- not_null
|
||||
- name: REPAY_CONTRACT_ADDRESS
|
||||
tests:
|
||||
- not_null:
|
||||
where: REPAY_CONTRACT_SYMBOL <> 'ETH'
|
||||
- name: REPAY_CONTRACT_SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
- name: REPAYED_AMOUNT
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: REPAYED_AMOUNT_USD
|
||||
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,110 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['silver','defi','lending','curated']
|
||||
) }}
|
||||
|
||||
WITH contracts AS (
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ ref('core__dim_contracts') }}
|
||||
),
|
||||
log_pull AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
contract_address,
|
||||
c.name as token_name,
|
||||
c.symbol as token_symbol,
|
||||
c.decimals as token_decimals,
|
||||
l.modified_timestamp AS _inserted_timestamp,
|
||||
CONCAT(
|
||||
l.tx_hash,
|
||||
'-',
|
||||
l.event_index
|
||||
) AS _log_id
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }} l
|
||||
LEFT JOIN
|
||||
contracts c
|
||||
ON
|
||||
CONTRACT_ADDRESS = ADDRESS
|
||||
WHERE
|
||||
topics [0] :: STRING = '0x7ac369dbd14fa5ea3f473ed67cc9d598964a77501540ba6751eb0b3decf5870d'
|
||||
AND C.name LIKE '%Cream%'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND l.modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND l.modified_timestamp >= CURRENT_DATE() - 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(TYPE, '_', trace_address) = 'STATICCALL_0_2'
|
||||
),
|
||||
contract_pull AS (
|
||||
SELECT
|
||||
l.tx_hash,
|
||||
l.block_number,
|
||||
l.block_timestamp,
|
||||
l.contract_address,
|
||||
token_name,
|
||||
token_symbol,
|
||||
token_decimals,
|
||||
CASE
|
||||
WHEN token_symbol = 'crETH' THEN LOWER('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2')
|
||||
ELSE t.underlying_asset
|
||||
END AS underlying_asset,
|
||||
l._inserted_timestamp,
|
||||
l._log_id
|
||||
FROM
|
||||
log_pull l
|
||||
LEFT JOIN traces_pull t
|
||||
ON l.contract_address = t.token_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.name AS underlying_name,
|
||||
C.symbol AS underlying_symbol,
|
||||
C.decimals AS underlying_decimals,
|
||||
l._inserted_timestamp,
|
||||
l._log_id
|
||||
FROM
|
||||
contract_pull l
|
||||
LEFT JOIN contracts C
|
||||
ON C.address = l.underlying_asset
|
||||
WHERE
|
||||
underlying_asset IS NOT NULL
|
||||
AND l.token_name IS NOT NULL
|
||||
@ -1,125 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['silver','defi','lending','curated']
|
||||
) }}
|
||||
-- pull all token addresses and corresponding name
|
||||
WITH asset_details AS (
|
||||
|
||||
SELECT
|
||||
token_address,
|
||||
token_symbol,
|
||||
token_name,
|
||||
token_decimals,
|
||||
underlying_asset_address,
|
||||
underlying_name,
|
||||
underlying_symbol,
|
||||
underlying_decimals
|
||||
FROM
|
||||
{{ ref('silver__cream_asset_details') }}
|
||||
),
|
||||
cream_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,
|
||||
'Cream' AS platform,
|
||||
modified_timestamp AS _inserted_timestamp,
|
||||
CONCAT(
|
||||
tx_hash :: STRING,
|
||||
'-',
|
||||
event_index :: STRING
|
||||
) AS _log_id
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
WHERE
|
||||
contract_address IN (
|
||||
SELECT
|
||||
token_address
|
||||
FROM
|
||||
asset_details
|
||||
)
|
||||
AND topics [0] :: STRING = '0x13ed6866d4e1ee6da46f845c46d7e54120883d75c5ea9a2dacc1c4ca8984ab80'
|
||||
AND tx_succeeded
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
cream_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
|
||||
cream_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
|
||||
cream_combine qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,42 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__cream_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,128 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['silver','defi','lending','curated']
|
||||
) }}
|
||||
-- pull all token addresses and corresponding name
|
||||
WITH asset_details AS (
|
||||
|
||||
SELECT
|
||||
token_address,
|
||||
token_symbol,
|
||||
token_name,
|
||||
token_decimals,
|
||||
underlying_asset_address,
|
||||
underlying_name,
|
||||
underlying_symbol,
|
||||
underlying_decimals
|
||||
FROM
|
||||
{{ ref('silver__cream_asset_details') }}
|
||||
),
|
||||
cream_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,
|
||||
'Cream' AS platform,
|
||||
modified_timestamp AS _inserted_timestamp,
|
||||
CONCAT(
|
||||
tx_hash :: STRING,
|
||||
'-',
|
||||
event_index :: STRING
|
||||
) AS _log_id
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
WHERE
|
||||
contract_address IN (
|
||||
SELECT
|
||||
token_address
|
||||
FROM
|
||||
asset_details
|
||||
)
|
||||
AND topics [0] :: STRING = '0x4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f'
|
||||
AND tx_succeeded
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
cream_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
|
||||
cream_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
|
||||
cream_combine qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,47 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__cream_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,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 asset_details AS (
|
||||
|
||||
SELECT
|
||||
token_address,
|
||||
token_symbol,
|
||||
token_name,
|
||||
token_decimals,
|
||||
underlying_asset_address,
|
||||
underlying_name,
|
||||
underlying_symbol,
|
||||
underlying_decimals
|
||||
FROM
|
||||
{{ ref('silver__cream_asset_details') }}
|
||||
),
|
||||
cream_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,
|
||||
'Cream' AS platform,
|
||||
modified_timestamp AS _inserted_timestamp,
|
||||
CONCAT(
|
||||
tx_hash :: STRING,
|
||||
'-',
|
||||
event_index :: STRING
|
||||
) AS _log_id
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
WHERE
|
||||
contract_address IN (
|
||||
SELECT
|
||||
token_address
|
||||
FROM
|
||||
asset_details
|
||||
)
|
||||
AND topics [0] :: STRING = '0x298637f684da70674f26509b10f07ec2fbc77a335ab1e7d6215a4b2484d8bb52'
|
||||
AND tx_succeeded
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
liquidation_union AS (
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
borrower,
|
||||
token,
|
||||
asd1.token_symbol AS token_symbol,
|
||||
liquidator,
|
||||
seizeTokens_raw / pow(
|
||||
10,
|
||||
asd2.token_decimals
|
||||
) AS tokens_seized,
|
||||
tokenCollateral AS protocol_market,
|
||||
asd2.token_symbol AS collateral_token_symbol,
|
||||
asd2.underlying_asset_address AS collateral_token,
|
||||
asd2.underlying_symbol AS collateral_symbol,
|
||||
repayAmount_raw AS amount_unadj,
|
||||
repayAmount_raw / pow(
|
||||
10,
|
||||
asd1.underlying_decimals
|
||||
) AS amount,
|
||||
asd1.underlying_decimals,
|
||||
asd1.underlying_asset_address AS liquidation_contract_address,
|
||||
asd1.underlying_symbol AS liquidation_contract_symbol,
|
||||
l.platform,
|
||||
l._inserted_timestamp,
|
||||
l._log_id
|
||||
FROM
|
||||
cream_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__cream_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,122 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['silver','defi','lending','curated']
|
||||
) }}
|
||||
-- pull all token addresses and corresponding name
|
||||
WITH asset_details AS (
|
||||
|
||||
SELECT
|
||||
token_address,
|
||||
token_symbol,
|
||||
token_name,
|
||||
token_decimals,
|
||||
underlying_asset_address,
|
||||
underlying_name,
|
||||
underlying_symbol,
|
||||
underlying_decimals
|
||||
FROM
|
||||
{{ ref('silver__cream_asset_details') }}
|
||||
),
|
||||
cream_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,
|
||||
'Cream' AS platform,
|
||||
modified_timestamp AS _inserted_timestamp,
|
||||
CONCAT(
|
||||
tx_hash :: STRING,
|
||||
'-',
|
||||
event_index :: STRING
|
||||
) AS _log_id
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
WHERE
|
||||
contract_address IN (
|
||||
SELECT
|
||||
token_address
|
||||
FROM
|
||||
asset_details
|
||||
)
|
||||
AND topics [0] :: STRING = '0x1a2a22cb034d26d1854bdc6666a5b91fe25efbbb5dcad3b0355478d6f5c362a1'
|
||||
AND tx_succeeded
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
cream_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
|
||||
cream_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
|
||||
cream_combine qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,44 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__cream_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__cream_asset_details') }}
|
||||
),
|
||||
cream_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,
|
||||
'Cream' 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 %}
|
||||
),
|
||||
cream_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
|
||||
cream_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
|
||||
cream_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__cream_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,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 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('0x690043fB6826F9D9381C56f43971F4F044BcE3Aa')
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= CURRENT_DATE() - 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_0_2'
|
||||
),
|
||||
contracts AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ ref('core__dim_contracts') }}
|
||||
),
|
||||
contract_pull AS (
|
||||
SELECT
|
||||
l.tx_hash,
|
||||
l.block_number,
|
||||
l.block_timestamp,
|
||||
l.contract_address,
|
||||
C.name AS token_name,
|
||||
C.symbol AS token_symbol,
|
||||
C.decimals AS token_decimals,
|
||||
CASE
|
||||
WHEN token_symbol = 'fETH' THEN LOWER('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2')
|
||||
ELSE t.underlying_asset
|
||||
END AS 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.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.name AS underlying_name,
|
||||
C.symbol AS underlying_symbol,
|
||||
C.decimals AS underlying_decimals,
|
||||
l._inserted_timestamp,
|
||||
l._log_id
|
||||
FROM
|
||||
contract_pull l
|
||||
LEFT JOIN contracts C
|
||||
ON C.address = l.underlying_asset
|
||||
WHERE
|
||||
underlying_asset IS NOT NULL
|
||||
AND l.token_name IS NOT NULL
|
||||
@ -1,125 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['silver','defi','lending','curated']
|
||||
) }}
|
||||
-- pull all token addresses and corresponding name
|
||||
WITH asset_details AS (
|
||||
|
||||
SELECT
|
||||
token_address,
|
||||
token_symbol,
|
||||
token_name,
|
||||
token_decimals,
|
||||
underlying_asset_address,
|
||||
underlying_name,
|
||||
underlying_symbol,
|
||||
underlying_decimals
|
||||
FROM
|
||||
{{ ref('silver__flux_asset_details') }}
|
||||
),
|
||||
flux_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,
|
||||
'Flux' AS platform,
|
||||
modified_timestamp AS _inserted_timestamp,
|
||||
CONCAT(
|
||||
tx_hash :: STRING,
|
||||
'-',
|
||||
event_index :: STRING
|
||||
) AS _log_id
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
WHERE
|
||||
contract_address IN (
|
||||
SELECT
|
||||
token_address
|
||||
FROM
|
||||
asset_details
|
||||
)
|
||||
AND topics [0] :: STRING = '0x13ed6866d4e1ee6da46f845c46d7e54120883d75c5ea9a2dacc1c4ca8984ab80'
|
||||
AND tx_succeeded
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
flux_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
|
||||
flux_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
|
||||
flux_combine qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,42 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__flux_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,128 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['silver','defi','lending','curated']
|
||||
) }}
|
||||
-- pull all token addresses and corresponding name
|
||||
WITH asset_details AS (
|
||||
|
||||
SELECT
|
||||
token_address,
|
||||
token_symbol,
|
||||
token_name,
|
||||
token_decimals,
|
||||
underlying_asset_address,
|
||||
underlying_name,
|
||||
underlying_symbol,
|
||||
underlying_decimals
|
||||
FROM
|
||||
{{ ref('silver__flux_asset_details') }}
|
||||
),
|
||||
flux_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,
|
||||
'Flux' AS platform,
|
||||
modified_timestamp AS _inserted_timestamp,
|
||||
CONCAT(
|
||||
tx_hash :: STRING,
|
||||
'-',
|
||||
event_index :: STRING
|
||||
) AS _log_id
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
WHERE
|
||||
contract_address IN (
|
||||
SELECT
|
||||
token_address
|
||||
FROM
|
||||
asset_details
|
||||
)
|
||||
AND topics [0] :: STRING = '0x4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f'
|
||||
AND tx_succeeded
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
flux_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
|
||||
flux_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
|
||||
flux_combine qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,47 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__flux_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,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 asset_details AS (
|
||||
|
||||
SELECT
|
||||
token_address,
|
||||
token_symbol,
|
||||
token_name,
|
||||
token_decimals,
|
||||
underlying_asset_address,
|
||||
underlying_name,
|
||||
underlying_symbol,
|
||||
underlying_decimals
|
||||
FROM
|
||||
{{ ref('silver__flux_asset_details') }}
|
||||
),
|
||||
flux_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,
|
||||
'Flux' AS platform,
|
||||
modified_timestamp AS _inserted_timestamp,
|
||||
CONCAT(
|
||||
tx_hash :: STRING,
|
||||
'-',
|
||||
event_index :: STRING
|
||||
) AS _log_id
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
WHERE
|
||||
contract_address IN (
|
||||
SELECT
|
||||
token_address
|
||||
FROM
|
||||
asset_details
|
||||
)
|
||||
AND topics [0] :: STRING = '0x298637f684da70674f26509b10f07ec2fbc77a335ab1e7d6215a4b2484d8bb52'
|
||||
AND tx_succeeded
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
liquidation_union AS (
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
borrower,
|
||||
token,
|
||||
asd1.token_symbol AS token_symbol,
|
||||
liquidator,
|
||||
seizeTokens_raw / pow(
|
||||
10,
|
||||
asd2.token_decimals
|
||||
) AS tokens_seized,
|
||||
tokenCollateral AS protocol_market,
|
||||
asd2.token_symbol AS collateral_token_symbol,
|
||||
asd2.underlying_asset_address AS collateral_token,
|
||||
asd2.underlying_symbol AS collateral_symbol,
|
||||
repayAmount_raw AS amount_unadj,
|
||||
repayAmount_raw / pow(
|
||||
10,
|
||||
asd1.underlying_decimals
|
||||
) AS amount,
|
||||
asd1.underlying_decimals,
|
||||
asd1.underlying_asset_address AS liquidation_contract_address,
|
||||
asd1.underlying_symbol AS liquidation_contract_symbol,
|
||||
l.platform,
|
||||
l._inserted_timestamp,
|
||||
l._log_id
|
||||
FROM
|
||||
flux_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__flux_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,122 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['silver','defi','lending','curated']
|
||||
) }}
|
||||
-- pull all token addresses and corresponding name
|
||||
WITH asset_details AS (
|
||||
|
||||
SELECT
|
||||
token_address,
|
||||
token_symbol,
|
||||
token_name,
|
||||
token_decimals,
|
||||
underlying_asset_address,
|
||||
underlying_name,
|
||||
underlying_symbol,
|
||||
underlying_decimals
|
||||
FROM
|
||||
{{ ref('silver__flux_asset_details') }}
|
||||
),
|
||||
flux_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,
|
||||
'Flux' AS platform,
|
||||
modified_timestamp AS _inserted_timestamp,
|
||||
CONCAT(
|
||||
tx_hash :: STRING,
|
||||
'-',
|
||||
event_index :: STRING
|
||||
) AS _log_id
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
WHERE
|
||||
contract_address IN (
|
||||
SELECT
|
||||
token_address
|
||||
FROM
|
||||
asset_details
|
||||
)
|
||||
AND topics [0] :: STRING = '0x1a2a22cb034d26d1854bdc6666a5b91fe25efbbb5dcad3b0355478d6f5c362a1'
|
||||
AND tx_succeeded
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
flux_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
|
||||
flux_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
|
||||
flux_combine qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,44 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__flux_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__flux_asset_details') }}
|
||||
),
|
||||
flux_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,
|
||||
'Flux' 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 %}
|
||||
),
|
||||
flux_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
|
||||
flux_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
|
||||
flux_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__flux_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,75 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
unique_key = '_log_id',
|
||||
tags = ['silver','defi','lending','curated']
|
||||
) }}
|
||||
|
||||
WITH logs AS (
|
||||
|
||||
SELECT
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
CASE
|
||||
WHEN topics [0] = '0xb7f7e57b7bb3a5186ad1bd43405339ba361555344aec7a4be01968e88ee3883e' THEN CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40))
|
||||
WHEN topics [0] = '0x9303649990c462969a3c46d4e2c758166e92f5a4b18c67f26d3e58d2b0660e67' THEN CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 42))
|
||||
WHEN topics [0] = '0xc6fa598658c9cdf9eaa5f76414ef17a38a7f74c0e719a0571a3f73d9ecd755b7' THEN CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 42))
|
||||
END AS pool_address,*
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
WHERE
|
||||
topics [0] IN (
|
||||
'0xb7f7e57b7bb3a5186ad1bd43405339ba361555344aec7a4be01968e88ee3883e',
|
||||
'0x9303649990c462969a3c46d4e2c758166e92f5a4b18c67f26d3e58d2b0660e67',
|
||||
'0xc6fa598658c9cdf9eaa5f76414ef17a38a7f74c0e719a0571a3f73d9ecd755b7'
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '36 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND modified_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
),
|
||||
logs_transform AS (
|
||||
SELECT
|
||||
pool_address AS frax_market_address,
|
||||
NAME AS frax_market_name,
|
||||
symbol AS frax_market_symbol,
|
||||
decimals,
|
||||
CONCAT('0x', SUBSTR(topics [3] :: STRING, 27, 42)) AS underlying_asset,
|
||||
CONCAT(
|
||||
l.tx_hash,
|
||||
'-',
|
||||
l.event_index
|
||||
) AS _log_id,
|
||||
l.modified_timestamp AS _inserted_timestamp
|
||||
FROM
|
||||
logs l
|
||||
LEFT JOIN {{ ref('core__dim_contracts') }}
|
||||
ON address = pool_address
|
||||
)
|
||||
SELECT
|
||||
frax_market_address,
|
||||
frax_market_name,
|
||||
frax_market_symbol,
|
||||
l.decimals,
|
||||
c.name AS underlying_name,
|
||||
underlying_asset,
|
||||
c.symbol AS underlying_symbol,
|
||||
c.decimals AS underlying_decimals,
|
||||
l._log_id,
|
||||
l._inserted_timestamp
|
||||
FROM
|
||||
logs_transform l
|
||||
LEFT JOIN
|
||||
{{ ref('core__dim_contracts') }} c
|
||||
ON
|
||||
c.address = underlying_asset
|
||||
WHERE
|
||||
frax_market_name IS NOT NULL
|
||||
AND
|
||||
c.decimals IS NOT NULL
|
||||
@ -1,97 +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_join AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_timestamp,
|
||||
block_number,
|
||||
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, 42)) AS borrower,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 42)) AS receiver,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
) :: INTEGER AS borrow_amount_unadj,
|
||||
borrow_amount_unadj / pow(
|
||||
10,
|
||||
decimals
|
||||
) AS borrow_amount,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [1] :: STRING
|
||||
) :: INTEGER / pow(
|
||||
10,
|
||||
decimals
|
||||
) AS shares_added,
|
||||
borrow_amount / NULLIF(
|
||||
shares_added,
|
||||
0
|
||||
) AS borrow_share_price,
|
||||
f.frax_market_address,
|
||||
f.frax_market_symbol,
|
||||
f.underlying_asset,
|
||||
f.underlying_symbol,
|
||||
CONCAT(
|
||||
l.tx_hash,
|
||||
'-',
|
||||
l.event_index
|
||||
) AS _log_id,
|
||||
l.modified_timestamp AS _inserted_timestamp
|
||||
FROM
|
||||
{{ ref('silver__fraxlend_asset_details') }}
|
||||
f
|
||||
LEFT JOIN {{ ref('core__fact_event_logs') }}
|
||||
l
|
||||
ON f.frax_market_address = l.contract_address
|
||||
WHERE
|
||||
topics [0] = '0x01348584ec81ac7acd52b7d66d9ade986dd909f3d513881c190fc31c90527efe'
|
||||
AND tx_succeeded
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND l.modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_timestamp,
|
||||
block_number,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
borrower,
|
||||
receiver,
|
||||
borrow_amount_unadj,
|
||||
borrow_amount,
|
||||
shares_added,
|
||||
borrow_share_price,
|
||||
frax_market_address,
|
||||
frax_market_symbol,
|
||||
lower('0x853d955aCEf822Db058eb8505911ED77F175b99e') AS borrow_asset,
|
||||
'FRAX' AS borrow_symbol,
|
||||
underlying_asset AS collateral_asset,
|
||||
underlying_symbol,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
log_join qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,61 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__fraxlend_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: 3
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: BORROWER
|
||||
tests:
|
||||
- not_null
|
||||
- name: RECEIVER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BORROW_AMOUNT
|
||||
tests:
|
||||
- not_null
|
||||
- name: BORROWED_AMOUNT_USD
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: SHARES_ADDED
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: BORROWED_SHARE_PRICE
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: FRAX_MARKET_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: FRAX_MARKET_SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
- name: SYMBOL
|
||||
- name: BORROW_ASSET
|
||||
tests:
|
||||
- not_null
|
||||
@ -1,85 +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_join AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_timestamp,
|
||||
block_number,
|
||||
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, 42)) AS caller,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 42)) AS owner,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
) :: INTEGER AS deposit_amount_unadj,
|
||||
deposit_amount_unadj / pow(
|
||||
10,
|
||||
f.underlying_decimals
|
||||
) AS deposit_amount,
|
||||
f.frax_market_address,
|
||||
f.frax_market_symbol,
|
||||
f.underlying_asset,
|
||||
f.underlying_symbol,
|
||||
f.underlying_decimals,
|
||||
CONCAT(
|
||||
l.tx_hash,
|
||||
'-',
|
||||
l.event_index
|
||||
) AS _log_id,
|
||||
l.modified_timestamp AS _inserted_timestamp
|
||||
FROM
|
||||
{{ ref('silver__fraxlend_asset_details') }}
|
||||
f
|
||||
LEFT JOIN {{ ref('core__fact_event_logs') }}
|
||||
l
|
||||
ON f.frax_market_address = l.contract_address
|
||||
WHERE
|
||||
topics [0] = '0xa32435755c235de2976ed44a75a2f85cb01faf0c894f639fe0c32bb9455fea8f'
|
||||
AND tx_succeeded
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND l.modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_timestamp,
|
||||
block_number,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
caller,
|
||||
owner,
|
||||
deposit_amount_unadj,
|
||||
deposit_amount,
|
||||
frax_market_address,
|
||||
frax_market_symbol,
|
||||
underlying_asset AS deposit_asset,
|
||||
underlying_symbol,
|
||||
underlying_decimals,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
log_join qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,61 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__fraxlend_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: 3
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: CALLER
|
||||
tests:
|
||||
- not_null
|
||||
- name: OWNER
|
||||
tests:
|
||||
- not_null
|
||||
- name: DEPOSIT_AMOUNT
|
||||
tests:
|
||||
- not_null
|
||||
- name: DEPOSIT_AMOUNT_USD
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: DEPOSIT_SHARES
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: DEPOSIT_SHARE_PRICE
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: FRAX_MARKET_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: FRAX_MARKET_SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
- name: SYMBOL
|
||||
- name: DEPOSIT_ASSET
|
||||
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 log_join AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_timestamp,
|
||||
block_number,
|
||||
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,
|
||||
origin_from_address AS liquidator,
|
||||
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 42)) AS borrower,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
) :: INTEGER AS collateral_for_liquidator_unadj,
|
||||
collateral_for_liquidator_unadj / pow(
|
||||
10,
|
||||
f.underlying_decimals
|
||||
) AS collateral_for_liquidator,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [1] :: STRING
|
||||
) :: INTEGER / pow(
|
||||
10,
|
||||
decimals
|
||||
) AS shares_to_liquidate,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [2] :: STRING
|
||||
) :: INTEGER / pow(
|
||||
10,
|
||||
decimals
|
||||
) AS liquidator_repay_amount,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [3] :: STRING
|
||||
) :: INTEGER / pow(
|
||||
10,
|
||||
decimals
|
||||
) AS shares_to_adjust,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [4] :: STRING
|
||||
) :: INTEGER / pow(
|
||||
10,
|
||||
decimals
|
||||
) AS amount_to_adjust,
|
||||
liquidator_repay_amount / NULLIF(
|
||||
shares_to_liquidate,
|
||||
0
|
||||
) AS liquidator_share_price,
|
||||
f.frax_market_address,
|
||||
f.frax_market_symbol,
|
||||
f.underlying_asset,
|
||||
f.underlying_symbol,
|
||||
f.underlying_decimals,
|
||||
CONCAT(
|
||||
l.tx_hash,
|
||||
'-',
|
||||
l.event_index
|
||||
) AS _log_id,
|
||||
l.modified_timestamp AS _inserted_timestamp
|
||||
FROM
|
||||
{{ ref('silver__fraxlend_asset_details') }}
|
||||
f
|
||||
LEFT JOIN {{ ref('core__fact_event_logs') }}
|
||||
l
|
||||
ON f.frax_market_address = l.contract_address
|
||||
WHERE
|
||||
topics [0] = '0x35f432a64bd3767447a456650432406c6cacb885819947a202216eeea6820ecf'
|
||||
AND tx_succeeded
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND l.modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_timestamp,
|
||||
block_number,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
liquidator,
|
||||
borrower,
|
||||
collateral_for_liquidator_unadj,
|
||||
collateral_for_liquidator,
|
||||
shares_to_liquidate,
|
||||
liquidator_repay_amount,
|
||||
shares_to_adjust,
|
||||
amount_to_adjust,
|
||||
liquidator_share_price,
|
||||
LOWER('0x853d955aCEf822Db058eb8505911ED77F175b99e') AS debt_asset,
|
||||
frax_market_address,
|
||||
frax_market_symbol,
|
||||
underlying_asset,
|
||||
underlying_symbol,
|
||||
underlying_decimals,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
log_join l qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,76 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__fraxlend_liquidations
|
||||
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: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: LIQUIDATOR
|
||||
tests:
|
||||
- not_null
|
||||
- name: BORROWER
|
||||
tests:
|
||||
- not_null
|
||||
- name: COLLATERAL_FOR_LIQUIDATOR
|
||||
tests:
|
||||
- not_null
|
||||
- name: SHARES_TO_LIQUIDATE
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: LIQUIDATOR_REPAY_AMOUNT
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: LIQUIDATOR_REPAY_AMOUNT_USD
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: SHARES_TO_ADJUST
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: AMOUNT_TO_ADJUST
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: LIQUIDATOR_SHARE_PRICE
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: FRAX_MARKET_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: FRAX_MARKET_SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
- name: SYMBOL
|
||||
- name: UNDERLYING_ASSET
|
||||
tests:
|
||||
- not_null
|
||||
@ -1,100 +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_join AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_timestamp,
|
||||
block_number,
|
||||
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, 42)) AS payer,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 42)) AS borrower,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
) :: INTEGER AS repay_amount_unadj,
|
||||
repay_amount_unadj / pow(
|
||||
10,
|
||||
decimals
|
||||
) AS repay_amount,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [1] :: STRING
|
||||
) :: INTEGER / pow(
|
||||
10,
|
||||
decimals
|
||||
) AS repay_shares,
|
||||
repay_amount / NULLIF(
|
||||
repay_shares,
|
||||
0
|
||||
) AS repay_share_price,
|
||||
f.frax_market_address,
|
||||
f.frax_market_symbol,
|
||||
f.underlying_asset,
|
||||
f.underlying_symbol,
|
||||
f.underlying_decimals,
|
||||
CONCAT(
|
||||
l.tx_hash,
|
||||
'-',
|
||||
l.event_index
|
||||
) AS _log_id,
|
||||
l.modified_timestamp AS _inserted_timestamp
|
||||
FROM
|
||||
{{ ref('silver__fraxlend_asset_details') }}
|
||||
f
|
||||
LEFT JOIN {{ ref('core__fact_event_logs') }}
|
||||
l
|
||||
ON f.frax_market_address = l.contract_address
|
||||
WHERE
|
||||
topics [0] = '0x9dc1449a0ff0c152e18e8289d865b47acc6e1b76b1ecb239c13d6ee22a9206a7'
|
||||
AND tx_succeeded
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND l.modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_timestamp,
|
||||
block_number,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
payer,
|
||||
borrower,
|
||||
repay_amount_unadj,
|
||||
repay_amount,
|
||||
repay_shares,
|
||||
repay_share_price,
|
||||
frax_market_address,
|
||||
frax_market_symbol,
|
||||
lower('0x853d955aCEf822Db058eb8505911ED77F175b99e') AS repay_asset,
|
||||
'FRAX' AS repay_symbol,
|
||||
underlying_asset,
|
||||
underlying_symbol,
|
||||
underlying_decimals,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
log_join l qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
|
||||
@ -1,64 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__fraxlend_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
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 7
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: PAYER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BORROWER
|
||||
tests:
|
||||
- not_null
|
||||
- name: REPAY_AMOUNT
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: REPAYED_AMOUNT_USD
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: REPAY_SHARES
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: REPAY_SHARE_PRICE
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: FRAX_MARKET_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: FRAX_MARKET_SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
- name: SYMBOL
|
||||
- name: UNDERLYING_ASSET
|
||||
tests:
|
||||
- not_null
|
||||
@ -1,87 +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_join AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_timestamp,
|
||||
block_number,
|
||||
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, 42)) AS caller,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 42)) AS receiver,
|
||||
CONCAT('0x', SUBSTR(topics [3] :: STRING, 27, 42)) AS owner,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
) :: INTEGER AS withdraw_amount_unadj,
|
||||
withdraw_amount_unadj / pow(
|
||||
10,
|
||||
f.underlying_decimals
|
||||
) AS withdraw_amount,
|
||||
f.frax_market_address,
|
||||
f.frax_market_symbol,
|
||||
f.underlying_asset,
|
||||
f.underlying_symbol,
|
||||
f.underlying_decimals,
|
||||
CONCAT(
|
||||
l.tx_hash,
|
||||
'-',
|
||||
l.event_index
|
||||
) AS _log_id,
|
||||
l.modified_timestamp AS _inserted_timestamp
|
||||
FROM
|
||||
{{ ref('silver__fraxlend_asset_details') }}
|
||||
f
|
||||
LEFT JOIN {{ ref('core__fact_event_logs') }}
|
||||
l
|
||||
ON f.frax_market_address = l.contract_address
|
||||
WHERE
|
||||
topics [0] = '0xbc290bb45104f73cf92115c9603987c3f8fd30c182a13603d8cffa49b5f59952'
|
||||
AND tx_succeeded
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND l.modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_timestamp,
|
||||
block_number,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
caller,
|
||||
receiver,
|
||||
owner,
|
||||
withdraw_amount_unadj,
|
||||
withdraw_amount,
|
||||
frax_market_address,
|
||||
frax_market_symbol,
|
||||
underlying_asset,
|
||||
underlying_symbol,
|
||||
underlying_decimals,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
log_join qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -1,67 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__fraxlend_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: 3
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: CALLER
|
||||
tests:
|
||||
- not_null
|
||||
- name: RECEIVER
|
||||
tests:
|
||||
- not_null
|
||||
- name: OWNER
|
||||
tests:
|
||||
- not_null
|
||||
- name: WITHDRAW_AMOUNT
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: WITHDRAW_AMOUNT_USD
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: WITHDRAW_SHARES
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: WITHDRAW_SHARES_PRICE
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: FRAX_MARKET_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: FRAX_MARKET_SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
- name: SYMBOL
|
||||
- name: UNDERLYING_ASSET
|
||||
tests:
|
||||
- not_null
|
||||
@ -1,123 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['silver','defi','lending','curated']
|
||||
) }}
|
||||
|
||||
WITH traces AS (
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
tx_hash,
|
||||
block_timestamp,
|
||||
from_address,
|
||||
to_address,
|
||||
LEFT(
|
||||
input,
|
||||
10
|
||||
) AS function_sig,
|
||||
regexp_substr_all(SUBSTR(input, 11), '.{64}') AS segmented_input,
|
||||
CONCAT('0x', SUBSTR(segmented_input [0] :: STRING, 25)) AS loan_token,
|
||||
CONCAT('0x', SUBSTR(segmented_input [1] :: STRING, 25)) AS collateral_token,
|
||||
CONCAT('0x', SUBSTR(segmented_input [2] :: STRING, 25)) AS oracle_address,
|
||||
CONCAT('0x', SUBSTR(segmented_input [3] :: STRING, 25)) AS irm_address,
|
||||
TRY_TO_NUMBER(
|
||||
utils.udf_hex_to_int(
|
||||
segmented_input [4] :: STRING
|
||||
)
|
||||
) AS lltv,
|
||||
TRY_TO_NUMBER(
|
||||
utils.udf_hex_to_int(
|
||||
segmented_input [5] :: STRING
|
||||
)
|
||||
) AS amount,
|
||||
TRY_TO_NUMBER(
|
||||
utils.udf_hex_to_int(
|
||||
segmented_input [6] :: STRING
|
||||
)
|
||||
) AS shares,
|
||||
CONCAT('0x', SUBSTR(segmented_input [7] :: STRING, 25)) AS on_behalf_address,
|
||||
CONCAT('0x', SUBSTR(segmented_input [8] :: STRING, 25)) AS receiver_address,
|
||||
concat_ws(
|
||||
'-',
|
||||
block_number,
|
||||
tx_position,
|
||||
CONCAT(
|
||||
TYPE,
|
||||
'_',
|
||||
trace_address
|
||||
)
|
||||
) AS _call_id,
|
||||
modified_timestamp AS _inserted_timestamp
|
||||
FROM
|
||||
{{ ref('core__fact_traces') }}
|
||||
t
|
||||
WHERE
|
||||
to_address = '0xbbbbbbbbbb9cc5e90e3b3af64bdaf62c37eeffcb' --Morpho Blue
|
||||
AND function_sig = '0x50d8cd4b'
|
||||
AND trace_succeeded
|
||||
AND tx_succeeded
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
),
|
||||
tx_join AS (
|
||||
SELECT
|
||||
tx.block_number,
|
||||
tx.tx_hash,
|
||||
tx.block_timestamp,
|
||||
tx.from_address AS origin_from_address,
|
||||
tx.to_address AS origin_to_address,
|
||||
tx.origin_function_signature,
|
||||
t.from_address,
|
||||
t.to_address AS contract_address,
|
||||
tx.from_address AS borrower_address,
|
||||
t.loan_token,
|
||||
t.collateral_token,
|
||||
t.amount,
|
||||
t.on_behalf_address,
|
||||
t.receiver_address,
|
||||
t._call_id,
|
||||
t._inserted_timestamp
|
||||
FROM
|
||||
traces t
|
||||
INNER JOIN {{ ref('core__fact_transactions') }}
|
||||
tx
|
||||
ON tx.block_number = t.block_number
|
||||
AND tx.tx_hash = t.tx_hash
|
||||
)
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
loan_token AS market,
|
||||
amount AS amount_unadj,
|
||||
amount / pow(
|
||||
10,
|
||||
C.decimals
|
||||
) AS amount,
|
||||
C.symbol,
|
||||
C.decimals,
|
||||
borrower_address,
|
||||
contract_address AS lending_pool_contract,
|
||||
'Morpho Blue' AS platform,
|
||||
'ethereum' AS blockchain,
|
||||
_call_id AS _id,
|
||||
t._inserted_timestamp
|
||||
FROM
|
||||
tx_join t
|
||||
LEFT JOIN {{ ref('core__dim_contracts') }} C
|
||||
ON address = t.loan_token
|
||||
@ -1,42 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__morpho_borrows
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- _ID
|
||||
columns:
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- name: MARKET
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT_UNADJ
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: BORROWER_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: LENDING_POOL_CONTRACT
|
||||
tests:
|
||||
- not_null
|
||||
- name: PLATFORM
|
||||
tests:
|
||||
- not_null
|
||||
- name: SYMBOL
|
||||
- name: BLOCKCHAIN
|
||||
tests:
|
||||
- not_null
|
||||
@ -1,123 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['silver','defi','lending','curated']
|
||||
) }}
|
||||
|
||||
WITH traces AS (
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
tx_hash,
|
||||
block_timestamp,
|
||||
from_address,
|
||||
to_address,
|
||||
LEFT(
|
||||
input,
|
||||
10
|
||||
) AS function_sig,
|
||||
regexp_substr_all(SUBSTR(input, 11), '.{64}') AS segmented_input,
|
||||
CONCAT('0x', SUBSTR(segmented_input [0] :: STRING, 25)) AS loan_token,
|
||||
CONCAT('0x', SUBSTR(segmented_input [1] :: STRING, 25)) AS collateral_token,
|
||||
CONCAT('0x', SUBSTR(segmented_input [2] :: STRING, 25)) AS oracle_address,
|
||||
CONCAT('0x', SUBSTR(segmented_input [3] :: STRING, 25)) AS irm_address,
|
||||
TRY_TO_NUMBER(
|
||||
utils.udf_hex_to_int(
|
||||
segmented_input [4] :: STRING
|
||||
)
|
||||
) AS lltv,
|
||||
TRY_TO_NUMBER(
|
||||
utils.udf_hex_to_int(
|
||||
segmented_input [5] :: STRING
|
||||
)
|
||||
) AS amount,
|
||||
TRY_TO_NUMBER(
|
||||
utils.udf_hex_to_int(
|
||||
segmented_input [6] :: STRING
|
||||
)
|
||||
) AS shares,
|
||||
CONCAT('0x', SUBSTR(segmented_input [7] :: STRING, 25)) AS on_behalf_address,
|
||||
CONCAT('0x', SUBSTR(segmented_input [8] :: STRING, 25)) AS receiver_address,
|
||||
concat_ws(
|
||||
'-',
|
||||
block_number,
|
||||
tx_position,
|
||||
CONCAT(
|
||||
TYPE,
|
||||
'_',
|
||||
trace_address
|
||||
)
|
||||
) AS _call_id,
|
||||
modified_timestamp AS _inserted_timestamp
|
||||
FROM
|
||||
{{ ref('core__fact_traces') }}
|
||||
t
|
||||
WHERE
|
||||
to_address = '0xbbbbbbbbbb9cc5e90e3b3af64bdaf62c37eeffcb' --Morpho Blue
|
||||
AND function_sig = '0xa99aad89'
|
||||
AND trace_succeeded
|
||||
AND tx_succeeded
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
),
|
||||
tx_join AS (
|
||||
SELECT
|
||||
tx.block_number,
|
||||
tx.tx_hash,
|
||||
tx.block_timestamp,
|
||||
tx.from_address AS origin_from_address,
|
||||
tx.to_address AS origin_to_address,
|
||||
tx.origin_function_signature,
|
||||
t.from_address,
|
||||
t.to_address AS contract_address,
|
||||
tx.from_address AS depositor_address,
|
||||
t.loan_token,
|
||||
t.collateral_token,
|
||||
t.amount,
|
||||
t.on_behalf_address,
|
||||
t.receiver_address,
|
||||
t._call_id,
|
||||
t._inserted_timestamp
|
||||
FROM
|
||||
traces t
|
||||
INNER JOIN {{ ref('core__fact_transactions') }}
|
||||
tx
|
||||
ON tx.block_number = t.block_number
|
||||
AND tx.tx_hash = t.tx_hash
|
||||
)
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
loan_token AS market,
|
||||
amount AS amount_unadj,
|
||||
amount / pow(
|
||||
10,
|
||||
C.decimals
|
||||
) AS amount,
|
||||
C.symbol,
|
||||
C.decimals,
|
||||
depositor_address,
|
||||
contract_address AS lending_pool_contract,
|
||||
'Morpho Blue' AS platform,
|
||||
'ethereum' AS blockchain,
|
||||
_call_id AS _id,
|
||||
t._inserted_timestamp
|
||||
FROM
|
||||
tx_join t
|
||||
LEFT JOIN {{ ref('core__dim_contracts') }} C
|
||||
ON address = t.loan_token
|
||||
@ -1,42 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__morpho_deposits
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- _ID
|
||||
columns:
|
||||
- name: BLOCKCHAIN
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT_UNADJ
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: MARKET
|
||||
tests:
|
||||
- not_null
|
||||
- name: DEPOSITOR_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: LENDING_POOL_CONTRACT
|
||||
tests:
|
||||
- not_null
|
||||
- name: PLATFORM
|
||||
tests:
|
||||
- not_null
|
||||
- name: SYMBOL
|
||||
@ -1,75 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['silver','defi','lending','curated']
|
||||
) }}
|
||||
|
||||
with flashloan AS(
|
||||
|
||||
SELECT
|
||||
l.tx_hash,
|
||||
l.block_number,
|
||||
l.block_timestamp,
|
||||
l.event_index,
|
||||
l.origin_from_address,
|
||||
l.origin_to_address,
|
||||
l.origin_function_signature,
|
||||
l.contract_address,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS caller,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS token,
|
||||
try_to_number(
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
))
|
||||
AS flashloan_quantity,
|
||||
CONCAT(
|
||||
l.tx_hash,
|
||||
'-',
|
||||
l.event_index
|
||||
) AS _log_id,
|
||||
l.modified_timestamp AS _inserted_timestamp
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
l
|
||||
WHERE
|
||||
topics[0]::STRING = '0xc76f1b4fe4396ac07a9fa55a415d4ca430e72651d37d3401f3bed7cb13fc4f12'
|
||||
AND contract_address = '0xbbbbbbbbbb9cc5e90e3b3af64bdaf62c37eeffcb'
|
||||
{% if is_incremental() %}
|
||||
AND l.modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
caller as initiator_address,
|
||||
token as market,
|
||||
c.symbol,
|
||||
flashloan_quantity AS flashloan_amount_unadj,
|
||||
flashloan_quantity / pow(
|
||||
10,
|
||||
c.decimals
|
||||
) AS flashloan_amount,
|
||||
'Morpho Blue' AS platform,
|
||||
'ethereum' AS blockchain,
|
||||
f._log_id,
|
||||
f._inserted_timestamp
|
||||
FROM
|
||||
flashloan f
|
||||
LEFT JOIN {{ ref('core__dim_contracts') }} c
|
||||
ON f.token = c.address
|
||||
@ -1,42 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__morpho_flashloans
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- _LOG_ID
|
||||
columns:
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: MARKET
|
||||
tests:
|
||||
- not_null
|
||||
- name: FLASHLOAN_AMOUNT_UNADJ
|
||||
tests:
|
||||
- not_null
|
||||
- name: FLASHLOAN_AMOUNT
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: INITIATOR_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: PLATFORM
|
||||
tests:
|
||||
- not_null
|
||||
- name: SYMBOL
|
||||
- name: BLOCKCHAIN
|
||||
tests:
|
||||
- not_null
|
||||
@ -1,139 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['silver','defi','lending','curated']
|
||||
) }}
|
||||
|
||||
WITH traces AS (
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
tx_hash,
|
||||
block_timestamp,
|
||||
from_address,
|
||||
to_address,
|
||||
LEFT(
|
||||
input,
|
||||
10
|
||||
) AS function_sig,
|
||||
decoded_input_data :marketParams :loanToken :: STRING AS loan_token,
|
||||
decoded_input_data :marketParams :collateralToken :: STRING AS collateral_token,
|
||||
decoded_input_data :marketParams :oracle :: STRING AS oracle_address,
|
||||
decoded_input_data :marketParams :irm :: STRING AS irm_address,
|
||||
decoded_input_data :borrower :: STRING AS borrower,
|
||||
decoded_output_data :output_1 :: INTEGER AS amount,
|
||||
concat_ws(
|
||||
'-',
|
||||
block_number,
|
||||
tx_position,
|
||||
CONCAT(
|
||||
TYPE,
|
||||
'_',
|
||||
trace_index --replace with trace_address
|
||||
)
|
||||
) AS _call_id,
|
||||
modified_timestamp AS _inserted_timestamp
|
||||
FROM
|
||||
{{ ref('core__ez_decoded_traces') }}
|
||||
WHERE
|
||||
to_address = '0xbbbbbbbbbb9cc5e90e3b3af64bdaf62c37eeffcb' --Morpho Blue
|
||||
AND function_sig = '0xd8eabcb8'
|
||||
AND trace_succeeded
|
||||
AND tx_succeeded
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
),
|
||||
logs AS(
|
||||
SELECT
|
||||
l.tx_hash,
|
||||
l.block_number,
|
||||
l.block_timestamp,
|
||||
l.event_index,
|
||||
l.origin_from_address,
|
||||
l.origin_to_address,
|
||||
l.origin_function_signature,
|
||||
l.contract_address,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS caller,
|
||||
CONCAT('0x', SUBSTR(topics [3] :: STRING, 27, 40)) AS borrower,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
) :: INTEGER AS repay_assets,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [2] :: STRING
|
||||
) :: INTEGER AS seized_assets,
|
||||
COALESCE(
|
||||
l.origin_to_address,
|
||||
l.contract_address
|
||||
) AS lending_pool_contract,
|
||||
CONCAT(
|
||||
l.tx_hash,
|
||||
'-',
|
||||
l.event_index
|
||||
) AS _log_id,
|
||||
l.modified_timestamp AS _inserted_timestamp
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
l
|
||||
WHERE
|
||||
topics [0] :: STRING = '0xa4946ede45d0c6f06a0f5ce92c9ad3b4751452d2fe0e25010783bcab57a67e41'
|
||||
AND l.contract_address = '0xbbbbbbbbbb9cc5e90e3b3af64bdaf62c37eeffcb'
|
||||
AND tx_hash IN (
|
||||
SELECT
|
||||
tx_hash
|
||||
FROM
|
||||
traces
|
||||
)
|
||||
)
|
||||
SELECT
|
||||
l.tx_hash,
|
||||
l.block_number,
|
||||
l.block_timestamp,
|
||||
l.event_index,
|
||||
l.origin_from_address,
|
||||
l.origin_to_address,
|
||||
l.origin_function_signature,
|
||||
l.contract_address,
|
||||
l.caller AS liquidator,
|
||||
l.borrower,
|
||||
t.loan_token AS debt_asset,
|
||||
c0.symbol AS debt_asset_symbol,
|
||||
l.repay_assets AS repayed_amount_unadj,
|
||||
l.repay_assets / pow(
|
||||
10,
|
||||
c0.decimals
|
||||
) AS repayed_amount,
|
||||
t.collateral_token AS collateral_asset,
|
||||
c1.symbol AS collateral_asset_symbol,
|
||||
l.seized_assets AS amount_unadj,
|
||||
l.seized_assets / pow(
|
||||
10,
|
||||
c1.decimals
|
||||
) AS amount,
|
||||
'Morpho Blue' AS platform,
|
||||
'ethereum' AS blockchain,
|
||||
t._call_id AS _id,
|
||||
t._inserted_timestamp
|
||||
FROM
|
||||
traces t
|
||||
LEFT JOIN logs l
|
||||
ON l.tx_hash = t.tx_hash
|
||||
AND l.seized_assets = t.amount
|
||||
LEFT JOIN {{ ref('core__dim_contracts') }}
|
||||
c0
|
||||
ON c0.address = t.loan_token
|
||||
LEFT JOIN {{ ref('core__dim_contracts') }}
|
||||
c1
|
||||
ON c1.address = t.collateral_token
|
||||
WHERE
|
||||
l.caller IS NOT NULL --filters one edge tx case where no logs are emitted
|
||||
@ -1,81 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__morpho_liquidations
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- _ID
|
||||
columns:
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: ORIGIN_FROM_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: ORIGIN_TO_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: ORIGIN_FUNCTION_SIGNATURE
|
||||
tests:
|
||||
- not_null
|
||||
- name: CONTRACT_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: LIQUIDATOR
|
||||
tests:
|
||||
- not_null
|
||||
- name: BORROWER
|
||||
tests:
|
||||
- not_null
|
||||
- name: DEBT_ASSET
|
||||
tests:
|
||||
- not_null
|
||||
- name: DEBT_ASSET_SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
- name: REPAYED_AMOUNT_UNADJ
|
||||
tests:
|
||||
- not_null
|
||||
- name: REPAYED_AMOUNT
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: COLLATERAL_ASSET
|
||||
tests:
|
||||
- not_null
|
||||
- name: COLLATERAL_ASSET_SYMBOL
|
||||
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: PLATFORM
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCKCHAIN
|
||||
tests:
|
||||
- not_null
|
||||
- name: _ID
|
||||
- name: _INSERTED_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
@ -1,123 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['silver','defi','lending','curated']
|
||||
) }}
|
||||
|
||||
WITH traces AS (
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
tx_hash,
|
||||
block_timestamp,
|
||||
from_address,
|
||||
to_address,
|
||||
LEFT(
|
||||
input,
|
||||
10
|
||||
) AS function_sig,
|
||||
regexp_substr_all(SUBSTR(input, 11), '.{64}') AS segmented_input,
|
||||
CONCAT('0x', SUBSTR(segmented_input [0] :: STRING, 25)) AS loan_token,
|
||||
CONCAT('0x', SUBSTR(segmented_input [1] :: STRING, 25)) AS collateral_token,
|
||||
CONCAT('0x', SUBSTR(segmented_input [2] :: STRING, 25)) AS oracle_address,
|
||||
CONCAT('0x', SUBSTR(segmented_input [3] :: STRING, 25)) AS irm_address,
|
||||
TRY_TO_NUMBER(
|
||||
utils.udf_hex_to_int(
|
||||
segmented_input [4] :: STRING
|
||||
)
|
||||
) AS lltv,
|
||||
TRY_TO_NUMBER(
|
||||
utils.udf_hex_to_int(
|
||||
segmented_input [5] :: STRING
|
||||
)
|
||||
) AS amount,
|
||||
TRY_TO_NUMBER(
|
||||
utils.udf_hex_to_int(
|
||||
segmented_input [6] :: STRING
|
||||
)
|
||||
) AS shares,
|
||||
CONCAT('0x', SUBSTR(segmented_input [7] :: STRING, 25)) AS on_behalf_address,
|
||||
CONCAT('0x', SUBSTR(segmented_input [8] :: STRING, 25)) AS receiver_address,
|
||||
concat_ws(
|
||||
'-',
|
||||
block_number,
|
||||
tx_position,
|
||||
CONCAT(
|
||||
TYPE,
|
||||
'_',
|
||||
trace_address
|
||||
)
|
||||
) AS _call_id,
|
||||
modified_timestamp AS _inserted_timestamp
|
||||
FROM
|
||||
{{ ref('core__fact_traces') }}
|
||||
WHERE
|
||||
to_address = '0xbbbbbbbbbb9cc5e90e3b3af64bdaf62c37eeffcb' --Morpho Blue
|
||||
AND function_sig = '0x20b76e81'
|
||||
AND trace_succeeded
|
||||
AND tx_succeeded
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
),
|
||||
tx_join AS (
|
||||
SELECT
|
||||
tx.block_number,
|
||||
tx.tx_hash,
|
||||
tx.block_timestamp,
|
||||
tx.from_address AS origin_from_address,
|
||||
tx.to_address AS origin_to_address,
|
||||
tx.origin_function_signature,
|
||||
t.from_address,
|
||||
t.to_address AS contract_address,
|
||||
tx.from_address AS borrower_address,
|
||||
t.loan_token,
|
||||
t.collateral_token,
|
||||
t.amount,
|
||||
t.on_behalf_address,
|
||||
t.receiver_address,
|
||||
t._call_id,
|
||||
t._inserted_timestamp
|
||||
FROM
|
||||
traces t
|
||||
INNER JOIN {{ ref('core__fact_transactions') }}
|
||||
tx
|
||||
ON tx.block_number = t.block_number
|
||||
AND tx.tx_hash = t.tx_hash
|
||||
)
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
loan_token AS market,
|
||||
amount AS amount_unadj,
|
||||
amount / pow(
|
||||
10,
|
||||
C.decimals
|
||||
) AS amount,
|
||||
on_behalf_address AS payer,
|
||||
borrower_address,
|
||||
contract_address AS lending_pool_contract,
|
||||
C.symbol,
|
||||
C.decimals,
|
||||
'Morpho Blue' AS platform,
|
||||
'ethereum' AS blockchain,
|
||||
t._call_id AS _id,
|
||||
t._inserted_timestamp
|
||||
FROM
|
||||
tx_join t
|
||||
LEFT JOIN {{ ref('core__dim_contracts') }} C
|
||||
ON address = t.loan_token
|
||||
@ -1,44 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__morpho_repayments
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- _ID
|
||||
columns:
|
||||
- name: BLOCKCHAIN
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- name: MARKET
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT_UNADJ
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: PAYER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BORROWER_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: PLATFORM
|
||||
tests:
|
||||
- not_null
|
||||
- name: SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
@ -1,123 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['silver','defi','lending','curated']
|
||||
) }}
|
||||
|
||||
WITH traces AS (
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
tx_hash,
|
||||
block_timestamp,
|
||||
from_address,
|
||||
to_address,
|
||||
LEFT(
|
||||
input,
|
||||
10
|
||||
) AS function_sig,
|
||||
regexp_substr_all(SUBSTR(input, 11), '.{64}') AS segmented_input,
|
||||
CONCAT('0x', SUBSTR(segmented_input [0] :: STRING, 25)) AS loan_token,
|
||||
CONCAT('0x', SUBSTR(segmented_input [1] :: STRING, 25)) AS collateral_token,
|
||||
CONCAT('0x', SUBSTR(segmented_input [2] :: STRING, 25)) AS oracle_address,
|
||||
CONCAT('0x', SUBSTR(segmented_input [3] :: STRING, 25)) AS irm_address,
|
||||
TRY_TO_NUMBER(
|
||||
utils.udf_hex_to_int(
|
||||
segmented_input [4] :: STRING
|
||||
)
|
||||
) AS lltv,
|
||||
TRY_TO_NUMBER(
|
||||
utils.udf_hex_to_int(
|
||||
segmented_input [5] :: STRING
|
||||
)
|
||||
) AS amount,
|
||||
TRY_TO_NUMBER(
|
||||
utils.udf_hex_to_int(
|
||||
segmented_input [6] :: STRING
|
||||
)
|
||||
) AS shares,
|
||||
CONCAT('0x', SUBSTR(segmented_input [7] :: STRING, 25)) AS on_behalf_address,
|
||||
CONCAT('0x', SUBSTR(segmented_input [8] :: STRING, 25)) AS receiver_address,
|
||||
concat_ws(
|
||||
'-',
|
||||
block_number,
|
||||
tx_position,
|
||||
CONCAT(
|
||||
TYPE,
|
||||
'_',
|
||||
trace_address
|
||||
)
|
||||
) AS _call_id,
|
||||
modified_timestamp AS _inserted_timestamp
|
||||
FROM
|
||||
{{ ref('core__fact_traces') }}
|
||||
t
|
||||
WHERE
|
||||
to_address = '0xbbbbbbbbbb9cc5e90e3b3af64bdaf62c37eeffcb' --Morpho Blue
|
||||
AND function_sig = '0x5c2bea49'
|
||||
AND trace_succeeded
|
||||
AND tx_succeeded
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
),
|
||||
tx_join AS (
|
||||
SELECT
|
||||
tx.block_number,
|
||||
tx.tx_hash,
|
||||
tx.block_timestamp,
|
||||
tx.from_address AS origin_from_address,
|
||||
tx.to_address AS origin_to_address,
|
||||
tx.origin_function_signature,
|
||||
t.from_address,
|
||||
t.to_address AS contract_address,
|
||||
tx.from_address AS depositor_address,
|
||||
t.loan_token,
|
||||
t.collateral_token,
|
||||
t.amount,
|
||||
t.on_behalf_address,
|
||||
t.receiver_address,
|
||||
t._call_id,
|
||||
t._inserted_timestamp
|
||||
FROM
|
||||
traces t
|
||||
INNER JOIN {{ ref('core__fact_transactions') }}
|
||||
tx
|
||||
ON tx.block_number = t.block_number
|
||||
AND tx.tx_hash = t.tx_hash
|
||||
)
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
loan_token AS market,
|
||||
amount AS amount_unadj,
|
||||
amount / pow(
|
||||
10,
|
||||
C.decimals
|
||||
) AS amount,
|
||||
depositor_address,
|
||||
contract_address AS lending_pool_contract,
|
||||
C.symbol,
|
||||
C.decimals,
|
||||
'Morpho Blue' AS platform,
|
||||
'ethereum' AS blockchain,
|
||||
t._call_id AS _id,
|
||||
t._inserted_timestamp
|
||||
FROM
|
||||
tx_join t
|
||||
LEFT JOIN {{ ref('core__dim_contracts') }} C
|
||||
ON address = t.loan_token
|
||||
@ -1,39 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__morpho_withdraws
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- _ID
|
||||
columns:
|
||||
- name: BLOCKCHAIN
|
||||
tests:
|
||||
- not_null
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- name: MARKET
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT_UNADJ
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: DEPOSITOR_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: PLATFORM
|
||||
tests:
|
||||
- not_null
|
||||
- name: SYMBOL
|
||||
@ -1,132 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['silver','defi','lending','curated']
|
||||
) }}
|
||||
WITH --borrows from Aave LendingPool contracts
|
||||
atoken_meta AS (
|
||||
SELECT
|
||||
atoken_address,
|
||||
version_pool,
|
||||
atoken_symbol,
|
||||
atoken_name,
|
||||
atoken_decimals,
|
||||
underlying_address,
|
||||
underlying_symbol,
|
||||
underlying_name,
|
||||
underlying_decimals,
|
||||
atoken_version,
|
||||
atoken_created_block,
|
||||
atoken_stable_debt_address,
|
||||
atoken_variable_debt_address
|
||||
FROM
|
||||
{{ ref('silver__radiant_tokens') }}
|
||||
),
|
||||
borrow AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS reserve_1,
|
||||
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,
|
||||
modified_timestamp AS _inserted_timestamp,
|
||||
CONCAT(
|
||||
tx_hash :: STRING,
|
||||
'-',
|
||||
event_index :: STRING
|
||||
) AS _log_id,
|
||||
'Radiant' AS radiant_version,
|
||||
origin_from_address AS borrower_address,
|
||||
COALESCE(
|
||||
origin_to_address,
|
||||
contract_address
|
||||
) AS lending_pool_contract,
|
||||
CASE
|
||||
WHEN reserve_1 = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' THEN '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
|
||||
ELSE reserve_1
|
||||
END AS radiant_market
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
WHERE
|
||||
topics [0] :: STRING = '0xc6a898309e823ee50bac64e45ca8adba6690e99e7841c45d754e2a38e9019d9b'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
AND contract_address IN (SELECT distinct(version_pool) from atoken_meta)
|
||||
AND tx_succeeded --excludes failed txs
|
||||
)
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
LOWER(
|
||||
radiant_market
|
||||
) AS radiant_market,
|
||||
LOWER(
|
||||
atoken_meta.atoken_address
|
||||
) AS radiant_token,
|
||||
borrow_quantity AS amount_unadj,
|
||||
borrow_quantity / pow(
|
||||
10,
|
||||
atoken_meta.underlying_decimals
|
||||
) AS amount,
|
||||
LOWER(
|
||||
borrower_address
|
||||
) AS borrower_address,
|
||||
CASE
|
||||
WHEN borrow_rate_mode = 2 THEN 'Variable Rate'
|
||||
ELSE 'Stable Rate'
|
||||
END AS borrow_rate_mode,
|
||||
LOWER(
|
||||
lending_pool_contract
|
||||
) AS lending_pool_contract,
|
||||
radiant_version AS platform,
|
||||
atoken_meta.underlying_symbol AS symbol,
|
||||
atoken_meta.underlying_decimals AS underlying_decimals,
|
||||
'ethereum' AS blockchain,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
borrow
|
||||
LEFT JOIN atoken_meta
|
||||
ON borrow.radiant_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__radiant_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: RADIANT_MARKET
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT_UNADJ
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: BORROWER_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: BORROW_RATE_MODE
|
||||
tests:
|
||||
- not_null
|
||||
- name: LENDING_POOL_CONTRACT
|
||||
tests:
|
||||
- not_null
|
||||
- name: PLATFORM
|
||||
tests:
|
||||
- not_null
|
||||
- name: SYMBOL
|
||||
- name: BLOCKCHAIN
|
||||
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
|
||||
atoken_meta AS (
|
||||
SELECT
|
||||
atoken_address,
|
||||
version_pool,
|
||||
atoken_symbol,
|
||||
atoken_name,
|
||||
atoken_decimals,
|
||||
underlying_address,
|
||||
underlying_symbol,
|
||||
underlying_name,
|
||||
underlying_decimals,
|
||||
atoken_version,
|
||||
atoken_created_block,
|
||||
atoken_stable_debt_address,
|
||||
atoken_variable_debt_address
|
||||
FROM
|
||||
{{ ref('silver__radiant_tokens') }}
|
||||
),
|
||||
deposits AS(
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS reserve_1,
|
||||
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,
|
||||
'Radiant' AS radiant_version,
|
||||
origin_from_address AS depositor_address,
|
||||
COALESCE(
|
||||
origin_to_address,
|
||||
contract_address
|
||||
) AS lending_pool_contract,
|
||||
CASE
|
||||
WHEN reserve_1 = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' THEN '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
|
||||
ELSE reserve_1
|
||||
END AS radiant_market,
|
||||
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 = '0xde6857219544bb5b7746f48ed30be6386fefc61b2f864cacf559893bf50fd951'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
AND contract_address IN (SELECT distinct(version_pool) from atoken_meta)
|
||||
AND tx_succeeded --excludes failed txs
|
||||
)
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
LOWER(
|
||||
radiant_market
|
||||
) AS radiant_market,
|
||||
LOWER(
|
||||
atoken_meta.atoken_address
|
||||
) AS radiant_token,
|
||||
deposit_quantity AS amount_unadj,
|
||||
deposit_quantity / pow(
|
||||
10,
|
||||
atoken_meta.underlying_decimals
|
||||
) AS amount,
|
||||
LOWER(
|
||||
depositor_address
|
||||
) AS depositor_address,
|
||||
LOWER(
|
||||
lending_pool_contract
|
||||
) AS lending_pool_contract,
|
||||
radiant_version AS platform,
|
||||
atoken_meta.underlying_symbol AS symbol,
|
||||
'ethereum' AS blockchain,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
deposits
|
||||
LEFT JOIN atoken_meta
|
||||
ON deposits.radiant_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__radiant_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: RADIANT_MARKET
|
||||
tests:
|
||||
- not_null
|
||||
- name: DEPOSITOR_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: LENDING_POOL_CONTRACT
|
||||
tests:
|
||||
- not_null
|
||||
- name: PLATFORM
|
||||
tests:
|
||||
- not_null
|
||||
- name: SYMBOL
|
||||
@ -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
|
||||
atoken_meta AS (
|
||||
SELECT
|
||||
atoken_address,
|
||||
version_pool,
|
||||
atoken_symbol,
|
||||
atoken_name,
|
||||
atoken_decimals,
|
||||
underlying_address,
|
||||
underlying_symbol,
|
||||
underlying_name,
|
||||
underlying_decimals,
|
||||
atoken_version,
|
||||
atoken_created_block,
|
||||
atoken_stable_debt_address,
|
||||
atoken_variable_debt_address
|
||||
FROM
|
||||
{{ ref('silver__radiant_tokens') }}
|
||||
),
|
||||
flashloan AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS target_address,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS initiator_address,
|
||||
CONCAT('0x', SUBSTR(topics [3] :: STRING, 27, 40)) AS asset_1,
|
||||
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,
|
||||
CONCAT(
|
||||
tx_hash :: STRING,
|
||||
'-',
|
||||
event_index :: STRING
|
||||
) AS _log_id,
|
||||
modified_timestamp AS _inserted_timestamp,
|
||||
COALESCE(
|
||||
origin_to_address,
|
||||
contract_address
|
||||
) AS lending_pool_contract,
|
||||
'Radiant' AS radiant_version,
|
||||
CASE
|
||||
WHEN asset_1 = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' THEN '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
|
||||
ELSE asset_1
|
||||
END AS radiant_market
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
WHERE
|
||||
topics [0] :: STRING = '0x631042c832b07452973831137f2d73e395028b44b250dedc5abb0ee766e168ac'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
AND contract_address IN (SELECT distinct(version_pool) from atoken_meta)
|
||||
AND tx_succeeded --excludes failed txs
|
||||
)
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
LOWER(
|
||||
radiant_market
|
||||
) AS radiant_market,
|
||||
LOWER(
|
||||
atoken_meta.atoken_address
|
||||
) AS radiant_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,
|
||||
LOWER(initiator_address) AS initiator_address,
|
||||
LOWER(target_address) AS target_address,
|
||||
radiant_version AS platform,
|
||||
atoken_meta.underlying_symbol AS symbol,
|
||||
'ethereum' AS blockchain,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
flashloan
|
||||
LEFT JOIN atoken_meta
|
||||
ON flashloan.radiant_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__radiant_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: RADIANT_MARKET
|
||||
tests:
|
||||
- not_null
|
||||
- name: RADIANT_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,131 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['silver','defi','lending','curated']
|
||||
) }}
|
||||
|
||||
WITH
|
||||
atoken_meta AS (
|
||||
SELECT
|
||||
atoken_address,
|
||||
version_pool,
|
||||
atoken_symbol,
|
||||
atoken_name,
|
||||
atoken_decimals,
|
||||
underlying_address,
|
||||
underlying_symbol,
|
||||
underlying_name,
|
||||
underlying_decimals,
|
||||
atoken_version,
|
||||
atoken_created_block,
|
||||
atoken_stable_debt_address,
|
||||
atoken_variable_debt_address
|
||||
FROM
|
||||
{{ ref('silver__radiant_tokens') }}
|
||||
),
|
||||
liquidation AS(
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS collateralAsset_1,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS debtAsset_1,
|
||||
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,
|
||||
CONCAT(
|
||||
tx_hash :: STRING,
|
||||
'-',
|
||||
event_index :: STRING
|
||||
) AS _log_id,
|
||||
modified_timestamp AS _inserted_timestamp,
|
||||
'Radiant' AS radiant_version,
|
||||
COALESCE(
|
||||
origin_to_address,
|
||||
contract_address
|
||||
) AS lending_pool_contract,
|
||||
CASE
|
||||
WHEN debtAsset_1 = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' THEN '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
|
||||
ELSE debtAsset_1
|
||||
END AS debt_asset,
|
||||
CASE
|
||||
WHEN collateralAsset_1 = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' THEN '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
|
||||
ELSE collateralAsset_1
|
||||
END AS collateral_asset
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
WHERE
|
||||
topics [0] :: STRING = '0xe76026d190f8c969db64638eaf9bc7087a3758e7fe58c017135a5051b4d7c4f8'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
AND contract_address IN (SELECT distinct(version_pool) from atoken_meta)
|
||||
AND tx_succeeded --excludes failed txs
|
||||
)
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
LOWER(
|
||||
collateral_asset
|
||||
) AS collateral_asset,
|
||||
LOWER(
|
||||
amc.atoken_address
|
||||
) AS collateral_radiant_token,
|
||||
liquidated_amount AS amount_unadj,
|
||||
liquidated_amount / pow(
|
||||
10,
|
||||
amc.atoken_decimals
|
||||
) AS amount,
|
||||
LOWER(
|
||||
debt_asset
|
||||
) AS debt_asset,
|
||||
LOWER(
|
||||
amd.atoken_address
|
||||
) AS debt_radiant_token,
|
||||
debt_to_cover_amount / pow(
|
||||
10,
|
||||
amd.underlying_decimals
|
||||
) AS debt_to_cover_amount,
|
||||
liquidator_address AS liquidator,
|
||||
borrower_address AS borrower,
|
||||
radiant_version as platform,
|
||||
amc.underlying_symbol AS collateral_token_symbol,
|
||||
amd.underlying_symbol AS debt_token_symbol,
|
||||
'ethereum' 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,54 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__radiant_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_RADIANT_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_RADIANT_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,118 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['silver','defi','lending','curated']
|
||||
) }}
|
||||
|
||||
WITH
|
||||
atoken_meta AS (
|
||||
SELECT
|
||||
atoken_address,
|
||||
version_pool,
|
||||
atoken_symbol,
|
||||
atoken_name,
|
||||
atoken_decimals,
|
||||
underlying_address,
|
||||
underlying_symbol,
|
||||
underlying_name,
|
||||
underlying_decimals,
|
||||
atoken_version,
|
||||
atoken_created_block,
|
||||
atoken_stable_debt_address,
|
||||
atoken_variable_debt_address
|
||||
FROM
|
||||
{{ ref('silver__radiant_tokens') }}
|
||||
),
|
||||
repay AS(
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS reserve_1,
|
||||
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,
|
||||
CONCAT(
|
||||
tx_hash :: STRING,
|
||||
'-',
|
||||
event_index :: STRING
|
||||
) AS _log_id,
|
||||
modified_timestamp AS _inserted_timestamp,
|
||||
'Radiant' AS radiant_version,
|
||||
COALESCE(
|
||||
origin_to_address,
|
||||
contract_address
|
||||
) AS lending_pool_contract,
|
||||
origin_from_address AS repayer_address,
|
||||
CASE
|
||||
WHEN reserve_1 = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' THEN '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
|
||||
ELSE reserve_1
|
||||
END AS radiant_market
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
WHERE
|
||||
topics [0] :: STRING IN (
|
||||
'0x4cdde6e09bb755c9a5589ebaec640bbfedff1362d4b255ebf8339782b9942faa',
|
||||
'0xb718f0b14f03d8c3adf35b15e3da52421b042ac879e5a689011a8b1e0036773d',
|
||||
'0xa534c8dbe71f871f9f3530e97a74601fea17b426cae02e1c5aee42c96c784051'
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
AND contract_address IN (SELECT distinct(version_pool) from atoken_meta)
|
||||
AND tx_succeeded --excludes failed txs
|
||||
)
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
LOWER(
|
||||
radiant_market
|
||||
) AS radiant_market,
|
||||
LOWER(
|
||||
atoken_meta.atoken_address
|
||||
) AS radiant_token,
|
||||
repayed_amount AS amount_unadj,
|
||||
repayed_amount / pow(
|
||||
10,
|
||||
atoken_meta.underlying_decimals
|
||||
) AS amount,
|
||||
repayer_address AS payer,
|
||||
borrower_address AS borrower,
|
||||
LOWER(
|
||||
lending_pool_contract
|
||||
) AS lending_pool_contract,
|
||||
radiant_version as platform,
|
||||
atoken_meta.underlying_symbol AS symbol,
|
||||
'ethereum' AS blockchain,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
repay
|
||||
LEFT JOIN atoken_meta
|
||||
ON repay.radiant_market = atoken_meta.underlying_address qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user