Repository navigation
v0.4.0 — Redeem Watchdog
One-liner: pUSD-era redeem observability for AI agents. No keys required.
After Polymarket's pUSD redemption flow shipped, normal users redeem in-app. Agents still need a status lane: which wallet has redeemable value, which condition still surfaces as redeemable=true in the Data API, whether a low-cash strategy account needs attention. v0.4 adds three small helpers to fill that gap — read-only, zero-dep, no signing.
New helpers (src/index.ts)
fetchRedeemablePositionsPage(user, opts)— Data API/positions?redeemable=truesummarizeRedeemablePositions(rows)— group byconditionId, sumcurrentValue(losing rows correctly contribute$0, not theirsize; negative values clamp to0)resolveRedeemMode({ mode, lowWatermark })— returns"watchdog"or"low_watermark". Intentionally no"active"value: this toolkit never executes a redeem, so an active label belongs in your own wallet system.
New artifacts
examples/15-redeem-watchdog.ts— copy-paste demodocs/cookbook.md §11— bilingual recipe (EN + ZH localized rewrite)tests/redeem_watchdog.test.ts— 9 tests covering pure functions, network URL assembly, and the regression points caught during review
Safety boundary
This release only reads public APIs. It does not redeem tokens, sign Safe transactions, call relayers, move funds, or require private keys. The official Polymarket app remains the right place for normal user redemption.
Review trail
This release went through two rounds of independent Codex review:
- Round 1 caught
currentValue || sizefalsely inflating losing redeemable rows: a demo wallet with three losing tokens (size > 0,currentValue = 0) was reporting$1.84payable, when the real payable amount is$0. Fixed by replacing the||fallback with acurrentValue == nullnull-check. - Round 2 caught a missing
>= 0clamp on negativecurrentValue. Fixed by clamping at the summary level.
Tests went from 2 → 9. Full review trail visible in PR #10 and commits 9f89557 + 64f9d15.
Tests
npm test— 9/9 passtsc --noEmit— clean- Example 15 smoke against demo wallet
0x63ce342161250d705dc0b16df89036c8e5f9ba9areturnsestimatedRedeemableValue: 0(was falsely$1.84before the fix)
Quickstart
npx tsx examples/15-redeem-watchdog.ts <proxy_wallet> [low_watermark]