> For the complete documentation index, see [llms.txt](https://sharwa.gitbook.io/sharwa-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sharwa.gitbook.io/sharwa-docs/margin-account/liquidation.md).

# Liquidation

## How Liquidation Works

When the margin ratio of a margin account falls below 105%, the account will be liquidated.&#x20;

### **Here’s how it works:**

As long as the total value of all assets in your margin account (denominated in $USDC) exceeds your total debt ( in $USDC) by at least 5%, your account remains safe.

If the margin ratio drops below 105%, liquidation will occur.

**Example:**

* Your margin account value: 110,000 $USDC
* Your aggregated debt: 100,000 $USDC
* Margin ratio: 110% → Your account is safe. You can reduce your debt but cannot increase leverage.

**Now, imagine that prices change, and your account value decreases:**

* New margin account value: 104,999 $USDC
* New aggregated debt: 100,000 $USDC
* New margin ratio: 104.99% → This is below the 105% threshold, triggering liquidation.

At this point, Sharwa will liquidate your positions to cover the debt, ensuring the system remains solvent.

### Order of Liquidation in a Margin Account

1\. Sell all ERC-20 tokens (e.g., $WETH, $WBTC) for $USDC&#x20;

2\. Exercise option position to receive $USDC.e (Hegic options payoffs in $USDC.e).

3\. Swap $USDC.e for $USDC&#x20;

4\. Use $USDC to buy back $ETH: USDC obtained from the previous steps is used to buy back the equivalent of $ETH (including debt and interest) to repay the debt to liquidity providers in the ETH liquidity pool (if applicable).

5\. Use $USDC to buy back $WBTC: Similarly, $USDC is used to buy back $WBTC (including debt and interest) to repay the debt to liquidity providers in the $WBTC liquidity pool (if applicable).

6\. Repay $USDC debt: If there’s any remaining $USDC debt, it is repaid using the $USDC from the previous steps.

7\. Remaining $USDC after repaying debts is returned to the margin account, allowing the trader to withdraw or use the funds to open new debts.

## Who triggers liquidations

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

To make sure margin accounts are liquidated promptly, we’ve set up two separate liquidation systems to monitor and act on all margin accounts:

* Se**rver-Side Script:** A classic script runs on a server, continuously pulling real-time data. When a margin account becomes eligible for liquidation, the script automatically triggers the liquidation mechanism.
* **Chainlink Automation:** This decentralized solution adds another level of reliability. When a margin account is ready for liquidation, Chainlink Automation steps in and triggers the liquidation process.
