> 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/orderspoke.md).

# OrderSpoke

The `OrderSpoke` smart contract acts as a decentralized mechanism to securely manage order fills and handle token transfers from solver entities directly to users.

Upon creation, it instantiates an `Executor` contract responsible to execute the hooks in a safe way.

The main tasks of the order spoke are:

* **Order Validation:** Ensures orders meet conditions such as expiration deadlines, duplication prevention and primary filler restrictions.
* **Funds Transfer:** Handles secure transfers of output tokens from the solver to the user.
* **Hooks Execution:** Executes additional external calls if specified in the order.
* **Cross-chain Settlement:** Sends confirmation messages to the originating chain OrderSpoke upon successful order fill.

**TL;DR**\
The `OrderSpoke` contract is part of a cross-chain order fulfillment system. It receives “pending” order notifications from a central hub (via `onMessageReceived`), allows an off-chain solver to fill those orders with exactly the right funds and call data (`fillOrder`), manages fee deductions, executes an optional callback on fulfillment, and then relays a response back to the source chain’s hub. It also lets the owner sweep stranded tokens and update configuration settings (hub addresses and fee rate).

***

### Events

| Event                  | Parameters                                                                                                                                          | Description                                                                                                      |
| ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
| `HubUpdated`           | <p><code>chainId</code><br><code>oldHubAddr</code><br><code>newHubAddr</code></p>                                                                   | Emitted when the owner changes the hub address for a given chain.                                                |
| `FeeUpdated`           | <p><code>oldFee</code> (indexed)<br><code>newFee</code> (indexed)</p>                                                                               | Emitted when the owner updates the per-order fee rate (in basis-points out of 10 000).                           |
| `PendingOrderReceived` | <p><code>orderId</code> (indexed)<br><code>spokeChainId</code> (indexed)</p>                                                                        | Emitted when a new order arrives from a hub on another chain and is marked PENDING.                              |
| `OrderFilled`          | <p><code>orderId</code> (indexed)<br><code>order</code><br><code>caller</code> (indexed)</p>                                                        | Emitted after successfully filling an order: funds transferred, callback called (if any), and message sent back. |
| `TokenSweep`           | <p><code>tokenType</code> (indexed)<br><code>tokenId</code><br><code>token</code> (indexed)<br><code>to</code> (indexed)<br><code>amount</code></p> | Emitted when the owner sweeps tokens/ETH out of the contract for arbitrary token types.                          |

***

### Errors

| Error                                                                     | Description                                                                                                      |
| ------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
| `UndefinedHub()`                                                          | Thrown if there is no configured hub address for the chain where the order originated or is destined.            |
| `InvalidFeeValue()`                                                       | Thrown if the owner tries to set a fee greater than the maximum resolution (10 000 basis-points).                |
| `InvalidOrder()`                                                          | Thrown if an order ID is unrecognized (never registered as PENDING).                                             |
| `OrderAlreadyFilled()`                                                    | Thrown if attempting to fill an order that’s already marked FILLED.                                              |
| `OrderExpired()`                                                          | Thrown if the block timestamp has passed the order’s `deadline` field.                                           |
| `InvalidDestinationChain()`                                               | Thrown if the order’s `destinationChainId` doesn’t match the current chain.                                      |
| `RestrictedToPrimaryFiller()`                                             | Thrown if a specific primary filler is designated and only that address can fill before its own deadline.        |
| `ExternalCallFailed()`                                                    | Thrown if the optional callback (hook) execution fails inside the `Executor`.                                    |
| <p><strong>Inherited</strong>:<br><code>InsufficientGasValue()</code></p> | Thrown if the sender didn’t supply enough native ETH to cover the order’s declared `callValue` or output amount. |
