Skip to content

feat(polymarket): v0.2.6 — 14+9 bug fixes from live testing (2 rounds)#156

Closed
skylavis-sky wants to merge 17 commits intookx:mainfrom
skylavis-sky:update/polymarket-v0.2.5
Closed

feat(polymarket): v0.2.6 — 14+9 bug fixes from live testing (2 rounds)#156
skylavis-sky wants to merge 17 commits intookx:mainfrom
skylavis-sky:update/polymarket-v0.2.5

Conversation

@skylavis-sky
Copy link
Copy Markdown
Contributor

@skylavis-sky skylavis-sky commented Apr 12, 2026

Plugin Submission

Plugin name: polymarket
Version: 0.2.6
Type: update

Checklist

  • plugin-store lint passes locally with no errors
  • I have read the Development Guide
  • My plugin does NOT use reserved prefixes (okx-, official-, plugin-store-)
  • LICENSE file is included
  • SKILL.md has YAML frontmatter with name and description

What does this plugin do?

Polymarket plugin for trading prediction markets on Polygon. This PR covers two rounds of bug fixes from live testing — 14 fixes in v0.2.5 and 9 fixes in v0.2.6.

Which onchainos commands does it use?

  • onchainos wallet addresses --chain 137 — resolve active wallet
  • onchainos wallet sign-message --type eip712 — EIP-712 order signing
  • onchainos wallet contract-call --chain 137 --to <addr> --input-data <hex> --force — approvals (USDC.e approve, CTF setApprovalForAll)

Security Considerations

  • Accesses active Polygon wallet; initiates USDC.e approve and CTF setApprovalForAll transactions with --force
  • v0.2.6: USDC.e balance check fires before any approval tx — no gas wasted on orders that would be rejected for insufficient funds
  • v0.2.5: on-chain isApprovedForAll check (Polygon RPC eth_call) before each setApprovalForAll

Testing

  • Built locally with cargo build — clean build, only pre-existing dead-code warnings
  • All v0.2.5 fixes derived from round 1 live testing; all v0.2.6 fixes derived from round 2 live testing
  • check-access geo-restriction probe tested live on both restricted and unrestricted IPs

v0.2.6 Changes (round 2 testing)

Critical [C1]:

  • buy/sell/redeem on neg_risk: true markets now approve the correct contract. Root cause: Gamma API omits negRisk for many markets → defaulted to falseCTF_EXCHANGE approved instead of NEG_RISK_CTF_EXCHANGE. Fix: resolve_market_token now fetches CLOB market by condition_id after each Gamma lookup to get the authoritative neg_risk.

Major [M1]:

  • buy: USDC.e balance read from /balance-allowance and checked before any approval tx. Insufficient balance now exits with a clear error instead of wasting gas.
  • sell: fully restructured — GCD alignment + zero-amount guard now precede all auth operations. setApprovalForAll can no longer fire for an order that would fail divisibility (e.g. --shares 0.001).

Minor:

  • [N1] buy --dry-run now returns full projected order fields (condition_id, token_id, limit_price, usdc_amount, shares, fee_rate_bps, post_only, expires). Market resolution and GCD alignment run in dry-run mode.
  • [N2] sell --dry-run runs GCD alignment and shows adjusted limit_price, shares, usdc_out, with limit_price_requested and price_adjusted flag.
  • [N3] is_ctf_approved_for_all returns Result<bool>; Polygon RPC failures are logged to stderr. Approval log messages name the specific exchange.
  • [N4] sell logs a price adjustment warning to stderr when --price is rounded for tick size. Matches buy's pattern.
  • [N5] get-positions adds redeemable_note field — distinguishes "winning outcome, redeem to collect USDC.e" from "losing outcome, redemption would receive $0".
  • [N6] Betting-vocabulary trigger phrases added to plugin description (place a bet on, bet on, trade on prediction markets, etc).
  • [S1] redeem pre-checks wallet positions; warns to stderr before submitting a zero-value redemption.

v0.2.5 Changes (round 1 testing)

Critical:

  • sell on neg_risk: true markets: approve_ctf now approves both NEG_RISK_CTF_EXCHANGE and NEG_RISK_ADAPTER

Major:

  • Redundant setApprovalForAll eliminated via on-chain isApprovedForAll check
  • Resting orders pre-validated against min_order_size before approval; --round-up snaps to minimum
  • --keyword filter fixed (Gamma API ?q= is a no-op; replaced with client-side filtering)

Minor (P6–P17): sell zero-amount guard, GCD alignment stderr warning, enriched dry-run output, buy USDC round-down warning, get-market fee_bps, list-markets category field removed, --expires help text, SKILL.md updates, geo-restriction check-access command, redeem command, accepting_orders guard, stale-401 auto-clear, six SKILL.md scenario hints, changelog extracted to CHANGELOG.md

Critical:
- fix(sell/neg_risk): approve both NEG_RISK_CTF_EXCHANGE and NEG_RISK_ADAPTER
  for neg_risk markets; was only approving CTF_EXCHANGE, causing every sell to
  fail with "allowance not enough"

Major:
- fix(sell): check isApprovedForAll on-chain (Polygon RPC eth_call) before
  submitting setApprovalForAll; eliminates redundant approval txs when already
  approved (CLOB balance-allowance API does not reliably report ERC-1155 state)
- fix(buy): add resting-order min_order_size guard (price < best_ask); pre-
  validates against CLOB minimum before approval; --round-up snaps to minimum
- fix(list-markets): replace no-op Gamma ?q= with client-side keyword filter
  on question/slug fields (confirmed Gamma API ignores the q param)

Minor:
- fix(sell): implement zero-amount divisibility guard (was documented but missing)
- fix(sell): warn stderr when GCD alignment reduces requested share amount
- fix(sell/dry-run): output now includes side, order_type, limit_price, post_only,
  expires (previously only market_id, outcome, shares, estimated_price:null)
- fix(buy): warn stderr when USDC amount rounded down by GCD alignment
- fix(get-market): show fee_bps from CLOB maker_base_fee; remove unreliable
  per-token last_trade (CLOB /book returns market-level value for all tokens)
- fix(list-markets): remove always-null category field from output
- fix(main): --expires help text 60s -> 90s (matches actual validation)
- fix(SKILL): telemetry version 0.2.1 -> 0.2.5
- fix(SKILL): add buy --dry-run to flags table
- fix(SKILL): update min_order_size guidance (IS enforced for resting orders)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 12, 2026

🔨 Phase 2: Build Verification — ✅ PASSED

Plugin: polymarket | Language: rust
Source: @

Compiled from developer source code by our CI. Users install our build artifacts.

Build succeeded. Compiled artifact uploaded as workflow artifact.


Source integrity: commit SHA `` is the content fingerprint.

…tion

Adds `polymarket redeem --market-id <id>` which calls redeemPositions on
the Gnosis CTF contract with indexSets=[1,2]. The CTF no-ops for losing
tokens, so passing both outcomes is always safe. --dry-run previews the
call without submitting. neg_risk markets are rejected (use Polymarket
web UI). sha3 keccak256 used to compute the function selector at runtime.

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

Update — redeem command added (same branch, commit 5a29016)

Added polymarket redeem --market-id <id> for post-resolution token redemption:

  • Calls redeemPositions(collateralToken, parentCollectionId, conditionId, indexSets) on the Gnosis CTF contract
  • indexSets=[1,2] covers both YES and NO outcomes — CTF no-ops for losing tokens, so passing both is safe
  • --dry-run previews the call without submitting
  • neg_risk: true markets are rejected with a clear message (use Polymarket web UI)
  • sha3 = "0.10" (RustCrypto) added to compute the function selector via keccak256 at runtime

SKILL.md updated: redeem added to Command Routing Table, full command section added, changelog entry added to v0.2.5.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 12, 2026

✅ Phase 1: Structure Validation — PASSED

Linting skills/polymarket...

  ⚠️  [W100] suspicious pattern: 'base64' — contains base64 reference — may embed hidden content
  ⚠️  [W100] suspicious pattern: 'curl ' — contains curl command — external network request

✓ Plugin 'polymarket' passed with 2 warning(s)

→ Proceeding to Phase 2: Build Verification

Three-step guide for new users: connect onchainos wallet, top up
USDC.e on Polygon (with bridge options), then find markets and place
a first trade. Addresses user feedback about feeling lost after install.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Polymarket's responsibility is only to verify a Polygon address exists.
How the wallet is connected (email, hardware wallet, key import, etc.)
is onchainos's concern, not ours. Removed onchainos wallet login calls
from Quickstart Step 1 and Pre-flight Step 3; replaced with a single
address check and a redirect to the onchainos plugin.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Keep wallet login as the suggested default path; other wallet types
(hardware, imported key) are acknowledged but deferred to onchainos.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…abilities

onchainos only supports email OTP and API key login — no hardware wallet
or key import. Replace vague "other wallet types" reference with the two
concrete login modes actually supported.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…/W140

Linter flags bridge URLs in fund-transfer context as potential data
exfiltration (E141) and as undeclared api_calls (W140). Replace hyperlinks
with plain-text mentions — users can find bridge UIs themselves.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Document the POST /order probe approach and the body-matching logic.
Both restricted and unrestricted IP cases confirmed in live testing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Removes the hidden POST probe from list-markets (wrong place for a
side-effecting network call on a read command). Adds explicit
`polymarket check-access` command — run once before topping up USDC.
Returns accessible: true/false. Quickstart updated to use it in Step 2.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Users installing via npx were getting lost with no guidance. Two fixes:
1. New-user trigger phrases added to description (just installed, get
   started, how do I use, etc.) so the skill activates on post-install prompts.
2. Proactive Onboarding section added with explicit agent instructions
   to walk through the quickstart conversationally — wallet check, access
   check, balance check, market browse, first trade — one step at a time.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ning

Real user session showed agent deciding onchainos sign-message was
unavailable (based on top-level --help), then manually constructing
EIP-712 messages and running raw curl signing flows instead of just
running polymarket buy.

Fixes:
- Add explicit DO NOT rules: no manual EIP-712 construction, no curl
  signing workarounds, no concluding sign-message is missing without
  checking onchainos wallet sign-message --help specifically.
- Pre-flight Step 2 now verifies sign-message subcommand directly.
  If missing, fix is to upgrade onchainos, not bypass the plugin.
- Proactive Onboarding includes same sign-message check upfront.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…arounds

Second user session showed agent correctly diagnosing missing sign-message
but then giving up and suggesting: trade via Polymarket website, use
MetaMask, or export private key from agentic wallet. All wrong.

Fixes:
- Pre-flight Step 2 now includes `onchainos upgrade` as the explicit fix
  when sign-message is missing, with re-verify step.
- DO NOT rules extended: no suggesting web UI fallback, no MetaMask
  redirect, no private key export (security risk).
- Proactive Onboarding updated with same upgrade path.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
….md scenario hints

- config: add clear_credentials() that removes ~/.config/polymarket/creds.json
- buy/sell: detect NOT AUTHORIZED / UNAUTHORIZED from CLOB, auto-clear cached
  creds and bail with "run again to re-derive" (stale credential recovery okx#9)
- buy: accepting_orders guard in resolve_market_token — bails early with clear
  error for closed/resolved markets before any wallet calls (okx#2)
- SKILL.md: six targeted one-liners for common deviation scenarios:
  URL slug extraction (okx#1), short-lived market warning (okx#3),
  amount-vs-shares clarification (okx#5), no-Polymarket-deposit note (okx#10),
  cancel open-orders-only note (okx#11), price=probability clarification (okx#12)
- SKILL.md: credential rotation section updated to mention auto-clear

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… from SKILL.md

SKILL.md ## Changelog section replaced with a single reference line.
Full history preserved in CHANGELOG.md. Saves ~8.7 KB / ~2,100 tokens
that were loaded into agent context on every turn.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
[C1] fix: resolve_market_token now fetches CLOB neg_risk after Gamma lookup.
     Gamma API omits negRisk for many markets → defaulted to false → wrong
     contract approved (CTF_EXCHANGE instead of NEG_RISK_CTF_EXCHANGE).
     All neg_risk buy/sell/redeem calls now use authoritative CLOB value.

[M1] fix: USDC.e balance check in buy fires BEFORE the approval tx.
     Wallet balance is read from /balance-allowance; insufficient balance
     bails with a clear error instead of wasting gas on a failed order.

[M1] fix: sell fully restructured — public API work (market lookup, tick
     size, price, GCD alignment, zero-amount guard) now precedes all auth
     ops. setApprovalForAll can no longer fire for an order that would
     immediately fail the divisibility check.

[N1] fix: buy --dry-run returns full projected order fields (condition_id,
     token_id, limit_price, usdc_amount, shares, fee_rate_bps, etc).
     Market resolution and GCD alignment run in dry-run mode.

[N2] fix: sell --dry-run runs GCD alignment and shows adjusted limit_price,
     shares, usdc_out. Includes limit_price_requested and price_adjusted flag.

[N3] fix: is_ctf_approved_for_all returns Result<bool>; RPC failures are
     logged to stderr. Approval log messages name the specific exchange.

[N4] fix: sell logs price adjustment warning to stderr when --price is
     rounded to satisfy tick size. Matches buy's adjustment warning format.

[N5] fix: get-positions adds redeemable_note field — distinguishes winning
     ("redeem to collect USDC.e") from losing ("receive $0") redeemable positions.

[N6] fix: added betting-vocabulary trigger phrases to plugin description.

[S1] fix: redeem pre-checks positions; warns to stderr if all redeemable
     positions show current_value ≈ $0 (market resolved against the user).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@skylavis-sky skylavis-sky changed the title feat(polymarket): v0.2.5 — 14 bug fixes from live testing feat(polymarket): v0.2.6 — 14+9 bug fixes from live testing (2 rounds) Apr 12, 2026
@skylavis-sky skylavis-sky deleted the update/polymarket-v0.2.5 branch April 12, 2026 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant