# Router flow

How a router runs a Maxy buy from quote to finality, who can send a refund, and what a sell asks of a router. It is for DEX aggregators, bridge routers and wallet SDKs. The overview: [For aggregators](https://maxy.co/docs/for-aggregators).

## Six steps

A router runs a Maxy buy in six steps.

1. Call `GET /quote` with the user's wallet and Bitcoin address.
2. Ask the wallet to sign each signature step: `intent` for ETH, BNB or AVAX; `witness`, plus `permit` when asked, for USDC. Check first that each step's typed data hashes to its `hash`.
3. Send the quote's `order` and the signatures, keyed by step id, to `POST /orders` within 60 seconds of the quote.
4. If `simulation.ok` is true, ask the wallet to send the transaction that comes back.
5. Call `POST /orders/submit` with the transaction hash, so a solver starts at once.
6. Track the order with `GET /status`, by `txHash` or by `orderId`. A USDC order has no user transaction, so track it by its order id, which is the quote's `quoteId`.

USDC on Base and Arbitrum skips steps 4 and 5: the user signs, and the solver opens the escrow and pays the gas.

What each step sends and answers, for ETH, BNB or AVAX:

| Step | Who or what | Details |
| --- | --- | --- |
| 1. Quote | `GET /quote` with `fromAddress` and `toAddress` | `order`, and `steps`: `intent`, `order`, `escrow` |
| 2. Sign | The paying wallet | The `intent` step's `typedData`: EIP-712, domain `BitcoinIntentSettler` version `6`. Check it hashes to the step's `hash`. No gas |
| 3. Place | `POST /orders` with `{ order, signatures: { intent } }` | Within 60 seconds of the quote, or `409 quote_expired` with a fresh quote in `details.freshQuote`. Answers `transaction` (`to` the settler, `data`, `value`, `from`), `simulation` and `next` |
| 4. Send | The paying wallet | `transaction`, only if `simulation.ok` is true. `openNativeBuyIntent` accepts only the wallet that signed as sender |
| 5. Hand over | `POST /orders/submit` with `next.body` plus `txHash` | The solver starts at once. Answers `notified` and the status path |

Step 5 checks the order again: unchanged from its quote, its intent's deadline still ahead, and a buy within your key's cap and what the solver fills now. Otherwise it answers `400` or `422` and the escrow is not handed on: `POST /orders/{id}/cancel` takes it back.

An order whose escrow transaction is never sent lapses at the intent's deadline, 2 hours after the quote: `expiresAt` in the step 3 answer. On USDC (`evm-btc-gasless`), step 3 answers `submitted: true` and the user sends nothing: the solver opens the escrow and pays its gas. The same steps with code: [Buy BTC](https://maxy.co/docs/buy-btc#sign).

## Finality

For routers: a Maxy buy reads `completed` the moment the Bitcoin is sent, so your user sees it move at once. Report the transfer as final when `btcConfirmations` reaches 1, about 10 minutes later. Until then the solver may replace the payment with one of the same amount to the same address, and `btcTxId` changes to match.

## Refunds

Refunds are open and permissionless. Once a deadline passes, anyone can send the cancel, slash or refund call, and the coins can go only to the user. No Maxy server is needed, and none can stop it. A third party that sends a slash earns half the solver's bond, and a user who sends it keeps the whole bond. Routers can send these calls for their users: `GET /orders/{id}/refund` and `POST /orders/{id}/cancel` build the transaction for any sending wallet. Who sends them in practice: [When it fails](https://maxy.co/docs/when-it-fails#refunds).

## Selling BTC

For routers: a Maxy sell is built for safety first. The payout is locked on chain for the user before any Bitcoin is sent. That adds two steps to plan for. The receiving EVM wallet signs the sell intent, and the deposit address appears once the solver has locked the payout. The user then pays the exact amount, in one output, within 19 Bitcoin blocks. Routers can integrate buys first and add sells once both wallets are connected in their flow. A payment that misses the amount or the window is returned under the [mispaid-sell policy](https://maxy.co/docs/mispaid-sells#the-mispaid-sell-policy). The steps compared with a Bitcoin-first router flow: [Sell BTC](https://maxy.co/docs/sell-btc#for-routers).

---
Source: https://maxy.co/docs/router-flow (Maxy Docs › Maxy for your app › Use cases)
