# Liquidation Mechanics on Flaex

Liquidation on flæx is fundamentally a close order. If the liquidation criteria are met, a liquidator would call a function on the flaex contract to trigger the liquidation process where it would force a close of the liquidated user’s position.

As a liquidation incentive, liquidators receive a percentage of the liquidated user’s collateral.

flæx relies on its lending partner, AAVE, for the liquidation process but also factors in the Uniswap price as a benchmark. To ensure fairness, flæx uses an oracle aggregator that combines prices from both AAVE's native oracle and the Uniswap Oracle, each contributing 50% to the final liquidation price.

The concept of a "Margin Ratio" is central to flæx's liquidation process. The Margin Ratio is calculated as follows:

```
MarginRatio = Value of Collateral/Value of Borrow
```

Currently, a position is subject to liquidation if the Margin Ratio drops to or below 1.1. Users will receive a Margin Call at a Margin Ratio of 1.25, signalling them to either supply more collateral or close their position to avoid liquidation if market conditions worsen.

Using the Uniswap Oracle can be risky, particularly on Layer 2 networks like Optimism and Arbitrum, where price manipulation is cheaper compared to Layer 1. On the flip side, AAVE’s native Oracle is safer but may suffer from delays and may not capture minor price fluctuations.

flæx’s design aggregates data from both oracles, capturing the strengths of each while minimizing the risks of oracle manipulation and malicious liquidations.

For a liquidation to be valid, the following condition must be met:

<figure><img src="https://2556163140-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Frt7CATwY7OuHUlwgVlxJ%2Fuploads%2FNNjL3Dm77ZYSu0BjFdj8%2Fimage.png?alt=media&#x26;token=e95633ad-e8dd-4686-9cab-ed82cc6d6c0c" alt=""><figcaption></figcaption></figure>

Where:

* **UniswapMarginRatio:** This is the Margin Ratio from the largest Uniswap liquidity pool containing the two assets.
* **AAVEMarginRatio:** This is the Margin Ratio based on AAVE’s data.

This dual-check mechanism ensures a more accurate liquidation price and mitigates the risk of Uniswap Oracle manipulation. For liquidation to proceed, the Uniswap Margin Ratio must be less than the AAVE Margin Ratio, but not by more than 3%.
