@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
package/CHANGELOG.md CHANGED
@@ -7,6 +7,36 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [35.2.0]
11
+
12
+ ### Added
13
+
14
+ - Add tracing infrastructure ([#4575](https://github.com/MetaMask/core/pull/4575))
15
+ - Add optional `trace` callback to constructor.
16
+ - Add optional `traceContext` option to `addTransaction` method.
17
+ - Add initial tracing of transaction lifecycle.
18
+
19
+ ### Changed
20
+
21
+ - Bump `@metamask/base-controller` from `^6.0.2` to `^6.0.3` ([#4625](https://github.com/MetaMask/core/pull/4625))
22
+ - Bump `@metamask/network-controller` from `^20.1.0` to `^20.2.0` ([#4618](https://github.com/MetaMask/core/pull/4618))
23
+ - Bump `@metamask/eth-json-rpc-provider` from `^4.1.2` to `^4.1.3` ([#4607](https://github.com/MetaMask/core/pull/4607))
24
+
25
+ ### Removed
26
+
27
+ - Remove validation of `gasValues` passed to `speedUpTransaction` and `stopTransaction` methods ([#4617](https://github.com/MetaMask/core/pull/4617))
28
+
29
+ ## [35.1.1]
30
+
31
+ ### Changed
32
+
33
+ - Upgrade TypeScript version from `~5.0.4` to `~5.2.2` ([#4576](https://github.com/MetaMask/core/pull/4576), [#4584](https://github.com/MetaMask/core/pull/4584))
34
+
35
+ ### Fixed
36
+
37
+ - Fix gaps in transaction validation and async error logging ([#4596](https://github.com/MetaMask/core/pull/4596))
38
+ - Upgrade `@metamask/nonce-tracker` from v5 to v6 ([#4591](https://github.com/MetaMask/core/pull/4591))
39
+
10
40
  ## [35.1.0]
11
41
 
12
42
  ### Added
@@ -948,7 +978,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
948
978
 
949
979
  All changes listed after this point were applied to this package following the monorepo conversion.
950
980
 
951
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@35.1.0...HEAD
981
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@35.2.0...HEAD
982
+ [35.2.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@35.1.1...@metamask/transaction-controller@35.2.0
983
+ [35.1.1]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@35.1.0...@metamask/transaction-controller@35.1.1
952
984
  [35.1.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@35.0.1...@metamask/transaction-controller@35.1.0
953
985
  [35.0.1]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@35.0.0...@metamask/transaction-controller@35.0.1
954
986
  [35.0.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@34.0.0...@metamask/transaction-controller@35.0.0
@@ -4,12 +4,13 @@
4
4
 
5
5
 
6
6
 
7
- var _chunkQKS2F7VGjs = require('./chunk-QKS2F7VG.js');
7
+ var _chunkVKWOHNDOjs = require('./chunk-VKWOHNDO.js');
8
8
  require('./chunk-PRUNMTRD.js');
9
+ require('./chunk-5QVDIVJH.js');
9
10
  require('./chunk-NNCUD3QF.js');
10
11
  require('./chunk-KT6UAKBB.js');
11
12
  require('./chunk-SD6CWFDF.js');
12
- require('./chunk-RXIUMVA5.js');
13
+ require('./chunk-4OYPDGHO.js');
13
14
  require('./chunk-ULD4JC3Q.js');
14
15
  require('./chunk-7LXE4KHV.js');
15
16
  require('./chunk-V72C4MCR.js');
@@ -18,22 +19,22 @@ require('./chunk-NYKRCWBG.js');
18
19
  require('./chunk-WR5F34OW.js');
19
20
  require('./chunk-YVCX6Z75.js');
20
21
  require('./chunk-TJMQEH57.js');
21
- require('./chunk-2EU6346V.js');
22
+ require('./chunk-5HYWLTVQ.js');
22
23
  require('./chunk-2XKEAKQG.js');
23
24
  require('./chunk-RHDPOIS4.js');
24
25
  require('./chunk-6OLJWLKK.js');
25
26
  require('./chunk-7NMV2NPM.js');
26
27
  require('./chunk-XVYXRCRL.js');
27
28
  require('./chunk-HMOSP33F.js');
28
- require('./chunk-ARZHJFVG.js');
29
- require('./chunk-QTKXIDGE.js');
30
- require('./chunk-C3WC4OJ3.js');
31
- require('./chunk-QH2H4W3N.js');
32
- require('./chunk-OZ6UB42C.js');
33
- require('./chunk-76FONEDA.js');
29
+ require('./chunk-UHAFIPSL.js');
30
+ require('./chunk-EHWAY6XU.js');
31
+ require('./chunk-BZV72SCF.js');
32
+ require('./chunk-QKV7E5BO.js');
33
+ require('./chunk-KTGMNUTQ.js');
34
+ require('./chunk-YWLMT7XH.js');
34
35
  require('./chunk-UGN7PBON.js');
35
36
  require('./chunk-S6VGOPUY.js');
36
- require('./chunk-AYTU4HU5.js');
37
+ require('./chunk-PSZ34BI5.js');
37
38
  require('./chunk-Z4BLTVTB.js');
38
39
 
39
40
 
@@ -41,5 +42,5 @@ require('./chunk-Z4BLTVTB.js');
41
42
 
42
43
 
43
44
 
44
- exports.ApprovalState = _chunkQKS2F7VGjs.ApprovalState; exports.CANCEL_RATE = _chunkQKS2F7VGjs.CANCEL_RATE; exports.HARDFORK = _chunkQKS2F7VGjs.HARDFORK; exports.SPEED_UP_RATE = _chunkQKS2F7VGjs.SPEED_UP_RATE; exports.TransactionController = _chunkQKS2F7VGjs.TransactionController;
45
+ exports.ApprovalState = _chunkVKWOHNDOjs.ApprovalState; exports.CANCEL_RATE = _chunkVKWOHNDOjs.CANCEL_RATE; exports.HARDFORK = _chunkVKWOHNDOjs.HARDFORK; exports.SPEED_UP_RATE = _chunkVKWOHNDOjs.SPEED_UP_RATE; exports.TransactionController = _chunkVKWOHNDOjs.TransactionController;
45
46
  //# sourceMappingURL=TransactionController.js.map
@@ -4,12 +4,13 @@ import {
4
4
  HARDFORK,
5
5
  SPEED_UP_RATE,
6
6
  TransactionController
7
- } from "./chunk-5JWPMHSZ.mjs";
7
+ } from "./chunk-XTMJ25EF.mjs";
8
8
  import "./chunk-6DDVVUJC.mjs";
9
+ import "./chunk-JOQK7A5G.mjs";
9
10
  import "./chunk-3AVRGHUO.mjs";
10
11
  import "./chunk-K4KOSAGM.mjs";
11
12
  import "./chunk-KG4UW4K4.mjs";
12
- import "./chunk-5ZEJT5SN.mjs";
13
+ import "./chunk-X4XSEYPL.mjs";
13
14
  import "./chunk-6B5BEO3R.mjs";
14
15
  import "./chunk-FRKQ3Z2L.mjs";
15
16
  import "./chunk-5G6OHAXI.mjs";
@@ -18,22 +19,22 @@ import "./chunk-VEVVBHP3.mjs";
18
19
  import "./chunk-Z4GV3YQQ.mjs";
19
20
  import "./chunk-FG74Z3F5.mjs";
20
21
  import "./chunk-FMRLPVFZ.mjs";
21
- import "./chunk-SFFTNB2X.mjs";
22
+ import "./chunk-VGFPVAKX.mjs";
22
23
  import "./chunk-NOHEXQ7Y.mjs";
23
24
  import "./chunk-3ZV5YEUV.mjs";
24
25
  import "./chunk-4V4XIPCI.mjs";
25
26
  import "./chunk-EKJXGERC.mjs";
26
27
  import "./chunk-EGQCE3FK.mjs";
27
28
  import "./chunk-HQSNKCXI.mjs";
28
- import "./chunk-UHG2LLVV.mjs";
29
- import "./chunk-H2KZOK3J.mjs";
30
- import "./chunk-VXNPVIYL.mjs";
31
- import "./chunk-GNAL5HC2.mjs";
32
- import "./chunk-Q56I5ONX.mjs";
33
- import "./chunk-JXXTNVU4.mjs";
29
+ import "./chunk-KYRW4BLA.mjs";
30
+ import "./chunk-AWIJZAW3.mjs";
31
+ import "./chunk-SFFOC25Q.mjs";
32
+ import "./chunk-JIFPK37W.mjs";
33
+ import "./chunk-UHSRHP55.mjs";
34
+ import "./chunk-NNHSNPT2.mjs";
34
35
  import "./chunk-O6ZZVIFH.mjs";
35
36
  import "./chunk-UQQWZT6C.mjs";
36
- import "./chunk-6SJYXSF3.mjs";
37
+ import "./chunk-LFFYCDHB.mjs";
37
38
  import "./chunk-XUI43LEZ.mjs";
38
39
  export {
39
40
  ApprovalState,
@@ -1,6 +1,9 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkOZ6UB42Cjs = require('./chunk-OZ6UB42C.js');
3
+ var _chunkKTGMNUTQjs = require('./chunk-KTGMNUTQ.js');
4
+
5
+
6
+ var _chunkPSZ34BI5js = require('./chunk-PSZ34BI5.js');
4
7
 
5
8
  // src/utils/validation.ts
6
9
  var _abi = require('@ethersproject/abi');
@@ -26,6 +29,7 @@ async function validateTransactionOrigin(permittedAddresses, selectedAddress, fr
26
29
  }
27
30
  }
28
31
  function validateTxParams(txParams, isEIP1559Compatible = true) {
32
+ validateEnvelopeType(txParams.type);
29
33
  validateEIP1559Compatibility(txParams, isEIP1559Compatible);
30
34
  validateParamFrom(txParams.from);
31
35
  validateParamRecipient(txParams);
@@ -34,8 +38,19 @@ function validateTxParams(txParams, isEIP1559Compatible = true) {
34
38
  validateParamChainId(txParams.chainId);
35
39
  validateGasFeeParams(txParams);
36
40
  }
41
+ function validateEnvelopeType(type) {
42
+ if (type && !Object.values(_chunkPSZ34BI5js.TransactionEnvelopeType).includes(
43
+ type
44
+ )) {
45
+ throw _rpcerrors.rpcErrors.invalidParams(
46
+ `Invalid transaction envelope type: "${type}". Must be one of: ${Object.values(
47
+ _chunkPSZ34BI5js.TransactionEnvelopeType
48
+ ).join(", ")}`
49
+ );
50
+ }
51
+ }
37
52
  function validateEIP1559Compatibility(txParams, isEIP1559Compatible) {
38
- if (_chunkOZ6UB42Cjs.isEIP1559Transaction.call(void 0, txParams) && !isEIP1559Compatible) {
53
+ if (_chunkKTGMNUTQjs.isEIP1559Transaction.call(void 0, txParams) && !isEIP1559Compatible) {
39
54
  throw _rpcerrors.rpcErrors.invalidParams(
40
55
  "Invalid transaction params: params specify an EIP-1559 transaction but the current network does not support EIP-1559"
41
56
  );
@@ -183,4 +198,4 @@ function ensureFieldIsString(txParams, field) {
183
198
 
184
199
 
185
200
  exports.validateTransactionOrigin = validateTransactionOrigin; exports.validateTxParams = validateTxParams;
186
- //# sourceMappingURL=chunk-RXIUMVA5.js.map
201
+ //# sourceMappingURL=chunk-4OYPDGHO.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/validation.ts"],"names":[],"mappings":"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","sourcesContent":["import { Interface } from '@ethersproject/abi';\nimport { ORIGIN_METAMASK, isValidHexAddress } from '@metamask/controller-utils';\nimport { abiERC20 } from '@metamask/metamask-eth-abis';\nimport { providerErrors, rpcErrors } from '@metamask/rpc-errors';\n\nimport { TransactionEnvelopeType, type TransactionParams } from '../types';\nimport { isEIP1559Transaction } from './utils';\n\ntype GasFieldsToValidate = 'gasPrice' | 'maxFeePerGas' | 'maxPriorityFeePerGas';\n\n/**\n * Validates whether a transaction initiated by a specific 'from' address is permitted by the origin.\n *\n * @param permittedAddresses - The permitted accounts for the given origin.\n * @param selectedAddress - The currently selected Ethereum address in the wallet.\n * @param from - The address from which the transaction is initiated.\n * @param origin - The origin or source of the transaction.\n * @throws Throws an error if the transaction is not permitted.\n */\nexport async function validateTransactionOrigin(\n permittedAddresses: string[],\n selectedAddress: string,\n from: string,\n origin: string,\n) {\n if (origin === ORIGIN_METAMASK) {\n // Ensure the 'from' address matches the currently selected address\n if (from !== selectedAddress) {\n throw rpcErrors.internal({\n message: `Internally initiated transaction is using invalid account.`,\n data: {\n origin,\n fromAddress: from,\n selectedAddress,\n },\n });\n }\n return;\n }\n\n // Check if the origin has permissions to initiate transactions from the specified address\n if (!permittedAddresses.includes(from)) {\n throw providerErrors.unauthorized({ data: { origin } });\n }\n}\n\n/**\n * Validates the transaction params for required properties and throws in\n * the event of any validation error.\n *\n * @param txParams - Transaction params object to validate.\n * @param isEIP1559Compatible - whether or not the current network supports EIP-1559 transactions.\n */\nexport function validateTxParams(\n txParams: TransactionParams,\n isEIP1559Compatible = true,\n) {\n validateEnvelopeType(txParams.type);\n validateEIP1559Compatibility(txParams, isEIP1559Compatible);\n validateParamFrom(txParams.from);\n validateParamRecipient(txParams);\n validateParamValue(txParams.value);\n validateParamData(txParams.data);\n validateParamChainId(txParams.chainId);\n validateGasFeeParams(txParams);\n}\n\n/**\n * Validates the `type` property, ensuring that if it is specified, it is a valid transaction envelope type.\n *\n * @param type - The transaction envelope type to validate.\n * @throws Throws invalid params if the type is not a valid transaction envelope type.\n */\nfunction validateEnvelopeType(type: string | undefined) {\n if (\n type &&\n !Object.values(TransactionEnvelopeType).includes(\n type as TransactionEnvelopeType,\n )\n ) {\n throw rpcErrors.invalidParams(\n `Invalid transaction envelope type: \"${type}\". Must be one of: ${Object.values(\n TransactionEnvelopeType,\n ).join(', ')}`,\n );\n }\n}\n\n/**\n * Validates EIP-1559 compatibility for transaction creation.\n *\n * @param txParams - The transaction parameters to validate.\n * @param isEIP1559Compatible - Indicates if the current network supports EIP-1559.\n * @throws Throws invalid params if the transaction specifies EIP-1559 but the network does not support it.\n */\nfunction validateEIP1559Compatibility(\n txParams: TransactionParams,\n isEIP1559Compatible: boolean,\n) {\n if (isEIP1559Transaction(txParams) && !isEIP1559Compatible) {\n throw rpcErrors.invalidParams(\n 'Invalid transaction params: params specify an EIP-1559 transaction but the current network does not support EIP-1559',\n );\n }\n}\n\n/**\n * Validates value property, ensuring it is a valid positive integer number\n * denominated in wei.\n *\n * @param value - The value to validate, expressed as a string.\n * @throws Throws an error if the value is not a valid positive integer\n * number denominated in wei.\n * - If the value contains a hyphen (-), it is considered invalid.\n * - If the value contains a decimal point (.), it is considered invalid.\n * - If the value is not a finite number, is NaN, or is not a safe integer, it is considered invalid.\n */\nfunction validateParamValue(value?: string) {\n if (value !== undefined) {\n if (value.includes('-')) {\n throw rpcErrors.invalidParams(\n `Invalid transaction value \"${value}\": not a positive number.`,\n );\n }\n\n if (value.includes('.')) {\n throw rpcErrors.invalidParams(\n `Invalid transaction value \"${value}\": number must be in wei.`,\n );\n }\n const intValue = parseInt(value, 10);\n const isValid =\n Number.isFinite(intValue) &&\n !Number.isNaN(intValue) &&\n !isNaN(Number(value)) &&\n Number.isSafeInteger(intValue);\n if (!isValid) {\n throw rpcErrors.invalidParams(\n `Invalid transaction value ${value}: number must be a valid number.`,\n );\n }\n }\n}\n\n/**\n * Validates the recipient address in a transaction's parameters.\n *\n * @param txParams - The transaction parameters object to validate.\n * @throws Throws an error if the recipient address is invalid:\n * - If the recipient address is an empty string ('0x') or undefined and the transaction contains data,\n * the \"to\" field is removed from the transaction parameters.\n * - If the recipient address is not a valid hexadecimal Ethereum address, an error is thrown.\n */\nfunction validateParamRecipient(txParams: TransactionParams) {\n if (txParams.to === '0x' || txParams.to === undefined) {\n if (txParams.data) {\n delete txParams.to;\n } else {\n throw rpcErrors.invalidParams(`Invalid \"to\" address.`);\n }\n } else if (txParams.to !== undefined && !isValidHexAddress(txParams.to)) {\n throw rpcErrors.invalidParams(`Invalid \"to\" address.`);\n }\n}\n\n/**\n * Validates the recipient address in a transaction's parameters.\n *\n * @param from - The from property to validate.\n * @throws Throws an error if the recipient address is invalid:\n * - If the recipient address is an empty string ('0x') or undefined and the transaction contains data,\n * the \"to\" field is removed from the transaction parameters.\n * - If the recipient address is not a valid hexadecimal Ethereum address, an error is thrown.\n */\nfunction validateParamFrom(from: string) {\n if (!from || typeof from !== 'string') {\n throw rpcErrors.invalidParams(\n `Invalid \"from\" address ${from}: not a string.`,\n );\n }\n if (!isValidHexAddress(from)) {\n throw rpcErrors.invalidParams('Invalid \"from\" address.');\n }\n}\n\n/**\n * Validates input data for transactions.\n *\n * @param value - The input data to validate.\n * @throws Throws invalid params if the input data is invalid.\n */\nfunction validateParamData(value?: string) {\n if (value) {\n const ERC20Interface = new Interface(abiERC20);\n try {\n ERC20Interface.parseTransaction({ data: value });\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n if (error.message.match(/BUFFER_OVERRUN/u)) {\n throw rpcErrors.invalidParams(\n 'Invalid transaction params: data out-of-bounds, BUFFER_OVERRUN.',\n );\n }\n }\n }\n}\n\n/**\n * Validates chainId type.\n *\n * @param chainId - The chainId to validate.\n */\nfunction validateParamChainId(chainId: number | string | undefined) {\n if (\n chainId !== undefined &&\n typeof chainId !== 'number' &&\n typeof chainId !== 'string'\n ) {\n throw rpcErrors.invalidParams(\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n `Invalid transaction params: chainId is not a Number or hex string. got: (${chainId})`,\n );\n }\n}\n\n/**\n * Validates gas values.\n *\n * @param txParams - The transaction parameters to validate.\n */\nfunction validateGasFeeParams(txParams: TransactionParams) {\n if (txParams.gasPrice) {\n ensureProperTransactionEnvelopeTypeProvided(txParams, 'gasPrice');\n ensureMutuallyExclusiveFieldsNotProvided(\n txParams,\n 'gasPrice',\n 'maxFeePerGas',\n );\n ensureMutuallyExclusiveFieldsNotProvided(\n txParams,\n 'gasPrice',\n 'maxPriorityFeePerGas',\n );\n ensureFieldIsString(txParams, 'gasPrice');\n }\n\n if (txParams.maxFeePerGas) {\n ensureProperTransactionEnvelopeTypeProvided(txParams, 'maxFeePerGas');\n ensureMutuallyExclusiveFieldsNotProvided(\n txParams,\n 'maxFeePerGas',\n 'gasPrice',\n );\n ensureFieldIsString(txParams, 'maxFeePerGas');\n }\n\n if (txParams.maxPriorityFeePerGas) {\n ensureProperTransactionEnvelopeTypeProvided(\n txParams,\n 'maxPriorityFeePerGas',\n );\n ensureMutuallyExclusiveFieldsNotProvided(\n txParams,\n 'maxPriorityFeePerGas',\n 'gasPrice',\n );\n ensureFieldIsString(txParams, 'maxPriorityFeePerGas');\n }\n}\n\n/**\n * Ensures that the provided txParams has the proper 'type' specified for the\n * given field, if it is provided. If types do not match throws an\n * invalidParams error.\n *\n * @param txParams - The transaction parameters object\n * @param field - The current field being validated\n * @throws {ethErrors.rpc.invalidParams} Throws if type does not match the\n * expectations for provided field.\n */\nfunction ensureProperTransactionEnvelopeTypeProvided(\n txParams: TransactionParams,\n field: GasFieldsToValidate,\n) {\n switch (field) {\n case 'maxFeePerGas':\n case 'maxPriorityFeePerGas':\n if (\n txParams.type &&\n txParams.type !== TransactionEnvelopeType.feeMarket\n ) {\n throw rpcErrors.invalidParams(\n `Invalid transaction envelope type: specified type \"${txParams.type}\" but including maxFeePerGas and maxPriorityFeePerGas requires type: \"${TransactionEnvelopeType.feeMarket}\"`,\n );\n }\n break;\n case 'gasPrice':\n default:\n if (\n txParams.type &&\n txParams.type === TransactionEnvelopeType.feeMarket\n ) {\n throw rpcErrors.invalidParams(\n `Invalid transaction envelope type: specified type \"${txParams.type}\" but included a gasPrice instead of maxFeePerGas and maxPriorityFeePerGas`,\n );\n }\n }\n}\n\n/**\n * Given two fields, ensure that the second field is not included in txParams,\n * and if it is throw an invalidParams error.\n *\n * @param txParams - The transaction parameters object\n * @param fieldBeingValidated - The current field being validated\n * @param mutuallyExclusiveField - The field to ensure is not provided\n * @throws {ethErrors.rpc.invalidParams} Throws if mutuallyExclusiveField is\n * present in txParams.\n */\nfunction ensureMutuallyExclusiveFieldsNotProvided(\n txParams: TransactionParams,\n fieldBeingValidated: GasFieldsToValidate,\n mutuallyExclusiveField: GasFieldsToValidate,\n) {\n if (typeof txParams[mutuallyExclusiveField] !== 'undefined') {\n throw rpcErrors.invalidParams(\n `Invalid transaction params: specified ${fieldBeingValidated} but also included ${mutuallyExclusiveField}, these cannot be mixed`,\n );\n }\n}\n\n/**\n * Ensures that the provided value for field is a string, throws an\n * invalidParams error if field is not a string.\n *\n * @param txParams - The transaction parameters object\n * @param field - The current field being validated\n * @throws {rpcErrors.invalidParams} Throws if field is not a string\n */\nfunction ensureFieldIsString(\n txParams: TransactionParams,\n field: GasFieldsToValidate,\n) {\n if (typeof txParams[field] !== 'string') {\n throw rpcErrors.invalidParams(\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n `Invalid transaction params: ${field} is not a string. got: (${txParams[field]})`,\n );\n }\n}\n"]}
@@ -3,7 +3,7 @@
3
3
  var _chunk2XKEAKQGjs = require('./chunk-2XKEAKQG.js');
4
4
 
5
5
 
6
- var _chunk76FONEDAjs = require('./chunk-76FONEDA.js');
6
+ var _chunkYWLMT7XHjs = require('./chunk-YWLMT7XH.js');
7
7
 
8
8
 
9
9
  var _chunkS6VGOPUYjs = require('./chunk-S6VGOPUY.js');
@@ -148,7 +148,7 @@ _updateTransactionGasFeeEstimates = new WeakSet();
148
148
  updateTransactionGasFeeEstimates_fn = async function(transactionMeta, gasFeeControllerData) {
149
149
  const { chainId, networkClientId } = transactionMeta;
150
150
  const ethQuery = new (0, _ethquery2.default)(_chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _getProvider).call(this, chainId, networkClientId));
151
- const gasFeeFlow = _chunk76FONEDAjs.getGasFeeFlow.call(void 0, transactionMeta, _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _gasFeeFlows));
151
+ const gasFeeFlow = _chunkYWLMT7XHjs.getGasFeeFlow.call(void 0, transactionMeta, _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _gasFeeFlows));
152
152
  if (gasFeeFlow) {
153
153
  log(
154
154
  "Found gas fee flow",
@@ -225,4 +225,4 @@ getGasFeeControllerData_fn = async function(transactions) {
225
225
 
226
226
 
227
227
  exports.GasFeePoller = GasFeePoller;
228
- //# sourceMappingURL=chunk-2EU6346V.js.map
228
+ //# sourceMappingURL=chunk-5HYWLTVQ.js.map
@@ -0,0 +1,68 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/utils/retry.ts
2
+ var _controllerutils = require('@metamask/controller-utils');
3
+ var _utils = require('@metamask/utils');
4
+ function getTransactionParamsWithIncreasedGasFee(originalTransactionParams, rate, newGasValues) {
5
+ const newGasPrice = getIncreasedGasPrice(
6
+ originalTransactionParams,
7
+ rate,
8
+ newGasValues
9
+ );
10
+ const new1559Values = getIncreased1559Values(
11
+ originalTransactionParams,
12
+ rate,
13
+ newGasValues
14
+ );
15
+ if (new1559Values) {
16
+ const newTxParams = {
17
+ ...originalTransactionParams,
18
+ ...new1559Values
19
+ };
20
+ delete newTxParams.gasPrice;
21
+ return newTxParams;
22
+ }
23
+ if (newGasPrice) {
24
+ const newTxParams = {
25
+ ...originalTransactionParams,
26
+ gasPrice: newGasPrice
27
+ };
28
+ delete newTxParams.maxFeePerGas;
29
+ delete newTxParams.maxPriorityFeePerGas;
30
+ return newTxParams;
31
+ }
32
+ throw new Error(
33
+ "Cannot increase gas fee as no current values and no new values were provided"
34
+ );
35
+ }
36
+ function getIncreased1559Values(originalTransactionParams, rate, newGasValues) {
37
+ if (newGasValues && "maxFeePerGas" in newGasValues && "maxPriorityFeePerGas" in newGasValues) {
38
+ return newGasValues;
39
+ }
40
+ const currentMaxFeePerGas = originalTransactionParams.maxFeePerGas;
41
+ const currentMaxPriorityFeePerGas = originalTransactionParams.maxPriorityFeePerGas;
42
+ if (!currentMaxFeePerGas || !currentMaxPriorityFeePerGas || currentMaxFeePerGas === "0x0" || currentMaxPriorityFeePerGas === "0x0") {
43
+ return void 0;
44
+ }
45
+ const maxFeePerGas = multiplyHex(currentMaxFeePerGas, rate);
46
+ const maxPriorityFeePerGas = multiplyHex(currentMaxPriorityFeePerGas, rate);
47
+ return { maxFeePerGas, maxPriorityFeePerGas };
48
+ }
49
+ function getIncreasedGasPrice(originalTransactionParams, rate, newGasValues) {
50
+ if (newGasValues && "gasPrice" in newGasValues) {
51
+ return newGasValues.gasPrice;
52
+ }
53
+ const currentGasPrice = originalTransactionParams.gasPrice;
54
+ if (!currentGasPrice || currentGasPrice === "0x0") {
55
+ return void 0;
56
+ }
57
+ return multiplyHex(currentGasPrice, rate);
58
+ }
59
+ function multiplyHex(value, multiplier) {
60
+ const decimalValue = _controllerutils.convertHexToDecimal.call(void 0, value);
61
+ const decimalResult = parseInt(`${decimalValue * multiplier}`, 10);
62
+ return _utils.add0x.call(void 0, decimalResult.toString(16));
63
+ }
64
+
65
+
66
+
67
+ exports.getTransactionParamsWithIncreasedGasFee = getTransactionParamsWithIncreasedGasFee;
68
+ //# sourceMappingURL=chunk-5QVDIVJH.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/retry.ts"],"names":[],"mappings":";AAAA,SAAS,2BAA2B;AAEpC,SAAS,aAAa;AAYf,SAAS,wCACd,2BACA,MACA,cACmB;AACnB,QAAM,cAAc;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,QAAM,gBAAgB;AAAA,IACpB;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,MAAI,eAAe;AACjB,UAAM,cAAiC;AAAA,MACrC,GAAG;AAAA,MACH,GAAG;AAAA,IACL;AAEA,WAAO,YAAY;AAEnB,WAAO;AAAA,EACT;AAEA,MAAI,aAAa;AACf,UAAM,cAAiC;AAAA,MACrC,GAAG;AAAA,MACH,UAAU;AAAA,IACZ;AAEA,WAAO,YAAY;AACnB,WAAO,YAAY;AAEnB,WAAO;AAAA,EACT;AAEA,QAAM,IAAI;AAAA,IACR;AAAA,EACF;AACF;AASA,SAAS,uBACP,2BACA,MACA,cACoC;AACpC,MACE,gBACA,kBAAkB,gBAClB,0BAA0B,cAC1B;AACA,WAAO;AAAA,EACT;AAEA,QAAM,sBAAsB,0BAA0B;AAItD,QAAM,8BACJ,0BAA0B;AAE5B,MACE,CAAC,uBACD,CAAC,+BACD,wBAAwB,SACxB,gCAAgC,OAChC;AACA,WAAO;AAAA,EACT;AAEA,QAAM,eAAe,YAAY,qBAAqB,IAAI;AAC1D,QAAM,uBAAuB,YAAY,6BAA6B,IAAI;AAE1E,SAAO,EAAE,cAAc,qBAAqB;AAC9C;AASA,SAAS,qBACP,2BACA,MACA,cACiB;AACjB,MAAI,gBAAgB,cAAc,cAAc;AAC9C,WAAO,aAAa;AAAA,EACtB;AAEA,QAAM,kBAAkB,0BAA0B;AAElD,MAAI,CAAC,mBAAmB,oBAAoB,OAAO;AACjD,WAAO;AAAA,EACT;AAEA,SAAO,YAAY,iBAAiB,IAAI;AAC1C;AAQA,SAAS,YAAY,OAAwB,YAAyB;AACpE,QAAM,eAAe,oBAAoB,KAAK;AAC9C,QAAM,gBAAgB,SAAS,GAAG,eAAe,UAAU,IAAI,EAAE;AAEjE,SAAO,MAAM,cAAc,SAAS,EAAE,CAAC;AACzC","sourcesContent":["import { convertHexToDecimal } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\nimport { add0x } from '@metamask/utils';\n\nimport type { FeeMarketEIP1559Values, GasPriceValue } from '../types';\nimport { type TransactionParams } from '../types';\n\n/**\n * Returns new transaction parameters with increased gas fees.\n * @param originalTransactionParams - The original transaction parameters.\n * @param rate - The rate by which to increase the existing gas fee properties.\n * @param newGasValues - Optional new gas values to use instead of increased the existing values.\n * @returns The new transaction parameters with the increased gas fee properties.\n */\nexport function getTransactionParamsWithIncreasedGasFee(\n originalTransactionParams: TransactionParams,\n rate: number,\n newGasValues?: GasPriceValue | FeeMarketEIP1559Values,\n): TransactionParams {\n const newGasPrice = getIncreasedGasPrice(\n originalTransactionParams,\n rate,\n newGasValues,\n );\n\n const new1559Values = getIncreased1559Values(\n originalTransactionParams,\n rate,\n newGasValues,\n );\n\n if (new1559Values) {\n const newTxParams: TransactionParams = {\n ...originalTransactionParams,\n ...new1559Values,\n };\n\n delete newTxParams.gasPrice;\n\n return newTxParams;\n }\n\n if (newGasPrice) {\n const newTxParams: TransactionParams = {\n ...originalTransactionParams,\n gasPrice: newGasPrice,\n };\n\n delete newTxParams.maxFeePerGas;\n delete newTxParams.maxPriorityFeePerGas;\n\n return newTxParams;\n }\n\n throw new Error(\n 'Cannot increase gas fee as no current values and no new values were provided',\n );\n}\n\n/**\n * Generate the increased EIP-1559 gas properties.\n * @param originalTransactionParams - The original transaction parameters.\n * @param rate - The rate by which to increase the existing gas fee properties.\n * @param newGasValues - Optional new gas values to use instead of increased the existing values.\n * @returns The new EIP-1559 gas properties.\n */\nfunction getIncreased1559Values(\n originalTransactionParams: TransactionParams,\n rate: number,\n newGasValues?: GasPriceValue | FeeMarketEIP1559Values,\n): FeeMarketEIP1559Values | undefined {\n if (\n newGasValues &&\n 'maxFeePerGas' in newGasValues &&\n 'maxPriorityFeePerGas' in newGasValues\n ) {\n return newGasValues;\n }\n\n const currentMaxFeePerGas = originalTransactionParams.maxFeePerGas as\n | Hex\n | undefined;\n\n const currentMaxPriorityFeePerGas =\n originalTransactionParams.maxPriorityFeePerGas as Hex | undefined;\n\n if (\n !currentMaxFeePerGas ||\n !currentMaxPriorityFeePerGas ||\n currentMaxFeePerGas === '0x0' ||\n currentMaxPriorityFeePerGas === '0x0'\n ) {\n return undefined;\n }\n\n const maxFeePerGas = multiplyHex(currentMaxFeePerGas, rate);\n const maxPriorityFeePerGas = multiplyHex(currentMaxPriorityFeePerGas, rate);\n\n return { maxFeePerGas, maxPriorityFeePerGas };\n}\n\n/**\n * Generate the increased gas price.\n * @param originalTransactionParams - The original transaction parameters.\n * @param rate - The rate by which to increase the existing gas fee properties.\n * @param newGasValues - Optional new gas values to use instead of increased the existing values.\n * @returns The new gas price.\n */\nfunction getIncreasedGasPrice(\n originalTransactionParams: TransactionParams,\n rate: number,\n newGasValues?: GasPriceValue | FeeMarketEIP1559Values,\n): Hex | undefined {\n if (newGasValues && 'gasPrice' in newGasValues) {\n return newGasValues.gasPrice as Hex;\n }\n\n const currentGasPrice = originalTransactionParams.gasPrice as Hex | undefined;\n\n if (!currentGasPrice || currentGasPrice === '0x0') {\n return undefined;\n }\n\n return multiplyHex(currentGasPrice, rate);\n}\n\n/**\n * Multiply a hex value by a multiplier.\n * @param value - The hex value to multiply.\n * @param multiplier - The multiplier.\n * @returns The multiplied hex value.\n */\nfunction multiplyHex(value: Hex | undefined, multiplier: number): Hex {\n const decimalValue = convertHexToDecimal(value);\n const decimalResult = parseInt(`${decimalValue * multiplier}`, 10);\n\n return add0x(decimalResult.toString(16));\n}\n"]}
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  gweiDecimalToWeiHex
3
- } from "./chunk-VXNPVIYL.mjs";
3
+ } from "./chunk-SFFOC25Q.mjs";
4
4
  import {
5
5
  projectLogger
6
6
  } from "./chunk-UQQWZT6C.mjs";
7
7
  import {
8
8
  GasFeeEstimateLevel
9
- } from "./chunk-6SJYXSF3.mjs";
9
+ } from "./chunk-LFFYCDHB.mjs";
10
10
  import {
11
11
  __privateAdd,
12
12
  __privateMethod
@@ -109,4 +109,4 @@ getLegacyLevel_fn = function(gasFeeEstimates, level) {
109
109
  export {
110
110
  DefaultGasFeeFlow
111
111
  };
112
- //# sourceMappingURL=chunk-H2KZOK3J.mjs.map
112
+ //# sourceMappingURL=chunk-AWIJZAW3.mjs.map
@@ -1,9 +1,9 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkQH2H4W3Njs = require('./chunk-QH2H4W3N.js');
3
+ var _chunkQKV7E5BOjs = require('./chunk-QKV7E5BO.js');
4
4
 
5
5
 
6
- var _chunk76FONEDAjs = require('./chunk-76FONEDA.js');
6
+ var _chunkYWLMT7XHjs = require('./chunk-YWLMT7XH.js');
7
7
 
8
8
 
9
9
  var _chunkS6VGOPUYjs = require('./chunk-S6VGOPUY.js');
@@ -20,7 +20,7 @@ var log = _utils.createModuleLogger.call(void 0, _chunkS6VGOPUYjs.projectLogger,
20
20
  async function updateGasFees(request) {
21
21
  const { txMeta } = request;
22
22
  const initialParams = { ...txMeta.txParams };
23
- const isSwap = _chunkQH2H4W3Njs.SWAP_TRANSACTION_TYPES.includes(
23
+ const isSwap = _chunkQKV7E5BOjs.SWAP_TRANSACTION_TYPES.includes(
24
24
  txMeta.type
25
25
  );
26
26
  const savedGasFees = isSwap ? void 0 : request.getSavedGasFees(txMeta.chainId);
@@ -186,7 +186,7 @@ async function getSuggestedGasFees(request) {
186
186
  if (!eip1559 && txMeta.txParams.gasPrice || eip1559 && txMeta.txParams.maxFeePerGas && txMeta.txParams.maxPriorityFeePerGas) {
187
187
  return {};
188
188
  }
189
- const gasFeeFlow = _chunk76FONEDAjs.getGasFeeFlow.call(void 0, txMeta, gasFeeFlows);
189
+ const gasFeeFlow = _chunkYWLMT7XHjs.getGasFeeFlow.call(void 0, txMeta, gasFeeFlows);
190
190
  try {
191
191
  const gasFeeControllerData = await getGasFeeEstimates({ networkClientId });
192
192
  const response = await gasFeeFlow.getGasFees({
@@ -223,4 +223,4 @@ async function getSuggestedGasFees(request) {
223
223
 
224
224
 
225
225
  exports.updateGasFees = updateGasFees; exports.gweiDecimalToWeiHex = gweiDecimalToWeiHex;
226
- //# sourceMappingURL=chunk-C3WC4OJ3.js.map
226
+ //# sourceMappingURL=chunk-BZV72SCF.js.map
@@ -1,12 +1,12 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkC3WC4OJ3js = require('./chunk-C3WC4OJ3.js');
3
+ var _chunkBZV72SCFjs = require('./chunk-BZV72SCF.js');
4
4
 
5
5
 
6
6
  var _chunkS6VGOPUYjs = require('./chunk-S6VGOPUY.js');
7
7
 
8
8
 
9
- var _chunkAYTU4HU5js = require('./chunk-AYTU4HU5.js');
9
+ var _chunkPSZ34BI5js = require('./chunk-PSZ34BI5.js');
10
10
 
11
11
 
12
12
 
@@ -55,7 +55,7 @@ var DefaultGasFeeFlow = class {
55
55
  };
56
56
  _getFeeMarkEstimates = new WeakSet();
57
57
  getFeeMarkEstimates_fn = function(gasFeeEstimates) {
58
- const levels = Object.values(_chunkAYTU4HU5js.GasFeeEstimateLevel).reduce(
58
+ const levels = Object.values(_chunkPSZ34BI5js.GasFeeEstimateLevel).reduce(
59
59
  (result, level) => ({
60
60
  ...result,
61
61
  [level]: _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getFeeMarketLevel, getFeeMarketLevel_fn).call(this, gasFeeEstimates, level)
@@ -69,7 +69,7 @@ getFeeMarkEstimates_fn = function(gasFeeEstimates) {
69
69
  };
70
70
  _getLegacyEstimates = new WeakSet();
71
71
  getLegacyEstimates_fn = function(gasFeeEstimates) {
72
- const levels = Object.values(_chunkAYTU4HU5js.GasFeeEstimateLevel).reduce(
72
+ const levels = Object.values(_chunkPSZ34BI5js.GasFeeEstimateLevel).reduce(
73
73
  (result, level) => ({
74
74
  ...result,
75
75
  [level]: _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getLegacyLevel, getLegacyLevel_fn).call(this, gasFeeEstimates, level)
@@ -85,15 +85,15 @@ _getGasPriceEstimates = new WeakSet();
85
85
  getGasPriceEstimates_fn = function(gasFeeEstimates) {
86
86
  return {
87
87
  type: "eth_gasPrice" /* GasPrice */,
88
- gasPrice: _chunkC3WC4OJ3js.gweiDecimalToWeiHex.call(void 0, gasFeeEstimates.gasPrice)
88
+ gasPrice: _chunkBZV72SCFjs.gweiDecimalToWeiHex.call(void 0, gasFeeEstimates.gasPrice)
89
89
  };
90
90
  };
91
91
  _getFeeMarketLevel = new WeakSet();
92
92
  getFeeMarketLevel_fn = function(gasFeeEstimates, level) {
93
- const maxFeePerGas = _chunkC3WC4OJ3js.gweiDecimalToWeiHex.call(void 0,
93
+ const maxFeePerGas = _chunkBZV72SCFjs.gweiDecimalToWeiHex.call(void 0,
94
94
  gasFeeEstimates[level].suggestedMaxFeePerGas
95
95
  );
96
- const maxPriorityFeePerGas = _chunkC3WC4OJ3js.gweiDecimalToWeiHex.call(void 0,
96
+ const maxPriorityFeePerGas = _chunkBZV72SCFjs.gweiDecimalToWeiHex.call(void 0,
97
97
  gasFeeEstimates[level].suggestedMaxPriorityFeePerGas
98
98
  );
99
99
  return {
@@ -103,10 +103,10 @@ getFeeMarketLevel_fn = function(gasFeeEstimates, level) {
103
103
  };
104
104
  _getLegacyLevel = new WeakSet();
105
105
  getLegacyLevel_fn = function(gasFeeEstimates, level) {
106
- return _chunkC3WC4OJ3js.gweiDecimalToWeiHex.call(void 0, gasFeeEstimates[level]);
106
+ return _chunkBZV72SCFjs.gweiDecimalToWeiHex.call(void 0, gasFeeEstimates[level]);
107
107
  };
108
108
 
109
109
 
110
110
 
111
111
  exports.DefaultGasFeeFlow = DefaultGasFeeFlow;
112
- //# sourceMappingURL=chunk-QTKXIDGE.js.map
112
+ //# sourceMappingURL=chunk-EHWAY6XU.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  validateIfTransactionUnapproved
3
- } from "./chunk-Q56I5ONX.mjs";
3
+ } from "./chunk-UHSRHP55.mjs";
4
4
  import {
5
5
  CHAIN_IDS
6
6
  } from "./chunk-O6ZZVIFH.mjs";
@@ -254,4 +254,4 @@ export {
254
254
  updateSwapsTransaction,
255
255
  updatePostTransactionBalance
256
256
  };
257
- //# sourceMappingURL=chunk-GNAL5HC2.mjs.map
257
+ //# sourceMappingURL=chunk-JIFPK37W.mjs.map
@@ -0,0 +1,68 @@
1
+ // src/utils/retry.ts
2
+ import { convertHexToDecimal } from "@metamask/controller-utils";
3
+ import { add0x } from "@metamask/utils";
4
+ function getTransactionParamsWithIncreasedGasFee(originalTransactionParams, rate, newGasValues) {
5
+ const newGasPrice = getIncreasedGasPrice(
6
+ originalTransactionParams,
7
+ rate,
8
+ newGasValues
9
+ );
10
+ const new1559Values = getIncreased1559Values(
11
+ originalTransactionParams,
12
+ rate,
13
+ newGasValues
14
+ );
15
+ if (new1559Values) {
16
+ const newTxParams = {
17
+ ...originalTransactionParams,
18
+ ...new1559Values
19
+ };
20
+ delete newTxParams.gasPrice;
21
+ return newTxParams;
22
+ }
23
+ if (newGasPrice) {
24
+ const newTxParams = {
25
+ ...originalTransactionParams,
26
+ gasPrice: newGasPrice
27
+ };
28
+ delete newTxParams.maxFeePerGas;
29
+ delete newTxParams.maxPriorityFeePerGas;
30
+ return newTxParams;
31
+ }
32
+ throw new Error(
33
+ "Cannot increase gas fee as no current values and no new values were provided"
34
+ );
35
+ }
36
+ function getIncreased1559Values(originalTransactionParams, rate, newGasValues) {
37
+ if (newGasValues && "maxFeePerGas" in newGasValues && "maxPriorityFeePerGas" in newGasValues) {
38
+ return newGasValues;
39
+ }
40
+ const currentMaxFeePerGas = originalTransactionParams.maxFeePerGas;
41
+ const currentMaxPriorityFeePerGas = originalTransactionParams.maxPriorityFeePerGas;
42
+ if (!currentMaxFeePerGas || !currentMaxPriorityFeePerGas || currentMaxFeePerGas === "0x0" || currentMaxPriorityFeePerGas === "0x0") {
43
+ return void 0;
44
+ }
45
+ const maxFeePerGas = multiplyHex(currentMaxFeePerGas, rate);
46
+ const maxPriorityFeePerGas = multiplyHex(currentMaxPriorityFeePerGas, rate);
47
+ return { maxFeePerGas, maxPriorityFeePerGas };
48
+ }
49
+ function getIncreasedGasPrice(originalTransactionParams, rate, newGasValues) {
50
+ if (newGasValues && "gasPrice" in newGasValues) {
51
+ return newGasValues.gasPrice;
52
+ }
53
+ const currentGasPrice = originalTransactionParams.gasPrice;
54
+ if (!currentGasPrice || currentGasPrice === "0x0") {
55
+ return void 0;
56
+ }
57
+ return multiplyHex(currentGasPrice, rate);
58
+ }
59
+ function multiplyHex(value, multiplier) {
60
+ const decimalValue = convertHexToDecimal(value);
61
+ const decimalResult = parseInt(`${decimalValue * multiplier}`, 10);
62
+ return add0x(decimalResult.toString(16));
63
+ }
64
+
65
+ export {
66
+ getTransactionParamsWithIncreasedGasFee
67
+ };
68
+ //# sourceMappingURL=chunk-JOQK7A5G.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/retry.ts"],"sourcesContent":["import { convertHexToDecimal } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\nimport { add0x } from '@metamask/utils';\n\nimport type { FeeMarketEIP1559Values, GasPriceValue } from '../types';\nimport { type TransactionParams } from '../types';\n\n/**\n * Returns new transaction parameters with increased gas fees.\n * @param originalTransactionParams - The original transaction parameters.\n * @param rate - The rate by which to increase the existing gas fee properties.\n * @param newGasValues - Optional new gas values to use instead of increased the existing values.\n * @returns The new transaction parameters with the increased gas fee properties.\n */\nexport function getTransactionParamsWithIncreasedGasFee(\n originalTransactionParams: TransactionParams,\n rate: number,\n newGasValues?: GasPriceValue | FeeMarketEIP1559Values,\n): TransactionParams {\n const newGasPrice = getIncreasedGasPrice(\n originalTransactionParams,\n rate,\n newGasValues,\n );\n\n const new1559Values = getIncreased1559Values(\n originalTransactionParams,\n rate,\n newGasValues,\n );\n\n if (new1559Values) {\n const newTxParams: TransactionParams = {\n ...originalTransactionParams,\n ...new1559Values,\n };\n\n delete newTxParams.gasPrice;\n\n return newTxParams;\n }\n\n if (newGasPrice) {\n const newTxParams: TransactionParams = {\n ...originalTransactionParams,\n gasPrice: newGasPrice,\n };\n\n delete newTxParams.maxFeePerGas;\n delete newTxParams.maxPriorityFeePerGas;\n\n return newTxParams;\n }\n\n throw new Error(\n 'Cannot increase gas fee as no current values and no new values were provided',\n );\n}\n\n/**\n * Generate the increased EIP-1559 gas properties.\n * @param originalTransactionParams - The original transaction parameters.\n * @param rate - The rate by which to increase the existing gas fee properties.\n * @param newGasValues - Optional new gas values to use instead of increased the existing values.\n * @returns The new EIP-1559 gas properties.\n */\nfunction getIncreased1559Values(\n originalTransactionParams: TransactionParams,\n rate: number,\n newGasValues?: GasPriceValue | FeeMarketEIP1559Values,\n): FeeMarketEIP1559Values | undefined {\n if (\n newGasValues &&\n 'maxFeePerGas' in newGasValues &&\n 'maxPriorityFeePerGas' in newGasValues\n ) {\n return newGasValues;\n }\n\n const currentMaxFeePerGas = originalTransactionParams.maxFeePerGas as\n | Hex\n | undefined;\n\n const currentMaxPriorityFeePerGas =\n originalTransactionParams.maxPriorityFeePerGas as Hex | undefined;\n\n if (\n !currentMaxFeePerGas ||\n !currentMaxPriorityFeePerGas ||\n currentMaxFeePerGas === '0x0' ||\n currentMaxPriorityFeePerGas === '0x0'\n ) {\n return undefined;\n }\n\n const maxFeePerGas = multiplyHex(currentMaxFeePerGas, rate);\n const maxPriorityFeePerGas = multiplyHex(currentMaxPriorityFeePerGas, rate);\n\n return { maxFeePerGas, maxPriorityFeePerGas };\n}\n\n/**\n * Generate the increased gas price.\n * @param originalTransactionParams - The original transaction parameters.\n * @param rate - The rate by which to increase the existing gas fee properties.\n * @param newGasValues - Optional new gas values to use instead of increased the existing values.\n * @returns The new gas price.\n */\nfunction getIncreasedGasPrice(\n originalTransactionParams: TransactionParams,\n rate: number,\n newGasValues?: GasPriceValue | FeeMarketEIP1559Values,\n): Hex | undefined {\n if (newGasValues && 'gasPrice' in newGasValues) {\n return newGasValues.gasPrice as Hex;\n }\n\n const currentGasPrice = originalTransactionParams.gasPrice as Hex | undefined;\n\n if (!currentGasPrice || currentGasPrice === '0x0') {\n return undefined;\n }\n\n return multiplyHex(currentGasPrice, rate);\n}\n\n/**\n * Multiply a hex value by a multiplier.\n * @param value - The hex value to multiply.\n * @param multiplier - The multiplier.\n * @returns The multiplied hex value.\n */\nfunction multiplyHex(value: Hex | undefined, multiplier: number): Hex {\n const decimalValue = convertHexToDecimal(value);\n const decimalResult = parseInt(`${decimalValue * multiplier}`, 10);\n\n return add0x(decimalResult.toString(16));\n}\n"],"mappings":";AAAA,SAAS,2BAA2B;AAEpC,SAAS,aAAa;AAYf,SAAS,wCACd,2BACA,MACA,cACmB;AACnB,QAAM,cAAc;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,QAAM,gBAAgB;AAAA,IACpB;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,MAAI,eAAe;AACjB,UAAM,cAAiC;AAAA,MACrC,GAAG;AAAA,MACH,GAAG;AAAA,IACL;AAEA,WAAO,YAAY;AAEnB,WAAO;AAAA,EACT;AAEA,MAAI,aAAa;AACf,UAAM,cAAiC;AAAA,MACrC,GAAG;AAAA,MACH,UAAU;AAAA,IACZ;AAEA,WAAO,YAAY;AACnB,WAAO,YAAY;AAEnB,WAAO;AAAA,EACT;AAEA,QAAM,IAAI;AAAA,IACR;AAAA,EACF;AACF;AASA,SAAS,uBACP,2BACA,MACA,cACoC;AACpC,MACE,gBACA,kBAAkB,gBAClB,0BAA0B,cAC1B;AACA,WAAO;AAAA,EACT;AAEA,QAAM,sBAAsB,0BAA0B;AAItD,QAAM,8BACJ,0BAA0B;AAE5B,MACE,CAAC,uBACD,CAAC,+BACD,wBAAwB,SACxB,gCAAgC,OAChC;AACA,WAAO;AAAA,EACT;AAEA,QAAM,eAAe,YAAY,qBAAqB,IAAI;AAC1D,QAAM,uBAAuB,YAAY,6BAA6B,IAAI;AAE1E,SAAO,EAAE,cAAc,qBAAqB;AAC9C;AASA,SAAS,qBACP,2BACA,MACA,cACiB;AACjB,MAAI,gBAAgB,cAAc,cAAc;AAC9C,WAAO,aAAa;AAAA,EACtB;AAEA,QAAM,kBAAkB,0BAA0B;AAElD,MAAI,CAAC,mBAAmB,oBAAoB,OAAO;AACjD,WAAO;AAAA,EACT;AAEA,SAAO,YAAY,iBAAiB,IAAI;AAC1C;AAQA,SAAS,YAAY,OAAwB,YAAyB;AACpE,QAAM,eAAe,oBAAoB,KAAK;AAC9C,QAAM,gBAAgB,SAAS,GAAG,eAAe,UAAU,IAAI,EAAE;AAEjE,SAAO,MAAM,cAAc,SAAS,EAAE,CAAC;AACzC;","names":[]}
@@ -1,5 +1,4 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/utils/utils.ts
2
- var _controllerutils = require('@metamask/controller-utils');
3
2
 
4
3
 
5
4
 
@@ -48,21 +47,6 @@ var validateGasValues = (gasValues) => {
48
47
  }
49
48
  });
50
49
  };
51
- var isFeeMarketEIP1559Values = (gasValues) => gasValues?.maxFeePerGas !== void 0 || gasValues?.maxPriorityFeePerGas !== void 0;
52
- var isGasPriceValue = (gasValues) => gasValues?.gasPrice !== void 0;
53
- var getIncreasedPriceHex = (value, rate) => _utils.add0x.call(void 0, `${parseInt(`${value * rate}`, 10).toString(16)}`);
54
- var getIncreasedPriceFromExisting = (value, rate) => {
55
- return getIncreasedPriceHex(_controllerutils.convertHexToDecimal.call(void 0, value), rate);
56
- };
57
- function validateMinimumIncrease(proposed, min) {
58
- const proposedDecimal = _controllerutils.convertHexToDecimal.call(void 0, proposed);
59
- const minDecimal = _controllerutils.convertHexToDecimal.call(void 0, min);
60
- if (proposedDecimal >= minDecimal) {
61
- return proposed;
62
- }
63
- const errorMsg = `The proposed value: ${proposedDecimal} should meet or exceed the minimum value: ${minDecimal}`;
64
- throw new Error(errorMsg);
65
- }
66
50
  function validateIfTransactionUnapproved(transactionMeta, fnName) {
67
51
  if (transactionMeta?.status !== "unapproved" /* unapproved */) {
68
52
  throw new Error(
@@ -118,10 +102,5 @@ function padHexToEvenLength(hex) {
118
102
 
119
103
 
120
104
 
121
-
122
-
123
-
124
-
125
-
126
- exports.ESTIMATE_GAS_ERROR = ESTIMATE_GAS_ERROR; exports.normalizeTransactionParams = normalizeTransactionParams; exports.isEIP1559Transaction = isEIP1559Transaction; exports.validateGasValues = validateGasValues; exports.isFeeMarketEIP1559Values = isFeeMarketEIP1559Values; exports.isGasPriceValue = isGasPriceValue; exports.getIncreasedPriceHex = getIncreasedPriceHex; exports.getIncreasedPriceFromExisting = getIncreasedPriceFromExisting; exports.validateMinimumIncrease = validateMinimumIncrease; exports.validateIfTransactionUnapproved = validateIfTransactionUnapproved; exports.normalizeTxError = normalizeTxError; exports.normalizeGasFeeValues = normalizeGasFeeValues; exports.padHexToEvenLength = padHexToEvenLength;
127
- //# sourceMappingURL=chunk-OZ6UB42C.js.map
105
+ exports.ESTIMATE_GAS_ERROR = ESTIMATE_GAS_ERROR; exports.normalizeTransactionParams = normalizeTransactionParams; exports.isEIP1559Transaction = isEIP1559Transaction; exports.validateGasValues = validateGasValues; exports.validateIfTransactionUnapproved = validateIfTransactionUnapproved; exports.normalizeTxError = normalizeTxError; exports.normalizeGasFeeValues = normalizeGasFeeValues; exports.padHexToEvenLength = padHexToEvenLength;
106
+ //# sourceMappingURL=chunk-KTGMNUTQ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/utils.ts"],"names":[],"mappings":"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","sourcesContent":["import {\n add0x,\n getKnownPropertyNames,\n isStrictHexString,\n} from '@metamask/utils';\nimport type { Json } from '@metamask/utils';\n\nimport { TransactionStatus } from '../types';\nimport type {\n TransactionParams,\n TransactionMeta,\n TransactionError,\n GasPriceValue,\n FeeMarketEIP1559Values,\n} from '../types';\n\nexport const ESTIMATE_GAS_ERROR = 'eth_estimateGas rpc method error';\n\n// TODO: Replace `any` with type\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst NORMALIZERS: { [param in keyof TransactionParams]: any } = {\n data: (data: string) => add0x(padHexToEvenLength(data)),\n from: (from: string) => add0x(from).toLowerCase(),\n gas: (gas: string) => add0x(gas),\n gasLimit: (gas: string) => add0x(gas),\n gasPrice: (gasPrice: string) => add0x(gasPrice),\n nonce: (nonce: string) => add0x(nonce),\n to: (to: string) => add0x(to).toLowerCase(),\n value: (value: string) => add0x(value),\n maxFeePerGas: (maxFeePerGas: string) => add0x(maxFeePerGas),\n maxPriorityFeePerGas: (maxPriorityFeePerGas: string) =>\n add0x(maxPriorityFeePerGas),\n estimatedBaseFee: (maxPriorityFeePerGas: string) =>\n add0x(maxPriorityFeePerGas),\n type: (type: string) => add0x(type),\n};\n\n/**\n * Normalizes properties on transaction params.\n *\n * @param txParams - The transaction params to normalize.\n * @returns Normalized transaction params.\n */\nexport function normalizeTransactionParams(txParams: TransactionParams) {\n const normalizedTxParams: TransactionParams = { from: '' };\n\n for (const key of getKnownPropertyNames(NORMALIZERS)) {\n if (txParams[key]) {\n normalizedTxParams[key] = NORMALIZERS[key](txParams[key]);\n }\n }\n\n if (!normalizedTxParams.value) {\n normalizedTxParams.value = '0x0';\n }\n\n return normalizedTxParams;\n}\n\n/**\n * Checks if a transaction is EIP-1559 by checking for the existence of\n * maxFeePerGas and maxPriorityFeePerGas within its parameters.\n *\n * @param txParams - Transaction params object to add.\n * @returns Boolean that is true if the transaction is EIP-1559 (has maxFeePerGas and maxPriorityFeePerGas), otherwise returns false.\n */\nexport function isEIP1559Transaction(txParams: TransactionParams): boolean {\n const hasOwnProp = (obj: TransactionParams, key: string) =>\n Object.prototype.hasOwnProperty.call(obj, key);\n return (\n hasOwnProp(txParams, 'maxFeePerGas') &&\n hasOwnProp(txParams, 'maxPriorityFeePerGas')\n );\n}\n\nexport const validateGasValues = (\n gasValues: GasPriceValue | FeeMarketEIP1559Values,\n) => {\n Object.keys(gasValues).forEach((key) => {\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const value = (gasValues as any)[key];\n if (typeof value !== 'string' || !isStrictHexString(value)) {\n throw new TypeError(\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n `expected hex string for ${key} but received: ${value}`,\n );\n }\n });\n};\n\n/**\n * Validates that a transaction is unapproved.\n * Throws if the transaction is not unapproved.\n *\n * @param transactionMeta - The transaction metadata to check.\n * @param fnName - The name of the function calling this helper.\n */\nexport function validateIfTransactionUnapproved(\n transactionMeta: TransactionMeta | undefined,\n fnName: string,\n) {\n if (transactionMeta?.status !== TransactionStatus.unapproved) {\n throw new Error(\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n `TransactionsController: Can only call ${fnName} on an unapproved transaction.\\n Current tx status: ${transactionMeta?.status}`,\n );\n }\n}\n\n/**\n * Normalizes properties on transaction params.\n *\n * @param error - The error to be normalize.\n * @returns Normalized transaction error.\n */\nexport function normalizeTxError(\n error: Error & { code?: string; value?: unknown },\n): TransactionError {\n return {\n name: error.name,\n message: error.message,\n stack: error.stack,\n code: error.code,\n rpc: isJsonCompatible(error.value) ? error.value : undefined,\n };\n}\n\n/**\n * Normalize an object containing gas fee values.\n *\n * @param gasFeeValues - An object containing gas fee values.\n * @returns An object containing normalized gas fee values.\n */\nexport function normalizeGasFeeValues(\n gasFeeValues: GasPriceValue | FeeMarketEIP1559Values,\n): GasPriceValue | FeeMarketEIP1559Values {\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const normalize = (value: any) =>\n typeof value === 'string' ? add0x(value) : value;\n\n if ('gasPrice' in gasFeeValues) {\n return {\n gasPrice: normalize(gasFeeValues.gasPrice),\n };\n }\n\n return {\n maxFeePerGas: normalize(gasFeeValues.maxFeePerGas),\n maxPriorityFeePerGas: normalize(gasFeeValues.maxPriorityFeePerGas),\n };\n}\n\n/**\n * Determines whether the given value can be encoded as JSON.\n *\n * @param value - The value.\n * @returns True if the value is JSON-encodable, false if not.\n */\nfunction isJsonCompatible(value: unknown): value is Json {\n try {\n JSON.parse(JSON.stringify(value));\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Ensure a hex string is of even length by adding a leading 0 if necessary.\n * Any existing `0x` prefix is preserved but is not added if missing.\n *\n * @param hex - The hex string to ensure is even.\n * @returns The hex string with an even length.\n */\nexport function padHexToEvenLength(hex: string) {\n const prefix = hex.toLowerCase().startsWith('0x') ? hex.slice(0, 2) : '';\n const data = prefix ? hex.slice(2) : hex;\n const evenData = data.length % 2 === 0 ? data : `0${data}`;\n\n return prefix + evenData;\n}\n"]}
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  DefaultGasFeeFlow
3
- } from "./chunk-H2KZOK3J.mjs";
3
+ } from "./chunk-AWIJZAW3.mjs";
4
4
  import {
5
5
  projectLogger
6
6
  } from "./chunk-UQQWZT6C.mjs";
7
7
  import {
8
8
  GasFeeEstimateLevel
9
- } from "./chunk-6SJYXSF3.mjs";
9
+ } from "./chunk-LFFYCDHB.mjs";
10
10
  import {
11
11
  __privateAdd,
12
12
  __privateMethod
@@ -118,4 +118,4 @@ feesToString_fn = function(fees) {
118
118
  export {
119
119
  LineaGasFeeFlow
120
120
  };
121
- //# sourceMappingURL=chunk-UHG2LLVV.mjs.map
121
+ //# sourceMappingURL=chunk-KYRW4BLA.mjs.map