@metamask-previews/user-operation-controller 41.2.9-preview-4f4c98e → 41.2.9-preview-eb263b0ee
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 +0 -4
- package/dist/BlockTrackerPollingController.cjs +68 -0
- package/dist/BlockTrackerPollingController.cjs.map +1 -0
- package/dist/{BlockTrackerPollingController.d.ts → BlockTrackerPollingController.d.cts} +11 -11
- package/dist/BlockTrackerPollingController.d.cts.map +1 -0
- package/dist/BlockTrackerPollingController.d.mts +41 -0
- package/dist/BlockTrackerPollingController.d.mts.map +1 -0
- package/dist/{BlockTrackerPollingController.js → BlockTrackerPollingController.mjs} +16 -17
- package/dist/BlockTrackerPollingController.mjs.map +1 -0
- package/dist/UserOperationController-method-action-types.cjs +7 -0
- package/dist/UserOperationController-method-action-types.cjs.map +1 -0
- package/dist/{UserOperationController-method-action-types.d.ts → UserOperationController-method-action-types.d.cts} +2 -2
- package/dist/UserOperationController-method-action-types.d.cts.map +1 -0
- package/dist/UserOperationController-method-action-types.d.mts +57 -0
- package/dist/UserOperationController-method-action-types.d.mts.map +1 -0
- package/dist/{UserOperationController-method-action-types.js → UserOperationController-method-action-types.mjs} +1 -1
- package/dist/UserOperationController-method-action-types.mjs.map +1 -0
- package/dist/UserOperationController.cjs +495 -0
- package/dist/UserOperationController.cjs.map +1 -0
- package/dist/{UserOperationController.d.ts → UserOperationController.d.cts} +15 -13
- package/dist/UserOperationController.d.cts.map +1 -0
- package/dist/UserOperationController.d.mts +136 -0
- package/dist/UserOperationController.d.mts.map +1 -0
- package/dist/{UserOperationController.js → UserOperationController.mjs} +20 -19
- package/dist/UserOperationController.mjs.map +1 -0
- package/dist/constants.cjs +7 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/{constants.d.ts → constants.d.cts} +1 -1
- package/dist/constants.d.cts.map +1 -0
- package/dist/constants.d.mts +4 -0
- package/dist/constants.d.mts.map +1 -0
- package/dist/{constants.js → constants.mjs} +1 -1
- package/dist/constants.mjs.map +1 -0
- package/dist/helpers/Bundler.cjs +91 -0
- package/dist/helpers/Bundler.cjs.map +1 -0
- package/dist/helpers/{Bundler.d.ts → Bundler.d.cts} +2 -2
- package/dist/helpers/Bundler.d.cts.map +1 -0
- package/dist/helpers/Bundler.d.mts +46 -0
- package/dist/helpers/Bundler.d.mts.map +1 -0
- package/dist/helpers/{Bundler.js → Bundler.mjs} +2 -2
- package/dist/helpers/Bundler.mjs.map +1 -0
- package/dist/helpers/PendingUserOperationTracker.cjs +127 -0
- package/dist/helpers/PendingUserOperationTracker.cjs.map +1 -0
- package/dist/helpers/{PendingUserOperationTracker.d.ts → PendingUserOperationTracker.d.cts} +12 -10
- package/dist/helpers/PendingUserOperationTracker.d.cts.map +1 -0
- package/dist/helpers/PendingUserOperationTracker.d.mts +51 -0
- package/dist/helpers/PendingUserOperationTracker.d.mts.map +1 -0
- package/dist/helpers/{PendingUserOperationTracker.js → PendingUserOperationTracker.mjs} +16 -9
- package/dist/helpers/PendingUserOperationTracker.mjs.map +1 -0
- package/dist/helpers/SnapSmartContractAccount.cjs +64 -0
- package/dist/helpers/SnapSmartContractAccount.cjs.map +1 -0
- package/dist/helpers/{SnapSmartContractAccount.d.ts → SnapSmartContractAccount.d.cts} +3 -3
- package/dist/helpers/SnapSmartContractAccount.d.cts.map +1 -0
- package/dist/helpers/SnapSmartContractAccount.d.mts +10 -0
- package/dist/helpers/SnapSmartContractAccount.d.mts.map +1 -0
- package/dist/helpers/{SnapSmartContractAccount.js → SnapSmartContractAccount.mjs} +3 -3
- package/dist/helpers/SnapSmartContractAccount.mjs.map +1 -0
- package/dist/index.cjs +19 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +3 -0
- package/dist/index.mjs.map +1 -0
- package/dist/logger.cjs +8 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +5 -0
- package/dist/logger.d.cts.map +1 -0
- package/dist/logger.d.mts +5 -0
- package/dist/logger.d.mts.map +1 -0
- package/dist/{logger.js → logger.mjs} +2 -2
- package/dist/logger.mjs.map +1 -0
- package/dist/types.cjs +16 -0
- package/dist/types.cjs.map +1 -0
- package/dist/{types.d.ts → types.d.cts} +3 -3
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +294 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/{types.js → types.mjs} +1 -1
- package/dist/types.mjs.map +1 -0
- package/dist/utils/chain-id.cjs +17 -0
- package/dist/utils/chain-id.cjs.map +1 -0
- package/dist/utils/{chain-id.d.ts → chain-id.d.cts} +1 -1
- package/dist/utils/chain-id.d.cts.map +1 -0
- package/dist/utils/chain-id.d.mts +8 -0
- package/dist/utils/chain-id.d.mts.map +1 -0
- package/dist/utils/{chain-id.js → chain-id.mjs} +1 -1
- package/dist/utils/chain-id.mjs.map +1 -0
- package/dist/utils/gas-fees.cjs +194 -0
- package/dist/utils/gas-fees.cjs.map +1 -0
- package/dist/utils/{gas-fees.d.ts → gas-fees.d.cts} +6 -6
- package/dist/utils/gas-fees.d.cts.map +1 -0
- package/dist/utils/gas-fees.d.mts +24 -0
- package/dist/utils/gas-fees.d.mts.map +1 -0
- package/dist/utils/{gas-fees.js → gas-fees.mjs} +15 -8
- package/dist/utils/gas-fees.mjs.map +1 -0
- package/dist/utils/gas.cjs +72 -0
- package/dist/utils/gas.cjs.map +1 -0
- package/dist/utils/{gas.d.ts → gas.d.cts} +2 -2
- package/dist/utils/gas.d.cts.map +1 -0
- package/dist/utils/gas.d.mts +10 -0
- package/dist/utils/gas.d.mts.map +1 -0
- package/dist/utils/{gas.js → gas.mjs} +14 -7
- package/dist/utils/gas.mjs.map +1 -0
- package/dist/utils/transaction.cjs +117 -0
- package/dist/utils/transaction.cjs.map +1 -0
- package/dist/utils/{transaction.d.ts → transaction.d.cts} +3 -3
- package/dist/utils/transaction.d.cts.map +1 -0
- package/dist/utils/transaction.d.mts +10 -0
- package/dist/utils/transaction.d.mts.map +1 -0
- package/dist/utils/{transaction.js → transaction.mjs} +13 -6
- package/dist/utils/transaction.mjs.map +1 -0
- package/dist/utils/validation.cjs +162 -0
- package/dist/utils/validation.cjs.map +1 -0
- package/dist/utils/{validation.d.ts → validation.d.cts} +3 -3
- package/dist/utils/validation.d.cts.map +1 -0
- package/dist/utils/validation.d.mts +33 -0
- package/dist/utils/validation.d.mts.map +1 -0
- package/dist/utils/{validation.js → validation.mjs} +5 -5
- package/dist/utils/validation.mjs.map +1 -0
- package/package.json +17 -13
- package/dist/BlockTrackerPollingController.d.ts.map +0 -1
- package/dist/BlockTrackerPollingController.js.map +0 -1
- package/dist/UserOperationController-method-action-types.d.ts.map +0 -1
- package/dist/UserOperationController-method-action-types.js.map +0 -1
- package/dist/UserOperationController.d.ts.map +0 -1
- package/dist/UserOperationController.js.map +0 -1
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js.map +0 -1
- package/dist/helpers/Bundler.d.ts.map +0 -1
- package/dist/helpers/Bundler.js.map +0 -1
- package/dist/helpers/PendingUserOperationTracker.d.ts.map +0 -1
- package/dist/helpers/PendingUserOperationTracker.js.map +0 -1
- package/dist/helpers/SnapSmartContractAccount.d.ts.map +0 -1
- package/dist/helpers/SnapSmartContractAccount.js.map +0 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -3
- package/dist/index.js.map +0 -1
- package/dist/logger.d.ts +0 -4
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils/chain-id.d.ts.map +0 -1
- package/dist/utils/chain-id.js.map +0 -1
- package/dist/utils/gas-fees.d.ts.map +0 -1
- package/dist/utils/gas-fees.js.map +0 -1
- package/dist/utils/gas.d.ts.map +0 -1
- package/dist/utils/gas.js.map +0 -1
- package/dist/utils/transaction.d.ts.map +0 -1
- package/dist/utils/transaction.js.map +0 -1
- package/dist/utils/validation.d.ts.map +0 -1
- package/dist/utils/validation.js.map +0 -1
|
@@ -0,0 +1,495 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.UserOperationController = void 0;
|
|
19
|
+
const base_controller_1 = require("@metamask/base-controller");
|
|
20
|
+
const controller_utils_1 = require("@metamask/controller-utils");
|
|
21
|
+
const rpc_errors_1 = require("@metamask/rpc-errors");
|
|
22
|
+
const transaction_controller_1 = require("@metamask/transaction-controller");
|
|
23
|
+
const utils_1 = require("@metamask/utils");
|
|
24
|
+
// This package purposefully relies on Node's EventEmitter module.
|
|
25
|
+
// eslint-disable-next-line import-x/no-nodejs-modules
|
|
26
|
+
const events_1 = __importDefault(require("events"));
|
|
27
|
+
const lodash_1 = require("lodash");
|
|
28
|
+
const uuid_1 = require("uuid");
|
|
29
|
+
const constants_js_1 = require("./constants.cjs");
|
|
30
|
+
const Bundler_js_1 = require("./helpers/Bundler.cjs");
|
|
31
|
+
const PendingUserOperationTracker_js_1 = require("./helpers/PendingUserOperationTracker.cjs");
|
|
32
|
+
const SnapSmartContractAccount_js_1 = require("./helpers/SnapSmartContractAccount.cjs");
|
|
33
|
+
const logger_js_1 = require("./logger.cjs");
|
|
34
|
+
const types_js_1 = require("./types.cjs");
|
|
35
|
+
const gas_fees_js_1 = require("./utils/gas-fees.cjs");
|
|
36
|
+
const gas_js_1 = require("./utils/gas.cjs");
|
|
37
|
+
const transaction_js_1 = require("./utils/transaction.cjs");
|
|
38
|
+
const validation_js_1 = require("./utils/validation.cjs");
|
|
39
|
+
const controllerName = 'UserOperationController';
|
|
40
|
+
const MESSENGER_EXPOSED_METHODS = [
|
|
41
|
+
'addUserOperation',
|
|
42
|
+
'addUserOperationFromTransaction',
|
|
43
|
+
'startPollingByNetworkClientId',
|
|
44
|
+
];
|
|
45
|
+
const stateMetadata = {
|
|
46
|
+
userOperations: {
|
|
47
|
+
includeInStateLogs: true,
|
|
48
|
+
persist: true,
|
|
49
|
+
includeInDebugSnapshot: false,
|
|
50
|
+
usedInUi: true,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
const getDefaultState = () => ({
|
|
54
|
+
userOperations: {},
|
|
55
|
+
});
|
|
56
|
+
/**
|
|
57
|
+
* Controller for creating and managing the life cycle of user operations.
|
|
58
|
+
*/
|
|
59
|
+
class UserOperationController extends base_controller_1.BaseController {
|
|
60
|
+
/**
|
|
61
|
+
* Construct a UserOperationController instance.
|
|
62
|
+
*
|
|
63
|
+
* @param options - Controller options.
|
|
64
|
+
* @param options.entrypoint - Address of the entrypoint contract.
|
|
65
|
+
* @param options.getGasFeeEstimates - Callback to get gas fee estimates.
|
|
66
|
+
* @param options.messenger - Restricted messenger for the user operation controller.
|
|
67
|
+
* @param options.state - Initial state to set on the controller.
|
|
68
|
+
*/
|
|
69
|
+
constructor({ entrypoint, getGasFeeEstimates, messenger, state, }) {
|
|
70
|
+
super({
|
|
71
|
+
name: controllerName,
|
|
72
|
+
metadata: stateMetadata,
|
|
73
|
+
messenger,
|
|
74
|
+
state: { ...getDefaultState(), ...state },
|
|
75
|
+
});
|
|
76
|
+
_UserOperationController_instances.add(this);
|
|
77
|
+
_UserOperationController_entrypoint.set(this, void 0);
|
|
78
|
+
_UserOperationController_getGasFeeEstimates.set(this, void 0);
|
|
79
|
+
_UserOperationController_pendingUserOperationTracker.set(this, void 0);
|
|
80
|
+
this.hub = new events_1.default();
|
|
81
|
+
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
82
|
+
__classPrivateFieldSet(this, _UserOperationController_entrypoint, entrypoint, "f");
|
|
83
|
+
__classPrivateFieldSet(this, _UserOperationController_getGasFeeEstimates, getGasFeeEstimates, "f");
|
|
84
|
+
__classPrivateFieldSet(this, _UserOperationController_pendingUserOperationTracker, new PendingUserOperationTracker_js_1.PendingUserOperationTracker({
|
|
85
|
+
getUserOperations: () => (0, lodash_1.cloneDeep)(Object.values(this.state.userOperations)),
|
|
86
|
+
messenger,
|
|
87
|
+
}), "f");
|
|
88
|
+
__classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_addPendingUserOperationTrackerListeners).call(this);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Create and submit a user operation.
|
|
92
|
+
*
|
|
93
|
+
* @param request - Information required to create a user operation.
|
|
94
|
+
* @param request.data - Data to include in the resulting transaction.
|
|
95
|
+
* @param request.maxFeePerGas - Maximum fee per gas to pay towards the transaction.
|
|
96
|
+
* @param request.maxPriorityFeePerGas - Maximum priority fee per gas to pay towards the transaction.
|
|
97
|
+
* @param request.to - Destination address of the resulting transaction.
|
|
98
|
+
* @param request.value - Value to include in the resulting transaction.
|
|
99
|
+
* @param options - Configuration options when creating a user operation.
|
|
100
|
+
* @param options.networkClientId - ID of the network client used to query the chain.
|
|
101
|
+
* @param options.origin - Origin of the user operation, such as the hostname of a dApp.
|
|
102
|
+
* @param options.requireApproval - Whether to require user approval before submitting the user operation. Defaults to true.
|
|
103
|
+
* @param options.smartContractAccount - Smart contract abstraction to provide the contract specific values such as call data and nonce. Defaults to the current snap account.
|
|
104
|
+
* @param options.swaps - Swap metadata to record with the user operation.
|
|
105
|
+
* @param options.type - Type of the transaction.
|
|
106
|
+
*/
|
|
107
|
+
async addUserOperation(request, options) {
|
|
108
|
+
(0, validation_js_1.validateAddUserOperationRequest)(request);
|
|
109
|
+
(0, validation_js_1.validateAddUserOperationOptions)(options);
|
|
110
|
+
return await __classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_addUserOperation).call(this, request, options);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Create and submit a user operation equivalent to the provided transaction.
|
|
114
|
+
*
|
|
115
|
+
* @param transaction - Transaction to use as the basis for the user operation.
|
|
116
|
+
* @param options - Configuration options when creating a user operation.
|
|
117
|
+
* @param options.networkClientId - ID of the network client used to query the chain.
|
|
118
|
+
* @param options.origin - Origin of the user operation, such as the hostname of a dApp.
|
|
119
|
+
* @param options.requireApproval - Whether to require user approval before submitting the user operation. Defaults to true.
|
|
120
|
+
* @param options.smartContractAccount - Smart contract abstraction to provide the contract specific values such as call data and nonce. Defaults to the current snap account.
|
|
121
|
+
* @param options.swaps - Swap metadata to record with the user operation.
|
|
122
|
+
* @param options.type - Type of the transaction.
|
|
123
|
+
*/
|
|
124
|
+
async addUserOperationFromTransaction(transaction, options) {
|
|
125
|
+
(0, validation_js_1.validateAddUserOperationOptions)(options);
|
|
126
|
+
const { data, from, maxFeePerGas, maxPriorityFeePerGas, to, value } = transaction;
|
|
127
|
+
const request = {
|
|
128
|
+
data: data === '' ? undefined : data,
|
|
129
|
+
from,
|
|
130
|
+
maxFeePerGas,
|
|
131
|
+
maxPriorityFeePerGas,
|
|
132
|
+
to,
|
|
133
|
+
value,
|
|
134
|
+
};
|
|
135
|
+
(0, validation_js_1.validateAddUserOperationRequest)(request);
|
|
136
|
+
return await __classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_addUserOperation).call(this, request, { ...options, transaction });
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Starts polling for pending user operations on the given network.
|
|
140
|
+
*
|
|
141
|
+
* @param networkClientId - The ID of the network client to poll.
|
|
142
|
+
* @returns The polling token that can be used to stop polling.
|
|
143
|
+
*/
|
|
144
|
+
startPollingByNetworkClientId(networkClientId) {
|
|
145
|
+
return __classPrivateFieldGet(this, _UserOperationController_pendingUserOperationTracker, "f").startPolling({
|
|
146
|
+
networkClientId,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
exports.UserOperationController = UserOperationController;
|
|
151
|
+
_UserOperationController_entrypoint = new WeakMap(), _UserOperationController_getGasFeeEstimates = new WeakMap(), _UserOperationController_pendingUserOperationTracker = new WeakMap(), _UserOperationController_instances = new WeakSet(), _UserOperationController_addUserOperation = async function _UserOperationController_addUserOperation(request, options) {
|
|
152
|
+
(0, logger_js_1.projectLogger)('Adding user operation', { request, options });
|
|
153
|
+
const { networkClientId, origin, smartContractAccount: requestSmartContractAccount, swaps, transaction, } = options;
|
|
154
|
+
const { chainId, provider } = await __classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_getProvider).call(this, networkClientId);
|
|
155
|
+
const metadata = await __classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_createMetadata).call(this, chainId, origin, transaction, swaps);
|
|
156
|
+
const smartContractAccount = requestSmartContractAccount ??
|
|
157
|
+
new SnapSmartContractAccount_js_1.SnapSmartContractAccount(this.messenger);
|
|
158
|
+
const cache = {
|
|
159
|
+
chainId,
|
|
160
|
+
metadata,
|
|
161
|
+
options: { ...options, smartContractAccount },
|
|
162
|
+
provider,
|
|
163
|
+
request,
|
|
164
|
+
transaction,
|
|
165
|
+
};
|
|
166
|
+
const { id } = metadata;
|
|
167
|
+
let throwError = false;
|
|
168
|
+
const hashValue = (async () => {
|
|
169
|
+
try {
|
|
170
|
+
return await __classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_prepareAndSubmitUserOperation).call(this, cache);
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
__classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_failUserOperation).call(this, metadata, error);
|
|
174
|
+
if (throwError) {
|
|
175
|
+
throw error;
|
|
176
|
+
}
|
|
177
|
+
return undefined;
|
|
178
|
+
}
|
|
179
|
+
})();
|
|
180
|
+
const hash = async () => {
|
|
181
|
+
throwError = true;
|
|
182
|
+
return await hashValue;
|
|
183
|
+
};
|
|
184
|
+
const transactionHash = async () => {
|
|
185
|
+
await hash();
|
|
186
|
+
const { transactionHash: finalTransactionHash } = await __classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_waitForConfirmation).call(this, metadata);
|
|
187
|
+
return finalTransactionHash;
|
|
188
|
+
};
|
|
189
|
+
return {
|
|
190
|
+
id,
|
|
191
|
+
hash,
|
|
192
|
+
transactionHash,
|
|
193
|
+
};
|
|
194
|
+
}, _UserOperationController_prepareAndSubmitUserOperation = async function _UserOperationController_prepareAndSubmitUserOperation(cache) {
|
|
195
|
+
const { metadata, options } = cache;
|
|
196
|
+
const { requireApproval, smartContractAccount } = options;
|
|
197
|
+
let resultCallbacks;
|
|
198
|
+
try {
|
|
199
|
+
await __classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_prepareUserOperation).call(this, cache);
|
|
200
|
+
await __classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_addPaymasterData).call(this, metadata, smartContractAccount);
|
|
201
|
+
this.hub.emit('user-operation-added', metadata);
|
|
202
|
+
if (requireApproval !== false) {
|
|
203
|
+
resultCallbacks = await __classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_approveUserOperation).call(this, cache);
|
|
204
|
+
}
|
|
205
|
+
await __classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_signUserOperation).call(this, metadata, smartContractAccount);
|
|
206
|
+
await __classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_submitUserOperation).call(this, metadata);
|
|
207
|
+
resultCallbacks?.success();
|
|
208
|
+
return metadata.hash;
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
/* istanbul ignore next */
|
|
212
|
+
resultCallbacks?.error(error);
|
|
213
|
+
throw error;
|
|
214
|
+
}
|
|
215
|
+
}, _UserOperationController_waitForConfirmation = async function _UserOperationController_waitForConfirmation(metadata) {
|
|
216
|
+
const { id, hash } = metadata;
|
|
217
|
+
(0, logger_js_1.projectLogger)('Waiting for confirmation', id, hash);
|
|
218
|
+
return new Promise((resolve, reject) => {
|
|
219
|
+
this.hub.once(`${id}:confirmed`, (finalMetadata) => {
|
|
220
|
+
resolve(finalMetadata);
|
|
221
|
+
});
|
|
222
|
+
this.hub.once(`${id}:failed`, (_finalMetadata, error) => {
|
|
223
|
+
reject(error);
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
}, _UserOperationController_createMetadata = async function _UserOperationController_createMetadata(chainId, origin, transaction, swaps) {
|
|
227
|
+
const metadata = {
|
|
228
|
+
actualGasCost: null,
|
|
229
|
+
actualGasUsed: null,
|
|
230
|
+
baseFeePerGas: null,
|
|
231
|
+
bundlerUrl: null,
|
|
232
|
+
chainId,
|
|
233
|
+
error: null,
|
|
234
|
+
hash: null,
|
|
235
|
+
id: (0, uuid_1.v1)(),
|
|
236
|
+
origin,
|
|
237
|
+
status: types_js_1.UserOperationStatus.Unapproved,
|
|
238
|
+
swapsMetadata: swaps
|
|
239
|
+
? {
|
|
240
|
+
approvalTxId: swaps.approvalTxId ?? null,
|
|
241
|
+
destinationTokenAddress: swaps.destinationTokenAddress ?? null,
|
|
242
|
+
destinationTokenAmount: swaps.destinationTokenAmount ?? null,
|
|
243
|
+
destinationTokenDecimals: swaps.destinationTokenDecimals ?? null,
|
|
244
|
+
destinationTokenSymbol: swaps.destinationTokenSymbol ?? null,
|
|
245
|
+
estimatedBaseFee: swaps.estimatedBaseFee ?? null,
|
|
246
|
+
sourceTokenAddress: swaps.sourceTokenAddress ?? null,
|
|
247
|
+
sourceTokenAmount: swaps.sourceTokenAmount ?? null,
|
|
248
|
+
sourceTokenDecimals: swaps.sourceTokenDecimals ?? null,
|
|
249
|
+
sourceTokenSymbol: swaps.sourceTokenSymbol ?? null,
|
|
250
|
+
swapAndSendRecipient: swaps.swapAndSendRecipient ?? null,
|
|
251
|
+
swapMetaData: swaps.swapMetaData ?? null,
|
|
252
|
+
swapTokenValue: swaps.swapTokenValue ?? null,
|
|
253
|
+
}
|
|
254
|
+
: null,
|
|
255
|
+
time: Date.now(),
|
|
256
|
+
transactionHash: null,
|
|
257
|
+
transactionParams: transaction ?? null,
|
|
258
|
+
transactionType: null,
|
|
259
|
+
userFeeLevel: null,
|
|
260
|
+
userOperation: __classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_createEmptyUserOperation).call(this, transaction),
|
|
261
|
+
};
|
|
262
|
+
__classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_updateMetadata).call(this, metadata);
|
|
263
|
+
(0, logger_js_1.projectLogger)('Added user operation', metadata.id);
|
|
264
|
+
return metadata;
|
|
265
|
+
}, _UserOperationController_prepareUserOperation = async function _UserOperationController_prepareUserOperation(cache) {
|
|
266
|
+
const { chainId, metadata, options, provider, request, transaction } = cache;
|
|
267
|
+
const { data, from, to, value } = request;
|
|
268
|
+
const { id, transactionParams, userOperation } = metadata;
|
|
269
|
+
const { smartContractAccount } = options;
|
|
270
|
+
(0, logger_js_1.projectLogger)('Preparing user operation', { id });
|
|
271
|
+
const transactionType = await __classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_getTransactionType).call(this, transaction, options);
|
|
272
|
+
metadata.transactionType = transactionType ?? null;
|
|
273
|
+
(0, logger_js_1.projectLogger)('Determined transaction type', transactionType);
|
|
274
|
+
await (0, gas_fees_js_1.updateGasFees)({
|
|
275
|
+
getGasFeeEstimates: __classPrivateFieldGet(this, _UserOperationController_getGasFeeEstimates, "f"),
|
|
276
|
+
metadata,
|
|
277
|
+
originalRequest: request,
|
|
278
|
+
provider,
|
|
279
|
+
transaction: transactionParams ?? undefined,
|
|
280
|
+
});
|
|
281
|
+
const response = await smartContractAccount.prepareUserOperation({
|
|
282
|
+
chainId,
|
|
283
|
+
data,
|
|
284
|
+
from,
|
|
285
|
+
to,
|
|
286
|
+
value,
|
|
287
|
+
});
|
|
288
|
+
(0, validation_js_1.validatePrepareUserOperationResponse)(response);
|
|
289
|
+
const { bundler: bundlerUrl, callData, dummyPaymasterAndData, dummySignature, initCode, nonce, sender, } = response;
|
|
290
|
+
userOperation.callData = callData;
|
|
291
|
+
userOperation.initCode = initCode ?? constants_js_1.EMPTY_BYTES;
|
|
292
|
+
userOperation.nonce = nonce;
|
|
293
|
+
userOperation.paymasterAndData = dummyPaymasterAndData ?? constants_js_1.EMPTY_BYTES;
|
|
294
|
+
userOperation.sender = sender;
|
|
295
|
+
userOperation.signature = dummySignature ?? constants_js_1.EMPTY_BYTES;
|
|
296
|
+
metadata.bundlerUrl = bundlerUrl;
|
|
297
|
+
await (0, gas_js_1.updateGas)(metadata, response, __classPrivateFieldGet(this, _UserOperationController_entrypoint, "f"));
|
|
298
|
+
__classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_updateMetadata).call(this, metadata);
|
|
299
|
+
}, _UserOperationController_addPaymasterData = async function _UserOperationController_addPaymasterData(metadata, smartContractAccount) {
|
|
300
|
+
const { id, userOperation, chainId } = metadata;
|
|
301
|
+
(0, logger_js_1.projectLogger)('Requesting paymaster data', { id });
|
|
302
|
+
const response = await smartContractAccount.updateUserOperation({
|
|
303
|
+
userOperation,
|
|
304
|
+
chainId,
|
|
305
|
+
});
|
|
306
|
+
(0, validation_js_1.validateUpdateUserOperationResponse)(response);
|
|
307
|
+
userOperation.paymasterAndData = response.paymasterAndData ?? constants_js_1.EMPTY_BYTES;
|
|
308
|
+
if (response.callGasLimit) {
|
|
309
|
+
userOperation.callGasLimit = response.callGasLimit;
|
|
310
|
+
}
|
|
311
|
+
if (response.preVerificationGas) {
|
|
312
|
+
userOperation.preVerificationGas = response.preVerificationGas;
|
|
313
|
+
}
|
|
314
|
+
if (response.verificationGasLimit) {
|
|
315
|
+
userOperation.verificationGasLimit = response.verificationGasLimit;
|
|
316
|
+
}
|
|
317
|
+
__classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_updateMetadata).call(this, metadata);
|
|
318
|
+
}, _UserOperationController_approveUserOperation = async function _UserOperationController_approveUserOperation(cache) {
|
|
319
|
+
(0, logger_js_1.projectLogger)('Requesting approval');
|
|
320
|
+
const { metadata } = cache;
|
|
321
|
+
const { resultCallbacks, value } = await __classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_requestApproval).call(this, metadata);
|
|
322
|
+
const updatedTransaction = value?.txMeta;
|
|
323
|
+
if (updatedTransaction) {
|
|
324
|
+
await __classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_updateUserOperationAfterApproval).call(this, cache, updatedTransaction);
|
|
325
|
+
}
|
|
326
|
+
metadata.status = types_js_1.UserOperationStatus.Approved;
|
|
327
|
+
__classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_updateMetadata).call(this, metadata);
|
|
328
|
+
return resultCallbacks;
|
|
329
|
+
}, _UserOperationController_signUserOperation = async function _UserOperationController_signUserOperation(metadata, smartContractAccount) {
|
|
330
|
+
const { id, chainId, userOperation } = metadata;
|
|
331
|
+
(0, logger_js_1.projectLogger)('Signing user operation', id, userOperation);
|
|
332
|
+
const response = await smartContractAccount.signUserOperation({
|
|
333
|
+
userOperation,
|
|
334
|
+
chainId,
|
|
335
|
+
});
|
|
336
|
+
(0, validation_js_1.validateSignUserOperationResponse)(response);
|
|
337
|
+
const { signature } = response;
|
|
338
|
+
userOperation.signature = signature;
|
|
339
|
+
(0, logger_js_1.projectLogger)('Signed user operation', signature);
|
|
340
|
+
metadata.status = types_js_1.UserOperationStatus.Signed;
|
|
341
|
+
__classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_updateMetadata).call(this, metadata);
|
|
342
|
+
}, _UserOperationController_submitUserOperation = async function _UserOperationController_submitUserOperation(metadata) {
|
|
343
|
+
const { userOperation } = metadata;
|
|
344
|
+
(0, logger_js_1.projectLogger)('Submitting user operation', userOperation);
|
|
345
|
+
const bundler = new Bundler_js_1.Bundler(metadata.bundlerUrl);
|
|
346
|
+
const hash = await bundler.sendUserOperation(userOperation, __classPrivateFieldGet(this, _UserOperationController_entrypoint, "f"));
|
|
347
|
+
metadata.hash = hash;
|
|
348
|
+
metadata.status = types_js_1.UserOperationStatus.Submitted;
|
|
349
|
+
__classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_updateMetadata).call(this, metadata);
|
|
350
|
+
}, _UserOperationController_failUserOperation = function _UserOperationController_failUserOperation(metadata, error) {
|
|
351
|
+
const { id } = metadata;
|
|
352
|
+
const rawError = error;
|
|
353
|
+
(0, logger_js_1.projectLogger)('User operation failed', id, error);
|
|
354
|
+
metadata.error = {
|
|
355
|
+
name: rawError.name,
|
|
356
|
+
message: rawError.message,
|
|
357
|
+
stack: rawError.stack,
|
|
358
|
+
code: rawError.code,
|
|
359
|
+
rpc: rawError.value,
|
|
360
|
+
};
|
|
361
|
+
metadata.status = types_js_1.UserOperationStatus.Failed;
|
|
362
|
+
__classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_updateMetadata).call(this, metadata);
|
|
363
|
+
if (String(rawError.code) === String(rpc_errors_1.errorCodes.provider.userRejectedRequest)) {
|
|
364
|
+
__classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_deleteMetadata).call(this, id);
|
|
365
|
+
}
|
|
366
|
+
}, _UserOperationController_createEmptyUserOperation = function _UserOperationController_createEmptyUserOperation(transaction) {
|
|
367
|
+
return {
|
|
368
|
+
callData: constants_js_1.EMPTY_BYTES,
|
|
369
|
+
callGasLimit: constants_js_1.EMPTY_BYTES,
|
|
370
|
+
initCode: constants_js_1.EMPTY_BYTES,
|
|
371
|
+
maxFeePerGas: transaction?.maxFeePerGas ?? constants_js_1.EMPTY_BYTES,
|
|
372
|
+
maxPriorityFeePerGas: transaction?.maxPriorityFeePerGas ?? constants_js_1.EMPTY_BYTES,
|
|
373
|
+
nonce: constants_js_1.EMPTY_BYTES,
|
|
374
|
+
paymasterAndData: constants_js_1.EMPTY_BYTES,
|
|
375
|
+
preVerificationGas: constants_js_1.EMPTY_BYTES,
|
|
376
|
+
sender: constants_js_1.ADDRESS_ZERO,
|
|
377
|
+
signature: constants_js_1.EMPTY_BYTES,
|
|
378
|
+
verificationGasLimit: constants_js_1.EMPTY_BYTES,
|
|
379
|
+
};
|
|
380
|
+
}, _UserOperationController_updateMetadata = function _UserOperationController_updateMetadata(metadata) {
|
|
381
|
+
const { id } = metadata;
|
|
382
|
+
this.update((state) => {
|
|
383
|
+
state.userOperations[id] = (0, lodash_1.cloneDeep)(metadata);
|
|
384
|
+
});
|
|
385
|
+
__classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_updateTransaction).call(this, metadata);
|
|
386
|
+
}, _UserOperationController_deleteMetadata = function _UserOperationController_deleteMetadata(id) {
|
|
387
|
+
this.update((state) => {
|
|
388
|
+
delete state.userOperations[id];
|
|
389
|
+
});
|
|
390
|
+
}, _UserOperationController_updateTransaction = function _UserOperationController_updateTransaction(metadata) {
|
|
391
|
+
if (!metadata.transactionParams) {
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
const transactionMetadata = (0, transaction_js_1.getTransactionMetadata)(metadata);
|
|
395
|
+
this.hub.emit('transaction-updated', transactionMetadata);
|
|
396
|
+
}, _UserOperationController_addPendingUserOperationTrackerListeners = function _UserOperationController_addPendingUserOperationTrackerListeners() {
|
|
397
|
+
__classPrivateFieldGet(this, _UserOperationController_pendingUserOperationTracker, "f").hub.on('user-operation-confirmed', (metadata) => {
|
|
398
|
+
(0, logger_js_1.projectLogger)('In listener...');
|
|
399
|
+
this.hub.emit('user-operation-confirmed', metadata);
|
|
400
|
+
this.hub.emit(`${metadata.id}:confirmed`, metadata);
|
|
401
|
+
});
|
|
402
|
+
__classPrivateFieldGet(this, _UserOperationController_pendingUserOperationTracker, "f").hub.on('user-operation-failed', (metadata, error) => {
|
|
403
|
+
this.hub.emit('user-operation-failed', metadata, error);
|
|
404
|
+
this.hub.emit(`${metadata.id}:failed`, metadata, error);
|
|
405
|
+
});
|
|
406
|
+
__classPrivateFieldGet(this, _UserOperationController_pendingUserOperationTracker, "f").hub.on('user-operation-updated', (metadata) => {
|
|
407
|
+
__classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_updateMetadata).call(this, metadata);
|
|
408
|
+
});
|
|
409
|
+
}, _UserOperationController_requestApproval = async function _UserOperationController_requestApproval(metadata) {
|
|
410
|
+
const { id, origin } = metadata;
|
|
411
|
+
const type = controller_utils_1.ApprovalType.Transaction;
|
|
412
|
+
const requestData = { txId: id };
|
|
413
|
+
return (await this.messenger.call('ApprovalController:addRequest', {
|
|
414
|
+
id,
|
|
415
|
+
origin,
|
|
416
|
+
type,
|
|
417
|
+
requestData,
|
|
418
|
+
expectsResult: true,
|
|
419
|
+
}, true));
|
|
420
|
+
}, _UserOperationController_getTransactionType = async function _UserOperationController_getTransactionType(transaction, options) {
|
|
421
|
+
if (!transaction) {
|
|
422
|
+
return undefined;
|
|
423
|
+
}
|
|
424
|
+
if (options.type) {
|
|
425
|
+
return options.type;
|
|
426
|
+
}
|
|
427
|
+
return transaction_controller_1.TransactionType.contractInteraction;
|
|
428
|
+
}, _UserOperationController_getProvider = async function _UserOperationController_getProvider(networkClientId) {
|
|
429
|
+
const { provider, configuration } = this.messenger.call('NetworkController:getNetworkClientById', networkClientId);
|
|
430
|
+
const { chainId } = configuration;
|
|
431
|
+
return { provider, chainId };
|
|
432
|
+
}, _UserOperationController_updateUserOperationAfterApproval = async function _UserOperationController_updateUserOperationAfterApproval(cache, updatedTransaction) {
|
|
433
|
+
(0, logger_js_1.projectLogger)('Found updated transaction in approval', { updatedTransaction });
|
|
434
|
+
const { metadata, request } = cache;
|
|
435
|
+
const { userOperation } = metadata;
|
|
436
|
+
const usingPaymaster = userOperation.paymasterAndData !== constants_js_1.EMPTY_BYTES;
|
|
437
|
+
const updatedMaxFeePerGas = (0, utils_1.add0x)(updatedTransaction.txParams.maxFeePerGas);
|
|
438
|
+
const updatedMaxPriorityFeePerGas = (0, utils_1.add0x)(updatedTransaction.txParams.maxPriorityFeePerGas);
|
|
439
|
+
let regenerateUserOperation = false;
|
|
440
|
+
const previousMaxFeePerGas = userOperation.maxFeePerGas;
|
|
441
|
+
const previousMaxPriorityFeePerGas = userOperation.maxPriorityFeePerGas;
|
|
442
|
+
const gasFeesUpdated = previousMaxFeePerGas !== updatedMaxFeePerGas ||
|
|
443
|
+
previousMaxPriorityFeePerGas !== updatedMaxPriorityFeePerGas;
|
|
444
|
+
/**
|
|
445
|
+
* true when we detect {@link getTransactionMetadata} has set the gas fees to zero
|
|
446
|
+
* because the userOperation has a paymaster. This should not be mistaken for gas
|
|
447
|
+
* fees being updated during the approval process.
|
|
448
|
+
*/
|
|
449
|
+
const areGasFeesZeroBecauseOfPaymaster = usingPaymaster &&
|
|
450
|
+
updatedMaxFeePerGas === constants_js_1.VALUE_ZERO &&
|
|
451
|
+
updatedMaxPriorityFeePerGas === constants_js_1.VALUE_ZERO;
|
|
452
|
+
if (gasFeesUpdated && !areGasFeesZeroBecauseOfPaymaster) {
|
|
453
|
+
(0, logger_js_1.projectLogger)('Gas fees updated during approval', {
|
|
454
|
+
previousMaxFeePerGas,
|
|
455
|
+
previousMaxPriorityFeePerGas,
|
|
456
|
+
updatedMaxFeePerGas,
|
|
457
|
+
updatedMaxPriorityFeePerGas,
|
|
458
|
+
});
|
|
459
|
+
userOperation.maxFeePerGas = updatedMaxFeePerGas;
|
|
460
|
+
userOperation.maxPriorityFeePerGas = updatedMaxPriorityFeePerGas;
|
|
461
|
+
regenerateUserOperation = usingPaymaster;
|
|
462
|
+
}
|
|
463
|
+
const previousData = request.data ?? constants_js_1.EMPTY_BYTES;
|
|
464
|
+
const updatedData = updatedTransaction.txParams.data ?? constants_js_1.EMPTY_BYTES;
|
|
465
|
+
if (previousData !== updatedData) {
|
|
466
|
+
(0, logger_js_1.projectLogger)('Data updated during approval', { previousData, updatedData });
|
|
467
|
+
regenerateUserOperation = true;
|
|
468
|
+
}
|
|
469
|
+
const previousValue = request.value ?? constants_js_1.VALUE_ZERO;
|
|
470
|
+
const updatedValue = updatedTransaction.txParams.value ?? constants_js_1.VALUE_ZERO;
|
|
471
|
+
if (previousValue !== updatedValue) {
|
|
472
|
+
(0, logger_js_1.projectLogger)('Value updated during approval', { previousValue, updatedValue });
|
|
473
|
+
regenerateUserOperation = true;
|
|
474
|
+
}
|
|
475
|
+
if (regenerateUserOperation) {
|
|
476
|
+
const updatedRequest = {
|
|
477
|
+
...request,
|
|
478
|
+
data: updatedData,
|
|
479
|
+
maxFeePerGas: updatedMaxFeePerGas,
|
|
480
|
+
maxPriorityFeePerGas: updatedMaxPriorityFeePerGas,
|
|
481
|
+
value: updatedValue,
|
|
482
|
+
};
|
|
483
|
+
await __classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_regenerateUserOperation).call(this, {
|
|
484
|
+
...cache,
|
|
485
|
+
request: updatedRequest,
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
}, _UserOperationController_regenerateUserOperation = async function _UserOperationController_regenerateUserOperation(cache) {
|
|
489
|
+
(0, logger_js_1.projectLogger)('Regenerating user operation as parameters were updated during approval');
|
|
490
|
+
const { options: { smartContractAccount }, metadata, } = cache;
|
|
491
|
+
await __classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_prepareUserOperation).call(this, cache);
|
|
492
|
+
await __classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_addPaymasterData).call(this, metadata, smartContractAccount);
|
|
493
|
+
(0, logger_js_1.projectLogger)('Regenerated user operation', metadata.userOperation);
|
|
494
|
+
};
|
|
495
|
+
//# sourceMappingURL=UserOperationController.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UserOperationController.cjs","sourceRoot":"","sources":["../src/UserOperationController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAKA,+DAA2D;AAK3D,iEAA0D;AAY1D,qDAAkD;AAClD,6EAAmE;AAKnE,2CAAwC;AACxC,kEAAkE;AAClE,sDAAsD;AACtD,oDAAkC;AAClC,mCAAmC;AACnC,+BAAoC;AAEpC,kDAAuE;AACvE,sDAA+C;AAC/C,8FAAuF;AACvF,wFAAiF;AACjF,4CAAmD;AAMnD,0CAAiD;AAEjD,sDAAoD;AACpD,4CAA2C;AAC3C,4DAAgE;AAChE,0DAM+B;AAE/B,MAAM,cAAc,GAAG,yBAAyB,CAAC;AAEjD,MAAM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8B,EAAE,EAAE,YAAY,EAAE,WAAW,EAAE,CAAC,CAAC;QACnE,uBAAuB,GAAG,IAAI,CAAC;IACjC,CAAC;IAED,MAAM,aAAa,GAAG,OAAO,CAAC,KAAK,IAAI,yBAAU,CAAC;IAClD,MAAM,YAAY,GAAG,kBAAkB,CAAC,QAAQ,CAAC,KAAK,IAAI,yBAAU,CAAC;IAErE,IAAI,aAAa,KAAK,YAAY,EAAE,CAAC;QACnC,IAAA,yBAAG,EAAC,+BAA+B,EAAE,EAAE,aAAa,EAAE,YAAY,EAAE,CAAC,CAAC;QACtE,uBAAuB,GAAG,IAAI,CAAC;IACjC,CAAC;IAED,IAAI,uBAAuB,EAAE,CAAC;QAC5B,MAAM,cAAc,GAAG;YACrB,GAAG,OAAO;YACV,IAAI,EAAE,WAAW;YACjB,YAAY,EAAE,mBAAmB;YACjC,oBAAoB,EAAE,2BAA2B;YACjD,KAAK,EAAE,YAAY;SACpB,CAAC;QAEF,MAAM,uBAAA,IAAI,4FAAyB,MAA7B,IAAI,EAA0B;YAClC,GAAG,KAAK;YACR,OAAO,EAAE,cAAc;SACxB,CAAC,CAAC;IACL,CAAC;AACH,CAAC,qDAED,KAAK,2DAA0B,KAAyB;IACtD,IAAA,yBAAG,EACD,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,IAAA,yBAAG,EAAC,4BAA4B,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAC;AAC5D,CAAC","sourcesContent":["import type {\n AcceptResultCallbacks,\n ApprovalControllerAddRequestAction,\n AddResult,\n} from '@metamask/approval-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport { ApprovalType } from '@metamask/controller-utils';\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 { TransactionType } from '@metamask/transaction-controller';\nimport type {\n TransactionMeta,\n TransactionParams,\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.js';\nimport { Bundler } from './helpers/Bundler.js';\nimport { PendingUserOperationTracker } from './helpers/PendingUserOperationTracker.js';\nimport { SnapSmartContractAccount } from './helpers/SnapSmartContractAccount.js';\nimport { projectLogger as log } from './logger.js';\nimport type {\n SmartContractAccount,\n UserOperation,\n UserOperationMetadata,\n} from './types.js';\nimport { UserOperationStatus } from './types.js';\nimport type { UserOperationControllerMethodActions } from './UserOperationController-method-action-types.js';\nimport { updateGasFees } from './utils/gas-fees.js';\nimport { updateGas } from './utils/gas.js';\nimport { getTransactionMetadata } from './utils/transaction.js';\nimport {\n validateAddUserOperationOptions,\n validateAddUserOperationRequest,\n validatePrepareUserOperationResponse,\n validateSignUserOperationResponse,\n validateUpdateUserOperationResponse,\n} from './utils/validation.js';\n\nconst controllerName = 'UserOperationController';\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'addUserOperation',\n 'addUserOperationFromTransaction',\n 'startPollingByNetworkClientId',\n] as const;\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 on<T extends keyof Events>(\n eventName: T,\n listener: (...args: Events[T]) => void,\n ): UserOperationControllerEventEmitter;\n\n once<T extends keyof Events>(\n eventName: T,\n listener: (...args: Events[T]) => void,\n ): UserOperationControllerEventEmitter;\n\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 | UserOperationControllerMethodActions\n | NetworkControllerGetNetworkClientByIdAction\n | ApprovalControllerAddRequestAction\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 readonly #entrypoint: string;\n\n readonly #getGasFeeEstimates: () => Promise<GasFeeState>;\n\n readonly #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.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\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 /**\n * Starts polling for pending user operations on the given network.\n *\n * @param networkClientId - The ID of the network client to poll.\n * @returns The polling token that can be used to stop polling.\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 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 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 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 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 return TransactionType.contractInteraction;\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,15 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
import
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
8
|
-
import {
|
|
9
|
-
import type {
|
|
10
|
-
import
|
|
11
|
-
import type {
|
|
12
|
-
import
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="npm-which/node_modules/@types/node/events.js" />
|
|
3
|
+
import type { ApprovalControllerAddRequestAction } from "@metamask/approval-controller";
|
|
4
|
+
import { BaseController } from "@metamask/base-controller";
|
|
5
|
+
import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
|
|
6
|
+
import type { GasFeeState } from "@metamask/gas-fee-controller";
|
|
7
|
+
import type { KeyringControllerPrepareUserOperationAction, KeyringControllerPatchUserOperationAction, KeyringControllerSignUserOperationAction } from "@metamask/keyring-controller";
|
|
8
|
+
import type { Messenger } from "@metamask/messenger";
|
|
9
|
+
import type { NetworkControllerGetNetworkClientByIdAction } from "@metamask/network-controller";
|
|
10
|
+
import { TransactionType } from "@metamask/transaction-controller";
|
|
11
|
+
import type { TransactionMeta, TransactionParams } from "@metamask/transaction-controller";
|
|
12
|
+
import EventEmitter from "events";
|
|
13
|
+
import type { SmartContractAccount, UserOperationMetadata } from "./types.cjs";
|
|
14
|
+
import type { UserOperationControllerMethodActions } from "./UserOperationController-method-action-types.cjs";
|
|
13
15
|
declare const controllerName = "UserOperationController";
|
|
14
16
|
type Events = {
|
|
15
17
|
'transaction-updated': [metadata: TransactionMeta];
|
|
@@ -131,4 +133,4 @@ export declare class UserOperationController extends BaseController<typeof contr
|
|
|
131
133
|
startPollingByNetworkClientId(networkClientId: string): string;
|
|
132
134
|
}
|
|
133
135
|
export {};
|
|
134
|
-
//# sourceMappingURL=UserOperationController.d.
|
|
136
|
+
//# sourceMappingURL=UserOperationController.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UserOperationController.d.cts","sourceRoot":"","sources":["../src/UserOperationController.ts"],"names":[],"mappings":";;AAAA,OAAO,KAAK,EAEV,kCAAkC,EAEnC,sCAAsC;AACvC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AAEnC,OAAO,KAAK,EAAE,WAAW,EAAE,qCAAqC;AAChE,OAAO,KAAK,EACV,2CAA2C,EAC3C,yCAAyC,EACzC,wCAAwC,EACzC,qCAAqC;AACtC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EACV,2CAA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