Skip to main content
This page compiles every formula referenced elsewhere in the docs, sourced directly from the deployed contracts. All prices and USD amounts are 18-decimal fixed point unless noted. All Bps values are out of 10,000 (e.g. 50 bps = 0.5%).

Pre-trade checks (RiskEngine)

Leverage bounds:
Implemented without division, as: sizeUsd >= collateralAmount * minLeverage and collateralAmount * maxLeverage >= sizeUsd. Initial margin:
This is checked independently of the leverage bounds above, both must pass. Open interest cap (checked per side, long and short tracked separately):

PnL, margin ratio, and liquidation (RiskEngine)

Unrealized PnL:
Effective collateral:
Margin ratio:
Maintenance margin:
Liquidation trigger:
Liquidation price (isolated):
See Positions & Margin and PnL & Liquidation for the walkthroughs behind these.

Cross-margin liquidation (RiskEngine)

Account-level check, across every open cross position for one collateral token:
The caller-supplied position set must exactly match the trader’s actual open cross-position count for that token, or the check reverts, this prevents omitting a healthy position to bias the result. Cross liquidation price for one position (snapshot-based, holds every other position’s PnL fixed at its current mark price):
This number is only valid until another position in the same cross book moves, it’s a point-in-time estimate, not a standing guarantee. See Margin Modes.

Funding (FundingManager)

Funding owed by a position:
Positive means the position owes funding. See Funding Rate.

Fees (FeeCollector)

Trading fee:
feeBps is takerFeeBps for market orders, makerFeeBps for limit orders. Liquidation fee:
Fee distribution split:
See Fees.

Liquidation settlement (Liquidator)

That value is split against the keeper fee three ways:
See Liquidation Engine.

Slippage (Matcher, off-chain)

See Slippage & Execution.

Points (PointsSystem)

tradePointsEarned accrues on both opening and closing a position, each counted separately. See Points & Referrals.