Swap / DEX·EVM
CoW Swap (CoW Protocol)
Meta-DEX with batch auctions, Coincidence-of-Wants matching, and MEV-protected RFQ via competing solvers. Users sign off-chain orders; solvers settle them on-chain in batches.
- 01MEV-protected swaps
- 02gasless / signed-order flow
- 03large-size trades with price improvement
- 04limit orders and TWAP
- 05EVM order flow auctions
- pnpm add @cowprotocol/cow-sdk
| Variable | Scope | Description |
|---|---|---|
| NEXT_PUBLIC_COW_APP_CODE | Client | App identifier string written into the order's `appData` for analytics and partner attribution. Any short string; register a richer appData document via the appData hub for hooks/referrals. |
Use CoW Protocol for MEV-protected swaps via signed orders. Initialize `const orderBookApi = new OrderBookApi({ chainId: SupportedChainId.MAINNET, env: 'prod' })` from `@cowprotocol/cow-sdk`. Quote: `orderBookApi.getQuote({ sellToken, buyToken, sellAmountBeforeFee, from, kind: OrderQuoteSideKindSell.SELL })`. Sign the EIP-712 `Order` struct with the user's wallet (or use `OrderSigningUtils.signOrder`). Submit: `orderBookApi.sendOrder({ ...order, signature, signingScheme: SigningScheme.EIP712 })`. Tokens must be approved to the GPv2VaultRelayer (per chain). Supported chains: Ethereum, Gnosis, Arbitrum, Base, Sepolia.
- ⚑Approvals go to the **GPv2VaultRelayer**, not the Settlement contract — approving the wrong address means orders are placed but never settle.
- ⚑Settlement latency is batch-driven (typically 30s–a few minutes) — orders are not instant; UI must show a `pending → fulfilled / expired / cancelled` state machine.
- ⚑Partial fills are off by default; set `partiallyFillable: true` only if your UX explicitly handles partial settlement.
- ⚑Fees are deducted from `sellAmount` (sell orders) or added to `sellAmount` (buy orders) — quote returns `feeAmount`; pass `sellAmountBeforeFee` correctly or the order signs the wrong notional.
- ⚑ETH cannot be sold directly (CoW is ERC20-only) — wrap to WETH first or use the CoW EthFlow contract; buy-side native ETH is supported via the Settlement's unwrap hook.
- ⚑On-chain (smart-contract) wallets must use EIP-1271 (`SigningScheme.EIP1271`) and pre-sign or implement `isValidSignature` — EOA EIP-712 flow won't work for Safe / Argent / 4337 accounts.
- ⚑Chain coverage is limited (Ethereum, Gnosis, Arbitrum, Base, Sepolia) — don't assume coverage matches a generic EVM aggregator.