-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added hourly interest for Aave on Base (#7404)
* Added hourly interest for Aave on Base * Update post_hook format and incremental filter * Update dbt_subprojects/daily_spellbook/models/aave/base/aave_base_schema.yml * Update dbt_subprojects/daily_spellbook/models/aave/base/aave_v3_base_interest_rates.sql * Use tokens table * Add real values to the test * Use correct base table * Added aave_v3_base.L2Pool_evt_ReserveDataUpdated source * Update test values --------- Co-authored-by: Huang Geyang <[email protected]>
- Loading branch information
Showing
5 changed files
with
196 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
dbt_subprojects/daily_spellbook/models/aave/base/aave_base_interest_rates.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{{ config( | ||
schema = 'aave_base' | ||
, alias = 'interest_rates' | ||
, post_hook='{{ expose_spells(blockchains = \'["base"]\', | ||
spell_type = "project", | ||
spell_name = "aave", | ||
contributors = \'["mikeghen1","batwayne", "chuxin"]\') }}' | ||
) | ||
}} | ||
|
||
SELECT * | ||
FROM | ||
( | ||
SELECT | ||
reserve, | ||
symbol, | ||
hour, | ||
deposit_apy, | ||
stable_borrow_apy, | ||
variable_borrow_apy | ||
FROM {{ ref('aave_v3_base_interest_rates') }} | ||
/* | ||
UNION ALL | ||
< add new version as needed | ||
*/ | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
dbt_subprojects/daily_spellbook/models/aave/base/aave_v3_base_interest_rates.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{{ config( | ||
schema = 'aave_v3_base' | ||
, alias = 'interest_rates' | ||
, materialized = 'incremental' | ||
, file_format = 'delta' | ||
, incremental_strategy = 'merge' | ||
, unique_key = ['reserve', 'symbol', 'hour'] | ||
, post_hook='{{ expose_spells(blockchains = \'["base"]\', | ||
spell_type = "project", | ||
spell_name = "aave_v3", | ||
contributors = \'["mikeghen1","batwayne", "chuxin"]\') }}' | ||
) | ||
}} | ||
|
||
select | ||
a.reserve, | ||
t.symbol, | ||
date_trunc('hour',a.evt_block_time) as hour, | ||
avg(CAST(a.liquidityRate AS DOUBLE)) / 1e27 as deposit_apy, | ||
avg(CAST(a.stableBorrowRate AS DOUBLE)) / 1e27 as stable_borrow_apy, | ||
avg(CAST(a.variableBorrowRate AS DOUBLE)) / 1e27 as variable_borrow_apy | ||
from {{ source('aave_v3_base', 'L2Pool_evt_ReserveDataUpdated') }} a | ||
left join {{ source('tokens', 'erc20') }} t | ||
on a.reserve = t.contract_address and t.blockchain = 'base' | ||
{% if is_incremental() %} | ||
WHERE {{ incremental_predicate('evt_block_time') }} | ||
{% endif %} | ||
group by 1,2,3 |
25 changes: 25 additions & 0 deletions
25
dbt_subprojects/daily_spellbook/tests/aave/base/aave_base_interests_test.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
with unit_test1 | ||
as (select case | ||
when abs(variable_borrow_apy - 0.10808360395679557) / 0.10808360395679557 < 0.001 | ||
then true | ||
else false | ||
end as test | ||
from {{ ref('aave_v3_base_interest_rates' )}} | ||
where reserve = 0x833589fcd6edb6e08f4c7c32d4f71b54bda02913 -- USDC | ||
and hour = TIMESTAMP '2025-01-02 20:00'), | ||
unit_test2 | ||
as (select case | ||
when abs(deposit_apy - 0.015712521763084) / 0.015712521763084 < 0.001 | ||
then true | ||
else false | ||
end as test | ||
from {{ ref('aave_v3_base_interest_rates' )}} | ||
where symbol = 'WETH' -- 0x4200000000000000000000000000000000000006 | ||
and hour = TIMESTAMP '2024-08-21 03:00') | ||
select * | ||
from (select * | ||
from unit_test1 | ||
union | ||
select * | ||
from unit_test2) | ||
where test = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
version: 2 | ||
|
||
sources: | ||
- name: aave_v3_base | ||
description: "Decoded contracts for aave v3 on Base" | ||
|
||
tables: | ||
- name: L2Pool_evt_ReserveDataUpdated | ||
description: "Provides the liquidity index, stable and variable borrow rates for aave v3 reserves." | ||
columns: | ||
- name: contract_address | ||
description: "Aave token contract address" | ||
type: varbinary | ||
|
||
- name: evt_tx_hash | ||
description: "Transaction hash of the event" | ||
type: varbinary | ||
|
||
- name: evt_tx_from | ||
description: "Address that initiated the transaction" | ||
type: varbinary | ||
|
||
- name: evt_tx_to | ||
description: "Address that received the transaction" | ||
type: varbinary | ||
|
||
- name: evt_index | ||
description: "Event index" | ||
type: bigint | ||
|
||
- name: evt_block_time | ||
description: "Timestamp for block event time in UTC" | ||
type: timestamp | ||
|
||
- name: evt_block_number | ||
description: "Event block number" | ||
type: bigint | ||
|
||
- name: reserve | ||
description: "Aave reserve contract address" | ||
type: varbinary | ||
|
||
- name: liquidityRate | ||
description: "Liquidity rate value of the reserve" | ||
type: uint256 | ||
|
||
- name: stableBorrowRate | ||
description: "Stable borrow rate value of the reserve" | ||
type: uint256 | ||
|
||
- name: variableBorrowRate | ||
description: "Variable borrow rate value of the reserve" | ||
type: uint256 | ||
|
||
- name: liquidityIndex | ||
description: "Liquidity index value of the reserve" | ||
type: uint256 | ||
|
||
- name: variableBorrowIndex | ||
description: "Variable borrow index value of the reserve" | ||
type: uint256 |