.validateBorrow
Last updated
Was this helpful?
Last updated
Was this helpful?
getFlags (status check)
L2 priceOracleSentinel check
InterestRateMode check (stable or variable)
Get decimals & borrowCap
Check borrowCap is not exceeded
If in Isolation Mode
check if asset is borrowable in Isolation mode and,
total exposure is less than the collateral debt ceiling
if in E-Mode
check reserve is in the same E-mode as user,
get eModePriceSource
CalculateUserAccountData:
HF, LTV, userDebt, userCollateral...
ensure account health is sound
Check if new total debt can be supported by collateral
Convert new borrow into Base CCY
Calculate total collateral required in Base CCY
check if sufficient collateral
If stable borrow -> check if requirements are met
If user is already borrowing ANY reserve -> check if in siloed borrowing state
Asset must be
Active
NOT PAUSED
NOT FROZEN
Borrowing enabled
priceOracleSentinel is for L2 markets, when sequencer fails/lags.
address(0) -> none set, since L1
if address set -> check that borrow is allowed
params.interestRateMode
is an enum; representation of user input via UIUX.
either variable or stable must be selected
else transaction reverts with error
retrieve the asset's decimals and borrow cap, for which the user wishes to borrow.
Once we have the decimals for the asset, we can define 1 unit of the asset in terms of decimals:
This is important because assets can have different definitions of 1 unit, due to inconsistent use of decimals:
Most typical ERC20 tokens: 1 unit = 1e18
USDC: 1 unit = 1e6
If (borrowCap != 0) {...check that its not exceeded with this new borrow action...}
if there is borrowCap set, vars.borrowCap
will be some non-zero value, thereby moving to execute the code within the if block.
Check that borrowCap is not exceeded with latest variableBorrowIndex
currentDebt * newVariableIndex
(index updated in updateState
)
Ignores incoming borrow action:
only checks that preexisting debt compounded with the most recent interest does not exceed borrow cap.
If so, can move forward and validate the incoming borrow action.
check if asset is borrowable in Isolation mode and,
total exposure is less than the collateral debt ceiling
Extracts bit 80 - 115 in the bitmap ReserveConfigurationMap
Serves to validate account health; healthFactor > 1
Convert new borrow into Base CCY
Calculate total collateral required in Base CCY
Check if sufficient collateral
reserve must be enabled for stable rate borrowing
(user should not be using reserve as collateral) || (LTV for reserve should be 0) || borrowAmount < user's Atoken balance
Users can only borrow only a portion of total available liquidity
User can only borrow up to 25% of availableLiquidity
, in a single stable borrow transaction.
If the user already has a borrowing position, check if the user is in siloed borrowing mode.
If user is in siloed borrowing mode, ensure that they are borrowing more of the siloed asset, not some other asset.
For in-depth explanation see: see
To understand getDecimals
: see under common functions
To understand getBorrowCap
: see under common functions
For in-depth explanation see: see
See , the process is similar.
See