src/types/model.ts
ConditionalOrder type
Represents a conditional order registered in the system.Fields
id
Unique identifier for the conditional order, computed as keccak256(serialized_order). This ID is used as the context key in the ComposableCoW contract.
tx
Transaction hash of the transaction that created this conditional order. Useful for debugging and tracking order creation.
params
The conditional order parameters from the CoW Protocol SDK:
- Handler contract address
- Salt for uniqueness
- Static input data
proof
For orders created via merkle root, contains:
merkleRoot: The root hashpath: Array of hashes forming the merkle path
null.
orders
A map tracking all discrete orders that have been posted for this conditional order:
- Key: Order UID
- Value: Order status (SUBMITTED or FILLED)
composableCow
The contract address to poll for creating discrete orders. Usually the ComposableCoW contract, but may be a custom handler.
pollResult
Caches the last poll result to avoid redundant polling:
lastExecutionTimestamp: When the order was last checkedblockNumber: Block number of last pollresult: The SDK poll result
Related types
Registry class
Manages the state of all conditional orders across owners.Fields
version
Schema version for the registry. Used for migrations when the data structure changes. Current version: 2.
ownerOrders
The main data structure: a map from owner addresses to their conditional orders.
- Key: Owner address (Safe or EOA)
- Value: Set of conditional orders for that owner
storage
Reference to the database service for persistence.
network
Chain ID as a string (e.g., “1” for mainnet, “5” for Goerli).
lastNotifiedError
Timestamp of the last error notification sent to Slack. Used to prevent notification spam.
lastProcessedBlock
The last block that was successfully processed. Used to resume from the correct position after restart.
Methods
Registry.load()
Loads the registry from the database.
genesisBlockNumber - 1.
Handles schema migrations automatically based on the persisted version.
Registry.dump()
Exports the registry as a JSON string.
/api/dump/:chainId endpoint.
write()
Persists the registry to the database atomically.
- Registry version
- Conditional orders by owner
- Last notified error timestamp
- Last processed block
stringifyOrders()
Serializes the owner orders map to JSON.
Map and Set objects using custom replacer functions.
Computed properties
ExecutionContext
Provides dependencies to domain logic functions.Usage
Passed to domain functions that need to read/write state:RegistryBlock
Represents a processed block.- Track the last processed block
- Detect chain reorganizations (hash mismatch)
- Resume from correct position after restart
Storage keys
The registry uses these database keys:Data serialization
The registry handles JavaScript data structures that don’t serialize to JSON naturally:Map serialization
Set serialization
Schema migrations
When the registry schema changes:- Increment
CONDITIONAL_ORDER_REGISTRY_VERSION - Add migration logic in
parseConditionalOrders() - The migration runs automatically on load
Example: Version 1 to 2
Version 2 added theid field to conditional orders: