Skip to content

Commit 39190c9

Browse files
authored
refactor: remove swaps-controller package (#27547)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> The `@metamask/swaps-controller` package is no longer needed — swaps functionality is now handled by `BridgeController` and `BridgeStatusController`. This PR removes the package and all associated wiring: - **Deleted** the controller initializer (`swaps-controller-init.ts`) and its messenger (`swaps-controller-messenger.ts`), along with their tests. - **Removed** `SwapsController` from the Engine initialization, types, state-change event constants, and Sentry state mask. - **Cleaned up** the swaps Redux reducer by removing all selectors that read from `SwapsController` state (e.g. `swapsTokensObjectSelector`, `swapsTokensMultiChainObjectSelector`, `swapsTopAssetsSelector`, etc.) and the helper functions they depended on. - **Inlined** the `FeatureFlags` interface and `CHAIN_ID_TO_NAME_MAP` constant locally in `app/reducers/swaps/utils.ts` so the remaining liveness logic no longer imports from the deleted package. - **Added** migration 126 to strip `SwapsController` from persisted `backgroundState` on upgrade. - **Removed** `SwapsController` entries from test fixtures (`initial-background-state.json`, `default-fixture.json`), snapshot files, and mock states (Bridge, EngineService). - **Removed** the `@metamask/swaps-controller` dependency from `package.json` and cleaned up `yarn.lock` (also drops transitive `@metamask/utils@10`, `human-standard-token-abi`). ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: null ## **Related issues** Fixes: https://consensyssoftware.atlassian.net/browse/SWAPS-3927 ## **Manual testing steps** N/A — This is an internal refactoring with no UI or behavior changes. Swaps functionality continues to work through BridgeController. Existing unit tests and migration tests cover the removal. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** N/A ### **After** N/A ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I've included tests if applicable - [x] I've documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I've applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **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. <!-- Generated with the help of the pr-description AI skill --> <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Removes a controller from Engine wiring, persisted state, and selector surface area; any missed references could cause runtime init or state-shape regressions despite being a deletion-focused change. > > **Overview** > Removes the legacy `SwapsController` integration end-to-end: Engine init/messenger/type wiring is deleted, state-change subscriptions and Sentry masking are updated, and the `@metamask/swaps-controller` dependency is dropped. > > Strips `SwapsController`-backed Redux selectors and test/mocked state that depended on its persisted background state, and adds migration `127` to delete `engine.backgroundState.SwapsController` on upgrade. Fixtures, snapshots, and Bridge/EngineService tests are updated accordingly, with swaps liveness utilities inlining the needed feature-flag types and chain-name mapping. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 23265cb. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 13baa70 commit 39190c9

29 files changed

Lines changed: 151 additions & 1297 deletions

File tree

.agents/skills/e2e-test/SKILL.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ Step 5 → Iterate (fix → lint → run) until green
8989

9090
Documentation is split by **action**. Open only the reference that matches what you are doing.
9191

92-
| Action | File | When to open it |
93-
| --------------------------------------------- | ---------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
94-
| **Writing or updating a spec** | [references/writing-tests.md](references/writing-tests.md) | New spec file, spec structure, FixtureBuilder patterns, smoke/regression templates. |
95-
| **Page Objects and selectors** | [references/page-objects.md](references/page-objects.md) | Create or update POM classes, selector/testId conventions, Matchers/Gestures/Assertions API. |
96-
| **API and feature flag mocking** | [references/mocking.md](references/mocking.md) | testSpecificMock, setupRemoteFeatureFlagsMock, setupMockRequest, shared mock files. |
92+
| Action | File | When to open it |
93+
| --------------------------------------------- | ------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
94+
| **Writing or updating a spec** | [references/writing-tests.md](references/writing-tests.md) | New spec file, spec structure, FixtureBuilder patterns, smoke/regression templates. |
95+
| **Page Objects and selectors** | [references/page-objects.md](references/page-objects.md) | Create or update POM classes, selector/testId conventions, Matchers/Gestures/Assertions API. |
96+
| **API and feature flag mocking** | [references/mocking.md](references/mocking.md) | testSpecificMock, setupRemoteFeatureFlagsMock, setupMockRequest, shared mock files. |
9797
| **MetaMetrics / analytics expectations** | [tests/docs/analytics-e2e.md](../../../tests/docs/analytics-e2e.md) | `analyticsExpectations` on `withFixtures`, declarative checks, presets in `tests/helpers/analytics/expectations/`. |
98-
| **Running tests, debugging, fixing failures** | [references/running-tests.md](references/running-tests.md) | Build check, detox run commands, lint/tsc, common failures table, retry patterns, iteration loop. |
98+
| **Running tests, debugging, fixing failures** | [references/running-tests.md](references/running-tests.md) | Build check, detox run commands, lint/tsc, common failures table, retry patterns, iteration loop. |

app/components/UI/Bridge/Views/BridgeView/BridgeView.test.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,6 @@ jest.mock('../../../../../core/Engine', () => {
9898
unsubscribe: jest.fn(),
9999
},
100100
context: {
101-
SwapsController: {
102-
fetchAggregatorMetadataWithCache: jest.fn(),
103-
fetchTopAssetsWithCache: jest.fn(),
104-
fetchTokenWithCache: jest.fn(),
105-
},
106101
KeyringController: {
107102
state: {
108103
keyrings: [

app/components/UI/Bridge/_mocks_/initialState.ts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -609,35 +609,6 @@ export const initialState = {
609609
},
610610
},
611611
},
612-
SwapsController: {
613-
chainCache: {
614-
[ethChainId]: {
615-
aggregatorMetadata: null,
616-
tokens: null,
617-
topAssets: [
618-
{
619-
address: ethToken1Address,
620-
symbol: 'TOKEN1',
621-
},
622-
{
623-
address: ethToken2Address,
624-
symbol: 'HELLO',
625-
},
626-
],
627-
aggregatorMetadataLastFetched: 0,
628-
topAssetsLastFetched: 0,
629-
tokensLastFetched: 0,
630-
},
631-
[optimismChainId]: {
632-
aggregatorMetadata: null,
633-
tokens: null,
634-
topAssets: null,
635-
aggregatorMetadataLastFetched: 0,
636-
topAssetsLastFetched: 0,
637-
tokensLastFetched: 0,
638-
},
639-
},
640-
},
641612
KeyringController: {
642613
vault: '',
643614
isUnlocked: true,

app/core/Engine/Engine.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ import { earnControllerInit } from './controllers/earn-controller-init';
164164
import { geolocationApiServiceInit } from './controllers/geolocation-api-service-init';
165165
import { geolocationControllerInit } from './controllers/geolocation-controller';
166166
import { rewardsDataServiceInit } from './controllers/rewards-data-service-init';
167-
import { swapsControllerInit } from './controllers/swaps-controller-init';
168167
import { remoteFeatureFlagControllerInit } from './controllers/remote-feature-flag-controller-init';
169168
import { errorReportingServiceInit } from './controllers/error-reporting-service-init';
170169
import { storageServiceInit } from './controllers/storage-service/storage-service-init';
@@ -334,7 +333,6 @@ export class Engine {
334333
BridgeStatusController: bridgeStatusControllerInit,
335334
NftController: nftControllerInit,
336335
NftDetectionController: nftDetectionControllerInit,
337-
SwapsController: swapsControllerInit,
338336
///: BEGIN:ONLY_INCLUDE_IF(preinstalled-snaps,external-snaps)
339337
ExecutionService: executionServiceInit,
340338
CronjobController: cronjobControllerInit,
@@ -450,7 +448,6 @@ export class Engine {
450448
const bridgeController = controllersByName.BridgeController;
451449
const nftController = controllersByName.NftController;
452450
const nftDetectionController = controllersByName.NftDetectionController;
453-
const swapsController = controllersByName.SwapsController;
454451
const networkController = controllersByName.NetworkController;
455452

456453
///: BEGIN:ONLY_INCLUDE_IF(preinstalled-snaps,external-snaps)
@@ -530,7 +527,6 @@ export class Engine {
530527
TransactionController: this.transactionController,
531528
TransactionPayController: controllersByName.TransactionPayController,
532529
SmartTransactionsController: this.smartTransactionsController,
533-
SwapsController: swapsController,
534530
GasFeeController: this.gasFeeController,
535531
GatorPermissionsController: gatorPermissionsController,
536532
ApprovalController: approvalController,
@@ -1351,7 +1347,6 @@ export default {
13511347
SelectedNetworkController,
13521348
SignatureController,
13531349
SmartTransactionsController,
1354-
SwapsController,
13551350
TokenBalancesController,
13561351
TokenListController,
13571352
TokenRatesController,
@@ -1421,7 +1416,6 @@ export default {
14211416
SelectedNetworkController: SelectedNetworkController.state,
14221417
SignatureController: SignatureController.state,
14231418
SmartTransactionsController: SmartTransactionsController.state,
1424-
SwapsController: SwapsController.state,
14251419
TokenBalancesController: TokenBalancesController.state,
14261420
TokenListController: TokenListController.state,
14271421
TokenRatesController: TokenRatesController.state,

app/core/Engine/constants.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ export const BACKGROUND_STATE_CHANGE_EVENT_NAMES = [
4747
'SelectedNetworkController:stateChange',
4848
'SignatureController:stateChange',
4949
'SmartTransactionsController:stateChange',
50-
'SwapsController:stateChange',
5150
'TokenBalancesController:stateChange',
5251
'TokenListController:stateChange',
5352
'TokenRatesController:stateChange',
@@ -92,22 +91,6 @@ export const BACKGROUND_STATE_CHANGE_EVENT_NAMES = [
9291
'ComplianceController:stateChange',
9392
] as const;
9493

95-
export const swapsSupportedChainIds = [
96-
NETWORK_CHAIN_ID.MAINNET,
97-
NETWORK_CHAIN_ID.BSC,
98-
NETWORK_CHAIN_ID.POLYGON,
99-
NETWORK_CHAIN_ID.AVALANCHE,
100-
NETWORK_CHAIN_ID.ARBITRUM,
101-
NETWORK_CHAIN_ID.OPTIMISM,
102-
NETWORK_CHAIN_ID.ZKSYNC_ERA,
103-
NETWORK_CHAIN_ID.LINEA_MAINNET,
104-
NETWORK_CHAIN_ID.BASE,
105-
NETWORK_CHAIN_ID.SEI,
106-
NETWORK_CHAIN_ID.MONAD,
107-
NETWORK_CHAIN_ID.HYPE,
108-
NETWORK_CHAIN_ID.MEGAETH_MAINNET,
109-
];
110-
11194
export const MAINNET_DISPLAY_NAME = 'Ethereum';
11295
export const LINEA_MAINNET_DISPLAY_NAME = 'Linea';
11396
export const POLYGON_DISPLAY_NAME = 'Polygon';

app/core/Engine/controllers/swaps-controller-init.test.ts

Lines changed: 0 additions & 51 deletions
This file was deleted.

app/core/Engine/controllers/swaps-controller-init.ts

Lines changed: 0 additions & 38 deletions
This file was deleted.

app/core/Engine/messengers/index.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ import {
118118
import { getGeolocationApiServiceMessenger } from './geolocation-api-service-messenger';
119119
import { getGeolocationControllerMessenger } from './geolocation-controller-messenger';
120120
import { getRewardsDataServiceMessenger } from './rewards-data-service-messenger';
121-
import { getSwapsControllerMessenger } from './swaps-controller-messenger';
122121
import {
123122
getDelegationControllerInitMessenger,
124123
getDelegationControllerMessenger,
@@ -372,10 +371,6 @@ export const CONTROLLER_MESSENGERS = {
372371
getMessenger: getSmartTransactionsControllerMessenger,
373372
getInitMessenger: getSmartTransactionsControllerInitMessenger,
374373
},
375-
SwapsController: {
376-
getMessenger: getSwapsControllerMessenger,
377-
getInitMessenger: noop,
378-
},
379374
NetworkEnablementController: {
380375
getMessenger: getNetworkEnablementControllerMessenger,
381376
getInitMessenger: noop,

app/core/Engine/messengers/swaps-controller-messenger.test.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

app/core/Engine/messengers/swaps-controller-messenger.ts

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)