From c793e67681575abb172ca4df6bfb5f9c9293235e Mon Sep 17 00:00:00 2001 From: Salah-Eddine Saakoun Date: Mon, 8 Sep 2025 15:52:52 +0200 Subject: [PATCH 1/4] refactor: migrate UserOperationController to @metamask/messenger --- .../user-operation-controller/CHANGELOG.md | 3 ++ .../user-operation-controller/package.json | 1 + .../src/UserOperationController.ts | 37 ++++++++++--------- .../tsconfig.build.json | 3 ++ .../user-operation-controller/tsconfig.json | 3 ++ yarn.lock | 8 ++++ 6 files changed, 37 insertions(+), 18 deletions(-) diff --git a/packages/user-operation-controller/CHANGELOG.md b/packages/user-operation-controller/CHANGELOG.md index 3fe8c5374de..b8edcc03ad9 100644 --- a/packages/user-operation-controller/CHANGELOG.md +++ b/packages/user-operation-controller/CHANGELOG.md @@ -13,6 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- **BREAKING:** Use new `Messenger` from `@metamask/messenger` ([#6494](https://github.com/MetaMask/core/pull/6494)) + - Previously, `UserOperationController` accepted a `RestrictedMessenger` instance from `@metamask/base-controller`. +- Bump `@metamask/utils` from `^11.4.2` to `^11.8.0` ([#6588](https://github.com/MetaMask/core/pull/6588)) - Bump `@metamask/controller-utils` from `^11.12.0` to `^11.14.0` ([#6620](https://github.com/MetaMask/core/pull/6620), [#6629](https://github.com/MetaMask/core/pull/6629)) - Bump `@metamask/base-controller` from `^8.1.0` to `^8.4.0` ([#6355](https://github.com/MetaMask/core/pull/6355), [#6465](https://github.com/MetaMask/core/pull/6465), [#6632](https://github.com/MetaMask/core/pull/6632)) - Bump `@metamask/utils` from `^11.4.2` to `^11.8.1` ([#6588](https://github.com/MetaMask/core/pull/6588), [#6708](https://github.com/MetaMask/core/pull/6708)) diff --git a/packages/user-operation-controller/package.json b/packages/user-operation-controller/package.json index c3637f7a652..0b8cd146d4b 100644 --- a/packages/user-operation-controller/package.json +++ b/packages/user-operation-controller/package.json @@ -51,6 +51,7 @@ "@metamask/base-controller": "^8.4.0", "@metamask/controller-utils": "^11.14.0", "@metamask/eth-query": "^4.0.0", + "@metamask/messenger": "^0.2.0", "@metamask/polling-controller": "^14.0.0", "@metamask/rpc-errors": "^7.0.2", "@metamask/superstruct": "^3.1.0", diff --git a/packages/user-operation-controller/src/UserOperationController.ts b/packages/user-operation-controller/src/UserOperationController.ts index 6f0180d5b84..1a59badf2f4 100644 --- a/packages/user-operation-controller/src/UserOperationController.ts +++ b/packages/user-operation-controller/src/UserOperationController.ts @@ -3,8 +3,11 @@ import type { AddApprovalRequest, AddResult, } from '@metamask/approval-controller'; -import type { RestrictedMessenger } from '@metamask/base-controller'; -import { BaseController } from '@metamask/base-controller'; +import { + BaseController, + type ControllerGetStateAction, + type ControllerStateChangeEvent, +} from '@metamask/base-controller/next'; import { ApprovalType } from '@metamask/controller-utils'; import EthQuery from '@metamask/eth-query'; import type { GasFeeState } from '@metamask/gas-fee-controller'; @@ -13,6 +16,7 @@ import type { KeyringControllerPatchUserOperationAction, KeyringControllerSignUserOperationAction, } from '@metamask/keyring-controller'; +import type { Messenger } from '@metamask/messenger'; import type { NetworkControllerGetNetworkClientByIdAction, Provider, @@ -28,7 +32,6 @@ import { add0x } from '@metamask/utils'; // This package purposefully relies on Node's EventEmitter module. // eslint-disable-next-line import-x/no-nodejs-modules import EventEmitter from 'events'; -import type { Patch } from 'immer'; import { cloneDeep } from 'lodash'; import { v1 as random } from 'uuid'; @@ -102,15 +105,15 @@ export type UserOperationControllerState = { userOperations: Record; }; -export type GetUserOperationState = { - type: `${typeof controllerName}:getState`; - handler: () => UserOperationControllerState; -}; +export type GetUserOperationState = ControllerGetStateAction< + typeof controllerName, + UserOperationControllerState +>; -export type UserOperationStateChange = { - type: `${typeof controllerName}:stateChange`; - payload: [UserOperationControllerState, Patch[]]; -}; +export type UserOperationStateChange = ControllerStateChangeEvent< + typeof controllerName, + UserOperationControllerState +>; export type UserOperationControllerActions = | GetUserOperationState @@ -122,12 +125,10 @@ export type UserOperationControllerActions = export type UserOperationControllerEvents = UserOperationStateChange; -export type UserOperationControllerMessenger = RestrictedMessenger< +export type UserOperationControllerMessenger = Messenger< typeof controllerName, UserOperationControllerActions, - UserOperationControllerEvents, - UserOperationControllerActions['type'], - UserOperationControllerEvents['type'] + UserOperationControllerEvents >; export type UserOperationControllerOptions = { @@ -339,7 +340,7 @@ export class UserOperationController extends BaseController< const smartContractAccount = requestSmartContractAccount ?? - new SnapSmartContractAccount(this.messagingSystem); + new SnapSmartContractAccount(this.messenger); const cache: UserOperationCache = { chainId, @@ -739,7 +740,7 @@ export class UserOperationController extends BaseController< const type = ApprovalType.Transaction; const requestData = { txId: id }; - return (await this.messagingSystem.call( + return (await this.messenger.call( 'ApprovalController:addRequest', { id, @@ -774,7 +775,7 @@ export class UserOperationController extends BaseController< async #getProvider( networkClientId: string, ): Promise<{ provider: Provider; chainId: string }> { - const { provider, configuration } = this.messagingSystem.call( + const { provider, configuration } = this.messenger.call( 'NetworkController:getNetworkClientById', networkClientId, ); diff --git a/packages/user-operation-controller/tsconfig.build.json b/packages/user-operation-controller/tsconfig.build.json index 4c886f75e4d..51437a5055f 100644 --- a/packages/user-operation-controller/tsconfig.build.json +++ b/packages/user-operation-controller/tsconfig.build.json @@ -26,6 +26,9 @@ }, { "path": "../transaction-controller/tsconfig.build.json" + }, + { + "path": "../messenger/tsconfig.build.json" } ], "include": ["../../types", "./src"] diff --git a/packages/user-operation-controller/tsconfig.json b/packages/user-operation-controller/tsconfig.json index 2a0259e8b9b..f597f35bf69 100644 --- a/packages/user-operation-controller/tsconfig.json +++ b/packages/user-operation-controller/tsconfig.json @@ -24,6 +24,9 @@ }, { "path": "../transaction-controller" + }, + { + "path": "../messenger" } ], "include": ["../../types", "./src"] diff --git a/yarn.lock b/yarn.lock index 4c490b218f9..82080091cf6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3820,6 +3820,13 @@ __metadata: languageName: unknown linkType: soft +"@metamask/messenger@npm:^0.2.0": + version: 0.2.0 + resolution: "@metamask/messenger@npm:0.2.0" + checksum: 10/48f682d9cde1208fbda0936022dea37acc3828cc221203b5f917df25c131d9a250dc5e86e9263f5dba8ee7c05adc6752a68dfb57da7d297f95f38b052f4fe5c1 + languageName: node + linkType: hard + "@metamask/messenger@npm:^0.3.0, @metamask/messenger@workspace:packages/messenger": version: 0.0.0-use.local resolution: "@metamask/messenger@workspace:packages/messenger" @@ -4832,6 +4839,7 @@ __metadata: "@metamask/eth-query": "npm:^4.0.0" "@metamask/gas-fee-controller": "npm:^24.0.0" "@metamask/keyring-controller": "npm:^23.1.0" + "@metamask/messenger": "npm:^0.2.0" "@metamask/network-controller": "npm:^24.2.0" "@metamask/polling-controller": "npm:^14.0.0" "@metamask/rpc-errors": "npm:^7.0.2" From 0cc3ead908e1cd8b431dec41f3ae7d231682f447 Mon Sep 17 00:00:00 2001 From: Salah-Eddine Saakoun Date: Wed, 24 Sep 2025 14:41:59 +0200 Subject: [PATCH 2/4] fix: changelog order --- packages/user-operation-controller/CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/user-operation-controller/CHANGELOG.md b/packages/user-operation-controller/CHANGELOG.md index b8edcc03ad9..2cf06cd9dbc 100644 --- a/packages/user-operation-controller/CHANGELOG.md +++ b/packages/user-operation-controller/CHANGELOG.md @@ -15,7 +15,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **BREAKING:** Use new `Messenger` from `@metamask/messenger` ([#6494](https://github.com/MetaMask/core/pull/6494)) - Previously, `UserOperationController` accepted a `RestrictedMessenger` instance from `@metamask/base-controller`. -- Bump `@metamask/utils` from `^11.4.2` to `^11.8.0` ([#6588](https://github.com/MetaMask/core/pull/6588)) - Bump `@metamask/controller-utils` from `^11.12.0` to `^11.14.0` ([#6620](https://github.com/MetaMask/core/pull/6620), [#6629](https://github.com/MetaMask/core/pull/6629)) - Bump `@metamask/base-controller` from `^8.1.0` to `^8.4.0` ([#6355](https://github.com/MetaMask/core/pull/6355), [#6465](https://github.com/MetaMask/core/pull/6465), [#6632](https://github.com/MetaMask/core/pull/6632)) - Bump `@metamask/utils` from `^11.4.2` to `^11.8.1` ([#6588](https://github.com/MetaMask/core/pull/6588), [#6708](https://github.com/MetaMask/core/pull/6708)) From a845e04a20aaecd4702eedfe707be683e568bf32 Mon Sep 17 00:00:00 2001 From: Salah-Eddine Saakoun Date: Wed, 24 Sep 2025 14:43:16 +0200 Subject: [PATCH 3/4] fix: messenger version --- packages/user-operation-controller/package.json | 2 +- yarn.lock | 9 +-------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/packages/user-operation-controller/package.json b/packages/user-operation-controller/package.json index 0b8cd146d4b..8ee456ca2f4 100644 --- a/packages/user-operation-controller/package.json +++ b/packages/user-operation-controller/package.json @@ -51,7 +51,7 @@ "@metamask/base-controller": "^8.4.0", "@metamask/controller-utils": "^11.14.0", "@metamask/eth-query": "^4.0.0", - "@metamask/messenger": "^0.2.0", + "@metamask/messenger": "^0.3.0", "@metamask/polling-controller": "^14.0.0", "@metamask/rpc-errors": "^7.0.2", "@metamask/superstruct": "^3.1.0", diff --git a/yarn.lock b/yarn.lock index 82080091cf6..b7d3b961c7e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3820,13 +3820,6 @@ __metadata: languageName: unknown linkType: soft -"@metamask/messenger@npm:^0.2.0": - version: 0.2.0 - resolution: "@metamask/messenger@npm:0.2.0" - checksum: 10/48f682d9cde1208fbda0936022dea37acc3828cc221203b5f917df25c131d9a250dc5e86e9263f5dba8ee7c05adc6752a68dfb57da7d297f95f38b052f4fe5c1 - languageName: node - linkType: hard - "@metamask/messenger@npm:^0.3.0, @metamask/messenger@workspace:packages/messenger": version: 0.0.0-use.local resolution: "@metamask/messenger@workspace:packages/messenger" @@ -4839,7 +4832,7 @@ __metadata: "@metamask/eth-query": "npm:^4.0.0" "@metamask/gas-fee-controller": "npm:^24.0.0" "@metamask/keyring-controller": "npm:^23.1.0" - "@metamask/messenger": "npm:^0.2.0" + "@metamask/messenger": "npm:^0.3.0" "@metamask/network-controller": "npm:^24.2.0" "@metamask/polling-controller": "npm:^14.0.0" "@metamask/rpc-errors": "npm:^7.0.2" From 1dc59c056d94f11b56ba05dcab166195531fad83 Mon Sep 17 00:00:00 2001 From: Salah-Eddine Saakoun Date: Wed, 24 Sep 2025 15:45:24 +0200 Subject: [PATCH 4/4] fix: rename anonymous to includeInDebugSnapshot --- .../src/UserOperationController.test.ts | 4 ++-- .../user-operation-controller/src/UserOperationController.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/user-operation-controller/src/UserOperationController.test.ts b/packages/user-operation-controller/src/UserOperationController.test.ts index b1c26ff44a1..53070fbbd55 100644 --- a/packages/user-operation-controller/src/UserOperationController.test.ts +++ b/packages/user-operation-controller/src/UserOperationController.test.ts @@ -1,4 +1,4 @@ -import { deriveStateFromMetadata } from '@metamask/base-controller'; +import { deriveStateFromMetadata } from '@metamask/base-controller/next'; import { ApprovalType } from '@metamask/controller-utils'; import { errorCodes } from '@metamask/rpc-errors'; import { @@ -1453,7 +1453,7 @@ describe('UserOperationController', () => { deriveStateFromMetadata( controller.state, controller.metadata, - 'anonymous', + 'includeInDebugSnapshot', ), ).toMatchInlineSnapshot(`Object {}`); }); diff --git a/packages/user-operation-controller/src/UserOperationController.ts b/packages/user-operation-controller/src/UserOperationController.ts index 1a59badf2f4..6d76efd0c08 100644 --- a/packages/user-operation-controller/src/UserOperationController.ts +++ b/packages/user-operation-controller/src/UserOperationController.ts @@ -63,7 +63,7 @@ const stateMetadata = { userOperations: { includeInStateLogs: true, persist: true, - anonymous: false, + includeInDebugSnapshot: false, usedInUi: true, }, };