Overview
Composable orders enable you to create programmatic orders (sometimes called conditional orders) that execute based on custom logic rather than executing immediately. These orders leverage theComposableCoW smart contract framework to define conditions that must be met before an order becomes tradeable.
Key benefits of composable orders:
- Programmatic Execution — Orders only execute when specific conditions are met
- Advanced Strategies — Build complex trading strategies like TWAP, DCA, or custom logic
- Gas Efficiency — Reduce on-chain transactions by batching order logic
- Merkle Tree Storage — Efficiently store multiple orders using Merkle proofs
ConditionalOrder Base Class
All composable orders inherit from theConditionalOrder abstract base class:
Key Properties and Methods
Order Identification
Creating Orders
Generate calldata to create a programmatic order on-chain:Polling Orders
Check if a programmatic order is ready to be executed:Authorization
ComposableCow Contract Integration
Multiplexer for Multiple Orders
TheMultiplexer class enables efficient management of multiple programmatic orders using Merkle trees:
Custom Handler Implementation
Best Practices
Validate Order Parameters: Always implement thorough validation in the
is_valid() method to catch errors before submitting orders on-chain.- Handle Polling Errors Gracefully: Use appropriate
PollResultCodevalues to signal whether polling should be retried, delayed, or stopped entirely. - Test with Testnets First: Always test programmatic orders on testnets (like Sepolia) before deploying to mainnet.
- Use Salt for Uniqueness: The salt parameter ensures each order has a unique ID even if other parameters are identical.
Related Resources
- TWAP Orders — Learn about Time-Weighted Average Price orders
- Signing Schemes — Understand different order signing methods
- Composable API — Composable orders API documentation