> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ambichain.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Routers and inboxes

> The destination router that takes payment, and the Ethereum inbox that believes only that router.

`src/outcomes/EvmOutcomes.sol`, `Optimistic.sol`, `Optimism.sol`, `Arbitrum.sol`, `Retryable.sol`.

## RemoteOrder

The filler passes this to the router. Every field must match the matched order, or the router computes a different statement.

| Field | Type | Value |
| - | - | - |
| `id` | `uint256` | Order ID on the market |
| `maker` | `address` | The maker |
| `offeredToken` | `address` | Escrow token on Ethereum |
| `offeredAmount` | `uint256` | Escrow amount |
| `filler` | `address` | The matched filler |
| `inbox` | `address` | The order's verifier on Ethereum |
| `token` | `address` | Payment token on the destination; `address(0)` for native |
| `recipient` | `address payable` | Who gets paid |
| `amount` | `uint256` | Payment amount |
| `payBy` | `uint64` | The deadline |

`Outcome` is `Pending` (0), `Paid` (1) or `ExpiredUnpaid` (2).

## OutcomeRouter

**pay(RemoteOrder order) payable** `matched filler`

Reverts with `InvalidOutcome` unless the caller is `order.filler`, it's before `payBy`, the amount is non-zero, and the recipient is non-zero and not the caller. Records Paid, transfers the exact amount (native via `msg.value`, ERC-20 via `transferFrom`, checking the recipient's balance rose by exactly the amount), and sends the outcome. Any native value beyond the payment is the message budget. Emits `Decided(statement, Paid)` and, for ERC-20s, `TokenPaid(statement, spent, received)`.

**payToken(RemoteOrder order, uint256 transferAmount, uint256 maxDebit) payable** `matched filler`

For tokens that take a fee on transfer. Transfers `transferAmount` and records Paid only if the recipient received at least `order.amount` (`InsufficientReceived`) and the caller was debited at most `maxDebit` (`DebitLimitExceeded`). `InvalidPaymentLimits` if `transferAmount` is below `order.amount` or above `maxDebit`. `msg.value` is the message budget.

**expire(RemoteOrder order) payable** `anyone`

Records ExpiredUnpaid at or after `payBy` and sends it. Emits `Decided(statement, ExpiredUnpaid)`.

**resend(RemoteOrder order) payable** `anyone`

Sends a recorded outcome again.

**statement(RemoteOrder order) view → bytes32** `view`

The statement for these inputs.

**outcomes(bytes32) view → Outcome** `view`

The recorded outcome.

Immutables: `ORIGIN_CHAIN`, `MARKET`, plus the messenger. Routers whose bridge charges nothing (`OptimismRouter`, `ArbitrumRouter`) revert with `InvalidOutcome` on a non-zero message budget.

## OutcomeInbox

**accepts(Request request) view → bool** `market`

True only when called by the market and the request names this inbox, `proveBy = 0`, a 20-byte non-zero recipient, 40 bytes of `routeData` naming this inbox's router, the chain string `eip155:<REMOTE_CHAIN>`, and an asset string matching the token in `routeData`.

**record(bytes32 statement, Outcome outcome)** `canonical messenger only`

Stores the outcome if the call is authenticated (below). Ignores a repeat of the same outcome; reverts `BadRoute` on a conflicting one or `Pending`. Emits `Recorded(statement, outcome)`.

**verify(bytes32 statement, bytes) view → bool** `view`

True when Paid is recorded.

**verifyExpired(bytes32 statement, bytes) view → bool** `view`

True when ExpiredUnpaid is recorded.

Immutables: `MARKET`, `REMOTE_ROUTER`, `REMOTE_CHAIN`, plus the messenger or bridge.

## OptimisticInbox

Adds bonded claims to an inbox. `settledOutcome(statement)` is the bridge's record if there is one, otherwise the outcome of an undisputed claim whose window has closed. `verify` and `verifyExpired` read it.

**claimPaid(uint256 id) payable / claimExpired(uint256 id) payable → bytes32 statement** `anyone`

Claims the outcome of a matched order on this inbox, with `msg.value == CLAIM_BOND` (`WrongBond` otherwise). One claim per statement. Expiry claims only at or after `payBy`. `ClaimUnavailable` if the order isn't matched on this inbox or the statement already has a claim or a record. Emits `Claimed(statement, id, claimant, outcome, deadline)`.

**dispute(bytes32 statement) payable** `anyone but the claimant`

Before the claim's deadline and while no record exists, with `msg.value == DISPUTE_BOND`. One dispute per claim. A disputed claim never settles by itself. Emits `Disputed(statement, disputer)`.

**resolve(bytes32 statement)** `anyone`

Releases bonds. Disputed: once the bridge's record exists, the side it agrees with is credited both bonds. Undisputed: after the window the claimant gets the bond back, unless a contradicting record arrived first, in which case the order's counterparty gets it. Emits `Resolved(statement, winner, amount, truth)`.

**withdrawBonds(address to)** `bond holder`

Sends your bond credit to `to`. Emits `BondWithdrawn(account, to, amount)`.

Immutables: `LIVENESS` (5 minutes to 1 day), `CLAIM_BOND`, `DISPUTE_BOND`. Views: `claims(statement)`, `bonds(account)`, `settledOutcome(statement)`.

## RetryableRouter and AliasedInbox

For a market on a Nitro rollup (Elysium) and a route on its parent chain (HyperEVM).

**quote(uint256 parentBaseFee, uint256 childMaxFeePerGas) view → uint256** `view`

The message budget for one ticket: the Inbox's submission fee plus `GAS_LIMIT × childMaxFeePerGas`. Pass 0 for the current parent base fee.

`_send` takes the submission fee from the budget and sets the ticket's fee cap from the rest, with refunds to the payer on Elysium. A budget that covers only the submission fee creates a ticket that anyone can redeem later. Emits `TicketCreated(statement, ticket, budget, maxFeePerGas)`. Immutables: `INBOX`, `GAS_LIMIT` (200,000 on Elysium).

`AliasedInbox` authenticates `record` with `msg.sender == ALIASED_ROUTER`, the router's address plus Nitro's alias offset `0x1111000000000000000000000000000000001111`.

## Adapters

| Contract | Sends or authenticates with |
| - | - |
| `OptimismRouter` | `MESSENGER.sendMessage(inbox, record(...), 150000)` |
| `OptimismInbox` | `msg.sender == MESSENGER` and `MESSENGER.xDomainMessageSender() == REMOTE_ROUTER` |
| `ArbitrumRouter` | `ARBSYS.sendTxToL1(inbox, record(...))` |
| `ArbitrumInbox` | `msg.sender == BRIDGE` and `BRIDGE.activeOutbox().l2ToL1Sender() == REMOTE_ROUTER` |
| `OptimismOptimisticInbox`, `ArbitrumOptimisticInbox` | The same as the inboxes above, plus bonded claims |
| `RetryableRouter` | `INBOX.createRetryableTicket(inbox, 0, submission, payer, payer, GAS_LIMIT, maxFeePerGas, record(...))` |
| `AliasedInbox` | `msg.sender == ALIASED_ROUTER` |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.