feat(perps-controller): sync controller from mobile cf20fa64fa#8658
feat(perps-controller): sync controller from mobile cf20fa64fa#8658
Conversation
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.
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
@metamaskbot publish-previews |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
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.
Reviewed by Cursor Bugbot for commit 7e9e273. Configure here.
| const HARDWARE_KEYRING_TYPES = new Set<string>([ | ||
| 'Ledger Hardware', | ||
| 'QR Hardware Wallet Device', | ||
| ]); |
There was a problem hiding this comment.
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)
Reviewed by Cursor Bugbot for commit 7e9e273. Configure here.
There was a problem hiding this comment.
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.


Summary
Syncs
app/controllers/perps/from metamask-mobile commitcf20fa64fa(branchfeat/unified-account).The bulk of this sync lands the HyperLiquid unified-account rollout: a deferred
dexAbstraction → unifiedAccountmigration triggered from withdraw, trade, and other action entry points so first trades and withdrawals see unified collateral.Highlights
userAbstractionfailures.agentSetAbstractionwire-code magic string with a typed constant.@nktkas/hyperliquidto^0.32.2for the newuserAbstraction/userSetAbstraction/agentSetAbstractionAPI surface.Validation
bash scripts/perps/validate-core-sync.sh --core-path <core>→ all 12 steps PASS (build step verified manually viayarn workspace @metamask/perps-controller buildsince root build:all--cleancleans cross-package refs).dist/PerpsController.{mjs,cjs}retains thewebpackIgnore: truesafeguard for extension consumers.Test plan
yarn workspace @metamask/perps-controller testyarn workspace @metamask/perps-controller builddist/PerpsController.{mjs,cjs}containswebpackIgnore: trueNote
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
dexAbstractionenablement with a new#ensureUnifiedAccountEnabledflow 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:
userAbstractionis fetched and propagated throughHyperLiquidSubscriptionService/addSpotBalanceToAccountStateto only fold spot USDC into tradeable collateral forunifiedAccount/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/hyperliquidto^0.32.2(plus new typedagentSetAbstractionwire constants).Reviewed by Cursor Bugbot for commit 7e9e273. Bugbot is set up for automated code reviews on this repo. Configure here.