Skip to main content
A settlement moves one asset (asset_out) from the chain’s deposit contract to a target and brings another (asset_in) back, atomically, without a withdrawal. Market makers use settlements to hedge or unwind exposure from Tplus fills onchain; the onchain leg behaves like a flash loan against the deposit contract’s funds. Two parties: the user, whose Tplus balance is debited and credited, and a settler, an approved account whose executor runs the onchain transaction. Settlers are approved per-chain; the list is readable onchain via getApprovedSettlers().

Flow

  1. Request and margin check. The request (POST /settlement/init) specifies asset out/in, amounts, sub-account, mode, the settler, and optionally max_fee, the most the outgoing leg may reserve for its rebalancing fee (18-decimal units of asset_out, signed from protocol version 3; omitted accepts whatever the protocol reserves, "0" only a fee-free approval). A request whose fee is priced above it is rejected before any lock, with code FEE_ABOVE_MAXIMUM. Validation: asset_in must differ from asset_out, and the mode (Margin or Spot) must match the sub-account type. The clearing engine simulates an initial-margin check at both oracle and mark price: the account must pass IM and the settlement, including the rebalancing fee, must not decrease the IM surplus. Accounts with no borrows always pass.
  2. Lock. The outgoing amount is moved into a settlement lock keyed by the request’s chain and nonce.
  3. Approval. The protocol signs a time-bound approval. The approval is returned by POST /settlement/init; outstanding user approvals can be fetched with GET /settlement/signatures/{user_id}.
  4. Execution. The settler calls executeAtomicSettlement(...) on the deposit contract within the validity window, which the protocol sets per chain. The deposit contract verifies signature, nonce, and expiry.
  5. Confirm or expire. A confirmed settlement event credits asset_in to the user. If the transaction does not land in time, or reverts, which emits no event, the lock expires, funds are restored, and the deposit contract rejects late execution because validUntil has passed.
The margin check compares simulated initial-margin surplus before and after the settlement:
For a simple USD-out, ETH-in settlement:
Example: an account sends out 1,000 USDC, pays a 10 USD rebalancing fee, and receives 0.6 ETH. If ETH = 2,000 USD and im_factor = 90%, the incoming ETH contributes 0.6 * 2,000 USD * 90% = 1,080 USD to IM surplus, so delta_IM_surplus = 1,080 USD - 1,000 USD - 10 USD = +70 USD and the settlement passes. If the account receives only 0.5 ETH, the contribution is 900 USD, delta_IM_surplus = -110 USD, and the request is rejected before any lock.

Utilization caps

Each asset has a utilization cap (max_utilization, a per-asset onchain risk parameter). Utilization is the share of the asset’s deposits that is currently borrowed, and the cap bounds how far they can be drawn down. When an asset sits at its cap, the protocol will not let it leave the deposit contract through the live single-settlement path. A settlement that would move a capped asset out is blocked until utilization falls. In a batch settlement, a settler executes several settlements together through executeBatchSettlements, and the deposit contract moves only the net of each token across them instead of every gross leg:
  • net < 0: the batch sends more of the token out than it brings in; the deposit contract pushes only the difference to the settler.
  • net > 0: the batch brings more in than it sends out; the deposit contract pulls only the difference from the settler.
  • net = 0: the legs cancel and the token never moves.
A token both bought and sold inside one batch nets out and never crosses the deposit contract boundary. That is the mechanism for settling capped assets when the batch nets to zero or a net inflow for that asset. A batch settlement nets token movements in and out of the deposit contract, not obligations. Each settlement is honored on its own terms. The settler must commit, per settlement, to deliver at least that settlement’s amountIn (one user’s leg cannot subsidize another’s); the deposit contract emits a separate Settled event per settlement with the real amounts; and margin checks, locks, and nonces all operate on the real per-settlement amounts, not the net. Each settlement in a batch is approved on its own through POST /settlement/init. The settler then submits the approvals together with executeBatchSettlements, or one at a time with executeAtomicSettlement.

Integrator details

  • Nonces are independent sequences per user, per chain, and per action type (deposit / withdrawal / settlement); settlement nonces are additionally scoped per sub-account. Do not assume cross-channel ordering. Onchain counters: depositCounts(user), withdrawalCounts(user), settlementCounts(user, account).
  • The settlement nonce (inner.nonce) is required and signed. It must be >= the onchain counter and must not collide with an in-flight lock. Executing a nonce voids every pending approval numbered below it. The deprecated outer nonce must equal it if sent.
  • A sync taker order carries no nonce. The clearing engine numbers the settlement it derives from the fill one above the account’s highest in-flight nonce on that chain, in the same sequence as settlement requests. A request that reuses a pending nonce returns HTTP 400 with code INVALID_NONCE.
  • Approvals are returned by POST /settlement/init; before retrying, have the settler authenticate and call GET /settlement/signatures/{user_id} with the settler’s own user ID.
  • Deposit contract revert reasons: Expired, SettlerNotApproved, NotExecutor, InvalidSignature, InvalidNonce(expected, given), TransferFailed, TransferFromFailed, InsufficientAmountFromExecutor.
  • POST /settlement/init is rejected before any lock if the account does not pass IM, the settlement would decrease the IM surplus, an open-interest cap or the collateral cap would be breached, the oracle is stale or the asset is circuit-broken, or asset_in equals asset_out.