@metamask-previews/gas-fee-controller 26.3.2-preview-8bfa290fb → 27.0.0-preview-97d6b86c0
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 +19 -1
- package/dist/{GasFeeController-method-action-types.d.mts → GasFeeController-method-action-types.d.ts} +2 -2
- package/dist/GasFeeController-method-action-types.d.ts.map +1 -0
- package/dist/{GasFeeController-method-action-types.mjs → GasFeeController-method-action-types.js} +1 -1
- package/dist/GasFeeController-method-action-types.js.map +1 -0
- package/dist/{GasFeeController.d.cts → GasFeeController.d.ts} +18 -18
- package/dist/GasFeeController.d.ts.map +1 -0
- package/dist/{GasFeeController.mjs → GasFeeController.js} +57 -60
- package/dist/GasFeeController.js.map +1 -0
- package/dist/{determineGasFeeCalculations.d.mts → determineGasFeeCalculations.d.ts} +2 -2
- package/dist/determineGasFeeCalculations.d.ts.map +1 -0
- package/dist/{determineGasFeeCalculations.mjs → determineGasFeeCalculations.js} +2 -2
- package/dist/determineGasFeeCalculations.js.map +1 -0
- package/dist/{gas-util.d.cts → gas-util.d.ts} +3 -3
- package/dist/gas-util.d.ts.map +1 -0
- package/dist/{gas-util.mjs → gas-util.js} +3 -10
- package/dist/gas-util.js.map +1 -0
- package/dist/{index.d.cts → index.d.ts} +3 -3
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +19 -23
- package/dist/GasFeeController-method-action-types.cjs +0 -7
- package/dist/GasFeeController-method-action-types.cjs.map +0 -1
- package/dist/GasFeeController-method-action-types.d.cts +0 -75
- package/dist/GasFeeController-method-action-types.d.cts.map +0 -1
- package/dist/GasFeeController-method-action-types.d.mts.map +0 -1
- package/dist/GasFeeController-method-action-types.mjs.map +0 -1
- package/dist/GasFeeController.cjs +0 -370
- package/dist/GasFeeController.cjs.map +0 -1
- package/dist/GasFeeController.d.cts.map +0 -1
- package/dist/GasFeeController.d.mts +0 -297
- package/dist/GasFeeController.d.mts.map +0 -1
- package/dist/GasFeeController.mjs.map +0 -1
- package/dist/determineGasFeeCalculations.cjs +0 -109
- package/dist/determineGasFeeCalculations.cjs.map +0 -1
- package/dist/determineGasFeeCalculations.d.cts +0 -42
- package/dist/determineGasFeeCalculations.d.cts.map +0 -1
- package/dist/determineGasFeeCalculations.d.mts.map +0 -1
- package/dist/determineGasFeeCalculations.mjs.map +0 -1
- package/dist/gas-util.cjs +0 -143
- package/dist/gas-util.cjs.map +0 -1
- package/dist/gas-util.d.cts.map +0 -1
- package/dist/gas-util.d.mts +0 -43
- package/dist/gas-util.d.mts.map +0 -1
- package/dist/gas-util.mjs.map +0 -1
- package/dist/index.cjs +0 -18
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts +0 -3
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -2
- package/dist/index.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,7 +9,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
9
9
|
|
|
10
10
|
### Changed
|
|
11
11
|
|
|
12
|
+
- Bump `@types/uuid` from `^8.3.0` to `^9.0.8` ([#10117](https://github.com/MetaMask/core/pull/10117))
|
|
13
|
+
- Bump `uuid` from `^8.3.2` to `^9.0.1` ([#10117](https://github.com/MetaMask/core/pull/10117))
|
|
14
|
+
|
|
15
|
+
## [27.0.0]
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- **BREAKING:** Drop CommonJS support ([#9536](https://github.com/MetaMask/core/pull/9536))
|
|
20
|
+
- This package is now ESM-only, but can still be used in CommonJS projects via `require(esm)` in modern Node.js versions (22+), or dynamic imports in older Node.js versions.
|
|
21
|
+
- **BREAKING:** Bump minimum Node.js version to 22 ([#9976](https://github.com/MetaMask/core/pull/9976))
|
|
22
|
+
- **BREAKING:** Bump TypeScript target to ES2022 ([#10019](https://github.com/MetaMask/core/pull/10019))
|
|
23
|
+
- This package now ships ES2022 code, requiring a compatible modern environment or bundler configuration to consume.
|
|
12
24
|
- Bump `@metamask/utils` from `^11.11.0` to `^11.12.0` ([#10076](https://github.com/MetaMask/core/pull/10076))
|
|
25
|
+
- Bump `@metamask/base-controller` from `^9.1.0` to `^10.0.0` ([#10160](https://github.com/MetaMask/core/pull/10160))
|
|
26
|
+
- Bump `@metamask/controller-utils` from `^12.3.0` to `^13.0.0` ([#10160](https://github.com/MetaMask/core/pull/10160))
|
|
27
|
+
- Bump `@metamask/messenger` from `^2.0.0` to `^3.0.0` ([#10160](https://github.com/MetaMask/core/pull/10160))
|
|
28
|
+
- Bump `@metamask/network-controller` from `^36.0.0` to `^37.0.0` ([#10160](https://github.com/MetaMask/core/pull/10160))
|
|
29
|
+
- Bump `@metamask/polling-controller` from `^16.0.9` to `^17.0.0` ([#10160](https://github.com/MetaMask/core/pull/10160))
|
|
13
30
|
|
|
14
31
|
## [26.3.2]
|
|
15
32
|
|
|
@@ -590,7 +607,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
590
607
|
|
|
591
608
|
All changes listed after this point were applied to this package following the monorepo conversion.
|
|
592
609
|
|
|
593
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@
|
|
610
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@27.0.0...HEAD
|
|
611
|
+
[27.0.0]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@26.3.2...@metamask/gas-fee-controller@27.0.0
|
|
594
612
|
[26.3.2]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@26.3.1...@metamask/gas-fee-controller@26.3.2
|
|
595
613
|
[26.3.1]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@26.3.0...@metamask/gas-fee-controller@26.3.1
|
|
596
614
|
[26.3.0]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@26.2.4...@metamask/gas-fee-controller@26.3.0
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* This file is auto generated.
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
*/
|
|
5
|
-
import type { GasFeeController } from
|
|
5
|
+
import type { GasFeeController } from './GasFeeController.js';
|
|
6
6
|
/**
|
|
7
7
|
* Resets the polling interval by stopping and restarting polling
|
|
8
8
|
* with the existing poll tokens.
|
|
@@ -72,4 +72,4 @@ export type GasFeeControllerDisableNonRPCGasFeeApisAction = {
|
|
|
72
72
|
* Union of all GasFeeController action types.
|
|
73
73
|
*/
|
|
74
74
|
export type GasFeeControllerMethodActions = GasFeeControllerResetPollingAction | GasFeeControllerFetchGasFeeEstimatesAction | GasFeeControllerGetGasFeeEstimatesAndStartPollingAction | GasFeeControllerDisconnectPollerAction | GasFeeControllerStopPollingAction | GasFeeControllerGetTimeEstimateAction | GasFeeControllerEnableNonRPCGasFeeApisAction | GasFeeControllerDisableNonRPCGasFeeApisAction;
|
|
75
|
-
//# sourceMappingURL=GasFeeController-method-action-types.d.
|
|
75
|
+
//# sourceMappingURL=GasFeeController-method-action-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GasFeeController-method-action-types.d.ts","sourceRoot":"","sources":["../src/GasFeeController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D;;;GAGG;AACH,MAAM,MAAM,kCAAkC,GAAG;IAC/C,IAAI,EAAE,+BAA+B,CAAC;IACtC,OAAO,EAAE,gBAAgB,CAAC,cAAc,CAAC,CAAC;CAC3C,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,0CAA0C,GAAG;IACvD,IAAI,EAAE,uCAAuC,CAAC;IAC9C,OAAO,EAAE,gBAAgB,CAAC,sBAAsB,CAAC,CAAC;CACnD,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,uDAAuD,GAAG;IACpE,IAAI,EAAE,oDAAoD,CAAC;IAC3D,OAAO,EAAE,gBAAgB,CAAC,mCAAmC,CAAC,CAAC;CAChE,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,sCAAsC,GAAG;IACnD,IAAI,EAAE,mCAAmC,CAAC;IAC1C,OAAO,EAAE,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;CAC/C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,iCAAiC,GAAG;IAC9C,IAAI,EAAE,8BAA8B,CAAC;IACrC,OAAO,EAAE,gBAAgB,CAAC,aAAa,CAAC,CAAC;CAC1C,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,qCAAqC,GAAG;IAClD,IAAI,EAAE,kCAAkC,CAAC;IACzC,OAAO,EAAE,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;CAC9C,CAAC;AAEF,MAAM,MAAM,4CAA4C,GAAG;IACzD,IAAI,EAAE,yCAAyC,CAAC;IAChD,OAAO,EAAE,gBAAgB,CAAC,wBAAwB,CAAC,CAAC;CACrD,CAAC;AAEF,MAAM,MAAM,6CAA6C,GAAG;IAC1D,IAAI,EAAE,0CAA0C,CAAC;IACjD,OAAO,EAAE,gBAAgB,CAAC,yBAAyB,CAAC,CAAC;CACtD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GACrC,kCAAkC,GAClC,0CAA0C,GAC1C,uDAAuD,GACvD,sCAAsC,GACtC,iCAAiC,GACjC,qCAAqC,GACrC,4CAA4C,GAC5C,6CAA6C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GasFeeController-method-action-types.js","sourceRoot":"","sources":["../src/GasFeeController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { GasFeeController } from './GasFeeController.js';\n\n/**\n * Resets the polling interval by stopping and restarting polling\n * with the existing poll tokens.\n */\nexport type GasFeeControllerResetPollingAction = {\n type: `GasFeeController:resetPolling`;\n handler: GasFeeController['resetPolling'];\n};\n\n/**\n * Fetches gas fee estimates.\n *\n * @param options - The gas fee estimate options.\n * @returns The gas fee estimates.\n */\nexport type GasFeeControllerFetchGasFeeEstimatesAction = {\n type: `GasFeeController:fetchGasFeeEstimates`;\n handler: GasFeeController['fetchGasFeeEstimates'];\n};\n\n/**\n * Gets gas fee estimates and starts polling for updates.\n *\n * @param pollToken - An existing poll token to reuse, or undefined to\n * generate a new one.\n * @returns The poll token that can be used to stop polling.\n */\nexport type GasFeeControllerGetGasFeeEstimatesAndStartPollingAction = {\n type: `GasFeeController:getGasFeeEstimatesAndStartPolling`;\n handler: GasFeeController['getGasFeeEstimatesAndStartPolling'];\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 */\nexport type GasFeeControllerDisconnectPollerAction = {\n type: `GasFeeController:disconnectPoller`;\n handler: GasFeeController['disconnectPoller'];\n};\n\n/**\n * Stops polling for gas fee estimates and clears all poll tokens.\n */\nexport type GasFeeControllerStopPollingAction = {\n type: `GasFeeController:stopPolling`;\n handler: GasFeeController['stopPolling'];\n};\n\n/**\n * Gets the estimated time for a transaction based on the given gas parameters.\n *\n * @param maxPriorityFeePerGas - The maximum priority fee per gas in GWEI.\n * @param maxFeePerGas - The maximum fee per gas in GWEI.\n * @returns The estimated time bounds, or an empty object if fee market\n * estimates are not available.\n */\nexport type GasFeeControllerGetTimeEstimateAction = {\n type: `GasFeeController:getTimeEstimate`;\n handler: GasFeeController['getTimeEstimate'];\n};\n\nexport type GasFeeControllerEnableNonRPCGasFeeApisAction = {\n type: `GasFeeController:enableNonRPCGasFeeApis`;\n handler: GasFeeController['enableNonRPCGasFeeApis'];\n};\n\nexport type GasFeeControllerDisableNonRPCGasFeeApisAction = {\n type: `GasFeeController:disableNonRPCGasFeeApis`;\n handler: GasFeeController['disableNonRPCGasFeeApis'];\n};\n\n/**\n * Union of all GasFeeController action types.\n */\nexport type GasFeeControllerMethodActions =\n | GasFeeControllerResetPollingAction\n | GasFeeControllerFetchGasFeeEstimatesAction\n | GasFeeControllerGetGasFeeEstimatesAndStartPollingAction\n | GasFeeControllerDisconnectPollerAction\n | GasFeeControllerStopPollingAction\n | GasFeeControllerGetTimeEstimateAction\n | GasFeeControllerEnableNonRPCGasFeeApisAction\n | GasFeeControllerDisableNonRPCGasFeeApisAction;\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { ControllerGetStateAction, ControllerStateChangeEvent } from
|
|
2
|
-
import type { Messenger } from
|
|
3
|
-
import type { NetworkClientId, NetworkControllerGetEIP1559CompatibilityAction, NetworkControllerGetNetworkClientByIdAction, NetworkControllerGetStateAction, NetworkControllerNetworkDidChangeEvent, NetworkState, ProviderProxy } from
|
|
4
|
-
import type { Hex } from
|
|
5
|
-
import type { GasFeeControllerMethodActions } from
|
|
1
|
+
import type { ControllerGetStateAction, ControllerStateChangeEvent } from '@metamask/base-controller';
|
|
2
|
+
import type { Messenger } from '@metamask/messenger';
|
|
3
|
+
import type { NetworkClientId, NetworkControllerGetEIP1559CompatibilityAction, NetworkControllerGetNetworkClientByIdAction, NetworkControllerGetStateAction, NetworkControllerNetworkDidChangeEvent, NetworkState, ProviderProxy } from '@metamask/network-controller';
|
|
4
|
+
import type { Hex } from '@metamask/utils';
|
|
5
|
+
import type { GasFeeControllerMethodActions } from './GasFeeController-method-action-types.js';
|
|
6
6
|
export declare const LEGACY_GAS_PRICES_API_URL = "https://api.metaswap.codefi.network/gasPrices";
|
|
7
7
|
export type unknownString = 'unknown';
|
|
8
8
|
export type FeeMarketEstimateType = 'fee-market';
|
|
@@ -16,10 +16,10 @@ export type NoEstimateType = 'none';
|
|
|
16
16
|
* has been fetched.
|
|
17
17
|
*/
|
|
18
18
|
export declare const GAS_ESTIMATE_TYPES: {
|
|
19
|
-
FEE_MARKET:
|
|
20
|
-
LEGACY:
|
|
21
|
-
ETH_GASPRICE:
|
|
22
|
-
NONE:
|
|
19
|
+
FEE_MARKET: FeeMarketEstimateType;
|
|
20
|
+
LEGACY: LegacyEstimateType;
|
|
21
|
+
ETH_GASPRICE: EthGasPriceEstimateType;
|
|
22
|
+
NONE: NoEstimateType;
|
|
23
23
|
};
|
|
24
24
|
export type GasEstimateType = FeeMarketEstimateType | EthGasPriceEstimateType | LegacyEstimateType | NoEstimateType;
|
|
25
25
|
export type EstimatedGasFeeTimeBounds = {
|
|
@@ -158,18 +158,18 @@ type GasFeePollingInput = {
|
|
|
158
158
|
networkClientId: NetworkClientId;
|
|
159
159
|
};
|
|
160
160
|
declare const GasFeeController_base: (abstract new (...args: any[]) => {
|
|
161
|
-
readonly
|
|
162
|
-
"__#6@#intervalLength": number | undefined;
|
|
163
|
-
setIntervalLength(intervalLength: number): void;
|
|
164
|
-
getIntervalLength(): number | undefined;
|
|
165
|
-
_startPolling(input: GasFeePollingInput): void;
|
|
166
|
-
_stopPollingByPollingTokenSetId(key: string): void;
|
|
167
|
-
readonly "__#3@#pollingTokenSets": Map<string, Set<string>>;
|
|
168
|
-
readonly "__#3@#callbacks": Map<string, Set<(input: GasFeePollingInput) => void>>;
|
|
161
|
+
readonly _callbacks: Map<string, Set<(input: GasFeePollingInput) => void>>;
|
|
169
162
|
_executePoll(input: GasFeePollingInput): Promise<void>;
|
|
170
163
|
startPolling(input: GasFeePollingInput): string;
|
|
171
164
|
stopAllPolling(): void;
|
|
172
165
|
stopPollingByPollingToken(pollingToken: string): void;
|
|
166
|
+
readonly _intervalIds: Record<import("@metamask/polling-controller").PollingTokenSetId, NodeJS.Timeout>;
|
|
167
|
+
_intervalLength: number | undefined;
|
|
168
|
+
setIntervalLength(intervalLength: number): void;
|
|
169
|
+
getIntervalLength(): number | undefined;
|
|
170
|
+
_startPolling(input: GasFeePollingInput): void;
|
|
171
|
+
_stopPollingByPollingTokenSetId(key: import("@metamask/polling-controller").PollingTokenSetId): void;
|
|
172
|
+
readonly _pollingTokenSets: Map<import("@metamask/polling-controller").PollingTokenSetId, Set<string>>;
|
|
173
173
|
onPollingComplete(input: GasFeePollingInput, callback: (input: GasFeePollingInput) => void): void;
|
|
174
174
|
}) & typeof import("@metamask/base-controller").BaseController;
|
|
175
175
|
/**
|
|
@@ -294,4 +294,4 @@ export declare class GasFeeController extends GasFeeController_base<typeof name,
|
|
|
294
294
|
disableNonRPCGasFeeApis(): void;
|
|
295
295
|
}
|
|
296
296
|
export default GasFeeController;
|
|
297
|
-
//# sourceMappingURL=GasFeeController.d.
|
|
297
|
+
//# 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,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,MAAM,2BAA2B,CAAC;AAOnC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EACV,eAAe,EACf,8CAA8C,EAC9C,2CAA2C,EAC3C,+BAA+B,EAC/B,sCAAsC,EACtC,YAAY,EACZ,aAAa,EACd,MAAM,8BAA8B,CAAC;AAEtC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAU3C,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,2CAA2C,CAAC;AAE/F,eAAO,MAAM,yBAAyB,kDAAkD,CAAC;AAEzF,MAAM,MAAM,aAAa,GAAG,SAAS,CAAC;AAItC,MAAM,MAAM,qBAAqB,GAAG,YAAY,CAAC;AAIjD,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAC;AAK1C,MAAM,MAAM,uBAAuB,GAAG,cAAc,CAAC;AAGrD,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC;AAEpC;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB;IAC7B,UAAU,EAAkB,qBAAqB;IACjD,MAAM,EAAc,kBAAkB;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AM,GAAG,SAAS,GAC5B,OAAO,CAAC,MAAM,CAAC,CAWjB;IAED;;;;;;;OAOG;IACG,wBAAwB,CAC5B,OAAO,GAAE,0BAA+B,GACvC,OAAO,CAAC,WAAW,CAAC,CAoFtB;IAED;;;;OAIG;IACH,gBAAgB,CAAC,SAAS,EAAE,MAAM,QAKjC;IAED;;OAEG;IACH,WAAW,SAMV;IAED;;;;OAIG;IACM,OAAO,SAGf;IAED,OAAO,CAAC,KAAK;IAYb;;;;;;OAMG;IACG,YAAY,CAAC,EAAE,eAAe,EAAE,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAEzE;IAED,OAAO,CAAC,UAAU;YAMJ,uBAAuB;IAWrC;;;;;;;OAOG;IACH,eAAe,CACb,oBAAoB,EAAE,MAAM,EAC5B,YAAY,EAAE,MAAM,GACnB,yBAAyB,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAYnD;IA2CD,sBAAsB,SAIrB;IAED,uBAAuB,SAItB;CACF;eAEc,gBAAgB"}
|
|
@@ -1,28 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
-
};
|
|
12
|
-
var _GasFeeController_instances, _GasFeeController_getProvider, _GasFeeController_getChainId, _GasFeeController_onNetworkControllerDidChange, _GasFeeController_getEthQuery, _GasFeeController_getCurrentChainId, _GasFeeController_getChainIdFromNetworkController, _GasFeeController_getChainIdForNetworkClient;
|
|
13
|
-
function $importDefault(module) {
|
|
14
|
-
if (module?.__esModule) {
|
|
15
|
-
return module.default;
|
|
16
|
-
}
|
|
17
|
-
return module;
|
|
18
|
-
}
|
|
19
|
-
import { convertHexToDecimal, safelyExecute, toHex } from "@metamask/controller-utils";
|
|
20
|
-
import $EthQuery from "@metamask/eth-query";
|
|
21
|
-
const EthQuery = $importDefault($EthQuery);
|
|
22
|
-
import { StaticIntervalPollingController } from "@metamask/polling-controller";
|
|
23
|
-
import { v1 as random } from "uuid";
|
|
24
|
-
import determineGasFeeCalculations from "./determineGasFeeCalculations.mjs";
|
|
25
|
-
import { fetchGasEstimates, fetchLegacyGasPriceEstimates, fetchEthGasPriceEstimate, calculateTimeEstimate } from "./gas-util.mjs";
|
|
1
|
+
import { convertHexToDecimal, safelyExecute, toHex, } from '@metamask/controller-utils';
|
|
2
|
+
import EthQuery from '@metamask/eth-query';
|
|
3
|
+
import { StaticIntervalPollingController } from '@metamask/polling-controller';
|
|
4
|
+
import { v1 as random } from 'uuid';
|
|
5
|
+
import determineGasFeeCalculations from './determineGasFeeCalculations.js';
|
|
6
|
+
import { fetchGasEstimates, fetchLegacyGasPriceEstimates, fetchEthGasPriceEstimate, calculateTimeEstimate, } from './gas-util.js';
|
|
26
7
|
export const LEGACY_GAS_PRICES_API_URL = `https://api.metaswap.codefi.network/gasPrices`;
|
|
27
8
|
/**
|
|
28
9
|
* Indicates which type of gasEstimate the controller is currently returning.
|
|
@@ -90,6 +71,19 @@ const defaultState = {
|
|
|
90
71
|
* Controller that retrieves gas fee estimate data and polls for updated data on a set interval
|
|
91
72
|
*/
|
|
92
73
|
export class GasFeeController extends StaticIntervalPollingController() {
|
|
74
|
+
intervalId;
|
|
75
|
+
intervalDelay;
|
|
76
|
+
pollTokens;
|
|
77
|
+
legacyAPIEndpoint;
|
|
78
|
+
EIP1559APIEndpoint;
|
|
79
|
+
getCurrentNetworkEIP1559Compatibility;
|
|
80
|
+
getCurrentNetworkLegacyGasAPICompatibility;
|
|
81
|
+
getCurrentAccountEIP1559Compatibility;
|
|
82
|
+
currentChainId;
|
|
83
|
+
ethQuery;
|
|
84
|
+
clientId;
|
|
85
|
+
#getProvider;
|
|
86
|
+
#getChainId;
|
|
93
87
|
/**
|
|
94
88
|
* Creates a GasFeeController instance.
|
|
95
89
|
*
|
|
@@ -120,9 +114,6 @@ export class GasFeeController extends StaticIntervalPollingController() {
|
|
|
120
114
|
messenger,
|
|
121
115
|
state: { ...defaultState, ...state },
|
|
122
116
|
});
|
|
123
|
-
_GasFeeController_instances.add(this);
|
|
124
|
-
_GasFeeController_getProvider.set(this, void 0);
|
|
125
|
-
_GasFeeController_getChainId.set(this, void 0);
|
|
126
117
|
this.intervalDelay = interval;
|
|
127
118
|
this.setIntervalLength(interval);
|
|
128
119
|
this.pollTokens = new Set();
|
|
@@ -132,17 +123,17 @@ export class GasFeeController extends StaticIntervalPollingController() {
|
|
|
132
123
|
getCurrentNetworkLegacyGasAPICompatibility;
|
|
133
124
|
this.getCurrentAccountEIP1559Compatibility =
|
|
134
125
|
getCurrentAccountEIP1559Compatibility;
|
|
135
|
-
|
|
126
|
+
this.#getProvider = getProvider;
|
|
136
127
|
this.EIP1559APIEndpoint = EIP1559APIEndpoint;
|
|
137
128
|
this.legacyAPIEndpoint = legacyAPIEndpoint;
|
|
138
129
|
this.clientId = clientId;
|
|
139
130
|
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
140
131
|
if (onNetworkDidChange && getChainId) {
|
|
141
|
-
|
|
132
|
+
this.#getChainId = getChainId;
|
|
142
133
|
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
143
134
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
144
135
|
onNetworkDidChange(async (networkControllerState) => {
|
|
145
|
-
await
|
|
136
|
+
await this.#onNetworkControllerDidChange(networkControllerState);
|
|
146
137
|
});
|
|
147
138
|
}
|
|
148
139
|
else {
|
|
@@ -150,7 +141,7 @@ export class GasFeeController extends StaticIntervalPollingController() {
|
|
|
150
141
|
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
151
142
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
152
143
|
async (networkControllerState) => {
|
|
153
|
-
await
|
|
144
|
+
await this.#onNetworkControllerDidChange(networkControllerState);
|
|
154
145
|
});
|
|
155
146
|
}
|
|
156
147
|
}
|
|
@@ -217,15 +208,16 @@ export class GasFeeController extends StaticIntervalPollingController() {
|
|
|
217
208
|
}
|
|
218
209
|
ethQuery = new EthQuery(networkClient.provider);
|
|
219
210
|
}
|
|
220
|
-
ethQuery
|
|
221
|
-
isLegacyGasAPICompatible
|
|
222
|
-
|
|
211
|
+
ethQuery ??= this.#getEthQuery();
|
|
212
|
+
isLegacyGasAPICompatible ??=
|
|
213
|
+
this.getCurrentNetworkLegacyGasAPICompatibility();
|
|
214
|
+
decimalChainId ??= convertHexToDecimal(this.#getCurrentChainId());
|
|
223
215
|
try {
|
|
224
|
-
isEIP1559Compatible
|
|
216
|
+
isEIP1559Compatible ??= await this.getEIP1559Compatibility();
|
|
225
217
|
}
|
|
226
218
|
catch (e) {
|
|
227
219
|
console.error(e);
|
|
228
|
-
isEIP1559Compatible
|
|
220
|
+
isEIP1559Compatible ??= false;
|
|
229
221
|
}
|
|
230
222
|
const gasFeeCalculations = await determineGasFeeCalculations({
|
|
231
223
|
isEIP1559Compatible,
|
|
@@ -242,7 +234,7 @@ export class GasFeeController extends StaticIntervalPollingController() {
|
|
|
242
234
|
});
|
|
243
235
|
if (shouldUpdateState) {
|
|
244
236
|
const chainId = toHex(decimalChainId);
|
|
245
|
-
const currentChainId =
|
|
237
|
+
const currentChainId = this.#getCurrentChainId();
|
|
246
238
|
this.update((state) => {
|
|
247
239
|
if (currentChainId === chainId) {
|
|
248
240
|
state.gasFeeEstimates = gasFeeCalculations.gasFeeEstimates;
|
|
@@ -250,7 +242,7 @@ export class GasFeeController extends StaticIntervalPollingController() {
|
|
|
250
242
|
gasFeeCalculations.estimatedGasFeeTimeBounds;
|
|
251
243
|
state.gasEstimateType = gasFeeCalculations.gasEstimateType;
|
|
252
244
|
}
|
|
253
|
-
state.gasFeeEstimatesByChainId
|
|
245
|
+
state.gasFeeEstimatesByChainId ??= {};
|
|
254
246
|
state.gasFeeEstimatesByChainId[chainId] = {
|
|
255
247
|
gasFeeEstimates: gasFeeCalculations.gasFeeEstimates,
|
|
256
248
|
estimatedGasFeeTimeBounds: gasFeeCalculations.estimatedGasFeeTimeBounds,
|
|
@@ -335,6 +327,31 @@ export class GasFeeController extends StaticIntervalPollingController() {
|
|
|
335
327
|
}
|
|
336
328
|
return calculateTimeEstimate(maxPriorityFeePerGas, maxFeePerGas, this.state.gasFeeEstimates);
|
|
337
329
|
}
|
|
330
|
+
async #onNetworkControllerDidChange({ selectedNetworkClientId, }) {
|
|
331
|
+
const newChainId = this.#getChainIdForNetworkClient(selectedNetworkClientId);
|
|
332
|
+
if (newChainId !== this.currentChainId) {
|
|
333
|
+
// Reset so the next fetch rebuilds it from the new network's provider.
|
|
334
|
+
this.ethQuery = undefined;
|
|
335
|
+
await this.resetPolling();
|
|
336
|
+
this.currentChainId = newChainId;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
#getEthQuery() {
|
|
340
|
+
this.ethQuery ??= new EthQuery(this.#getProvider());
|
|
341
|
+
return this.ethQuery;
|
|
342
|
+
}
|
|
343
|
+
#getCurrentChainId() {
|
|
344
|
+
this.currentChainId ??=
|
|
345
|
+
this.#getChainId?.() ?? this.#getChainIdFromNetworkController();
|
|
346
|
+
return this.currentChainId;
|
|
347
|
+
}
|
|
348
|
+
#getChainIdFromNetworkController() {
|
|
349
|
+
const { selectedNetworkClientId } = this.messenger.call('NetworkController:getState');
|
|
350
|
+
return this.#getChainIdForNetworkClient(selectedNetworkClientId);
|
|
351
|
+
}
|
|
352
|
+
#getChainIdForNetworkClient(networkClientId) {
|
|
353
|
+
return this.messenger.call('NetworkController:getNetworkClientById', networkClientId).configuration.chainId;
|
|
354
|
+
}
|
|
338
355
|
enableNonRPCGasFeeApis() {
|
|
339
356
|
this.update((state) => {
|
|
340
357
|
state.nonRPCGasFeeApisDisabled = false;
|
|
@@ -346,25 +363,5 @@ export class GasFeeController extends StaticIntervalPollingController() {
|
|
|
346
363
|
});
|
|
347
364
|
}
|
|
348
365
|
}
|
|
349
|
-
_GasFeeController_getProvider = new WeakMap(), _GasFeeController_getChainId = new WeakMap(), _GasFeeController_instances = new WeakSet(), _GasFeeController_onNetworkControllerDidChange = async function _GasFeeController_onNetworkControllerDidChange({ selectedNetworkClientId, }) {
|
|
350
|
-
const newChainId = __classPrivateFieldGet(this, _GasFeeController_instances, "m", _GasFeeController_getChainIdForNetworkClient).call(this, selectedNetworkClientId);
|
|
351
|
-
if (newChainId !== this.currentChainId) {
|
|
352
|
-
// Reset so the next fetch rebuilds it from the new network's provider.
|
|
353
|
-
this.ethQuery = undefined;
|
|
354
|
-
await this.resetPolling();
|
|
355
|
-
this.currentChainId = newChainId;
|
|
356
|
-
}
|
|
357
|
-
}, _GasFeeController_getEthQuery = function _GasFeeController_getEthQuery() {
|
|
358
|
-
this.ethQuery ?? (this.ethQuery = new EthQuery(__classPrivateFieldGet(this, _GasFeeController_getProvider, "f").call(this)));
|
|
359
|
-
return this.ethQuery;
|
|
360
|
-
}, _GasFeeController_getCurrentChainId = function _GasFeeController_getCurrentChainId() {
|
|
361
|
-
this.currentChainId ?? (this.currentChainId = __classPrivateFieldGet(this, _GasFeeController_getChainId, "f")?.call(this) ?? __classPrivateFieldGet(this, _GasFeeController_instances, "m", _GasFeeController_getChainIdFromNetworkController).call(this));
|
|
362
|
-
return this.currentChainId;
|
|
363
|
-
}, _GasFeeController_getChainIdFromNetworkController = function _GasFeeController_getChainIdFromNetworkController() {
|
|
364
|
-
const { selectedNetworkClientId } = this.messenger.call('NetworkController:getState');
|
|
365
|
-
return __classPrivateFieldGet(this, _GasFeeController_instances, "m", _GasFeeController_getChainIdForNetworkClient).call(this, selectedNetworkClientId);
|
|
366
|
-
}, _GasFeeController_getChainIdForNetworkClient = function _GasFeeController_getChainIdForNetworkClient(networkClientId) {
|
|
367
|
-
return this.messenger.call('NetworkController:getNetworkClientById', networkClientId).configuration.chainId;
|
|
368
|
-
};
|
|
369
366
|
export default GasFeeController;
|
|
370
|
-
//# sourceMappingURL=GasFeeController.
|
|
367
|
+
//# sourceMappingURL=GasFeeController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GasFeeController.js","sourceRoot":"","sources":["../src/GasFeeController.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,KAAK,GACN,MAAM,4BAA4B,CAAC;AACpC,OAAO,QAAQ,MAAM,qBAAqB,CAAC;AAW3C,OAAO,EAAE,+BAA+B,EAAE,MAAM,8BAA8B,CAAC;AAE/E,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,2BAA2B,MAAM,kCAAkC,CAAC;AAC3E,OAAO,EACL,iBAAiB,EACjB,4BAA4B,EAC5B,wBAAwB,EACxB,qBAAqB,GACtB,MAAM,eAAe,CAAC;AAGvB,MAAM,CAAC,MAAM,yBAAyB,GAAG,+CAA+C,CAAC;AAoBzF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,UAAU,EAAE,YAAqC;IACjD,MAAM,EAAE,QAA8B;IACtC,YAAY,EAAE,cAAyC;IACvD,IAAI,EAAE,MAAwB;CAC/B,CAAC;AAqGF,MAAM,QAAQ,GAA+B;IAC3C,wBAAwB,EAAE;QACxB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,IAAI;KACf;IACD,eAAe,EAAE;QACf,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,IAAI;KACf;IACD,yBAAyB,EAA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KAAK,CAAC,wBAAwB,GAAG,KAAK,CAAC;QACzC,CAAC,CAAC,CAAC;IACL,CAAC;IAED,uBAAuB;QACrB,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,wBAAwB,GAAG,IAAI,CAAC;QACxC,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED,eAAe,gBAAgB,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\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 { Messenger } from '@metamask/messenger';\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.js';\nimport {\n fetchGasEstimates,\n fetchLegacyGasPriceEstimates,\n fetchEthGasPriceEstimate,\n calculateTimeEstimate,\n} from './gas-util.js';\nimport type { GasFeeControllerMethodActions } from './GasFeeController-method-action-types.js';\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 *\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 *\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 *\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 *\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: StateMetadata<GasFeeState> = {\n gasFeeEstimatesByChainId: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n gasFeeEstimates: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n estimatedGasFeeTimeBounds: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n gasEstimateType: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n nonRPCGasFeeApisDisabled: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\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 *\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\nconst MESSENGER_EXPOSED_METHODS = [\n 'disableNonRPCGasFeeApis',\n 'disconnectPoller',\n 'enableNonRPCGasFeeApis',\n 'fetchGasFeeEstimates',\n 'getGasFeeEstimatesAndStartPolling',\n 'getTimeEstimate',\n 'resetPolling',\n 'stopPolling',\n] as const;\n\nexport type GasFeeStateChange = ControllerStateChangeEvent<\n typeof name,\n GasFeeState\n>;\n\nexport type GetGasFeeState = ControllerGetStateAction<typeof name, GasFeeState>;\n\nexport type GasFeeControllerActions =\n | GetGasFeeState\n | GasFeeControllerMethodActions;\n\nexport type GasFeeControllerEvents = GasFeeStateChange;\n\ntype AllowedActions =\n | NetworkControllerGetStateAction\n | NetworkControllerGetNetworkClientByIdAction\n | NetworkControllerGetEIP1559CompatibilityAction;\n\nexport type GasFeeMessenger = Messenger<\n typeof name,\n GasFeeControllerActions | AllowedActions,\n GasFeeControllerEvents | NetworkControllerNetworkDidChangeEvent\n>;\n\nconst defaultState: GasFeeState = {\n gasFeeEstimatesByChainId: {},\n gasFeeEstimates: {},\n estimatedGasFeeTimeBounds: {},\n gasEstimateType: GAS_ESTIMATE_TYPES.NONE,\n nonRPCGasFeeApisDisabled: false,\n};\n\n/** The input to start polling for the {@link GasFeeController} */\ntype GasFeePollingInput = {\n networkClientId: NetworkClientId;\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<GasFeePollingInput>()<\n typeof name,\n GasFeeState,\n GasFeeMessenger\n> {\n private intervalId?: ReturnType<typeof setTimeout>;\n\n private readonly intervalDelay;\n\n private readonly pollTokens: Set<string>;\n\n private readonly legacyAPIEndpoint: string;\n\n private readonly EIP1559APIEndpoint: string;\n\n private readonly getCurrentNetworkEIP1559Compatibility;\n\n private readonly getCurrentNetworkLegacyGasAPICompatibility;\n\n private readonly getCurrentAccountEIP1559Compatibility;\n\n private currentChainId?: Hex;\n\n private ethQuery?: EthQuery;\n\n private readonly clientId?: string;\n\n readonly #getProvider: () => ProviderProxy;\n\n readonly #getChainId?: () => Hex;\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 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.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n\n if (onNetworkDidChange && getChainId) {\n this.#getChainId = 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 this.messenger.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 /**\n * Resets the polling interval by stopping and restarting polling\n * with the existing poll tokens.\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 /**\n * Fetches gas fee estimates.\n *\n * @param options - The gas fee estimate options.\n * @returns The gas fee estimates.\n */\n async fetchGasFeeEstimates(options?: FetchGasFeeEstimateOptions) {\n return await this._fetchGasFeeEstimateData(options);\n }\n\n /**\n * Gets gas fee estimates and starts polling for updates.\n *\n * @param pollToken - An existing poll token to reuse, or undefined to\n * generate a new one.\n * @returns The poll token that can be used to stop polling.\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.messenger.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.messenger.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.#getEthQuery();\n\n isLegacyGasAPICompatible ??=\n this.getCurrentNetworkLegacyGasAPICompatibility();\n\n decimalChainId ??= convertHexToDecimal(this.#getCurrentChainId());\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 const currentChainId = this.#getCurrentChainId();\n this.update((state) => {\n if (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 /**\n * Stops polling for gas fee estimates and clears all poll tokens.\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 * @param input - The input for the poll.\n * @param input.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 }: GasFeePollingInput): 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 /**\n * Gets the estimated time for a transaction based on the given gas parameters.\n *\n * @param maxPriorityFeePerGas - The maximum priority fee per gas in GWEI.\n * @param maxFeePerGas - The maximum fee per gas in GWEI.\n * @returns The estimated time bounds, or an empty object if fee market\n * estimates are not available.\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.#getChainIdForNetworkClient(\n selectedNetworkClientId,\n );\n\n if (newChainId !== this.currentChainId) {\n // Reset so the next fetch rebuilds it from the new network's provider.\n this.ethQuery = undefined;\n await this.resetPolling();\n\n this.currentChainId = newChainId;\n }\n }\n\n #getEthQuery(): EthQuery {\n this.ethQuery ??= new EthQuery(this.#getProvider());\n return this.ethQuery;\n }\n\n #getCurrentChainId(): Hex {\n this.currentChainId ??=\n this.#getChainId?.() ?? this.#getChainIdFromNetworkController();\n return this.currentChainId;\n }\n\n #getChainIdFromNetworkController(): Hex {\n const { selectedNetworkClientId } = this.messenger.call(\n 'NetworkController:getState',\n );\n return this.#getChainIdForNetworkClient(selectedNetworkClientId);\n }\n\n #getChainIdForNetworkClient(networkClientId: NetworkClientId): Hex {\n return this.messenger.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n ).configuration.chainId;\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"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { EstimatedGasFeeTimeBounds, EthGasPriceEstimate, GasFeeEstimates, GasFeeState as GasFeeCalculations, LegacyGasPriceEstimate } from
|
|
1
|
+
import type { EstimatedGasFeeTimeBounds, EthGasPriceEstimate, GasFeeEstimates, GasFeeState as GasFeeCalculations, LegacyGasPriceEstimate } from './GasFeeController.js';
|
|
2
2
|
type DetermineGasFeeCalculationsRequest = {
|
|
3
3
|
isEIP1559Compatible: boolean;
|
|
4
4
|
isLegacyGasAPICompatible: boolean;
|
|
@@ -39,4 +39,4 @@ type DetermineGasFeeCalculationsRequest = {
|
|
|
39
39
|
*/
|
|
40
40
|
export default function determineGasFeeCalculations(args: DetermineGasFeeCalculationsRequest): Promise<GasFeeCalculations>;
|
|
41
41
|
export {};
|
|
42
|
-
//# sourceMappingURL=determineGasFeeCalculations.d.
|
|
42
|
+
//# sourceMappingURL=determineGasFeeCalculations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"determineGasFeeCalculations.d.ts","sourceRoot":"","sources":["../src/determineGasFeeCalculations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,yBAAyB,EACzB,mBAAmB,EACnB,eAAe,EACf,WAAW,IAAI,kBAAkB,EACjC,sBAAsB,EACvB,MAAM,uBAAuB,CAAC;AAG/B,KAAK,kCAAkC,GAAG;IACxC,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,4BAA4B,EAAE,CAC5B,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,MAAM,KACd,OAAO,CAAC,sBAAsB,CAAC,CAAC;IACrC,+BAA+B,EAAE,MAAM,CAAC;IAGxC,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;IAG7B,QAAQ,EAAE,GAAG,CAAC;IACd,wBAAwB,CAAC,EAAE,OAAO,CAAC;CACpC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAA8B,2BAA2B,CACvD,IAAI,EAAE,kCAAkC,GACvC,OAAO,CAAC,kBAAkB,CAAC,CAY7B"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GAS_ESTIMATE_TYPES } from
|
|
1
|
+
import { GAS_ESTIMATE_TYPES } from './GasFeeController.js';
|
|
2
2
|
/**
|
|
3
3
|
* Obtains a set of max base and priority fee estimates along with time estimates so that we
|
|
4
4
|
* can present them to users when they are sending transactions or making swaps.
|
|
@@ -103,4 +103,4 @@ async function getEstimatesUsingProvider(request) {
|
|
|
103
103
|
gasEstimateType: GAS_ESTIMATE_TYPES.ETH_GASPRICE,
|
|
104
104
|
};
|
|
105
105
|
}
|
|
106
|
-
//# sourceMappingURL=determineGasFeeCalculations.
|
|
106
|
+
//# sourceMappingURL=determineGasFeeCalculations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"determineGasFeeCalculations.js","sourceRoot":"","sources":["../src/determineGasFeeCalculations.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AA8B3D;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,2BAA2B,CACvD,IAAwC;IAExC,IAAI,CAAC;QACH,OAAO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AAyB;QACzB,eAAe,EAAE,kBAAkB,CAAC,UAAU;KAC/C,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,KAAK,UAAU,+BAA+B,CAC5C,OAA2C;IAE3C,MAAM,EACJ,4BAA4B,EAC5B,+BAA+B,EAC/B,QAAQ,GACT,GAAG,OAAO,CAAC;IAEZ,MAAM,SAAS,GAAG,MAAM,4BAA4B,CAClD,+BAA+B,EAC/B,QAAQ,CACT,CAAC;IAEF,OAAO;QACL,eAAe,EAAE,SAAS;QAC1B,yBAAyB,EAAE,EAAE;QAC7B,eAAe,EAAE,kBAAkB,CAAC,MAAM;KAC3C,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,KAAK,UAAU,yBAAyB,CACtC,OAA2C;IAE3C,MAAM,EAAE,QAAQ,EAAE,wBAAwB,EAAE,GAAG,OAAO,CAAC;IAEvD,MAAM,SAAS,GAAG,MAAM,wBAAwB,CAAC,QAAQ,CAAC,CAAC;IAE3D,OAAO;QACL,eAAe,EAAE,SAAS;QAC1B,yBAAyB,EAAE,EAAE;QAC7B,eAAe,EAAE,kBAAkB,CAAC,YAAY;KACjD,CAAC;AACJ,CAAC","sourcesContent":["import type {\n EstimatedGasFeeTimeBounds,\n EthGasPriceEstimate,\n GasFeeEstimates,\n GasFeeState as GasFeeCalculations,\n LegacyGasPriceEstimate,\n} from './GasFeeController.js';\nimport { GAS_ESTIMATE_TYPES } from './GasFeeController.js';\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 *\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 *\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 *\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 *\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"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type EthQuery from
|
|
2
|
-
import type { GasFeeEstimates, EthGasPriceEstimate, EstimatedGasFeeTimeBounds, LegacyGasPriceEstimate } from
|
|
1
|
+
import type EthQuery from '@metamask/eth-query';
|
|
2
|
+
import type { GasFeeEstimates, EthGasPriceEstimate, EstimatedGasFeeTimeBounds, LegacyGasPriceEstimate } from './GasFeeController.js';
|
|
3
3
|
/**
|
|
4
4
|
* Convert a decimal GWEI value to a decimal string rounded to the nearest WEI.
|
|
5
5
|
*
|
|
@@ -40,4 +40,4 @@ export declare function fetchEthGasPriceEstimate(ethQuery: EthQuery): Promise<Et
|
|
|
40
40
|
* @returns The estimated lower and upper bounds for when this transaction will be confirmed.
|
|
41
41
|
*/
|
|
42
42
|
export declare function calculateTimeEstimate(maxPriorityFeePerGas: string, maxFeePerGas: string, gasFeeEstimates: GasFeeEstimates): EstimatedGasFeeTimeBounds;
|
|
43
|
-
//# sourceMappingURL=gas-util.d.
|
|
43
|
+
//# 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":"AAMA,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAC;AAGhD,OAAO,KAAK,EACV,eAAe,EACf,mBAAmB,EACnB,yBAAyB,EAEzB,sBAAsB,EACvB,MAAM,uBAAuB,CAAC;AAI/B;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,UAI7D;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,QAAQ,GACjB,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"}
|
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return module.default;
|
|
4
|
-
}
|
|
5
|
-
return module;
|
|
6
|
-
}
|
|
7
|
-
import { query, handleFetch, gweiDecToWEIBN, weiHexToGweiDec } from "@metamask/controller-utils";
|
|
8
|
-
import $BN from "bn.js";
|
|
9
|
-
const BN = $importDefault($BN);
|
|
1
|
+
import { query, handleFetch, gweiDecToWEIBN, weiHexToGweiDec, } from '@metamask/controller-utils';
|
|
2
|
+
import BN from 'bn.js';
|
|
10
3
|
const makeClientIdHeader = (clientId) => ({ 'X-Client-Id': clientId });
|
|
11
4
|
/**
|
|
12
5
|
* Convert a decimal GWEI value to a decimal string rounded to the nearest WEI.
|
|
@@ -136,4 +129,4 @@ export function calculateTimeEstimate(maxPriorityFeePerGas, maxFeePerGas, gasFee
|
|
|
136
129
|
upperTimeBound,
|
|
137
130
|
};
|
|
138
131
|
}
|
|
139
|
-
//# sourceMappingURL=gas-util.
|
|
132
|
+
//# sourceMappingURL=gas-util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gas-util.js","sourceRoot":"","sources":["../src/gas-util.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,WAAW,EACX,cAAc,EACd,eAAe,GAChB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,MAAM,OAAO,CAAC;AAUvB,MAAM,kBAAkB,GAAG,CAAC,QAAgB,EAAE,EAAE,CAAC,CAAC,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,CAAC;AAE/E;;;;;GAKG;AACH,MAAM,UAAU,2BAA2B,CAAC,CAAkB;IAC5D,MAAM,cAAc,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACtD,MAAM,YAAY,GAAG,eAAe,CAAC,cAAc,CAAC,CAAC;IACrD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,GAAW,EACX,QAAiB;IAEjB,MAAM,SAAS,GAAG,MAAM,WAAW,CACjC,GAAG,EACH,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,kBAAkB,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CACjE,CAAC;IACF,OAAO;QACL,GAAG,EAAE;YACH,GAAG,SAAS,CAAC,GAAG;YAChB,6BAA6B,EAAE,2BAA2B,CACxD,SAAS,CAAC,GAAG,CAAC,6BAA6B,CAC5C;YACD,qBAAqB,EAAE,2BAA2B,CAChD,SAAS,CAAC,GAAG,CAAC,qBAAqB,CACpC;SACF;QACD,MAAM,EAAE;YACN,GAAG,SAAS,CAAC,MAAM;YACnB,6BAA6B,EAAE,2BAA2B,CACxD,SAAS,CA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CAAC;SAAM,IACL,uBAAuB,CAAC,GAAG,CAAC,yBAAyB,CAAC;QACtD,uBAAuB,CAAC,EAAE,CAAC,uBAAuB,CAAC,EACnD,CAAC;QACD,cAAc,GAAG,MAAM,CAAC,mBAAmB,CAAC;QAC5C,cAAc,GAAG,MAAM,CAAC,mBAAmB,CAAC;IAC9C,CAAC;SAAM,IAAI,uBAAuB,CAAC,EAAE,CAAC,uBAAuB,CAAC,EAAE,CAAC;QAC/D,cAAc,GAAG,IAAI,CAAC,mBAAmB,CAAC;QAC1C,cAAc,GAAG,IAAI,CAAC,mBAAmB,CAAC;IAC5C,CAAC;SAAM,CAAC;QACN,cAAc,GAAG,CAAC,CAAC;QACnB,cAAc,GAAG,IAAI,CAAC,mBAAmB,CAAC;IAC5C,CAAC;IAED,OAAO;QACL,cAAc;QACd,cAAc;KACf,CAAC;AACJ,CAAC","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.js';\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"]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export type { GasFeeControllerResetPollingAction, GasFeeControllerFetchGasFeeEstimatesAction, GasFeeControllerGetGasFeeEstimatesAndStartPollingAction, GasFeeControllerDisconnectPollerAction, GasFeeControllerStopPollingAction, GasFeeControllerGetTimeEstimateAction, GasFeeControllerEnableNonRPCGasFeeApisAction, GasFeeControllerDisableNonRPCGasFeeApisAction, } from
|
|
3
|
-
//# sourceMappingURL=index.d.
|
|
1
|
+
export * from './GasFeeController.js';
|
|
2
|
+
export type { GasFeeControllerResetPollingAction, GasFeeControllerFetchGasFeeEstimatesAction, GasFeeControllerGetGasFeeEstimatesAndStartPollingAction, GasFeeControllerDisconnectPollerAction, GasFeeControllerStopPollingAction, GasFeeControllerGetTimeEstimateAction, GasFeeControllerEnableNonRPCGasFeeApisAction, GasFeeControllerDisableNonRPCGasFeeApisAction, } from './GasFeeController-method-action-types.js';
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,YAAY,EACV,kCAAkC,EAClC,0CAA0C,EAC1C,uDAAuD,EACvD,sCAAsC,EACtC,iCAAiC,EACjC,qCAAqC,EACrC,4CAA4C,EAC5C,6CAA6C,GAC9C,MAAM,2CAA2C,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC","sourcesContent":["export * from './GasFeeController.js';\nexport type {\n GasFeeControllerResetPollingAction,\n GasFeeControllerFetchGasFeeEstimatesAction,\n GasFeeControllerGetGasFeeEstimatesAndStartPollingAction,\n GasFeeControllerDisconnectPollerAction,\n GasFeeControllerStopPollingAction,\n GasFeeControllerGetTimeEstimateAction,\n GasFeeControllerEnableNonRPCGasFeeApisAction,\n GasFeeControllerDisableNonRPCGasFeeApisAction,\n} from './GasFeeController-method-action-types.js';\n"]}
|