Skip to content

fix(perps): handle inactive Lighter market metadata - #10110

Merged
abretonc7s merged 2 commits into
mainfrom
fix/perps/lighter-inactive-market-metadata
Sep 4, 2026
Merged

abretonc7s merged 2 commits into
mainfrom
fix/perps/lighter-inactive-market-metadata

Conversation

@abretonc7s

@abretonc7s abretonc7s commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Explanation

Lighter retains inactive markets for historical identity and can zero their order minimums and margin fractions. The strict response decoder rejected those retired rows, which prevented otherwise valid active markets from loading.

This change accepts zero constraints only for inactive rows, omits retired markets whose risk metadata cannot produce canonical market data, and preserves inactive rows with valid metadata as delisted. Positions left on retired markets remain readable using their current position leverage as a non-tradable cap. Active markets remain strict and fail closed on zero or malformed constraints.

Validated with:

  • 322 focused Lighter service/provider tests
  • Full @metamask/perps-controller test suite and Core build
  • Targeted ESLint, formatting, and changelog validation
  • Mobile yalc integration using package 16.1.0 (yalc.sig ee73aeec8330f58ce0a6e9c6b4cf42a3)
  • A 36/36-node iOS recipe covering Lighter and Hyperliquid on mainnet and testnet
  • Revalidated Lighter mainnet on iOS mm-1: live markets loaded and the invalid inactive-market metadata error was absent

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 — not applicable; this change is non-breaking

Note

Low Risk
Scoped to Lighter public market-metadata parsing and listing; active markets remain fail-closed on bad constraints, with no changes to signing, deposits, or position operations.

Overview
Fixes Lighter market loading when the venue returns inactive perp rows with zeroed minimum order sizes or margin fractions—metadata Lighter keeps for history but that previously made the strict HTTP decoder reject the whole response and block active markets.

LighterClientService now allows zero minimums and margin fractions only when status === 'inactive', with refine validators still requiring positive values for active markets. LighterProvider adds isInactiveMarketWithoutUsableRiskMetadata to drop those retired rows from getMarketDataWithPrices and margin caching, skips them in getMarkets when leverage metadata is omitted (instead of throwing), and still surfaces inactive markets with valid risk data as delisted. Tests cover both omission and preservation paths.

Reviewed by Cursor Bugbot for commit 445456c. Bugbot is set up for automated code reviews on this repo. Configure here.

@abretonc7s
abretonc7s force-pushed the fix/perps/lighter-inactive-market-metadata branch from ef8dd5b to 445456c Compare September 4, 2026 11:04
@abretonc7s
abretonc7s marked this pull request as ready for review September 4, 2026 11:06
@abretonc7s
abretonc7s requested review from a team as code owners September 4, 2026 11:06

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 445456c. Configure here.

Comment thread packages/perps-controller/src/providers/LighterProvider.ts
@abretonc7s
abretonc7s enabled auto-merge September 4, 2026 11:43
@abretonc7s
abretonc7s added this pull request to the merge queue Sep 4, 2026
Merged via the queue into main with commit 784ba54 Sep 4, 2026
46 checks passed
@abretonc7s
abretonc7s deleted the fix/perps/lighter-inactive-market-metadata branch September 4, 2026 15:23
pull Bot pushed a commit to Reality2byte/core that referenced this pull request Sep 8, 2026
## Explanation

Lighter account discovery can return sparse balance fields, and API code
`21100` authoritatively means the selected wallet has no venue account.
The provider previously rejected funded accounts during discovery and
left no-account subscribers waiting indefinitely.

This change validates only identity fields during address discovery,
queries all API-key slots so non-default registrations are found, emits
empty account state only for confirmed no-account responses, and
preserves existing state for transport, auth, and integrity failures.
REST trade decoding now permits an omitted counterparty PnL while the
fill adapter still requires the selected account's PnL. It also removes
the per-frame Lighter price debug log.

Validated with:

- Full `@metamask/perps-controller` suite (89.48% line coverage) and
full Core monorepo build
- Focused Lighter service/adapter tests (`109/109`), targeted ESLint,
Prettier, and package changelog validation
- Mobile typecheck against yalc package `16.1.0` (`yalc.sig`
`12ffef2527e5de1f35bb8b3cff91fa02`)
- iOS `mm-1` no-account settlement on `dev7`: markets rendered with no
balance, positions, orders, or activity
- iOS funded Lighter testnet lifecycle on rebased Mobile `5beed0f35b`
using published `mm-harness@0.47.1`: BTC order `242458746910186`,
position `0.00012` at `81267.2`, close `68943931413978`, final state
flat (`26/26` recipe nodes)

## References

- Related to https://consensyssoftware.atlassian.net/browse/TAT-3766
- Follow-up to MetaMask#10110
- Unblocks MetaMask/metamask-mobile#34865

## Checklist

- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation for new or updated code as appropriate
- [x] I've communicated consumer-facing changes in the package changelog
- [ ] I've introduced breaking changes — not applicable; this change is
non-breaking

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Changes Lighter account-binding, empty-state emission, and API-key
discovery paths that affect trading readiness and live subscriptions;
behavior is narrowed with tests but mistakes could show wrong balances
or block registration.
> 
> **Overview**
> Fixes **Lighter account discovery and subscriber settlement** so
wallets with funded venue accounts are not rejected on sparse discovery
payloads, and UI no longer spins forever when the wallet truly has no
Lighter account.
> 
> **Account resolution:** `accountsByL1Address` now validates only
identity fields (`AccountSummaryStruct` / `LighterAccountSummary`),
while full `account` reads stay strict. API code **21100** and empty
`subAccounts` map to `LighterAccountNotFoundError`. On channel setup,
that case emits **authoritative empty** account/positions/orders;
transport, auth, capability, and malformed responses **keep the last
snapshot**.
> 
> **Trading readiness:** Venue key checks call
`getApiKeys(accountIndex)` (all slots) instead of probing a single
unused slot, which previously returned `api key not found` and blocked
first-time registration.
> 
> **History / noise:** REST trade decoding allows omitted
`askAccountPnl` / `bidAccountPnl`; the fill adapter still requires PnL
for the **selected** account. Per-frame Lighter price-stream debug
logging is removed.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
dcf7cc6. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
@abretonc7s abretonc7s mentioned this pull request Sep 9, 2026
3 of 4 tasks
pull Bot pushed a commit to Reality2byte/core that referenced this pull request Sep 9, 2026
## Explanation

Publishes `@metamask/perps-controller@16.2.0`. No other workspace
packages are version-bumped.

This is a minor, not a major. Expanding `PerpsErrorCode` with the
margin-mode codes is additive; clients should handle unknown codes in a
catch-all rather than an exhaustive map. Optional
`OrderParams.marginMode` and `MarketInfo.marginMode` keep existing
callers on the isolated-leverage path.

Also includes the HyperLiquid TWAP terminal-record fix and Lighter
account/market/log fixes.

## References

- MetaMask#10136
- MetaMask#10122
- MetaMask#10119
- MetaMask#10110

## Checklist

- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md)
- [ ] I've introduced [breaking
changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md)
in this PR and have prepared draft pull requests for clients and
consumer packages to resolve them

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Low Risk**
> This PR only bumps versions and edits changelog/README/JSDoc; trading
behavior ships in the referenced feature PRs, not in this diff.
> 
> **Overview**
> Cuts **release 1245.0.0**, publishing
**`@metamask/perps-controller@16.2.0`** (monorepo root version bump
only; no other workspace packages change).
> 
> The diff is mostly release bookkeeping: **`package.json` versions**, a
new **`[16.2.0]` changelog** section (margin-mode error codes and
HyperLiquid `marginMode` API, TWAP terminal-record fix, Lighter
account/market/logging fixes — already merged via linked PRs), and
**consumer guidance** updates.
> 
> **Policy clarification:** new **`PerpsErrorCode` values (including the
four margin-mode codes) are documented as additive minors**, not
breaking — the changelog drops the prior **BREAKING** wording.
**`README.md`** adds an **Error codes** section and
**`perpsErrorCodes.ts`** JSDoc now tells clients to use a **catch-all**
for unknown codes instead of an exhaustive `Record<PerpsErrorCode, …>`.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
add8f2d. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants