fix: humanize portfolio P&L instead of summing raw mixed units (#551) #1082

Merged
PlasticDigits merged 2 commits from fix/551-portfolio-pnl-scale into main 2026-08-18 03:06:24 +00:00
PlasticDigits commented 2026-08-18 02:08:26 +00:00 (Migrated from gitlab.com)

Closes #551

Summary

  • /portfolio and /trader/:addr Open Positions now scale indexer raw integers by pair decimals and label the token (net = human quote; cost / realized P&L = human base; avg entry = human base per quote).
  • GET /api/v1/traders/{addr}/positions still returns raw NUMERIC and adds asset_0_decimals / asset_1_decimals plus optional denoms. Missing decimals render as —, never assume 6.
  • Header Total realized P&L is a USD sum of per-pair P&L via P522-Q on the base token (unpriced pairs omitted, not $0). Total volume / fees / best / worst show — because traders.total_* mixes incompatible tokens (volume USD is #553).

Issue criteria

  • Per-pair realized P&L, cost basis, net position, and avg entry scaled by decimals and labeled with the token (not formatNum of raw integers)
  • Avg entry is human-scale base per quote (raw × 10^(d1 − d0)), not an unscaled raw ratio
  • Header totals do not add raw mixed-quote numbers: realized P&L in USD, volume/fees/best/worst as —
  • Manual: open /portfolio (or /trader/:addr) for a wallet that swapped on UST1/cUSTC and cLUNC/UST1; confirm rows match tx history and header is not a unitless 38.29M
  • Tape Amount in / out / Price — out of scope (#557)
  • Trader / Charts volume USD + leaderboard — out of scope (#553, !1081)
  • Replace UST1=$1 / USTR=2.5× USTC catalog — out of scope (#556)

Test plan

  • make verify-issue-551 (docs crosslinks, indexer position_tracker + api_traders, frontend scale helper / table / summary / portfolio)
  • After deploy: confirm production /portfolio and /trader/:addr with mixed-decimal pairs

Invariants / skills

P551-1–P551-6 in docs/indexer-invariants.md, docs/frontend.md § My Portfolio, skills/AGENTS_FRONTEND_PORTFOLIO_PNL.md (crosslinked from AGENTS.md and AGENTS_FRONTEND_PORTFOLIO.md).

Closes #551 ## Summary - `/portfolio` and `/trader/:addr` Open Positions now scale indexer raw integers by pair decimals and label the token (net = human quote; cost / realized P&L = human base; avg entry = human base per quote). - `GET /api/v1/traders/{addr}/positions` still returns raw NUMERIC and adds `asset_0_decimals` / `asset_1_decimals` plus optional denoms. Missing decimals render as `—`, never assume 6. - Header **Total realized P&L** is a USD sum of per-pair P&L via P522-Q on the **base** token (unpriced pairs omitted, not `$0`). **Total volume / fees / best / worst** show `—` because `traders.total_*` mixes incompatible tokens (volume USD is #553). ## Issue criteria - [x] Per-pair realized P&L, cost basis, net position, and avg entry scaled by decimals and labeled with the token (not `formatNum` of raw integers) - [x] Avg entry is human-scale base per quote (`raw × 10^(d1 − d0)`), not an unscaled raw ratio - [x] Header totals do not add raw mixed-quote numbers: realized P&L in USD, volume/fees/best/worst as `—` - [ ] Manual: open `/portfolio` (or `/trader/:addr`) for a wallet that swapped on UST1/cUSTC and cLUNC/UST1; confirm rows match tx history and header is not a unitless `38.29M` - [ ] Tape Amount in / out / Price — out of scope ([#557](https://gitlab.com/PlasticDigits/cl8y-dex-terraclassic/-/issues/557)) - [ ] Trader / Charts volume USD + leaderboard — out of scope ([#553](https://gitlab.com/PlasticDigits/cl8y-dex-terraclassic/-/issues/553), !1081) - [ ] Replace UST1=`$1` / USTR=`2.5×` USTC catalog — out of scope ([#556](https://gitlab.com/PlasticDigits/cl8y-dex-terraclassic/-/issues/556)) ## Test plan - [x] `make verify-issue-551` (docs crosslinks, indexer `position_tracker` + `api_traders`, frontend scale helper / table / summary / portfolio) - [ ] After deploy: confirm production `/portfolio` and `/trader/:addr` with mixed-decimal pairs ## Invariants / skills P551-1–P551-6 in `docs/indexer-invariants.md`, `docs/frontend.md` § My Portfolio, `skills/AGENTS_FRONTEND_PORTFOLIO_PNL.md` (crosslinked from `AGENTS.md` and `AGENTS_FRONTEND_PORTFOLIO.md`).
PlasticDigits commented 2026-08-18 02:56:22 +00:00 (Migrated from gitlab.com)

Important - launch was 2.5 ustc = 1 ustr, but now ustr is trading freely, so make sure that is well documented & set as invariant (ustr is set by market, not fixed) before merging

Important - launch was 2.5 ustc = 1 ustr, but now ustr is trading freely, so make sure that is well documented & set as invariant (ustr is set by market, not fixed) before merging
PlasticDigits commented 2026-08-18 03:06:06 +00:00 (Migrated from gitlab.com)

added 6 commits

  • 17237431...4ddad9a6 - 5 commits from branch main
  • 0993d192 - Merge branch 'main' into fix/551-portfolio-pnl-scale

Compare with previous version

added 6 commits <ul><li>17237431...4ddad9a6 - 5 commits from branch <code>main</code></li><li>0993d192 - Merge branch &#39;main&#39; into fix/551-portfolio-pnl-scale</li></ul> [Compare with previous version](/PlasticDigits/cl8y-dex-terraclassic/-/merge_requests/364/diffs?diff_id=1967161551&start_sha=1723743143f5abded123c5da713e46ebc668d7e7)
PlasticDigits commented 2026-08-18 03:06:24 +00:00 (Migrated from gitlab.com)

mentioned in commit eed4be8d11

mentioned in commit eed4be8d114c26b3f92e2392eea8ba849ae6496d
PlasticDigits (Migrated from gitlab.com) merged commit eed4be8d11 into main 2026-08-18 03:06:24 +00:00
PlasticDigits commented 2026-08-18 03:08:39 +00:00 (Migrated from gitlab.com)

mentioned in commit da70fed37d

mentioned in commit da70fed37df41aaa111a242457875cfd9cf85ad6
PlasticDigits commented 2026-08-18 03:11:23 +00:00 (Migrated from gitlab.com)

mentioned in issue #553

mentioned in issue #553
PlasticDigits commented 2026-08-18 03:11:25 +00:00 (Migrated from gitlab.com)

mentioned in issue #556

mentioned in issue #556
PlasticDigits commented 2026-08-18 03:11:33 +00:00 (Migrated from gitlab.com)

mentioned in issue #551

mentioned in issue #551
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!1082
No description provided.