👻
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
  • Execution flow
  • liquidate/burn collateral
  • _liquidateATokens
  • _burnCollateralATokens

Was this helpful?

Edit on GitHub
  1. Functions
  2. liquidate

liquidate/burn collateral

Previous_burnDebtTokensNextliquidation Fee

Last updated 1 year ago

Was this helpful?

Overview

Execution flow

liquidate/burn collateral

If liquidator has opted to receive aTokens in payment (params.receiveAToken == true)

  • _liquidateATokens will be executed

  • Else: _burnCollatearlATokens will be executed

_liquidateATokens

Transfers aTokens from the target user to the liquidator.

  • Amount transferred: debtRepaid + liquidation penalty (in collateral terms)

  • If the liquidator did not have aTokens of this kind previously,

    • validateUseAsCollateral

    • setUsingAsCollateral

validateUseAsCollateral ensures that liquidator is not in isolation mode and the incoming asset is not an isolation mode asset.

If these conditions are met, the reserve transferred to the liquidator is set to be used as collateral.

transferOnLiquidiation calls _transfer, which executes the transfer of aTokens.

  • validate is set to false, therefore finalizeTransfer is not executed

For explanations on validateUseAsCollateral and setUsingAsCollateral, please see the supply section on the following segments:

Where possible, Aave opts to set supplied assets as collateral automatically. The exception to this are isolated assets.

_burnCollateralATokens

If the liquidator does not wish to receive ATokens, the alternative would be to transfer the underlying asset to them (instead of aDAI, transfer DAI).

To enact a transfer of the underlying asset, its corresponding aTokens must be "redeemed". Effectively, this means that liquidity is being removed from the system. This would therefore impact interest rates, and they have to be updated.

Hence, updateInterestRates is executed with parameters:

  • liquidityAdded = 0

  • liquidityRemoved = actualCollateralToLiquidate

Lastly, burn is executed.

  • _burnScaled: burn scaledAmount and update user balances

  • safeTransfer underlying asset from target user to liquidator

TO-DO:

  • does updateState need to be run again here?

  • nothing material would have changed between its inital execution to this point

  • confirm this.

validateUseAsCollateral
setUsingAsCollateral
Drawing