Skip to content

feat(v2): flip POLYMARKET_V2_ENABLED default to true (Phase 2 — DO NOT MERGE BEFORE 2026-04-28 11:00 UTC)#49

Merged
smypmsa merged 1 commit intomainfrom
feat/v2-flip-default
Apr 28, 2026
Merged

feat(v2): flip POLYMARKET_V2_ENABLED default to true (Phase 2 — DO NOT MERGE BEFORE 2026-04-28 11:00 UTC)#49
smypmsa merged 1 commit intomainfrom
feat/v2-flip-default

Conversation

@smypmsa
Copy link
Copy Markdown
Member

@smypmsa smypmsa commented Apr 27, 2026

⚠️ DO NOT MERGE BEFORE 2026-04-28 11:00 UTC

This is Phase 2 of the V1 retirement plan, prepared in advance so the cutover is a one-click merge — not a scramble.

Pre-cutover (now), V1 endpoints still hold all the liquidity. Merging this PR before 11:00 UTC would route trades to V2 endpoints with empty books, causing slippage / no-fill failures across the bot.

The right merge moment: at or shortly after 11:00 UTC tomorrow, when Polymarket's V1 endpoints stop accepting orders and V2 becomes the live trading path.

Summary

Flips the default of `POLYMARKET_V2_ENABLED` from off-when-unset to on-when-unset. The flag itself still exists; explicit `POLYMARKET_V2_ENABLED=false` keeps the V1 code path during the soak window. V1 is fully removed in v2.0 (~2026-05-05) — see #37.

Changes

  • `backend/core/feature_flags.py::v2_enabled()` — default from `""` → `"true"`. Docstring rewritten.
  • `backend/tests/test_v2_collateral.py` and `tests/test_v2_order_struct.py` — `v1` fixture now `setenv("false")` (explicit opt-in), `v2` fixture now `delenv` (default). Added `test_default_is_true_post_cutover` and `test_explicit_false_opts_into_v1`.
  • `.env.example` — comment block rewritten to document the new V2 default and the V1 opt-out path.

Behavior matrix

Operator state Before this PR After this PR
`POLYMARKET_V2_ENABLED` set explicitly to `true` V2 V2 (unchanged)
`POLYMARKET_V2_ENABLED` set explicitly to `false` V1 V1 (unchanged — opt-in)
Flag not set in `.env` at all V1 V2 (this is the flip)

Test plan

  • `pytest tests/` — 42 passed (one new test added)
  • `ruff check` — clean
  • At cutover: merge, then verify a fresh `uv run python -c "from core.feature_flags import v2_enabled; print(v2_enabled())"` returns `True` without any env var set
  • Verify backend with no `.env` flag set routes through V2 client / pUSD / V2 exchanges via `/wallet/status` and a small live trade

Out of scope

Roadmap

Phase When Status
1 2026-04-27 ✓ tag `v1-final`, README banner, release notes
2 2026-04-28 11:00 UTC this PR — draft, ready to merge at cutover
3 (v2.0) ~2026-05-05 #37 — delete V1 paths, drop `py-clob-client` dep, semver bump

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • V2 CLOB trading stack (pUSD collateral) is now the default path; V1 path remains available through explicit environment configuration.

Phase 2 of the V1 retirement plan, scheduled to merge at the
2026-04-28 11:00 UTC Polymarket cutover. After cutover the V1 endpoints
stop accepting orders, so V2 becomes the only path that actually trades.
The flag still works for explicit V1 opt-in (`POLYMARKET_V2_ENABLED=false`)
during the soak window — the V1 code itself is removed in v2.0 / #37
~2026-05-05.

Changes:
- feature_flags.v2_enabled() defaults to "true" when the env var is unset
- v1 fixture in both test files now setenv("false") instead of delenv
- v2 fixture switches to delenv (default-on) for symmetry
- TestFeatureFlag covers the new defaults
- .env.example now documents the V2 default + the V1 opt-out path

42/42 tests pass on the new defaults. Behavior at runtime:
- Existing operators with POLYMARKET_V2_ENABLED=true: unchanged
- Operators who set =false explicitly: still on V1 (until v2.0 deletes V1)
- Operators with no flag set: now on V2 (was V1)

DO NOT MERGE BEFORE 2026-04-28 11:00 UTC. Pre-cutover this would route
trades to V2 endpoints with no liquidity.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 27, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: be171894-ad4d-4d25-8159-d5bcd19b7924

📥 Commits

Reviewing files that changed from the base of the PR and between 50ad24e and 01422eb.

📒 Files selected for processing (4)
  • .env.example
  • backend/core/feature_flags.py
  • backend/tests/test_v2_collateral.py
  • backend/tests/test_v2_order_struct.py

📝 Walkthrough

Walkthrough

The pull request inverts the default behavior of the POLYMARKET_V2_ENABLED feature flag from disabled to enabled, reflecting the post-cutover trading path selection. The .env.example documentation, feature flag default value, and test fixtures are all updated to align with this new default behavior.

Changes

Cohort / File(s) Summary
Feature Flag Default Inversion
.env.example, backend/core/feature_flags.py
Updates documentation and default environment value for POLYMARKET_V2_ENABLED from disabled to enabled by default, reflecting post-2026-04-28 cutover. V1 endpoints no longer operational for orders unless explicitly opted into via POLYMARKET_V2_ENABLED=false.
Test Fixture Alignment
backend/tests/test_v2_collateral.py, backend/tests/test_v2_order_struct.py
Inverts test fixtures to match new default behavior: v1 fixtures now explicitly set flag to "false" to opt into legacy paths, while v2 fixtures unset the variable to use V2 default. Feature flag assertions updated accordingly.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related issues

Possibly related PRs

Poem

🐰 V2 hops forward as the default way,
Legacy paths fade with each passing day,
Fixtures flipped and flags reset true,
Post-cutover trading gets its debut! 🚀

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/v2-flip-default

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

smypmsa added a commit that referenced this pull request Apr 27, 2026
So a fresh Claude Code session starting tomorrow can pick up the cutover
plan from this file alone. Adds:
- Cutover timestamp + Phase 2 PR #49 pointer + DO-NOT-MERGE-EARLY warning
- Single-source feature_flags.v2_enabled() reference
- Operator post-flip steps (set_approvals, wrap)
- v1-final tag pointer for legacy reference
- Missing API routes (/positions/{id}/exit, /wallet/generate|import|unlock|lock|approve-contracts)
- POLYMARKET_V2_ENABLED in env list

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@smypmsa smypmsa marked this pull request as ready for review April 28, 2026 11:23
@smypmsa smypmsa merged commit 306cbcb into main Apr 28, 2026
1 check was pending
@smypmsa smypmsa deleted the feat/v2-flip-default branch April 28, 2026 11:23
smypmsa added a commit that referenced this pull request Apr 28, 2026
V1 endpoints stopped accepting orders at 2026-04-28 11:00 UTC. The
POLYMARKET_V2_ENABLED flag flipped default in PR #49 (commit 306cbcb);
this PR removes the V1 code path entirely.

Backend:
- Delete core/feature_flags.py and the V2_CONTRACTS namespace; merge V2
  addresses into CONTRACTS (CTF_EXCHANGE / NEG_RISK_CTF_EXCHANGE now hold
  V2 addresses, plus PUSD / onramp / offramp).
- core/wallet/manager.py: drop _collateral_address/_exchange_addresses
  helpers, drop NEG_RISK_ADAPTER approvals (dead allowance after #45),
  rename WalletBalances.usdc_e -> pusd.
- core/trading/clob_client.py: delete _get_clob_client_v1 and the V1
  endpoint; CLOB client is V2 only.
- core/trading/clob.py: drop V1 import branch.
- core/trading/executor.py and core/positions/manager.py: drop V1
  collateral helpers and the vestigial neg_risk parameter on
  _split_position / _merge_tokens (Gamma's negRisk is a UI hint, not
  on-chain routing — see #45).
- pyproject.toml: drop py-clob-client dep, keep py-clob-client-v2.

Tests:
- Delete test_v2_collateral.py (V1/V2 branch tests no longer meaningful).
- Strip V1 fixtures from test_v2_order_struct.py.

Routers / frontend: cascade rename usdc_e -> pusd through
server/routers/wallet.py, server/routers/trading.py,
hooks/useWallet.tsx, components/PortfolioModal.tsx,
components/terminal/WalletDropdown.tsx (label updated to "pUSD").

Experiments: remove duplicated _v2_enabled() in 01_setup_wallet.py,
03_buy_position.py, 04_transfer_tokens.py; hardcode V2 paths.

Docs: drop the V2 cutover banner from README.md and the cutover section
in CLAUDE.md; drop POLYMARKET_V2_ENABLED line from .env.example.

Operator post-merge step (not code): revoke V1 USDC.e approvals.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
smypmsa added a commit that referenced this pull request Apr 28, 2026
* chore(v2): scaffold V1 retirement (Phase 3)

Empty marker commit so the draft PR can exist. Real changes will be
pushed when this branch is picked up post-soak.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore(v2): retire V1 paths post-cutover (closes #37)

V1 endpoints stopped accepting orders at 2026-04-28 11:00 UTC. The
POLYMARKET_V2_ENABLED flag flipped default in PR #49 (commit 306cbcb);
this PR removes the V1 code path entirely.

Backend:
- Delete core/feature_flags.py and the V2_CONTRACTS namespace; merge V2
  addresses into CONTRACTS (CTF_EXCHANGE / NEG_RISK_CTF_EXCHANGE now hold
  V2 addresses, plus PUSD / onramp / offramp).
- core/wallet/manager.py: drop _collateral_address/_exchange_addresses
  helpers, drop NEG_RISK_ADAPTER approvals (dead allowance after #45),
  rename WalletBalances.usdc_e -> pusd.
- core/trading/clob_client.py: delete _get_clob_client_v1 and the V1
  endpoint; CLOB client is V2 only.
- core/trading/clob.py: drop V1 import branch.
- core/trading/executor.py and core/positions/manager.py: drop V1
  collateral helpers and the vestigial neg_risk parameter on
  _split_position / _merge_tokens (Gamma's negRisk is a UI hint, not
  on-chain routing — see #45).
- pyproject.toml: drop py-clob-client dep, keep py-clob-client-v2.

Tests:
- Delete test_v2_collateral.py (V1/V2 branch tests no longer meaningful).
- Strip V1 fixtures from test_v2_order_struct.py.

Routers / frontend: cascade rename usdc_e -> pusd through
server/routers/wallet.py, server/routers/trading.py,
hooks/useWallet.tsx, components/PortfolioModal.tsx,
components/terminal/WalletDropdown.tsx (label updated to "pUSD").

Experiments: remove duplicated _v2_enabled() in 01_setup_wallet.py,
03_buy_position.py, 04_transfer_tokens.py; hardcode V2 paths.

Docs: drop the V2 cutover banner from README.md and the cutover section
in CLAUDE.md; drop POLYMARKET_V2_ENABLED line from .env.example.

Operator post-merge step (not code): revoke V1 USDC.e approvals.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(skills): drop USDC.e from enter/exit-position skills

Update collateral terminology to match V2: rename `usdc_e` -> `pusd` in
example wallet/balance JSON, swap "USDC.e" -> "pUSD" in instructional
prose. The other four alphapoly skills (feature, experiment, pipeline,
portfolios) had no V1 references and were left alone.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore(v2): keep V2 CLOB URL aligned with main fix

Main got a fix at c189a3c — Polymarket consolidated clob-v2.polymarket.com
into clob.polymarket.com post-cutover. This branch was rewriting the same
file with the old URL, which would have re-introduced the bug at squash-merge.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(v2): estimate gas live for split + merge

Hardcoded gas: 300000 was rejected by Chainstack RPC under stricter
post-cutover limits ('INTERNAL_ERROR: gas limit is too high'). Actual
usage is ~135k for split and ~90k for merge. Estimate live and apply
25% headroom.

Verified live during V2 validation: a stuck $3 merge that failed under
the old hardcoded limit went through cleanly with the estimate.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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