@metamask-previews/transaction-controller 45.1.0-preview-df91d059 → 45.1.0-preview-862b5dac

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 (64) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/TransactionController.cjs +45 -4
  3. package/dist/TransactionController.cjs.map +1 -1
  4. package/dist/TransactionController.d.cts +20 -3
  5. package/dist/TransactionController.d.cts.map +1 -1
  6. package/dist/TransactionController.d.mts +20 -3
  7. package/dist/TransactionController.d.mts.map +1 -1
  8. package/dist/TransactionController.mjs +45 -4
  9. package/dist/TransactionController.mjs.map +1 -1
  10. package/dist/constants.cjs +20 -1
  11. package/dist/constants.cjs.map +1 -1
  12. package/dist/constants.d.cts +15 -0
  13. package/dist/constants.d.cts.map +1 -1
  14. package/dist/constants.d.mts +15 -0
  15. package/dist/constants.d.mts.map +1 -1
  16. package/dist/constants.mjs +19 -0
  17. package/dist/constants.mjs.map +1 -1
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +1 -1
  20. package/dist/index.d.cts.map +1 -1
  21. package/dist/index.d.mts +1 -1
  22. package/dist/index.d.mts.map +1 -1
  23. package/dist/index.mjs.map +1 -1
  24. package/dist/types.cjs +5 -0
  25. package/dist/types.cjs.map +1 -1
  26. package/dist/types.d.cts +51 -0
  27. package/dist/types.d.cts.map +1 -1
  28. package/dist/types.d.mts +51 -0
  29. package/dist/types.d.mts.map +1 -1
  30. package/dist/types.mjs +5 -0
  31. package/dist/types.mjs.map +1 -1
  32. package/dist/utils/batch.cjs +84 -0
  33. package/dist/utils/batch.cjs.map +1 -0
  34. package/dist/utils/batch.d.cts +32 -0
  35. package/dist/utils/batch.d.cts.map +1 -0
  36. package/dist/utils/batch.d.mts +32 -0
  37. package/dist/utils/batch.d.mts.map +1 -0
  38. package/dist/utils/batch.mjs +79 -0
  39. package/dist/utils/batch.mjs.map +1 -0
  40. package/dist/utils/eip7702.cjs +76 -1
  41. package/dist/utils/eip7702.cjs.map +1 -1
  42. package/dist/utils/eip7702.d.cts +35 -1
  43. package/dist/utils/eip7702.d.cts.map +1 -1
  44. package/dist/utils/eip7702.d.mts +35 -1
  45. package/dist/utils/eip7702.d.mts.map +1 -1
  46. package/dist/utils/eip7702.mjs +74 -2
  47. package/dist/utils/eip7702.mjs.map +1 -1
  48. package/dist/utils/feature-flags.cjs +53 -0
  49. package/dist/utils/feature-flags.cjs.map +1 -0
  50. package/dist/utils/feature-flags.d.cts +34 -0
  51. package/dist/utils/feature-flags.d.cts.map +1 -0
  52. package/dist/utils/feature-flags.d.mts +34 -0
  53. package/dist/utils/feature-flags.d.mts.map +1 -0
  54. package/dist/utils/feature-flags.mjs +47 -0
  55. package/dist/utils/feature-flags.mjs.map +1 -0
  56. package/dist/utils/validation.cjs +15 -4
  57. package/dist/utils/validation.cjs.map +1 -1
  58. package/dist/utils/validation.d.cts +7 -3
  59. package/dist/utils/validation.d.cts.map +1 -1
  60. package/dist/utils/validation.d.mts +7 -3
  61. package/dist/utils/validation.d.mts.map +1 -1
  62. package/dist/utils/validation.mjs +16 -5
  63. package/dist/utils/validation.mjs.map +1 -1
  64. package/package.json +5 -3
package/CHANGELOG.md CHANGED
@@ -7,6 +7,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ### Added
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.
30
+
10
31
  ## [45.1.0]
11
32
 
12
33
  ### Added
@@ -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_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_getInternalAccounts, _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");
@@ -43,6 +43,7 @@ const MultichainTrackingHelper_1 = require("./helpers/MultichainTrackingHelper.c
43
43
  const PendingTransactionTracker_1 = require("./helpers/PendingTransactionTracker.cjs");
44
44
  const logger_1 = require("./logger.cjs");
45
45
  const types_1 = require("./types.cjs");
46
+ const batch_1 = require("./utils/batch.cjs");
46
47
  const eip7702_1 = require("./utils/eip7702.cjs");
47
48
  const external_transactions_1 = require("./utils/external-transactions.cjs");
48
49
  const gas_1 = require("./utils/gas.cjs");
@@ -321,6 +322,34 @@ class TransactionController extends base_controller_1.BaseController {
321
322
  async handleMethodData(fourBytePrefix, networkClientId) {
322
323
  return __classPrivateFieldGet(this, _TransactionController_methodDataHelper, "f").lookup(fourBytePrefix, networkClientId);
323
324
  }
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
+ }
324
353
  /**
325
354
  * Add a new unapproved transaction to state. Parameters will be validated, a
326
355
  * unique transaction id will be generated, and gas and gasPrice will be calculated
@@ -331,6 +360,7 @@ class TransactionController extends base_controller_1.BaseController {
331
360
  * @param options.actionId - Unique ID to prevent duplicate requests.
332
361
  * @param options.deviceConfirmedOn - An enum to indicate what device confirmed the transaction.
333
362
  * @param options.method - RPC method that requested the transaction.
363
+ * @param options.nestedTransactions - Params for any nested transactions encoded in the data.
334
364
  * @param options.origin - The origin of the transaction request, such as a dApp hostname.
335
365
  * @param options.requireApproval - Whether the transaction requires approval by the user, defaults to true unless explicitly disabled.
336
366
  * @param options.securityAlertResponse - Response from security validator.
@@ -345,7 +375,7 @@ class TransactionController extends base_controller_1.BaseController {
345
375
  */
346
376
  async addTransaction(txParams, options) {
347
377
  (0, logger_1.projectLogger)('Adding transaction', txParams, options);
348
- const { actionId, deviceConfirmedOn, method, networkClientId, origin, requireApproval, securityAlertResponse, sendFlowHistory, swaps = {}, traceContext, type, } = options;
378
+ const { actionId, deviceConfirmedOn, method, nestedTransactions, networkClientId, origin, requireApproval, securityAlertResponse, sendFlowHistory, swaps = {}, traceContext, type, } = options;
349
379
  txParams = (0, utils_2.normalizeTransactionParams)(txParams);
350
380
  if (!__classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").has(networkClientId)) {
351
381
  throw new Error(`Network client not found - ${networkClientId}`);
@@ -354,12 +384,15 @@ class TransactionController extends base_controller_1.BaseController {
354
384
  ? undefined
355
385
  : await this.getPermittedAccounts?.(origin);
356
386
  const selectedAddress = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getSelectedAccount).call(this).address;
387
+ const internalAccounts = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getInternalAccounts).call(this);
357
388
  await (0, validation_1.validateTransactionOrigin)({
358
389
  from: txParams.from,
390
+ internalAccounts,
359
391
  origin,
360
392
  permittedAddresses,
361
393
  selectedAddress,
362
394
  txParams,
395
+ type,
363
396
  });
364
397
  const isEIP1559Compatible = await this.getEIP1559Compatibility(networkClientId);
365
398
  (0, validation_1.validateTxParams)(txParams, isEIP1559Compatible);
@@ -381,6 +414,7 @@ class TransactionController extends base_controller_1.BaseController {
381
414
  deviceConfirmedOn,
382
415
  id: (0, uuid_1.v1)(),
383
416
  isFirstTimeInteraction: undefined,
417
+ nestedTransactions,
384
418
  networkClientId,
385
419
  origin,
386
420
  securityAlertResponse,
@@ -1223,7 +1257,7 @@ class TransactionController extends base_controller_1.BaseController {
1223
1257
  }
1224
1258
  });
1225
1259
  this.onTransactionStatusChange(transactionMeta);
1226
- const rawTx = await __classPrivateFieldGet(this, _TransactionController_trace, "f").call(this, { name: 'Sign', parentContext: traceContext }, () => this.signTransaction(transactionMeta, transactionMeta.txParams));
1260
+ const rawTx = await __classPrivateFieldGet(this, _TransactionController_trace, "f").call(this, { name: 'Sign', parentContext: traceContext }, () => this.signTransaction(transactionMeta));
1227
1261
  if (!this.beforePublish(transactionMeta)) {
1228
1262
  (0, logger_1.projectLogger)('Skipping publishing transaction based on hook');
1229
1263
  this.messagingSystem.publish(`${controllerName}:transactionPublishingSkipped`, transactionMeta);
@@ -1590,7 +1624,8 @@ class TransactionController extends base_controller_1.BaseController {
1590
1624
  const currentAccountIsEIP1559Compatible = await this.getCurrentAccountEIP1559Compatibility();
1591
1625
  return (currentNetworkIsEIP1559Compatible && currentAccountIsEIP1559Compatible);
1592
1626
  }
1593
- async signTransaction(transactionMeta, txParams) {
1627
+ async signTransaction(transactionMeta) {
1628
+ const { txParams } = transactionMeta;
1594
1629
  (0, logger_1.projectLogger)('Signing transaction', txParams);
1595
1630
  const { authorizationList, from } = txParams;
1596
1631
  const finalTxParams = { ...txParams };
@@ -1619,6 +1654,7 @@ class TransactionController extends base_controller_1.BaseController {
1619
1654
  const transactionMetaWithRsv = {
1620
1655
  ...this.updateTransactionMetaRSV(transactionMetaFromHook, signedTx),
1621
1656
  status: types_1.TransactionStatus.signed,
1657
+ txParams: finalTxParams,
1622
1658
  };
1623
1659
  this.updateTransaction(transactionMetaWithRsv, 'TransactionController#approveTransaction - Transaction signed');
1624
1660
  this.onTransactionStatusChange(transactionMetaWithRsv);
@@ -1964,6 +2000,11 @@ _TransactionController_internalEvents = new WeakMap(), _TransactionController_me
1964
2000
  });
1965
2001
  }, _TransactionController_getSelectedAccount = function _TransactionController_getSelectedAccount() {
1966
2002
  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);
1967
2008
  }, _TransactionController_updateSubmitHistory = function _TransactionController_updateSubmitHistory(transactionMeta, hash) {
1968
2009
  const { chainId, networkClientId, origin, rawTx, txParams } = transactionMeta;
1969
2010
  const { networkConfigurationsByChainId } = this.getNetworkState();