isFirstSupply
Overview

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 assetvalidateUseAsCollateral
: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.
isFirstSupply
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.
validateUseAsCollateral
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.

isUsingAsCollateralAny
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
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
.

Visual aid
isUsingCollateralOne: checks if the user has been supplying only 1 asset as collateral
return (!isolationMode && getDebtCeiling == 0)
!isolationMode && getDebtCeiling == 0
:
TRUE => there is no debt ceiling on incoming supplied asset AND the user is not in isolation mode.
setUsingAsCollateral

(reserveIndex << 1) + 1
(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
bit = 1 << offset
If usingAsCollateral
is true, indicating that the reserve should be marked as used for collateral,
bitwise OR operation between
data
and thebit
value (self.data |= bit
).sets the corresponding bit in the
self.data
variable to1
If usingAsCollateral
is false, indicating that the reserve should NOT be marked as collateral
bitwise AND operation between
data
and thebit
value (self.data &= bit
).sets the corresponding bit in the
self.data
variable to0
Last updated
Was this helpful?