> For the complete documentation index, see [llms.txt](https://docs.symm.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.symm.io/options-protocol-architecture/technical-architecture/liquidation-system.md).

# Liquidation System

The Symmio Options Protocol has a liquidation system that manages counterparty risk and keeps the protocol solvent. Liquidations are orchestrated by the *Symmio Clearing House*, the protocol's enforcement and settlement authority.

### Liquidation workflow

Liquidation has three core stages.

#### Step 1: flagging

* The Clearing House can flag accounts that look insolvent based on external solvency checks.
* Flagging creates a `LiquidationDetail` entry with status `FLAGGED`.
* There are distinct flagging functions for different margin types (isolated, cross) and parties (PartyA or PartyB).
* Once flagged, the account enters a grace period in which it can recover solvency before liquidation is enforced.

#### Step 2: liquidation execution

* After the grace period, if the account is still insolvent, the Clearing House can execute the liquidation.
* On execution, the status moves from `FLAGGED` to `IN_PROGRESS`.
* The collateral price and unrealized PnL (UPNL) at liquidation time are recorded to determine accurate settlement amounts.
* Relevant cross-margin balances are zeroed out and redistributed or seized as required.

#### Step 3: cancel intents, close trades, and adjust balances

* The Clearing House finalizes balance adjustments for all affected parties.
* Some balance changes may already happen in Step 2 (for example, during cross balance resets); this step makes sure all final deltas are applied.
* The liquidated party must not keep any open intents or open trades, so the Clearing House forcibly cancels remaining intents and closes all active trades for the liquidated party. This guarantees a clean state.

#### Liquidation states

| State        | Description                                   | Next actions                                           |
| ------------ | --------------------------------------------- | ------------------------------------------------------ |
| FLAGGED      | Account flagged as insolvent                  | Execute liquidation, or unflag if recovered            |
| IN\_PROGRESS | Liquidation actively being processed          | Close trades, confiscate assets, distribute collateral |
| CANCELLED    | Flagged liquidation cancelled due to recovery | Return to normal operation                             |

### Liquidation types

#### 1. Isolated PartyB liquidation

Used when PartyB becomes insolvent in isolated margin mode, where PartyA buys an option from PartyB:

```solidity
// Flagging
flagIsolatedPartyBLiquidation(address partyB, address collateral)

// Execution
liquidateIsolatedPartyB(address partyB, address collateral, int256 upnl, uint256 collateralPrice)

// Unflagging (if Party B recovers)
unflagIsolatedPartyBLiquidation(address partyB, address collateral)
```

**Trigger conditions:**

* The total loss of open positions exceeds the loss coverage of the isolated balance.
* `isolatedBalance + (effectiveUpnl * 1e18) / collateralPrice < 0`
* where `effectiveUpnl = upnl > 0 ? upnl : (upnl * lossCoverage) / 1e18`
* This liquidation function makes no balance changes.

#### 2. Cross PartyB liquidation

Used when PartyB becomes insolvent in cross margin mode:

```solidity
// Flagging
flagCrossPartyBLiquidation(address partyB, address partyA, address collateral)

// Execution
liquidateCrossPartyB(address partyB, address partyA, address collateral, int256 upnl, uint256 collateralPrice)

// Unflagging
unflagCrossPartyBLiquidation(address partyB, address partyA, address collateral)
```

**Trigger conditions:**

* PartyB's cross loss of open trades with a specific PartyA exceeds the loss coverage of the cross balance.
* `crossBalance.balance + (effectiveUpnl * 1e18) / collateralPrice < 0`
* where `effectiveUpnl = upnl > 0 ? upnl : (upnl * lossCoverage) / 1e18`

**Liquidation process:**

* Remaining cross balance is transferred to PartyA via scheduled release.
* All cross margin entries (balance, locked, totalMM) reset to zero.
* Liquidation status advances to `IN_PROGRESS`.

#### 3. Cross PartyA liquidation

Used when PartyA becomes insolvent in cross margin mode:

```solidity
// Flagging
flagPartyALiquidation(address partyA, address partyB, address collateral)

// Execution
liquidateCrossPartyA(uint256 liquidationId, int256 upnl, uint256 collateralPrice)

// Unflagging
unflagPartyALiquidation(address partyA, address partyB, address collateral)
```

**Trigger conditions:**

* `(crossBalance.balance - totalMM) + (upnl * 1e18) / collateralPrice < 0`
* PartyA's available balance is insufficient to cover maintenance margin plus losses.

**Liquidation process:**

* Remaining cross balance is transferred to PartyB via scheduled release.
* All cross margin entries reset to zero.
* Liquidation proceeds to the position-closure phase.

### Clearing House operations

The Clearing House also has shared methods for closing, cancelling, and changing balances.

#### Trade closure during liquidation

```solidity
closeTrades(uint256 liquidationId, uint256[] memory tradeIds, uint256[] memory prices)
```

* All specified trades must belong to the liquidated parties.
* Trades are closed at liquidator-provided prices.
* Trade status changes to `LIQUIDATED`.
* Associated close intents are cancelled.

#### Asset confiscation

```solidity
confiscatePartyA(uint256 liquidationId, uint256 amount)
confiscatePartyBWithdrawal(uint256 withdrawId)
```

**PartyA confiscation:** removes a specified amount from PartyA's cross balance to cover liquidation costs and losses; requires sufficient available balance.

**PartyB withdrawal confiscation:** cancels pending PartyB withdrawals during liquidation and returns the withdrawn amount to PartyB's isolated balance, preventing capital flight during the process.

#### Collateral distribution

```solidity
distributeCollateral(
address partyB,
address collateral,
MarginType marginType,
address[] memory partyAs,
uint256[] memory amounts
)
```

* Distributes PartyB's remaining collateral among affected PartyA accounts.
* Uses the scheduled-release system for secure transfers.
* Distributes proportionally based on losses and exposure.
* Ensures the total distribution doesn't exceed the available balance.

#### Intent cancellation during liquidation

```solidity
// Open intents
cancelOpenIntents(uint256[] memory intentIds)

// Close intents
cancelCloseIntents(uint256[] memory intentIds)
```

* Only cancels intents involving insolvent parties.
* Handles fees and premium refunds appropriately.
* Expired intents go through the normal expiration flow.
* Prevents further trading by liquidated accounts.


---

# 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.symm.io/options-protocol-architecture/technical-architecture/liquidation-system.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.
