👻
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
  • getFlags
  • Example: ACTIVE_MASK illustration
  • Summary
  • Overview of required checks

Was this helpful?

Edit on GitHub
  1. Functions
  2. Common Functions

getFlags

PreviousSupplyCap, BorrowCapNextmore on flags

Last updated 1 year ago

Was this helpful?

getFlags

This function is defined in ReserveConfiguration.sol.

Function takes ReserveConfigurationMap struct as parameter. As we can see below, ReserveConfigurationMap contains data, which is a bitmap, and the various status flags range from bit 56 to 60.

getFlags makes use of the following bitmap masks to extract the relevant bits pertaining to each status flag:

The masks are applied upon the bitmap contained within the ReserveConfigurationMap struct. The bits that are relevant to us are from bit 56 - 60.

Notice how only the 15th hex character from the least significant bit varies in value across each of the masks - all other characters are F.

The exception to this is the PAUSED_MASK.

  • All the bits that are irrelevant within the bitmap have their corresponding bit in the bitmap mask to be set to F (1111 in binary).

  • The bitwise NOT (~), will led to an inversion of bit values, and together with the bitwise AND (&), this means that irrelevant bits will be paired up against 0 values in the mask for the & operation.

  • As such, they will be set to 0. The only bits that have a chance to be non-zero, will fall within bit 56 - 60, surfacing the values we require.

Example: ACTIVE_MASK illustration

As an example, lets overlay the ACTIVE_MASK upon the bitmap.

// ACTIVE_MASK: 0xFFF...E...FF
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFF
  • First 14 hex characters from the least significant bit are set to F - covers the values of bits from 0 - 55.

  • The 15th hex character in ACTIVE_MASK is set to E; 1110 in binary.

  • This results in only bit 56 being set to 0 - consequently, through the paired bitwise NOT and AND operation, only this bit has a possibility of being any value other than 0.

If the active flag is set to 0, the result will be as follows:

            0x0000...0...0   (data)
         &  0x0000...1...0   (~mask)
          -------------
           0x00000...0...0   (result)

// Remember the rules of bitwise AND (&):
// 0 & 0 = 0
// 0 & 1 = 0
// 1 & 1 = 1

Finally, the bitwise result is checked if its NOT equal to 0:

function getFlags(..) returns(...) {
    ...
    (dataLocal & ~ACTIVE_MASK) != 0,
    ...
}

// earlier result 
(0x00000...0...0) != 0
  • result is 0x00....00, which is equal to 0, evaluating to be FALSE. Therefore, in this case, isActive == FALSE.

On the other hand, if the active flag was set to 1 like so:

            0x0000...1...0   (data)
         &  0x0000...1...0   (~mask)
          -------------
           0x00000...1...0   (true)
  • The bitwise result contains a single bit set to 1, therefore it will not evaluate to be 0.

(dataLocal & ~ACTIVE_MASK) != 0,
(0x00000...1...0) != 0
  • isActive in this scenario will be true.

Summary

If the active flag bit achieves a non-zero value after the bitwise operations, != 0, will evaluate to true, thereby indicating that asset is in ACTIVE status.

If the active flag bit has a zero value, != 0, will evaluate to false, indicating that the asset is NOT ACTIVE.

Overview of required checks

Function
Active
Frozen
Paused
Borrowing Enabled
Stable Borrowing Enabled

Supply

Yes

No

No

Withdraw

Yes

No

Borrow

Yes

No

No

Yes

Depends on the mode

Repay

Yes

No

SwapRateMode

Yes

No

No

Depends on the mode

RebalanceStableBorrowRate

Yes

No

SetUseReserveAsCollateral

Yes

No

Flashloan

Yes

No

Liquidate

Yes

No

AToken Transfer

No

  • In V2 it is not possible to pause a specific reserve, only the entire pool.

  • In V3 role emergencyAdmin can pause a specific reserve.

This process applies similarly to the other status flags. If you are confused as to how bitwise operations work, please see the previous section: .

Reference:

bitmap & masks
https://docs.aave.com/faq/frozen-markets-and-reserves
getFlags
masks
DataTypes.sol