Portfolio positions: /traders/{addr}/positions drops or undercounts trades on 18-decimal pairs #676
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#676
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
GET /api/v1/traders/{addr}/positionsdisagrees withGET /api/v1/traders/{addr}/trades, specifically on pairs involving an 18-decimal token. Every 6/6-decimal pair aggregates correctly; the two pairs with an 18-dec asset are wrong.Evidence (same wallet, both endpoints)
/positionstrade_count/tradescountThe 18/6 pair undercounts (stale trade_count, and therefore net position/cost basis); the 6/18 pair is omitted from the positions response entirely despite trades in the feed.
Impact
Open Positions on /portfolio is incomplete/incorrect for the economic mixed-decimal pairs (UST1/USTR, CL8Y-cb/cUSTC) — the same 6-vs-18-decimal class #529 fixed on the contract side.
Likely cause
Decimal scaling / overflow (or an exclusion filter) in the positions materialization for 18-decimal assets. Related: #529.
Repro
For a wallet that has traded UST1/USTR and CL8Y-cb/cUSTC, compare per-pair
trade_countin/positionsagainst the count in/trades: 6/6 pairs match, 18-decimal pairs don't. A repro wallet can be shared privately.mentioned in commit
724f514bf3mentioned in merge request !1180
Implemented on !1180.
trader_positionswasNUMERIC(38, 18)(|x| < 10^20). Raw 18-dec amounts (~100 human USTR/CL8Y) failed the upsert after the swap row landed, so/tradesstayed complete and/positionsundercounted or dropped the pair.Fix: widen to
NUMERIC(78, 18), one-shot SQL replay, poller repair whentrade_countstill diverges.make verify-issue-676is green twice.Needs Coolify migrate + indexer restart before a live retest on the 18-dec wallet.
mentioned in commit
972d46f9f1mentioned in issue #686
marked as related to #686
Merged via !1180 (
972d46f9) ontomain36d64528.make verify-issue-676PASS (6/6, Postgres). Coolify leftover: apply20260827120000_trader_positions_numeric_78.sql, redeploy indexer, then compare/positionsvs/tradeson UST1/USTR and CL8Y-cb/cUSTC. Iftrade_countstill diverges,cl8y-dex-indexer rebuild-positions. Do not reopen unless P676 is wrong. Post-merge ops: #686.