Skip to content

feat(perps-controller): sync controller from mobile cf20fa64fa#8658

Merged
gambinish merged 3 commits intomainfrom
feat/perps/controller-apr-30
May 1, 2026
Merged

feat(perps-controller): sync controller from mobile cf20fa64fa#8658
gambinish merged 3 commits intomainfrom
feat/perps/controller-apr-30

Conversation

@abretonc7s
Copy link
Copy Markdown
Contributor

@abretonc7s abretonc7s commented Apr 30, 2026

Summary

Syncs app/controllers/perps/ from metamask-mobile commit cf20fa64fa (branch feat/unified-account).

The bulk of this sync lands the HyperLiquid unified-account rollout: a deferred dexAbstraction → unifiedAccount migration triggered from withdraw, trade, and other action entry points so first trades and withdrawals see unified collateral.

Highlights

  • Force HyperLiquid unified-account abstraction with deferred migration; harden migration handling across WS-vs-REST races and transient userAbstraction failures.
  • Mode-aware spot folding and tradeable-balance for unified-mode flows.
  • Restored HyperLiquid withdrawal for Unified Account Mode users; added arb USDC withdraw balance support.
  • Replaced the agentSetAbstraction wire-code magic string with a typed constant.
  • Bumped @nktkas/hyperliquid to ^0.32.2 for the new userAbstraction / userSetAbstraction / agentSetAbstraction API surface.

Validation

  • bash scripts/perps/validate-core-sync.sh --core-path <core> → all 12 steps PASS (build step verified manually via yarn workspace @metamask/perps-controller build since root build:all --clean cleans cross-package refs).
  • dist/PerpsController.{mjs,cjs} retains the webpackIgnore: true safeguard for extension consumers.
  • Suppressions: 8 (unchanged from previous sync).

Test plan

  • CI green
  • yarn workspace @metamask/perps-controller test
  • yarn workspace @metamask/perps-controller build
  • Verify dist/PerpsController.{mjs,cjs} contains webpackIgnore: true

Note

Medium Risk
Updates HyperLiquid trading/withdrawal readiness and balance calculations, which can impact reported funds and migration/signing flows; regression risk is moderate due to new async migration + caching/race-handling logic.

Overview
Forces HyperLiquid accounts toward Unified Account by replacing the legacy dexAbstraction enablement with a new #ensureUnifiedAccountEnabled flow that can defer the user-signed migration until action time (trade/withdraw), while silently enabling it for compatible modes when possible.

Balances are now mode-aware: userAbstraction is fetched and propagated through HyperLiquidSubscriptionService/addSpotBalanceToAccountState to only fold spot USDC into tradeable collateral for unifiedAccount/portfolioMargin, including extra guards to avoid WS-vs-REST races and to retry transient abstraction/migration failures.

Adds new account-setup analytics fields/events, detects hardware wallets to avoid init-time signature prompts, and bumps @nktkas/hyperliquid to ^0.32.2 (plus new typed agentSetAbstraction wire constants).

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

Syncs app/controllers/perps/ from metamask-mobile commit cf20fa64fa.

Highlights:
- Force HyperLiquid unified-account abstraction with deferred dexAbstraction
  → unifiedAccount migration triggered from withdraw, trade, and other action
  entry points so first trades and withdrawals see unified collateral.
- Mode-aware spot folding and tradeable-balance flows for unified mode.
- Hardened migration handling: retry after transient userAbstraction failures,
  preserve REST results across WS-vs-REST races, and recover the resolved
  abstraction mode after migration.
- Restored HyperLiquid withdrawal for Unified Account Mode users and added
  arb USDC withdraw balance support.
- Bumped @nktkas/hyperliquid to ^0.32.2 for the new userAbstraction /
  userSetAbstraction / agentSetAbstraction API surface.
@socket-security
Copy link
Copy Markdown

socket-security Bot commented Apr 30, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updated@​nktkas/​hyperliquid@​0.30.3 ⏵ 0.32.298 +110010096100

View full report

@abretonc7s abretonc7s marked this pull request as ready for review April 30, 2026 15:24
@abretonc7s abretonc7s requested review from a team as code owners April 30, 2026 15:24
@geositta
Copy link
Copy Markdown

@metamaskbot publish-previews

@github-actions
Copy link
Copy Markdown
Contributor

Preview builds have been published. Learn how to use preview builds in other projects.

Expand for full list of packages and versions.
@metamask-previews/account-tree-controller@7.1.0-preview-56dd1249f
@metamask-previews/accounts-controller@37.2.0-preview-56dd1249f
@metamask-previews/address-book-controller@7.1.1-preview-56dd1249f
@metamask-previews/ai-controllers@0.6.3-preview-56dd1249f
@metamask-previews/analytics-controller@1.0.1-preview-56dd1249f
@metamask-previews/analytics-data-regulation-controller@0.0.0-preview-56dd1249f
@metamask-previews/announcement-controller@8.1.0-preview-56dd1249f
@metamask-previews/app-metadata-controller@2.0.1-preview-56dd1249f
@metamask-previews/approval-controller@9.0.1-preview-56dd1249f
@metamask-previews/assets-controller@6.2.1-preview-56dd1249f
@metamask-previews/assets-controllers@105.0.0-preview-56dd1249f
@metamask-previews/authenticated-user-storage@1.0.0-preview-56dd1249f
@metamask-previews/base-controller@9.1.0-preview-56dd1249f
@metamask-previews/base-data-service@0.1.1-preview-56dd1249f
@metamask-previews/bridge-controller@71.0.0-preview-56dd1249f
@metamask-previews/bridge-status-controller@71.1.0-preview-56dd1249f
@metamask-previews/build-utils@3.0.4-preview-56dd1249f
@metamask-previews/chain-agnostic-permission@1.5.0-preview-56dd1249f
@metamask-previews/chomp-api-service@3.0.0-preview-56dd1249f
@metamask-previews/claims-controller@0.5.0-preview-56dd1249f
@metamask-previews/client-controller@1.0.1-preview-56dd1249f
@metamask-previews/compliance-controller@2.0.0-preview-56dd1249f
@metamask-previews/composable-controller@12.0.1-preview-56dd1249f
@metamask-previews/config-registry-controller@0.3.0-preview-56dd1249f
@metamask-previews/connectivity-controller@0.2.0-preview-56dd1249f
@metamask-previews/controller-utils@11.20.0-preview-56dd1249f
@metamask-previews/core-backend@6.2.1-preview-56dd1249f
@metamask-previews/delegation-controller@3.0.0-preview-56dd1249f
@metamask-previews/earn-controller@12.0.0-preview-56dd1249f
@metamask-previews/eip-5792-middleware@3.0.3-preview-56dd1249f
@metamask-previews/eip-7702-internal-rpc-middleware@0.1.0-preview-56dd1249f
@metamask-previews/eip1193-permission-middleware@1.0.3-preview-56dd1249f
@metamask-previews/ens-controller@19.1.1-preview-56dd1249f
@metamask-previews/eth-block-tracker@15.0.1-preview-56dd1249f
@metamask-previews/eth-json-rpc-middleware@23.1.3-preview-56dd1249f
@metamask-previews/eth-json-rpc-provider@6.0.1-preview-56dd1249f
@metamask-previews/foundryup@1.0.1-preview-56dd1249f
@metamask-previews/gas-fee-controller@26.1.1-preview-56dd1249f
@metamask-previews/gator-permissions-controller@4.0.0-preview-56dd1249f
@metamask-previews/geolocation-controller@0.1.2-preview-56dd1249f
@metamask-previews/json-rpc-engine@10.2.4-preview-56dd1249f
@metamask-previews/json-rpc-middleware-stream@8.0.8-preview-56dd1249f
@metamask-previews/keyring-controller@25.3.0-preview-56dd1249f
@metamask-previews/logging-controller@8.0.1-preview-56dd1249f
@metamask-previews/message-manager@14.1.1-preview-56dd1249f
@metamask-previews/messenger@1.2.0-preview-56dd1249f
@metamask-previews/messenger-cli@0.2.0-preview-56dd1249f
@metamask-previews/money-account-balance-service@0.2.0-preview-56dd1249f
@metamask-previews/money-account-controller@0.1.0-preview-56dd1249f
@metamask-previews/money-account-upgrade-controller@1.3.0-preview-56dd1249f
@metamask-previews/multichain-account-service@8.0.1-preview-56dd1249f
@metamask-previews/multichain-api-middleware@2.0.0-preview-56dd1249f
@metamask-previews/multichain-network-controller@3.0.6-preview-56dd1249f
@metamask-previews/multichain-transactions-controller@7.0.4-preview-56dd1249f
@metamask-previews/name-controller@9.1.1-preview-56dd1249f
@metamask-previews/network-controller@30.1.0-preview-56dd1249f
@metamask-previews/network-enablement-controller@5.0.2-preview-56dd1249f
@metamask-previews/notification-services-controller@23.1.0-preview-56dd1249f
@metamask-previews/passkey-controller@1.0.0-preview-56dd1249f
@metamask-previews/permission-controller@12.3.0-preview-56dd1249f
@metamask-previews/permission-log-controller@5.1.0-preview-56dd1249f
@metamask-previews/perps-controller@4.0.0-preview-56dd1249f
@metamask-previews/phishing-controller@17.1.1-preview-56dd1249f
@metamask-previews/polling-controller@16.0.4-preview-56dd1249f
@metamask-previews/preferences-controller@23.1.0-preview-56dd1249f
@metamask-previews/profile-metrics-controller@3.1.3-preview-56dd1249f
@metamask-previews/profile-sync-controller@28.0.2-preview-56dd1249f
@metamask-previews/ramps-controller@13.2.0-preview-56dd1249f
@metamask-previews/rate-limit-controller@7.0.1-preview-56dd1249f
@metamask-previews/react-data-query@0.2.0-preview-56dd1249f
@metamask-previews/remote-feature-flag-controller@4.2.0-preview-56dd1249f
@metamask-previews/sample-controllers@4.0.4-preview-56dd1249f
@metamask-previews/seedless-onboarding-controller@9.1.0-preview-56dd1249f
@metamask-previews/selected-network-controller@26.1.0-preview-56dd1249f
@metamask-previews/shield-controller@5.1.1-preview-56dd1249f
@metamask-previews/signature-controller@39.2.0-preview-56dd1249f
@metamask-previews/snap-account-service@0.0.0-preview-56dd1249f
@metamask-previews/social-controllers@2.2.0-preview-56dd1249f
@metamask-previews/storage-service@1.0.1-preview-56dd1249f
@metamask-previews/subscription-controller@6.1.2-preview-56dd1249f
@metamask-previews/transaction-controller@65.0.0-preview-56dd1249f
@metamask-previews/transaction-pay-controller@20.1.0-preview-56dd1249f
@metamask-previews/user-operation-controller@41.2.0-preview-56dd1249f

Copy link
Copy Markdown

@cursor cursor Bot left a comment

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 7e9e273. Configure here.

const HARDWARE_KEYRING_TYPES = new Set<string>([
'Ledger Hardware',
'QR Hardware Wallet Device',
]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Incomplete hardware keyring set misses Trezor/Lattice/OneKey wallets

Medium Severity

HARDWARE_KEYRING_TYPES only lists 'Ledger Hardware' and 'QR Hardware Wallet Device', but the canonical KeyringTypes enum in @metamask/keyring-controller also includes 'Trezor Hardware', 'Lattice Hardware', and 'OneKey Hardware'. Because isSelectedHardwareWallet() returns false for those wallets, #ensureReady passes allowUserSigning: true during init, causing an unwanted EIP-712 signing prompt on those hardware devices when users merely open the Perps section — the exact prompt spam the deferral logic was designed to prevent.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 7e9e273. Configure here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Unsure if this is intentional or not. I'm going to assume that it is. If we need to support other hw wallet types we can always publish another release.

@gambinish gambinish enabled auto-merge May 1, 2026 18:46
@gambinish gambinish added this pull request to the merge queue May 1, 2026
Merged via the queue into main with commit 0cdbce3 May 1, 2026
366 checks passed
@gambinish gambinish deleted the feat/perps/controller-apr-30 branch May 1, 2026 19:09
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.

3 participants