isFirstSupply
Last updated
Last updated
This is the last execution block for a supply action. This if block only executes in the event of a user's very first supply action for a specific asset.
If on minting ATokens, isFirstSupply
is returned as TRUE
, and the nested validateUseAsCollateral
returns TRUE
as well,
isFirstSupply
: TRUE
=> user's first time supplying this specific asset
validateUseAsCollateral
: TRUE
=> either:
isUsingAnyCollateralAny
: TRUE
=> user never supplied any asset ever,
OR,
!isolationMode && getDebtCeiling == 0
: TRUE => there is no debt ceiling on incoming supplied asset AND the user is not in isolation mode.
captures the return value from mint
TRUE
if user has no prior supply actions, and therefore a pre-dating zero supply balance
If TRUE
, execution moves into the nested if block, with the return value of validateUseAsCollateral
as the condition.
This function checks if the incoming asset can be used as collateral. If the user is previously in isolated mode, other assets cannot be supplied as collateral at the same time.
Supplied assets are automatically treated as collateral, if possible.
checks if user has been supplying ANY asset as collateral
returns FALSE
if user has NOT supplied ANY asset so far
If the user has never supplied any assets to date, (isUsingAsCollateralAny
returns FALSE
) validateUseAsCollateral
will exit early and return TRUE
.
Execution will then proceed to setUsingAsCollateral
; this will engage in first-time user configuration setup.
User cannot be in isolation mode if he has no supplied action to date.
However, if isUsingAsCollateralAny
is true; user has executed supply action sometime before. This means, we must check if the user is currently in isolation mode; achieved by getIsolationMode
.
If he is, it could cause conflict with the new supply action.
Additionally, there would be no need to execute setUsingAsCollateral
, as this is not a first-time user.
getIsolationMode
if user is supplying only one type of collateral, get the debt ceiling of the collateral to check if its an isolated asset.
returns TRUE
, along with value of debt ceiling
If the user is supplying multiple types of collateral, clearly he is not in isolation mode, returns FALSE
.
isUsingCollateralOne: checks if the user has been supplying only 1 asset as collateral
!isolationMode && getDebtCeiling == 0
:
TRUE => there is no debt ceiling on incoming supplied asset AND the user is not in isolation mode.
(reserveIndex << 1) + 1
This bitwise operation doubles the index and increments it by 1
Creates the necessary offset to manipulate the relevant bits to the asset of specified index
For more in-depth explanation see: isUsingCollateral
bit = 1 << offset
If usingAsCollateral
is true, indicating that the reserve should be marked as used for collateral,
bitwise OR operation between data
and the bit
value (self.data |= bit
).
sets the corresponding bit in the self.data
variable to 1
If usingAsCollateral
is false, indicating that the reserve should NOT be marked as collateral
bitwise AND operation between data
and the bit
value (self.data &= bit
).
sets the corresponding bit in the self.data
variable to 0