@somnia-chain/markets-sdk / index / PerpLiquidationPreview
Type Alias: PerpLiquidationPreview
PerpLiquidationPreview = {
priceable:false;asOfBlock:bigint; } | {priceable:true;asOfBlock:bigint;markPrice:bigint;currentSize:bigint;currentLiquidationPrice:bigint|null;projectedSize:bigint;projectedEntryPrice:bigint;realizedPnl:bigint;fee:bigint;projectedEquity:bigint;projectedMmReq:bigint;projectedLiquidationPrice:bigint|null;projectedPositionLeverageBps:bigint|null; }
Defined in: packages/sdk/src/perp/margin.ts:2516
Where an order would put the liquidation price if it filled — and where it sits now, for the comparison that is the actual question.
A discriminated union: an unpriceable market yields no preview, because the mark is
an input to every field below. Narrow on priceable first.
Union Members
Type Literal
{ priceable: false; asOfBlock: bigint; }
priceable
priceable:
false
The pool's mark feed is stale or zero, so there is nothing to project against — and an order with an increasing leg would revert on the contract's own freshness gate anyway.
asOfBlock
asOfBlock:
bigint
The block every read was pinned to.
Type Literal
{ priceable: true; asOfBlock: bigint; markPrice: bigint; currentSize: bigint; currentLiquidationPrice: bigint | null; projectedSize: bigint; projectedEntryPrice: bigint; realizedPnl: bigint; fee: bigint; projectedEquity: bigint; projectedMmReq: bigint; projectedLiquidationPrice: bigint | null; projectedPositionLeverageBps: bigint | null; }
priceable
priceable:
true
asOfBlock
asOfBlock:
bigint
The block every read was pinned to.
A projection is a statement about THIS block, not about the block the order fills in. Every field moves with the mark, so re-quote near send time for anything close to the edge.
markPrice
markPrice:
bigint
Mark price the whole projection is measured against.
currentSize
currentSize:
bigint
SIGNED position size before the fill, raw base units.
currentLiquidationPrice
currentLiquidationPrice:
bigint|null
Liquidation price of the position as it stands NOW, or null when flat.
Identical to client.getLiquidationPrice at this block — same kernel, same
inputs — so the two can be shown side by side without them disagreeing.
projectedSize
projectedSize:
bigint
SIGNED position size after the fill; 0n when the order closes out exactly.
projectedEntryPrice
projectedEntryPrice:
bigint
Volume-weighted average entry price after the fill, raw quote per whole base.
Follows MarginBank.settleTrade: the order's price on an OPEN or a FLIP, the
floored VWAP of old and new on an INCREASE, and untouched on a reduce (a
partial close does not re-price what remains). 0n when the fill closes the
position out, matching _clearPosition.
realizedPnl
realizedPnl:
bigint
Realized PnL the fill books into the collateral balance (signed).
Non-zero only for a reduce, close, or flip — an open or an increase realizes
nothing. Floored toward −∞, matching _realizedPnlForClose.
fee
fee:
bigint
Trading fee the fill would charge, raw collateral units — NEGATIVE for a maker rebate, which is a credit.
Charged on fill notional at the pool's taker rate by default; pass asMaker
for the maker rate. It reduces equity, so it moves the liquidation price, which
is why it is modelled here even though SomniaMarketsClient.previewPerpOrderMargin (a
question about the LOCK) has no reason to.
projectedEquity
projectedEquity:
bigint
Account equity after the fill (signed) — the projection's numerator.
equity − uPnlBefore + uPnlAfter + realizedPnl − fee, all at the current mark.
Re-marking is what makes an adverse entry cost equity immediately: a position
opens at the order's price but is marked at the mark, so the gap lands here.
projectedMmReq
projectedMmReq:
bigint
Aggregate maintenance requirement after the fill — this market's contribution recomputed on the new size, with every other market's left exactly as the bank reported it.
projectedLiquidationPrice
projectedLiquidationPrice:
bigint|null
Liquidation price after the fill, or null when the order leaves the account
flat in this market (nothing left to liquidate).
Compare against currentLiquidationPrice: a same-side add moves it toward the mark, a reduce away from it.
projectedPositionLeverageBps
projectedPositionLeverageBps:
bigint|null
This position's leverage after the fill, bps of 1x — post-fill notional over
post-fill equity. null on non-positive projected equity, as on
PerpLeverage.positionLeverageBps.