@metamask-previews/transaction-controller 21.1.0-preview.cbe2fbb7 → 21.1.0-preview.d392f46

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 (35) hide show
  1. package/dist/TransactionController.d.ts +30 -78
  2. package/dist/TransactionController.d.ts.map +1 -1
  3. package/dist/TransactionController.js +104 -414
  4. package/dist/TransactionController.js.map +1 -1
  5. package/dist/helpers/EtherscanRemoteTransactionSource.d.ts.map +1 -1
  6. package/dist/helpers/EtherscanRemoteTransactionSource.js +8 -28
  7. package/dist/helpers/EtherscanRemoteTransactionSource.js.map +1 -1
  8. package/dist/helpers/IncomingTransactionHelper.d.ts +3 -3
  9. package/dist/helpers/IncomingTransactionHelper.d.ts.map +1 -1
  10. package/dist/helpers/IncomingTransactionHelper.js +14 -17
  11. package/dist/helpers/IncomingTransactionHelper.js.map +1 -1
  12. package/dist/helpers/PendingTransactionTracker.d.ts +7 -7
  13. package/dist/helpers/PendingTransactionTracker.d.ts.map +1 -1
  14. package/dist/helpers/PendingTransactionTracker.js +26 -26
  15. package/dist/helpers/PendingTransactionTracker.js.map +1 -1
  16. package/dist/types.d.ts +0 -8
  17. package/dist/types.d.ts.map +1 -1
  18. package/dist/types.js.map +1 -1
  19. package/dist/utils/etherscan.d.ts +0 -7
  20. package/dist/utils/etherscan.d.ts.map +1 -1
  21. package/dist/utils/etherscan.js +6 -16
  22. package/dist/utils/etherscan.js.map +1 -1
  23. package/dist/utils/gas-fees.d.ts +3 -4
  24. package/dist/utils/gas-fees.d.ts.map +1 -1
  25. package/dist/utils/gas-fees.js +2 -6
  26. package/dist/utils/gas-fees.js.map +1 -1
  27. package/dist/utils/gas.d.ts +2 -3
  28. package/dist/utils/gas.d.ts.map +1 -1
  29. package/dist/utils/gas.js +5 -4
  30. package/dist/utils/gas.js.map +1 -1
  31. package/dist/utils/nonce.d.ts +3 -3
  32. package/dist/utils/nonce.d.ts.map +1 -1
  33. package/dist/utils/nonce.js +3 -3
  34. package/dist/utils/nonce.js.map +1 -1
  35. package/package.json +1 -2
@@ -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,31 @@ 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.
102
95
  * @param config - Initial options used to configure this controller.
103
96
  * @param state - Initial state to set on this controller.
104
97
  */
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) {
98
+ constructor({ blockTracker, cancelMultiplier, disableHistory, disableSendFlowHistory, disableSwaps, getCurrentAccountEIP1559Compatibility, getCurrentNetworkEIP1559Compatibility, getExternalPendingTransactions, getGasFeeEstimates, getNetworkState, getPermittedAccounts, getSavedGasFees, getSelectedAddress, incomingTransactions = {}, messenger, onNetworkStateChange, pendingTransactions = {}, provider, securityProviderRequest, speedUpMultiplier, hooks = {}, }, config, state) {
106
99
  var _a, _b, _c, _d, _e;
107
100
  super(config, state);
108
- _TransactionController_instances.add(this);
109
101
  this.inProcessOfSigning = new Set();
110
102
  this.mutex = new async_mutex_1.Mutex();
111
- this.nonceMutexesByChainId = new Map();
112
103
  this.signAbortCallbacks = new Map();
113
104
  /**
114
105
  * EventEmitter instance used to listen to specific transactional events
@@ -118,50 +109,6 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
118
109
  * Name of this controller used during composition
119
110
  */
120
111
  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
112
  this.defaultConfig = {
166
113
  txHistoryLimit: 40,
167
114
  };
@@ -171,11 +118,6 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
171
118
  lastFetchedBlockNumbers: {},
172
119
  };
173
120
  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
121
  this.provider = provider;
180
122
  this.messagingSystem = messenger;
181
123
  this.getNetworkState = getNetworkState;
@@ -199,8 +141,6 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
199
141
  this.securityProviderRequest = securityProviderRequest;
200
142
  this.cancelMultiplier = cancelMultiplier !== null && cancelMultiplier !== void 0 ? cancelMultiplier : exports.CANCEL_RATE;
201
143
  this.speedUpMultiplier = speedUpMultiplier !== null && speedUpMultiplier !== void 0 ? speedUpMultiplier : exports.SPEED_UP_RATE;
202
- this.incomingTransactionOptions = incomingTransactions;
203
- this.pendingTransactionOptions = pendingTransactions;
204
144
  this.afterSign = (_a = hooks === null || hooks === void 0 ? void 0 : hooks.afterSign) !== null && _a !== void 0 ? _a : (() => true);
205
145
  this.beforeApproveOnInit = (_b = hooks === null || hooks === void 0 ? void 0 : hooks.beforeApproveOnInit) !== null && _b !== void 0 ? _b : (() => true);
206
146
  this.beforeCheckPendingTransaction =
@@ -214,24 +154,24 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
214
154
  // @ts-expect-error provider types misaligned: SafeEventEmitterProvider vs Record<string,string>
215
155
  provider,
216
156
  blockTracker,
217
- getPendingTransactions: this.getNonceTrackerPendingTransactions.bind(this, undefined),
157
+ getPendingTransactions: this.getNonceTrackerPendingTransactions.bind(this),
218
158
  getConfirmedTransactions: this.getNonceTrackerTransactions.bind(this, types_1.TransactionStatus.confirmed),
219
159
  });
220
- const etherscanRemoteTransactionSource = new EtherscanRemoteTransactionSource_1.EtherscanRemoteTransactionSource({
221
- includeTokenTransfers: incomingTransactions.includeTokenTransfers,
222
- });
223
160
  this.incomingTransactionHelper = new IncomingTransactionHelper_1.IncomingTransactionHelper({
224
161
  blockTracker,
225
162
  getCurrentAccount: getSelectedAddress,
226
163
  getLastFetchedBlockNumbers: () => this.state.lastFetchedBlockNumbers,
227
- getChainId: this.getChainId.bind(this),
164
+ getNetworkState,
228
165
  isEnabled: incomingTransactions.isEnabled,
229
166
  queryEntireHistory: incomingTransactions.queryEntireHistory,
230
- remoteTransactionSource: etherscanRemoteTransactionSource,
167
+ remoteTransactionSource: new EtherscanRemoteTransactionSource_1.EtherscanRemoteTransactionSource({
168
+ includeTokenTransfers: incomingTransactions.includeTokenTransfers,
169
+ }),
231
170
  transactionLimit: this.config.txHistoryLimit,
232
171
  updateTransactions: incomingTransactions.updateTransactions,
233
172
  });
234
- this.addIncomingTransactionHelperListeners();
173
+ this.incomingTransactionHelper.hub.on('transactions', this.onIncomingTransactions.bind(this));
174
+ this.incomingTransactionHelper.hub.on('updatedLastFetchedBlockNumbers', this.onUpdatedLastFetchedBlockNumbers.bind(this));
235
175
  this.pendingTransactionTracker = new PendingTransactionTracker_1.PendingTransactionTracker({
236
176
  approveTransaction: this.approveTransaction.bind(this),
237
177
  blockTracker,
@@ -239,11 +179,12 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
239
179
  getEthQuery: () => this.ethQuery,
240
180
  getTransactions: () => this.state.transactions,
241
181
  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
- }),
182
+ nonceTracker: this.nonceTracker,
183
+ onStateChange: (listener) => {
184
+ this.subscribe(listener);
185
+ onNetworkStateChange(listener);
186
+ listener();
187
+ },
247
188
  publishTransaction: this.publishTransaction.bind(this),
248
189
  hooks: {
249
190
  beforeCheckPendingTransaction: this.beforeCheckPendingTransaction.bind(this),
@@ -251,32 +192,11 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
251
192
  },
252
193
  });
253
194
  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
195
  onNetworkStateChange(() => {
260
196
  (0, logger_1.projectLogger)('Detected network change', this.getChainId());
261
- this.pendingTransactionTracker.startIfPendingTransactions();
262
197
  this.onBootCleanup();
263
198
  });
264
199
  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
200
  }
281
201
  failTransaction(transactionMeta, error, actionId) {
282
202
  const newTransactionMeta = Object.assign(Object.assign({}, transactionMeta), { error: (0, utils_1.normalizeTxError)(error), status: types_1.TransactionStatus.failed });
@@ -296,18 +216,6 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
296
216
  return { registryMethod, parsedRegistryMethod };
297
217
  });
298
218
  }
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
219
  /**
312
220
  * Handle new method data request.
313
221
  *
@@ -352,26 +260,21 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
352
260
  * @param opts.swaps - Options for swaps transactions.
353
261
  * @param opts.swaps.hasApproveTx - Whether the transaction has an approval transaction.
354
262
  * @param opts.swaps.meta - Metadata for swap transaction.
355
- * @param opts.networkClientId - The id of the network client for this transaction.
356
263
  * @returns Object containing a promise resolving to the transaction hash if approved.
357
264
  */
358
- addTransaction(txParams, { actionId, deviceConfirmedOn, method, origin, requireApproval, securityAlertResponse, sendFlowHistory, swaps = {}, type, networkClientId, } = {}) {
265
+ addTransaction(txParams, { actionId, deviceConfirmedOn, method, origin, requireApproval, securityAlertResponse, sendFlowHistory, swaps = {}, type, } = {}) {
359
266
  return __awaiter(this, void 0, void 0, function* () {
360
267
  (0, logger_1.projectLogger)('Adding transaction', txParams);
361
268
  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);
269
+ const isEIP1559Compatible = yield this.getEIP1559Compatibility();
366
270
  (0, validation_1.validateTxParams)(txParams, isEIP1559Compatible);
367
271
  if (origin) {
368
272
  yield (0, validation_1.validateTransactionOrigin)(yield this.getPermittedAccounts(origin), this.getSelectedAddress(), txParams.from, origin);
369
273
  }
370
274
  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;
275
+ const transactionType = type !== null && type !== void 0 ? type : (yield (0, transaction_type_1.determineTransactionType)(txParams, this.ethQuery)).type;
374
276
  const existingTransactionMeta = this.getTransactionWithActionId(actionId);
277
+ const chainId = this.getChainId();
375
278
  // If a request to add a transaction with the same actionId is submitted again, a new transaction will not be created for it.
376
279
  const transactionMeta = existingTransactionMeta || {
377
280
  // Add actionId to txMeta to check if same actionId is seen again
@@ -388,7 +291,6 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
388
291
  userEditedGasLimit: false,
389
292
  verifiedOnBlockchain: false,
390
293
  type: transactionType,
391
- networkClientId,
392
294
  };
393
295
  yield this.updateGasProperties(transactionMeta);
394
296
  // Checks if a transaction already exists with a given actionId
@@ -425,45 +327,15 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
425
327
  };
426
328
  });
427
329
  }
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
- });
330
+ startIncomingTransactionPolling() {
331
+ this.incomingTransactionHelper.start();
447
332
  }
448
- stopAllIncomingTransactionPolling() {
333
+ stopIncomingTransactionPolling() {
449
334
  this.incomingTransactionHelper.stop();
450
- if (this.enableMultichain) {
451
- for (const [, trackingMap] of this.trackingMap) {
452
- trackingMap.incomingTransactionHelper.stop();
453
- }
454
- }
455
335
  }
456
- updateIncomingTransactions(networkClientIds = []) {
336
+ updateIncomingTransactions() {
457
337
  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
- })));
338
+ yield this.incomingTransactionHelper.update();
467
339
  });
468
340
  }
469
341
  /**
@@ -535,7 +407,7 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
535
407
  to: transactionMeta.txParams.from,
536
408
  value: '0x0',
537
409
  };
538
- const unsignedEthTx = this.prepareUnsignedEthTx(transactionMeta.chainId, newTxParams);
410
+ const unsignedEthTx = this.prepareUnsignedEthTx(newTxParams);
539
411
  const signedTx = yield this.sign(unsignedEthTx, transactionMeta.txParams.from);
540
412
  const rawTx = (0, ethereumjs_util_1.bufferToHex)(signedTx.serialize());
541
413
  const newFee = (_c = newTxParams.maxFeePerGas) !== null && _c !== void 0 ? _c : newTxParams.gasPrice;
@@ -547,15 +419,10 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
547
419
  newFee,
548
420
  txParams: newTxParams,
549
421
  });
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);
422
+ const hash = yield this.publishTransaction(rawTx);
555
423
  const cancelTransactionMeta = {
556
424
  actionId,
557
425
  chainId: transactionMeta.chainId,
558
- networkClientId: transactionMeta.networkClientId,
559
426
  estimatedBaseFee,
560
427
  hash,
561
428
  id: (0, uuid_1.v1)(),
@@ -631,7 +498,7 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
631
498
  (existingMaxPriorityFeePerGas && minMaxPriorityFeePerGas);
632
499
  const txParams = newMaxFeePerGas && newMaxPriorityFeePerGas
633
500
  ? 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);
501
+ const unsignedEthTx = this.prepareUnsignedEthTx(txParams);
635
502
  const signedTx = yield this.sign(unsignedEthTx, transactionMeta.txParams.from);
636
503
  yield this.updateTransactionMetaRSV(transactionMeta, signedTx);
637
504
  const rawTx = (0, ethereumjs_util_1.bufferToHex)(signedTx.serialize());
@@ -640,11 +507,7 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
640
507
  ? transactionMeta.txParams.maxFeePerGas
641
508
  : transactionMeta.txParams.gasPrice;
642
509
  (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);
510
+ const hash = yield (0, controller_utils_1.query)(this.ethQuery, 'sendRawTransaction', [rawTx]);
648
511
  const baseTransactionMeta = Object.assign(Object.assign({}, transactionMeta), { estimatedBaseFee, id: (0, uuid_1.v1)(), time: Date.now(), hash,
649
512
  actionId, originalGasEstimate: transactionMeta.txParams.gas, type: types_1.TransactionType.retry, originalType: transactionMeta.type });
650
513
  const newTransactionMeta = newMaxFeePerGas && newMaxPriorityFeePerGas
@@ -666,13 +529,11 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
666
529
  * Estimates required gas for a given transaction.
667
530
  *
668
531
  * @param transaction - The transaction to estimate gas for.
669
- * @param networkClientId - The network client id to use for the estimate.
670
532
  * @returns The gas and gas price.
671
533
  */
672
- estimateGas(transaction, networkClientId) {
534
+ estimateGas(transaction) {
673
535
  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);
536
+ const { estimatedGas, simulationFails } = yield (0, gas_1.estimateGas)(transaction, this.ethQuery);
676
537
  return { gas: estimatedGas, simulationFails };
677
538
  });
678
539
  }
@@ -681,12 +542,10 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
681
542
  *
682
543
  * @param transaction - The transaction params to estimate gas for.
683
544
  * @param multiplier - The multiplier to use for the gas buffer.
684
- * @param networkClientId - The network client id to use for the estimate.
685
545
  */
686
- estimateGasBuffered(transaction, multiplier, networkClientId) {
546
+ estimateGasBuffered(transaction, multiplier) {
687
547
  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);
548
+ const { blockGasLimit, estimatedGas, simulationFails } = yield (0, gas_1.estimateGas)(transaction, this.ethQuery);
690
549
  const gas = (0, gas_1.addGasBuffer)(estimatedGas, blockGasLimit, multiplier);
691
550
  return {
692
551
  gas,
@@ -756,6 +615,12 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
756
615
  transactions: this.trimTransactionsForState(newTransactions),
757
616
  });
758
617
  }
618
+ startIncomingTransactionProcessing() {
619
+ this.incomingTransactionHelper.start();
620
+ }
621
+ stopIncomingTransactionProcessing() {
622
+ this.incomingTransactionHelper.stop();
623
+ }
759
624
  /**
760
625
  * Adds external provided transaction to state as confirmed transaction.
761
626
  *
@@ -906,40 +771,11 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
906
771
  * Ensure `releaseLock` is called once processing of the `nonce` value is complete.
907
772
  *
908
773
  * @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
774
  * @returns object with the `nextNonce` `nonceDetails`, and the releaseLock.
911
775
  */
912
- getNonceLock(address, networkClientId) {
776
+ getNonceLock(address) {
913
777
  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
- }
778
+ return this.nonceTracker.getNonceLock(address);
943
779
  });
944
780
  }
945
781
  /**
@@ -974,10 +810,7 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
974
810
  };
975
811
  editableParams.txParams = (0, lodash_1.pickBy)(editableParams.txParams);
976
812
  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
- }));
813
+ const { type } = yield (0, transaction_type_1.determineTransactionType)(updatedTransaction.txParams, this.ethQuery);
981
814
  updatedTransaction.type = type;
982
815
  this.updateTransaction(updatedTransaction, `Update Editable Params for ${txId}`);
983
816
  return this.getTransaction(txId);
@@ -998,7 +831,7 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
998
831
  return '';
999
832
  }
1000
833
  const initialTx = listOfTxParams[0];
1001
- const common = this.getCommonConfiguration(initialTx.chainId);
834
+ const common = this.getCommonConfiguration();
1002
835
  const initialTxAsEthTx = tx_1.TransactionFactory.fromTxData(initialTx, {
1003
836
  common,
1004
837
  });
@@ -1011,12 +844,12 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1011
844
  try {
1012
845
  // TODO: we should add a check to verify that all transactions have the same from address
1013
846
  const fromAddress = initialTx.from;
1014
- nonceLock = yield this.getNonceLock(fromAddress);
847
+ nonceLock = yield this.nonceTracker.getNonceLock(fromAddress);
1015
848
  const nonce = nonceLock.nextNonce;
1016
849
  (0, logger_1.projectLogger)('Using nonce from nonce tracker', nonce, nonceLock.nonceDetails);
1017
850
  rawTransactions = yield Promise.all(listOfTxParams.map((txParams) => {
1018
851
  txParams.nonce = (0, ethereumjs_util_1.addHexPrefix)(nonce.toString(16));
1019
- return this.signExternalTransaction(txParams.chainId, txParams);
852
+ return this.signExternalTransaction(txParams);
1020
853
  }));
1021
854
  }
1022
855
  catch (err) {
@@ -1176,18 +1009,19 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1176
1009
  }
1177
1010
  return filteredTransactions;
1178
1011
  }
1179
- signExternalTransaction(chainId, transactionParams) {
1012
+ signExternalTransaction(transactionParams) {
1180
1013
  return __awaiter(this, void 0, void 0, function* () {
1181
1014
  if (!this.sign) {
1182
1015
  throw new Error('No sign method defined.');
1183
1016
  }
1184
1017
  const normalizedTransactionParams = (0, utils_1.normalizeTxParams)(transactionParams);
1018
+ const chainId = this.getChainId();
1185
1019
  const type = (0, utils_1.isEIP1559Transaction)(normalizedTransactionParams)
1186
1020
  ? types_1.TransactionEnvelopeType.feeMarket
1187
1021
  : types_1.TransactionEnvelopeType.legacy;
1188
1022
  const updatedTransactionParams = Object.assign(Object.assign({}, normalizedTransactionParams), { type, gasLimit: normalizedTransactionParams.gas, chainId });
1189
1023
  const { from } = updatedTransactionParams;
1190
- const common = this.getCommonConfiguration(chainId);
1024
+ const common = this.getCommonConfiguration();
1191
1025
  const unsignedTransaction = tx_1.TransactionFactory.fromTxData(updatedTransactionParams, { common });
1192
1026
  const signedTransaction = yield this.sign(unsignedTransaction, from);
1193
1027
  const rawTransaction = (0, ethereumjs_util_1.bufferToHex)(signedTransaction.serialize());
@@ -1225,36 +1059,35 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1225
1059
  }
1226
1060
  updateGasProperties(transactionMeta) {
1227
1061
  return __awaiter(this, void 0, void 0, function* () {
1228
- const isEIP1559Compatible = (yield this.getEIP1559Compatibility(transactionMeta.networkClientId)) &&
1062
+ const isEIP1559Compatible = (yield this.getEIP1559Compatibility()) &&
1229
1063
  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;
1064
+ const chainId = this.getChainId();
1235
1065
  yield (0, gas_1.updateGas)({
1236
- ethQuery: __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getEthQuery).call(this, { networkClientId, chainId }),
1237
- chainId,
1238
- isCustomNetwork,
1066
+ ethQuery: this.ethQuery,
1067
+ providerConfig: this.getNetworkState().providerConfig,
1239
1068
  txMeta: transactionMeta,
1240
1069
  });
1241
1070
  yield (0, gas_fees_1.updateGasFees)({
1242
1071
  eip1559: isEIP1559Compatible,
1243
- ethQuery: __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getEthQuery).call(this, { networkClientId, chainId }),
1244
- getSavedGasFees: this.getSavedGasFees.bind(this),
1072
+ ethQuery: this.ethQuery,
1073
+ getSavedGasFees: this.getSavedGasFees.bind(this, chainId),
1245
1074
  getGasFeeEstimates: this.getGasFeeEstimates.bind(this),
1246
1075
  txMeta: transactionMeta,
1247
1076
  });
1248
1077
  });
1249
1078
  }
1079
+ getCurrentChainTransactionsByStatus(status) {
1080
+ const chainId = this.getChainId();
1081
+ return this.state.transactions.filter((transaction) => transaction.status === status && transaction.chainId === chainId);
1082
+ }
1250
1083
  onBootCleanup() {
1251
1084
  this.submitApprovedTransactions();
1252
1085
  }
1253
1086
  /**
1254
- * Force submit approved transactions for all chains.
1087
+ * Force to submit approved transactions on current chain.
1255
1088
  */
1256
1089
  submitApprovedTransactions() {
1257
- const approvedTransactions = this.state.transactions.filter((transaction) => transaction.status === types_1.TransactionStatus.approved);
1090
+ const approvedTransactions = this.getCurrentChainTransactionsByStatus(types_1.TransactionStatus.approved);
1258
1091
  for (const transactionMeta of approvedTransactions) {
1259
1092
  if (this.beforeApproveOnInit(transactionMeta)) {
1260
1093
  this.approveTransaction(transactionMeta.id).catch((error) => {
@@ -1348,9 +1181,10 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1348
1181
  return __awaiter(this, void 0, void 0, function* () {
1349
1182
  const { transactions } = this.state;
1350
1183
  const releaseLock = yield this.mutex.acquire();
1184
+ const chainId = this.getChainId();
1351
1185
  const index = transactions.findIndex(({ id }) => transactionId === id);
1352
1186
  const transactionMeta = transactions[index];
1353
- const { txParams: { from }, networkClientId, } = transactionMeta;
1187
+ const { txParams: { from }, } = transactionMeta;
1354
1188
  let releaseNonceLock;
1355
1189
  try {
1356
1190
  if (!this.sign) {
@@ -1358,7 +1192,7 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1358
1192
  this.failTransaction(transactionMeta, new Error('No sign method defined.'));
1359
1193
  return;
1360
1194
  }
1361
- else if (!transactionMeta.chainId) {
1195
+ else if (!chainId) {
1362
1196
  releaseLock();
1363
1197
  this.failTransaction(transactionMeta, new Error('No chainId defined.'));
1364
1198
  return;
@@ -1367,11 +1201,11 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1367
1201
  (0, logger_1.projectLogger)('Skipping approval as signing in progress', transactionId);
1368
1202
  return;
1369
1203
  }
1370
- const [nonce, releaseNonce] = yield (0, nonce_1.getNextNonce)(transactionMeta, (address) => this.getNonceLock(address, networkClientId));
1204
+ const [nonce, releaseNonce] = yield (0, nonce_1.getNextNonce)(transactionMeta, this.nonceTracker);
1371
1205
  releaseNonceLock = releaseNonce;
1372
1206
  transactionMeta.status = types_1.TransactionStatus.approved;
1373
1207
  transactionMeta.txParams.nonce = nonce;
1374
- transactionMeta.txParams.chainId = transactionMeta.chainId;
1208
+ transactionMeta.txParams.chainId = chainId;
1375
1209
  const baseTxParams = Object.assign(Object.assign({}, transactionMeta.txParams), { gasLimit: transactionMeta.txParams.gas });
1376
1210
  this.updateTransaction(transactionMeta, 'TransactionController#approveTransaction - Transaction approved');
1377
1211
  this.onTransactionStatusChange(transactionMeta);
@@ -1387,18 +1221,14 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1387
1221
  if (!rawTx) {
1388
1222
  return;
1389
1223
  }
1390
- const ethQuery = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getEthQuery).call(this, {
1391
- networkClientId: transactionMeta.networkClientId,
1392
- chainId: transactionMeta.chainId,
1393
- });
1394
1224
  if (transactionMeta.type === types_1.TransactionType.swap) {
1395
1225
  (0, logger_1.projectLogger)('Determining pre-transaction balance');
1396
- const preTxBalance = yield (0, controller_utils_1.query)(ethQuery, 'getBalance', [from]);
1226
+ const preTxBalance = yield (0, controller_utils_1.query)(this.ethQuery, 'getBalance', [from]);
1397
1227
  transactionMeta.preTxBalance = preTxBalance;
1398
1228
  (0, logger_1.projectLogger)('Updated pre-transaction balance', transactionMeta.preTxBalance);
1399
1229
  }
1400
1230
  (0, logger_1.projectLogger)('Publishing transaction', txParams);
1401
- const hash = yield this.publishTransaction(ethQuery, rawTx);
1231
+ const hash = yield this.publishTransaction(rawTx);
1402
1232
  (0, logger_1.projectLogger)('Publish successful', hash);
1403
1233
  transactionMeta.hash = hash;
1404
1234
  transactionMeta.status = types_1.TransactionStatus.submitted;
@@ -1423,9 +1253,9 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1423
1253
  }
1424
1254
  });
1425
1255
  }
1426
- publishTransaction(ethQuery, rawTransaction) {
1256
+ publishTransaction(rawTransaction) {
1427
1257
  return __awaiter(this, void 0, void 0, function* () {
1428
- return yield (0, controller_utils_1.query)(ethQuery, 'sendRawTransaction', [rawTransaction]);
1258
+ return yield (0, controller_utils_1.query)(this.ethQuery, 'sendRawTransaction', [rawTransaction]);
1429
1259
  });
1430
1260
  }
1431
1261
  /**
@@ -1541,17 +1371,14 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1541
1371
  const isCompleted = this.isLocalFinalState(transaction.status);
1542
1372
  return { meta: transaction, isCompleted };
1543
1373
  }
1544
- getChainId(networkClientId) {
1545
- if (networkClientId) {
1546
- return this.getNetworkClientById(networkClientId).configuration.chainId;
1547
- }
1374
+ getChainId() {
1548
1375
  const { providerConfig } = this.getNetworkState();
1549
1376
  return providerConfig.chainId;
1550
1377
  }
1551
- prepareUnsignedEthTx(chainId, txParams) {
1378
+ prepareUnsignedEthTx(txParams) {
1552
1379
  return tx_1.TransactionFactory.fromTxData(txParams, {
1380
+ common: this.getCommonConfiguration(),
1553
1381
  freeze: false,
1554
- common: this.getCommonConfiguration(chainId),
1555
1382
  });
1556
1383
  }
1557
1384
  /**
@@ -1561,11 +1388,17 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1561
1388
  * specified in txParams, @ethereumjs/tx is able to determine which EIP-2718
1562
1389
  * transaction type to use.
1563
1390
  *
1564
- * @param chainId - The chainId to use for the configuration.
1565
1391
  * @returns common configuration object
1566
1392
  */
1567
- getCommonConfiguration(chainId) {
1393
+ getCommonConfiguration() {
1394
+ const { providerConfig: { type: chain, chainId, nickname: name }, } = this.getNetworkState();
1395
+ if (chain !== controller_utils_1.RPC &&
1396
+ chain !== controller_utils_1.NetworkType['linea-goerli'] &&
1397
+ chain !== controller_utils_1.NetworkType['linea-mainnet']) {
1398
+ return new common_1.Common({ chain, hardfork: exports.HARDFORK });
1399
+ }
1568
1400
  const customChainParams = {
1401
+ name,
1569
1402
  chainId: parseInt(chainId, 16),
1570
1403
  defaultHardfork: exports.HARDFORK,
1571
1404
  };
@@ -1620,7 +1453,7 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1620
1453
  */
1621
1454
  addExternalTransaction(transactionMeta) {
1622
1455
  var _a, _b;
1623
- const { chainId } = transactionMeta;
1456
+ const chainId = this.getChainId();
1624
1457
  const { transactions } = this.state;
1625
1458
  const fromAddress = (_a = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.txParams) === null || _a === void 0 ? void 0 : _a.from;
1626
1459
  const sameFromAndNetworkTransactions = transactions.filter((transaction) => transaction.txParams.from === fromAddress &&
@@ -1647,13 +1480,10 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1647
1480
  */
1648
1481
  markNonceDuplicatesDropped(transactionId) {
1649
1482
  var _a, _b;
1483
+ const chainId = this.getChainId();
1650
1484
  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;
1485
+ const nonce = (_a = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.txParams) === null || _a === void 0 ? void 0 : _a.nonce;
1486
+ const from = (_b = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.txParams) === null || _b === void 0 ? void 0 : _b.from;
1657
1487
  const sameNonceTxs = this.state.transactions.filter((transaction) => transaction.id !== transactionId &&
1658
1488
  transaction.txParams.from === from &&
1659
1489
  transaction.txParams.nonce === nonce &&
@@ -1664,8 +1494,8 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1664
1494
  }
1665
1495
  // Mark all same nonce transactions as dropped and give it a replacedBy hash
1666
1496
  for (const transaction of sameNonceTxs) {
1667
- transaction.replacedBy = transactionMeta.hash;
1668
- transaction.replacedById = transactionMeta.id;
1497
+ transaction.replacedBy = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.hash;
1498
+ transaction.replacedById = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.id;
1669
1499
  // Drop any transaction that wasn't previously failed (off chain failure)
1670
1500
  if (transaction.status !== types_1.TransactionStatus.failed) {
1671
1501
  this.setTransactionStatusDropped(transaction);
@@ -1721,37 +1551,23 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1721
1551
  }
1722
1552
  });
1723
1553
  }
1724
- getEIP1559Compatibility(networkClientId) {
1554
+ getEIP1559Compatibility() {
1725
1555
  return __awaiter(this, void 0, void 0, function* () {
1726
- const currentNetworkIsEIP1559Compatible = yield this.getCurrentNetworkEIP1559Compatibility(networkClientId);
1556
+ const currentNetworkIsEIP1559Compatible = yield this.getCurrentNetworkEIP1559Compatibility();
1727
1557
  const currentAccountIsEIP1559Compatible = yield this.getCurrentAccountEIP1559Compatibility();
1728
1558
  return (currentNetworkIsEIP1559Compatible && currentAccountIsEIP1559Compatible);
1729
1559
  });
1730
1560
  }
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));
1561
+ addPendingTransactionTrackerListeners() {
1562
+ this.pendingTransactionTracker.hub.on('transaction-confirmed', this.onConfirmedTransaction.bind(this));
1563
+ this.pendingTransactionTracker.hub.on('transaction-dropped', this.setTransactionStatusDropped.bind(this));
1564
+ this.pendingTransactionTracker.hub.on('transaction-failed', this.failTransaction.bind(this));
1565
+ this.pendingTransactionTracker.hub.on('transaction-updated', this.updateTransaction.bind(this));
1750
1566
  }
1751
1567
  signTransaction(transactionMeta, txParams) {
1752
1568
  return __awaiter(this, void 0, void 0, function* () {
1753
1569
  (0, logger_1.projectLogger)('Signing transaction', txParams);
1754
- const unsignedEthTx = this.prepareUnsignedEthTx(transactionMeta.chainId, txParams);
1570
+ const unsignedEthTx = this.prepareUnsignedEthTx(txParams);
1755
1571
  this.inProcessOfSigning.add(transactionMeta.id);
1756
1572
  const signedTx = yield new Promise((resolve, reject) => {
1757
1573
  var _a;
@@ -1781,13 +1597,14 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1781
1597
  onTransactionStatusChange(transactionMeta) {
1782
1598
  this.hub.emit('transaction-status-update', { transactionMeta });
1783
1599
  }
1784
- getNonceTrackerPendingTransactions(chainId, address) {
1785
- const standardPendingTransactions = this.getNonceTrackerTransactions(types_1.TransactionStatus.submitted, address, chainId);
1786
- const externalPendingTransactions = this.getExternalPendingTransactions(address, chainId);
1600
+ getNonceTrackerPendingTransactions(address) {
1601
+ const standardPendingTransactions = this.getNonceTrackerTransactions(types_1.TransactionStatus.submitted, address);
1602
+ const externalPendingTransactions = this.getExternalPendingTransactions(address);
1787
1603
  return [...standardPendingTransactions, ...externalPendingTransactions];
1788
1604
  }
1789
- getNonceTrackerTransactions(status, address, chainId = this.getChainId()) {
1790
- return (0, nonce_1.getAndFormatTransactionsForNonceTracker)(chainId, address, status, this.state.transactions);
1605
+ getNonceTrackerTransactions(status, address) {
1606
+ const currentChainId = this.getChainId();
1607
+ return (0, nonce_1.getAndFormatTransactionsForNonceTracker)(currentChainId, address, status, this.state.transactions);
1791
1608
  }
1792
1609
  onConfirmedTransaction(transactionMeta) {
1793
1610
  (0, logger_1.projectLogger)('Processing confirmed transaction', transactionMeta.id);
@@ -1805,12 +1622,8 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1805
1622
  if (transactionMeta.type !== types_1.TransactionType.swap) {
1806
1623
  return;
1807
1624
  }
1808
- const ethQuery = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getEthQuery).call(this, {
1809
- networkClientId: transactionMeta.networkClientId,
1810
- chainId: transactionMeta.chainId,
1811
- });
1812
1625
  const { updatedTransactionMeta, approvalTransactionMeta } = yield (0, swaps_1.updatePostTransactionBalance)(transactionMeta, {
1813
- ethQuery,
1626
+ ethQuery: this.ethQuery,
1814
1627
  getTransaction: this.getTransaction.bind(this),
1815
1628
  updateTransaction: this.updateTransaction.bind(this),
1816
1629
  });
@@ -1827,127 +1640,4 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1827
1640
  }
1828
1641
  }
1829
1642
  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
1643
  //# sourceMappingURL=TransactionController.js.map