Skip to main content

Order Canceler

The Order Canceler contract provides a streamlined interface for cancelling orders across markets. Orders are identified by their NFT token IDs, making batch cancellation straightforward.

Contract Address

NetworkAddress
Sepolia Testnet0x53ad1ffcd7afb1b14c5f18be8f256606efb11b1b
This is a Sepolia testnet address. Mainnet address will be different.

Why Use Order Canceler?

When you place a limit order, you receive an Order NFT that represents your order. The Order Canceler allows you to:
  • Cancel by NFT ID - Simply provide the NFT token ID instead of order details
  • Batch cancel - Cancel multiple orders across multiple markets in one transaction
  • Cancel to any address - Send returned tokens to yourself or another address

Functions

cancel

Cancels orders and returns tokens to the caller’s address.
function cancel(CancelParams[] calldata paramsList) external
Parameters:
ParameterTypeDescription
paramsListCancelParams[]Array of cancel parameters
CancelParams:
FieldTypeDescription
marketaddressThe market (OrderBook) contract address
tokenIdsuint256[]Array of Order NFT token IDs to cancel

cancelTo

Cancels orders and sends returned tokens to a specified address.
function cancelTo(CancelParams[] calldata paramsList, address to) external
Parameters:
ParameterTypeDescription
paramsListCancelParams[]Array of cancel parameters
toaddressRecipient address for the returned tokens

Usage Examples

JavaScript (ethers.js)

import { ethers } from 'ethers';

const CANCELER_ADDRESS = '0x53ad1ffcd7afb1b14c5f18be8f256606efb11b1b';
const CANCELER_ABI = [
  {
    "name": "cancel",
    "type": "function",
    "stateMutability": "nonpayable",
    "inputs": [{
      "name": "paramsList",
      "type": "tuple[]",
      "components": [
        { "name": "market", "type": "address" },
        { "name": "tokenIds", "type": "uint256[]" }
      ]
    }],
    "outputs": []
  },
  {
    "name": "cancelTo",
    "type": "function",
    "stateMutability": "nonpayable",
    "inputs": [
      {
        "name": "paramsList",
        "type": "tuple[]",
        "components": [
          { "name": "market", "type": "address" },
          { "name": "tokenIds", "type": "uint256[]" }
        ]
      },
      { "name": "to", "type": "address" }
    ],
    "outputs": []
  }
];

const provider = new ethers.JsonRpcProvider('https://0xrpc.io/sep');
const signer = new ethers.Wallet(PRIVATE_KEY, provider);
const canceler = new ethers.Contract(CANCELER_ADDRESS, CANCELER_ABI, signer);

// Cancel orders from a single market
const cancelParams = [{
  market: '0x2e4a11c7711c6a69ac973cbc40a9b16d14f9aa7e',  // EURC/XSGD market
  tokenIds: [123n, 456n, 789n]  // Your order NFT IDs
}];

const tx = await canceler.cancel(cancelParams);
await tx.wait();
console.log('Orders cancelled successfully');

Cancel Orders from Multiple Markets

// Cancel orders across multiple markets in one transaction
const cancelParams = [
  {
    market: '0x2e4a11c7711c6a69ac973cbc40a9b16d14f9aa7e',  // EURC/XSGD
    tokenIds: [123n, 456n]
  },
  {
    market: '0x1234567890abcdef1234567890abcdef12345678',  // Another market
    tokenIds: [789n, 1011n, 1213n]
  }
];

const tx = await canceler.cancel(cancelParams);
await tx.wait();

Python (web3.py)

from web3 import Web3

CANCELER_ADDRESS = '0x53ad1ffcd7afb1b14c5f18be8f256606efb11b1b'
CANCELER_ABI = [...]  # ABI from above

w3 = Web3(Web3.HTTPProvider('https://0xrpc.io/sep'))
canceler = w3.eth.contract(address=CANCELER_ADDRESS, abi=CANCELER_ABI)

# Cancel orders
cancel_params = [(
    '0x2e4a11c7711c6a69ac973cbc40a9b16d14f9aa7e',  # market
    [123, 456, 789]  # tokenIds
)]

tx = canceler.functions.cancel(cancel_params).build_transaction({
    'from': account.address,
    'nonce': w3.eth.get_transaction_count(account.address),
    'gas': 300000,
    'gasPrice': w3.eth.gas_price
})

signed_tx = w3.eth.account.sign_transaction(tx, private_key)
tx_hash = w3.eth.send_raw_transaction(signed_tx.raw_transaction)
receipt = w3.eth.wait_for_transaction_receipt(tx_hash)

Getting Your Order NFT IDs

When you place a limit order through the Router, you receive an Order NFT. You can find your order NFT IDs via:

GraphQL Query

query MyOrders($user: String!) {
  openOrders(
    where: { user: $user }
    orderBy: createdAt
    orderDirection: desc
  ) {
    nftId        # This is the tokenId for cancellation
    market
    isBid
    price
    rawOpenAmount
    createdAt
  }
}

From Transaction Events

The Order NFT contract emits a Transfer event when an order is created:
// Listen for Transfer events from the Order NFT contract
const orderNFT = new ethers.Contract(ORDER_NFT_ADDRESS, ['event Transfer(address indexed from, address indexed to, uint256 indexed tokenId)'], provider);

orderNFT.on('Transfer', (from, to, tokenId) => {
  if (from === ethers.ZeroAddress && to === yourAddress) {
    console.log(`New order created with NFT ID: ${tokenId}`);
  }
});

Return Values

When you cancel an order:
  1. Unfilled amount - The remaining order amount is returned to you
  2. Filled amount - Any filled proceeds are also claimed and returned
The cancel function also claims any filled proceeds. You don’t need to call claim separately on cancelled orders.

Error Cases

ErrorCause
Order not foundThe NFT ID doesn’t exist or has already been cancelled
Not ownerYou don’t own this Order NFT
Order fully filledThe order has been completely filled (nothing to cancel)

See Also