# liquidate

## Overview

This function is called by liquidators to liquidate "bad loans". Accounts with a health factor of less than 1 are eligible for liquidation.

**Assuming user's healthFactor < 1:**

* if healthFactor > 0.95 => close factor set to 50%
* if healthFactor <= 0.95 => close factor set to 100%&#x20;

Liquidators are awarded with liquidation bonus, which can be paid in ATokens or the underlying asset as well.&#x20;

{% hint style="info" %}

* user’s health factor: $$0.95 < hf < 1$$, the loan is eligible for a liquidation of 50%.
* user’s health factor: $$hf <= 0.95$$, the loan is eligible for a liquidation of 100%.
  {% endhint %}

<figure><img src="https://1829638638-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0k7YXwFGMFZcsyqkM4q1%2Fuploads%2FKNKbQ4ivYydz1FipZDTg%2Fimage.png?alt=media&#x26;token=ca635a65-30ca-40f9-9821-71a9553e3576" alt=""><figcaption></figcaption></figure>

<img src="https://1829638638-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0k7YXwFGMFZcsyqkM4q1%2Fuploads%2F9JhdtKmoMcOMn48Uvsm2%2Ffile.excalidraw.svg?alt=media&#x26;token=0f3a49e7-ca96-4576-a6c2-cebcc1ddd7b6" alt="" class="gitbook-drawing">

* `executeLiquidationCall` contains the core logics&#x20;

## executeLiquidationCall

<figure><img src="https://1829638638-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0k7YXwFGMFZcsyqkM4q1%2Fuploads%2Fv1eFIDfMZBGmuKTeA6eH%2Fimage.png?alt=media&#x26;token=8226c766-002d-4162-bc86-12350dedde39" alt=""><figcaption></figcaption></figure>

### Execution flow

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

We will breakdown and examine the unique sections of logics within **executeLiquidationCall**. Code delineated in orange are common functions and can be explored in that [section](https://calnix.gitbook.io/aave-book/functions/common-functions).

## Visual Aid

{% embed url="<https://link.excalidraw.com/readonly/CBWXwogzvmzFhZw3BcJs?darkMode=true>" %}


---

# Agent Instructions: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
