fix(perps): stabilize Lighter account loading by abretonc7s · Pull Request #10119 · MetaMask/core · GitHub
Skip to content

fix(perps): stabilize Lighter account loading - #10119

Open
abretonc7s wants to merge 1 commit into
mainfrom
fix/perps/lighter-account-loading
Open

fix(perps): stabilize Lighter account loading#10119
abretonc7s wants to merge 1 commit into
mainfrom
fix/perps/lighter-account-loading

Conversation

@abretonc7s

@abretonc7s abretonc7s commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

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

Checklist

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

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.

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

@abretonc7s
abretonc7s force-pushed the fix/perps/lighter-account-loading branch from f84b740 to 7b91634 Compare September 4, 2026 15:50
@abretonc7s
abretonc7s marked this pull request as ready for review September 4, 2026 15:50
@abretonc7s
abretonc7s requested review from a team as code owners September 4, 2026 15:50
@abretonc7s
abretonc7s deployed to default-branch September 4, 2026 15:50 — with GitHub Actions Active
@abretonc7s
abretonc7s enabled auto-merge September 4, 2026 15:50
@abretonc7s abretonc7s added bug Something isn't working team-perps labels Sep 4, 2026
@abretonc7s
abretonc7s force-pushed the fix/perps/lighter-account-loading branch from 7b91634 to dcf7cc6 Compare September 4, 2026 16:27
@abretonc7s

Copy link
Copy Markdown
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working team-perps

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant