Before the router can pullDocumentation Index
Fetch the complete documentation index at: https://docs.o1.exchange/llms.txt
Use this file to discover all available pages before exploring further.
tokenIn from a user, the user must approve the router as a spender. This is standard ERC-20 behavior. The aggregator supports two patterns:
- Standard
approve+ swap — two transactions, but works for any ERC-20. - EIP-2612 permit + swap — one transaction, but only works for tokens that implement the permit extension.
No approval is needed when
tokenIn is native ETH (using the sentinel 0xEeee...EEeE or 0x0). In that case, the router pulls value via msg.value. See Native ETH.Pattern 1: standard approve
This is the universal fallback. Two transactions per first swap, then no approvals on subsequent swaps if the previous allowance is large enough.
Approve amount strategies
- Approve exact amount (recommended)
- Approve max (least friction)
- Approve a buffered amount
Approve exactly
amountIn. Re-approves on every swap. Safest from a security standpoint — the router only ever has rights to the exact amount being swapped.Pattern 2: EIP-2612 permit (one transaction)
For tokens that implement EIP-2612 (USDC and a growing number of others on Base), the user can sign an off-chain permit that the router consumes inside the same transaction as the swap. Net effect: one signature, one transaction, noapprove step.
How it works
Build the permit typed data
Read the token’s
name, EIP712_VERSION, and the user’s nonces(user). Construct the EIP-712 domain and message.User signs the permit off-chain
Use
signTypedData (eth_signTypedData_v4). No gas, no on-chain state change.Example
/submit:
Detecting permit support
Not every token implements EIP-2612. The cheapest way to detect support is to readnonces(user) on the token and treat a successful read as a positive signal. Tokens without permit will revert.
approve automatically when permit support is missing.
Security checklist
Always approve the router only
The approval target is always the canonical
O1Router address: 0xe56e22354DDdc07cF2dfbCFb53a90fB0a56E50D5. Reject any UI that asks you to approve a different address while using this API.Verify the spender on the response
submit.to should equal the router address. If it doesn’t, abort and report.Respect deadlines on permits
Use a short deadline (5 to 15 minutes). Don’t sign permits with deadlines hours in the future — they’re a long-lived approval risk if the signature leaks.
Don't reuse permits
Each permit signature consumes a
nonce. Don’t try to bundle multiple swaps under a single permit.