feat(temp): Perps Controller integration#40078
Conversation
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
Caution MetaMask internal reviewing guidelines:
|
✨ Files requiring CODEOWNER review ✨👨🔧 @MetaMask/extension-platform (1 files, +34 -0)
🕵️ @MetaMask/extension-privacy-reviewers (1 files, +1 -0)
👨🔧 @MetaMask/perps (4 files, +1370 -0)
📜 @MetaMask/policy-reviewers (8 files, +1700 -0)
Tip Follow the policy review process outlined in the LavaMoat Policy Review Process doc before expecting an approval from Policy Reviewers. 🧪 @MetaMask/qa (1 files, +34 -0)
|
…taMask/metamask-extension into perps/poc-controller-integration-temp
…c-controller-integration-temp
…c-controller-integration-temp
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
| outStream.mmFinished = true; | ||
| this.removeListener('update', handleUpdate); | ||
| patchStore.destroy(); | ||
| perpsStream.destroy(); |
There was a problem hiding this comment.
Misleading indentation places cleanup inside guard block
Low Severity
The perpsStream.destroy() call has 8 spaces of indentation while all other statements inside the same if (!outStream.mmFinished) block use 10 spaces. This makes it visually appear to sit at the same level as the if statement (i.e., outside the block), even though it is syntactically inside. The inconsistency could mislead a future contributor into thinking it's already outside the guard and accidentally moving it or duplicating cleanup logic.
…itTransaction, background implicitly calls it
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
…taMask/metamask-extension into perps/poc-controller-integration-temp
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
|
Builds ready [78ca711]
⚡ Performance Benchmarks
🌐 Dapp Page Load BenchmarksCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
geositta
left a comment
There was a problem hiding this comment.
Thanks for latest changes, this looks good to merge from my side.
The Perps deposit flow is now consistently routed through the controller backed confirmation path, duplicate hook paths were cleaned up, and confirm footer behavior is back to the standard queue flow.
Just one request - a stale jsdoc comment to cleanup.
| * Navigate to the Activity tab when a confirmation disappears without | ||
| * explicit user action (e.g. dapp changes network). Per-type routing | ||
| * after user-initiated confirm/cancel is handled elsewhere (e.g. | ||
| * useShieldConfirm, usePerpsConfirm inside useTransactionConfirm). |
There was a problem hiding this comment.
Please update this comment reference now that usePerpsConfirm hook no longer exists.
| this.#viewActive = active; | ||
| } | ||
|
|
||
| activateStreaming( |
There was a problem hiding this comment.
@gambinish I don’t see current UI callers of this so it would be safer to deprecate/remove this path to prevent regression.
There was a problem hiding this comment.
Can this and the changes to index.tsx be reverted? Are these just remnants from the removed changes?
| })); | ||
|
|
||
| jest.mock('./alerts/useSpenderAlerts', () => ({ | ||
| useSpenderAlerts: () => [], |
There was a problem hiding this comment.
Does this exist or all changes in this file also remnants?
|
We got enough pushback on this PR to warrant breaking it out into more incremental PRs. Here they are in order that they should be merged:
Adding the |





Description
Summary
This PR integrates @metamask/perps-controller into MetaMask Extension, establishing the controller layer for perpetual futures trading functionality. It was scoped down from a larger feature branch to focus on controller integration only — the initial UI was handled in a separate "mocked" PR (#40076, which was merged first).
What's Included
Core controller setup:
Dependencies:
@metamask/perps-controller@^1.0.0(production package — preview dependency fully removed)Related Branches
Changelog
CHANGELOG entry: Integrate Perps Controller
Related issues
Fixes:
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Medium Risk
Adds a new background controller and per-connection streaming lifecycle to
metamask-controllerplus new build/policy allowances for multiple ESM dependencies, which could affect runtime stability and bundle/permission constraints if misconfigured.Overview
Integrates
@metamask/perps-controllerinto the extension controller layer by registering a newPerpsController(with persisted-state merge and a defensiveensureInitializedguard) and exposing a background API surface (perpsInit, trading/data methods, and preferences helpers).Adds a per-UI-connection
PerpsStreamBridgeto manage WebSocket subscription lifecycles and emitperpsStreamUpdatemessages (static account/order/position streams plus dynamic price/orderbook/candle streams), including teardown on disconnect/testnet toggle/outstream end.Updates controller messenger wiring and initialization plumbing, adds a geoblock fallback env var (
MM_PERPS_BLOCKED_REGIONS), removes prior perps-controller mocks in Jest/webpack configs, and extends build/webpack/LavaMoat policies to allow the new perps and SDK ESM/transitive dependencies; includes comprehensive unit tests for the init logic, infrastructure stubs, and stream bridge.Written by Cursor Bugbot for commit 116b98c. This will update automatically on new commits. Configure here.