Skip to content

feat(perps): add reliable Lighter trading and advanced orders - #10638

Merged
geositta merged 192 commits into
mainfrom
feat/lighter-native-trigger-orders
Oct 5, 2026
Merged

geositta merged 192 commits into
mainfrom
feat/lighter-native-trigger-orders

Conversation

@abretonc7s

@abretonc7s abretonc7s commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Explanation

Recover Lighter trading access for the selected wallet after restore, preserve other devices' keys, and isolate account/network changes.

Add supported trigger orders, position protection, Scale, post-only limits, order editing and isolated-margin updates. Reconcile uncertain submissions without replay. Preserve accepted orders and cancellations through response loss, restart and account changes. Delayed Chase cancellation confirmation uses observation-only reconciliation, preventing another cancellation dispatch.

Tests, build and Mobile integration pass. Basic testnet trading, restart and reconnect are validated; final advanced-order and reinstall validation remain pending. TWAP is unavailable, Chase is a bounded testnet probe, and further TP/SL work is deferred.

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 prepared draft consumer PRs

Note

High Risk
Large, breaking changes to Lighter order placement, protection, and financial dispatch with new recovery/Chase reconciliation paths; incorrect settlement or lifecycle fencing could block trading or mishandle ambiguous venue state.

Overview
Expands perps-controller with durable Lighter trading, recovery, and advanced order flows, plus controller/messenger APIs and monorepo test wiring so clients can observe and reconcile without blind replay.

Controller & aggregation adds lifecycle-fenced actions: getChaseOrderOwnership and reconcileChaseOrderCancellation (read/settle only—no new cancel dispatch), attached and Scale group list/review, reviewRecoveryVenue, reconcileRecoveredDispatches, and resolveRecoveryProtection. placeOrder/validateOrder snapshot Scale intent via captureScaleOrderParams; testnet Lighter can opt into chaseTestnetProbe from client config. Aggregated subscriptions tag order/fill callbacks with providerId and forward optional onError.

Lighter & HyperLiquid behavior (documented heavily in README/CHANGELOG) includes explicit margin mode and updateMargin, standalone triggers, partial/independent position TP/SL with expectedPosition, native attached OTO/OTOCO, Scale preview/placement/cancel with expectedScaleLadder, post-only limits, same-order editOrder settlement, multi-slot key recovery and dispatch reconciliation, and default-off testnet Chase/TWAP probes (LighterTwapService, Chase utilities/constants). Breaking Lighter changes: attached TP/SL on placeOrder, stricter grouped-signer shapes, new capability/Scale states, and rejecting stray triggerPrice on basic orders. HyperLiquid gains guarded post-sign dispatch (createGuardedHyperLiquidClient) and richer HYPERLIQUID_ORDER_CAPABILITIES.

Tooling maps @metamask/perps-controller/constants/* and utils/* to source in Jest; package Jest compiles selected ESM SDK deps on Node 22.

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

@abretonc7s abretonc7s self-assigned this Sep 30, 2026
@abretonc7s
abretonc7s marked this pull request as ready for review September 30, 2026 23:19
@abretonc7s
abretonc7s requested review from a team as code owners September 30, 2026 23:19

@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.

Stale Bugbot comment from a previous run.

Comment thread packages/perps-controller/src/providers/LighterProvider.ts
@abretonc7s
abretonc7s changed the base branch from fix/lighter-device-key-recovery to main October 2, 2026 23:15
@abretonc7s
abretonc7s dismissed geositta’s stale review October 2, 2026 23:15

The base branch was changed.

@abretonc7s
abretonc7s marked this pull request as ready for review October 3, 2026 00:08
@abretonc7s
abretonc7s deployed to default-branch October 3, 2026 00:08 — with GitHub Actions Active

@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.

Stale Bugbot comment from a previous run.

Comment thread packages/perps-controller/src/PerpsController.ts Outdated

@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 e3d7a4c. Configure here.

Comment thread packages/perps-controller/src/services/LighterChaseService.ts
@abretonc7s
abretonc7s enabled auto-merge October 5, 2026 09:57

@geositta geositta left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approve, the three findings are resolved: protection obligations survive key slot migration, trigger support excludes spot markets, and recovery cannot continue a guarded removal after its position precondition fails.

@abretonc7s
abretonc7s added this pull request to the merge queue Oct 5, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 5, 2026
@geositta
geositta added this pull request to the merge queue Oct 5, 2026
Merged via the queue into main with commit bf084f6 Oct 5, 2026
346 checks passed
@geositta
geositta deleted the feat/lighter-native-trigger-orders branch October 5, 2026 22:20
@abretonc7s abretonc7s mentioned this pull request Oct 6, 2026
4 tasks done
Naz-Ovh pushed a commit to 0x-fork/metamask-core that referenced this pull request Oct 7, 2026
## Explanation

Releases `@metamask/perps-controller` **19.0.0 → 20.0.0**. The monorepo
version goes **1314.0.0 → 1315.0.0**.

No other package is being published. Perps-controller has no in-monorepo
dependents that need a workspace range bump.

The bump is **major**. Public unions and Lighter order validation
change:

- **BREAKING:** Lighter `placeOrder` / `validateOrder` accept supported
native attached TP/SL instead of refusing all attachments. Gate
forwarding on `attachedTpsl`.
([MetaMask#10638](MetaMask#10638))
- **BREAKING:** Grouped Lighter signer calls require grouping/count
`1/2` or `2/2` with two orders, or `3/3` with three orders.
([MetaMask#10638](MetaMask#10638))
- **BREAKING:** `ScaleOrderChild.state` adds `canceled`.
([MetaMask#10638](MetaMask#10638))
- **BREAKING:** `DirectProviderOrderCapabilitiesUnavailableReason` and
`OrderCapabilitiesUnavailableReason` add `order_market_unsupported`.
([MetaMask#10638](MetaMask#10638))
- **BREAKING:** Stray `triggerPrice` on Lighter basic market/limit
orders is refused with `ORDER_TRIGGER_PRICE_NOT_SUPPORTED`.
([MetaMask#10638](MetaMask#10638))
- **BREAKING:** Lighter position TP/SL replacement and removal preserve
independent partial triggers.
([MetaMask#10638](MetaMask#10638))
- **BREAKING:** `OrderFill.pnl` is optional when the venue omits
realized PnL. Treat missing as unknown, not zero.
([MetaMask#10605](MetaMask#10605))

Also ships Lighter Scale/Chase/TWAP probe work, fee quote attribution
(`feeSource`, `metamaskFeeDiscountBips`), HyperLiquid agent/signing
fixes, quieter optional-messenger failures, and watchlist
hydration/write races.

## Changelog

Moved Unreleased entries in `packages/perps-controller/CHANGELOG.md`
under `[20.0.0]`. Removed Uncategorized monorepo release markers
(1311–1314) that do not affect package consumers. Dropped a duplicate
Chase probe summary already covered by more specific entries.

## References

- Source PRs: [MetaMask#10638](MetaMask#10638),
[MetaMask#10618](MetaMask#10618),
[MetaMask#10605](MetaMask#10605),
[MetaMask#10643](MetaMask#10643),
[MetaMask#10650](MetaMask#10650),
[MetaMask#10651](MetaMask#10651),
[MetaMask#10665](MetaMask#10665),
[MetaMask#10670](MetaMask#10670),
[MetaMask#10683](MetaMask#10683)
- No in-monorepo consumer packages to bump. Mobile and Extension
exhaustive union matches need the new members on upgrade. Lighter
attached TP/SL stays gated on `attachedTpsl` and client rollout.

## 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)
- [x] 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

Made with [Cursor](https://cursor.com)

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
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