🌊Liquidations
Liquidations are an essential part of the platform's risk management system. They occur when a position's collateral falls below the required maintenance margin. This document outlines the process of checking for and executing liquidations.
Checking Liquidatable Positions
To determine if a position is liquidatable, you can call the checkIsLiquidatable
function in the Execution
library:
solidity
This function calculates whether a position's remaining collateral (after accounting for PnL, borrowing fees, and funding fees) is less than the required maintenance collateral.
Parameters:
address _tradeStorage: The address of the trade storage smart contract.
address _market: The address of the market smart contract
bytes32 _marketId: The ID of the market where the position exists.
bytes32 _positionKey: The key of the open position.
uint256 _indexPrice: The current index price to 30 decimal places. E.g $2500 = 2.5e33.
uint256 _indexBaseUnit: The base units of the index asset. Usually just 18.
Returns:
bool isLiquidatable: True if the position can be liquidated, false otherwise.
Executing a Liquidation
Executing a liquidation is a two-step process:
Step 1: Request Execution Pricing
Before liquidating a position, you must first call the requestExecutionPricing
function on the Router
smart contract:
solidity
Parameters:
MarketId _id: The ID of the market where the position exists.
bytes32 _key: The position key of the position to be liquidated.
bool _isPositionKey: Should be set to true for liquidations.
Returns:
bytes32 priceRequestKey: A unique key for the price update request.
Note: This function is payable and requires a fee to cover the cost of the price update. Ensure you send enough ETH to cover the priceUpdateFee.
Step 2: Liquidate the Position
After requesting the execution pricing and waiting for a price to be signed, you can proceed to liquidate the position by calling the liquidatePosition
function on the PositionManager
contract:
solidity
Parameters:
MarketId _id: The ID of the market where the position is being liquidated.
bytes32 _positionKey: The position key of the position to be liquidated.
bytes32 _requestKey: The price request key returned from the requestExecutionPricing function.
Important Notes:
Only the person who requested the pricing for an order should be able to initiate the liquidation, up until a certain time buffer.
After that time buffer, any user should be able to initiate the liquidation.
Tracking Open Positions
To efficiently monitor positions that may be approaching liquidation, you can use a subgraph to track open positions. This allows for real-time monitoring and quick identification of positions that may need to be liquidated. By following these steps and utilizing the provided functions, you can effectively manage and execute liquidations on the platform.
Last updated