Skip to content

Add aave v2, v3 helper and Avalon Finance adapter #2713

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

Merged
merged 13 commits into from
May 9, 2025

Conversation

noateden
Copy link
Contributor

This pull request support the Aave fees and revenue helper. It supports version 2 and version 3. Forks can use this helper with given configs.

This pull request also contains a case study of Avalon Finance is using Aave helper.

@llamabutler
Copy link

The avalon.ts adapter exports:

> [email protected] test
> ts-node --transpile-only cli/testAdapter.ts fees avalon.ts

🦙 Running AVALON.TS adapter 🦙
---------------------------------------------------
Start Date:	Tue, 25 Mar 2025 17:32:53 GMT
End Date:	Wed, 26 Mar 2025 17:32:53 GMT
---------------------------------------------------

[Error: Llama RPC error! method: undefined 
- host: https://bsc-dataseed.binance.org error: missing trie node
- host: https://binance.nodereal.io error: missing trie node
- host: https://endpoints.omniatech.io/v1/bsc/mainnet/public error: empty reader set
- host: https://bsc-dataseed1.defibit.io error: missing trie node
- host: https://0.48.club error: empty reader set
- host: https://bsc-pokt.nodies.app error: empty reader set
- host: https://bsc-dataseed.bnbchain.org error: missing trie node] {
  _underlyingError: '[object Object]',
  _isCustomError: true,
  chain: 'bsc'
}

@llamabutler
Copy link

The avalon.ts adapter exports:

> [email protected] test
> ts-node --transpile-only cli/testAdapter.ts fees avalon.ts

🦙 Running AVALON.TS adapter 🦙
---------------------------------------------------
Start Date:	Tue, 25 Mar 2025 17:39:40 GMT
End Date:	Wed, 26 Mar 2025 17:39:40 GMT
---------------------------------------------------

[Error: Llama RPC error! method: undefined 
- host: https://bsc-dataseed.binance.org error: missing trie node
- host: https://bsc-dataseed2.defibit.io error: missing trie node
- host: https://bsc-dataseed1.ninicoin.io error: missing trie node
- host: https://bsc-dataseed.bnbchain.org error: missing trie node
- host: https://bsc-dataseed2.ninicoin.io error: missing trie node
- host: https://bsc-dataseed2.bnbchain.org error: missing trie node
- host: https://bsc.meowrpc.com error: empty reader set] {
  _underlyingError: '[object Object]',
  _isCustomError: true,
  chain: 'bsc'
}

@g1nt0ki g1nt0ki self-assigned this Mar 26, 2025
@llamabutler
Copy link

The avalon.ts adapter exports:

> [email protected] test
> ts-node --transpile-only cli/testAdapter.ts fees avalon.ts

🦙 Running AVALON.TS adapter 🦙
---------------------------------------------------
Start Date:	Tue, 25 Mar 2025 20:50:19 GMT
End Date:	Wed, 26 Mar 2025 20:50:19 GMT
---------------------------------------------------

[Error: Llama RPC error! method: undefined 
- host: https://bsc-dataseed.binance.org error: missing trie node
- host: https://0.48.club error: empty reader set
- host: https://bsc-dataseed3.defibit.io error: missing trie node
- host: https://bsc-dataseed4.bnbchain.org error: missing trie node
- host: https://bsc-dataseed1.defibit.io error: missing trie node
- host: https://bsc-dataseed1.ninicoin.io error: missing trie node
- host: https://bsc-dataseed1.bnbchain.org error: missing trie node] {
  _underlyingError: '[object Object]',
  _isCustomError: true,
  chain: 'bsc'
}

params: [event.reserve],
skipCache: true,
permitFailure: false,
block: event.blockNumber - 1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line is why the block parameter you set here are ignored: https://github.com/DefiLlama/defillama-sdk/blob/master/src/ChainApi.ts#L48

so, instead of options.api, you need to use the vannila sdk.api2.call like here:
https://github.com/DefiLlama/DefiLlama-Adapters/blob/main/projects/contango/index.js#L21

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but, approx how many of these events are emitted per day? if it is a lot, one rpc call per event is not exactly scalable

// get reserves configs, mainly reserveFactor values
const reserveConfigs = await options.api.multiCall({
abi: AaveAbis.getReserveConfiguration,
calls: reservesList.map(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for the map here, you can move the target to the top level and do calls: reservesList,

const totalDailySupplySideRevenue = options.createBalances()

for (const pool of pools) {
const { dailyFees, dailyRevenue } = await getPoolFees(pool, options)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not pass dailyFees & dailyRevenue as third arg, this way, you dont have add everything up later

totalDailyHoldersRevenue.addBalances(dailyRevenue)

Object.entries(dailyRevenue.getBalances()).forEach(([token, balance]) => {
totalDailySupplySideRevenue.addTokenVannila(token, Number(balance) * -1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can simplify this by cloning the dailyFees object (.clone() ) and then subtracting daily revenue object (https://github.com/DefiLlama/defillama-sdk/blob/master/src/Balances.ts#L153)

@llamabutler
Copy link

The avalon.ts adapter exports:

> [email protected] test
> ts-node --transpile-only cli/testAdapter.ts fees avalon.ts

🦙 Running AVALON.TS adapter 🦙
---------------------------------------------------
Start Date:	Wed, 26 Mar 2025 03:31:35 GMT
End Date:	Thu, 27 Mar 2025 03:31:35 GMT
---------------------------------------------------

[Error: Llama RPC error! method: undefined 
- host: https://bsc-dataseed.binance.org error: missing trie node
- host: https://bsc-dataseed1.ninicoin.io error: missing trie node
- host: https://bsc-dataseed3.ninicoin.io error: missing trie node
- host: https://bsc-dataseed2.defibit.io error: missing trie node
- host: https://bsc-dataseed1.defibit.io error: missing trie node
- host: https://bsc.rpc.blxrbdn.com error: empty reader set
- host: https://0.48.club error: empty reader set] {
  _underlyingError: '[object Object]',
  _isCustomError: true,
  chain: 'bsc'
}

@llamabutler
Copy link

The avalon.ts adapter exports:

> [email protected] test
> ts-node --transpile-only cli/testAdapter.ts fees avalon.ts

🦙 Running AVALON.TS adapter 🦙
---------------------------------------------------
Start Date:	Wed, 26 Mar 2025 03:53:55 GMT
End Date:	Thu, 27 Mar 2025 03:53:55 GMT
---------------------------------------------------

[Error: Llama RPC error! method: undefined 
- host: https://bsc-dataseed.binance.org error: missing trie node
- host: https://bsc-dataseed1.ninicoin.io error: missing trie node
- host: https://bsc-dataseed4.defibit.io error: missing trie node
- host: https://bsc.meowrpc.com error: empty reader set
- host: https://bsc-dataseed3.ninicoin.io error: missing trie node
- host: https://bsc.rpc.blxrbdn.com error: empty reader set
- host: https://api.zan.top/bsc-mainnet error: Request failed with status code 429] {
  _underlyingError: '[object Object]',
  _isCustomError: true,
  chain: 'bsc'
}

@@ -76,7 +68,7 @@ async function getPoolFees(pool: AaveLendingPoolConfig, options: FetchOptions):
.flat()

for (const event of events) {
const reserveData = await options.api.call({
const reserveData = await sdk.api2.abi.call({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to pass chain parameter here, else it will run against ethereum (the default chain)

@llamabutler
Copy link

The avalon.ts adapter exports:

> [email protected] test
> ts-node --transpile-only cli/testAdapter.ts fees avalon.ts

🦙 Running AVALON.TS adapter 🦙
---------------------------------------------------
Start Date:	Wed, 26 Mar 2025 08:28:40 GMT
End Date:	Thu, 27 Mar 2025 08:28:40 GMT
---------------------------------------------------

[Error: Llama RPC error! method: undefined 
- host: https://bsc-dataseed.binance.org error: missing trie node
- host: https://bsc-dataseed3.defibit.io error: missing trie node
- host: https://endpoints.omniatech.io/v1/bsc/mainnet/public error: empty reader set
- host: https://api.zan.top/bsc-mainnet error: Request failed with status code 429
- host: https://bsc-dataseed1.bnbchain.org error: missing trie node
- host: https://binance.nodereal.io error: missing trie node
- host: https://rpc-bsc.48.club error: empty reader set] {
  _underlyingError: '[object Object]',
  _isCustomError: true,
  chain: 'bsc'
}

@llamabutler
Copy link

The avalon.ts adapter exports:

> [email protected] test
> ts-node --transpile-only cli/testAdapter.ts fees avalon.ts

🦙 Running AVALON.TS adapter 🦙
---------------------------------------------------
Start Date:	Wed, 26 Mar 2025 09:17:47 GMT
End Date:	Thu, 27 Mar 2025 09:17:47 GMT
---------------------------------------------------

[Error: Llama RPC error! method: undefined 
- host: https://bsc-dataseed.binance.org error: missing trie node
- host: https://bsc-dataseed3.ninicoin.io error: missing trie node
- host: https://bsc-dataseed3.defibit.io error: missing trie node
- host: https://bsc-dataseed4.bnbchain.org error: missing trie node
- host: https://bsc.rpc.blxrbdn.com error: empty reader set
- host: https://bsc-dataseed1.ninicoin.io error: missing trie node
- host: https://bsc-dataseed1.defibit.io error: missing trie node] {
  _underlyingError: '[object Object]',
  _isCustomError: true,
  chain: 'bsc'
}

@llamabutler
Copy link

The aave adapter exports:

> [email protected] test
> ts-node --transpile-only cli/testAdapter.ts fees aave

🦙 Running AAVE adapter 🦙
---------------------------------------------------
Start Date:	Thu, 08 May 2025 09:34:32 GMT
End Date:	Fri, 09 May 2025 09:34:32 GMT
---------------------------------------------------

[Error: Promise pool failed! 
 PromisePoolError: Llama RPC error! method: undefined 
- host: https://bsc-dataseed.binance.org error: missing trie node
- host: https://bsc.blockrazor.xyz error: empty reader set
- host: https://binance.nodereal.io error: missing trie node
- host: https://bsc-dataseed4.bnbchain.org error: missing trie node
- host: https://bsc-dataseed1.bnbchain.org error: missing trie node
- host: https://bsc.meowrpc.com error: empty reader set
- host: https://0.48.club error: empty reader set] {
  _isCustomError: true,
  chain: 'bsc'
}

@llamabutler
Copy link

The avalon.ts adapter exports:

> [email protected] test
> ts-node --transpile-only cli/testAdapter.ts fees avalon.ts

🦙 Running AVALON.TS adapter 🦙
---------------------------------------------------
Start Date:	Thu, 08 May 2025 09:35:09 GMT
End Date:	Fri, 09 May 2025 09:35:09 GMT
---------------------------------------------------

[Error: Promise pool failed! 
 PromisePoolError: Llama RPC error! method: undefined 
- host: https://bsc-dataseed.binance.org error: missing trie node
- host: https://bsc.drpc.org error: Request failed with status code 500
- host: https://bsc-dataseed3.ninicoin.io error: missing trie node
- host: https://bsc-dataseed2.bnbchain.org error: missing trie node
- host: https://bsc-rpc.publicnode.com error: missing trie node c7ac3d7f9472ae03336b2dd5ff5756e8042dbc2c195817b2c8d554d27c3a6c91 (path ) state 0xc7ac3d7f9472ae03336b2dd5ff5756e8042dbc2c195817b2c8d554d27c3a6c91 is not available
- host: https://bsc-pokt.nodies.app error: empty reader set
- host: https://bsc-dataseed4.defibit.io error: missing trie node] {
  _isCustomError: true,
  chain: 'bsc'
}

@llamabutler
Copy link

The aave adapter exports:

> [email protected] test
> ts-node --transpile-only cli/testAdapter.ts fees aave

🦙 Running AAVE adapter 🦙
---------------------------------------------------
Start Date:	Thu, 08 May 2025 09:39:17 GMT
End Date:	Fri, 09 May 2025 09:39:17 GMT
---------------------------------------------------

[Error: Llama RPC error! method: undefined 
- host: https://bsc-dataseed.binance.org error: missing trie node
- host: https://rpc.therpc.io/bsc error: missing trie node eecd010cc06c5ad353d8c346e1bc83cf8a992ea77d045209160b453fe7240b94 (path ) state 0xeecd010cc06c5ad353d8c346e1bc83cf8a992ea77d045209160b453fe7240b94 is not available
- host: https://binance.nodereal.io error: missing trie node
- host: https://bsc-rpc.publicnode.com error: missing trie node eecd010cc06c5ad353d8c346e1bc83cf8a992ea77d045209160b453fe7240b94 (path ) state 0xeecd010cc06c5ad353d8c346e1bc83cf8a992ea77d045209160b453fe7240b94 is not available
- host: https://bsc-dataseed4.bnbchain.org error: missing trie node
- host: https://endpoints.omniatech.io/v1/bsc/mainnet/public error: missing trie node
- host: https://bsc-dataseed1.defibit.io error: missing trie node] {
  _underlyingError: '[object Object]',
  _isCustomError: true,
  chain: 'bsc'
}

@llamabutler
Copy link

The avalon.ts adapter exports:

> [email protected] test
> ts-node --transpile-only cli/testAdapter.ts fees avalon.ts

🦙 Running AVALON.TS adapter 🦙
---------------------------------------------------
Start Date:	Thu, 08 May 2025 09:40:45 GMT
End Date:	Fri, 09 May 2025 09:40:45 GMT
---------------------------------------------------

[Error: Promise pool failed! 
 PromisePoolError: Llama RPC error! method: undefined 
- host: https://bsc-dataseed.binance.org error: missing trie node
- host: https://bsc-dataseed4.defibit.io error: missing trie node
- host: https://bsc-dataseed4.bnbchain.org error: missing trie node
- host: https://bsc.drpc.org error: Request failed with status code 500
- host: https://bsc-dataseed2.defibit.io error: missing trie node
- host: https://bsc-rpc.publicnode.com error: missing trie node eecd010cc06c5ad353d8c346e1bc83cf8a992ea77d045209160b453fe7240b94 (path ) state 0xeecd010cc06c5ad353d8c346e1bc83cf8a992ea77d045209160b453fe7240b94 is not available
- host: https://bsc-dataseed1.defibit.io error: missing trie node] {
  _isCustomError: true,
  chain: 'bsc'
}

@llamabutler
Copy link

The aave adapter exports:

> [email protected] test
> ts-node --transpile-only cli/testAdapter.ts fees aave

🦙 Running AAVE adapter 🦙
---------------------------------------------------
Start Date:	Thu, 08 May 2025 09:55:02 GMT
End Date:	Fri, 09 May 2025 09:55:02 GMT
---------------------------------------------------

[Error: Llama RPC error! method: undefined 
- host: https://bsc-dataseed.binance.org error: missing trie node
- host: https://bsc-dataseed1.ninicoin.io error: missing trie node
- host: https://bsc.blockrazor.xyz error: empty reader set
- host: https://bnb.api.onfinality.io/public error: Request failed with status code 429
- host: https://bsc-dataseed4.ninicoin.io error: missing trie node
- host: https://rpc.therpc.io/bsc error: missing trie node 9edabb5bfa416022f75ff44cd2d622358e96b9db40dab1c7891d560b08523490 (path ) state 0x9edabb5bfa416022f75ff44cd2d622358e96b9db40dab1c7891d560b08523490 is not available
- host: https://endpoints.omniatech.io/v1/bsc/mainnet/public error: missing trie node 9edabb5bfa416022f75ff44cd2d622358e96b9db40dab1c7891d560b08523490 (path ) state 0x9edabb5bfa416022f75ff44cd2d622358e96b9db40dab1c7891d560b08523490 is not available] {
  _underlyingError: '[object Object]',
  _isCustomError: true,
  chain: 'bsc'
}

@llamabutler
Copy link

The avalon.ts adapter exports:

> [email protected] test
> ts-node --transpile-only cli/testAdapter.ts fees avalon.ts

🦙 Running AVALON.TS adapter 🦙
---------------------------------------------------
Start Date:	Thu, 08 May 2025 09:55:41 GMT
End Date:	Fri, 09 May 2025 09:55:41 GMT
---------------------------------------------------

[Error: Llama RPC error! method: undefined 
- host: https://bsc-dataseed.binance.org error: missing trie node
- host: https://bsc.drpc.org error: Request failed with status code 500
- host: https://bsc-dataseed1.bnbchain.org error: missing trie node
- host: https://bsc-dataseed1.defibit.io error: missing trie node
- host: https://rpc-bsc.48.club error: empty reader set
- host: https://bsc-dataseed2.ninicoin.io error: missing trie node
- host: https://rpc.therpc.io/bsc error: missing trie node 9edabb5bfa416022f75ff44cd2d622358e96b9db40dab1c7891d560b08523490 (path ) state 0x9edabb5bfa416022f75ff44cd2d622358e96b9db40dab1c7891d560b08523490 is not available] {
  _underlyingError: '[object Object]',
  _isCustomError: true,
  chain: 'bsc'
}

@noateden noateden merged commit 3c2fa3b into DefiLlama:master May 9, 2025
2 checks passed
@noateden noateden deleted the f/aave-fees-adapter branch May 9, 2025 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants