> For the complete documentation index, see [llms.txt](https://docs.ilayer.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ilayer.io/hub-and-spoke/orderhub.md).

# OrderHub

The `OrderHub` contract manages user orders and custody of tokens until orders are filled, withdrawn, or expired. It acts as a gateway for off-chain orders, allowing users (or their solver bot delegates for gasless execution) to submit orders by providing a signed order request. Each order request comes with a nonce to prevent order creation replay, orders themselves are signed by the user using the EIP712 standard or the EIP165 for smart contract signatures.

Data coming from the RFQ stream is fed into the order intent and signed by the user, then broadcasted to the designated solver for execution or the order directly created by the user on-chain.

**TL;DR**\
The OrderHub contract is a cross-chain “order book” that lets users create off-chain orders with ERC-20/ERC-721/ERC-1155/NATIVE tokens, lock their assets in this contract and send a message via a router to a counterparty settlement contract (the `OrderSpoke`) sitting on another chain. Once the counter-party funds and the router relays back, the contract releases the assets to the designated recipient. Users can also withdraw unfilled orders after a buffer period. Order checks enforce nonce unicity, deadlines, token approvals/permits and reentrancy protection.

***

### Events

| Event                       | Parameters                                                  | Description                                                                                 |
| --------------------------- | ----------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
| **SpokeUpdated**            | `chainId`, `oldSpokeAddr`, `newSpokeAddr`                   | Emitted when the owner changes the destination “spoke” address for a given chain.           |
| **TimeBufferUpdated**       | `oldTimeBufferVal`, `newTimeBufferVal` (indexed)            | Emitted when the owner adjusts the extra time users have to withdraw expired orders.        |
| **MaxOrderDeadlineUpdated** | `oldDeadline`, `newDeadline` (indexed)                      | Emitted when the owner sets a new maximum span users may set for an order’s deadline.       |
| **OrderCreated**            | `orderId` (indexed), `nonce`, `Order order`, `caller` (idx) | Emitted when a user successfully creates (locks) an order and it’s sent through the router. |
| **OrderWithdrawn**          | `orderId` (indexed), `caller` (indexed)                     | Emitted when a user withdraws their active order and assets are returned.                   |
| **OrderSettled**            | `orderId` (indexed), `Order order`                          | Emitted when the router calls back to settle (fill) the order and assets are forwarded.     |
| **ERC721Received**          | `operator`, `from`, `tokenId`, `data`                       | Emitted when this contract receives an ERC-721 token via `safeTransferFrom`.                |
| **ERC1155Received**         | `operator`, `from`, `id`, `value`, `data`                   | Emitted when this contract receives a single ERC-1155 token via `safeTransferFrom`.         |
| **ERC1155BatchReceived**    | `operator`, `from`, `ids`, `values`, `data`                 | Emitted when this contract receives multiple ERC-1155 tokens via `safeBatchTransferFrom`.   |

***

### Errors

| Error                          | Description                                                                                     |
| ------------------------------ | ----------------------------------------------------------------------------------------------- |
| **RequestNonceReused**         | The user’s off-chain order request nonce has already been used.                                 |
| **RequestExpired**             | The off-chain order request deadline (for signature validity) has passed.                       |
| **UndefinedSpoke**             | No spoke address is set for the order’s destination chain.                                      |
| **InvalidOrderInputApprovals** | The number of input tokens doesn’t match the number of provided permit blobs.                   |
| **InvalidOrderSignature**      | The order’s EIP-712 signature failed to validate against the user’s address.                    |
| **InvalidDeadline**            | The order’s deadline exceeds the configured maximum span.                                       |
| **InvalidSourceChain**         | The on-chain `block.chainid` doesn’t match the order’s declared source chain.                   |
| **InvalidDestinationChain**    | The callback from the router came from an unexpected chain (shouldn’t happen in normal flow).   |
| **OrderDeadlinesMismatch**     | The primary-filler deadline is after the overall order deadline.                                |
| **OrderPrimaryFillerExpired**  | The time window for the primary filler has elapsed before the order expires.                    |
| **OrderCannotBeWithdrawn**     | Conditions to withdraw (wrong caller, still within buffer window, or non-active status) failed. |
| **OrderCannotBeFilled**        | Conditions to settle (wrong status) failed when router callback arrives.                        |
| **OrderExpired**               | The order’s deadline has passed before creation or settlement.                                  |
| **InsufficientGasValue**       | The user didn’t send enough native (ETH) value to cover the declared input amount.              |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.ilayer.io/hub-and-spoke/orderhub.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
