Skip to main content

BaseConditionalOrder

BaseConditionalOrder is an abstract contract serving as the foundational layer for creating custom conditional order types in CoW Protocol. It implements IConditionalOrderGenerator and handles verification workflows, enabling developers to focus on order generation logic.

Core Implementation Requirements

Developers must implement the getTradeableOrder function, which generates discrete CoW Protocol orders based on conditional parameters. This function receives:
ParameterDescription
ownerThe Safe address that owns the order
senderThe address calling the function
ctxContext key for cabinet storage
staticInputABI-encoded order configuration
offchainInputDynamic parameters from watchtowers
The function must return a valid GPv2Order.Data struct.

Error Handling

The contract specifies distinct error types for watchtower optimization:
ErrorDescription
OrderNotValidGeneral condition failure (may resolve later)
PollTryNextBlockCheck again at the next block
PollTryAtBlockCheck at a specific block number
PollTryAtEpochCheck at a specific timestamp (recommended for time-based conditions)
PollNeverPermanently stop polling (order completed or expired)

Key Features

  • Automatic hash verification through the verify function, which compares generated order hashes against provided hashes
  • ERC-165 interface detection via supportsInterface

Best Practices

  • Validate input data early
  • Use precise timing signals rather than generic errors
  • Store dynamic state via the cabinet mechanism
  • Ensure unique order hashes (typically through distinct validTo values)
  • Handle all edge cases including pre-start and post-expiration states
Last modified on March 4, 2026