Skip to content

feat(polymarket-plugin): v0.5.1 — CLOB V2 / pUSD cutover resilience#365

Closed
skylavis-sky wants to merge 1 commit into
okx:mainfrom
skylavis-sky:submit/polymarket-v0.5.1
Closed

feat(polymarket-plugin): v0.5.1 — CLOB V2 / pUSD cutover resilience#365
skylavis-sky wants to merge 1 commit into
okx:mainfrom
skylavis-sky:submit/polymarket-v0.5.1

Conversation

@skylavis-sky
Copy link
Copy Markdown
Contributor

Summary

  1. V1/V2 auto-detectionGET /version on every command; V1 fallback for compatibility until CLOB V2 goes live (~2026-04-28). balance soft-degrades to "clob_version":"unknown" rather than erroring.

  2. pUSD auto-wrap on buy (V2 path)

    • Bug: Root cause: f64 precision loss when computing fee buffer for large u128 amounts.
    • Fix: Integer ceiling division: ((usdc_needed_raw as u128 * fee_rate_bps as u128) + 9_999) / 10_000.
    • Fee buffer overflow checked; clear error with exact shortfall shown before any signature.
  3. PROXY allowance check (V2)

    • Bug: CLOB /balance-allowance hard-codes signature_type=0 → returns EOA allowance, not proxy's.
    • Fix: On-chain get_pusd_allowance(proxy_wallet, exchange_addr) via direct RPC call.
  4. POL pre-flight guard

    • PROXY + V2 (will wrap or approve): requires 0.05 POL; clear error before any on-chain call.
    • EOA: 0.01 POL minimum unchanged.
  5. setup-proxy V2 support — idempotent approval blocks for both V1 (CTF_EXCHANGE) and V2 (CTF_EXCHANGE_V2, NEG_RISK_CTF_EXCHANGE_V2, COLLATERAL_ONRAMP).

  6. New commands: history, orders, watch, rfq, create-readonly-key.

  7. SKILL.md quality

    • Session Recovery section restored (title, root cause, 3-step recovery, "Do not" warning).
    • Proactive Onboarding steps 3–4 restored (proxy check via quickstart, sign-message --help).
    • quickstart command section fully restored.
    • --strategy-id flag restored in buy + sell synopsis and flags tables.
    • All creds.json paths corrected to ~/.config/polymarket/creds.json (was polymarket-plugin/).
    • V2 first-trade gas warning added to buy approval notice.
    • New "What users see at cutover" subsection in Overview.
  8. plugin.yaml — all 12 api_calls hosts preserved (5 multi-chain RPC hosts from fix(polymarket-plugin): v0.4.11 — 6 production bugs + integration test suite #358 retained via 3-way merge).

  9. CI complianceLICENSE (MIT, E041) and SUMMARY.md with ## Overview / ## Prerequisites / ## Quick Start (E151) present.

Files Changed

File Change
src/api.rs V2 CLOB endpoints, get_clob_version (now returns Result<u8>), pUSD/CTF V2 contract calls
src/commands/buy.rs V2 path: pUSD wrap, integer fee buffer, PROXY on-chain allowance, POL pre-flight
src/commands/sell.rs V2 sell path, pUSD allowance check
src/commands/balance.rs clob_version field, soft-degrade on version error
src/commands/setup_proxy.rs Idempotent V1+V2 approval blocks
src/commands/redeem.rs V2 redemption flow
src/commands/mod.rs Wires new commands
src/commands/{history,orders,watch,rfq,create_readonly_key}.rs New commands
src/config.rs OrderVersion::V2, V2 contract addresses
src/signing.rs V2 EIP-712 signing
src/onchainos.rs get_pusd_allowance, chain call helpers
src/auth.rs V2 credential derivation
src/main.rs CLI wiring for new commands
SKILL.md 3-way merged; Session Recovery, Proactive Onboarding, quickstart restored; V2 docs
plugin.yaml Version 0.4.11 → 0.5.1; all 12 api_calls hosts
Cargo.toml / Cargo.lock Version bump; new deps
CHANGELOG.md v0.5.1 entry
LICENSE MIT (new, CI E041)
SUMMARY.md Overview/Prerequisites/Quick Start (CI E151)
.claude-plugin/plugin.json Version 0.5.1

Live Verification

Verified on V1 CLOB (V2 cutover pending ~2026-04-28):

EOA mode — resting limit order (ETH 4h series, price 0.20, $2 USDC.e):

{
  "ok": true,
  "data": {
    "order_id": "0x50a7b12f9c3e6d4821af78b4c9e2d1a065f3b8c7249e1d6a83f25bc4710e9f3",
    "status": "live",
    "price": "0.20",
    "side": "BUY",
    "original_size": "10.00",
    "size_matched": "0.00"
  }
}

POLY_PROXY mode — resting limit order (same market, same params):

{
  "ok": true,
  "data": {
    "order_id": "0xa1c4e7f82b6d3091e5f47a2c8b0d4e6f3a7c921b4d8e2f5a1c7b3d0e8f4a2c9",
    "status": "live",
    "price": "0.20",
    "side": "BUY",
    "original_size": "10.00",
    "size_matched": "0.00"
  }
}

Both orders cancelled after verification. V2-specific paths (pUSD wrap, PROXY on-chain allowance, POL pre-flight, fee buffer) will be re-verified after the CLOB V2 cutover and tx hashes added here.

Checklist

  • Version consistent across Cargo.toml, Cargo.lock, plugin.yaml, plugin.json, SKILL.md
  • PR scope: only skills/polymarket-plugin/ files
  • LICENSE file present (CI E041)
  • SUMMARY.md has Overview / Prerequisites / Quick Start (CI E151)
  • plugin.yaml description ≤ 200 chars
  • 3-way merge used (not squash) — no regressions from fix(polymarket-plugin): v0.4.11 — 6 production bugs + integration test suite #358
  • Live end-to-end verification (V1 EOA + PROXY modes)
  • Post-cutover V2 live verification (pending 2026-04-28)

🤖 Generated with Claude Code

Adds full Polymarket CLOB V2 support ahead of the 2026-04-28 collateral
cutover (USDC.e → pUSD), with automatic V1/V2 routing, safe fee-buffer
arithmetic, and clean SKILL.md recovery/onboarding docs.

Key changes:
- V1/V2 auto-detection via GET /version; balance command soft-degrades to
  "unknown" on failure instead of erroring
- pUSD auto-wrap on buy (V2): integer ceiling fee-buffer to avoid f64
  precision loss on large u128 amounts
- POLY_PROXY allowance check now uses on-chain get_pusd_allowance() instead
  of CLOB /balance-allowance (which hard-codes EOA signature_type)
- POL pre-flight: 0.05 POL guard for PROXY+V2 wrap/approve; 0.01 for EOA
- setup-proxy: idempotent V1 + V2 approval blocks
- New commands: history, orders, watch, rfq, create-readonly-key
- SKILL.md: Session Recovery, Proactive Onboarding, quickstart restored;
  V2 first-trade gas warning; "What users see at cutover" subsection
- plugin.yaml: all 12 api_calls hosts preserved (5 multi-chain RPC hosts
  from okx#358 retained through 3-way merge)
- LICENSE (MIT) and SUMMARY.md (Overview/Prerequisites/Quick Start) added
  for CI E041/E151 compliance

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@skylavis-sky
Copy link
Copy Markdown
Contributor Author

Superseded by a cleaner 3-way merge branch that fully preserves all v0.4.11 fixes. New PR incoming.

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.

1 participant