@metamask/transaction-controller 28.1.1 → 29.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/CHANGELOG.md +28 -1
  2. package/dist/TransactionController.js +11 -10
  3. package/dist/TransactionController.mjs +10 -9
  4. package/dist/{chunk-LDXTSESK.mjs → chunk-4M7FHI4S.mjs} +20 -4
  5. package/dist/chunk-4M7FHI4S.mjs.map +1 -0
  6. package/dist/{chunk-FK7AP6SH.js → chunk-5C3CSQAD.js} +12 -5
  7. package/dist/{chunk-YEJJKWT2.mjs.map → chunk-5C3CSQAD.js.map} +1 -1
  8. package/dist/{chunk-V6UIRCOF.js → chunk-7DJO6UZA.js} +48 -13
  9. package/dist/chunk-7DJO6UZA.js.map +1 -0
  10. package/dist/{chunk-HQAADNXH.mjs → chunk-7TPXSDXL.mjs} +120 -34
  11. package/dist/chunk-7TPXSDXL.mjs.map +1 -0
  12. package/dist/{chunk-TWND5SFD.mjs → chunk-AGJNOOBN.mjs} +17 -12
  13. package/dist/chunk-AGJNOOBN.mjs.map +1 -0
  14. package/dist/{chunk-LNX4JTOL.js → chunk-DUFOYA4D.js} +7 -7
  15. package/dist/chunk-DUFOYA4D.js.map +1 -0
  16. package/dist/{chunk-UH7FNVKS.js → chunk-EMDU4XLM.js} +19 -14
  17. package/dist/chunk-EMDU4XLM.js.map +1 -0
  18. package/dist/chunk-FMRLPVFZ.mjs +66 -0
  19. package/dist/chunk-FMRLPVFZ.mjs.map +1 -0
  20. package/dist/{chunk-EQNKFFTM.js → chunk-KNYSD4JP.js} +21 -5
  21. package/dist/chunk-KNYSD4JP.js.map +1 -0
  22. package/dist/{chunk-FMCTVRU2.js → chunk-N55SEKK7.js} +123 -37
  23. package/dist/chunk-N55SEKK7.js.map +1 -0
  24. package/dist/{chunk-YEJJKWT2.mjs → chunk-N6JXPWLY.mjs} +11 -4
  25. package/dist/chunk-N6JXPWLY.mjs.map +1 -0
  26. package/dist/chunk-REOG6YD4.mjs +112 -0
  27. package/dist/chunk-REOG6YD4.mjs.map +1 -0
  28. package/dist/{chunk-HHK4QSNF.mjs → chunk-SL3GHHKG.mjs} +47 -12
  29. package/dist/chunk-SL3GHHKG.mjs.map +1 -0
  30. package/dist/chunk-TJMQEH57.js +66 -0
  31. package/dist/chunk-TJMQEH57.js.map +1 -0
  32. package/dist/chunk-VJYFB7BM.js +112 -0
  33. package/dist/chunk-VJYFB7BM.js.map +1 -0
  34. package/dist/{chunk-NCRWKI6Y.mjs → chunk-XL3HBKDE.mjs} +4 -4
  35. package/dist/chunk-XL3HBKDE.mjs.map +1 -0
  36. package/dist/errors.js +1 -1
  37. package/dist/errors.mjs +1 -1
  38. package/dist/gas-flows/DefaultGasFeeFlow.js +5 -5
  39. package/dist/gas-flows/DefaultGasFeeFlow.mjs +4 -4
  40. package/dist/gas-flows/LineaGasFeeFlow.js +6 -6
  41. package/dist/gas-flows/LineaGasFeeFlow.mjs +5 -5
  42. package/dist/gas-flows/TestGasFeeFlow.js +9 -0
  43. package/dist/gas-flows/TestGasFeeFlow.js.map +1 -0
  44. package/dist/gas-flows/TestGasFeeFlow.mjs +9 -0
  45. package/dist/gas-flows/TestGasFeeFlow.mjs.map +1 -0
  46. package/dist/helpers/EtherscanRemoteTransactionSource.js +1 -1
  47. package/dist/helpers/EtherscanRemoteTransactionSource.mjs +1 -1
  48. package/dist/helpers/GasFeePoller.js +4 -4
  49. package/dist/helpers/GasFeePoller.mjs +3 -3
  50. package/dist/helpers/MultichainTrackingHelper.js +1 -1
  51. package/dist/helpers/MultichainTrackingHelper.mjs +1 -1
  52. package/dist/helpers/PendingTransactionTracker.js +1 -1
  53. package/dist/helpers/PendingTransactionTracker.mjs +1 -1
  54. package/dist/index.js +15 -10
  55. package/dist/index.mjs +14 -9
  56. package/dist/tsconfig.build.tsbuildinfo +1 -1
  57. package/dist/types/TransactionController.d.ts +12 -5
  58. package/dist/types/TransactionController.d.ts.map +1 -1
  59. package/dist/types/gas-flows/DefaultGasFeeFlow.d.ts.map +1 -1
  60. package/dist/types/gas-flows/TestGasFeeFlow.d.ts +12 -0
  61. package/dist/types/gas-flows/TestGasFeeFlow.d.ts.map +1 -0
  62. package/dist/types/helpers/GasFeePoller.d.ts +5 -3
  63. package/dist/types/helpers/GasFeePoller.d.ts.map +1 -1
  64. package/dist/types/index.d.ts +2 -2
  65. package/dist/types/index.d.ts.map +1 -1
  66. package/dist/types/types.d.ts +36 -18
  67. package/dist/types/types.d.ts.map +1 -1
  68. package/dist/types/utils/gas-flow.d.ts +8 -14
  69. package/dist/types/utils/gas-flow.d.ts.map +1 -1
  70. package/dist/types.js +4 -2
  71. package/dist/types.mjs +3 -1
  72. package/dist/utils/external-transactions.js +1 -1
  73. package/dist/utils/external-transactions.mjs +1 -1
  74. package/dist/utils/gas-fees.js +4 -4
  75. package/dist/utils/gas-fees.mjs +3 -3
  76. package/dist/utils/gas-flow.js +3 -3
  77. package/dist/utils/gas-flow.mjs +2 -2
  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 +1 -1
  83. package/dist/utils/swaps.mjs +1 -1
  84. package/dist/utils/transaction-type.js +1 -1
  85. package/dist/utils/transaction-type.mjs +1 -1
  86. package/dist/utils/utils.js +1 -1
  87. package/dist/utils/utils.mjs +1 -1
  88. package/dist/utils/validation.js +1 -1
  89. package/dist/utils/validation.mjs +1 -1
  90. package/package.json +4 -4
  91. package/dist/chunk-4RJXBKSR.js +0 -90
  92. package/dist/chunk-4RJXBKSR.js.map +0 -1
  93. package/dist/chunk-EQNKFFTM.js.map +0 -1
  94. package/dist/chunk-FK7AP6SH.js.map +0 -1
  95. package/dist/chunk-FMCTVRU2.js.map +0 -1
  96. package/dist/chunk-HHK4QSNF.mjs.map +0 -1
  97. package/dist/chunk-HQAADNXH.mjs.map +0 -1
  98. package/dist/chunk-LDXTSESK.mjs.map +0 -1
  99. package/dist/chunk-LNX4JTOL.js.map +0 -1
  100. package/dist/chunk-NCRWKI6Y.mjs.map +0 -1
  101. package/dist/chunk-NPEXNXSY.mjs +0 -90
  102. package/dist/chunk-NPEXNXSY.mjs.map +0 -1
  103. package/dist/chunk-TWND5SFD.mjs.map +0 -1
  104. package/dist/chunk-UH7FNVKS.js.map +0 -1
  105. package/dist/chunk-V6UIRCOF.js.map +0 -1
@@ -0,0 +1,112 @@
1
+ import {
2
+ gweiDecimalToWeiHex
3
+ } from "./chunk-4M7FHI4S.mjs";
4
+ import {
5
+ projectLogger
6
+ } from "./chunk-UQQWZT6C.mjs";
7
+ import {
8
+ GasFeeEstimateLevel
9
+ } from "./chunk-N6JXPWLY.mjs";
10
+ import {
11
+ __privateAdd,
12
+ __privateMethod
13
+ } from "./chunk-XUI43LEZ.mjs";
14
+
15
+ // src/gas-flows/DefaultGasFeeFlow.ts
16
+ import { GAS_ESTIMATE_TYPES } from "@metamask/gas-fee-controller";
17
+ import { createModuleLogger } from "@metamask/utils";
18
+ var log = createModuleLogger(projectLogger, "default-gas-fee-flow");
19
+ var _getFeeMarkEstimates, getFeeMarkEstimates_fn, _getLegacyEstimates, getLegacyEstimates_fn, _getGasPriceEstimates, getGasPriceEstimates_fn, _getFeeMarketLevel, getFeeMarketLevel_fn, _getLegacyLevel, getLegacyLevel_fn;
20
+ var DefaultGasFeeFlow = class {
21
+ constructor() {
22
+ __privateAdd(this, _getFeeMarkEstimates);
23
+ __privateAdd(this, _getLegacyEstimates);
24
+ __privateAdd(this, _getGasPriceEstimates);
25
+ __privateAdd(this, _getFeeMarketLevel);
26
+ __privateAdd(this, _getLegacyLevel);
27
+ }
28
+ matchesTransaction(_transactionMeta) {
29
+ return true;
30
+ }
31
+ async getGasFees(request) {
32
+ const { gasFeeControllerData } = request;
33
+ const { gasEstimateType, gasFeeEstimates } = gasFeeControllerData;
34
+ let response;
35
+ switch (gasEstimateType) {
36
+ case GAS_ESTIMATE_TYPES.FEE_MARKET:
37
+ log("Using fee market estimates", gasFeeEstimates);
38
+ response = __privateMethod(this, _getFeeMarkEstimates, getFeeMarkEstimates_fn).call(this, gasFeeEstimates);
39
+ break;
40
+ case GAS_ESTIMATE_TYPES.LEGACY:
41
+ log("Using legacy estimates", gasFeeEstimates);
42
+ response = __privateMethod(this, _getLegacyEstimates, getLegacyEstimates_fn).call(this, gasFeeEstimates);
43
+ break;
44
+ case GAS_ESTIMATE_TYPES.ETH_GASPRICE:
45
+ log("Using eth_gasPrice estimates", gasFeeEstimates);
46
+ response = __privateMethod(this, _getGasPriceEstimates, getGasPriceEstimates_fn).call(this, gasFeeEstimates);
47
+ break;
48
+ default:
49
+ throw new Error(`Unsupported gas estimate type: ${gasEstimateType}`);
50
+ }
51
+ return {
52
+ estimates: response
53
+ };
54
+ }
55
+ };
56
+ _getFeeMarkEstimates = new WeakSet();
57
+ getFeeMarkEstimates_fn = function(gasFeeEstimates) {
58
+ const levels = Object.values(GasFeeEstimateLevel).reduce(
59
+ (result, level) => ({
60
+ ...result,
61
+ [level]: __privateMethod(this, _getFeeMarketLevel, getFeeMarketLevel_fn).call(this, gasFeeEstimates, level)
62
+ }),
63
+ {}
64
+ );
65
+ return {
66
+ type: "fee-market" /* FeeMarket */,
67
+ ...levels
68
+ };
69
+ };
70
+ _getLegacyEstimates = new WeakSet();
71
+ getLegacyEstimates_fn = function(gasFeeEstimates) {
72
+ const levels = Object.values(GasFeeEstimateLevel).reduce(
73
+ (result, level) => ({
74
+ ...result,
75
+ [level]: __privateMethod(this, _getLegacyLevel, getLegacyLevel_fn).call(this, gasFeeEstimates, level)
76
+ }),
77
+ {}
78
+ );
79
+ return {
80
+ type: "legacy" /* Legacy */,
81
+ ...levels
82
+ };
83
+ };
84
+ _getGasPriceEstimates = new WeakSet();
85
+ getGasPriceEstimates_fn = function(gasFeeEstimates) {
86
+ return {
87
+ type: "eth_gasPrice" /* GasPrice */,
88
+ gasPrice: gweiDecimalToWeiHex(gasFeeEstimates.gasPrice)
89
+ };
90
+ };
91
+ _getFeeMarketLevel = new WeakSet();
92
+ getFeeMarketLevel_fn = function(gasFeeEstimates, level) {
93
+ const maxFeePerGas = gweiDecimalToWeiHex(
94
+ gasFeeEstimates[level].suggestedMaxFeePerGas
95
+ );
96
+ const maxPriorityFeePerGas = gweiDecimalToWeiHex(
97
+ gasFeeEstimates[level].suggestedMaxPriorityFeePerGas
98
+ );
99
+ return {
100
+ maxFeePerGas,
101
+ maxPriorityFeePerGas
102
+ };
103
+ };
104
+ _getLegacyLevel = new WeakSet();
105
+ getLegacyLevel_fn = function(gasFeeEstimates, level) {
106
+ return gweiDecimalToWeiHex(gasFeeEstimates[level]);
107
+ };
108
+
109
+ export {
110
+ DefaultGasFeeFlow
111
+ };
112
+ //# sourceMappingURL=chunk-REOG6YD4.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/gas-flows/DefaultGasFeeFlow.ts"],"sourcesContent":["import type {\n LegacyGasPriceEstimate,\n GasFeeEstimates as FeeMarketGasPriceEstimate,\n EthGasPriceEstimate,\n} from '@metamask/gas-fee-controller';\nimport { GAS_ESTIMATE_TYPES } from '@metamask/gas-fee-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\n\nimport { projectLogger } from '../logger';\nimport type {\n FeeMarketGasFeeEstimateForLevel,\n FeeMarketGasFeeEstimates,\n GasFeeEstimates,\n GasFeeFlow,\n GasFeeFlowRequest,\n GasFeeFlowResponse,\n GasPriceGasFeeEstimates,\n LegacyGasFeeEstimates,\n TransactionMeta,\n} from '../types';\nimport { GasFeeEstimateLevel, GasFeeEstimateType } from '../types';\nimport { gweiDecimalToWeiHex } from '../utils/gas-fees';\n\nconst log = createModuleLogger(projectLogger, 'default-gas-fee-flow');\n\n/**\n * The standard implementation of a gas fee flow that obtains gas fee estimates using only the GasFeeController.\n */\nexport class DefaultGasFeeFlow implements GasFeeFlow {\n matchesTransaction(_transactionMeta: TransactionMeta): boolean {\n return true;\n }\n\n async getGasFees(request: GasFeeFlowRequest): Promise<GasFeeFlowResponse> {\n const { gasFeeControllerData } = request;\n const { gasEstimateType, gasFeeEstimates } = gasFeeControllerData;\n\n let response: GasFeeEstimates;\n\n switch (gasEstimateType) {\n case GAS_ESTIMATE_TYPES.FEE_MARKET:\n log('Using fee market estimates', gasFeeEstimates);\n response = this.#getFeeMarkEstimates(gasFeeEstimates);\n break;\n case GAS_ESTIMATE_TYPES.LEGACY:\n log('Using legacy estimates', gasFeeEstimates);\n response = this.#getLegacyEstimates(\n gasFeeEstimates as LegacyGasPriceEstimate,\n );\n break;\n case GAS_ESTIMATE_TYPES.ETH_GASPRICE:\n log('Using eth_gasPrice estimates', gasFeeEstimates);\n response = this.#getGasPriceEstimates(\n gasFeeEstimates as EthGasPriceEstimate,\n );\n break;\n default:\n throw new Error(`Unsupported gas estimate type: ${gasEstimateType}`);\n }\n\n return {\n estimates: response,\n };\n }\n\n #getFeeMarkEstimates(\n gasFeeEstimates: FeeMarketGasPriceEstimate,\n ): FeeMarketGasFeeEstimates {\n const levels = Object.values(GasFeeEstimateLevel).reduce(\n (result, level) => ({\n ...result,\n [level]: this.#getFeeMarketLevel(gasFeeEstimates, level),\n }),\n {} as Omit<FeeMarketGasFeeEstimates, 'type'>,\n );\n\n return {\n type: GasFeeEstimateType.FeeMarket,\n ...levels,\n };\n }\n\n #getLegacyEstimates(\n gasFeeEstimates: LegacyGasPriceEstimate,\n ): LegacyGasFeeEstimates {\n const levels = Object.values(GasFeeEstimateLevel).reduce(\n (result, level) => ({\n ...result,\n [level]: this.#getLegacyLevel(gasFeeEstimates, level),\n }),\n {} as Omit<LegacyGasFeeEstimates, 'type'>,\n );\n\n return {\n type: GasFeeEstimateType.Legacy,\n ...levels,\n };\n }\n\n #getGasPriceEstimates(\n gasFeeEstimates: EthGasPriceEstimate,\n ): GasPriceGasFeeEstimates {\n return {\n type: GasFeeEstimateType.GasPrice,\n gasPrice: gweiDecimalToWeiHex(gasFeeEstimates.gasPrice),\n };\n }\n\n #getFeeMarketLevel(\n gasFeeEstimates: FeeMarketGasPriceEstimate,\n level: GasFeeEstimateLevel,\n ): FeeMarketGasFeeEstimateForLevel {\n const maxFeePerGas = gweiDecimalToWeiHex(\n gasFeeEstimates[level].suggestedMaxFeePerGas,\n );\n\n const maxPriorityFeePerGas = gweiDecimalToWeiHex(\n gasFeeEstimates[level].suggestedMaxPriorityFeePerGas,\n );\n\n return {\n maxFeePerGas,\n maxPriorityFeePerGas,\n };\n }\n\n #getLegacyLevel(\n gasFeeEstimates: LegacyGasPriceEstimate,\n level: GasFeeEstimateLevel,\n ): Hex {\n return gweiDecimalToWeiHex(gasFeeEstimates[level]);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAKA,SAAS,0BAA0B;AAEnC,SAAS,0BAA0B;AAiBnC,IAAM,MAAM,mBAAmB,eAAe,sBAAsB;AAxBpE;AA6BO,IAAM,oBAAN,MAA8C;AAAA,EAA9C;AAqCL;AAiBA;AAiBA;AASA;AAkBA;AAAA;AAAA,EAjGA,mBAAmB,kBAA4C;AAC7D,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,WAAW,SAAyD;AACxE,UAAM,EAAE,qBAAqB,IAAI;AACjC,UAAM,EAAE,iBAAiB,gBAAgB,IAAI;AAE7C,QAAI;AAEJ,YAAQ,iBAAiB;AAAA,MACvB,KAAK,mBAAmB;AACtB,YAAI,8BAA8B,eAAe;AACjD,mBAAW,sBAAK,8CAAL,WAA0B;AACrC;AAAA,MACF,KAAK,mBAAmB;AACtB,YAAI,0BAA0B,eAAe;AAC7C,mBAAW,sBAAK,4CAAL,WACT;AAEF;AAAA,MACF,KAAK,mBAAmB;AACtB,YAAI,gCAAgC,eAAe;AACnD,mBAAW,sBAAK,gDAAL,WACT;AAEF;AAAA,MACF;AACE,cAAM,IAAI,MAAM,kCAAkC,eAAe,EAAE;AAAA,IACvE;AAEA,WAAO;AAAA,MACL,WAAW;AAAA,IACb;AAAA,EACF;AAqEF;AAnEE;AAAA,yBAAoB,SAClB,iBAC0B;AAC1B,QAAM,SAAS,OAAO,OAAO,mBAAmB,EAAE;AAAA,IAChD,CAAC,QAAQ,WAAW;AAAA,MAClB,GAAG;AAAA,MACH,CAAC,KAAK,GAAG,sBAAK,0CAAL,WAAwB,iBAAiB;AAAA,IACpD;AAAA,IACA,CAAC;AAAA,EACH;AAEA,SAAO;AAAA,IACL;AAAA,IACA,GAAG;AAAA,EACL;AACF;AAEA;AAAA,wBAAmB,SACjB,iBACuB;AACvB,QAAM,SAAS,OAAO,OAAO,mBAAmB,EAAE;AAAA,IAChD,CAAC,QAAQ,WAAW;AAAA,MAClB,GAAG;AAAA,MACH,CAAC,KAAK,GAAG,sBAAK,oCAAL,WAAqB,iBAAiB;AAAA,IACjD;AAAA,IACA,CAAC;AAAA,EACH;AAEA,SAAO;AAAA,IACL;AAAA,IACA,GAAG;AAAA,EACL;AACF;AAEA;AAAA,0BAAqB,SACnB,iBACyB;AACzB,SAAO;AAAA,IACL;AAAA,IACA,UAAU,oBAAoB,gBAAgB,QAAQ;AAAA,EACxD;AACF;AAEA;AAAA,uBAAkB,SAChB,iBACA,OACiC;AACjC,QAAM,eAAe;AAAA,IACnB,gBAAgB,KAAK,EAAE;AAAA,EACzB;AAEA,QAAM,uBAAuB;AAAA,IAC3B,gBAAgB,KAAK,EAAE;AAAA,EACzB;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;AAEA;AAAA,oBAAe,SACb,iBACA,OACK;AACL,SAAO,oBAAoB,gBAAgB,KAAK,CAAC;AACnD;","names":[]}
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-NOHEXQ7Y.mjs";
4
4
  import {
5
5
  getGasFeeFlow
6
- } from "./chunk-TWND5SFD.mjs";
6
+ } from "./chunk-AGJNOOBN.mjs";
7
7
  import {
8
8
  projectLogger
9
9
  } from "./chunk-UQQWZT6C.mjs";
@@ -20,11 +20,12 @@ import { createModuleLogger } from "@metamask/utils";
20
20
  import EventEmitter from "events";
21
21
  var log = createModuleLogger(projectLogger, "gas-fee-poller");
22
22
  var INTERVAL_MILLISECONDS = 1e4;
23
- var _gasFeeFlows, _getGasFeeControllerEstimates, _getProvider, _getTransactions, _layer1GasFeeFlows, _timeout, _running, _start, start_fn, _stop, stop_fn, _onTimeout, onTimeout_fn, _updateUnapprovedTransactions, updateUnapprovedTransactions_fn, _updateUnapprovedTransaction, updateUnapprovedTransaction_fn, _updateTransactionGasFeeEstimates, updateTransactionGasFeeEstimates_fn, _updateTransactionLayer1GasFee, updateTransactionLayer1GasFee_fn, _getUnapprovedTransactions, getUnapprovedTransactions_fn;
23
+ var _findNetworkClientIdByChainId, _gasFeeFlows, _getGasFeeControllerEstimates, _getProvider, _getTransactions, _layer1GasFeeFlows, _timeout, _running, _start, start_fn, _stop, stop_fn, _onTimeout, onTimeout_fn, _updateUnapprovedTransactions, updateUnapprovedTransactions_fn, _updateUnapprovedTransaction, updateUnapprovedTransaction_fn, _updateTransactionGasFeeEstimates, updateTransactionGasFeeEstimates_fn, _updateTransactionLayer1GasFee, updateTransactionLayer1GasFee_fn, _getUnapprovedTransactions, getUnapprovedTransactions_fn, _getGasFeeControllerData, getGasFeeControllerData_fn;
24
24
  var GasFeePoller = class {
25
25
  /**
26
26
  * Constructs a new instance of the GasFeePoller.
27
27
  * @param options - The options for this instance.
28
+ * @param options.findNetworkClientIdByChainId - Callback to find the network client ID by chain ID.
28
29
  * @param options.gasFeeFlows - The gas fee flows to use to obtain suitable gas fees.
29
30
  * @param options.getGasFeeControllerEstimates - Callback to obtain the default fee estimates.
30
31
  * @param options.getProvider - Callback to obtain a provider instance.
@@ -33,6 +34,7 @@ var GasFeePoller = class {
33
34
  * @param options.onStateChange - Callback to register a listener for controller state changes.
34
35
  */
35
36
  constructor({
37
+ findNetworkClientIdByChainId,
36
38
  gasFeeFlows,
37
39
  getGasFeeControllerEstimates,
38
40
  getProvider,
@@ -48,7 +50,9 @@ var GasFeePoller = class {
48
50
  __privateAdd(this, _updateTransactionGasFeeEstimates);
49
51
  __privateAdd(this, _updateTransactionLayer1GasFee);
50
52
  __privateAdd(this, _getUnapprovedTransactions);
53
+ __privateAdd(this, _getGasFeeControllerData);
51
54
  this.hub = new EventEmitter();
55
+ __privateAdd(this, _findNetworkClientIdByChainId, void 0);
52
56
  __privateAdd(this, _gasFeeFlows, void 0);
53
57
  __privateAdd(this, _getGasFeeControllerEstimates, void 0);
54
58
  __privateAdd(this, _getProvider, void 0);
@@ -56,6 +60,7 @@ var GasFeePoller = class {
56
60
  __privateAdd(this, _layer1GasFeeFlows, void 0);
57
61
  __privateAdd(this, _timeout, void 0);
58
62
  __privateAdd(this, _running, false);
63
+ __privateSet(this, _findNetworkClientIdByChainId, findNetworkClientIdByChainId);
59
64
  __privateSet(this, _gasFeeFlows, gasFeeFlows);
60
65
  __privateSet(this, _layer1GasFeeFlows, layer1GasFeeFlows);
61
66
  __privateSet(this, _getGasFeeControllerEstimates, getGasFeeControllerEstimates);
@@ -71,6 +76,7 @@ var GasFeePoller = class {
71
76
  });
72
77
  }
73
78
  };
79
+ _findNetworkClientIdByChainId = new WeakMap();
74
80
  _gasFeeFlows = new WeakMap();
75
81
  _getGasFeeControllerEstimates = new WeakMap();
76
82
  _getProvider = new WeakMap();
@@ -105,20 +111,27 @@ onTimeout_fn = async function() {
105
111
  _updateUnapprovedTransactions = new WeakSet();
106
112
  updateUnapprovedTransactions_fn = async function() {
107
113
  const unapprovedTransactions = __privateMethod(this, _getUnapprovedTransactions, getUnapprovedTransactions_fn).call(this);
108
- if (unapprovedTransactions.length) {
109
- log("Found unapproved transactions", unapprovedTransactions.length);
114
+ if (!unapprovedTransactions.length) {
115
+ return;
110
116
  }
117
+ log("Found unapproved transactions", unapprovedTransactions.length);
118
+ const gasFeeControllerDataByChainId = await __privateMethod(this, _getGasFeeControllerData, getGasFeeControllerData_fn).call(this, unapprovedTransactions);
119
+ log("Retrieved gas fee controller data", gasFeeControllerDataByChainId);
111
120
  await Promise.all(
112
- unapprovedTransactions.flatMap(
113
- (tx) => __privateMethod(this, _updateUnapprovedTransaction, updateUnapprovedTransaction_fn).call(this, tx)
114
- )
121
+ unapprovedTransactions.flatMap((tx) => {
122
+ const { chainId } = tx;
123
+ const gasFeeControllerData = gasFeeControllerDataByChainId.get(
124
+ chainId
125
+ );
126
+ return __privateMethod(this, _updateUnapprovedTransaction, updateUnapprovedTransaction_fn).call(this, tx, gasFeeControllerData);
127
+ })
115
128
  );
116
129
  };
117
130
  _updateUnapprovedTransaction = new WeakSet();
118
- updateUnapprovedTransaction_fn = async function(transactionMeta) {
131
+ updateUnapprovedTransaction_fn = async function(transactionMeta, gasFeeControllerData) {
119
132
  const { id } = transactionMeta;
120
133
  const [gasFeeEstimatesResponse, layer1GasFee] = await Promise.all([
121
- __privateMethod(this, _updateTransactionGasFeeEstimates, updateTransactionGasFeeEstimates_fn).call(this, transactionMeta),
134
+ __privateMethod(this, _updateTransactionGasFeeEstimates, updateTransactionGasFeeEstimates_fn).call(this, transactionMeta, gasFeeControllerData),
122
135
  __privateMethod(this, _updateTransactionLayer1GasFee, updateTransactionLayer1GasFee_fn).call(this, transactionMeta)
123
136
  ]);
124
137
  if (!gasFeeEstimatesResponse && !layer1GasFee) {
@@ -132,7 +145,7 @@ updateUnapprovedTransaction_fn = async function(transactionMeta) {
132
145
  });
133
146
  };
134
147
  _updateTransactionGasFeeEstimates = new WeakSet();
135
- updateTransactionGasFeeEstimates_fn = async function(transactionMeta) {
148
+ updateTransactionGasFeeEstimates_fn = async function(transactionMeta, gasFeeControllerData) {
136
149
  const { chainId, networkClientId } = transactionMeta;
137
150
  const ethQuery = new EthQuery(__privateGet(this, _getProvider).call(this, chainId, networkClientId));
138
151
  const gasFeeFlow = getGasFeeFlow(transactionMeta, __privateGet(this, _gasFeeFlows));
@@ -145,7 +158,7 @@ updateTransactionGasFeeEstimates_fn = async function(transactionMeta) {
145
158
  }
146
159
  const request = {
147
160
  ethQuery,
148
- getGasFeeControllerEstimates: __privateGet(this, _getGasFeeControllerEstimates),
161
+ gasFeeControllerData,
149
162
  transactionMeta
150
163
  };
151
164
  let gasFeeEstimates;
@@ -186,8 +199,30 @@ getUnapprovedTransactions_fn = function() {
186
199
  (tx) => tx.status === "unapproved" /* unapproved */
187
200
  );
188
201
  };
202
+ _getGasFeeControllerData = new WeakSet();
203
+ getGasFeeControllerData_fn = async function(transactions) {
204
+ const networkClientIdsByChainId = /* @__PURE__ */ new Map();
205
+ for (const transaction of transactions) {
206
+ const { chainId, networkClientId: transactionNetworkClientId } = transaction;
207
+ if (networkClientIdsByChainId.has(chainId)) {
208
+ continue;
209
+ }
210
+ const networkClientId = transactionNetworkClientId ?? __privateGet(this, _findNetworkClientIdByChainId).call(this, chainId);
211
+ networkClientIdsByChainId.set(chainId, networkClientId);
212
+ }
213
+ log("Extracted network client IDs by chain ID", networkClientIdsByChainId);
214
+ const entryPromises = Array.from(networkClientIdsByChainId.entries()).map(
215
+ async ([chainId, networkClientId]) => {
216
+ return [
217
+ chainId,
218
+ await __privateGet(this, _getGasFeeControllerEstimates).call(this, { networkClientId })
219
+ ];
220
+ }
221
+ );
222
+ return new Map(await Promise.all(entryPromises));
223
+ };
189
224
 
190
225
  export {
191
226
  GasFeePoller
192
227
  };
193
- //# sourceMappingURL=chunk-HHK4QSNF.mjs.map
228
+ //# sourceMappingURL=chunk-SL3GHHKG.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/helpers/GasFeePoller.ts"],"sourcesContent":["import EthQuery from '@metamask/eth-query';\nimport type {\n FetchGasFeeEstimateOptions,\n GasFeeState,\n} from '@metamask/gas-fee-controller';\nimport type { NetworkClientId, Provider } from '@metamask/network-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\nimport EventEmitter from 'events';\n\nimport { projectLogger } from '../logger';\nimport type {\n GasFeeEstimates,\n GasFeeFlow,\n GasFeeFlowRequest,\n Layer1GasFeeFlow,\n} from '../types';\nimport { TransactionStatus, type TransactionMeta } from '../types';\nimport { getGasFeeFlow } from '../utils/gas-flow';\nimport { getTransactionLayer1GasFee } from '../utils/layer1-gas-fee-flow';\n\nconst log = createModuleLogger(projectLogger, 'gas-fee-poller');\n\nconst INTERVAL_MILLISECONDS = 10000;\n\n/**\n * Automatically polls and updates suggested gas fees on unapproved transactions.\n */\nexport class GasFeePoller {\n hub: EventEmitter = new EventEmitter();\n\n #findNetworkClientIdByChainId: (chainId: Hex) => NetworkClientId | undefined;\n\n #gasFeeFlows: GasFeeFlow[];\n\n #getGasFeeControllerEstimates: (\n options: FetchGasFeeEstimateOptions,\n ) => Promise<GasFeeState>;\n\n #getProvider: (chainId: Hex, networkClientId?: NetworkClientId) => Provider;\n\n #getTransactions: () => TransactionMeta[];\n\n #layer1GasFeeFlows: Layer1GasFeeFlow[];\n\n #timeout: ReturnType<typeof setTimeout> | undefined;\n\n #running = false;\n\n /**\n * Constructs a new instance of the GasFeePoller.\n * @param options - The options for this instance.\n * @param options.findNetworkClientIdByChainId - Callback to find the network client ID by chain ID.\n * @param options.gasFeeFlows - The gas fee flows to use to obtain suitable gas fees.\n * @param options.getGasFeeControllerEstimates - Callback to obtain the default fee estimates.\n * @param options.getProvider - Callback to obtain a provider instance.\n * @param options.getTransactions - Callback to obtain the transaction data.\n * @param options.layer1GasFeeFlows - The layer 1 gas fee flows to use to obtain suitable layer 1 gas fees.\n * @param options.onStateChange - Callback to register a listener for controller state changes.\n */\n constructor({\n findNetworkClientIdByChainId,\n gasFeeFlows,\n getGasFeeControllerEstimates,\n getProvider,\n getTransactions,\n layer1GasFeeFlows,\n onStateChange,\n }: {\n findNetworkClientIdByChainId: (chainId: Hex) => NetworkClientId | undefined;\n gasFeeFlows: GasFeeFlow[];\n getGasFeeControllerEstimates: (\n options: FetchGasFeeEstimateOptions,\n ) => Promise<GasFeeState>;\n getProvider: (chainId: Hex, networkClientId?: NetworkClientId) => Provider;\n getTransactions: () => TransactionMeta[];\n layer1GasFeeFlows: Layer1GasFeeFlow[];\n onStateChange: (listener: () => void) => void;\n }) {\n this.#findNetworkClientIdByChainId = findNetworkClientIdByChainId;\n this.#gasFeeFlows = gasFeeFlows;\n this.#layer1GasFeeFlows = layer1GasFeeFlows;\n this.#getGasFeeControllerEstimates = getGasFeeControllerEstimates;\n this.#getProvider = getProvider;\n this.#getTransactions = getTransactions;\n\n onStateChange(() => {\n const unapprovedTransactions = this.#getUnapprovedTransactions();\n\n if (unapprovedTransactions.length) {\n this.#start();\n } else {\n this.#stop();\n }\n });\n }\n\n #start() {\n if (this.#running) {\n return;\n }\n\n // Intentionally not awaiting since this starts the timeout chain.\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this.#onTimeout();\n\n this.#running = true;\n\n log('Started polling');\n }\n\n #stop() {\n if (!this.#running) {\n return;\n }\n\n clearTimeout(this.#timeout);\n\n this.#timeout = undefined;\n this.#running = false;\n\n log('Stopped polling');\n }\n\n async #onTimeout() {\n await this.#updateUnapprovedTransactions();\n\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.#timeout = setTimeout(() => this.#onTimeout(), INTERVAL_MILLISECONDS);\n }\n\n async #updateUnapprovedTransactions() {\n const unapprovedTransactions = this.#getUnapprovedTransactions();\n\n if (!unapprovedTransactions.length) {\n return;\n }\n\n log('Found unapproved transactions', unapprovedTransactions.length);\n\n const gasFeeControllerDataByChainId = await this.#getGasFeeControllerData(\n unapprovedTransactions,\n );\n\n log('Retrieved gas fee controller data', gasFeeControllerDataByChainId);\n\n await Promise.all(\n unapprovedTransactions.flatMap((tx) => {\n const { chainId } = tx;\n\n const gasFeeControllerData = gasFeeControllerDataByChainId.get(\n chainId,\n ) as GasFeeState;\n\n return this.#updateUnapprovedTransaction(tx, gasFeeControllerData);\n }),\n );\n }\n\n async #updateUnapprovedTransaction(\n transactionMeta: TransactionMeta,\n gasFeeControllerData: GasFeeState,\n ) {\n const { id } = transactionMeta;\n\n const [gasFeeEstimatesResponse, layer1GasFee] = await Promise.all([\n this.#updateTransactionGasFeeEstimates(\n transactionMeta,\n gasFeeControllerData,\n ),\n this.#updateTransactionLayer1GasFee(transactionMeta),\n ]);\n\n if (!gasFeeEstimatesResponse && !layer1GasFee) {\n return;\n }\n\n this.hub.emit('transaction-updated', {\n transactionId: id,\n gasFeeEstimates: gasFeeEstimatesResponse?.gasFeeEstimates,\n gasFeeEstimatesLoaded: gasFeeEstimatesResponse?.gasFeeEstimatesLoaded,\n layer1GasFee,\n });\n }\n\n async #updateTransactionGasFeeEstimates(\n transactionMeta: TransactionMeta,\n gasFeeControllerData: GasFeeState,\n ): Promise<\n | { gasFeeEstimates?: GasFeeEstimates; gasFeeEstimatesLoaded: boolean }\n | undefined\n > {\n const { chainId, networkClientId } = transactionMeta;\n\n const ethQuery = new EthQuery(this.#getProvider(chainId, networkClientId));\n const gasFeeFlow = getGasFeeFlow(transactionMeta, this.#gasFeeFlows);\n\n if (gasFeeFlow) {\n log(\n 'Found gas fee flow',\n gasFeeFlow.constructor.name,\n transactionMeta.id,\n );\n }\n\n const request: GasFeeFlowRequest = {\n ethQuery,\n gasFeeControllerData,\n transactionMeta,\n };\n\n let gasFeeEstimates: GasFeeEstimates | undefined;\n\n if (gasFeeFlow) {\n try {\n const response = await gasFeeFlow.getGasFees(request);\n gasFeeEstimates = response.estimates;\n } catch (error) {\n log('Failed to get suggested gas fees', transactionMeta.id, error);\n }\n }\n\n if (!gasFeeEstimates && transactionMeta.gasFeeEstimatesLoaded) {\n return undefined;\n }\n\n log('Updated gas fee estimates', {\n gasFeeEstimates,\n transaction: transactionMeta.id,\n });\n\n return { gasFeeEstimates, gasFeeEstimatesLoaded: true };\n }\n\n async #updateTransactionLayer1GasFee(\n transactionMeta: TransactionMeta,\n ): Promise<Hex | undefined> {\n const { chainId, networkClientId } = transactionMeta;\n const provider = this.#getProvider(chainId, networkClientId);\n\n const layer1GasFee = await getTransactionLayer1GasFee({\n layer1GasFeeFlows: this.#layer1GasFeeFlows,\n provider,\n transactionMeta,\n });\n\n if (layer1GasFee) {\n log('Updated layer 1 gas fee', layer1GasFee, transactionMeta.id);\n }\n\n return layer1GasFee;\n }\n\n #getUnapprovedTransactions() {\n return this.#getTransactions().filter(\n (tx) => tx.status === TransactionStatus.unapproved,\n );\n }\n\n async #getGasFeeControllerData(\n transactions: TransactionMeta[],\n ): Promise<Map<string, GasFeeState>> {\n const networkClientIdsByChainId = new Map<Hex, NetworkClientId>();\n\n for (const transaction of transactions) {\n const { chainId, networkClientId: transactionNetworkClientId } =\n transaction;\n\n if (networkClientIdsByChainId.has(chainId)) {\n continue;\n }\n\n const networkClientId =\n transactionNetworkClientId ??\n (this.#findNetworkClientIdByChainId(chainId) as string);\n\n networkClientIdsByChainId.set(chainId, networkClientId);\n }\n\n log('Extracted network client IDs by chain ID', networkClientIdsByChainId);\n\n const entryPromises = Array.from(networkClientIdsByChainId.entries()).map(\n async ([chainId, networkClientId]) => {\n return [\n chainId,\n await this.#getGasFeeControllerEstimates({ networkClientId }),\n ] as const;\n },\n );\n\n return new Map(await Promise.all(entryPromises));\n }\n}\n"],"mappings":"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","names":[]}
@@ -0,0 +1,66 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+
6
+ var _chunkZ4BLTVTBjs = require('./chunk-Z4BLTVTB.js');
7
+
8
+ // src/gas-flows/TestGasFeeFlow.ts
9
+ var _controllerutils = require('@metamask/controller-utils');
10
+ var INCREMENT = 1e15;
11
+ var LEVEL_DIFFERENCE = 0.5;
12
+ var _counter, _getValueForTotalFee, getValueForTotalFee_fn;
13
+ var TestGasFeeFlow = class {
14
+ constructor() {
15
+ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _getValueForTotalFee);
16
+ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _counter, 1);
17
+ }
18
+ matchesTransaction(_transactionMeta) {
19
+ return true;
20
+ }
21
+ async getGasFees(request) {
22
+ const { transactionMeta } = request;
23
+ const { txParams } = transactionMeta;
24
+ const { gas: gasHex } = txParams;
25
+ if (!gasHex) {
26
+ throw new Error("Cannot estimate fee without gas value");
27
+ }
28
+ const gasDecimal = parseInt(gasHex, 16);
29
+ const difference = INCREMENT * LEVEL_DIFFERENCE;
30
+ const mediumMaxTarget = (_chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _counter) + 1) * INCREMENT;
31
+ const mediumPriorityTarget = _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _counter) * INCREMENT;
32
+ const lowMaxTarget = mediumMaxTarget - difference;
33
+ const lowPriorityTarget = mediumPriorityTarget - difference;
34
+ const highMaxTarget = mediumMaxTarget + difference;
35
+ const highPriorityTarget = mediumPriorityTarget + difference;
36
+ _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _counter, _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _counter) + 1);
37
+ return {
38
+ estimates: {
39
+ type: "fee-market" /* FeeMarket */,
40
+ low: {
41
+ maxFeePerGas: _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getValueForTotalFee, getValueForTotalFee_fn).call(this, lowMaxTarget, gasDecimal),
42
+ maxPriorityFeePerGas: _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getValueForTotalFee, getValueForTotalFee_fn).call(this, lowPriorityTarget, gasDecimal)
43
+ },
44
+ medium: {
45
+ maxFeePerGas: _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getValueForTotalFee, getValueForTotalFee_fn).call(this, mediumMaxTarget, gasDecimal),
46
+ maxPriorityFeePerGas: _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getValueForTotalFee, getValueForTotalFee_fn).call(this, mediumPriorityTarget, gasDecimal)
47
+ },
48
+ high: {
49
+ maxFeePerGas: _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getValueForTotalFee, getValueForTotalFee_fn).call(this, highMaxTarget, gasDecimal),
50
+ maxPriorityFeePerGas: _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getValueForTotalFee, getValueForTotalFee_fn).call(this, highPriorityTarget, gasDecimal)
51
+ }
52
+ }
53
+ };
54
+ }
55
+ };
56
+ _counter = new WeakMap();
57
+ _getValueForTotalFee = new WeakSet();
58
+ getValueForTotalFee_fn = function(totalFee, gas) {
59
+ const feeDecimal = Math.ceil(totalFee / gas);
60
+ return _controllerutils.toHex.call(void 0, feeDecimal);
61
+ };
62
+
63
+
64
+
65
+ exports.TestGasFeeFlow = TestGasFeeFlow;
66
+ //# sourceMappingURL=chunk-TJMQEH57.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/gas-flows/TestGasFeeFlow.ts"],"names":[],"mappings":";;;;;;;;AAAA,SAAS,aAAa;AAWtB,IAAM,YAAY;AAClB,IAAM,mBAAmB;AAZzB;AAmBO,IAAM,iBAAN,MAA2C;AAAA,EAA3C;AA0DL;AAzDA,iCAAW;AAAA;AAAA,EAEX,mBAAmB,kBAA4C;AAC7D,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,WAAW,SAAyD;AACxE,UAAM,EAAE,gBAAgB,IAAI;AAC5B,UAAM,EAAE,SAAS,IAAI;AACrB,UAAM,EAAE,KAAK,OAAO,IAAI;AAExB,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI,MAAM,uCAAuC;AAAA,IACzD;AAEA,UAAM,aAAa,SAAS,QAAQ,EAAE;AACtC,UAAM,aAAa,YAAY;AAE/B,UAAM,mBAAmB,mBAAK,YAAW,KAAK;AAC9C,UAAM,uBAAuB,mBAAK,YAAW;AAE7C,UAAM,eAAe,kBAAkB;AACvC,UAAM,oBAAoB,uBAAuB;AAEjD,UAAM,gBAAgB,kBAAkB;AACxC,UAAM,qBAAqB,uBAAuB;AAElD,uBAAK,UAAL,mBAAK,YAAY;AAEjB,WAAO;AAAA,MACL,WAAW;AAAA,QACT;AAAA,QACA,KAAK;AAAA,UACH,cAAc,sBAAK,8CAAL,WAA0B,cAAc;AAAA,UACtD,sBAAsB,sBAAK,8CAAL,WACpB,mBACA;AAAA,QAEJ;AAAA,QACA,QAAQ;AAAA,UACN,cAAc,sBAAK,8CAAL,WAA0B,iBAAiB;AAAA,UACzD,sBAAsB,sBAAK,8CAAL,WACpB,sBACA;AAAA,QAEJ;AAAA,QACA,MAAM;AAAA,UACJ,cAAc,sBAAK,8CAAL,WAA0B,eAAe;AAAA,UACvD,sBAAsB,sBAAK,8CAAL,WACpB,oBACA;AAAA,QAEJ;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAMF;AA7DE;AAyDA;AAAA,yBAAoB,SAAC,UAAkB,KAAkB;AACvD,QAAM,aAAa,KAAK,KAAK,WAAW,GAAG;AAC3C,SAAO,MAAM,UAAU;AACzB","sourcesContent":["import { toHex } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\n\nimport {\n GasFeeEstimateType,\n type GasFeeFlow,\n type GasFeeFlowRequest,\n type GasFeeFlowResponse,\n type TransactionMeta,\n} from '../types';\n\nconst INCREMENT = 1e15; // 0.001 ETH\nconst LEVEL_DIFFERENCE = 0.5;\n\n/**\n * A gas fee flow to facilitate testing in the clients.\n * Increments the total gas fee by a fixed amount each time it is called.\n * Relies on the transaction's gas value to generate a distinct total fee in the UI.\n */\nexport class TestGasFeeFlow implements GasFeeFlow {\n #counter = 1;\n\n matchesTransaction(_transactionMeta: TransactionMeta): boolean {\n return true;\n }\n\n async getGasFees(request: GasFeeFlowRequest): Promise<GasFeeFlowResponse> {\n const { transactionMeta } = request;\n const { txParams } = transactionMeta;\n const { gas: gasHex } = txParams;\n\n if (!gasHex) {\n throw new Error('Cannot estimate fee without gas value');\n }\n\n const gasDecimal = parseInt(gasHex, 16);\n const difference = INCREMENT * LEVEL_DIFFERENCE;\n\n const mediumMaxTarget = (this.#counter + 1) * INCREMENT;\n const mediumPriorityTarget = this.#counter * INCREMENT;\n\n const lowMaxTarget = mediumMaxTarget - difference;\n const lowPriorityTarget = mediumPriorityTarget - difference;\n\n const highMaxTarget = mediumMaxTarget + difference;\n const highPriorityTarget = mediumPriorityTarget + difference;\n\n this.#counter += 1;\n\n return {\n estimates: {\n type: GasFeeEstimateType.FeeMarket,\n low: {\n maxFeePerGas: this.#getValueForTotalFee(lowMaxTarget, gasDecimal),\n maxPriorityFeePerGas: this.#getValueForTotalFee(\n lowPriorityTarget,\n gasDecimal,\n ),\n },\n medium: {\n maxFeePerGas: this.#getValueForTotalFee(mediumMaxTarget, gasDecimal),\n maxPriorityFeePerGas: this.#getValueForTotalFee(\n mediumPriorityTarget,\n gasDecimal,\n ),\n },\n high: {\n maxFeePerGas: this.#getValueForTotalFee(highMaxTarget, gasDecimal),\n maxPriorityFeePerGas: this.#getValueForTotalFee(\n highPriorityTarget,\n gasDecimal,\n ),\n },\n },\n };\n }\n\n #getValueForTotalFee(totalFee: number, gas: number): Hex {\n const feeDecimal = Math.ceil(totalFee / gas);\n return toHex(feeDecimal);\n }\n}\n"]}
@@ -0,0 +1,112 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkKNYSD4JPjs = require('./chunk-KNYSD4JP.js');
4
+
5
+
6
+ var _chunkS6VGOPUYjs = require('./chunk-S6VGOPUY.js');
7
+
8
+
9
+ var _chunk5C3CSQADjs = require('./chunk-5C3CSQAD.js');
10
+
11
+
12
+
13
+ var _chunkZ4BLTVTBjs = require('./chunk-Z4BLTVTB.js');
14
+
15
+ // src/gas-flows/DefaultGasFeeFlow.ts
16
+ var _gasfeecontroller = require('@metamask/gas-fee-controller');
17
+ var _utils = require('@metamask/utils');
18
+ var log = _utils.createModuleLogger.call(void 0, _chunkS6VGOPUYjs.projectLogger, "default-gas-fee-flow");
19
+ var _getFeeMarkEstimates, getFeeMarkEstimates_fn, _getLegacyEstimates, getLegacyEstimates_fn, _getGasPriceEstimates, getGasPriceEstimates_fn, _getFeeMarketLevel, getFeeMarketLevel_fn, _getLegacyLevel, getLegacyLevel_fn;
20
+ var DefaultGasFeeFlow = class {
21
+ constructor() {
22
+ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _getFeeMarkEstimates);
23
+ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _getLegacyEstimates);
24
+ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _getGasPriceEstimates);
25
+ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _getFeeMarketLevel);
26
+ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _getLegacyLevel);
27
+ }
28
+ matchesTransaction(_transactionMeta) {
29
+ return true;
30
+ }
31
+ async getGasFees(request) {
32
+ const { gasFeeControllerData } = request;
33
+ const { gasEstimateType, gasFeeEstimates } = gasFeeControllerData;
34
+ let response;
35
+ switch (gasEstimateType) {
36
+ case _gasfeecontroller.GAS_ESTIMATE_TYPES.FEE_MARKET:
37
+ log("Using fee market estimates", gasFeeEstimates);
38
+ response = _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getFeeMarkEstimates, getFeeMarkEstimates_fn).call(this, gasFeeEstimates);
39
+ break;
40
+ case _gasfeecontroller.GAS_ESTIMATE_TYPES.LEGACY:
41
+ log("Using legacy estimates", gasFeeEstimates);
42
+ response = _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getLegacyEstimates, getLegacyEstimates_fn).call(this, gasFeeEstimates);
43
+ break;
44
+ case _gasfeecontroller.GAS_ESTIMATE_TYPES.ETH_GASPRICE:
45
+ log("Using eth_gasPrice estimates", gasFeeEstimates);
46
+ response = _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getGasPriceEstimates, getGasPriceEstimates_fn).call(this, gasFeeEstimates);
47
+ break;
48
+ default:
49
+ throw new Error(`Unsupported gas estimate type: ${gasEstimateType}`);
50
+ }
51
+ return {
52
+ estimates: response
53
+ };
54
+ }
55
+ };
56
+ _getFeeMarkEstimates = new WeakSet();
57
+ getFeeMarkEstimates_fn = function(gasFeeEstimates) {
58
+ const levels = Object.values(_chunk5C3CSQADjs.GasFeeEstimateLevel).reduce(
59
+ (result, level) => ({
60
+ ...result,
61
+ [level]: _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getFeeMarketLevel, getFeeMarketLevel_fn).call(this, gasFeeEstimates, level)
62
+ }),
63
+ {}
64
+ );
65
+ return {
66
+ type: "fee-market" /* FeeMarket */,
67
+ ...levels
68
+ };
69
+ };
70
+ _getLegacyEstimates = new WeakSet();
71
+ getLegacyEstimates_fn = function(gasFeeEstimates) {
72
+ const levels = Object.values(_chunk5C3CSQADjs.GasFeeEstimateLevel).reduce(
73
+ (result, level) => ({
74
+ ...result,
75
+ [level]: _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getLegacyLevel, getLegacyLevel_fn).call(this, gasFeeEstimates, level)
76
+ }),
77
+ {}
78
+ );
79
+ return {
80
+ type: "legacy" /* Legacy */,
81
+ ...levels
82
+ };
83
+ };
84
+ _getGasPriceEstimates = new WeakSet();
85
+ getGasPriceEstimates_fn = function(gasFeeEstimates) {
86
+ return {
87
+ type: "eth_gasPrice" /* GasPrice */,
88
+ gasPrice: _chunkKNYSD4JPjs.gweiDecimalToWeiHex.call(void 0, gasFeeEstimates.gasPrice)
89
+ };
90
+ };
91
+ _getFeeMarketLevel = new WeakSet();
92
+ getFeeMarketLevel_fn = function(gasFeeEstimates, level) {
93
+ const maxFeePerGas = _chunkKNYSD4JPjs.gweiDecimalToWeiHex.call(void 0,
94
+ gasFeeEstimates[level].suggestedMaxFeePerGas
95
+ );
96
+ const maxPriorityFeePerGas = _chunkKNYSD4JPjs.gweiDecimalToWeiHex.call(void 0,
97
+ gasFeeEstimates[level].suggestedMaxPriorityFeePerGas
98
+ );
99
+ return {
100
+ maxFeePerGas,
101
+ maxPriorityFeePerGas
102
+ };
103
+ };
104
+ _getLegacyLevel = new WeakSet();
105
+ getLegacyLevel_fn = function(gasFeeEstimates, level) {
106
+ return _chunkKNYSD4JPjs.gweiDecimalToWeiHex.call(void 0, gasFeeEstimates[level]);
107
+ };
108
+
109
+
110
+
111
+ exports.DefaultGasFeeFlow = DefaultGasFeeFlow;
112
+ //# sourceMappingURL=chunk-VJYFB7BM.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/gas-flows/DefaultGasFeeFlow.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,SAAS,0BAA0B;AAEnC,SAAS,0BAA0B;AAiBnC,IAAM,MAAM,mBAAmB,eAAe,sBAAsB;AAxBpE;AA6BO,IAAM,oBAAN,MAA8C;AAAA,EAA9C;AAqCL;AAiBA;AAiBA;AASA;AAkBA;AAAA;AAAA,EAjGA,mBAAmB,kBAA4C;AAC7D,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,WAAW,SAAyD;AACxE,UAAM,EAAE,qBAAqB,IAAI;AACjC,UAAM,EAAE,iBAAiB,gBAAgB,IAAI;AAE7C,QAAI;AAEJ,YAAQ,iBAAiB;AAAA,MACvB,KAAK,mBAAmB;AACtB,YAAI,8BAA8B,eAAe;AACjD,mBAAW,sBAAK,8CAAL,WAA0B;AACrC;AAAA,MACF,KAAK,mBAAmB;AACtB,YAAI,0BAA0B,eAAe;AAC7C,mBAAW,sBAAK,4CAAL,WACT;AAEF;AAAA,MACF,KAAK,mBAAmB;AACtB,YAAI,gCAAgC,eAAe;AACnD,mBAAW,sBAAK,gDAAL,WACT;AAEF;AAAA,MACF;AACE,cAAM,IAAI,MAAM,kCAAkC,eAAe,EAAE;AAAA,IACvE;AAEA,WAAO;AAAA,MACL,WAAW;AAAA,IACb;AAAA,EACF;AAqEF;AAnEE;AAAA,yBAAoB,SAClB,iBAC0B;AAC1B,QAAM,SAAS,OAAO,OAAO,mBAAmB,EAAE;AAAA,IAChD,CAAC,QAAQ,WAAW;AAAA,MAClB,GAAG;AAAA,MACH,CAAC,KAAK,GAAG,sBAAK,0CAAL,WAAwB,iBAAiB;AAAA,IACpD;AAAA,IACA,CAAC;AAAA,EACH;AAEA,SAAO;AAAA,IACL;AAAA,IACA,GAAG;AAAA,EACL;AACF;AAEA;AAAA,wBAAmB,SACjB,iBACuB;AACvB,QAAM,SAAS,OAAO,OAAO,mBAAmB,EAAE;AAAA,IAChD,CAAC,QAAQ,WAAW;AAAA,MAClB,GAAG;AAAA,MACH,CAAC,KAAK,GAAG,sBAAK,oCAAL,WAAqB,iBAAiB;AAAA,IACjD;AAAA,IACA,CAAC;AAAA,EACH;AAEA,SAAO;AAAA,IACL;AAAA,IACA,GAAG;AAAA,EACL;AACF;AAEA;AAAA,0BAAqB,SACnB,iBACyB;AACzB,SAAO;AAAA,IACL;AAAA,IACA,UAAU,oBAAoB,gBAAgB,QAAQ;AAAA,EACxD;AACF;AAEA;AAAA,uBAAkB,SAChB,iBACA,OACiC;AACjC,QAAM,eAAe;AAAA,IACnB,gBAAgB,KAAK,EAAE;AAAA,EACzB;AAEA,QAAM,uBAAuB;AAAA,IAC3B,gBAAgB,KAAK,EAAE;AAAA,EACzB;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;AAEA;AAAA,oBAAe,SACb,iBACA,OACK;AACL,SAAO,oBAAoB,gBAAgB,KAAK,CAAC;AACnD","sourcesContent":["import type {\n LegacyGasPriceEstimate,\n GasFeeEstimates as FeeMarketGasPriceEstimate,\n EthGasPriceEstimate,\n} from '@metamask/gas-fee-controller';\nimport { GAS_ESTIMATE_TYPES } from '@metamask/gas-fee-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\n\nimport { projectLogger } from '../logger';\nimport type {\n FeeMarketGasFeeEstimateForLevel,\n FeeMarketGasFeeEstimates,\n GasFeeEstimates,\n GasFeeFlow,\n GasFeeFlowRequest,\n GasFeeFlowResponse,\n GasPriceGasFeeEstimates,\n LegacyGasFeeEstimates,\n TransactionMeta,\n} from '../types';\nimport { GasFeeEstimateLevel, GasFeeEstimateType } from '../types';\nimport { gweiDecimalToWeiHex } from '../utils/gas-fees';\n\nconst log = createModuleLogger(projectLogger, 'default-gas-fee-flow');\n\n/**\n * The standard implementation of a gas fee flow that obtains gas fee estimates using only the GasFeeController.\n */\nexport class DefaultGasFeeFlow implements GasFeeFlow {\n matchesTransaction(_transactionMeta: TransactionMeta): boolean {\n return true;\n }\n\n async getGasFees(request: GasFeeFlowRequest): Promise<GasFeeFlowResponse> {\n const { gasFeeControllerData } = request;\n const { gasEstimateType, gasFeeEstimates } = gasFeeControllerData;\n\n let response: GasFeeEstimates;\n\n switch (gasEstimateType) {\n case GAS_ESTIMATE_TYPES.FEE_MARKET:\n log('Using fee market estimates', gasFeeEstimates);\n response = this.#getFeeMarkEstimates(gasFeeEstimates);\n break;\n case GAS_ESTIMATE_TYPES.LEGACY:\n log('Using legacy estimates', gasFeeEstimates);\n response = this.#getLegacyEstimates(\n gasFeeEstimates as LegacyGasPriceEstimate,\n );\n break;\n case GAS_ESTIMATE_TYPES.ETH_GASPRICE:\n log('Using eth_gasPrice estimates', gasFeeEstimates);\n response = this.#getGasPriceEstimates(\n gasFeeEstimates as EthGasPriceEstimate,\n );\n break;\n default:\n throw new Error(`Unsupported gas estimate type: ${gasEstimateType}`);\n }\n\n return {\n estimates: response,\n };\n }\n\n #getFeeMarkEstimates(\n gasFeeEstimates: FeeMarketGasPriceEstimate,\n ): FeeMarketGasFeeEstimates {\n const levels = Object.values(GasFeeEstimateLevel).reduce(\n (result, level) => ({\n ...result,\n [level]: this.#getFeeMarketLevel(gasFeeEstimates, level),\n }),\n {} as Omit<FeeMarketGasFeeEstimates, 'type'>,\n );\n\n return {\n type: GasFeeEstimateType.FeeMarket,\n ...levels,\n };\n }\n\n #getLegacyEstimates(\n gasFeeEstimates: LegacyGasPriceEstimate,\n ): LegacyGasFeeEstimates {\n const levels = Object.values(GasFeeEstimateLevel).reduce(\n (result, level) => ({\n ...result,\n [level]: this.#getLegacyLevel(gasFeeEstimates, level),\n }),\n {} as Omit<LegacyGasFeeEstimates, 'type'>,\n );\n\n return {\n type: GasFeeEstimateType.Legacy,\n ...levels,\n };\n }\n\n #getGasPriceEstimates(\n gasFeeEstimates: EthGasPriceEstimate,\n ): GasPriceGasFeeEstimates {\n return {\n type: GasFeeEstimateType.GasPrice,\n gasPrice: gweiDecimalToWeiHex(gasFeeEstimates.gasPrice),\n };\n }\n\n #getFeeMarketLevel(\n gasFeeEstimates: FeeMarketGasPriceEstimate,\n level: GasFeeEstimateLevel,\n ): FeeMarketGasFeeEstimateForLevel {\n const maxFeePerGas = gweiDecimalToWeiHex(\n gasFeeEstimates[level].suggestedMaxFeePerGas,\n );\n\n const maxPriorityFeePerGas = gweiDecimalToWeiHex(\n gasFeeEstimates[level].suggestedMaxPriorityFeePerGas,\n );\n\n return {\n maxFeePerGas,\n maxPriorityFeePerGas,\n };\n }\n\n #getLegacyLevel(\n gasFeeEstimates: LegacyGasPriceEstimate,\n level: GasFeeEstimateLevel,\n ): Hex {\n return gweiDecimalToWeiHex(gasFeeEstimates[level]);\n }\n}\n"]}
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  DefaultGasFeeFlow
3
- } from "./chunk-NPEXNXSY.mjs";
3
+ } from "./chunk-REOG6YD4.mjs";
4
4
  import {
5
5
  projectLogger
6
6
  } from "./chunk-UQQWZT6C.mjs";
7
7
  import {
8
8
  GasFeeEstimateLevel
9
- } from "./chunk-YEJJKWT2.mjs";
9
+ } from "./chunk-N6JXPWLY.mjs";
10
10
  import {
11
11
  __privateAdd,
12
12
  __privateMethod
@@ -71,7 +71,7 @@ getLineaGasFees_fn = async function(request) {
71
71
  maxPriorityFeePerGas: toHex(priorityFees[level])
72
72
  }
73
73
  }),
74
- {}
74
+ { type: "fee-market" /* FeeMarket */ }
75
75
  );
76
76
  return { estimates };
77
77
  };
@@ -118,4 +118,4 @@ feesToString_fn = function(fees) {
118
118
  export {
119
119
  LineaGasFeeFlow
120
120
  };
121
- //# sourceMappingURL=chunk-NCRWKI6Y.mjs.map
121
+ //# sourceMappingURL=chunk-XL3HBKDE.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/gas-flows/LineaGasFeeFlow.ts"],"sourcesContent":["import { ChainId, hexToBN, query, toHex } from '@metamask/controller-utils';\nimport type EthQuery from '@metamask/eth-query';\nimport { createModuleLogger, type Hex } from '@metamask/utils';\nimport type BN from 'bn.js';\n\nimport { projectLogger } from '../logger';\nimport type {\n GasFeeEstimates,\n GasFeeFlow,\n GasFeeFlowRequest,\n GasFeeFlowResponse,\n TransactionMeta,\n} from '../types';\nimport { GasFeeEstimateLevel, GasFeeEstimateType } from '../types';\nimport { DefaultGasFeeFlow } from './DefaultGasFeeFlow';\n\ntype LineaEstimateGasResponse = {\n baseFeePerGas: Hex;\n priorityFeePerGas: Hex;\n};\n\ntype FeesByLevel = {\n [key in GasFeeEstimateLevel]: BN;\n};\n\nconst log = createModuleLogger(projectLogger, 'linea-gas-fee-flow');\n\nconst LINEA_CHAIN_IDS: Hex[] = [\n ChainId['linea-mainnet'],\n ChainId['linea-goerli'],\n ChainId['linea-sepolia'],\n];\n\nconst BASE_FEE_MULTIPLIERS = {\n low: 1,\n medium: 1.35,\n high: 1.7,\n};\n\nconst PRIORITY_FEE_MULTIPLIERS = {\n low: 1,\n medium: 1.05,\n high: 1.1,\n};\n\n/**\n * Implementation of a gas fee flow specific to Linea networks that obtains gas fee estimates using:\n * - The `linea_estimateGas` RPC method to obtain the base fee and lowest priority fee.\n * - Static multipliers to increase the base and priority fees.\n */\nexport class LineaGasFeeFlow implements GasFeeFlow {\n matchesTransaction(transactionMeta: TransactionMeta): boolean {\n return LINEA_CHAIN_IDS.includes(transactionMeta.chainId);\n }\n\n async getGasFees(request: GasFeeFlowRequest): Promise<GasFeeFlowResponse> {\n try {\n return await this.#getLineaGasFees(request);\n } catch (error) {\n log('Using default flow as fallback due to error', error);\n return new DefaultGasFeeFlow().getGasFees(request);\n }\n }\n\n async #getLineaGasFees(\n request: GasFeeFlowRequest,\n ): Promise<GasFeeFlowResponse> {\n const { ethQuery, transactionMeta } = request;\n\n const lineaResponse = await this.#getLineaResponse(\n transactionMeta,\n ethQuery,\n );\n\n log('Received Linea response', lineaResponse);\n\n const baseFees = this.#getValuesFromMultipliers(\n lineaResponse.baseFeePerGas,\n BASE_FEE_MULTIPLIERS,\n );\n\n log('Generated base fees', this.#feesToString(baseFees));\n\n const priorityFees = this.#getValuesFromMultipliers(\n lineaResponse.priorityFeePerGas,\n PRIORITY_FEE_MULTIPLIERS,\n );\n\n log('Generated priority fees', this.#feesToString(priorityFees));\n\n const maxFees = this.#getMaxFees(baseFees, priorityFees);\n\n log('Generated max fees', this.#feesToString(maxFees));\n\n const estimates = Object.values(GasFeeEstimateLevel).reduce(\n (result, level) => ({\n ...result,\n [level]: {\n maxFeePerGas: toHex(maxFees[level]),\n maxPriorityFeePerGas: toHex(priorityFees[level]),\n },\n }),\n { type: GasFeeEstimateType.FeeMarket } as GasFeeEstimates,\n );\n\n return { estimates };\n }\n\n #getLineaResponse(\n transactionMeta: TransactionMeta,\n ethQuery: EthQuery,\n ): Promise<LineaEstimateGasResponse> {\n return query(ethQuery, 'linea_estimateGas', [\n {\n from: transactionMeta.txParams.from,\n to: transactionMeta.txParams.to,\n value: transactionMeta.txParams.value,\n input: transactionMeta.txParams.data,\n // Required in request but no impact on response.\n gasPrice: '0x100000000',\n },\n ]);\n }\n\n #getValuesFromMultipliers(\n value: Hex,\n multipliers: { low: number; medium: number; high: number },\n ): FeesByLevel {\n const base = hexToBN(value);\n const low = base.muln(multipliers.low);\n const medium = base.muln(multipliers.medium);\n const high = base.muln(multipliers.high);\n\n return {\n low,\n medium,\n high,\n };\n }\n\n #getMaxFees(\n baseFees: Record<GasFeeEstimateLevel, BN>,\n priorityFees: Record<GasFeeEstimateLevel, BN>,\n ): FeesByLevel {\n return {\n low: baseFees.low.add(priorityFees.low),\n medium: baseFees.medium.add(priorityFees.medium),\n high: baseFees.high.add(priorityFees.high),\n };\n }\n\n #feesToString(fees: FeesByLevel) {\n return Object.values(GasFeeEstimateLevel).map((level) =>\n fees[level].toString(10),\n );\n }\n}\n"],"mappings":"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","names":[]}
package/dist/errors.js CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
 
6
6
  var _chunkHMOSP33Fjs = require('./chunk-HMOSP33F.js');
7
- require('./chunk-FK7AP6SH.js');
7
+ require('./chunk-5C3CSQAD.js');
8
8
  require('./chunk-Z4BLTVTB.js');
9
9
 
10
10
 
package/dist/errors.mjs CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  SimulationInvalidResponseError,
5
5
  SimulationRevertedError
6
6
  } from "./chunk-HQSNKCXI.mjs";
7
- import "./chunk-YEJJKWT2.mjs";
7
+ import "./chunk-N6JXPWLY.mjs";
8
8
  import "./chunk-XUI43LEZ.mjs";
9
9
  export {
10
10
  SimulationChainNotSupportedError,
@@ -1,15 +1,15 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunk4RJXBKSRjs = require('../chunk-4RJXBKSR.js');
4
- require('../chunk-EQNKFFTM.js');
3
+ var _chunkVJYFB7BMjs = require('../chunk-VJYFB7BM.js');
4
+ require('../chunk-KNYSD4JP.js');
5
5
  require('../chunk-C2LNDHP4.js');
6
6
  require('../chunk-UGFBA4GV.js');
7
- require('../chunk-UH7FNVKS.js');
7
+ require('../chunk-EMDU4XLM.js');
8
8
  require('../chunk-UGN7PBON.js');
9
9
  require('../chunk-S6VGOPUY.js');
10
- require('../chunk-FK7AP6SH.js');
10
+ require('../chunk-5C3CSQAD.js');
11
11
  require('../chunk-Z4BLTVTB.js');
12
12
 
13
13
 
14
- exports.DefaultGasFeeFlow = _chunk4RJXBKSRjs.DefaultGasFeeFlow;
14
+ exports.DefaultGasFeeFlow = _chunkVJYFB7BMjs.DefaultGasFeeFlow;
15
15
  //# sourceMappingURL=DefaultGasFeeFlow.js.map
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  DefaultGasFeeFlow
3
- } from "../chunk-NPEXNXSY.mjs";
4
- import "../chunk-LDXTSESK.mjs";
3
+ } from "../chunk-REOG6YD4.mjs";
4
+ import "../chunk-4M7FHI4S.mjs";
5
5
  import "../chunk-ZGUNOEUQ.mjs";
6
6
  import "../chunk-J56A7UCK.mjs";
7
- import "../chunk-TWND5SFD.mjs";
7
+ import "../chunk-AGJNOOBN.mjs";
8
8
  import "../chunk-O6ZZVIFH.mjs";
9
9
  import "../chunk-UQQWZT6C.mjs";
10
- import "../chunk-YEJJKWT2.mjs";
10
+ import "../chunk-N6JXPWLY.mjs";
11
11
  import "../chunk-XUI43LEZ.mjs";
12
12
  export {
13
13
  DefaultGasFeeFlow
@@ -1,16 +1,16 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkLNX4JTOLjs = require('../chunk-LNX4JTOL.js');
4
- require('../chunk-4RJXBKSR.js');
5
- require('../chunk-EQNKFFTM.js');
3
+ var _chunkDUFOYA4Djs = require('../chunk-DUFOYA4D.js');
4
+ require('../chunk-VJYFB7BM.js');
5
+ require('../chunk-KNYSD4JP.js');
6
6
  require('../chunk-C2LNDHP4.js');
7
7
  require('../chunk-UGFBA4GV.js');
8
- require('../chunk-UH7FNVKS.js');
8
+ require('../chunk-EMDU4XLM.js');
9
9
  require('../chunk-UGN7PBON.js');
10
10
  require('../chunk-S6VGOPUY.js');
11
- require('../chunk-FK7AP6SH.js');
11
+ require('../chunk-5C3CSQAD.js');
12
12
  require('../chunk-Z4BLTVTB.js');
13
13
 
14
14
 
15
- exports.LineaGasFeeFlow = _chunkLNX4JTOLjs.LineaGasFeeFlow;
15
+ exports.LineaGasFeeFlow = _chunkDUFOYA4Djs.LineaGasFeeFlow;
16
16
  //# sourceMappingURL=LineaGasFeeFlow.js.map
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  LineaGasFeeFlow
3
- } from "../chunk-NCRWKI6Y.mjs";
4
- import "../chunk-NPEXNXSY.mjs";
5
- import "../chunk-LDXTSESK.mjs";
3
+ } from "../chunk-XL3HBKDE.mjs";
4
+ import "../chunk-REOG6YD4.mjs";
5
+ import "../chunk-4M7FHI4S.mjs";
6
6
  import "../chunk-ZGUNOEUQ.mjs";
7
7
  import "../chunk-J56A7UCK.mjs";
8
- import "../chunk-TWND5SFD.mjs";
8
+ import "../chunk-AGJNOOBN.mjs";
9
9
  import "../chunk-O6ZZVIFH.mjs";
10
10
  import "../chunk-UQQWZT6C.mjs";
11
- import "../chunk-YEJJKWT2.mjs";
11
+ import "../chunk-N6JXPWLY.mjs";
12
12
  import "../chunk-XUI43LEZ.mjs";
13
13
  export {
14
14
  LineaGasFeeFlow