Skip to main content

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

Order
required
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

  1. Verifies the caller is the order maker
  2. Computes the order hash
  3. Checks if order is already filled or cancelled
  4. Marks the order as isFilledOrCancelled = true in storage
  5. Emits OrderCancelled event

Events

event
Emitted when an order is successfully cancelled.
  • orderHash: Hash of the cancelled order

Errors

error
Caller is not the order maker and cannot cancel this order
error
Order has already been fully filled or previously cancelled

Example Usage

cancelOrders

Cancels multiple orders in a single transaction.

Parameters

Order[]
required
Array of orders to be cancelled. See Order Structure for details.Requirements:
  • All orders must have msg.sender as 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:
  1. Verifies the caller is the order maker
  2. Computes the order hash
  3. Checks if order is already filled or cancelled
  4. Marks the order as isFilledOrCancelled = true
  5. Emits OrderCancelled event

Events

event
Emitted for each order that is successfully cancelled.

Errors

All errors from cancelOrder can be thrown for any order in the array:
error
Caller is not the maker for one or more orders
error
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 setting isFilledOrCancelled = 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

Use cancelOrders 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 calling incrementNonce(). 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

Use cancelOrder when you need to cancel a specific order:
  • Market conditions changed
  • Order was created with wrong parameters
  • Strategic repositioning of liquidity

Batch Cancellation

Use cancelOrders 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