Subaccounts & margin
Funds and positions live in subaccounts. Margin is shared inside a subaccount, while different subaccounts are isolated from each other.
Subaccounts
- How many and how they are created. Up to 128 subaccounts per address. A subaccount is created by its first deposit.
- Subaccount 0. Used by default: IBC deposits without a memo are credited to it.
- Cross-margin inside. All positions of a subaccount use the same collateral: profit on one position supports another.
- Isolation between subaccounts. A loss or a liquidation in one subaccount does not affect the others.
Margin
| Value | How it is computed |
|---|---|
| Equity | Collateral + unrealized PnL at the oracle price + funding |
| Initial margin (IM) | Position notional divided by leverage. It is also reserved for the unfilled remainder of opening orders. Reduce-only orders reserve no margin |
| Maintenance margin (MM) | Position notional multiplied by the market rate: 0.5% for BTC and ETH, 1% for the others |
Liquidation starts when the subaccount's equity falls below its total MM. Details are in Liquidations, ADL & insurance.
Leverage
- Choice. Leverage is set in each order, up to the market maximum (currently 10x).
- Adding to a position. Size, entry and margin are combined, and leverage is recalculated.
- Partial close. Releases margin proportionally; leverage does not change.
Changing a position's margin
With MsgAdjustMargin, margin can be added to a position or removed from it:
- Add within free collateral. Leverage goes down and the position becomes more resilient.
- Remove only if the subaccount's equity is above MM and the new leverage stays within the market maximum.
Margin from open interest
Governance can set two open-interest thresholds for a market:
- Below the lower threshold the regular initial margin applies.
- Between the thresholds it rises linearly.
- At the upper threshold it equals 100%, which means 1x leverage.
Large open interest therefore needs more collateral. While the thresholds are not set, the mechanism is off.
Withdrawals and transfers
- How much can be withdrawn. Equity minus the larger of MM and the IM of positions. No more than the collateral not reserved for open orders can leave.
- When withdrawal is impossible. If equity is not above MM, and while one of the positions has no fresh price or its pair is closed by the oracle (a pause or the circuit breaker).
- Transfers. The same rules apply to transfers between your own subaccounts.
- Pause after a bankruptcy. If any subaccount on the network goes bankrupt with a deficit of 0.1 USDC or more, withdrawals and transfers across the network are frozen for 50 blocks (~42 s). This gives the deficit time to be covered before funds leave the system.
Closing a position
MsgClosePosition sends a market reduce order through the book. One close executes up to 10 trades. If the position is larger, the rest stays open and the close is repeated.
Automatic order removal
At the end of every block the protocol removes orders that lack margin:
- Opening orders. If the subaccount's collateral less its unrealized loss is below the IM of its positions plus the margin reserved for orders, all its opening orders are removed. If a position has no fresh price and its pair is not closed by the oracle, the removal waits for a fresh price.
- Reduce-only orders. Removed if their position no longer exists.