Skip to content

refactor(perps): perps-controller folder setup#25813

Merged
abretonc7s merged 26 commits intomainfrom
refactor/perps/reorg-cleanup
Feb 11, 2026
Merged

refactor(perps): perps-controller folder setup#25813
abretonc7s merged 26 commits intomainfrom
refactor/perps/reorg-cleanup

Conversation

@abretonc7s
Copy link
Contributor

@abretonc7s abretonc7s commented Feb 7, 2026

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-controller on 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:

  1. 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 a ServiceContext abstraction for runtime injection of mobile-specific infrastructure.

  2. All imports use the @metamask/perps-controller alias — configured in tsconfig.json, babel.config.js, metro.config.js, and jest.config.js. This simulates the npm package boundary so that every import site is ready for extraction with zero diff.

  3. ESLint no-restricted-imports rule enforces the boundary going forward — direct imports from app/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

Feature: Perps trading functionality unchanged after refactor

  Scenario: User opens perps market view
    Given the user has perps feature enabled
    When user navigates to the perps trading screen
    Then the market list loads correctly with live prices

  Scenario: User places a perps order
    Given the user is on a perps market detail page
    When user enters order parameters and submits
    Then the order executes successfully via HyperLiquid

  Scenario: User views open positions and orders
    Given the user has existing perps positions
    When user navigates to positions/orders tab
    Then all positions and open orders display correctly

Screenshots/Recordings

N/A — pure refactor, no UI changes.

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

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-imports rule to block direct imports from app/controllers/perps/** and updates depcheck config to ignore the new @metamask/perps-controller TS 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 local controllers/*, constants/*, and utils/* to @metamask/perps-controller, and removes a now-redundant controllers/utils.ts helper.

Mobile-only constants and adapters are carved out. constants/chartConfig.ts and constants/perpsConfig.ts are slimmed to UI-specific exports while portable enums/pure logic move to the controller package; new constants/perpsUIConfig.ts holds 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.

@abretonc7s abretonc7s requested review from a team as code owners February 7, 2026 11:17
@github-actions
Copy link
Contributor

github-actions bot commented Feb 7, 2026

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.

@metamaskbot metamaskbot added the team-perps Perps team label Feb 7, 2026
@abretonc7s abretonc7s changed the title Refactor/perps/reorg cleanup refactor(perps): perps-controller folder setup Feb 7, 2026
…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
…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.
@abretonc7s abretonc7s force-pushed the refactor/perps/reorg-cleanup branch from 8ecf7ea to 7fc41bb Compare February 8, 2026 00:34
Copy link

@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 3 potential issues.

@abretonc7s abretonc7s force-pushed the refactor/perps/reorg-cleanup branch from 7fc41bb to 541e06d Compare February 8, 2026 00:55
@abretonc7s abretonc7s added no-changelog no-changelog Indicates no external facing user changes, therefore no changelog documentation needed no changelog required No changelog entry is required for this change labels Feb 8, 2026
aganglada
aganglada previously approved these changes Feb 9, 2026
sahar-fehri
sahar-fehri previously approved these changes Feb 9, 2026
Copy link
Contributor

@sahar-fehri sahar-fehri left a comment

Choose a reason for hiding this comment

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

LGTM

gambinish
gambinish previously approved these changes Feb 10, 2026
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
@abretonc7s abretonc7s dismissed stale reviews from gambinish, sahar-fehri, and aganglada via e00c885 February 11, 2026 03:20
gambinish
gambinish previously approved these changes Feb 11, 2026
@github-actions
Copy link
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokePerps, SmokeWalletPlatform, SmokeConfirmations
  • Selected Performance tags: @PerformancePreps
  • Risk Level: medium
  • AI Confidence: 85%
click to see 🤖 AI reasoning details

E2E Test Selection:
This PR contains 100 files, all related to Perps (Perpetuals) trading functionality. The changes include:

  1. Perps UI Components: Extensive changes to Perps views (PerpsHomeView, PerpsMarketListView, PerpsWithdrawView, PerpsOrderView, PerpsPositionsView, etc.) and components (PerpsMarketList, PerpsCard, PerpsMarketHeader, etc.)

  2. AssetOverview Integration: The AssetOverview component includes Perps Discovery Banner integration that shows when viewing assets with available Perps markets

  3. Configuration Files: Updates to .depcheckrc.yml (adding @metamask/perps-controller to ignores) and .eslintrc.js (ESLint rules for Perps controller imports)

Based on the tag descriptions:

  • SmokePerps: Directly tests perpetuals trading functionality including Add Funds flow, balance verification, and Perps interface - all directly affected by these changes
  • SmokeWalletPlatform: Per the tag description, "Perps is also a section inside the Trending tab (SmokeWalletPlatform); changes to Perps views (headers, lists, full views, e.g. PerpsHomeView, PerpsMarketListView, PerpsWithdrawView) affect Trending"
  • SmokeConfirmations: Per the SmokePerps tag description, "When selecting SmokePerps, also select SmokeConfirmations (Add Funds deposits are on-chain transactions)"

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:
The PR contains extensive changes to Perps UI components including PerpsHomeView, PerpsMarketListView, PerpsPositionsView, and various Perps components. These changes could impact perps market loading, position management, and add funds flow performance. The @PerformancePreps tag specifically covers 'perps market loading, position management, add funds flow, and order execution' which are all areas affected by this PR.

View GitHub Actions results

@sonarqubecloud
Copy link

Copy link
Contributor

@caieu caieu left a comment

Choose a reason for hiding this comment

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

LGTM

@abretonc7s abretonc7s added this pull request to the merge queue Feb 11, 2026
Copy link
Contributor

@caieu caieu left a comment

Choose a reason for hiding this comment

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

LGTM

Merged via the queue into main with commit 4cd86d3 Feb 11, 2026
97 of 98 checks passed
@abretonc7s abretonc7s deleted the refactor/perps/reorg-cleanup branch February 11, 2026 12:06
@github-actions github-actions bot locked and limited conversation to collaborators Feb 11, 2026
@metamaskbot metamaskbot added the release-7.66.0 Issue or pull request that will be included in release 7.66.0 label Feb 11, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

no changelog required No changelog entry is required for this change no-changelog no-changelog Indicates no external facing user changes, therefore no changelog documentation needed release-7.66.0 Issue or pull request that will be included in release 7.66.0 size-XL skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. team-perps Perps team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants