Search
K

Liquidation Engine

Managing trading risks through timely liquidations
Carbon has an on-chain liquidation mechanism to liquidate derivatives positions that are at risk of going brankrupt (i.e. become insolvent). This ensures that their profitable counterparties receive the appropriate payouts.
During liquidation, the Liquidation Engine takes over the liquidated position to close it at the best possible price on the open market.
Additionally, Carbon utilizes an Insurance Fund to prevent system losses, as well as an Auto-Deleveraging (ADL) System to maintain market continuity even in black swan events. When a position is closed at a favorable price, the surplus funds are transferred to the on-chain Insurance Fund. Conversely, if the position is closed at a loss, the Insurance Fund is first used to absorb the losses.
If the Insurance Fund is insufficient to manage the deficit, the ADL system takes over, deleveraging opposing positions in order of profit and leverage, socializing losses among the most profitable traders. This means that positions that are the most profitable and have a high level of leverage will be the first to undergo deleveraging.

Liquidation

When a position’s allocated margin is less than its required maintenance margin, the position is deemed to be at risk of bankruptcy and therefore liable for liquidation.
The required maintenance margin of a linear futures position is given by:
MaintenanceMargin=MaintenanceMarginRatio[InitialMarginBase+(floor(RiskStepSize/PositionSize)InitialMarginStep)]Maintenance Margin = Maintenance Margin Ratio * [Initial Margin Base + (floor(Risk Step Size / Position Size) * Initial Margin Step)]
The above parameters are specific to each market and are automatically defined when a futures (perpetuals) market is created; You can check out an example of this on Carbonscan here.
Accounts with administrative privileges can adjust these parameters as well.

Liquidators

Liquidators are external actors that monitor the level of liquidation risk associated with each position. They broadcast liquidation messages to notify the chain when a risky position needs to be liquidated.
It's important to note that a position can only be liquidated when a liquidation message containing the position ID (MsgInitiateLiquidation) is broadcasted by a liquidator.
The Carbon node binary includes a liquidator service that can be executed by anyone with a Carbon account. While there are no existing incentives for submitting liquidation transactions, it only takes one liquidator to submit a transaction, and the Carbon core dev team is currently operating at least one such liquidator.

Liquidation Engine

When a valid liquidation message is received, existing orders that might increase the size of the risky position is first cancelled.

Partial Liquidation

Since margin requirements increase as position size grows (due to the RiskStepSize market parameter, as described earlier), to lower the margin requirements of larger positions, they may be partially liquidated to reduce their risk.
The minimum quantity of the position that needs to be reduced such that the it meets the maintenance margin requirements is first calculated.
The liquidation engine then attempts to reduce the position's risk by submitting a Fill-or-Kill order at the position’s bankruptcy price for the calculated quantity. If there is insufficient liquidity on the order book to execute this order fully, a full liquidation will occur, as the position would remain at risk otherwise.

Liquidation Procedure

When a liquidated position is taken over by the on-chain liquidation engine, any remaining margin within that position is transferred to the liquidation engine.
The position is then disposed of by the liquidation engine in amalgamated blocks of liquidation orders.
The liquidation engine's maximum order size is defined by MaxLiquidationOrderTicket. To reduce the impact on the market's Mark Price, larger positions are split up into multiple orders.
Each liquidation order is first quoted at the bankruptcy price of the position, which is the closing price that renders the amalgamated position to be worth $0.
Any profits earned, due to existing orders on the order book matching the liquidation order at a price more favourable than the bankruptcy price, is transferred to the Insurance Fund.
If the liquidation order does not fill immediately, the order is aggressed every 5 seconds by making the order price progressively worse (such that it is more attractive to fill). Any shortfall caused by the unfavourable closing price is covered by the Insurance Fund.
In the event that the liquidation order remains unfilled on the order book for a certain duration, which is defined by MaxLiquidationOrderDuration, auto-deleveraging will be initiated to force the closure of the liquidation engine’s outstanding position.
The above parameters are specific to each market and are automatically defined when a futures (perpetuals) market is created; You can check out an example of this on Carbonscan here.
Accounts with administrative privileges can adjust these parameters as well.

Insurance Fund

The insurance fund is shared by all markets.
The address of the insurance fund can be found here.
In the future, Carbon plans to allow users to directly contribute to the insurance fund to increase its size and avoid ADL. In return, contributors will be able to earn a yield on their contribution when the fund exceeds a particular target threshold.

Auto-Deleveraging (ADL) System

Carbon uses an Auto-Deleveraging (ADL) system as its margining approach for derivative instruments, as an evolution to the “Socialised Loss” system.
The Socialised Loss system has some drawbacks:
  • A single risky trader can cause significant losses for all traders, including low-risk ones;
  • Profits must be locked until rebalancing or settlement occurs, in case of a loss.
The ADL system addresses these issues by resolving loss uncertainty, allowing traders to make timely decisions when a deleveraging event occurs, instead of having to wait for rebalancing or settlement to occur.

Deleveraging Process

In the event that (i) liquidation orders cannot be filled in a timely manner, or (ii) there are insufficient funds in Insurance Fund to cover the shortfall, the ADL system will start to deleverage opposing positions in order of profit and leverage, socializing losses among only the most profitable positions.
The positions with the highest profit and leverage are closed out first (in order of ranking) until the initially liquidated position is fully closed. The price at which a profitable positions are closed out is the bankruptcy price of the liquidation order.

Priority Ranking Calculation

The priority for deleveraging is determined by the profit earned and leverage set by traders, where those who are more profitable and have higher leverage are deleveraged first
The ranking calculation is as follows:
Ranking = PNL Percentage * Effective Leverage (if PNL percentage > 0)
= PNL Percentage / Effective Leverage (if PNL percentage < 0)
where
Effective Leverage = abs(Mark Value) / (Mark Value - Bankrupt Value)
PNL percentage = (Mark Value - Avg Entry Value) / abs(Avg Entry Value)
Mark Value = Position Value at Mark Price
Bankrupt Value = Position Value at Bankruptcy Price
Avg Entry Value = Position Value at Average Entry Price
The system splits the positions into longs and shorts and arranges them in descending order of rank (i.e. from highest to lowest), such that positions with higher ranks are deleveraged first.

Example

Suppose there are six long positions in the system, and their effective leveraged PnL score has been calculated. Note that a higher PnL Ranking corresponds to a higher effective leveraged PnL.
Position
Quantity
PNL Ranking
1
10
3
2
10
6
3
20
1
4
30
4
5
20
5
6
10
2
The system then rank these positions based on their scores, from highest score to lowest score:
Position
Quantity
PNL Ranking
2
10
6
5
20
5
4
30
4
1
10
3
6
10
2
3
20
1
In the case of a liquidation, the system will prioritize deleveraging the higher ranked positions first.
Let’s consider a short position that has been liquidated with a size of 20 and a bankruptcy price of $650. In this case, Positions 2 and 5 will be deleveraged at the bankruptcy price of $650.
Position 2 will have its entire position of 10 contracts closed, while the remaining 10 contracts from the liquidated short position will be assigned to Position 5.
As a result, Position 5 will have 10 contracts remaining out of its original 20 contracts.