Position Equity
Two Margin Levels
Every position has two thresholds that create a buffer zone between opening and liquidation.
The protocol enforces
imFactorBps > mmFactorBps — any attempt to violate this reverts. This gap creates the buffer: equity starts above IM and must erode through the buffer before liquidation.
Variable Leverage
Traders choose their own margin within[minIM, notional]. More margin means lower leverage and a larger liquidation buffer.
Isolated Margin
Each position’s margin is completely independent:- A loss on Position A does not affect Position B
- Maximum loss per position is capped at that position’s locked margin
- Free collateral in your account is never at risk from open positions
- Liquidation of one position does not affect others
Isolated vs cross margin
Isolated vs cross margin
In a cross-margin system, all positions share a common margin pool. A loss on one position can drain margin from others, and the entire account balance is at risk.The protocol defines a
MarginMode enum with ISOLATED (0) and CROSS (1) values, but only isolated margin is implemented in M2. The isolated model provides clearer risk boundaries and prevents cascading failures.Margin Operations
Add Margin
Increases locked margin, reducing leverage and increasing the liquidation buffer.
- Allowed at any time, even when liquidatable (rescue mechanism)
- Total locked margin cannot exceed notional
- Amount transfers from free collateral
Remove Margin
Decreases locked margin, increasing leverage and freeing collateral.
- Not allowed when liquidatable
- Remaining margin must stay above minIM
- Equity after removal must stay above MM threshold
Snapshotted Rates
When a position is opened, margin configuration parameters are snapshotted and stored with the position:
Admin configuration changes only affect newly opened positions. Existing positions retain the parameters they were opened with — no admin action can retroactively move the liquidation threshold.
Worked Example
Full margin lifecycle
Full margin lifecycle
Setup:Add 25 USDC margin:Price recovers, PnL now +15 USDC:Remove 30 USDC margin:
- Notional: 1,000 USDC
- Margin deposited: 50 USDC (5%, 20x leverage)
- Minimum IM: 20 USDC (2%)
- MM threshold: 10 USDC (1%)
What happens if PnL loss exceeds locked margin?
What happens if PnL loss exceeds locked margin?
When a position’s market PnL loss exceeds its locked margin (
|marketPnl| > imLocked), the excess becomes bad debt. The trader’s realized loss is capped at imLocked, and the remaining loss is absorbed by pool equity. A BadDebt event is emitted for monitoring. The pool equity floor is clamped to zero — it cannot go negative.Account Equity
Beyond individual positions, the protocol tracks aggregate account equity:aggregateUnrealizedPnL sums unrealized PnL across all open positions. Available via the subgraph for informational purposes.