# Router

To enable cross-chain communications among a vast number of chains, iLayer employs both Axelar and LayerZero.

On each chain, a specific Router supporting either one or both of these bridging solutions will be deployed, with the plan to add support for more (Chainlink's CCIP, Across, Everclear) in the near future.

Contracts that can call the router must be whitelisted, this is to block eventual attackers from accessing the priviledged message routing infrastructure as well as to prevent polluting the event log for the Router contracts.

When invoking the Hub or the Spoke smart contracts, the user can decide which bridge to use via a specific `Bridge` enum argument. Currently available options are:

* `NULL` same-chain execution without any bridging, **sourceChainID** must match **destinationChainID**&#x20;
* `LAYERZERO` [only for Lz-supported chains](https://docs.layerzero.network/v2/deployments/deployed-contracts)
* `AXELAR` [only for Ax-supported chains](https://www.axelar.network/ecosystem#chains)

The `BaseRouter` is essentially an interface that defines a generic “cross-chain message router” that lets callers send arbitrary payloads to other chains via various bridge protocols. OrderHubs and Spokes pass in a `Message` struct (which encodes which bridge to use, the target chain ID and receiver address, the payload bytes, any extra data and the sender) and the router emits an event when it’s broadcast or reverts if the route is not supported.

**Key functionality**

* **Bridges supported**: an enum of possible cross-chain bridges (`LAYERZERO`, `AXELAR`, `CCIP`, etc.)
* **send(...)**: payable function to dispatch `Message` via the chosen bridge
* **Message struct**: bundles all routing info plus arbitrary payload

***

#### Events

| Event                | Parameters                                                    | Description                                                                                                                             |
| -------------------- | ------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| `MessageBroadcasted` | `Message message`                                             | Emitted after a message is successfully enqueued for bridging, contains the full `Message` struct so off-chain relayers can pick it up. |
| `WhitelistUpdated`   | `address indexed target, bool previousStatus, bool newStatus` | Registers an update to the whitelist of contracts that can access the router.                                                           |

***

#### Errors

| Error                        | When It’s Thrown                                                                                                      |
| ---------------------------- | --------------------------------------------------------------------------------------------------------------------- |
| `UnsupportedBridgingRoute()` | Caller specified a `Bridge` enum value that this router hasn’t implemented (e.g. `Bridge.WORMHOLE` if unimplemented). |
| `NotWhitelisted`             | The contract trying to interact with the router is not whitelisted.                                                   |

***

**Structs & Enums (for reference)**

```solidity
enum Bridge {
    NULL,        // same chain
    LAYERZERO,   // LayerZero bridge
    AXELAR,      // Axelar bridge
    CCIP,        // Chainlink CCIP
    ACROSS,      // Across Protocol
    EVERCLEAR,   // Everclear
    WORMHOLE     // Wormhole bridge
}

struct Message {
    Bridge bridge;        // which bridge to use
    uint32 chainId;       // destination chain ID
    bytes32 destination;  // recipient’s address on the dest chain
    bytes payload;        // arbitrary data to deliver
    bytes extra;          // bridge-specific extra data
    bytes32 sender;       // sender encoded addr
}
```

In a nutshell: you call `send(...)` with a `Message`, pay any required fee and if the chosen bridge is supported the router emits `MessageBroadcasted`; otherwise it reverts with `UnsupportedBridgingRoute()`.


---

# Agent Instructions: 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:

```
GET https://docs.ilayer.io/router.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
