Cancel a limit order

To cancel an earlier placed order(s), a transaction AugustusRFQ.cancelOrder (or CancelOrders) needs to be sent on behalf of the order's maker.

Transaction parameters:

orderHash: limit order unique id

Example

/* eslint-disable @typescript-eslint/no-unused-vars */
import axios from 'axios';
import * as dotenv from 'dotenv';
import { ethers } from 'ethers';
import {
  constructPartialSDK,
  constructEthersContractCaller,
  constructAxiosFetcher,
  constructCancelLimitOrder,
  constructGetLimitOrders,
} from '..';
dotenv.config();

const maker = new ethers.Wallet(process.env.PK).connect(ethers.getDefaultProvider(1));

const fetcher = constructAxiosFetcher(axios);

// provider must have write access to account
// this would usually be wallet provider (Metamask)
const provider = ethers.getDefaultProvider(1);
const contractCaller = constructEthersContractCaller(
  {
    ethersProviderOrSigner: provider,
    EthersContract: ethers.Contract,
  },
  maker.address
);

const paraSwapLimitOrderSDK = constructPartialSDK(
  {
    chainId: 1,
    fetcher,
    contractCaller,
  },
  constructGetLimitOrders,
  constructCancelLimitOrder
);

async function run() {
  const { orders: currentOrders } = await paraSwapLimitOrderSDK.getLimitOrders({
    maker: maker.address,
    type: 'LIMIT',
  });

  if (!currentOrders[0]?.orderHash) throw new Error('No orders found');

  const deleteTx: ethers.ContractTransaction =
    await paraSwapLimitOrderSDK.cancelLimitOrder(currentOrders[0].orderHash);

  console.log('deleteTx', deleteTx);
}

Last updated