Overview
Composable orders enable you to create conditional orders that execute based on custom logic rather than executing immediately. These orders leverage the ComposableCow smart contract framework to define conditions that must be met before an order becomes tradeable. Key benefits of composable orders:- Conditional 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, which provides core functionality:
conditional_order_structure.py
Key Properties and Methods
Order Identification
order_properties.py
Creating Orders
Generate calldata to create a conditional order on-chain:creating_orders.py
Polling Orders
Check if a conditional order is ready to be executed:polling_orders.py
Authorization
Conditional orders must be authorized on-chain before they can execute:authorization.py
ComposableCow Contract Integration
TheComposableCow contract is the core smart contract that manages conditional orders:
composable_cow_contract.py
Multiplexer for Multiple Orders
TheMultiplexer class enables efficient management of multiple conditional orders using Merkle trees:
multiplexer_usage.py
Custom Handler Implementation
To create a custom order type, you need to:- Deploy a handler contract that implements the
IConditionalOrderinterface - Extend the ConditionalOrder class with your custom logic
- Register your order type with the factory
custom_handler.py
Best Practices
Validate Order Parameters
Validate Order Parameters
Always implement thorough validation in the
is_valid() method to catch errors before submitting orders on-chain.Handle Polling Errors Gracefully
Handle Polling Errors Gracefully
Use appropriate
PollResultCode values to signal whether polling should be retried, delayed, or stopped entirely.Test with Testnets First
Test with Testnets First
Always test conditional orders on testnets (like Sepolia) before deploying to mainnet.
Use Salt for Uniqueness
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
Order Types
API reference for order structures
Composable API
Composable orders API documentation
