PP-2 UI: Trader page -- "Best Trade" stat displays 0 when no individual trade has a realized P&L of zero; should show the least-worst loss or N/A #344
Labels
No labels
agent:fix_bugfix
agent:fix_conflicts
agent:fix_security
agent:gap_analysis
agent:implement
agent:implement
agent:implement
agent:open_issues
agent:ready
agent:research
agent:security_audit
agent:verify
architecture
backend
blocker:hybrid
blocker:launch
blocker:limit-orders
blocker:v2
block:log_only
block:security
bug
ci
contracts
correctness
deploy
dev
devops
docs
documentation
duplicate
e2e
enhancement
epic
feature
frontend
functional-completion
gas
good first issue
governance
help wanted
high-risk
hooks
hybrid
indexer
infra
infrastructure
integrators
invalid
launch-blocker
limit-orders
localnet
localterra
low priority
missing-implementation
needs-design
ops
performance
priority
high
priority
medium
product
qa
QA
question
ready
ready
research
scripts
security
security-hardening
smartcontracts
tech-debt
testing
ux
UX
v2
verification
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
code/cl8y-dex-terraclassic#344
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
On the
/trader/:addresspage, the "Best Trade" summary stat displays0after executing 5 trades across the EMBER/CORAL pair. All realized P&L events (EMBER to CORAL sells) produced negative results -- none were break-even or profitable. The "Best Trade" value of0does not correspond to any trade in the history and is not the correct representation of the best realized outcome.Observed data
Trade history (5 trades, EMBER/CORAL pair):
All three EMBER to CORAL sells were executed below the average entry price of 1.04352. The two CORAL to EMBER buys add to cost basis and do not realize gains. No trade produced a realized P&L of 0 or above.
Reproduction steps
/trader/:addresson LocalTerra after executing several trades in the same pair0rather than the actual best (least-worst) realized trade valueExpected behavior
"Best Trade" should display the highest individual realized P&L value from the trade history. If all realized trades are losses, the best trade is the smallest loss (closest to zero but still negative). Displaying
0when no trade had a realized P&L of zero is incorrect.Acceptable alternatives: display the actual least-worst value, or display "N/A" / "--" when no profitable trades exist.
Actual behavior
"Best Trade" displays
0regardless of whether any trade actually achieved break-even. This makes it impossible to distinguish between "had a break-even trade" and "stat defaulted to zero".Screenshot
Possible root cause area
The
Best Tradevalue is likely initialized to0in the indexer or frontend and only updated when a trade with positive P&L is found. If no profitable trade exists, the initial0is returned as-is rather than returning the actual maximum of all P&L values (the least-negative realized trade).Relevant area: indexer trader P&L aggregation query, or the frontend component rendering summary stats on
/trader/:address.Impact assessment
Environment
/trader/terra1753zuaneacfr60rg37l8d4t0x7j4yvqgsl7cvvSeverity: P2(polish) -- incorrect summary stat; does not affect trade execution or fund safety.
Related checklist items: PP-2
cc: @PlasticDigits
mentioned in commit 4a0812cd087152712894986d26cd8859f74c1d71
mentioned in merge request !848
MR !848 opened
Changes: Nullable best/worst trade PnL + CASE update SQL; UI N/A when unset.
Verify
cargo test --lib(indexer)mentioned in merge request !849
mentioned in commit
b10b8a0fe9mentioned in commit
1c37ef869cmentioned in merge request !850
mentioned in commit
83dc19286dVerification complete — #344
All acceptance and verification criteria PASS on
main(83dc192).Results
cargo test --libbest_trade_pnlnot sentinel 0GET /api/v1/traders/terra1x46…→-20757.62…(all-loss trader, 62 trades)/trader/terra1x46…shows negative least-worst loss (not0orN/A)traderProfilePayload.test.tsMerged fixes: !848, !850 (break-even backfill repair).
Re-verify checklist
cargo test --lib(indexer)Ran the re-verify checklist on main
83dc192, plus the migration path the original pass couldn't cover (a live DB still on the pre-fix schema).cargo test --lib: 134/134Evidence txs: 8133A18A (basis buy), B74B1396 / 638E71E5 (loss sells), wallet terra18nln8ypzlvkpcq6whdymqjac8pypxc5sd9m6jm.
One observation while tracing this, not a regression: the position model is per-pair quote exposure, so selling quote that arrived via plain transfer (never bought on the pair) realizes the full proceeds as positive PnL — zero basis. I reproduced it: a fresh wallet's first trade (quote side, transferred-in funds) realized +297,600,661, the entire return amount. It's consistent with the documented exposure model and doesn't touch this fix, but it does inflate total_realized_pnl for transfer-funded wallets. If PP-2 "values are correct" needs to be tighter for mainnet, capping realization at the tracked position would be the knob.
mentioned in issue #337