Skip to content

v0.4.0 — Redeem Watchdog

Choose a tag to compare

@runesleo runesleo released this 02 May 06:11
· 29 commits to main since this release
ee54571

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=true
  • summarizeRedeemablePositions(rows) — group by conditionId, sum currentValue (losing rows correctly contribute $0, not their size; negative values clamp to 0)
  • 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 demo
  • docs/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 || size falsely inflating losing redeemable rows: a demo wallet with three losing tokens (size > 0, currentValue = 0) was reporting $1.84 payable, when the real payable amount is $0. Fixed by replacing the || fallback with a currentValue == null null-check.
  • Round 2 caught a missing >= 0 clamp on negative currentValue. 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 pass
  • tsc --noEmit — clean
  • Example 15 smoke against demo wallet 0x63ce342161250d705dc0b16df89036c8e5f9ba9a returns estimatedRedeemableValue: 0 (was falsely $1.84 before the fix)

Quickstart

npx tsx examples/15-redeem-watchdog.ts <proxy_wallet> [low_watermark]