Flow
BaiBai uses a gasless order flow:- List supported tokens.
- Request a quote.
- Check quote expiry.
- Make sure the sell token is approved for Permit2.
- Ask the user to sign the returned EIP-712 typed data.
- Submit the quote ID, signature, and optional
clientOrderId. - Poll order status until it is terminal.
Only EIP-712 gasless orders are supported today. Traditional/non-gasless orders are coming soon.
Quote
Request quotes with token base-unit amounts as decimal strings.kind: "buy" and buyAmountAfterFee.
Quote Expiry
Every quote has two expiry fields:expiration: ISO timestamp for the quote object.quote.validTo: Permit deadline in Unix seconds.
POST /orders returns an expired-quote error, request a fresh quote and signature.
Routing Controls
routingPreference is optional:
| Value | Meaning |
|---|---|
auto | Default. Choose the best available route. May use BaiBai Prop AMM liquidity, external liquidity, or a split route. |
preferBaiBai | Prefer BaiBai Prop AMM liquidity when it is competitive with the best available route. |
onlyBaiBai | Only quote BaiBai Prop AMM liquidity. If BaiBai has no route or enough liquidity, the quote fails. |
auto unless your integration has a reason to bias execution.
Approvals
For ERC-20 sell tokens, the user must approve Permit2 before signing/submitting. Approvequote.permit2.allowanceTarget for at least quote.quote.sellAmount:
quote.permit2.allowanceTarget is the Permit2 contract that receives the ERC-20 approval. quote.permit2.spender is the BaiBai settlement spender included in the signed typed data. Do not approve spender directly for Permit2 allowance checks.Signing
Sign thepermit2.typedData object returned by /quote exactly as-is.
PermitWitnessTransferFrom signature with this BaiBai witness:
Submit
Submit the quote ID and signature. IncludeclientOrderId when you need idempotency across retries.
clientOrderId was already accepted for the same owner, BaiBai returns the existing order instead of creating a duplicate.
Polling
PollGET /orders/{orderId} until the status is terminal.
| Status | Meaning | Terminal |
|---|---|---|
pending | Order accepted and executing. | No |
filled | Order completed. | Yes |
failed | Order failed. | Yes |
expired | Quote/signature expired before fill. | Yes |
Native ETH
ETH is not a gasless order token. Use WETH in quote and order requests.- Swapping from ETH: request an indicative quote with WETH as the sell token, then wrap ETH to WETH before signing/submitting.
- Swapping to ETH: quote and buy WETH, then unwrap WETH after fill.
- BaiBai does not wrap or unwrap for integrators.
0x4200000000000000000000000000000000000006
Retry Guidance
| Situation | What to do |
|---|---|
429 RATE_LIMITED | Wait for retry-after, then retry. |
| Quote expired | Request a fresh quote and signature. |
| Invalid signature | Re-sign the exact latest permit2.typedData. |
pending order | Keep polling. Do not submit a second order unless you use the same clientOrderId. |
| Unknown order ID | Verify the ID from POST /orders; otherwise treat it as terminal for that poll request. |
Related Docs
API Reference
Endpoint fields, examples, errors, rate limits, and OpenAPI.
Wallet Integration
Wallet-side Permit2, signing, polling, and ETH/WETH examples.
BaiBai Overview
Product overview and architecture.