Skip to main content
Kimia uses a cross-margin model per market: one UserAccount holds one position and the collateral that backs it. Free collateral is shared between the open position and any resting orders.

Margin types

TypeWhen checkedDefault
Initial marginOpening or increasing a position, and on withdrawal1000 bps (10%)
Maintenance marginEvery time a margin sensor runs (liquidation check)500 bps (5%)
Reserved marginAt place_order placement (resting orders)Locks notional × initial_margin_ratio

Formulas

notional=base_amount×priceBASE_PRECISION\text{notional} = \frac{|\text{base\_amount}| \times \text{price}}{\text{BASE\_PRECISION}} initial_req=notional×initial_margin_ratio10,000\text{initial\_req} = \frac{\text{notional} \times \text{initial\_margin\_ratio}}{10{,}000} maint_req=notional×maintenance_margin_ratio10,000\text{maint\_req} = \frac{\text{notional} \times \text{maintenance\_margin\_ratio}}{10{,}000} free_collateral=collateraltotal_reserved_margin\text{free\_collateral} = \text{collateral} - \text{total\_reserved\_margin} health=free_collateral+unrealized_pnlmaint_req\text{health} = \text{free\_collateral} + \text{unrealized\_pnl} - \text{maint\_req} Liquidation triggers when health0\text{health} \leq 0.

Why reserved margin?

Without reservation, an attacker could:
  1. Deposit 100 USDC.
  2. Place 10 resting limit orders, each of which individually passes the initial-margin check.
  3. Wait for adverse fills, and end up with a position whose required margin exceeds their deposit.
Reserving margin at placement ties each order to real, untouched collateral.

Max leverage

max_leverage=10,000initial_margin_ratio\text{max\_leverage} = \frac{10{,}000}{\text{initial\_margin\_ratio}} With V1’s 1000 bps ratio, that’s 10×.

Liquidation price

Given an open position, the liquidation price is where health hits 0: Long: liq_price=entrycollateralmaint_reqbase\text{liq\_price} = \text{entry} - \frac{\text{collateral} - \text{maint\_req}}{|\text{base}|} Short: liq_price=entry+collateralmaint_reqbase\text{liq\_price} = \text{entry} + \frac{\text{collateral} - \text{maint\_req}}{|\text{base}|} The app displays this live and recalculates whenever your collateral or position size changes.

Worked example

Deposit:  1,000 USDC
Open:     5 SOL long @ $130 (notional = $650, 6.5× leverage)

initial_req = 650 × 0.10 = $65      ← check passes (free = $1,000)
maint_req   = 650 × 0.05 = $32.5

liq_price (long) = 130 − (1,000 − 32.5) / 5 = 130 − 193.5 = negative
                → i.e. never liquidated until funding eats collateral

Settling funding changes collateral

Funding payments move silently in and out of UserAccount.collateral when settle_funding runs or when you trade. That means:
  • Your liquidation price drifts over time even if mark hasn’t moved.
  • Watch both mark and your collateral balance.
  • Holding a losing direction through many funding periods can trigger liquidation purely from funding, not from adverse price.