Skip to content

feat(polymarket): migrate to CLOB V2 SDK, pUSD collateral, and V2 exchange contracts#106

Merged
JamesLawton merged 1 commit intomainfrom
feat/polymarket-clob-v2
Apr 28, 2026
Merged

feat(polymarket): migrate to CLOB V2 SDK, pUSD collateral, and V2 exchange contracts#106
JamesLawton merged 1 commit intomainfrom
feat/polymarket-clob-v2

Conversation

@AkshatGada
Copy link
Copy Markdown
Collaborator

@AkshatGada AkshatGada commented Apr 28, 2026

Polymarket shipped CLOB V2 on April 28, 2026. This PR migrates our entire Polymarket integration to the new infrastructure , new SDK, new collateral token (pUSD), new exchange contracts, and a new order signing format. The V1 SDK no longer works against production.

What changed

SDK swap

  • Replaced @polymarket/clob-client + @polymarket/order-utils with @polymarket/clob-client-v2@1.0.0
  • ClobClient constructor changed from positional args to options object (chainIdchain, proxy wallet → funderAddress)
  • SignatureTypeSignatureTypeV2 (now exported from the v2 client directly)

New collateral: pUSD

  • Polymarket replaced USDC.e with pUSD as the trading collateral
  • Added automatic USDC.e → pUSD wrapping step in the clob-buy flow via the CollateralOnramp contract
  • Buy flow is now: smart wallet → USDC.e to proxy wallet → wrap to pUSD → CLOB order

V2 exchange contracts

  • Updated CTF_EXCHANGE to 0xE111180000d2663C0091e4f400237545B87B996B
  • Updated NEG_RISK_CTF_EXCHANGE to 0xe2222d279d744050d28e00520010520000310F59
  • Added constants: PUSD, COLLATERAL_ONRAMP, COLLATERAL_OFFRAMP

Approval flow updated

  • Now approves pUSD → V2 exchange, CTF → V2 exchange, USDC.e → CollateralOnramp
  • All users (including returning) must re-run approve --broadcast since V2 uses entirely new contracts

Bug fix: proxy wallet ABI

  • The proxy wallet function is proxy() (selector 0x34ee9791), not execute() (0xe8454e54)
  • The old selector was silently accepted by the factory but did nothing — all proxy wallet calls (approvals, wrapping) were no-ops
  • Fixed the ABI function name, confirmed working with on-chain transactions

SKILL.md rewrite

  • Updated for V2: pUSD collateral, mandatory re-approval, wrapping flow, updated troubleshooting

Files changed

  • packages/polygon-agent-cli/package.json — dependency swap
  • packages/polygon-agent-cli/src/lib/polymarket.ts — constants, SDK client, ABI fix
  • packages/polygon-agent-cli/src/commands/polymarket.ts — approvals, wrapping step, output labels
  • skills/polygon-polymarket/SKILL.md — full rewrite
  • pnpm-lock.yaml

Test plan

Tested end-to-end on production V2 (clob.polymarket.com, version: 2) with real on-chain transactions:

  • V2 approvals broadcast — tx 0x6cf87c... (3 approvals: pUSD, CTF, USDC.e→Onramp)
  • USDC.e → pUSD wrap via CollateralOnramp — tx 0x00b686...
  • GTC limit order posted on V2 test endpoint — orderId 0x4d32e7..., status: live
  • Order cancelled successfully
  • FOK market order Feature/webhook callback #1 matched on production — "Trump ends Iran military ops" — orderId 0x16acbd...
  • FOK market order Review updates #2 matched on production — "Hormuz blockade lifted" — orderId 0x488232...
  • FOK market order updated flow, fixed fee options #3 matched on production — "Bitcoin $150k" — orderId 0x5a6e4b...
  • Positions query returns all 5 positions correctly
  • Markets search/browse — Gamma API unchanged, working
  • Proxy wallet lookup — working
  • Dry-run outputs show correct V2 flow (fund → wrap → order)

…hange contracts

- Replace @polymarket/clob-client + order-utils with @polymarket/clob-client-v2@1.0.0
- Update ClobClient constructor to options object (chainId → chain, funderAddress)
- Update exchange contract addresses to V2 (CTF_EXCHANGE, NEG_RISK_CTF_EXCHANGE)
- Add pUSD, COLLATERAL_ONRAMP, COLLATERAL_OFFRAMP constants
- Add USDC.e → pUSD wrapping step in clob-buy flow via CollateralOnramp
- Update approve flow: pUSD → V2 exchange, CTF → V2 exchange, USDC.e → onramp
- Fix proxy wallet ABI: function name is proxy() not execute() (selector 0x34ee9791)
- Rewrite SKILL.md for V2: pUSD collateral, re-approval requirement, wrapping flow

Tested E2E on V2 test endpoint (clob-v2.polymarket.com):
- Approvals: tx 0x6cf87c...
- Wrap USDC.e → pUSD: tx 0x00b686...
- GTC order posted: orderId 0x4d32e7..., status live
- Cancel + orders + positions all verified
@JamesLawton JamesLawton merged commit 501bf69 into main Apr 28, 2026
2 checks passed
@JamesLawton JamesLawton deleted the feat/polymarket-clob-v2 branch April 28, 2026 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants