Skip to content

feat(env)!: add Environment with production and preproduction presets - #30

Merged
SebastianBoehler merged 6 commits into
SebastianBoehler:mainfrom
yluoc:environments
Oct 6, 2026
Merged

SebastianBoehler merged 6 commits into
SebastianBoehler:mainfrom
yluoc:environments

Conversation

@yluoc

@yluoc yluoc commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds polymarket::Environment. It holds every endpoint and contract for a deployment, with production() and preproduction() presets taken from the official SDKs.

Before this, ClobClient hard-coded the production Data API host and the mainnet exchange addresses. It also accepted chain 80002 while signing those orders against the mainnet exchanges.

  • ClobClient has new Environment constructors. The existing string constructors use production with only the CLOB host replaced, and accept only chain 137.
  • Config::for_environment() and PositionClientConfig::for_environment() build configs from an environment.
  • The examples and order_test read POLYMARKET_ENV.
  • New live-labeled read-only test against the preproduction CLOB: test_preproduction_live.

Preproduction is not a testnet. It runs on Polygon mainnet with the production contracts, so funds are real.

Verification

Commands run and their actual results:

  • ctest --test-dir build -LE live (Linux Release): 53 of 53 passed.
  • POLYMARKET_RUN_LIVE_SMOKE=1 ctest -R test_preproduction_live: passed.
  • POLYMARKET_ENV=preproduction ./rest_example: read preproduction markets and a book.
  • scripts/quality.py: C++ checks passed.

Checks not run and the reason (or none):

  • Prettier on README.md: no Node runtime was available locally. CI runs it.
  • macOS and Debug builds: covered by the CI matrix.
  • Live orders and funded transactions: out of scope for this change.
  • Preproduction Gamma, Data API and relayer: their root URLs returned 503, so only the preproduction CLOB was checked.
  • test_clob_client_contracts sometimes fails its pagination checks. This also happens on main and is unrelated to this change.

Compatibility and evidence

Public API, binary compatibility, or release implications (or none):

  • Breaking: ClobClient(url, 80002) now throws. Use an Environment with explicit contracts instead.
  • Rebuild required: ClobClient's layout changed.
  • Additive: the new header polymarket/environment.hpp and the factories.

For protocol changes: no wire or signing changes. Presets come from ts-sdk environments.ts at f72f9b3 and py-sdk environments.py at 3f5b181.

For live checks: only read-only preproduction CLOB calls were made live. Host routing and contract selection are covered by local fixtures.

@yluoc

yluoc commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Why added Environment: Polymarket's endpoints and contract addresses have to match each other, but the SDK only let you change the CLOB URL. The Data API host and exchange addresses were hard-coded. So pointing ClobClient at preprod or a local mock still sent position calls to production and signed orders for the mainnet exchanges. Chain 80002 was even accepted but signed wrong.

Environment holds every URL and contract in one object (production(), preproduction(), or your own copy). You pass it to ClobClient, Config and PositionClientConfig, and everything stays in sync. This makes testing against mocks, Polygon forks or preprod possible, and if Polymarket moves a host there's one place to update.

Heads up: preprod is not a testnet. It's on Polygon mainnet with real contracts and real funds.

@yluoc yluoc changed the title Environments feat(env)!: add Environment with production and preproduction presets Oct 6, 2026
@SebastianBoehler
SebastianBoehler merged commit 7e46930 into SebastianBoehler:main Oct 6, 2026
3 of 4 checks passed
@yluoc
yluoc deleted the environments branch October 6, 2026 23:44
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