getIsolationModeState
Last updated
Last updated
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:
isUsingAsCollateralOne
_getFirstAssetIdByMask
getDebtCeiling
Essentially,
isUsingAsCollateralOne
: check if user has ONLY ONE asset as collateral (any one).
If check returns true, possible that the user is in isolation mode.
get and return isolation details: (true, assetAddress, debtCeiling)
_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
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
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.
getDebtCeiling
will extract the debt ceiling value held within bits 212-251 in the 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: