> For the complete documentation index, see [llms.txt](https://calnix.gitbook.io/aave-book/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://calnix.gitbook.io/aave-book/functions/liquidate/liquidate-burn-collateral.md).

# liquidate/burn collateral

## Overview

<figure><img src="/files/0ccGoRTL5H2XZUoohcTt" alt=""><figcaption></figcaption></figure>

### Execution flow

* [x] <mark style="color:orange;">cache + updateState + get health factor</mark>
* [x] \_calculateDebt
* [x] validateLiquidationCall
* [x] getConfigurationData
* [x] calculateAvailableCollateralToLiquidate
* [x] <mark style="color:orange;">setBorrowing</mark>
* [x] <mark style="color:orange;">setUsingAsCollateral</mark>
* [x] \_burnDebtTokens
* [x] <mark style="color:orange;">updateInterestRates</mark>
* [x] <mark style="color:orange;">updateIsolatedDebtIfIsolated</mark>
* [ ] liquidate/burn collateral
* [ ] liquidation fee
* [ ] Wrap-up

## liquidate/burn collateral

<img src="/files/sMacrF3a63Wsy0Rbg5hv" alt="" class="gitbook-drawing">

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

* `_liquidateATokens` will be executed
* **Else**: \_burnCollatearlATokens will be executed

## `_liquidateATokens`&#x20;

Transfers aTokens from the target user to the liquidator.&#x20;

* 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.&#x20;

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

<figure><img src="/files/UFEuedFLEqphorV10OAl" alt=""><figcaption></figcaption></figure>

`transferOnLiquidiation` calls `_transfer`, which executes the transfer of aTokens.

<figure><img src="/files/1I0bbWwjksyXUPK3JXQs" alt=""><figcaption></figcaption></figure>

* `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:

* [validateUseAsCollateral](/aave-book/functions/supply/isfirstsupply.md#validateuseascollateral)
* &#x20;[setUsingAsCollateral](/aave-book/functions/supply/isfirstsupply.md#setusingascollateral)

{% hint style="info" %}
Where possible, Aave opts to set supplied assets as collateral automatically. The exception to this are isolated assets.&#x20;
{% endhint %}

## \_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).

<figure><img src="/files/2MASXPHHNss1caV7GyZw" alt=""><figcaption></figcaption></figure>

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.&#x20;

**Hence, `updateInterestRates` is executed with parameters:**

* liquidityAdded = 0
* liquidityRemoved = actualCollateralToLiquidate

Lastly, **`burn`** is executed.&#x20;

<figure><img src="/files/4ZfcZ0xOyOYaq4FtJGCB" alt=""><figcaption></figcaption></figure>

* **`_burnScaled`**: burn scaledAmount and update user balances
* safeTransfer underlying asset from target user to liquidator

{% hint style="warning" %}
TO-DO:

* does updateState need to be run again here?
* nothing material would have changed between its inital execution to this point
* confirm this.
  {% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://calnix.gitbook.io/aave-book/functions/liquidate/liquidate-burn-collateral.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
