@metamask/transaction-controller 35.1.0 → 35.2.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 (108) hide show
  1. package/CHANGELOG.md +33 -1
  2. package/dist/TransactionController.js +12 -11
  3. package/dist/TransactionController.mjs +11 -10
  4. package/dist/{chunk-RXIUMVA5.js → chunk-4OYPDGHO.js} +18 -3
  5. package/dist/chunk-4OYPDGHO.js.map +1 -0
  6. package/dist/{chunk-2EU6346V.js → chunk-5HYWLTVQ.js} +3 -3
  7. package/dist/chunk-5QVDIVJH.js +68 -0
  8. package/dist/chunk-5QVDIVJH.js.map +1 -0
  9. package/dist/{chunk-H2KZOK3J.mjs → chunk-AWIJZAW3.mjs} +3 -3
  10. package/dist/{chunk-C3WC4OJ3.js → chunk-BZV72SCF.js} +5 -5
  11. package/dist/{chunk-QTKXIDGE.js → chunk-EHWAY6XU.js} +9 -9
  12. package/dist/{chunk-GNAL5HC2.mjs → chunk-JIFPK37W.mjs} +2 -2
  13. package/dist/chunk-JOQK7A5G.mjs +68 -0
  14. package/dist/chunk-JOQK7A5G.mjs.map +1 -0
  15. package/dist/{chunk-OZ6UB42C.js → chunk-KTGMNUTQ.js} +2 -23
  16. package/dist/chunk-KTGMNUTQ.js.map +1 -0
  17. package/dist/{chunk-UHG2LLVV.mjs → chunk-KYRW4BLA.mjs} +3 -3
  18. package/dist/{chunk-6SJYXSF3.mjs → chunk-LFFYCDHB.mjs} +1 -1
  19. package/dist/{chunk-6SJYXSF3.mjs.map → chunk-LFFYCDHB.mjs.map} +1 -1
  20. package/dist/{chunk-JXXTNVU4.mjs → chunk-NNHSNPT2.mjs} +2 -2
  21. package/dist/{chunk-AYTU4HU5.js → chunk-PSZ34BI5.js} +1 -1
  22. package/dist/{chunk-AYTU4HU5.js.map → chunk-PSZ34BI5.js.map} +1 -1
  23. package/dist/{chunk-QH2H4W3N.js → chunk-QKV7E5BO.js} +5 -5
  24. package/dist/{chunk-VXNPVIYL.mjs → chunk-SFFOC25Q.mjs} +3 -3
  25. package/dist/{chunk-ARZHJFVG.js → chunk-UHAFIPSL.js} +6 -6
  26. package/dist/{chunk-Q56I5ONX.mjs → chunk-UHSRHP55.mjs} +1 -22
  27. package/dist/chunk-UHSRHP55.mjs.map +1 -0
  28. package/dist/{chunk-SFFTNB2X.mjs → chunk-VGFPVAKX.mjs} +2 -2
  29. package/dist/{chunk-QKS2F7VG.js → chunk-VKWOHNDO.js} +231 -288
  30. package/dist/chunk-VKWOHNDO.js.map +1 -0
  31. package/dist/{chunk-5ZEJT5SN.mjs → chunk-X4XSEYPL.mjs} +17 -2
  32. package/dist/chunk-X4XSEYPL.mjs.map +1 -0
  33. package/dist/{chunk-5JWPMHSZ.mjs → chunk-XTMJ25EF.mjs} +213 -270
  34. package/dist/chunk-XTMJ25EF.mjs.map +1 -0
  35. package/dist/{chunk-76FONEDA.js → chunk-YWLMT7XH.js} +4 -4
  36. package/dist/errors.js +1 -1
  37. package/dist/errors.mjs +1 -1
  38. package/dist/gas-flows/DefaultGasFeeFlow.js +7 -7
  39. package/dist/gas-flows/DefaultGasFeeFlow.mjs +6 -6
  40. package/dist/gas-flows/LineaGasFeeFlow.js +8 -8
  41. package/dist/gas-flows/LineaGasFeeFlow.mjs +7 -7
  42. package/dist/gas-flows/TestGasFeeFlow.js +1 -1
  43. package/dist/gas-flows/TestGasFeeFlow.mjs +1 -1
  44. package/dist/helpers/EtherscanRemoteTransactionSource.js +1 -1
  45. package/dist/helpers/EtherscanRemoteTransactionSource.mjs +1 -1
  46. package/dist/helpers/GasFeePoller.js +4 -4
  47. package/dist/helpers/GasFeePoller.mjs +3 -3
  48. package/dist/helpers/MultichainTrackingHelper.js +1 -1
  49. package/dist/helpers/MultichainTrackingHelper.mjs +1 -1
  50. package/dist/helpers/PendingTransactionTracker.js +1 -1
  51. package/dist/helpers/PendingTransactionTracker.mjs +1 -1
  52. package/dist/index.js +12 -11
  53. package/dist/index.mjs +11 -10
  54. package/dist/tsconfig.build.tsbuildinfo +1 -1
  55. package/dist/types/TransactionController.d.ts +8 -10
  56. package/dist/types/TransactionController.d.ts.map +1 -1
  57. package/dist/types/index.d.ts +2 -2
  58. package/dist/types/index.d.ts.map +1 -1
  59. package/dist/types/types.d.ts +40 -0
  60. package/dist/types/types.d.ts.map +1 -1
  61. package/dist/types/utils/retry.d.ts +11 -0
  62. package/dist/types/utils/retry.d.ts.map +1 -0
  63. package/dist/types/utils/utils.d.ts +1 -15
  64. package/dist/types/utils/utils.d.ts.map +1 -1
  65. package/dist/types/utils/validation.d.ts.map +1 -1
  66. package/dist/types.js +2 -2
  67. package/dist/types.mjs +1 -1
  68. package/dist/utils/external-transactions.js +1 -1
  69. package/dist/utils/external-transactions.mjs +1 -1
  70. package/dist/utils/gas-fees.js +6 -6
  71. package/dist/utils/gas-fees.mjs +5 -5
  72. package/dist/utils/gas-flow.js +3 -3
  73. package/dist/utils/gas-flow.mjs +2 -2
  74. package/dist/utils/retry.js +8 -0
  75. package/dist/utils/retry.js.map +1 -0
  76. package/dist/utils/retry.mjs +8 -0
  77. package/dist/utils/retry.mjs.map +1 -0
  78. package/dist/utils/simulation-api.js +1 -1
  79. package/dist/utils/simulation-api.mjs +1 -1
  80. package/dist/utils/simulation.js +1 -1
  81. package/dist/utils/simulation.mjs +1 -1
  82. package/dist/utils/swaps.js +4 -4
  83. package/dist/utils/swaps.mjs +3 -3
  84. package/dist/utils/transaction-type.js +1 -1
  85. package/dist/utils/transaction-type.mjs +1 -1
  86. package/dist/utils/utils.js +3 -13
  87. package/dist/utils/utils.mjs +4 -14
  88. package/dist/utils/validation.js +4 -4
  89. package/dist/utils/validation.mjs +3 -3
  90. package/package.json +9 -8
  91. package/dist/chunk-5JWPMHSZ.mjs.map +0 -1
  92. package/dist/chunk-5ZEJT5SN.mjs.map +0 -1
  93. package/dist/chunk-OZ6UB42C.js.map +0 -1
  94. package/dist/chunk-Q56I5ONX.mjs.map +0 -1
  95. package/dist/chunk-QKS2F7VG.js.map +0 -1
  96. package/dist/chunk-RXIUMVA5.js.map +0 -1
  97. /package/dist/{chunk-2EU6346V.js.map → chunk-5HYWLTVQ.js.map} +0 -0
  98. /package/dist/{chunk-H2KZOK3J.mjs.map → chunk-AWIJZAW3.mjs.map} +0 -0
  99. /package/dist/{chunk-C3WC4OJ3.js.map → chunk-BZV72SCF.js.map} +0 -0
  100. /package/dist/{chunk-QTKXIDGE.js.map → chunk-EHWAY6XU.js.map} +0 -0
  101. /package/dist/{chunk-GNAL5HC2.mjs.map → chunk-JIFPK37W.mjs.map} +0 -0
  102. /package/dist/{chunk-UHG2LLVV.mjs.map → chunk-KYRW4BLA.mjs.map} +0 -0
  103. /package/dist/{chunk-JXXTNVU4.mjs.map → chunk-NNHSNPT2.mjs.map} +0 -0
  104. /package/dist/{chunk-QH2H4W3N.js.map → chunk-QKV7E5BO.js.map} +0 -0
  105. /package/dist/{chunk-VXNPVIYL.mjs.map → chunk-SFFOC25Q.mjs.map} +0 -0
  106. /package/dist/{chunk-ARZHJFVG.js.map → chunk-UHAFIPSL.js.map} +0 -0
  107. /package/dist/{chunk-SFFTNB2X.mjs.map → chunk-VGFPVAKX.mjs.map} +0 -0
  108. /package/dist/{chunk-76FONEDA.js.map → chunk-YWLMT7XH.js.map} +0 -0
@@ -2,6 +2,9 @@ import {
2
2
  getAndFormatTransactionsForNonceTracker,
3
3
  getNextNonce
4
4
  } from "./chunk-6DDVVUJC.mjs";
5
+ import {
6
+ getTransactionParamsWithIncreasedGasFee
7
+ } from "./chunk-JOQK7A5G.mjs";
5
8
  import {
6
9
  getSimulationData
7
10
  } from "./chunk-3AVRGHUO.mjs";
@@ -11,7 +14,7 @@ import {
11
14
  import {
12
15
  validateTransactionOrigin,
13
16
  validateTxParams
14
- } from "./chunk-5ZEJT5SN.mjs";
17
+ } from "./chunk-X4XSEYPL.mjs";
15
18
  import {
16
19
  PendingTransactionTracker
17
20
  } from "./chunk-6B5BEO3R.mjs";
@@ -38,7 +41,7 @@ import {
38
41
  } from "./chunk-FMRLPVFZ.mjs";
39
42
  import {
40
43
  GasFeePoller
41
- } from "./chunk-SFFTNB2X.mjs";
44
+ } from "./chunk-VGFPVAKX.mjs";
42
45
  import {
43
46
  getTransactionLayer1GasFee,
44
47
  updateTransactionLayer1GasFee
@@ -54,32 +57,28 @@ import {
54
57
  } from "./chunk-EKJXGERC.mjs";
55
58
  import {
56
59
  LineaGasFeeFlow
57
- } from "./chunk-UHG2LLVV.mjs";
60
+ } from "./chunk-KYRW4BLA.mjs";
58
61
  import {
59
62
  DefaultGasFeeFlow
60
- } from "./chunk-H2KZOK3J.mjs";
63
+ } from "./chunk-AWIJZAW3.mjs";
61
64
  import {
62
65
  updateGasFees
63
- } from "./chunk-VXNPVIYL.mjs";
66
+ } from "./chunk-SFFOC25Q.mjs";
64
67
  import {
65
68
  updatePostTransactionBalance,
66
69
  updateSwapsTransaction
67
- } from "./chunk-GNAL5HC2.mjs";
70
+ } from "./chunk-JIFPK37W.mjs";
68
71
  import {
69
- getIncreasedPriceFromExisting,
70
72
  isEIP1559Transaction,
71
- isFeeMarketEIP1559Values,
72
- isGasPriceValue,
73
73
  normalizeGasFeeValues,
74
74
  normalizeTransactionParams,
75
75
  normalizeTxError,
76
76
  validateGasValues,
77
- validateIfTransactionUnapproved,
78
- validateMinimumIncrease
79
- } from "./chunk-Q56I5ONX.mjs";
77
+ validateIfTransactionUnapproved
78
+ } from "./chunk-UHSRHP55.mjs";
80
79
  import {
81
80
  getGasFeeFlow
82
- } from "./chunk-JXXTNVU4.mjs";
81
+ } from "./chunk-NNHSNPT2.mjs";
83
82
  import {
84
83
  projectLogger
85
84
  } from "./chunk-UQQWZT6C.mjs";
@@ -143,7 +142,7 @@ function getDefaultTransactionControllerState() {
143
142
  lastFetchedBlockNumbers: {}
144
143
  };
145
144
  }
146
- var _internalEvents, _incomingTransactionOptions, _pendingTransactionOptions, _transactionHistoryLimit, _isSimulationEnabled, _testGasFeeFlows, _multichainTrackingHelper, _createNonceTracker, createNonceTracker_fn, _createIncomingTransactionHelper, createIncomingTransactionHelper_fn, _createPendingTransactionTracker, createPendingTransactionTracker_fn, _checkForPendingTransactionAndStartPolling, _stopAllTracking, stopAllTracking_fn, _removeIncomingTransactionHelperListeners, removeIncomingTransactionHelperListeners_fn, _addIncomingTransactionHelperListeners, addIncomingTransactionHelperListeners_fn, _removePendingTransactionTrackerListeners, removePendingTransactionTrackerListeners_fn, _addPendingTransactionTrackerListeners, addPendingTransactionTrackerListeners_fn, _getNonceTrackerPendingTransactions, getNonceTrackerPendingTransactions_fn, _getGasFeeFlows, getGasFeeFlows_fn, _getLayer1GasFeeFlows, getLayer1GasFeeFlows_fn, _updateTransactionInternal, updateTransactionInternal_fn, _checkIfTransactionParamsUpdated, checkIfTransactionParamsUpdated_fn, _onTransactionParamsUpdated, onTransactionParamsUpdated_fn, _updateSimulationData, updateSimulationData_fn, _onGasFeePollerTransactionUpdate, onGasFeePollerTransactionUpdate_fn, _getNetworkClientId, getNetworkClientId_fn, _getGlobalNetworkClientId, getGlobalNetworkClientId_fn, _getGlobalChainId, getGlobalChainId_fn, _isCustomNetwork, isCustomNetwork_fn, _getSelectedAccount, getSelectedAccount_fn;
145
+ var _internalEvents, _incomingTransactionOptions, _pendingTransactionOptions, _trace, _transactionHistoryLimit, _isSimulationEnabled, _testGasFeeFlows, _multichainTrackingHelper, _retryTransaction, retryTransaction_fn, _createNonceTracker, createNonceTracker_fn, _createIncomingTransactionHelper, createIncomingTransactionHelper_fn, _createPendingTransactionTracker, createPendingTransactionTracker_fn, _checkForPendingTransactionAndStartPolling, _stopAllTracking, stopAllTracking_fn, _removeIncomingTransactionHelperListeners, removeIncomingTransactionHelperListeners_fn, _addIncomingTransactionHelperListeners, addIncomingTransactionHelperListeners_fn, _removePendingTransactionTrackerListeners, removePendingTransactionTrackerListeners_fn, _addPendingTransactionTrackerListeners, addPendingTransactionTrackerListeners_fn, _getNonceTrackerPendingTransactions, getNonceTrackerPendingTransactions_fn, _getGasFeeFlows, getGasFeeFlows_fn, _getLayer1GasFeeFlows, getLayer1GasFeeFlows_fn, _updateTransactionInternal, updateTransactionInternal_fn, _checkIfTransactionParamsUpdated, checkIfTransactionParamsUpdated_fn, _onTransactionParamsUpdated, onTransactionParamsUpdated_fn, _updateSimulationData, updateSimulationData_fn, _onGasFeePollerTransactionUpdate, onGasFeePollerTransactionUpdate_fn, _getNetworkClientId, getNetworkClientId_fn, _getGlobalNetworkClientId, getGlobalNetworkClientId_fn, _getGlobalChainId, getGlobalChainId_fn, _isCustomNetwork, isCustomNetwork_fn, _getSelectedAccount, getSelectedAccount_fn;
147
146
  var TransactionController = class extends BaseController {
148
147
  /**
149
148
  * Constructs a TransactionController.
@@ -172,6 +171,7 @@ var TransactionController = class extends BaseController {
172
171
  * @param options.sign - Function used to sign transactions.
173
172
  * @param options.state - Initial state to set on this controller.
174
173
  * @param options.testGasFeeFlows - Whether to use the test gas fee flow.
174
+ * @param options.trace - Callback to generate trace information.
175
175
  * @param options.transactionHistoryLimit - Transaction history limit.
176
176
  * @param options.hooks - The controller hooks.
177
177
  */
@@ -199,6 +199,7 @@ var TransactionController = class extends BaseController {
199
199
  sign,
200
200
  state,
201
201
  testGasFeeFlows,
202
+ trace,
202
203
  transactionHistoryLimit = 40,
203
204
  hooks
204
205
  }) {
@@ -211,6 +212,7 @@ var TransactionController = class extends BaseController {
211
212
  ...state
212
213
  }
213
214
  });
215
+ __privateAdd(this, _retryTransaction);
214
216
  __privateAdd(this, _createNonceTracker);
215
217
  __privateAdd(this, _createIncomingTransactionHelper);
216
218
  __privateAdd(this, _createPendingTransactionTracker);
@@ -238,6 +240,7 @@ var TransactionController = class extends BaseController {
238
240
  __privateAdd(this, _incomingTransactionOptions, void 0);
239
241
  __privateAdd(this, _pendingTransactionOptions, void 0);
240
242
  this.signAbortCallbacks = /* @__PURE__ */ new Map();
243
+ __privateAdd(this, _trace, void 0);
241
244
  __privateAdd(this, _transactionHistoryLimit, void 0);
242
245
  __privateAdd(this, _isSimulationEnabled, void 0);
243
246
  __privateAdd(this, _testGasFeeFlows, void 0);
@@ -265,6 +268,7 @@ var TransactionController = class extends BaseController {
265
268
  __privateSet(this, _transactionHistoryLimit, transactionHistoryLimit);
266
269
  this.sign = sign;
267
270
  __privateSet(this, _testGasFeeFlows, testGasFeeFlows === true);
271
+ __privateSet(this, _trace, trace ?? ((_request, fn) => fn?.()));
268
272
  this.afterSign = hooks?.afterSign ?? (() => true);
269
273
  this.beforeApproveOnInit = hooks?.beforeApproveOnInit ?? (() => true);
270
274
  this.beforeCheckPendingTransaction = hooks?.beforeCheckPendingTransaction ?? /* istanbul ignore next */
@@ -439,6 +443,7 @@ var TransactionController = class extends BaseController {
439
443
  * @param opts.swaps.hasApproveTx - Whether the transaction has an approval transaction.
440
444
  * @param opts.swaps.meta - Metadata for swap transaction.
441
445
  * @param opts.networkClientId - The id of the network client for this transaction.
446
+ * @param opts.traceContext - The parent context for any new traces.
442
447
  * @returns Object containing a promise resolving to the transaction hash if approved.
443
448
  */
444
449
  async addTransaction(txParams, {
@@ -450,6 +455,7 @@ var TransactionController = class extends BaseController {
450
455
  securityAlertResponse,
451
456
  sendFlowHistory,
452
457
  swaps = {},
458
+ traceContext,
453
459
  type,
454
460
  networkClientId: requestNetworkClientId
455
461
  } = {}) {
@@ -501,7 +507,9 @@ var TransactionController = class extends BaseController {
501
507
  type: transactionType,
502
508
  networkClientId
503
509
  };
504
- await this.updateGasProperties(addedTransactionMeta);
510
+ await __privateGet(this, _trace).call(this, { name: "Estimate Gas Properties", parentContext: traceContext }, (context) => this.updateGasProperties(addedTransactionMeta, {
511
+ traceContext: context
512
+ }));
505
513
  if (!existingTransactionMeta) {
506
514
  if (method && this.securityProviderRequest) {
507
515
  const securityProviderResponse = await this.securityProviderRequest(
@@ -528,7 +536,12 @@ var TransactionController = class extends BaseController {
528
536
  );
529
537
  this.addMetadata(addedTransactionMeta);
530
538
  if (requireApproval !== false) {
531
- __privateMethod(this, _updateSimulationData, updateSimulationData_fn).call(this, addedTransactionMeta);
539
+ __privateMethod(this, _updateSimulationData, updateSimulationData_fn).call(this, addedTransactionMeta, {
540
+ traceContext
541
+ }).catch((error) => {
542
+ projectLogger("Error while updating simulation data", error);
543
+ throw error;
544
+ });
532
545
  } else {
533
546
  projectLogger("Skipping simulation as approval not required");
534
547
  }
@@ -541,7 +554,8 @@ var TransactionController = class extends BaseController {
541
554
  result: this.processApproval(addedTransactionMeta, {
542
555
  isExisting: Boolean(existingTransactionMeta),
543
556
  requireApproval,
544
- actionId
557
+ actionId,
558
+ traceContext
545
559
  }),
546
560
  transactionMeta: addedTransactionMeta
547
561
  };
@@ -591,116 +605,30 @@ var TransactionController = class extends BaseController {
591
605
  estimatedBaseFee,
592
606
  actionId
593
607
  } = {}) {
594
- if (this.getTransactionWithActionId(actionId)) {
595
- return;
596
- }
597
- if (gasValues) {
598
- gasValues = normalizeGasFeeValues(gasValues);
599
- validateGasValues(gasValues);
600
- }
601
- projectLogger("Creating cancel transaction", transactionId, gasValues);
602
- const transactionMeta = this.getTransaction(transactionId);
603
- if (!transactionMeta) {
604
- return;
605
- }
606
- if (!this.sign) {
607
- throw new Error("No sign method defined.");
608
- }
609
- const minGasPrice = getIncreasedPriceFromExisting(
610
- transactionMeta.txParams.gasPrice,
611
- CANCEL_RATE
612
- );
613
- const gasPriceFromValues = isGasPriceValue(gasValues) && gasValues.gasPrice;
614
- const newGasPrice = gasPriceFromValues && validateMinimumIncrease(gasPriceFromValues, minGasPrice) || minGasPrice;
615
- const existingMaxFeePerGas = transactionMeta.txParams?.maxFeePerGas;
616
- const minMaxFeePerGas = getIncreasedPriceFromExisting(
617
- existingMaxFeePerGas,
618
- CANCEL_RATE
619
- );
620
- const maxFeePerGasValues = isFeeMarketEIP1559Values(gasValues) && gasValues.maxFeePerGas;
621
- const newMaxFeePerGas = maxFeePerGasValues && validateMinimumIncrease(maxFeePerGasValues, minMaxFeePerGas) || existingMaxFeePerGas && minMaxFeePerGas;
622
- const existingMaxPriorityFeePerGas = transactionMeta.txParams?.maxPriorityFeePerGas;
623
- const minMaxPriorityFeePerGas = getIncreasedPriceFromExisting(
624
- existingMaxPriorityFeePerGas,
625
- CANCEL_RATE
626
- );
627
- const maxPriorityFeePerGasValues = isFeeMarketEIP1559Values(gasValues) && gasValues.maxPriorityFeePerGas;
628
- const newMaxPriorityFeePerGas = maxPriorityFeePerGasValues && validateMinimumIncrease(
629
- maxPriorityFeePerGasValues,
630
- minMaxPriorityFeePerGas
631
- ) || existingMaxPriorityFeePerGas && minMaxPriorityFeePerGas;
632
- const newTxParams = newMaxFeePerGas && newMaxPriorityFeePerGas ? {
633
- from: transactionMeta.txParams.from,
634
- gasLimit: transactionMeta.txParams.gas,
635
- maxFeePerGas: newMaxFeePerGas,
636
- maxPriorityFeePerGas: newMaxPriorityFeePerGas,
637
- type: "0x2" /* feeMarket */,
638
- nonce: transactionMeta.txParams.nonce,
639
- to: transactionMeta.txParams.from,
640
- value: "0x0"
641
- } : {
642
- from: transactionMeta.txParams.from,
643
- gasLimit: transactionMeta.txParams.gas,
644
- gasPrice: newGasPrice,
645
- nonce: transactionMeta.txParams.nonce,
646
- to: transactionMeta.txParams.from,
647
- value: "0x0"
648
- };
649
- const unsignedEthTx = this.prepareUnsignedEthTx(
650
- transactionMeta.chainId,
651
- newTxParams
652
- );
653
- const signedTx = await this.sign(
654
- unsignedEthTx,
655
- transactionMeta.txParams.from
656
- );
657
- const rawTx = bufferToHex(signedTx.serialize());
658
- const newFee = newTxParams.maxFeePerGas ?? newTxParams.gasPrice;
659
- const oldFee = newTxParams.maxFeePerGas ? transactionMeta.txParams.maxFeePerGas : transactionMeta.txParams.gasPrice;
660
- projectLogger("Submitting cancel transaction", {
661
- oldFee,
662
- newFee,
663
- txParams: newTxParams
664
- });
665
- const ethQuery = __privateGet(this, _multichainTrackingHelper).getEthQuery({
666
- networkClientId: transactionMeta.networkClientId,
667
- chainId: transactionMeta.chainId
668
- });
669
- const hash = await this.publishTransactionForRetry(
670
- ethQuery,
671
- rawTx,
672
- transactionMeta
673
- );
674
- const cancelTransactionMeta = {
608
+ return await __privateMethod(this, _retryTransaction, retryTransaction_fn).call(this, {
675
609
  actionId,
676
- chainId: transactionMeta.chainId,
677
- networkClientId: transactionMeta.networkClientId,
678
610
  estimatedBaseFee,
679
- hash,
680
- id: random(),
681
- originalGasEstimate: transactionMeta.txParams.gas,
682
- status: "submitted" /* submitted */,
683
- time: Date.now(),
684
- type: "cancel" /* cancel */,
685
- txParams: newTxParams
686
- };
687
- this.addMetadata(cancelTransactionMeta);
688
- this.messagingSystem.publish(`${controllerName}:transactionApproved`, {
689
- transactionMeta: cancelTransactionMeta,
690
- actionId
691
- });
692
- this.messagingSystem.publish(`${controllerName}:transactionSubmitted`, {
693
- transactionMeta: cancelTransactionMeta,
694
- actionId
611
+ gasValues,
612
+ label: "cancel",
613
+ rate: CANCEL_RATE,
614
+ transactionId,
615
+ transactionType: "cancel" /* cancel */,
616
+ prepareTransactionParams: (txParams) => {
617
+ delete txParams.data;
618
+ txParams.to = txParams.from;
619
+ txParams.value = "0x0";
620
+ },
621
+ afterSubmit: (newTransactionMeta) => {
622
+ this.messagingSystem.publish(
623
+ `${controllerName}:transactionFinished`,
624
+ newTransactionMeta
625
+ );
626
+ __privateGet(this, _internalEvents).emit(
627
+ `${newTransactionMeta.id}:finished`,
628
+ newTransactionMeta
629
+ );
630
+ }
695
631
  });
696
- this.messagingSystem.publish(
697
- `${controllerName}:transactionFinished`,
698
- cancelTransactionMeta
699
- );
700
- __privateGet(this, _internalEvents).emit(
701
- `${transactionMeta.id}:finished`,
702
- cancelTransactionMeta
703
- );
704
632
  }
705
633
  /**
706
634
  * Attempts to speed up a transaction increasing transaction gasPrice by ten percent.
@@ -715,118 +643,21 @@ var TransactionController = class extends BaseController {
715
643
  actionId,
716
644
  estimatedBaseFee
717
645
  } = {}) {
718
- if (this.getTransactionWithActionId(actionId)) {
719
- return;
720
- }
721
- if (gasValues) {
722
- gasValues = normalizeGasFeeValues(gasValues);
723
- validateGasValues(gasValues);
724
- }
725
- projectLogger("Creating speed up transaction", transactionId, gasValues);
726
- const transactionMeta = this.getTransaction(transactionId);
727
- if (!transactionMeta) {
728
- return;
729
- }
730
- if (!this.sign) {
731
- throw new Error("No sign method defined.");
732
- }
733
- const minGasPrice = getIncreasedPriceFromExisting(
734
- transactionMeta.txParams.gasPrice,
735
- SPEED_UP_RATE
736
- );
737
- const gasPriceFromValues = isGasPriceValue(gasValues) && gasValues.gasPrice;
738
- const newGasPrice = gasPriceFromValues && validateMinimumIncrease(gasPriceFromValues, minGasPrice) || minGasPrice;
739
- const existingMaxFeePerGas = transactionMeta.txParams?.maxFeePerGas;
740
- const minMaxFeePerGas = getIncreasedPriceFromExisting(
741
- existingMaxFeePerGas,
742
- SPEED_UP_RATE
743
- );
744
- const maxFeePerGasValues = isFeeMarketEIP1559Values(gasValues) && gasValues.maxFeePerGas;
745
- const newMaxFeePerGas = maxFeePerGasValues && validateMinimumIncrease(maxFeePerGasValues, minMaxFeePerGas) || existingMaxFeePerGas && minMaxFeePerGas;
746
- const existingMaxPriorityFeePerGas = transactionMeta.txParams?.maxPriorityFeePerGas;
747
- const minMaxPriorityFeePerGas = getIncreasedPriceFromExisting(
748
- existingMaxPriorityFeePerGas,
749
- SPEED_UP_RATE
750
- );
751
- const maxPriorityFeePerGasValues = isFeeMarketEIP1559Values(gasValues) && gasValues.maxPriorityFeePerGas;
752
- const newMaxPriorityFeePerGas = maxPriorityFeePerGasValues && validateMinimumIncrease(
753
- maxPriorityFeePerGasValues,
754
- minMaxPriorityFeePerGas
755
- ) || existingMaxPriorityFeePerGas && minMaxPriorityFeePerGas;
756
- const txParams = newMaxFeePerGas && newMaxPriorityFeePerGas ? {
757
- ...transactionMeta.txParams,
758
- gasLimit: transactionMeta.txParams.gas,
759
- maxFeePerGas: newMaxFeePerGas,
760
- maxPriorityFeePerGas: newMaxPriorityFeePerGas,
761
- type: "0x2" /* feeMarket */
762
- } : {
763
- ...transactionMeta.txParams,
764
- gasLimit: transactionMeta.txParams.gas,
765
- gasPrice: newGasPrice
766
- };
767
- const unsignedEthTx = this.prepareUnsignedEthTx(
768
- transactionMeta.chainId,
769
- txParams
770
- );
771
- const signedTx = await this.sign(
772
- unsignedEthTx,
773
- transactionMeta.txParams.from
774
- );
775
- const transactionMetaWithRsv = this.updateTransactionMetaRSV(
776
- transactionMeta,
777
- signedTx
778
- );
779
- const rawTx = bufferToHex(signedTx.serialize());
780
- const newFee = txParams.maxFeePerGas ?? txParams.gasPrice;
781
- const oldFee = txParams.maxFeePerGas ? transactionMetaWithRsv.txParams.maxFeePerGas : transactionMetaWithRsv.txParams.gasPrice;
782
- projectLogger("Submitting speed up transaction", { oldFee, newFee, txParams });
783
- const ethQuery = __privateGet(this, _multichainTrackingHelper).getEthQuery({
784
- networkClientId: transactionMeta.networkClientId,
785
- chainId: transactionMeta.chainId
786
- });
787
- const hash = await this.publishTransactionForRetry(
788
- ethQuery,
789
- rawTx,
790
- transactionMeta
791
- );
792
- const baseTransactionMeta = {
793
- ...transactionMetaWithRsv,
794
- estimatedBaseFee,
795
- id: random(),
796
- time: Date.now(),
797
- hash,
646
+ return await __privateMethod(this, _retryTransaction, retryTransaction_fn).call(this, {
798
647
  actionId,
799
- originalGasEstimate: transactionMeta.txParams.gas,
800
- type: "retry" /* retry */,
801
- originalType: transactionMeta.type
802
- };
803
- const newTransactionMeta = newMaxFeePerGas && newMaxPriorityFeePerGas ? {
804
- ...baseTransactionMeta,
805
- txParams: {
806
- ...transactionMeta.txParams,
807
- maxFeePerGas: newMaxFeePerGas,
808
- maxPriorityFeePerGas: newMaxPriorityFeePerGas
809
- }
810
- } : {
811
- ...baseTransactionMeta,
812
- txParams: {
813
- ...transactionMeta.txParams,
814
- gasPrice: newGasPrice
648
+ estimatedBaseFee,
649
+ gasValues,
650
+ label: "speed up",
651
+ rate: SPEED_UP_RATE,
652
+ transactionId,
653
+ transactionType: "retry" /* retry */,
654
+ afterSubmit: (newTransactionMeta) => {
655
+ this.messagingSystem.publish(
656
+ `${controllerName}:speedupTransactionAdded`,
657
+ newTransactionMeta
658
+ );
815
659
  }
816
- };
817
- this.addMetadata(newTransactionMeta);
818
- this.messagingSystem.publish(`${controllerName}:transactionApproved`, {
819
- transactionMeta: newTransactionMeta,
820
- actionId
821
- });
822
- this.messagingSystem.publish(`${controllerName}:transactionSubmitted`, {
823
- transactionMeta: newTransactionMeta,
824
- actionId
825
660
  });
826
- this.messagingSystem.publish(
827
- `${controllerName}:speedupTransactionAdded`,
828
- newTransactionMeta
829
- );
830
661
  }
831
662
  /**
832
663
  * Estimates required gas for a given transaction.
@@ -960,7 +791,10 @@ var TransactionController = class extends BaseController {
960
791
  `${controllerName}:confirmExternalTransaction - Add external transaction`
961
792
  );
962
793
  this.onTransactionStatusChange(updatedTransactionMeta);
963
- this.updatePostBalance(updatedTransactionMeta);
794
+ this.updatePostBalance(updatedTransactionMeta).catch((error) => {
795
+ projectLogger("Error while updating post balance", error);
796
+ throw error;
797
+ });
964
798
  this.messagingSystem.publish(
965
799
  `${controllerName}:transactionConfirmed`,
966
800
  updatedTransactionMeta
@@ -1492,6 +1326,7 @@ var TransactionController = class extends BaseController {
1492
1326
  this.signAbortCallbacks.delete(transactionId);
1493
1327
  }
1494
1328
  addMetadata(transactionMeta) {
1329
+ validateTxParams(transactionMeta.txParams);
1495
1330
  this.update((state) => {
1496
1331
  state.transactions = this.trimTransactionsForState([
1497
1332
  ...state.transactions,
@@ -1499,8 +1334,8 @@ var TransactionController = class extends BaseController {
1499
1334
  ]);
1500
1335
  });
1501
1336
  }
1502
- async updateGasProperties(transactionMeta) {
1503
- const isEIP1559Compatible = await this.getEIP1559Compatibility(transactionMeta.networkClientId) && transactionMeta.txParams.type !== "0x0" /* legacy */;
1337
+ async updateGasProperties(transactionMeta, { traceContext } = {}) {
1338
+ const isEIP1559Compatible = transactionMeta.txParams.type !== "0x0" /* legacy */ && await this.getEIP1559Compatibility(transactionMeta.networkClientId);
1504
1339
  const { networkClientId, chainId } = transactionMeta;
1505
1340
  const isCustomNetwork = __privateMethod(this, _isCustomNetwork, isCustomNetwork_fn).call(this, networkClientId);
1506
1341
  const ethQuery = __privateGet(this, _multichainTrackingHelper).getEthQuery({
@@ -1511,25 +1346,27 @@ var TransactionController = class extends BaseController {
1511
1346
  networkClientId,
1512
1347
  chainId
1513
1348
  });
1514
- await updateGas({
1515
- ethQuery,
1516
- chainId,
1517
- isCustomNetwork,
1518
- txMeta: transactionMeta
1349
+ await __privateGet(this, _trace).call(this, { name: "Update Gas", parentContext: traceContext }, async () => {
1350
+ await updateGas({
1351
+ ethQuery,
1352
+ chainId,
1353
+ isCustomNetwork,
1354
+ txMeta: transactionMeta
1355
+ });
1519
1356
  });
1520
- await updateGasFees({
1357
+ await __privateGet(this, _trace).call(this, { name: "Update Gas Fees", parentContext: traceContext }, async () => await updateGasFees({
1521
1358
  eip1559: isEIP1559Compatible,
1522
1359
  ethQuery,
1523
1360
  gasFeeFlows: this.gasFeeFlows,
1524
1361
  getGasFeeEstimates: this.getGasFeeEstimates,
1525
1362
  getSavedGasFees: this.getSavedGasFees.bind(this),
1526
1363
  txMeta: transactionMeta
1527
- });
1528
- await updateTransactionLayer1GasFee({
1364
+ }));
1365
+ await __privateGet(this, _trace).call(this, { name: "Update Layer 1 Gas Fees", parentContext: traceContext }, async () => await updateTransactionLayer1GasFee({
1529
1366
  layer1GasFeeFlows: this.layer1GasFeeFlows,
1530
1367
  provider,
1531
1368
  transactionMeta
1532
- });
1369
+ }));
1533
1370
  }
1534
1371
  onBootCleanup() {
1535
1372
  this.submitApprovedTransactions();
@@ -1553,7 +1390,8 @@ var TransactionController = class extends BaseController {
1553
1390
  isExisting = false,
1554
1391
  requireApproval,
1555
1392
  shouldShowRequest = true,
1556
- actionId
1393
+ actionId,
1394
+ traceContext
1557
1395
  }) {
1558
1396
  const transactionId = transactionMeta.id;
1559
1397
  let resultCallbacks;
@@ -1562,9 +1400,10 @@ var TransactionController = class extends BaseController {
1562
1400
  if (meta && !isExisting && !isCompleted) {
1563
1401
  try {
1564
1402
  if (requireApproval !== false) {
1565
- const acceptResult = await this.requestApproval(transactionMeta, {
1566
- shouldShowRequest
1567
- });
1403
+ const acceptResult = await __privateGet(this, _trace).call(this, { name: "Await Approval", parentContext: traceContext }, (context) => this.requestApproval(transactionMeta, {
1404
+ shouldShowRequest,
1405
+ traceContext: context
1406
+ }));
1568
1407
  resultCallbacks = acceptResult.resultCallbacks;
1569
1408
  const approvalValue = acceptResult.value;
1570
1409
  const updatedTransaction = approvalValue?.txMeta;
@@ -1581,7 +1420,10 @@ var TransactionController = class extends BaseController {
1581
1420
  }
1582
1421
  const { isCompleted: isTxCompleted } = this.isTransactionCompleted(transactionId);
1583
1422
  if (!isTxCompleted) {
1584
- const approvalResult = await this.approveTransaction(transactionId);
1423
+ const approvalResult = await this.approveTransaction(
1424
+ transactionId,
1425
+ traceContext
1426
+ );
1585
1427
  if (approvalResult === "skipped-via-before-publish-hook" /* SkippedViaBeforePublishHook */ && resultCallbacks) {
1586
1428
  resultCallbacks.success();
1587
1429
  }
@@ -1635,8 +1477,9 @@ var TransactionController = class extends BaseController {
1635
1477
  * A `<tx.id>:finished` hub event is fired after success or failure.
1636
1478
  *
1637
1479
  * @param transactionId - The ID of the transaction to approve.
1480
+ * @param traceContext - The parent context for any new traces.
1638
1481
  */
1639
- async approveTransaction(transactionId) {
1482
+ async approveTransaction(transactionId, traceContext) {
1640
1483
  const cleanupTasks = new Array();
1641
1484
  cleanupTasks.push(await this.mutex.acquire());
1642
1485
  let transactionMeta = this.getTransactionOrThrow(transactionId);
@@ -1684,10 +1527,7 @@ var TransactionController = class extends BaseController {
1684
1527
  };
1685
1528
  });
1686
1529
  this.onTransactionStatusChange(transactionMeta);
1687
- const rawTx = await this.signTransaction(
1688
- transactionMeta,
1689
- transactionMeta.txParams
1690
- );
1530
+ const rawTx = await __privateGet(this, _trace).call(this, { name: "Sign", parentContext: traceContext }, () => this.signTransaction(transactionMeta, transactionMeta.txParams));
1691
1531
  if (!this.beforePublish(transactionMeta)) {
1692
1532
  projectLogger("Skipping publishing transaction based on hook");
1693
1533
  this.messagingSystem.publish(
@@ -1712,13 +1552,16 @@ var TransactionController = class extends BaseController {
1712
1552
  ]);
1713
1553
  }
1714
1554
  projectLogger("Publishing transaction", transactionMeta.txParams);
1715
- let { transactionHash: hash } = await this.publish(
1716
- transactionMeta,
1717
- rawTx
1718
- );
1719
- if (hash === void 0) {
1720
- hash = await this.publishTransaction(ethQuery, rawTx);
1721
- }
1555
+ let hash;
1556
+ await __privateGet(this, _trace).call(this, { name: "Publish", parentContext: traceContext }, async () => {
1557
+ ({ transactionHash: hash } = await this.publish(
1558
+ transactionMeta,
1559
+ rawTx
1560
+ ));
1561
+ if (hash === void 0) {
1562
+ hash = await this.publishTransaction(ethQuery, rawTx);
1563
+ }
1564
+ });
1722
1565
  projectLogger("Publish successful", hash);
1723
1566
  transactionMeta = __privateMethod(this, _updateTransactionInternal, updateTransactionInternal_fn).call(this, {
1724
1567
  transactionId,
@@ -1849,11 +1692,19 @@ var TransactionController = class extends BaseController {
1849
1692
  "submitted" /* submitted */
1850
1693
  ].includes(status);
1851
1694
  }
1852
- async requestApproval(txMeta, { shouldShowRequest }) {
1695
+ async requestApproval(txMeta, {
1696
+ shouldShowRequest,
1697
+ traceContext
1698
+ }) {
1853
1699
  const id = this.getApprovalId(txMeta);
1854
1700
  const { origin } = txMeta;
1855
1701
  const type = ApprovalType.Transaction;
1856
1702
  const requestData = { txId: txMeta.id };
1703
+ await __privateGet(this, _trace).call(this, {
1704
+ name: "Notification Display",
1705
+ id,
1706
+ parentContext: traceContext
1707
+ });
1857
1708
  return await this.messagingSystem.call(
1858
1709
  "ApprovalController:addRequest",
1859
1710
  {
@@ -2177,7 +2028,10 @@ var TransactionController = class extends BaseController {
2177
2028
  transactionMeta
2178
2029
  );
2179
2030
  this.onTransactionStatusChange(transactionMeta);
2180
- this.updatePostBalance(transactionMeta);
2031
+ this.updatePostBalance(transactionMeta).catch((error) => {
2032
+ projectLogger("Error while updating post balance", error);
2033
+ throw error;
2034
+ });
2181
2035
  }
2182
2036
  async updatePostBalance(transactionMeta) {
2183
2037
  try {
@@ -2234,10 +2088,96 @@ var TransactionController = class extends BaseController {
2234
2088
  _internalEvents = new WeakMap();
2235
2089
  _incomingTransactionOptions = new WeakMap();
2236
2090
  _pendingTransactionOptions = new WeakMap();
2091
+ _trace = new WeakMap();
2237
2092
  _transactionHistoryLimit = new WeakMap();
2238
2093
  _isSimulationEnabled = new WeakMap();
2239
2094
  _testGasFeeFlows = new WeakMap();
2240
2095
  _multichainTrackingHelper = new WeakMap();
2096
+ _retryTransaction = new WeakSet();
2097
+ retryTransaction_fn = async function({
2098
+ actionId,
2099
+ afterSubmit,
2100
+ estimatedBaseFee,
2101
+ gasValues,
2102
+ label,
2103
+ prepareTransactionParams,
2104
+ rate,
2105
+ transactionId,
2106
+ transactionType
2107
+ }) {
2108
+ if (this.getTransactionWithActionId(actionId)) {
2109
+ return;
2110
+ }
2111
+ if (gasValues) {
2112
+ gasValues = normalizeGasFeeValues(gasValues);
2113
+ validateGasValues(gasValues);
2114
+ }
2115
+ projectLogger(`Creating ${label} transaction`, transactionId, gasValues);
2116
+ const transactionMeta = this.getTransaction(transactionId);
2117
+ if (!transactionMeta) {
2118
+ return;
2119
+ }
2120
+ if (!this.sign) {
2121
+ throw new Error("No sign method defined.");
2122
+ }
2123
+ const newTxParams = getTransactionParamsWithIncreasedGasFee(
2124
+ transactionMeta.txParams,
2125
+ rate,
2126
+ gasValues
2127
+ );
2128
+ prepareTransactionParams?.(newTxParams);
2129
+ const unsignedEthTx = this.prepareUnsignedEthTx(
2130
+ transactionMeta.chainId,
2131
+ newTxParams
2132
+ );
2133
+ const signedTx = await this.sign(
2134
+ unsignedEthTx,
2135
+ transactionMeta.txParams.from
2136
+ );
2137
+ const transactionMetaWithRsv = this.updateTransactionMetaRSV(
2138
+ transactionMeta,
2139
+ signedTx
2140
+ );
2141
+ const rawTx = bufferToHex(signedTx.serialize());
2142
+ const newFee = newTxParams.maxFeePerGas ?? newTxParams.gasPrice;
2143
+ const oldFee = newTxParams.maxFeePerGas ? transactionMetaWithRsv.txParams.maxFeePerGas : transactionMetaWithRsv.txParams.gasPrice;
2144
+ projectLogger(`Submitting ${label} transaction`, {
2145
+ oldFee,
2146
+ newFee,
2147
+ txParams: newTxParams
2148
+ });
2149
+ const ethQuery = __privateGet(this, _multichainTrackingHelper).getEthQuery({
2150
+ networkClientId: transactionMeta.networkClientId,
2151
+ chainId: transactionMeta.chainId
2152
+ });
2153
+ const hash = await this.publishTransactionForRetry(
2154
+ ethQuery,
2155
+ rawTx,
2156
+ transactionMeta
2157
+ );
2158
+ const newTransactionMeta = {
2159
+ ...transactionMetaWithRsv,
2160
+ estimatedBaseFee,
2161
+ id: random(),
2162
+ time: Date.now(),
2163
+ hash,
2164
+ actionId,
2165
+ originalGasEstimate: transactionMeta.txParams.gas,
2166
+ type: transactionType,
2167
+ txParams: newTxParams,
2168
+ originalType: transactionMeta.type
2169
+ };
2170
+ this.addMetadata(newTransactionMeta);
2171
+ this.messagingSystem.publish(`${controllerName}:transactionApproved`, {
2172
+ transactionMeta: newTransactionMeta,
2173
+ actionId
2174
+ });
2175
+ this.messagingSystem.publish(`${controllerName}:transactionSubmitted`, {
2176
+ transactionMeta: newTransactionMeta,
2177
+ actionId
2178
+ });
2179
+ afterSubmit?.(newTransactionMeta);
2180
+ };
2241
2181
  _createNonceTracker = new WeakSet();
2242
2182
  createNonceTracker_fn = function({
2243
2183
  provider,
@@ -2248,7 +2188,7 @@ createNonceTracker_fn = function({
2248
2188
  // TODO: Fix types
2249
2189
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2250
2190
  provider,
2251
- // @ts-expect-error TODO: Fix types
2191
+ // TODO: Fix types
2252
2192
  blockTracker,
2253
2193
  getPendingTransactions: __privateMethod(this, _getNonceTrackerPendingTransactions, getNonceTrackerPendingTransactions_fn).bind(
2254
2194
  this,
@@ -2447,11 +2387,14 @@ onTransactionParamsUpdated_fn = function(transactionMeta, updatedParams) {
2447
2387
  (param) => updatedParams.includes(param)
2448
2388
  )) {
2449
2389
  projectLogger("Updating simulation data due to transaction parameter update");
2450
- __privateMethod(this, _updateSimulationData, updateSimulationData_fn).call(this, transactionMeta);
2390
+ __privateMethod(this, _updateSimulationData, updateSimulationData_fn).call(this, transactionMeta).catch((error) => {
2391
+ projectLogger("Error updating simulation data", error);
2392
+ throw error;
2393
+ });
2451
2394
  }
2452
2395
  };
2453
2396
  _updateSimulationData = new WeakSet();
2454
- updateSimulationData_fn = async function(transactionMeta) {
2397
+ updateSimulationData_fn = async function(transactionMeta, { traceContext } = {}) {
2455
2398
  const { id: transactionId, chainId, txParams } = transactionMeta;
2456
2399
  const { from, to, value, data } = txParams;
2457
2400
  let simulationData = {
@@ -2465,13 +2408,13 @@ updateSimulationData_fn = async function(transactionMeta) {
2465
2408
  __privateMethod(this, _updateTransactionInternal, updateTransactionInternal_fn).call(this, { transactionId, skipHistory: true }, (txMeta) => {
2466
2409
  txMeta.simulationData = void 0;
2467
2410
  });
2468
- simulationData = await getSimulationData({
2411
+ simulationData = await __privateGet(this, _trace).call(this, { name: "Simulate", parentContext: traceContext }, () => getSimulationData({
2469
2412
  chainId,
2470
2413
  from,
2471
2414
  to,
2472
2415
  value,
2473
2416
  data
2474
- });
2417
+ }));
2475
2418
  }
2476
2419
  const finalTransactionMeta = this.getTransaction(transactionId);
2477
2420
  if (!finalTransactionMeta) {
@@ -2563,4 +2506,4 @@ export {
2563
2506
  ApprovalState,
2564
2507
  TransactionController
2565
2508
  };
2566
- //# sourceMappingURL=chunk-5JWPMHSZ.mjs.map
2509
+ //# sourceMappingURL=chunk-XTMJ25EF.mjs.map