👻
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
  • isFirstSupply
  • validateUseAsCollateral
  • getIsolationMode
  • setUsingAsCollateral

Was this helpful?

Edit on GitHub
  1. Functions
  2. supply

isFirstSupply

Previoustransfer & mintNextisUsingAsCollateralOne, isUsingAsCollateralAny

Last updated 1 year ago

Was this helpful?

Overview

This is the last execution block for a supply action. This if block only executes in the event of a user's very first supply action for a specific asset.

If on minting ATokens, isFirstSupply is returned as TRUE, and the nested validateUseAsCollateral returns TRUE as well,

  • isFirstSupply : TRUE => user's first time supplying this specific asset

  • validateUseAsCollateral : TRUE => either:

    • isUsingAnyCollateralAny: TRUE => user never supplied any asset ever,

    • OR,

    • !isolationMode && getDebtCeiling == 0: TRUE => there is no debt ceiling on incoming supplied asset AND the user is not in isolation mode.

isFirstSupply

  • captures the return value from mint

  • TRUE if user has no prior supply actions, and therefore a pre-dating zero supply balance

If TRUE, execution moves into the nested if block, with the return value of validateUseAsCollateral as the condition.

validateUseAsCollateral

Supplied assets are automatically treated as collateral, if possible.

isUsingAsCollateralAny

  • checks if user has been supplying ANY asset as collateral

  • returns FALSE if user has NOT supplied ANY asset so far

If the user has never supplied any assets to date, (isUsingAsCollateralAny returns FALSE) validateUseAsCollateral will exit early and return TRUE.

User cannot be in isolation mode if he has no supplied action to date.

However, if isUsingAsCollateralAny is true; user has executed supply action sometime before. This means, we must check if the user is currently in isolation mode; achieved by getIsolationMode.

  • If he is, it could cause conflict with the new supply action.

  • Additionally, there would be no need to execute setUsingAsCollateral, as this is not a first-time user.

getIsolationMode

  • if user is supplying only one type of collateral, get the debt ceiling of the collateral to check if its an isolated asset.

    • returns TRUE, along with value of debt ceiling

  • If the user is supplying multiple types of collateral, clearly he is not in isolation mode, returns FALSE.

Visual aid

  • isUsingCollateralOne: checks if the user has been supplying only 1 asset as collateral

return (!isolationMode && getDebtCeiling == 0)

!isolationMode && getDebtCeiling == 0:

  • TRUE => there is no debt ceiling on incoming supplied asset AND the user is not in isolation mode.

setUsingAsCollateral

(reserveIndex << 1) + 1

  • This bitwise operation doubles the index and increments it by 1

  • Creates the necessary offset to manipulate the relevant bits to the asset of specified index

bit = 1 << offset

If usingAsCollateral is true, indicating that the reserve should be marked as used for collateral,

  • bitwise OR operation between data and the bit value (self.data |= bit).

  • sets the corresponding bit in the self.data variable to 1

If usingAsCollateral is false, indicating that the reserve should NOT be marked as collateral

  • bitwise AND operation between data and the bit value (self.data &= bit).

  • sets the corresponding bit in the self.data variable to 0

This function checks if the incoming asset can be used as collateral. If the user is previously in , other assets cannot be supplied as collateral at the same time.

Execution will then proceed to ; this will engage in first-time user configuration setup.

For more in-depth explanation see:

isolated mode
isUsingAsCollateralAny breakdown
setUsingAsCollateral
Drawing
Drawing
Drawing
isUsingCollateral