> For the complete documentation index, see [llms.txt](https://docs.gammaswap.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gammaswap.com/guides/liquidations/how-liquidations-work.md).

# How Liquidations Work

Liquidations occur when the *Liquidity Debt* of a loan exceeds the *Liquidity Collateral* beyond the Liquidation Threshold of 99.5%.

### Liquidation Threshold

Since the liquidation threshold LTV ratio is 99.5%, then liquidation happens when the liquidity loan is greater than the liquidity collateral multiplied by 99.5%.

`liquidity debt > liquidity collateral * LTV_threshold`

This threshold can be modified when opening a leveraged perpetual trade in the platform.

### Liquidation Penalty

The penalty paid to the liquidator is the remaining collateral. For example, if liquidation happened right at the point that the liquidity debt crossed the liquidity collateral \* LTV\_Threshold and the LTV\_Threshold is 99.5%, that means the liquidation penalty fee is 0.5% of the liquidity collateral.

The penalty fee will never be lower than 0.25% of the liquidity collateral. Therefore if there's less than 0.25% available as collateral after paying for the liquidity debt, then the rest of the debt is written down and passed as a loss to LPs.

`Liquidation Penalty = max{collateral * penalty fee, collateral - liquidity debt}`

### **Liquidation Functions**

Liquidation functions are called directly from the GammaPool contract. They are not available to be called from the periphery (PositionManager) contract.

***liquidateWithLP(uint256 tokenId)*** - the tokenId refers to the loan that is subject to liquidation. The liquidator must first pass the LP Tokens required to pay the debt either partially or in full. That means that the collateral tokens of the loan are not used. If an excessive amount of LP tokens are passed, the excess amount is refunded to the liquidator. The liquidator receives the collateral, which is in reserve tokens.

***liquidate(uint256 tokenId, int256\[] calldata deltas)*** - the tokenId refers to the loan that is subject to liquidation. The liquidator can use the collateral tokens of the loan to liquidate with this function. A loan can only be liquidated in full with this function. Therefore, if the collateral is deficient on one side to retrieve the required LP token, the liquidator can use the delta's array to rebalance the position. Optionally, the liquidator can also deposit reserve tokens to rebalance the position so that he can retrieve the required LP Token debt. The liquidator receives the remaining collateral of the loan. If the liquidator deposited collateral in excess, he will receive back this excess collateral too.

***batchLiquidations(uint256\[] calldata tokenIds)*** - the tokenIds of loans to be liquidated are passed in this function. The purpose of this function is to liquidate multiple loans at the same time. There may be occasions where a loan is not economically viable to liquidate on its own due to transaction fees, but in batch it is economically feasible to liquidate. The liquidator must pass the required amount of LP Tokens to pay for the debts of all the loans that are to be liquidated. All loans must be liquidated in full. If an excess amount of LP tokens is passed, this excess amount will be refunded to the liquidator. The liquidator receives the collateral of the loans that are to be liquidated.


---

# 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://docs.gammaswap.com/guides/liquidations/how-liquidations-work.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.
