Overview
The CTF Exchange provides two functions for cancelling orders. Orders can only be cancelled by their maker (the address that holds funds for the order). Once cancelled, an order cannot be filled.cancelOrder
Cancels a single order.Parameters
The order to be cancelled. See Order Structure for details.Must be an order where
msg.sender is the maker.Requirements
- Caller must be the order maker (
msg.sender == order.maker) - Order must not already be filled or cancelled
Behavior
- Verifies the caller is the order maker
- Computes the order hash
- Checks if order is already filled or cancelled
- Marks the order as
isFilledOrCancelled = truein storage - Emits
OrderCancelledevent
Events
Emitted when an order is successfully cancelled.
orderHash: Hash of the cancelled order
Errors
Caller is not the order maker and cannot cancel this order
Order has already been fully filled or previously cancelled
Example Usage
cancelOrders
Cancels multiple orders in a single transaction.Parameters
Array of orders to be cancelled. See Order Structure for details.Requirements:
- All orders must have
msg.senderas the maker - Each order must not already be filled or cancelled
Requirements
- Caller must be the maker for all orders in the array
- Each order must not already be filled or cancelled
- Transaction will revert if any order fails validation
Behavior
Iterates through the orders array and calls the internal_cancelOrder function for each order. All cancellations are executed atomically - if any order fails, the entire transaction reverts.
For each order:
- Verifies the caller is the order maker
- Computes the order hash
- Checks if order is already filled or cancelled
- Marks the order as
isFilledOrCancelled = true - Emits
OrderCancelledevent
Events
Emitted for each order that is successfully cancelled.
Errors
All errors fromcancelOrder can be thrown for any order in the array:
Caller is not the maker for one or more orders
One or more orders have already been fully filled or previously cancelled
Example Usage
Important Notes
On-Chain State
Cancelling an order updates its on-chain state by settingisFilledOrCancelled = true. This is permanent and irreversible.
Signature Still Valid
Even after cancellation, the order’s cryptographic signature remains valid. However, any attempt to fill a cancelled order will fail the validation check and revert.Gas Efficiency
UsecancelOrders instead of multiple cancelOrder calls to save gas when cancelling multiple orders.
Alternative: Nonce Increment
Instead of cancelling orders individually, makers can invalidate all their orders with a specific nonce by callingincrementNonce(). This is more gas-efficient when cancelling many orders. See Nonce Manager for details.
Pre-Cancellation
Orders can be cancelled before they are filled, even if they haven’t been submitted to the order book yet. This is useful for pre-emptively cancelling orders that may have been signed but not yet broadcast.Use Cases
Single Order Cancellation
UsecancelOrder when you need to cancel a specific order:
- Market conditions changed
- Order was created with wrong parameters
- Strategic repositioning of liquidity
Batch Cancellation
UsecancelOrders when you need to:
- Cancel multiple orders from the same market
- Clear all pending orders atomically
- Reduce gas costs compared to individual cancellations
Emergency Cancellation
Quickly cancel all orders if:- Market experiences extreme volatility
- Security concerns arise
- Need to withdraw liquidity immediately
See Also
- fillOrder - Fill a single order
- Nonce Manager - Invalidate orders via nonce increment
- Order Structure - Details on the Order type
- Order Validation - How orders are validated