Liquidation Overview
Liquidations occur when a user’s margin requirement exceeds their total collateral. The protocol relies on permissionless liquidators (keepers) to identify and liquidate underwater positions.Liquidation Trigger
A user can be liquidated when:totalCollateral= value of all deposits and positive PnL (with haircuts)maintenanceMarginRequirement= required margin to maintain positions
User Status During Liquidation
sdk/src/types.ts
BeingLiquidated status.
Liquidation Types
Drift supports multiple liquidation types depending on the user’s state:sdk/src/types.ts
Liquidate Perp
Reduces perp positions to improve margin health:sdk/src/types.ts
- Calculate margin shortage
- Determine max position size to liquidate
- Transfer position to liquidator at oracle price
- Apply liquidation fees
- Update user margin
Liquidate Spot
Reduces spot borrows or converts deposits:sdk/src/types.ts
- Liquidator selects asset and liability markets
- Calculate transfer amounts with liquidation multiplier
- Transfer liability from user to liquidator
- Transfer asset from user to liquidator
- Apply insurance fund fee
Liquidate Borrow for Perp PnL
Uses positive perp PnL to repay spot borrows:sdk/src/types.ts
Liquidate Perp PnL for Deposit
Takes user’s deposits to cover negative perp PnL:sdk/src/types.ts
Liquidation Fees
Liquidators receive fees as incentive:Perp Liquidation Fees
liquidatorFee + ifLiquidationFee
Example: Liquidating 6 total fee
- Liquidator receives: $5
- Insurance fund receives: $1
Spot Liquidation Multipliers
Spot liquidations use liability/asset multipliers:Liquidation Amount Limits
Liquidations happen progressively, not all at once:Max Percentage to Liquidate
sdk/src/math/liquidation.ts
initialPctToLiquidate (e.g., 10%) to 100% over liquidationDuration slots (e.g., 150 slots = ~1 minute).
Progressive liquidation gives users time to add margin and prevents excessive position closure during brief volatility.
Base Asset Amount to Cover Shortage
sdk/src/math/liquidation.ts
undefined (liquidate all).
Bankruptcy
When a user’s collateral is insufficient even after full liquidation, bankruptcy procedures activate.Perp Bankruptcy
sdk/src/types.ts
- Calculate remaining negative PnL
- Insurance fund covers what it can
- Remaining loss is socialized via funding rate adjustment
- If applicable, clawback from recent profitable traders
Spot Bankruptcy
sdk/src/types.ts
- Calculate remaining borrow after liquidating all deposits
- Insurance fund covers what it can
- Remaining loss is socialized to depositors via cumulative deposit interest adjustment
Liquidation Record
Each liquidation emits a comprehensive record:sdk/src/types.ts
Liquidation Margin Freed
Tracks how much margin has been freed through liquidations:- If
liquidationMarginFreed > 0, liquidation is in progress - Slots since
lastActiveSlotdetermine current max liquidation percentage - Resets to 0 when user is healthy again
Order Cancellation During Liquidation
When liquidation begins:- All risk-increasing orders are cancelled
- Reduce-only orders may remain
- Order IDs are recorded in
canceledOrderIds - Users cannot place new risk-increasing orders
Isolated Position Liquidation
Isolated positions are liquidated independently:- Check isolated position margin independently
- Liquidate only the isolated position if underwater
- Use only isolated collateral
- Cross-margin positions remain unaffected
- If isolated collateral insufficient, bankruptcy on isolated position only
Isolated positions protect your main account from high-risk trades. Only the isolated collateral is at risk.
Liquidation Bit Flags
sdk/src/types.ts
Insurance Fund
The insurance fund backs the protocol against insolvency:- Receives portion of liquidation fees
- Covers bankruptcy losses before socialization
- Per-market insurance funds for spot markets
- Shared perp insurance fund
Insurance Fund Structure
Liquidator Incentives
Liquidators are incentivized through:- Liquidation fees: Direct fee on liquidated amount
- Price improvement: Acquire positions below market price
- Insurance fund fees: Additional fee to IF
- User has 10 SOL short at 50
- Liquidator takes over the short position
- Liquidator pays: 10 * 994
- User receives: 1000 position
- Liquidator profit: $6 (plus any favorable position movement)
- IF receives: $1
Preventing Liquidation
Users can avoid liquidation by:- Adding collateral: Deposit more funds
- Reducing positions: Close or reduce losing positions
- Settling PnL: Settle positive unrealized PnL
- Repaying borrows: Reduce spot liabilities
- Cancelling orders: Free up margin from open orders
Monitor your margin ratio regularly. Set up alerts when approaching maintenance margin threshold.
Next Steps
Margin System
Understand margin requirements in detail
Positions
Learn about position management
Markets
Review market-specific liquidation parameters
Keeper Bots
Build a liquidator bot