Chains
CoW Swap Integration
IBEX FI API β CoW Swap integration (quote β presign swap)
This guide describes the end-to-end flow to execute a swap via CoW Protocol with IBEX FI API: get a quote, prepare a Safe operation, WebAuthn (passkey) signing, and on-chain execution (approve + presign via setPreSignature).
Overview
- Fetch and persist a quote: GET
/v1.2/safes/quoteβ returnsquoteId - Prepare the Safe operation: POST
/v1.2/safes/operationswith\{ type: "SWAP_FROM_QUOTE", quoteId \}β returns WebAuthncredentialRequestOptions - Sign client-side using simplewebauthn
- Submit the operation: PUT
/v1.2/safes/operationswithcredentialβ performs approve +setPreSignature, returnsuserOpHash
Notes:
- The API uses an on-chain presign strategy: the order is sent to CoW, then the Safe signs on-chain via
setPreSignature(orderUid, true). - Idempotency: the API keeps an in-process
orderUidcache keyed by(safeAddress, quoteId)to avoid duplicate order creation (cache resets on redeploy). - Execution locks: a per-Safe lock prevents concurrent executions sharing the same nonce.
Prerequisites
- Authentication: JWT (see auth docs)
- Authorized domain rpId (table
Domain) - Existing Safe for the current user
- CoW environment variables configured:
COW_BASE_<chainId>``: CoW base URL for the target chainCOW_APPCODE,COW_ENV: AppData metadataCOW_SLIPPAGE_BPS_<DEFAULT_CHAIN_ID>``: default slippage in bipsCOW_PARTNER_ADDRESS_<DEFAULT_CHAIN_ID>``: main partner walletCOW_PARTNER_BIPS_<DEFAULT_CHAIN_ID>``: total partner fee bips- Optional per-domain (
Domain):wallet(partner),share(fraction 0..1 of the partner bips allocated to the domain) - On-chain execution contracts (used by the API):
COW_VAULT_RELAYER_<DEFAULT_CHAIN_ID>``COW_SETTLEMENT_<DEFAULT_CHAIN_ID>``
1) Get a CoW quote
Endpoint:
Query params:
sellTokenAddress(required): EVM address of the sell tokenbuyTokenAddress(required): EVM address of the buy tokenamount(required): human string amount (per sell token decimals)chainId(optional): defaults toEnv.DEFAULT_CHAIN_IDsafeAddress(optional): defaults to the first Safe of the current user
Response (example):
Curl example:
2) Prepare the Safe operation (SWAP_FROM_QUOTE)
Endpoint:
Body (example):
Response: WebAuthn options for passkey authentication
The client then signs using simplewebauthn:
3) Submit the operation (execution)
Endpoint:
Body:
Response:
Execution details (API side):
- Approve the sell token for the CoW vault relayer (
COW_VAULT_RELAYER_<DEFAULT_CHAIN_ID>``) - Call
setPreSignature(orderUid, true)on the settlement contract (COW_SETTLEMENT_<DEFAULT_CHAIN_ID>``) via MultiSend - Idempotency: if an
orderUidalready exists for(safe, quoteId), it is reused - Per-safe lock avoids βsame sender and nonceβ errors
Common errors
- 400: unknown tokens / missing metadata (BCReader), invalid parameters, unknown quoteId
- 401: missing/invalid JWT or unknown rpId
- 409: concurrent execution or duplicate nonce
- 422/500: blockchain constraints, on-chain failures
Best practices
- Always call
GET /v1.2/safes/quoteright before preparing to ensurevalidTofreshness - Use
X-Blockchain-Id(or?blockchainId) explicitly when multiple chains are supported - Ensure
COW_BASE_<chainId>`` is set for the target chain - Configure partner variables properly (appCode, env, bips, wallet) when fee sharing is needed