@metamask/transaction-controller 21.2.0 → 23.0.0

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 (40) hide show
  1. package/CHANGELOG.md +58 -1
  2. package/dist/TransactionController.d.ts +113 -113
  3. package/dist/TransactionController.d.ts.map +1 -1
  4. package/dist/TransactionController.js +315 -181
  5. package/dist/TransactionController.js.map +1 -1
  6. package/dist/helpers/EtherscanRemoteTransactionSource.d.ts.map +1 -1
  7. package/dist/helpers/EtherscanRemoteTransactionSource.js +28 -8
  8. package/dist/helpers/EtherscanRemoteTransactionSource.js.map +1 -1
  9. package/dist/helpers/IncomingTransactionHelper.d.ts +17 -3
  10. package/dist/helpers/IncomingTransactionHelper.d.ts.map +1 -1
  11. package/dist/helpers/IncomingTransactionHelper.js +17 -14
  12. package/dist/helpers/IncomingTransactionHelper.js.map +1 -1
  13. package/dist/helpers/MultichainTrackingHelper.d.ts +72 -0
  14. package/dist/helpers/MultichainTrackingHelper.d.ts.map +1 -0
  15. package/dist/helpers/MultichainTrackingHelper.js +292 -0
  16. package/dist/helpers/MultichainTrackingHelper.js.map +1 -0
  17. package/dist/helpers/PendingTransactionTracker.d.ts +13 -7
  18. package/dist/helpers/PendingTransactionTracker.d.ts.map +1 -1
  19. package/dist/helpers/PendingTransactionTracker.js +43 -23
  20. package/dist/helpers/PendingTransactionTracker.js.map +1 -1
  21. package/dist/types.d.ts +5 -0
  22. package/dist/types.d.ts.map +1 -1
  23. package/dist/types.js.map +1 -1
  24. package/dist/utils/etherscan.d.ts +7 -0
  25. package/dist/utils/etherscan.d.ts.map +1 -1
  26. package/dist/utils/etherscan.js +17 -6
  27. package/dist/utils/etherscan.js.map +1 -1
  28. package/dist/utils/gas-fees.d.ts +4 -3
  29. package/dist/utils/gas-fees.d.ts.map +1 -1
  30. package/dist/utils/gas-fees.js +6 -2
  31. package/dist/utils/gas-fees.js.map +1 -1
  32. package/dist/utils/gas.d.ts +3 -2
  33. package/dist/utils/gas.d.ts.map +1 -1
  34. package/dist/utils/gas.js +4 -5
  35. package/dist/utils/gas.js.map +1 -1
  36. package/dist/utils/nonce.d.ts +3 -3
  37. package/dist/utils/nonce.d.ts.map +1 -1
  38. package/dist/utils/nonce.js +3 -3
  39. package/dist/utils/nonce.js.map +1 -1
  40. package/package.json +9 -8
@@ -8,9 +8,21 @@ 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 __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
12
+ if (kind === "m") throw new TypeError("Private method is not writable");
13
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
15
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
16
+ };
17
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
18
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
19
+ 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");
20
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
21
+ };
11
22
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
23
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
24
  };
25
+ var _TransactionController_instances, _TransactionController_incomingTransactionOptions, _TransactionController_pendingTransactionOptions, _TransactionController_multichainTrackingHelper, _TransactionController_createNonceTracker, _TransactionController_createIncomingTransactionHelper, _TransactionController_createPendingTransactionTracker, _TransactionController_checkForPendingTransactionAndStartPolling, _TransactionController_stopAllTracking, _TransactionController_removeIncomingTransactionHelperListeners, _TransactionController_addIncomingTransactionHelperListeners, _TransactionController_removePendingTransactionTrackerListeners, _TransactionController_addPendingTransactionTrackerListeners, _TransactionController_getNonceTrackerPendingTransactions;
14
26
  Object.defineProperty(exports, "__esModule", { value: true });
15
27
  exports.TransactionController = exports.SPEED_UP_RATE = exports.CANCEL_RATE = exports.HARDFORK = void 0;
16
28
  const common_1 = require("@ethereumjs/common");
@@ -18,6 +30,7 @@ const tx_1 = require("@ethereumjs/tx");
18
30
  const base_controller_1 = require("@metamask/base-controller");
19
31
  const controller_utils_1 = require("@metamask/controller-utils");
20
32
  const eth_query_1 = __importDefault(require("@metamask/eth-query"));
33
+ const network_controller_1 = require("@metamask/network-controller");
21
34
  const rpc_errors_1 = require("@metamask/rpc-errors");
22
35
  const async_mutex_1 = require("async-mutex");
23
36
  const eth_method_registry_1 = require("eth-method-registry");
@@ -28,6 +41,7 @@ const nonce_tracker_1 = require("nonce-tracker");
28
41
  const uuid_1 = require("uuid");
29
42
  const EtherscanRemoteTransactionSource_1 = require("./helpers/EtherscanRemoteTransactionSource");
30
43
  const IncomingTransactionHelper_1 = require("./helpers/IncomingTransactionHelper");
44
+ const MultichainTrackingHelper_1 = require("./helpers/MultichainTrackingHelper");
31
45
  const PendingTransactionTracker_1 = require("./helpers/PendingTransactionTracker");
32
46
  const logger_1 = require("./logger");
33
47
  const types_1 = require("./types");
@@ -44,7 +58,7 @@ exports.HARDFORK = common_1.Hardfork.London;
44
58
  /**
45
59
  * Multiplier used to determine a transaction's increased gas fee during cancellation
46
60
  */
47
- exports.CANCEL_RATE = 1.5;
61
+ exports.CANCEL_RATE = 1.1;
48
62
  /**
49
63
  * Multiplier used to determine a transaction's increased gas fee during speed up
50
64
  */
@@ -57,51 +71,16 @@ const controllerName = 'TransactionController';
57
71
  * Controller responsible for submitting and managing transactions.
58
72
  */
59
73
  class TransactionController extends base_controller_1.BaseControllerV1 {
60
- /**
61
- * Creates a TransactionController instance.
62
- *
63
- * @param options - The controller options.
64
- * @param options.blockTracker - The block tracker used to poll for new blocks data.
65
- * @param options.cancelMultiplier - Multiplier used to determine a transaction's increased gas fee during cancellation.
66
- * @param options.disableHistory - Whether to disable storing history in transaction metadata.
67
- * @param options.disableSendFlowHistory - Explicitly disable transaction metadata history.
68
- * @param options.disableSwaps - Whether to disable additional processing on swaps transactions.
69
- * @param options.getCurrentAccountEIP1559Compatibility - Whether or not the account supports EIP-1559.
70
- * @param options.getCurrentNetworkEIP1559Compatibility - Whether or not the network supports EIP-1559.
71
- * @param options.getExternalPendingTransactions - Callback to retrieve pending transactions from external sources.
72
- * @param options.getGasFeeEstimates - Callback to retrieve gas fee estimates.
73
- * @param options.getNetworkState - Gets the state of the network controller.
74
- * @param options.getPermittedAccounts - Get accounts that a given origin has permissions for.
75
- * @param options.getSavedGasFees - Gets the saved gas fee config.
76
- * @param options.getSelectedAddress - Gets the address of the currently selected account.
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.
82
- * @param options.messenger - The controller messenger.
83
- * @param options.onNetworkStateChange - Allows subscribing to network controller state changes.
84
- * @param options.pendingTransactions - Configuration options for pending transaction support.
85
- * @param options.pendingTransactions.isResubmitEnabled - Whether transaction publishing is automatically retried.
86
- * @param options.provider - The provider used to create the underlying EthQuery instance.
87
- * @param options.securityProviderRequest - A function for verifying a transaction, whether it is malicious or not.
88
- * @param options.speedUpMultiplier - Multiplier used to determine a transaction's increased gas fee during speed up.
89
- * @param options.hooks - The controller hooks.
90
- * @param options.hooks.afterSign - Additional logic to execute after signing a transaction. Return false to not change the status to signed.
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.
92
- * @param options.hooks.beforeCheckPendingTransaction - Additional logic to execute before checking pending transactions. Return false to prevent the broadcast of the transaction.
93
- * @param options.hooks.beforePublish - Additional logic to execute before publishing a transaction. Return false to prevent the broadcast of the transaction.
94
- * @param options.hooks.getAdditionalSignArguments - Returns additional arguments required to sign a transaction.
95
- * @param options.hooks.publish - Alternate logic to publish a transaction.
96
- * @param config - Initial options used to configure this controller.
97
- * @param state - Initial state to set on this controller.
98
- */
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) {
74
+ constructor({ blockTracker, disableHistory, disableSendFlowHistory, disableSwaps, getCurrentAccountEIP1559Compatibility, getCurrentNetworkEIP1559Compatibility, getExternalPendingTransactions, getGasFeeEstimates, getNetworkState, getPermittedAccounts, getSavedGasFees, getSelectedAddress, incomingTransactions = {}, messenger, onNetworkStateChange, pendingTransactions = {}, provider, securityProviderRequest, getNetworkClientRegistry, isMultichainEnabled = false, hooks, }, config, state) {
100
75
  var _a, _b, _c, _d, _e, _f;
101
76
  super(config, state);
77
+ _TransactionController_instances.add(this);
102
78
  this.inProcessOfSigning = new Set();
103
79
  this.mutex = new async_mutex_1.Mutex();
80
+ _TransactionController_incomingTransactionOptions.set(this, void 0);
81
+ _TransactionController_pendingTransactionOptions.set(this, void 0);
104
82
  this.signAbortCallbacks = new Map();
83
+ _TransactionController_multichainTrackingHelper.set(this, void 0);
105
84
  /**
106
85
  * EventEmitter instance used to listen to specific transactional events
107
86
  */
@@ -110,6 +89,11 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
110
89
  * Name of this controller used during composition
111
90
  */
112
91
  this.name = 'TransactionController';
92
+ _TransactionController_checkForPendingTransactionAndStartPolling.set(this, () => {
93
+ // PendingTransactionTracker reads state through its getTransactions hook
94
+ this.pendingTransactionTracker.startIfPendingTransactions();
95
+ __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").checkForPendingTransactionAndStartPolling();
96
+ });
113
97
  this.defaultConfig = {
114
98
  txHistoryLimit: 40,
115
99
  };
@@ -119,10 +103,8 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
119
103
  lastFetchedBlockNumbers: {},
120
104
  };
121
105
  this.initialize();
122
- this.provider = provider;
123
106
  this.messagingSystem = messenger;
124
107
  this.getNetworkState = getNetworkState;
125
- this.ethQuery = new eth_query_1.default(provider);
126
108
  this.isSendFlowHistoryDisabled = disableSendFlowHistory !== null && disableSendFlowHistory !== void 0 ? disableSendFlowHistory : false;
127
109
  this.isHistoryDisabled = disableHistory !== null && disableHistory !== void 0 ? disableHistory : false;
128
110
  this.isSwapsDisabled = disableSwaps !== null && disableSwaps !== void 0 ? disableSwaps : false;
@@ -140,8 +122,8 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
140
122
  this.getExternalPendingTransactions =
141
123
  getExternalPendingTransactions !== null && getExternalPendingTransactions !== void 0 ? getExternalPendingTransactions : (() => []);
142
124
  this.securityProviderRequest = securityProviderRequest;
143
- this.cancelMultiplier = cancelMultiplier !== null && cancelMultiplier !== void 0 ? cancelMultiplier : exports.CANCEL_RATE;
144
- this.speedUpMultiplier = speedUpMultiplier !== null && speedUpMultiplier !== void 0 ? speedUpMultiplier : exports.SPEED_UP_RATE;
125
+ __classPrivateFieldSet(this, _TransactionController_incomingTransactionOptions, incomingTransactions, "f");
126
+ __classPrivateFieldSet(this, _TransactionController_pendingTransactionOptions, pendingTransactions, "f");
145
127
  this.afterSign = (_a = hooks === null || hooks === void 0 ? void 0 : hooks.afterSign) !== null && _a !== void 0 ? _a : (() => true);
146
128
  this.beforeApproveOnInit = (_b = hooks === null || hooks === void 0 ? void 0 : hooks.beforeApproveOnInit) !== null && _b !== void 0 ? _b : (() => true);
147
129
  this.beforeCheckPendingTransaction =
@@ -153,50 +135,51 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
153
135
  (_e = hooks === null || hooks === void 0 ? void 0 : hooks.getAdditionalSignArguments) !== null && _e !== void 0 ? _e : (() => []);
154
136
  this.publish =
155
137
  (_f = hooks === null || hooks === void 0 ? void 0 : hooks.publish) !== null && _f !== void 0 ? _f : (() => Promise.resolve({ transactionHash: undefined }));
156
- this.nonceTracker = new nonce_tracker_1.NonceTracker({
157
- // @ts-expect-error provider types misaligned: SafeEventEmitterProvider vs Record<string,string>
138
+ this.nonceTracker = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_createNonceTracker).call(this, {
158
139
  provider,
159
140
  blockTracker,
160
- getPendingTransactions: this.getNonceTrackerPendingTransactions.bind(this),
161
- getConfirmedTransactions: this.getNonceTrackerTransactions.bind(this, types_1.TransactionStatus.confirmed),
162
141
  });
163
- this.incomingTransactionHelper = new IncomingTransactionHelper_1.IncomingTransactionHelper({
164
- blockTracker,
165
- getCurrentAccount: getSelectedAddress,
166
- getLastFetchedBlockNumbers: () => this.state.lastFetchedBlockNumbers,
167
- getNetworkState,
168
- isEnabled: incomingTransactions.isEnabled,
169
- queryEntireHistory: incomingTransactions.queryEntireHistory,
170
- remoteTransactionSource: new EtherscanRemoteTransactionSource_1.EtherscanRemoteTransactionSource({
171
- includeTokenTransfers: incomingTransactions.includeTokenTransfers,
172
- }),
173
- transactionLimit: this.config.txHistoryLimit,
174
- updateTransactions: incomingTransactions.updateTransactions,
175
- });
176
- this.incomingTransactionHelper.hub.on('transactions', this.onIncomingTransactions.bind(this));
177
- this.incomingTransactionHelper.hub.on('updatedLastFetchedBlockNumbers', this.onUpdatedLastFetchedBlockNumbers.bind(this));
178
- this.pendingTransactionTracker = new PendingTransactionTracker_1.PendingTransactionTracker({
179
- approveTransaction: this.approveTransaction.bind(this),
180
- blockTracker,
181
- getChainId: this.getChainId.bind(this),
182
- getEthQuery: () => this.ethQuery,
183
- getTransactions: () => this.state.transactions,
184
- isResubmitEnabled: pendingTransactions.isResubmitEnabled,
142
+ __classPrivateFieldSet(this, _TransactionController_multichainTrackingHelper, new MultichainTrackingHelper_1.MultichainTrackingHelper({
143
+ isMultichainEnabled,
144
+ provider,
185
145
  nonceTracker: this.nonceTracker,
186
- onStateChange: (listener) => {
187
- this.subscribe(listener);
188
- onNetworkStateChange(listener);
189
- listener();
146
+ incomingTransactionOptions: incomingTransactions,
147
+ findNetworkClientIdByChainId: (chainId) => {
148
+ return this.messagingSystem.call(`NetworkController:findNetworkClientIdByChainId`, chainId);
190
149
  },
191
- publishTransaction: this.publishTransaction.bind(this),
192
- hooks: {
193
- beforeCheckPendingTransaction: this.beforeCheckPendingTransaction.bind(this),
194
- beforePublish: this.beforePublish.bind(this),
150
+ getNetworkClientById: ((networkClientId) => {
151
+ return this.messagingSystem.call(`NetworkController:getNetworkClientById`, networkClientId);
152
+ }),
153
+ getNetworkClientRegistry,
154
+ removeIncomingTransactionHelperListeners: __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_removeIncomingTransactionHelperListeners).bind(this),
155
+ removePendingTransactionTrackerListeners: __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_removePendingTransactionTrackerListeners).bind(this),
156
+ createNonceTracker: __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_createNonceTracker).bind(this),
157
+ createIncomingTransactionHelper: __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_createIncomingTransactionHelper).bind(this),
158
+ createPendingTransactionTracker: __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_createPendingTransactionTracker).bind(this),
159
+ onNetworkStateChange: (listener) => {
160
+ this.messagingSystem.subscribe('NetworkController:stateChange', listener);
195
161
  },
162
+ }), "f");
163
+ __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").initialize();
164
+ const etherscanRemoteTransactionSource = new EtherscanRemoteTransactionSource_1.EtherscanRemoteTransactionSource({
165
+ includeTokenTransfers: incomingTransactions.includeTokenTransfers,
166
+ });
167
+ this.incomingTransactionHelper = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_createIncomingTransactionHelper).call(this, {
168
+ blockTracker,
169
+ etherscanRemoteTransactionSource,
170
+ });
171
+ this.pendingTransactionTracker = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_createPendingTransactionTracker).call(this, {
172
+ provider,
173
+ blockTracker,
196
174
  });
197
- this.addPendingTransactionTrackerListeners();
175
+ // when transactionsController state changes
176
+ // check for pending transactions and start polling if there are any
177
+ this.subscribe(__classPrivateFieldGet(this, _TransactionController_checkForPendingTransactionAndStartPolling, "f"));
178
+ // TODO once v2 is merged make sure this only runs when
179
+ // selectedNetworkClientId changes
198
180
  onNetworkStateChange(() => {
199
181
  (0, logger_1.projectLogger)('Detected network change', this.getChainId());
182
+ this.pendingTransactionTracker.startIfPendingTransactions();
200
183
  this.onBootCleanup();
201
184
  });
202
185
  this.onBootCleanup();
@@ -219,6 +202,12 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
219
202
  return { registryMethod, parsedRegistryMethod };
220
203
  });
221
204
  }
205
+ /**
206
+ * Stops polling and removes listeners to prepare the controller for garbage collection.
207
+ */
208
+ destroy() {
209
+ __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_stopAllTracking).call(this);
210
+ }
222
211
  /**
223
212
  * Handle new method data request.
224
213
  *
@@ -263,21 +252,30 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
263
252
  * @param opts.swaps - Options for swaps transactions.
264
253
  * @param opts.swaps.hasApproveTx - Whether the transaction has an approval transaction.
265
254
  * @param opts.swaps.meta - Metadata for swap transaction.
255
+ * @param opts.networkClientId - The id of the network client for this transaction.
266
256
  * @returns Object containing a promise resolving to the transaction hash if approved.
267
257
  */
268
- addTransaction(txParams, { actionId, deviceConfirmedOn, method, origin, requireApproval, securityAlertResponse, sendFlowHistory, swaps = {}, type, } = {}) {
258
+ addTransaction(txParams, { actionId, deviceConfirmedOn, method, origin, requireApproval, securityAlertResponse, sendFlowHistory, swaps = {}, type, networkClientId, } = {}) {
269
259
  return __awaiter(this, void 0, void 0, function* () {
270
260
  (0, logger_1.projectLogger)('Adding transaction', txParams);
271
261
  txParams = (0, utils_1.normalizeTxParams)(txParams);
272
- const isEIP1559Compatible = yield this.getEIP1559Compatibility();
262
+ if (networkClientId &&
263
+ !__classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").has(networkClientId)) {
264
+ throw new Error('The networkClientId for this transaction could not be found');
265
+ }
266
+ const isEIP1559Compatible = yield this.getEIP1559Compatibility(networkClientId);
273
267
  (0, validation_1.validateTxParams)(txParams, isEIP1559Compatible);
274
268
  if (origin) {
275
269
  yield (0, validation_1.validateTransactionOrigin)(yield this.getPermittedAccounts(origin), this.getSelectedAddress(), txParams.from, origin);
276
270
  }
277
271
  const dappSuggestedGasFees = this.generateDappSuggestedGasFees(txParams, origin);
278
- const transactionType = type !== null && type !== void 0 ? type : (yield (0, transaction_type_1.determineTransactionType)(txParams, this.ethQuery)).type;
272
+ const chainId = this.getChainId(networkClientId);
273
+ const ethQuery = __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getEthQuery({
274
+ networkClientId,
275
+ chainId,
276
+ });
277
+ const transactionType = type !== null && type !== void 0 ? type : (yield (0, transaction_type_1.determineTransactionType)(txParams, ethQuery)).type;
279
278
  const existingTransactionMeta = this.getTransactionWithActionId(actionId);
280
- const chainId = this.getChainId();
281
279
  // If a request to add a transaction with the same actionId is submitted again, a new transaction will not be created for it.
282
280
  const transactionMeta = existingTransactionMeta || {
283
281
  // Add actionId to txMeta to check if same actionId is seen again
@@ -294,6 +292,7 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
294
292
  userEditedGasLimit: false,
295
293
  verifiedOnBlockchain: false,
296
294
  type: transactionType,
295
+ networkClientId,
297
296
  };
298
297
  yield this.updateGasProperties(transactionMeta);
299
298
  // Checks if a transaction already exists with a given actionId
@@ -330,15 +329,31 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
330
329
  };
331
330
  });
332
331
  }
333
- startIncomingTransactionPolling() {
334
- this.incomingTransactionHelper.start();
332
+ startIncomingTransactionPolling(networkClientIds = []) {
333
+ if (networkClientIds.length === 0) {
334
+ this.incomingTransactionHelper.start();
335
+ return;
336
+ }
337
+ __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").startIncomingTransactionPolling(networkClientIds);
338
+ }
339
+ stopIncomingTransactionPolling(networkClientIds = []) {
340
+ if (networkClientIds.length === 0) {
341
+ this.incomingTransactionHelper.stop();
342
+ return;
343
+ }
344
+ __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").stopIncomingTransactionPolling(networkClientIds);
335
345
  }
336
- stopIncomingTransactionPolling() {
346
+ stopAllIncomingTransactionPolling() {
337
347
  this.incomingTransactionHelper.stop();
348
+ __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").stopAllIncomingTransactionPolling();
338
349
  }
339
- updateIncomingTransactions() {
350
+ updateIncomingTransactions(networkClientIds = []) {
340
351
  return __awaiter(this, void 0, void 0, function* () {
341
- yield this.incomingTransactionHelper.update();
352
+ if (networkClientIds.length === 0) {
353
+ yield this.incomingTransactionHelper.update();
354
+ return;
355
+ }
356
+ yield __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").updateIncomingTransactions(networkClientIds);
342
357
  });
343
358
  }
344
359
  /**
@@ -372,21 +387,21 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
372
387
  throw new Error('No sign method defined.');
373
388
  }
374
389
  // gasPrice (legacy non EIP1559)
375
- const minGasPrice = (0, utils_1.getIncreasedPriceFromExisting)(transactionMeta.txParams.gasPrice, this.cancelMultiplier);
390
+ const minGasPrice = (0, utils_1.getIncreasedPriceFromExisting)(transactionMeta.txParams.gasPrice, exports.CANCEL_RATE);
376
391
  const gasPriceFromValues = (0, utils_1.isGasPriceValue)(gasValues) && gasValues.gasPrice;
377
392
  const newGasPrice = (gasPriceFromValues &&
378
393
  (0, utils_1.validateMinimumIncrease)(gasPriceFromValues, minGasPrice)) ||
379
394
  minGasPrice;
380
395
  // maxFeePerGas (EIP1559)
381
396
  const existingMaxFeePerGas = (_a = transactionMeta.txParams) === null || _a === void 0 ? void 0 : _a.maxFeePerGas;
382
- const minMaxFeePerGas = (0, utils_1.getIncreasedPriceFromExisting)(existingMaxFeePerGas, this.cancelMultiplier);
397
+ const minMaxFeePerGas = (0, utils_1.getIncreasedPriceFromExisting)(existingMaxFeePerGas, exports.CANCEL_RATE);
383
398
  const maxFeePerGasValues = (0, utils_1.isFeeMarketEIP1559Values)(gasValues) && gasValues.maxFeePerGas;
384
399
  const newMaxFeePerGas = (maxFeePerGasValues &&
385
400
  (0, utils_1.validateMinimumIncrease)(maxFeePerGasValues, minMaxFeePerGas)) ||
386
401
  (existingMaxFeePerGas && minMaxFeePerGas);
387
402
  // maxPriorityFeePerGas (EIP1559)
388
403
  const existingMaxPriorityFeePerGas = (_b = transactionMeta.txParams) === null || _b === void 0 ? void 0 : _b.maxPriorityFeePerGas;
389
- const minMaxPriorityFeePerGas = (0, utils_1.getIncreasedPriceFromExisting)(existingMaxPriorityFeePerGas, this.cancelMultiplier);
404
+ const minMaxPriorityFeePerGas = (0, utils_1.getIncreasedPriceFromExisting)(existingMaxPriorityFeePerGas, exports.CANCEL_RATE);
390
405
  const maxPriorityFeePerGasValues = (0, utils_1.isFeeMarketEIP1559Values)(gasValues) && gasValues.maxPriorityFeePerGas;
391
406
  const newMaxPriorityFeePerGas = (maxPriorityFeePerGasValues &&
392
407
  (0, utils_1.validateMinimumIncrease)(maxPriorityFeePerGasValues, minMaxPriorityFeePerGas)) ||
@@ -410,7 +425,7 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
410
425
  to: transactionMeta.txParams.from,
411
426
  value: '0x0',
412
427
  };
413
- const unsignedEthTx = this.prepareUnsignedEthTx(newTxParams);
428
+ const unsignedEthTx = this.prepareUnsignedEthTx(transactionMeta.chainId, newTxParams);
414
429
  const signedTx = yield this.sign(unsignedEthTx, transactionMeta.txParams.from);
415
430
  const rawTx = (0, ethereumjs_util_1.bufferToHex)(signedTx.serialize());
416
431
  const newFee = (_c = newTxParams.maxFeePerGas) !== null && _c !== void 0 ? _c : newTxParams.gasPrice;
@@ -422,10 +437,15 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
422
437
  newFee,
423
438
  txParams: newTxParams,
424
439
  });
425
- const hash = yield this.publishTransaction(rawTx);
440
+ const ethQuery = __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getEthQuery({
441
+ networkClientId: transactionMeta.networkClientId,
442
+ chainId: transactionMeta.chainId,
443
+ });
444
+ const hash = yield this.publishTransactionForRetry(ethQuery, rawTx, transactionMeta);
426
445
  const cancelTransactionMeta = {
427
446
  actionId,
428
447
  chainId: transactionMeta.chainId,
448
+ networkClientId: transactionMeta.networkClientId,
429
449
  estimatedBaseFee,
430
450
  hash,
431
451
  id: (0, uuid_1.v1)(),
@@ -480,28 +500,28 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
480
500
  throw new Error('No sign method defined.');
481
501
  }
482
502
  // gasPrice (legacy non EIP1559)
483
- const minGasPrice = (0, utils_1.getIncreasedPriceFromExisting)(transactionMeta.txParams.gasPrice, this.speedUpMultiplier);
503
+ const minGasPrice = (0, utils_1.getIncreasedPriceFromExisting)(transactionMeta.txParams.gasPrice, exports.SPEED_UP_RATE);
484
504
  const gasPriceFromValues = (0, utils_1.isGasPriceValue)(gasValues) && gasValues.gasPrice;
485
505
  const newGasPrice = (gasPriceFromValues &&
486
506
  (0, utils_1.validateMinimumIncrease)(gasPriceFromValues, minGasPrice)) ||
487
507
  minGasPrice;
488
508
  // maxFeePerGas (EIP1559)
489
509
  const existingMaxFeePerGas = (_a = transactionMeta.txParams) === null || _a === void 0 ? void 0 : _a.maxFeePerGas;
490
- const minMaxFeePerGas = (0, utils_1.getIncreasedPriceFromExisting)(existingMaxFeePerGas, this.speedUpMultiplier);
510
+ const minMaxFeePerGas = (0, utils_1.getIncreasedPriceFromExisting)(existingMaxFeePerGas, exports.SPEED_UP_RATE);
491
511
  const maxFeePerGasValues = (0, utils_1.isFeeMarketEIP1559Values)(gasValues) && gasValues.maxFeePerGas;
492
512
  const newMaxFeePerGas = (maxFeePerGasValues &&
493
513
  (0, utils_1.validateMinimumIncrease)(maxFeePerGasValues, minMaxFeePerGas)) ||
494
514
  (existingMaxFeePerGas && minMaxFeePerGas);
495
515
  // maxPriorityFeePerGas (EIP1559)
496
516
  const existingMaxPriorityFeePerGas = (_b = transactionMeta.txParams) === null || _b === void 0 ? void 0 : _b.maxPriorityFeePerGas;
497
- const minMaxPriorityFeePerGas = (0, utils_1.getIncreasedPriceFromExisting)(existingMaxPriorityFeePerGas, this.speedUpMultiplier);
517
+ const minMaxPriorityFeePerGas = (0, utils_1.getIncreasedPriceFromExisting)(existingMaxPriorityFeePerGas, exports.SPEED_UP_RATE);
498
518
  const maxPriorityFeePerGasValues = (0, utils_1.isFeeMarketEIP1559Values)(gasValues) && gasValues.maxPriorityFeePerGas;
499
519
  const newMaxPriorityFeePerGas = (maxPriorityFeePerGasValues &&
500
520
  (0, utils_1.validateMinimumIncrease)(maxPriorityFeePerGasValues, minMaxPriorityFeePerGas)) ||
501
521
  (existingMaxPriorityFeePerGas && minMaxPriorityFeePerGas);
502
522
  const txParams = newMaxFeePerGas && newMaxPriorityFeePerGas
503
523
  ? 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 });
504
- const unsignedEthTx = this.prepareUnsignedEthTx(txParams);
524
+ const unsignedEthTx = this.prepareUnsignedEthTx(transactionMeta.chainId, txParams);
505
525
  const signedTx = yield this.sign(unsignedEthTx, transactionMeta.txParams.from);
506
526
  yield this.updateTransactionMetaRSV(transactionMeta, signedTx);
507
527
  const rawTx = (0, ethereumjs_util_1.bufferToHex)(signedTx.serialize());
@@ -510,7 +530,11 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
510
530
  ? transactionMeta.txParams.maxFeePerGas
511
531
  : transactionMeta.txParams.gasPrice;
512
532
  (0, logger_1.projectLogger)('Submitting speed up transaction', { oldFee, newFee, txParams });
513
- const hash = yield (0, controller_utils_1.query)(this.ethQuery, 'sendRawTransaction', [rawTx]);
533
+ const ethQuery = __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getEthQuery({
534
+ networkClientId: transactionMeta.networkClientId,
535
+ chainId: transactionMeta.chainId,
536
+ });
537
+ const hash = yield this.publishTransactionForRetry(ethQuery, rawTx, transactionMeta);
514
538
  const baseTransactionMeta = Object.assign(Object.assign({}, transactionMeta), { estimatedBaseFee, id: (0, uuid_1.v1)(), time: Date.now(), hash,
515
539
  actionId, originalGasEstimate: transactionMeta.txParams.gas, type: types_1.TransactionType.retry, originalType: transactionMeta.type });
516
540
  const newTransactionMeta = newMaxFeePerGas && newMaxPriorityFeePerGas
@@ -532,11 +556,15 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
532
556
  * Estimates required gas for a given transaction.
533
557
  *
534
558
  * @param transaction - The transaction to estimate gas for.
559
+ * @param networkClientId - The network client id to use for the estimate.
535
560
  * @returns The gas and gas price.
536
561
  */
537
- estimateGas(transaction) {
562
+ estimateGas(transaction, networkClientId) {
538
563
  return __awaiter(this, void 0, void 0, function* () {
539
- const { estimatedGas, simulationFails } = yield (0, gas_1.estimateGas)(transaction, this.ethQuery);
564
+ const ethQuery = __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getEthQuery({
565
+ networkClientId,
566
+ });
567
+ const { estimatedGas, simulationFails } = yield (0, gas_1.estimateGas)(transaction, ethQuery);
540
568
  return { gas: estimatedGas, simulationFails };
541
569
  });
542
570
  }
@@ -545,10 +573,14 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
545
573
  *
546
574
  * @param transaction - The transaction params to estimate gas for.
547
575
  * @param multiplier - The multiplier to use for the gas buffer.
576
+ * @param networkClientId - The network client id to use for the estimate.
548
577
  */
549
- estimateGasBuffered(transaction, multiplier) {
578
+ estimateGasBuffered(transaction, multiplier, networkClientId) {
550
579
  return __awaiter(this, void 0, void 0, function* () {
551
- const { blockGasLimit, estimatedGas, simulationFails } = yield (0, gas_1.estimateGas)(transaction, this.ethQuery);
580
+ const ethQuery = __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getEthQuery({
581
+ networkClientId,
582
+ });
583
+ const { blockGasLimit, estimatedGas, simulationFails } = yield (0, gas_1.estimateGas)(transaction, ethQuery);
552
584
  const gas = (0, gas_1.addGasBuffer)(estimatedGas, blockGasLimit, multiplier);
553
585
  return {
554
586
  gas,
@@ -618,12 +650,6 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
618
650
  transactions: this.trimTransactionsForState(newTransactions),
619
651
  });
620
652
  }
621
- startIncomingTransactionProcessing() {
622
- this.incomingTransactionHelper.start();
623
- }
624
- stopIncomingTransactionProcessing() {
625
- this.incomingTransactionHelper.stop();
626
- }
627
653
  /**
628
654
  * Adds external provided transaction to state as confirmed transaction.
629
655
  *
@@ -769,16 +795,9 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
769
795
  this.updateTransaction(updatedMeta, 'TransactionController:updatePreviousGasParams - Previous gas values updated');
770
796
  return this.getTransaction(transactionId);
771
797
  }
772
- /**
773
- * Gets the next nonce according to the nonce-tracker.
774
- * Ensure `releaseLock` is called once processing of the `nonce` value is complete.
775
- *
776
- * @param address - The hex string address for the transaction.
777
- * @returns object with the `nextNonce` `nonceDetails`, and the releaseLock.
778
- */
779
- getNonceLock(address) {
798
+ getNonceLock(address, networkClientId) {
780
799
  return __awaiter(this, void 0, void 0, function* () {
781
- return this.nonceTracker.getNonceLock(address);
800
+ return __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getNonceLock(address, networkClientId);
782
801
  });
783
802
  }
784
803
  /**
@@ -813,7 +832,10 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
813
832
  };
814
833
  editableParams.txParams = (0, lodash_1.pickBy)(editableParams.txParams);
815
834
  const updatedTransaction = (0, lodash_1.merge)(transactionMeta, editableParams);
816
- const { type } = yield (0, transaction_type_1.determineTransactionType)(updatedTransaction.txParams, this.ethQuery);
835
+ const { type } = yield (0, transaction_type_1.determineTransactionType)(updatedTransaction.txParams, __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getEthQuery({
836
+ networkClientId: transactionMeta.networkClientId,
837
+ chainId: transactionMeta.chainId,
838
+ }));
817
839
  updatedTransaction.type = type;
818
840
  this.updateTransaction(updatedTransaction, `Update Editable Params for ${txId}`);
819
841
  return this.getTransaction(txId);
@@ -836,7 +858,19 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
836
858
  return '';
837
859
  }
838
860
  const initialTx = listOfTxParams[0];
839
- const common = this.getCommonConfiguration();
861
+ const common = this.getCommonConfiguration(initialTx.chainId);
862
+ // We need to ensure we get the nonce using the the NonceTracker on the chain matching
863
+ // the txParams. In this context we only have chainId available to us, but the
864
+ // NonceTrackers are keyed by networkClientId. To workaround this, we attempt to find
865
+ // a networkClientId that matches the chainId. As a fallback, the globally selected
866
+ // network's NonceTracker will be used instead.
867
+ let networkClientId;
868
+ try {
869
+ networkClientId = this.messagingSystem.call(`NetworkController:findNetworkClientIdByChainId`, initialTx.chainId);
870
+ }
871
+ catch (err) {
872
+ (0, logger_1.projectLogger)('failed to find networkClientId from chainId', err);
873
+ }
840
874
  const initialTxAsEthTx = tx_1.TransactionFactory.fromTxData(initialTx, {
841
875
  common,
842
876
  });
@@ -851,7 +885,7 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
851
885
  const fromAddress = initialTx.from;
852
886
  const requiresNonce = hasNonce !== true;
853
887
  nonceLock = requiresNonce
854
- ? yield this.nonceTracker.getNonceLock(fromAddress)
888
+ ? yield this.getNonceLock(fromAddress, networkClientId)
855
889
  : undefined;
856
890
  const nonce = nonceLock
857
891
  ? (0, ethereumjs_util_1.addHexPrefix)(nonceLock.nextNonce.toString(16))
@@ -861,7 +895,7 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
861
895
  }
862
896
  rawTransactions = yield Promise.all(listOfTxParams.map((txParams) => {
863
897
  txParams.nonce = nonce;
864
- return this.signExternalTransaction(txParams);
898
+ return this.signExternalTransaction(txParams.chainId, txParams);
865
899
  }));
866
900
  }
867
901
  catch (err) {
@@ -1019,19 +1053,18 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1019
1053
  }
1020
1054
  return filteredTransactions;
1021
1055
  }
1022
- signExternalTransaction(transactionParams) {
1056
+ signExternalTransaction(chainId, transactionParams) {
1023
1057
  return __awaiter(this, void 0, void 0, function* () {
1024
1058
  if (!this.sign) {
1025
1059
  throw new Error('No sign method defined.');
1026
1060
  }
1027
1061
  const normalizedTransactionParams = (0, utils_1.normalizeTxParams)(transactionParams);
1028
- const chainId = this.getChainId();
1029
1062
  const type = (0, utils_1.isEIP1559Transaction)(normalizedTransactionParams)
1030
1063
  ? types_1.TransactionEnvelopeType.feeMarket
1031
1064
  : types_1.TransactionEnvelopeType.legacy;
1032
1065
  const updatedTransactionParams = Object.assign(Object.assign({}, normalizedTransactionParams), { type, gasLimit: normalizedTransactionParams.gas, chainId });
1033
1066
  const { from } = updatedTransactionParams;
1034
- const common = this.getCommonConfiguration();
1067
+ const common = this.getCommonConfiguration(chainId);
1035
1068
  const unsignedTransaction = tx_1.TransactionFactory.fromTxData(updatedTransactionParams, { common });
1036
1069
  const signedTransaction = yield this.sign(unsignedTransaction, from);
1037
1070
  const rawTransaction = (0, ethereumjs_util_1.bufferToHex)(signedTransaction.serialize());
@@ -1069,35 +1102,41 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1069
1102
  }
1070
1103
  updateGasProperties(transactionMeta) {
1071
1104
  return __awaiter(this, void 0, void 0, function* () {
1072
- const isEIP1559Compatible = (yield this.getEIP1559Compatibility()) &&
1105
+ const isEIP1559Compatible = (yield this.getEIP1559Compatibility(transactionMeta.networkClientId)) &&
1073
1106
  transactionMeta.txParams.type !== types_1.TransactionEnvelopeType.legacy;
1074
- const chainId = this.getChainId();
1107
+ const { networkClientId, chainId } = transactionMeta;
1108
+ const isCustomNetwork = networkClientId
1109
+ ? this.messagingSystem.call(`NetworkController:getNetworkClientById`, networkClientId).configuration.type === network_controller_1.NetworkClientType.Custom
1110
+ : this.getNetworkState().providerConfig.type === controller_utils_1.NetworkType.rpc;
1075
1111
  yield (0, gas_1.updateGas)({
1076
- ethQuery: this.ethQuery,
1077
- providerConfig: this.getNetworkState().providerConfig,
1112
+ ethQuery: __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getEthQuery({
1113
+ networkClientId,
1114
+ chainId,
1115
+ }),
1116
+ chainId,
1117
+ isCustomNetwork,
1078
1118
  txMeta: transactionMeta,
1079
1119
  });
1080
1120
  yield (0, gas_fees_1.updateGasFees)({
1081
1121
  eip1559: isEIP1559Compatible,
1082
- ethQuery: this.ethQuery,
1083
- getSavedGasFees: this.getSavedGasFees.bind(this, chainId),
1122
+ ethQuery: __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getEthQuery({
1123
+ networkClientId,
1124
+ chainId,
1125
+ }),
1126
+ getSavedGasFees: this.getSavedGasFees.bind(this),
1084
1127
  getGasFeeEstimates: this.getGasFeeEstimates.bind(this),
1085
1128
  txMeta: transactionMeta,
1086
1129
  });
1087
1130
  });
1088
1131
  }
1089
- getCurrentChainTransactionsByStatus(status) {
1090
- const chainId = this.getChainId();
1091
- return this.state.transactions.filter((transaction) => transaction.status === status && transaction.chainId === chainId);
1092
- }
1093
1132
  onBootCleanup() {
1094
1133
  this.submitApprovedTransactions();
1095
1134
  }
1096
1135
  /**
1097
- * Force to submit approved transactions on current chain.
1136
+ * Force submit approved transactions for all chains.
1098
1137
  */
1099
1138
  submitApprovedTransactions() {
1100
- const approvedTransactions = this.getCurrentChainTransactionsByStatus(types_1.TransactionStatus.approved);
1139
+ const approvedTransactions = this.state.transactions.filter((transaction) => transaction.status === types_1.TransactionStatus.approved);
1101
1140
  for (const transactionMeta of approvedTransactions) {
1102
1141
  if (this.beforeApproveOnInit(transactionMeta)) {
1103
1142
  this.approveTransaction(transactionMeta.id).catch((error) => {
@@ -1191,10 +1230,9 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1191
1230
  return __awaiter(this, void 0, void 0, function* () {
1192
1231
  const { transactions } = this.state;
1193
1232
  const releaseLock = yield this.mutex.acquire();
1194
- const chainId = this.getChainId();
1195
1233
  const index = transactions.findIndex(({ id }) => transactionId === id);
1196
1234
  const transactionMeta = transactions[index];
1197
- const { txParams: { from }, } = transactionMeta;
1235
+ const { txParams: { from }, networkClientId, } = transactionMeta;
1198
1236
  let releaseNonceLock;
1199
1237
  try {
1200
1238
  if (!this.sign) {
@@ -1202,7 +1240,7 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1202
1240
  this.failTransaction(transactionMeta, new Error('No sign method defined.'));
1203
1241
  return;
1204
1242
  }
1205
- else if (!chainId) {
1243
+ else if (!transactionMeta.chainId) {
1206
1244
  releaseLock();
1207
1245
  this.failTransaction(transactionMeta, new Error('No chainId defined.'));
1208
1246
  return;
@@ -1211,11 +1249,11 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1211
1249
  (0, logger_1.projectLogger)('Skipping approval as signing in progress', transactionId);
1212
1250
  return;
1213
1251
  }
1214
- const [nonce, releaseNonce] = yield (0, nonce_1.getNextNonce)(transactionMeta, this.nonceTracker);
1252
+ const [nonce, releaseNonce] = yield (0, nonce_1.getNextNonce)(transactionMeta, (address) => __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getNonceLock(address, networkClientId));
1215
1253
  releaseNonceLock = releaseNonce;
1216
1254
  transactionMeta.status = types_1.TransactionStatus.approved;
1217
1255
  transactionMeta.txParams.nonce = nonce;
1218
- transactionMeta.txParams.chainId = chainId;
1256
+ transactionMeta.txParams.chainId = transactionMeta.chainId;
1219
1257
  const baseTxParams = Object.assign(Object.assign({}, transactionMeta.txParams), { gasLimit: transactionMeta.txParams.gas });
1220
1258
  this.updateTransaction(transactionMeta, 'TransactionController#approveTransaction - Transaction approved');
1221
1259
  this.onTransactionStatusChange(transactionMeta);
@@ -1231,16 +1269,20 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1231
1269
  if (!rawTx) {
1232
1270
  return;
1233
1271
  }
1272
+ const ethQuery = __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getEthQuery({
1273
+ networkClientId: transactionMeta.networkClientId,
1274
+ chainId: transactionMeta.chainId,
1275
+ });
1234
1276
  if (transactionMeta.type === types_1.TransactionType.swap) {
1235
1277
  (0, logger_1.projectLogger)('Determining pre-transaction balance');
1236
- const preTxBalance = yield (0, controller_utils_1.query)(this.ethQuery, 'getBalance', [from]);
1278
+ const preTxBalance = yield (0, controller_utils_1.query)(ethQuery, 'getBalance', [from]);
1237
1279
  transactionMeta.preTxBalance = preTxBalance;
1238
1280
  (0, logger_1.projectLogger)('Updated pre-transaction balance', transactionMeta.preTxBalance);
1239
1281
  }
1240
1282
  (0, logger_1.projectLogger)('Publishing transaction', txParams);
1241
1283
  let { transactionHash: hash } = yield this.publish(transactionMeta, rawTx);
1242
1284
  if (hash === undefined) {
1243
- hash = yield this.publishTransaction(rawTx);
1285
+ hash = yield this.publishTransaction(ethQuery, rawTx);
1244
1286
  }
1245
1287
  (0, logger_1.projectLogger)('Publish successful', hash);
1246
1288
  transactionMeta.hash = hash;
@@ -1266,9 +1308,9 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1266
1308
  }
1267
1309
  });
1268
1310
  }
1269
- publishTransaction(rawTransaction) {
1311
+ publishTransaction(ethQuery, rawTransaction) {
1270
1312
  return __awaiter(this, void 0, void 0, function* () {
1271
- return yield (0, controller_utils_1.query)(this.ethQuery, 'sendRawTransaction', [rawTransaction]);
1313
+ return yield (0, controller_utils_1.query)(ethQuery, 'sendRawTransaction', [rawTransaction]);
1272
1314
  });
1273
1315
  }
1274
1316
  /**
@@ -1384,14 +1426,17 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1384
1426
  const isCompleted = this.isLocalFinalState(transaction.status);
1385
1427
  return { meta: transaction, isCompleted };
1386
1428
  }
1387
- getChainId() {
1429
+ getChainId(networkClientId) {
1430
+ if (networkClientId) {
1431
+ return this.messagingSystem.call(`NetworkController:getNetworkClientById`, networkClientId).configuration.chainId;
1432
+ }
1388
1433
  const { providerConfig } = this.getNetworkState();
1389
1434
  return providerConfig.chainId;
1390
1435
  }
1391
- prepareUnsignedEthTx(txParams) {
1436
+ prepareUnsignedEthTx(chainId, txParams) {
1392
1437
  return tx_1.TransactionFactory.fromTxData(txParams, {
1393
- common: this.getCommonConfiguration(),
1394
1438
  freeze: false,
1439
+ common: this.getCommonConfiguration(chainId),
1395
1440
  });
1396
1441
  }
1397
1442
  /**
@@ -1401,17 +1446,11 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1401
1446
  * specified in txParams, @ethereumjs/tx is able to determine which EIP-2718
1402
1447
  * transaction type to use.
1403
1448
  *
1449
+ * @param chainId - The chainId to use for the configuration.
1404
1450
  * @returns common configuration object
1405
1451
  */
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
- }
1452
+ getCommonConfiguration(chainId) {
1413
1453
  const customChainParams = {
1414
- name,
1415
1454
  chainId: parseInt(chainId, 16),
1416
1455
  defaultHardfork: exports.HARDFORK,
1417
1456
  };
@@ -1466,7 +1505,7 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1466
1505
  */
1467
1506
  addExternalTransaction(transactionMeta) {
1468
1507
  var _a, _b;
1469
- const chainId = this.getChainId();
1508
+ const { chainId } = transactionMeta;
1470
1509
  const { transactions } = this.state;
1471
1510
  const fromAddress = (_a = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.txParams) === null || _a === void 0 ? void 0 : _a.from;
1472
1511
  const sameFromAndNetworkTransactions = transactions.filter((transaction) => transaction.txParams.from === fromAddress &&
@@ -1493,10 +1532,13 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1493
1532
  */
1494
1533
  markNonceDuplicatesDropped(transactionId) {
1495
1534
  var _a, _b;
1496
- const chainId = this.getChainId();
1497
1535
  const transactionMeta = this.getTransaction(transactionId);
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;
1536
+ if (!transactionMeta) {
1537
+ return;
1538
+ }
1539
+ const nonce = (_a = transactionMeta.txParams) === null || _a === void 0 ? void 0 : _a.nonce;
1540
+ const from = (_b = transactionMeta.txParams) === null || _b === void 0 ? void 0 : _b.from;
1541
+ const { chainId } = transactionMeta;
1500
1542
  const sameNonceTxs = this.state.transactions.filter((transaction) => transaction.id !== transactionId &&
1501
1543
  transaction.txParams.from === from &&
1502
1544
  transaction.txParams.nonce === nonce &&
@@ -1507,8 +1549,8 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1507
1549
  }
1508
1550
  // Mark all same nonce transactions as dropped and give it a replacedBy hash
1509
1551
  for (const transaction of sameNonceTxs) {
1510
- transaction.replacedBy = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.hash;
1511
- transaction.replacedById = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.id;
1552
+ transaction.replacedBy = transactionMeta.hash;
1553
+ transaction.replacedById = transactionMeta.id;
1512
1554
  // Drop any transaction that wasn't previously failed (off chain failure)
1513
1555
  if (transaction.status !== types_1.TransactionStatus.failed) {
1514
1556
  this.setTransactionStatusDropped(transaction);
@@ -1564,23 +1606,17 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1564
1606
  }
1565
1607
  });
1566
1608
  }
1567
- getEIP1559Compatibility() {
1609
+ getEIP1559Compatibility(networkClientId) {
1568
1610
  return __awaiter(this, void 0, void 0, function* () {
1569
- const currentNetworkIsEIP1559Compatible = yield this.getCurrentNetworkEIP1559Compatibility();
1611
+ const currentNetworkIsEIP1559Compatible = yield this.getCurrentNetworkEIP1559Compatibility(networkClientId);
1570
1612
  const currentAccountIsEIP1559Compatible = yield this.getCurrentAccountEIP1559Compatibility();
1571
1613
  return (currentNetworkIsEIP1559Compatible && currentAccountIsEIP1559Compatible);
1572
1614
  });
1573
1615
  }
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));
1579
- }
1580
1616
  signTransaction(transactionMeta, txParams) {
1581
1617
  return __awaiter(this, void 0, void 0, function* () {
1582
1618
  (0, logger_1.projectLogger)('Signing transaction', txParams);
1583
- const unsignedEthTx = this.prepareUnsignedEthTx(txParams);
1619
+ const unsignedEthTx = this.prepareUnsignedEthTx(transactionMeta.chainId, txParams);
1584
1620
  this.inProcessOfSigning.add(transactionMeta.id);
1585
1621
  const signedTx = yield new Promise((resolve, reject) => {
1586
1622
  var _a;
@@ -1610,14 +1646,8 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1610
1646
  onTransactionStatusChange(transactionMeta) {
1611
1647
  this.hub.emit('transaction-status-update', { transactionMeta });
1612
1648
  }
1613
- getNonceTrackerPendingTransactions(address) {
1614
- const standardPendingTransactions = this.getNonceTrackerTransactions(types_1.TransactionStatus.submitted, address);
1615
- const externalPendingTransactions = this.getExternalPendingTransactions(address);
1616
- return [...standardPendingTransactions, ...externalPendingTransactions];
1617
- }
1618
- getNonceTrackerTransactions(status, address) {
1619
- const currentChainId = this.getChainId();
1620
- return (0, nonce_1.getAndFormatTransactionsForNonceTracker)(currentChainId, address, status, this.state.transactions);
1649
+ getNonceTrackerTransactions(status, address, chainId = this.getChainId()) {
1650
+ return (0, nonce_1.getAndFormatTransactionsForNonceTracker)(chainId, address, status, this.state.transactions);
1621
1651
  }
1622
1652
  onConfirmedTransaction(transactionMeta) {
1623
1653
  (0, logger_1.projectLogger)('Processing confirmed transaction', transactionMeta.id);
@@ -1635,8 +1665,12 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1635
1665
  if (transactionMeta.type !== types_1.TransactionType.swap) {
1636
1666
  return;
1637
1667
  }
1668
+ const ethQuery = __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getEthQuery({
1669
+ networkClientId: transactionMeta.networkClientId,
1670
+ chainId: transactionMeta.chainId,
1671
+ });
1638
1672
  const { updatedTransactionMeta, approvalTransactionMeta } = yield (0, swaps_1.updatePostTransactionBalance)(transactionMeta, {
1639
- ethQuery: this.ethQuery,
1673
+ ethQuery,
1640
1674
  getTransaction: this.getTransaction.bind(this),
1641
1675
  updateTransaction: this.updateTransaction.bind(this),
1642
1676
  });
@@ -1651,6 +1685,106 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
1651
1685
  }
1652
1686
  });
1653
1687
  }
1688
+ publishTransactionForRetry(ethQuery, rawTx, transactionMeta) {
1689
+ return __awaiter(this, void 0, void 0, function* () {
1690
+ try {
1691
+ const hash = yield this.publishTransaction(ethQuery, rawTx);
1692
+ return hash;
1693
+ }
1694
+ catch (error) {
1695
+ if (this.isTransactionAlreadyConfirmedError(error)) {
1696
+ yield this.pendingTransactionTracker.forceCheckTransaction(transactionMeta);
1697
+ throw new Error('Previous transaction is already confirmed');
1698
+ }
1699
+ throw error;
1700
+ }
1701
+ });
1702
+ }
1703
+ /**
1704
+ * Ensures that error is a nonce issue
1705
+ *
1706
+ * @param error - The error to check
1707
+ * @returns Whether or not the error is a nonce issue
1708
+ */
1709
+ // TODO: Replace `any` with type
1710
+ // Some networks are returning original error in the data field
1711
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1712
+ isTransactionAlreadyConfirmedError(error) {
1713
+ var _a, _b, _c;
1714
+ return (((_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.includes('nonce too low')) ||
1715
+ ((_c = (_b = error === null || error === void 0 ? void 0 : error.data) === null || _b === void 0 ? void 0 : _b.message) === null || _c === void 0 ? void 0 : _c.includes('nonce too low')));
1716
+ }
1654
1717
  }
1655
1718
  exports.TransactionController = TransactionController;
1719
+ _TransactionController_incomingTransactionOptions = new WeakMap(), _TransactionController_pendingTransactionOptions = new WeakMap(), _TransactionController_multichainTrackingHelper = new WeakMap(), _TransactionController_checkForPendingTransactionAndStartPolling = new WeakMap(), _TransactionController_instances = new WeakSet(), _TransactionController_createNonceTracker = function _TransactionController_createNonceTracker({ provider, blockTracker, chainId, }) {
1720
+ return new nonce_tracker_1.NonceTracker({
1721
+ // TODO: Replace `any` with type
1722
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1723
+ provider: provider,
1724
+ blockTracker,
1725
+ getPendingTransactions: __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getNonceTrackerPendingTransactions).bind(this, chainId),
1726
+ getConfirmedTransactions: this.getNonceTrackerTransactions.bind(this, types_1.TransactionStatus.confirmed),
1727
+ });
1728
+ }, _TransactionController_createIncomingTransactionHelper = function _TransactionController_createIncomingTransactionHelper({ blockTracker, etherscanRemoteTransactionSource, chainId, }) {
1729
+ const incomingTransactionHelper = new IncomingTransactionHelper_1.IncomingTransactionHelper({
1730
+ blockTracker,
1731
+ getCurrentAccount: this.getSelectedAddress,
1732
+ getLastFetchedBlockNumbers: () => this.state.lastFetchedBlockNumbers,
1733
+ getChainId: chainId ? () => chainId : this.getChainId.bind(this),
1734
+ isEnabled: __classPrivateFieldGet(this, _TransactionController_incomingTransactionOptions, "f").isEnabled,
1735
+ queryEntireHistory: __classPrivateFieldGet(this, _TransactionController_incomingTransactionOptions, "f").queryEntireHistory,
1736
+ remoteTransactionSource: etherscanRemoteTransactionSource,
1737
+ transactionLimit: this.config.txHistoryLimit,
1738
+ updateTransactions: __classPrivateFieldGet(this, _TransactionController_incomingTransactionOptions, "f").updateTransactions,
1739
+ });
1740
+ __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_addIncomingTransactionHelperListeners).call(this, incomingTransactionHelper);
1741
+ return incomingTransactionHelper;
1742
+ }, _TransactionController_createPendingTransactionTracker = function _TransactionController_createPendingTransactionTracker({ provider, blockTracker, chainId, }) {
1743
+ const ethQuery = new eth_query_1.default(provider);
1744
+ const getChainId = chainId ? () => chainId : this.getChainId.bind(this);
1745
+ const pendingTransactionTracker = new PendingTransactionTracker_1.PendingTransactionTracker({
1746
+ approveTransaction: this.approveTransaction.bind(this),
1747
+ blockTracker,
1748
+ getChainId,
1749
+ getEthQuery: () => ethQuery,
1750
+ getTransactions: () => this.state.transactions,
1751
+ isResubmitEnabled: __classPrivateFieldGet(this, _TransactionController_pendingTransactionOptions, "f").isResubmitEnabled,
1752
+ getGlobalLock: () => __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").acquireNonceLockForChainIdKey({
1753
+ chainId: getChainId(),
1754
+ }),
1755
+ publishTransaction: this.publishTransaction.bind(this),
1756
+ hooks: {
1757
+ beforeCheckPendingTransaction: this.beforeCheckPendingTransaction.bind(this),
1758
+ beforePublish: this.beforePublish.bind(this),
1759
+ },
1760
+ });
1761
+ __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_addPendingTransactionTrackerListeners).call(this, pendingTransactionTracker);
1762
+ return pendingTransactionTracker;
1763
+ }, _TransactionController_stopAllTracking = function _TransactionController_stopAllTracking() {
1764
+ this.pendingTransactionTracker.stop();
1765
+ __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_removePendingTransactionTrackerListeners).call(this, this.pendingTransactionTracker);
1766
+ this.incomingTransactionHelper.stop();
1767
+ __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_removeIncomingTransactionHelperListeners).call(this, this.incomingTransactionHelper);
1768
+ __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").stopAllTracking();
1769
+ }, _TransactionController_removeIncomingTransactionHelperListeners = function _TransactionController_removeIncomingTransactionHelperListeners(incomingTransactionHelper) {
1770
+ incomingTransactionHelper.hub.removeAllListeners('transactions');
1771
+ incomingTransactionHelper.hub.removeAllListeners('updatedLastFetchedBlockNumbers');
1772
+ }, _TransactionController_addIncomingTransactionHelperListeners = function _TransactionController_addIncomingTransactionHelperListeners(incomingTransactionHelper) {
1773
+ incomingTransactionHelper.hub.on('transactions', this.onIncomingTransactions.bind(this));
1774
+ incomingTransactionHelper.hub.on('updatedLastFetchedBlockNumbers', this.onUpdatedLastFetchedBlockNumbers.bind(this));
1775
+ }, _TransactionController_removePendingTransactionTrackerListeners = function _TransactionController_removePendingTransactionTrackerListeners(pendingTransactionTracker) {
1776
+ pendingTransactionTracker.hub.removeAllListeners('transaction-confirmed');
1777
+ pendingTransactionTracker.hub.removeAllListeners('transaction-dropped');
1778
+ pendingTransactionTracker.hub.removeAllListeners('transaction-failed');
1779
+ pendingTransactionTracker.hub.removeAllListeners('transaction-updated');
1780
+ }, _TransactionController_addPendingTransactionTrackerListeners = function _TransactionController_addPendingTransactionTrackerListeners(pendingTransactionTracker) {
1781
+ pendingTransactionTracker.hub.on('transaction-confirmed', this.onConfirmedTransaction.bind(this));
1782
+ pendingTransactionTracker.hub.on('transaction-dropped', this.setTransactionStatusDropped.bind(this));
1783
+ pendingTransactionTracker.hub.on('transaction-failed', this.failTransaction.bind(this));
1784
+ pendingTransactionTracker.hub.on('transaction-updated', this.updateTransaction.bind(this));
1785
+ }, _TransactionController_getNonceTrackerPendingTransactions = function _TransactionController_getNonceTrackerPendingTransactions(chainId, address) {
1786
+ const standardPendingTransactions = this.getNonceTrackerTransactions(types_1.TransactionStatus.submitted, address, chainId);
1787
+ const externalPendingTransactions = this.getExternalPendingTransactions(address, chainId);
1788
+ return [...standardPendingTransactions, ...externalPendingTransactions];
1789
+ };
1656
1790
  //# sourceMappingURL=TransactionController.js.map