👻
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
  • setBorrowing

Was this helpful?

Edit on GitHub
  1. Functions
  2. borrow

setBorrowing

PreviousMint debt tokenNextupdate IsolationMode debt

Last updated 1 year ago

Was this helpful?

Overview

bool ifFirstBorrowing captures the return value from either of the debt token's mint function. It is true, if the user had no debt previously, thereby making this incoming borrow action the user's very first one.

setBorrowing

The function performs bitwise operations to set or unset the borrowing status for the specified reserve.

It calculates the bit position based on the reserveIndex and creates a bit mask by left shifting 1 by twice the reserveIndex value. This mask is captured by the bit variable.

Setting Borrowing Status: If borrowing is true, the function uses a bitwise OR operation (|=) to set the corresponding bit in the self.data bitmap. This indicates that the user is borrowing the specified reserve.

Unsetting Borrowing Status: If borrowing is false, the function uses a bitwise AND operation (&=) with the bitwise negation (~bit) to unset the corresponding bit in the self.data map. This indicates that the user is not borrowing the specified reserve.

The process for both are similar, one sets the borrow flag, the other sets the collateral flag.

For in-depth illustration on how this function works, see: .

setUsingAsCollateral
Drawing