Functions
createSettlement()
Registers a new settlement on-chain with its state machine rules. This call is permissionless - anyone can call it. Gas cost is the natural spam filter.| Parameter | Description |
|---|---|
settlementId | UUID converted to bytes32 (16 bytes UUID + 16 bytes zero padding) |
initialState | Index of the initial state in the template’s states list |
transitions | Array of allowed (fromState, toState) pairs |
gates | Array of (state, gateType) pairs defining preconditions |
partyHashes | Keccak256 hashes of party identifiers |
timeoutAt | Unix timestamp deadline for the settlement |
SettlementCreated(bytes32 settlementId)
transition()
Proposes a state transition. The contract validates the proposal against the registered rules and gate checks before accepting.| Parameter | Description |
|---|---|
settlementId | The settlement to transition |
targetState | Index of the target state |
evidenceHash | SHA-256 of "fromState:toState:triggeredBy" for audit |
- Settlement exists and is not in a terminal state
(currentState, targetState)is in the registered transitions list- If the target state has a gate, the gate condition is met
- Caller is authorized (coordinator role)
StateTransition(bytes32 settlementId, uint8 fromState, uint8 toState, bytes32 evidenceHash)
timeout()
Triggers a timeout for an expired settlement. This call is permissionless - anyone can call it after the deadline. No dependency on KeyStone.- Settlement exists and is not in a terminal state
block.timestamp >= timeoutAt
SettlementTimedOut(bytes32 settlementId)
View functions
Events
| Event | When | Purpose |
|---|---|---|
SettlementCreated(bytes32 settlementId) | New settlement registered | Audit trail, indexer trigger |
StateTransition(bytes32 settlementId, uint8 fromState, uint8 toState, bytes32 evidenceHash) | Any state change | Immutable transition record |
SettlementTimedOut(bytes32 settlementId) | Timeout triggered | Audit trail, triggers rollback |
Gate types
Gates are preconditions checked before a transition is accepted:| Gate Type | Contract Checked | Function Called |
|---|---|---|
COMPLIANCE_CLEARED | ComplianceRegistry | areAllPartiesCleared(settlementId) |
ALL_DEPOSITS_CONFIRMED | KeystoneEscrow | allLegsDeposited(settlementId) |
Access control
| Function | Who Can Call |
|---|---|
createSettlement() | Anyone (permissionless) |
transition() | Coordinator role only (KeyStone engine) |
timeout() | Anyone (permissionless, after deadline) |
getSettlement() / getState() | Anyone (view) |
Data conversion
| Source | Target | Method |
|---|---|---|
| UUID (16 bytes) | bytes32 | Right-pad with 16 zero bytes |
| State name (string) | uint8 | Index in template’s states list |
| Evidence | bytes32 | SHA-256 of "from_state:to_state:triggered_by" |
| Party identity | bytes32 | keccak256(abi.encode(participantId_bytes32, walletAddress)) |