Skip to main content

Settlements

All money moves through one rail: the existing commit → reveal lanes on SwapERC20. Invoice payments do not introduce a second settlement path — they mint Order templates that resolve into the same Orders, byte-identical wire.

Commit/reveal in one paragraph

Commit has no confidentiality: the commit body carries all nine preimage fields in plaintext; the withheld pieces are the maker signature, the AirSwap order nonce, and the protocol fee. What commit buys is equivocation-binding — the intent is bound to the taker under an expiry window, and the server’s stored commitNonce + commitmentExpiry are authoritative at reveal. Reveal is single-fire: no transport retry; an already-revealed commit refuses.

The payment attempt machine

One invoice maps to a list of payment attempts (mapping 1 → N). One attempt = one payment try: FAILED/EXPIRED are terminal for the attempt, not the invoice — the 1 → N mapping simply creates the next attempt with a fresh nonce.

The Order template law

POST /v1/invoices/{invoiceId}/payments returns an unsigned 10-minute Order template. The debtor’s agent signs it offline and posts it to the bind endpoint — POST /v1/invoices/{invoiceId}/payments/{attemptId}/order (ORDER_SIGNED’s wire path; the /api twin is the same handler — one law, two mounts). The template’s fixed law: The receipted fee semantics: debtor-cost = target + 7 bps in the payment token; creditor-net = target (dust returns to the debtor). feeBearer is a pricing term on the claim — who prices the fee into the deal — never a protocol path. The posted Order must satisfy this template law exactly (400 tier). The signature must recover to the debtor over the exact fields in the SwapERC20 v4 EIP-712 order domain — the Order signature IS the payment’s signature; no new EIP-712 type exists for payment.

Idempotency and nonce discipline

  • The Idempotency-Key namespace is scoped per invoice — uniqueness is (invoiceId, idempotencyKey). The same key on a different invoice names a different attempt.
  • A retried intent with the same key returns the same attempt (200 replay) — a network retry never burns a second nonce or double-counts an in-flight payment. The same key with a different payload is 409 INVOICE_IDEMPOTENCY_CONFLICT.
  • Terminal-retry rule: a key on a terminal attempt (RECEIPTED/FAILED/EXPIRED) replays the same terminal record and never re-executes — a key never resurrects. The next attempt mints a new key (or omits the header to take the derived (invoiceId, attemptSeq) key).
  • Nonce discipline: a fresh nonce per attempt, never reused — even when the previous attempt expired unburned (the bitmap only burns on success). Auditability over cleverness: the nonce column is a complete payment history with no exceptions to explain.
  • Attempt rows are permanent: replay-by-key never expires; the only TTLs are the 10-minute Order clock and the attempt’s own terminality.

The amount law

The template’s signerAmount targets the attempt’s amount:
  • Default — the full outstanding at intent creation.
  • Partial — pass the optional amount on the intent request (invoice- currency atomic units, above zero and at most the outstanding at intent creation, else 400 INVOICE_AMOUNT_INVALID). Partial payment intents exist and PARTIALLY_PAID is reachable through this declared lane.
The attempt pins its target (intentAmount, immutable for the attempt’s life — replays return the same template). The race is disclosed: outstanding can shrink between intent and receipt. The bind’s stale-template guard refuses an order whose signer leg exceeds the current outstanding (request a fresh intent instead of overpaying); two concurrent full-outstanding attempts can both receipt → surplus, settled out-of-band.

Settlement receipt and the five-way mapping

The reveal’s Swap event is the complete receipt — nonce indexed, both parties, both legs, protocolFeeAmount, blockNumber. The ledger binds:
with chainId recorded from day one alongside nonce/txHash, so Phase 2’s cross-chain settlement is a service change, not schema surgery. Every attempt also records paymentCurrency (null for swap-direct) — the day-one multi-currency settlement-usage metric.

Payment templates

Two-tier status convention

Refusals come in exactly two tiers — no third tier:

Where to next