Skip to main content

Margin & Leverage

Leverage Bounds

Every position must satisfy the maximum leverage constraint.

Maximum Leverage

notional×margincol×SCALAR_7\text{notional} \times \text{margin} \leq \text{col} \times \text{SCALAR\_7}

Equivalently: leverage <= 1 / margin. With margin expressed as a SCALAR_7 fraction, the maximum allowed position size is col / margin. A margin of 100_000 (1%) caps leverage at 100x; halving margin doubles the cap.

Initial Margin vs Liquidation Threshold

PropertyInitial MarginLiquidation Threshold
RateConfigurable per marketConfigurable per market
SourceMarketConfig.marginMarketConfig.liq_fee
Enforced atOpen, modify collateralLiquidation check
Max value50% (MAX_MARGIN)25% (MAX_LIQ_FEE)
PurposeBuffer between opening and liquidationEquity below this triggers liquidation

The validation rule margin > liq_fee ensures there is always a gap between the opening margin requirement and the liquidation threshold. This gap is the safety buffer that absorbs PnL and fee accrual before liquidation triggers.

Collateral Modification

When withdrawing collateral from a filled position, an additional margin check is applied:

equity=new_col+pnltotal_fee\text{equity} = \text{new\_col} + \text{pnl} - \text{total\_fee} equitynotional×marginSCALAR_7\text{equity} \geq \text{notional} \times \frac{\text{margin}}{\text{SCALAR\_7}}

Where total_fee includes accrued funding and borrowing at current indices. If this check fails, the withdrawal is rejected with WithdrawalBreaksMargin. This prevents users from extracting collateral to the point where their position becomes immediately liquidatable.

Collateral withdrawal uses the initial margin requirement (margin), not the liquidation threshold (liq_fee). This provides an extra buffer. A user cannot withdraw collateral down to the liquidation threshold level.