@metamask-previews/transaction-controller 21.1.0-preview.cbe2fbb7 → 21.2.0-preview.08978bf

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.
Files changed (36) hide show
  1. package/CHANGELOG.md +9 -1
  2. package/dist/TransactionController.d.ts +39 -78
  3. package/dist/TransactionController.d.ts.map +1 -1
  4. package/dist/TransactionController.js +125 -422
  5. package/dist/TransactionController.js.map +1 -1
  6. package/dist/helpers/EtherscanRemoteTransactionSource.d.ts.map +1 -1
  7. package/dist/helpers/EtherscanRemoteTransactionSource.js +8 -28
  8. package/dist/helpers/EtherscanRemoteTransactionSource.js.map +1 -1
  9. package/dist/helpers/IncomingTransactionHelper.d.ts +3 -3
  10. package/dist/helpers/IncomingTransactionHelper.d.ts.map +1 -1
  11. package/dist/helpers/IncomingTransactionHelper.js +14 -17
  12. package/dist/helpers/IncomingTransactionHelper.js.map +1 -1
  13. package/dist/helpers/PendingTransactionTracker.d.ts +7 -7
  14. package/dist/helpers/PendingTransactionTracker.d.ts.map +1 -1
  15. package/dist/helpers/PendingTransactionTracker.js +26 -26
  16. package/dist/helpers/PendingTransactionTracker.js.map +1 -1
  17. package/dist/types.d.ts +0 -8
  18. package/dist/types.d.ts.map +1 -1
  19. package/dist/types.js.map +1 -1
  20. package/dist/utils/etherscan.d.ts +0 -7
  21. package/dist/utils/etherscan.d.ts.map +1 -1
  22. package/dist/utils/etherscan.js +6 -16
  23. package/dist/utils/etherscan.js.map +1 -1
  24. package/dist/utils/gas-fees.d.ts +3 -4
  25. package/dist/utils/gas-fees.d.ts.map +1 -1
  26. package/dist/utils/gas-fees.js +2 -6
  27. package/dist/utils/gas-fees.js.map +1 -1
  28. package/dist/utils/gas.d.ts +2 -3
  29. package/dist/utils/gas.d.ts.map +1 -1
  30. package/dist/utils/gas.js +5 -4
  31. package/dist/utils/gas.js.map +1 -1
  32. package/dist/utils/nonce.d.ts +3 -3
  33. package/dist/utils/nonce.d.ts.map +1 -1
  34. package/dist/utils/nonce.js +3 -3
  35. package/dist/utils/nonce.js.map +1 -1
  36. package/package.json +6 -7
@@ -8,15 +8,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
12
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
13
- 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");
14
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
15
- };
16
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
17
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
13
  };
19
- var _TransactionController_instances, _TransactionController_acquireNonceLockForChainIdKey, _TransactionController_getEthQuery, _TransactionController_refreshEtherscanRemoteTransactionSources, _TransactionController_refreshTrackingMap, _TransactionController_initTrackingMap, _TransactionController_checkForPendingTransactionAndStartPolling, _TransactionController_stopTrackingByNetworkClientId, _TransactionController_stopAllTracking, _TransactionController_startTrackingByNetworkClientId;
20
14
  Object.defineProperty(exports, "__esModule", { value: true });
21
15
  exports.TransactionController = exports.SPEED_UP_RATE = exports.CANCEL_RATE = exports.HARDFORK = void 0;
22
16
  const common_1 = require("@ethereumjs/common");
@@ -24,7 +18,6 @@ const tx_1 = require("@ethereumjs/tx");
24
18
  const base_controller_1 = require("@metamask/base-controller");
25
19
  const controller_utils_1 = require("@metamask/controller-utils");
26
20
  const eth_query_1 = __importDefault(require("@metamask/eth-query"));
27
- const network_controller_1 = require("@metamask/network-controller");
28
21
  const rpc_errors_1 = require("@metamask/rpc-errors");
29
22
  const async_mutex_1 = require("async-mutex");
30
23
  const eth_method_registry_1 = require("eth-method-registry");
@@ -82,33 +75,32 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
82
75
  * @param options.getSavedGasFees - Gets the saved gas fee config.
83
76
  * @param options.getSelectedAddress - Gets the address of the currently selected account.
84
77
  * @param options.incomingTransactions - Configuration options for incoming transaction support.
78
+ * @param options.incomingTransactions.includeTokenTransfers - Whether or not to include ERC20 token transfers.
79
+ * @param options.incomingTransactions.isEnabled - Whether or not incoming transaction retrieval is enabled.
80
+ * @param options.incomingTransactions.queryEntireHistory - Whether to initially query the entire transaction history or only recent blocks.
81
+ * @param options.incomingTransactions.updateTransactions - Whether to update local transactions using remote transaction data.
85
82
  * @param options.messenger - The controller messenger.
86
83
  * @param options.onNetworkStateChange - Allows subscribing to network controller state changes.
87
84
  * @param options.pendingTransactions - Configuration options for pending transaction support.
85
+ * @param options.pendingTransactions.isResubmitEnabled - Whether transaction publishing is automatically retried.
88
86
  * @param options.provider - The provider used to create the underlying EthQuery instance.
89
87
  * @param options.securityProviderRequest - A function for verifying a transaction, whether it is malicious or not.
90
88
  * @param options.speedUpMultiplier - Multiplier used to determine a transaction's increased gas fee during speed up.
91
- * @param options.findNetworkClientIdByChainId - Finds a networkClientId with the given chainId from the NetworkController.
92
- * @param options.getNetworkClientById - Gets the network client with the given id from the NetworkController.
93
89
  * @param options.hooks - The controller hooks.
94
90
  * @param options.hooks.afterSign - Additional logic to execute after signing a transaction. Return false to not change the status to signed.
95
91
  * @param options.hooks.beforeApproveOnInit - Additional logic to execute before starting an approval flow for a transaction during initialization. Return false to skip the transaction.
96
92
  * @param options.hooks.beforeCheckPendingTransaction - Additional logic to execute before checking pending transactions. Return false to prevent the broadcast of the transaction.
97
93
  * @param options.hooks.beforePublish - Additional logic to execute before publishing a transaction. Return false to prevent the broadcast of the transaction.
98
94
  * @param options.hooks.getAdditionalSignArguments - Returns additional arguments required to sign a transaction.
99
- * @param options.hub - Use a different event emitter for the hub.
100
- * @param options.getNetworkClientRegistry - Gets the network client registry.
101
- * @param options.enableMultichain - Enable multichain support.
95
+ * @param options.hooks.publish - Alternate logic to publish a transaction.
102
96
  * @param config - Initial options used to configure this controller.
103
97
  * @param state - Initial state to set on this controller.
104
98
  */
105
- constructor({ blockTracker, cancelMultiplier, disableHistory, disableSendFlowHistory, disableSwaps, getCurrentAccountEIP1559Compatibility, getCurrentNetworkEIP1559Compatibility, getExternalPendingTransactions, getGasFeeEstimates, getNetworkState, getPermittedAccounts, getSavedGasFees, getSelectedAddress, incomingTransactions = {}, messenger, onNetworkStateChange, pendingTransactions = {}, provider, securityProviderRequest, speedUpMultiplier, findNetworkClientIdByChainId, getNetworkClientById, getNetworkClientRegistry, hub, enableMultichain = false, hooks = {}, }, config, state) {
106
- var _a, _b, _c, _d, _e;
99
+ constructor({ blockTracker, cancelMultiplier, disableHistory, disableSendFlowHistory, disableSwaps, getCurrentAccountEIP1559Compatibility, getCurrentNetworkEIP1559Compatibility, getExternalPendingTransactions, getGasFeeEstimates, getNetworkState, getPermittedAccounts, getSavedGasFees, getSelectedAddress, incomingTransactions = {}, messenger, onNetworkStateChange, pendingTransactions = {}, provider, securityProviderRequest, speedUpMultiplier, hooks = {}, }, config, state) {
100
+ var _a, _b, _c, _d, _e, _f;
107
101
  super(config, state);
108
- _TransactionController_instances.add(this);
109
102
  this.inProcessOfSigning = new Set();
110
103
  this.mutex = new async_mutex_1.Mutex();
111
- this.nonceMutexesByChainId = new Map();
112
104
  this.signAbortCallbacks = new Map();
113
105
  /**
114
106
  * EventEmitter instance used to listen to specific transactional events
@@ -118,50 +110,6 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
118
110
  * Name of this controller used during composition
119
111
  */
120
112
  this.name = 'TransactionController';
121
- this.trackingMap = new Map();
122
- this.etherscanRemoteTransactionSourcesMap = new Map();
123
- _TransactionController_refreshEtherscanRemoteTransactionSources.set(this, (networkClients) => {
124
- // this will be prettier when we have consolidated network clients with a single chainId:
125
- // check if there are still other network clients using the same chainId
126
- // if not remove the etherscanRemoteTransaction source from the map
127
- const chainIdsInRegistry = new Set();
128
- Object.values(networkClients).forEach((networkClient) => chainIdsInRegistry.add(networkClient.configuration.chainId));
129
- const existingChainIds = Array.from(this.etherscanRemoteTransactionSourcesMap.keys());
130
- const chainIdsToRemove = existingChainIds.filter((chainId) => !chainIdsInRegistry.has(chainId));
131
- chainIdsToRemove.forEach((chainId) => {
132
- this.etherscanRemoteTransactionSourcesMap.delete(chainId);
133
- });
134
- });
135
- _TransactionController_refreshTrackingMap.set(this, (networkClients) => {
136
- __classPrivateFieldGet(this, _TransactionController_refreshEtherscanRemoteTransactionSources, "f").call(this, networkClients);
137
- const networkClientIds = Object.keys(networkClients);
138
- const existingNetworkClientIds = Array.from(this.trackingMap.keys());
139
- // Remove tracking for NetworkClientIds that no longer exist
140
- const networkClientIdsToRemove = existingNetworkClientIds.filter((id) => !networkClientIds.includes(id));
141
- networkClientIdsToRemove.forEach((id) => {
142
- __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_stopTrackingByNetworkClientId).call(this, id);
143
- });
144
- // Start tracking new NetworkClientIds from the registry
145
- const networkClientIdsToAdd = networkClientIds.filter((id) => !existingNetworkClientIds.includes(id));
146
- networkClientIdsToAdd.forEach((id) => {
147
- __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_startTrackingByNetworkClientId).call(this, id);
148
- });
149
- });
150
- _TransactionController_initTrackingMap.set(this, () => {
151
- const networkClients = this.getNetworkClientRegistry();
152
- const networkClientIds = Object.keys(networkClients);
153
- networkClientIds.map((id) => __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_startTrackingByNetworkClientId).call(this, id));
154
- this.hub.emit('tracking-map-init', networkClientIds);
155
- });
156
- _TransactionController_checkForPendingTransactionAndStartPolling.set(this, () => {
157
- // PendingTransactionTracker reads state through its getTransactions hook
158
- this.pendingTransactionTracker.startIfPendingTransactions();
159
- if (this.enableMultichain) {
160
- for (const [, trackingMap] of this.trackingMap) {
161
- trackingMap.pendingTransactionTracker.startIfPendingTransactions();
162
- }
163
- }
164
- });
165
113
  this.defaultConfig = {
166
114
  txHistoryLimit: 40,
167
115
  };
@@ -171,11 +119,6 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
171
119
  lastFetchedBlockNumbers: {},
172
120
  };
173
121
  this.initialize();
174
- this.hub = hub !== null && hub !== void 0 ? hub : this.hub;
175
- this.enableMultichain = enableMultichain;
176
- this.findNetworkClientIdByChainId = findNetworkClientIdByChainId;
177
- this.getNetworkClientById = getNetworkClientById;
178
- this.getNetworkClientRegistry = getNetworkClientRegistry;
179
122
  this.provider = provider;
180
123
  this.messagingSystem = messenger;
181
124
  this.getNetworkState = getNetworkState;
@@ -199,8 +142,6 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
199
142
  this.securityProviderRequest = securityProviderRequest;
200
143
  this.cancelMultiplier = cancelMultiplier !== null && cancelMultiplier !== void 0 ? cancelMultiplier : exports.CANCEL_RATE;
201
144
  this.speedUpMultiplier = speedUpMultiplier !== null && speedUpMultiplier !== void 0 ? speedUpMultiplier : exports.SPEED_UP_RATE;
202
- this.incomingTransactionOptions = incomingTransactions;
203
- this.pendingTransactionOptions = pendingTransactions;
204
145
  this.afterSign = (_a = hooks === null || hooks === void 0 ? void 0 : hooks.afterSign) !== null && _a !== void 0 ? _a : (() => true);
205
146
  this.beforeApproveOnInit = (_b = hooks === null || hooks === void 0 ? void 0 : hooks.beforeApproveOnInit) !== null && _b !== void 0 ? _b : (() => true);
206
147
  this.beforeCheckPendingTransaction =
@@ -210,28 +151,30 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
210
151
  this.beforePublish = (_d = hooks === null || hooks === void 0 ? void 0 : hooks.beforePublish) !== null && _d !== void 0 ? _d : (() => true);
211
152
  this.getAdditionalSignArguments =
212
153
  (_e = hooks === null || hooks === void 0 ? void 0 : hooks.getAdditionalSignArguments) !== null && _e !== void 0 ? _e : (() => []);
154
+ this.publish =
155
+ (_f = hooks === null || hooks === void 0 ? void 0 : hooks.publish) !== null && _f !== void 0 ? _f : (() => Promise.resolve({ transactionHash: undefined }));
213
156
  this.nonceTracker = new nonce_tracker_1.NonceTracker({
214
157
  // @ts-expect-error provider types misaligned: SafeEventEmitterProvider vs Record<string,string>
215
158
  provider,
216
159
  blockTracker,
217
- getPendingTransactions: this.getNonceTrackerPendingTransactions.bind(this, undefined),
160
+ getPendingTransactions: this.getNonceTrackerPendingTransactions.bind(this),
218
161
  getConfirmedTransactions: this.getNonceTrackerTransactions.bind(this, types_1.TransactionStatus.confirmed),
219
162
  });
220
- const etherscanRemoteTransactionSource = new EtherscanRemoteTransactionSource_1.EtherscanRemoteTransactionSource({
221
- includeTokenTransfers: incomingTransactions.includeTokenTransfers,
222
- });
223
163
  this.incomingTransactionHelper = new IncomingTransactionHelper_1.IncomingTransactionHelper({
224
164
  blockTracker,
225
165
  getCurrentAccount: getSelectedAddress,
226
166
  getLastFetchedBlockNumbers: () => this.state.lastFetchedBlockNumbers,
227
- getChainId: this.getChainId.bind(this),
167
+ getNetworkState,
228
168
  isEnabled: incomingTransactions.isEnabled,
229
169
  queryEntireHistory: incomingTransactions.queryEntireHistory,
230
- remoteTransactionSource: etherscanRemoteTransactionSource,
170
+ remoteTransactionSource: new EtherscanRemoteTransactionSource_1.EtherscanRemoteTransactionSource({
171
+ includeTokenTransfers: incomingTransactions.includeTokenTransfers,
172
+ }),
231
173
  transactionLimit: this.config.txHistoryLimit,
232
174
  updateTransactions: incomingTransactions.updateTransactions,
233
175
  });
234
- this.addIncomingTransactionHelperListeners();
176
+ this.incomingTransactionHelper.hub.on('transactions', this.onIncomingTransactions.bind(this));
177
+ this.incomingTransactionHelper.hub.on('updatedLastFetchedBlockNumbers', this.onUpdatedLastFetchedBlockNumbers.bind(this));
235
178
  this.pendingTransactionTracker = new PendingTransactionTracker_1.PendingTransactionTracker({
236
179
  approveTransaction: this.approveTransaction.bind(this),
237
180
  blockTracker,
@@ -239,11 +182,12 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
239
182
  getEthQuery: () => this.ethQuery,
240
183
  getTransactions: () => this.state.transactions,
241
184
  isResubmitEnabled: pendingTransactions.isResubmitEnabled,
242
- getGlobalLock: () => __awaiter(this, void 0, void 0, function* () {
243
- return __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_acquireNonceLockForChainIdKey).call(this, {
244
- chainId: this.getChainId(),
245
- });
246
- }),
185
+ nonceTracker: this.nonceTracker,
186
+ onStateChange: (listener) => {
187
+ this.subscribe(listener);
188
+ onNetworkStateChange(listener);
189
+ listener();
190
+ },
247
191
  publishTransaction: this.publishTransaction.bind(this),
248
192
  hooks: {
249
193
  beforeCheckPendingTransaction: this.beforeCheckPendingTransaction.bind(this),
@@ -251,32 +195,11 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
251
195
  },
252
196
  });
253
197
  this.addPendingTransactionTrackerListeners();
254
- // when transactionsController state changes
255
- // check for pending transactions and start polling if there are any
256
- this.subscribe(__classPrivateFieldGet(this, _TransactionController_checkForPendingTransactionAndStartPolling, "f"));
257
- // TODO once v2 is merged make sure this only runs when
258
- // selectedNetworkClientId changes
259
198
  onNetworkStateChange(() => {
260
199
  (0, logger_1.projectLogger)('Detected network change', this.getChainId());
261
- this.pendingTransactionTracker.startIfPendingTransactions();
262
200
  this.onBootCleanup();
263
201
  });
264
202
  this.onBootCleanup();
265
- this.messagingSystem.subscribe('NetworkController:stateChange', (_, patches) => {
266
- if (this.enableMultichain) {
267
- const networkClients = this.getNetworkClientRegistry();
268
- patches.forEach(({ op, path }) => {
269
- if (op === 'remove' && path[0] === 'networkConfigurations') {
270
- const networkClientId = path[1];
271
- delete networkClients[networkClientId];
272
- }
273
- });
274
- __classPrivateFieldGet(this, _TransactionController_refreshTrackingMap, "f").call(this, networkClients);
275
- }
276
- });
277
- if (this.enableMultichain) {
278
- __classPrivateFieldGet(this, _TransactionController_initTrackingMap, "f").call(this);
279
- }
280
203
  }
281
204
  failTransaction(transactionMeta, error, actionId) {
282
205
  const newTransactionMeta = Object.assign(Object.assign({}, transactionMeta), { error: (0, utils_1.normalizeTxError)(error), status: types_1.TransactionStatus.failed });
@@ -296,18 +219,6 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
296
219
  return { registryMethod, parsedRegistryMethod };
297
220
  });
298
221
  }
299
- setEnableMultichain(enableMultichain) {
300
- this.enableMultichain = enableMultichain;
301
- if (enableMultichain) {
302
- __classPrivateFieldGet(this, _TransactionController_initTrackingMap, "f").call(this);
303
- }
304
- }
305
- /**
306
- * Stops polling and removes listeners to prepare the controller for garbage collection.
307
- */
308
- destroy() {
309
- __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_stopAllTracking).call(this);
310
- }
311
222
  /**
312
223
  * Handle new method data request.
313
224
  *
@@ -352,26 +263,21 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
352
263
  * @param opts.swaps - Options for swaps transactions.
353
264
  * @param opts.swaps.hasApproveTx - Whether the transaction has an approval transaction.
354
265
  * @param opts.swaps.meta - Metadata for swap transaction.
355
- * @param opts.networkClientId - The id of the network client for this transaction.
356
266
  * @returns Object containing a promise resolving to the transaction hash if approved.
357
267
  */
358
- addTransaction(txParams, { actionId, deviceConfirmedOn, method, origin, requireApproval, securityAlertResponse, sendFlowHistory, swaps = {}, type, networkClientId, } = {}) {
268
+ addTransaction(txParams, { actionId, deviceConfirmedOn, method, origin, requireApproval, securityAlertResponse, sendFlowHistory, swaps = {}, type, } = {}) {
359
269
  return __awaiter(this, void 0, void 0, function* () {
360
270
  (0, logger_1.projectLogger)('Adding transaction', txParams);
361
271
  txParams = (0, utils_1.normalizeTxParams)(txParams);
362
- if (networkClientId && !this.trackingMap.has(networkClientId)) {
363
- throw new Error('The networkClientId for this transaction could not be found');
364
- }
365
- const isEIP1559Compatible = yield this.getEIP1559Compatibility(networkClientId);
272
+ const isEIP1559Compatible = yield this.getEIP1559Compatibility();
366
273
  (0, validation_1.validateTxParams)(txParams, isEIP1559Compatible);
367
274
  if (origin) {
368
275
  yield (0, validation_1.validateTransactionOrigin)(yield this.getPermittedAccounts(origin), this.getSelectedAddress(), txParams.from, origin);
369
276
  }
370
277
  const dappSuggestedGasFees = this.generateDappSuggestedGasFees(txParams, origin);
371
- const chainId = this.getChainId(networkClientId);
372
- const ethQuery = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getEthQuery).call(this, { networkClientId, chainId });
373
- const transactionType = type !== null && type !== void 0 ? type : (yield (0, transaction_type_1.determineTransactionType)(txParams, ethQuery)).type;
278
+ const transactionType = type !== null && type !== void 0 ? type : (yield (0, transaction_type_1.determineTransactionType)(txParams, this.ethQuery)).type;
374
279
  const existingTransactionMeta = this.getTransactionWithActionId(actionId);
280
+ const chainId = this.getChainId();
375
281
  // If a request to add a transaction with the same actionId is submitted again, a new transaction will not be created for it.
376
282
  const transactionMeta = existingTransactionMeta || {
377
283
  // Add actionId to txMeta to check if same actionId is seen again
@@ -388,7 +294,6 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
388
294
  userEditedGasLimit: false,
389
295
  verifiedOnBlockchain: false,
390
296
  type: transactionType,
391
- networkClientId,
392
297
  };
393
298
  yield this.updateGasProperties(transactionMeta);
394
299
  // Checks if a transaction already exists with a given actionId
@@ -425,45 +330,15 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
425
330
  };
426
331
  });
427
332
  }
428
- startIncomingTransactionPolling(networkClientIds = []) {
429
- if (networkClientIds.length === 0 || !this.enableMultichain) {
430
- this.incomingTransactionHelper.start();
431
- return;
432
- }
433
- networkClientIds.forEach((networkClientId) => {
434
- var _a;
435
- (_a = this.trackingMap.get(networkClientId)) === null || _a === void 0 ? void 0 : _a.incomingTransactionHelper.start();
436
- });
437
- }
438
- stopIncomingTransactionPolling(networkClientIds = []) {
439
- if (networkClientIds.length === 0 || !this.enableMultichain) {
440
- this.incomingTransactionHelper.stop();
441
- return;
442
- }
443
- networkClientIds.forEach((networkClientId) => {
444
- var _a;
445
- (_a = this.trackingMap.get(networkClientId)) === null || _a === void 0 ? void 0 : _a.incomingTransactionHelper.stop();
446
- });
333
+ startIncomingTransactionPolling() {
334
+ this.incomingTransactionHelper.start();
447
335
  }
448
- stopAllIncomingTransactionPolling() {
336
+ stopIncomingTransactionPolling() {
449
337
  this.incomingTransactionHelper.stop();
450
- if (this.enableMultichain) {
451
- for (const [, trackingMap] of this.trackingMap) {
452
- trackingMap.incomingTransactionHelper.stop();
453
- }
454
- }
455
338
  }
456
- updateIncomingTransactions(networkClientIds = []) {
339
+ updateIncomingTransactions() {
457
340
  return __awaiter(this, void 0, void 0, function* () {
458
- if (networkClientIds.length === 0 || !this.enableMultichain) {
459
- yield this.incomingTransactionHelper.update();
460
- return;
461
- }
462
- yield Promise.allSettled(networkClientIds.map((networkClientId) => __awaiter(this, void 0, void 0, function* () {
463
- var _a;
464
- return yield ((_a = this.trackingMap
465
- .get(networkClientId)) === null || _a === void 0 ? void 0 : _a.incomingTransactionHelper.update());
466
- })));
341
+ yield this.incomingTransactionHelper.update();
467
342
  });
468
343
  }
469
344
  /**
@@ -535,7 +410,7 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
535
410
  to: transactionMeta.txParams.from,
536
411
  value: '0x0',
537
412
  };
538
- const unsignedEthTx = this.prepareUnsignedEthTx(transactionMeta.chainId, newTxParams);
413
+ const unsignedEthTx = this.prepareUnsignedEthTx(newTxParams);
539
414
  const signedTx = yield this.sign(unsignedEthTx, transactionMeta.txParams.from);
540
415
  const rawTx = (0, ethereumjs_util_1.bufferToHex)(signedTx.serialize());
541
416
  const newFee = (_c = newTxParams.maxFeePerGas) !== null && _c !== void 0 ? _c : newTxParams.gasPrice;
@@ -547,15 +422,10 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
547
422
  newFee,
548
423
  txParams: newTxParams,
549
424
  });
550
- const ethQuery = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getEthQuery).call(this, {
551
- networkClientId: transactionMeta.networkClientId,
552
- chainId: transactionMeta.chainId,
553
- });
554
- const hash = yield this.publishTransaction(ethQuery, rawTx);
425
+ const hash = yield this.publishTransaction(rawTx);
555
426
  const cancelTransactionMeta = {
556
427
  actionId,
557
428
  chainId: transactionMeta.chainId,
558
- networkClientId: transactionMeta.networkClientId,
559
429
  estimatedBaseFee,
560
430
  hash,
561
431
  id: (0, uuid_1.v1)(),
@@ -631,7 +501,7 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
631
501
  (existingMaxPriorityFeePerGas && minMaxPriorityFeePerGas);
632
502
  const txParams = newMaxFeePerGas && newMaxPriorityFeePerGas
633
503
  ? Object.assign(Object.assign({}, transactionMeta.txParams), { gasLimit: transactionMeta.txParams.gas, maxFeePerGas: newMaxFeePerGas, maxPriorityFeePerGas: newMaxPriorityFeePerGas, type: types_1.TransactionEnvelopeType.feeMarket }) : Object.assign(Object.assign({}, transactionMeta.txParams), { gasLimit: transactionMeta.txParams.gas, gasPrice: newGasPrice });
634
- const unsignedEthTx = this.prepareUnsignedEthTx(transactionMeta.chainId, txParams);
504
+ const unsignedEthTx = this.prepareUnsignedEthTx(txParams);
635
505
  const signedTx = yield this.sign(unsignedEthTx, transactionMeta.txParams.from);
636
506
  yield this.updateTransactionMetaRSV(transactionMeta, signedTx);
637
507
  const rawTx = (0, ethereumjs_util_1.bufferToHex)(signedTx.serialize());
@@ -640,11 +510,7 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
640
510
  ? transactionMeta.txParams.maxFeePerGas
641
511
  : transactionMeta.txParams.gasPrice;
642
512
  (0, logger_1.projectLogger)('Submitting speed up transaction', { oldFee, newFee, txParams });
643
- const ethQuery = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getEthQuery).call(this, {
644
- networkClientId: transactionMeta.networkClientId,
645
- chainId: transactionMeta.chainId,
646
- });
647
- const hash = yield this.publishTransaction(ethQuery, rawTx);
513
+ const hash = yield (0, controller_utils_1.query)(this.ethQuery, 'sendRawTransaction', [rawTx]);
648
514
  const baseTransactionMeta = Object.assign(Object.assign({}, transactionMeta), { estimatedBaseFee, id: (0, uuid_1.v1)(), time: Date.now(), hash,
649
515
  actionId, originalGasEstimate: transactionMeta.txParams.gas, type: types_1.TransactionType.retry, originalType: transactionMeta.type });
650
516
  const newTransactionMeta = newMaxFeePerGas && newMaxPriorityFeePerGas
@@ -666,13 +532,11 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
666
532
  * Estimates required gas for a given transaction.
667
533
  *
668
534
  * @param transaction - The transaction to estimate gas for.
669
- * @param networkClientId - The network client id to use for the estimate.
670
535
  * @returns The gas and gas price.
671
536
  */
672
- estimateGas(transaction, networkClientId) {
537
+ estimateGas(transaction) {
673
538
  return __awaiter(this, void 0, void 0, function* () {
674
- const ethQuery = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getEthQuery).call(this, { networkClientId });
675
- const { estimatedGas, simulationFails } = yield (0, gas_1.estimateGas)(transaction, ethQuery);
539
+ const { estimatedGas, simulationFails } = yield (0, gas_1.estimateGas)(transaction, this.ethQuery);
676
540
  return { gas: estimatedGas, simulationFails };
677
541
  });
678
542
  }
@@ -681,12 +545,10 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
681
545
  *
682
546
  * @param transaction - The transaction params to estimate gas for.
683
547
  * @param multiplier - The multiplier to use for the gas buffer.
684
- * @param networkClientId - The network client id to use for the estimate.
685
548
  */
686
- estimateGasBuffered(transaction, multiplier, networkClientId) {
549
+ estimateGasBuffered(transaction, multiplier) {
687
550
  return __awaiter(this, void 0, void 0, function* () {
688
- const ethQuery = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getEthQuery).call(this, { networkClientId });
689
- const { blockGasLimit, estimatedGas, simulationFails } = yield (0, gas_1.estimateGas)(transaction, ethQuery);
551
+ const { blockGasLimit, estimatedGas, simulationFails } = yield (0, gas_1.estimateGas)(transaction, this.ethQuery);
690
552
  const gas = (0, gas_1.addGasBuffer)(estimatedGas, blockGasLimit, multiplier);
691
553
  return {
692
554
  gas,
@@ -756,6 +618,12 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
756
618
  transactions: this.trimTransactionsForState(newTransactions),
757
619
  });
758
620
  }
621
+ startIncomingTransactionProcessing() {
622
+ this.incomingTransactionHelper.start();
623
+ }
624
+ stopIncomingTransactionProcessing() {
625
+ this.incomingTransactionHelper.stop();
626
+ }
759
627
  /**
760
628
  * Adds external provided transaction to state as confirmed transaction.
761
629
  *
@@ -906,40 +774,11 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
906
774
  * Ensure `releaseLock` is called once processing of the `nonce` value is complete.
907
775
  *
908
776
  * @param address - The hex string address for the transaction.
909
- * @param networkClientId - The network client ID for the transaction, used to fetch the correct nonce tracker.
910
777
  * @returns object with the `nextNonce` `nonceDetails`, and the releaseLock.
911
778
  */
912
- getNonceLock(address, networkClientId) {
779
+ getNonceLock(address) {
913
780
  return __awaiter(this, void 0, void 0, function* () {
914
- let releaseLockForChainIdKey;
915
- let { nonceTracker } = this;
916
- if (networkClientId && this.enableMultichain) {
917
- const networkClient = this.getNetworkClientById(networkClientId);
918
- releaseLockForChainIdKey = yield __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_acquireNonceLockForChainIdKey).call(this, {
919
- chainId: networkClient.configuration.chainId,
920
- key: address,
921
- });
922
- const trackers = this.trackingMap.get(networkClientId);
923
- if (!trackers) {
924
- throw new Error('missing nonceTracker for networkClientId');
925
- }
926
- nonceTracker = trackers === null || trackers === void 0 ? void 0 : trackers.nonceTracker;
927
- }
928
- // Acquires the lock for the chainId + address and the nonceLock from the nonceTracker, then
929
- // couples them together by replacing the nonceLock's releaseLock method with
930
- // an anonymous function that calls releases both the original nonceLock and the
931
- // lock for the chainId.
932
- try {
933
- const nonceLock = yield nonceTracker.getNonceLock(address);
934
- return Object.assign(Object.assign({}, nonceLock), { releaseLock: () => {
935
- nonceLock.releaseLock();
936
- releaseLockForChainIdKey === null || releaseLockForChainIdKey === void 0 ? void 0 : releaseLockForChainIdKey();
937
- } });
938
- }
939
- catch (err) {
940
- releaseLockForChainIdKey === null || releaseLockForChainIdKey === void 0 ? void 0 : releaseLockForChainIdKey();
941
- throw err;
942
- }
781
+ return this.nonceTracker.getNonceLock(address);
943
782
  });
944
783
  }
945
784
  /**
@@ -974,10 +813,7 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
974
813
  };
975
814
  editableParams.txParams = (0, lodash_1.pickBy)(editableParams.txParams);
976
815
  const updatedTransaction = (0, lodash_1.merge)(transactionMeta, editableParams);
977
- const { type } = yield (0, transaction_type_1.determineTransactionType)(updatedTransaction.txParams, __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getEthQuery).call(this, {
978
- networkClientId: transactionMeta.networkClientId,
979
- chainId: transactionMeta.chainId,
980
- }));
816
+ const { type } = yield (0, transaction_type_1.determineTransactionType)(updatedTransaction.txParams, this.ethQuery);
981
817
  updatedTransaction.type = type;
982
818
  this.updateTransaction(updatedTransaction, `Update Editable Params for ${txId}`);
983
819
  return this.getTransaction(txId);
@@ -987,9 +823,11 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
987
823
  * Signs and returns the raw transaction data for provided transaction params list.
988
824
  *
989
825
  * @param listOfTxParams - The list of transaction params to approve.
826
+ * @param opts - Options bag.
827
+ * @param opts.hasNonce - Whether the transactions already have a nonce.
990
828
  * @returns The raw transactions.
991
829
  */
992
- approveTransactionsWithSameNonce(listOfTxParams = []) {
830
+ approveTransactionsWithSameNonce(listOfTxParams = [], { hasNonce } = {}) {
993
831
  return __awaiter(this, void 0, void 0, function* () {
994
832
  (0, logger_1.projectLogger)('Approving transactions with same nonce', {
995
833
  transactions: listOfTxParams,
@@ -998,7 +836,7 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
998
836
  return '';
999
837
  }
1000
838
  const initialTx = listOfTxParams[0];
1001
- const common = this.getCommonConfiguration(initialTx.chainId);
839
+ const common = this.getCommonConfiguration();
1002
840
  const initialTxAsEthTx = tx_1.TransactionFactory.fromTxData(initialTx, {
1003
841
  common,
1004
842
  });
@@ -1011,12 +849,19 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1011
849
  try {
1012
850
  // TODO: we should add a check to verify that all transactions have the same from address
1013
851
  const fromAddress = initialTx.from;
1014
- nonceLock = yield this.getNonceLock(fromAddress);
1015
- const nonce = nonceLock.nextNonce;
1016
- (0, logger_1.projectLogger)('Using nonce from nonce tracker', nonce, nonceLock.nonceDetails);
852
+ const requiresNonce = hasNonce !== true;
853
+ nonceLock = requiresNonce
854
+ ? yield this.nonceTracker.getNonceLock(fromAddress)
855
+ : undefined;
856
+ const nonce = nonceLock
857
+ ? (0, ethereumjs_util_1.addHexPrefix)(nonceLock.nextNonce.toString(16))
858
+ : initialTx.nonce;
859
+ if (nonceLock) {
860
+ (0, logger_1.projectLogger)('Using nonce from nonce tracker', nonce, nonceLock.nonceDetails);
861
+ }
1017
862
  rawTransactions = yield Promise.all(listOfTxParams.map((txParams) => {
1018
- txParams.nonce = (0, ethereumjs_util_1.addHexPrefix)(nonce.toString(16));
1019
- return this.signExternalTransaction(txParams.chainId, txParams);
863
+ txParams.nonce = nonce;
864
+ return this.signExternalTransaction(txParams);
1020
865
  }));
1021
866
  }
1022
867
  catch (err) {
@@ -1026,9 +871,7 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1026
871
  throw err;
1027
872
  }
1028
873
  finally {
1029
- if (nonceLock) {
1030
- nonceLock.releaseLock();
1031
- }
874
+ nonceLock === null || nonceLock === void 0 ? void 0 : nonceLock.releaseLock();
1032
875
  this.inProcessOfSigning.delete(initialTxAsSerializedHex);
1033
876
  }
1034
877
  return rawTransactions;
@@ -1176,18 +1019,19 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1176
1019
  }
1177
1020
  return filteredTransactions;
1178
1021
  }
1179
- signExternalTransaction(chainId, transactionParams) {
1022
+ signExternalTransaction(transactionParams) {
1180
1023
  return __awaiter(this, void 0, void 0, function* () {
1181
1024
  if (!this.sign) {
1182
1025
  throw new Error('No sign method defined.');
1183
1026
  }
1184
1027
  const normalizedTransactionParams = (0, utils_1.normalizeTxParams)(transactionParams);
1028
+ const chainId = this.getChainId();
1185
1029
  const type = (0, utils_1.isEIP1559Transaction)(normalizedTransactionParams)
1186
1030
  ? types_1.TransactionEnvelopeType.feeMarket
1187
1031
  : types_1.TransactionEnvelopeType.legacy;
1188
1032
  const updatedTransactionParams = Object.assign(Object.assign({}, normalizedTransactionParams), { type, gasLimit: normalizedTransactionParams.gas, chainId });
1189
1033
  const { from } = updatedTransactionParams;
1190
- const common = this.getCommonConfiguration(chainId);
1034
+ const common = this.getCommonConfiguration();
1191
1035
  const unsignedTransaction = tx_1.TransactionFactory.fromTxData(updatedTransactionParams, { common });
1192
1036
  const signedTransaction = yield this.sign(unsignedTransaction, from);
1193
1037
  const rawTransaction = (0, ethereumjs_util_1.bufferToHex)(signedTransaction.serialize());
@@ -1225,36 +1069,35 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1225
1069
  }
1226
1070
  updateGasProperties(transactionMeta) {
1227
1071
  return __awaiter(this, void 0, void 0, function* () {
1228
- const isEIP1559Compatible = (yield this.getEIP1559Compatibility(transactionMeta.networkClientId)) &&
1072
+ const isEIP1559Compatible = (yield this.getEIP1559Compatibility()) &&
1229
1073
  transactionMeta.txParams.type !== types_1.TransactionEnvelopeType.legacy;
1230
- const { networkClientId, chainId } = transactionMeta;
1231
- const isCustomNetwork = networkClientId
1232
- ? this.getNetworkClientById(networkClientId).configuration.type ===
1233
- network_controller_1.NetworkClientType.Custom
1234
- : this.getNetworkState().providerConfig.type === controller_utils_1.NetworkType.rpc;
1074
+ const chainId = this.getChainId();
1235
1075
  yield (0, gas_1.updateGas)({
1236
- ethQuery: __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getEthQuery).call(this, { networkClientId, chainId }),
1237
- chainId,
1238
- isCustomNetwork,
1076
+ ethQuery: this.ethQuery,
1077
+ providerConfig: this.getNetworkState().providerConfig,
1239
1078
  txMeta: transactionMeta,
1240
1079
  });
1241
1080
  yield (0, gas_fees_1.updateGasFees)({
1242
1081
  eip1559: isEIP1559Compatible,
1243
- ethQuery: __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getEthQuery).call(this, { networkClientId, chainId }),
1244
- getSavedGasFees: this.getSavedGasFees.bind(this),
1082
+ ethQuery: this.ethQuery,
1083
+ getSavedGasFees: this.getSavedGasFees.bind(this, chainId),
1245
1084
  getGasFeeEstimates: this.getGasFeeEstimates.bind(this),
1246
1085
  txMeta: transactionMeta,
1247
1086
  });
1248
1087
  });
1249
1088
  }
1089
+ getCurrentChainTransactionsByStatus(status) {
1090
+ const chainId = this.getChainId();
1091
+ return this.state.transactions.filter((transaction) => transaction.status === status && transaction.chainId === chainId);
1092
+ }
1250
1093
  onBootCleanup() {
1251
1094
  this.submitApprovedTransactions();
1252
1095
  }
1253
1096
  /**
1254
- * Force submit approved transactions for all chains.
1097
+ * Force to submit approved transactions on current chain.
1255
1098
  */
1256
1099
  submitApprovedTransactions() {
1257
- const approvedTransactions = this.state.transactions.filter((transaction) => transaction.status === types_1.TransactionStatus.approved);
1100
+ const approvedTransactions = this.getCurrentChainTransactionsByStatus(types_1.TransactionStatus.approved);
1258
1101
  for (const transactionMeta of approvedTransactions) {
1259
1102
  if (this.beforeApproveOnInit(transactionMeta)) {
1260
1103
  this.approveTransaction(transactionMeta.id).catch((error) => {
@@ -1348,9 +1191,10 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1348
1191
  return __awaiter(this, void 0, void 0, function* () {
1349
1192
  const { transactions } = this.state;
1350
1193
  const releaseLock = yield this.mutex.acquire();
1194
+ const chainId = this.getChainId();
1351
1195
  const index = transactions.findIndex(({ id }) => transactionId === id);
1352
1196
  const transactionMeta = transactions[index];
1353
- const { txParams: { from }, networkClientId, } = transactionMeta;
1197
+ const { txParams: { from }, } = transactionMeta;
1354
1198
  let releaseNonceLock;
1355
1199
  try {
1356
1200
  if (!this.sign) {
@@ -1358,7 +1202,7 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1358
1202
  this.failTransaction(transactionMeta, new Error('No sign method defined.'));
1359
1203
  return;
1360
1204
  }
1361
- else if (!transactionMeta.chainId) {
1205
+ else if (!chainId) {
1362
1206
  releaseLock();
1363
1207
  this.failTransaction(transactionMeta, new Error('No chainId defined.'));
1364
1208
  return;
@@ -1367,11 +1211,11 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1367
1211
  (0, logger_1.projectLogger)('Skipping approval as signing in progress', transactionId);
1368
1212
  return;
1369
1213
  }
1370
- const [nonce, releaseNonce] = yield (0, nonce_1.getNextNonce)(transactionMeta, (address) => this.getNonceLock(address, networkClientId));
1214
+ const [nonce, releaseNonce] = yield (0, nonce_1.getNextNonce)(transactionMeta, this.nonceTracker);
1371
1215
  releaseNonceLock = releaseNonce;
1372
1216
  transactionMeta.status = types_1.TransactionStatus.approved;
1373
1217
  transactionMeta.txParams.nonce = nonce;
1374
- transactionMeta.txParams.chainId = transactionMeta.chainId;
1218
+ transactionMeta.txParams.chainId = chainId;
1375
1219
  const baseTxParams = Object.assign(Object.assign({}, transactionMeta.txParams), { gasLimit: transactionMeta.txParams.gas });
1376
1220
  this.updateTransaction(transactionMeta, 'TransactionController#approveTransaction - Transaction approved');
1377
1221
  this.onTransactionStatusChange(transactionMeta);
@@ -1387,18 +1231,17 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1387
1231
  if (!rawTx) {
1388
1232
  return;
1389
1233
  }
1390
- const ethQuery = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getEthQuery).call(this, {
1391
- networkClientId: transactionMeta.networkClientId,
1392
- chainId: transactionMeta.chainId,
1393
- });
1394
1234
  if (transactionMeta.type === types_1.TransactionType.swap) {
1395
1235
  (0, logger_1.projectLogger)('Determining pre-transaction balance');
1396
- const preTxBalance = yield (0, controller_utils_1.query)(ethQuery, 'getBalance', [from]);
1236
+ const preTxBalance = yield (0, controller_utils_1.query)(this.ethQuery, 'getBalance', [from]);
1397
1237
  transactionMeta.preTxBalance = preTxBalance;
1398
1238
  (0, logger_1.projectLogger)('Updated pre-transaction balance', transactionMeta.preTxBalance);
1399
1239
  }
1400
1240
  (0, logger_1.projectLogger)('Publishing transaction', txParams);
1401
- const hash = yield this.publishTransaction(ethQuery, rawTx);
1241
+ let { transactionHash: hash } = yield this.publish(transactionMeta, rawTx);
1242
+ if (hash === undefined) {
1243
+ hash = yield this.publishTransaction(rawTx);
1244
+ }
1402
1245
  (0, logger_1.projectLogger)('Publish successful', hash);
1403
1246
  transactionMeta.hash = hash;
1404
1247
  transactionMeta.status = types_1.TransactionStatus.submitted;
@@ -1423,9 +1266,9 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1423
1266
  }
1424
1267
  });
1425
1268
  }
1426
- publishTransaction(ethQuery, rawTransaction) {
1269
+ publishTransaction(rawTransaction) {
1427
1270
  return __awaiter(this, void 0, void 0, function* () {
1428
- return yield (0, controller_utils_1.query)(ethQuery, 'sendRawTransaction', [rawTransaction]);
1271
+ return yield (0, controller_utils_1.query)(this.ethQuery, 'sendRawTransaction', [rawTransaction]);
1429
1272
  });
1430
1273
  }
1431
1274
  /**
@@ -1541,17 +1384,14 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1541
1384
  const isCompleted = this.isLocalFinalState(transaction.status);
1542
1385
  return { meta: transaction, isCompleted };
1543
1386
  }
1544
- getChainId(networkClientId) {
1545
- if (networkClientId) {
1546
- return this.getNetworkClientById(networkClientId).configuration.chainId;
1547
- }
1387
+ getChainId() {
1548
1388
  const { providerConfig } = this.getNetworkState();
1549
1389
  return providerConfig.chainId;
1550
1390
  }
1551
- prepareUnsignedEthTx(chainId, txParams) {
1391
+ prepareUnsignedEthTx(txParams) {
1552
1392
  return tx_1.TransactionFactory.fromTxData(txParams, {
1393
+ common: this.getCommonConfiguration(),
1553
1394
  freeze: false,
1554
- common: this.getCommonConfiguration(chainId),
1555
1395
  });
1556
1396
  }
1557
1397
  /**
@@ -1561,11 +1401,17 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1561
1401
  * specified in txParams, @ethereumjs/tx is able to determine which EIP-2718
1562
1402
  * transaction type to use.
1563
1403
  *
1564
- * @param chainId - The chainId to use for the configuration.
1565
1404
  * @returns common configuration object
1566
1405
  */
1567
- getCommonConfiguration(chainId) {
1406
+ getCommonConfiguration() {
1407
+ const { providerConfig: { type: chain, chainId, nickname: name }, } = this.getNetworkState();
1408
+ if (chain !== controller_utils_1.RPC &&
1409
+ chain !== controller_utils_1.NetworkType['linea-goerli'] &&
1410
+ chain !== controller_utils_1.NetworkType['linea-mainnet']) {
1411
+ return new common_1.Common({ chain, hardfork: exports.HARDFORK });
1412
+ }
1568
1413
  const customChainParams = {
1414
+ name,
1569
1415
  chainId: parseInt(chainId, 16),
1570
1416
  defaultHardfork: exports.HARDFORK,
1571
1417
  };
@@ -1620,7 +1466,7 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1620
1466
  */
1621
1467
  addExternalTransaction(transactionMeta) {
1622
1468
  var _a, _b;
1623
- const { chainId } = transactionMeta;
1469
+ const chainId = this.getChainId();
1624
1470
  const { transactions } = this.state;
1625
1471
  const fromAddress = (_a = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.txParams) === null || _a === void 0 ? void 0 : _a.from;
1626
1472
  const sameFromAndNetworkTransactions = transactions.filter((transaction) => transaction.txParams.from === fromAddress &&
@@ -1647,13 +1493,10 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1647
1493
  */
1648
1494
  markNonceDuplicatesDropped(transactionId) {
1649
1495
  var _a, _b;
1496
+ const chainId = this.getChainId();
1650
1497
  const transactionMeta = this.getTransaction(transactionId);
1651
- if (!transactionMeta) {
1652
- return;
1653
- }
1654
- const nonce = (_a = transactionMeta.txParams) === null || _a === void 0 ? void 0 : _a.nonce;
1655
- const from = (_b = transactionMeta.txParams) === null || _b === void 0 ? void 0 : _b.from;
1656
- const { chainId } = transactionMeta;
1498
+ const nonce = (_a = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.txParams) === null || _a === void 0 ? void 0 : _a.nonce;
1499
+ const from = (_b = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.txParams) === null || _b === void 0 ? void 0 : _b.from;
1657
1500
  const sameNonceTxs = this.state.transactions.filter((transaction) => transaction.id !== transactionId &&
1658
1501
  transaction.txParams.from === from &&
1659
1502
  transaction.txParams.nonce === nonce &&
@@ -1664,8 +1507,8 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1664
1507
  }
1665
1508
  // Mark all same nonce transactions as dropped and give it a replacedBy hash
1666
1509
  for (const transaction of sameNonceTxs) {
1667
- transaction.replacedBy = transactionMeta.hash;
1668
- transaction.replacedById = transactionMeta.id;
1510
+ transaction.replacedBy = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.hash;
1511
+ transaction.replacedById = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.id;
1669
1512
  // Drop any transaction that wasn't previously failed (off chain failure)
1670
1513
  if (transaction.status !== types_1.TransactionStatus.failed) {
1671
1514
  this.setTransactionStatusDropped(transaction);
@@ -1721,37 +1564,23 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1721
1564
  }
1722
1565
  });
1723
1566
  }
1724
- getEIP1559Compatibility(networkClientId) {
1567
+ getEIP1559Compatibility() {
1725
1568
  return __awaiter(this, void 0, void 0, function* () {
1726
- const currentNetworkIsEIP1559Compatible = yield this.getCurrentNetworkEIP1559Compatibility(networkClientId);
1569
+ const currentNetworkIsEIP1559Compatible = yield this.getCurrentNetworkEIP1559Compatibility();
1727
1570
  const currentAccountIsEIP1559Compatible = yield this.getCurrentAccountEIP1559Compatibility();
1728
1571
  return (currentNetworkIsEIP1559Compatible && currentAccountIsEIP1559Compatible);
1729
1572
  });
1730
1573
  }
1731
- removeIncomingTransactionHelperListeners(incomingTransactionHelper = this.incomingTransactionHelper) {
1732
- incomingTransactionHelper.hub.removeAllListeners('transactions');
1733
- incomingTransactionHelper.hub.removeAllListeners('updatedLastFetchedBlockNumbers');
1734
- }
1735
- addIncomingTransactionHelperListeners(incomingTransactionHelper = this.incomingTransactionHelper) {
1736
- incomingTransactionHelper.hub.on('transactions', this.onIncomingTransactions.bind(this));
1737
- incomingTransactionHelper.hub.on('updatedLastFetchedBlockNumbers', this.onUpdatedLastFetchedBlockNumbers.bind(this));
1738
- }
1739
- removePendingTransactionTrackerListeners(pendingTransactionTracker = this.pendingTransactionTracker) {
1740
- pendingTransactionTracker.hub.removeAllListeners('transaction-confirmed');
1741
- pendingTransactionTracker.hub.removeAllListeners('transaction-dropped');
1742
- pendingTransactionTracker.hub.removeAllListeners('transaction-failed');
1743
- pendingTransactionTracker.hub.removeAllListeners('transaction-updated');
1744
- }
1745
- addPendingTransactionTrackerListeners(pendingTransactionTracker = this.pendingTransactionTracker) {
1746
- pendingTransactionTracker.hub.on('transaction-confirmed', this.onConfirmedTransaction.bind(this));
1747
- pendingTransactionTracker.hub.on('transaction-dropped', this.setTransactionStatusDropped.bind(this));
1748
- pendingTransactionTracker.hub.on('transaction-failed', this.failTransaction.bind(this));
1749
- pendingTransactionTracker.hub.on('transaction-updated', this.updateTransaction.bind(this));
1574
+ addPendingTransactionTrackerListeners() {
1575
+ this.pendingTransactionTracker.hub.on('transaction-confirmed', this.onConfirmedTransaction.bind(this));
1576
+ this.pendingTransactionTracker.hub.on('transaction-dropped', this.setTransactionStatusDropped.bind(this));
1577
+ this.pendingTransactionTracker.hub.on('transaction-failed', this.failTransaction.bind(this));
1578
+ this.pendingTransactionTracker.hub.on('transaction-updated', this.updateTransaction.bind(this));
1750
1579
  }
1751
1580
  signTransaction(transactionMeta, txParams) {
1752
1581
  return __awaiter(this, void 0, void 0, function* () {
1753
1582
  (0, logger_1.projectLogger)('Signing transaction', txParams);
1754
- const unsignedEthTx = this.prepareUnsignedEthTx(transactionMeta.chainId, txParams);
1583
+ const unsignedEthTx = this.prepareUnsignedEthTx(txParams);
1755
1584
  this.inProcessOfSigning.add(transactionMeta.id);
1756
1585
  const signedTx = yield new Promise((resolve, reject) => {
1757
1586
  var _a;
@@ -1781,13 +1610,14 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1781
1610
  onTransactionStatusChange(transactionMeta) {
1782
1611
  this.hub.emit('transaction-status-update', { transactionMeta });
1783
1612
  }
1784
- getNonceTrackerPendingTransactions(chainId, address) {
1785
- const standardPendingTransactions = this.getNonceTrackerTransactions(types_1.TransactionStatus.submitted, address, chainId);
1786
- const externalPendingTransactions = this.getExternalPendingTransactions(address, chainId);
1613
+ getNonceTrackerPendingTransactions(address) {
1614
+ const standardPendingTransactions = this.getNonceTrackerTransactions(types_1.TransactionStatus.submitted, address);
1615
+ const externalPendingTransactions = this.getExternalPendingTransactions(address);
1787
1616
  return [...standardPendingTransactions, ...externalPendingTransactions];
1788
1617
  }
1789
- getNonceTrackerTransactions(status, address, chainId = this.getChainId()) {
1790
- return (0, nonce_1.getAndFormatTransactionsForNonceTracker)(chainId, address, status, this.state.transactions);
1618
+ getNonceTrackerTransactions(status, address) {
1619
+ const currentChainId = this.getChainId();
1620
+ return (0, nonce_1.getAndFormatTransactionsForNonceTracker)(currentChainId, address, status, this.state.transactions);
1791
1621
  }
1792
1622
  onConfirmedTransaction(transactionMeta) {
1793
1623
  (0, logger_1.projectLogger)('Processing confirmed transaction', transactionMeta.id);
@@ -1805,12 +1635,8 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1805
1635
  if (transactionMeta.type !== types_1.TransactionType.swap) {
1806
1636
  return;
1807
1637
  }
1808
- const ethQuery = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getEthQuery).call(this, {
1809
- networkClientId: transactionMeta.networkClientId,
1810
- chainId: transactionMeta.chainId,
1811
- });
1812
1638
  const { updatedTransactionMeta, approvalTransactionMeta } = yield (0, swaps_1.updatePostTransactionBalance)(transactionMeta, {
1813
- ethQuery,
1639
+ ethQuery: this.ethQuery,
1814
1640
  getTransaction: this.getTransaction.bind(this),
1815
1641
  updateTransaction: this.updateTransaction.bind(this),
1816
1642
  });
@@ -1827,127 +1653,4 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1827
1653
  }
1828
1654
  }
1829
1655
  exports.TransactionController = TransactionController;
1830
- _TransactionController_refreshEtherscanRemoteTransactionSources = new WeakMap(), _TransactionController_refreshTrackingMap = new WeakMap(), _TransactionController_initTrackingMap = new WeakMap(), _TransactionController_checkForPendingTransactionAndStartPolling = new WeakMap(), _TransactionController_instances = new WeakSet(), _TransactionController_acquireNonceLockForChainIdKey = function _TransactionController_acquireNonceLockForChainIdKey({ chainId, key = 'global', }) {
1831
- return __awaiter(this, void 0, void 0, function* () {
1832
- let nonceMutexesForChainId = this.nonceMutexesByChainId.get(chainId);
1833
- if (!nonceMutexesForChainId) {
1834
- nonceMutexesForChainId = new Map();
1835
- this.nonceMutexesByChainId.set(chainId, nonceMutexesForChainId);
1836
- }
1837
- let nonceMutexForKey = nonceMutexesForChainId.get(key);
1838
- if (!nonceMutexForKey) {
1839
- nonceMutexForKey = new async_mutex_1.Mutex();
1840
- nonceMutexesForChainId.set(key, nonceMutexForKey);
1841
- }
1842
- return yield nonceMutexForKey.acquire();
1843
- });
1844
- }, _TransactionController_getEthQuery = function _TransactionController_getEthQuery({ networkClientId, chainId, }) {
1845
- // if multichain is disabled, use the global ethQuery
1846
- if (!this.enableMultichain) {
1847
- return this.ethQuery;
1848
- }
1849
- let networkClient;
1850
- if (networkClientId) {
1851
- try {
1852
- networkClient = this.getNetworkClientById(networkClientId);
1853
- }
1854
- catch (err) {
1855
- (0, logger_1.projectLogger)('failed to get network client by networkClientId');
1856
- }
1857
- }
1858
- if (!networkClient && chainId) {
1859
- try {
1860
- networkClientId = this.findNetworkClientIdByChainId(chainId);
1861
- networkClient = this.getNetworkClientById(networkClientId);
1862
- }
1863
- catch (err) {
1864
- (0, logger_1.projectLogger)('failed to get network client by chainId');
1865
- }
1866
- }
1867
- if (networkClient) {
1868
- return new eth_query_1.default(networkClient.provider);
1869
- }
1870
- // NOTE(JL): we're not ready to drop globally selected ethQuery yet.
1871
- // Some calls to getEthQuery only have access to optional networkClientId
1872
- // throw new Error('failed to get eth query instance');
1873
- return this.ethQuery;
1874
- }, _TransactionController_stopTrackingByNetworkClientId = function _TransactionController_stopTrackingByNetworkClientId(networkClientId) {
1875
- const trackers = this.trackingMap.get(networkClientId);
1876
- if (trackers) {
1877
- trackers.pendingTransactionTracker.stop();
1878
- this.removePendingTransactionTrackerListeners(trackers.pendingTransactionTracker);
1879
- trackers.incomingTransactionHelper.stop();
1880
- this.removeIncomingTransactionHelperListeners(trackers.incomingTransactionHelper);
1881
- this.trackingMap.delete(networkClientId);
1882
- this.hub.emit('tracking-map-remove', networkClientId);
1883
- }
1884
- }, _TransactionController_stopAllTracking = function _TransactionController_stopAllTracking() {
1885
- this.pendingTransactionTracker.stop();
1886
- this.removePendingTransactionTrackerListeners();
1887
- this.incomingTransactionHelper.stop();
1888
- this.removeIncomingTransactionHelperListeners();
1889
- if (this.enableMultichain) {
1890
- for (const [networkClientId] of this.trackingMap) {
1891
- __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_stopTrackingByNetworkClientId).call(this, networkClientId);
1892
- }
1893
- }
1894
- }, _TransactionController_startTrackingByNetworkClientId = function _TransactionController_startTrackingByNetworkClientId(networkClientId) {
1895
- const trackers = this.trackingMap.get(networkClientId);
1896
- if (trackers) {
1897
- return;
1898
- }
1899
- const networkClient = this.getNetworkClientById(networkClientId);
1900
- const { chainId } = networkClient.configuration;
1901
- let etherscanRemoteTransactionSource = this.etherscanRemoteTransactionSourcesMap.get(chainId);
1902
- if (!etherscanRemoteTransactionSource) {
1903
- etherscanRemoteTransactionSource = new EtherscanRemoteTransactionSource_1.EtherscanRemoteTransactionSource({
1904
- includeTokenTransfers: this.incomingTransactionOptions.includeTokenTransfers,
1905
- });
1906
- this.etherscanRemoteTransactionSourcesMap.set(chainId, etherscanRemoteTransactionSource);
1907
- }
1908
- const ethQuery = new eth_query_1.default(networkClient.provider);
1909
- const nonceTracker = new nonce_tracker_1.NonceTracker({
1910
- // TODO: Replace `any` with type
1911
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1912
- provider: networkClient.provider,
1913
- blockTracker: networkClient.blockTracker,
1914
- getPendingTransactions: this.getNonceTrackerPendingTransactions.bind(this, chainId),
1915
- getConfirmedTransactions: this.getNonceTrackerTransactions.bind(this, types_1.TransactionStatus.confirmed),
1916
- });
1917
- const incomingTransactionHelper = new IncomingTransactionHelper_1.IncomingTransactionHelper({
1918
- blockTracker: networkClient.blockTracker,
1919
- getCurrentAccount: this.getSelectedAddress,
1920
- getLastFetchedBlockNumbers: () => this.state.lastFetchedBlockNumbers,
1921
- getChainId: () => chainId,
1922
- isEnabled: this.incomingTransactionOptions.isEnabled,
1923
- queryEntireHistory: this.incomingTransactionOptions.queryEntireHistory,
1924
- remoteTransactionSource: etherscanRemoteTransactionSource,
1925
- transactionLimit: this.config.txHistoryLimit,
1926
- updateTransactions: this.incomingTransactionOptions.updateTransactions,
1927
- });
1928
- this.addIncomingTransactionHelperListeners(incomingTransactionHelper);
1929
- const pendingTransactionTracker = new PendingTransactionTracker_1.PendingTransactionTracker({
1930
- approveTransaction: this.approveTransaction.bind(this),
1931
- blockTracker: networkClient.blockTracker,
1932
- getChainId: () => chainId,
1933
- getEthQuery: () => ethQuery,
1934
- getTransactions: () => this.state.transactions,
1935
- isResubmitEnabled: this.pendingTransactionOptions.isResubmitEnabled,
1936
- getGlobalLock: __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_acquireNonceLockForChainIdKey).bind(this, {
1937
- chainId,
1938
- }),
1939
- publishTransaction: this.publishTransaction.bind(this),
1940
- hooks: {
1941
- beforeCheckPendingTransaction: this.beforeCheckPendingTransaction.bind(this),
1942
- beforePublish: this.beforePublish.bind(this),
1943
- },
1944
- });
1945
- this.addPendingTransactionTrackerListeners(pendingTransactionTracker);
1946
- this.trackingMap.set(networkClientId, {
1947
- nonceTracker,
1948
- incomingTransactionHelper,
1949
- pendingTransactionTracker,
1950
- });
1951
- this.hub.emit('tracking-map-add', networkClientId);
1952
- };
1953
1656
  //# sourceMappingURL=TransactionController.js.map