From faf75ce5ca3214d1696d1106a57b1b8a3b5a3d48 Mon Sep 17 00:00:00 2001 From: Marcin Ciarka Date: Tue, 15 Oct 2024 11:29:41 +0200 Subject: [PATCH] Refactor Aave V3 EMode category handling --- .../aave-v3/aave-v3-pool-data-provider.ts | 4 ++-- .../update-handlers/aaveV3/aaveV3Handler.ts | 19 +++++++------------ 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/blockchain/aave-v3/aave-v3-pool-data-provider.ts b/blockchain/aave-v3/aave-v3-pool-data-provider.ts index efd16d9fee..0da06229ef 100644 --- a/blockchain/aave-v3/aave-v3-pool-data-provider.ts +++ b/blockchain/aave-v3/aave-v3-pool-data-provider.ts @@ -2,7 +2,6 @@ import BigNumber from 'bignumber.js' import { NetworkIds } from 'blockchain/networks' import { amountFromRay, amountFromWei } from 'blockchain/utils' import { warnIfAddressIsZero } from 'helpers/warnIfAddressIsZero' -import { one, zero } from 'helpers/zero' import { AaveV3PoolDataProvider__factory } from 'types/ethers-contracts' import type { BaseParameters } from './utils' @@ -202,7 +201,8 @@ export function getAaveV3EModeCategoryForAssets({ }: AaveV3EModeForAssetsParameters): Promise { const isCollateralEthCorrelated = collateralToken.toUpperCase().includes('ETH') const isDebtEthCorrelated = debtToken.toUpperCase().includes('ETH') - const strategyEModeCategory = isCollateralEthCorrelated || isDebtEthCorrelated ? one : zero + const strategyEModeCategory = + isCollateralEthCorrelated || isDebtEthCorrelated ? new BigNumber(1) : new BigNumber(0) return Promise.resolve(strategyEModeCategory) } diff --git a/handlers/product-hub/update-handlers/aaveV3/aaveV3Handler.ts b/handlers/product-hub/update-handlers/aaveV3/aaveV3Handler.ts index ff0d6fde12..9a6546c18f 100644 --- a/handlers/product-hub/update-handlers/aaveV3/aaveV3Handler.ts +++ b/handlers/product-hub/update-handlers/aaveV3/aaveV3Handler.ts @@ -22,7 +22,7 @@ import { aaveLikeAprToApy } from 'handlers/product-hub/helpers' import type { ProductHubHandlerResponse } from 'handlers/product-hub/types' import { ensureFind } from 'helpers/ensure-find' import { getYieldsRequest } from 'helpers/lambda/yields' -import { zero } from 'helpers/zero' +import { one, zero } from 'helpers/zero' import { memoize } from 'lodash' import { aaveV3ProductHubProducts } from './aave-v3-products' @@ -133,20 +133,16 @@ export default async function (tickers: Tickers): ProductHubHandlerResponse { ) const earnProductsEmodeLtvPromises = await Promise.all( aaveV3SupportedNetworkList.map(async (networkId) => { - const [cat1, cat2] = await Promise.all([ + // currently theres only one category - eth correlated + const [cat1] = await Promise.all([ getEModeCategoryData({ categoryId: new BigNumber(1), networkId: networkId as AaveV3SupportedNetwork, }), - getEModeCategoryData({ - categoryId: new BigNumber(2), - networkId: networkId as AaveV3SupportedNetwork, - }), ]) return { [networkId]: { 1: cat1.ltv, - 2: cat2.ltv, }, } }), @@ -164,13 +160,12 @@ export default async function (tickers: Tickers): ProductHubHandlerResponse { }), memoizedTokensData(product.network as AaveV3Networks, tickers), ]) - const isEModeTokenPair = !strategyEmodeCategory.isZero() + const isEmodeStrategy = strategyEmodeCategory.eq(one) const aaveLikeEmodeRiskRatio = - (isEModeTokenPair && - earnProductsEmodeLtv[networkId][strategyEmodeCategory.toNumber() as 1 | 2]) || + (isEmodeStrategy && earnProductsEmodeLtv[networkId][strategyEmodeCategory.toNumber() as 1]) || zero - const ltv = isEModeTokenPair + const ltv = isEmodeStrategy ? aaveLikeEmodeRiskRatio : ensureFind( tokensReserveData[product.network as AaveV3Networks].tokensReserveConfigurationData.find( @@ -183,7 +178,7 @@ export default async function (tickers: Tickers): ProductHubHandlerResponse { const response = await getYieldsRequest( { - actionSource: `product-hub handler aaveV3 EMODE:${isEModeTokenPair} ${product.primaryToken}/${product.secondaryToken} ${product.network}`, + actionSource: `product-hub handler aaveV3 EMODE:${isEmodeStrategy} ${product.primaryToken}/${product.secondaryToken} ${product.network}`, collateralTokenAddress: contracts.tokens[product.primaryToken].address, quoteTokenAddress: contracts.tokens[product.secondaryToken].address, collateralToken: product.primaryToken,