Skip to content

Commit

Permalink
Refactor Aave V3 EMode category handling
Browse files Browse the repository at this point in the history
  • Loading branch information
marcinciarka committed Oct 15, 2024
1 parent 9032373 commit faf75ce
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
4 changes: 2 additions & 2 deletions blockchain/aave-v3/aave-v3-pool-data-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -202,7 +201,8 @@ export function getAaveV3EModeCategoryForAssets({
}: AaveV3EModeForAssetsParameters): Promise<BigNumber> {
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)
}
Expand Down
19 changes: 7 additions & 12 deletions handlers/product-hub/update-handlers/aaveV3/aaveV3Handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,
},
}
}),
Expand All @@ -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(
Expand All @@ -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,
Expand Down

0 comments on commit faf75ce

Please sign in to comment.