Migrate to Polymarket v2 + pUSD (April 28 2026 exchange upgrade)#61
Draft
petrarka wants to merge 1 commit into
Draft
Migrate to Polymarket v2 + pUSD (April 28 2026 exchange upgrade)#61petrarka wants to merge 1 commit into
petrarka wants to merge 1 commit into
Conversation
Polymarket migrated the exchange and collateral on April 28 2026:
USDC.e -> pUSD (1:1 USDC wrapper) and CLOB v1 -> v2. The legacy
@polymarket/clob-client (v1) is no longer compatible with the live
exchange — orders signed against the v1 contracts are rejected.
Changes:
- Swap @polymarket/clob-client@^4.22.8 for @polymarket/clob-client-v2@^1.0.6
(plus viem as supporting dep). The v2 SDK uses an object-form
constructor ({ host, chain, signer }), renames chainId -> chain,
and exposes a single createOrDeriveApiKey() call.
- UserOrder / UserMarketOrder become UserOrderV2 / UserMarketOrderV2.
The v2 types drop feeRateBps, nonce, and taker (server-side now);
order construction in services/trading.ts updated accordingly.
- services/config.ts: collateral address points to pUSD
(0xC011a7E12a19f7B1f670d46F03B03f3342E82DFB), exchange addresses
updated to v2 (0xE111180... and 0xe2222d2...). Added constants for
USDC.e, CollateralOnramp, and CollateralOfframp to support future
wrap/unwrap tooling.
- services/approvals.ts: collateral allowances target pUSD on the
v2 exchanges. Renamed helper getUsdcContract -> getCollateralContract.
- services/redemption.ts: redeemPositions passes pUSD (not USDC.e) as
the collateral token.
- services/api.ts: dropped PolymarketSDK (v1) from @jsr/hk__polymarket
in favor of a direct /book fetch — the endpoint is public so this
also removes the need to construct a CLOB client just to read order
books. GammaSDK retained for market discovery (unaffected by the
upgrade).
- tools/get-balance-allowance.ts, tools/update-balance-allowance.ts:
AssetType imported from the v2 SDK.
Adds smoke-test.mjs — 8-check regression harness that hits live
Polymarket APIs read-only by default. Exercises trading-client init
(createOrDeriveApiKey, getBalanceAllowance, getMarketInfo) only when
POLYMARKET_PRIVATE_KEY is set, and never places orders.
Default signatureType semantics are unchanged — v2 ClobClient still
accepts signatureType + funderAddress for proxy-wallet flows.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Polymarket migrated the exchange and collateral on April 28 2026: USDC.e → pUSD (1:1 USDC wrapper) and CLOB v1 → v2. The legacy
@polymarket/clob-client(v1) is no longer compatible — orders signed against the v1 contracts are rejected by the new exchange. This PR ports the server to the v2 SDK (@polymarket/clob-client-v2) and updates collateral / exchange addresses accordingly.Changes
@polymarket/clob-client@^4.22.8→@polymarket/clob-client-v2@^1.0.6, plusviemas supporting dep.services/trading.ts: v2 SDK uses an object-form constructor ({ host, chain, signer, ... }),chainIdis renamed tochain, andcreateOrDeriveApiKey()replaces the separatederiveApiKey()/createApiKey()calls.UserOrder/UserMarketOrderbecomeUserOrderV2/UserMarketOrderV2— the v2 types dropfeeRateBps,nonce, andtaker(server-side now); order construction was updated accordingly.services/config.ts: collateral now points to pUSD (0xC011a7E12a19f7B1f670d46F03B03f3342E82DFB); CTF Exchange v2 (0xE111180000d2663C0091e4f400237545B87B996B) and NegRisk Exchange v2 (0xe2222d279d744050d28e00520010520000310F59). AddedUSDCE_ADDRESS,COLLATERAL_ONRAMP_ADDRESS,COLLATERAL_OFFRAMP_ADDRESSconstants for future wrap/unwrap tooling.services/approvals.ts: collateral allowances target pUSD on the v2 exchanges. Renamed helpergetUsdcContract→getCollateralContract. Rationale message updated.services/redemption.ts:redeemPositionspasses pUSD (not USDC.e) as the collateral token.services/api.ts: dropped the v1PolymarketSDKusage from@jsr/hk__polymarketin favor of a direct/bookfetch — the endpoint is public, so this also removes the need to construct a CLOB client just to read order books.GammaSDKis retained (Gamma API was not affected by the upgrade).tools/get-balance-allowance.ts,tools/update-balance-allowance.ts:AssetTypeimport path updated to v2 SDK.signatureType+funderAddresscontinue to work — the v2 SDK still accepts them inClobClientOptions, so existing proxy-wallet / Safe flows are unchanged.Tests
Adds
smoke-test.mjs— 8-check regression harness that hits live Polymarket APIs read-only by default. Exercises trading-client init (createOrDeriveApiKey,getBalanceAllowance,getMarketInfo) only whenPOLYMARKET_PRIVATE_KEYis set, and never places orders.Run with
node smoke-test.mjsafterpnpm install && pnpm build.Local run on this branch (signer = a fresh empty Polygon EOA):
Test plan
pnpm install(lockfile is regenerated in this branch)pnpm buildsucceedsnode smoke-test.mjs— 4 read-only checks pass without env configPOLYMARKET_PRIVATE_KEYset, the 4 additional trading-client init checks passNotes for reviewers
@jsr/hk__polymarketGamma SDK still transitively pulls@polymarket/clob-client(v1). It's unused by us now but I left it as a transitive dep to keep the Gamma read path untouched. Happy to also drop Gamma SDK + inline the few Gammafetchcalls if you'd prefer.minorfor the changeset since this is a hard break for anyone running 0.0.18 against the live exchange. Tweak as you see fit.Co-authored with Claude (Opus 4.7). Migration steps were derived from https://docs.polymarket.com/v2-migration and the official
@polymarket/clob-client-v2package types.