# Liquidation

The liquidation process in the Fathom protocol involves several key components and steps outlined in detail in the `LiquidationEngine` and `FixedSpreadLiquidationStrategy` contracts. The liquidation mechanism maintains the system's stability by handling under-collateralized positions. Here is an overview of the process:

**Components Involved:**

1. **Liquidation Engine (`LiquidationEngine`):** Manages the overall liquidation process.
2. **Fixed Spread Liquidation Strategy (`FixedSpreadLiquidationStrategy`):** Implements a specific strategy for liquidation.
3. **Collateral Pool Config (`CollateralPoolConfig`):** Provides configuration for collateral pools, including parameters like liquidation ratio, close factor, and liquidator incentives.
4. **BookKeeper (`BookKeeper`):** Records positions, stablecoin balances and collateral.
5. **System Debt Engine (`SystemDebtEngine`):** Manages the system's overall debt and surpluses, including systemBadDebt and systemSurpluses.
6. **Price Oracle (`PriceOracle`):** Provides price feeds for collateral assets.

**Liquidation Process:**

1. **Triggering Liquidation:**

* A position becomes eligible for liquidation when its collateral value falls below a predefined threshold (defined by the liquidation ratio in `CollateralPoolConfig`). The liquidation Ratio is the same as ( *1 / Loan to Value Ratio*).&#x20;
* The `PriceOracle` plays a crucial role in determining the health of positions by providing the latest available prices for collateral assets.

2. **Liquidation Execution:**

* The liquidation process is initiated by a liquidator (which, at the moment, is a role only available to whitelisted addresses) who identifies an under-collateralized position and calls the liquidate function in `LiquidationEngine`.
* The liquidate function checks various conditions, such as the liquidator's whitelist status, the system's operational status (live), and the health of the price feed.
* If the conditions are met, `LiquidationEngine` interacts with the `FixedSpreadLiquidationStrategy` to execute the liquidation.

3. **Fixed Spread Liquidation Strategy:**

* This strategy determines the specifics of the liquidation, such as the amount of debt to be repaid and the amount of collateral to be seized.
* It calculates the required parameters based on current prices, debt accumulated rates, and other factors defined in `CollateralPoolConfig`.

4. **Financial Adjustments:**

* Upon successful liquidation, the `BookKeeper` updates the financial state of the system, including adjusting the debt and collateral amounts for the liquidated position.
* The `SystemDebtEngine` may also handle any resultant bad debt from the liquidation process.

5. **Distribution of Assets:**

* The liquidator typically receives a portion of the seized collateral as an incentive, with the rest used to repay the debt.
* Parameters like liquidator incentives and treasury fees govern the distribution of assets.

6. **Edge Cases and Safeguards:**

* The system includes various safeguards and checks to prevent unauthorized access and ensure the integrity of the liquidation process.
* For instance, roles and permissions are enforced using access control mechanisms.

The following subsection guides you through the liquidation process in detail.


---

# 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://docs.fathom.fi/fxd-stablecoin/liquidation.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.
