# Cow Protocol Sdk

> CoW Protocol SDK — TypeScript monorepo for intent-based DEX trading with MEV protection. Coincidence of Wants (CoW): batch auction matching, solver network finds optimal routes. Order types: market, limit, TWAP (composable). 14 packages covering trad

- **Type:** Skill
- **Install:** `agentstack add skill-mahmoud20138-tradecraft-cow-protocol-sdk`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [mahmoud20138](https://agentstack.voostack.com/s/mahmoud20138)
- **Installs:** 0
- **Category:** [Finance & Payments](https://agentstack.voostack.com/c/finance-and-payments)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [mahmoud20138](https://github.com/mahmoud20138)
- **Source:** https://github.com/mahmoud20138/Tradecraft/tree/main/plugins/tradecraft/skills/cow-protocol-sdk

## Install

```sh
agentstack add skill-mahmoud20138-tradecraft-cow-protocol-sdk
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# cow-protocol-sdk

USE FOR:
  - "CoW Protocol / CoW Swap integration"
  - "MEV-protected DeFi trading"
  - "intent-based DEX order"
  - "TWAP on-chain order"
  - "limit order on DEX (crypto)"
  - "cross-chain swap / bridge"
  - "batch auction solver trading"
  - "TypeScript DeFi trading SDK"
tags: [CoW-Protocol, DeFi, DEX, MEV-protection, TWAP, limit-order, intent-based, Ethereum, TypeScript, solver, batch-auction]
kind: sdk
category: crypto-defi-trading

---

## What Is CoW Protocol?

Intent-based trading protocol with MEV protection via batch auctions and solver network.

- Repo: https://github.com/cowprotocol/cow-sdk
- Docs: docs.cow.fi
- Interface: swap.cow.fi (CoW Swap)
- Model: **Coincidence of Wants** — direct peer-to-peer matching when possible

### How CoW Works

```
User submits signed intent (not on-chain tx)
         ↓
Solver network competes to find best execution:
  Option A: CoW match   → peer-to-peer, no AMM needed (best price)
  Option B: AMM route   → Uniswap/Curve/etc. (fallback)
  Option C: Aggregator  → 1inch/Paraswap route
         ↓
Best solver wins batch auction → executes on-chain
User gets guaranteed price or better (surplus → user)
```

**MEV Protection**: Orders are signed intents, not on-chain txs → front-running impossible.
**Surplus**: Any price improvement beyond quoted amount goes back to the user.

---

## Supported Networks

Ethereum · BNB Chain · Gnosis Chain · Polygon · Base · Arbitrum One · Avalanche · Linea · Ink · Sepolia (testnet)

---

## Package Architecture (14 packages)

| Package | Purpose |
|---------|---------|
| `@cowprotocol/cow-sdk` | Main entry point (re-exports all) |
| `@cowprotocol/sdk-trading` | High-level: quote → sign → post |
| `@cowprotocol/sdk-order-book` | OrderBook API client (get/post orders) |
| `@cowprotocol/sdk-order-signing` | Cryptographic signing utilities |
| `@cowprotocol/sdk-composable` | Programmatic orders: TWAP, conditional |
| `@cowprotocol/sdk-bridging` | Cross-chain token transfers |
| `@cowprotocol/sdk-cow-shed` | Account abstraction support |
| `@cowprotocol/sdk-viem-adapter` | Viem provider adapter |
| `@cowprotocol/sdk-ethers-v6-adapter` | Ethers v6 adapter |
| `@cowprotocol/sdk-ethers-v5-adapter` | Ethers v5 adapter |
| `@cowprotocol/sdk-app-data` | Order metadata / app data |
| `@cowprotocol/sdk-config` | Chain/environment config |
| `@cowprotocol/sdk-contracts-ts` | Type-safe contract ABIs |
| `@cowprotocol/sdk-subgraph` | GraphQL subgraph queries |

---

## Installation

```bash
npm install @cowprotocol/cow-sdk
# or
pnpm add @cowprotocol/cow-sdk
```

---

## Core Usage: Quote → Sign → Post

```typescript
import { TradingSdk, SupportedChainId, OrderKind } from "@cowprotocol/cow-sdk"
import { createWalletClient, http } from "viem"
import { privateKeyToAccount } from "viem/accounts"
import { mainnet } from "viem/chains"

// Setup
const account = privateKeyToAccount("0x...")
const walletClient = createWalletClient({ account, chain: mainnet, transport: http() })

const sdk = new TradingSdk({
  chainId: SupportedChainId.MAINNET,
  signer: walletClient,
})

// 1. Get quote
const quote = await sdk.getQuote({
  kind: OrderKind.SELL,
  sellToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH
  buyToken:  "0x6B175474E89094C44Da98b954EedeAC495271d0F", // DAI
  amount: "1000000000000000000", // 1 WETH (18 decimals)
})

console.log(`Quote: sell 1 WETH → get ${quote.buyAmount} DAI`)

// 2. Post order (sign + submit in one step)
const orderId = await sdk.postSwapOrder({
  ...quote,
  slippageBps: 50, // 0.5% slippage tolerance
})

console.log(`Order posted: ${orderId}`)
// Track at: https://explorer.cow.fi/orders/${orderId}
```

---

## Order Types

### Market Order (Swap)
```typescript
// Execute immediately at best available price
const orderId = await sdk.postSwapOrder({
  kind: OrderKind.SELL,
  sellToken: WETH,
  buyToken: DAI,
  amount: parseEther("1"),
  slippageBps: 50,
})
```

### Limit Order
```typescript
// Execute only when price reaches target
const orderId = await sdk.postLimitOrder({
  kind: OrderKind.SELL,
  sellToken: WETH,
  buyToken: DAI,
  sellAmount: parseEther("1"),
  buyAmount: parseUnits("3200", 18), // Only fill if 1 WETH ≥ 3200 DAI
  validTo: Math.floor(Date.now() / 1000) + 86400, // expires in 24h
})
```

### TWAP (Time-Weighted Average Price)
```typescript
import { buildTWAPOrder } from "@cowprotocol/sdk-composable"

// Split 10 WETH into 10 parts over 24 hours
const twapOrder = buildTWAPOrder({
  sellToken: WETH,
  buyToken: DAI,
  totalSellAmount: parseEther("10"),
  numberOfParts: 10,
  timeBetweenParts: 2 * 60 * 60, // every 2 hours
  span: 0,                         // execute anytime within each window
})

const orderId = await sdk.postComposableOrder(twapOrder)
```

---

## OrderBook API (Direct)

```typescript
import { OrderBookApi, SupportedChainId } from "@cowprotocol/cow-sdk"

const orderBook = new OrderBookApi({ chainId: SupportedChainId.MAINNET })

// Get all open orders for a wallet
const orders = await orderBook.getOrders({ owner: "0x..." })

// Get order status
const order = await orderBook.getOrder(orderId)
console.log(order.status) // "open" | "fulfilled" | "cancelled" | "expired"

// Cancel an order
await orderBook.cancelOrder(orderId, signature)
```

---

## Cross-Chain Bridging

```typescript
import { BridgingSdk } from "@cowprotocol/sdk-bridging"

const bridge = new BridgingSdk({ chainId: SupportedChainId.MAINNET })

// Bridge USDC from Ethereum → Arbitrum
const bridgeOrder = await bridge.postBridgeOrder({
  sellToken: USDC_MAINNET,
  buyToken: USDC_ARBITRUM,
  amount: parseUnits("1000", 6),
  targetChainId: SupportedChainId.ARBITRUM_ONE,
})
```

---

## Key Advantages Over Standard DEX Aggregators

| Feature | CoW Protocol | 1inch / Paraswap |
|---------|-------------|-----------------|
| MEV Protection | ✓ (signed intents) | ✗ (on-chain txs) |
| Surplus to user | ✓ (price improvement) | ✗ (keeper keeps it) |
| Peer-to-peer matching | ✓ (CoW mechanism) | ✗ |
| TWAP orders | ✓ (composable) | Limited |
| Limit orders | ✓ | ✓ |
| Gas costs | Lower (batched) | Standard |

---

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [mahmoud20138](https://github.com/mahmoud20138)
- **Source:** [mahmoud20138/Tradecraft](https://github.com/mahmoud20138/Tradecraft)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-mahmoud20138-tradecraft-cow-protocol-sdk
- Seller: https://agentstack.voostack.com/s/mahmoud20138
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
