@metamask-previews/transaction-controller 45.1.0-preview-f51ef7f8 → 45.1.0-preview-cd1fb95d

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 (76) hide show
  1. package/CHANGELOG.md +4 -18
  2. package/dist/TransactionController.cjs +35 -48
  3. package/dist/TransactionController.cjs.map +1 -1
  4. package/dist/TransactionController.d.cts +10 -20
  5. package/dist/TransactionController.d.cts.map +1 -1
  6. package/dist/TransactionController.d.mts +10 -20
  7. package/dist/TransactionController.d.mts.map +1 -1
  8. package/dist/TransactionController.mjs +33 -46
  9. package/dist/TransactionController.mjs.map +1 -1
  10. package/dist/constants.cjs +1 -20
  11. package/dist/constants.cjs.map +1 -1
  12. package/dist/constants.d.cts +0 -15
  13. package/dist/constants.d.cts.map +1 -1
  14. package/dist/constants.d.mts +0 -15
  15. package/dist/constants.d.mts.map +1 -1
  16. package/dist/constants.mjs +0 -19
  17. package/dist/constants.mjs.map +1 -1
  18. package/dist/{utils/resimulate.cjs → helpers/ResimulateHelper.cjs} +93 -4
  19. package/dist/helpers/ResimulateHelper.cjs.map +1 -0
  20. package/dist/{utils/resimulate.d.cts → helpers/ResimulateHelper.d.cts} +13 -1
  21. package/dist/helpers/ResimulateHelper.d.cts.map +1 -0
  22. package/dist/{utils/resimulate.d.mts → helpers/ResimulateHelper.d.mts} +13 -1
  23. package/dist/helpers/ResimulateHelper.d.mts.map +1 -0
  24. package/dist/{utils/resimulate.mjs → helpers/ResimulateHelper.mjs} +93 -5
  25. package/dist/helpers/ResimulateHelper.mjs.map +1 -0
  26. package/dist/index.cjs.map +1 -1
  27. package/dist/index.d.cts +1 -1
  28. package/dist/index.d.cts.map +1 -1
  29. package/dist/index.d.mts +1 -1
  30. package/dist/index.d.mts.map +1 -1
  31. package/dist/index.mjs.map +1 -1
  32. package/dist/types.cjs +0 -5
  33. package/dist/types.cjs.map +1 -1
  34. package/dist/types.d.cts +4 -51
  35. package/dist/types.d.cts.map +1 -1
  36. package/dist/types.d.mts +4 -51
  37. package/dist/types.d.mts.map +1 -1
  38. package/dist/types.mjs +0 -5
  39. package/dist/types.mjs.map +1 -1
  40. package/dist/utils/eip7702.cjs +2 -84
  41. package/dist/utils/eip7702.cjs.map +1 -1
  42. package/dist/utils/eip7702.d.cts +3 -42
  43. package/dist/utils/eip7702.d.cts.map +1 -1
  44. package/dist/utils/eip7702.d.mts +3 -42
  45. package/dist/utils/eip7702.d.mts.map +1 -1
  46. package/dist/utils/eip7702.mjs +3 -82
  47. package/dist/utils/eip7702.mjs.map +1 -1
  48. package/dist/utils/validation.cjs +4 -15
  49. package/dist/utils/validation.cjs.map +1 -1
  50. package/dist/utils/validation.d.cts +3 -7
  51. package/dist/utils/validation.d.cts.map +1 -1
  52. package/dist/utils/validation.d.mts +3 -7
  53. package/dist/utils/validation.d.mts.map +1 -1
  54. package/dist/utils/validation.mjs +5 -16
  55. package/dist/utils/validation.mjs.map +1 -1
  56. package/package.json +3 -5
  57. package/dist/utils/batch.cjs +0 -84
  58. package/dist/utils/batch.cjs.map +0 -1
  59. package/dist/utils/batch.d.cts +0 -32
  60. package/dist/utils/batch.d.cts.map +0 -1
  61. package/dist/utils/batch.d.mts +0 -32
  62. package/dist/utils/batch.d.mts.map +0 -1
  63. package/dist/utils/batch.mjs +0 -79
  64. package/dist/utils/batch.mjs.map +0 -1
  65. package/dist/utils/feature-flags.cjs +0 -53
  66. package/dist/utils/feature-flags.cjs.map +0 -1
  67. package/dist/utils/feature-flags.d.cts +0 -34
  68. package/dist/utils/feature-flags.d.cts.map +0 -1
  69. package/dist/utils/feature-flags.d.mts +0 -34
  70. package/dist/utils/feature-flags.d.mts.map +0 -1
  71. package/dist/utils/feature-flags.mjs +0 -47
  72. package/dist/utils/feature-flags.mjs.map +0 -1
  73. package/dist/utils/resimulate.cjs.map +0 -1
  74. package/dist/utils/resimulate.d.cts.map +0 -1
  75. package/dist/utils/resimulate.d.mts.map +0 -1
  76. package/dist/utils/resimulate.mjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -9,24 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9
9
 
10
10
  ### Added
11
11
 
12
- - Support atomic batch transactions ([#5306](https://github.com/MetaMask/core/pull/5306))
13
- - Add methods:
14
- - `addTransactionBatch`
15
- - `isAtomicBatchSupported`
16
- - Add `batch` to `TransactionType`.
17
- - Add `nestedTransactions` to `TransactionMeta`.
18
- - Add new types:
19
- - `BatchTransactionParams`
20
- - `TransactionBatchSingleRequest`
21
- - `TransactionBatchRequest`
22
- - `TransactionBatchResult`
23
- - Add dependency on `@metamask/remote-feature-flag-controller:^1.4.0`.
24
-
25
- ### Changed
26
-
27
- - **BREAKING:** Support atomic batch transactions ([#5306](https://github.com/MetaMask/core/pull/5306))
28
- - Require `AccountsController:getState` action permission in messenger.
29
- - Require `RemoteFeatureFlagController:getState` action permission in messenger.
12
+ - Adds ability of re-simulating transaction depending on the `isActive` property on `transactionMeta` ([#5189](https://github.com/MetaMask/core/pull/5189))
13
+ - `isActive` property is expected to set by client.
14
+ - Re-simulation of transactions will occur every 3 seconds if `isActive` is `true`.
15
+ - Adds `setTransactionActive` function to update the `isActive` property on `transactionMeta`. ([#5189](https://github.com/MetaMask/core/pull/5189))
30
16
 
31
17
  ## [45.1.0]
32
18
 
@@ -13,7 +13,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
13
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
15
  };
16
- var _TransactionController_instances, _TransactionController_internalEvents, _TransactionController_methodDataHelper, _TransactionController_incomingTransactionChainIds, _TransactionController_incomingTransactionHelper, _TransactionController_incomingTransactionOptions, _TransactionController_pendingTransactionOptions, _TransactionController_trace, _TransactionController_transactionHistoryLimit, _TransactionController_isFirstTimeInteractionEnabled, _TransactionController_isSimulationEnabled, _TransactionController_testGasFeeFlows, _TransactionController_multichainTrackingHelper, _TransactionController_retryTransaction, _TransactionController_getChainId, _TransactionController_getNetworkClientId, _TransactionController_getEthQuery, _TransactionController_getProvider, _TransactionController_createNonceTracker, _TransactionController_createPendingTransactionTracker, _TransactionController_checkForPendingTransactionAndStartPolling, _TransactionController_stopAllTracking, _TransactionController_addIncomingTransactionHelperListeners, _TransactionController_removePendingTransactionTrackerListeners, _TransactionController_addPendingTransactionTrackerListeners, _TransactionController_getNonceTrackerPendingTransactions, _TransactionController_getGasFeeFlows, _TransactionController_getLayer1GasFeeFlows, _TransactionController_updateTransactionInternal, _TransactionController_updateFirstTimeInteraction, _TransactionController_updateSimulationData, _TransactionController_onGasFeePollerTransactionUpdate, _TransactionController_getSelectedAccount, _TransactionController_getInternalAccounts, _TransactionController_updateSubmitHistory;
16
+ var _TransactionController_instances, _TransactionController_internalEvents, _TransactionController_methodDataHelper, _TransactionController_incomingTransactionChainIds, _TransactionController_incomingTransactionHelper, _TransactionController_incomingTransactionOptions, _TransactionController_pendingTransactionOptions, _TransactionController_trace, _TransactionController_transactionHistoryLimit, _TransactionController_isFirstTimeInteractionEnabled, _TransactionController_isSimulationEnabled, _TransactionController_testGasFeeFlows, _TransactionController_multichainTrackingHelper, _TransactionController_retryTransaction, _TransactionController_getChainId, _TransactionController_getNetworkClientId, _TransactionController_getEthQuery, _TransactionController_getProvider, _TransactionController_createNonceTracker, _TransactionController_createPendingTransactionTracker, _TransactionController_checkForPendingTransactionAndStartPolling, _TransactionController_stopAllTracking, _TransactionController_addIncomingTransactionHelperListeners, _TransactionController_removePendingTransactionTrackerListeners, _TransactionController_addPendingTransactionTrackerListeners, _TransactionController_getNonceTrackerPendingTransactions, _TransactionController_getGasFeeFlows, _TransactionController_getLayer1GasFeeFlows, _TransactionController_updateTransactionInternal, _TransactionController_updateFirstTimeInteraction, _TransactionController_updateSimulationData, _TransactionController_onGasFeePollerTransactionUpdate, _TransactionController_getSelectedAccount, _TransactionController_updateSubmitHistory;
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.TransactionController = exports.ApprovalState = exports.SPEED_UP_RATE = exports.CANCEL_RATE = void 0;
19
19
  const base_controller_1 = require("@metamask/base-controller");
@@ -41,9 +41,9 @@ const IncomingTransactionHelper_1 = require("./helpers/IncomingTransactionHelper
41
41
  const MethodDataHelper_1 = require("./helpers/MethodDataHelper.cjs");
42
42
  const MultichainTrackingHelper_1 = require("./helpers/MultichainTrackingHelper.cjs");
43
43
  const PendingTransactionTracker_1 = require("./helpers/PendingTransactionTracker.cjs");
44
+ const ResimulateHelper_1 = require("./helpers/ResimulateHelper.cjs");
44
45
  const logger_1 = require("./logger.cjs");
45
46
  const types_1 = require("./types.cjs");
46
- const batch_1 = require("./utils/batch.cjs");
47
47
  const eip7702_1 = require("./utils/eip7702.cjs");
48
48
  const external_transactions_1 = require("./utils/external-transactions.cjs");
49
49
  const gas_1 = require("./utils/gas.cjs");
@@ -53,7 +53,6 @@ const history_1 = require("./utils/history.cjs");
53
53
  const layer1_gas_fee_flow_1 = require("./utils/layer1-gas-fee-flow.cjs");
54
54
  const nonce_1 = require("./utils/nonce.cjs");
55
55
  const prepare_1 = require("./utils/prepare.cjs");
56
- const resimulate_1 = require("./utils/resimulate.cjs");
57
56
  const retry_1 = require("./utils/retry.cjs");
58
57
  const simulation_1 = require("./utils/simulation.cjs");
59
58
  const swaps_1 = require("./utils/swaps.cjs");
@@ -303,6 +302,13 @@ class TransactionController extends base_controller_1.BaseController {
303
302
  // when transactionsController state changes
304
303
  // check for pending transactions and start polling if there are any
305
304
  this.messagingSystem.subscribe('TransactionController:stateChange', __classPrivateFieldGet(this, _TransactionController_checkForPendingTransactionAndStartPolling, "f"));
305
+ new ResimulateHelper_1.ResimulateHelper({
306
+ simulateTransaction: __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_updateSimulationData).bind(this),
307
+ onTransactionsUpdate: (listener) => {
308
+ this.messagingSystem.subscribe('TransactionController:stateChange', listener, (controllerState) => controllerState.transactions);
309
+ },
310
+ getTransactions: () => this.state.transactions,
311
+ });
306
312
  this.onBootCleanup();
307
313
  __classPrivateFieldGet(this, _TransactionController_checkForPendingTransactionAndStartPolling, "f").call(this);
308
314
  }
@@ -322,34 +328,6 @@ class TransactionController extends base_controller_1.BaseController {
322
328
  async handleMethodData(fourBytePrefix, networkClientId) {
323
329
  return __classPrivateFieldGet(this, _TransactionController_methodDataHelper, "f").lookup(fourBytePrefix, networkClientId);
324
330
  }
325
- /**
326
- * Add a batch of transactions to be submitted after approval.
327
- *
328
- * @param request - Request object containing the transactions to add.
329
- * @returns Result object containing the generated batch ID.
330
- */
331
- async addTransactionBatch(request) {
332
- return await (0, batch_1.addTransactionBatch)({
333
- addTransaction: this.addTransaction.bind(this),
334
- getChainId: __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getChainId).bind(this),
335
- getEthQuery: (networkClientId) => __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getEthQuery).call(this, { networkClientId }),
336
- messenger: this.messagingSystem,
337
- request,
338
- });
339
- }
340
- /**
341
- * Determine which chains support atomic batch transactions with the given account address.
342
- *
343
- * @param address - The address of the account to check.
344
- * @returns The supported chain IDs.
345
- */
346
- async isAtomicBatchSupported(address) {
347
- return (0, batch_1.isAtomicBatchSupported)({
348
- address,
349
- getEthQuery: (chainId) => __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getEthQuery).call(this, { chainId }),
350
- messenger: this.messagingSystem,
351
- });
352
- }
353
331
  /**
354
332
  * Add a new unapproved transaction to state. Parameters will be validated, a
355
333
  * unique transaction id will be generated, and gas and gasPrice will be calculated
@@ -360,7 +338,6 @@ class TransactionController extends base_controller_1.BaseController {
360
338
  * @param options.actionId - Unique ID to prevent duplicate requests.
361
339
  * @param options.deviceConfirmedOn - An enum to indicate what device confirmed the transaction.
362
340
  * @param options.method - RPC method that requested the transaction.
363
- * @param options.nestedTransactions - Params for any nested transactions encoded in the data.
364
341
  * @param options.origin - The origin of the transaction request, such as a dApp hostname.
365
342
  * @param options.requireApproval - Whether the transaction requires approval by the user, defaults to true unless explicitly disabled.
366
343
  * @param options.securityAlertResponse - Response from security validator.
@@ -375,7 +352,7 @@ class TransactionController extends base_controller_1.BaseController {
375
352
  */
376
353
  async addTransaction(txParams, options) {
377
354
  (0, logger_1.projectLogger)('Adding transaction', txParams, options);
378
- const { actionId, deviceConfirmedOn, method, nestedTransactions, networkClientId, origin, requireApproval, securityAlertResponse, sendFlowHistory, swaps = {}, traceContext, type, } = options;
355
+ const { actionId, deviceConfirmedOn, method, networkClientId, origin, requireApproval, securityAlertResponse, sendFlowHistory, swaps = {}, traceContext, type, } = options;
379
356
  txParams = (0, utils_2.normalizeTransactionParams)(txParams);
380
357
  if (!__classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").has(networkClientId)) {
381
358
  throw new Error(`Network client not found - ${networkClientId}`);
@@ -384,15 +361,12 @@ class TransactionController extends base_controller_1.BaseController {
384
361
  ? undefined
385
362
  : await this.getPermittedAccounts?.(origin);
386
363
  const selectedAddress = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getSelectedAccount).call(this).address;
387
- const internalAccounts = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getInternalAccounts).call(this);
388
364
  await (0, validation_1.validateTransactionOrigin)({
389
365
  from: txParams.from,
390
- internalAccounts,
391
366
  origin,
392
367
  permittedAddresses,
393
368
  selectedAddress,
394
369
  txParams,
395
- type,
396
370
  });
397
371
  const isEIP1559Compatible = await this.getEIP1559Compatibility(networkClientId);
398
372
  (0, validation_1.validateTxParams)(txParams, isEIP1559Compatible);
@@ -414,7 +388,6 @@ class TransactionController extends base_controller_1.BaseController {
414
388
  deviceConfirmedOn,
415
389
  id: (0, uuid_1.v1)(),
416
390
  isFirstTimeInteraction: undefined,
417
- nestedTransactions,
418
391
  networkClientId,
419
392
  origin,
420
393
  securityAlertResponse,
@@ -829,6 +802,27 @@ class TransactionController extends base_controller_1.BaseController {
829
802
  this.updateTransaction(updatedTransaction, `Update Editable Params for ${txId}`);
830
803
  return this.getTransaction(txId);
831
804
  }
805
+ /**
806
+ * Update the isActive state of a transaction.
807
+ *
808
+ * @param transactionId - The ID of the transaction to update.
809
+ * @param isActive - The active state.
810
+ */
811
+ setTransactionActive(transactionId, isActive) {
812
+ const transactionMeta = this.getTransaction(transactionId);
813
+ if (!transactionMeta) {
814
+ throw new Error(`Transaction with id ${transactionId} not found`);
815
+ }
816
+ __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_updateTransactionInternal).call(this, {
817
+ transactionId,
818
+ note: 'TransactionController#setTransactionActive - Transaction isActive updated',
819
+ skipHistory: true,
820
+ skipValidation: true,
821
+ skipResimulateCheck: true,
822
+ }, (updatedTransactionMeta) => {
823
+ updatedTransactionMeta.isActive = isActive;
824
+ });
825
+ }
832
826
  /**
833
827
  * Signs and returns the raw transaction data for provided transaction params list.
834
828
  *
@@ -1257,7 +1251,7 @@ class TransactionController extends base_controller_1.BaseController {
1257
1251
  }
1258
1252
  });
1259
1253
  this.onTransactionStatusChange(transactionMeta);
1260
- const rawTx = await __classPrivateFieldGet(this, _TransactionController_trace, "f").call(this, { name: 'Sign', parentContext: traceContext }, () => this.signTransaction(transactionMeta));
1254
+ const rawTx = await __classPrivateFieldGet(this, _TransactionController_trace, "f").call(this, { name: 'Sign', parentContext: traceContext }, () => this.signTransaction(transactionMeta, transactionMeta.txParams));
1261
1255
  if (!this.beforePublish(transactionMeta)) {
1262
1256
  (0, logger_1.projectLogger)('Skipping publishing transaction based on hook');
1263
1257
  this.messagingSystem.publish(`${controllerName}:transactionPublishingSkipped`, transactionMeta);
@@ -1624,8 +1618,7 @@ class TransactionController extends base_controller_1.BaseController {
1624
1618
  const currentAccountIsEIP1559Compatible = await this.getCurrentAccountEIP1559Compatibility();
1625
1619
  return (currentNetworkIsEIP1559Compatible && currentAccountIsEIP1559Compatible);
1626
1620
  }
1627
- async signTransaction(transactionMeta) {
1628
- const { txParams } = transactionMeta;
1621
+ async signTransaction(transactionMeta, txParams) {
1629
1622
  (0, logger_1.projectLogger)('Signing transaction', txParams);
1630
1623
  const { authorizationList, from } = txParams;
1631
1624
  const finalTxParams = { ...txParams };
@@ -1654,7 +1647,6 @@ class TransactionController extends base_controller_1.BaseController {
1654
1647
  const transactionMetaWithRsv = {
1655
1648
  ...this.updateTransactionMetaRSV(transactionMetaFromHook, signedTx),
1656
1649
  status: types_1.TransactionStatus.signed,
1657
- txParams: finalTxParams,
1658
1650
  };
1659
1651
  this.updateTransaction(transactionMetaWithRsv, 'TransactionController#approveTransaction - Transaction signed');
1660
1652
  this.onTransactionStatusChange(transactionMetaWithRsv);
@@ -1883,7 +1875,7 @@ _TransactionController_internalEvents = new WeakMap(), _TransactionController_me
1883
1875
  (0, validation_1.validateTxParams)(transactionMeta.txParams);
1884
1876
  }
1885
1877
  if (!skipResimulateCheck && __classPrivateFieldGet(this, _TransactionController_isSimulationEnabled, "f").call(this)) {
1886
- resimulateResponse = (0, resimulate_1.shouldResimulate)(originalTransactionMeta, transactionMeta);
1878
+ resimulateResponse = (0, ResimulateHelper_1.shouldResimulate)(originalTransactionMeta, transactionMeta);
1887
1879
  }
1888
1880
  const shouldSkipHistory = this.isHistoryDisabled || skipHistory;
1889
1881
  if (!shouldSkipHistory) {
@@ -1965,7 +1957,7 @@ _TransactionController_internalEvents = new WeakMap(), _TransactionController_me
1965
1957
  }));
1966
1958
  if (blockTime &&
1967
1959
  prevSimulationData &&
1968
- (0, resimulate_1.hasSimulationDataChanged)(prevSimulationData, simulationData)) {
1960
+ (0, ResimulateHelper_1.hasSimulationDataChanged)(prevSimulationData, simulationData)) {
1969
1961
  simulationData = {
1970
1962
  ...simulationData,
1971
1963
  isUpdatedAfterSecurityCheck: true,
@@ -2000,11 +1992,6 @@ _TransactionController_internalEvents = new WeakMap(), _TransactionController_me
2000
1992
  });
2001
1993
  }, _TransactionController_getSelectedAccount = function _TransactionController_getSelectedAccount() {
2002
1994
  return this.messagingSystem.call('AccountsController:getSelectedAccount');
2003
- }, _TransactionController_getInternalAccounts = function _TransactionController_getInternalAccounts() {
2004
- const state = this.messagingSystem.call('AccountsController:getState');
2005
- return Object.values(state.internalAccounts?.accounts ?? {})
2006
- .filter((account) => account.type === 'eip155:eoa')
2007
- .map((account) => account.address);
2008
1995
  }, _TransactionController_updateSubmitHistory = function _TransactionController_updateSubmitHistory(transactionMeta, hash) {
2009
1996
  const { chainId, networkClientId, origin, rawTx, txParams } = transactionMeta;
2010
1997
  const { networkConfigurationsByChainId } = this.getNetworkState();