Fix #676: persist 18-decimal trader positions #1180

Merged
PlasticDigits merged 2 commits from issue-676-positions-18dec into main 2026-08-27 04:51:40 +00:00
PlasticDigits commented 2026-08-27 00:35:07 +00:00 (Migrated from gitlab.com)

Summary

  • GET /api/v1/traders/{addr}/positions was missing or undercounting swaps on mixed 6/18 pairs (UST1/USTR omitted; CL8Y-cb/cUSTC trade_count stale) while /trades was complete.
  • Root cause: trader_positions used NUMERIC(38, 18) (|x| < 10^20). ~100 human 18-dec tokens is 10^20 raw, so the position upsert failed after swap_events insert. Replay then skipped the update.
  • Widen those columns (and trader P&L/fee columns) to NUMERIC(78, 18), one-shot SQL-replay existing swaps, and repair on poller start when trade_count still diverges. Positions JSON uses plain digit strings.

Closes #676.

Test plan

  • make verify-issue-676 (Postgres + indexer .env; no wasm)
  • Confirm 6/6 pairs still match /positions vs /trades
  • After Coolify migrate + indexer restart, compare a wallet that traded UST1/USTR and CL8Y-cb/cUSTC: per-pair trade_count equals that pair’s /trades count
  • /portfolio Open Positions lists UST1/USTR and CL8Y-cb/cUSTC when those trades exist
  • Optional: cl8y-dex-indexer rebuild-positions if counts still diverge after migrate-only
## Summary - `GET /api/v1/traders/{addr}/positions` was missing or undercounting swaps on mixed 6/18 pairs (UST1/USTR omitted; CL8Y-cb/cUSTC `trade_count` stale) while `/trades` was complete. - Root cause: `trader_positions` used `NUMERIC(38, 18)` (`|x| < 10^20`). ~100 human 18-dec tokens is `10^20` raw, so the position upsert failed after `swap_events` insert. Replay then skipped the update. - Widen those columns (and trader P&L/fee columns) to `NUMERIC(78, 18)`, one-shot SQL-replay existing swaps, and repair on poller start when `trade_count` still diverges. Positions JSON uses plain digit strings. Closes #676. ## Test plan - [ ] `make verify-issue-676` (Postgres + indexer `.env`; no wasm) - [ ] Confirm 6/6 pairs still match `/positions` vs `/trades` - [ ] After Coolify migrate + indexer restart, compare a wallet that traded UST1/USTR and CL8Y-cb/cUSTC: per-pair `trade_count` equals that pair’s `/trades` count - [ ] `/portfolio` Open Positions lists UST1/USTR and CL8Y-cb/cUSTC when those trades exist - [ ] Optional: `cl8y-dex-indexer rebuild-positions` if counts still diverge after migrate-only
PlasticDigits commented 2026-08-27 00:36:01 +00:00 (Migrated from gitlab.com)

mentioned in issue #676

mentioned in issue #676
PlasticDigits commented 2026-08-27 04:51:39 +00:00 (Migrated from gitlab.com)

added 10 commits

  • 724f514b...95151035 - 9 commits from branch main
  • 226a3b3f - Merge origin/main into issue-676-positions-18dec.

Compare with previous version

added 10 commits <ul><li>724f514b...95151035 - 9 commits from branch <code>main</code></li><li>226a3b3f - Merge origin/main into issue-676-positions-18dec.</li></ul> [Compare with previous version](/PlasticDigits/cl8y-dex-terraclassic/-/merge_requests/462/diffs?diff_id=1986965515&start_sha=724f514bf3662fa6dc63cd3bd6f16cc03b5ccddf)
PlasticDigits commented 2026-08-27 04:51:40 +00:00 (Migrated from gitlab.com)

mentioned in commit 972d46f9f1

mentioned in commit 972d46f9f12647f2dba2b086cd9ee90f3dd194de
PlasticDigits (Migrated from gitlab.com) merged commit 972d46f9f1 into main 2026-08-27 04:51:40 +00:00
PlasticDigits commented 2026-08-27 05:29:53 +00:00 (Migrated from gitlab.com)

mentioned in issue #686

mentioned in issue #686
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
code/cl8y-dex-terraclassic!1180
No description provided.