diff --git a/README.md b/README.md index 0b377cff988..87ee8de540a 100644 --- a/README.md +++ b/README.md @@ -216,6 +216,7 @@ linkStyle default opacity:0.5 earn_controller --> transaction_controller; eip_5792_middleware --> transaction_controller; eip_5792_middleware --> keyring_controller; + eip_7702_internal_rpc_middleware --> controller_utils; eip1193_permission_middleware --> chain_agnostic_permission; eip1193_permission_middleware --> controller_utils; eip1193_permission_middleware --> json_rpc_engine; @@ -336,6 +337,7 @@ linkStyle default opacity:0.5 transaction_controller --> remote_feature_flag_controller; user_operation_controller --> base_controller; user_operation_controller --> controller_utils; + user_operation_controller --> messenger; user_operation_controller --> polling_controller; user_operation_controller --> approval_controller; user_operation_controller --> eth_block_tracker; diff --git a/packages/user-operation-controller/CHANGELOG.md b/packages/user-operation-controller/CHANGELOG.md index 773a51aaa49..c0aa55a5d92 100644 --- a/packages/user-operation-controller/CHANGELOG.md +++ b/packages/user-operation-controller/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### 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`. +- **BREAKING:** Metadata property `anonymous` renamed to `includeInDebugSnapshot` ([#6494](https://github.com/MetaMask/core/pull/6494)) + ## [39.2.1] ### Changed diff --git a/packages/user-operation-controller/package.json b/packages/user-operation-controller/package.json index 0a76137abff..de6e9389449 100644 --- a/packages/user-operation-controller/package.json +++ b/packages/user-operation-controller/package.json @@ -51,6 +51,7 @@ "@metamask/base-controller": "^8.4.2", "@metamask/controller-utils": "^11.14.1", "@metamask/eth-query": "^4.0.0", + "@metamask/messenger": "^0.3.0", "@metamask/polling-controller": "^14.0.2", "@metamask/rpc-errors": "^7.0.2", "@metamask/superstruct": "^3.1.0", 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 6f0180d5b84..6d76efd0c08 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'; @@ -60,7 +63,7 @@ const stateMetadata = { userOperations: { includeInStateLogs: true, persist: true, - anonymous: false, + includeInDebugSnapshot: false, usedInUi: true, }, }; @@ -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 f67c9bc6cb0..794cc71cd29 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5052,6 +5052,7 @@ __metadata: "@metamask/eth-query": "npm:^4.0.0" "@metamask/gas-fee-controller": "npm:^24.1.1" "@metamask/keyring-controller": "npm:^23.2.0" + "@metamask/messenger": "npm:^0.3.0" "@metamask/network-controller": "npm:^24.3.1" "@metamask/polling-controller": "npm:^14.0.2" "@metamask/rpc-errors": "npm:^7.0.2"