@metamask/gas-fee-controller 15.1.0 → 15.1.2

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 (85) hide show
  1. package/CHANGELOG.md +19 -1
  2. package/dist/GasFeeController.js +3 -9
  3. package/dist/GasFeeController.mjs +2 -8
  4. package/dist/{chunk-INMZ3EB5.mjs → chunk-BEVZS3YV.mjs} +83 -79
  5. package/dist/chunk-BEVZS3YV.mjs.map +1 -0
  6. package/dist/{chunk-QKQ22L3U.js → chunk-H5WHAYLI.js} +91 -87
  7. package/dist/chunk-H5WHAYLI.js.map +1 -0
  8. package/dist/{chunk-QVES4OOM.mjs → chunk-KORLXV32.mjs} +28 -1
  9. package/dist/{chunk-QVES4OOM.mjs.map → chunk-KORLXV32.mjs.map} +1 -1
  10. package/dist/{chunk-NARPHUTR.js → chunk-Q2YPK5SL.js} +30 -3
  11. package/dist/chunk-Q2YPK5SL.js.map +1 -0
  12. package/dist/determineGasFeeCalculations.js +3 -9
  13. package/dist/determineGasFeeCalculations.mjs +2 -8
  14. package/dist/gas-util.js +2 -3
  15. package/dist/gas-util.mjs +1 -2
  16. package/dist/index.js +3 -9
  17. package/dist/index.mjs +2 -8
  18. package/dist/tsconfig.build.tsbuildinfo +1 -1
  19. package/dist/types/GasFeeController.d.ts.map +1 -1
  20. package/dist/types/determineGasFeeCalculations.d.ts +16 -17
  21. package/dist/types/determineGasFeeCalculations.d.ts.map +1 -1
  22. package/package.json +3 -3
  23. package/dist/chunk-5INBFZXY.js +0 -127
  24. package/dist/chunk-5INBFZXY.js.map +0 -1
  25. package/dist/chunk-AQN4AQEF.mjs +0 -127
  26. package/dist/chunk-AQN4AQEF.mjs.map +0 -1
  27. package/dist/chunk-C4I7KKIU.mjs +0 -12
  28. package/dist/chunk-C4I7KKIU.mjs.map +0 -1
  29. package/dist/chunk-EXCWMMNV.mjs +0 -39
  30. package/dist/chunk-EXCWMMNV.mjs.map +0 -1
  31. package/dist/chunk-EZVGDV5H.js +0 -39
  32. package/dist/chunk-EZVGDV5H.js.map +0 -1
  33. package/dist/chunk-GE7RMDFV.js +0 -77
  34. package/dist/chunk-GE7RMDFV.js.map +0 -1
  35. package/dist/chunk-GUWY6WP6.mjs +0 -77
  36. package/dist/chunk-GUWY6WP6.mjs.map +0 -1
  37. package/dist/chunk-INMZ3EB5.mjs.map +0 -1
  38. package/dist/chunk-LO7OP5FM.js +0 -19
  39. package/dist/chunk-LO7OP5FM.js.map +0 -1
  40. package/dist/chunk-NARPHUTR.js.map +0 -1
  41. package/dist/chunk-QKQ22L3U.js.map +0 -1
  42. package/dist/chunk-S2EH2EPS.js +0 -12
  43. package/dist/chunk-S2EH2EPS.js.map +0 -1
  44. package/dist/chunk-SINQOHIN.mjs +0 -19
  45. package/dist/chunk-SINQOHIN.mjs.map +0 -1
  46. package/dist/chunk-XUI43LEZ.mjs +0 -30
  47. package/dist/chunk-XUI43LEZ.mjs.map +0 -1
  48. package/dist/chunk-Z4BLTVTB.js +0 -30
  49. package/dist/chunk-Z4BLTVTB.js.map +0 -1
  50. package/dist/fetchBlockFeeHistory.js +0 -8
  51. package/dist/fetchBlockFeeHistory.js.map +0 -1
  52. package/dist/fetchBlockFeeHistory.mjs +0 -8
  53. package/dist/fetchBlockFeeHistory.mjs.map +0 -1
  54. package/dist/fetchGasEstimatesViaEthFeeHistory/calculateGasFeeEstimatesForPriorityLevels.js +0 -9
  55. package/dist/fetchGasEstimatesViaEthFeeHistory/calculateGasFeeEstimatesForPriorityLevels.js.map +0 -1
  56. package/dist/fetchGasEstimatesViaEthFeeHistory/calculateGasFeeEstimatesForPriorityLevels.mjs +0 -9
  57. package/dist/fetchGasEstimatesViaEthFeeHistory/calculateGasFeeEstimatesForPriorityLevels.mjs.map +0 -1
  58. package/dist/fetchGasEstimatesViaEthFeeHistory/fetchLatestBlock.js +0 -8
  59. package/dist/fetchGasEstimatesViaEthFeeHistory/fetchLatestBlock.js.map +0 -1
  60. package/dist/fetchGasEstimatesViaEthFeeHistory/fetchLatestBlock.mjs +0 -8
  61. package/dist/fetchGasEstimatesViaEthFeeHistory/fetchLatestBlock.mjs.map +0 -1
  62. package/dist/fetchGasEstimatesViaEthFeeHistory/medianOf.js +0 -8
  63. package/dist/fetchGasEstimatesViaEthFeeHistory/medianOf.js.map +0 -1
  64. package/dist/fetchGasEstimatesViaEthFeeHistory/medianOf.mjs +0 -8
  65. package/dist/fetchGasEstimatesViaEthFeeHistory/medianOf.mjs.map +0 -1
  66. package/dist/fetchGasEstimatesViaEthFeeHistory/types.js +0 -1
  67. package/dist/fetchGasEstimatesViaEthFeeHistory/types.js.map +0 -1
  68. package/dist/fetchGasEstimatesViaEthFeeHistory/types.mjs +0 -1
  69. package/dist/fetchGasEstimatesViaEthFeeHistory/types.mjs.map +0 -1
  70. package/dist/fetchGasEstimatesViaEthFeeHistory.js +0 -12
  71. package/dist/fetchGasEstimatesViaEthFeeHistory.js.map +0 -1
  72. package/dist/fetchGasEstimatesViaEthFeeHistory.mjs +0 -12
  73. package/dist/fetchGasEstimatesViaEthFeeHistory.mjs.map +0 -1
  74. package/dist/types/fetchBlockFeeHistory.d.ts +0 -115
  75. package/dist/types/fetchBlockFeeHistory.d.ts.map +0 -1
  76. package/dist/types/fetchGasEstimatesViaEthFeeHistory/calculateGasFeeEstimatesForPriorityLevels.d.ts +0 -17
  77. package/dist/types/fetchGasEstimatesViaEthFeeHistory/calculateGasFeeEstimatesForPriorityLevels.d.ts.map +0 -1
  78. package/dist/types/fetchGasEstimatesViaEthFeeHistory/fetchLatestBlock.d.ts +0 -12
  79. package/dist/types/fetchGasEstimatesViaEthFeeHistory/fetchLatestBlock.d.ts.map +0 -1
  80. package/dist/types/fetchGasEstimatesViaEthFeeHistory/medianOf.d.ts +0 -10
  81. package/dist/types/fetchGasEstimatesViaEthFeeHistory/medianOf.d.ts.map +0 -1
  82. package/dist/types/fetchGasEstimatesViaEthFeeHistory/types.d.ts +0 -7
  83. package/dist/types/fetchGasEstimatesViaEthFeeHistory/types.d.ts.map +0 -1
  84. package/dist/types/fetchGasEstimatesViaEthFeeHistory.d.ts +0 -22
  85. package/dist/types/fetchGasEstimatesViaEthFeeHistory.d.ts.map +0 -1
package/CHANGELOG.md CHANGED
@@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [15.1.2]
11
+
12
+ ### Fixed
13
+
14
+ - Add a metadata property for nonRPCGasFeeApisDisabled ([#4245](https://github.com/MetaMask/core/pull/4245))
15
+
16
+ ## [15.1.1]
17
+
18
+ ### Changed
19
+
20
+ - Bump `@metamask/polling-controller` to `^6.0.2` ([#4234](https://github.com/MetaMask/core/pull/4234))
21
+
22
+ ### Removed
23
+
24
+ - Remove fee history fallback in favour of `eth_gasPrice` call ([#4210](https://github.com/MetaMask/core/pull/4210))
25
+
10
26
  ## [15.1.0]
11
27
 
12
28
  ### Added
@@ -259,7 +275,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
259
275
 
260
276
  All changes listed after this point were applied to this package following the monorepo conversion.
261
277
 
262
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@15.1.0...HEAD
278
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@15.1.2...HEAD
279
+ [15.1.2]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@15.1.1...@metamask/gas-fee-controller@15.1.2
280
+ [15.1.1]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@15.1.0...@metamask/gas-fee-controller@15.1.1
263
281
  [15.1.0]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@15.0.0...@metamask/gas-fee-controller@15.1.0
264
282
  [15.0.0]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@14.0.1...@metamask/gas-fee-controller@15.0.0
265
283
  [14.0.1]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@14.0.0...@metamask/gas-fee-controller@14.0.1
@@ -3,18 +3,12 @@
3
3
 
4
4
 
5
5
 
6
- var _chunkQKQ22L3Ujs = require('./chunk-QKQ22L3U.js');
7
- require('./chunk-EZVGDV5H.js');
8
- require('./chunk-5INBFZXY.js');
9
- require('./chunk-NARPHUTR.js');
10
- require('./chunk-GE7RMDFV.js');
11
- require('./chunk-S2EH2EPS.js');
12
- require('./chunk-LO7OP5FM.js');
13
- require('./chunk-Z4BLTVTB.js');
6
+ var _chunkH5WHAYLIjs = require('./chunk-H5WHAYLI.js');
7
+ require('./chunk-Q2YPK5SL.js');
14
8
 
15
9
 
16
10
 
17
11
 
18
12
 
19
- exports.GAS_API_BASE_URL = _chunkQKQ22L3Ujs.GAS_API_BASE_URL; exports.GAS_ESTIMATE_TYPES = _chunkQKQ22L3Ujs.GAS_ESTIMATE_TYPES; exports.GasFeeController = _chunkQKQ22L3Ujs.GasFeeController; exports.default = _chunkQKQ22L3Ujs.GasFeeController_default;
13
+ exports.GAS_API_BASE_URL = _chunkH5WHAYLIjs.GAS_API_BASE_URL; exports.GAS_ESTIMATE_TYPES = _chunkH5WHAYLIjs.GAS_ESTIMATE_TYPES; exports.GasFeeController = _chunkH5WHAYLIjs.GasFeeController; exports.default = _chunkH5WHAYLIjs.GasFeeController_default;
20
14
  //# sourceMappingURL=GasFeeController.js.map
@@ -3,14 +3,8 @@ import {
3
3
  GAS_ESTIMATE_TYPES,
4
4
  GasFeeController,
5
5
  GasFeeController_default
6
- } from "./chunk-INMZ3EB5.mjs";
7
- import "./chunk-EXCWMMNV.mjs";
8
- import "./chunk-AQN4AQEF.mjs";
9
- import "./chunk-QVES4OOM.mjs";
10
- import "./chunk-GUWY6WP6.mjs";
11
- import "./chunk-C4I7KKIU.mjs";
12
- import "./chunk-SINQOHIN.mjs";
13
- import "./chunk-XUI43LEZ.mjs";
6
+ } from "./chunk-BEVZS3YV.mjs";
7
+ import "./chunk-KORLXV32.mjs";
14
8
  export {
15
9
  GAS_API_BASE_URL,
16
10
  GAS_ESTIMATE_TYPES,
@@ -1,18 +1,13 @@
1
1
  import {
2
- fetchGasEstimatesViaEthFeeHistory
3
- } from "./chunk-EXCWMMNV.mjs";
4
- import {
2
+ __privateAdd,
3
+ __privateGet,
4
+ __privateMethod,
5
+ __privateSet,
5
6
  calculateTimeEstimate,
6
7
  fetchEthGasPriceEstimate,
7
8
  fetchGasEstimates,
8
9
  fetchLegacyGasPriceEstimates
9
- } from "./chunk-QVES4OOM.mjs";
10
- import {
11
- __privateAdd,
12
- __privateGet,
13
- __privateMethod,
14
- __privateSet
15
- } from "./chunk-XUI43LEZ.mjs";
10
+ } from "./chunk-KORLXV32.mjs";
16
11
 
17
12
  // src/GasFeeController.ts
18
13
  import {
@@ -37,7 +32,8 @@ var metadata = {
37
32
  },
38
33
  gasFeeEstimates: { persist: true, anonymous: false },
39
34
  estimatedGasFeeTimeBounds: { persist: true, anonymous: false },
40
- gasEstimateType: { persist: true, anonymous: false }
35
+ gasEstimateType: { persist: true, anonymous: false },
36
+ nonRPCGasFeeApisDisabled: { persist: true, anonymous: false }
41
37
  };
42
38
  var name = "GasFeeController";
43
39
  var defaultState = {
@@ -188,7 +184,6 @@ var GasFeeController = class extends StaticIntervalPollingController {
188
184
  "<chain_id>",
189
185
  `${decimalChainId}`
190
186
  ),
191
- fetchGasEstimatesViaEthFeeHistory,
192
187
  fetchLegacyGasPriceEstimates,
193
188
  fetchLegacyGasPriceEstimatesUrl: this.legacyAPIEndpoint.replace(
194
189
  "<chain_id>",
@@ -308,79 +303,88 @@ onNetworkControllerDidChange_fn = async function(networkControllerState) {
308
303
  var GasFeeController_default = GasFeeController;
309
304
 
310
305
  // src/determineGasFeeCalculations.ts
311
- async function determineGasFeeCalculations({
312
- isEIP1559Compatible,
313
- isLegacyGasAPICompatible,
314
- fetchGasEstimates: fetchGasEstimates2,
315
- fetchGasEstimatesUrl,
316
- fetchGasEstimatesViaEthFeeHistory: fetchGasEstimatesViaEthFeeHistory2,
317
- fetchLegacyGasPriceEstimates: fetchLegacyGasPriceEstimates2,
318
- fetchLegacyGasPriceEstimatesUrl,
319
- fetchEthGasPriceEstimate: fetchEthGasPriceEstimate2,
320
- calculateTimeEstimate: calculateTimeEstimate2,
321
- clientId,
322
- ethQuery,
323
- infuraAPIKey,
324
- nonRPCGasFeeApisDisabled = false
325
- }) {
306
+ async function determineGasFeeCalculations(args) {
326
307
  try {
327
- if (isEIP1559Compatible) {
328
- let estimates;
329
- if (nonRPCGasFeeApisDisabled) {
330
- estimates = await fetchGasEstimatesViaEthFeeHistory2(ethQuery);
331
- } else {
332
- try {
333
- estimates = await fetchGasEstimates2(
334
- fetchGasEstimatesUrl,
335
- infuraAPIKey,
336
- clientId
337
- );
338
- } catch {
339
- estimates = await fetchGasEstimatesViaEthFeeHistory2(ethQuery);
340
- }
341
- }
342
- const { suggestedMaxPriorityFeePerGas, suggestedMaxFeePerGas } = estimates.medium;
343
- const estimatedGasFeeTimeBounds = calculateTimeEstimate2(
344
- suggestedMaxPriorityFeePerGas,
345
- suggestedMaxFeePerGas,
346
- estimates
347
- );
348
- return {
349
- gasFeeEstimates: estimates,
350
- estimatedGasFeeTimeBounds,
351
- gasEstimateType: GAS_ESTIMATE_TYPES.FEE_MARKET
352
- };
353
- } else if (isLegacyGasAPICompatible && !nonRPCGasFeeApisDisabled) {
354
- const estimates = await fetchLegacyGasPriceEstimates2(
355
- fetchLegacyGasPriceEstimatesUrl,
356
- infuraAPIKey,
357
- clientId
308
+ return await getEstimatesUsingFallbacks(args);
309
+ } catch (error) {
310
+ if (error instanceof Error) {
311
+ throw new Error(
312
+ `Gas fee/price estimation failed. Message: ${error.message}`
358
313
  );
359
- return {
360
- gasFeeEstimates: estimates,
361
- estimatedGasFeeTimeBounds: {},
362
- gasEstimateType: GAS_ESTIMATE_TYPES.LEGACY
363
- };
314
+ }
315
+ throw error;
316
+ }
317
+ }
318
+ async function getEstimatesUsingFallbacks(request) {
319
+ const {
320
+ isEIP1559Compatible,
321
+ isLegacyGasAPICompatible,
322
+ nonRPCGasFeeApisDisabled
323
+ } = request;
324
+ try {
325
+ if (isEIP1559Compatible && !nonRPCGasFeeApisDisabled) {
326
+ return await getEstimatesUsingFeeMarketEndpoint(request);
327
+ }
328
+ if (isLegacyGasAPICompatible && !nonRPCGasFeeApisDisabled) {
329
+ return await getEstimatesUsingLegacyEndpoint(request);
364
330
  }
365
331
  throw new Error("Main gas fee/price estimation failed. Use fallback");
366
332
  } catch {
367
- try {
368
- const estimates = await fetchEthGasPriceEstimate2(ethQuery);
369
- return {
370
- gasFeeEstimates: estimates,
371
- estimatedGasFeeTimeBounds: {},
372
- gasEstimateType: GAS_ESTIMATE_TYPES.ETH_GASPRICE
373
- };
374
- } catch (error) {
375
- if (error instanceof Error) {
376
- throw new Error(
377
- `Gas fee/price estimation failed. Message: ${error.message}`
378
- );
379
- }
380
- throw error;
381
- }
333
+ return await getEstimatesUsingProvider(request);
382
334
  }
383
335
  }
336
+ async function getEstimatesUsingFeeMarketEndpoint(request) {
337
+ const {
338
+ fetchGasEstimates: fetchGasEstimates2,
339
+ fetchGasEstimatesUrl,
340
+ infuraAPIKey,
341
+ clientId,
342
+ calculateTimeEstimate: calculateTimeEstimate2
343
+ } = request;
344
+ const estimates = await fetchGasEstimates2(
345
+ fetchGasEstimatesUrl,
346
+ infuraAPIKey,
347
+ clientId
348
+ );
349
+ const { suggestedMaxPriorityFeePerGas, suggestedMaxFeePerGas } = estimates.medium;
350
+ const estimatedGasFeeTimeBounds = calculateTimeEstimate2(
351
+ suggestedMaxPriorityFeePerGas,
352
+ suggestedMaxFeePerGas,
353
+ estimates
354
+ );
355
+ return {
356
+ gasFeeEstimates: estimates,
357
+ estimatedGasFeeTimeBounds,
358
+ gasEstimateType: GAS_ESTIMATE_TYPES.FEE_MARKET
359
+ };
360
+ }
361
+ async function getEstimatesUsingLegacyEndpoint(request) {
362
+ const {
363
+ fetchLegacyGasPriceEstimates: fetchLegacyGasPriceEstimates2,
364
+ fetchLegacyGasPriceEstimatesUrl,
365
+ infuraAPIKey,
366
+ clientId
367
+ } = request;
368
+ const estimates = await fetchLegacyGasPriceEstimates2(
369
+ fetchLegacyGasPriceEstimatesUrl,
370
+ infuraAPIKey,
371
+ clientId
372
+ );
373
+ return {
374
+ gasFeeEstimates: estimates,
375
+ estimatedGasFeeTimeBounds: {},
376
+ gasEstimateType: GAS_ESTIMATE_TYPES.LEGACY
377
+ };
378
+ }
379
+ async function getEstimatesUsingProvider(request) {
380
+ const { ethQuery, fetchEthGasPriceEstimate: fetchEthGasPriceEstimate2 } = request;
381
+ const estimates = await fetchEthGasPriceEstimate2(ethQuery);
382
+ return {
383
+ gasFeeEstimates: estimates,
384
+ estimatedGasFeeTimeBounds: {},
385
+ gasEstimateType: GAS_ESTIMATE_TYPES.ETH_GASPRICE
386
+ };
387
+ }
384
388
 
385
389
  export {
386
390
  determineGasFeeCalculations,
@@ -389,4 +393,4 @@ export {
389
393
  GasFeeController,
390
394
  GasFeeController_default
391
395
  };
392
- //# sourceMappingURL=chunk-INMZ3EB5.mjs.map
396
+ //# sourceMappingURL=chunk-BEVZS3YV.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/GasFeeController.ts","../src/determineGasFeeCalculations.ts"],"sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedControllerMessenger,\n} from '@metamask/base-controller';\nimport {\n convertHexToDecimal,\n safelyExecute,\n toHex,\n} from '@metamask/controller-utils';\nimport EthQuery from '@metamask/eth-query';\nimport type {\n NetworkClientId,\n NetworkControllerGetEIP1559CompatibilityAction,\n NetworkControllerGetNetworkClientByIdAction,\n NetworkControllerGetStateAction,\n NetworkControllerNetworkDidChangeEvent,\n NetworkState,\n ProviderProxy,\n} from '@metamask/network-controller';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport type { Hex } from '@metamask/utils';\nimport { v1 as random } from 'uuid';\n\nimport determineGasFeeCalculations from './determineGasFeeCalculations';\nimport {\n calculateTimeEstimate,\n fetchGasEstimates,\n fetchLegacyGasPriceEstimates,\n fetchEthGasPriceEstimate,\n} from './gas-util';\n\nexport const GAS_API_BASE_URL = 'https://gas.api.infura.io';\n\nexport type unknownString = 'unknown';\n\n// Fee Market describes the way gas is set after the london hardfork, and was\n// defined by EIP-1559.\nexport type FeeMarketEstimateType = 'fee-market';\n// Legacy describes gasPrice estimates from before london hardfork, when the\n// user is connected to mainnet and are presented with fast/average/slow\n// estimate levels to choose from.\nexport type LegacyEstimateType = 'legacy';\n// EthGasPrice describes a gasPrice estimate received from eth_gasPrice. Post\n// london this value should only be used for legacy type transactions when on\n// networks that support EIP-1559. This type of estimate is the most accurate\n// to display on custom networks that don't support EIP-1559.\nexport type EthGasPriceEstimateType = 'eth_gasPrice';\n// NoEstimate describes the state of the controller before receiving its first\n// estimate.\nexport type NoEstimateType = 'none';\n\n/**\n * Indicates which type of gasEstimate the controller is currently returning.\n * This is useful as a way of asserting that the shape of gasEstimates matches\n * expectations. NONE is a special case indicating that no previous gasEstimate\n * has been fetched.\n */\nexport const GAS_ESTIMATE_TYPES = {\n FEE_MARKET: 'fee-market' as FeeMarketEstimateType,\n LEGACY: 'legacy' as LegacyEstimateType,\n ETH_GASPRICE: 'eth_gasPrice' as EthGasPriceEstimateType,\n NONE: 'none' as NoEstimateType,\n};\n\nexport type GasEstimateType =\n | FeeMarketEstimateType\n | EthGasPriceEstimateType\n | LegacyEstimateType\n | NoEstimateType;\n\nexport type EstimatedGasFeeTimeBounds = {\n lowerTimeBound: number | null;\n upperTimeBound: number | unknownString;\n};\n\n/**\n * @type EthGasPriceEstimate\n *\n * A single gas price estimate for networks and accounts that don't support EIP-1559\n * This estimate comes from eth_gasPrice but is converted to dec gwei to match other\n * return values\n * @property gasPrice - A GWEI dec string\n */\n\nexport type EthGasPriceEstimate = {\n gasPrice: string;\n};\n\n/**\n * @type LegacyGasPriceEstimate\n *\n * A set of gas price estimates for networks and accounts that don't support EIP-1559\n * These estimates include low, medium and high all as strings representing gwei in\n * decimal format.\n * @property high - gasPrice, in decimal gwei string format, suggested for fast inclusion\n * @property medium - gasPrice, in decimal gwei string format, suggested for avg inclusion\n * @property low - gasPrice, in decimal gwei string format, suggested for slow inclusion\n */\nexport type LegacyGasPriceEstimate = {\n high: string;\n medium: string;\n low: string;\n};\n\n/**\n * @type Eip1559GasFee\n *\n * Data necessary to provide an estimate of a gas fee with a specific tip\n * @property minWaitTimeEstimate - The fastest the transaction will take, in milliseconds\n * @property maxWaitTimeEstimate - The slowest the transaction will take, in milliseconds\n * @property suggestedMaxPriorityFeePerGas - A suggested \"tip\", a GWEI hex number\n * @property suggestedMaxFeePerGas - A suggested max fee, the most a user will pay. a GWEI hex number\n */\nexport type Eip1559GasFee = {\n minWaitTimeEstimate: number; // a time duration in milliseconds\n maxWaitTimeEstimate: number; // a time duration in milliseconds\n suggestedMaxPriorityFeePerGas: string; // a GWEI decimal number\n suggestedMaxFeePerGas: string; // a GWEI decimal number\n};\n\n/**\n * @type GasFeeEstimates\n *\n * Data necessary to provide multiple GasFee estimates, and supporting information, to the user\n * @property low - A GasFee for a minimum necessary combination of tip and maxFee\n * @property medium - A GasFee for a recommended combination of tip and maxFee\n * @property high - A GasFee for a high combination of tip and maxFee\n * @property estimatedBaseFee - An estimate of what the base fee will be for the pending/next block. A GWEI dec number\n * @property networkCongestion - A normalized number that can be used to gauge the congestion\n * level of the network, with 0 meaning not congested and 1 meaning extremely congested\n */\nexport type GasFeeEstimates = SourcedGasFeeEstimates | FallbackGasFeeEstimates;\n\ntype SourcedGasFeeEstimates = {\n low: Eip1559GasFee;\n medium: Eip1559GasFee;\n high: Eip1559GasFee;\n estimatedBaseFee: string;\n historicalBaseFeeRange: [string, string];\n baseFeeTrend: 'up' | 'down' | 'level';\n latestPriorityFeeRange: [string, string];\n historicalPriorityFeeRange: [string, string];\n priorityFeeTrend: 'up' | 'down' | 'level';\n networkCongestion: number;\n};\n\ntype FallbackGasFeeEstimates = {\n low: Eip1559GasFee;\n medium: Eip1559GasFee;\n high: Eip1559GasFee;\n estimatedBaseFee: string;\n historicalBaseFeeRange: null;\n baseFeeTrend: null;\n latestPriorityFeeRange: null;\n historicalPriorityFeeRange: null;\n priorityFeeTrend: null;\n networkCongestion: null;\n};\n\nconst metadata = {\n gasFeeEstimatesByChainId: {\n persist: true,\n anonymous: false,\n },\n gasFeeEstimates: { persist: true, anonymous: false },\n estimatedGasFeeTimeBounds: { persist: true, anonymous: false },\n gasEstimateType: { persist: true, anonymous: false },\n nonRPCGasFeeApisDisabled: { persist: true, anonymous: false },\n};\n\nexport type GasFeeStateEthGasPrice = {\n gasFeeEstimates: EthGasPriceEstimate;\n estimatedGasFeeTimeBounds: Record<string, never>;\n gasEstimateType: EthGasPriceEstimateType;\n};\n\nexport type GasFeeStateFeeMarket = {\n gasFeeEstimates: GasFeeEstimates;\n estimatedGasFeeTimeBounds: EstimatedGasFeeTimeBounds | Record<string, never>;\n gasEstimateType: FeeMarketEstimateType;\n};\n\nexport type GasFeeStateLegacy = {\n gasFeeEstimates: LegacyGasPriceEstimate;\n estimatedGasFeeTimeBounds: Record<string, never>;\n gasEstimateType: LegacyEstimateType;\n};\n\nexport type GasFeeStateNoEstimates = {\n gasFeeEstimates: Record<string, never>;\n estimatedGasFeeTimeBounds: Record<string, never>;\n gasEstimateType: NoEstimateType;\n};\n\nexport type FetchGasFeeEstimateOptions = {\n shouldUpdateState?: boolean;\n networkClientId?: NetworkClientId;\n};\n\n/**\n * @type GasFeeState\n *\n * Gas Fee controller state\n * @property gasFeeEstimates - Gas fee estimate data based on new EIP-1559 properties\n * @property estimatedGasFeeTimeBounds - Estimates representing the minimum and maximum\n */\nexport type SingleChainGasFeeState =\n | GasFeeStateEthGasPrice\n | GasFeeStateFeeMarket\n | GasFeeStateLegacy\n | GasFeeStateNoEstimates;\n\nexport type GasFeeEstimatesByChainId = {\n gasFeeEstimatesByChainId?: Record<string, SingleChainGasFeeState>;\n};\n\nexport type GasFeeState = GasFeeEstimatesByChainId &\n SingleChainGasFeeState & {\n nonRPCGasFeeApisDisabled?: boolean;\n };\n\nconst name = 'GasFeeController';\n\nexport type GasFeeStateChange = ControllerStateChangeEvent<\n typeof name,\n GasFeeState\n>;\n\nexport type GetGasFeeState = ControllerGetStateAction<typeof name, GasFeeState>;\n\nexport type GasFeeControllerActions = GetGasFeeState;\n\nexport type GasFeeControllerEvents = GasFeeStateChange;\n\ntype AllowedActions =\n | NetworkControllerGetStateAction\n | NetworkControllerGetNetworkClientByIdAction\n | NetworkControllerGetEIP1559CompatibilityAction;\n\ntype GasFeeMessenger = RestrictedControllerMessenger<\n typeof name,\n GasFeeControllerActions | AllowedActions,\n GasFeeControllerEvents | NetworkControllerNetworkDidChangeEvent,\n AllowedActions['type'],\n NetworkControllerNetworkDidChangeEvent['type']\n>;\n\nconst defaultState: GasFeeState = {\n gasFeeEstimatesByChainId: {},\n gasFeeEstimates: {},\n estimatedGasFeeTimeBounds: {},\n gasEstimateType: GAS_ESTIMATE_TYPES.NONE,\n nonRPCGasFeeApisDisabled: false,\n};\n\n/**\n * Controller that retrieves gas fee estimate data and polls for updated data on a set interval\n */\nexport class GasFeeController extends StaticIntervalPollingController<\n typeof name,\n GasFeeState,\n GasFeeMessenger\n> {\n private intervalId?: ReturnType<typeof setTimeout>;\n\n private readonly intervalDelay;\n\n private readonly pollTokens: Set<string>;\n\n private readonly legacyAPIEndpoint: string;\n\n private readonly EIP1559APIEndpoint: string;\n\n private readonly getCurrentNetworkEIP1559Compatibility;\n\n private readonly getCurrentNetworkLegacyGasAPICompatibility;\n\n private readonly getCurrentAccountEIP1559Compatibility;\n\n private readonly infuraAPIKey: string;\n\n private currentChainId;\n\n private ethQuery?: EthQuery;\n\n private readonly clientId?: string;\n\n #getProvider: () => ProviderProxy;\n\n /**\n * Creates a GasFeeController instance.\n *\n * @param options - The controller options.\n * @param options.interval - The time in milliseconds to wait between polls.\n * @param options.messenger - The controller messenger.\n * @param options.state - The initial state.\n * @param options.getCurrentNetworkEIP1559Compatibility - Determines whether or not the current\n * network is EIP-1559 compatible.\n * @param options.getCurrentNetworkLegacyGasAPICompatibility - Determines whether or not the\n * current network is compatible with the legacy gas price API.\n * @param options.getCurrentAccountEIP1559Compatibility - Determines whether or not the current\n * account is EIP-1559 compatible.\n * @param options.getChainId - Returns the current chain ID.\n * @param options.getProvider - Returns a network provider for the current network.\n * @param options.onNetworkDidChange - A function for registering an event handler for the\n * network state change event.\n * @param options.clientId - The client ID used to identify to the gas estimation API who is\n * asking for estimates.\n * @param options.infuraAPIKey - The Infura API key used for infura API requests.\n */\n constructor({\n interval = 15000,\n messenger,\n state,\n getCurrentNetworkEIP1559Compatibility,\n getCurrentAccountEIP1559Compatibility,\n getChainId,\n getCurrentNetworkLegacyGasAPICompatibility,\n getProvider,\n onNetworkDidChange,\n clientId,\n infuraAPIKey,\n }: {\n interval?: number;\n messenger: GasFeeMessenger;\n state?: GasFeeState;\n getCurrentNetworkEIP1559Compatibility: () => Promise<boolean>;\n getCurrentNetworkLegacyGasAPICompatibility: () => boolean;\n getCurrentAccountEIP1559Compatibility?: () => boolean;\n getChainId?: () => Hex;\n getProvider: () => ProviderProxy;\n onNetworkDidChange?: (listener: (state: NetworkState) => void) => void;\n clientId?: string;\n infuraAPIKey: string;\n }) {\n super({\n name,\n metadata,\n messenger,\n state: { ...defaultState, ...state },\n });\n this.intervalDelay = interval;\n this.setIntervalLength(interval);\n this.pollTokens = new Set();\n this.getCurrentNetworkEIP1559Compatibility =\n getCurrentNetworkEIP1559Compatibility;\n this.getCurrentNetworkLegacyGasAPICompatibility =\n getCurrentNetworkLegacyGasAPICompatibility;\n this.getCurrentAccountEIP1559Compatibility =\n getCurrentAccountEIP1559Compatibility;\n this.#getProvider = getProvider;\n this.EIP1559APIEndpoint = `${GAS_API_BASE_URL}/networks/<chain_id>/suggestedGasFees`;\n this.legacyAPIEndpoint = `${GAS_API_BASE_URL}/networks/<chain_id>/gasPrices`;\n this.clientId = clientId;\n this.infuraAPIKey = infuraAPIKey;\n\n this.ethQuery = new EthQuery(this.#getProvider());\n\n if (onNetworkDidChange && getChainId) {\n this.currentChainId = getChainId();\n onNetworkDidChange(async (networkControllerState) => {\n await this.#onNetworkControllerDidChange(networkControllerState);\n });\n } else {\n this.currentChainId = this.messagingSystem.call(\n 'NetworkController:getState',\n ).providerConfig.chainId;\n this.messagingSystem.subscribe(\n 'NetworkController:networkDidChange',\n async (networkControllerState) => {\n await this.#onNetworkControllerDidChange(networkControllerState);\n },\n );\n }\n }\n\n async resetPolling() {\n if (this.pollTokens.size !== 0) {\n const tokens = Array.from(this.pollTokens);\n this.stopPolling();\n await this.getGasFeeEstimatesAndStartPolling(tokens[0]);\n tokens.slice(1).forEach((token) => {\n this.pollTokens.add(token);\n });\n }\n }\n\n async fetchGasFeeEstimates(options?: FetchGasFeeEstimateOptions) {\n return await this._fetchGasFeeEstimateData(options);\n }\n\n async getGasFeeEstimatesAndStartPolling(\n pollToken: string | undefined,\n ): Promise<string> {\n const _pollToken = pollToken || random();\n\n this.pollTokens.add(_pollToken);\n\n if (this.pollTokens.size === 1) {\n await this._fetchGasFeeEstimateData();\n this._poll();\n }\n\n return _pollToken;\n }\n\n /**\n * Gets and sets gasFeeEstimates in state.\n *\n * @param options - The gas fee estimate options.\n * @param options.shouldUpdateState - Determines whether the state should be updated with the\n * updated gas estimates.\n * @returns The gas fee estimates.\n */\n async _fetchGasFeeEstimateData(\n options: FetchGasFeeEstimateOptions = {},\n ): Promise<GasFeeState> {\n const { shouldUpdateState = true, networkClientId } = options;\n\n let ethQuery,\n isEIP1559Compatible,\n isLegacyGasAPICompatible,\n decimalChainId: number;\n\n if (networkClientId !== undefined) {\n const networkClient = this.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n isLegacyGasAPICompatible = networkClient.configuration.chainId === '0x38';\n\n decimalChainId = convertHexToDecimal(networkClient.configuration.chainId);\n\n try {\n const result = await this.messagingSystem.call(\n 'NetworkController:getEIP1559Compatibility',\n networkClientId,\n );\n isEIP1559Compatible = result || false;\n } catch {\n isEIP1559Compatible = false;\n }\n ethQuery = new EthQuery(networkClient.provider);\n }\n\n ethQuery ??= this.ethQuery;\n\n isLegacyGasAPICompatible ??=\n this.getCurrentNetworkLegacyGasAPICompatibility();\n\n decimalChainId ??= convertHexToDecimal(this.currentChainId);\n\n try {\n isEIP1559Compatible ??= await this.getEIP1559Compatibility();\n } catch (e) {\n console.error(e);\n isEIP1559Compatible ??= false;\n }\n\n const gasFeeCalculations = await determineGasFeeCalculations({\n isEIP1559Compatible,\n isLegacyGasAPICompatible,\n fetchGasEstimates,\n fetchGasEstimatesUrl: this.EIP1559APIEndpoint.replace(\n '<chain_id>',\n `${decimalChainId}`,\n ),\n fetchLegacyGasPriceEstimates,\n fetchLegacyGasPriceEstimatesUrl: this.legacyAPIEndpoint.replace(\n '<chain_id>',\n `${decimalChainId}`,\n ),\n fetchEthGasPriceEstimate,\n calculateTimeEstimate,\n clientId: this.clientId,\n ethQuery,\n infuraAPIKey: this.infuraAPIKey,\n nonRPCGasFeeApisDisabled: this.state.nonRPCGasFeeApisDisabled,\n });\n\n if (shouldUpdateState) {\n const chainId = toHex(decimalChainId);\n this.update((state) => {\n if (this.currentChainId === chainId) {\n state.gasFeeEstimates = gasFeeCalculations.gasFeeEstimates;\n state.estimatedGasFeeTimeBounds =\n gasFeeCalculations.estimatedGasFeeTimeBounds;\n state.gasEstimateType = gasFeeCalculations.gasEstimateType;\n }\n state.gasFeeEstimatesByChainId ??= {};\n state.gasFeeEstimatesByChainId[chainId] = {\n gasFeeEstimates: gasFeeCalculations.gasFeeEstimates,\n estimatedGasFeeTimeBounds:\n gasFeeCalculations.estimatedGasFeeTimeBounds,\n gasEstimateType: gasFeeCalculations.gasEstimateType,\n } as SingleChainGasFeeState;\n });\n }\n\n return gasFeeCalculations;\n }\n\n /**\n * Remove the poll token, and stop polling if the set of poll tokens is empty.\n *\n * @param pollToken - The poll token to disconnect.\n */\n disconnectPoller(pollToken: string) {\n this.pollTokens.delete(pollToken);\n if (this.pollTokens.size === 0) {\n this.stopPolling();\n }\n }\n\n stopPolling() {\n if (this.intervalId) {\n clearInterval(this.intervalId);\n }\n this.pollTokens.clear();\n this.resetState();\n }\n\n /**\n * Prepare to discard this controller.\n *\n * This stops any active polling.\n */\n override destroy() {\n super.destroy();\n this.stopPolling();\n }\n\n private _poll() {\n if (this.intervalId) {\n clearInterval(this.intervalId);\n }\n\n this.intervalId = setInterval(async () => {\n await safelyExecute(() => this._fetchGasFeeEstimateData());\n }, this.intervalDelay);\n }\n\n /**\n * Fetching token list from the Token Service API.\n *\n * @private\n * @param networkClientId - The ID of the network client triggering the fetch.\n * @returns A promise that resolves when this operation completes.\n */\n async _executePoll(networkClientId: string): Promise<void> {\n await this._fetchGasFeeEstimateData({ networkClientId });\n }\n\n private resetState() {\n this.update(() => {\n return defaultState;\n });\n }\n\n private async getEIP1559Compatibility() {\n const currentNetworkIsEIP1559Compatible =\n await this.getCurrentNetworkEIP1559Compatibility();\n const currentAccountIsEIP1559Compatible =\n this.getCurrentAccountEIP1559Compatibility?.() ?? true;\n\n return (\n currentNetworkIsEIP1559Compatible && currentAccountIsEIP1559Compatible\n );\n }\n\n getTimeEstimate(\n maxPriorityFeePerGas: string,\n maxFeePerGas: string,\n ): EstimatedGasFeeTimeBounds | Record<string, never> {\n if (\n !this.state.gasFeeEstimates ||\n this.state.gasEstimateType !== GAS_ESTIMATE_TYPES.FEE_MARKET\n ) {\n return {};\n }\n return calculateTimeEstimate(\n maxPriorityFeePerGas,\n maxFeePerGas,\n this.state.gasFeeEstimates,\n );\n }\n\n async #onNetworkControllerDidChange(networkControllerState: NetworkState) {\n const newChainId = networkControllerState.providerConfig.chainId;\n\n if (newChainId !== this.currentChainId) {\n this.ethQuery = new EthQuery(this.#getProvider());\n await this.resetPolling();\n\n this.currentChainId = newChainId;\n }\n }\n\n enableNonRPCGasFeeApis() {\n this.update((state) => {\n state.nonRPCGasFeeApisDisabled = false;\n });\n }\n\n disableNonRPCGasFeeApis() {\n this.update((state) => {\n state.nonRPCGasFeeApisDisabled = true;\n });\n }\n}\n\nexport default GasFeeController;\n","import type {\n EstimatedGasFeeTimeBounds,\n EthGasPriceEstimate,\n GasFeeEstimates,\n GasFeeState as GasFeeCalculations,\n LegacyGasPriceEstimate,\n} from './GasFeeController';\nimport { GAS_ESTIMATE_TYPES } from './GasFeeController';\n\ntype DetermineGasFeeCalculationsRequest = {\n isEIP1559Compatible: boolean;\n isLegacyGasAPICompatible: boolean;\n fetchGasEstimates: (\n url: string,\n infuraAPIKey: string,\n clientId?: string,\n ) => Promise<GasFeeEstimates>;\n fetchGasEstimatesUrl: string;\n fetchLegacyGasPriceEstimates: (\n url: string,\n infuraAPIKey: string,\n clientId?: string,\n ) => Promise<LegacyGasPriceEstimate>;\n fetchLegacyGasPriceEstimatesUrl: string;\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n fetchEthGasPriceEstimate: (ethQuery: any) => Promise<EthGasPriceEstimate>;\n calculateTimeEstimate: (\n maxPriorityFeePerGas: string,\n maxFeePerGas: string,\n gasFeeEstimates: GasFeeEstimates,\n ) => EstimatedGasFeeTimeBounds;\n clientId: string | undefined;\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ethQuery: any;\n infuraAPIKey: string;\n nonRPCGasFeeApisDisabled?: boolean;\n};\n\n/**\n * Obtains a set of max base and priority fee estimates along with time estimates so that we\n * can present them to users when they are sending transactions or making swaps.\n *\n * @param args - The arguments.\n * @param args.isEIP1559Compatible - Governs whether or not we can use an EIP-1559-only method to\n * produce estimates.\n * @param args.isLegacyGasAPICompatible - Governs whether or not we can use a non-EIP-1559 method to\n * produce estimates (for instance, testnets do not support estimates altogether).\n * @param args.fetchGasEstimates - A function that fetches gas estimates using an EIP-1559-specific\n * API.\n * @param args.fetchGasEstimatesUrl - The URL for the API we can use to obtain EIP-1559-specific\n * estimates.\n * @param args.fetchLegacyGasPriceEstimates - A function that fetches gas estimates using an\n * non-EIP-1559-specific API.\n * @param args.fetchLegacyGasPriceEstimatesUrl - The URL for the API we can use to obtain\n * non-EIP-1559-specific estimates.\n * @param args.fetchEthGasPriceEstimate - A function that fetches gas estimates using\n * `eth_gasPrice`.\n * @param args.calculateTimeEstimate - A function that determine time estimate bounds.\n * @param args.clientId - An identifier that an API can use to know who is asking for estimates.\n * @param args.ethQuery - An EthQuery instance we can use to talk to Ethereum directly.\n * @param args.infuraAPIKey - Infura API key to use for requests to Infura.\n * @param args.nonRPCGasFeeApisDisabled - Whether to disable requests to the legacyAPIEndpoint and the EIP1559APIEndpoint\n * @returns The gas fee calculations.\n */\nexport default async function determineGasFeeCalculations(\n args: DetermineGasFeeCalculationsRequest,\n): Promise<GasFeeCalculations> {\n try {\n return await getEstimatesUsingFallbacks(args);\n } catch (error) {\n if (error instanceof Error) {\n throw new Error(\n `Gas fee/price estimation failed. Message: ${error.message}`,\n );\n }\n\n throw error;\n }\n}\n\n/**\n * Retrieve the gas fee estimates using a series of fallback mechanisms.\n * @param request - The request object.\n * @returns The gas fee estimates.\n */\nasync function getEstimatesUsingFallbacks(\n request: DetermineGasFeeCalculationsRequest,\n): Promise<GasFeeCalculations> {\n const {\n isEIP1559Compatible,\n isLegacyGasAPICompatible,\n nonRPCGasFeeApisDisabled,\n } = request;\n\n try {\n if (isEIP1559Compatible && !nonRPCGasFeeApisDisabled) {\n return await getEstimatesUsingFeeMarketEndpoint(request);\n }\n\n if (isLegacyGasAPICompatible && !nonRPCGasFeeApisDisabled) {\n return await getEstimatesUsingLegacyEndpoint(request);\n }\n\n throw new Error('Main gas fee/price estimation failed. Use fallback');\n } catch {\n return await getEstimatesUsingProvider(request);\n }\n}\n\n/**\n * Retrieve gas fee estimates using the EIP-1559 endpoint of the gas API.\n * @param request - The request object.\n * @returns The gas fee estimates.\n */\nasync function getEstimatesUsingFeeMarketEndpoint(\n request: DetermineGasFeeCalculationsRequest,\n): Promise<GasFeeCalculations> {\n const {\n fetchGasEstimates,\n fetchGasEstimatesUrl,\n infuraAPIKey,\n clientId,\n calculateTimeEstimate,\n } = request;\n\n const estimates = await fetchGasEstimates(\n fetchGasEstimatesUrl,\n infuraAPIKey,\n clientId,\n );\n\n const { suggestedMaxPriorityFeePerGas, suggestedMaxFeePerGas } =\n estimates.medium;\n\n const estimatedGasFeeTimeBounds = calculateTimeEstimate(\n suggestedMaxPriorityFeePerGas,\n suggestedMaxFeePerGas,\n estimates,\n );\n\n return {\n gasFeeEstimates: estimates,\n estimatedGasFeeTimeBounds,\n gasEstimateType: GAS_ESTIMATE_TYPES.FEE_MARKET,\n };\n}\n\n/**\n * Retrieve gas fee estimates using the legacy endpoint of the gas API.\n * @param request - The request object.\n * @returns The gas fee estimates.\n */\nasync function getEstimatesUsingLegacyEndpoint(\n request: DetermineGasFeeCalculationsRequest,\n): Promise<GasFeeCalculations> {\n const {\n fetchLegacyGasPriceEstimates,\n fetchLegacyGasPriceEstimatesUrl,\n infuraAPIKey,\n clientId,\n } = request;\n\n const estimates = await fetchLegacyGasPriceEstimates(\n fetchLegacyGasPriceEstimatesUrl,\n infuraAPIKey,\n clientId,\n );\n\n return {\n gasFeeEstimates: estimates,\n estimatedGasFeeTimeBounds: {},\n gasEstimateType: GAS_ESTIMATE_TYPES.LEGACY,\n };\n}\n\n/**\n * Retrieve gas fee estimates using an `eth_gasPrice` call to the RPC provider.\n * @param request - The request object.\n * @returns The gas fee estimates.\n */\nasync function getEstimatesUsingProvider(\n request: DetermineGasFeeCalculationsRequest,\n): Promise<GasFeeCalculations> {\n const { ethQuery, fetchEthGasPriceEstimate } = request;\n\n const estimates = await fetchEthGasPriceEstimate(ethQuery);\n\n return {\n gasFeeEstimates: estimates,\n estimatedGasFeeTimeBounds: {},\n gasEstimateType: GAS_ESTIMATE_TYPES.ETH_GASPRICE,\n };\n}\n"],"mappings":";;;;;;;;;;;;AAKA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,O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A,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,uBAAAC;AAAA,EACF,IAAI;AAEJ,QAAM,YAAY,MAAMD;AAAA,IACtB;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,QAAM,EAAE,+BAA+B,sBAAsB,IAC3D,UAAU;AAEZ,QAAM,4BAA4BC;AAAA,IAChC;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,SAAO;AAAA,IACL,iBAAiB;AAAA,IACjB;AAAA,IACA,iBAAiB,mBAAmB;AAAA,EACtC;AACF;AAOA,eAAe,gCACb,SAC6B;AAC7B,QAAM;AAAA,IACJ,8BAAAC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AAEJ,QAAM,YAAY,MAAMA;AAAA,IACtB;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,SAAO;AAAA,IACL,iBAAiB;AAAA,IACjB,2BAA2B,CAAC;AAAA,IAC5B,iBAAiB,mBAAmB;AAAA,EACtC;AACF;AAOA,eAAe,0BACb,SAC6B;AAC7B,QAAM,EAAE,UAAU,0BAAAC,0BAAyB,IAAI;AAE/C,QAAM,YAAY,MAAMA,0BAAyB,QAAQ;AAEzD,SAAO;AAAA,IACL,iBAAiB;AAAA,IACjB,2BAA2B,CAAC;AAAA,IAC5B,iBAAiB,mBAAmB;AAAA,EACtC;AACF;","names":["fetchGasEstimates","calculateTimeEstimate","fetchLegacyGasPriceEstimates","fetchEthGasPriceEstimate"]}
@@ -1,18 +1,13 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2
2
 
3
- var _chunkEZVGDV5Hjs = require('./chunk-EZVGDV5H.js');
4
3
 
5
4
 
6
5
 
7
6
 
8
7
 
9
- var _chunkNARPHUTRjs = require('./chunk-NARPHUTR.js');
10
8
 
11
9
 
12
-
13
-
14
-
15
- var _chunkZ4BLTVTBjs = require('./chunk-Z4BLTVTB.js');
10
+ var _chunkQ2YPK5SLjs = require('./chunk-Q2YPK5SL.js');
16
11
 
17
12
  // src/GasFeeController.ts
18
13
 
@@ -37,7 +32,8 @@ var metadata = {
37
32
  },
38
33
  gasFeeEstimates: { persist: true, anonymous: false },
39
34
  estimatedGasFeeTimeBounds: { persist: true, anonymous: false },
40
- gasEstimateType: { persist: true, anonymous: false }
35
+ gasEstimateType: { persist: true, anonymous: false },
36
+ nonRPCGasFeeApisDisabled: { persist: true, anonymous: false }
41
37
  };
42
38
  var name = "GasFeeController";
43
39
  var defaultState = {
@@ -89,24 +85,24 @@ var GasFeeController = class extends _pollingcontroller.StaticIntervalPollingCon
89
85
  messenger,
90
86
  state: { ...defaultState, ...state }
91
87
  });
92
- _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _onNetworkControllerDidChange);
93
- _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _getProvider, void 0);
88
+ _chunkQ2YPK5SLjs.__privateAdd.call(void 0, this, _onNetworkControllerDidChange);
89
+ _chunkQ2YPK5SLjs.__privateAdd.call(void 0, this, _getProvider, void 0);
94
90
  this.intervalDelay = interval;
95
91
  this.setIntervalLength(interval);
96
92
  this.pollTokens = /* @__PURE__ */ new Set();
97
93
  this.getCurrentNetworkEIP1559Compatibility = getCurrentNetworkEIP1559Compatibility;
98
94
  this.getCurrentNetworkLegacyGasAPICompatibility = getCurrentNetworkLegacyGasAPICompatibility;
99
95
  this.getCurrentAccountEIP1559Compatibility = getCurrentAccountEIP1559Compatibility;
100
- _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _getProvider, getProvider);
96
+ _chunkQ2YPK5SLjs.__privateSet.call(void 0, this, _getProvider, getProvider);
101
97
  this.EIP1559APIEndpoint = `${GAS_API_BASE_URL}/networks/<chain_id>/suggestedGasFees`;
102
98
  this.legacyAPIEndpoint = `${GAS_API_BASE_URL}/networks/<chain_id>/gasPrices`;
103
99
  this.clientId = clientId;
104
100
  this.infuraAPIKey = infuraAPIKey;
105
- this.ethQuery = new (0, _ethquery2.default)(_chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _getProvider).call(this));
101
+ this.ethQuery = new (0, _ethquery2.default)(_chunkQ2YPK5SLjs.__privateGet.call(void 0, this, _getProvider).call(this));
106
102
  if (onNetworkDidChange && getChainId) {
107
103
  this.currentChainId = getChainId();
108
104
  onNetworkDidChange(async (networkControllerState) => {
109
- await _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _onNetworkControllerDidChange, onNetworkControllerDidChange_fn).call(this, networkControllerState);
105
+ await _chunkQ2YPK5SLjs.__privateMethod.call(void 0, this, _onNetworkControllerDidChange, onNetworkControllerDidChange_fn).call(this, networkControllerState);
110
106
  });
111
107
  } else {
112
108
  this.currentChainId = this.messagingSystem.call(
@@ -115,7 +111,7 @@ var GasFeeController = class extends _pollingcontroller.StaticIntervalPollingCon
115
111
  this.messagingSystem.subscribe(
116
112
  "NetworkController:networkDidChange",
117
113
  async (networkControllerState) => {
118
- await _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _onNetworkControllerDidChange, onNetworkControllerDidChange_fn).call(this, networkControllerState);
114
+ await _chunkQ2YPK5SLjs.__privateMethod.call(void 0, this, _onNetworkControllerDidChange, onNetworkControllerDidChange_fn).call(this, networkControllerState);
119
115
  }
120
116
  );
121
117
  }
@@ -183,19 +179,18 @@ var GasFeeController = class extends _pollingcontroller.StaticIntervalPollingCon
183
179
  const gasFeeCalculations = await determineGasFeeCalculations({
184
180
  isEIP1559Compatible,
185
181
  isLegacyGasAPICompatible,
186
- fetchGasEstimates: _chunkNARPHUTRjs.fetchGasEstimates,
182
+ fetchGasEstimates: _chunkQ2YPK5SLjs.fetchGasEstimates,
187
183
  fetchGasEstimatesUrl: this.EIP1559APIEndpoint.replace(
188
184
  "<chain_id>",
189
185
  `${decimalChainId}`
190
186
  ),
191
- fetchGasEstimatesViaEthFeeHistory: _chunkEZVGDV5Hjs.fetchGasEstimatesViaEthFeeHistory,
192
- fetchLegacyGasPriceEstimates: _chunkNARPHUTRjs.fetchLegacyGasPriceEstimates,
187
+ fetchLegacyGasPriceEstimates: _chunkQ2YPK5SLjs.fetchLegacyGasPriceEstimates,
193
188
  fetchLegacyGasPriceEstimatesUrl: this.legacyAPIEndpoint.replace(
194
189
  "<chain_id>",
195
190
  `${decimalChainId}`
196
191
  ),
197
- fetchEthGasPriceEstimate: _chunkNARPHUTRjs.fetchEthGasPriceEstimate,
198
- calculateTimeEstimate: _chunkNARPHUTRjs.calculateTimeEstimate,
192
+ fetchEthGasPriceEstimate: _chunkQ2YPK5SLjs.fetchEthGasPriceEstimate,
193
+ calculateTimeEstimate: _chunkQ2YPK5SLjs.calculateTimeEstimate,
199
194
  clientId: this.clientId,
200
195
  ethQuery,
201
196
  infuraAPIKey: this.infuraAPIKey,
@@ -278,7 +273,7 @@ var GasFeeController = class extends _pollingcontroller.StaticIntervalPollingCon
278
273
  if (!this.state.gasFeeEstimates || this.state.gasEstimateType !== GAS_ESTIMATE_TYPES.FEE_MARKET) {
279
274
  return {};
280
275
  }
281
- return _chunkNARPHUTRjs.calculateTimeEstimate.call(void 0,
276
+ return _chunkQ2YPK5SLjs.calculateTimeEstimate.call(void 0,
282
277
  maxPriorityFeePerGas,
283
278
  maxFeePerGas,
284
279
  this.state.gasFeeEstimates
@@ -300,7 +295,7 @@ _onNetworkControllerDidChange = new WeakSet();
300
295
  onNetworkControllerDidChange_fn = async function(networkControllerState) {
301
296
  const newChainId = networkControllerState.providerConfig.chainId;
302
297
  if (newChainId !== this.currentChainId) {
303
- this.ethQuery = new (0, _ethquery2.default)(_chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _getProvider).call(this));
298
+ this.ethQuery = new (0, _ethquery2.default)(_chunkQ2YPK5SLjs.__privateGet.call(void 0, this, _getProvider).call(this));
304
299
  await this.resetPolling();
305
300
  this.currentChainId = newChainId;
306
301
  }
@@ -308,79 +303,88 @@ onNetworkControllerDidChange_fn = async function(networkControllerState) {
308
303
  var GasFeeController_default = GasFeeController;
309
304
 
310
305
  // src/determineGasFeeCalculations.ts
311
- async function determineGasFeeCalculations({
312
- isEIP1559Compatible,
313
- isLegacyGasAPICompatible,
314
- fetchGasEstimates: fetchGasEstimates2,
315
- fetchGasEstimatesUrl,
316
- fetchGasEstimatesViaEthFeeHistory: fetchGasEstimatesViaEthFeeHistory2,
317
- fetchLegacyGasPriceEstimates: fetchLegacyGasPriceEstimates2,
318
- fetchLegacyGasPriceEstimatesUrl,
319
- fetchEthGasPriceEstimate: fetchEthGasPriceEstimate2,
320
- calculateTimeEstimate: calculateTimeEstimate2,
321
- clientId,
322
- ethQuery,
323
- infuraAPIKey,
324
- nonRPCGasFeeApisDisabled = false
325
- }) {
306
+ async function determineGasFeeCalculations(args) {
326
307
  try {
327
- if (isEIP1559Compatible) {
328
- let estimates;
329
- if (nonRPCGasFeeApisDisabled) {
330
- estimates = await fetchGasEstimatesViaEthFeeHistory2(ethQuery);
331
- } else {
332
- try {
333
- estimates = await fetchGasEstimates2(
334
- fetchGasEstimatesUrl,
335
- infuraAPIKey,
336
- clientId
337
- );
338
- } catch {
339
- estimates = await fetchGasEstimatesViaEthFeeHistory2(ethQuery);
340
- }
341
- }
342
- const { suggestedMaxPriorityFeePerGas, suggestedMaxFeePerGas } = estimates.medium;
343
- const estimatedGasFeeTimeBounds = calculateTimeEstimate2(
344
- suggestedMaxPriorityFeePerGas,
345
- suggestedMaxFeePerGas,
346
- estimates
308
+ return await getEstimatesUsingFallbacks(args);
309
+ } catch (error) {
310
+ if (error instanceof Error) {
311
+ throw new Error(
312
+ `Gas fee/price estimation failed. Message: ${error.message}`
347
313
  );
348
- return {
349
- gasFeeEstimates: estimates,
350
- estimatedGasFeeTimeBounds,
351
- gasEstimateType: GAS_ESTIMATE_TYPES.FEE_MARKET
352
- };
353
- } else if (isLegacyGasAPICompatible && !nonRPCGasFeeApisDisabled) {
354
- const estimates = await fetchLegacyGasPriceEstimates2(
355
- fetchLegacyGasPriceEstimatesUrl,
356
- infuraAPIKey,
357
- clientId
358
- );
359
- return {
360
- gasFeeEstimates: estimates,
361
- estimatedGasFeeTimeBounds: {},
362
- gasEstimateType: GAS_ESTIMATE_TYPES.LEGACY
363
- };
314
+ }
315
+ throw error;
316
+ }
317
+ }
318
+ async function getEstimatesUsingFallbacks(request) {
319
+ const {
320
+ isEIP1559Compatible,
321
+ isLegacyGasAPICompatible,
322
+ nonRPCGasFeeApisDisabled
323
+ } = request;
324
+ try {
325
+ if (isEIP1559Compatible && !nonRPCGasFeeApisDisabled) {
326
+ return await getEstimatesUsingFeeMarketEndpoint(request);
327
+ }
328
+ if (isLegacyGasAPICompatible && !nonRPCGasFeeApisDisabled) {
329
+ return await getEstimatesUsingLegacyEndpoint(request);
364
330
  }
365
331
  throw new Error("Main gas fee/price estimation failed. Use fallback");
366
332
  } catch {
367
- try {
368
- const estimates = await fetchEthGasPriceEstimate2(ethQuery);
369
- return {
370
- gasFeeEstimates: estimates,
371
- estimatedGasFeeTimeBounds: {},
372
- gasEstimateType: GAS_ESTIMATE_TYPES.ETH_GASPRICE
373
- };
374
- } catch (error) {
375
- if (error instanceof Error) {
376
- throw new Error(
377
- `Gas fee/price estimation failed. Message: ${error.message}`
378
- );
379
- }
380
- throw error;
381
- }
333
+ return await getEstimatesUsingProvider(request);
382
334
  }
383
335
  }
336
+ async function getEstimatesUsingFeeMarketEndpoint(request) {
337
+ const {
338
+ fetchGasEstimates: fetchGasEstimates2,
339
+ fetchGasEstimatesUrl,
340
+ infuraAPIKey,
341
+ clientId,
342
+ calculateTimeEstimate: calculateTimeEstimate2
343
+ } = request;
344
+ const estimates = await fetchGasEstimates2(
345
+ fetchGasEstimatesUrl,
346
+ infuraAPIKey,
347
+ clientId
348
+ );
349
+ const { suggestedMaxPriorityFeePerGas, suggestedMaxFeePerGas } = estimates.medium;
350
+ const estimatedGasFeeTimeBounds = calculateTimeEstimate2(
351
+ suggestedMaxPriorityFeePerGas,
352
+ suggestedMaxFeePerGas,
353
+ estimates
354
+ );
355
+ return {
356
+ gasFeeEstimates: estimates,
357
+ estimatedGasFeeTimeBounds,
358
+ gasEstimateType: GAS_ESTIMATE_TYPES.FEE_MARKET
359
+ };
360
+ }
361
+ async function getEstimatesUsingLegacyEndpoint(request) {
362
+ const {
363
+ fetchLegacyGasPriceEstimates: fetchLegacyGasPriceEstimates2,
364
+ fetchLegacyGasPriceEstimatesUrl,
365
+ infuraAPIKey,
366
+ clientId
367
+ } = request;
368
+ const estimates = await fetchLegacyGasPriceEstimates2(
369
+ fetchLegacyGasPriceEstimatesUrl,
370
+ infuraAPIKey,
371
+ clientId
372
+ );
373
+ return {
374
+ gasFeeEstimates: estimates,
375
+ estimatedGasFeeTimeBounds: {},
376
+ gasEstimateType: GAS_ESTIMATE_TYPES.LEGACY
377
+ };
378
+ }
379
+ async function getEstimatesUsingProvider(request) {
380
+ const { ethQuery, fetchEthGasPriceEstimate: fetchEthGasPriceEstimate2 } = request;
381
+ const estimates = await fetchEthGasPriceEstimate2(ethQuery);
382
+ return {
383
+ gasFeeEstimates: estimates,
384
+ estimatedGasFeeTimeBounds: {},
385
+ gasEstimateType: GAS_ESTIMATE_TYPES.ETH_GASPRICE
386
+ };
387
+ }
384
388
 
385
389
 
386
390
 
@@ -389,4 +393,4 @@ async function determineGasFeeCalculations({
389
393
 
390
394
 
391
395
  exports.determineGasFeeCalculations = determineGasFeeCalculations; exports.GAS_API_BASE_URL = GAS_API_BASE_URL; exports.GAS_ESTIMATE_TYPES = GAS_ESTIMATE_TYPES; exports.GasFeeController = GasFeeController; exports.GasFeeController_default = GasFeeController_default;
392
- //# sourceMappingURL=chunk-QKQ22L3U.js.map
396
+ //# sourceMappingURL=chunk-H5WHAYLI.js.map