👻
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
  • updateIsolatedDebtIfIsolated
  • Collect repay

Was this helpful?

Edit on GitHub
  1. Functions
  2. repay

Cleanup + Collect repay

Previousburn debt tokensNextliquidate

Last updated 1 year ago

Was this helpful?

Overview

We will cover the last three components in this section.

setBorrowing

If there is no outstanding debt left, within userConfig, set the borrowing flag for the asset to 0.

updateIsolatedDebtIfIsolated

In the event that the debt position was collateralized by an isolated asset, and a repay or liquidation occurred

  • total debt of the isolated asset must be decremented (isolationModeTotalDebt)

If user is in isolation mode:

  • get total isolated debt from reservesData (isolationModeTotalDebt)

  • rebase the decimals of paybackAmount

if isolationModeTotalDebt < repayAmount

  • reset total isolated debt on asset to 0

  • Else: decrement total isolated debt by repayAmount

Collect repay

Finally, the repayment is collected from the function caller.

If useATokens was set to true, like in repayWithATokens, Atokens would be burnt.

Example: User has DAI debt and also holds aDAI token

  • can use aDAI to repay DAI debt in single transaction without any approvals or having to withdraw their supplied liquidity to the pool using repayWithATokens feature

  • aDAI tokens would be burnt, reducing his claim on supplied assets.

Else, useATokens is set to false, in the case of repay;

  • asset is pulled from user via safeTransferFrom

  • example: borrowed USDC, repaying USDC: principal + plus interest

For function's inner workings, see: under the borrow section.

was previously explained in the borrow section

See withdraw section for

AToken.burn
getisolationModeState
setBorrowing
Drawing