Collecting Orders
On VM chains, assets can be pulled from users via approvals – a feature not available on non-VM chains – instead the sequence of operation has been modified to allow the user to push assets to the solver. The easiest routes originate from a VM chain – these routes are generally permissionless – while routes originating from BTC are more difficult – these routes are generally permissioned.
Pulling Orders
The simplest way to collect orderflow from EVM is via polling. The order server stores orders in a dictionary format, allowing for straightforward parsing by integrators and provides a high level of transparency in the implementation.
Subscribing to Orders
Subscribing to orders allow you to listen directly to the order flow. This section outlines how to subscribe to new orders using a WebSocket connection, allowing for real-time updates without the need to continuously poll the order server. By leveraging WebSocket, the Catalyst order server broadcasts new orders as they arrive, offering a significant reduction in latency but at the cost of increased complexity due to the need for a persistent connection and local filtering of incoming data.
Instead of polling for new orders, you can establish a WebSocket connection to the Catalyst order server. The server provides a WebSocket endpoint that pushes new order data to subscribers in real time. However, unlike polling, the data received through WebSocket is not pre-filtered. This means every order event will be pushed to your application, and it’s up to your implementation to manage and filter these events locally.
Below is a simplified implementation in pure JavaScript that demonstrates how to connect to the WebSocket server, handle incoming messages, respond to ping events, and automatically attempt to reconnect if the connection is lost.
(TODO update typescript block)
Evaluating Orders
After fetching an order, the solver must thoroughly evaluate it to determine its viability and potential execution. To facilitate this evaluation, several contextual pointers are available within the returned order data. Key aspects to consider include:
-
Quote Validation: Use the
OrderDto.quote
field to access the price context, which provides the pricing details for the inputs and outputs of the order. If you trust the order server, you can primarily rely on this quote to validate the order’s pricing. However, it’s crucial to verify that the solver supports the specific origin chain (OrderDto.order.originChainId
) and output chains (OrderDto.order.orderData.outputs[...].chainId
) as well as their respective tokens (input[].token
andoutput[].token
). These parameters are guaranteed to be present across all order types. -
Solver-Exclusive Orders: Some orders may initially be restricted to specific solvers. This is indicated by the
OrderDto.order.orderData.verificationContract
field. If this field is defined and not equal toaddress(0)
, the order is exclusive to the designated solver until theslopeStartingTime
elapses, after which the order becomes available for anyone to fulfill. -
Mutually Exclusive Orders: Be aware of potential conflicts between orders. If you encounter two orders with the same
OrderDto.order.swapper
andOrderDto.order.nonce
, these orders are mutually exclusive, meaning only one of them can be submitted on-chain. This mechanism prevents double submissions and ensures the integrity of the order processing.
Evaluating orders carefully ensures that solvers can accurately determine the feasibility of executing an order, adhere to exclusivity rules, and avoid conflicts, thereby maintaining the integrity and efficiency of the order fulfillment process.