Skip to content

fix(perps): normalize Lighter history wire values - #10187

Open
abretonc7s wants to merge 3 commits into
mainfrom
fix/perps/lighter-history-wire-units
Open

fix(perps): normalize Lighter history wire values#10187
abretonc7s wants to merge 3 commits into
mainfrom
fix/perps/lighter-history-wire-units

Conversation

@abretonc7s

@abretonc7s abretonc7s commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Explanation

Fix two Lighter history wire contracts observed while validating the Mobile integration:

  • The venue omits account PnL on opens from a flat position. Accept that omission as zero only after validating that the selected account's pre-trade position is zero. Missing PnL for existing positions and malformed supplied PnL still fail closed.
  • Order endpoints return seconds, whereas trade timestamps and client order displays use milliseconds. Normalize order timestamps at the adapter boundary, retaining already-normalized millisecond inputs. Do not change trade timestamps.

Evidence: testnet trade 20887 omitted both PnL fields and reported a zero pre-position; canceled order 844424929822070 reported timestamp 1789088736. Raw authenticated reads were retained locally without auth tokens or keys. No new trade was required for this fix.

Validation:

  • Regressions first: five expected failures, then all 79 adapter tests passed.
  • Full Perps suite: 79 suites, 3,598 tests passed, 40 skipped.
  • Full Core production build, focused ESLint, formatting and package changelog validation passed.
  • Built from the compatible 16.2.0 release and installed through targeted yalc in Mobile. Mobile full TypeScript and 189 focused history tests passed.
  • iOS mm-1: observed all eight opening/closing BTC history rows. Final eight-node Harness date proof passed, including the exact canceled order's millisecond identity, visible canceled row, inspected screenshot under Today, and no BTC position/open-order residue.

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

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

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 lighterAdapter boundary so Mobile history dates and fill rows match venue data.

Fill PnL: The venue can omit account realized PnL on opens from flat. adaptFillFromLighterTrade now 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. adaptOrderFromLighter multiplies values below 1e12 by 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.

@abretonc7s abretonc7s self-assigned this Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant