@metamask/gas-fee-controller 26.0.3 → 26.1.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 +16 -1
- package/dist/GasFeeController-method-action-types.cjs +7 -0
- package/dist/GasFeeController-method-action-types.cjs.map +1 -0
- package/dist/GasFeeController-method-action-types.d.cts +67 -0
- package/dist/GasFeeController-method-action-types.d.cts.map +1 -0
- package/dist/GasFeeController-method-action-types.d.mts +67 -0
- package/dist/GasFeeController-method-action-types.d.mts.map +1 -0
- package/dist/GasFeeController-method-action-types.mjs +6 -0
- package/dist/GasFeeController-method-action-types.mjs.map +1 -0
- package/dist/GasFeeController.cjs +37 -0
- package/dist/GasFeeController.cjs.map +1 -1
- package/dist/GasFeeController.d.cts +30 -1
- package/dist/GasFeeController.d.cts.map +1 -1
- package/dist/GasFeeController.d.mts +30 -1
- package/dist/GasFeeController.d.mts.map +1 -1
- package/dist/GasFeeController.mjs +37 -0
- package/dist/GasFeeController.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [26.1.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Expose missing public `GasFeeController` methods through its messenger ([#8183](https://github.com/MetaMask/core/pull/8183))
|
|
15
|
+
- The following actions are now available:
|
|
16
|
+
- `GasFeeController:resetPolling`
|
|
17
|
+
- `GasFeeController:fetchGasFeeEstimates`
|
|
18
|
+
- `GasFeeController:getGasFeeEstimatesAndStartPolling`
|
|
19
|
+
- `GasFeeController:disconnectPoller`
|
|
20
|
+
- `GasFeeController:stopPolling`
|
|
21
|
+
- `GasFeeController:getTimeEstimate`
|
|
22
|
+
- Corresponding action types (e.g. `GasFeeControllerResetPollingAction`) are available as well.
|
|
23
|
+
|
|
10
24
|
## [26.0.3]
|
|
11
25
|
|
|
12
26
|
### Changed
|
|
@@ -496,7 +510,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
496
510
|
|
|
497
511
|
All changes listed after this point were applied to this package following the monorepo conversion.
|
|
498
512
|
|
|
499
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@26.0
|
|
513
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@26.1.0...HEAD
|
|
514
|
+
[26.1.0]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@26.0.3...@metamask/gas-fee-controller@26.1.0
|
|
500
515
|
[26.0.3]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@26.0.2...@metamask/gas-fee-controller@26.0.3
|
|
501
516
|
[26.0.2]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@26.0.1...@metamask/gas-fee-controller@26.0.2
|
|
502
517
|
[26.0.1]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@26.0.0...@metamask/gas-fee-controller@26.0.1
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GasFeeController-method-action-types.cjs","sourceRoot":"","sources":["../src/GasFeeController-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { GasFeeController } from './GasFeeController';\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\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"]}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is auto generated by `scripts/generate-method-action-types.ts`.
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
*/
|
|
5
|
+
import type { GasFeeController } from "./GasFeeController.cjs";
|
|
6
|
+
/**
|
|
7
|
+
* Resets the polling interval by stopping and restarting polling
|
|
8
|
+
* with the existing poll tokens.
|
|
9
|
+
*/
|
|
10
|
+
export type GasFeeControllerResetPollingAction = {
|
|
11
|
+
type: `GasFeeController:resetPolling`;
|
|
12
|
+
handler: GasFeeController['resetPolling'];
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Fetches gas fee estimates.
|
|
16
|
+
*
|
|
17
|
+
* @param options - The gas fee estimate options.
|
|
18
|
+
* @returns The gas fee estimates.
|
|
19
|
+
*/
|
|
20
|
+
export type GasFeeControllerFetchGasFeeEstimatesAction = {
|
|
21
|
+
type: `GasFeeController:fetchGasFeeEstimates`;
|
|
22
|
+
handler: GasFeeController['fetchGasFeeEstimates'];
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Gets gas fee estimates and starts polling for updates.
|
|
26
|
+
*
|
|
27
|
+
* @param pollToken - An existing poll token to reuse, or undefined to
|
|
28
|
+
* generate a new one.
|
|
29
|
+
* @returns The poll token that can be used to stop polling.
|
|
30
|
+
*/
|
|
31
|
+
export type GasFeeControllerGetGasFeeEstimatesAndStartPollingAction = {
|
|
32
|
+
type: `GasFeeController:getGasFeeEstimatesAndStartPolling`;
|
|
33
|
+
handler: GasFeeController['getGasFeeEstimatesAndStartPolling'];
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Remove the poll token, and stop polling if the set of poll tokens is empty.
|
|
37
|
+
*
|
|
38
|
+
* @param pollToken - The poll token to disconnect.
|
|
39
|
+
*/
|
|
40
|
+
export type GasFeeControllerDisconnectPollerAction = {
|
|
41
|
+
type: `GasFeeController:disconnectPoller`;
|
|
42
|
+
handler: GasFeeController['disconnectPoller'];
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Stops polling for gas fee estimates and clears all poll tokens.
|
|
46
|
+
*/
|
|
47
|
+
export type GasFeeControllerStopPollingAction = {
|
|
48
|
+
type: `GasFeeController:stopPolling`;
|
|
49
|
+
handler: GasFeeController['stopPolling'];
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Gets the estimated time for a transaction based on the given gas parameters.
|
|
53
|
+
*
|
|
54
|
+
* @param maxPriorityFeePerGas - The maximum priority fee per gas in GWEI.
|
|
55
|
+
* @param maxFeePerGas - The maximum fee per gas in GWEI.
|
|
56
|
+
* @returns The estimated time bounds, or an empty object if fee market
|
|
57
|
+
* estimates are not available.
|
|
58
|
+
*/
|
|
59
|
+
export type GasFeeControllerGetTimeEstimateAction = {
|
|
60
|
+
type: `GasFeeController:getTimeEstimate`;
|
|
61
|
+
handler: GasFeeController['getTimeEstimate'];
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Union of all GasFeeController action types.
|
|
65
|
+
*/
|
|
66
|
+
export type GasFeeControllerMethodActions = GasFeeControllerResetPollingAction | GasFeeControllerFetchGasFeeEstimatesAction | GasFeeControllerGetGasFeeEstimatesAndStartPollingAction | GasFeeControllerDisconnectPollerAction | GasFeeControllerStopPollingAction | GasFeeControllerGetTimeEstimateAction;
|
|
67
|
+
//# sourceMappingURL=GasFeeController-method-action-types.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GasFeeController-method-action-types.d.cts","sourceRoot":"","sources":["../src/GasFeeController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,+BAA2B;AAE3D;;;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;;GAEG;AACH,MAAM,MAAM,6BAA6B,GACrC,kCAAkC,GAClC,0CAA0C,GAC1C,uDAAuD,GACvD,sCAAsC,GACtC,iCAAiC,GACjC,qCAAqC,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is auto generated by `scripts/generate-method-action-types.ts`.
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
*/
|
|
5
|
+
import type { GasFeeController } from "./GasFeeController.mjs";
|
|
6
|
+
/**
|
|
7
|
+
* Resets the polling interval by stopping and restarting polling
|
|
8
|
+
* with the existing poll tokens.
|
|
9
|
+
*/
|
|
10
|
+
export type GasFeeControllerResetPollingAction = {
|
|
11
|
+
type: `GasFeeController:resetPolling`;
|
|
12
|
+
handler: GasFeeController['resetPolling'];
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Fetches gas fee estimates.
|
|
16
|
+
*
|
|
17
|
+
* @param options - The gas fee estimate options.
|
|
18
|
+
* @returns The gas fee estimates.
|
|
19
|
+
*/
|
|
20
|
+
export type GasFeeControllerFetchGasFeeEstimatesAction = {
|
|
21
|
+
type: `GasFeeController:fetchGasFeeEstimates`;
|
|
22
|
+
handler: GasFeeController['fetchGasFeeEstimates'];
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Gets gas fee estimates and starts polling for updates.
|
|
26
|
+
*
|
|
27
|
+
* @param pollToken - An existing poll token to reuse, or undefined to
|
|
28
|
+
* generate a new one.
|
|
29
|
+
* @returns The poll token that can be used to stop polling.
|
|
30
|
+
*/
|
|
31
|
+
export type GasFeeControllerGetGasFeeEstimatesAndStartPollingAction = {
|
|
32
|
+
type: `GasFeeController:getGasFeeEstimatesAndStartPolling`;
|
|
33
|
+
handler: GasFeeController['getGasFeeEstimatesAndStartPolling'];
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Remove the poll token, and stop polling if the set of poll tokens is empty.
|
|
37
|
+
*
|
|
38
|
+
* @param pollToken - The poll token to disconnect.
|
|
39
|
+
*/
|
|
40
|
+
export type GasFeeControllerDisconnectPollerAction = {
|
|
41
|
+
type: `GasFeeController:disconnectPoller`;
|
|
42
|
+
handler: GasFeeController['disconnectPoller'];
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Stops polling for gas fee estimates and clears all poll tokens.
|
|
46
|
+
*/
|
|
47
|
+
export type GasFeeControllerStopPollingAction = {
|
|
48
|
+
type: `GasFeeController:stopPolling`;
|
|
49
|
+
handler: GasFeeController['stopPolling'];
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Gets the estimated time for a transaction based on the given gas parameters.
|
|
53
|
+
*
|
|
54
|
+
* @param maxPriorityFeePerGas - The maximum priority fee per gas in GWEI.
|
|
55
|
+
* @param maxFeePerGas - The maximum fee per gas in GWEI.
|
|
56
|
+
* @returns The estimated time bounds, or an empty object if fee market
|
|
57
|
+
* estimates are not available.
|
|
58
|
+
*/
|
|
59
|
+
export type GasFeeControllerGetTimeEstimateAction = {
|
|
60
|
+
type: `GasFeeController:getTimeEstimate`;
|
|
61
|
+
handler: GasFeeController['getTimeEstimate'];
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Union of all GasFeeController action types.
|
|
65
|
+
*/
|
|
66
|
+
export type GasFeeControllerMethodActions = GasFeeControllerResetPollingAction | GasFeeControllerFetchGasFeeEstimatesAction | GasFeeControllerGetGasFeeEstimatesAndStartPollingAction | GasFeeControllerDisconnectPollerAction | GasFeeControllerStopPollingAction | GasFeeControllerGetTimeEstimateAction;
|
|
67
|
+
//# sourceMappingURL=GasFeeController-method-action-types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GasFeeController-method-action-types.d.mts","sourceRoot":"","sources":["../src/GasFeeController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,+BAA2B;AAE3D;;;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;;GAEG;AACH,MAAM,MAAM,6BAA6B,GACrC,kCAAkC,GAClC,0CAA0C,GAC1C,uDAAuD,GACvD,sCAAsC,GACtC,iCAAiC,GACjC,qCAAqC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GasFeeController-method-action-types.mjs","sourceRoot":"","sources":["../src/GasFeeController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { GasFeeController } from './GasFeeController';\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\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"]}
|
|
@@ -68,6 +68,14 @@ const metadata = {
|
|
|
68
68
|
},
|
|
69
69
|
};
|
|
70
70
|
const name = 'GasFeeController';
|
|
71
|
+
const MESSENGER_EXPOSED_METHODS = [
|
|
72
|
+
'disconnectPoller',
|
|
73
|
+
'fetchGasFeeEstimates',
|
|
74
|
+
'getGasFeeEstimatesAndStartPolling',
|
|
75
|
+
'getTimeEstimate',
|
|
76
|
+
'resetPolling',
|
|
77
|
+
'stopPolling',
|
|
78
|
+
];
|
|
71
79
|
const defaultState = {
|
|
72
80
|
gasFeeEstimatesByChainId: {},
|
|
73
81
|
gasFeeEstimates: {},
|
|
@@ -125,6 +133,7 @@ class GasFeeController extends (0, polling_controller_1.StaticIntervalPollingCon
|
|
|
125
133
|
this.legacyAPIEndpoint = legacyAPIEndpoint;
|
|
126
134
|
this.clientId = clientId;
|
|
127
135
|
this.ethQuery = new eth_query_1.default(__classPrivateFieldGet(this, _GasFeeController_getProvider, "f").call(this));
|
|
136
|
+
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
128
137
|
if (onNetworkDidChange && getChainId) {
|
|
129
138
|
this.currentChainId = getChainId();
|
|
130
139
|
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
@@ -144,6 +153,10 @@ class GasFeeController extends (0, polling_controller_1.StaticIntervalPollingCon
|
|
|
144
153
|
});
|
|
145
154
|
}
|
|
146
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* Resets the polling interval by stopping and restarting polling
|
|
158
|
+
* with the existing poll tokens.
|
|
159
|
+
*/
|
|
147
160
|
async resetPolling() {
|
|
148
161
|
if (this.pollTokens.size !== 0) {
|
|
149
162
|
const tokens = Array.from(this.pollTokens);
|
|
@@ -154,9 +167,22 @@ class GasFeeController extends (0, polling_controller_1.StaticIntervalPollingCon
|
|
|
154
167
|
});
|
|
155
168
|
}
|
|
156
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* Fetches gas fee estimates.
|
|
172
|
+
*
|
|
173
|
+
* @param options - The gas fee estimate options.
|
|
174
|
+
* @returns The gas fee estimates.
|
|
175
|
+
*/
|
|
157
176
|
async fetchGasFeeEstimates(options) {
|
|
158
177
|
return await this._fetchGasFeeEstimateData(options);
|
|
159
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* Gets gas fee estimates and starts polling for updates.
|
|
181
|
+
*
|
|
182
|
+
* @param pollToken - An existing poll token to reuse, or undefined to
|
|
183
|
+
* generate a new one.
|
|
184
|
+
* @returns The poll token that can be used to stop polling.
|
|
185
|
+
*/
|
|
160
186
|
async getGasFeeEstimatesAndStartPolling(pollToken) {
|
|
161
187
|
const _pollToken = pollToken || (0, uuid_1.v1)();
|
|
162
188
|
this.pollTokens.add(_pollToken);
|
|
@@ -243,6 +269,9 @@ class GasFeeController extends (0, polling_controller_1.StaticIntervalPollingCon
|
|
|
243
269
|
this.stopPolling();
|
|
244
270
|
}
|
|
245
271
|
}
|
|
272
|
+
/**
|
|
273
|
+
* Stops polling for gas fee estimates and clears all poll tokens.
|
|
274
|
+
*/
|
|
246
275
|
stopPolling() {
|
|
247
276
|
if (this.intervalId) {
|
|
248
277
|
clearInterval(this.intervalId);
|
|
@@ -289,6 +318,14 @@ class GasFeeController extends (0, polling_controller_1.StaticIntervalPollingCon
|
|
|
289
318
|
const currentAccountIsEIP1559Compatible = this.getCurrentAccountEIP1559Compatibility?.() ?? true;
|
|
290
319
|
return (currentNetworkIsEIP1559Compatible && currentAccountIsEIP1559Compatible);
|
|
291
320
|
}
|
|
321
|
+
/**
|
|
322
|
+
* Gets the estimated time for a transaction based on the given gas parameters.
|
|
323
|
+
*
|
|
324
|
+
* @param maxPriorityFeePerGas - The maximum priority fee per gas in GWEI.
|
|
325
|
+
* @param maxFeePerGas - The maximum fee per gas in GWEI.
|
|
326
|
+
* @returns The estimated time bounds, or an empty object if fee market
|
|
327
|
+
* estimates are not available.
|
|
328
|
+
*/
|
|
292
329
|
getTimeEstimate(maxPriorityFeePerGas, maxFeePerGas) {
|
|
293
330
|
if (!this.state.gasFeeEstimates ||
|
|
294
331
|
this.state.gasEstimateType !== exports.GAS_ESTIMATE_TYPES.FEE_MARKET) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GasFeeController.cjs","sourceRoot":"","sources":["../src/GasFeeController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAKA,iEAIoC;AACpC,oEAA2C;AAW3C,qEAA+E;AAE/E,+BAAoC;AAEpC,oGAAwE;AACxE,6CAKoB;AAEP,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;AAqGF,MAAM,QAAQ,GAA+B;IAC3C,wBAAwB,EAAE;QACxB,kBAAkB,EAA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AC;QAEzD,OAAO,CACL,iCAAiC,IAAI,iCAAiC,CACvE,CAAC;IACJ,CAAC;IAED,eAAe,CACb,oBAA4B,EAC5B,YAAoB;QAEpB,IACE,CAAC,IAAI,CAAC,KAAK,CAAC,eAAe;YAC3B,IAAI,CAAC,KAAK,CAAC,eAAe,KAAK,0BAAkB,CAAC,UAAU,EAC5D,CAAC;YACD,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,OAAO,IAAA,gCAAqB,EAC1B,oBAAoB,EACpB,YAAY,EACZ,IAAI,CAAC,KAAK,CAAC,eAAe,CAC3B,CAAC;IACJ,CAAC;IAkBD,sBAAsB;QACpB,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,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;AA9WD,4CA8WC;6IA3BC,KAAK,yDAA+B,EAClC,uBAAuB,GACV;IACb,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CACpC,wCAAwC,EACxC,uBAAuB,CACxB,CAAC,aAAa,CAAC,OAAO,CAAC;IAExB,IAAI,UAAU,KAAK,IAAI,CAAC,cAAc,EAAE,CAAC;QACvC,IAAI,CAAC,QAAQ,GAAG,IAAI,mBAAQ,CAAC,uBAAA,IAAI,qCAAa,MAAjB,IAAI,CAAe,CAAC,CAAC;QAClD,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;QAE1B,IAAI,CAAC,cAAc,GAAG,UAAU,CAAC;IACnC,CAAC;AACH,CAAC;AAeH,kBAAe,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';\nimport {\n fetchGasEstimates,\n fetchLegacyGasPriceEstimates,\n fetchEthGasPriceEstimate,\n calculateTimeEstimate,\n} from './gas-util';\n\nexport const LEGACY_GAS_PRICES_API_URL = `https://api.metaswap.codefi.network/gasPrices`;\n\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\nexport type GasFeeStateChange = ControllerStateChangeEvent<\n typeof name,\n GasFeeState\n>;\n\nexport type GetGasFeeState = ControllerGetStateAction<typeof name, GasFeeState>;\n\nexport type GasFeeControllerActions = GetGasFeeState;\n\nexport type GasFeeControllerEvents = GasFeeStateChange;\n\ntype AllowedActions =\n | NetworkControllerGetStateAction\n | NetworkControllerGetNetworkClientByIdAction\n | NetworkControllerGetEIP1559CompatibilityAction;\n\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;\n\n private ethQuery?: EthQuery;\n\n private readonly clientId?: string;\n\n readonly #getProvider: () => ProviderProxy;\n\n /**\n * Creates a GasFeeController instance.\n *\n * @param options - The controller options.\n * @param options.interval - The time in milliseconds to wait between polls.\n * @param options.messenger - The controller messenger.\n * @param options.state - The initial state.\n * @param options.getCurrentNetworkEIP1559Compatibility - Determines whether or not the current\n * network is EIP-1559 compatible.\n * @param options.getCurrentNetworkLegacyGasAPICompatibility - Determines whether or not the\n * current network is compatible with the legacy gas price API.\n * @param options.getCurrentAccountEIP1559Compatibility - Determines whether or not the current\n * account is EIP-1559 compatible.\n * @param options.getChainId - Returns the current chain ID.\n * @param options.getProvider - Returns a network provider for the current network.\n * @param options.onNetworkDidChange - A function for registering an event handler for the\n * network state change event.\n * @param options.legacyAPIEndpoint - The legacy gas price API URL. This option is primarily for\n * testing purposes.\n * @param options.EIP1559APIEndpoint - The EIP-1559 gas price API URL.\n * @param options.clientId - The client ID used to identify to the gas estimation API who is\n * asking for estimates.\n */\n constructor({\n interval = 15000,\n messenger,\n state,\n getCurrentNetworkEIP1559Compatibility,\n getCurrentAccountEIP1559Compatibility,\n getChainId,\n getCurrentNetworkLegacyGasAPICompatibility,\n getProvider,\n onNetworkDidChange,\n legacyAPIEndpoint = LEGACY_GAS_PRICES_API_URL,\n EIP1559APIEndpoint,\n clientId,\n }: {\n interval?: number;\n messenger: GasFeeMessenger;\n state?: GasFeeState;\n getCurrentNetworkEIP1559Compatibility: () => Promise<boolean>;\n getCurrentNetworkLegacyGasAPICompatibility: () => boolean;\n getCurrentAccountEIP1559Compatibility?: () => boolean;\n getChainId?: () => Hex;\n getProvider: () => ProviderProxy;\n onNetworkDidChange?: (listener: (state: NetworkState) => void) => void;\n legacyAPIEndpoint?: string;\n EIP1559APIEndpoint: string;\n clientId?: string;\n }) {\n super({\n name,\n metadata,\n messenger,\n state: { ...defaultState, ...state },\n });\n this.intervalDelay = interval;\n this.setIntervalLength(interval);\n this.pollTokens = new Set();\n this.getCurrentNetworkEIP1559Compatibility =\n getCurrentNetworkEIP1559Compatibility;\n this.getCurrentNetworkLegacyGasAPICompatibility =\n getCurrentNetworkLegacyGasAPICompatibility;\n this.getCurrentAccountEIP1559Compatibility =\n getCurrentAccountEIP1559Compatibility;\n this.#getProvider = getProvider;\n this.EIP1559APIEndpoint = EIP1559APIEndpoint;\n this.legacyAPIEndpoint = legacyAPIEndpoint;\n this.clientId = clientId;\n\n this.ethQuery = new EthQuery(this.#getProvider());\n\n if (onNetworkDidChange && getChainId) {\n this.currentChainId = getChainId();\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n onNetworkDidChange(async (networkControllerState) => {\n await this.#onNetworkControllerDidChange(networkControllerState);\n });\n } else {\n const { selectedNetworkClientId } = this.messenger.call(\n 'NetworkController:getState',\n );\n this.currentChainId = this.messenger.call(\n 'NetworkController:getNetworkClientById',\n selectedNetworkClientId,\n ).configuration.chainId;\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 async resetPolling() {\n if (this.pollTokens.size !== 0) {\n const tokens = Array.from(this.pollTokens);\n this.stopPolling();\n await this.getGasFeeEstimatesAndStartPolling(tokens[0]);\n tokens.slice(1).forEach((token) => {\n this.pollTokens.add(token);\n });\n }\n }\n\n async fetchGasFeeEstimates(options?: FetchGasFeeEstimateOptions) {\n return await this._fetchGasFeeEstimateData(options);\n }\n\n async getGasFeeEstimatesAndStartPolling(\n pollToken: string | undefined,\n ): Promise<string> {\n const _pollToken = pollToken || random();\n\n this.pollTokens.add(_pollToken);\n\n if (this.pollTokens.size === 1) {\n await this._fetchGasFeeEstimateData();\n this._poll();\n }\n\n return _pollToken;\n }\n\n /**\n * Gets and sets gasFeeEstimates in state.\n *\n * @param options - The gas fee estimate options.\n * @param options.shouldUpdateState - Determines whether the state should be updated with the\n * updated gas estimates.\n * @returns The gas fee estimates.\n */\n async _fetchGasFeeEstimateData(\n options: FetchGasFeeEstimateOptions = {},\n ): Promise<GasFeeState> {\n const { shouldUpdateState = true, networkClientId } = options;\n\n let ethQuery,\n isEIP1559Compatible,\n isLegacyGasAPICompatible,\n decimalChainId: number;\n\n if (networkClientId !== undefined) {\n const networkClient = this.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.ethQuery;\n\n isLegacyGasAPICompatible ??=\n this.getCurrentNetworkLegacyGasAPICompatibility();\n\n decimalChainId ??= convertHexToDecimal(this.currentChainId);\n\n try {\n isEIP1559Compatible ??= await this.getEIP1559Compatibility();\n } catch (e) {\n console.error(e);\n isEIP1559Compatible ??= false;\n }\n\n const gasFeeCalculations = await determineGasFeeCalculations({\n isEIP1559Compatible,\n isLegacyGasAPICompatible,\n fetchGasEstimates,\n fetchGasEstimatesUrl: this.EIP1559APIEndpoint.replace(\n '<chain_id>',\n `${decimalChainId}`,\n ),\n fetchLegacyGasPriceEstimates,\n fetchLegacyGasPriceEstimatesUrl: this.legacyAPIEndpoint.replace(\n '<chain_id>',\n `${decimalChainId}`,\n ),\n fetchEthGasPriceEstimate,\n calculateTimeEstimate,\n clientId: this.clientId,\n ethQuery,\n nonRPCGasFeeApisDisabled: this.state.nonRPCGasFeeApisDisabled,\n });\n\n if (shouldUpdateState) {\n const chainId = toHex(decimalChainId);\n this.update((state) => {\n if (this.currentChainId === chainId) {\n state.gasFeeEstimates = gasFeeCalculations.gasFeeEstimates;\n state.estimatedGasFeeTimeBounds =\n gasFeeCalculations.estimatedGasFeeTimeBounds;\n state.gasEstimateType = gasFeeCalculations.gasEstimateType;\n }\n state.gasFeeEstimatesByChainId ??= {};\n state.gasFeeEstimatesByChainId[chainId] = {\n gasFeeEstimates: gasFeeCalculations.gasFeeEstimates,\n estimatedGasFeeTimeBounds:\n gasFeeCalculations.estimatedGasFeeTimeBounds,\n gasEstimateType: gasFeeCalculations.gasEstimateType,\n } as SingleChainGasFeeState;\n });\n }\n\n return gasFeeCalculations;\n }\n\n /**\n * Remove the poll token, and stop polling if the set of poll tokens is empty.\n *\n * @param pollToken - The poll token to disconnect.\n */\n disconnectPoller(pollToken: string) {\n this.pollTokens.delete(pollToken);\n if (this.pollTokens.size === 0) {\n this.stopPolling();\n }\n }\n\n stopPolling() {\n if (this.intervalId) {\n clearInterval(this.intervalId);\n }\n this.pollTokens.clear();\n this.resetState();\n }\n\n /**\n * Prepare to discard this controller.\n *\n * This stops any active polling.\n */\n override destroy() {\n super.destroy();\n this.stopPolling();\n }\n\n private _poll() {\n if (this.intervalId) {\n clearInterval(this.intervalId);\n }\n\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.intervalId = setInterval(async () => {\n await safelyExecute(() => this._fetchGasFeeEstimateData());\n }, this.intervalDelay);\n }\n\n /**\n * Fetching token list from the Token Service API.\n *\n * @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 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.messenger.call(\n 'NetworkController:getNetworkClientById',\n selectedNetworkClientId,\n ).configuration.chainId;\n\n if (newChainId !== this.currentChainId) {\n this.ethQuery = new EthQuery(this.#getProvider());\n await this.resetPolling();\n\n this.currentChainId = newChainId;\n }\n }\n\n enableNonRPCGasFeeApis() {\n this.update((state) => {\n state.nonRPCGasFeeApisDisabled = false;\n });\n }\n\n disableNonRPCGasFeeApis() {\n this.update((state) => {\n state.nonRPCGasFeeApisDisabled = true;\n });\n }\n}\n\nexport default GasFeeController;\n"]}
|
|
1
|
+
{"version":3,"file":"GasFeeController.cjs","sourceRoot":"","sources":["../src/GasFeeController.ts"],"names":[],"mappings":";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AK,EAAE,EAAE;YACpB,KAAK,CAAC,wBAAwB,GAAG,IAAI,CAAC;QACxC,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA/YD,4CA+YC;6IA3BC,KAAK,yDAA+B,EAClC,uBAAuB,GACV;IACb,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CACpC,wCAAwC,EACxC,uBAAuB,CACxB,CAAC,aAAa,CAAC,OAAO,CAAC;IAExB,IAAI,UAAU,KAAK,IAAI,CAAC,cAAc,EAAE,CAAC;QACvC,IAAI,CAAC,QAAQ,GAAG,IAAI,mBAAQ,CAAC,uBAAA,IAAI,qCAAa,MAAjB,IAAI,CAAe,CAAC,CAAC;QAClD,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;QAE1B,IAAI,CAAC,cAAc,GAAG,UAAU,CAAC;IACnC,CAAC;AACH,CAAC;AAeH,kBAAe,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';\nimport {\n fetchGasEstimates,\n fetchLegacyGasPriceEstimates,\n fetchEthGasPriceEstimate,\n calculateTimeEstimate,\n} from './gas-util';\nimport type { GasFeeControllerMethodActions } from './GasFeeController-method-action-types';\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 'disconnectPoller',\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;\n\n private ethQuery?: EthQuery;\n\n private readonly clientId?: string;\n\n readonly #getProvider: () => ProviderProxy;\n\n /**\n * Creates a GasFeeController instance.\n *\n * @param options - The controller options.\n * @param options.interval - The time in milliseconds to wait between polls.\n * @param options.messenger - The controller messenger.\n * @param options.state - The initial state.\n * @param options.getCurrentNetworkEIP1559Compatibility - Determines whether or not the current\n * network is EIP-1559 compatible.\n * @param options.getCurrentNetworkLegacyGasAPICompatibility - Determines whether or not the\n * current network is compatible with the legacy gas price API.\n * @param options.getCurrentAccountEIP1559Compatibility - Determines whether or not the current\n * account is EIP-1559 compatible.\n * @param options.getChainId - Returns the current chain ID.\n * @param options.getProvider - Returns a network provider for the current network.\n * @param options.onNetworkDidChange - A function for registering an event handler for the\n * network state change event.\n * @param options.legacyAPIEndpoint - The legacy gas price API URL. This option is primarily for\n * testing purposes.\n * @param options.EIP1559APIEndpoint - The EIP-1559 gas price API URL.\n * @param options.clientId - The client ID used to identify to the gas estimation API who is\n * asking for estimates.\n */\n constructor({\n interval = 15000,\n messenger,\n state,\n getCurrentNetworkEIP1559Compatibility,\n getCurrentAccountEIP1559Compatibility,\n getChainId,\n getCurrentNetworkLegacyGasAPICompatibility,\n getProvider,\n onNetworkDidChange,\n legacyAPIEndpoint = LEGACY_GAS_PRICES_API_URL,\n EIP1559APIEndpoint,\n clientId,\n }: {\n interval?: number;\n messenger: GasFeeMessenger;\n state?: GasFeeState;\n getCurrentNetworkEIP1559Compatibility: () => Promise<boolean>;\n getCurrentNetworkLegacyGasAPICompatibility: () => boolean;\n getCurrentAccountEIP1559Compatibility?: () => boolean;\n getChainId?: () => Hex;\n getProvider: () => ProviderProxy;\n onNetworkDidChange?: (listener: (state: NetworkState) => void) => void;\n legacyAPIEndpoint?: string;\n EIP1559APIEndpoint: string;\n clientId?: string;\n }) {\n super({\n name,\n metadata,\n messenger,\n state: { ...defaultState, ...state },\n });\n this.intervalDelay = interval;\n this.setIntervalLength(interval);\n this.pollTokens = new Set();\n this.getCurrentNetworkEIP1559Compatibility =\n getCurrentNetworkEIP1559Compatibility;\n this.getCurrentNetworkLegacyGasAPICompatibility =\n getCurrentNetworkLegacyGasAPICompatibility;\n this.getCurrentAccountEIP1559Compatibility =\n getCurrentAccountEIP1559Compatibility;\n this.#getProvider = getProvider;\n this.EIP1559APIEndpoint = EIP1559APIEndpoint;\n this.legacyAPIEndpoint = legacyAPIEndpoint;\n this.clientId = clientId;\n\n this.ethQuery = new EthQuery(this.#getProvider());\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n\n if (onNetworkDidChange && getChainId) {\n this.currentChainId = getChainId();\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n onNetworkDidChange(async (networkControllerState) => {\n await this.#onNetworkControllerDidChange(networkControllerState);\n });\n } else {\n const { selectedNetworkClientId } = this.messenger.call(\n 'NetworkController:getState',\n );\n this.currentChainId = this.messenger.call(\n 'NetworkController:getNetworkClientById',\n selectedNetworkClientId,\n ).configuration.chainId;\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.ethQuery;\n\n isLegacyGasAPICompatible ??=\n this.getCurrentNetworkLegacyGasAPICompatibility();\n\n decimalChainId ??= convertHexToDecimal(this.currentChainId);\n\n try {\n isEIP1559Compatible ??= await this.getEIP1559Compatibility();\n } catch (e) {\n console.error(e);\n isEIP1559Compatible ??= false;\n }\n\n const gasFeeCalculations = await determineGasFeeCalculations({\n isEIP1559Compatible,\n isLegacyGasAPICompatible,\n fetchGasEstimates,\n fetchGasEstimatesUrl: this.EIP1559APIEndpoint.replace(\n '<chain_id>',\n `${decimalChainId}`,\n ),\n fetchLegacyGasPriceEstimates,\n fetchLegacyGasPriceEstimatesUrl: this.legacyAPIEndpoint.replace(\n '<chain_id>',\n `${decimalChainId}`,\n ),\n fetchEthGasPriceEstimate,\n calculateTimeEstimate,\n clientId: this.clientId,\n ethQuery,\n nonRPCGasFeeApisDisabled: this.state.nonRPCGasFeeApisDisabled,\n });\n\n if (shouldUpdateState) {\n const chainId = toHex(decimalChainId);\n this.update((state) => {\n if (this.currentChainId === chainId) {\n state.gasFeeEstimates = gasFeeCalculations.gasFeeEstimates;\n state.estimatedGasFeeTimeBounds =\n gasFeeCalculations.estimatedGasFeeTimeBounds;\n state.gasEstimateType = gasFeeCalculations.gasEstimateType;\n }\n state.gasFeeEstimatesByChainId ??= {};\n state.gasFeeEstimatesByChainId[chainId] = {\n gasFeeEstimates: gasFeeCalculations.gasFeeEstimates,\n estimatedGasFeeTimeBounds:\n gasFeeCalculations.estimatedGasFeeTimeBounds,\n gasEstimateType: gasFeeCalculations.gasEstimateType,\n } as SingleChainGasFeeState;\n });\n }\n\n return gasFeeCalculations;\n }\n\n /**\n * Remove the poll token, and stop polling if the set of poll tokens is empty.\n *\n * @param pollToken - The poll token to disconnect.\n */\n disconnectPoller(pollToken: string) {\n this.pollTokens.delete(pollToken);\n if (this.pollTokens.size === 0) {\n this.stopPolling();\n }\n }\n\n /**\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.messenger.call(\n 'NetworkController:getNetworkClientById',\n selectedNetworkClientId,\n ).configuration.chainId;\n\n if (newChainId !== this.currentChainId) {\n this.ethQuery = new EthQuery(this.#getProvider());\n await this.resetPolling();\n\n this.currentChainId = newChainId;\n }\n }\n\n enableNonRPCGasFeeApis() {\n this.update((state) => {\n state.nonRPCGasFeeApisDisabled = false;\n });\n }\n\n disableNonRPCGasFeeApis() {\n this.update((state) => {\n state.nonRPCGasFeeApisDisabled = true;\n });\n }\n}\n\nexport default GasFeeController;\n"]}
|
|
@@ -2,6 +2,7 @@ import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@meta
|
|
|
2
2
|
import type { Messenger } from "@metamask/messenger";
|
|
3
3
|
import type { NetworkClientId, NetworkControllerGetEIP1559CompatibilityAction, NetworkControllerGetNetworkClientByIdAction, NetworkControllerGetStateAction, NetworkControllerNetworkDidChangeEvent, NetworkState, ProviderProxy } from "@metamask/network-controller";
|
|
4
4
|
import type { Hex } from "@metamask/utils";
|
|
5
|
+
import type { GasFeeControllerMethodActions } from "./GasFeeController-method-action-types.cjs";
|
|
5
6
|
export declare const LEGACY_GAS_PRICES_API_URL = "https://api.metaswap.codefi.network/gasPrices";
|
|
6
7
|
export type unknownString = 'unknown';
|
|
7
8
|
export type FeeMarketEstimateType = 'fee-market';
|
|
@@ -148,7 +149,7 @@ export type GasFeeState = GasFeeEstimatesByChainId & SingleChainGasFeeState & {
|
|
|
148
149
|
declare const name = "GasFeeController";
|
|
149
150
|
export type GasFeeStateChange = ControllerStateChangeEvent<typeof name, GasFeeState>;
|
|
150
151
|
export type GetGasFeeState = ControllerGetStateAction<typeof name, GasFeeState>;
|
|
151
|
-
export type GasFeeControllerActions = GetGasFeeState;
|
|
152
|
+
export type GasFeeControllerActions = GetGasFeeState | GasFeeControllerMethodActions;
|
|
152
153
|
export type GasFeeControllerEvents = GasFeeStateChange;
|
|
153
154
|
type AllowedActions = NetworkControllerGetStateAction | NetworkControllerGetNetworkClientByIdAction | NetworkControllerGetEIP1559CompatibilityAction;
|
|
154
155
|
export type GasFeeMessenger = Messenger<typeof name, GasFeeControllerActions | AllowedActions, GasFeeControllerEvents | NetworkControllerNetworkDidChangeEvent>;
|
|
@@ -224,8 +225,25 @@ export declare class GasFeeController extends GasFeeController_base<typeof name,
|
|
|
224
225
|
EIP1559APIEndpoint: string;
|
|
225
226
|
clientId?: string;
|
|
226
227
|
});
|
|
228
|
+
/**
|
|
229
|
+
* Resets the polling interval by stopping and restarting polling
|
|
230
|
+
* with the existing poll tokens.
|
|
231
|
+
*/
|
|
227
232
|
resetPolling(): Promise<void>;
|
|
233
|
+
/**
|
|
234
|
+
* Fetches gas fee estimates.
|
|
235
|
+
*
|
|
236
|
+
* @param options - The gas fee estimate options.
|
|
237
|
+
* @returns The gas fee estimates.
|
|
238
|
+
*/
|
|
228
239
|
fetchGasFeeEstimates(options?: FetchGasFeeEstimateOptions): Promise<GasFeeState>;
|
|
240
|
+
/**
|
|
241
|
+
* Gets gas fee estimates and starts polling for updates.
|
|
242
|
+
*
|
|
243
|
+
* @param pollToken - An existing poll token to reuse, or undefined to
|
|
244
|
+
* generate a new one.
|
|
245
|
+
* @returns The poll token that can be used to stop polling.
|
|
246
|
+
*/
|
|
229
247
|
getGasFeeEstimatesAndStartPolling(pollToken: string | undefined): Promise<string>;
|
|
230
248
|
/**
|
|
231
249
|
* Gets and sets gasFeeEstimates in state.
|
|
@@ -242,6 +260,9 @@ export declare class GasFeeController extends GasFeeController_base<typeof name,
|
|
|
242
260
|
* @param pollToken - The poll token to disconnect.
|
|
243
261
|
*/
|
|
244
262
|
disconnectPoller(pollToken: string): void;
|
|
263
|
+
/**
|
|
264
|
+
* Stops polling for gas fee estimates and clears all poll tokens.
|
|
265
|
+
*/
|
|
245
266
|
stopPolling(): void;
|
|
246
267
|
/**
|
|
247
268
|
* Prepare to discard this controller.
|
|
@@ -260,6 +281,14 @@ export declare class GasFeeController extends GasFeeController_base<typeof name,
|
|
|
260
281
|
_executePoll({ networkClientId }: GasFeePollingInput): Promise<void>;
|
|
261
282
|
private resetState;
|
|
262
283
|
private getEIP1559Compatibility;
|
|
284
|
+
/**
|
|
285
|
+
* Gets the estimated time for a transaction based on the given gas parameters.
|
|
286
|
+
*
|
|
287
|
+
* @param maxPriorityFeePerGas - The maximum priority fee per gas in GWEI.
|
|
288
|
+
* @param maxFeePerGas - The maximum fee per gas in GWEI.
|
|
289
|
+
* @returns The estimated time bounds, or an empty object if fee market
|
|
290
|
+
* estimates are not available.
|
|
291
|
+
*/
|
|
263
292
|
getTimeEstimate(maxPriorityFeePerGas: string, maxFeePerGas: string): EstimatedGasFeeTimeBounds | Record<string, never>;
|
|
264
293
|
enableNonRPCGasFeeApis(): void;
|
|
265
294
|
disableNonRPCGasFeeApis(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GasFeeController.d.cts","sourceRoot":"","sources":["../src/GasFeeController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AAOnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EACV,eAAe,EACf,8CAA8C,EAC9C,2CAA2C,EAC3C,+BAA+B,EAC/B,sCAAsC,EACtC,YAAY,EACZ,aAAa,EACd,qCAAqC;AAEtC,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;
|
|
1
|
+
{"version":3,"file":"GasFeeController.d.cts","sourceRoot":"","sources":["../src/GasFeeController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AAOnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EACV,eAAe,EACf,8CAA8C,EAC9C,2CAA2C,EAC3C,+BAA+B,EAC/B,sCAAsC,EACtC,YAAY,EACZ,aAAa,EACd,qCAAqC;AAEtC,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAU3C,OAAO,KAAK,EAAE,6BAA6B,EAAE,mDAA+C;AAE5F,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,MAA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,OAAO,CAAC,MAAM,CAAC;IAalB;;;;;;;OAOG;IACG,wBAAwB,CAC5B,OAAO,GAAE,0BAA+B,GACvC,OAAO,CAAC,WAAW,CAAC;IAqFvB;;;;OAIG;IACH,gBAAgB,CAAC,SAAS,EAAE,MAAM;IAOlC;;OAEG;IACH,WAAW;IAQX;;;;OAIG;IACM,OAAO;IAKhB,OAAO,CAAC,KAAK;IAYb;;;;;;OAMG;IACG,YAAY,CAAC,EAAE,eAAe,EAAE,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1E,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;IA8BpD,sBAAsB;IAMtB,uBAAuB;CAKxB;AAED,eAAe,gBAAgB,CAAC"}
|
|
@@ -2,6 +2,7 @@ import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@meta
|
|
|
2
2
|
import type { Messenger } from "@metamask/messenger";
|
|
3
3
|
import type { NetworkClientId, NetworkControllerGetEIP1559CompatibilityAction, NetworkControllerGetNetworkClientByIdAction, NetworkControllerGetStateAction, NetworkControllerNetworkDidChangeEvent, NetworkState, ProviderProxy } from "@metamask/network-controller";
|
|
4
4
|
import type { Hex } from "@metamask/utils";
|
|
5
|
+
import type { GasFeeControllerMethodActions } from "./GasFeeController-method-action-types.mjs";
|
|
5
6
|
export declare const LEGACY_GAS_PRICES_API_URL = "https://api.metaswap.codefi.network/gasPrices";
|
|
6
7
|
export type unknownString = 'unknown';
|
|
7
8
|
export type FeeMarketEstimateType = 'fee-market';
|
|
@@ -148,7 +149,7 @@ export type GasFeeState = GasFeeEstimatesByChainId & SingleChainGasFeeState & {
|
|
|
148
149
|
declare const name = "GasFeeController";
|
|
149
150
|
export type GasFeeStateChange = ControllerStateChangeEvent<typeof name, GasFeeState>;
|
|
150
151
|
export type GetGasFeeState = ControllerGetStateAction<typeof name, GasFeeState>;
|
|
151
|
-
export type GasFeeControllerActions = GetGasFeeState;
|
|
152
|
+
export type GasFeeControllerActions = GetGasFeeState | GasFeeControllerMethodActions;
|
|
152
153
|
export type GasFeeControllerEvents = GasFeeStateChange;
|
|
153
154
|
type AllowedActions = NetworkControllerGetStateAction | NetworkControllerGetNetworkClientByIdAction | NetworkControllerGetEIP1559CompatibilityAction;
|
|
154
155
|
export type GasFeeMessenger = Messenger<typeof name, GasFeeControllerActions | AllowedActions, GasFeeControllerEvents | NetworkControllerNetworkDidChangeEvent>;
|
|
@@ -224,8 +225,25 @@ export declare class GasFeeController extends GasFeeController_base<typeof name,
|
|
|
224
225
|
EIP1559APIEndpoint: string;
|
|
225
226
|
clientId?: string;
|
|
226
227
|
});
|
|
228
|
+
/**
|
|
229
|
+
* Resets the polling interval by stopping and restarting polling
|
|
230
|
+
* with the existing poll tokens.
|
|
231
|
+
*/
|
|
227
232
|
resetPolling(): Promise<void>;
|
|
233
|
+
/**
|
|
234
|
+
* Fetches gas fee estimates.
|
|
235
|
+
*
|
|
236
|
+
* @param options - The gas fee estimate options.
|
|
237
|
+
* @returns The gas fee estimates.
|
|
238
|
+
*/
|
|
228
239
|
fetchGasFeeEstimates(options?: FetchGasFeeEstimateOptions): Promise<GasFeeState>;
|
|
240
|
+
/**
|
|
241
|
+
* Gets gas fee estimates and starts polling for updates.
|
|
242
|
+
*
|
|
243
|
+
* @param pollToken - An existing poll token to reuse, or undefined to
|
|
244
|
+
* generate a new one.
|
|
245
|
+
* @returns The poll token that can be used to stop polling.
|
|
246
|
+
*/
|
|
229
247
|
getGasFeeEstimatesAndStartPolling(pollToken: string | undefined): Promise<string>;
|
|
230
248
|
/**
|
|
231
249
|
* Gets and sets gasFeeEstimates in state.
|
|
@@ -242,6 +260,9 @@ export declare class GasFeeController extends GasFeeController_base<typeof name,
|
|
|
242
260
|
* @param pollToken - The poll token to disconnect.
|
|
243
261
|
*/
|
|
244
262
|
disconnectPoller(pollToken: string): void;
|
|
263
|
+
/**
|
|
264
|
+
* Stops polling for gas fee estimates and clears all poll tokens.
|
|
265
|
+
*/
|
|
245
266
|
stopPolling(): void;
|
|
246
267
|
/**
|
|
247
268
|
* Prepare to discard this controller.
|
|
@@ -260,6 +281,14 @@ export declare class GasFeeController extends GasFeeController_base<typeof name,
|
|
|
260
281
|
_executePoll({ networkClientId }: GasFeePollingInput): Promise<void>;
|
|
261
282
|
private resetState;
|
|
262
283
|
private getEIP1559Compatibility;
|
|
284
|
+
/**
|
|
285
|
+
* Gets the estimated time for a transaction based on the given gas parameters.
|
|
286
|
+
*
|
|
287
|
+
* @param maxPriorityFeePerGas - The maximum priority fee per gas in GWEI.
|
|
288
|
+
* @param maxFeePerGas - The maximum fee per gas in GWEI.
|
|
289
|
+
* @returns The estimated time bounds, or an empty object if fee market
|
|
290
|
+
* estimates are not available.
|
|
291
|
+
*/
|
|
263
292
|
getTimeEstimate(maxPriorityFeePerGas: string, maxFeePerGas: string): EstimatedGasFeeTimeBounds | Record<string, never>;
|
|
264
293
|
enableNonRPCGasFeeApis(): void;
|
|
265
294
|
disableNonRPCGasFeeApis(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GasFeeController.d.mts","sourceRoot":"","sources":["../src/GasFeeController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AAOnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EACV,eAAe,EACf,8CAA8C,EAC9C,2CAA2C,EAC3C,+BAA+B,EAC/B,sCAAsC,EACtC,YAAY,EACZ,aAAa,EACd,qCAAqC;AAEtC,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;
|
|
1
|
+
{"version":3,"file":"GasFeeController.d.mts","sourceRoot":"","sources":["../src/GasFeeController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK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
|
const name = 'GasFeeController';
|
|
72
|
+
const MESSENGER_EXPOSED_METHODS = [
|
|
73
|
+
'disconnectPoller',
|
|
74
|
+
'fetchGasFeeEstimates',
|
|
75
|
+
'getGasFeeEstimatesAndStartPolling',
|
|
76
|
+
'getTimeEstimate',
|
|
77
|
+
'resetPolling',
|
|
78
|
+
'stopPolling',
|
|
79
|
+
];
|
|
72
80
|
const defaultState = {
|
|
73
81
|
gasFeeEstimatesByChainId: {},
|
|
74
82
|
gasFeeEstimates: {},
|
|
@@ -126,6 +134,7 @@ export class GasFeeController extends StaticIntervalPollingController() {
|
|
|
126
134
|
this.legacyAPIEndpoint = legacyAPIEndpoint;
|
|
127
135
|
this.clientId = clientId;
|
|
128
136
|
this.ethQuery = new EthQuery(__classPrivateFieldGet(this, _GasFeeController_getProvider, "f").call(this));
|
|
137
|
+
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
129
138
|
if (onNetworkDidChange && getChainId) {
|
|
130
139
|
this.currentChainId = getChainId();
|
|
131
140
|
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
@@ -145,6 +154,10 @@ export class GasFeeController extends StaticIntervalPollingController() {
|
|
|
145
154
|
});
|
|
146
155
|
}
|
|
147
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Resets the polling interval by stopping and restarting polling
|
|
159
|
+
* with the existing poll tokens.
|
|
160
|
+
*/
|
|
148
161
|
async resetPolling() {
|
|
149
162
|
if (this.pollTokens.size !== 0) {
|
|
150
163
|
const tokens = Array.from(this.pollTokens);
|
|
@@ -155,9 +168,22 @@ export class GasFeeController extends StaticIntervalPollingController() {
|
|
|
155
168
|
});
|
|
156
169
|
}
|
|
157
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Fetches gas fee estimates.
|
|
173
|
+
*
|
|
174
|
+
* @param options - The gas fee estimate options.
|
|
175
|
+
* @returns The gas fee estimates.
|
|
176
|
+
*/
|
|
158
177
|
async fetchGasFeeEstimates(options) {
|
|
159
178
|
return await this._fetchGasFeeEstimateData(options);
|
|
160
179
|
}
|
|
180
|
+
/**
|
|
181
|
+
* Gets gas fee estimates and starts polling for updates.
|
|
182
|
+
*
|
|
183
|
+
* @param pollToken - An existing poll token to reuse, or undefined to
|
|
184
|
+
* generate a new one.
|
|
185
|
+
* @returns The poll token that can be used to stop polling.
|
|
186
|
+
*/
|
|
161
187
|
async getGasFeeEstimatesAndStartPolling(pollToken) {
|
|
162
188
|
const _pollToken = pollToken || random();
|
|
163
189
|
this.pollTokens.add(_pollToken);
|
|
@@ -244,6 +270,9 @@ export class GasFeeController extends StaticIntervalPollingController() {
|
|
|
244
270
|
this.stopPolling();
|
|
245
271
|
}
|
|
246
272
|
}
|
|
273
|
+
/**
|
|
274
|
+
* Stops polling for gas fee estimates and clears all poll tokens.
|
|
275
|
+
*/
|
|
247
276
|
stopPolling() {
|
|
248
277
|
if (this.intervalId) {
|
|
249
278
|
clearInterval(this.intervalId);
|
|
@@ -290,6 +319,14 @@ export class GasFeeController extends StaticIntervalPollingController() {
|
|
|
290
319
|
const currentAccountIsEIP1559Compatible = this.getCurrentAccountEIP1559Compatibility?.() ?? true;
|
|
291
320
|
return (currentNetworkIsEIP1559Compatible && currentAccountIsEIP1559Compatible);
|
|
292
321
|
}
|
|
322
|
+
/**
|
|
323
|
+
* Gets the estimated time for a transaction based on the given gas parameters.
|
|
324
|
+
*
|
|
325
|
+
* @param maxPriorityFeePerGas - The maximum priority fee per gas in GWEI.
|
|
326
|
+
* @param maxFeePerGas - The maximum fee per gas in GWEI.
|
|
327
|
+
* @returns The estimated time bounds, or an empty object if fee market
|
|
328
|
+
* estimates are not available.
|
|
329
|
+
*/
|
|
293
330
|
getTimeEstimate(maxPriorityFeePerGas, maxFeePerGas) {
|
|
294
331
|
if (!this.state.gasFeeEstimates ||
|
|
295
332
|
this.state.gasEstimateType !== GAS_ESTIMATE_TYPES.FEE_MARKET) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3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IACL,CAAC;CACF;6IA3BC,KAAK,yDAA+B,EAClC,uBAAuB,GACV;IACb,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CACpC,wCAAwC,EACxC,uBAAuB,CACxB,CAAC,aAAa,CAAC,OAAO,CAAC;IAExB,IAAI,UAAU,KAAK,IAAI,CAAC,cAAc,EAAE,CAAC;QACvC,IAAI,CAAC,QAAQ,GAAG,IAAI,QAAQ,CAAC,uBAAA,IAAI,qCAAa,MAAjB,IAAI,CAAe,CAAC,CAAC;QAClD,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;QAE1B,IAAI,CAAC,cAAc,GAAG,UAAU,CAAC;IACnC,CAAC;AACH,CAAC;AAeH,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';\nimport {\n fetchGasEstimates,\n fetchLegacyGasPriceEstimates,\n fetchEthGasPriceEstimate,\n calculateTimeEstimate,\n} from './gas-util';\n\nexport const LEGACY_GAS_PRICES_API_URL = `https://api.metaswap.codefi.network/gasPrices`;\n\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\nexport type GasFeeStateChange = ControllerStateChangeEvent<\n typeof name,\n GasFeeState\n>;\n\nexport type GetGasFeeState = ControllerGetStateAction<typeof name, GasFeeState>;\n\nexport type GasFeeControllerActions = GetGasFeeState;\n\nexport type GasFeeControllerEvents = GasFeeStateChange;\n\ntype AllowedActions =\n | NetworkControllerGetStateAction\n | NetworkControllerGetNetworkClientByIdAction\n | NetworkControllerGetEIP1559CompatibilityAction;\n\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;\n\n private ethQuery?: EthQuery;\n\n private readonly clientId?: string;\n\n readonly #getProvider: () => ProviderProxy;\n\n /**\n * Creates a GasFeeController instance.\n *\n * @param options - The controller options.\n * @param options.interval - The time in milliseconds to wait between polls.\n * @param options.messenger - The controller messenger.\n * @param options.state - The initial state.\n * @param options.getCurrentNetworkEIP1559Compatibility - Determines whether or not the current\n * network is EIP-1559 compatible.\n * @param options.getCurrentNetworkLegacyGasAPICompatibility - Determines whether or not the\n * current network is compatible with the legacy gas price API.\n * @param options.getCurrentAccountEIP1559Compatibility - Determines whether or not the current\n * account is EIP-1559 compatible.\n * @param options.getChainId - Returns the current chain ID.\n * @param options.getProvider - Returns a network provider for the current network.\n * @param options.onNetworkDidChange - A function for registering an event handler for the\n * network state change event.\n * @param options.legacyAPIEndpoint - The legacy gas price API URL. This option is primarily for\n * testing purposes.\n * @param options.EIP1559APIEndpoint - The EIP-1559 gas price API URL.\n * @param options.clientId - The client ID used to identify to the gas estimation API who is\n * asking for estimates.\n */\n constructor({\n interval = 15000,\n messenger,\n state,\n getCurrentNetworkEIP1559Compatibility,\n getCurrentAccountEIP1559Compatibility,\n getChainId,\n getCurrentNetworkLegacyGasAPICompatibility,\n getProvider,\n onNetworkDidChange,\n legacyAPIEndpoint = LEGACY_GAS_PRICES_API_URL,\n EIP1559APIEndpoint,\n clientId,\n }: {\n interval?: number;\n messenger: GasFeeMessenger;\n state?: GasFeeState;\n getCurrentNetworkEIP1559Compatibility: () => Promise<boolean>;\n getCurrentNetworkLegacyGasAPICompatibility: () => boolean;\n getCurrentAccountEIP1559Compatibility?: () => boolean;\n getChainId?: () => Hex;\n getProvider: () => ProviderProxy;\n onNetworkDidChange?: (listener: (state: NetworkState) => void) => void;\n legacyAPIEndpoint?: string;\n EIP1559APIEndpoint: string;\n clientId?: string;\n }) {\n super({\n name,\n metadata,\n messenger,\n state: { ...defaultState, ...state },\n });\n this.intervalDelay = interval;\n this.setIntervalLength(interval);\n this.pollTokens = new Set();\n this.getCurrentNetworkEIP1559Compatibility =\n getCurrentNetworkEIP1559Compatibility;\n this.getCurrentNetworkLegacyGasAPICompatibility =\n getCurrentNetworkLegacyGasAPICompatibility;\n this.getCurrentAccountEIP1559Compatibility =\n getCurrentAccountEIP1559Compatibility;\n this.#getProvider = getProvider;\n this.EIP1559APIEndpoint = EIP1559APIEndpoint;\n this.legacyAPIEndpoint = legacyAPIEndpoint;\n this.clientId = clientId;\n\n this.ethQuery = new EthQuery(this.#getProvider());\n\n if (onNetworkDidChange && getChainId) {\n this.currentChainId = getChainId();\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n onNetworkDidChange(async (networkControllerState) => {\n await this.#onNetworkControllerDidChange(networkControllerState);\n });\n } else {\n const { selectedNetworkClientId } = this.messenger.call(\n 'NetworkController:getState',\n );\n this.currentChainId = this.messenger.call(\n 'NetworkController:getNetworkClientById',\n selectedNetworkClientId,\n ).configuration.chainId;\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 async resetPolling() {\n if (this.pollTokens.size !== 0) {\n const tokens = Array.from(this.pollTokens);\n this.stopPolling();\n await this.getGasFeeEstimatesAndStartPolling(tokens[0]);\n tokens.slice(1).forEach((token) => {\n this.pollTokens.add(token);\n });\n }\n }\n\n async fetchGasFeeEstimates(options?: FetchGasFeeEstimateOptions) {\n return await this._fetchGasFeeEstimateData(options);\n }\n\n async getGasFeeEstimatesAndStartPolling(\n pollToken: string | undefined,\n ): Promise<string> {\n const _pollToken = pollToken || random();\n\n this.pollTokens.add(_pollToken);\n\n if (this.pollTokens.size === 1) {\n await this._fetchGasFeeEstimateData();\n this._poll();\n }\n\n return _pollToken;\n }\n\n /**\n * Gets and sets gasFeeEstimates in state.\n *\n * @param options - The gas fee estimate options.\n * @param options.shouldUpdateState - Determines whether the state should be updated with the\n * updated gas estimates.\n * @returns The gas fee estimates.\n */\n async _fetchGasFeeEstimateData(\n options: FetchGasFeeEstimateOptions = {},\n ): Promise<GasFeeState> {\n const { shouldUpdateState = true, networkClientId } = options;\n\n let ethQuery,\n isEIP1559Compatible,\n isLegacyGasAPICompatible,\n decimalChainId: number;\n\n if (networkClientId !== undefined) {\n const networkClient = this.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.ethQuery;\n\n isLegacyGasAPICompatible ??=\n this.getCurrentNetworkLegacyGasAPICompatibility();\n\n decimalChainId ??= convertHexToDecimal(this.currentChainId);\n\n try {\n isEIP1559Compatible ??= await this.getEIP1559Compatibility();\n } catch (e) {\n console.error(e);\n isEIP1559Compatible ??= false;\n }\n\n const gasFeeCalculations = await determineGasFeeCalculations({\n isEIP1559Compatible,\n isLegacyGasAPICompatible,\n fetchGasEstimates,\n fetchGasEstimatesUrl: this.EIP1559APIEndpoint.replace(\n '<chain_id>',\n `${decimalChainId}`,\n ),\n fetchLegacyGasPriceEstimates,\n fetchLegacyGasPriceEstimatesUrl: this.legacyAPIEndpoint.replace(\n '<chain_id>',\n `${decimalChainId}`,\n ),\n fetchEthGasPriceEstimate,\n calculateTimeEstimate,\n clientId: this.clientId,\n ethQuery,\n nonRPCGasFeeApisDisabled: this.state.nonRPCGasFeeApisDisabled,\n });\n\n if (shouldUpdateState) {\n const chainId = toHex(decimalChainId);\n this.update((state) => {\n if (this.currentChainId === chainId) {\n state.gasFeeEstimates = gasFeeCalculations.gasFeeEstimates;\n state.estimatedGasFeeTimeBounds =\n gasFeeCalculations.estimatedGasFeeTimeBounds;\n state.gasEstimateType = gasFeeCalculations.gasEstimateType;\n }\n state.gasFeeEstimatesByChainId ??= {};\n state.gasFeeEstimatesByChainId[chainId] = {\n gasFeeEstimates: gasFeeCalculations.gasFeeEstimates,\n estimatedGasFeeTimeBounds:\n gasFeeCalculations.estimatedGasFeeTimeBounds,\n gasEstimateType: gasFeeCalculations.gasEstimateType,\n } as SingleChainGasFeeState;\n });\n }\n\n return gasFeeCalculations;\n }\n\n /**\n * Remove the poll token, and stop polling if the set of poll tokens is empty.\n *\n * @param pollToken - The poll token to disconnect.\n */\n disconnectPoller(pollToken: string) {\n this.pollTokens.delete(pollToken);\n if (this.pollTokens.size === 0) {\n this.stopPolling();\n }\n }\n\n stopPolling() {\n if (this.intervalId) {\n clearInterval(this.intervalId);\n }\n this.pollTokens.clear();\n this.resetState();\n }\n\n /**\n * Prepare to discard this controller.\n *\n * This stops any active polling.\n */\n override destroy() {\n super.destroy();\n this.stopPolling();\n }\n\n private _poll() {\n if (this.intervalId) {\n clearInterval(this.intervalId);\n }\n\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.intervalId = setInterval(async () => {\n await safelyExecute(() => this._fetchGasFeeEstimateData());\n }, this.intervalDelay);\n }\n\n /**\n * Fetching token list from the Token Service API.\n *\n * @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 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.messenger.call(\n 'NetworkController:getNetworkClientById',\n selectedNetworkClientId,\n ).configuration.chainId;\n\n if (newChainId !== this.currentChainId) {\n this.ethQuery = new EthQuery(this.#getProvider());\n await this.resetPolling();\n\n this.currentChainId = newChainId;\n }\n }\n\n enableNonRPCGasFeeApis() {\n this.update((state) => {\n state.nonRPCGasFeeApisDisabled = false;\n });\n }\n\n disableNonRPCGasFeeApis() {\n this.update((state) => {\n state.nonRPCGasFeeApisDisabled = true;\n });\n }\n}\n\nexport default GasFeeController;\n"]}
|
|
1
|
+
{"version":3,"file":"GasFeeController.mjs","sourceRoot":"","sources":["../src/GasFeeController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAKA,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,KAAK,EACN,mCAAmC;AACpC,OAAO,SAAQ,4BAA4B;;AAW3C,OAAO,EAAE,+BAA+B,EAAE,qCAAqC;AAE/E,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,aAAa;AAEpC,OAAO,2BAA2B,0CAAsC;AACxE,OAAO,EACL,iBAAiB,EACjB,4BAA4B,EAC5B,wBAAwB,EACxB,qBAAqB,EACtB,uBAAmB;AAGpB,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,EAA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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';\nimport {\n fetchGasEstimates,\n fetchLegacyGasPriceEstimates,\n fetchEthGasPriceEstimate,\n calculateTimeEstimate,\n} from './gas-util';\nimport type { GasFeeControllerMethodActions } from './GasFeeController-method-action-types';\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 'disconnectPoller',\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;\n\n private ethQuery?: EthQuery;\n\n private readonly clientId?: string;\n\n readonly #getProvider: () => ProviderProxy;\n\n /**\n * Creates a GasFeeController instance.\n *\n * @param options - The controller options.\n * @param options.interval - The time in milliseconds to wait between polls.\n * @param options.messenger - The controller messenger.\n * @param options.state - The initial state.\n * @param options.getCurrentNetworkEIP1559Compatibility - Determines whether or not the current\n * network is EIP-1559 compatible.\n * @param options.getCurrentNetworkLegacyGasAPICompatibility - Determines whether or not the\n * current network is compatible with the legacy gas price API.\n * @param options.getCurrentAccountEIP1559Compatibility - Determines whether or not the current\n * account is EIP-1559 compatible.\n * @param options.getChainId - Returns the current chain ID.\n * @param options.getProvider - Returns a network provider for the current network.\n * @param options.onNetworkDidChange - A function for registering an event handler for the\n * network state change event.\n * @param options.legacyAPIEndpoint - The legacy gas price API URL. This option is primarily for\n * testing purposes.\n * @param options.EIP1559APIEndpoint - The EIP-1559 gas price API URL.\n * @param options.clientId - The client ID used to identify to the gas estimation API who is\n * asking for estimates.\n */\n constructor({\n interval = 15000,\n messenger,\n state,\n getCurrentNetworkEIP1559Compatibility,\n getCurrentAccountEIP1559Compatibility,\n getChainId,\n getCurrentNetworkLegacyGasAPICompatibility,\n getProvider,\n onNetworkDidChange,\n legacyAPIEndpoint = LEGACY_GAS_PRICES_API_URL,\n EIP1559APIEndpoint,\n clientId,\n }: {\n interval?: number;\n messenger: GasFeeMessenger;\n state?: GasFeeState;\n getCurrentNetworkEIP1559Compatibility: () => Promise<boolean>;\n getCurrentNetworkLegacyGasAPICompatibility: () => boolean;\n getCurrentAccountEIP1559Compatibility?: () => boolean;\n getChainId?: () => Hex;\n getProvider: () => ProviderProxy;\n onNetworkDidChange?: (listener: (state: NetworkState) => void) => void;\n legacyAPIEndpoint?: string;\n EIP1559APIEndpoint: string;\n clientId?: string;\n }) {\n super({\n name,\n metadata,\n messenger,\n state: { ...defaultState, ...state },\n });\n this.intervalDelay = interval;\n this.setIntervalLength(interval);\n this.pollTokens = new Set();\n this.getCurrentNetworkEIP1559Compatibility =\n getCurrentNetworkEIP1559Compatibility;\n this.getCurrentNetworkLegacyGasAPICompatibility =\n getCurrentNetworkLegacyGasAPICompatibility;\n this.getCurrentAccountEIP1559Compatibility =\n getCurrentAccountEIP1559Compatibility;\n this.#getProvider = getProvider;\n this.EIP1559APIEndpoint = EIP1559APIEndpoint;\n this.legacyAPIEndpoint = legacyAPIEndpoint;\n this.clientId = clientId;\n\n this.ethQuery = new EthQuery(this.#getProvider());\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n\n if (onNetworkDidChange && getChainId) {\n this.currentChainId = getChainId();\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n onNetworkDidChange(async (networkControllerState) => {\n await this.#onNetworkControllerDidChange(networkControllerState);\n });\n } else {\n const { selectedNetworkClientId } = this.messenger.call(\n 'NetworkController:getState',\n );\n this.currentChainId = this.messenger.call(\n 'NetworkController:getNetworkClientById',\n selectedNetworkClientId,\n ).configuration.chainId;\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.ethQuery;\n\n isLegacyGasAPICompatible ??=\n this.getCurrentNetworkLegacyGasAPICompatibility();\n\n decimalChainId ??= convertHexToDecimal(this.currentChainId);\n\n try {\n isEIP1559Compatible ??= await this.getEIP1559Compatibility();\n } catch (e) {\n console.error(e);\n isEIP1559Compatible ??= false;\n }\n\n const gasFeeCalculations = await determineGasFeeCalculations({\n isEIP1559Compatible,\n isLegacyGasAPICompatible,\n fetchGasEstimates,\n fetchGasEstimatesUrl: this.EIP1559APIEndpoint.replace(\n '<chain_id>',\n `${decimalChainId}`,\n ),\n fetchLegacyGasPriceEstimates,\n fetchLegacyGasPriceEstimatesUrl: this.legacyAPIEndpoint.replace(\n '<chain_id>',\n `${decimalChainId}`,\n ),\n fetchEthGasPriceEstimate,\n calculateTimeEstimate,\n clientId: this.clientId,\n ethQuery,\n nonRPCGasFeeApisDisabled: this.state.nonRPCGasFeeApisDisabled,\n });\n\n if (shouldUpdateState) {\n const chainId = toHex(decimalChainId);\n this.update((state) => {\n if (this.currentChainId === chainId) {\n state.gasFeeEstimates = gasFeeCalculations.gasFeeEstimates;\n state.estimatedGasFeeTimeBounds =\n gasFeeCalculations.estimatedGasFeeTimeBounds;\n state.gasEstimateType = gasFeeCalculations.gasEstimateType;\n }\n state.gasFeeEstimatesByChainId ??= {};\n state.gasFeeEstimatesByChainId[chainId] = {\n gasFeeEstimates: gasFeeCalculations.gasFeeEstimates,\n estimatedGasFeeTimeBounds:\n gasFeeCalculations.estimatedGasFeeTimeBounds,\n gasEstimateType: gasFeeCalculations.gasEstimateType,\n } as SingleChainGasFeeState;\n });\n }\n\n return gasFeeCalculations;\n }\n\n /**\n * Remove the poll token, and stop polling if the set of poll tokens is empty.\n *\n * @param pollToken - The poll token to disconnect.\n */\n disconnectPoller(pollToken: string) {\n this.pollTokens.delete(pollToken);\n if (this.pollTokens.size === 0) {\n this.stopPolling();\n }\n }\n\n /**\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.messenger.call(\n 'NetworkController:getNetworkClientById',\n selectedNetworkClientId,\n ).configuration.chainId;\n\n if (newChainId !== this.currentChainId) {\n this.ethQuery = new EthQuery(this.#getProvider());\n await this.resetPolling();\n\n this.currentChainId = newChainId;\n }\n }\n\n enableNonRPCGasFeeApis() {\n this.update((state) => {\n state.nonRPCGasFeeApisDisabled = false;\n });\n }\n\n disableNonRPCGasFeeApis() {\n this.update((state) => {\n state.nonRPCGasFeeApisDisabled = true;\n });\n }\n}\n\nexport default GasFeeController;\n"]}
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAmC","sourcesContent":["export * from './GasFeeController';\n"]}
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAmC","sourcesContent":["export * from './GasFeeController';\nexport type {\n GasFeeControllerResetPollingAction,\n GasFeeControllerFetchGasFeeEstimatesAction,\n GasFeeControllerGetGasFeeEstimatesAndStartPollingAction,\n GasFeeControllerDisconnectPollerAction,\n GasFeeControllerStopPollingAction,\n GasFeeControllerGetTimeEstimateAction,\n} from './GasFeeController-method-action-types';\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export * from "./GasFeeController.cjs";
|
|
2
|
+
export type { GasFeeControllerResetPollingAction, GasFeeControllerFetchGasFeeEstimatesAction, GasFeeControllerGetGasFeeEstimatesAndStartPollingAction, GasFeeControllerDisconnectPollerAction, GasFeeControllerStopPollingAction, GasFeeControllerGetTimeEstimateAction, } from "./GasFeeController-method-action-types.cjs";
|
|
2
3
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uCAAmC"}
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uCAAmC;AACnC,YAAY,EACV,kCAAkC,EAClC,0CAA0C,EAC1C,uDAAuD,EACvD,sCAAsC,EACtC,iCAAiC,EACjC,qCAAqC,GACtC,mDAA+C"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export * from "./GasFeeController.mjs";
|
|
2
|
+
export type { GasFeeControllerResetPollingAction, GasFeeControllerFetchGasFeeEstimatesAction, GasFeeControllerGetGasFeeEstimatesAndStartPollingAction, GasFeeControllerDisconnectPollerAction, GasFeeControllerStopPollingAction, GasFeeControllerGetTimeEstimateAction, } from "./GasFeeController-method-action-types.mjs";
|
|
2
3
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uCAAmC"}
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uCAAmC;AACnC,YAAY,EACV,kCAAkC,EAClC,0CAA0C,EAC1C,uDAAuD,EACvD,sCAAsC,EACtC,iCAAiC,EACjC,qCAAqC,GACtC,mDAA+C"}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uCAAmC","sourcesContent":["export * from './GasFeeController';\n"]}
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uCAAmC","sourcesContent":["export * from './GasFeeController';\nexport type {\n GasFeeControllerResetPollingAction,\n GasFeeControllerFetchGasFeeEstimatesAction,\n GasFeeControllerGetGasFeeEstimatesAndStartPollingAction,\n GasFeeControllerDisconnectPollerAction,\n GasFeeControllerStopPollingAction,\n GasFeeControllerGetTimeEstimateAction,\n} from './GasFeeController-method-action-types';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/gas-fee-controller",
|
|
3
|
-
"version": "26.0
|
|
3
|
+
"version": "26.1.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",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"build:docs": "typedoc",
|
|
41
41
|
"changelog:update": "../../scripts/update-changelog.sh @metamask/gas-fee-controller",
|
|
42
42
|
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/gas-fee-controller",
|
|
43
|
-
"
|
|
43
|
+
"generate-method-action-types": "tsx ../../scripts/generate-method-action-types.ts",
|
|
44
44
|
"since-latest-release": "../../scripts/since-latest-release.sh",
|
|
45
45
|
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
|
|
46
46
|
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
|
|
@@ -71,6 +71,7 @@
|
|
|
71
71
|
"jest-when": "^3.4.2",
|
|
72
72
|
"nock": "^13.3.1",
|
|
73
73
|
"ts-jest": "^29.2.5",
|
|
74
|
+
"tsx": "^4.20.5",
|
|
74
75
|
"typedoc": "^0.25.13",
|
|
75
76
|
"typedoc-plugin-missing-exports": "^2.0.0",
|
|
76
77
|
"typescript": "~5.3.3"
|