Gasless Cancel
Last updated
Was this helpful?
Last updated
Was this helpful?
In addition to , KyberSwap Limit Order Makers have the option to cancel their orders without incurring gas. As Taker order fulfilment requires both a Maker and KyberSwap Operator signature, Makers are able to cancel their orders gaslessly by instructing the KyberSwap Operator to cancel their orders.
Please refer to for more details on this design.
KyberSwap exposes 2 APIs which Makers will need to call to gaslessly cancel their order:
In addition to the above, Makers are also able to query their active order(s) to aid with filtering orders to cancel:
Limit Order API Demo
The code snippets in the guide below have been extracted from our demo GitHub repo which showcases the full end-to-end Limit Order operations in a TypeScript environment.
We can use the /read-ks/api/v1/orders
to get the list of "active" or "open" Maker orders:
In this case, the above query will return all of the Maker active orders from which we can then filter for our target order to cancel.
For our purposes, we will just take the first order which matches our makerAsset
and takerAsset
pair:
To get the unsigned Cancel Order message, we will send the following request to the /write/api/v1/orders/cancel-sign
endpoint:
Based on the response above, we can then proceed to request the Maker's signature:
With the maker-signed transaction, we can then append the signature to the request body to be sent to /write/api/v1/orders/cancel
:
We are now ready to call the /write/api/v1/orders/cancel
API with the formatted cancel order message:
Note that we have included an Origin
header parameter as a means to authenticate the request.
Once the KyberSwap LO Service receives the gasless cancel order, the KyberSwap Operator will no longer sign the orderIds that were requested to be gaslessly cancelled. In rare cases where the KyberSwap Operator had recently signed the target orderId (i.e. when target order is close to the market price), Makers might need to wait up till a maximum of 5 minutes for the Operator signature to lapse before their order is cancelled.
The cancelled orderId
as well as any operator signature expiry timestamp will be returned as part of the response values from the /write/api/v1/orders/cancel
API.
: Get the EIP712 cancel order message to be signed. The response of this API will need to be signed with before submitting cancel order request below.
: Cancel order(s) by sending in order params which includes the signed EIP712 message.
: Get all orders created by a Maker address filtered by the order status.
To proceed with this guide, users must have created an Active or Open Limit Order. Please refer to the for instructions on how to achieve this programmatically.
Note that you can specify more than a single orderId
to be cancelled by adding to the orderIds
array. Once submitted, the KyberSwap LO Service will return an unsigned Cancel Order message.
exposes human-readable data for user's to view prior to signing the transaction.
Our example assumes a pure Node.js implementation and therefore uses the ethers.js function to sign the EIP712 message. Note that the type
object used is per the primaryType
that is returned by the KyberSwap LO Service.
For further information on how to implement this from the browser UI, you can also take reference from MetaMask's .
Please refer to for more info.