@metamask-previews/transaction-controller 46.0.0-preview-ea165590 → 46.0.0-preview-7a21cbc

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 +49 -5
  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 +49 -5
  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 +84 -2
  41. package/dist/utils/eip7702.cjs.map +1 -1
  42. package/dist/utils/eip7702.d.cts +42 -3
  43. package/dist/utils/eip7702.d.cts.map +1 -1
  44. package/dist/utils/eip7702.d.mts +42 -3
  45. package/dist/utils/eip7702.d.mts.map +1 -1
  46. package/dist/utils/eip7702.mjs +82 -3
  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 +39 -0
  51. package/dist/utils/feature-flags.d.cts.map +1 -0
  52. package/dist/utils/feature-flags.d.mts +39 -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
  ## [46.0.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");
@@ -44,6 +44,7 @@ const PendingTransactionTracker_1 = require("./helpers/PendingTransactionTracker
44
44
  const ResimulateHelper_1 = require("./helpers/ResimulateHelper.cjs");
45
45
  const logger_1 = require("./logger.cjs");
46
46
  const types_1 = require("./types.cjs");
47
+ const batch_1 = require("./utils/batch.cjs");
47
48
  const eip7702_1 = require("./utils/eip7702.cjs");
48
49
  const external_transactions_1 = require("./utils/external-transactions.cjs");
49
50
  const gas_1 = require("./utils/gas.cjs");
@@ -328,6 +329,34 @@ class TransactionController extends base_controller_1.BaseController {
328
329
  async handleMethodData(fourBytePrefix, networkClientId) {
329
330
  return __classPrivateFieldGet(this, _TransactionController_methodDataHelper, "f").lookup(fourBytePrefix, networkClientId);
330
331
  }
332
+ /**
333
+ * Add a batch of transactions to be submitted after approval.
334
+ *
335
+ * @param request - Request object containing the transactions to add.
336
+ * @returns Result object containing the generated batch ID.
337
+ */
338
+ async addTransactionBatch(request) {
339
+ return await (0, batch_1.addTransactionBatch)({
340
+ addTransaction: this.addTransaction.bind(this),
341
+ getChainId: __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getChainId).bind(this),
342
+ getEthQuery: (networkClientId) => __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getEthQuery).call(this, { networkClientId }),
343
+ messenger: this.messagingSystem,
344
+ request,
345
+ });
346
+ }
347
+ /**
348
+ * Determine which chains support atomic batch transactions with the given account address.
349
+ *
350
+ * @param address - The address of the account to check.
351
+ * @returns The supported chain IDs.
352
+ */
353
+ async isAtomicBatchSupported(address) {
354
+ return (0, batch_1.isAtomicBatchSupported)({
355
+ address,
356
+ getEthQuery: (chainId) => __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getEthQuery).call(this, { chainId }),
357
+ messenger: this.messagingSystem,
358
+ });
359
+ }
331
360
  /**
332
361
  * Add a new unapproved transaction to state. Parameters will be validated, a
333
362
  * unique transaction id will be generated, and gas and gasPrice will be calculated
@@ -338,6 +367,7 @@ class TransactionController extends base_controller_1.BaseController {
338
367
  * @param options.actionId - Unique ID to prevent duplicate requests.
339
368
  * @param options.deviceConfirmedOn - An enum to indicate what device confirmed the transaction.
340
369
  * @param options.method - RPC method that requested the transaction.
370
+ * @param options.nestedTransactions - Params for any nested transactions encoded in the data.
341
371
  * @param options.origin - The origin of the transaction request, such as a dApp hostname.
342
372
  * @param options.requireApproval - Whether the transaction requires approval by the user, defaults to true unless explicitly disabled.
343
373
  * @param options.securityAlertResponse - Response from security validator.
@@ -352,7 +382,7 @@ class TransactionController extends base_controller_1.BaseController {
352
382
  */
353
383
  async addTransaction(txParams, options) {
354
384
  (0, logger_1.projectLogger)('Adding transaction', txParams, options);
355
- const { actionId, deviceConfirmedOn, method, networkClientId, origin, requireApproval, securityAlertResponse, sendFlowHistory, swaps = {}, traceContext, type, } = options;
385
+ const { actionId, deviceConfirmedOn, method, nestedTransactions, networkClientId, origin, requireApproval, securityAlertResponse, sendFlowHistory, swaps = {}, traceContext, type, } = options;
356
386
  txParams = (0, utils_2.normalizeTransactionParams)(txParams);
357
387
  if (!__classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").has(networkClientId)) {
358
388
  throw new Error(`Network client not found - ${networkClientId}`);
@@ -361,12 +391,15 @@ class TransactionController extends base_controller_1.BaseController {
361
391
  ? undefined
362
392
  : await this.getPermittedAccounts?.(origin);
363
393
  const selectedAddress = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getSelectedAccount).call(this).address;
394
+ const internalAccounts = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getInternalAccounts).call(this);
364
395
  await (0, validation_1.validateTransactionOrigin)({
365
396
  from: txParams.from,
397
+ internalAccounts,
366
398
  origin,
367
399
  permittedAddresses,
368
400
  selectedAddress,
369
401
  txParams,
402
+ type,
370
403
  });
371
404
  const isEIP1559Compatible = await this.getEIP1559Compatibility(networkClientId);
372
405
  (0, validation_1.validateTxParams)(txParams, isEIP1559Compatible);
@@ -388,6 +421,7 @@ class TransactionController extends base_controller_1.BaseController {
388
421
  deviceConfirmedOn,
389
422
  id: (0, uuid_1.v1)(),
390
423
  isFirstTimeInteraction: undefined,
424
+ nestedTransactions,
391
425
  networkClientId,
392
426
  origin,
393
427
  securityAlertResponse,
@@ -1183,7 +1217,10 @@ class TransactionController extends base_controller_1.BaseController {
1183
1217
  if (!isTxCompleted) {
1184
1218
  if (error?.code === rpc_errors_1.errorCodes.provider.userRejectedRequest) {
1185
1219
  this.cancelTransaction(transactionId, actionId);
1186
- throw rpc_errors_1.providerErrors.userRejectedRequest('MetaMask Tx Signature: User denied transaction signature.');
1220
+ throw rpc_errors_1.providerErrors.userRejectedRequest({
1221
+ message: 'MetaMask Tx Signature: User denied transaction signature.',
1222
+ data: error?.data,
1223
+ });
1187
1224
  }
1188
1225
  else {
1189
1226
  this.failTransaction(meta, error, actionId);
@@ -1251,7 +1288,7 @@ class TransactionController extends base_controller_1.BaseController {
1251
1288
  }
1252
1289
  });
1253
1290
  this.onTransactionStatusChange(transactionMeta);
1254
- const rawTx = await __classPrivateFieldGet(this, _TransactionController_trace, "f").call(this, { name: 'Sign', parentContext: traceContext }, () => this.signTransaction(transactionMeta, transactionMeta.txParams));
1291
+ const rawTx = await __classPrivateFieldGet(this, _TransactionController_trace, "f").call(this, { name: 'Sign', parentContext: traceContext }, () => this.signTransaction(transactionMeta));
1255
1292
  if (!this.beforePublish(transactionMeta)) {
1256
1293
  (0, logger_1.projectLogger)('Skipping publishing transaction based on hook');
1257
1294
  this.messagingSystem.publish(`${controllerName}:transactionPublishingSkipped`, transactionMeta);
@@ -1618,7 +1655,8 @@ class TransactionController extends base_controller_1.BaseController {
1618
1655
  const currentAccountIsEIP1559Compatible = await this.getCurrentAccountEIP1559Compatibility();
1619
1656
  return (currentNetworkIsEIP1559Compatible && currentAccountIsEIP1559Compatible);
1620
1657
  }
1621
- async signTransaction(transactionMeta, txParams) {
1658
+ async signTransaction(transactionMeta) {
1659
+ const { txParams } = transactionMeta;
1622
1660
  (0, logger_1.projectLogger)('Signing transaction', txParams);
1623
1661
  const { authorizationList, from } = txParams;
1624
1662
  const finalTxParams = { ...txParams };
@@ -1647,6 +1685,7 @@ class TransactionController extends base_controller_1.BaseController {
1647
1685
  const transactionMetaWithRsv = {
1648
1686
  ...this.updateTransactionMetaRSV(transactionMetaFromHook, signedTx),
1649
1687
  status: types_1.TransactionStatus.signed,
1688
+ txParams: finalTxParams,
1650
1689
  };
1651
1690
  this.updateTransaction(transactionMetaWithRsv, 'TransactionController#approveTransaction - Transaction signed');
1652
1691
  this.onTransactionStatusChange(transactionMetaWithRsv);
@@ -1992,6 +2031,11 @@ _TransactionController_internalEvents = new WeakMap(), _TransactionController_me
1992
2031
  });
1993
2032
  }, _TransactionController_getSelectedAccount = function _TransactionController_getSelectedAccount() {
1994
2033
  return this.messagingSystem.call('AccountsController:getSelectedAccount');
2034
+ }, _TransactionController_getInternalAccounts = function _TransactionController_getInternalAccounts() {
2035
+ const state = this.messagingSystem.call('AccountsController:getState');
2036
+ return Object.values(state.internalAccounts?.accounts ?? {})
2037
+ .filter((account) => account.type === 'eip155:eoa')
2038
+ .map((account) => account.address);
1995
2039
  }, _TransactionController_updateSubmitHistory = function _TransactionController_updateSubmitHistory(transactionMeta, hash) {
1996
2040
  const { chainId, networkClientId, origin, rawTx, txParams } = transactionMeta;
1997
2041
  const { networkConfigurationsByChainId } = this.getNetworkState();