fix: resolve HTTP 400 invalid order payload via official py-clob-client-v2 SDK (signature_type=3 / POLY_1271)#5
Open
matteocelani wants to merge 1 commit into
Conversation
a6754de to
df6004b
Compare
… (POLY_1271) Polymarket migrated to CLOB V2 (April 28 2026) with new exchange contracts and an updated EIP-712 schema, breaking the bot's hand-rolled OrderSigner. Replaces the legacy custom signer with the official py-clob-client-v2 SDK, which handles V2 typed-data signing, HMAC L2 auth, and payload construction. Accounts created via the Polymarket web UI follow the deposit-wallet flow: pUSD is held on a smart-contract deposit wallet (the "Solo per uso API" address on the user profile). Orders use signature_type=3 (POLY_1271) with the deposit wallet as funder; the backend validates the ERC-1271-wrapped signature against the contract. - Dependency: py-clob-client -> py-clob-client-v2>=1.0.0 - src/bot.py: connect() derives API credentials via SDK; place_order delegates to sdk_client.create_and_post_order; cancel/get_orders use SDK too - Credential caching (src/bot.py + src/client.py): cached api_creds.json is bound to the safe_address it was derived for; stale creds are auto-purged when the configured funder changes - src/config.py + config/default.yaml: default signature_type=3 - src/signer.py: kept for backward compatibility (no longer used for orders) - strategies/gabagool_strategy.py + src/main.py + src/telegram_notifier.py: hook the new place_order error contract for clearer Telegram alerts Fixes strongca22-cpu#6.
df6004b to
9815677
Compare
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.
Description
This PR resolves the
HTTP 400 — Invalid order payloaderrors that occurred when placing orders on the Polymarket CLOB V2.Root cause: the bot manually constructed and signed EIP-712 payloads via a custom
OrderSigner. Polymarket migrated to CLOB V2 (April 28 2026) with new exchange contracts and an updated EIP-712 schema, breaking the custom signer.The legacy custom signing flow has been replaced with the official
py-clob-client-v2Python SDK, which handles EIP-712 typed-data signing, HMAC L2 auth, and payload construction internally.Wallet flow used
Polymarket accounts created via the web UI (MetaMask connection) follow the deposit-wallet flow:
0x0ada…).SignatureTypeV2.POLY_1271(signature_type=3) with the deposit wallet address asfunder.Changes
py-clob-clientwithpy-clob-client-v2>=1.0.0.src/bot.py):connect()derives API credentials via the official SDK;place_order()delegates entirely tosdk_client.create_and_post_order().src/bot.py+src/client.py): cachedapi_creds.jsonis now bound to asafe_addressand auto-invalidated when the configuredfunderchanges, preventing stale credentials from carrying over after a wallet swap.config/default.yaml,src/config.py):signature_type=3(POLY_1271 — deposit-wallet flow).How to migrate
POLY_PRIVATE_KEYandPOLY_SAFE_ADDRESS(deposit wallet shown on Polymarket profile as "Solo per uso API") inconfig/.env.data/api_creds.json.Fixes #6.