👻
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
  • validateRepay
  • Setting paybackAmount
  • If useAtokens == true && params.amount == type.max
  • If params.amount < paybackAmount

Was this helpful?

Edit on GitHub
  1. Functions
  2. repay

validateRepay, paybackAmount

Previousget current debtNextburn debt tokens

Last updated 1 year ago

Was this helpful?

Overview

validateRepay

  • amountSent is params.amount, which is amount passed into repay

The first two require statements serves as input validation for amountSent

  1. ensure that value is non-zero

  2. ensure that an explicit amount was set by the user, else ensure that msg.sender is paying for himself

  1. If amountSent is type().max -> indicates an explicit amount was not set by user

  2. msg.sender is not onBehalfOf: paying for someone else

  3. when repaying for another party, user must be explicit in amount

    • cannot just whack uint256.max as a cover all

    • cos' what if the debt was unexpectedly large

Then we check if the asset status via getFlags:

  • Active

  • Not Paused

Lastly, we check that user has a non-zero debt in either one of the interest rate mode: stable or variable.

  • if both are zero, there is no debt to repay

Setting paybackAmount

  • Select the non-zero debt value and assign it to paybackAmount

Here paybackAmount reflects the total debt position of the user.

If useAtokens == true && params.amount == type.max

  • overwrite repay amount (params.amount) to the user's AToken balance

  • this is the max that can be repaid, given AToken balances

Applicable for repayWithATokens

In the case of repay, useATokens is set to false, therefore the code within the if section is not executed.

If params.amount < paybackAmount

  • User has opted to repay his debt partially,

  • overwrite paybackAmount to reflect user's choice of partial repayment

Here paybackAmount reflects what the user wishes to repay.

Another way to view this, is: "Is the user able to cover his total debt with the repay amount, if not, set paybackAmount to what he has offered to repay"

See link for in-depth explanation on

getFlags