Skip to main content
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.

Contract Relationships

Read Functions

getLiquidationParams

function getLiquidationParams(uint256 positionId)
    external view
    returns (bool isLiquidatable, int256 markPrice, int256 estimatedPnl, uint256 liquidationFee)
Returns liquidation eligibility and parameters for a position.
NameTypeDescription
positionIduint256Position to check
Returns:
NameTypeDescription
isLiquidatableboolWhether position can be liquidated
markPriceint256Current forward price (18 decimals)
estimatedPnlint256Estimated PnL at current price
liquidationFeeuint256Trading fee + liquidation penalty

getEarlyTerminationParams

function getEarlyTerminationParams(uint256 positionId)
    external view
    returns (int256 closePrice, int256 estimatedPnl, uint256 terminationFee, uint16 premiumDiscountAdjBps)
Returns early termination parameters for a position.
NameTypeDescription
positionIduint256Position to check
Returns:
NameTypeDescription
closePriceint256Forward price with adjustment (18 decimals)
estimatedPnlint256Estimated PnL at close price
terminationFeeuint256Trading fee for early close
premiumDiscountAdjBpsuint16Premium/discount adjustment applied

positionManager

function positionManager() external view returns (address)
Returns the address of the PositionManager contract.

marginAccounts

function marginAccounts() external view returns (address)
Returns the address of the MarginAccounts contract.

poolVault

function poolVault() external view returns (address)
Returns the address of the PoolVault contract.

oracle

function oracle() external view returns (address)
Returns the address of the OracleModule contract.

Write Functions

settlePosition

function settlePosition(uint256 positionId) external
Settles a matured position at the recorded fixing price. Permissionless — anyone can call. Validation checks (in order):
#CheckRevert Error
1Position must be OPENPositionNotOpen
2block.timestamp >= fixingTimestampNotMatured
3Position must not be liquidatableSettlementNotAllowed
4Fixing price must be recorded and > 0FixingPriceNotSet

liquidatePosition

function liquidatePosition(uint256 positionId) external
Liquidates an underwater position at the current forward price. Permissionless — anyone can call. Validation checks (in order):
#CheckRevert Error
1Position must be OPENPositionNotOpen
2Position must be liquidatable (equity < MM threshold)NotLiquidatable

batchSettlePositions

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.
NameTypeDescription
pairIdbytes32Currency pair to settle
maxCountuint256Maximum positions to process

batchLiquidatePositions

function batchLiquidatePositions(bytes32 pairId, uint256 maxCount) external returns (uint256 liquidated)
Batch-liquidates up to maxCount underwater positions for a pair.
NameTypeDescription
pairIdbytes32Currency pair to liquidate
maxCountuint256Maximum positions to process

closePosition

function closePosition(uint256 positionId) external
Early termination — closes the position at the current forward price. Owner only. Validation checks (in order):
#CheckRevert Error
1Position must be OPENPositionNotOpen
2Caller must be position ownerUnauthorized
3Position must not be liquidatableEarlyTerminationNotAllowed
4Oracle must return valid forward priceOracleInvalid

reducePosition

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):
#CheckRevert Error
1Position must be OPENPositionNotOpen
2Caller must be position ownerUnauthorized
3reductionNotional > 0ZeroAmount
4reductionNotional <= notionalInvalidParameter
5Position must not be liquidatableEarlyTerminationNotAllowed
6Oracle must return valid forward priceOracleInvalid

PnL Capping

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.

Events

EventWhen Emitted
PositionSettledAtMaturityPosition settled at fixing price after maturity
PositionLiquidatedUnderwater position liquidated at forward price
PositionClosedEarlyPosition closed before maturity by owner
PositionReducedPosition partially reduced
FeesCollectedFees collected during any settlement type

Position Manager

Opening positions and margin adjustments.

Settlement

Protocol-level settlement mechanics and PnL formulas.

Liquidation

Liquidation conditions and penalty structure.