.validateBorrow
Overview
validateBorrow()
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
getFlags
Asset must be
Active
NOT PAUSED
NOT FROZEN
Borrowing enabled
For in-depth explanation see: see getFlags
L2 priceOracleSentinel check
priceOracleSentinel is for L2 markets, when sequencer fails/lags.
address(0) -> none set, since L1
if address set -> check that borrow is allowed
InterestRateMode check (stable or variable)
params.interestRateMode
is an enum; representation of user input via UIUX.
either variable or stable must be selected
else transaction reverts with error
Get decimals & borrowCap
retrieve the asset's decimals and borrow cap, for which the user wishes to borrow.
To understand
getDecimals
: see getDecimals under common functionsTo understand
getBorrowCap
: see SupplyCap, BorrowCap under common functions
what assets have borrowCaps, and wen?
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
Check borrowCap
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 inupdateState
)
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.
If existing debt (variable + stable) accounting for latest interest, exceeds borrow cap -> to hell with your borrow
Remember that totalStableDebt was obtained in .cache via getSupplyData()
If in Isolation Mode
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
For in-depth explanation see: see getFlags
If in E-Mode
See getReserveFactor, the process is similar.
calculateUserAccountData
Serves to validate account health; healthFactor > 1
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
What is the base currency on Aave?
It depends on the market, V2 ETH Mainnet and V2 Polygon use ETH-based oracles, and all other markets use USD-based oracles
Each market has an AaveOracle contract where you can query token prices in the base currency.
If stable borrow -> check if requirements are met
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 user is already borrowing ANY reserve -> check if in siloed borrowing state
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.
Last updated