@metamask-previews/user-operation-controller 39.2.0-preview-cd26f001 → 39.2.0-preview-e9856975

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ### Changed
11
+
12
+ - **BREAKING:** Use new `Messenger` from `@metamask/messenger` ([#6494](https://github.com/MetaMask/core/pull/6494))
13
+ - Previously, `UserOperationController` accepted a `RestrictedMessenger` instance from `@metamask/base-controller`.
14
+
10
15
  ## [39.2.0]
11
16
 
12
17
  ### Changed
@@ -16,7 +16,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
16
16
  var _UserOperationController_instances, _UserOperationController_entrypoint, _UserOperationController_getGasFeeEstimates, _UserOperationController_pendingUserOperationTracker, _UserOperationController_addUserOperation, _UserOperationController_prepareAndSubmitUserOperation, _UserOperationController_waitForConfirmation, _UserOperationController_createMetadata, _UserOperationController_prepareUserOperation, _UserOperationController_addPaymasterData, _UserOperationController_approveUserOperation, _UserOperationController_signUserOperation, _UserOperationController_submitUserOperation, _UserOperationController_failUserOperation, _UserOperationController_createEmptyUserOperation, _UserOperationController_updateMetadata, _UserOperationController_deleteMetadata, _UserOperationController_updateTransaction, _UserOperationController_addPendingUserOperationTrackerListeners, _UserOperationController_requestApproval, _UserOperationController_getTransactionType, _UserOperationController_getProvider, _UserOperationController_updateUserOperationAfterApproval, _UserOperationController_regenerateUserOperation;
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.UserOperationController = void 0;
19
- const base_controller_1 = require("@metamask/base-controller");
19
+ const next_1 = require("@metamask/base-controller/next");
20
20
  const controller_utils_1 = require("@metamask/controller-utils");
21
21
  const eth_query_1 = __importDefault(require("@metamask/eth-query"));
22
22
  const rpc_errors_1 = require("@metamask/rpc-errors");
@@ -42,7 +42,7 @@ const stateMetadata = {
42
42
  userOperations: {
43
43
  includeInStateLogs: true,
44
44
  persist: true,
45
- anonymous: false,
45
+ includeInDebugSnapshot: false,
46
46
  usedInUi: true,
47
47
  },
48
48
  };
@@ -52,7 +52,7 @@ const getDefaultState = () => ({
52
52
  /**
53
53
  * Controller for creating and managing the life cycle of user operations.
54
54
  */
55
- class UserOperationController extends base_controller_1.BaseController {
55
+ class UserOperationController extends next_1.BaseController {
56
56
  /**
57
57
  * Construct a UserOperationController instance.
58
58
  *
@@ -143,7 +143,7 @@ _UserOperationController_entrypoint = new WeakMap(), _UserOperationController_ge
143
143
  const { chainId, provider } = await __classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_getProvider).call(this, networkClientId);
144
144
  const metadata = await __classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_createMetadata).call(this, chainId, origin, transaction, swaps);
145
145
  const smartContractAccount = requestSmartContractAccount ??
146
- new SnapSmartContractAccount_1.SnapSmartContractAccount(this.messagingSystem);
146
+ new SnapSmartContractAccount_1.SnapSmartContractAccount(this.messenger);
147
147
  const cache = {
148
148
  chainId,
149
149
  metadata,
@@ -403,7 +403,7 @@ _UserOperationController_entrypoint = new WeakMap(), _UserOperationController_ge
403
403
  const { id, origin } = metadata;
404
404
  const type = controller_utils_1.ApprovalType.Transaction;
405
405
  const requestData = { txId: id };
406
- return (await this.messagingSystem.call('ApprovalController:addRequest', {
406
+ return (await this.messenger.call('ApprovalController:addRequest', {
407
407
  id,
408
408
  origin,
409
409
  type,
@@ -421,7 +421,7 @@ _UserOperationController_entrypoint = new WeakMap(), _UserOperationController_ge
421
421
  const result = (0, transaction_controller_1.determineTransactionType)(transaction, ethQuery);
422
422
  return (await result).type;
423
423
  }, _UserOperationController_getProvider = async function _UserOperationController_getProvider(networkClientId) {
424
- const { provider, configuration } = this.messagingSystem.call('NetworkController:getNetworkClientById', networkClientId);
424
+ const { provider, configuration } = this.messenger.call('NetworkController:getNetworkClientById', networkClientId);
425
425
  const { chainId } = configuration;
426
426
  return { provider, chainId };
427
427
  }, _UserOperationController_updateUserOperationAfterApproval = async function _UserOperationController_updateUserOperationAfterApproval(cache, updatedTransaction) {
@@ -1 +1 @@
1
- {"version":3,"file":"UserOperationController.cjs","sourceRoot":"","sources":["../src/UserOperationController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAMA,+DAA2D;AAC3D,iEAA0D;AAC1D,oEAA2C;AAW3C,qDAAkD;AAClD,6EAK0C;AAC1C,2CAAwC;AACxC,kEAAkE;AAClE,sDAAsD;AACtD,oDAAkC;AAElC,mCAAmC;AACnC,+BAAoC;AAEpC,+CAAoE;AACpE,mDAA4C;AAC5C,2FAAoF;AACpF,qFAA8E;AAC9E,yCAAgD;AAMhD,uCAA8C;AAC9C,yCAAwC;AACxC,mDAAiD;AACjD,yDAA6D;AAC7D,uDAM4B;AAE5B,MAAM,cAAc,GAAG,yBAAyB,CAAC;AAEjD,MAAM,aAAa,GAAG;IACpB,cAAc,EAAE;QACd,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,KAAK;QAChB,QAAQ,EAAE,IAAI;KACf;CACF,CAAC;AAEF,MAAM,eAAe,GAAG,GAAG,EAAE,CAAC,CAAC;IAC7B,cAAc,EAAE,EAAE;CACnB,CAAC,CAAC;AA+HH;;GAEG;AACH,MAAa,uBAAwB,SAAQ,gCAI5C;IASC;;;;;;;;OAQG;IACH,YAAY,EACV,UAAU,EACV,kBAAkB,EAClB,SAAS,EACT,KAAK,GAC0B;QAC/B,KAAK,CAAC;YACJ,IAAI,EAAE,cAAc;YACpB,QAAQ,EAAE,aAAa;YACvB,SAAS;YACT,KAAK,EAAE,EAAE,GAAG,eAAe,EAAE,EAAE,GAAG,KAAK,EAAE;SAC1C,CAAC,CAAC;;QA1BL,sDAAoB;QAEpB,8DAAgD;QAEhD,uEAA0D;QAwBxD,IAAI,CAAC,GAAG,GAAG,IAAI,gBAAY,EAAyC,CAAC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C;IAEF,MAAM,EACJ,OAAO,EAAE,EAAE,oBAAoB,EAAE,EACjC,QAAQ,GACT,GAAG,KAAK,CAAC;IAEV,MAAM,uBAAA,IAAI,yFAAsB,MAA1B,IAAI,EAAuB,KAAK,CAAC,CAAC;IACxC,MAAM,uBAAA,IAAI,qFAAkB,MAAtB,IAAI,EAAmB,QAAQ,EAAE,oBAAoB,CAAC,CAAC;IAE7D,IAAA,sBAAG,EAAC,4BAA4B,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAC;AAC5D,CAAC","sourcesContent":["import type {\n AcceptResultCallbacks,\n AddApprovalRequest,\n AddResult,\n} from '@metamask/approval-controller';\nimport type { RestrictedMessenger } from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { ApprovalType } from '@metamask/controller-utils';\nimport EthQuery from '@metamask/eth-query';\nimport type { GasFeeState } from '@metamask/gas-fee-controller';\nimport type {\n KeyringControllerPrepareUserOperationAction,\n KeyringControllerPatchUserOperationAction,\n KeyringControllerSignUserOperationAction,\n} from '@metamask/keyring-controller';\nimport type {\n NetworkControllerGetNetworkClientByIdAction,\n Provider,\n} from '@metamask/network-controller';\nimport { errorCodes } from '@metamask/rpc-errors';\nimport {\n determineTransactionType,\n type TransactionMeta,\n type TransactionParams,\n type TransactionType,\n} from '@metamask/transaction-controller';\nimport { add0x } from '@metamask/utils';\n// This package purposefully relies on Node's EventEmitter module.\n// eslint-disable-next-line import-x/no-nodejs-modules\nimport EventEmitter from 'events';\nimport type { Patch } from 'immer';\nimport { cloneDeep } from 'lodash';\nimport { v1 as random } from 'uuid';\n\nimport { ADDRESS_ZERO, EMPTY_BYTES, VALUE_ZERO } from './constants';\nimport { Bundler } from './helpers/Bundler';\nimport { PendingUserOperationTracker } from './helpers/PendingUserOperationTracker';\nimport { SnapSmartContractAccount } from './helpers/SnapSmartContractAccount';\nimport { projectLogger as log } from './logger';\nimport type {\n SmartContractAccount,\n UserOperation,\n UserOperationMetadata,\n} from './types';\nimport { UserOperationStatus } from './types';\nimport { updateGas } from './utils/gas';\nimport { updateGasFees } from './utils/gas-fees';\nimport { getTransactionMetadata } from './utils/transaction';\nimport {\n validateAddUserOperationOptions,\n validateAddUserOperationRequest,\n validatePrepareUserOperationResponse,\n validateSignUserOperationResponse,\n validateUpdateUserOperationResponse,\n} from './utils/validation';\n\nconst controllerName = 'UserOperationController';\n\nconst stateMetadata = {\n userOperations: {\n includeInStateLogs: true,\n persist: true,\n anonymous: false,\n usedInUi: true,\n },\n};\n\nconst getDefaultState = () => ({\n userOperations: {},\n});\n\ntype Events = {\n 'transaction-updated': [metadata: TransactionMeta];\n 'user-operation-added': [metadata: UserOperationMetadata];\n 'user-operation-confirmed': [metadata: UserOperationMetadata];\n 'user-operation-failed': [metadata: UserOperationMetadata, error: Error];\n [key: `${string}:confirmed`]: [metadata: UserOperationMetadata];\n [key: `${string}:failed`]: [metadata: UserOperationMetadata, error: Error];\n};\n\nexport type UserOperationControllerEventEmitter = EventEmitter & {\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n on<T extends keyof Events>(\n eventName: T,\n listener: (...args: Events[T]) => void,\n ): UserOperationControllerEventEmitter;\n\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n once<T extends keyof Events>(\n eventName: T,\n listener: (...args: Events[T]) => void,\n ): UserOperationControllerEventEmitter;\n\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n emit<T extends keyof Events>(eventName: T, ...args: Events[T]): boolean;\n};\n\nexport type UserOperationControllerState = {\n userOperations: Record<string, UserOperationMetadata>;\n};\n\nexport type GetUserOperationState = {\n type: `${typeof controllerName}:getState`;\n handler: () => UserOperationControllerState;\n};\n\nexport type UserOperationStateChange = {\n type: `${typeof controllerName}:stateChange`;\n payload: [UserOperationControllerState, Patch[]];\n};\n\nexport type UserOperationControllerActions =\n | GetUserOperationState\n | NetworkControllerGetNetworkClientByIdAction\n | AddApprovalRequest\n | KeyringControllerPrepareUserOperationAction\n | KeyringControllerPatchUserOperationAction\n | KeyringControllerSignUserOperationAction;\n\nexport type UserOperationControllerEvents = UserOperationStateChange;\n\nexport type UserOperationControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n UserOperationControllerActions,\n UserOperationControllerEvents,\n UserOperationControllerActions['type'],\n UserOperationControllerEvents['type']\n>;\n\nexport type UserOperationControllerOptions = {\n entrypoint: string;\n getGasFeeEstimates: () => Promise<GasFeeState>;\n interval?: number;\n messenger: UserOperationControllerMessenger;\n state?: Partial<UserOperationControllerState>;\n};\n\nexport type AddUserOperationRequest = {\n data?: string;\n from: string;\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n to?: string;\n value?: string;\n};\n\nexport type AddUserOperationSwapOptions = {\n approvalTxId?: string;\n destinationTokenAddress?: string;\n destinationTokenAmount?: string;\n destinationTokenDecimals?: number;\n destinationTokenSymbol?: string;\n estimatedBaseFee?: string;\n sourceTokenAddress?: string;\n sourceTokenAmount?: string;\n sourceTokenDecimals?: number;\n sourceTokenSymbol?: string;\n swapAndSendRecipient?: string;\n swapMetaData?: Record<string, unknown>;\n swapTokenValue?: string;\n};\n\nexport type AddUserOperationOptions = {\n networkClientId: string;\n origin: string;\n requireApproval?: boolean;\n smartContractAccount?: SmartContractAccount;\n swaps?: AddUserOperationSwapOptions;\n type?: TransactionType;\n};\n\nexport type AddUserOperationResponse = {\n id: string;\n hash: () => Promise<string | undefined>;\n transactionHash: () => Promise<string | undefined>;\n};\n\n/**\n * All the objects related to a pending user operation in order to:\n * - Avoid duplicated effort to derive the same properties.\n * - Minimise duplicate arguments in private methods.\n */\ntype UserOperationCache = {\n chainId: string;\n metadata: UserOperationMetadata;\n options: AddUserOperationOptions & {\n smartContractAccount: SmartContractAccount;\n };\n provider: Provider;\n request: AddUserOperationRequest;\n transaction?: TransactionParams;\n};\n\n/**\n * Controller for creating and managing the life cycle of user operations.\n */\nexport class UserOperationController extends BaseController<\n typeof controllerName,\n UserOperationControllerState,\n UserOperationControllerMessenger\n> {\n hub: UserOperationControllerEventEmitter;\n\n #entrypoint: string;\n\n #getGasFeeEstimates: () => Promise<GasFeeState>;\n\n #pendingUserOperationTracker: PendingUserOperationTracker;\n\n /**\n * Construct a UserOperationController instance.\n *\n * @param options - Controller options.\n * @param options.entrypoint - Address of the entrypoint contract.\n * @param options.getGasFeeEstimates - Callback to get gas fee estimates.\n * @param options.messenger - Restricted messenger for the user operation controller.\n * @param options.state - Initial state to set on the controller.\n */\n constructor({\n entrypoint,\n getGasFeeEstimates,\n messenger,\n state,\n }: UserOperationControllerOptions) {\n super({\n name: controllerName,\n metadata: stateMetadata,\n messenger,\n state: { ...getDefaultState(), ...state },\n });\n\n this.hub = new EventEmitter() as UserOperationControllerEventEmitter;\n\n this.#entrypoint = entrypoint;\n this.#getGasFeeEstimates = getGasFeeEstimates;\n\n this.#pendingUserOperationTracker = new PendingUserOperationTracker({\n getUserOperations: () =>\n cloneDeep(Object.values(this.state.userOperations)),\n messenger,\n });\n\n this.#addPendingUserOperationTrackerListeners();\n }\n\n /**\n * Create and submit a user operation.\n *\n * @param request - Information required to create a user operation.\n * @param request.data - Data to include in the resulting transaction.\n * @param request.maxFeePerGas - Maximum fee per gas to pay towards the transaction.\n * @param request.maxPriorityFeePerGas - Maximum priority fee per gas to pay towards the transaction.\n * @param request.to - Destination address of the resulting transaction.\n * @param request.value - Value to include in the resulting transaction.\n * @param options - Configuration options when creating a user operation.\n * @param options.networkClientId - ID of the network client used to query the chain.\n * @param options.origin - Origin of the user operation, such as the hostname of a dApp.\n * @param options.requireApproval - Whether to require user approval before submitting the user operation. Defaults to true.\n * @param options.smartContractAccount - Smart contract abstraction to provide the contract specific values such as call data and nonce. Defaults to the current snap account.\n * @param options.swaps - Swap metadata to record with the user operation.\n * @param options.type - Type of the transaction.\n */\n async addUserOperation(\n request: AddUserOperationRequest,\n options: AddUserOperationOptions,\n ): Promise<AddUserOperationResponse> {\n validateAddUserOperationRequest(request);\n validateAddUserOperationOptions(options);\n\n return await this.#addUserOperation(request, options);\n }\n\n /**\n * Create and submit a user operation equivalent to the provided transaction.\n *\n * @param transaction - Transaction to use as the basis for the user operation.\n * @param options - Configuration options when creating a user operation.\n * @param options.networkClientId - ID of the network client used to query the chain.\n * @param options.origin - Origin of the user operation, such as the hostname of a dApp.\n * @param options.requireApproval - Whether to require user approval before submitting the user operation. Defaults to true.\n * @param options.smartContractAccount - Smart contract abstraction to provide the contract specific values such as call data and nonce. Defaults to the current snap account.\n * @param options.swaps - Swap metadata to record with the user operation.\n * @param options.type - Type of the transaction.\n */\n async addUserOperationFromTransaction(\n transaction: TransactionParams,\n options: AddUserOperationOptions,\n ): Promise<AddUserOperationResponse> {\n validateAddUserOperationOptions(options);\n\n const { data, from, maxFeePerGas, maxPriorityFeePerGas, to, value } =\n transaction;\n\n const request: AddUserOperationRequest = {\n data: data === '' ? undefined : data,\n from,\n maxFeePerGas,\n maxPriorityFeePerGas,\n to,\n value,\n };\n\n validateAddUserOperationRequest(request);\n\n return await this.#addUserOperation(request, { ...options, transaction });\n }\n\n startPollingByNetworkClientId(networkClientId: string): string {\n return this.#pendingUserOperationTracker.startPolling({\n networkClientId,\n });\n }\n\n async #addUserOperation(\n request: AddUserOperationRequest,\n options: AddUserOperationOptions & { transaction?: TransactionParams },\n ): Promise<AddUserOperationResponse> {\n log('Adding user operation', { request, options });\n\n const {\n networkClientId,\n origin,\n smartContractAccount: requestSmartContractAccount,\n swaps,\n transaction,\n } = options;\n\n const { chainId, provider } = await this.#getProvider(networkClientId);\n\n const metadata = await this.#createMetadata(\n chainId,\n origin,\n transaction,\n swaps,\n );\n\n const smartContractAccount =\n requestSmartContractAccount ??\n new SnapSmartContractAccount(this.messagingSystem);\n\n const cache: UserOperationCache = {\n chainId,\n metadata,\n options: { ...options, smartContractAccount },\n provider,\n request,\n transaction,\n };\n\n const { id } = metadata;\n let throwError = false;\n\n const hashValue = (async () => {\n try {\n return await this.#prepareAndSubmitUserOperation(cache);\n } catch (error) {\n this.#failUserOperation(metadata, error);\n\n if (throwError) {\n throw error;\n }\n\n return undefined;\n }\n })();\n\n const hash = async () => {\n throwError = true;\n return await hashValue;\n };\n\n const transactionHash = async () => {\n await hash();\n\n const { transactionHash: finalTransactionHash } =\n await this.#waitForConfirmation(metadata);\n\n return finalTransactionHash as string;\n };\n\n return {\n id,\n hash,\n transactionHash,\n };\n }\n\n async #prepareAndSubmitUserOperation(cache: UserOperationCache) {\n const { metadata, options } = cache;\n const { requireApproval, smartContractAccount } = options;\n let resultCallbacks: AcceptResultCallbacks | undefined;\n\n try {\n await this.#prepareUserOperation(cache);\n await this.#addPaymasterData(metadata, smartContractAccount);\n\n this.hub.emit('user-operation-added', metadata);\n\n if (requireApproval !== false) {\n resultCallbacks = await this.#approveUserOperation(cache);\n }\n\n await this.#signUserOperation(metadata, smartContractAccount);\n await this.#submitUserOperation(metadata);\n\n resultCallbacks?.success();\n\n return metadata.hash as string;\n } catch (error) {\n /* istanbul ignore next */\n resultCallbacks?.error(error as Error);\n throw error;\n }\n }\n\n async #waitForConfirmation(\n metadata: UserOperationMetadata,\n ): Promise<UserOperationMetadata> {\n const { id, hash } = metadata;\n\n log('Waiting for confirmation', id, hash);\n\n return new Promise((resolve, reject) => {\n this.hub.once(`${id}:confirmed`, (finalMetadata) => {\n resolve(finalMetadata);\n });\n\n this.hub.once(`${id}:failed`, (_finalMetadata, error) => {\n reject(error);\n });\n });\n }\n\n async #createMetadata(\n chainId: string,\n origin: string,\n transaction?: TransactionParams,\n swaps?: AddUserOperationSwapOptions,\n ): Promise<UserOperationMetadata> {\n const metadata: UserOperationMetadata = {\n actualGasCost: null,\n actualGasUsed: null,\n baseFeePerGas: null,\n bundlerUrl: null,\n chainId,\n error: null,\n hash: null,\n id: random(),\n origin,\n status: UserOperationStatus.Unapproved,\n swapsMetadata: swaps\n ? {\n approvalTxId: swaps.approvalTxId ?? null,\n destinationTokenAddress: swaps.destinationTokenAddress ?? null,\n destinationTokenAmount: swaps.destinationTokenAmount ?? null,\n destinationTokenDecimals: swaps.destinationTokenDecimals ?? null,\n destinationTokenSymbol: swaps.destinationTokenSymbol ?? null,\n estimatedBaseFee: swaps.estimatedBaseFee ?? null,\n sourceTokenAddress: swaps.sourceTokenAddress ?? null,\n sourceTokenAmount: swaps.sourceTokenAmount ?? null,\n sourceTokenDecimals: swaps.sourceTokenDecimals ?? null,\n sourceTokenSymbol: swaps.sourceTokenSymbol ?? null,\n swapAndSendRecipient: swaps.swapAndSendRecipient ?? null,\n swapMetaData: (swaps.swapMetaData as Record<string, never>) ?? null,\n swapTokenValue: swaps.swapTokenValue ?? null,\n }\n : null,\n time: Date.now(),\n transactionHash: null,\n transactionParams: (transaction as Required<TransactionParams>) ?? null,\n transactionType: null,\n userFeeLevel: null,\n userOperation: this.#createEmptyUserOperation(transaction),\n };\n\n this.#updateMetadata(metadata);\n\n log('Added user operation', metadata.id);\n\n return metadata;\n }\n\n async #prepareUserOperation(cache: UserOperationCache) {\n const { chainId, metadata, options, provider, request, transaction } =\n cache;\n\n const { data, from, to, value } = request;\n const { id, transactionParams, userOperation } = metadata;\n const { smartContractAccount } = options;\n\n log('Preparing user operation', { id });\n\n const transactionType = await this.#getTransactionType(\n transaction,\n provider,\n options,\n );\n\n metadata.transactionType = transactionType ?? null;\n\n log('Determined transaction type', transactionType);\n\n await updateGasFees({\n getGasFeeEstimates: this.#getGasFeeEstimates,\n metadata,\n originalRequest: request,\n provider,\n transaction: transactionParams ?? undefined,\n });\n\n const response = await smartContractAccount.prepareUserOperation({\n chainId,\n data,\n from,\n to,\n value,\n });\n\n validatePrepareUserOperationResponse(response);\n\n const {\n bundler: bundlerUrl,\n callData,\n dummyPaymasterAndData,\n dummySignature,\n initCode,\n nonce,\n sender,\n } = response;\n\n userOperation.callData = callData;\n userOperation.initCode = initCode ?? EMPTY_BYTES;\n userOperation.nonce = nonce;\n userOperation.paymasterAndData = dummyPaymasterAndData ?? EMPTY_BYTES;\n userOperation.sender = sender;\n userOperation.signature = dummySignature ?? EMPTY_BYTES;\n\n metadata.bundlerUrl = bundlerUrl;\n\n await updateGas(metadata, response, this.#entrypoint);\n\n this.#updateMetadata(metadata);\n }\n\n async #addPaymasterData(\n metadata: UserOperationMetadata,\n smartContractAccount: SmartContractAccount,\n ) {\n const { id, userOperation, chainId } = metadata;\n\n log('Requesting paymaster data', { id });\n\n const response = await smartContractAccount.updateUserOperation({\n userOperation,\n chainId,\n });\n\n validateUpdateUserOperationResponse(response);\n\n userOperation.paymasterAndData = response.paymasterAndData ?? EMPTY_BYTES;\n if (response.callGasLimit) {\n userOperation.callGasLimit = response.callGasLimit;\n }\n if (response.preVerificationGas) {\n userOperation.preVerificationGas = response.preVerificationGas;\n }\n if (response.verificationGasLimit) {\n userOperation.verificationGasLimit = response.verificationGasLimit;\n }\n\n this.#updateMetadata(metadata);\n }\n\n async #approveUserOperation(cache: UserOperationCache) {\n log('Requesting approval');\n\n const { metadata } = cache;\n\n const { resultCallbacks, value } = await this.#requestApproval(metadata);\n const updatedTransaction = value?.txMeta;\n\n if (updatedTransaction) {\n await this.#updateUserOperationAfterApproval(cache, updatedTransaction);\n }\n\n metadata.status = UserOperationStatus.Approved;\n\n this.#updateMetadata(metadata);\n\n return resultCallbacks;\n }\n\n async #signUserOperation(\n metadata: UserOperationMetadata,\n smartContractAccount: SmartContractAccount,\n ) {\n const { id, chainId, userOperation } = metadata;\n\n log('Signing user operation', id, userOperation);\n\n const response = await smartContractAccount.signUserOperation({\n userOperation,\n chainId,\n });\n\n validateSignUserOperationResponse(response);\n\n const { signature } = response;\n\n userOperation.signature = signature;\n\n log('Signed user operation', signature);\n\n metadata.status = UserOperationStatus.Signed;\n\n this.#updateMetadata(metadata);\n }\n\n async #submitUserOperation(metadata: UserOperationMetadata) {\n const { userOperation } = metadata;\n\n log('Submitting user operation', userOperation);\n\n const bundler = new Bundler(metadata.bundlerUrl as string);\n\n const hash = await bundler.sendUserOperation(\n userOperation,\n this.#entrypoint,\n );\n\n metadata.hash = hash;\n metadata.status = UserOperationStatus.Submitted;\n\n this.#updateMetadata(metadata);\n }\n\n #failUserOperation(metadata: UserOperationMetadata, error: unknown) {\n const { id } = metadata;\n const rawError = error as Record<string, string>;\n\n log('User operation failed', id, error);\n\n metadata.error = {\n name: rawError.name,\n message: rawError.message,\n stack: rawError.stack,\n code: rawError.code,\n rpc: rawError.value,\n };\n\n metadata.status = UserOperationStatus.Failed;\n\n this.#updateMetadata(metadata);\n\n if (\n String(rawError.code) === String(errorCodes.provider.userRejectedRequest)\n ) {\n this.#deleteMetadata(id);\n }\n }\n\n #createEmptyUserOperation(transaction?: TransactionParams): UserOperation {\n return {\n callData: EMPTY_BYTES,\n callGasLimit: EMPTY_BYTES,\n initCode: EMPTY_BYTES,\n maxFeePerGas: transaction?.maxFeePerGas ?? EMPTY_BYTES,\n maxPriorityFeePerGas: transaction?.maxPriorityFeePerGas ?? EMPTY_BYTES,\n nonce: EMPTY_BYTES,\n paymasterAndData: EMPTY_BYTES,\n preVerificationGas: EMPTY_BYTES,\n sender: ADDRESS_ZERO,\n signature: EMPTY_BYTES,\n verificationGasLimit: EMPTY_BYTES,\n };\n }\n\n #updateMetadata(metadata: UserOperationMetadata) {\n const { id } = metadata;\n\n this.update((state) => {\n state.userOperations[id] = cloneDeep(metadata);\n });\n\n this.#updateTransaction(metadata);\n }\n\n #deleteMetadata(id: string) {\n this.update((state) => {\n delete state.userOperations[id];\n });\n }\n\n #updateTransaction(metadata: UserOperationMetadata) {\n if (!metadata.transactionParams) {\n return;\n }\n\n const transactionMetadata = getTransactionMetadata(metadata);\n\n this.hub.emit('transaction-updated', transactionMetadata);\n }\n\n #addPendingUserOperationTrackerListeners() {\n this.#pendingUserOperationTracker.hub.on(\n 'user-operation-confirmed',\n (metadata) => {\n log('In listener...');\n this.hub.emit('user-operation-confirmed', metadata);\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n this.hub.emit(`${metadata.id}:confirmed`, metadata);\n },\n );\n\n this.#pendingUserOperationTracker.hub.on(\n 'user-operation-failed',\n (metadata, error) => {\n this.hub.emit('user-operation-failed', metadata, error);\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n this.hub.emit(`${metadata.id}:failed`, metadata, error);\n },\n );\n\n this.#pendingUserOperationTracker.hub.on(\n 'user-operation-updated',\n (metadata) => {\n this.#updateMetadata(metadata);\n },\n );\n }\n\n async #requestApproval(metadata: UserOperationMetadata) {\n const { id, origin } = metadata;\n const type = ApprovalType.Transaction;\n const requestData = { txId: id };\n\n return (await this.messagingSystem.call(\n 'ApprovalController:addRequest',\n {\n id,\n origin,\n type,\n requestData,\n expectsResult: true,\n },\n true, // Should display approval request to user\n )) as AddResult & { value?: { txMeta?: TransactionMeta } };\n }\n\n async #getTransactionType(\n transaction: TransactionParams | undefined,\n provider: Provider,\n options: AddUserOperationOptions,\n ): Promise<TransactionType | undefined> {\n if (!transaction) {\n return undefined;\n }\n\n if (options.type) {\n return options.type;\n }\n\n const ethQuery = new EthQuery(provider);\n const result = determineTransactionType(transaction, ethQuery);\n\n return (await result).type;\n }\n\n async #getProvider(\n networkClientId: string,\n ): Promise<{ provider: Provider; chainId: string }> {\n const { provider, configuration } = this.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n\n const { chainId } = configuration;\n\n return { provider, chainId };\n }\n\n async #updateUserOperationAfterApproval(\n cache: UserOperationCache,\n updatedTransaction: TransactionMeta,\n ) {\n log('Found updated transaction in approval', { updatedTransaction });\n\n const { metadata, request } = cache;\n\n const { userOperation } = metadata;\n const usingPaymaster = userOperation.paymasterAndData !== EMPTY_BYTES;\n\n const updatedMaxFeePerGas = add0x(\n updatedTransaction.txParams.maxFeePerGas as string,\n );\n\n const updatedMaxPriorityFeePerGas = add0x(\n updatedTransaction.txParams.maxPriorityFeePerGas as string,\n );\n\n let regenerateUserOperation = false;\n const previousMaxFeePerGas = userOperation.maxFeePerGas;\n const previousMaxPriorityFeePerGas = userOperation.maxPriorityFeePerGas;\n\n const gasFeesUpdated =\n previousMaxFeePerGas !== updatedMaxFeePerGas ||\n previousMaxPriorityFeePerGas !== updatedMaxPriorityFeePerGas;\n\n /**\n * true when we detect {@link getTransactionMetadata} has set the gas fees to zero\n * because the userOperation has a paymaster. This should not be mistaken for gas\n * fees being updated during the approval process.\n */\n const areGasFeesZeroBecauseOfPaymaster =\n usingPaymaster &&\n updatedMaxFeePerGas === VALUE_ZERO &&\n updatedMaxPriorityFeePerGas === VALUE_ZERO;\n\n if (gasFeesUpdated && !areGasFeesZeroBecauseOfPaymaster) {\n log('Gas fees updated during approval', {\n previousMaxFeePerGas,\n previousMaxPriorityFeePerGas,\n updatedMaxFeePerGas,\n updatedMaxPriorityFeePerGas,\n });\n\n userOperation.maxFeePerGas = updatedMaxFeePerGas;\n userOperation.maxPriorityFeePerGas = updatedMaxPriorityFeePerGas;\n\n regenerateUserOperation = usingPaymaster;\n }\n\n const previousData = request.data ?? EMPTY_BYTES;\n const updatedData = updatedTransaction.txParams.data ?? EMPTY_BYTES;\n\n if (previousData !== updatedData) {\n log('Data updated during approval', { previousData, updatedData });\n regenerateUserOperation = true;\n }\n\n const previousValue = request.value ?? VALUE_ZERO;\n const updatedValue = updatedTransaction.txParams.value ?? VALUE_ZERO;\n\n if (previousValue !== updatedValue) {\n log('Value updated during approval', { previousValue, updatedValue });\n regenerateUserOperation = true;\n }\n\n if (regenerateUserOperation) {\n const updatedRequest = {\n ...request,\n data: updatedData,\n maxFeePerGas: updatedMaxFeePerGas,\n maxPriorityFeePerGas: updatedMaxPriorityFeePerGas,\n value: updatedValue,\n };\n\n await this.#regenerateUserOperation({\n ...cache,\n request: updatedRequest,\n });\n }\n }\n\n async #regenerateUserOperation(cache: UserOperationCache) {\n log(\n 'Regenerating user operation as parameters were updated during approval',\n );\n\n const {\n options: { smartContractAccount },\n metadata,\n } = cache;\n\n await this.#prepareUserOperation(cache);\n await this.#addPaymasterData(metadata, smartContractAccount);\n\n log('Regenerated user operation', metadata.userOperation);\n }\n}\n"]}
1
+ {"version":3,"file":"UserOperationController.cjs","sourceRoot":"","sources":["../src/UserOperationController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAKA,yDAIwC;AACxC,iEAA0D;AAC1D,oEAA2C;AAY3C,qDAAkD;AAClD,6EAK0C;AAC1C,2CAAwC;AACxC,kEAAkE;AAClE,sDAAsD;AACtD,oDAAkC;AAClC,mCAAmC;AACnC,+BAAoC;AAEpC,+CAAoE;AACpE,mDAA4C;AAC5C,2FAAoF;AACpF,qFAA8E;AAC9E,yCAAgD;AAMhD,uCAA8C;AAC9C,yCAAwC;AACxC,mDAAiD;AACjD,yDAA6D;AAC7D,uDAM4B;AAE5B,MAAM,cAAc,GAAG,yBAAyB,CAAC;AAEjD,MAAM,aAAa,GAAG;IACpB,cAAc,EAAE;QACd,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,IAAI;KACf;CACF,CAAC;AAEF,MAAM,eAAe,GAAG,GAAG,EAAE,CAAC,CAAC;IAC7B,cAAc,EAAE,EAAE;CACnB,CAAC,CAAC;AA6HH;;GAEG;AACH,MAAa,uBAAwB,SAAQ,qBAI5C;IASC;;;;;;;;OAQG;IACH,YAAY,EACV,UAAU,EACV,kBAAkB,EAClB,SAAS,EACT,KAAK,GAC0B;QAC/B,KAAK,CAAC;YACJ,IAAI,EAAE,cAAc;YACpB,QAAQ,EAAE,aAAa;YACvB,SAAS;YACT,KAAK,EAAE,EAAE,GAAG,eAAe,EAAE,EAAE,GAAG,KAAK,EAAE;SAC1C,CAAC,CAAC;;QA1BL,sDAAoB;QAEpB,8DAAgD;QAEhD,uEAA0D;QAwBxD,IAAI,CAAC,GAAG,GAAG,IAAI,gBAAY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AwE,CACzE,CAAC;IAEF,MAAM,EACJ,OAAO,EAAE,EAAE,oBAAoB,EAAE,EACjC,QAAQ,GACT,GAAG,KAAK,CAAC;IAEV,MAAM,uBAAA,IAAI,yFAAsB,MAA1B,IAAI,EAAuB,KAAK,CAAC,CAAC;IACxC,MAAM,uBAAA,IAAI,qFAAkB,MAAtB,IAAI,EAAmB,QAAQ,EAAE,oBAAoB,CAAC,CAAC;IAE7D,IAAA,sBAAG,EAAC,4BAA4B,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAC;AAC5D,CAAC","sourcesContent":["import type {\n AcceptResultCallbacks,\n AddApprovalRequest,\n AddResult,\n} from '@metamask/approval-controller';\nimport {\n BaseController,\n type ControllerGetStateAction,\n type ControllerStateChangeEvent,\n} from '@metamask/base-controller/next';\nimport { ApprovalType } from '@metamask/controller-utils';\nimport EthQuery from '@metamask/eth-query';\nimport type { GasFeeState } from '@metamask/gas-fee-controller';\nimport type {\n KeyringControllerPrepareUserOperationAction,\n KeyringControllerPatchUserOperationAction,\n KeyringControllerSignUserOperationAction,\n} from '@metamask/keyring-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n NetworkControllerGetNetworkClientByIdAction,\n Provider,\n} from '@metamask/network-controller';\nimport { errorCodes } from '@metamask/rpc-errors';\nimport {\n determineTransactionType,\n type TransactionMeta,\n type TransactionParams,\n type TransactionType,\n} from '@metamask/transaction-controller';\nimport { add0x } from '@metamask/utils';\n// This package purposefully relies on Node's EventEmitter module.\n// eslint-disable-next-line import-x/no-nodejs-modules\nimport EventEmitter from 'events';\nimport { cloneDeep } from 'lodash';\nimport { v1 as random } from 'uuid';\n\nimport { ADDRESS_ZERO, EMPTY_BYTES, VALUE_ZERO } from './constants';\nimport { Bundler } from './helpers/Bundler';\nimport { PendingUserOperationTracker } from './helpers/PendingUserOperationTracker';\nimport { SnapSmartContractAccount } from './helpers/SnapSmartContractAccount';\nimport { projectLogger as log } from './logger';\nimport type {\n SmartContractAccount,\n UserOperation,\n UserOperationMetadata,\n} from './types';\nimport { UserOperationStatus } from './types';\nimport { updateGas } from './utils/gas';\nimport { updateGasFees } from './utils/gas-fees';\nimport { getTransactionMetadata } from './utils/transaction';\nimport {\n validateAddUserOperationOptions,\n validateAddUserOperationRequest,\n validatePrepareUserOperationResponse,\n validateSignUserOperationResponse,\n validateUpdateUserOperationResponse,\n} from './utils/validation';\n\nconst controllerName = 'UserOperationController';\n\nconst stateMetadata = {\n userOperations: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n};\n\nconst getDefaultState = () => ({\n userOperations: {},\n});\n\ntype Events = {\n 'transaction-updated': [metadata: TransactionMeta];\n 'user-operation-added': [metadata: UserOperationMetadata];\n 'user-operation-confirmed': [metadata: UserOperationMetadata];\n 'user-operation-failed': [metadata: UserOperationMetadata, error: Error];\n [key: `${string}:confirmed`]: [metadata: UserOperationMetadata];\n [key: `${string}:failed`]: [metadata: UserOperationMetadata, error: Error];\n};\n\nexport type UserOperationControllerEventEmitter = EventEmitter & {\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n on<T extends keyof Events>(\n eventName: T,\n listener: (...args: Events[T]) => void,\n ): UserOperationControllerEventEmitter;\n\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n once<T extends keyof Events>(\n eventName: T,\n listener: (...args: Events[T]) => void,\n ): UserOperationControllerEventEmitter;\n\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n emit<T extends keyof Events>(eventName: T, ...args: Events[T]): boolean;\n};\n\nexport type UserOperationControllerState = {\n userOperations: Record<string, UserOperationMetadata>;\n};\n\nexport type GetUserOperationState = ControllerGetStateAction<\n typeof controllerName,\n UserOperationControllerState\n>;\n\nexport type UserOperationStateChange = ControllerStateChangeEvent<\n typeof controllerName,\n UserOperationControllerState\n>;\n\nexport type UserOperationControllerActions =\n | GetUserOperationState\n | NetworkControllerGetNetworkClientByIdAction\n | AddApprovalRequest\n | KeyringControllerPrepareUserOperationAction\n | KeyringControllerPatchUserOperationAction\n | KeyringControllerSignUserOperationAction;\n\nexport type UserOperationControllerEvents = UserOperationStateChange;\n\nexport type UserOperationControllerMessenger = Messenger<\n typeof controllerName,\n UserOperationControllerActions,\n UserOperationControllerEvents\n>;\n\nexport type UserOperationControllerOptions = {\n entrypoint: string;\n getGasFeeEstimates: () => Promise<GasFeeState>;\n interval?: number;\n messenger: UserOperationControllerMessenger;\n state?: Partial<UserOperationControllerState>;\n};\n\nexport type AddUserOperationRequest = {\n data?: string;\n from: string;\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n to?: string;\n value?: string;\n};\n\nexport type AddUserOperationSwapOptions = {\n approvalTxId?: string;\n destinationTokenAddress?: string;\n destinationTokenAmount?: string;\n destinationTokenDecimals?: number;\n destinationTokenSymbol?: string;\n estimatedBaseFee?: string;\n sourceTokenAddress?: string;\n sourceTokenAmount?: string;\n sourceTokenDecimals?: number;\n sourceTokenSymbol?: string;\n swapAndSendRecipient?: string;\n swapMetaData?: Record<string, unknown>;\n swapTokenValue?: string;\n};\n\nexport type AddUserOperationOptions = {\n networkClientId: string;\n origin: string;\n requireApproval?: boolean;\n smartContractAccount?: SmartContractAccount;\n swaps?: AddUserOperationSwapOptions;\n type?: TransactionType;\n};\n\nexport type AddUserOperationResponse = {\n id: string;\n hash: () => Promise<string | undefined>;\n transactionHash: () => Promise<string | undefined>;\n};\n\n/**\n * All the objects related to a pending user operation in order to:\n * - Avoid duplicated effort to derive the same properties.\n * - Minimise duplicate arguments in private methods.\n */\ntype UserOperationCache = {\n chainId: string;\n metadata: UserOperationMetadata;\n options: AddUserOperationOptions & {\n smartContractAccount: SmartContractAccount;\n };\n provider: Provider;\n request: AddUserOperationRequest;\n transaction?: TransactionParams;\n};\n\n/**\n * Controller for creating and managing the life cycle of user operations.\n */\nexport class UserOperationController extends BaseController<\n typeof controllerName,\n UserOperationControllerState,\n UserOperationControllerMessenger\n> {\n hub: UserOperationControllerEventEmitter;\n\n #entrypoint: string;\n\n #getGasFeeEstimates: () => Promise<GasFeeState>;\n\n #pendingUserOperationTracker: PendingUserOperationTracker;\n\n /**\n * Construct a UserOperationController instance.\n *\n * @param options - Controller options.\n * @param options.entrypoint - Address of the entrypoint contract.\n * @param options.getGasFeeEstimates - Callback to get gas fee estimates.\n * @param options.messenger - Restricted messenger for the user operation controller.\n * @param options.state - Initial state to set on the controller.\n */\n constructor({\n entrypoint,\n getGasFeeEstimates,\n messenger,\n state,\n }: UserOperationControllerOptions) {\n super({\n name: controllerName,\n metadata: stateMetadata,\n messenger,\n state: { ...getDefaultState(), ...state },\n });\n\n this.hub = new EventEmitter() as UserOperationControllerEventEmitter;\n\n this.#entrypoint = entrypoint;\n this.#getGasFeeEstimates = getGasFeeEstimates;\n\n this.#pendingUserOperationTracker = new PendingUserOperationTracker({\n getUserOperations: () =>\n cloneDeep(Object.values(this.state.userOperations)),\n messenger,\n });\n\n this.#addPendingUserOperationTrackerListeners();\n }\n\n /**\n * Create and submit a user operation.\n *\n * @param request - Information required to create a user operation.\n * @param request.data - Data to include in the resulting transaction.\n * @param request.maxFeePerGas - Maximum fee per gas to pay towards the transaction.\n * @param request.maxPriorityFeePerGas - Maximum priority fee per gas to pay towards the transaction.\n * @param request.to - Destination address of the resulting transaction.\n * @param request.value - Value to include in the resulting transaction.\n * @param options - Configuration options when creating a user operation.\n * @param options.networkClientId - ID of the network client used to query the chain.\n * @param options.origin - Origin of the user operation, such as the hostname of a dApp.\n * @param options.requireApproval - Whether to require user approval before submitting the user operation. Defaults to true.\n * @param options.smartContractAccount - Smart contract abstraction to provide the contract specific values such as call data and nonce. Defaults to the current snap account.\n * @param options.swaps - Swap metadata to record with the user operation.\n * @param options.type - Type of the transaction.\n */\n async addUserOperation(\n request: AddUserOperationRequest,\n options: AddUserOperationOptions,\n ): Promise<AddUserOperationResponse> {\n validateAddUserOperationRequest(request);\n validateAddUserOperationOptions(options);\n\n return await this.#addUserOperation(request, options);\n }\n\n /**\n * Create and submit a user operation equivalent to the provided transaction.\n *\n * @param transaction - Transaction to use as the basis for the user operation.\n * @param options - Configuration options when creating a user operation.\n * @param options.networkClientId - ID of the network client used to query the chain.\n * @param options.origin - Origin of the user operation, such as the hostname of a dApp.\n * @param options.requireApproval - Whether to require user approval before submitting the user operation. Defaults to true.\n * @param options.smartContractAccount - Smart contract abstraction to provide the contract specific values such as call data and nonce. Defaults to the current snap account.\n * @param options.swaps - Swap metadata to record with the user operation.\n * @param options.type - Type of the transaction.\n */\n async addUserOperationFromTransaction(\n transaction: TransactionParams,\n options: AddUserOperationOptions,\n ): Promise<AddUserOperationResponse> {\n validateAddUserOperationOptions(options);\n\n const { data, from, maxFeePerGas, maxPriorityFeePerGas, to, value } =\n transaction;\n\n const request: AddUserOperationRequest = {\n data: data === '' ? undefined : data,\n from,\n maxFeePerGas,\n maxPriorityFeePerGas,\n to,\n value,\n };\n\n validateAddUserOperationRequest(request);\n\n return await this.#addUserOperation(request, { ...options, transaction });\n }\n\n startPollingByNetworkClientId(networkClientId: string): string {\n return this.#pendingUserOperationTracker.startPolling({\n networkClientId,\n });\n }\n\n async #addUserOperation(\n request: AddUserOperationRequest,\n options: AddUserOperationOptions & { transaction?: TransactionParams },\n ): Promise<AddUserOperationResponse> {\n log('Adding user operation', { request, options });\n\n const {\n networkClientId,\n origin,\n smartContractAccount: requestSmartContractAccount,\n swaps,\n transaction,\n } = options;\n\n const { chainId, provider } = await this.#getProvider(networkClientId);\n\n const metadata = await this.#createMetadata(\n chainId,\n origin,\n transaction,\n swaps,\n );\n\n const smartContractAccount =\n requestSmartContractAccount ??\n new SnapSmartContractAccount(this.messenger);\n\n const cache: UserOperationCache = {\n chainId,\n metadata,\n options: { ...options, smartContractAccount },\n provider,\n request,\n transaction,\n };\n\n const { id } = metadata;\n let throwError = false;\n\n const hashValue = (async () => {\n try {\n return await this.#prepareAndSubmitUserOperation(cache);\n } catch (error) {\n this.#failUserOperation(metadata, error);\n\n if (throwError) {\n throw error;\n }\n\n return undefined;\n }\n })();\n\n const hash = async () => {\n throwError = true;\n return await hashValue;\n };\n\n const transactionHash = async () => {\n await hash();\n\n const { transactionHash: finalTransactionHash } =\n await this.#waitForConfirmation(metadata);\n\n return finalTransactionHash as string;\n };\n\n return {\n id,\n hash,\n transactionHash,\n };\n }\n\n async #prepareAndSubmitUserOperation(cache: UserOperationCache) {\n const { metadata, options } = cache;\n const { requireApproval, smartContractAccount } = options;\n let resultCallbacks: AcceptResultCallbacks | undefined;\n\n try {\n await this.#prepareUserOperation(cache);\n await this.#addPaymasterData(metadata, smartContractAccount);\n\n this.hub.emit('user-operation-added', metadata);\n\n if (requireApproval !== false) {\n resultCallbacks = await this.#approveUserOperation(cache);\n }\n\n await this.#signUserOperation(metadata, smartContractAccount);\n await this.#submitUserOperation(metadata);\n\n resultCallbacks?.success();\n\n return metadata.hash as string;\n } catch (error) {\n /* istanbul ignore next */\n resultCallbacks?.error(error as Error);\n throw error;\n }\n }\n\n async #waitForConfirmation(\n metadata: UserOperationMetadata,\n ): Promise<UserOperationMetadata> {\n const { id, hash } = metadata;\n\n log('Waiting for confirmation', id, hash);\n\n return new Promise((resolve, reject) => {\n this.hub.once(`${id}:confirmed`, (finalMetadata) => {\n resolve(finalMetadata);\n });\n\n this.hub.once(`${id}:failed`, (_finalMetadata, error) => {\n reject(error);\n });\n });\n }\n\n async #createMetadata(\n chainId: string,\n origin: string,\n transaction?: TransactionParams,\n swaps?: AddUserOperationSwapOptions,\n ): Promise<UserOperationMetadata> {\n const metadata: UserOperationMetadata = {\n actualGasCost: null,\n actualGasUsed: null,\n baseFeePerGas: null,\n bundlerUrl: null,\n chainId,\n error: null,\n hash: null,\n id: random(),\n origin,\n status: UserOperationStatus.Unapproved,\n swapsMetadata: swaps\n ? {\n approvalTxId: swaps.approvalTxId ?? null,\n destinationTokenAddress: swaps.destinationTokenAddress ?? null,\n destinationTokenAmount: swaps.destinationTokenAmount ?? null,\n destinationTokenDecimals: swaps.destinationTokenDecimals ?? null,\n destinationTokenSymbol: swaps.destinationTokenSymbol ?? null,\n estimatedBaseFee: swaps.estimatedBaseFee ?? null,\n sourceTokenAddress: swaps.sourceTokenAddress ?? null,\n sourceTokenAmount: swaps.sourceTokenAmount ?? null,\n sourceTokenDecimals: swaps.sourceTokenDecimals ?? null,\n sourceTokenSymbol: swaps.sourceTokenSymbol ?? null,\n swapAndSendRecipient: swaps.swapAndSendRecipient ?? null,\n swapMetaData: (swaps.swapMetaData as Record<string, never>) ?? null,\n swapTokenValue: swaps.swapTokenValue ?? null,\n }\n : null,\n time: Date.now(),\n transactionHash: null,\n transactionParams: (transaction as Required<TransactionParams>) ?? null,\n transactionType: null,\n userFeeLevel: null,\n userOperation: this.#createEmptyUserOperation(transaction),\n };\n\n this.#updateMetadata(metadata);\n\n log('Added user operation', metadata.id);\n\n return metadata;\n }\n\n async #prepareUserOperation(cache: UserOperationCache) {\n const { chainId, metadata, options, provider, request, transaction } =\n cache;\n\n const { data, from, to, value } = request;\n const { id, transactionParams, userOperation } = metadata;\n const { smartContractAccount } = options;\n\n log('Preparing user operation', { id });\n\n const transactionType = await this.#getTransactionType(\n transaction,\n provider,\n options,\n );\n\n metadata.transactionType = transactionType ?? null;\n\n log('Determined transaction type', transactionType);\n\n await updateGasFees({\n getGasFeeEstimates: this.#getGasFeeEstimates,\n metadata,\n originalRequest: request,\n provider,\n transaction: transactionParams ?? undefined,\n });\n\n const response = await smartContractAccount.prepareUserOperation({\n chainId,\n data,\n from,\n to,\n value,\n });\n\n validatePrepareUserOperationResponse(response);\n\n const {\n bundler: bundlerUrl,\n callData,\n dummyPaymasterAndData,\n dummySignature,\n initCode,\n nonce,\n sender,\n } = response;\n\n userOperation.callData = callData;\n userOperation.initCode = initCode ?? EMPTY_BYTES;\n userOperation.nonce = nonce;\n userOperation.paymasterAndData = dummyPaymasterAndData ?? EMPTY_BYTES;\n userOperation.sender = sender;\n userOperation.signature = dummySignature ?? EMPTY_BYTES;\n\n metadata.bundlerUrl = bundlerUrl;\n\n await updateGas(metadata, response, this.#entrypoint);\n\n this.#updateMetadata(metadata);\n }\n\n async #addPaymasterData(\n metadata: UserOperationMetadata,\n smartContractAccount: SmartContractAccount,\n ) {\n const { id, userOperation, chainId } = metadata;\n\n log('Requesting paymaster data', { id });\n\n const response = await smartContractAccount.updateUserOperation({\n userOperation,\n chainId,\n });\n\n validateUpdateUserOperationResponse(response);\n\n userOperation.paymasterAndData = response.paymasterAndData ?? EMPTY_BYTES;\n if (response.callGasLimit) {\n userOperation.callGasLimit = response.callGasLimit;\n }\n if (response.preVerificationGas) {\n userOperation.preVerificationGas = response.preVerificationGas;\n }\n if (response.verificationGasLimit) {\n userOperation.verificationGasLimit = response.verificationGasLimit;\n }\n\n this.#updateMetadata(metadata);\n }\n\n async #approveUserOperation(cache: UserOperationCache) {\n log('Requesting approval');\n\n const { metadata } = cache;\n\n const { resultCallbacks, value } = await this.#requestApproval(metadata);\n const updatedTransaction = value?.txMeta;\n\n if (updatedTransaction) {\n await this.#updateUserOperationAfterApproval(cache, updatedTransaction);\n }\n\n metadata.status = UserOperationStatus.Approved;\n\n this.#updateMetadata(metadata);\n\n return resultCallbacks;\n }\n\n async #signUserOperation(\n metadata: UserOperationMetadata,\n smartContractAccount: SmartContractAccount,\n ) {\n const { id, chainId, userOperation } = metadata;\n\n log('Signing user operation', id, userOperation);\n\n const response = await smartContractAccount.signUserOperation({\n userOperation,\n chainId,\n });\n\n validateSignUserOperationResponse(response);\n\n const { signature } = response;\n\n userOperation.signature = signature;\n\n log('Signed user operation', signature);\n\n metadata.status = UserOperationStatus.Signed;\n\n this.#updateMetadata(metadata);\n }\n\n async #submitUserOperation(metadata: UserOperationMetadata) {\n const { userOperation } = metadata;\n\n log('Submitting user operation', userOperation);\n\n const bundler = new Bundler(metadata.bundlerUrl as string);\n\n const hash = await bundler.sendUserOperation(\n userOperation,\n this.#entrypoint,\n );\n\n metadata.hash = hash;\n metadata.status = UserOperationStatus.Submitted;\n\n this.#updateMetadata(metadata);\n }\n\n #failUserOperation(metadata: UserOperationMetadata, error: unknown) {\n const { id } = metadata;\n const rawError = error as Record<string, string>;\n\n log('User operation failed', id, error);\n\n metadata.error = {\n name: rawError.name,\n message: rawError.message,\n stack: rawError.stack,\n code: rawError.code,\n rpc: rawError.value,\n };\n\n metadata.status = UserOperationStatus.Failed;\n\n this.#updateMetadata(metadata);\n\n if (\n String(rawError.code) === String(errorCodes.provider.userRejectedRequest)\n ) {\n this.#deleteMetadata(id);\n }\n }\n\n #createEmptyUserOperation(transaction?: TransactionParams): UserOperation {\n return {\n callData: EMPTY_BYTES,\n callGasLimit: EMPTY_BYTES,\n initCode: EMPTY_BYTES,\n maxFeePerGas: transaction?.maxFeePerGas ?? EMPTY_BYTES,\n maxPriorityFeePerGas: transaction?.maxPriorityFeePerGas ?? EMPTY_BYTES,\n nonce: EMPTY_BYTES,\n paymasterAndData: EMPTY_BYTES,\n preVerificationGas: EMPTY_BYTES,\n sender: ADDRESS_ZERO,\n signature: EMPTY_BYTES,\n verificationGasLimit: EMPTY_BYTES,\n };\n }\n\n #updateMetadata(metadata: UserOperationMetadata) {\n const { id } = metadata;\n\n this.update((state) => {\n state.userOperations[id] = cloneDeep(metadata);\n });\n\n this.#updateTransaction(metadata);\n }\n\n #deleteMetadata(id: string) {\n this.update((state) => {\n delete state.userOperations[id];\n });\n }\n\n #updateTransaction(metadata: UserOperationMetadata) {\n if (!metadata.transactionParams) {\n return;\n }\n\n const transactionMetadata = getTransactionMetadata(metadata);\n\n this.hub.emit('transaction-updated', transactionMetadata);\n }\n\n #addPendingUserOperationTrackerListeners() {\n this.#pendingUserOperationTracker.hub.on(\n 'user-operation-confirmed',\n (metadata) => {\n log('In listener...');\n this.hub.emit('user-operation-confirmed', metadata);\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n this.hub.emit(`${metadata.id}:confirmed`, metadata);\n },\n );\n\n this.#pendingUserOperationTracker.hub.on(\n 'user-operation-failed',\n (metadata, error) => {\n this.hub.emit('user-operation-failed', metadata, error);\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n this.hub.emit(`${metadata.id}:failed`, metadata, error);\n },\n );\n\n this.#pendingUserOperationTracker.hub.on(\n 'user-operation-updated',\n (metadata) => {\n this.#updateMetadata(metadata);\n },\n );\n }\n\n async #requestApproval(metadata: UserOperationMetadata) {\n const { id, origin } = metadata;\n const type = ApprovalType.Transaction;\n const requestData = { txId: id };\n\n return (await this.messenger.call(\n 'ApprovalController:addRequest',\n {\n id,\n origin,\n type,\n requestData,\n expectsResult: true,\n },\n true, // Should display approval request to user\n )) as AddResult & { value?: { txMeta?: TransactionMeta } };\n }\n\n async #getTransactionType(\n transaction: TransactionParams | undefined,\n provider: Provider,\n options: AddUserOperationOptions,\n ): Promise<TransactionType | undefined> {\n if (!transaction) {\n return undefined;\n }\n\n if (options.type) {\n return options.type;\n }\n\n const ethQuery = new EthQuery(provider);\n const result = determineTransactionType(transaction, ethQuery);\n\n return (await result).type;\n }\n\n async #getProvider(\n networkClientId: string,\n ): Promise<{ provider: Provider; chainId: string }> {\n const { provider, configuration } = this.messenger.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n\n const { chainId } = configuration;\n\n return { provider, chainId };\n }\n\n async #updateUserOperationAfterApproval(\n cache: UserOperationCache,\n updatedTransaction: TransactionMeta,\n ) {\n log('Found updated transaction in approval', { updatedTransaction });\n\n const { metadata, request } = cache;\n\n const { userOperation } = metadata;\n const usingPaymaster = userOperation.paymasterAndData !== EMPTY_BYTES;\n\n const updatedMaxFeePerGas = add0x(\n updatedTransaction.txParams.maxFeePerGas as string,\n );\n\n const updatedMaxPriorityFeePerGas = add0x(\n updatedTransaction.txParams.maxPriorityFeePerGas as string,\n );\n\n let regenerateUserOperation = false;\n const previousMaxFeePerGas = userOperation.maxFeePerGas;\n const previousMaxPriorityFeePerGas = userOperation.maxPriorityFeePerGas;\n\n const gasFeesUpdated =\n previousMaxFeePerGas !== updatedMaxFeePerGas ||\n previousMaxPriorityFeePerGas !== updatedMaxPriorityFeePerGas;\n\n /**\n * true when we detect {@link getTransactionMetadata} has set the gas fees to zero\n * because the userOperation has a paymaster. This should not be mistaken for gas\n * fees being updated during the approval process.\n */\n const areGasFeesZeroBecauseOfPaymaster =\n usingPaymaster &&\n updatedMaxFeePerGas === VALUE_ZERO &&\n updatedMaxPriorityFeePerGas === VALUE_ZERO;\n\n if (gasFeesUpdated && !areGasFeesZeroBecauseOfPaymaster) {\n log('Gas fees updated during approval', {\n previousMaxFeePerGas,\n previousMaxPriorityFeePerGas,\n updatedMaxFeePerGas,\n updatedMaxPriorityFeePerGas,\n });\n\n userOperation.maxFeePerGas = updatedMaxFeePerGas;\n userOperation.maxPriorityFeePerGas = updatedMaxPriorityFeePerGas;\n\n regenerateUserOperation = usingPaymaster;\n }\n\n const previousData = request.data ?? EMPTY_BYTES;\n const updatedData = updatedTransaction.txParams.data ?? EMPTY_BYTES;\n\n if (previousData !== updatedData) {\n log('Data updated during approval', { previousData, updatedData });\n regenerateUserOperation = true;\n }\n\n const previousValue = request.value ?? VALUE_ZERO;\n const updatedValue = updatedTransaction.txParams.value ?? VALUE_ZERO;\n\n if (previousValue !== updatedValue) {\n log('Value updated during approval', { previousValue, updatedValue });\n regenerateUserOperation = true;\n }\n\n if (regenerateUserOperation) {\n const updatedRequest = {\n ...request,\n data: updatedData,\n maxFeePerGas: updatedMaxFeePerGas,\n maxPriorityFeePerGas: updatedMaxPriorityFeePerGas,\n value: updatedValue,\n };\n\n await this.#regenerateUserOperation({\n ...cache,\n request: updatedRequest,\n });\n }\n }\n\n async #regenerateUserOperation(cache: UserOperationCache) {\n log(\n 'Regenerating user operation as parameters were updated during approval',\n );\n\n const {\n options: { smartContractAccount },\n metadata,\n } = cache;\n\n await this.#prepareUserOperation(cache);\n await this.#addPaymasterData(metadata, smartContractAccount);\n\n log('Regenerated user operation', metadata.userOperation);\n }\n}\n"]}
@@ -1,13 +1,12 @@
1
1
  /// <reference types="node" />
2
2
  import type { AddApprovalRequest } from "@metamask/approval-controller";
3
- import type { RestrictedMessenger } from "@metamask/base-controller";
4
- import { BaseController } from "@metamask/base-controller";
3
+ import { BaseController, type ControllerGetStateAction, type ControllerStateChangeEvent } from "@metamask/base-controller/next";
5
4
  import type { GasFeeState } from "@metamask/gas-fee-controller";
6
5
  import type { KeyringControllerPrepareUserOperationAction, KeyringControllerPatchUserOperationAction, KeyringControllerSignUserOperationAction } from "@metamask/keyring-controller";
6
+ import type { Messenger } from "@metamask/messenger";
7
7
  import type { NetworkControllerGetNetworkClientByIdAction } from "@metamask/network-controller";
8
8
  import { type TransactionMeta, type TransactionParams, type TransactionType } from "@metamask/transaction-controller";
9
9
  import EventEmitter from "events";
10
- import type { Patch } from "immer";
11
10
  import type { SmartContractAccount, UserOperationMetadata } from "./types.cjs";
12
11
  declare const controllerName = "UserOperationController";
13
12
  type Events = {
@@ -26,17 +25,11 @@ export type UserOperationControllerEventEmitter = EventEmitter & {
26
25
  export type UserOperationControllerState = {
27
26
  userOperations: Record<string, UserOperationMetadata>;
28
27
  };
29
- export type GetUserOperationState = {
30
- type: `${typeof controllerName}:getState`;
31
- handler: () => UserOperationControllerState;
32
- };
33
- export type UserOperationStateChange = {
34
- type: `${typeof controllerName}:stateChange`;
35
- payload: [UserOperationControllerState, Patch[]];
36
- };
28
+ export type GetUserOperationState = ControllerGetStateAction<typeof controllerName, UserOperationControllerState>;
29
+ export type UserOperationStateChange = ControllerStateChangeEvent<typeof controllerName, UserOperationControllerState>;
37
30
  export type UserOperationControllerActions = GetUserOperationState | NetworkControllerGetNetworkClientByIdAction | AddApprovalRequest | KeyringControllerPrepareUserOperationAction | KeyringControllerPatchUserOperationAction | KeyringControllerSignUserOperationAction;
38
31
  export type UserOperationControllerEvents = UserOperationStateChange;
39
- export type UserOperationControllerMessenger = RestrictedMessenger<typeof controllerName, UserOperationControllerActions, UserOperationControllerEvents, UserOperationControllerActions['type'], UserOperationControllerEvents['type']>;
32
+ export type UserOperationControllerMessenger = Messenger<typeof controllerName, UserOperationControllerActions, UserOperationControllerEvents>;
40
33
  export type UserOperationControllerOptions = {
41
34
  entrypoint: string;
42
35
  getGasFeeEstimates: () => Promise<GasFeeState>;
@@ -1 +1 @@
1
- {"version":3,"file":"UserOperationController.d.cts","sourceRoot":"","sources":["../src/UserOperationController.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAEV,kBAAkB,EAEnB,sCAAsC;AACvC,OAAO,KAAK,EAAE,mBAAmB,EAAE,kCAAkC;AACrE,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAG3D,OAAO,KAAK,EAAE,WAAW,EAAE,qCAAqC;AAChE,OAAO,KAAK,EACV,2CAA2C,EAC3C,yCAAyC,EACzC,wCAAwC,EACzC,qCAAqC;AACtC,OAAO,KAAK,EACV,2CAA2C,EAE5C,qCAAqC;AAEtC,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACrB,yCAAyC;AAI1C,OAAO,YAAY,eAAe;AAClC,OAAO,KAAK,EAAE,KAAK,EAAE,cAAc;AASnC,OAAO,KAAK,EACV,oBAAoB,EAEpB,qBAAqB,EACtB,oBAAgB;AAajB,QAAA,MAAM,cAAc,4BAA4B,CAAC;AAejD,KAAK,MAAM,GAAG;IACZ,qBAAqB,EAAE,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;IACnD,sBAAsB,EAAE,CAAC,QAAQ,EAAE,qBAAqB,CAAC,CAAC;IAC1D,0BAA0B,EAAE,CAAC,QAAQ,EAAE,qBAAqB,CAAC,CAAC;IAC9D,uBAAuB,EAAE,CAAC,QAAQ,EAAE,qBAAqB,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IACzE,CAAC,GAAG,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AAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAC5C,KAAK,CAAC,EAAE,2BAA2B,CAAC;IACpC,IAAI,CAAC,EAAE,eAAe,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IACxC,eAAe,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;CACpD,CAAC;AAkBF;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,cAAc,CACzD,OAAO,cAAc,EACrB,4BAA4B,EAC5B,gCAAgC,CACjC;;IACC,GAAG,EAAE,mCAAmC,CAAC;IAQzC;;;;;;;;OAQG;gBACS,EACV,UAAU,EACV,kBAAkB,EAClB,SAAS,EACT,KAAK,GACN,EAAE,8BAA8B;IAsBjC;;;;;;;;;;;;;;;;OAgBG;IACG,gBAAgB,CACpB,OAAO,EAAE,uBAAuB,EAChC,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,wBAAwB,CAAC;IAOpC;;;;;;;;;;;OAWG;IACG,+BAA+B,CACnC,WAAW,EAAE,iBAAiB,EAC9B,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,wBAAwB,CAAC;IAoBpC,6BAA6B,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM;CA8jB/D"}
1
+ {"version":3,"file":"UserOperationController.d.cts","sourceRoot":"","sources":["../src/UserOperationController.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAEV,kBAAkB,EAEnB,sCAAsC;AACvC,O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ACrB,4BAA4B,EAC5B,gCAAgC,CACjC;;IACC,GAAG,EAAE,mCAAmC,CAAC;IAQzC;;;;;;;;OAQG;gBACS,EACV,UAAU,EACV,kBAAkB,EAClB,SAAS,EACT,KAAK,GACN,EAAE,8BAA8B;IAsBjC;;;;;;;;;;;;;;;;OAgBG;IACG,gBAAgB,CACpB,OAAO,EAAE,uBAAuB,EAChC,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,wBAAwB,CAAC;IAOpC;;;;;;;;;;;OAWG;IACG,+BAA+B,CACnC,WAAW,EAAE,iBAAiB,EAC9B,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,wBAAwB,CAAC;IAoBpC,6BAA6B,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM;CA8jB/D"}
@@ -1,13 +1,12 @@
1
1
  /// <reference types="node" />
2
2
  import type { AddApprovalRequest } from "@metamask/approval-controller";
3
- import type { RestrictedMessenger } from "@metamask/base-controller";
4
- import { BaseController } from "@metamask/base-controller";
3
+ import { BaseController, type ControllerGetStateAction, type ControllerStateChangeEvent } from "@metamask/base-controller/next";
5
4
  import type { GasFeeState } from "@metamask/gas-fee-controller";
6
5
  import type { KeyringControllerPrepareUserOperationAction, KeyringControllerPatchUserOperationAction, KeyringControllerSignUserOperationAction } from "@metamask/keyring-controller";
6
+ import type { Messenger } from "@metamask/messenger";
7
7
  import type { NetworkControllerGetNetworkClientByIdAction } from "@metamask/network-controller";
8
8
  import { type TransactionMeta, type TransactionParams, type TransactionType } from "@metamask/transaction-controller";
9
9
  import EventEmitter from "events";
10
- import type { Patch } from "immer";
11
10
  import type { SmartContractAccount, UserOperationMetadata } from "./types.mjs";
12
11
  declare const controllerName = "UserOperationController";
13
12
  type Events = {
@@ -26,17 +25,11 @@ export type UserOperationControllerEventEmitter = EventEmitter & {
26
25
  export type UserOperationControllerState = {
27
26
  userOperations: Record<string, UserOperationMetadata>;
28
27
  };
29
- export type GetUserOperationState = {
30
- type: `${typeof controllerName}:getState`;
31
- handler: () => UserOperationControllerState;
32
- };
33
- export type UserOperationStateChange = {
34
- type: `${typeof controllerName}:stateChange`;
35
- payload: [UserOperationControllerState, Patch[]];
36
- };
28
+ export type GetUserOperationState = ControllerGetStateAction<typeof controllerName, UserOperationControllerState>;
29
+ export type UserOperationStateChange = ControllerStateChangeEvent<typeof controllerName, UserOperationControllerState>;
37
30
  export type UserOperationControllerActions = GetUserOperationState | NetworkControllerGetNetworkClientByIdAction | AddApprovalRequest | KeyringControllerPrepareUserOperationAction | KeyringControllerPatchUserOperationAction | KeyringControllerSignUserOperationAction;
38
31
  export type UserOperationControllerEvents = UserOperationStateChange;
39
- export type UserOperationControllerMessenger = RestrictedMessenger<typeof controllerName, UserOperationControllerActions, UserOperationControllerEvents, UserOperationControllerActions['type'], UserOperationControllerEvents['type']>;
32
+ export type UserOperationControllerMessenger = Messenger<typeof controllerName, UserOperationControllerActions, UserOperationControllerEvents>;
40
33
  export type UserOperationControllerOptions = {
41
34
  entrypoint: string;
42
35
  getGasFeeEstimates: () => Promise<GasFeeState>;
@@ -1 +1 @@
1
- {"version":3,"file":"UserOperationController.d.mts","sourceRoot":"","sources":["../src/UserOperationController.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAEV,kBAAkB,EAEnB,sCAAsC;AACvC,OAAO,KAAK,EAAE,mBAAmB,EAAE,kCAAkC;AACrE,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAG3D,OAAO,KAAK,EAAE,WAAW,EAAE,qCAAqC;AAChE,OAAO,KAAK,EACV,2CAA2C,EAC3C,yCAAyC,EACzC,wCAAwC,EACzC,qCAAqC;AACtC,OAAO,KAAK,EACV,2CAA2C,EAE5C,qCAAqC;AAEtC,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACrB,yCAAyC;AAI1C,OAAO,YAAY,eAAe;AAClC,OAAO,KAAK,EAAE,KAAK,EAAE,cAAc;AASnC,OAAO,KAAK,EACV,oBAAo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E,oBAAoB,CAAC;IAC5C,KAAK,CAAC,EAAE,2BAA2B,CAAC;IACpC,IAAI,CAAC,EAAE,eAAe,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IACxC,eAAe,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;CACpD,CAAC;AAkBF;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,cAAc,CACzD,OAAO,cAAc,EACrB,4BAA4B,EAC5B,gCAAgC,CACjC;;IACC,GAAG,EAAE,mCAAmC,CAAC;IAQzC;;;;;;;;OAQG;gBACS,EACV,UAAU,EACV,kBAAkB,EAClB,SAAS,EACT,KAAK,GACN,EAAE,8BAA8B;IAsBjC;;;;;;;;;;;;;;;;OAgBG;IACG,gBAAgB,CACpB,OAAO,EAAE,uBAAuB,EAChC,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,wBAAwB,CAAC;IAOpC;;;;;;;;;;;OAWG;IACG,+BAA+B,CACnC,WAAW,EAAE,iBAAiB,EAC9B,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,wBAAwB,CAAC;IAoBpC,6BAA6B,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM;CA8jB/D"}
@@ -16,7 +16,7 @@ function $importDefault(module) {
16
16
  }
17
17
  return module;
18
18
  }
19
- import { BaseController } from "@metamask/base-controller";
19
+ import { BaseController } from "@metamask/base-controller/next";
20
20
  import { ApprovalType } from "@metamask/controller-utils";
21
21
  import $EthQuery from "@metamask/eth-query";
22
22
  const EthQuery = $importDefault($EthQuery);
@@ -44,7 +44,7 @@ const stateMetadata = {
44
44
  userOperations: {
45
45
  includeInStateLogs: true,
46
46
  persist: true,
47
- anonymous: false,
47
+ includeInDebugSnapshot: false,
48
48
  usedInUi: true,
49
49
  },
50
50
  };
@@ -144,7 +144,7 @@ _UserOperationController_entrypoint = new WeakMap(), _UserOperationController_ge
144
144
  const { chainId, provider } = await __classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_getProvider).call(this, networkClientId);
145
145
  const metadata = await __classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_createMetadata).call(this, chainId, origin, transaction, swaps);
146
146
  const smartContractAccount = requestSmartContractAccount ??
147
- new SnapSmartContractAccount(this.messagingSystem);
147
+ new SnapSmartContractAccount(this.messenger);
148
148
  const cache = {
149
149
  chainId,
150
150
  metadata,
@@ -404,7 +404,7 @@ _UserOperationController_entrypoint = new WeakMap(), _UserOperationController_ge
404
404
  const { id, origin } = metadata;
405
405
  const type = ApprovalType.Transaction;
406
406
  const requestData = { txId: id };
407
- return (await this.messagingSystem.call('ApprovalController:addRequest', {
407
+ return (await this.messenger.call('ApprovalController:addRequest', {
408
408
  id,
409
409
  origin,
410
410
  type,
@@ -422,7 +422,7 @@ _UserOperationController_entrypoint = new WeakMap(), _UserOperationController_ge
422
422
  const result = determineTransactionType(transaction, ethQuery);
423
423
  return (await result).type;
424
424
  }, _UserOperationController_getProvider = async function _UserOperationController_getProvider(networkClientId) {
425
- const { provider, configuration } = this.messagingSystem.call('NetworkController:getNetworkClientById', networkClientId);
425
+ const { provider, configuration } = this.messenger.call('NetworkController:getNetworkClientById', networkClientId);
426
426
  const { chainId } = configuration;
427
427
  return { provider, chainId };
428
428
  }, _UserOperationController_updateUserOperationAfterApproval = async function _UserOperationController_updateUserOperationAfterApproval(cache, updatedTransaction) {
@@ -1 +1 @@
1
- {"version":3,"file":"UserOperationController.mjs","sourceRoot":"","sources":["../src/UserOperationController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAMA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,EAAE,YAAY,EAAE,mCAAmC;AAC1D,OAAO,SAAQ,4BAA4B;;AAW3C,OAAO,EAAE,UAAU,EAAE,6BAA6B;AAClD,OA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AI,EAAuB,KAAK,CAAC,CAAC;IACxC,MAAM,uBAAA,IAAI,qFAAkB,MAAtB,IAAI,EAAmB,QAAQ,EAAE,oBAAoB,CAAC,CAAC;IAE7D,GAAG,CAAC,4BAA4B,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAC;AAC5D,CAAC","sourcesContent":["import type {\n AcceptResultCallbacks,\n AddApprovalRequest,\n AddResult,\n} from '@metamask/approval-controller';\nimport type { RestrictedMessenger } from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { ApprovalType } from '@metamask/controller-utils';\nimport EthQuery from '@metamask/eth-query';\nimport type { GasFeeState } from '@metamask/gas-fee-controller';\nimport type {\n KeyringControllerPrepareUserOperationAction,\n KeyringControllerPatchUserOperationAction,\n KeyringControllerSignUserOperationAction,\n} from '@metamask/keyring-controller';\nimport type {\n NetworkControllerGetNetworkClientByIdAction,\n Provider,\n} from '@metamask/network-controller';\nimport { errorCodes } from '@metamask/rpc-errors';\nimport {\n determineTransactionType,\n type TransactionMeta,\n type TransactionParams,\n type TransactionType,\n} from '@metamask/transaction-controller';\nimport { add0x } from '@metamask/utils';\n// This package purposefully relies on Node's EventEmitter module.\n// eslint-disable-next-line import-x/no-nodejs-modules\nimport EventEmitter from 'events';\nimport type { Patch } from 'immer';\nimport { cloneDeep } from 'lodash';\nimport { v1 as random } from 'uuid';\n\nimport { ADDRESS_ZERO, EMPTY_BYTES, VALUE_ZERO } from './constants';\nimport { Bundler } from './helpers/Bundler';\nimport { PendingUserOperationTracker } from './helpers/PendingUserOperationTracker';\nimport { SnapSmartContractAccount } from './helpers/SnapSmartContractAccount';\nimport { projectLogger as log } from './logger';\nimport type {\n SmartContractAccount,\n UserOperation,\n UserOperationMetadata,\n} from './types';\nimport { UserOperationStatus } from './types';\nimport { updateGas } from './utils/gas';\nimport { updateGasFees } from './utils/gas-fees';\nimport { getTransactionMetadata } from './utils/transaction';\nimport {\n validateAddUserOperationOptions,\n validateAddUserOperationRequest,\n validatePrepareUserOperationResponse,\n validateSignUserOperationResponse,\n validateUpdateUserOperationResponse,\n} from './utils/validation';\n\nconst controllerName = 'UserOperationController';\n\nconst stateMetadata = {\n userOperations: {\n includeInStateLogs: true,\n persist: true,\n anonymous: false,\n usedInUi: true,\n },\n};\n\nconst getDefaultState = () => ({\n userOperations: {},\n});\n\ntype Events = {\n 'transaction-updated': [metadata: TransactionMeta];\n 'user-operation-added': [metadata: UserOperationMetadata];\n 'user-operation-confirmed': [metadata: UserOperationMetadata];\n 'user-operation-failed': [metadata: UserOperationMetadata, error: Error];\n [key: `${string}:confirmed`]: [metadata: UserOperationMetadata];\n [key: `${string}:failed`]: [metadata: UserOperationMetadata, error: Error];\n};\n\nexport type UserOperationControllerEventEmitter = EventEmitter & {\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n on<T extends keyof Events>(\n eventName: T,\n listener: (...args: Events[T]) => void,\n ): UserOperationControllerEventEmitter;\n\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n once<T extends keyof Events>(\n eventName: T,\n listener: (...args: Events[T]) => void,\n ): UserOperationControllerEventEmitter;\n\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n emit<T extends keyof Events>(eventName: T, ...args: Events[T]): boolean;\n};\n\nexport type UserOperationControllerState = {\n userOperations: Record<string, UserOperationMetadata>;\n};\n\nexport type GetUserOperationState = {\n type: `${typeof controllerName}:getState`;\n handler: () => UserOperationControllerState;\n};\n\nexport type UserOperationStateChange = {\n type: `${typeof controllerName}:stateChange`;\n payload: [UserOperationControllerState, Patch[]];\n};\n\nexport type UserOperationControllerActions =\n | GetUserOperationState\n | NetworkControllerGetNetworkClientByIdAction\n | AddApprovalRequest\n | KeyringControllerPrepareUserOperationAction\n | KeyringControllerPatchUserOperationAction\n | KeyringControllerSignUserOperationAction;\n\nexport type UserOperationControllerEvents = UserOperationStateChange;\n\nexport type UserOperationControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n UserOperationControllerActions,\n UserOperationControllerEvents,\n UserOperationControllerActions['type'],\n UserOperationControllerEvents['type']\n>;\n\nexport type UserOperationControllerOptions = {\n entrypoint: string;\n getGasFeeEstimates: () => Promise<GasFeeState>;\n interval?: number;\n messenger: UserOperationControllerMessenger;\n state?: Partial<UserOperationControllerState>;\n};\n\nexport type AddUserOperationRequest = {\n data?: string;\n from: string;\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n to?: string;\n value?: string;\n};\n\nexport type AddUserOperationSwapOptions = {\n approvalTxId?: string;\n destinationTokenAddress?: string;\n destinationTokenAmount?: string;\n destinationTokenDecimals?: number;\n destinationTokenSymbol?: string;\n estimatedBaseFee?: string;\n sourceTokenAddress?: string;\n sourceTokenAmount?: string;\n sourceTokenDecimals?: number;\n sourceTokenSymbol?: string;\n swapAndSendRecipient?: string;\n swapMetaData?: Record<string, unknown>;\n swapTokenValue?: string;\n};\n\nexport type AddUserOperationOptions = {\n networkClientId: string;\n origin: string;\n requireApproval?: boolean;\n smartContractAccount?: SmartContractAccount;\n swaps?: AddUserOperationSwapOptions;\n type?: TransactionType;\n};\n\nexport type AddUserOperationResponse = {\n id: string;\n hash: () => Promise<string | undefined>;\n transactionHash: () => Promise<string | undefined>;\n};\n\n/**\n * All the objects related to a pending user operation in order to:\n * - Avoid duplicated effort to derive the same properties.\n * - Minimise duplicate arguments in private methods.\n */\ntype UserOperationCache = {\n chainId: string;\n metadata: UserOperationMetadata;\n options: AddUserOperationOptions & {\n smartContractAccount: SmartContractAccount;\n };\n provider: Provider;\n request: AddUserOperationRequest;\n transaction?: TransactionParams;\n};\n\n/**\n * Controller for creating and managing the life cycle of user operations.\n */\nexport class UserOperationController extends BaseController<\n typeof controllerName,\n UserOperationControllerState,\n UserOperationControllerMessenger\n> {\n hub: UserOperationControllerEventEmitter;\n\n #entrypoint: string;\n\n #getGasFeeEstimates: () => Promise<GasFeeState>;\n\n #pendingUserOperationTracker: PendingUserOperationTracker;\n\n /**\n * Construct a UserOperationController instance.\n *\n * @param options - Controller options.\n * @param options.entrypoint - Address of the entrypoint contract.\n * @param options.getGasFeeEstimates - Callback to get gas fee estimates.\n * @param options.messenger - Restricted messenger for the user operation controller.\n * @param options.state - Initial state to set on the controller.\n */\n constructor({\n entrypoint,\n getGasFeeEstimates,\n messenger,\n state,\n }: UserOperationControllerOptions) {\n super({\n name: controllerName,\n metadata: stateMetadata,\n messenger,\n state: { ...getDefaultState(), ...state },\n });\n\n this.hub = new EventEmitter() as UserOperationControllerEventEmitter;\n\n this.#entrypoint = entrypoint;\n this.#getGasFeeEstimates = getGasFeeEstimates;\n\n this.#pendingUserOperationTracker = new PendingUserOperationTracker({\n getUserOperations: () =>\n cloneDeep(Object.values(this.state.userOperations)),\n messenger,\n });\n\n this.#addPendingUserOperationTrackerListeners();\n }\n\n /**\n * Create and submit a user operation.\n *\n * @param request - Information required to create a user operation.\n * @param request.data - Data to include in the resulting transaction.\n * @param request.maxFeePerGas - Maximum fee per gas to pay towards the transaction.\n * @param request.maxPriorityFeePerGas - Maximum priority fee per gas to pay towards the transaction.\n * @param request.to - Destination address of the resulting transaction.\n * @param request.value - Value to include in the resulting transaction.\n * @param options - Configuration options when creating a user operation.\n * @param options.networkClientId - ID of the network client used to query the chain.\n * @param options.origin - Origin of the user operation, such as the hostname of a dApp.\n * @param options.requireApproval - Whether to require user approval before submitting the user operation. Defaults to true.\n * @param options.smartContractAccount - Smart contract abstraction to provide the contract specific values such as call data and nonce. Defaults to the current snap account.\n * @param options.swaps - Swap metadata to record with the user operation.\n * @param options.type - Type of the transaction.\n */\n async addUserOperation(\n request: AddUserOperationRequest,\n options: AddUserOperationOptions,\n ): Promise<AddUserOperationResponse> {\n validateAddUserOperationRequest(request);\n validateAddUserOperationOptions(options);\n\n return await this.#addUserOperation(request, options);\n }\n\n /**\n * Create and submit a user operation equivalent to the provided transaction.\n *\n * @param transaction - Transaction to use as the basis for the user operation.\n * @param options - Configuration options when creating a user operation.\n * @param options.networkClientId - ID of the network client used to query the chain.\n * @param options.origin - Origin of the user operation, such as the hostname of a dApp.\n * @param options.requireApproval - Whether to require user approval before submitting the user operation. Defaults to true.\n * @param options.smartContractAccount - Smart contract abstraction to provide the contract specific values such as call data and nonce. Defaults to the current snap account.\n * @param options.swaps - Swap metadata to record with the user operation.\n * @param options.type - Type of the transaction.\n */\n async addUserOperationFromTransaction(\n transaction: TransactionParams,\n options: AddUserOperationOptions,\n ): Promise<AddUserOperationResponse> {\n validateAddUserOperationOptions(options);\n\n const { data, from, maxFeePerGas, maxPriorityFeePerGas, to, value } =\n transaction;\n\n const request: AddUserOperationRequest = {\n data: data === '' ? undefined : data,\n from,\n maxFeePerGas,\n maxPriorityFeePerGas,\n to,\n value,\n };\n\n validateAddUserOperationRequest(request);\n\n return await this.#addUserOperation(request, { ...options, transaction });\n }\n\n startPollingByNetworkClientId(networkClientId: string): string {\n return this.#pendingUserOperationTracker.startPolling({\n networkClientId,\n });\n }\n\n async #addUserOperation(\n request: AddUserOperationRequest,\n options: AddUserOperationOptions & { transaction?: TransactionParams },\n ): Promise<AddUserOperationResponse> {\n log('Adding user operation', { request, options });\n\n const {\n networkClientId,\n origin,\n smartContractAccount: requestSmartContractAccount,\n swaps,\n transaction,\n } = options;\n\n const { chainId, provider } = await this.#getProvider(networkClientId);\n\n const metadata = await this.#createMetadata(\n chainId,\n origin,\n transaction,\n swaps,\n );\n\n const smartContractAccount =\n requestSmartContractAccount ??\n new SnapSmartContractAccount(this.messagingSystem);\n\n const cache: UserOperationCache = {\n chainId,\n metadata,\n options: { ...options, smartContractAccount },\n provider,\n request,\n transaction,\n };\n\n const { id } = metadata;\n let throwError = false;\n\n const hashValue = (async () => {\n try {\n return await this.#prepareAndSubmitUserOperation(cache);\n } catch (error) {\n this.#failUserOperation(metadata, error);\n\n if (throwError) {\n throw error;\n }\n\n return undefined;\n }\n })();\n\n const hash = async () => {\n throwError = true;\n return await hashValue;\n };\n\n const transactionHash = async () => {\n await hash();\n\n const { transactionHash: finalTransactionHash } =\n await this.#waitForConfirmation(metadata);\n\n return finalTransactionHash as string;\n };\n\n return {\n id,\n hash,\n transactionHash,\n };\n }\n\n async #prepareAndSubmitUserOperation(cache: UserOperationCache) {\n const { metadata, options } = cache;\n const { requireApproval, smartContractAccount } = options;\n let resultCallbacks: AcceptResultCallbacks | undefined;\n\n try {\n await this.#prepareUserOperation(cache);\n await this.#addPaymasterData(metadata, smartContractAccount);\n\n this.hub.emit('user-operation-added', metadata);\n\n if (requireApproval !== false) {\n resultCallbacks = await this.#approveUserOperation(cache);\n }\n\n await this.#signUserOperation(metadata, smartContractAccount);\n await this.#submitUserOperation(metadata);\n\n resultCallbacks?.success();\n\n return metadata.hash as string;\n } catch (error) {\n /* istanbul ignore next */\n resultCallbacks?.error(error as Error);\n throw error;\n }\n }\n\n async #waitForConfirmation(\n metadata: UserOperationMetadata,\n ): Promise<UserOperationMetadata> {\n const { id, hash } = metadata;\n\n log('Waiting for confirmation', id, hash);\n\n return new Promise((resolve, reject) => {\n this.hub.once(`${id}:confirmed`, (finalMetadata) => {\n resolve(finalMetadata);\n });\n\n this.hub.once(`${id}:failed`, (_finalMetadata, error) => {\n reject(error);\n });\n });\n }\n\n async #createMetadata(\n chainId: string,\n origin: string,\n transaction?: TransactionParams,\n swaps?: AddUserOperationSwapOptions,\n ): Promise<UserOperationMetadata> {\n const metadata: UserOperationMetadata = {\n actualGasCost: null,\n actualGasUsed: null,\n baseFeePerGas: null,\n bundlerUrl: null,\n chainId,\n error: null,\n hash: null,\n id: random(),\n origin,\n status: UserOperationStatus.Unapproved,\n swapsMetadata: swaps\n ? {\n approvalTxId: swaps.approvalTxId ?? null,\n destinationTokenAddress: swaps.destinationTokenAddress ?? null,\n destinationTokenAmount: swaps.destinationTokenAmount ?? null,\n destinationTokenDecimals: swaps.destinationTokenDecimals ?? null,\n destinationTokenSymbol: swaps.destinationTokenSymbol ?? null,\n estimatedBaseFee: swaps.estimatedBaseFee ?? null,\n sourceTokenAddress: swaps.sourceTokenAddress ?? null,\n sourceTokenAmount: swaps.sourceTokenAmount ?? null,\n sourceTokenDecimals: swaps.sourceTokenDecimals ?? null,\n sourceTokenSymbol: swaps.sourceTokenSymbol ?? null,\n swapAndSendRecipient: swaps.swapAndSendRecipient ?? null,\n swapMetaData: (swaps.swapMetaData as Record<string, never>) ?? null,\n swapTokenValue: swaps.swapTokenValue ?? null,\n }\n : null,\n time: Date.now(),\n transactionHash: null,\n transactionParams: (transaction as Required<TransactionParams>) ?? null,\n transactionType: null,\n userFeeLevel: null,\n userOperation: this.#createEmptyUserOperation(transaction),\n };\n\n this.#updateMetadata(metadata);\n\n log('Added user operation', metadata.id);\n\n return metadata;\n }\n\n async #prepareUserOperation(cache: UserOperationCache) {\n const { chainId, metadata, options, provider, request, transaction } =\n cache;\n\n const { data, from, to, value } = request;\n const { id, transactionParams, userOperation } = metadata;\n const { smartContractAccount } = options;\n\n log('Preparing user operation', { id });\n\n const transactionType = await this.#getTransactionType(\n transaction,\n provider,\n options,\n );\n\n metadata.transactionType = transactionType ?? null;\n\n log('Determined transaction type', transactionType);\n\n await updateGasFees({\n getGasFeeEstimates: this.#getGasFeeEstimates,\n metadata,\n originalRequest: request,\n provider,\n transaction: transactionParams ?? undefined,\n });\n\n const response = await smartContractAccount.prepareUserOperation({\n chainId,\n data,\n from,\n to,\n value,\n });\n\n validatePrepareUserOperationResponse(response);\n\n const {\n bundler: bundlerUrl,\n callData,\n dummyPaymasterAndData,\n dummySignature,\n initCode,\n nonce,\n sender,\n } = response;\n\n userOperation.callData = callData;\n userOperation.initCode = initCode ?? EMPTY_BYTES;\n userOperation.nonce = nonce;\n userOperation.paymasterAndData = dummyPaymasterAndData ?? EMPTY_BYTES;\n userOperation.sender = sender;\n userOperation.signature = dummySignature ?? EMPTY_BYTES;\n\n metadata.bundlerUrl = bundlerUrl;\n\n await updateGas(metadata, response, this.#entrypoint);\n\n this.#updateMetadata(metadata);\n }\n\n async #addPaymasterData(\n metadata: UserOperationMetadata,\n smartContractAccount: SmartContractAccount,\n ) {\n const { id, userOperation, chainId } = metadata;\n\n log('Requesting paymaster data', { id });\n\n const response = await smartContractAccount.updateUserOperation({\n userOperation,\n chainId,\n });\n\n validateUpdateUserOperationResponse(response);\n\n userOperation.paymasterAndData = response.paymasterAndData ?? EMPTY_BYTES;\n if (response.callGasLimit) {\n userOperation.callGasLimit = response.callGasLimit;\n }\n if (response.preVerificationGas) {\n userOperation.preVerificationGas = response.preVerificationGas;\n }\n if (response.verificationGasLimit) {\n userOperation.verificationGasLimit = response.verificationGasLimit;\n }\n\n this.#updateMetadata(metadata);\n }\n\n async #approveUserOperation(cache: UserOperationCache) {\n log('Requesting approval');\n\n const { metadata } = cache;\n\n const { resultCallbacks, value } = await this.#requestApproval(metadata);\n const updatedTransaction = value?.txMeta;\n\n if (updatedTransaction) {\n await this.#updateUserOperationAfterApproval(cache, updatedTransaction);\n }\n\n metadata.status = UserOperationStatus.Approved;\n\n this.#updateMetadata(metadata);\n\n return resultCallbacks;\n }\n\n async #signUserOperation(\n metadata: UserOperationMetadata,\n smartContractAccount: SmartContractAccount,\n ) {\n const { id, chainId, userOperation } = metadata;\n\n log('Signing user operation', id, userOperation);\n\n const response = await smartContractAccount.signUserOperation({\n userOperation,\n chainId,\n });\n\n validateSignUserOperationResponse(response);\n\n const { signature } = response;\n\n userOperation.signature = signature;\n\n log('Signed user operation', signature);\n\n metadata.status = UserOperationStatus.Signed;\n\n this.#updateMetadata(metadata);\n }\n\n async #submitUserOperation(metadata: UserOperationMetadata) {\n const { userOperation } = metadata;\n\n log('Submitting user operation', userOperation);\n\n const bundler = new Bundler(metadata.bundlerUrl as string);\n\n const hash = await bundler.sendUserOperation(\n userOperation,\n this.#entrypoint,\n );\n\n metadata.hash = hash;\n metadata.status = UserOperationStatus.Submitted;\n\n this.#updateMetadata(metadata);\n }\n\n #failUserOperation(metadata: UserOperationMetadata, error: unknown) {\n const { id } = metadata;\n const rawError = error as Record<string, string>;\n\n log('User operation failed', id, error);\n\n metadata.error = {\n name: rawError.name,\n message: rawError.message,\n stack: rawError.stack,\n code: rawError.code,\n rpc: rawError.value,\n };\n\n metadata.status = UserOperationStatus.Failed;\n\n this.#updateMetadata(metadata);\n\n if (\n String(rawError.code) === String(errorCodes.provider.userRejectedRequest)\n ) {\n this.#deleteMetadata(id);\n }\n }\n\n #createEmptyUserOperation(transaction?: TransactionParams): UserOperation {\n return {\n callData: EMPTY_BYTES,\n callGasLimit: EMPTY_BYTES,\n initCode: EMPTY_BYTES,\n maxFeePerGas: transaction?.maxFeePerGas ?? EMPTY_BYTES,\n maxPriorityFeePerGas: transaction?.maxPriorityFeePerGas ?? EMPTY_BYTES,\n nonce: EMPTY_BYTES,\n paymasterAndData: EMPTY_BYTES,\n preVerificationGas: EMPTY_BYTES,\n sender: ADDRESS_ZERO,\n signature: EMPTY_BYTES,\n verificationGasLimit: EMPTY_BYTES,\n };\n }\n\n #updateMetadata(metadata: UserOperationMetadata) {\n const { id } = metadata;\n\n this.update((state) => {\n state.userOperations[id] = cloneDeep(metadata);\n });\n\n this.#updateTransaction(metadata);\n }\n\n #deleteMetadata(id: string) {\n this.update((state) => {\n delete state.userOperations[id];\n });\n }\n\n #updateTransaction(metadata: UserOperationMetadata) {\n if (!metadata.transactionParams) {\n return;\n }\n\n const transactionMetadata = getTransactionMetadata(metadata);\n\n this.hub.emit('transaction-updated', transactionMetadata);\n }\n\n #addPendingUserOperationTrackerListeners() {\n this.#pendingUserOperationTracker.hub.on(\n 'user-operation-confirmed',\n (metadata) => {\n log('In listener...');\n this.hub.emit('user-operation-confirmed', metadata);\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n this.hub.emit(`${metadata.id}:confirmed`, metadata);\n },\n );\n\n this.#pendingUserOperationTracker.hub.on(\n 'user-operation-failed',\n (metadata, error) => {\n this.hub.emit('user-operation-failed', metadata, error);\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n this.hub.emit(`${metadata.id}:failed`, metadata, error);\n },\n );\n\n this.#pendingUserOperationTracker.hub.on(\n 'user-operation-updated',\n (metadata) => {\n this.#updateMetadata(metadata);\n },\n );\n }\n\n async #requestApproval(metadata: UserOperationMetadata) {\n const { id, origin } = metadata;\n const type = ApprovalType.Transaction;\n const requestData = { txId: id };\n\n return (await this.messagingSystem.call(\n 'ApprovalController:addRequest',\n {\n id,\n origin,\n type,\n requestData,\n expectsResult: true,\n },\n true, // Should display approval request to user\n )) as AddResult & { value?: { txMeta?: TransactionMeta } };\n }\n\n async #getTransactionType(\n transaction: TransactionParams | undefined,\n provider: Provider,\n options: AddUserOperationOptions,\n ): Promise<TransactionType | undefined> {\n if (!transaction) {\n return undefined;\n }\n\n if (options.type) {\n return options.type;\n }\n\n const ethQuery = new EthQuery(provider);\n const result = determineTransactionType(transaction, ethQuery);\n\n return (await result).type;\n }\n\n async #getProvider(\n networkClientId: string,\n ): Promise<{ provider: Provider; chainId: string }> {\n const { provider, configuration } = this.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n\n const { chainId } = configuration;\n\n return { provider, chainId };\n }\n\n async #updateUserOperationAfterApproval(\n cache: UserOperationCache,\n updatedTransaction: TransactionMeta,\n ) {\n log('Found updated transaction in approval', { updatedTransaction });\n\n const { metadata, request } = cache;\n\n const { userOperation } = metadata;\n const usingPaymaster = userOperation.paymasterAndData !== EMPTY_BYTES;\n\n const updatedMaxFeePerGas = add0x(\n updatedTransaction.txParams.maxFeePerGas as string,\n );\n\n const updatedMaxPriorityFeePerGas = add0x(\n updatedTransaction.txParams.maxPriorityFeePerGas as string,\n );\n\n let regenerateUserOperation = false;\n const previousMaxFeePerGas = userOperation.maxFeePerGas;\n const previousMaxPriorityFeePerGas = userOperation.maxPriorityFeePerGas;\n\n const gasFeesUpdated =\n previousMaxFeePerGas !== updatedMaxFeePerGas ||\n previousMaxPriorityFeePerGas !== updatedMaxPriorityFeePerGas;\n\n /**\n * true when we detect {@link getTransactionMetadata} has set the gas fees to zero\n * because the userOperation has a paymaster. This should not be mistaken for gas\n * fees being updated during the approval process.\n */\n const areGasFeesZeroBecauseOfPaymaster =\n usingPaymaster &&\n updatedMaxFeePerGas === VALUE_ZERO &&\n updatedMaxPriorityFeePerGas === VALUE_ZERO;\n\n if (gasFeesUpdated && !areGasFeesZeroBecauseOfPaymaster) {\n log('Gas fees updated during approval', {\n previousMaxFeePerGas,\n previousMaxPriorityFeePerGas,\n updatedMaxFeePerGas,\n updatedMaxPriorityFeePerGas,\n });\n\n userOperation.maxFeePerGas = updatedMaxFeePerGas;\n userOperation.maxPriorityFeePerGas = updatedMaxPriorityFeePerGas;\n\n regenerateUserOperation = usingPaymaster;\n }\n\n const previousData = request.data ?? EMPTY_BYTES;\n const updatedData = updatedTransaction.txParams.data ?? EMPTY_BYTES;\n\n if (previousData !== updatedData) {\n log('Data updated during approval', { previousData, updatedData });\n regenerateUserOperation = true;\n }\n\n const previousValue = request.value ?? VALUE_ZERO;\n const updatedValue = updatedTransaction.txParams.value ?? VALUE_ZERO;\n\n if (previousValue !== updatedValue) {\n log('Value updated during approval', { previousValue, updatedValue });\n regenerateUserOperation = true;\n }\n\n if (regenerateUserOperation) {\n const updatedRequest = {\n ...request,\n data: updatedData,\n maxFeePerGas: updatedMaxFeePerGas,\n maxPriorityFeePerGas: updatedMaxPriorityFeePerGas,\n value: updatedValue,\n };\n\n await this.#regenerateUserOperation({\n ...cache,\n request: updatedRequest,\n });\n }\n }\n\n async #regenerateUserOperation(cache: UserOperationCache) {\n log(\n 'Regenerating user operation as parameters were updated during approval',\n );\n\n const {\n options: { smartContractAccount },\n metadata,\n } = cache;\n\n await this.#prepareUserOperation(cache);\n await this.#addPaymasterData(metadata, smartContractAccount);\n\n log('Regenerated user operation', metadata.userOperation);\n }\n}\n"]}
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;YACR,OAAO,EAAE,cAAc;SACxB,CAAC,CAAC;KACJ;AACH,CAAC,qDAED,KAAK,2DAA0B,KAAyB;IACtD,GAAG,CACD,wEAAwE,CACzE,CAAC;IAEF,MAAM,EACJ,OAAO,EAAE,EAAE,oBAAoB,EAAE,EACjC,QAAQ,GACT,GAAG,KAAK,CAAC;IAEV,MAAM,uBAAA,IAAI,yFAAsB,MAA1B,IAAI,EAAuB,KAAK,CAAC,CAAC;IACxC,MAAM,uBAAA,IAAI,qFAAkB,MAAtB,IAAI,EAAmB,QAAQ,EAAE,oBAAoB,CAAC,CAAC;IAE7D,GAAG,CAAC,4BAA4B,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAC;AAC5D,CAAC","sourcesContent":["import type {\n AcceptResultCallbacks,\n AddApprovalRequest,\n AddResult,\n} from '@metamask/approval-controller';\nimport {\n BaseController,\n type ControllerGetStateAction,\n type ControllerStateChangeEvent,\n} from '@metamask/base-controller/next';\nimport { ApprovalType } from '@metamask/controller-utils';\nimport EthQuery from '@metamask/eth-query';\nimport type { GasFeeState } from '@metamask/gas-fee-controller';\nimport type {\n KeyringControllerPrepareUserOperationAction,\n KeyringControllerPatchUserOperationAction,\n KeyringControllerSignUserOperationAction,\n} from '@metamask/keyring-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n NetworkControllerGetNetworkClientByIdAction,\n Provider,\n} from '@metamask/network-controller';\nimport { errorCodes } from '@metamask/rpc-errors';\nimport {\n determineTransactionType,\n type TransactionMeta,\n type TransactionParams,\n type TransactionType,\n} from '@metamask/transaction-controller';\nimport { add0x } from '@metamask/utils';\n// This package purposefully relies on Node's EventEmitter module.\n// eslint-disable-next-line import-x/no-nodejs-modules\nimport EventEmitter from 'events';\nimport { cloneDeep } from 'lodash';\nimport { v1 as random } from 'uuid';\n\nimport { ADDRESS_ZERO, EMPTY_BYTES, VALUE_ZERO } from './constants';\nimport { Bundler } from './helpers/Bundler';\nimport { PendingUserOperationTracker } from './helpers/PendingUserOperationTracker';\nimport { SnapSmartContractAccount } from './helpers/SnapSmartContractAccount';\nimport { projectLogger as log } from './logger';\nimport type {\n SmartContractAccount,\n UserOperation,\n UserOperationMetadata,\n} from './types';\nimport { UserOperationStatus } from './types';\nimport { updateGas } from './utils/gas';\nimport { updateGasFees } from './utils/gas-fees';\nimport { getTransactionMetadata } from './utils/transaction';\nimport {\n validateAddUserOperationOptions,\n validateAddUserOperationRequest,\n validatePrepareUserOperationResponse,\n validateSignUserOperationResponse,\n validateUpdateUserOperationResponse,\n} from './utils/validation';\n\nconst controllerName = 'UserOperationController';\n\nconst stateMetadata = {\n userOperations: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n};\n\nconst getDefaultState = () => ({\n userOperations: {},\n});\n\ntype Events = {\n 'transaction-updated': [metadata: TransactionMeta];\n 'user-operation-added': [metadata: UserOperationMetadata];\n 'user-operation-confirmed': [metadata: UserOperationMetadata];\n 'user-operation-failed': [metadata: UserOperationMetadata, error: Error];\n [key: `${string}:confirmed`]: [metadata: UserOperationMetadata];\n [key: `${string}:failed`]: [metadata: UserOperationMetadata, error: Error];\n};\n\nexport type UserOperationControllerEventEmitter = EventEmitter & {\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n on<T extends keyof Events>(\n eventName: T,\n listener: (...args: Events[T]) => void,\n ): UserOperationControllerEventEmitter;\n\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n once<T extends keyof Events>(\n eventName: T,\n listener: (...args: Events[T]) => void,\n ): UserOperationControllerEventEmitter;\n\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n emit<T extends keyof Events>(eventName: T, ...args: Events[T]): boolean;\n};\n\nexport type UserOperationControllerState = {\n userOperations: Record<string, UserOperationMetadata>;\n};\n\nexport type GetUserOperationState = ControllerGetStateAction<\n typeof controllerName,\n UserOperationControllerState\n>;\n\nexport type UserOperationStateChange = ControllerStateChangeEvent<\n typeof controllerName,\n UserOperationControllerState\n>;\n\nexport type UserOperationControllerActions =\n | GetUserOperationState\n | NetworkControllerGetNetworkClientByIdAction\n | AddApprovalRequest\n | KeyringControllerPrepareUserOperationAction\n | KeyringControllerPatchUserOperationAction\n | KeyringControllerSignUserOperationAction;\n\nexport type UserOperationControllerEvents = UserOperationStateChange;\n\nexport type UserOperationControllerMessenger = Messenger<\n typeof controllerName,\n UserOperationControllerActions,\n UserOperationControllerEvents\n>;\n\nexport type UserOperationControllerOptions = {\n entrypoint: string;\n getGasFeeEstimates: () => Promise<GasFeeState>;\n interval?: number;\n messenger: UserOperationControllerMessenger;\n state?: Partial<UserOperationControllerState>;\n};\n\nexport type AddUserOperationRequest = {\n data?: string;\n from: string;\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n to?: string;\n value?: string;\n};\n\nexport type AddUserOperationSwapOptions = {\n approvalTxId?: string;\n destinationTokenAddress?: string;\n destinationTokenAmount?: string;\n destinationTokenDecimals?: number;\n destinationTokenSymbol?: string;\n estimatedBaseFee?: string;\n sourceTokenAddress?: string;\n sourceTokenAmount?: string;\n sourceTokenDecimals?: number;\n sourceTokenSymbol?: string;\n swapAndSendRecipient?: string;\n swapMetaData?: Record<string, unknown>;\n swapTokenValue?: string;\n};\n\nexport type AddUserOperationOptions = {\n networkClientId: string;\n origin: string;\n requireApproval?: boolean;\n smartContractAccount?: SmartContractAccount;\n swaps?: AddUserOperationSwapOptions;\n type?: TransactionType;\n};\n\nexport type AddUserOperationResponse = {\n id: string;\n hash: () => Promise<string | undefined>;\n transactionHash: () => Promise<string | undefined>;\n};\n\n/**\n * All the objects related to a pending user operation in order to:\n * - Avoid duplicated effort to derive the same properties.\n * - Minimise duplicate arguments in private methods.\n */\ntype UserOperationCache = {\n chainId: string;\n metadata: UserOperationMetadata;\n options: AddUserOperationOptions & {\n smartContractAccount: SmartContractAccount;\n };\n provider: Provider;\n request: AddUserOperationRequest;\n transaction?: TransactionParams;\n};\n\n/**\n * Controller for creating and managing the life cycle of user operations.\n */\nexport class UserOperationController extends BaseController<\n typeof controllerName,\n UserOperationControllerState,\n UserOperationControllerMessenger\n> {\n hub: UserOperationControllerEventEmitter;\n\n #entrypoint: string;\n\n #getGasFeeEstimates: () => Promise<GasFeeState>;\n\n #pendingUserOperationTracker: PendingUserOperationTracker;\n\n /**\n * Construct a UserOperationController instance.\n *\n * @param options - Controller options.\n * @param options.entrypoint - Address of the entrypoint contract.\n * @param options.getGasFeeEstimates - Callback to get gas fee estimates.\n * @param options.messenger - Restricted messenger for the user operation controller.\n * @param options.state - Initial state to set on the controller.\n */\n constructor({\n entrypoint,\n getGasFeeEstimates,\n messenger,\n state,\n }: UserOperationControllerOptions) {\n super({\n name: controllerName,\n metadata: stateMetadata,\n messenger,\n state: { ...getDefaultState(), ...state },\n });\n\n this.hub = new EventEmitter() as UserOperationControllerEventEmitter;\n\n this.#entrypoint = entrypoint;\n this.#getGasFeeEstimates = getGasFeeEstimates;\n\n this.#pendingUserOperationTracker = new PendingUserOperationTracker({\n getUserOperations: () =>\n cloneDeep(Object.values(this.state.userOperations)),\n messenger,\n });\n\n this.#addPendingUserOperationTrackerListeners();\n }\n\n /**\n * Create and submit a user operation.\n *\n * @param request - Information required to create a user operation.\n * @param request.data - Data to include in the resulting transaction.\n * @param request.maxFeePerGas - Maximum fee per gas to pay towards the transaction.\n * @param request.maxPriorityFeePerGas - Maximum priority fee per gas to pay towards the transaction.\n * @param request.to - Destination address of the resulting transaction.\n * @param request.value - Value to include in the resulting transaction.\n * @param options - Configuration options when creating a user operation.\n * @param options.networkClientId - ID of the network client used to query the chain.\n * @param options.origin - Origin of the user operation, such as the hostname of a dApp.\n * @param options.requireApproval - Whether to require user approval before submitting the user operation. Defaults to true.\n * @param options.smartContractAccount - Smart contract abstraction to provide the contract specific values such as call data and nonce. Defaults to the current snap account.\n * @param options.swaps - Swap metadata to record with the user operation.\n * @param options.type - Type of the transaction.\n */\n async addUserOperation(\n request: AddUserOperationRequest,\n options: AddUserOperationOptions,\n ): Promise<AddUserOperationResponse> {\n validateAddUserOperationRequest(request);\n validateAddUserOperationOptions(options);\n\n return await this.#addUserOperation(request, options);\n }\n\n /**\n * Create and submit a user operation equivalent to the provided transaction.\n *\n * @param transaction - Transaction to use as the basis for the user operation.\n * @param options - Configuration options when creating a user operation.\n * @param options.networkClientId - ID of the network client used to query the chain.\n * @param options.origin - Origin of the user operation, such as the hostname of a dApp.\n * @param options.requireApproval - Whether to require user approval before submitting the user operation. Defaults to true.\n * @param options.smartContractAccount - Smart contract abstraction to provide the contract specific values such as call data and nonce. Defaults to the current snap account.\n * @param options.swaps - Swap metadata to record with the user operation.\n * @param options.type - Type of the transaction.\n */\n async addUserOperationFromTransaction(\n transaction: TransactionParams,\n options: AddUserOperationOptions,\n ): Promise<AddUserOperationResponse> {\n validateAddUserOperationOptions(options);\n\n const { data, from, maxFeePerGas, maxPriorityFeePerGas, to, value } =\n transaction;\n\n const request: AddUserOperationRequest = {\n data: data === '' ? undefined : data,\n from,\n maxFeePerGas,\n maxPriorityFeePerGas,\n to,\n value,\n };\n\n validateAddUserOperationRequest(request);\n\n return await this.#addUserOperation(request, { ...options, transaction });\n }\n\n startPollingByNetworkClientId(networkClientId: string): string {\n return this.#pendingUserOperationTracker.startPolling({\n networkClientId,\n });\n }\n\n async #addUserOperation(\n request: AddUserOperationRequest,\n options: AddUserOperationOptions & { transaction?: TransactionParams },\n ): Promise<AddUserOperationResponse> {\n log('Adding user operation', { request, options });\n\n const {\n networkClientId,\n origin,\n smartContractAccount: requestSmartContractAccount,\n swaps,\n transaction,\n } = options;\n\n const { chainId, provider } = await this.#getProvider(networkClientId);\n\n const metadata = await this.#createMetadata(\n chainId,\n origin,\n transaction,\n swaps,\n );\n\n const smartContractAccount =\n requestSmartContractAccount ??\n new SnapSmartContractAccount(this.messenger);\n\n const cache: UserOperationCache = {\n chainId,\n metadata,\n options: { ...options, smartContractAccount },\n provider,\n request,\n transaction,\n };\n\n const { id } = metadata;\n let throwError = false;\n\n const hashValue = (async () => {\n try {\n return await this.#prepareAndSubmitUserOperation(cache);\n } catch (error) {\n this.#failUserOperation(metadata, error);\n\n if (throwError) {\n throw error;\n }\n\n return undefined;\n }\n })();\n\n const hash = async () => {\n throwError = true;\n return await hashValue;\n };\n\n const transactionHash = async () => {\n await hash();\n\n const { transactionHash: finalTransactionHash } =\n await this.#waitForConfirmation(metadata);\n\n return finalTransactionHash as string;\n };\n\n return {\n id,\n hash,\n transactionHash,\n };\n }\n\n async #prepareAndSubmitUserOperation(cache: UserOperationCache) {\n const { metadata, options } = cache;\n const { requireApproval, smartContractAccount } = options;\n let resultCallbacks: AcceptResultCallbacks | undefined;\n\n try {\n await this.#prepareUserOperation(cache);\n await this.#addPaymasterData(metadata, smartContractAccount);\n\n this.hub.emit('user-operation-added', metadata);\n\n if (requireApproval !== false) {\n resultCallbacks = await this.#approveUserOperation(cache);\n }\n\n await this.#signUserOperation(metadata, smartContractAccount);\n await this.#submitUserOperation(metadata);\n\n resultCallbacks?.success();\n\n return metadata.hash as string;\n } catch (error) {\n /* istanbul ignore next */\n resultCallbacks?.error(error as Error);\n throw error;\n }\n }\n\n async #waitForConfirmation(\n metadata: UserOperationMetadata,\n ): Promise<UserOperationMetadata> {\n const { id, hash } = metadata;\n\n log('Waiting for confirmation', id, hash);\n\n return new Promise((resolve, reject) => {\n this.hub.once(`${id}:confirmed`, (finalMetadata) => {\n resolve(finalMetadata);\n });\n\n this.hub.once(`${id}:failed`, (_finalMetadata, error) => {\n reject(error);\n });\n });\n }\n\n async #createMetadata(\n chainId: string,\n origin: string,\n transaction?: TransactionParams,\n swaps?: AddUserOperationSwapOptions,\n ): Promise<UserOperationMetadata> {\n const metadata: UserOperationMetadata = {\n actualGasCost: null,\n actualGasUsed: null,\n baseFeePerGas: null,\n bundlerUrl: null,\n chainId,\n error: null,\n hash: null,\n id: random(),\n origin,\n status: UserOperationStatus.Unapproved,\n swapsMetadata: swaps\n ? {\n approvalTxId: swaps.approvalTxId ?? null,\n destinationTokenAddress: swaps.destinationTokenAddress ?? null,\n destinationTokenAmount: swaps.destinationTokenAmount ?? null,\n destinationTokenDecimals: swaps.destinationTokenDecimals ?? null,\n destinationTokenSymbol: swaps.destinationTokenSymbol ?? null,\n estimatedBaseFee: swaps.estimatedBaseFee ?? null,\n sourceTokenAddress: swaps.sourceTokenAddress ?? null,\n sourceTokenAmount: swaps.sourceTokenAmount ?? null,\n sourceTokenDecimals: swaps.sourceTokenDecimals ?? null,\n sourceTokenSymbol: swaps.sourceTokenSymbol ?? null,\n swapAndSendRecipient: swaps.swapAndSendRecipient ?? null,\n swapMetaData: (swaps.swapMetaData as Record<string, never>) ?? null,\n swapTokenValue: swaps.swapTokenValue ?? null,\n }\n : null,\n time: Date.now(),\n transactionHash: null,\n transactionParams: (transaction as Required<TransactionParams>) ?? null,\n transactionType: null,\n userFeeLevel: null,\n userOperation: this.#createEmptyUserOperation(transaction),\n };\n\n this.#updateMetadata(metadata);\n\n log('Added user operation', metadata.id);\n\n return metadata;\n }\n\n async #prepareUserOperation(cache: UserOperationCache) {\n const { chainId, metadata, options, provider, request, transaction } =\n cache;\n\n const { data, from, to, value } = request;\n const { id, transactionParams, userOperation } = metadata;\n const { smartContractAccount } = options;\n\n log('Preparing user operation', { id });\n\n const transactionType = await this.#getTransactionType(\n transaction,\n provider,\n options,\n );\n\n metadata.transactionType = transactionType ?? null;\n\n log('Determined transaction type', transactionType);\n\n await updateGasFees({\n getGasFeeEstimates: this.#getGasFeeEstimates,\n metadata,\n originalRequest: request,\n provider,\n transaction: transactionParams ?? undefined,\n });\n\n const response = await smartContractAccount.prepareUserOperation({\n chainId,\n data,\n from,\n to,\n value,\n });\n\n validatePrepareUserOperationResponse(response);\n\n const {\n bundler: bundlerUrl,\n callData,\n dummyPaymasterAndData,\n dummySignature,\n initCode,\n nonce,\n sender,\n } = response;\n\n userOperation.callData = callData;\n userOperation.initCode = initCode ?? EMPTY_BYTES;\n userOperation.nonce = nonce;\n userOperation.paymasterAndData = dummyPaymasterAndData ?? EMPTY_BYTES;\n userOperation.sender = sender;\n userOperation.signature = dummySignature ?? EMPTY_BYTES;\n\n metadata.bundlerUrl = bundlerUrl;\n\n await updateGas(metadata, response, this.#entrypoint);\n\n this.#updateMetadata(metadata);\n }\n\n async #addPaymasterData(\n metadata: UserOperationMetadata,\n smartContractAccount: SmartContractAccount,\n ) {\n const { id, userOperation, chainId } = metadata;\n\n log('Requesting paymaster data', { id });\n\n const response = await smartContractAccount.updateUserOperation({\n userOperation,\n chainId,\n });\n\n validateUpdateUserOperationResponse(response);\n\n userOperation.paymasterAndData = response.paymasterAndData ?? EMPTY_BYTES;\n if (response.callGasLimit) {\n userOperation.callGasLimit = response.callGasLimit;\n }\n if (response.preVerificationGas) {\n userOperation.preVerificationGas = response.preVerificationGas;\n }\n if (response.verificationGasLimit) {\n userOperation.verificationGasLimit = response.verificationGasLimit;\n }\n\n this.#updateMetadata(metadata);\n }\n\n async #approveUserOperation(cache: UserOperationCache) {\n log('Requesting approval');\n\n const { metadata } = cache;\n\n const { resultCallbacks, value } = await this.#requestApproval(metadata);\n const updatedTransaction = value?.txMeta;\n\n if (updatedTransaction) {\n await this.#updateUserOperationAfterApproval(cache, updatedTransaction);\n }\n\n metadata.status = UserOperationStatus.Approved;\n\n this.#updateMetadata(metadata);\n\n return resultCallbacks;\n }\n\n async #signUserOperation(\n metadata: UserOperationMetadata,\n smartContractAccount: SmartContractAccount,\n ) {\n const { id, chainId, userOperation } = metadata;\n\n log('Signing user operation', id, userOperation);\n\n const response = await smartContractAccount.signUserOperation({\n userOperation,\n chainId,\n });\n\n validateSignUserOperationResponse(response);\n\n const { signature } = response;\n\n userOperation.signature = signature;\n\n log('Signed user operation', signature);\n\n metadata.status = UserOperationStatus.Signed;\n\n this.#updateMetadata(metadata);\n }\n\n async #submitUserOperation(metadata: UserOperationMetadata) {\n const { userOperation } = metadata;\n\n log('Submitting user operation', userOperation);\n\n const bundler = new Bundler(metadata.bundlerUrl as string);\n\n const hash = await bundler.sendUserOperation(\n userOperation,\n this.#entrypoint,\n );\n\n metadata.hash = hash;\n metadata.status = UserOperationStatus.Submitted;\n\n this.#updateMetadata(metadata);\n }\n\n #failUserOperation(metadata: UserOperationMetadata, error: unknown) {\n const { id } = metadata;\n const rawError = error as Record<string, string>;\n\n log('User operation failed', id, error);\n\n metadata.error = {\n name: rawError.name,\n message: rawError.message,\n stack: rawError.stack,\n code: rawError.code,\n rpc: rawError.value,\n };\n\n metadata.status = UserOperationStatus.Failed;\n\n this.#updateMetadata(metadata);\n\n if (\n String(rawError.code) === String(errorCodes.provider.userRejectedRequest)\n ) {\n this.#deleteMetadata(id);\n }\n }\n\n #createEmptyUserOperation(transaction?: TransactionParams): UserOperation {\n return {\n callData: EMPTY_BYTES,\n callGasLimit: EMPTY_BYTES,\n initCode: EMPTY_BYTES,\n maxFeePerGas: transaction?.maxFeePerGas ?? EMPTY_BYTES,\n maxPriorityFeePerGas: transaction?.maxPriorityFeePerGas ?? EMPTY_BYTES,\n nonce: EMPTY_BYTES,\n paymasterAndData: EMPTY_BYTES,\n preVerificationGas: EMPTY_BYTES,\n sender: ADDRESS_ZERO,\n signature: EMPTY_BYTES,\n verificationGasLimit: EMPTY_BYTES,\n };\n }\n\n #updateMetadata(metadata: UserOperationMetadata) {\n const { id } = metadata;\n\n this.update((state) => {\n state.userOperations[id] = cloneDeep(metadata);\n });\n\n this.#updateTransaction(metadata);\n }\n\n #deleteMetadata(id: string) {\n this.update((state) => {\n delete state.userOperations[id];\n });\n }\n\n #updateTransaction(metadata: UserOperationMetadata) {\n if (!metadata.transactionParams) {\n return;\n }\n\n const transactionMetadata = getTransactionMetadata(metadata);\n\n this.hub.emit('transaction-updated', transactionMetadata);\n }\n\n #addPendingUserOperationTrackerListeners() {\n this.#pendingUserOperationTracker.hub.on(\n 'user-operation-confirmed',\n (metadata) => {\n log('In listener...');\n this.hub.emit('user-operation-confirmed', metadata);\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n this.hub.emit(`${metadata.id}:confirmed`, metadata);\n },\n );\n\n this.#pendingUserOperationTracker.hub.on(\n 'user-operation-failed',\n (metadata, error) => {\n this.hub.emit('user-operation-failed', metadata, error);\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n this.hub.emit(`${metadata.id}:failed`, metadata, error);\n },\n );\n\n this.#pendingUserOperationTracker.hub.on(\n 'user-operation-updated',\n (metadata) => {\n this.#updateMetadata(metadata);\n },\n );\n }\n\n async #requestApproval(metadata: UserOperationMetadata) {\n const { id, origin } = metadata;\n const type = ApprovalType.Transaction;\n const requestData = { txId: id };\n\n return (await this.messenger.call(\n 'ApprovalController:addRequest',\n {\n id,\n origin,\n type,\n requestData,\n expectsResult: true,\n },\n true, // Should display approval request to user\n )) as AddResult & { value?: { txMeta?: TransactionMeta } };\n }\n\n async #getTransactionType(\n transaction: TransactionParams | undefined,\n provider: Provider,\n options: AddUserOperationOptions,\n ): Promise<TransactionType | undefined> {\n if (!transaction) {\n return undefined;\n }\n\n if (options.type) {\n return options.type;\n }\n\n const ethQuery = new EthQuery(provider);\n const result = determineTransactionType(transaction, ethQuery);\n\n return (await result).type;\n }\n\n async #getProvider(\n networkClientId: string,\n ): Promise<{ provider: Provider; chainId: string }> {\n const { provider, configuration } = this.messenger.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n\n const { chainId } = configuration;\n\n return { provider, chainId };\n }\n\n async #updateUserOperationAfterApproval(\n cache: UserOperationCache,\n updatedTransaction: TransactionMeta,\n ) {\n log('Found updated transaction in approval', { updatedTransaction });\n\n const { metadata, request } = cache;\n\n const { userOperation } = metadata;\n const usingPaymaster = userOperation.paymasterAndData !== EMPTY_BYTES;\n\n const updatedMaxFeePerGas = add0x(\n updatedTransaction.txParams.maxFeePerGas as string,\n );\n\n const updatedMaxPriorityFeePerGas = add0x(\n updatedTransaction.txParams.maxPriorityFeePerGas as string,\n );\n\n let regenerateUserOperation = false;\n const previousMaxFeePerGas = userOperation.maxFeePerGas;\n const previousMaxPriorityFeePerGas = userOperation.maxPriorityFeePerGas;\n\n const gasFeesUpdated =\n previousMaxFeePerGas !== updatedMaxFeePerGas ||\n previousMaxPriorityFeePerGas !== updatedMaxPriorityFeePerGas;\n\n /**\n * true when we detect {@link getTransactionMetadata} has set the gas fees to zero\n * because the userOperation has a paymaster. This should not be mistaken for gas\n * fees being updated during the approval process.\n */\n const areGasFeesZeroBecauseOfPaymaster =\n usingPaymaster &&\n updatedMaxFeePerGas === VALUE_ZERO &&\n updatedMaxPriorityFeePerGas === VALUE_ZERO;\n\n if (gasFeesUpdated && !areGasFeesZeroBecauseOfPaymaster) {\n log('Gas fees updated during approval', {\n previousMaxFeePerGas,\n previousMaxPriorityFeePerGas,\n updatedMaxFeePerGas,\n updatedMaxPriorityFeePerGas,\n });\n\n userOperation.maxFeePerGas = updatedMaxFeePerGas;\n userOperation.maxPriorityFeePerGas = updatedMaxPriorityFeePerGas;\n\n regenerateUserOperation = usingPaymaster;\n }\n\n const previousData = request.data ?? EMPTY_BYTES;\n const updatedData = updatedTransaction.txParams.data ?? EMPTY_BYTES;\n\n if (previousData !== updatedData) {\n log('Data updated during approval', { previousData, updatedData });\n regenerateUserOperation = true;\n }\n\n const previousValue = request.value ?? VALUE_ZERO;\n const updatedValue = updatedTransaction.txParams.value ?? VALUE_ZERO;\n\n if (previousValue !== updatedValue) {\n log('Value updated during approval', { previousValue, updatedValue });\n regenerateUserOperation = true;\n }\n\n if (regenerateUserOperation) {\n const updatedRequest = {\n ...request,\n data: updatedData,\n maxFeePerGas: updatedMaxFeePerGas,\n maxPriorityFeePerGas: updatedMaxPriorityFeePerGas,\n value: updatedValue,\n };\n\n await this.#regenerateUserOperation({\n ...cache,\n request: updatedRequest,\n });\n }\n }\n\n async #regenerateUserOperation(cache: UserOperationCache) {\n log(\n 'Regenerating user operation as parameters were updated during approval',\n );\n\n const {\n options: { smartContractAccount },\n metadata,\n } = cache;\n\n await this.#prepareUserOperation(cache);\n await this.#addPaymasterData(metadata, smartContractAccount);\n\n log('Regenerated user operation', metadata.userOperation);\n }\n}\n"]}
@@ -18,7 +18,7 @@ type PendingUserOperationPollingInput = {
18
18
  networkClientId: NetworkClientId;
19
19
  };
20
20
  declare const PendingUserOperationTracker_base: (abstract new (...args: any[]) => {
21
- "__#13@#activeListeners": Record<string, (options: import("@metamask/utils").Json) => Promise<void>>;
21
+ "__#12@#activeListeners": Record<string, (options: import("@metamask/utils").Json) => Promise<void>>;
22
22
  _getNetworkClientById(networkClientId: string): NetworkClient | undefined;
23
23
  _startPolling(input: PendingUserOperationPollingInput): void;
24
24
  _stopPollingByPollingTokenSetId(key: string): void;
@@ -18,7 +18,7 @@ type PendingUserOperationPollingInput = {
18
18
  networkClientId: NetworkClientId;
19
19
  };
20
20
  declare const PendingUserOperationTracker_base: (abstract new (...args: any[]) => {
21
- "__#13@#activeListeners": Record<string, (options: import("@metamask/utils").Json) => Promise<void>>;
21
+ "__#12@#activeListeners": Record<string, (options: import("@metamask/utils").Json) => Promise<void>>;
22
22
  _getNetworkClientById(networkClientId: string): NetworkClient | undefined;
23
23
  _startPolling(input: PendingUserOperationPollingInput): void;
24
24
  _stopPollingByPollingTokenSetId(key: string): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/user-operation-controller",
3
- "version": "39.2.0-preview-cd26f001",
3
+ "version": "39.2.0-preview-e9856975",
4
4
  "description": "Creates user operations and manages their life cycle",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -51,6 +51,7 @@
51
51
  "@metamask/base-controller": "^8.4.1",
52
52
  "@metamask/controller-utils": "^11.14.1",
53
53
  "@metamask/eth-query": "^4.0.0",
54
+ "@metamask/messenger": "^0.3.0",
54
55
  "@metamask/polling-controller": "^14.0.1",
55
56
  "@metamask/rpc-errors": "^7.0.2",
56
57
  "@metamask/superstruct": "^3.1.0",