Skip to content

Commit

Permalink
Morpho on Base (#7498)
Browse files Browse the repository at this point in the history
* init morpho on base

* fix base flashloans schema yml indentation

* fix base lending supply yml file

* add data source for base morpo

* deduplicate morpho base data sources

* fixed mopho typo

* fix morpho typo again

* correct seed file time formating

* correct date format

* correct seed files due to scientific notation instead of actual integer numbers

---------

Co-authored-by: jeff-dude <[email protected]>
  • Loading branch information
0xdatawolf001 and jeff-dude authored Jan 21, 2025
1 parent c4c4123 commit 383642f
Show file tree
Hide file tree
Showing 16 changed files with 403 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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')
]
%}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -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')
]
%}

Expand Down
Original file line number Diff line number Diff line change
@@ -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 %}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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')
]
%}

Expand Down
Original file line number Diff line number Diff line change
@@ -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 %}
Loading

0 comments on commit 383642f

Please sign in to comment.