👻
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
  • transfer
  • mint
  • Visual Aid

Was this helpful?

Edit on GitHub
  1. Functions
  2. supply

transfer & mint

PreviousvalidateSupplyNextisFirstSupply

Last updated 1 year ago

Was this helpful?

Overview

updateInterestRates was covered in the common functions section

transfer

IERC20(params.asset).safeTransferFrom(msg.sender, reserveCache.aTokenAddress, params.amount);

This transfers the asset to be supplied from user to the corresponding AToken contract

  • from: msg.sender

  • to: aTokenAddress (aDAI, aWETH...)

User' supplied assets are held on their respective AToken contracts; DAI held on aDAI.

Use of safeTransferFrom

SafeERC20 is a helper to make safe the interaction with someone else’s ERC20 token, in your contracts. What the helper does for you is:

  1. check the boolean return values of ERC20 operations and revert the transaction if they fail,

  2. at the same time allowing you to support some non-standard ERC20 tokens that don’t have boolean return values.

It additionally provides helpers to increase or decrease an allowance, to mitigate an attack 118 possible with vanilla approve.

For more: https://forum.openzeppelin.com/t/making-sure-i-understand-how-safeerc20-works/2940

mint

  • minting of ATokens corresponding the supplied asset

bool isFirstSupply = IAToken(reserveCache.aTokenAddress).mint(msg.sender, params.onBehalfOf, params.amount, reserveCache.nextLiquidityIndex);
  • mint calls _mintScaled

  • _mintScaled mints tokens in-line with the current liquidity index, as seen by amountScaled

  • amountToMint: amountScaledcast as uint128

  • balanceIncrease: interest accrued from user's last recorded index and current index

  • _userState[onBehalfOf].additionalData is updated with the latest index.

balanceIncrease is calculated as part of the mint event emission.

On super.BalanceOf and _userState[onBehalfOf].additionalData

  • super.BalanceOf calls balanceOf declared in IncentivizedERC20.sol

  • Inheritance: ScaledBalanceTokenBase > MintableIncentivizedERC20 > IncentivizedERC20

  • notice the irregular definition of balanceOf, it calls out a mapping _userState

  • _userState is mapping of user addresses to UserState structs

  • Each UserState struct stores a user's balance with a wildcard field of additionalData

additionalData in the context of Atokens

  • used to store the index of the user's last "index-sensitive" action: --> last supply/withdrawal/borrow/repayment

Returns

mint returns the bool value of (scaledBalance == 0)

  • scaledBalance is the amount of balance a user has of a specific asset pre-dating this supply action

  • (scaledBalance == 0) will return true only if this supply action is the user's very first supply action - specific to said asset.

  • The return bool value is useful to us as explained in the next section.

Visual Aid

Drawing