getIsolationModeState

Overview

getIsolationModeState

Check if user is in isolation mode, if so, return the isolated asset address and its corresponding debt ceiling.

Isolation mode: user can only use the specific isolation asset as collateral

There 3 other functions within getIsolationModeState which we will cover:

  1. isUsingAsCollateralOne

  2. _getFirstAssetIdByMask

  3. getDebtCeiling

Essentially,

  1. isUsingAsCollateralOne: check if user has ONLY ONE asset as collateral (any one).

  2. If check returns true, possible that the user is in isolation mode.

    • get and return isolation details: (true, assetAddress, debtCeiling)

  3. _getFirstAssetIdByMask is used to obtain the assetID of this asset.

    • Since isUsingAsCollateralOne is true,

    • only 1 asset to ID, no need to worry about multiple assets

  4. If isUsingAsCollateralOne is false

    • user has multiple reserves as collateral

    • not in Isolation mode

    • return (false, address(0), 0)

isUsingAsCollateralOne

Check if user has ONLY ONE asset as collateral (any one).

This function was explained previously when covering the supply function: isUsingCollateralOne

_getFirstAssetIdByMask

Returns the address of the first asset flagged in the bitmap given the corresponding bitmask.

  • if collateral_mask, find the first asset which has its collateral bit set to 1

uint256 internal constant COLLATERAL_MASK = 
0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA;
  • COLLATERAL_MASK is passed as mask

  • bitmapData is the binary string comprising of isolated collateral bits as explained in: isUsingAsCollateralAny

As we can see, we can end with id of value 1 -> index of the first asset which has its collateral bit set to 1 is 1.

getDebtCeiling

With the previously obtained asset index, we can retrieve the assetAddress by the reserveList mapping. With the address, we can retrieve its corresponding reservesData struct, using it to obtain the debt ceiling.

address assetAddress = reserveList[assetId];  //declared on PoolStorage.sol
uint256 ceiling = reservesData[assetAddress].configuration.getDebtCeiling();

getDebtCeiling will extract the debt ceiling value held within bits 212-251 in the ReserveConfigurationMap.

Reference: ReserveConfigurationMap

getDebtCeiling utilizes the same approach as explained in getReserveFactor; see that section for an in-depth explanation.

The debt ceiling value has decimals as dictated in ReserveConfiguration::DEBT_CEILING_DECIMALS, like so:

uint256 public constant DEBT_CEILING_DECIMALS = 2;

Last updated