fix(perps): normalize Lighter history wire values - #10187
Open
abretonc7s wants to merge 3 commits into
Open
Conversation
abretonc7s
enabled auto-merge
September 11, 2026 03:31
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Explanation
Fix two Lighter history wire contracts observed while validating the Mobile integration:
Evidence: testnet trade
20887omitted both PnL fields and reported a zero pre-position; canceled order844424929822070reported timestamp1789088736. Raw authenticated reads were retained locally without auth tokens or keys. No new trade was required for this fix.Validation:
The direct Core development-project TypeScript command is not a clean check on this release baseline: it reports project-reference/dependency errors and pre-existing malformed-input fixture types. Production compilation passed; the introduced malformed-input fixture has an explicit boundary cast.
References
tmp/lighter-rebase-20260910-ercHNq/history-date-proof-run-01/in the Mobile validation checkout.Checklist
No breaking API changes are intended. Mobile keeps the compatible local yalc build until a controller release includes this fix.
Note
Medium Risk
Changes Lighter fill PnL and order timestamp normalization used in trade/order history; incorrect logic would misstate PnL or display dates, but scope is limited to the Lighter adapter with fail-closed validation retained.
Overview
Fixes two Lighter wire-format mismatches at the
lighterAdapterboundary so Mobile history dates and fill rows match venue data.Fill PnL: The venue can omit account realized PnL on opens from flat.
adaptFillFromLighterTradenow treats missing PnL as'0'only after the selected account’s pre-trade position is validated as zero; missing PnL with an open position still fails closed, and malformed supplied PnL is still rejected.Order times: Order API timestamps arrive in Unix seconds while trades and clients expect milliseconds.
adaptOrderFromLightermultiplies values below1e12by 1000 and leaves already-normalized millisecond inputs unchanged; trade fill timestamps are untouched.Types and changelog document optional opening PnL and the seconds-vs-ms order contract; adapter tests cover flat opens, strict existing-position behavior, and timestamp normalization.
Reviewed by Cursor Bugbot for commit 2617b58. Bugbot is set up for automated code reviews on this repo. Configure here.