Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Margin

1. Overview

All trader margin is held internally in the perps contract as a USD value on each user’s userState.

Internal logics of the perps contract use USD amounts exclusively. Token conversion only happens at two boundaries:

  • Deposit — the user sends settlement currency (USDC) to the perps contract; the oracle price converts the token amount to USD and credits userState.margin.
  • Withdraw — the user requests a USD amount; the oracle price converts it to settlement currency tokens (floor-rounded) and transfers them out.

2. Trader Deposit

The user sends settlement currency as attached funds. The perps contract:

  1. Values the settlement currency at a fixed **\mathtt{depositValue} = \mathtt{amount} \times 1\mathtt{depositValue}$.

The tokens remain in the perps contract’s bank balance.

3. Trader Withdraw

The user specifies how much USD margin to withdraw. The perps contract:

  1. Computes $\mathtt{availableMargin}$ (see §8), clamped to zero.
  2. Ensures the requested amount does not exceed $\mathtt{availableMargin}1 rate (floor-rounded to base units).
  3. Transfers the tokens to the user.

4. Equity

A user’s equity (net account value) is:

where is the USD value of the user’s deposited margin (userState.margin).

Per-position unrealised PnL is:

and accrued funding is:

Positive accrued funding is a cost to the trader (subtracted from equity). Refer to Funding for details on the funding rate.

5. Initial margin (IM)

where is the per-pair initial margin ratio. IM is the minimum equity required to open or hold positions. It is used in two places:

  • Pre-match margin check — verifies the taker can afford the worst-case 100 % fill (see Order matching §5).
  • Available margin calculation — determines how much can be withdrawn or committed to new limit orders (see §8 below).

When checking a new order the IM is computed with a projected size: the user’s current position in that pair is replaced by the hypothetical post-fill position (). Positions in other pairs use their actual sizes.

6. Maintenance margin (MM)

where is the per-pair maintenance margin ratio (always ). A user becomes eligible for liquidation when:

See Liquidation for details.

7. Reserved margin

When a GTC limit order is placed, margin is reserved for the worst-case scenario (the entire order is opening):

The user’s total is the sum across all resting orders. Reserved margin is released proportionally as orders fill and fully released on cancellation. Reduce-only orders reserve zero margin (they can only close).

See Order matching §10 for when reservation occurs.

8. Available margin

where is the IM of current positions (§5 formula applied to actual sizes, without any projection). This determines how much can be withdrawn (§3) or committed to new limit orders.