Skip to main content

Domain Model

The domain model establishes fundamental data structures and business logic for overseeing programmatic orders. Location: src/types/model.ts

ConditionalOrder Type

This type represents a programmatic order that has been registered within the system.

Field Descriptions

id A unique identifier derived from keccak256(serialized_order). Used as the context key in the ComposableCoW contract. tx Hash of the transaction creating this programmatic order, helpful for tracking and debugging purposes. params Programmatic order parameters from the CoW Protocol SDK, including handler contract address, salt, and static input data. proof Contains merkle root and path array for orders created via merkle root; null for single orders. orders Tracks discrete orders posted for this programmatic order, mapping Order UID to status (SUBMITTED or FILLED). composableCow Contract address for polling to create discrete orders, typically ComposableCoW but may be a custom handler. pollResult Cached last poll result containing execution timestamp, block number, and poll outcome.

Registry Class

This class manages state across all programmatic orders for every owner.

Field Details

version Schema version used for migrations during structural changes. Currently at version 2. ownerOrders Primary data structure mapping owner addresses to their programmatic orders.
storage Reference to the database service for data persistence. network Chain identifier as a string (e.g., “1” for mainnet, “5” for Goerli). lastNotifiedError Timestamp of the last error notification, preventing excessive Slack alerts. lastProcessedBlock The most recently processed block, enabling resumption from the correct position.

Methods

Registry.load() Retrieves the registry from the database.
Creates a new empty registry starting from genesisBlockNumber - 1 if none exists. Schema migrations occur automatically based on persisted version. Registry.dump() Exports the registry as JSON.
Useful for debugging and /api/dump/:chainId endpoints. write() Persists the registry to the database atomically.
stringifyOrders() Serializes owner orders map to JSON, handling Map and Set objects.
Computed Properties

ExecutionContext

Supplies dependencies to domain logic functions.

Usage Example

RegistryBlock

Represents a processed block.
Tracks the last processed block, detects chain reorganizations, and enables restart recovery.

Storage Keys

The registry utilizes these database keys:
Each key is network-scoped for multi-chain support.

Data Serialization

The registry handles non-native JSON data structures through custom serialization.

Map Serialization

Set Serialization

Custom reviver functions restore these structures when loading.

Schema Migrations

When the registry schema evolves:
  1. Increment CONDITIONAL_ORDER_REGISTRY_VERSION
  2. Add migration logic in parseConditionalOrders()
  3. Migrations run automatically upon load

Example: Version 1 to 2

Version 2 introduced the id field:
This maintains backward compatibility during upgrades.
Last modified on March 12, 2026