@metamask/gas-fee-controller 16.0.0 → 18.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.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [18.0.0]
11
+
12
+ ### Added
13
+
14
+ - **BREAKING:** Add constructor options to `GasFeeController`: `EIP1559APIEndpoint` (required), and `legacyAPIEndpoint` (optional) which defaults to `LEGACY_GAS_PRICES_API_URL`. ([#4446](https://github.com/MetaMask/core/pull/4446))
15
+ - These URLs are no longer hardcoded within the controller.
16
+
17
+ ### Removed
18
+
19
+ - **BREAKING:** Remove `infuraAPIKey` as a constructor option for `GasFeeController`. This class field was previously used to construct and send the `Authorization` header for Infura gas API requests. ([#4446](https://github.com/MetaMask/core/pull/4446))
20
+
21
+ ## [17.0.0]
22
+
23
+ ### Changed
24
+
25
+ - **BREAKING:** Bump minimum Node version to 18.18 ([#3611](https://github.com/MetaMask/core/pull/3611))
26
+ - **BREAKING:** Bump dependency and peer dependency `@metamask/network-controller` to `^19.0.0` ([#4352](https://github.com/MetaMask/core/pull/4352))
27
+ - Bump `@metamask/base-controller` to `^6.0.0` ([#4352](https://github.com/MetaMask/core/pull/4352))
28
+ - Bump `@metamask/controller-utils` to `^11.0.0` ([#4352](https://github.com/MetaMask/core/pull/4352))
29
+ - Bump `@metamask/polling-controller` to `^8.0.0` ([#4352](https://github.com/MetaMask/core/pull/4352))
30
+
10
31
  ## [16.0.0]
11
32
 
12
33
  ### Changed
@@ -283,7 +304,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
283
304
 
284
305
  All changes listed after this point were applied to this package following the monorepo conversion.
285
306
 
286
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@16.0.0...HEAD
307
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@18.0.0...HEAD
308
+ [18.0.0]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@17.0.0...@metamask/gas-fee-controller@18.0.0
309
+ [17.0.0]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@16.0.0...@metamask/gas-fee-controller@17.0.0
287
310
  [16.0.0]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@15.1.2...@metamask/gas-fee-controller@16.0.0
288
311
  [15.1.2]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@15.1.1...@metamask/gas-fee-controller@15.1.2
289
312
  [15.1.1]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@15.1.0...@metamask/gas-fee-controller@15.1.1
@@ -3,12 +3,12 @@
3
3
 
4
4
 
5
5
 
6
- var _chunkH5WHAYLIjs = require('./chunk-H5WHAYLI.js');
7
- require('./chunk-Q2YPK5SL.js');
6
+ var _chunkS5H5NUEHjs = require('./chunk-S5H5NUEH.js');
7
+ require('./chunk-2MFVV2BX.js');
8
8
 
9
9
 
10
10
 
11
11
 
12
12
 
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;
13
+ exports.GAS_ESTIMATE_TYPES = _chunkS5H5NUEHjs.GAS_ESTIMATE_TYPES; exports.GasFeeController = _chunkS5H5NUEHjs.GasFeeController; exports.LEGACY_GAS_PRICES_API_URL = _chunkS5H5NUEHjs.LEGACY_GAS_PRICES_API_URL; exports.default = _chunkS5H5NUEHjs.GasFeeController_default;
14
14
  //# sourceMappingURL=GasFeeController.js.map
@@ -1,14 +1,14 @@
1
1
  import {
2
- GAS_API_BASE_URL,
3
2
  GAS_ESTIMATE_TYPES,
4
3
  GasFeeController,
5
- GasFeeController_default
6
- } from "./chunk-BEVZS3YV.mjs";
7
- import "./chunk-KORLXV32.mjs";
4
+ GasFeeController_default,
5
+ LEGACY_GAS_PRICES_API_URL
6
+ } from "./chunk-WXXOCPNT.mjs";
7
+ import "./chunk-R3IOI7AK.mjs";
8
8
  export {
9
- GAS_API_BASE_URL,
10
9
  GAS_ESTIMATE_TYPES,
11
10
  GasFeeController,
11
+ LEGACY_GAS_PRICES_API_URL,
12
12
  GasFeeController_default as default
13
13
  };
14
14
  //# sourceMappingURL=GasFeeController.mjs.map
@@ -35,11 +35,11 @@ function normalizeGWEIDecimalNumbers(n) {
35
35
  const numberAsGWEI = _controllerutils.weiHexToGweiDec.call(void 0, numberAsWEIHex);
36
36
  return numberAsGWEI;
37
37
  }
38
- async function fetchGasEstimates(url, infuraAPIKey, clientId) {
39
- const infuraAuthToken = buildInfuraAuthToken(infuraAPIKey);
40
- const estimates = await _controllerutils.handleFetch.call(void 0, url, {
41
- headers: getHeaders(infuraAuthToken, clientId)
42
- });
38
+ async function fetchGasEstimates(url, clientId) {
39
+ const estimates = await _controllerutils.handleFetch.call(void 0,
40
+ url,
41
+ clientId ? { headers: makeClientIdHeader(clientId) } : void 0
42
+ );
43
43
  return {
44
44
  low: {
45
45
  ...estimates.low,
@@ -77,14 +77,16 @@ async function fetchGasEstimates(url, infuraAPIKey, clientId) {
77
77
  networkCongestion: estimates.networkCongestion
78
78
  };
79
79
  }
80
- async function fetchLegacyGasPriceEstimates(url, infuraAPIKey, clientId) {
81
- const infuraAuthToken = buildInfuraAuthToken(infuraAPIKey);
80
+ async function fetchLegacyGasPriceEstimates(url, clientId) {
82
81
  const result = await _controllerutils.handleFetch.call(void 0, url, {
83
82
  referrer: url,
84
83
  referrerPolicy: "no-referrer-when-downgrade",
85
84
  method: "GET",
86
85
  mode: "cors",
87
- headers: getHeaders(infuraAuthToken, clientId)
86
+ headers: {
87
+ "Content-Type": "application/json",
88
+ ...clientId && makeClientIdHeader(clientId)
89
+ }
88
90
  });
89
91
  return {
90
92
  low: result.SafeGasPrice,
@@ -139,17 +141,6 @@ function calculateTimeEstimate(maxPriorityFeePerGas, maxFeePerGas, gasFeeEstimat
139
141
  upperTimeBound
140
142
  };
141
143
  }
142
- function buildInfuraAuthToken(infuraAPIKey) {
143
- return Buffer.from(`${infuraAPIKey}:`).toString("base64");
144
- }
145
- function getHeaders(infuraAuthToken, clientId) {
146
- return {
147
- "Content-Type": "application/json",
148
- Authorization: `Basic ${infuraAuthToken}`,
149
- // Only add the clientId header if clientId is a non-empty string
150
- ...clientId?.trim() ? makeClientIdHeader(clientId) : {}
151
- };
152
- }
153
144
 
154
145
 
155
146
 
@@ -162,4 +153,4 @@ function getHeaders(infuraAuthToken, clientId) {
162
153
 
163
154
 
164
155
  exports.__privateGet = __privateGet; exports.__privateAdd = __privateAdd; exports.__privateSet = __privateSet; exports.__privateMethod = __privateMethod; exports.normalizeGWEIDecimalNumbers = normalizeGWEIDecimalNumbers; exports.fetchGasEstimates = fetchGasEstimates; exports.fetchLegacyGasPriceEstimates = fetchLegacyGasPriceEstimates; exports.fetchEthGasPriceEstimate = fetchEthGasPriceEstimate; exports.calculateTimeEstimate = calculateTimeEstimate;
165
- //# sourceMappingURL=chunk-Q2YPK5SL.js.map
156
+ //# sourceMappingURL=chunk-2MFVV2BX.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/gas-util.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,OAAO,QAAQ;AAUf,IAAM,qBAAqB,CAAC,cAAsB,EAAE,eAAe,SAAS;AAQrE,SAAS,4BAA4B,GAAoB;AAC9D,QAAM,iBAAiB,eAAe,CAAC,EAAE,SAAS,EAAE;AACpD,QAAM,eAAe,gBAAgB,cAAc;AACnD,SAAO;AACT;AASA,eAAsB,kBACpB,KACA,UAC0B;AAC1B,QAAM,YAAY,MAAM;AAAA,IACtB;AAAA,IACA,WAAW,EAAE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AAS;AAAA,EAC/C;AACF;AAUO,SAAS,sBACd,sBACA,cACA,iBAC2B;AAC3B,QAAM,EAAE,KAAK,QAAQ,MAAM,iBAAiB,IAAI;AAEhD,QAAM,4BAA4B,eAAe,oBAAoB;AACrE,QAAM,oBAAoB,eAAe,YAAY;AACrD,QAAM,wBAAwB,eAAe,gBAAgB;AAE7D,QAAM,0BAA0B,GAAG;AAAA,IACjC;AAAA,IACA,kBAAkB,IAAI,qBAAqB;AAAA,EAC7C;AAEA,QAAM,yBAAyB;AAAA,IAC7B,IAAI;AAAA,EACN;AACA,QAAM,4BAA4B;AAAA,IAChC,OAAO;AAAA,EACT;AACA,QAAM,0BAA0B;AAAA,IAC9B,KAAK;AAAA,EACP;AAEA,MAAI;AACJ,MAAI;AAEJ,MAAI,wBAAwB,GAAG,sBAAsB,GAAG;AACtD,qBAAiB;AACjB,qBAAiB;AAAA,EACnB,WACE,wBAAwB,IAAI,sBAAsB,KAClD,wBAAwB,GAAG,yBAAyB,GACpD;AACA,qBAAiB,IAAI;AACrB,qBAAiB,IAAI;AAAA,EACvB,WACE,wBAAwB,IAAI,yBAAyB,KACrD,wBAAwB,GAAG,uBAAuB,GAClD;AACA,qBAAiB,OAAO;AACxB,qBAAiB,OAAO;AAAA,EAC1B,WAAW,wBAAwB,GAAG,uBAAuB,GAAG;AAC9D,qBAAiB,KAAK;AACtB,qBAAiB,KAAK;AAAA,EACxB,OAAO;AACL,qBAAiB;AACjB,qBAAiB,KAAK;AAAA,EACxB;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF","sourcesContent":["import {\n query,\n handleFetch,\n gweiDecToWEIBN,\n weiHexToGweiDec,\n} from '@metamask/controller-utils';\nimport type EthQuery from '@metamask/eth-query';\nimport BN from 'bn.js';\n\nimport type {\n GasFeeEstimates,\n EthGasPriceEstimate,\n EstimatedGasFeeTimeBounds,\n unknownString,\n LegacyGasPriceEstimate,\n} from './GasFeeController';\n\nconst makeClientIdHeader = (clientId: string) => ({ 'X-Client-Id': clientId });\n\n/**\n * Convert a decimal GWEI value to a decimal string rounded to the nearest WEI.\n *\n * @param n - The input GWEI amount, as a decimal string or a number.\n * @returns The decimal string GWEI amount.\n */\nexport function normalizeGWEIDecimalNumbers(n: string | number) {\n const numberAsWEIHex = gweiDecToWEIBN(n).toString(16);\n const numberAsGWEI = weiHexToGweiDec(numberAsWEIHex);\n return numberAsGWEI;\n}\n\n/**\n * Fetch gas estimates from the given URL.\n *\n * @param url - The gas estimate URL.\n * @param clientId - The client ID used to identify to the API who is asking for estimates.\n * @returns The gas estimates.\n */\nexport async function fetchGasEstimates(\n url: string,\n clientId?: string,\n): Promise<GasFeeEstimates> {\n const estimates = await handleFetch(\n url,\n clientId ? { headers: makeClientIdHeader(clientId) } : undefined,\n );\n return {\n low: {\n ...estimates.low,\n suggestedMaxPriorityFeePerGas: normalizeGWEIDecimalNumbers(\n estimates.low.suggestedMaxPriorityFeePerGas,\n ),\n suggestedMaxFeePerGas: normalizeGWEIDecimalNumbers(\n estimates.low.suggestedMaxFeePerGas,\n ),\n },\n medium: {\n ...estimates.medium,\n suggestedMaxPriorityFeePerGas: normalizeGWEIDecimalNumbers(\n estimates.medium.suggestedMaxPriorityFeePerGas,\n ),\n suggestedMaxFeePerGas: normalizeGWEIDecimalNumbers(\n estimates.medium.suggestedMaxFeePerGas,\n ),\n },\n high: {\n ...estimates.high,\n suggestedMaxPriorityFeePerGas: normalizeGWEIDecimalNumbers(\n estimates.high.suggestedMaxPriorityFeePerGas,\n ),\n suggestedMaxFeePerGas: normalizeGWEIDecimalNumbers(\n estimates.high.suggestedMaxFeePerGas,\n ),\n },\n estimatedBaseFee: normalizeGWEIDecimalNumbers(estimates.estimatedBaseFee),\n historicalBaseFeeRange: estimates.historicalBaseFeeRange,\n baseFeeTrend: estimates.baseFeeTrend,\n latestPriorityFeeRange: estimates.latestPriorityFeeRange,\n historicalPriorityFeeRange: estimates.historicalPriorityFeeRange,\n priorityFeeTrend: estimates.priorityFeeTrend,\n networkCongestion: estimates.networkCongestion,\n };\n}\n\n/**\n * Hit the legacy MetaSwaps gasPrices estimate api and return the low, medium\n * high values from that API.\n *\n * @param url - The URL to fetch gas price estimates from.\n * @param clientId - The client ID used to identify to the API who is asking for estimates.\n * @returns The gas price estimates.\n */\nexport async function fetchLegacyGasPriceEstimates(\n url: string,\n clientId?: string,\n): Promise<LegacyGasPriceEstimate> {\n const result = await handleFetch(url, {\n referrer: url,\n referrerPolicy: 'no-referrer-when-downgrade',\n method: 'GET',\n mode: 'cors',\n headers: {\n 'Content-Type': 'application/json',\n ...(clientId && makeClientIdHeader(clientId)),\n },\n });\n return {\n low: result.SafeGasPrice,\n medium: result.ProposeGasPrice,\n high: result.FastGasPrice,\n };\n}\n\n/**\n * Get a gas price estimate from the network using the `eth_gasPrice` method.\n *\n * @param ethQuery - The EthQuery instance to call the network with.\n * @returns A gas price estimate.\n */\nexport async function fetchEthGasPriceEstimate(\n ethQuery: EthQuery,\n): Promise<EthGasPriceEstimate> {\n const gasPrice = await query(ethQuery, 'gasPrice');\n return {\n gasPrice: weiHexToGweiDec(gasPrice).toString(),\n };\n}\n\n/**\n * Estimate the time it will take for a transaction to be confirmed.\n *\n * @param maxPriorityFeePerGas - The max priority fee per gas.\n * @param maxFeePerGas - The max fee per gas.\n * @param gasFeeEstimates - The gas fee estimates.\n * @returns The estimated lower and upper bounds for when this transaction will be confirmed.\n */\nexport function calculateTimeEstimate(\n maxPriorityFeePerGas: string,\n maxFeePerGas: string,\n gasFeeEstimates: GasFeeEstimates,\n): EstimatedGasFeeTimeBounds {\n const { low, medium, high, estimatedBaseFee } = gasFeeEstimates;\n\n const maxPriorityFeePerGasInWEI = gweiDecToWEIBN(maxPriorityFeePerGas);\n const maxFeePerGasInWEI = gweiDecToWEIBN(maxFeePerGas);\n const estimatedBaseFeeInWEI = gweiDecToWEIBN(estimatedBaseFee);\n\n const effectiveMaxPriorityFee = BN.min(\n maxPriorityFeePerGasInWEI,\n maxFeePerGasInWEI.sub(estimatedBaseFeeInWEI),\n );\n\n const lowMaxPriorityFeeInWEI = gweiDecToWEIBN(\n low.suggestedMaxPriorityFeePerGas,\n );\n const mediumMaxPriorityFeeInWEI = gweiDecToWEIBN(\n medium.suggestedMaxPriorityFeePerGas,\n );\n const highMaxPriorityFeeInWEI = gweiDecToWEIBN(\n high.suggestedMaxPriorityFeePerGas,\n );\n\n let lowerTimeBound;\n let upperTimeBound;\n\n if (effectiveMaxPriorityFee.lt(lowMaxPriorityFeeInWEI)) {\n lowerTimeBound = null;\n upperTimeBound = 'unknown' as unknownString;\n } else if (\n effectiveMaxPriorityFee.gte(lowMaxPriorityFeeInWEI) &&\n effectiveMaxPriorityFee.lt(mediumMaxPriorityFeeInWEI)\n ) {\n lowerTimeBound = low.minWaitTimeEstimate;\n upperTimeBound = low.maxWaitTimeEstimate;\n } else if (\n effectiveMaxPriorityFee.gte(mediumMaxPriorityFeeInWEI) &&\n effectiveMaxPriorityFee.lt(highMaxPriorityFeeInWEI)\n ) {\n lowerTimeBound = medium.minWaitTimeEstimate;\n upperTimeBound = medium.maxWaitTimeEstimate;\n } else if (effectiveMaxPriorityFee.eq(highMaxPriorityFeeInWEI)) {\n lowerTimeBound = high.minWaitTimeEstimate;\n upperTimeBound = high.maxWaitTimeEstimate;\n } else {\n lowerTimeBound = 0;\n upperTimeBound = high.maxWaitTimeEstimate;\n }\n\n return {\n lowerTimeBound,\n upperTimeBound,\n };\n}\n"]}
@@ -35,11 +35,11 @@ function normalizeGWEIDecimalNumbers(n) {
35
35
  const numberAsGWEI = weiHexToGweiDec(numberAsWEIHex);
36
36
  return numberAsGWEI;
37
37
  }
38
- async function fetchGasEstimates(url, infuraAPIKey, clientId) {
39
- const infuraAuthToken = buildInfuraAuthToken(infuraAPIKey);
40
- const estimates = await handleFetch(url, {
41
- headers: getHeaders(infuraAuthToken, clientId)
42
- });
38
+ async function fetchGasEstimates(url, clientId) {
39
+ const estimates = await handleFetch(
40
+ url,
41
+ clientId ? { headers: makeClientIdHeader(clientId) } : void 0
42
+ );
43
43
  return {
44
44
  low: {
45
45
  ...estimates.low,
@@ -77,14 +77,16 @@ async function fetchGasEstimates(url, infuraAPIKey, clientId) {
77
77
  networkCongestion: estimates.networkCongestion
78
78
  };
79
79
  }
80
- async function fetchLegacyGasPriceEstimates(url, infuraAPIKey, clientId) {
81
- const infuraAuthToken = buildInfuraAuthToken(infuraAPIKey);
80
+ async function fetchLegacyGasPriceEstimates(url, clientId) {
82
81
  const result = await handleFetch(url, {
83
82
  referrer: url,
84
83
  referrerPolicy: "no-referrer-when-downgrade",
85
84
  method: "GET",
86
85
  mode: "cors",
87
- headers: getHeaders(infuraAuthToken, clientId)
86
+ headers: {
87
+ "Content-Type": "application/json",
88
+ ...clientId && makeClientIdHeader(clientId)
89
+ }
88
90
  });
89
91
  return {
90
92
  low: result.SafeGasPrice,
@@ -139,17 +141,6 @@ function calculateTimeEstimate(maxPriorityFeePerGas, maxFeePerGas, gasFeeEstimat
139
141
  upperTimeBound
140
142
  };
141
143
  }
142
- function buildInfuraAuthToken(infuraAPIKey) {
143
- return Buffer.from(`${infuraAPIKey}:`).toString("base64");
144
- }
145
- function getHeaders(infuraAuthToken, clientId) {
146
- return {
147
- "Content-Type": "application/json",
148
- Authorization: `Basic ${infuraAuthToken}`,
149
- // Only add the clientId header if clientId is a non-empty string
150
- ...clientId?.trim() ? makeClientIdHeader(clientId) : {}
151
- };
152
- }
153
144
 
154
145
  export {
155
146
  __privateGet,
@@ -162,4 +153,4 @@ export {
162
153
  fetchEthGasPriceEstimate,
163
154
  calculateTimeEstimate
164
155
  };
165
- //# sourceMappingURL=chunk-KORLXV32.mjs.map
156
+ //# sourceMappingURL=chunk-R3IOI7AK.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/gas-util.ts"],"sourcesContent":["import {\n query,\n handleFetch,\n gweiDecToWEIBN,\n weiHexToGweiDec,\n} from '@metamask/controller-utils';\nimport type EthQuery from '@metamask/eth-query';\nimport BN from 'bn.js';\n\nimport type {\n GasFeeEstimates,\n EthGasPriceEstimate,\n EstimatedGasFeeTimeBounds,\n unknownString,\n LegacyGasPriceEstimate,\n} from './GasFeeController';\n\nconst makeClientIdHeader = (clientId: string) => ({ 'X-Client-Id': clientId });\n\n/**\n * Convert a decimal GWEI value to a decimal string rounded to the nearest WEI.\n *\n * @param n - The input GWEI amount, as a decimal string or a number.\n * @returns The decimal string GWEI amount.\n */\nexport function normalizeGWEIDecimalNumbers(n: string | number) {\n const numberAsWEIHex = gweiDecToWEIBN(n).toString(16);\n const numberAsGWEI = weiHexToGweiDec(numberAsWEIHex);\n return numberAsGWEI;\n}\n\n/**\n * Fetch gas estimates from the given URL.\n *\n * @param url - The gas estimate URL.\n * @param clientId - The client ID used to identify to the API who is asking for estimates.\n * @returns The gas estimates.\n */\nexport async function fetchGasEstimates(\n url: string,\n clientId?: string,\n): Promise<GasFeeEstimates> {\n const estimates = await handleFetch(\n url,\n clientId ? { headers: makeClientIdHeader(clientId) } : undefined,\n );\n return {\n low: {\n ...estimates.low,\n suggestedMaxPriorityFeePerGas: normalizeGWEIDecimalNumbers(\n estimates.low.suggestedMaxPriorityFeePerGas,\n ),\n suggestedMaxFeePerGas: normalizeGWEIDecimalNumbers(\n estimates.low.suggestedMaxFeePerGas,\n ),\n },\n medium: {\n ...estimates.medium,\n suggestedMaxPriorityFeePerGas: normalizeGWEIDecimalNumbers(\n estimates.medium.suggestedMaxPriorityFeePerGas,\n ),\n suggestedMaxFeePerGas: normalizeGWEIDecimalNumbers(\n estimates.medium.suggestedMaxFeePerGas,\n ),\n },\n high: {\n ...estimates.high,\n suggestedMaxPriorityFeePerGas: normalizeGWEIDecimalNumbers(\n estimates.high.suggestedMaxPriorityFeePerGas,\n ),\n suggestedMaxFeePerGas: normalizeGWEIDecimalNumbers(\n estimates.high.suggestedMaxFeePerGas,\n ),\n },\n estimatedBaseFee: normalizeGWEIDecimalNumbers(estimates.estimatedBaseFee),\n historicalBaseFeeRange: estimates.historicalBaseFeeRange,\n baseFeeTrend: estimates.baseFeeTrend,\n latestPriorityFeeRange: estimates.latestPriorityFeeRange,\n historicalPriorityFeeRange: estimates.historicalPriorityFeeRange,\n priorityFeeTrend: estimates.priorityFeeTrend,\n networkCongestion: estimates.networkCongestion,\n };\n}\n\n/**\n * Hit the legacy MetaSwaps gasPrices estimate api and return the low, medium\n * high values from that API.\n *\n * @param url - The URL to fetch gas price estimates from.\n * @param clientId - The client ID used to identify to the API who is asking for estimates.\n * @returns The gas price estimates.\n */\nexport async function fetchLegacyGasPriceEstimates(\n url: string,\n clientId?: string,\n): Promise<LegacyGasPriceEstimate> {\n const result = await handleFetch(url, {\n referrer: url,\n referrerPolicy: 'no-referrer-when-downgrade',\n method: 'GET',\n mode: 'cors',\n headers: {\n 'Content-Type': 'application/json',\n ...(clientId && makeClientIdHeader(clientId)),\n },\n });\n return {\n low: result.SafeGasPrice,\n medium: result.ProposeGasPrice,\n high: result.FastGasPrice,\n };\n}\n\n/**\n * Get a gas price estimate from the network using the `eth_gasPrice` method.\n *\n * @param ethQuery - The EthQuery instance to call the network with.\n * @returns A gas price estimate.\n */\nexport async function fetchEthGasPriceEstimate(\n ethQuery: EthQuery,\n): Promise<EthGasPriceEstimate> {\n const gasPrice = await query(ethQuery, 'gasPrice');\n return {\n gasPrice: weiHexToGweiDec(gasPrice).toString(),\n };\n}\n\n/**\n * Estimate the time it will take for a transaction to be confirmed.\n *\n * @param maxPriorityFeePerGas - The max priority fee per gas.\n * @param maxFeePerGas - The max fee per gas.\n * @param gasFeeEstimates - The gas fee estimates.\n * @returns The estimated lower and upper bounds for when this transaction will be confirmed.\n */\nexport function calculateTimeEstimate(\n maxPriorityFeePerGas: string,\n maxFeePerGas: string,\n gasFeeEstimates: GasFeeEstimates,\n): EstimatedGasFeeTimeBounds {\n const { low, medium, high, estimatedBaseFee } = gasFeeEstimates;\n\n const maxPriorityFeePerGasInWEI = gweiDecToWEIBN(maxPriorityFeePerGas);\n const maxFeePerGasInWEI = gweiDecToWEIBN(maxFeePerGas);\n const estimatedBaseFeeInWEI = gweiDecToWEIBN(estimatedBaseFee);\n\n const effectiveMaxPriorityFee = BN.min(\n maxPriorityFeePerGasInWEI,\n maxFeePerGasInWEI.sub(estimatedBaseFeeInWEI),\n );\n\n const lowMaxPriorityFeeInWEI = gweiDecToWEIBN(\n low.suggestedMaxPriorityFeePerGas,\n );\n const mediumMaxPriorityFeeInWEI = gweiDecToWEIBN(\n medium.suggestedMaxPriorityFeePerGas,\n );\n const highMaxPriorityFeeInWEI = gweiDecToWEIBN(\n high.suggestedMaxPriorityFeePerGas,\n );\n\n let lowerTimeBound;\n let upperTimeBound;\n\n if (effectiveMaxPriorityFee.lt(lowMaxPriorityFeeInWEI)) {\n lowerTimeBound = null;\n upperTimeBound = 'unknown' as unknownString;\n } else if (\n effectiveMaxPriorityFee.gte(lowMaxPriorityFeeInWEI) &&\n effectiveMaxPriorityFee.lt(mediumMaxPriorityFeeInWEI)\n ) {\n lowerTimeBound = low.minWaitTimeEstimate;\n upperTimeBound = low.maxWaitTimeEstimate;\n } else if (\n effectiveMaxPriorityFee.gte(mediumMaxPriorityFeeInWEI) &&\n effectiveMaxPriorityFee.lt(highMaxPriorityFeeInWEI)\n ) {\n lowerTimeBound = medium.minWaitTimeEstimate;\n upperTimeBound = medium.maxWaitTimeEstimate;\n } else if (effectiveMaxPriorityFee.eq(highMaxPriorityFeeInWEI)) {\n lowerTimeBound = high.minWaitTimeEstimate;\n upperTimeBound = high.maxWaitTimeEstimate;\n } else {\n lowerTimeBound = 0;\n upperTimeBound = high.maxWaitTimeEstimate;\n }\n\n return {\n lowerTimeBound,\n upperTimeBound,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,OAAO,QAAQ;AAUf,IAAM,qBAAqB,CAAC,cAAsB,EAAE,eAAe,SAAS;AAQrE,SAAS,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 
10
- var _chunkQ2YPK5SLjs = require('./chunk-Q2YPK5SL.js');
10
+ var _chunk2MFVV2BXjs = require('./chunk-2MFVV2BX.js');
11
11
 
12
12
  // src/GasFeeController.ts
13
13
 
@@ -18,7 +18,7 @@ var _controllerutils = require('@metamask/controller-utils');
18
18
  var _ethquery = require('@metamask/eth-query'); var _ethquery2 = _interopRequireDefault(_ethquery);
19
19
  var _pollingcontroller = require('@metamask/polling-controller');
20
20
  var _uuid = require('uuid');
21
- var GAS_API_BASE_URL = "https://gas.api.infura.io";
21
+ var LEGACY_GAS_PRICES_API_URL = `https://api.metaswap.codefi.network/gasPrices`;
22
22
  var GAS_ESTIMATE_TYPES = {
23
23
  FEE_MARKET: "fee-market",
24
24
  LEGACY: "legacy",
@@ -62,9 +62,11 @@ var GasFeeController = class extends _pollingcontroller.StaticIntervalPollingCon
62
62
  * @param options.getProvider - Returns a network provider for the current network.
63
63
  * @param options.onNetworkDidChange - A function for registering an event handler for the
64
64
  * network state change event.
65
+ * @param options.legacyAPIEndpoint - The legacy gas price API URL. This option is primarily for
66
+ * testing purposes.
67
+ * @param options.EIP1559APIEndpoint - The EIP-1559 gas price API URL.
65
68
  * @param options.clientId - The client ID used to identify to the gas estimation API who is
66
69
  * asking for estimates.
67
- * @param options.infuraAPIKey - The Infura API key used for infura API requests.
68
70
  */
69
71
  constructor({
70
72
  interval = 15e3,
@@ -76,8 +78,9 @@ var GasFeeController = class extends _pollingcontroller.StaticIntervalPollingCon
76
78
  getCurrentNetworkLegacyGasAPICompatibility,
77
79
  getProvider,
78
80
  onNetworkDidChange,
79
- clientId,
80
- infuraAPIKey
81
+ legacyAPIEndpoint = LEGACY_GAS_PRICES_API_URL,
82
+ EIP1559APIEndpoint,
83
+ clientId
81
84
  }) {
82
85
  super({
83
86
  name,
@@ -85,33 +88,38 @@ var GasFeeController = class extends _pollingcontroller.StaticIntervalPollingCon
85
88
  messenger,
86
89
  state: { ...defaultState, ...state }
87
90
  });
88
- _chunkQ2YPK5SLjs.__privateAdd.call(void 0, this, _onNetworkControllerDidChange);
89
- _chunkQ2YPK5SLjs.__privateAdd.call(void 0, this, _getProvider, void 0);
91
+ _chunk2MFVV2BXjs.__privateAdd.call(void 0, this, _onNetworkControllerDidChange);
92
+ _chunk2MFVV2BXjs.__privateAdd.call(void 0, this, _getProvider, void 0);
90
93
  this.intervalDelay = interval;
91
94
  this.setIntervalLength(interval);
92
95
  this.pollTokens = /* @__PURE__ */ new Set();
93
96
  this.getCurrentNetworkEIP1559Compatibility = getCurrentNetworkEIP1559Compatibility;
94
97
  this.getCurrentNetworkLegacyGasAPICompatibility = getCurrentNetworkLegacyGasAPICompatibility;
95
98
  this.getCurrentAccountEIP1559Compatibility = getCurrentAccountEIP1559Compatibility;
96
- _chunkQ2YPK5SLjs.__privateSet.call(void 0, this, _getProvider, getProvider);
97
- this.EIP1559APIEndpoint = `${GAS_API_BASE_URL}/networks/<chain_id>/suggestedGasFees`;
98
- this.legacyAPIEndpoint = `${GAS_API_BASE_URL}/networks/<chain_id>/gasPrices`;
99
+ _chunk2MFVV2BXjs.__privateSet.call(void 0, this, _getProvider, getProvider);
100
+ this.EIP1559APIEndpoint = EIP1559APIEndpoint;
101
+ this.legacyAPIEndpoint = legacyAPIEndpoint;
99
102
  this.clientId = clientId;
100
- this.infuraAPIKey = infuraAPIKey;
101
- this.ethQuery = new (0, _ethquery2.default)(_chunkQ2YPK5SLjs.__privateGet.call(void 0, this, _getProvider).call(this));
103
+ this.ethQuery = new (0, _ethquery2.default)(_chunk2MFVV2BXjs.__privateGet.call(void 0, this, _getProvider).call(this));
102
104
  if (onNetworkDidChange && getChainId) {
103
105
  this.currentChainId = getChainId();
104
106
  onNetworkDidChange(async (networkControllerState) => {
105
- await _chunkQ2YPK5SLjs.__privateMethod.call(void 0, this, _onNetworkControllerDidChange, onNetworkControllerDidChange_fn).call(this, networkControllerState);
107
+ await _chunk2MFVV2BXjs.__privateMethod.call(void 0, this, _onNetworkControllerDidChange, onNetworkControllerDidChange_fn).call(this, networkControllerState);
106
108
  });
107
109
  } else {
108
- this.currentChainId = this.messagingSystem.call(
110
+ const { selectedNetworkClientId } = this.messagingSystem.call(
109
111
  "NetworkController:getState"
110
- ).providerConfig.chainId;
112
+ );
113
+ this.currentChainId = this.messagingSystem.call(
114
+ "NetworkController:getNetworkClientById",
115
+ selectedNetworkClientId
116
+ ).configuration.chainId;
111
117
  this.messagingSystem.subscribe(
112
118
  "NetworkController:networkDidChange",
119
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
120
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
113
121
  async (networkControllerState) => {
114
- await _chunkQ2YPK5SLjs.__privateMethod.call(void 0, this, _onNetworkControllerDidChange, onNetworkControllerDidChange_fn).call(this, networkControllerState);
122
+ await _chunk2MFVV2BXjs.__privateMethod.call(void 0, this, _onNetworkControllerDidChange, onNetworkControllerDidChange_fn).call(this, networkControllerState);
115
123
  }
116
124
  );
117
125
  }
@@ -179,21 +187,20 @@ var GasFeeController = class extends _pollingcontroller.StaticIntervalPollingCon
179
187
  const gasFeeCalculations = await determineGasFeeCalculations({
180
188
  isEIP1559Compatible,
181
189
  isLegacyGasAPICompatible,
182
- fetchGasEstimates: _chunkQ2YPK5SLjs.fetchGasEstimates,
190
+ fetchGasEstimates: _chunk2MFVV2BXjs.fetchGasEstimates,
183
191
  fetchGasEstimatesUrl: this.EIP1559APIEndpoint.replace(
184
192
  "<chain_id>",
185
193
  `${decimalChainId}`
186
194
  ),
187
- fetchLegacyGasPriceEstimates: _chunkQ2YPK5SLjs.fetchLegacyGasPriceEstimates,
195
+ fetchLegacyGasPriceEstimates: _chunk2MFVV2BXjs.fetchLegacyGasPriceEstimates,
188
196
  fetchLegacyGasPriceEstimatesUrl: this.legacyAPIEndpoint.replace(
189
197
  "<chain_id>",
190
198
  `${decimalChainId}`
191
199
  ),
192
- fetchEthGasPriceEstimate: _chunkQ2YPK5SLjs.fetchEthGasPriceEstimate,
193
- calculateTimeEstimate: _chunkQ2YPK5SLjs.calculateTimeEstimate,
200
+ fetchEthGasPriceEstimate: _chunk2MFVV2BXjs.fetchEthGasPriceEstimate,
201
+ calculateTimeEstimate: _chunk2MFVV2BXjs.calculateTimeEstimate,
194
202
  clientId: this.clientId,
195
203
  ethQuery,
196
- infuraAPIKey: this.infuraAPIKey,
197
204
  nonRPCGasFeeApisDisabled: this.state.nonRPCGasFeeApisDisabled
198
205
  });
199
206
  if (shouldUpdateState) {
@@ -273,7 +280,7 @@ var GasFeeController = class extends _pollingcontroller.StaticIntervalPollingCon
273
280
  if (!this.state.gasFeeEstimates || this.state.gasEstimateType !== GAS_ESTIMATE_TYPES.FEE_MARKET) {
274
281
  return {};
275
282
  }
276
- return _chunkQ2YPK5SLjs.calculateTimeEstimate.call(void 0,
283
+ return _chunk2MFVV2BXjs.calculateTimeEstimate.call(void 0,
277
284
  maxPriorityFeePerGas,
278
285
  maxFeePerGas,
279
286
  this.state.gasFeeEstimates
@@ -292,10 +299,15 @@ var GasFeeController = class extends _pollingcontroller.StaticIntervalPollingCon
292
299
  };
293
300
  _getProvider = new WeakMap();
294
301
  _onNetworkControllerDidChange = new WeakSet();
295
- onNetworkControllerDidChange_fn = async function(networkControllerState) {
296
- const newChainId = networkControllerState.providerConfig.chainId;
302
+ onNetworkControllerDidChange_fn = async function({
303
+ selectedNetworkClientId
304
+ }) {
305
+ const newChainId = this.messagingSystem.call(
306
+ "NetworkController:getNetworkClientById",
307
+ selectedNetworkClientId
308
+ ).configuration.chainId;
297
309
  if (newChainId !== this.currentChainId) {
298
- this.ethQuery = new (0, _ethquery2.default)(_chunkQ2YPK5SLjs.__privateGet.call(void 0, this, _getProvider).call(this));
310
+ this.ethQuery = new (0, _ethquery2.default)(_chunk2MFVV2BXjs.__privateGet.call(void 0, this, _getProvider).call(this));
299
311
  await this.resetPolling();
300
312
  this.currentChainId = newChainId;
301
313
  }
@@ -337,15 +349,10 @@ async function getEstimatesUsingFeeMarketEndpoint(request) {
337
349
  const {
338
350
  fetchGasEstimates: fetchGasEstimates2,
339
351
  fetchGasEstimatesUrl,
340
- infuraAPIKey,
341
352
  clientId,
342
353
  calculateTimeEstimate: calculateTimeEstimate2
343
354
  } = request;
344
- const estimates = await fetchGasEstimates2(
345
- fetchGasEstimatesUrl,
346
- infuraAPIKey,
347
- clientId
348
- );
355
+ const estimates = await fetchGasEstimates2(fetchGasEstimatesUrl, clientId);
349
356
  const { suggestedMaxPriorityFeePerGas, suggestedMaxFeePerGas } = estimates.medium;
350
357
  const estimatedGasFeeTimeBounds = calculateTimeEstimate2(
351
358
  suggestedMaxPriorityFeePerGas,
@@ -362,12 +369,10 @@ async function getEstimatesUsingLegacyEndpoint(request) {
362
369
  const {
363
370
  fetchLegacyGasPriceEstimates: fetchLegacyGasPriceEstimates2,
364
371
  fetchLegacyGasPriceEstimatesUrl,
365
- infuraAPIKey,
366
372
  clientId
367
373
  } = request;
368
374
  const estimates = await fetchLegacyGasPriceEstimates2(
369
375
  fetchLegacyGasPriceEstimatesUrl,
370
- infuraAPIKey,
371
376
  clientId
372
377
  );
373
378
  return {
@@ -392,5 +397,5 @@ async function getEstimatesUsingProvider(request) {
392
397
 
393
398
 
394
399
 
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;
396
- //# sourceMappingURL=chunk-H5WHAYLI.js.map
400
+ exports.determineGasFeeCalculations = determineGasFeeCalculations; exports.LEGACY_GAS_PRICES_API_URL = LEGACY_GAS_PRICES_API_URL; exports.GAS_ESTIMATE_TYPES = GAS_ESTIMATE_TYPES; exports.GasFeeController = GasFeeController; exports.GasFeeController_default = GasFeeController_default;
401
+ //# sourceMappingURL=chunk-S5H5NUEH.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/GasFeeController.ts","../src/determineGasFeeCalculations.ts"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C,OAAO;AAAA,IACzD;AAEA,QAAI,4BAA4B,CAAC,0BAA0B;AACzD,aAAO,MAAM,gCAAgC,OAAO;AAAA,IACtD;AAEA,UAAM,IAAI,MAAM,oDAAoD;AAAA,EACtE,QAAQ;AACN,WAAO,MAAM,0BAA0B,OAAO;AAAA,EAChD;AACF;AAOA,eAAe,mCACb,SAC6B;AAC7B,QAAM;AAAA,IACJ,mBAAAA;AAAA,IACA;AAAA,IACA;AAAA,IACA,uBAAAC;AAAA,EACF,IAAI;AAEJ,QAAM,YAAY,MAAMD,mBAAkB,sBAAsB,QAAQ;AAExE,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,EACF,IAAI;AAEJ,QAAM,YAAY,MAAMA;AAAA,IACtB;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","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 fetchGasEstimates,\n fetchLegacyGasPriceEstimates,\n fetchEthGasPriceEstimate,\n calculateTimeEstimate,\n} from './gas-util';\n\nexport const LEGACY_GAS_PRICES_API_URL = `https://api.metaswap.codefi.network/gasPrices`;\n\n// TODO: Either fix this lint violation or explain why it's necessary to ignore.\n// eslint-disable-next-line @typescript-eslint/naming-convention\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 // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n private readonly EIP1559APIEndpoint: string;\n\n private readonly getCurrentNetworkEIP1559Compatibility;\n\n private readonly getCurrentNetworkLegacyGasAPICompatibility;\n\n private readonly getCurrentAccountEIP1559Compatibility;\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.legacyAPIEndpoint - The legacy gas price API URL. This option is primarily for\n * testing purposes.\n * @param options.EIP1559APIEndpoint - The EIP-1559 gas price API URL.\n * @param options.clientId - The client ID used to identify to the gas estimation API who is\n * asking for estimates.\n */\n constructor({\n interval = 15000,\n messenger,\n state,\n getCurrentNetworkEIP1559Compatibility,\n getCurrentAccountEIP1559Compatibility,\n getChainId,\n getCurrentNetworkLegacyGasAPICompatibility,\n getProvider,\n onNetworkDidChange,\n legacyAPIEndpoint = LEGACY_GAS_PRICES_API_URL,\n EIP1559APIEndpoint,\n clientId,\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 legacyAPIEndpoint?: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n EIP1559APIEndpoint: string;\n clientId?: 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 = EIP1559APIEndpoint;\n this.legacyAPIEndpoint = legacyAPIEndpoint;\n this.clientId = clientId;\n\n this.ethQuery = new EthQuery(this.#getProvider());\n\n if (onNetworkDidChange && getChainId) {\n this.currentChainId = getChainId();\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n onNetworkDidChange(async (networkControllerState) => {\n await this.#onNetworkControllerDidChange(networkControllerState);\n });\n } else {\n const { selectedNetworkClientId } = this.messagingSystem.call(\n 'NetworkController:getState',\n );\n this.currentChainId = this.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n selectedNetworkClientId,\n ).configuration.chainId;\n this.messagingSystem.subscribe(\n 'NetworkController:networkDidChange',\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\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 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 // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\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({\n selectedNetworkClientId,\n }: NetworkState) {\n const newChainId = this.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n selectedNetworkClientId,\n ).configuration.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 clientId?: string,\n ) => Promise<GasFeeEstimates>;\n fetchGasEstimatesUrl: string;\n fetchLegacyGasPriceEstimates: (\n url: 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 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.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 clientId,\n calculateTimeEstimate,\n } = request;\n\n const estimates = await fetchGasEstimates(fetchGasEstimatesUrl, clientId);\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 clientId,\n } = request;\n\n const estimates = await fetchLegacyGasPriceEstimates(\n fetchLegacyGasPriceEstimatesUrl,\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"]}
@@ -7,7 +7,7 @@ import {
7
7
  fetchEthGasPriceEstimate,
8
8
  fetchGasEstimates,
9
9
  fetchLegacyGasPriceEstimates
10
- } from "./chunk-KORLXV32.mjs";
10
+ } from "./chunk-R3IOI7AK.mjs";
11
11
 
12
12
  // src/GasFeeController.ts
13
13
  import {
@@ -18,7 +18,7 @@ import {
18
18
  import EthQuery from "@metamask/eth-query";
19
19
  import { StaticIntervalPollingController } from "@metamask/polling-controller";
20
20
  import { v1 as random } from "uuid";
21
- var GAS_API_BASE_URL = "https://gas.api.infura.io";
21
+ var LEGACY_GAS_PRICES_API_URL = `https://api.metaswap.codefi.network/gasPrices`;
22
22
  var GAS_ESTIMATE_TYPES = {
23
23
  FEE_MARKET: "fee-market",
24
24
  LEGACY: "legacy",
@@ -62,9 +62,11 @@ var GasFeeController = class extends StaticIntervalPollingController {
62
62
  * @param options.getProvider - Returns a network provider for the current network.
63
63
  * @param options.onNetworkDidChange - A function for registering an event handler for the
64
64
  * network state change event.
65
+ * @param options.legacyAPIEndpoint - The legacy gas price API URL. This option is primarily for
66
+ * testing purposes.
67
+ * @param options.EIP1559APIEndpoint - The EIP-1559 gas price API URL.
65
68
  * @param options.clientId - The client ID used to identify to the gas estimation API who is
66
69
  * asking for estimates.
67
- * @param options.infuraAPIKey - The Infura API key used for infura API requests.
68
70
  */
69
71
  constructor({
70
72
  interval = 15e3,
@@ -76,8 +78,9 @@ var GasFeeController = class extends StaticIntervalPollingController {
76
78
  getCurrentNetworkLegacyGasAPICompatibility,
77
79
  getProvider,
78
80
  onNetworkDidChange,
79
- clientId,
80
- infuraAPIKey
81
+ legacyAPIEndpoint = LEGACY_GAS_PRICES_API_URL,
82
+ EIP1559APIEndpoint,
83
+ clientId
81
84
  }) {
82
85
  super({
83
86
  name,
@@ -94,10 +97,9 @@ var GasFeeController = class extends StaticIntervalPollingController {
94
97
  this.getCurrentNetworkLegacyGasAPICompatibility = getCurrentNetworkLegacyGasAPICompatibility;
95
98
  this.getCurrentAccountEIP1559Compatibility = getCurrentAccountEIP1559Compatibility;
96
99
  __privateSet(this, _getProvider, getProvider);
97
- this.EIP1559APIEndpoint = `${GAS_API_BASE_URL}/networks/<chain_id>/suggestedGasFees`;
98
- this.legacyAPIEndpoint = `${GAS_API_BASE_URL}/networks/<chain_id>/gasPrices`;
100
+ this.EIP1559APIEndpoint = EIP1559APIEndpoint;
101
+ this.legacyAPIEndpoint = legacyAPIEndpoint;
99
102
  this.clientId = clientId;
100
- this.infuraAPIKey = infuraAPIKey;
101
103
  this.ethQuery = new EthQuery(__privateGet(this, _getProvider).call(this));
102
104
  if (onNetworkDidChange && getChainId) {
103
105
  this.currentChainId = getChainId();
@@ -105,11 +107,17 @@ var GasFeeController = class extends StaticIntervalPollingController {
105
107
  await __privateMethod(this, _onNetworkControllerDidChange, onNetworkControllerDidChange_fn).call(this, networkControllerState);
106
108
  });
107
109
  } else {
108
- this.currentChainId = this.messagingSystem.call(
110
+ const { selectedNetworkClientId } = this.messagingSystem.call(
109
111
  "NetworkController:getState"
110
- ).providerConfig.chainId;
112
+ );
113
+ this.currentChainId = this.messagingSystem.call(
114
+ "NetworkController:getNetworkClientById",
115
+ selectedNetworkClientId
116
+ ).configuration.chainId;
111
117
  this.messagingSystem.subscribe(
112
118
  "NetworkController:networkDidChange",
119
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
120
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
113
121
  async (networkControllerState) => {
114
122
  await __privateMethod(this, _onNetworkControllerDidChange, onNetworkControllerDidChange_fn).call(this, networkControllerState);
115
123
  }
@@ -193,7 +201,6 @@ var GasFeeController = class extends StaticIntervalPollingController {
193
201
  calculateTimeEstimate,
194
202
  clientId: this.clientId,
195
203
  ethQuery,
196
- infuraAPIKey: this.infuraAPIKey,
197
204
  nonRPCGasFeeApisDisabled: this.state.nonRPCGasFeeApisDisabled
198
205
  });
199
206
  if (shouldUpdateState) {
@@ -292,8 +299,13 @@ var GasFeeController = class extends StaticIntervalPollingController {
292
299
  };
293
300
  _getProvider = new WeakMap();
294
301
  _onNetworkControllerDidChange = new WeakSet();
295
- onNetworkControllerDidChange_fn = async function(networkControllerState) {
296
- const newChainId = networkControllerState.providerConfig.chainId;
302
+ onNetworkControllerDidChange_fn = async function({
303
+ selectedNetworkClientId
304
+ }) {
305
+ const newChainId = this.messagingSystem.call(
306
+ "NetworkController:getNetworkClientById",
307
+ selectedNetworkClientId
308
+ ).configuration.chainId;
297
309
  if (newChainId !== this.currentChainId) {
298
310
  this.ethQuery = new EthQuery(__privateGet(this, _getProvider).call(this));
299
311
  await this.resetPolling();
@@ -337,15 +349,10 @@ async function getEstimatesUsingFeeMarketEndpoint(request) {
337
349
  const {
338
350
  fetchGasEstimates: fetchGasEstimates2,
339
351
  fetchGasEstimatesUrl,
340
- infuraAPIKey,
341
352
  clientId,
342
353
  calculateTimeEstimate: calculateTimeEstimate2
343
354
  } = request;
344
- const estimates = await fetchGasEstimates2(
345
- fetchGasEstimatesUrl,
346
- infuraAPIKey,
347
- clientId
348
- );
355
+ const estimates = await fetchGasEstimates2(fetchGasEstimatesUrl, clientId);
349
356
  const { suggestedMaxPriorityFeePerGas, suggestedMaxFeePerGas } = estimates.medium;
350
357
  const estimatedGasFeeTimeBounds = calculateTimeEstimate2(
351
358
  suggestedMaxPriorityFeePerGas,
@@ -362,12 +369,10 @@ async function getEstimatesUsingLegacyEndpoint(request) {
362
369
  const {
363
370
  fetchLegacyGasPriceEstimates: fetchLegacyGasPriceEstimates2,
364
371
  fetchLegacyGasPriceEstimatesUrl,
365
- infuraAPIKey,
366
372
  clientId
367
373
  } = request;
368
374
  const estimates = await fetchLegacyGasPriceEstimates2(
369
375
  fetchLegacyGasPriceEstimatesUrl,
370
- infuraAPIKey,
371
376
  clientId
372
377
  );
373
378
  return {
@@ -388,9 +393,9 @@ async function getEstimatesUsingProvider(request) {
388
393
 
389
394
  export {
390
395
  determineGasFeeCalculations,
391
- GAS_API_BASE_URL,
396
+ LEGACY_GAS_PRICES_API_URL,
392
397
  GAS_ESTIMATE_TYPES,
393
398
  GasFeeController,
394
399
  GasFeeController_default
395
400
  };
396
- //# sourceMappingURL=chunk-BEVZS3YV.mjs.map
401
+ //# sourceMappingURL=chunk-WXXOCPNT.mjs.map