Permissionless maturity settlement at fixing price, liquidation of underwater positions when equity falls below maintenance margin, early termination at forward price, and partial position reduction — all with PnL capped at locked margin
The SettlementEngine executes all position closures: maturity settlement, liquidation, early termination, and partial reduction. All settlement and liquidation functions are permissionless — anyone can call them, enabling keeper automation.
function batchSettlePositions(bytes32 pairId, uint256 maxCount) external returns (uint256 settled)
Batch-settles up to maxCount matured positions for a pair. Skips positions that are liquidatable, lack a fixing price, or belong to a different pair. Clears orphaned forward slots after settlement.
function reducePosition(uint256 positionId, uint256 reductionNotional) external
Partially reduces a position’s notional. PnL on the reduced portion is settled immediately. If reductionNotional == notional, performs a full close.Validation checks (in order):
Losses are capped at marginAtRisk — the locked margin for a full close, or a proportional share for partial reduction. Profits are uncapped. Fees are deducted from remaining margin after the loss cap is applied.