User flows and examples / Quotes
Approvals and permits
Which coins need an allowance before an order, how a quote says so, and how the wallet gives it. For anyone who builds the steps between a quote and the order: wallets, frontends and backends that sign for themselves.
| Paying with | Allowance | What the wallet does |
|---|---|---|
| ETH, BNB, AVAX | None | The escrow transaction carries the value |
| USDC on Base and Arbitrum | Permit2, by signature | Signs a permit when Permit2's allowance is short, then a witness. No transaction, no gas |
| A token, coin to coin | The bridge contract, by transaction | Sends approve for exactly the amount, and waits for it to confirm |
| BTC, selling | None | The EVM wallet signs one sell order; the BTC goes out in one payment |
How a quote says so
Every quote lists its steps in order. An allowance shows in three places:
issues.allowance:{ spender, token, expected }, when the allowance is short.- A step with
idapprove(orapprove-resetfirst, for a token that refuses a new allowance over an old one), of kindtransaction. signing.approval: the same transaction, to send and confirm before anything is signed.
A permit is a signature step, like the order itself. Sign it with the other signature steps and post it in signatures under its id.
To try the transaction branch, quote with scenario=needs_approval. The sandbox adds an approve step and issues.allowance to any quote, and its transaction is simulated: never send it. The samples use the setup from Get a quote.
curl -s -G "$BASE/quote" -H "x-maxy-key: $MAXY_API_KEY" --data-urlencode "from=USDC on base" -d to=BTC -d amount=20 \ -d fromAddress="$WALLET" -d toAddress="$MY_BTC_ADDRESS" -d scenario=needs_approval > quote.json jq '{allowance: .issues.allowance, steps: [.steps[] | {id, kind}]}' quote.json
Follow the steps in order
Send each approval and wait for it to confirm, then sign every signature step, then post the order. The same loop handles a quote with no approval.
import { createPublicClient } from 'viem'; const publicClient = createPublicClient({ chain: base, transport: http() }); const q = new URLSearchParams({ from: 'USDC on base', to: 'BTC', amount: '20', fromAddress: account.address, toAddress: btcAddress, scenario: 'needs_approval' }); const quote = await fetch(`${BASE}/quote?${q}`, { headers: { 'x-maxy-key': KEY } }).then((r) => r.json()); const signatures: Record<string, string> = {}; for (const step of quote.steps) { if (step.kind === 'transaction' && step.id.startsWith('approve')) { const tx = step.transaction; if (tx.simulated) continue; // a sandbox transaction: never send it const hash = await walletClient.sendTransaction({ to: tx.to, data: tx.data, value: BigInt(tx.value) }); await publicClient.waitForTransactionReceipt({ hash }); // it must confirm before the signatures } else if (step.kind === 'signature') { if (hashTypedData(step.typedData) !== step.hash) throw new Error(`step ${step.id} does not hash to ${step.hash}`); signatures[step.id] = await walletClient.signTypedData(step.typedData); } } const placed = await fetch(`${BASE}/orders`, { method: 'POST', headers: { 'x-maxy-key': KEY, 'content-type': 'application/json' }, body: JSON.stringify({ order: quote.order, signatures }), }).then((r) => r.json()); console.log(Object.keys(signatures), placed.orderId, placed.submitted); // [ 'witness' ] 0x53414e44… true
The USDC permit
Paying in USDC on Base or Arbitrum, the wallet signs at most two messages. The permit is an EIP-2612 permit for Permit2, for exactly this order's USDC, and is skipped when the Permit2 allowance already covers the order. The witness is a Permit2 transfer bound to the order id, covering the settlement amount plus the price band. The solver submits the escrow and pays its gas. If it never does, the signature lapses 2 hours after the quote and the USDC never leaves the wallet.
Permit2 is 0x000000000022D473030F116dDEE9F6B43aC78BA3 on every chain. Check each typed message against its step's hash before the wallet opens, as above: nothing is signed if they differ.
When the wallet says no
| Case | Do |
|---|---|
The user declines (4001, user_rejected) | Nothing was signed: go back to the confirm screen |
| An approval reverts | Nothing was escrowed. Quote again |
issues.balance is set | The wallet holds less than the order: show what is missing |
| Over 60 seconds since the quote | 409 quote_expired: quote again and follow the new quote's steps |
The flow helpers do all of this for you, approvals included: Flow helpers. Each route's own page: Pay with USDC, Coin to coin.