Skip to content

Commit

Permalink
Refactor Aave V3 EMode category handling (#4044)
Browse files Browse the repository at this point in the history
* Refactor Aave V3 EMode category handling

This commit refactors the Aave V3 EMode category handling by renaming some functions and variables for clarity. The changes include:
- Renaming `getAaveV3EModeCategoryForAsset` to `getAaveV3EModeCategoryForAssets` for consistency.
- Updating the function signature of `getAaveV3EModeCategoryForAssets` to accept `debtToken` and `collateralToken` parameters instead of a single `token` parameter.
- Adding logic to determine the EMode category based on whether the collateral or debt token is correlated with ETH.
- Renaming the `primaryTokenEModeCategory` and `secondaryTokenEModeCategory` variables to `strategyEmodeCategory` for better naming.

These changes improve the readability and maintainability of the code related to Aave V3 EMode category handling.

* Refactor Aave V3 EMode category handling
  • Loading branch information
marcinciarka authored Oct 14, 2024
1 parent ceaf97c commit 9032373
Show file tree
Hide file tree
Showing 6 changed files with 399 additions and 737 deletions.
20 changes: 13 additions & 7 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,7 @@ import BigNumber from 'bignumber.js'
import { NetworkIds } from 'blockchain/networks'
import { amountFromRay, amountFromWei } from 'blockchain/utils'
import { warnIfAddressIsZero } from 'helpers/warnIfAddressIsZero'
import { zero } from 'helpers/zero'
import { one, zero } from 'helpers/zero'
import { AaveV3PoolDataProvider__factory } from 'types/ethers-contracts'

import type { BaseParameters } from './utils'
Expand Down Expand Up @@ -191,14 +191,20 @@ export function getAaveV3ReserveConfigurationData({
})
}

export interface AaveV3EModeForAssetParameters extends BaseParameters {
token: string
export interface AaveV3EModeForAssetsParameters extends BaseParameters {
debtToken: string
collateralToken: string
}

export function getAaveV3EModeCategoryForAsset(
_props: AaveV3EModeForAssetParameters,
): Promise<BigNumber> {
return Promise.resolve(zero)
export function getAaveV3EModeCategoryForAssets({
collateralToken,
debtToken,
}: AaveV3EModeForAssetsParameters): Promise<BigNumber> {
const isCollateralEthCorrelated = collateralToken.toUpperCase().includes('ETH')
const isDebtEthCorrelated = debtToken.toUpperCase().includes('ETH')
const strategyEModeCategory = isCollateralEthCorrelated || isDebtEthCorrelated ? one : zero

return Promise.resolve(strategyEModeCategory)
}

export interface AaveV3ReserveCapParameters extends BaseParameters {
Expand Down
3 changes: 2 additions & 1 deletion blockchain/aave-v3/aave-v3-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ export function getEModeCategoryData({
categoryId,
}: GetEModeCategoryDataParameters): Promise<GetEModeCategoryDataResult> {
const { contract } = networkMappings[networkId]()
return contract.getEModeCategoryData(categoryId.toString(16)).then((result) => {

return contract.getEModeCategoryCollateralConfig(categoryId.toString(16)).then((result) => {
return {
ltv: new BigNumber(result.ltv.toString()).div(10000),
liquidationThreshold: new BigNumber(result.liquidationThreshold.toString()).div(10000),
Expand Down
Loading

0 comments on commit 9032373

Please sign in to comment.