agentsclimarketplace

Cow protocol sdk

Skill mahmoud20138/Tradecraft/plugins/tradecraft/skills/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 tradFrom its SKILL.md

Install
npx -y skills add mahmoud20138/Tradecraft --skill cow-protocol-sdk

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 18 stars18 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

6.5 KB, ~1.7k tokens by cl100k_base, as published. Nobody here has run it

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.

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)

PackagePurpose
@cowprotocol/cow-sdkMain entry point (re-exports all)
@cowprotocol/sdk-tradingHigh-level: quote → sign → post
@cowprotocol/sdk-order-bookOrderBook API client (get/post orders)
@cowprotocol/sdk-order-signingCryptographic signing utilities
@cowprotocol/sdk-composableProgrammatic orders: TWAP, conditional
@cowprotocol/sdk-bridgingCross-chain token transfers
@cowprotocol/sdk-cow-shedAccount abstraction support
@cowprotocol/sdk-viem-adapterViem provider adapter
@cowprotocol/sdk-ethers-v6-adapterEthers v6 adapter
@cowprotocol/sdk-ethers-v5-adapterEthers v5 adapter
@cowprotocol/sdk-app-dataOrder metadata / app data
@cowprotocol/sdk-configChain/environment config
@cowprotocol/sdk-contracts-tsType-safe contract ABIs
@cowprotocol/sdk-subgraphGraphQL subgraph queries

Installation

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

Core Usage: Quote → Sign → Post

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)

// 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

// 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)

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)

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

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

FeatureCoW Protocol1inch / 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 costsLower (batched)Standard

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 610,677. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.