From 725e7a7ef7e0f65a15ac94830aade21bc5ce5bf1 Mon Sep 17 00:00:00 2001 From: 0xPeluche <0xpeluche@proton.me> Date: Thu, 7 Mar 2024 15:02:10 +0100 Subject: [PATCH] update Aave-v3 ethereum, add stake --- src/adapters/aave-v3/common/stake.ts | 50 ++++++++++++++++++++++++++ src/adapters/aave-v3/ethereum/index.ts | 17 +++++++++ 2 files changed, 67 insertions(+) create mode 100644 src/adapters/aave-v3/common/stake.ts diff --git a/src/adapters/aave-v3/common/stake.ts b/src/adapters/aave-v3/common/stake.ts new file mode 100644 index 000000000..8e0d17c78 --- /dev/null +++ b/src/adapters/aave-v3/common/stake.ts @@ -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, + }) +} diff --git a/src/adapters/aave-v3/ethereum/index.ts b/src/adapters/aave-v3/ethereum/index.ts index bff90b6ed..fdd4a5cff 100644 --- a/src/adapters/aave-v3/ethereum/index.ts +++ b/src/adapters/aave-v3/ethereum/index.ts @@ -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', @@ -23,6 +38,7 @@ export const getContracts = async (ctx: BaseContext) => { return { contracts: { pools, + stkAAVEwstETHBPTv2, }, } } @@ -31,6 +47,7 @@ export const getBalances: GetBalancesHandler = async (ctx, const [balances, healthFactor] = await Promise.all([ resolveBalances(ctx, contracts, { pools: getLendingPoolBalances, + stkAAVEwstETHBPTv2: (...args) => getAaveStakeBalances(...args, balancer_vault), }), getLendingPoolHealthFactor(ctx, lendingPool), ])