👻
Aave Book
  • Introduction
  • TradFi vs DeFi: Lending
  • Market forces x Interest Rate Models
  • On Indexes
    • Why use indexes?
  • Scaling and ATokens
  • Deposit & Borrow Interest
  • Stable borrowing
    • 🚧Under construction
  • Liquidation
    • 🚧TODO: Full example
    • 🚧Under construction: oracles
  • Primer
    • Bitmap & Masks
      • 🚧padding and bytes
    • WadRayLibrary
      • Math Operations
      • 🚧WIP: Scaling different decimal representations
      • 🚧WIP: 2's complement
      • 🚧casting: to uint128
    • PercentageMath
    • Embedded vs Linked Libraries
  • Functions
    • General Execution flow
    • Architecture & Design choices
      • 🚧Upgradability and Proxies
    • Common Functions
      • getReserveFactor, getDecimals
      • .cache
      • .updateState
      • .updateInterestRates
      • SupplyCap, BorrowCap
      • getFlags
        • 🚧more on flags
      • calculateUserAccountData
    • supply
      • validateSupply
      • transfer & mint
      • isFirstSupply
        • isUsingAsCollateralOne, isUsingAsCollateralAny
      • On check-effects-interactions pattern
    • withdraw
      • get user balance & withdraw amount
      • validateWithdraw
      • collateral check
      • burn ATokens
      • Ensure existing loans are collateralized
    • borrow
      • getIsolationModeState
      • .validateBorrow
      • Mint debt token
      • setBorrowing
      • update IsolationMode debt
      • transfer underlying to user
    • repay
      • get current debt
      • validateRepay, paybackAmount
      • burn debt tokens
      • Cleanup + Collect repay
    • liquidate
      • _calculateDebt
      • validateLiquidationCall
      • getConfigurationData
      • calculateAvailableCollateralToLiquidate
      • 🚧_burnDebtTokens
      • liquidate/burn collateral
      • liquidation Fee
      • Wrap-up
    • 🚧swapBorrowRateMode
    • 🚧setUserUseReserveAsCollateral
  • Contracts
    • AToken
      • Simple example: mint & balanceOf
    • StableDebtToken
      • Implementation explained
    • VariableDebtToken
    • DefaultReserveInterestRateStrategy
    • L2
      • 🚧PriceOracleSentinel
  • Audit findings
    • 🚧Under construction
  • Appendix
    • Simple, Compound, APR, APY
  • Aave Features
    • Risk Management
      • Supply & Borrow Caps
      • Isolation Mode
      • Siloed Borrowing
    • Other features
      • Repay with ATokens
      • eMode: High efficiency Mode
      • 🚧Aave Vault
      • 🚧Portal
Powered by GitBook
On this page
  • Overview
  • getIsolationModeState
  • isUsingAsCollateralOne
  • _getFirstAssetIdByMask
  • getDebtCeiling

Was this helpful?

Edit on GitHub
  1. Functions
  2. borrow

getIsolationModeState

PreviousborrowNext.validateBorrow

Last updated 1 year ago

Was this helpful?

Overview

getIsolationModeState

Check if user is in isolation mode, if so, return the isolated asset address and its corresponding debt ceiling.

Isolation mode: user can only use the specific isolation asset as collateral

There 3 other functions within getIsolationModeState which we will cover:

  1. isUsingAsCollateralOne

  2. _getFirstAssetIdByMask

  3. getDebtCeiling

Essentially,

  1. isUsingAsCollateralOne: check if user has ONLY ONE asset as collateral (any one).

  2. If check returns true, possible that the user is in isolation mode.

    • get and return isolation details: (true, assetAddress, debtCeiling)

  3. _getFirstAssetIdByMask is used to obtain the assetID of this asset.

    • Since isUsingAsCollateralOne is true,

    • only 1 asset to ID, no need to worry about multiple assets

  4. If isUsingAsCollateralOne is false

    • user has multiple reserves as collateral

    • not in Isolation mode

    • return (false, address(0), 0)

isUsingAsCollateralOne

Check if user has ONLY ONE asset as collateral (any one).

_getFirstAssetIdByMask

Returns the address of the first asset flagged in the bitmap given the corresponding bitmask.

  • if collateral_mask, find the first asset which has its collateral bit set to 1

uint256 internal constant COLLATERAL_MASK = 
0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA;
  • COLLATERAL_MASK is passed as mask

As we can see, we can end with id of value 1 -> index of the first asset which has its collateral bit set to 1 is 1.

getDebtCeiling

With the previously obtained asset index, we can retrieve the assetAddress by the reserveList mapping. With the address, we can retrieve its corresponding reservesData struct, using it to obtain the debt ceiling.

address assetAddress = reserveList[assetId];  //declared on PoolStorage.sol
uint256 ceiling = reservesData[assetAddress].configuration.getDebtCeiling();

getDebtCeiling will extract the debt ceiling value held within bits 212-251 in the ReserveConfigurationMap.

Reference: ReserveConfigurationMap

The debt ceiling value has decimals as dictated in ReserveConfiguration::DEBT_CEILING_DECIMALS, like so:

uint256 public constant DEBT_CEILING_DECIMALS = 2;

This function was explained previously when covering the supply function:

bitmapData is the binary string comprising of isolated collateral bits as explained in:

getDebtCeiling utilizes the same approach as explained in ; see that section for an in-depth explanation.

Drawing
Drawing
isUsingCollateralOne
isUsingAsCollateralAny
getReserveFactor