From 98470f3429430179c4927ff2263021926cfc6047 Mon Sep 17 00:00:00 2001 From: tomfutago Date: Sun, 22 Dec 2024 10:29:30 +0000 Subject: [PATCH 1/2] fix: add WrappedTokenGateway lookup --- .../lending_aave_compatible_supply.sql | 75 +++++++++++++------ .../aave_lido_v3_ethereum_base_supply.sql | 3 +- .../lending/supply/arbitrum/_sources.yml | 1 + .../lending/supply/avalanche_c/_sources.yml | 2 + .../_sector/lending/supply/base/_sources.yml | 1 + .../_sector/lending/supply/bnb/_sources.yml | 1 + .../lending/supply/ethereum/_sources.yml | 4 + .../lending/supply/fantom/_sources.yml | 1 + .../lending/supply/gnosis/_sources.yml | 1 + .../lending/supply/optimism/_sources.yml | 1 + .../lending/supply/polygon/_sources.yml | 2 + .../lending/supply/scroll/_sources.yml | 1 + 12 files changed, 69 insertions(+), 24 deletions(-) diff --git a/dbt_subprojects/hourly_spellbook/macros/sector/lending/lending_aave_compatible_supply.sql b/dbt_subprojects/hourly_spellbook/macros/sector/lending/lending_aave_compatible_supply.sql index 5320cf668bc..cfb4029fa3c 100644 --- a/dbt_subprojects/hourly_spellbook/macros/sector/lending/lending_aave_compatible_supply.sql +++ b/dbt_subprojects/hourly_spellbook/macros/sector/lending/lending_aave_compatible_supply.sql @@ -141,6 +141,14 @@ src_LendingPool_evt_Withdraw as ( {% endif %} ), +src_WrappedTokenGatewayV2_call_withdrawETH as ( + select * + from {{ source(project_decoded_as ~ '_' ~ blockchain, 'WrappedTokenGatewayV2_call_withdrawETH') }} + {% if is_incremental() %} + where {{ incremental_predicate('call_block_time') }} + {% endif %} +), + src_LendingPool_evt_LiquidationCall as ( select * from {{ source(project_decoded_as ~ '_' ~ blockchain, 'LendingPool_evt_LiquidationCall') }} @@ -167,18 +175,24 @@ base_supply as ( union all select 'withdraw' as transaction_type, - reserve as token_address, - user as depositor, - cast(null as varbinary) as on_behalf_of, - to as withdrawn_to, + w.reserve as token_address, + w.user as depositor, + cast(wrap.to as varbinary) as on_behalf_of, + w.to as withdrawn_to, cast(null as varbinary) as liquidator, - -1 * cast(amount as double) as amount, - contract_address, - evt_tx_hash, - evt_index, - evt_block_time, - evt_block_number - from src_LendingPool_evt_Withdraw + -1 * cast(w.amount as double) as amount, + w.contract_address, + w.evt_tx_hash, + w.evt_index, + w.evt_block_time, + w.evt_block_number + from src_LendingPool_evt_Withdraw w + left join src_WrappedTokenGatewayV2_call_withdrawETH wrap + on w.evt_block_number = wrap.call_block_number + and w.evt_tx_hash = wrap.call_tx_hash + and w.to = wrap.contract_address + and w.amount = wrap.amount + and wrap.call_success union all select 'deposit_liquidation' as transaction_type, @@ -225,7 +239,8 @@ from base_supply project, version, project_decoded_as = 'aave_v3', - decoded_contract_name = 'Pool' + decoded_contract_name = 'Pool', + decoded_wrapped_token_gateway_name = 'WrappedTokenGatewayV3' ) %} @@ -247,6 +262,14 @@ src_LendingPool_evt_Withdraw as ( {% endif %} ), +src_WrappedTokenGatewayV3_call_withdrawETH as ( + select * + from {{ source(project_decoded_as ~ '_' ~ blockchain, decoded_wrapped_token_gateway_name ~ '_call_withdrawETH') }} + {% if is_incremental() %} + where {{ incremental_predicate('call_block_time') }} + {% endif %} +), + src_LendingPool_evt_Repay as ( select * from {{ source(project_decoded_as ~ '_' ~ blockchain, decoded_contract_name ~ '_evt_Repay') }} @@ -282,18 +305,24 @@ base_supply as ( union all select 'withdraw' as transaction_type, - reserve as token_address, - user as depositor, - cast(null as varbinary) as on_behalf_of, - to as withdrawn_to, + w.reserve as token_address, + w.user as depositor, + cast(wrap.to as varbinary) as on_behalf_of, + w.to as withdrawn_to, cast(null as varbinary) as liquidator, - -1 * cast(amount as double) as amount, - contract_address, - evt_tx_hash, - evt_index, - evt_block_time, - evt_block_number - from src_LendingPool_evt_Withdraw + -1 * cast(w.amount as double) as amount, + w.contract_address, + w.evt_tx_hash, + w.evt_index, + w.evt_block_time, + w.evt_block_number + from src_LendingPool_evt_Withdraw w + left join src_WrappedTokenGatewayV3_call_withdrawETH wrap + on w.evt_block_number = wrap.call_block_number + and w.evt_tx_hash = wrap.call_tx_hash + and w.to = wrap.contract_address + and w.amount = wrap.amount + and wrap.call_success union all select 'repay_with_atokens' as transaction_type, diff --git a/dbt_subprojects/hourly_spellbook/models/_sector/lending/supply/ethereum/platforms/aave_lido_v3_ethereum_base_supply.sql b/dbt_subprojects/hourly_spellbook/models/_sector/lending/supply/ethereum/platforms/aave_lido_v3_ethereum_base_supply.sql index 2d19eebd8c1..4e30a0cd6a6 100644 --- a/dbt_subprojects/hourly_spellbook/models/_sector/lending/supply/ethereum/platforms/aave_lido_v3_ethereum_base_supply.sql +++ b/dbt_subprojects/hourly_spellbook/models/_sector/lending/supply/ethereum/platforms/aave_lido_v3_ethereum_base_supply.sql @@ -15,6 +15,7 @@ blockchain = 'ethereum', project = 'aave_lido', version = '3', - decoded_contract_name = 'LidoPool' + decoded_contract_name = 'LidoPool', + decoded_wrapped_token_gateway_name = 'LidoWrappedTokenGatewayV3' ) }} diff --git a/sources/_sector/lending/supply/arbitrum/_sources.yml b/sources/_sector/lending/supply/arbitrum/_sources.yml index 2e2ec7b3576..4cd48c2588d 100644 --- a/sources/_sector/lending/supply/arbitrum/_sources.yml +++ b/sources/_sector/lending/supply/arbitrum/_sources.yml @@ -5,6 +5,7 @@ sources: tables: - name: L2Pool_evt_Supply - name: L2Pool_evt_Withdraw + - name: WrappedTokenGatewayV3_call_withdrawETH - name: compound_v3_arbitrum tables: diff --git a/sources/_sector/lending/supply/avalanche_c/_sources.yml b/sources/_sector/lending/supply/avalanche_c/_sources.yml index 6704f977d09..9a600dbfab2 100644 --- a/sources/_sector/lending/supply/avalanche_c/_sources.yml +++ b/sources/_sector/lending/supply/avalanche_c/_sources.yml @@ -6,12 +6,14 @@ sources: - name: LendingPool_evt_Deposit - name: LendingPool_evt_Withdraw - name: LendingPool_evt_RedeemUnderlying + - name: WrappedTokenGatewayV2_call_withdrawETH - name: aave_v3_avalanche_c tables: - name: Pool_evt_Supply - name: Pool_evt_Withdraw - name: Pool_evt_RedeemUnderlying + - name: WrappedTokenGatewayV3_call_withdrawETH - name: benqi_finance_avalanche_c tables: diff --git a/sources/_sector/lending/supply/base/_sources.yml b/sources/_sector/lending/supply/base/_sources.yml index 93a23a0e7cb..0fe93a08384 100644 --- a/sources/_sector/lending/supply/base/_sources.yml +++ b/sources/_sector/lending/supply/base/_sources.yml @@ -6,6 +6,7 @@ sources: - name: L2Pool_evt_Supply - name: L2Pool_evt_Withdraw - name: L2Pool_evt_RedeemUnderlying + - name: WrappedTokenGatewayV3_call_withdrawETH - name: compound_v3_base tables: diff --git a/sources/_sector/lending/supply/bnb/_sources.yml b/sources/_sector/lending/supply/bnb/_sources.yml index 112c7e1b820..0fdc926b6d5 100644 --- a/sources/_sector/lending/supply/bnb/_sources.yml +++ b/sources/_sector/lending/supply/bnb/_sources.yml @@ -10,6 +10,7 @@ sources: tables: - name: Pool_evt_Supply - name: Pool_evt_Withdraw + - name: WrappedTokenGatewayV3_call_withdrawETH - name: the_granary_bnb tables: diff --git a/sources/_sector/lending/supply/ethereum/_sources.yml b/sources/_sector/lending/supply/ethereum/_sources.yml index bc4108ff420..ff1a916f458 100644 --- a/sources/_sector/lending/supply/ethereum/_sources.yml +++ b/sources/_sector/lending/supply/ethereum/_sources.yml @@ -11,21 +11,25 @@ sources: tables: - name: LendingPool_evt_Deposit - name: LendingPool_evt_Withdraw + - name: WrappedTokenGatewayV2_call_withdrawETH - name: aave_v3_ethereum tables: - name: Pool_evt_Supply - name: Pool_evt_Withdraw - name: Pool_evt_ReserveDataUpdated + - name: WrappedTokenGatewayV3_call_withdrawETH - name: LidoPool_evt_Supply - name: LidoPool_evt_Withdraw - name: LidoPool_evt_ReserveDataUpdated + - name: LidoWrappedTokenGatewayV3_call_withdrawETH - name: aave_v3_etherfi_ethereum tables: - name: PoolInstance_evt_Supply - name: PoolInstance_evt_Withdraw - name: PoolInstance_evt_ReserveDataUpdated + - name: WrappedTokenGatewayV3_call_withdrawETH - name: compound_v2_ethereum tables: diff --git a/sources/_sector/lending/supply/fantom/_sources.yml b/sources/_sector/lending/supply/fantom/_sources.yml index 24027641a58..bcd7da0b21e 100644 --- a/sources/_sector/lending/supply/fantom/_sources.yml +++ b/sources/_sector/lending/supply/fantom/_sources.yml @@ -6,6 +6,7 @@ sources: - name: Pool_evt_Supply - name: Pool_evt_Withdraw - name: Pool_evt_RedeemUnderlying + - name: WrappedTokenGatewayV3_call_withdrawETH - name: the_granary_fantom tables: diff --git a/sources/_sector/lending/supply/gnosis/_sources.yml b/sources/_sector/lending/supply/gnosis/_sources.yml index fe0319ee20d..54652218d9d 100644 --- a/sources/_sector/lending/supply/gnosis/_sources.yml +++ b/sources/_sector/lending/supply/gnosis/_sources.yml @@ -10,6 +10,7 @@ sources: tables: - name: Pool_evt_Supply - name: Pool_evt_Withdraw + - name: WrappedTokenGatewayV3_call_withdrawETH - name: real_rmm_v1_gnosis tables: diff --git a/sources/_sector/lending/supply/optimism/_sources.yml b/sources/_sector/lending/supply/optimism/_sources.yml index 4e90f45f3c7..3531ec489cb 100644 --- a/sources/_sector/lending/supply/optimism/_sources.yml +++ b/sources/_sector/lending/supply/optimism/_sources.yml @@ -6,6 +6,7 @@ sources: - name: Pool_evt_Supply - name: Pool_evt_Withdraw - name: Pool_evt_RedeemUnderlying + - name: WrappedTokenGatewayV3_call_withdrawETH - name: sonne_finance_optimism tables: diff --git a/sources/_sector/lending/supply/polygon/_sources.yml b/sources/_sector/lending/supply/polygon/_sources.yml index dc3812322c7..08f15c4112d 100644 --- a/sources/_sector/lending/supply/polygon/_sources.yml +++ b/sources/_sector/lending/supply/polygon/_sources.yml @@ -6,12 +6,14 @@ sources: - name: LendingPool_evt_Deposit - name: LendingPool_evt_Withdraw - name: LendingPool_evt_RedeemUnderlying + - name: WrappedTokenGatewayV2_call_withdrawETH - name: aave_v3_polygon tables: - name: Pool_evt_Supply - name: Pool_evt_Withdraw - name: Pool_evt_RedeemUnderlying + - name: WrappedTokenGatewayV3_call_withdrawETH - name: compound_v3_polygon tables: diff --git a/sources/_sector/lending/supply/scroll/_sources.yml b/sources/_sector/lending/supply/scroll/_sources.yml index 297f65da6b7..967e06b6d80 100644 --- a/sources/_sector/lending/supply/scroll/_sources.yml +++ b/sources/_sector/lending/supply/scroll/_sources.yml @@ -5,6 +5,7 @@ sources: tables: - name: L2Pool_evt_Supply - name: L2Pool_evt_Withdraw + - name: WrappedTokenGatewayV3_call_withdrawETH - name: layer_bank_scroll tables: From 47778cc00dc63f3f864db63ab9d96177a347c6b7 Mon Sep 17 00:00:00 2001 From: tomfutago Date: Sun, 22 Dec 2024 11:03:47 +0000 Subject: [PATCH 2/2] fix: apply only to aave --- .../lending_aave_compatible_supply.sql | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/dbt_subprojects/hourly_spellbook/macros/sector/lending/lending_aave_compatible_supply.sql b/dbt_subprojects/hourly_spellbook/macros/sector/lending/lending_aave_compatible_supply.sql index cfb4029fa3c..ab042cd9c11 100644 --- a/dbt_subprojects/hourly_spellbook/macros/sector/lending/lending_aave_compatible_supply.sql +++ b/dbt_subprojects/hourly_spellbook/macros/sector/lending/lending_aave_compatible_supply.sql @@ -141,6 +141,7 @@ src_LendingPool_evt_Withdraw as ( {% endif %} ), +{% if 'aave' in project %} src_WrappedTokenGatewayV2_call_withdrawETH as ( select * from {{ source(project_decoded_as ~ '_' ~ blockchain, 'WrappedTokenGatewayV2_call_withdrawETH') }} @@ -148,6 +149,7 @@ src_WrappedTokenGatewayV2_call_withdrawETH as ( where {{ incremental_predicate('call_block_time') }} {% endif %} ), +{% endif %} src_LendingPool_evt_LiquidationCall as ( select * @@ -177,7 +179,11 @@ base_supply as ( 'withdraw' as transaction_type, w.reserve as token_address, w.user as depositor, - cast(wrap.to as varbinary) as on_behalf_of, + {% if 'aave' in project %} + cast(wrap.to as varbinary) + {% else %} + cast(null as varbinary) + {% endif %} as on_behalf_of, w.to as withdrawn_to, cast(null as varbinary) as liquidator, -1 * cast(w.amount as double) as amount, @@ -187,12 +193,14 @@ base_supply as ( w.evt_block_time, w.evt_block_number from src_LendingPool_evt_Withdraw w + {% if 'aave' in project %} left join src_WrappedTokenGatewayV2_call_withdrawETH wrap on w.evt_block_number = wrap.call_block_number and w.evt_tx_hash = wrap.call_tx_hash and w.to = wrap.contract_address and w.amount = wrap.amount and wrap.call_success + {% endif %} union all select 'deposit_liquidation' as transaction_type, @@ -262,6 +270,7 @@ src_LendingPool_evt_Withdraw as ( {% endif %} ), +{% if 'aave' in project %} src_WrappedTokenGatewayV3_call_withdrawETH as ( select * from {{ source(project_decoded_as ~ '_' ~ blockchain, decoded_wrapped_token_gateway_name ~ '_call_withdrawETH') }} @@ -269,6 +278,7 @@ src_WrappedTokenGatewayV3_call_withdrawETH as ( where {{ incremental_predicate('call_block_time') }} {% endif %} ), +{% endif %} src_LendingPool_evt_Repay as ( select * @@ -307,7 +317,11 @@ base_supply as ( 'withdraw' as transaction_type, w.reserve as token_address, w.user as depositor, - cast(wrap.to as varbinary) as on_behalf_of, + {% if 'aave' in project %} + cast(wrap.to as varbinary) + {% else %} + cast(null as varbinary) + {% endif %} as on_behalf_of, w.to as withdrawn_to, cast(null as varbinary) as liquidator, -1 * cast(w.amount as double) as amount, @@ -317,12 +331,14 @@ base_supply as ( w.evt_block_time, w.evt_block_number from src_LendingPool_evt_Withdraw w + {% if 'aave' in project %} left join src_WrappedTokenGatewayV3_call_withdrawETH wrap on w.evt_block_number = wrap.call_block_number and w.evt_tx_hash = wrap.call_tx_hash and w.to = wrap.contract_address and w.amount = wrap.amount and wrap.call_success + {% endif %} union all select 'repay_with_atokens' as transaction_type,