fix(indexer): best/worst trade PnL aggregates (#344) #848
No reviewers
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!848
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "local1/344-best-trade-pnl"
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
best_trade_pnl/worst_trade_pnl; fixGREATEST(0, loss)bugTest plan
cargo test --lib(indexer)npm test -- traderProfilePayload.test.ts/trader/:addrafter losing trades shows least-negative best or N/ADocs
Merge after prior stacked MRs.
changed the description
mentioned in issue #344
changed the description
Stale Security Review comment
Stale Security Review comment
Stale Security Review comment
Cursor Bugbot has reviewed your changes and found 4 potential issues.
Bugbot Autofix is ON. A cloud agent has been kicked off to fix the reported issues.
Reviewed by Cursor Bugbot for commit 4a0812cd087152712894986d26cd8859f74c1d71. Configure here.
Wrap deposit uses net amount
High Severity
Native-wrap liquidity applies post-tax net units to
wrap_depositcoins, but treasury expects the user’s gross native deposit. CW20 allowances match the net amount, so the tx can succeed while attaching less native than the UI amount and minting less wrapped token than the user intended.Reviewed by Cursor Bugbot for commit 4a0812cd087152712894986d26cd8859f74c1d71. Configure here.
Tax cache ignores denom
Medium Severity
LCD tax params are cached for 60s in a single global entry without storing the denom. A later call for another native denom (e.g.
uusdafteruluna) can reuse the first denom’s tax cap and compute the wrong net minted amount.Reviewed by Cursor Bugbot for commit 4a0812cd087152712894986d26cd8859f74c1d71. Configure here.
Leaderboard null PnL shows zero
Low Severity
Nullable
best_trade_pnl/worst_trade_pnlare coerced to''for the leaderboard, thenparseFloatandformatNumtreat that as zero. Traders with unset aggregates show0and positive coloring instead of N/A, unlikePnlValueon the profile.Additional Locations (1)
frontend-dapp/src/pages/ChartsPage.tsx#L538-L567Reviewed by Cursor Bugbot for commit 4a0812cd087152712894986d26cd8859f74c1d71. Configure here.
Max reserve skips unwrap gas
Medium Severity
estimateNativeSwapUlunaFeesTotalnow adds unwrap gas whenneedsUnwrapOutputis set, but native Max hints on the swap page still omit that flag. Max spend can reserve too little LUNC for wrap + router + unwrap paths and lead to insufficient-fee or out-of-gas failures.Reviewed by Cursor Bugbot for commit 4a0812cd087152712894986d26cd8859f74c1d71. Configure here.
changed this line in version 2 of the diff
added 1 commit
Compare with previous version
changed the description
resolved all threads
Stale Security Review comment
Stale Security Review comment
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is ON. A cloud agent has been kicked off to fix the reported issues.
Reviewed by Cursor Bugbot for commit 548886b239fd3b31a10480b339deec8e934520d5. Configure here.
Migration nulls valid zero PnL
Low Severity
The backfill sets
best_trade_pnlorworst_trade_pnlto NULL whenever the stored value is0andtotal_realized_pnlis non-zero. A trader whose best or worst single trade was exactly break-even (0) matches that pattern and loses a valid zero in favor of APInull/ UI N/A.Reviewed by Cursor Bugbot for commit 548886b239fd3b31a10480b339deec8e934520d5. Configure here.
Native preflight uses gross offer
Medium Severity
For native-input swap quotes,
simulateNativeSwapandexecuteNativeSwapnow simulate and send the post–burn-tax CW20 amount, butpreflightSwapRouteSpreadstill seeds the first hop with grossrawInputAmount. Hop spread and max-spread gating can disagree with what actually executes.Reviewed by Cursor Bugbot for commit 548886b239fd3b31a10480b339deec8e934520d5. Configure here.
changed this line in version 4 of the diff
added 1 commit
Compare with previous version
changed the description
changed this file in version 7 of the diff
changed this file in version 7 of the diff
added 14 commits
mainb10b8a0f- fix(indexer): nullable best/worst trade PnL aggregates (#344)c063446c- Fix wrap deposit gross amounts, tax cache denom, leaderboard N/A, swap Max unwrap gas80de4937- fix: native preflight net offer and preserve break-even PnL in migration4b963d49- fix(frontend): drop duplicate nativeTransferTax import after rebaseCompare with previous version
changed the description
Stale Security Review comment
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is ON. A cloud agent has been kicked off to fix the reported issues.
Reviewed by Cursor Bugbot for commit
4b963d4980. Configure here.Zero best PnL still pinned
High Severity
update_trader_pnlonly treats unsetbest_trade_pnlwhen the column is SQLNULL. Rows that still have the legacy sentinel0useGREATEST(best_trade_pnl, $2), so a negative trade PnL leavesbest_trade_pnlat0. The migration does not clear every erroneous0(e.g. one realized loss among many buys), so the original all-loss pinning bug can persist after deploy.Additional Locations (1)
indexer/migrations/20260609120000_fix_trader_best_worst_pnl_null.sql#L17-L22Reviewed by Cursor Bugbot for commit
4b963d4980. Configure here.Null best resets on one trade
Medium Severity
When the migration sets
best_trade_pnltoNULLfor multi-trade rows, the nextupdate_trader_pnlassignsbest_trade_pnlto only the latest trade’s PnL instead of the max across prior closes. Historical least-negative losses are dropped until a full re-aggregate runs.Additional Locations (1)
indexer/migrations/20260609120000_fix_trader_best_worst_pnl_null.sql#L17-L22Reviewed by Cursor Bugbot for commit
4b963d4980. Configure here.added 1 commit
3f7ca070- fix(indexer): backfill and update legacy best_trade_pnl sentinel zeroCompare with previous version
changed the description
resolved all threads
mentioned in commit
1c37ef869cCursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is ON, but it could not run because the branch was deleted or merged before autofix could start.
Reviewed by Cursor Bugbot for commit
3f7ca07066. Configure here.Break-even best PnL overwritten
Medium Severity
The legacy-repair branch treats
total_realized_pnl = worst_trade_pnlas if the only realized trade were the worst loss. After a losing close and a break-even close (best_trade_pnlstill 0), that setsbest_trade_pnlto the worst loss instead of 0, skewing profiles and best-trade leaderboard rows.Additional Locations (1)
indexer/migrations/20260609120000_fix_trader_best_worst_pnl_null.sql#L16-L21Reviewed by Cursor Bugbot for commit
3f7ca07066. Configure here.mentioned in merge request !850
resolved all threads