Skip to content

Commit

Permalink
Added hourly interest for Aave on Base (#7404)
Browse files Browse the repository at this point in the history
* 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
mikeghen and Hosuke authored Jan 3, 2025
1 parent 01fb851 commit 23d8110
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 0 deletions.
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
*/
)
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,59 @@ models:
- &evt_index
name: evt_index
description: "Event index"

- name: aave_v3_base_interest_rates
meta:
blockchain: base
sector: lending
project: aave_v3
contributors: mikeghen1, batwayne, chuxin
config:
tags: ['base', 'aave_v3', 'interest', 'aave', 'lending']
description: "Hourly aave interest rates on base"
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- reserve
- symbol
- hour
columns:
- &reserve
name: reserve
description: "Aave reserve contract address"
- *symbol
- &hour
name: hour
description: "Block timestamp truncated to hours"
- &deposit_apy
name: deposit_apy
description: "Hourly deposit interest rate value of the reserve"
- &stable_borrow_apy
name: stable_borrow_apy
description: "Hourly stable borrow interest rate value of the reserve"
- &variable_borrow_apy
name: variable_borrow_apy
description: "Hourly variable borrow interest rate value of the reserve"

- name: aave_base_interest_rates
meta:
blockchain: base
sector: lending
project: aave
contributors: mikeghen1, batwayne, chuxin
config:
tags: ['base', 'aave_v3', 'interest', 'aave', 'lending']
description: "Hourly aave interest rates on base"
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- reserve
- symbol
- hour
columns:
- *reserve
- *symbol
- *hour
- *deposit_apy
- *stable_borrow_apy
- *variable_borrow_apy
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
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
61 changes: 61 additions & 0 deletions sources/aave/base/aave_base_sources.yml
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

0 comments on commit 23d8110

Please sign in to comment.