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

update Aave-v3 ethereum, add stake #1344

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
50 changes: 50 additions & 0 deletions src/adapters/aave-v3/common/stake.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import type { Balance, BalancesContext, Contract } from '@lib/adapter'
import { getUnderlyingsBalancesFromBalancer, type IBalancerBalance } from '@lib/balancer/underlying'
import { call } from '@lib/call'
import { abi as erc20Abi } from '@lib/erc20'

const abi = {
getTotalRewardsBalance: {
inputs: [{ internalType: 'address', name: 'staker', type: 'address' }],
name: 'getTotalRewardsBalance',
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
stateMutability: 'view',
type: 'function',
},
} as const

const AAVE: Contract = {
chain: 'ethereum',
address: '0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9',
decimals: 18,
symbol: 'AAVE',
}

export async function getAaveStakeBalances(ctx: BalancesContext, pool: Contract, vault: Contract) {
const [shareBalance, rewardsBalance] = await Promise.all([
call({
ctx,
target: pool.address,
params: [ctx.address],
abi: erc20Abi.balanceOf,
}),
call({
ctx,
target: pool.address,
params: [ctx.address],
abi: abi.getTotalRewardsBalance,
}),
])

const poolBalance: Balance = {
...(pool as Balance),
amount: shareBalance,
rewards: [{ ...AAVE, amount: rewardsBalance }],
category: 'stake',
}

return getUnderlyingsBalancesFromBalancer(ctx, [poolBalance] as IBalancerBalance[], vault, {
getAddress: (balance: Balance) => balance.token!,
getCategory: (balance: Balance) => balance.category,
})
}
17 changes: 17 additions & 0 deletions src/adapters/aave-v3/ethereum/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
import { getAaveStakeBalances } from '@adapters/aave-v3/common/stake'
import type { AdapterConfig, BaseContext, Contract, GetBalancesHandler } from '@lib/adapter'
import { resolveBalances } from '@lib/balance'

import { getLendingPoolBalances, getLendingPoolContracts, getLendingPoolHealthFactor } from '../common/lending'

const balancer_vault: Contract = {
chain: 'ethereum',
address: '0xba12222222228d8ba445958a75a0704d566bf2c8',
}

const stkAAVEwstETHBPTv2: Contract = {
chain: 'ethereum',
address: '0x9eda81c21c273a82be9bbc19b6a6182212068101',
token: '0x3de27EFa2F1AA663Ae5D458857e731c129069F29',
underlyings: ['0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0', '0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9'],
poolId: '0x3de27efa2f1aa663ae5d458857e731c129069f29000200000000000000000588',
rewards: ['0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9'],
}

const lendingPool: Contract = {
name: 'Pool',
displayName: 'Pool',
Expand All @@ -23,6 +38,7 @@ export const getContracts = async (ctx: BaseContext) => {
return {
contracts: {
pools,
stkAAVEwstETHBPTv2,
},
}
}
Expand All @@ -31,6 +47,7 @@ export const getBalances: GetBalancesHandler<typeof getContracts> = async (ctx,
const [balances, healthFactor] = await Promise.all([
resolveBalances<typeof getContracts>(ctx, contracts, {
pools: getLendingPoolBalances,
stkAAVEwstETHBPTv2: (...args) => getAaveStakeBalances(...args, balancer_vault),
}),
getLendingPoolHealthFactor(ctx, lendingPool),
])
Expand Down
Loading