chore(v2): 清理 V2 不再消费的 builderCreds dead surfaces#30
Merged
Conversation
## 背景 2026-04-28 V2 cutover 后,order signing 通过 bytes32 `builderCode` 做链上 attribution,HMAC `builderCreds` 三件套在 trading 路径上彻底不再被消费 — 仅 `RelayerService` 还用于 gasless TX envelope (Safe deploy / wrap / transfer)。 V1→V2 迁移 (PR #29) 时为了避免破坏 caller 同时保留了多个 dead surface: - `OrderManagerConfig.builderCreds` (从未被 V2 OrderManager 消费) - `PolymarketSDKConfig.builderCreds` (从未在 SDK constructor 内被 thread) - `index.ts` 中长达 30 行的 fail-fast guard, 用来在结构性类型仍接受旧字段时 做 V1 mental-model 的硬告警 这些是 V2 落地后的 dead weight, 增加阅读心智成本和未来 maintenance 风险。 ## 修改方案 ### §1 OrderManagerConfig.builderCreds — 移除 确认 dead, 仅在 type definition 上, 没有任何 runtime 消费路径。 ### §2 TradingService.createBuilderApiKey() helper — 保留 AS-IS - 函数名 mirror 上游 Polymarket SDK `l2Client.createBuilderApiKey()` (L3 endpoint) - return field `builderCreds` 也是上游 SDK 自身的 terminology - earning-engine `cli/wallet.ts` 与 `wallet/file-wallet-store.ts` 直接消费此 return, 其中 `BuilderCreds` 已是持久化磁盘 schema (FileWalletStore 的 JSON 字段) - Rename 会跨 repo 破坏 + 与 Polymarket 自己 API 命名错位 → 保守 keep 注释 (trading-service.ts:119-121) 已说明 V1/V2 distinction: "replaces the V1 builderCreds HMAC three-tuple. HMAC creds are still consumed by RelayerService for gasless TX envelopes; they are NOT used by V2 order signing." ### §3 PolymarketSDKConfig.builderCreds — 移除 - 调研 confirm: SDK constructor 中 `config.builderCreds` 仅出现于 fail-fast guard, 从未 thread 到 RelayerService / TradingService / OrderManager - earning-engine 所有 `new PolymarketSDK()` 调用均不传 config (4 处, 全部空构造) - earning-engine 创建 RelayerService 时直接 `new RelayerService({ builderCreds: ... })`, 不经过 PolymarketSDK - 因此移除是 safe 的 (无 cross-repo break), 比 rename 更诚实 (没有任何字段需要被 rename, 因为它本来就是 non-functional) ### §4 index.ts fail-fast guard — 移除 没有 `PolymarketSDKConfig.builderCreds` 字段就没有 V1 误传场景, guard 自然失去意义。 保留 7 行注释指向 guide-polymarket-v2-migration 供将来追溯。 ### §5 测试 - v2-trading-service-init.test.ts: 删除第二个 describe (4 个 fail-fast tests), 替换为 NOTE 解释为何被删 - v2-relayer-wrap.test.ts / v2-relayer-token-routing.test.ts: 保留 `builderCreds` 使用 — 这是 RelayerServiceConfig 的合法字段, 仍由 V2 Relayer 消费 ## API 变化 破坏性 (poly-sdk public API): - `PolymarketSDKConfig.builderCreds` 字段移除 — 迁移路径: 直接 `new RelayerService({ builderCreds })` - `OrderManagerConfig.builderCreds` 字段移除 — 没有 caller (V2 后即 dead) 非破坏性 (保留): - `TradingService.createBuilderApiKey()` 函数 + `BuilderKeyResult.builderCreds` return - `RelayerServiceConfig.builderCreds` (Relayer 仍用于 gasless TX) ## 风险与回滚 风险低: 1. earning-engine 所有 `new PolymarketSDK()` 都是空 config → 不传 builderCreds, 0 break 2. earning-engine RelayerService 直接构造, 不经 PolymarketSDK → 0 break 3. earning-engine OrderManager (poly-sdk 的) 没有 caller (search 0 hits in /cli/, /trading-engine/) → 0 break 回滚: `git revert <sha>` 即可, 仅 4 个文件 + 单 commit。 注: 发现 earning-engine `trading-engine/src/impl/live-order-executor.ts:67` 向 TradingServiceConfig 传 `builderCreds` (excess property), 这是 PRE-EXISTING bug (早于本次清理), 不在 poly-sdk 清理范围, 由 earning-engine 自己跟进。 ## 测试结果 - `npx tsc --noEmit`: 0 errors - `pnpm test`: 11 files / 150 tests passed (V1 时 154; 删除 4 个 fail-fast tests) - `pnpm build`: clean 净行数: -93 (24 inserted, 117 deleted), 4 files changed. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
5 tasks
cyl19970726
added a commit
that referenced
this pull request
May 6, 2026
…#32) V2 cutover (2026-04-28) 后 V1 trading 永久死亡, SDK 应只支持 V2 path. PR #30 留下了 @deprecated 标记的 V1 aliases 噪音, 本次彻底清理. 删除内容 ======== constants/v2-contracts.ts: - POLYGON_CONTRACTS_V1_LEGACY 整体删除 (V1 ctfExchange / negRiskExchange) - EIP_712.domainVersionV1 字段删除 (V2 only) clients/ctf-client.ts: - NEG_RISK_CTF_EXCHANGE_V1_DEPRECATED 删除 - CTF_EXCHANGE_V1_DEPRECATED 删除 - NEG_RISK_CTF_EXCHANGE 别名删除 (= V1 地址) - CTF_EXCHANGE 别名删除 (= V1 地址) - 保留 NEG_RISK_CTF_EXCHANGE_V2 / CTF_EXCHANGE_V2 (= POLYGON_CONTRACTS_V2.*) utils/calldata-decoder.ts: - MATCH_ORDERS_SELECTOR 顶层别名删除 (= V1 selector) - 移除 CTF_ROUTER / NEG_RISK_ROUTER 上的 @deprecated 标记 (这些不是 deprecated, 是 V1-mempool-tail-by-design constants, smart-money 仍消费) index.ts: - 同步移除上述 V1 surfaces 的 re-export services/relayer-service.ts: - split / merge / redeem / redeemBatch 删除 token 参数 (pUSD-only) - transferUsdc / approveUsdc 保留 CollateralToken 参数 (Onramp/Offramp + fund-out collect 仍合法消费) services/authorization-service.ts: - AllowancesResult.usdcBalance @deprecated 别名删除 保留的合理项 ============ - POLYGON_CONTRACTS_V2.usdcE: wrap helper / off-exchange flow 必需 - wrapUsdcToPUSD / unwrapPUSDtoUsdc: V2 architecture 必需 - transferUsdc(token = pUSD | USDC.e): main wallet 仍持 USDC.e 走 fund-out - approveUsdc(token = pUSD | USDC.e): Onramp/Offramp 需 USDC.e/pUSD approval - decodeMatchOrdersCalldataV1 + MATCH_ORDERS_SELECTOR_V1 + CTF_ROUTER / NEG_RISK_ROUTER: smart-money mempool tail (Plan 11 §6) 真实消费 - createBuilderApiKey / BuilderKeyResult.builderCreds: earning-engine cli 通过它生成 L3 HMAC creds 给 RelayerService bootstrap (cli/wallet.ts caller 实测仍消费, 删了会破) - 其他非 V1 的 @deprecated 标记 (OrderStatus migration / WS subscription format / Bridge types 等历史 API 演进, 不在本次 V2 cleanup 范围) 测试 ==== - 12 test files / 152 tests 全绿 - v2-relayer-token-routing.test.ts 删除 split/merge/redeem 的 USDC.e override 测试 (函数已不接受 token), 保留 approveUsdc / transferUsdc 的 dual-token 路由测试 - ctf-client.integration.test.ts 改用 NEG_RISK_CTF_EXCHANGE_V2 跨仓库影响 (P0 follow-up) ========================= earning-engine/cli/src/commands/wallet.ts 6 处仍 import 已删除的 CTF_EXCHANGE / NEG_RISK_CTF_EXCHANGE (V1 地址), 用于 wallet approval 矩阵. post-V2 这些 V1 地址不需要 approval, 应改用 POLYGON_CONTRACTS_V2.*. 详细 blocker 见: .claude/skills/guide-polymarket-v2-migration/notes/v2-aggressive-cleanup-blockers.md 净行数: +67 / -215 Branch: chore/v2-only-aggressive-cleanup 不开 PR (Lead 统一管理). Co-authored-by: hhh0x <[email protected]>
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.
背景
V2 migration PR #29 (e5f00c3) 完成后,user 发现 `builderCreds` (V1 HMAC) 仍残留在多个 V2 不再消费的 surface — 应清理。
决策
改动
测试
风险与回滚
风险 LOW: earning-engine 不通过 `PolymarketSDK` 构造器 thread `builderCreds` (verified by cross-repo grep)。所有 Relayer 流程直接构造 `RelayerService`。
回滚: `git revert 4347097` 单 commit。
Out-of-scope finding
预存在 TS error at `earning-engine/trading-engine/src/impl/live-order-executor.ts:67` — passes excess property `builderCreds` to `TradingServiceConfig`. 不在本 PR scope (poly-sdk only),flag 给 earning-engine layer follow-up (Plan 11 §5 cleanup pipeline).
🤖 Generated with Claude Code