@metamask/transaction-controller 46.0.0 → 48.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 (196) hide show
  1. package/CHANGELOG.md +39 -1
  2. package/dist/TransactionController.cjs +121 -40
  3. package/dist/TransactionController.cjs.map +1 -1
  4. package/dist/TransactionController.d.cts +81 -72
  5. package/dist/TransactionController.d.cts.map +1 -1
  6. package/dist/TransactionController.d.mts +81 -72
  7. package/dist/TransactionController.d.mts.map +1 -1
  8. package/dist/TransactionController.mjs +122 -41
  9. package/dist/TransactionController.mjs.map +1 -1
  10. package/dist/api/accounts-api.cjs +2 -0
  11. package/dist/api/accounts-api.cjs.map +1 -1
  12. package/dist/api/accounts-api.d.cts +2 -0
  13. package/dist/api/accounts-api.d.cts.map +1 -1
  14. package/dist/api/accounts-api.d.mts +2 -0
  15. package/dist/api/accounts-api.d.mts.map +1 -1
  16. package/dist/api/accounts-api.mjs +2 -0
  17. package/dist/api/accounts-api.mjs.map +1 -1
  18. package/dist/constants.cjs +20 -1
  19. package/dist/constants.cjs.map +1 -1
  20. package/dist/constants.d.cts +15 -0
  21. package/dist/constants.d.cts.map +1 -1
  22. package/dist/constants.d.mts +15 -0
  23. package/dist/constants.d.mts.map +1 -1
  24. package/dist/constants.mjs +19 -0
  25. package/dist/constants.mjs.map +1 -1
  26. package/dist/gas-flows/LineaGasFeeFlow.cjs +1 -1
  27. package/dist/gas-flows/LineaGasFeeFlow.cjs.map +1 -1
  28. package/dist/gas-flows/LineaGasFeeFlow.d.cts.map +1 -1
  29. package/dist/gas-flows/LineaGasFeeFlow.d.mts.map +1 -1
  30. package/dist/gas-flows/LineaGasFeeFlow.mjs +1 -1
  31. package/dist/gas-flows/LineaGasFeeFlow.mjs.map +1 -1
  32. package/dist/gas-flows/OptimismLayer1GasFeeFlow.cjs +1 -1
  33. package/dist/gas-flows/OptimismLayer1GasFeeFlow.cjs.map +1 -1
  34. package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.cts +1 -1
  35. package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.cts.map +1 -1
  36. package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.mts +1 -1
  37. package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.mts.map +1 -1
  38. package/dist/gas-flows/OptimismLayer1GasFeeFlow.mjs +1 -1
  39. package/dist/gas-flows/OptimismLayer1GasFeeFlow.mjs.map +1 -1
  40. package/dist/gas-flows/ScrollLayer1GasFeeFlow.cjs +1 -1
  41. package/dist/gas-flows/ScrollLayer1GasFeeFlow.cjs.map +1 -1
  42. package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.cts +1 -1
  43. package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.cts.map +1 -1
  44. package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.mts +1 -1
  45. package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.mts.map +1 -1
  46. package/dist/gas-flows/ScrollLayer1GasFeeFlow.mjs +1 -1
  47. package/dist/gas-flows/ScrollLayer1GasFeeFlow.mjs.map +1 -1
  48. package/dist/helpers/GasFeePoller.cjs +1 -0
  49. package/dist/helpers/GasFeePoller.cjs.map +1 -1
  50. package/dist/helpers/GasFeePoller.d.cts +1 -0
  51. package/dist/helpers/GasFeePoller.d.cts.map +1 -1
  52. package/dist/helpers/GasFeePoller.d.mts +1 -0
  53. package/dist/helpers/GasFeePoller.d.mts.map +1 -1
  54. package/dist/helpers/GasFeePoller.mjs +1 -0
  55. package/dist/helpers/GasFeePoller.mjs.map +1 -1
  56. package/dist/helpers/IncomingTransactionHelper.cjs.map +1 -1
  57. package/dist/helpers/IncomingTransactionHelper.d.cts.map +1 -1
  58. package/dist/helpers/IncomingTransactionHelper.d.mts.map +1 -1
  59. package/dist/helpers/IncomingTransactionHelper.mjs.map +1 -1
  60. package/dist/helpers/MethodDataHelper.cjs.map +1 -1
  61. package/dist/helpers/MethodDataHelper.d.cts.map +1 -1
  62. package/dist/helpers/MethodDataHelper.d.mts.map +1 -1
  63. package/dist/helpers/MethodDataHelper.mjs.map +1 -1
  64. package/dist/helpers/MultichainTrackingHelper.cjs +1 -21
  65. package/dist/helpers/MultichainTrackingHelper.cjs.map +1 -1
  66. package/dist/helpers/MultichainTrackingHelper.d.cts.map +1 -1
  67. package/dist/helpers/MultichainTrackingHelper.d.mts.map +1 -1
  68. package/dist/helpers/MultichainTrackingHelper.mjs +1 -21
  69. package/dist/helpers/MultichainTrackingHelper.mjs.map +1 -1
  70. package/dist/helpers/PendingTransactionTracker.cjs.map +1 -1
  71. package/dist/helpers/PendingTransactionTracker.d.cts.map +1 -1
  72. package/dist/helpers/PendingTransactionTracker.d.mts.map +1 -1
  73. package/dist/helpers/PendingTransactionTracker.mjs.map +1 -1
  74. package/dist/helpers/TransactionPoller.cjs +2 -0
  75. package/dist/helpers/TransactionPoller.cjs.map +1 -1
  76. package/dist/helpers/TransactionPoller.d.cts +2 -0
  77. package/dist/helpers/TransactionPoller.d.cts.map +1 -1
  78. package/dist/helpers/TransactionPoller.d.mts +2 -0
  79. package/dist/helpers/TransactionPoller.d.mts.map +1 -1
  80. package/dist/helpers/TransactionPoller.mjs +2 -0
  81. package/dist/helpers/TransactionPoller.mjs.map +1 -1
  82. package/dist/index.cjs.map +1 -1
  83. package/dist/index.d.cts +1 -1
  84. package/dist/index.d.cts.map +1 -1
  85. package/dist/index.d.mts +1 -1
  86. package/dist/index.d.mts.map +1 -1
  87. package/dist/index.mjs.map +1 -1
  88. package/dist/types.cjs +5 -0
  89. package/dist/types.cjs.map +1 -1
  90. package/dist/types.d.cts +51 -0
  91. package/dist/types.d.cts.map +1 -1
  92. package/dist/types.d.mts +51 -0
  93. package/dist/types.d.mts.map +1 -1
  94. package/dist/types.mjs +5 -0
  95. package/dist/types.mjs.map +1 -1
  96. package/dist/utils/batch.cjs +89 -0
  97. package/dist/utils/batch.cjs.map +1 -0
  98. package/dist/utils/batch.d.cts +33 -0
  99. package/dist/utils/batch.d.cts.map +1 -0
  100. package/dist/utils/batch.d.mts +33 -0
  101. package/dist/utils/batch.d.mts.map +1 -0
  102. package/dist/utils/batch.mjs +84 -0
  103. package/dist/utils/batch.mjs.map +1 -0
  104. package/dist/utils/eip7702.cjs +84 -2
  105. package/dist/utils/eip7702.cjs.map +1 -1
  106. package/dist/utils/eip7702.d.cts +35 -10
  107. package/dist/utils/eip7702.d.cts.map +1 -1
  108. package/dist/utils/eip7702.d.mts +35 -10
  109. package/dist/utils/eip7702.d.mts.map +1 -1
  110. package/dist/utils/eip7702.mjs +82 -3
  111. package/dist/utils/eip7702.mjs.map +1 -1
  112. package/dist/utils/feature-flags.cjs +53 -0
  113. package/dist/utils/feature-flags.cjs.map +1 -0
  114. package/dist/utils/feature-flags.d.cts +39 -0
  115. package/dist/utils/feature-flags.d.cts.map +1 -0
  116. package/dist/utils/feature-flags.d.mts +39 -0
  117. package/dist/utils/feature-flags.d.mts.map +1 -0
  118. package/dist/utils/feature-flags.mjs +47 -0
  119. package/dist/utils/feature-flags.mjs.map +1 -0
  120. package/dist/utils/gas-fees.cjs +48 -3
  121. package/dist/utils/gas-fees.cjs.map +1 -1
  122. package/dist/utils/gas-fees.d.cts +11 -0
  123. package/dist/utils/gas-fees.d.cts.map +1 -1
  124. package/dist/utils/gas-fees.d.mts +11 -0
  125. package/dist/utils/gas-fees.d.mts.map +1 -1
  126. package/dist/utils/gas-fees.mjs +48 -3
  127. package/dist/utils/gas-fees.mjs.map +1 -1
  128. package/dist/utils/gas-flow.cjs +4 -0
  129. package/dist/utils/gas-flow.cjs.map +1 -1
  130. package/dist/utils/gas-flow.d.cts +1 -0
  131. package/dist/utils/gas-flow.d.cts.map +1 -1
  132. package/dist/utils/gas-flow.d.mts +1 -0
  133. package/dist/utils/gas-flow.d.mts.map +1 -1
  134. package/dist/utils/gas-flow.mjs +4 -0
  135. package/dist/utils/gas-flow.mjs.map +1 -1
  136. package/dist/utils/gas.cjs +50 -1
  137. package/dist/utils/gas.cjs.map +1 -1
  138. package/dist/utils/gas.d.cts +22 -0
  139. package/dist/utils/gas.d.cts.map +1 -1
  140. package/dist/utils/gas.d.mts +22 -0
  141. package/dist/utils/gas.d.mts.map +1 -1
  142. package/dist/utils/gas.mjs +50 -1
  143. package/dist/utils/gas.mjs.map +1 -1
  144. package/dist/utils/layer1-gas-fee-flow.cjs +5 -1
  145. package/dist/utils/layer1-gas-fee-flow.cjs.map +1 -1
  146. package/dist/utils/layer1-gas-fee-flow.d.cts +4 -1
  147. package/dist/utils/layer1-gas-fee-flow.d.cts.map +1 -1
  148. package/dist/utils/layer1-gas-fee-flow.d.mts +4 -1
  149. package/dist/utils/layer1-gas-fee-flow.d.mts.map +1 -1
  150. package/dist/utils/layer1-gas-fee-flow.mjs +5 -1
  151. package/dist/utils/layer1-gas-fee-flow.mjs.map +1 -1
  152. package/dist/utils/retry.cjs +4 -0
  153. package/dist/utils/retry.cjs.map +1 -1
  154. package/dist/utils/retry.d.cts +1 -0
  155. package/dist/utils/retry.d.cts.map +1 -1
  156. package/dist/utils/retry.d.mts +1 -0
  157. package/dist/utils/retry.d.mts.map +1 -1
  158. package/dist/utils/retry.mjs +4 -0
  159. package/dist/utils/retry.mjs.map +1 -1
  160. package/dist/utils/simulation-api.cjs +6 -0
  161. package/dist/utils/simulation-api.cjs.map +1 -1
  162. package/dist/utils/simulation-api.d.cts +2 -0
  163. package/dist/utils/simulation-api.d.cts.map +1 -1
  164. package/dist/utils/simulation-api.d.mts +2 -0
  165. package/dist/utils/simulation-api.d.mts.map +1 -1
  166. package/dist/utils/simulation-api.mjs +6 -0
  167. package/dist/utils/simulation-api.mjs.map +1 -1
  168. package/dist/utils/simulation.cjs +19 -5
  169. package/dist/utils/simulation.cjs.map +1 -1
  170. package/dist/utils/simulation.d.cts +3 -1
  171. package/dist/utils/simulation.d.cts.map +1 -1
  172. package/dist/utils/simulation.d.mts +3 -1
  173. package/dist/utils/simulation.d.mts.map +1 -1
  174. package/dist/utils/simulation.mjs +19 -5
  175. package/dist/utils/simulation.mjs.map +1 -1
  176. package/dist/utils/swaps.cjs +2 -1
  177. package/dist/utils/swaps.cjs.map +1 -1
  178. package/dist/utils/swaps.d.cts +1 -0
  179. package/dist/utils/swaps.d.cts.map +1 -1
  180. package/dist/utils/swaps.d.mts +1 -0
  181. package/dist/utils/swaps.d.mts.map +1 -1
  182. package/dist/utils/swaps.mjs +2 -1
  183. package/dist/utils/swaps.mjs.map +1 -1
  184. package/dist/utils/transaction-type.cjs +3 -1
  185. package/dist/utils/transaction-type.cjs.map +1 -1
  186. package/dist/utils/transaction-type.mjs +3 -1
  187. package/dist/utils/transaction-type.mjs.map +1 -1
  188. package/dist/utils/validation.cjs +34 -5
  189. package/dist/utils/validation.cjs.map +1 -1
  190. package/dist/utils/validation.d.cts +19 -3
  191. package/dist/utils/validation.d.cts.map +1 -1
  192. package/dist/utils/validation.d.mts +19 -3
  193. package/dist/utils/validation.d.mts.map +1 -1
  194. package/dist/utils/validation.mjs +33 -5
  195. package/dist/utils/validation.mjs.map +1 -1
  196. package/package.json +9 -7
@@ -9,7 +9,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
9
9
  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");
10
10
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
11
  };
12
- 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;
12
+ 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, _TransactionController_updateGasEstimate;
13
13
  function $importDefault(module) {
14
14
  if (module?.__esModule) {
15
15
  return module.default;
@@ -46,7 +46,8 @@ import { PendingTransactionTracker } from "./helpers/PendingTransactionTracker.m
46
46
  import { ResimulateHelper, hasSimulationDataChanged, shouldResimulate } from "./helpers/ResimulateHelper.mjs";
47
47
  import { projectLogger as log } from "./logger.mjs";
48
48
  import { TransactionEnvelopeType, TransactionType, TransactionStatus, SimulationErrorCode } from "./types.mjs";
49
- import { signAuthorizationList } from "./utils/eip7702.mjs";
49
+ import { addTransactionBatch, isAtomicBatchSupported } from "./utils/batch.mjs";
50
+ import { generateEIP7702BatchTransaction, signAuthorizationList } from "./utils/eip7702.mjs";
50
51
  import { validateConfirmedExternalTransaction } from "./utils/external-transactions.mjs";
51
52
  import { addGasBuffer, estimateGas, updateGas } from "./utils/gas.mjs";
52
53
  import { updateGasFees } from "./utils/gas-fees.mjs";
@@ -155,31 +156,9 @@ export class TransactionController extends BaseController {
155
156
  * Constructs a TransactionController.
156
157
  *
157
158
  * @param options - The controller options.
158
- * @param options.disableHistory - Whether to disable storing history in transaction metadata.
159
- * @param options.disableSendFlowHistory - Explicitly disable transaction metadata history.
160
- * @param options.disableSwaps - Whether to disable additional processing on swaps transactions.
161
- * @param options.getCurrentAccountEIP1559Compatibility - Whether or not the account supports EIP-1559.
162
- * @param options.getCurrentNetworkEIP1559Compatibility - Whether or not the network supports EIP-1559.
163
- * @param options.getExternalPendingTransactions - Callback to retrieve pending transactions from external sources.
164
- * @param options.getGasFeeEstimates - Callback to retrieve gas fee estimates.
165
- * @param options.getNetworkClientRegistry - Gets the network client registry.
166
- * @param options.getNetworkState - Gets the state of the network controller.
167
- * @param options.getPermittedAccounts - Get accounts that a given origin has permissions for.
168
- * @param options.getSavedGasFees - Gets the saved gas fee config.
169
- * @param options.incomingTransactions - Configuration options for incoming transaction support.
170
- * @param options.isFirstTimeInteractionEnabled - Whether first time interaction checks are enabled.
171
- * @param options.isSimulationEnabled - Whether new transactions will be automatically simulated.
172
- * @param options.messenger - The controller messenger.
173
- * @param options.pendingTransactions - Configuration options for pending transaction support.
174
- * @param options.securityProviderRequest - A function for verifying a transaction, whether it is malicious or not.
175
- * @param options.sign - Function used to sign transactions.
176
- * @param options.state - Initial state to set on this controller.
177
- * @param options.testGasFeeFlows - Whether to use the test gas fee flow.
178
- * @param options.trace - Callback to generate trace information.
179
- * @param options.transactionHistoryLimit - Transaction history limit.
180
- * @param options.hooks - The controller hooks.
181
159
  */
182
- constructor({ disableHistory, disableSendFlowHistory, disableSwaps, getCurrentAccountEIP1559Compatibility, getCurrentNetworkEIP1559Compatibility, getExternalPendingTransactions, getGasFeeEstimates, getNetworkClientRegistry, getNetworkState, getPermittedAccounts, getSavedGasFees, incomingTransactions = {}, isFirstTimeInteractionEnabled, isSimulationEnabled, messenger, pendingTransactions = {}, securityProviderRequest, sign, state, testGasFeeFlows, trace, transactionHistoryLimit = 40, hooks, }) {
160
+ constructor(options) {
161
+ const { disableHistory, disableSendFlowHistory, disableSwaps, getCurrentAccountEIP1559Compatibility, getCurrentNetworkEIP1559Compatibility, getExternalPendingTransactions, getGasFeeEstimates, getNetworkClientRegistry, getNetworkState, getPermittedAccounts, getSavedGasFees, incomingTransactions = {}, isFirstTimeInteractionEnabled, isSimulationEnabled, messenger, pendingTransactions = {}, securityProviderRequest, sign, state, testGasFeeFlows, trace, transactionHistoryLimit = 40, hooks, } = options;
183
162
  super({
184
163
  name: controllerName,
185
164
  metadata,
@@ -330,6 +309,35 @@ export class TransactionController extends BaseController {
330
309
  async handleMethodData(fourBytePrefix, networkClientId) {
331
310
  return __classPrivateFieldGet(this, _TransactionController_methodDataHelper, "f").lookup(fourBytePrefix, networkClientId);
332
311
  }
312
+ /**
313
+ * Add a batch of transactions to be submitted after approval.
314
+ *
315
+ * @param request - Request object containing the transactions to add.
316
+ * @returns Result object containing the generated batch ID.
317
+ */
318
+ async addTransactionBatch(request) {
319
+ return await addTransactionBatch({
320
+ addTransaction: this.addTransaction.bind(this),
321
+ getChainId: __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getChainId).bind(this),
322
+ getEthQuery: (networkClientId) => __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getEthQuery).call(this, { networkClientId }),
323
+ getInternalAccounts: __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getInternalAccounts).bind(this),
324
+ messenger: this.messagingSystem,
325
+ request,
326
+ });
327
+ }
328
+ /**
329
+ * Determine which chains support atomic batch transactions with the given account address.
330
+ *
331
+ * @param address - The address of the account to check.
332
+ * @returns The supported chain IDs.
333
+ */
334
+ async isAtomicBatchSupported(address) {
335
+ return isAtomicBatchSupported({
336
+ address,
337
+ getEthQuery: (chainId) => __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getEthQuery).call(this, { chainId }),
338
+ messenger: this.messagingSystem,
339
+ });
340
+ }
333
341
  /**
334
342
  * Add a new unapproved transaction to state. Parameters will be validated, a
335
343
  * unique transaction id will be generated, and gas and gasPrice will be calculated
@@ -340,6 +348,7 @@ export class TransactionController extends BaseController {
340
348
  * @param options.actionId - Unique ID to prevent duplicate requests.
341
349
  * @param options.deviceConfirmedOn - An enum to indicate what device confirmed the transaction.
342
350
  * @param options.method - RPC method that requested the transaction.
351
+ * @param options.nestedTransactions - Params for any nested transactions encoded in the data.
343
352
  * @param options.origin - The origin of the transaction request, such as a dApp hostname.
344
353
  * @param options.requireApproval - Whether the transaction requires approval by the user, defaults to true unless explicitly disabled.
345
354
  * @param options.securityAlertResponse - Response from security validator.
@@ -354,7 +363,7 @@ export class TransactionController extends BaseController {
354
363
  */
355
364
  async addTransaction(txParams, options) {
356
365
  log('Adding transaction', txParams, options);
357
- const { actionId, deviceConfirmedOn, method, networkClientId, origin, requireApproval, securityAlertResponse, sendFlowHistory, swaps = {}, traceContext, type, } = options;
366
+ const { actionId, deviceConfirmedOn, method, nestedTransactions, networkClientId, origin, requireApproval, securityAlertResponse, sendFlowHistory, swaps = {}, traceContext, type, } = options;
358
367
  txParams = normalizeTransactionParams(txParams);
359
368
  if (!__classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").has(networkClientId)) {
360
369
  throw new Error(`Network client not found - ${networkClientId}`);
@@ -363,12 +372,15 @@ export class TransactionController extends BaseController {
363
372
  ? undefined
364
373
  : await this.getPermittedAccounts?.(origin);
365
374
  const selectedAddress = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getSelectedAccount).call(this).address;
375
+ const internalAccounts = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getInternalAccounts).call(this);
366
376
  await validateTransactionOrigin({
367
377
  from: txParams.from,
378
+ internalAccounts,
368
379
  origin,
369
380
  permittedAddresses,
370
381
  selectedAddress,
371
382
  txParams,
383
+ type,
372
384
  });
373
385
  const isEIP1559Compatible = await this.getEIP1559Compatibility(networkClientId);
374
386
  validateTxParams(txParams, isEIP1559Compatible);
@@ -390,6 +402,7 @@ export class TransactionController extends BaseController {
390
402
  deviceConfirmedOn,
391
403
  id: random(),
392
404
  isFirstTimeInteraction: undefined,
405
+ nestedTransactions,
393
406
  networkClientId,
394
407
  origin,
395
408
  securityAlertResponse,
@@ -480,7 +493,7 @@ export class TransactionController extends BaseController {
480
493
  * @param options.estimatedBaseFee - The estimated base fee of the transaction.
481
494
  */
482
495
  async stopTransaction(transactionId, gasValues, { estimatedBaseFee, actionId, } = {}) {
483
- return await __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_retryTransaction).call(this, {
496
+ await __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_retryTransaction).call(this, {
484
497
  actionId,
485
498
  estimatedBaseFee,
486
499
  gasValues,
@@ -509,7 +522,7 @@ export class TransactionController extends BaseController {
509
522
  * @param options.estimatedBaseFee - The estimated base fee of the transaction.
510
523
  */
511
524
  async speedUpTransaction(transactionId, gasValues, { actionId, estimatedBaseFee, } = {}) {
512
- return await __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_retryTransaction).call(this, {
525
+ await __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_retryTransaction).call(this, {
513
526
  actionId,
514
527
  estimatedBaseFee,
515
528
  gasValues,
@@ -542,6 +555,7 @@ export class TransactionController extends BaseController {
542
555
  * @param transaction - The transaction params to estimate gas for.
543
556
  * @param multiplier - The multiplier to use for the gas buffer.
544
557
  * @param networkClientId - The network client id to use for the estimate.
558
+ * @returns The buffered estimated gas and whether the estimation failed.
545
559
  */
546
560
  async estimateGasBuffered(transaction, multiplier, networkClientId) {
547
561
  const ethQuery = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getEthQuery).call(this, {
@@ -1028,6 +1042,7 @@ export class TransactionController extends BaseController {
1028
1042
  * @param request.transactionParams - The transaction parameters to estimate the layer 1 gas fee for.
1029
1043
  * @param request.chainId - The ID of the chain where the transaction will be executed.
1030
1044
  * @param request.networkClientId - The ID of a specific network client to process the transaction.
1045
+ * @returns The layer 1 gas fee.
1031
1046
  */
1032
1047
  async getLayer1GasFee({ transactionParams, chainId, networkClientId, }) {
1033
1048
  const provider = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getProvider).call(this, {
@@ -1090,6 +1105,54 @@ export class TransactionController extends BaseController {
1090
1105
  abortCallback();
1091
1106
  this.signAbortCallbacks.delete(transactionId);
1092
1107
  }
1108
+ /**
1109
+ * Update the transaction data of a single nested transaction within an atomic batch transaction.
1110
+ *
1111
+ * @param options - The options bag.
1112
+ * @param options.transactionId - ID of the atomic batch transaction.
1113
+ * @param options.transactionIndex - Index of the nested transaction within the atomic batch transaction.
1114
+ * @param options.transactionData - New data to set for the nested transaction.
1115
+ * @returns The updated data for the atomic batch transaction.
1116
+ */
1117
+ async updateAtomicBatchData({ transactionId, transactionIndex, transactionData, }) {
1118
+ log('Updating atomic batch data', {
1119
+ transactionId,
1120
+ transactionIndex,
1121
+ transactionData,
1122
+ });
1123
+ const updatedTransactionMeta = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_updateTransactionInternal).call(this, {
1124
+ transactionId,
1125
+ note: 'TransactionController#updateAtomicBatchData - Atomic batch data updated',
1126
+ }, (transactionMeta) => {
1127
+ const { nestedTransactions, txParams } = transactionMeta;
1128
+ const from = txParams.from;
1129
+ const nestedTransaction = nestedTransactions?.[transactionIndex];
1130
+ if (!nestedTransaction) {
1131
+ throw new Error(`Nested transaction not found with index - ${transactionIndex}`);
1132
+ }
1133
+ nestedTransaction.data = transactionData;
1134
+ const batchTransaction = generateEIP7702BatchTransaction(from, nestedTransactions);
1135
+ transactionMeta.txParams.data = batchTransaction.data;
1136
+ });
1137
+ const draftTransaction = cloneDeep({
1138
+ ...updatedTransactionMeta,
1139
+ txParams: {
1140
+ ...updatedTransactionMeta.txParams,
1141
+ // Clear existing gas to force estimation
1142
+ gas: undefined,
1143
+ },
1144
+ });
1145
+ await __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_updateGasEstimate).call(this, draftTransaction);
1146
+ __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_updateTransactionInternal).call(this, {
1147
+ transactionId,
1148
+ note: 'TransactionController#updateAtomicBatchData - Gas estimate updated',
1149
+ }, (transactionMeta) => {
1150
+ transactionMeta.txParams.gas = draftTransaction.txParams.gas;
1151
+ transactionMeta.simulationFails = draftTransaction.simulationFails;
1152
+ transactionMeta.gasLimitNoBuffer = draftTransaction.gasLimitNoBuffer;
1153
+ });
1154
+ return updatedTransactionMeta.txParams.data;
1155
+ }
1093
1156
  addMetadata(transactionMeta) {
1094
1157
  validateTxParams(transactionMeta.txParams);
1095
1158
  this.update((state) => {
@@ -1102,18 +1165,11 @@ export class TransactionController extends BaseController {
1102
1165
  async updateGasProperties(transactionMeta, { traceContext } = {}) {
1103
1166
  const isEIP1559Compatible = transactionMeta.txParams.type !== TransactionEnvelopeType.legacy &&
1104
1167
  (await this.getEIP1559Compatibility(transactionMeta.networkClientId));
1105
- const { networkClientId, chainId } = transactionMeta;
1106
- const isCustomNetwork = __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getNetworkClient({ networkClientId })
1107
- .configuration.type === NetworkClientType.Custom;
1168
+ const { networkClientId } = transactionMeta;
1108
1169
  const ethQuery = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getEthQuery).call(this, { networkClientId });
1109
1170
  const provider = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getProvider).call(this, { networkClientId });
1110
1171
  await __classPrivateFieldGet(this, _TransactionController_trace, "f").call(this, { name: 'Update Gas', parentContext: traceContext }, async () => {
1111
- await updateGas({
1112
- ethQuery,
1113
- chainId,
1114
- isCustomNetwork,
1115
- txMeta: transactionMeta,
1116
- });
1172
+ await __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_updateGasEstimate).call(this, transactionMeta);
1117
1173
  });
1118
1174
  await __classPrivateFieldGet(this, _TransactionController_trace, "f").call(this, { name: 'Update Gas Fees', parentContext: traceContext }, async () => await updateGasFees({
1119
1175
  eip1559: isEIP1559Compatible,
@@ -1185,7 +1241,10 @@ export class TransactionController extends BaseController {
1185
1241
  if (!isTxCompleted) {
1186
1242
  if (error?.code === errorCodes.provider.userRejectedRequest) {
1187
1243
  this.cancelTransaction(transactionId, actionId);
1188
- throw providerErrors.userRejectedRequest('MetaMask Tx Signature: User denied transaction signature.');
1244
+ throw providerErrors.userRejectedRequest({
1245
+ message: 'MetaMask Tx Signature: User denied transaction signature.',
1246
+ data: error?.data,
1247
+ });
1189
1248
  }
1190
1249
  else {
1191
1250
  this.failTransaction(meta, error, actionId);
@@ -1215,6 +1274,7 @@ export class TransactionController extends BaseController {
1215
1274
  *
1216
1275
  * @param transactionId - The ID of the transaction to approve.
1217
1276
  * @param traceContext - The parent context for any new traces.
1277
+ * @returns The state of the approval.
1218
1278
  */
1219
1279
  async approveTransaction(transactionId, traceContext) {
1220
1280
  const cleanupTasks = new Array();
@@ -1253,7 +1313,7 @@ export class TransactionController extends BaseController {
1253
1313
  }
1254
1314
  });
1255
1315
  this.onTransactionStatusChange(transactionMeta);
1256
- const rawTx = await __classPrivateFieldGet(this, _TransactionController_trace, "f").call(this, { name: 'Sign', parentContext: traceContext }, () => this.signTransaction(transactionMeta, transactionMeta.txParams));
1316
+ const rawTx = await __classPrivateFieldGet(this, _TransactionController_trace, "f").call(this, { name: 'Sign', parentContext: traceContext }, () => this.signTransaction(transactionMeta));
1257
1317
  if (!this.beforePublish(transactionMeta)) {
1258
1318
  log('Skipping publishing transaction based on hook');
1259
1319
  this.messagingSystem.publish(`${controllerName}:transactionPublishingSkipped`, transactionMeta);
@@ -1620,7 +1680,8 @@ export class TransactionController extends BaseController {
1620
1680
  const currentAccountIsEIP1559Compatible = await this.getCurrentAccountEIP1559Compatibility();
1621
1681
  return (currentNetworkIsEIP1559Compatible && currentAccountIsEIP1559Compatible);
1622
1682
  }
1623
- async signTransaction(transactionMeta, txParams) {
1683
+ async signTransaction(transactionMeta) {
1684
+ const { txParams } = transactionMeta;
1624
1685
  log('Signing transaction', txParams);
1625
1686
  const { authorizationList, from } = txParams;
1626
1687
  const finalTxParams = { ...txParams };
@@ -1649,6 +1710,7 @@ export class TransactionController extends BaseController {
1649
1710
  const transactionMetaWithRsv = {
1650
1711
  ...this.updateTransactionMetaRSV(transactionMetaFromHook, signedTx),
1651
1712
  status: TransactionStatus.signed,
1713
+ txParams: finalTxParams,
1652
1714
  };
1653
1715
  this.updateTransaction(transactionMetaWithRsv, 'TransactionController#approveTransaction - Transaction signed');
1654
1716
  this.onTransactionStatusChange(transactionMetaWithRsv);
@@ -1868,6 +1930,9 @@ _TransactionController_internalEvents = new WeakMap(), _TransactionController_me
1868
1930
  let resimulateResponse;
1869
1931
  this.update((state) => {
1870
1932
  const index = state.transactions.findIndex(({ id }) => id === transactionId);
1933
+ if (index === -1) {
1934
+ throw new Error(`Cannot update transaction as ID not found - ${transactionId}`);
1935
+ }
1871
1936
  let transactionMeta = state.transactions[index];
1872
1937
  const originalTransactionMeta = cloneDeep(transactionMeta);
1873
1938
  transactionMeta = callback(transactionMeta) ?? transactionMeta;
@@ -1993,6 +2058,11 @@ _TransactionController_internalEvents = new WeakMap(), _TransactionController_me
1993
2058
  });
1994
2059
  }, _TransactionController_getSelectedAccount = function _TransactionController_getSelectedAccount() {
1995
2060
  return this.messagingSystem.call('AccountsController:getSelectedAccount');
2061
+ }, _TransactionController_getInternalAccounts = function _TransactionController_getInternalAccounts() {
2062
+ const state = this.messagingSystem.call('AccountsController:getState');
2063
+ return Object.values(state.internalAccounts?.accounts ?? {})
2064
+ .filter((account) => account.type === 'eip155:eoa')
2065
+ .map((account) => account.address);
1996
2066
  }, _TransactionController_updateSubmitHistory = function _TransactionController_updateSubmitHistory(transactionMeta, hash) {
1997
2067
  const { chainId, networkClientId, origin, rawTx, txParams } = transactionMeta;
1998
2068
  const { networkConfigurationsByChainId } = this.getNetworkState();
@@ -2018,5 +2088,16 @@ _TransactionController_internalEvents = new WeakMap(), _TransactionController_me
2018
2088
  }
2019
2089
  submitHistory.unshift(submitHistoryEntry);
2020
2090
  });
2091
+ }, _TransactionController_updateGasEstimate = async function _TransactionController_updateGasEstimate(transactionMeta) {
2092
+ const { chainId, networkClientId } = transactionMeta;
2093
+ const isCustomNetwork = __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getNetworkClient({ networkClientId })
2094
+ .configuration.type === NetworkClientType.Custom;
2095
+ const ethQuery = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getEthQuery).call(this, { networkClientId });
2096
+ await updateGas({
2097
+ chainId,
2098
+ ethQuery,
2099
+ isCustomNetwork,
2100
+ txMeta: transactionMeta,
2101
+ });
2021
2102
  };
2022
2103
  //# sourceMappingURL=TransactionController.mjs.map