Exchange Liquidations: Architecture and Design Choices
Hey guys, it’s Tripathi, A security researcher and builder trying to make decentralized finance better.
We’ve seen multiple metas in the crypto over the years, whether it’s lending and borrowing, NFTs, AMM-based exchanges, liquid stakings, RWAs, Meme coins or the Solana universe. Every meta comes with its own community and innovation cycle, but onchain CLOB exchanges seem like one of the most efficient metas, having onboarded a significant number of new Traditional Finances people onchain. The rise of Hyperliquid has been marvelous, and we are already seeing the trend of increasing market share of DEXes. I’ve been trading, building, and auditing exchanges for a couple of months, and it’s been an amazing experience. Whether it’s CEX or DEX, the way exchanges handle risk parameters is always a fascinating topic to discuss.
Introduction
In this article, we’ll explore liquidation architecture and engine design, which can help you to understand liquidation better whether you are a trader, auditor or protocol designer. If you’ve been in crypto for even a month, you’ve probably seen conversations about large liquidations, ADL drama, socialized losses, or bankruptcy events in CT.
For newcomers, every trade you do, whether it’s borrowing, long, short, delta neutral, basis trading, or market making requires collateral. You give permissions to the exchange or other parties to seize the collateral if the required margin is not enough to cover the loss.
While each exchange implements liquidation slightly differently, the general architecture remains consistent,they use their Orderbook liquidity and dedicated market makers/vaults to handle liquidations. In liquidity crisis, this escalates into cross-exchange/chain liquidity, ADL, or Socialized losses/Bad debt situations. Ideally, as DEXes mature more and more, we hope to see cross-exchange margining and shared orderbooks.
The liquidation engine identify unhealthy accounts and exit from positions before they create bad debt for the exchange.
From a large set of accounts, how do find unhealthy accounts? Iterating over nearly half a million accounts and checking would be too naive and inefficient. Every optimization in liquidation creates value for both the exchange and users. Account’s health is directly linked with index/mark price changes so system must be able to find set of unhealthy accounts and execute the liquidation process before next mark price update.The concept of unhealthy accounts comes from minimum maintenance margin, if an account’s balance becomes less than the minimum maintenance margin, the account is considered unhealthy and liquidation is triggered.
Points to consider when analyzing Liquidation Architecture and Engine design
From a User Perspective
How do exchanges decide the order of accounts to liquidate?
If an account of bigger size gets liquidated before yours, the book might get thinner and you might get bad fill.
Which positions are prioritised for liquidation?
Suppose you hold multiple positions across different instruments,which one gets liquidated first? Whether the ordering is more favorable to your health or more inclined towards derisking the exchange.
When does ADL/Socialized losses kick in for profitable traders?
As a profitable trader, under what conditions can your position be force-reduced due to other users’ bad debt?
What are the liquidation fees.
Can you set a stop-loss just before liquidation to avoid high liquidation fees?
How do exchanges calculate initial margin and the IM-MM gap used in reduce-only mode?
What type of orders can you make during this reduce-only mode?
If exchanges support hedge mode, how is liquidation handled in this mode?
How do funding payments contribute to liquidations? is it continuous or hourly/weekly?
How do exchanges calculate mark price, and how hard is it to manipulate mark price?
From Exchange Perspective
How to keep mark price fair and how to redistribute weight on other exchange prices with the varying liquidity across exchanges?
How much slippage is acceptable during book liquidation, before routing to liquidator vault or insurance fund?
How to handle a resting orders which is gonna make an account unhealthy but can’t cancel since it’s not in reduce only mode?
What are the alternatives of backstop liquidation?
Can your exchange merge RFQ model in liquidation flow?
How to make a tradeoff between backstopping and triggering ADL?
Binance ADL ranking is cool but what improvement can be done there?
similarly Bybit had done niche work in hedge mode, can we improve that?
Enough for day, will come back with new interesting topic:)
