refactor(perps): perps-controller folder setup#25813
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. |
…ollers/ Move all platform-independent code into controllers/ directory to prepare for core monorepo extraction. Original locations now re-export from controllers/ for backward compatibility.
…o controllers/
Move 4 HyperLiquid service files and hyperLiquidOrderBookProcessor into
controllers/ so HyperLiquidProvider imports are fully internal. Add
marketDataFormatters to PerpsPlatformDependencies for portable number
formatting (replaces direct mobile mobileMarketDataFormatters import).
Moved files:
- services/HyperLiquid{Client,Subscription,Wallet}Service → controllers/services/
- services/TradingReadinessCache → controllers/services/
- utils/hyperLiquidOrderBookProcessor → controllers/utils/
Only TradingReadinessCache keeps a re-export stub (used by PerpsConnectionManager).
…ntrollers/ Final portability step: copy ensureError into controllers/utils/errorUtils.ts (25-line pure utility), move PerpsMeasurementName enum into controllers/constants/performanceMetrics.ts, update 13 service files to import from local errorUtils, and rewrite mobile-cleanup-dependencies.md as a migration guide.
…ias + move controllers/ to app/controllers/perps/ - Physically move app/components/UI/Perps/controllers/ to app/controllers/perps/ - Add @metamask/perps-controller path alias in tsconfig, babel, metro, jest configs - Update ~130 files to import from alias instead of relative paths - Replace import/no-restricted-paths with no-restricted-imports ESLint rule (operates on literal import strings, allowing the alias while blocking relative imports) - Add PR_DESC.md with full PR description
…ocol-agnostic naming
…troller Rewrite ~315 consumer files to import from the root barrel instead of deep sub-paths (types/, constants/, utils/, services/, selectors/). Expand the barrel in app/controllers/perps/index.ts to re-export all sub-modules, create utils/index.ts barrel, and add sub-module re-exports to types/index.ts. Delete shadowing utils.ts file that blocked the utils/ directory barrel.
…t paths Add @metamask/perps-controller to .depcheckrc.yml ignore list (tsconfig path alias, not an npm package). Update PERFORMANCE_CONFIG imports in handleHomeUrl and Wallet tests to use the controller alias instead of the old UI-layer path. Update Wallet snapshots after design-system package upgrade on main.
8ecf7ea to
7fc41bb
Compare
app/components/UI/Perps/components/PerpsMarketTradesList/PerpsMarketTradesList.test.tsx
Show resolved
Hide resolved
app/components/UI/Perps/components/PerpsCompactOrderRow/PerpsCompactOrderRow.test.tsx
Outdated
Show resolved
Hide resolved
...omponents/UI/Perps/components/PerpsLimitPriceBottomSheet/PerpsLimitPriceBottomSheet.test.tsx
Show resolved
Hide resolved
7fc41bb to
541e06d
Compare
Resolve 16 merge conflicts from recent main activity: - MYX Provider Stage 1 (#25773) - Lightweight Position Display (#25685) - Object parameter consistency (#25688) Conflict resolution strategy: - Controller core (6 files): merged main's additions, kept @metamask/perps-controller alias imports - MYX Provider (2 files): accepted main's content at new controller path, fixed imports - UI layer (5 files): merged both sides, fixed import paths to use alias - Token Details (2 files): took main's additions, fixed imports to use alias - tsconfig.json: kept alias + merged main's json-rpc-engine path
e00c885
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection:
Based on the tag descriptions:
The changes are contained within the Perps feature area and don't affect core wallet functionality, navigation, or other critical paths. The risk is medium because while the changes are extensive, they are isolated to the Perps feature. Performance Test Selection: |
|



Description
Per ADR-042 ("PerpsController Package Location"), the team is adopting a mobile-first strategy for perps: mobile remains the single source of truth, and the controller will be published as
@metamask/perps-controlleron npm so the Extension can achieve feature parity.The controller code originally lived under
app/components/UI/Perps/controllers/— that co-location with UI was the right design when perps was a mobile-only feature. Now that cross-platform publication is the goal, ADR-042 requires a prerequisite step: simulate package boundaries inside the mobile repo before actual extraction. This PR implements that "Mobile Isolation" section of ADR-042. No functional changes — this is a pure reorganization.Three outcomes:
Controller code lives at
app/controllers/perps/— physically separated from the UI layer and consistent with where other controllers sit in the mobile codebase. Services that were always part of the controller layer (connection management, trading readiness, all HyperLiquid services) now live there too, with aServiceContextabstraction for runtime injection of mobile-specific infrastructure.All imports use the
@metamask/perps-controlleralias — configured intsconfig.json,babel.config.js,metro.config.js, andjest.config.js. This simulates the npm package boundary so that every import site is ready for extraction with zero diff.ESLint
no-restricted-importsrule enforces the boundary going forward — direct imports fromapp/controllers/perps/are disallowed; all consumers must go through the alias, exactly as they would with a real npm package.Changelog
CHANGELOG entry: null
Related issues
Fixes: N/A — internal refactor for perps-controller portability
Manual testing steps
Screenshots/Recordings
N/A — pure refactor, no UI changes.
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Medium Risk
Broad refactor across many Perps modules changing import sources and moving constants, which risks subtle runtime/test breakages if any symbol wiring diverges. No business-logic changes are intended, but the new platform dependency surface (feature flags/formatters) needs verification.
Overview
Perps controller/package boundary is enforced. Adds an ESLint
no-restricted-importsrule to block direct imports fromapp/controllers/perps/**and updates depcheck config to ignore the new@metamask/perps-controllerTS path alias.UI code is migrated to the alias. Most Perps screens, components, hooks, and tests switch their imports (types, constants, helpers like
getPerpsDisplaySymbol, analytics event names, chart enums, trading calculations) from localcontrollers/*,constants/*, andutils/*to@metamask/perps-controller, and removes a now-redundantcontrollers/utils.tshelper.Mobile-only constants and adapters are carved out.
constants/chartConfig.tsandconstants/perpsConfig.tsare slimmed to UI-specific exports while portable enums/pure logic move to the controller package; newconstants/perpsUIConfig.tsholds UI-only fee/timing/spread values. The mobile platform bridge (mobileInfrastructure.ts) is extended to provide controller dependencies for version-gated feature flags and market-data formatting utilities.Written by Cursor Bugbot for commit 8350386. This will update automatically on new commits. Configure here.