Ensure existing loans are collateralized
Last updated
Last updated
This function checks if a user has been borrowing any asset.
Takes UserConfigurationMap
as input, which contains a bitmap of the user's collaterals and borrows.
Uses BORROWING_MASK
, which is a bitmask that isolates the borrowing bits within data
. BORROWING_MASK
has a specific pattern of bits, with alternating 1
and 0
.
The function applies this mask to data
using a bitwise AND operation (&). This effectively keeps only the bits in data
that correspond to borrowing positions, while setting all other bits to 0.
If the result of the bitwise AND operation between self.data
and BORROWING_MASK
is not equal to 0
, it means that at least one bit in the borrowing position is set to 1
. This indicates that the user has been borrowing from at least one reserve.
To summarize, BORROWING_MASK
is a bitmask that preserves only the borrowing-related bits within the data field. Applying the BORROWING_MASK using a bitwise AND operation helps identify the borrowed assets by setting all non-borrowing bits to 0 and preserving the borrowing bits.
If the user is borrowing any asset, AND has been using the asset about to be withdrawn as collateral => need to validate HF and LTV.
calls on validateHealthFactor
to return the bool hasZeroLTVCollateral
Etiher one of the following two conditions must be true for this function to not revert:
!hasZeroLtvCollateral
: user has a non-zero LTV value across all assets
Asset being withdrawn has an LTV of 0
Condition 1 serves as a sanity check, given that validateHFAndLtv
is executed in the context that the user isBorrowingAny
.
This function is primarily a wrapper around .calculateUserAccountDataParams
.
The require statement ensures that the calculated health factor (after withdrawal) is above the liquidation threshold. If its not, user will be unable to withdraw asset.
.calculateUserAccountDataParams
This function calculates and returns the following user data across all the assets:
totalCollateralInBaseCurrency
totalDebtInBaseCurrency
avgLTV
avgLiquidationThreshold
healthFactor
hasZeroLtvCollateral
See calculateUserAccountDataParams for the full breakdown explanation.