@metamask/gas-fee-controller 4.0.0 → 5.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
@@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [5.0.0]
10
+ ### Changed
11
+ - **BREAKING**: peerDeps: @metamask/network-controller@6.0.0->8.0.0 ([#1196](https://github.com/MetaMask/core/pull/1196))
12
+
13
+ ## [4.0.1]
14
+ ### Changed
15
+ - Adjust types to align with new version of `NetworkController` ([#1091](https://github.com/MetaMask/core/pull/1091))
16
+
9
17
  ## [4.0.0]
10
18
  ### Changed
11
19
  - **BREAKING:** Make the EIP-1559 endpoint a required argument ([#1083](https://github.com/MetaMask/core/pull/1083))
@@ -18,7 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
18
26
  ### Changed
19
27
  - **BREAKING:** Update `@metamask/network-controller` peer dependency to v3 ([#1041](https://github.com/MetaMask/controllers/pull/1041))
20
28
  - Rename this repository to `core` ([#1031](https://github.com/MetaMask/controllers/pull/1031))
21
- - Update `@metamask/controller-utils` package ([#1041](https://github.com/MetaMask/controllers/pull/1041))
29
+ - Update `@metamask/controller-utils` package ([#1041](https://github.com/MetaMask/controllers/pull/1041))
22
30
 
23
31
  ## [2.0.1]
24
32
  ### Fixed
@@ -38,7 +46,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
38
46
 
39
47
  All changes listed after this point were applied to this package following the monorepo conversion.
40
48
 
41
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@4.0.0...HEAD
49
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@5.0.0...HEAD
50
+ [5.0.0]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@4.0.1...@metamask/gas-fee-controller@5.0.0
51
+ [4.0.1]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@4.0.0...@metamask/gas-fee-controller@4.0.1
42
52
  [4.0.0]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@3.0.0...@metamask/gas-fee-controller@4.0.0
43
53
  [3.0.0]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@2.0.1...@metamask/gas-fee-controller@3.0.0
44
54
  [2.0.1]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@2.0.0...@metamask/gas-fee-controller@2.0.1
@@ -1,6 +1,6 @@
1
1
  import type { Patch } from 'immer';
2
2
  import { BaseControllerV2, RestrictedControllerMessenger } from '@metamask/base-controller';
3
- import type { NetworkControllerGetEthQueryAction, NetworkControllerGetProviderConfigAction, NetworkControllerProviderConfigChangeEvent, NetworkController, NetworkState } from '@metamask/network-controller';
3
+ import type { NetworkControllerGetEthQueryAction, NetworkControllerGetProviderConfigAction, NetworkControllerProviderConfigChangeEvent, NetworkState, ProviderProxy } from '@metamask/network-controller';
4
4
  export declare const LEGACY_GAS_PRICES_API_URL = "https://api.metaswap.codefi.network/gasPrices";
5
5
  export declare type unknownString = 'unknown';
6
6
  export declare type FeeMarketEstimateType = 'fee-market';
@@ -189,7 +189,7 @@ export declare class GasFeeController extends BaseControllerV2<typeof name, GasF
189
189
  getCurrentNetworkLegacyGasAPICompatibility: () => boolean;
190
190
  getCurrentAccountEIP1559Compatibility?: () => boolean;
191
191
  getChainId?: () => `0x${string}` | `${number}` | number;
192
- getProvider: () => NetworkController['provider'];
192
+ getProvider: () => ProviderProxy;
193
193
  onNetworkStateChange?: (listener: (state: NetworkState) => void) => void;
194
194
  legacyAPIEndpoint?: string;
195
195
  EIP1559APIEndpoint: string;
@@ -226,3 +226,4 @@ export declare class GasFeeController extends BaseControllerV2<typeof name, GasF
226
226
  getTimeEstimate(maxPriorityFeePerGas: string, maxFeePerGas: string): EstimatedGasFeeTimeBounds | Record<string, never>;
227
227
  }
228
228
  export default GasFeeController;
229
+ //# sourceMappingURL=GasFeeController.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GasFeeController.d.ts","sourceRoot":"","sources":["../src/GasFeeController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAInC,OAAO,EACL,gBAAgB,EAChB,6BAA6B,EAC9B,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EACV,kCAAkC,EAClC,wCAAwC,EACxC,0CAA0C,EAC1C,YAAY,EACZ,aAAa,EACd,MAAM,8BAA8B,CAAC;AAUtC,eAAO,MAAM,yBAAyB,kDAAkD,CAAC;AAEzF,oBAAY,aAAa,GAAG,SAAS,CAAC;AAItC,oBAAY,qBAAqB,GAAG,YAAY,CAAC;AAIjD,oBAAY,kBAAkB,GAAG,QAAQ,CAAC;AAK1C,oBAAY,uBAAuB,GAAG,cAAc,CAAC;AAGrD,oBAAY,cAAc,GAAG,MAAM,CAAC;AAEpC;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB;;;;;CAK9B,CAAC;AAEF,oBAAY,eAAe,GACvB,qBAAqB,GACrB,uBAAuB,GACvB,kBAAkB,GAClB,cAAc,CAAC;AAEnB,oBAAY,yBAAyB,GAAG;IACtC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,cAAc,EAAE,MAAM,GAAG,aAAa,CAAC;CACxC,CAAC;AAEF;;;;;;;GAOG;AAEH,oBAAY,mBAAmB,GAAG;IAChC,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;;;;;;GASG;AACH,oBAAY,sBAAsB,GAAG;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF;;;;;;;;GAQG;AACH,oBAAY,aAAa,GAAG;IAC1B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,6BAA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,EACpB,YAAY,EACZ,IAAI,CAAC,KAAK,CAAC,eAAe,CAC3B,CAAC;IACJ,CAAC;CACF;AA/SD,4CA+SC;AAED,kBAAe,gBAAgB,CAAC","sourcesContent":["import type { Patch } from 'immer';\nimport EthQuery from 'eth-query';\nimport { v1 as random } from 'uuid';\nimport { isHexString } from 'ethereumjs-util';\nimport {\n BaseControllerV2,\n RestrictedControllerMessenger,\n} from '@metamask/base-controller';\nimport { safelyExecute } from '@metamask/controller-utils';\nimport type {\n NetworkControllerGetEthQueryAction,\n NetworkControllerGetProviderConfigAction,\n NetworkControllerProviderConfigChangeEvent,\n NetworkController,\n NetworkState,\n} from '@metamask/network-controller';\nimport {\n fetchGasEstimates,\n fetchLegacyGasPriceEstimates,\n fetchEthGasPriceEstimate,\n calculateTimeEstimate,\n} from './gas-util';\nimport determineGasFeeCalculations from './determineGasFeeCalculations';\nimport fetchGasEstimatesViaEthFeeHistory from './fetchGasEstimatesViaEthFeeHistory';\n\nexport const LEGACY_GAS_PRICES_API_URL = `https://api.metaswap.codefi.network/gasPrices`;\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 gasFeeEstimates: { persist: true, anonymous: false },\n estimatedGasFeeTimeBounds: { persist: true, anonymous: false },\n gasEstimateType: { 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};\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 GasFeeState =\n | GasFeeStateEthGasPrice\n | GasFeeStateFeeMarket\n | GasFeeStateLegacy\n | GasFeeStateNoEstimates;\n\nconst name = 'GasFeeController';\n\nexport type GasFeeStateChange = {\n type: `${typeof name}:stateChange`;\n payload: [GasFeeState, Patch[]];\n};\n\nexport type GetGasFeeState = {\n type: `${typeof name}:getState`;\n handler: () => GasFeeState;\n};\n\ntype GasFeeMessenger = RestrictedControllerMessenger<\n typeof name,\n | GetGasFeeState\n | NetworkControllerGetProviderConfigAction\n | NetworkControllerGetEthQueryAction,\n GasFeeStateChange | NetworkControllerProviderConfigChangeEvent,\n | NetworkControllerGetProviderConfigAction['type']\n | NetworkControllerGetEthQueryAction['type'],\n NetworkControllerProviderConfigChangeEvent['type']\n>;\n\nconst defaultState: GasFeeState = {\n gasFeeEstimates: {},\n estimatedGasFeeTimeBounds: {},\n gasEstimateType: GAS_ESTIMATE_TYPES.NONE,\n};\n\nexport type ChainID = `0x${string}` | `${number}` | number;\n\n/**\n * Controller that retrieves gas fee estimate data and polls for updated data on a set interval\n */\nexport class GasFeeController extends BaseControllerV2<\n typeof name,\n GasFeeState,\n GasFeeMessenger\n> {\n private intervalId?: ReturnType<typeof setTimeout>;\n\n private intervalDelay;\n\n private pollTokens: Set<string>;\n\n private legacyAPIEndpoint: string;\n\n private EIP1559APIEndpoint: string;\n\n private getCurrentNetworkEIP1559Compatibility;\n\n private getCurrentNetworkLegacyGasAPICompatibility;\n\n private getCurrentAccountEIP1559Compatibility;\n\n private currentChainId;\n\n private ethQuery: any;\n\n private clientId?: string;\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.onNetworkStateChange - 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 onNetworkStateChange,\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?: () => `0x${string}` | `${number}` | number;\n getProvider: () => NetworkController['provider'];\n onNetworkStateChange?: (listener: (state: NetworkState) => void) => void;\n legacyAPIEndpoint?: string;\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.pollTokens = new Set();\n this.getCurrentNetworkEIP1559Compatibility =\n getCurrentNetworkEIP1559Compatibility;\n\n this.getCurrentNetworkLegacyGasAPICompatibility =\n getCurrentNetworkLegacyGasAPICompatibility;\n\n this.getCurrentAccountEIP1559Compatibility =\n getCurrentAccountEIP1559Compatibility;\n this.EIP1559APIEndpoint = EIP1559APIEndpoint;\n this.legacyAPIEndpoint = legacyAPIEndpoint;\n this.clientId = clientId;\n if (onNetworkStateChange && getChainId) {\n const initialProvider = getProvider();\n this.ethQuery = new EthQuery(initialProvider);\n this.currentChainId = getChainId();\n onNetworkStateChange(async () => {\n const newProvider = getProvider();\n const newChainId = getChainId();\n this.ethQuery = new EthQuery(newProvider);\n if (this.currentChainId !== newChainId) {\n this.currentChainId = newChainId;\n await this.resetPolling();\n }\n });\n } else {\n const providerConfig = this.messagingSystem.call(\n 'NetworkController:getProviderConfig',\n );\n this.currentChainId = providerConfig.chainId;\n this.ethQuery = this.messagingSystem.call(\n 'NetworkController:getEthQuery',\n );\n\n this.messagingSystem.subscribe(\n 'NetworkController:providerConfigChange',\n async (newProviderConfig) => {\n this.ethQuery = this.messagingSystem.call(\n 'NetworkController:getEthQuery',\n );\n\n if (this.currentChainId !== newProviderConfig.chainId) {\n this.currentChainId = newProviderConfig.chainId;\n await this.resetPolling();\n }\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 } = options;\n let isEIP1559Compatible;\n const isLegacyGasAPICompatible =\n this.getCurrentNetworkLegacyGasAPICompatibility();\n\n let chainId: number;\n if (typeof this.currentChainId === 'string') {\n if (isHexString(this.currentChainId)) {\n chainId = parseInt(this.currentChainId, 16);\n } else {\n chainId = parseInt(this.currentChainId, 10);\n }\n } else {\n chainId = this.currentChainId;\n }\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 `${chainId}`,\n ),\n fetchGasEstimatesViaEthFeeHistory,\n fetchLegacyGasPriceEstimates,\n fetchLegacyGasPriceEstimatesUrl: this.legacyAPIEndpoint.replace(\n '<chain_id>',\n `${chainId}`,\n ),\n fetchEthGasPriceEstimate,\n calculateTimeEstimate,\n clientId: this.clientId,\n ethQuery: this.ethQuery,\n });\n\n if (shouldUpdateState) {\n this.update((state) => {\n state.gasFeeEstimates = gasFeeCalculations.gasFeeEstimates;\n state.estimatedGasFeeTimeBounds =\n gasFeeCalculations.estimatedGasFeeTimeBounds;\n state.gasEstimateType = gasFeeCalculations.gasEstimateType;\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 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\nexport default GasFeeController;\n"]}
1
+ {"version":3,"file":"GasFeeController.js","sourceRoot":"","sources":["../src/GasFeeController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,0DAAiC;AACjC,+BAAoC;AACpC,qDAA8C;AAC9C,+DAGmC;AACnC,iEAA2D;AAQ3D,yCAKoB;AACpB,gGAAwE;AACxE,4GAAoF;AAEvE,QAAA,yBAAyB,GAAG,+CAA+C,CAAC;AAoBzF;;;;;GAKG;AACU,QAAA,kBAAkB,GAAG;IAChC,UAAU,EAAE,YAAqC;IACjD,MAAM,EAAE,QAA8B;IACtC,YAAY,EAAE,cAAyC;IACvD,IAAI,EAAE,MAAwB;CAC/B,CAAC;AAiGF,MAAM,QAAQ,GAAG;IACf,eAAe,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE;IACpD,yBAAyB,EAAE,EAAE,OAAO,EAAE,IAAI,E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AC;SACX;QACD,OAAO,IAAA,gCAAqB,EAC1B,oBAAoB,EACpB,YAAY,EACZ,IAAI,CAAC,KAAK,CAAC,eAAe,CAC3B,CAAC;IACJ,CAAC;CACF;AA/SD,4CA+SC;AAED,kBAAe,gBAAgB,CAAC","sourcesContent":["import type { Patch } from 'immer';\nimport EthQuery from 'eth-query';\nimport { v1 as random } from 'uuid';\nimport { isHexString } from 'ethereumjs-util';\nimport {\n BaseControllerV2,\n RestrictedControllerMessenger,\n} from '@metamask/base-controller';\nimport { safelyExecute } from '@metamask/controller-utils';\nimport type {\n NetworkControllerGetEthQueryAction,\n NetworkControllerGetProviderConfigAction,\n NetworkControllerProviderConfigChangeEvent,\n NetworkState,\n ProviderProxy,\n} from '@metamask/network-controller';\nimport {\n fetchGasEstimates,\n fetchLegacyGasPriceEstimates,\n fetchEthGasPriceEstimate,\n calculateTimeEstimate,\n} from './gas-util';\nimport determineGasFeeCalculations from './determineGasFeeCalculations';\nimport fetchGasEstimatesViaEthFeeHistory from './fetchGasEstimatesViaEthFeeHistory';\n\nexport const LEGACY_GAS_PRICES_API_URL = `https://api.metaswap.codefi.network/gasPrices`;\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 gasFeeEstimates: { persist: true, anonymous: false },\n estimatedGasFeeTimeBounds: { persist: true, anonymous: false },\n gasEstimateType: { 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};\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 GasFeeState =\n | GasFeeStateEthGasPrice\n | GasFeeStateFeeMarket\n | GasFeeStateLegacy\n | GasFeeStateNoEstimates;\n\nconst name = 'GasFeeController';\n\nexport type GasFeeStateChange = {\n type: `${typeof name}:stateChange`;\n payload: [GasFeeState, Patch[]];\n};\n\nexport type GetGasFeeState = {\n type: `${typeof name}:getState`;\n handler: () => GasFeeState;\n};\n\ntype GasFeeMessenger = RestrictedControllerMessenger<\n typeof name,\n | GetGasFeeState\n | NetworkControllerGetProviderConfigAction\n | NetworkControllerGetEthQueryAction,\n GasFeeStateChange | NetworkControllerProviderConfigChangeEvent,\n | NetworkControllerGetProviderConfigAction['type']\n | NetworkControllerGetEthQueryAction['type'],\n NetworkControllerProviderConfigChangeEvent['type']\n>;\n\nconst defaultState: GasFeeState = {\n gasFeeEstimates: {},\n estimatedGasFeeTimeBounds: {},\n gasEstimateType: GAS_ESTIMATE_TYPES.NONE,\n};\n\nexport type ChainID = `0x${string}` | `${number}` | number;\n\n/**\n * Controller that retrieves gas fee estimate data and polls for updated data on a set interval\n */\nexport class GasFeeController extends BaseControllerV2<\n typeof name,\n GasFeeState,\n GasFeeMessenger\n> {\n private intervalId?: ReturnType<typeof setTimeout>;\n\n private intervalDelay;\n\n private pollTokens: Set<string>;\n\n private legacyAPIEndpoint: string;\n\n private EIP1559APIEndpoint: string;\n\n private getCurrentNetworkEIP1559Compatibility;\n\n private getCurrentNetworkLegacyGasAPICompatibility;\n\n private getCurrentAccountEIP1559Compatibility;\n\n private currentChainId;\n\n private ethQuery: any;\n\n private clientId?: string;\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.onNetworkStateChange - 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 onNetworkStateChange,\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?: () => `0x${string}` | `${number}` | number;\n getProvider: () => ProviderProxy;\n onNetworkStateChange?: (listener: (state: NetworkState) => void) => void;\n legacyAPIEndpoint?: string;\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.pollTokens = new Set();\n this.getCurrentNetworkEIP1559Compatibility =\n getCurrentNetworkEIP1559Compatibility;\n\n this.getCurrentNetworkLegacyGasAPICompatibility =\n getCurrentNetworkLegacyGasAPICompatibility;\n\n this.getCurrentAccountEIP1559Compatibility =\n getCurrentAccountEIP1559Compatibility;\n this.EIP1559APIEndpoint = EIP1559APIEndpoint;\n this.legacyAPIEndpoint = legacyAPIEndpoint;\n this.clientId = clientId;\n if (onNetworkStateChange && getChainId) {\n const initialProvider = getProvider();\n this.ethQuery = new EthQuery(initialProvider);\n this.currentChainId = getChainId();\n onNetworkStateChange(async () => {\n const newProvider = getProvider();\n const newChainId = getChainId();\n this.ethQuery = new EthQuery(newProvider);\n if (this.currentChainId !== newChainId) {\n this.currentChainId = newChainId;\n await this.resetPolling();\n }\n });\n } else {\n const providerConfig = this.messagingSystem.call(\n 'NetworkController:getProviderConfig',\n );\n this.currentChainId = providerConfig.chainId;\n this.ethQuery = this.messagingSystem.call(\n 'NetworkController:getEthQuery',\n );\n\n this.messagingSystem.subscribe(\n 'NetworkController:providerConfigChange',\n async (newProviderConfig) => {\n this.ethQuery = this.messagingSystem.call(\n 'NetworkController:getEthQuery',\n );\n\n if (this.currentChainId !== newProviderConfig.chainId) {\n this.currentChainId = newProviderConfig.chainId;\n await this.resetPolling();\n }\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 } = options;\n let isEIP1559Compatible;\n const isLegacyGasAPICompatible =\n this.getCurrentNetworkLegacyGasAPICompatibility();\n\n let chainId: number;\n if (typeof this.currentChainId === 'string') {\n if (isHexString(this.currentChainId)) {\n chainId = parseInt(this.currentChainId, 16);\n } else {\n chainId = parseInt(this.currentChainId, 10);\n }\n } else {\n chainId = this.currentChainId;\n }\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 `${chainId}`,\n ),\n fetchGasEstimatesViaEthFeeHistory,\n fetchLegacyGasPriceEstimates,\n fetchLegacyGasPriceEstimatesUrl: this.legacyAPIEndpoint.replace(\n '<chain_id>',\n `${chainId}`,\n ),\n fetchEthGasPriceEstimate,\n calculateTimeEstimate,\n clientId: this.clientId,\n ethQuery: this.ethQuery,\n });\n\n if (shouldUpdateState) {\n this.update((state) => {\n state.gasFeeEstimates = gasFeeCalculations.gasFeeEstimates;\n state.estimatedGasFeeTimeBounds =\n gasFeeCalculations.estimatedGasFeeTimeBounds;\n state.gasEstimateType = gasFeeCalculations.gasEstimateType;\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 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\nexport default GasFeeController;\n"]}
@@ -38,3 +38,4 @@ export default function determineGasFeeCalculations({ isEIP1559Compatible, isLeg
38
38
  clientId: string | undefined;
39
39
  ethQuery: any;
40
40
  }): Promise<GasFeeCalculations>;
41
+ //# sourceMappingURL=determineGasFeeCalculations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"determineGasFeeCalculations.d.ts","sourceRoot":"","sources":["../src/determineGasFeeCalculations.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,yBAAyB,EACzB,mBAAmB,EACnB,eAAe,EACf,WAAW,IAAI,kBAAkB,EACjC,sBAAsB,EACvB,MAAM,oBAAoB,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAA8B,2BAA2B,CAAC,EACxD,mBAAmB,EACnB,wBAAwB,EACxB,iBAAiB,EACjB,oBAAoB,EACpB,iCAAiC,EACjC,4BAA4B,EAC5B,+BAA+B,EAC/B,wBAAwB,EACxB,qBAAqB,EACrB,QAAQ,EACR,QAAQ,GACT,EAAE;IACD,mBAAmB,EAAE,OAAO,CAAC;IAC7B,wBAAwB,EAAE,OAAO,CAAC;IAClC,iBAAiB,EAAE,CACjB,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,MAAM,KACd,OAAO,CAAC,eAAe,CAAC,CAAC;IAC9B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,iCAAiC,EAAE,CACjC,QAAQ,EAAE,GAAG,KACV,OAAO,CAAC,eAAe,CAAC,CAAC;IAC9B,4BAA4B,EAAE,CAC5B,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,MAAM,KACd,OAAO,CAAC,sBAAsB,CAAC,CAAC;IACrC,+BAA+B,EAAE,MAAM,CAAC;IACxC,wBAAwB,EAAE,CAAC,QAAQ,EAAE,GAAG,KAAK,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAC1E,qBAAqB,EAAE,CACrB,oBAAoB,EAAE,MAAM,EAC5B,YAAY,EAAE,MAAM,EACpB,eAAe,EAAE,eAAe,KAC7B,yBAAyB,CAAC;IAC/B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE,GAAG,CAAC;CACf,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAkD9B"}
@@ -113,3 +113,4 @@ export default function fetchBlockFeeHistory<Percentile extends number>({ ethQue
113
113
  includeNextBlock?: boolean;
114
114
  }): Promise<FeeHistoryBlock<Percentile>[]>;
115
115
  export {};
116
+ //# sourceMappingURL=fetchBlockFeeHistory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetchBlockFeeHistory.d.ts","sourceRoot":"","sources":["../src/fetchBlockFeeHistory.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AAGrC,aAAK,Q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C;IACpC,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,GAAG,OAAO,CAAC,eAAe,CAAC,UAAU,CAAC,EAAE,CAAC,CAwCzC"}
@@ -14,3 +14,4 @@ declare const PRIORITY_LEVEL_PERCENTILES: readonly [10, 20, 30];
14
14
  */
15
15
  export default function calculateGasFeeEstimatesForPriorityLevels(blocks: FeeHistoryBlock<Percentile>[]): Pick<GasFeeEstimates, PriorityLevel>;
16
16
  export {};
17
+ //# sourceMappingURL=calculateGasFeeEstimatesForPriorityLevels.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calculateGasFeeEstimatesForPriorityLevels.d.ts","sourceRoot":"","sources":["../../src/fetchGasEstimatesViaEthFeeHistory/calculateGasFeeEstimatesForPriorityLevels.ts"],"names":[],"mappings":"AAGA,OAAO,EAAiB,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAG1D,oBAAY,aAAa,GAAG,OAAO,eAAe,CAAC,MAAM,CAAC,CAAC;AAC3D,oBAAY,UAAU,GAAG,OAAO,0BAA0B,CAAC,MAAM,CAAC,CAAC;AAEnE,QAAA,MAAM,eAAe,oCAAqC,CAAC;AAC3D,QAAA,MAAM,0BAA0B,uBAAwB,CAAC;AAiFzD;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,yCAAyC,CAC/D,MAAM,EAAE,eAAe,CAAC,UAAU,CAAC,EAAE,GACpC,IAAI,CAAC,eAAe,EAAE,aAAa,CAAC,CAQtC"}
@@ -8,3 +8,4 @@ import { EthBlock, EthQuery } from './types';
8
8
  * @returns The block.
9
9
  */
10
10
  export default function fetchLatestBlock(ethQuery: EthQuery, includeFullTransactionData?: boolean): Promise<EthBlock>;
11
+ //# sourceMappingURL=fetchLatestBlock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetchLatestBlock.d.ts","sourceRoot":"","sources":["../../src/fetchGasEstimatesViaEthFeeHistory/fetchLatestBlock.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE7C;;;;;;;GAOG;AACH,wBAA8B,gBAAgB,CAC5C,QAAQ,EAAE,QAAQ,EAClB,0BAA0B,UAAQ,GACjC,OAAO,CAAC,QAAQ,CAAC,CAWnB"}
@@ -8,3 +8,4 @@ import { BN } from 'ethereumjs-util';
8
8
  * @returns The median number.
9
9
  */
10
10
  export default function medianOf(numbers: BN[]): BN;
11
+ //# sourceMappingURL=medianOf.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"medianOf.d.ts","sourceRoot":"","sources":["../../src/fetchGasEstimatesViaEthFeeHistory/medianOf.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AAErC;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,CAKlD"}
@@ -8,3 +8,4 @@ export declare type EthQuery = {
8
8
  getBlockByNumber: (blockNumber: BN | 'latest' | 'earliest' | 'pending') => Promise<EthBlock>;
9
9
  };
10
10
  export declare type FeeRange = [string, string];
11
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/fetchGasEstimatesViaEthFeeHistory/types.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AAErC,oBAAY,QAAQ,GAAG;IACrB,MAAM,EAAE,EAAE,CAAC;IACX,aAAa,EAAE,EAAE,CAAC;CACnB,CAAC;AAEF,oBAAY,QAAQ,GAAG;IACrB,gBAAgB,EAAE,CAChB,WAAW,EAAE,EAAE,GAAG,QAAQ,GAAG,UAAU,GAAG,SAAS,KAChD,OAAO,CAAC,QAAQ,CAAC,CAAC;CACxB,CAAC;AAEF,oBAAY,QAAQ,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC"}
@@ -19,3 +19,4 @@ import { EthQuery } from './fetchGasEstimatesViaEthFeeHistory/types';
19
19
  * for the next block's base fee.
20
20
  */
21
21
  export default function fetchGasEstimatesViaEthFeeHistory(ethQuery: EthQuery): Promise<GasFeeEstimates>;
22
+ //# sourceMappingURL=fetchGasEstimatesViaEthFeeHistory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetchGasEstimatesViaEthFeeHistory.d.ts","sourceRoot":"","sources":["../src/fetchGasEstimatesViaEthFeeHistory.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,2CAA2C,CAAC;AAKrE;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAA8B,iCAAiC,CAC7D,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,eAAe,CAAC,CAuB1B"}
@@ -39,3 +39,4 @@ export declare function fetchEthGasPriceEstimate(ethQuery: any): Promise<EthGasP
39
39
  * @returns The estimated lower and upper bounds for when this transaction will be confirmed.
40
40
  */
41
41
  export declare function calculateTimeEstimate(maxPriorityFeePerGas: string, maxFeePerGas: string, gasFeeEstimates: GasFeeEstimates): EstimatedGasFeeTimeBounds;
42
+ //# sourceMappingURL=gas-util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gas-util.d.ts","sourceRoot":"","sources":["../src/gas-util.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,yBAAyB,EAEzB,sBAAsB,EACvB,MAAM,oBAAoB,CAAC;AAI5B;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,OAI7D;AAED;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,eAAe,CAAC,CAyC1B;AAED;;;;;;;GAOG;AACH,wBAAsB,4BAA4B,CAChD,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,sBAAsB,CAAC,CAgBjC;AAED;;;;;GAKG;AACH,wBAAsB,wBAAwB,CAC5C,QAAQ,EAAE,GAAG,GACZ,OAAO,CAAC,mBAAmB,CAAC,CAK9B;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,oBAAoB,EAAE,MAAM,EAC5B,YAAY,EAAE,MAAM,EACpB,eAAe,EAAE,eAAe,GAC/B,yBAAyB,CAoD3B"}
package/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export * from './GasFeeController';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/gas-fee-controller",
3
- "version": "4.0.0",
3
+ "version": "5.0.0",
4
4
  "description": "Periodically calculates gas fee estimates based on various gas limits as well as other data displayed on transaction confirm screens",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -30,8 +30,8 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@metamask/base-controller": "^2.0.0",
33
- "@metamask/controller-utils": "^3.0.0",
34
- "@metamask/network-controller": "^5.0.0",
33
+ "@metamask/controller-utils": "^3.4.0",
34
+ "@metamask/network-controller": "^8.0.0",
35
35
  "@types/uuid": "^8.3.0",
36
36
  "babel-runtime": "^6.26.0",
37
37
  "eth-query": "^2.1.2",
@@ -42,20 +42,20 @@
42
42
  },
43
43
  "devDependencies": {
44
44
  "@metamask/auto-changelog": "^3.1.0",
45
- "@types/jest": "^26.0.22",
45
+ "@types/jest": "^27.4.1",
46
46
  "@types/jest-when": "^2.7.3",
47
47
  "deepmerge": "^4.2.2",
48
- "jest": "^26.4.2",
48
+ "jest": "^27.5.1",
49
49
  "jest-when": "^3.4.2",
50
50
  "nock": "^13.0.7",
51
51
  "sinon": "^9.2.4",
52
- "ts-jest": "^26.5.2",
52
+ "ts-jest": "^27.1.4",
53
53
  "typedoc": "^0.22.15",
54
54
  "typedoc-plugin-missing-exports": "^0.22.6",
55
55
  "typescript": "~4.6.3"
56
56
  },
57
57
  "peerDependencies": {
58
- "@metamask/network-controller": "^5.0.0"
58
+ "@metamask/network-controller": "^8.0.0"
59
59
  },
60
60
  "engines": {
61
61
  "node": ">=14.0.0"