Every settlement is driven by a deterministic state machine defined in its template and enforced on-chain by the SettlementCoordinator contract.Documentation Index
Fetch the complete documentation index at: https://docs.keystoneos.xyz/llms.txt
Use this file to discover all available pages before exploring further.
Two zones of control
The state machine has two distinct zones:| Zone | Who drives it | States |
|---|---|---|
| KeyStone-controlled | Settlement engine proposes transitions | INSTRUCTED through COMPLIANCE_CLEARED |
| Contract-autonomous | Contracts handle everything | AWAITING_DEPOSITS through FINALIZED |
How it works
KeyStone-controlled phase
- INSTRUCTED - Settlement created from matched instructions. Engine auto-advances.
- COMPLIANCE_CHECKING - Engine runs compliance screening via LSEG and CipherOwl. Results are attested to the ComplianceRegistry on-chain.
- COMPLIANCE_CLEARED - Compliance gate passed. Engine proposes transition past compliance.
- AWAITING_DEPOSITS - This is the handoff point. KeyStone is done.
Contract-autonomous phase
- AWAITING_DEPOSITS - Parties deposit directly to escrow contracts using their
deposit_secret. The escrow contract detects when all legs are deposited and notifies the coordinator (same-chain call or LayerZero message for cross-chain). - EXECUTING_SWAP - The coordinator verifies the atomicity gate (
allLegsDeposited == true) and callsexecuteSettlementwith recipient addresses (revealed only at this point) to all escrow contracts. - FINALIZED - Escrow contracts release deposits to recipients. Settlement complete.
Gate checks
The SettlementCoordinator checks conditions (gates) before allowing certain transitions:| Gate | What it checks | When |
|---|---|---|
| Compliance | ComplianceRegistry.areAllPartiesCleared() | Before transitioning past compliance |
| Deposits | Escrow.allLegsDeposited() | Before transitioning from AWAITING_DEPOSITS to EXECUTING_SWAP |
Transition enforcement
The SettlementCoordinator enforces strict rules:- Only transitions explicitly defined in the template are allowed
- No state can be skipped
- No client can force a state jump
- Gate conditions must be met before gated transitions
- Every transition is recorded as an on-chain event
Permissionless timeout
Anyone can calltimeout() on the SettlementCoordinator after the deadline. This triggers rollback on all chains without depending on KeyStone. Funds are never locked indefinitely.
Events
Every state transition produces an on-chain event from the SettlementCoordinator:Error handling
When an action fails:- The error is logged with full context
- The settlement remains in its current state (no partial transitions)
- If
timeout_atis reached, the settlement transitions toTIMED_OUT