From b94a845e652699bf6489e8c1e58aaf52e21afb0e Mon Sep 17 00:00:00 2001 From: piekczyk Date: Wed, 26 Jun 2024 13:38:46 +0200 Subject: [PATCH] Aave GHO markets (#3969) --- .../aave-v3/aave-v3-pool-data-provider.ts | 16 ++++++++++++++ .../strategies/ethereum-aave-v3-strategies.ts | 6 +++++ .../aave-v3-products/ethereum-mainnet.ts | 22 +++++++++++++++++++ .../update-handlers/aaveV3/aaveV3Handler.ts | 22 ++++++++++++++++++- 4 files changed, 65 insertions(+), 1 deletion(-) diff --git a/blockchain/aave-v3/aave-v3-pool-data-provider.ts b/blockchain/aave-v3/aave-v3-pool-data-provider.ts index 51a49f5d6d..dfe4e65377 100644 --- a/blockchain/aave-v3/aave-v3-pool-data-provider.ts +++ b/blockchain/aave-v3/aave-v3-pool-data-provider.ts @@ -148,6 +148,22 @@ export function getAaveV3ReserveData({ }) } +export function getAaveV3BorrowCap({ + token, + networkId, +}: AaveV3ReserveDataParameters): Promise { + const { contract, tokenMappings } = networkMappings[networkId]() + const tokenAddress = wethToEthAddress(tokenMappings, token) + warnIfAddressIsZero(tokenAddress, networkId, 'aaveV3PoolDataProvider', 'getReserveData') + + return ( + contract + .getReserveCaps(tokenAddress) + // doesn't require conversion from wei since value is already in correct format + .then((result) => new BigNumber(result.borrowCap.toString())) + ) +} + export function getAaveV3ReserveConfigurationData({ networkId, token, diff --git a/features/aave/strategies/ethereum-aave-v3-strategies.ts b/features/aave/strategies/ethereum-aave-v3-strategies.ts index 475621f46c..bbd1cae219 100644 --- a/features/aave/strategies/ethereum-aave-v3-strategies.ts +++ b/features/aave/strategies/ethereum-aave-v3-strategies.ts @@ -272,6 +272,12 @@ const availableTokenPairs: TokenPairConfig[] = [ strategyType: StrategyType.Long, productTypes: borrowAndMultiply, }, + { + collateral: 'WEETH', + debt: 'GHO', + strategyType: StrategyType.Long, + productTypes: borrowAndMultiply, + }, { collateral: 'ETH', debt: 'USDT', diff --git a/handlers/product-hub/update-handlers/aaveV3/aave-v3-products/ethereum-mainnet.ts b/handlers/product-hub/update-handlers/aaveV3/aave-v3-products/ethereum-mainnet.ts index 96da1d5c3a..9e815b7c2d 100644 --- a/handlers/product-hub/update-handlers/aaveV3/aave-v3-products/ethereum-mainnet.ts +++ b/handlers/product-hub/update-handlers/aaveV3/aave-v3-products/ethereum-mainnet.ts @@ -896,6 +896,28 @@ export const aaveV3EthereumMainnetProductHubProducts: ProductHubItemWithoutAddre network: NetworkNames.ethereumMainnet, protocol: LendingProtocol.AaveV3, }, + { + product: [OmniProductType.Multiply], + primaryToken: 'WEETH', + primaryTokenGroup: getTokenGroup('WEETH'), + secondaryToken: 'GHO', + depositToken: 'WEETH', + label: 'WEETH/GHO', + multiplyStrategyType: 'long', + multiplyStrategy: 'Long ETH', + network: NetworkNames.ethereumMainnet, + protocol: LendingProtocol.AaveV3, + }, + { + product: [OmniProductType.Borrow], + primaryToken: 'WEETH', + primaryTokenGroup: getTokenGroup('WEETH'), + secondaryToken: 'GHO', + depositToken: 'WEETH', + label: 'WEETH/GHO', + network: NetworkNames.ethereumMainnet, + protocol: LendingProtocol.AaveV3, + }, { product: [OmniProductType.Multiply], primaryToken: 'ETH', diff --git a/handlers/product-hub/update-handlers/aaveV3/aaveV3Handler.ts b/handlers/product-hub/update-handlers/aaveV3/aaveV3Handler.ts index 6a10c51d0a..9f69ed80ab 100644 --- a/handlers/product-hub/update-handlers/aaveV3/aaveV3Handler.ts +++ b/handlers/product-hub/update-handlers/aaveV3/aaveV3Handler.ts @@ -3,6 +3,7 @@ import BigNumber from 'bignumber.js' import type { AaveV3SupportedNetwork } from 'blockchain/aave-v3' import { aaveV3SupportedNetworkList, + getAaveV3BorrowCap, getAaveV3EModeCategoryForAsset, getAaveV3ReserveConfigurationData, getAaveV3ReserveData, @@ -39,6 +40,8 @@ const networkNameToIdMap = { [NetworkNames.baseMainnet]: NetworkIds.BASEMAINNET, } +const tokensWithoutAssociatedToken = ['GHO'] + const getAaveV3TokensData = async (networkName: AaveV3Networks, tickers: Tickers) => { const currentNetworkProducts = aaveV3ProductHubProducts.filter( (product) => product.network === networkName, @@ -62,13 +65,30 @@ const getAaveV3TokensData = async (networkName: AaveV3Networks, tickers: Tickers const tokensReserveDataPromises = secondaryTokensList.map(async (token) => { const reserveData = await getAaveV3ReserveData({ token, networkId }) const debtTokenPrice = new BigNumber(getTokenPrice(token, tickers, 'aaveV3Handler')) + + const fee = aaveLikeAprToApy(reserveData.variableBorrowRate) + + if (tokensWithoutAssociatedToken.includes(token.toUpperCase())) { + const borrowCap = await getAaveV3BorrowCap({ token, networkId }) + + return { + [token]: { + liquidity: borrowCap + .minus(reserveData.totalStableDebt) + .minus(reserveData.totalVariableDebt) + .times(debtTokenPrice), + fee, + }, + } + } + return { [token]: { liquidity: reserveData.totalAToken .minus(reserveData.totalStableDebt) .minus(reserveData.totalVariableDebt) .times(debtTokenPrice), - fee: aaveLikeAprToApy(reserveData.variableBorrowRate), + fee, }, } })