diff --git a/dbt_subprojects/hourly_spellbook/models/_sector/lending/borrow/base/_schema.yml b/dbt_subprojects/hourly_spellbook/models/_sector/lending/borrow/base/_schema.yml index 41a25a6121d..252cb1d3a1a 100644 --- a/dbt_subprojects/hourly_spellbook/models/_sector/lending/borrow/base/_schema.yml +++ b/dbt_subprojects/hourly_spellbook/models/_sector/lending/borrow/base/_schema.yml @@ -304,3 +304,39 @@ models: - *project_contract_address - *tx_hash - *evt_index + + - name: morpho_base_base_borrow + meta: + blockchain: base + sector: lending + project: Morpho + contributors: 0xDataWolf + config: + tags: ['lending', 'borrow', 'Morpho', 'base'] + description: "Morpho borrow transactions on Base" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - transaction_type + - token_address + - tx_hash + - evt_index + - check_lending_base_borrow_seed: + seed_file: ref('morpho_base_base_borrow_seed') + columns: + - *blockchain + - *project + - *version + - *transaction_type + - *token_address + - *borrower + - *on_behalf_of + - *repayer + - *liquidator + - *amount + - *block_month + - *block_time + - *block_number + - *project_contract_address + - *tx_hash + - *evt_index diff --git a/dbt_subprojects/hourly_spellbook/models/_sector/lending/borrow/base/lending_base_base_borrow.sql b/dbt_subprojects/hourly_spellbook/models/_sector/lending/borrow/base/lending_base_base_borrow.sql index 9686e5dc8f4..4a58dd601ae 100644 --- a/dbt_subprojects/hourly_spellbook/models/_sector/lending/borrow/base/lending_base_base_borrow.sql +++ b/dbt_subprojects/hourly_spellbook/models/_sector/lending/borrow/base/lending_base_base_borrow.sql @@ -13,7 +13,8 @@ ref('seamlessprotocol_base_base_borrow'), ref('moonwell_base_base_borrow'), ref('sonne_finance_base_base_borrow'), - ref('granary_base_base_borrow') + ref('granary_base_base_borrow'), + ref('morpho_base_base_borrow') ] %} diff --git a/dbt_subprojects/hourly_spellbook/models/_sector/lending/borrow/base/platforms/morpho_base_base_borrow.sql b/dbt_subprojects/hourly_spellbook/models/_sector/lending/borrow/base/platforms/morpho_base_base_borrow.sql new file mode 100644 index 00000000000..90283ca99e5 --- /dev/null +++ b/dbt_subprojects/hourly_spellbook/models/_sector/lending/borrow/base/platforms/morpho_base_base_borrow.sql @@ -0,0 +1,103 @@ +{{ + config( + schema = 'morpho_base', + alias = 'base_borrow', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['transaction_type', 'token_address', 'tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +WITH markets AS ( + SELECT id + , from_hex(JSON_EXTRACT_SCALAR("marketParams", '$.loanToken')) AS loanToken + , from_hex(JSON_EXTRACT_SCALAR("marketParams", '$.collateralToken')) AS collateralToken + , from_hex(JSON_EXTRACT_SCALAR("marketParams", '$.oracle')) AS oracle + , JSON_EXTRACT_SCALAR("marketParams", '$.irm') AS irm + , JSON_EXTRACT_SCALAR("marketParams", '$.lltv') AS lltv + FROM {{ source('morpho_blue_base', 'MorphoBlue_evt_CreateMarket') }} + ) + +, base_borrow AS ( + SELECT 'borrow' AS transaction_type + , 'variable' AS loan_type + , loanToken AS token_address + , caller AS borrower + , onBehalf AS on_behalf_of + , CAST(NULL AS varbinary) AS repayer + , CAST(NULL AS varbinary) AS liquidator + , CAST(assets AS double) AS amount + , contract_address + , evt_tx_hash + , evt_index + , evt_block_time + , evt_block_number + FROM {{ source('morpho_blue_base', 'MorphoBlue_evt_Borrow') }} + INNER JOIN markets USING (id) + {% if is_incremental() %} + WHERE {{ incremental_predicate('evt_block_time') }} + {% endif %} + + UNION ALL + + SELECT 'repay' AS transaction_type + , NULL AS loan_type + , loanToken AS token_address + , caller AS borrower + , onBehalf AS on_behalf_of + , caller AS repayer + , cast(null as varbinary) AS liquidator + , -1 * cast(assets AS double) AS amount + , contract_address + , evt_tx_hash + , evt_index + , evt_block_time + , evt_block_number + FROM {{ source('morpho_blue_base', 'MorphoBlue_evt_Repay') }} + INNER JOIN markets USING (id) + {% if is_incremental() %} + WHERE {{ incremental_predicate('evt_block_time') }} + {% endif %} + + UNION ALL + + select 'borrow_liquidation' AS transaction_type + , null AS loan_type + , loanToken AS token_address + , borrower + , borrower AS on_behalf_of + , caller AS repayer + , caller AS liquidator + , -1 * cast(repaidAssets AS double) AS amount + , contract_address + , evt_tx_hash + , evt_index + , evt_block_time + , evt_block_number + FROM {{ source('morpho_blue_base', 'MorphoBlue_evt_Liquidate') }} + INNER JOIN markets USING (id) + {% if is_incremental() %} + WHERE {{ incremental_predicate('evt_block_time') }} + {% endif %} + ) + +SELECT 'base' AS blockchain +, 'morpho' AS project +, '1' AS version +, transaction_type +, loan_type +, token_address +, borrower +, on_behalf_of +, repayer +, liquidator +, amount +, CAST(date_trunc('month', evt_block_time) AS date) AS block_month +, evt_block_time AS block_time +, evt_block_number AS block_number +, contract_address AS project_contract_address +, evt_tx_hash AS tx_hash +, evt_index +FROM base_borrow \ No newline at end of file diff --git a/dbt_subprojects/hourly_spellbook/models/_sector/lending/flashloans/base/_schema.yml b/dbt_subprojects/hourly_spellbook/models/_sector/lending/flashloans/base/_schema.yml index 17fbdf1de1f..e2e12989bb8 100644 --- a/dbt_subprojects/hourly_spellbook/models/_sector/lending/flashloans/base/_schema.yml +++ b/dbt_subprojects/hourly_spellbook/models/_sector/lending/flashloans/base/_schema.yml @@ -194,3 +194,35 @@ models: - *block_number - *tx_hash - *evt_index + + - name: morpho_base_base_flashloans + meta: + blockchain: base + sector: lending + project: morpho + contributors: 0xDataWolf + config: + tags: ['lending', 'flashloans', 'morpho', 'base'] + description: "Morpho flashloans transactions on Base" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_lending_base_flashloans_seed: + seed_file: ref('morpho_base_base_flashloans_seed') + columns: + - *blockchain + - *project + - *version + - *recipient + - *amount + - *fee + - *token_address + - *project_contract_address + - *block_month + - *block_time + - *block_number + - *tx_hash + - *evt_index + diff --git a/dbt_subprojects/hourly_spellbook/models/_sector/lending/flashloans/base/lending_base_base_flashloans.sql b/dbt_subprojects/hourly_spellbook/models/_sector/lending/flashloans/base/lending_base_base_flashloans.sql index ce2b799cbd0..0e09ed99275 100644 --- a/dbt_subprojects/hourly_spellbook/models/_sector/lending/flashloans/base/lending_base_base_flashloans.sql +++ b/dbt_subprojects/hourly_spellbook/models/_sector/lending/flashloans/base/lending_base_base_flashloans.sql @@ -11,7 +11,8 @@ ref('aave_v3_base_base_flashloans'), ref('seamlessprotocol_base_base_flashloans'), ref('granary_base_base_flashloans'), - ref('balancer_v2_base_base_flashloans') + ref('balancer_v2_base_base_flashloans'), + ref('morpho_base_base_flashloans') ] %} diff --git a/dbt_subprojects/hourly_spellbook/models/_sector/lending/flashloans/base/platforms/morpho_base_base_flashloans.sql b/dbt_subprojects/hourly_spellbook/models/_sector/lending/flashloans/base/platforms/morpho_base_base_flashloans.sql new file mode 100644 index 00000000000..68362e63294 --- /dev/null +++ b/dbt_subprojects/hourly_spellbook/models/_sector/lending/flashloans/base/platforms/morpho_base_base_flashloans.sql @@ -0,0 +1,29 @@ +{{ + config( + schema = 'morpho_base', + alias = 'base_flashloans', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +SELECT 'base' AS blockchain +, 'morpho' AS project +, '1' AS version +, caller AS recipient +, assets AS amount +, CAST(0 AS UINT256) AS fee +, token AS token_address +, contract_address AS project_contract_address +, date_trunc('month', evt_block_time) AS block_month +, evt_block_time AS block_time +, evt_block_number AS block_number +, evt_tx_hash AS tx_hash +, evt_index +FROM {{ source('morpho_blue_base', 'MorphoBlue_evt_FlashLoan') }} +{% if is_incremental() %} +WHERE {{ incremental_predicate('evt_block_time') }} +{% endif %} diff --git a/dbt_subprojects/hourly_spellbook/models/_sector/lending/supply/base/_schema.yml b/dbt_subprojects/hourly_spellbook/models/_sector/lending/supply/base/_schema.yml index e8a8728189b..bcb89272a06 100644 --- a/dbt_subprojects/hourly_spellbook/models/_sector/lending/supply/base/_schema.yml +++ b/dbt_subprojects/hourly_spellbook/models/_sector/lending/supply/base/_schema.yml @@ -304,3 +304,39 @@ models: - *project_contract_address - *tx_hash - *evt_index + + - name: morpho_base_base_supply + meta: + blockchain: base + sector: lending + project: Morpho + contributors: 0xDataWolf + config: + tags: ['lending', 'supply', 'morpho', 'base'] + description: "Morpho supply transactions on Base" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - transaction_type + - token_address + - tx_hash + - evt_index + - check_lending_base_supply_seed: + seed_file: ref('morpho_base_base_supply_seed') + columns: + - *blockchain + - *project + - *version + - *transaction_type + - *token_address + - *depositor + - *on_behalf_of + - *withdrawn_to + - *liquidator + - *amount + - *block_month + - *block_time + - *block_number + - *project_contract_address + - *tx_hash + - *evt_index \ No newline at end of file diff --git a/dbt_subprojects/hourly_spellbook/models/_sector/lending/supply/base/lending_base_base_supply.sql b/dbt_subprojects/hourly_spellbook/models/_sector/lending/supply/base/lending_base_base_supply.sql index 5b8ab0b7685..94490a7a942 100644 --- a/dbt_subprojects/hourly_spellbook/models/_sector/lending/supply/base/lending_base_base_supply.sql +++ b/dbt_subprojects/hourly_spellbook/models/_sector/lending/supply/base/lending_base_base_supply.sql @@ -13,7 +13,8 @@ ref('seamlessprotocol_base_base_supply'), ref('moonwell_base_base_supply'), ref('sonne_finance_base_base_supply'), - ref('granary_base_base_supply') + ref('granary_base_base_supply'), + ref('morpho_base_base_supply') ] %} diff --git a/dbt_subprojects/hourly_spellbook/models/_sector/lending/supply/base/platforms/morpho_base_base_supply.sql b/dbt_subprojects/hourly_spellbook/models/_sector/lending/supply/base/platforms/morpho_base_base_supply.sql new file mode 100644 index 00000000000..fde28bb9c77 --- /dev/null +++ b/dbt_subprojects/hourly_spellbook/models/_sector/lending/supply/base/platforms/morpho_base_base_supply.sql @@ -0,0 +1,91 @@ +{{ + config( + schema = 'morpho_base', + alias = 'base_supply', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['transaction_type', 'token_address', 'tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +WITH markets AS ( + SELECT id + , from_hex(JSON_EXTRACT_SCALAR("marketParams", '$.loanToken')) AS loanToken + , from_hex(JSON_EXTRACT_SCALAR("marketParams", '$.collateralToken')) AS collateralToken + , from_hex(JSON_EXTRACT_SCALAR("marketParams", '$.oracle')) AS oracle + , JSON_EXTRACT_SCALAR("marketParams", '$.irm') AS irm + , JSON_EXTRACT_SCALAR("marketParams", '$.lltv') AS lltv + FROM {{ source('morpho_blue_base', 'MorphoBlue_evt_CreateMarket') }} + ) + +SELECT 'base' AS blockchain +, 'morpho' AS project +, '1' AS version +, 'deposit' AS transaction_type +, loanToken AS token_address +, caller AS depositor +, onBehalf AS on_behalf_of +, CAST(NULL AS varbinary) AS withdrawn_to +, CAST(NULL AS varbinary) AS liquidator +, CAST(assets AS double) AS amount +, CAST(date_trunc('month', evt_block_time) AS date) AS block_month +, evt_block_time AS block_time +, evt_block_number AS block_number +, contract_address AS project_contract_address +, evt_tx_hash AS tx_hash +, evt_index +FROM {{ source('morpho_blue_base', 'MorphoBlue_evt_Supply') }} +INNER JOIN markets USING (id) +{% if is_incremental() %} +WHERE {{ incremental_predicate('evt_block_time') }} +{% endif %} + +UNION ALL + +SELECT 'base' AS blockchain +, 'morpho' AS project +, '1' AS version +, 'withdraw' AS transaction_type +, loanToken AS token_address +, CAST(NULL AS varbinary) AS depositor +, onBehalf AS on_behalf_of +, receiver AS withdrawn_to +, CAST(NULL AS varbinary) AS liquidator +, -1 * CAST(assets AS double) AS amount +, CAST(date_trunc('month', evt_block_time) AS date) AS block_month +, evt_block_time AS block_time +, evt_block_number AS block_number +, contract_address AS project_contract_address +, evt_tx_hash AS tx_hash +, evt_index +FROM {{ source('morpho_blue_base', 'MorphoBlue_evt_Withdraw') }} +INNER JOIN markets USING (id) +{% if is_incremental() %} +WHERE {{ incremental_predicate('evt_block_time') }} +{% endif %} + +UNION ALL + +SELECT 'base' AS blockchain +, 'morpho' AS project +, '1' AS version +, 'deposit_liquidation' AS transaction_type +, loanToken AS token_address +, borrower AS depositor +, CAST(NULL AS varbinary) AS on_behalf_of +, caller AS withdrawn_to +, caller AS liquidator +, -1 * CAST(seizedAssets AS double) AS amount +, CAST(date_trunc('month', evt_block_time) AS date) AS block_month +, evt_block_time AS block_time +, evt_block_number AS block_number +, contract_address AS project_contract_address +, evt_tx_hash AS tx_hash +, evt_index +FROM {{ source('morpho_blue_base', 'MorphoBlue_evt_Liquidate') }} +INNER JOIN markets USING (id) +{% if is_incremental() %} +WHERE {{ incremental_predicate('evt_block_time') }} +{% endif %} \ No newline at end of file diff --git a/dbt_subprojects/hourly_spellbook/seeds/_sector/lending/_schema.yml b/dbt_subprojects/hourly_spellbook/seeds/_sector/lending/_schema.yml index 213fd274c94..d9f73328a57 100644 --- a/dbt_subprojects/hourly_spellbook/seeds/_sector/lending/_schema.yml +++ b/dbt_subprojects/hourly_spellbook/seeds/_sector/lending/_schema.yml @@ -1586,3 +1586,44 @@ seeds: token_address: varbinary depositor: varbinary amount: double + - name: morpho_base_base_supply_seed + config: + column_types: + blockchain: varchar + project: varchar + version: varchar + block_number: bigint + block_time: timestamp + tx_hash: varbinary + evt_index: bigint + transaction_type: varchar + token_address: varbinary + depositor: varbinary + amount: double + - name: morpho_base_base_borrow_seed + config: + column_types: + blockchain: varchar + project: varchar + version: varchar + block_number: bigint + block_time: timestamp + tx_hash: varbinary + evt_index: bigint + transaction_type: varchar + token_address: varbinary + borrower: varbinary + amount: double + - name: morpho_base_base_flashloans_seed + config: + column_types: + blockchain: varchar + project: varchar + version: varchar + block_number: bigint + block_time: timestamp + tx_hash: varbinary + evt_index: bigint + token_address: varbinary + recipient: varbinary + amount: double diff --git a/dbt_subprojects/hourly_spellbook/seeds/_sector/lending/morpho_base_base_borrow_seed.csv b/dbt_subprojects/hourly_spellbook/seeds/_sector/lending/morpho_base_base_borrow_seed.csv new file mode 100644 index 00000000000..bedcba9e1f8 --- /dev/null +++ b/dbt_subprojects/hourly_spellbook/seeds/_sector/lending/morpho_base_base_borrow_seed.csv @@ -0,0 +1,4 @@ +blockchain,project,version,block_number,block_time,tx_hash,evt_index,transaction_type,token_address,borrower,amount +base,morpho,1,25284479,2025-01-20 07:31:00.000 UTC,0x01f16d52115a5c6a98beb4c762a80df220e44ceb130ac706c3fe3b94b49a3248,321,repay,0x833589fcd6edb6e08f4c7c32d4f71b54bda02913,0x23055618898e202386e6c13955a58d3c68200bfb,-14808252558 +base,morpho,1,25284456,2025-01-20 07:30:00.000 UTC,0x0b5275144b76662ebaf9050258994db20633332fd04d7ffa6fc78c176a3fd524,118,borrow,0x833589fcd6edb6e08f4c7c32d4f71b54bda02913,0x23055618898e202386e6c13955a58d3c68200bfb,10000000000 +base,morpho,1,25276722,2025-01-20 03:13:00.000 UTC,0x9301be46a878f9206bee3f6f6c2ddca96471fcee5f586290a99b15b4053262d4,353,borrow_liquidation,0x833589fcd6edb6e08f4c7c32d4f71b54bda02913,0x0576dc91b3ae72ee2721b814dca3dedce631d734,-66504 \ No newline at end of file diff --git a/dbt_subprojects/hourly_spellbook/seeds/_sector/lending/morpho_base_base_flashloans_seed.csv b/dbt_subprojects/hourly_spellbook/seeds/_sector/lending/morpho_base_base_flashloans_seed.csv new file mode 100644 index 00000000000..7ba08a68c86 --- /dev/null +++ b/dbt_subprojects/hourly_spellbook/seeds/_sector/lending/morpho_base_base_flashloans_seed.csv @@ -0,0 +1,4 @@ +blockchain,project,version,block_number,block_time,tx_hash,evt_index,token_address,recipient,amount +base,morpho,1,25275752,2025-01-20 02:40:00.000 UTC,0xabdbc348232792d94730aa573a4a006442342cf19abf155920907ed224243652,366,0x4200000000000000000000000000000000000006,0xf66ab55d9452480d6ca48704734e98e16f69ebe1,221117064767549000 +base,morpho,1,25279175,2025-01-20 04:34:00.000 UTC,0x124f6f13e82cf93a9c81bb306791a73e12f35f0a0b3b6d1b02d4c8cc1f15e968,388,0x4200000000000000000000000000000000000006,0xf66ab55d9452480d6ca48704734e98e16f69ebe1,157653411227257632 +base,morpho,1,25277384,2025-01-20 03:35:00.000 UTC,0x578f5ce92dd211ff5a8616b028a8fc3a54e0cb6b832e5b75bee65267a0df5f9e,485,0x4200000000000000000000000000000000000006,0xf66ab55d9452480d6ca48704734e98e16f69ebe1,193132207850073370 \ No newline at end of file diff --git a/dbt_subprojects/hourly_spellbook/seeds/_sector/lending/morpho_base_base_supply_seed.csv b/dbt_subprojects/hourly_spellbook/seeds/_sector/lending/morpho_base_base_supply_seed.csv new file mode 100644 index 00000000000..16998ce226b --- /dev/null +++ b/dbt_subprojects/hourly_spellbook/seeds/_sector/lending/morpho_base_base_supply_seed.csv @@ -0,0 +1,4 @@ +blockchain,project,version,block_number,block_time,tx_hash,evt_index,transaction_type,token_address,depositor,amount +base,morpho,1,25284700,2025-01-20 07:39:00.000 UTC,0x57b7ebfe9f8f973ffdeca6f3379e0bae76484f3060b7cca43d0410054e1df77e,266,withdraw,0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf,,-50000000 +base,morpho,1,25284644,2025-01-20 07:37:00.000 UTC,0x012fbe2365d53fdabe8e71aca45096bf40ce2e63a86b4ca735a54a7fec55796f,602,deposit,0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf,0x543257ef2161176d7c8cd90ba65c2d4caef5a796,3150889 +base,morpho,1,25276722,2025-01-20 03:13:00.000 UTC,0x9301be46a878f9206bee3f6f6c2ddca96471fcee5f586290a99b15b4053262d4,353,deposit_liquidation,0x833589fcd6edb6e08f4c7c32d4f71b54bda02913,0x0576dc91b3ae72ee2721b814dca3dedce631d734,-21423024020247 \ No newline at end of file diff --git a/sources/_sector/lending/borrow/base/_sources.yml b/sources/_sector/lending/borrow/base/_sources.yml index 702ec368e87..cc6d815a07d 100644 --- a/sources/_sector/lending/borrow/base/_sources.yml +++ b/sources/_sector/lending/borrow/base/_sources.yml @@ -75,3 +75,11 @@ sources: - name: LendingPool_evt_Borrow - name: LendingPool_evt_Repay - name: LendingPool_evt_LiquidationCall + + - name: morpho_blue_base + tables: + - name: MorphoBlue_evt_CreateMarket + - name: MorphoBlue_evt_Borrow + - name: MorphoBlue_evt_Repay + - name: MorphoBlue_evt_Liquidate + diff --git a/sources/_sector/lending/flashloans/base/_sources.yml b/sources/_sector/lending/flashloans/base/_sources.yml index e710193c472..b89f8442a2c 100644 --- a/sources/_sector/lending/flashloans/base/_sources.yml +++ b/sources/_sector/lending/flashloans/base/_sources.yml @@ -12,3 +12,7 @@ sources: - name: the_granary_base tables: - name: LendingPool_evt_FlashLoan + + - name: morpho_blue_base + tables: + - name: MorphoBlue_evt_FlashLoan diff --git a/sources/_sector/lending/supply/base/_sources.yml b/sources/_sector/lending/supply/base/_sources.yml index 0fe93a08384..4d5809229f3 100644 --- a/sources/_sector/lending/supply/base/_sources.yml +++ b/sources/_sector/lending/supply/base/_sources.yml @@ -60,3 +60,8 @@ sources: tables: - name: LendingPool_evt_Deposit - name: LendingPool_evt_Withdraw + + - name: morpho_blue_base + tables: + - name: MorphoBlue_evt_Supply + - name: MorphoBlue_evt_Withdraw