Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding aave interests abstraction in Dune v2 #1434

Merged
merged 35 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
dbc1965
Added interests abstraction for aave on ethereum
SohamP99 Aug 25, 2022
f335343
Added tests for the aave interests abstraction
SohamP99 Aug 25, 2022
df6b959
Added base sources file for aave abstractions
SohamP99 Aug 25, 2022
e362584
Add aave schema
SohamP99 Aug 25, 2022
46a77b3
Merge branch 'duneanalytics:main' into master
SohamP99 Aug 26, 2022
8aeb621
Merge branch 'duneanalytics:main' into master
SohamP99 Aug 28, 2022
cf5885c
Update models/base_sources/aave_base_sources.yml
SohamP99 Aug 28, 2022
be33673
Update aave_base_sources.yml
SohamP99 Aug 28, 2022
07464df
Update aave_ethereum_schema.yml
SohamP99 Aug 28, 2022
c42afce
Update models/aave/aave_ethereum_schema.yml
SohamP99 Aug 28, 2022
16c38f6
Update aave_ethereum_interest_rates.sql
SohamP99 Aug 28, 2022
48d4cbd
Update aave_ethereum_schema.yml
SohamP99 Aug 28, 2022
7e17621
Update and rename aave_ethereum_interest_rates.sql to aave_v2_ethereu…
SohamP99 Aug 28, 2022
25737f2
Update Aave_interests_test.sql
SohamP99 Aug 28, 2022
7241fe0
Update Aave_interests_test.sql
SohamP99 Aug 28, 2022
a8b5be2
Merge branch 'duneanalytics:main' into master
SohamP99 Aug 29, 2022
96c25e4
Rename models/aave/Ethereum/aave_v2_ethereum_interest_rates.sql to mo…
SohamP99 Aug 29, 2022
af7987b
Rename tests/aave/Ethereum/Aave_interests_test.sql to tests/aave/ethe…
SohamP99 Aug 29, 2022
b71af09
Merge branch 'duneanalytics:main' into master
SohamP99 Aug 30, 2022
581fbfe
Update aave_v2_ethereum_interest_rates.sql
SohamP99 Aug 30, 2022
434907a
Merge branch 'duneanalytics:main' into master
SohamP99 Aug 30, 2022
9f09fd9
Merge branch 'duneanalytics:main' into master
SohamP99 Aug 30, 2022
c2fe824
Merge branch 'duneanalytics:main' into master
SohamP99 Sep 1, 2022
bff5737
Update and rename models/aave/aave_ethereum_schema.yml to models/aave…
SohamP99 Sep 2, 2022
6d5101a
Rename models/base_sources/aave_base_sources.yml to models/aave/ether…
SohamP99 Sep 2, 2022
8cc7173
Update aave_interests_test.sql
SohamP99 Sep 2, 2022
8203d7d
Merge branch 'main' into master
SohamP99 Sep 2, 2022
b03fdf7
Merge branch 'duneanalytics:main' into master
SohamP99 Sep 3, 2022
06f11bb
Update aave_ethereum_sources.yml
SohamP99 Sep 3, 2022
3b9ecda
Update aave_v2_ethereum_interest_rates.sql
SohamP99 Sep 3, 2022
e07e89e
Update aave_ethereum_sources.yml
SohamP99 Sep 3, 2022
31e7738
Update aave_v2_ethereum_interest_rates.sql
SohamP99 Sep 3, 2022
a3ae4c7
Merge branch 'duneanalytics:main' into master
SohamP99 Sep 7, 2022
8d3d27c
Update aave_v2_ethereum_interest_rates.sql
SohamP99 Sep 7, 2022
a50907b
Merge branch 'duneanalytics:main' into master
SohamP99 Sep 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ clean-targets: # directories to be removed by `dbt clean`
# Full documentation: https://docs.getdbt.com/docs/configuring-models
models:
spellbook:
aave:
+schema: aave
+materialized: view
ethereum:
+schema: aave_ethereum
+materialized: view
ens:
+schema: ens
+materialized: view
Expand Down Expand Up @@ -229,3 +235,4 @@ seeds:
amount_original: double
platform_fee_amount: double
pool_fee_amount: double

27 changes: 27 additions & 0 deletions models/aave/ethereum/aave_ethereum_schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: 2

models:
- name: aave_v2_ethereum_interest_rates
meta:
blockchain: ethereum
sector: dex
project: aave_v2
contibutors: batwayne, chuxinh

config:
tags: ['ethereum', 'aave_v2', 'interest', 'aave', 'dex']
description: "Hourly aave interest rates on ethereum"
columns:
- name: reserve
description: "Aave reserve contract address"
- name: symbol
description: "Symbol of the reserve"
- name: hour
description: "Block timestamp truncated to hours"
- name: deposit_apy
description: "Hourly deposit interest rate value of the reserve"
- name: stable_borrow_apy
description: "Hourly stable borrow interest rate value of the reserve"
- name: variable_borrow_apy
description: "Hourly variable borrow interest rate value of the reserve"

41 changes: 41 additions & 0 deletions models/aave/ethereum/aave_ethereum_sources.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
version: 2

sources:
- name: aave_v2_ethereum
description: "Decoded contracts for aave v2 on Ethereum"

tables:
- name: LendingPool_evt_ReserveDataUpdated
loaded_at_field: evt_block_time
description: "Provides the liqudity index, stable and variable borrow rates for aave v2 reserves."
freshness:
warn_after: { count: 12, period: hour }
error_after: { count: 24, period: hour }
columns:
- name: contract_address
description: "Aave token contract address"
- &evt_block_number
name: evt_block_number
description: "Event block number"
- &evt_block_time
name: evt_block_time
description: "Timestamp for block event time in UTC"
- &evt_index
name: evt_index
description: "Event index"
- &evt_tx_hash
name: evt_tx_hash
description: "Transaction hash of the event"
- name: liqudityIndex
description: "Liqudity index value of the reserve"
- name: liqudityRate
description: "Liqudity rate value of the reserve"
- name: reserve
description: "Aave reserve contract address"
- name: stableBorrowRate
description: "Stable borrow rate value of the reserve"
- name: variableBorrowIndex
description: "Variable borrow index value of the reserve"
- name: variableBorrowRate
description: "Variable borrow rate value of the reserve"

13 changes: 13 additions & 0 deletions models/aave/ethereum/aave_v2_ethereum_interest_rates.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{ config(materialized='view', alias='aave_interest') }}
SohamP99 marked this conversation as resolved.
Show resolved Hide resolved

select
a.reserve,
t.symbol,
date_trunc('hour',a.evt_block_time) as hour,
avg(a.liquidityRate) / 1e27 as deposit_apy,
avg(a.stableBorrowRate) / 1e27 as stable_borrow_apy,
avg(a.variableBorrowRate) / 1e27 as variable_borrow_apy
from {{ source('aave_v2_ethereum', 'LendingPool_evt_ReserveDataUpdated') }} a
left join {{ ref('tokens_ethereum_erc20') }} t
on a.reserve=t.contract_address
SohamP99 marked this conversation as resolved.
Show resolved Hide resolved
group by 1,2,3
22 changes: 22 additions & 0 deletions tests/aave/ethereum/aave_interests_test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
with unit_test1
as (select case
when variable_borrow_apy = 0.024106036652769853 then true
else false
end as test
from {{ ref('aave_v2_ethereum_interest_rates' )}}
where reserve = '0xdac17f958d2ee523a2206206994597c13d831ec7'
and hour = '2022-08-22 12:00'),
unit_test2
as (select case when deposit_apy = 0.004223674732695223 then true
else false
end as test
from {{ ref('aave_v2_ethereum_interest_rates' )}}
where symbol = 'USDC'
and hour = '2022-08-25 09:00')
select *
from (select *
from unit_test1
union
select *
from unit_test2)
where test = false
SohamP99 marked this conversation as resolved.
Show resolved Hide resolved