SIP-2005: Perps V2 - Slippage protection for liquidations

Author
StatusImplemented
TypeGovernance
NetworkOptimism
ImplementorTBD
ReleaseTBD
ProposalLoading status...
Created2022-01-17

Simple Summary

This SIP proposes to incorporate slippage guards on liquidation transactions. This is done by splitting up the liquidation process into two components:

  • Flagging, where accounts flagged cannot interact with their positions until liquidation is enacted
  • Liquidation, where the liquidation is incorporated into the protocol via spontaneous liquidation or forced liquidation.

Abstract

The proposed liquidation mechanism can be broken down to the following:

  • Flagging: An account is eligible for flagging as per the _canLiquidate function. Keepers can trigger a flag which results in the position being staged for liquidation, at this point the account cannot interact with his position until liquidation is finalized and any pending exchange order is removed.

  • Spontaneous Liquidation can occur based on the following conditions:

  1. The account is flagged
  2. The price impact of the liquidation is below a maxLiquidationDelta
  3. The prevailing premium or discount of the market is below maxPD
  • Forced Liquidation can be performed by endorsed accounts. The protocol can endorse certain addresses, which allows them to force a liquidation and bypass both the maxLiquidationDelta and maxPD checks. It is important to mention that the vast majority of liquidated accounts are expected to be liquidated spontaneously , but for the sake of expedient rollout of perpetuals and as a initial safety precaution, liquidator endorsement would be used. In future perp iterations, a more decentralized solution that does not depend on account endorsement would be incorporated into the liquidation process.

Motivation

Liquidation of large positions creates an opportunity for traders to position themselves ahead of a liquidation and potentially profit from the resulting price impact. This SIP proposes measures to prevent opportunistic ordering of transactions surrounding liquidations.

Specification

The specification includes the following sections:

  • Flagging
  • Spontaneous Liquidation
  • Forced Liquidation

Flagging

An account who's remaining margin falls below his liquidation margin can be flagged. The flagger receives a sUSD reward, for triggering the flag:

$$ min( max(P * S * liquidationFeeRatio;minKeeperFee);maxKeeperFee) $$

Where the variables are defined as follows:

  • P is the oracle price
  • S is the size of the position being flagged
  • minKeeperFee is configurable via SCCP (currently 2 sUSD)
  • maxKeeperFee is configurable via SCCP (set to 1,000 sUSD)

A flagged account would not be able to interact with his position until liquidation is enacted (by spontaneous liquidation or forced liquidation). A flagged account is cleared of any pending exchange order.

Spontaneous Liquidation

Flagged accounts can be spontaneously liquidated, if the below two conditions are met

  1. The price impact of a liquidation is below a maxLiquidationDelta:

$$ \frac{|S|}{skewScale} < maxLiquidationDelta $$

  1. The instantaneous premium or discount is below maxPD:

$$ \frac{|skew|}{skewScale} < maxPD $$

Few things to note:

  • Upon successful liquidation, the keeper that triggers the transaction receives a sUSD configurable keeperLiquidationFee. The position is closed and the user can interact with the market by depositing sUSD and opening a new position.
  • keeperLiquidationFee is general variable agnostic to the market
  • maxLiquidationDelta and maxPD are both configurable variables per market.

Forced Liquidation

Endorsing Addresses

The protocol can add or remove addresses to the list of endorsed liquidators, via addEndorsedLiquidator and removeEndorsedLiquidator functions.

Forced Liquidation Logic

Liquidation can be triggered regardless of existing liquidation protection on flagged accounts. Liquidation would close the position and allows the user to interact with a given market. Endorsed keepers would incorporate off-chain logic to prevent execution of liquidations for market skew outliers. This allows for MEV-resistant liquidations while purely on-chain logic is developed further.

Technical Specification

Pending SC engineers input.

Test Cases

  • Setting the oracle price at a price where account A is not open for flagging
    • When a random account attempts to flag account A
      • ❌ Then transaction reverts, due to the account not being open for flagging
  • Setting the oracle price at a liquidation price of account A with an open position
    • When a random account attempts to flag account A, who's position isn't already flagged
      • ✅ Then the transaction succeeds and the flagger receives a liquidation reward
    • When a random account attempts to flag account A, who's position isn't already flagged and account A has a pending order
      • ✅ Then the transaction succeeds and the flagger receives a liquidation reward and pending orders are cancelled
    • When a random account attempts to flag account A, who's position is already flagged
      • ❌ Then transaction reverts, due to the account already being flagged
  • Setting Account A as flagged for liquidation:
    • When the price of liquidating A exceeds maxLiquidationDelta
      • When a random account attempts to liquidate account A
        • ❌ Then transaction reverts, due to the maxLiquidationDelta being exceeded
      • When a endorsed account attempts to liquidate account A
        • ✅ Then the transaction succeeds account A's position is closed, the liquidator receives no reward and the flag is removed
    • When the price impact of the liquidating A is below maxLiquidationDelta
      • When a random account attempts to liquidate account A
        • ✅ Then the transaction succeeds and the liquidator receives keeperLiquidationFee as a reward, account A's position is closed and the flag is removed
      • When a endorsed account attempts to liquidate account A
        • ✅ Then the transaction succeeds and the liquidator receives no reward, account A's position is closed and the flag is removed
    • When the price impact of the liquidating account A below maxLiquidationDelta and the price recovered that the account is no longer flaggable
      • When a random account attempts to liquidate account A
        • ✅ Then the transaction succeeds and the liquidator receives keeperLiquidationFee as a reward, account A's position is closed and the flag is removed
    • When the instantaneous PD is above maxPD
      • When a random account attempts to liquidate account A
        • ❌ Then transaction reverts, due to the maxPD being exceeded
      • When a endorsed account attempts to liquidate account A
        • ✅ Then the transaction succeeds account A's position is closed, the liquidator receives no reward and the flag is removed
    • When the instantaneous PD is below maxPD
      • When a random account attempts to liquidate account A
        • ✅ Then the transaction succeeds and the liquidator receives keeperLiquidationFee as a reward, account A's position is closed and the flag is removed
      • When a endorsed account attempts to liquidate account A
        • ✅ Then the transaction succeeds account A's position is closed, the liquidator receives no reward and the flag is removed
    • When the instantaneous PD is below maxPD and the price recovered that Account A is no longer flaggable
      • When a random account attempts to liquidate account A
        • ✅ Then the transaction succeeds and the liquidator receives keeperLiquidationFee as a reward, account A's position is closed and the flag is removed
    • When account A attempts to deposit sUSD into his position
      • ❌ Then transaction reverts, as the account is flagged for liquidation
    • When account A attempts to close his position
      • ❌ Then transaction reverts, as the account is flagged for liquidation
    • When account A attempts to increase his position
      • ❌ Then transaction reverts, as the account is flagged for liquidation
    • When account A attempts to decrease his position
      • ❌ Then transaction reverts, as the account is flagged for liquidation

Configurable Values (Via SCCP)

  • maxLiquidationDelta is the maximum delta beyound which spontaneous liquidation cannot occur
  • maxPD is the maximum market premium/discount beyound which spontaneous liquidation cannot occur
  • keeperLiquidationFee is the fee to a liquidator for triggering a spontaneous liquidation
  • endorsed liquidator addresses require an sccp

Copyright and related rights waived via CC0.