Aftermath
  • Aftermath
    • About Aftermath Finance
      • What are we building?
  • Getting Started
    • Creating an account
      • zkLogin
        • Removing a zkLogin account
      • Sui Metamask Snap
      • Native Sui wallets
    • Dynamic Gas
    • Navigating Aftermath
      • Interacting with your Wallet
      • Viewing your Portfolio
      • Changing your Settings
      • Bridge
      • Referrals
  • Trade
    • Smart-Order Router
      • Agg of Aggs
      • Making a trade
      • Exact Out
      • Fees
    • DCA
      • Why should I use DCA
      • How does DCA work
      • Tutorials
        • Creating a DCA order
        • Monitoring DCA progress
        • Advanced Features
      • Fees
      • Contracts
  • Limit Orders
    • Contracts
    • Fees
  • Pools
    • Constant Function Market Maker
      • Tutorials
        • Depositing
        • Withdrawing
        • Creating a Pool
      • Fees
      • Contracts
      • Audit
  • Farms
    • Afterburner Vaults
      • Tutorials
        • Staking into a Farm
        • Claiming Rewards
        • Unstaking
        • Creating a Farm
      • Architecture
        • Vault
        • Stake Position
      • Fees
      • FAQs
  • Liquid Staking
    • afSUI
      • Tutorials
        • Staking
        • Unstaking
      • Architecture
        • Packages & Modules
        • Entry Points
      • Fees
      • FAQs
      • Contracts
      • Audit
  • Perpetuals
    • Aftermath Perpetuals
      • Tutorials
        • Creating an Account
        • Selecting a Market
        • Creating a Market Order
        • Creating a Limit Order
        • Maintaining your Positions
      • Architecture
        • Oracle Prices
        • Margin
        • Account
        • Trading
        • Funding
        • Liquidations
        • Fees
  • GameFi
    • NFT AMM
      • Architecture
        • Fission Vaults
        • AMM Pools
      • Tutorials
        • Buy
        • Sell
        • Deposit
        • Withdraw
      • Sui Overflow
  • Our validator
    • About us
  • Developers
    • Aftermath TS SDK
      • Utils
        • Coin
        • Users Data
        • Authorization
      • Products
        • Prices
        • Router
        • DCA
        • Limit Orders
        • Liquid Staking
        • Pools
        • Farms
    • Aftermath REST API
  • Egg
    • About Egg
  • Legal
    • Terms of Service
    • Privacy Policy
  • Languages
    • 中文
    • 한국어
  • Links
    • X
    • Telegram
    • Discord
    • Github
    • Medium
    • Aftermath Validator
Powered by GitBook
On this page
  • Mark Price
  • Insurance Fund
  • Socialized Losses
  1. Perpetuals
  2. Aftermath Perpetuals
  3. Architecture

Liquidations

PreviousFundingNextFees

Last updated 6 months ago

A position may cross the maintenance margin requirements threshold due to two different reasons:

  • Index prices move causing the unrealized PnL of the account to eat at its margin

  • The account continually pays funding due to holding positions that contribute to price divergence

Note that withdrawing collateral and placing orders are not in the list due to the margin requirements checks which would stop both the operations.

When a position is below its maintenance margin requirements level, anyone can acquire such position at mark price. A constraint applied to liquidators is that they can only acquire just the part of the position necessary to bring it back above its initial margin requirments. This means that liquidations are generally partial, except when the liquidatee's margin is negative (i.e., the position has bad debt).

Another constraint is that a liquidator must have enough collateral by the end of the transaction to be above its own initial margin requirements after acquiring the position. In other words, liquidation is just like placing an order, except that the liquidator directly buys from the liquidatee at mark price. For this reason, the liquidator can choose to immediately market sell the acquired position, collecting a fee for the service.

Mark Price

The price at which the liquidator acquires a position is different from the index price used to compute the position's margin ratio. The mark price is calculated as follows:\

MarkPrice=median(BookPrice,FundingPrice,TwapPrice)FundingPrice=IndexPrice+TWA1m,1h(BookPrice−IndexPrice)⋅Time to next FundingFunding PeriodTwapPrice=IndexPrice+TWA5s,5m(BookPrice−IndexPrice){\small \begin{align*} \small & MarkPrice = median(BookPrice, FundingPrice, TwapPrice) \\ &FundingPrice = IndexPrice + \text{TWA}_{1m,1h}(BookPrice - IndexPrice) \cdot \frac{\text{Time to next Funding}}{ \text{Funding Period}} \\ &TwapPrice = IndexPrice + \text{TWA}_{5s,5m}(BookPrice - IndexPrice) \end{align*} }%​MarkPrice=median(BookPrice,FundingPrice,TwapPrice)FundingPrice=IndexPrice+TWA1m,1h​(BookPrice−IndexPrice)⋅Funding PeriodTime to next Funding​TwapPrice=IndexPrice+TWA5s,5m​(BookPrice−IndexPrice)​

See the chapter for the definition of TWAs.

Insurance Fund

A part of the fees collected during liquidations is destined to the market's insurance fund. Each market has its own insurance fund, avoiding the risk of volatile markets emptying other insurance funds, and can specify the insurance fund fee rate. The insurance fund is automatically used by the protocol to fully repay a position's bad debt in case of an untimely liquidation.

Socialized Losses

In case the insurance fund is not able to fully repay a position's bad debt, a mechanism to socialize losses is triggered. In particular, the bad debt amount is added to the funding rates in the opposite side of the liquidation, in order to incentivize traders to close their in-profit positions and stabilize the market as soon as possible.

Funding