@metamask-previews/gas-fee-controller 6.1.1-preview.3dbf14f
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 +85 -0
- package/LICENSE +20 -0
- package/README.md +15 -0
- package/dist/GasFeeController.d.ts +231 -0
- package/dist/GasFeeController.d.ts.map +1 -0
- package/dist/GasFeeController.js +262 -0
- package/dist/GasFeeController.js.map +1 -0
- package/dist/determineGasFeeCalculations.d.ts +41 -0
- package/dist/determineGasFeeCalculations.d.ts.map +1 -0
- package/dist/determineGasFeeCalculations.js +87 -0
- package/dist/determineGasFeeCalculations.js.map +1 -0
- package/dist/fetchBlockFeeHistory.d.ts +116 -0
- package/dist/fetchBlockFeeHistory.d.ts.map +1 -0
- package/dist/fetchBlockFeeHistory.js +202 -0
- package/dist/fetchBlockFeeHistory.js.map +1 -0
- package/dist/fetchGasEstimatesViaEthFeeHistory/calculateGasFeeEstimatesForPriorityLevels.d.ts +17 -0
- package/dist/fetchGasEstimatesViaEthFeeHistory/calculateGasFeeEstimatesForPriorityLevels.d.ts.map +1 -0
- package/dist/fetchGasEstimatesViaEthFeeHistory/calculateGasFeeEstimatesForPriorityLevels.js +89 -0
- package/dist/fetchGasEstimatesViaEthFeeHistory/calculateGasFeeEstimatesForPriorityLevels.js.map +1 -0
- package/dist/fetchGasEstimatesViaEthFeeHistory/fetchLatestBlock.d.ts +12 -0
- package/dist/fetchGasEstimatesViaEthFeeHistory/fetchLatestBlock.d.ts.map +1 -0
- package/dist/fetchGasEstimatesViaEthFeeHistory/fetchLatestBlock.js +32 -0
- package/dist/fetchGasEstimatesViaEthFeeHistory/fetchLatestBlock.js.map +1 -0
- package/dist/fetchGasEstimatesViaEthFeeHistory/medianOf.d.ts +11 -0
- package/dist/fetchGasEstimatesViaEthFeeHistory/medianOf.d.ts.map +1 -0
- package/dist/fetchGasEstimatesViaEthFeeHistory/medianOf.js +17 -0
- package/dist/fetchGasEstimatesViaEthFeeHistory/medianOf.js.map +1 -0
- package/dist/fetchGasEstimatesViaEthFeeHistory/types.d.ts +8 -0
- package/dist/fetchGasEstimatesViaEthFeeHistory/types.d.ts.map +1 -0
- package/dist/fetchGasEstimatesViaEthFeeHistory/types.js +3 -0
- package/dist/fetchGasEstimatesViaEthFeeHistory/types.js.map +1 -0
- package/dist/fetchGasEstimatesViaEthFeeHistory.d.ts +22 -0
- package/dist/fetchGasEstimatesViaEthFeeHistory.d.ts.map +1 -0
- package/dist/fetchGasEstimatesViaEthFeeHistory.js +53 -0
- package/dist/fetchGasEstimatesViaEthFeeHistory.js.map +1 -0
- package/dist/gas-util.d.ts +43 -0
- package/dist/gas-util.d.ts.map +1 -0
- package/dist/gas-util.js +140 -0
- package/dist/gas-util.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/package.json +66 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
All notable changes to this project will be documented in this file.
|
|
3
|
+
|
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## [6.1.1]
|
|
10
|
+
### Uncategorized
|
|
11
|
+
- Replace `eth-query` ^2.1.2 with `@metamask/eth-query` ^3.0.1 ([#1546](https://github.com/MetaMask/core/pull/1546))
|
|
12
|
+
|
|
13
|
+
## [6.1.0]
|
|
14
|
+
### Changed
|
|
15
|
+
- Update `@metamask/utils` to `^6.2.0` ([#1514](https://github.com/MetaMask/core/pull/1514))
|
|
16
|
+
- Remove unnecessary `babel-runtime` dependencies ([#1504](https://github.com/MetaMask/core/pull/1504))
|
|
17
|
+
|
|
18
|
+
## [6.0.1]
|
|
19
|
+
### Changed
|
|
20
|
+
- Bump dependency on `controller-utils` ([#1447](https://github.com/MetaMask/core/pull/1447))
|
|
21
|
+
- The new version of `controller-utils` adds `eth-query` to the list of dependencies. This dependency was added to improve internal types for `gas-fee-controller`. This has no impact on users of the package.
|
|
22
|
+
|
|
23
|
+
## [6.0.0]
|
|
24
|
+
### Changed
|
|
25
|
+
- **BREAKING:** Bump to Node 16 ([#1262](https://github.com/MetaMask/core/pull/1262))
|
|
26
|
+
- **BREAKING:** The `getChainId` constructor parameter now expects a `Hex` return type rather than a decimal string ([#1367](https://github.com/MetaMask/core/pull/1367))
|
|
27
|
+
- Add `@metamask/utils` dependency
|
|
28
|
+
- **BREAKING:** The gas fee controller messenger now requires the `NetworkController:stateChange` event instead of the `NetworkController:providerConfigChange` event ([#1329](https://github.com/MetaMask/core/pull/1329))
|
|
29
|
+
- This does not apply if `onNetworkStateChange` and `getChainId` are provided to the constructor
|
|
30
|
+
- **BREAKING:** The constructor parameter `onNetworkStateChange` now expects event handlers to be passed the full network state ([#1329](https://github.com/MetaMask/core/pull/1329))
|
|
31
|
+
- The type of the `onNetworkStateChange` parameter already expected the state to be provided, but it wasn't used before now
|
|
32
|
+
- **BREAKING:** Update `@metamask/network-controller` dependency and peer dependency
|
|
33
|
+
|
|
34
|
+
## [5.0.0]
|
|
35
|
+
### Changed
|
|
36
|
+
- **BREAKING**: peerDeps: @metamask/network-controller@6.0.0->8.0.0 ([#1196](https://github.com/MetaMask/core/pull/1196))
|
|
37
|
+
|
|
38
|
+
## [4.0.1]
|
|
39
|
+
### Changed
|
|
40
|
+
- Adjust types to align with new version of `NetworkController` ([#1091](https://github.com/MetaMask/core/pull/1091))
|
|
41
|
+
|
|
42
|
+
## [4.0.0]
|
|
43
|
+
### Changed
|
|
44
|
+
- **BREAKING:** Make the EIP-1559 endpoint a required argument ([#1083](https://github.com/MetaMask/core/pull/1083))
|
|
45
|
+
|
|
46
|
+
### Removed
|
|
47
|
+
- **BREAKING:** Remove `isomorphic-fetch` ([#1106](https://github.com/MetaMask/controllers/pull/1106))
|
|
48
|
+
- Consumers must now import `isomorphic-fetch` or another polyfill themselves if they are running in an environment without `fetch`
|
|
49
|
+
|
|
50
|
+
## [3.0.0]
|
|
51
|
+
### Changed
|
|
52
|
+
- **BREAKING:** Update `@metamask/network-controller` peer dependency to v3 ([#1041](https://github.com/MetaMask/controllers/pull/1041))
|
|
53
|
+
- Rename this repository to `core` ([#1031](https://github.com/MetaMask/controllers/pull/1031))
|
|
54
|
+
- Update `@metamask/controller-utils` package ([#1041](https://github.com/MetaMask/controllers/pull/1041))
|
|
55
|
+
|
|
56
|
+
## [2.0.1]
|
|
57
|
+
### Fixed
|
|
58
|
+
- This package will now warn if a required package is not present ([#1003](https://github.com/MetaMask/core/pull/1003))
|
|
59
|
+
|
|
60
|
+
## [2.0.0]
|
|
61
|
+
### Changed
|
|
62
|
+
- **BREAKING:** Bump `@metamask/network-controller` to 2.0.0 ([#995](https://github.com/MetaMask/core/pull/995))
|
|
63
|
+
- GasFeeController now expects NetworkController to respond to the `NetworkController:providerChangeConfig` event (previously named `NetworkController:providerChange`). If you are depending directly on `@metamask/network-controller`, you should update your version to at least 2.0.0 as well.
|
|
64
|
+
- Relax dependencies on `@metamask/base-controller`, `@metamask/controller-utils`, and `@metamask/network-controller` (use `^` instead of `~`) ([#998](https://github.com/MetaMask/core/pull/998))
|
|
65
|
+
|
|
66
|
+
## [1.0.0]
|
|
67
|
+
### Added
|
|
68
|
+
- Initial release
|
|
69
|
+
- As a result of converting our shared controllers repo into a monorepo ([#831](https://github.com/MetaMask/core/pull/831)), we've created this package from select parts of [`@metamask/controllers` v33.0.0](https://github.com/MetaMask/core/tree/v33.0.0), namely:
|
|
70
|
+
- Everything in `src/gas`
|
|
71
|
+
|
|
72
|
+
All changes listed after this point were applied to this package following the monorepo conversion.
|
|
73
|
+
|
|
74
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@6.1.1...HEAD
|
|
75
|
+
[6.1.1]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@6.1.0...@metamask/gas-fee-controller@6.1.1
|
|
76
|
+
[6.1.0]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@6.0.1...@metamask/gas-fee-controller@6.1.0
|
|
77
|
+
[6.0.1]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@6.0.0...@metamask/gas-fee-controller@6.0.1
|
|
78
|
+
[6.0.0]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@5.0.0...@metamask/gas-fee-controller@6.0.0
|
|
79
|
+
[5.0.0]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@4.0.1...@metamask/gas-fee-controller@5.0.0
|
|
80
|
+
[4.0.1]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@4.0.0...@metamask/gas-fee-controller@4.0.1
|
|
81
|
+
[4.0.0]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@3.0.0...@metamask/gas-fee-controller@4.0.0
|
|
82
|
+
[3.0.0]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@2.0.1...@metamask/gas-fee-controller@3.0.0
|
|
83
|
+
[2.0.1]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@2.0.0...@metamask/gas-fee-controller@2.0.1
|
|
84
|
+
[2.0.0]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@1.0.0...@metamask/gas-fee-controller@2.0.0
|
|
85
|
+
[1.0.0]: https://github.com/MetaMask/core/releases/tag/@metamask/gas-fee-controller@1.0.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 MetaMask
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# `@metamask/gas-fee-controller`
|
|
2
|
+
|
|
3
|
+
Periodically calculates gas fee estimates based on various gas limits as well as other data displayed on transaction confirm screens.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
`yarn add @metamask/gas-fee-controller`
|
|
8
|
+
|
|
9
|
+
or
|
|
10
|
+
|
|
11
|
+
`npm install @metamask/gas-fee-controller`
|
|
12
|
+
|
|
13
|
+
## Contributing
|
|
14
|
+
|
|
15
|
+
This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/core#readme).
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import type { RestrictedControllerMessenger } from '@metamask/base-controller';
|
|
2
|
+
import { BaseControllerV2 } from '@metamask/base-controller';
|
|
3
|
+
import type { NetworkControllerGetStateAction, NetworkControllerStateChangeEvent, NetworkState, ProviderProxy } from '@metamask/network-controller';
|
|
4
|
+
import type { Hex } from '@metamask/utils';
|
|
5
|
+
import type { Patch } from 'immer';
|
|
6
|
+
export declare const LEGACY_GAS_PRICES_API_URL = "https://api.metaswap.codefi.network/gasPrices";
|
|
7
|
+
export declare type unknownString = 'unknown';
|
|
8
|
+
export declare type FeeMarketEstimateType = 'fee-market';
|
|
9
|
+
export declare type LegacyEstimateType = 'legacy';
|
|
10
|
+
export declare type EthGasPriceEstimateType = 'eth_gasPrice';
|
|
11
|
+
export declare type NoEstimateType = 'none';
|
|
12
|
+
/**
|
|
13
|
+
* Indicates which type of gasEstimate the controller is currently returning.
|
|
14
|
+
* This is useful as a way of asserting that the shape of gasEstimates matches
|
|
15
|
+
* expectations. NONE is a special case indicating that no previous gasEstimate
|
|
16
|
+
* has been fetched.
|
|
17
|
+
*/
|
|
18
|
+
export declare const GAS_ESTIMATE_TYPES: {
|
|
19
|
+
FEE_MARKET: "fee-market";
|
|
20
|
+
LEGACY: "legacy";
|
|
21
|
+
ETH_GASPRICE: "eth_gasPrice";
|
|
22
|
+
NONE: "none";
|
|
23
|
+
};
|
|
24
|
+
export declare type GasEstimateType = FeeMarketEstimateType | EthGasPriceEstimateType | LegacyEstimateType | NoEstimateType;
|
|
25
|
+
export declare type EstimatedGasFeeTimeBounds = {
|
|
26
|
+
lowerTimeBound: number | null;
|
|
27
|
+
upperTimeBound: number | unknownString;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* @type EthGasPriceEstimate
|
|
31
|
+
*
|
|
32
|
+
* A single gas price estimate for networks and accounts that don't support EIP-1559
|
|
33
|
+
* This estimate comes from eth_gasPrice but is converted to dec gwei to match other
|
|
34
|
+
* return values
|
|
35
|
+
* @property gasPrice - A GWEI dec string
|
|
36
|
+
*/
|
|
37
|
+
export declare type EthGasPriceEstimate = {
|
|
38
|
+
gasPrice: string;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* @type LegacyGasPriceEstimate
|
|
42
|
+
*
|
|
43
|
+
* A set of gas price estimates for networks and accounts that don't support EIP-1559
|
|
44
|
+
* These estimates include low, medium and high all as strings representing gwei in
|
|
45
|
+
* decimal format.
|
|
46
|
+
* @property high - gasPrice, in decimal gwei string format, suggested for fast inclusion
|
|
47
|
+
* @property medium - gasPrice, in decimal gwei string format, suggested for avg inclusion
|
|
48
|
+
* @property low - gasPrice, in decimal gwei string format, suggested for slow inclusion
|
|
49
|
+
*/
|
|
50
|
+
export declare type LegacyGasPriceEstimate = {
|
|
51
|
+
high: string;
|
|
52
|
+
medium: string;
|
|
53
|
+
low: string;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* @type Eip1559GasFee
|
|
57
|
+
*
|
|
58
|
+
* Data necessary to provide an estimate of a gas fee with a specific tip
|
|
59
|
+
* @property minWaitTimeEstimate - The fastest the transaction will take, in milliseconds
|
|
60
|
+
* @property maxWaitTimeEstimate - The slowest the transaction will take, in milliseconds
|
|
61
|
+
* @property suggestedMaxPriorityFeePerGas - A suggested "tip", a GWEI hex number
|
|
62
|
+
* @property suggestedMaxFeePerGas - A suggested max fee, the most a user will pay. a GWEI hex number
|
|
63
|
+
*/
|
|
64
|
+
export declare type Eip1559GasFee = {
|
|
65
|
+
minWaitTimeEstimate: number;
|
|
66
|
+
maxWaitTimeEstimate: number;
|
|
67
|
+
suggestedMaxPriorityFeePerGas: string;
|
|
68
|
+
suggestedMaxFeePerGas: string;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* @type GasFeeEstimates
|
|
72
|
+
*
|
|
73
|
+
* Data necessary to provide multiple GasFee estimates, and supporting information, to the user
|
|
74
|
+
* @property low - A GasFee for a minimum necessary combination of tip and maxFee
|
|
75
|
+
* @property medium - A GasFee for a recommended combination of tip and maxFee
|
|
76
|
+
* @property high - A GasFee for a high combination of tip and maxFee
|
|
77
|
+
* @property estimatedBaseFee - An estimate of what the base fee will be for the pending/next block. A GWEI dec number
|
|
78
|
+
* @property networkCongestion - A normalized number that can be used to gauge the congestion
|
|
79
|
+
* level of the network, with 0 meaning not congested and 1 meaning extremely congested
|
|
80
|
+
*/
|
|
81
|
+
export declare type GasFeeEstimates = SourcedGasFeeEstimates | FallbackGasFeeEstimates;
|
|
82
|
+
declare type SourcedGasFeeEstimates = {
|
|
83
|
+
low: Eip1559GasFee;
|
|
84
|
+
medium: Eip1559GasFee;
|
|
85
|
+
high: Eip1559GasFee;
|
|
86
|
+
estimatedBaseFee: string;
|
|
87
|
+
historicalBaseFeeRange: [string, string];
|
|
88
|
+
baseFeeTrend: 'up' | 'down' | 'level';
|
|
89
|
+
latestPriorityFeeRange: [string, string];
|
|
90
|
+
historicalPriorityFeeRange: [string, string];
|
|
91
|
+
priorityFeeTrend: 'up' | 'down' | 'level';
|
|
92
|
+
networkCongestion: number;
|
|
93
|
+
};
|
|
94
|
+
declare type FallbackGasFeeEstimates = {
|
|
95
|
+
low: Eip1559GasFee;
|
|
96
|
+
medium: Eip1559GasFee;
|
|
97
|
+
high: Eip1559GasFee;
|
|
98
|
+
estimatedBaseFee: string;
|
|
99
|
+
historicalBaseFeeRange: null;
|
|
100
|
+
baseFeeTrend: null;
|
|
101
|
+
latestPriorityFeeRange: null;
|
|
102
|
+
historicalPriorityFeeRange: null;
|
|
103
|
+
priorityFeeTrend: null;
|
|
104
|
+
networkCongestion: null;
|
|
105
|
+
};
|
|
106
|
+
export declare type GasFeeStateEthGasPrice = {
|
|
107
|
+
gasFeeEstimates: EthGasPriceEstimate;
|
|
108
|
+
estimatedGasFeeTimeBounds: Record<string, never>;
|
|
109
|
+
gasEstimateType: EthGasPriceEstimateType;
|
|
110
|
+
};
|
|
111
|
+
export declare type GasFeeStateFeeMarket = {
|
|
112
|
+
gasFeeEstimates: GasFeeEstimates;
|
|
113
|
+
estimatedGasFeeTimeBounds: EstimatedGasFeeTimeBounds | Record<string, never>;
|
|
114
|
+
gasEstimateType: FeeMarketEstimateType;
|
|
115
|
+
};
|
|
116
|
+
export declare type GasFeeStateLegacy = {
|
|
117
|
+
gasFeeEstimates: LegacyGasPriceEstimate;
|
|
118
|
+
estimatedGasFeeTimeBounds: Record<string, never>;
|
|
119
|
+
gasEstimateType: LegacyEstimateType;
|
|
120
|
+
};
|
|
121
|
+
export declare type GasFeeStateNoEstimates = {
|
|
122
|
+
gasFeeEstimates: Record<string, never>;
|
|
123
|
+
estimatedGasFeeTimeBounds: Record<string, never>;
|
|
124
|
+
gasEstimateType: NoEstimateType;
|
|
125
|
+
};
|
|
126
|
+
export declare type FetchGasFeeEstimateOptions = {
|
|
127
|
+
shouldUpdateState?: boolean;
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* @type GasFeeState
|
|
131
|
+
*
|
|
132
|
+
* Gas Fee controller state
|
|
133
|
+
* @property gasFeeEstimates - Gas fee estimate data based on new EIP-1559 properties
|
|
134
|
+
* @property estimatedGasFeeTimeBounds - Estimates representing the minimum and maximum
|
|
135
|
+
*/
|
|
136
|
+
export declare type GasFeeState = GasFeeStateEthGasPrice | GasFeeStateFeeMarket | GasFeeStateLegacy | GasFeeStateNoEstimates;
|
|
137
|
+
declare const name = "GasFeeController";
|
|
138
|
+
export declare type GasFeeStateChange = {
|
|
139
|
+
type: `${typeof name}:stateChange`;
|
|
140
|
+
payload: [GasFeeState, Patch[]];
|
|
141
|
+
};
|
|
142
|
+
export declare type GetGasFeeState = {
|
|
143
|
+
type: `${typeof name}:getState`;
|
|
144
|
+
handler: () => GasFeeState;
|
|
145
|
+
};
|
|
146
|
+
declare type GasFeeMessenger = RestrictedControllerMessenger<typeof name, GetGasFeeState | NetworkControllerGetStateAction, GasFeeStateChange | NetworkControllerStateChangeEvent, NetworkControllerGetStateAction['type'], NetworkControllerStateChangeEvent['type']>;
|
|
147
|
+
/**
|
|
148
|
+
* Controller that retrieves gas fee estimate data and polls for updated data on a set interval
|
|
149
|
+
*/
|
|
150
|
+
export declare class GasFeeController extends BaseControllerV2<typeof name, GasFeeState, GasFeeMessenger> {
|
|
151
|
+
#private;
|
|
152
|
+
private intervalId?;
|
|
153
|
+
private readonly intervalDelay;
|
|
154
|
+
private readonly pollTokens;
|
|
155
|
+
private readonly legacyAPIEndpoint;
|
|
156
|
+
private readonly EIP1559APIEndpoint;
|
|
157
|
+
private readonly getCurrentNetworkEIP1559Compatibility;
|
|
158
|
+
private readonly getCurrentNetworkLegacyGasAPICompatibility;
|
|
159
|
+
private readonly getCurrentAccountEIP1559Compatibility;
|
|
160
|
+
private currentChainId;
|
|
161
|
+
private ethQuery?;
|
|
162
|
+
private readonly clientId?;
|
|
163
|
+
/**
|
|
164
|
+
* Creates a GasFeeController instance.
|
|
165
|
+
*
|
|
166
|
+
* @param options - The controller options.
|
|
167
|
+
* @param options.interval - The time in milliseconds to wait between polls.
|
|
168
|
+
* @param options.messenger - The controller messenger.
|
|
169
|
+
* @param options.state - The initial state.
|
|
170
|
+
* @param options.getCurrentNetworkEIP1559Compatibility - Determines whether or not the current
|
|
171
|
+
* network is EIP-1559 compatible.
|
|
172
|
+
* @param options.getCurrentNetworkLegacyGasAPICompatibility - Determines whether or not the
|
|
173
|
+
* current network is compatible with the legacy gas price API.
|
|
174
|
+
* @param options.getCurrentAccountEIP1559Compatibility - Determines whether or not the current
|
|
175
|
+
* account is EIP-1559 compatible.
|
|
176
|
+
* @param options.getChainId - Returns the current chain ID.
|
|
177
|
+
* @param options.getProvider - Returns a network provider for the current network.
|
|
178
|
+
* @param options.onNetworkStateChange - A function for registering an event handler for the
|
|
179
|
+
* network state change event.
|
|
180
|
+
* @param options.legacyAPIEndpoint - The legacy gas price API URL. This option is primarily for
|
|
181
|
+
* testing purposes.
|
|
182
|
+
* @param options.EIP1559APIEndpoint - The EIP-1559 gas price API URL.
|
|
183
|
+
* @param options.clientId - The client ID used to identify to the gas estimation API who is
|
|
184
|
+
* asking for estimates.
|
|
185
|
+
*/
|
|
186
|
+
constructor({ interval, messenger, state, getCurrentNetworkEIP1559Compatibility, getCurrentAccountEIP1559Compatibility, getChainId, getCurrentNetworkLegacyGasAPICompatibility, getProvider, onNetworkStateChange, legacyAPIEndpoint, EIP1559APIEndpoint, clientId, }: {
|
|
187
|
+
interval?: number;
|
|
188
|
+
messenger: GasFeeMessenger;
|
|
189
|
+
state?: GasFeeState;
|
|
190
|
+
getCurrentNetworkEIP1559Compatibility: () => Promise<boolean>;
|
|
191
|
+
getCurrentNetworkLegacyGasAPICompatibility: () => boolean;
|
|
192
|
+
getCurrentAccountEIP1559Compatibility?: () => boolean;
|
|
193
|
+
getChainId?: () => Hex;
|
|
194
|
+
getProvider: () => ProviderProxy;
|
|
195
|
+
onNetworkStateChange?: (listener: (state: NetworkState) => void) => void;
|
|
196
|
+
legacyAPIEndpoint?: string;
|
|
197
|
+
EIP1559APIEndpoint: string;
|
|
198
|
+
clientId?: string;
|
|
199
|
+
});
|
|
200
|
+
resetPolling(): Promise<void>;
|
|
201
|
+
fetchGasFeeEstimates(options?: FetchGasFeeEstimateOptions): Promise<GasFeeState>;
|
|
202
|
+
getGasFeeEstimatesAndStartPolling(pollToken: string | undefined): Promise<string>;
|
|
203
|
+
/**
|
|
204
|
+
* Gets and sets gasFeeEstimates in state.
|
|
205
|
+
*
|
|
206
|
+
* @param options - The gas fee estimate options.
|
|
207
|
+
* @param options.shouldUpdateState - Determines whether the state should be updated with the
|
|
208
|
+
* updated gas estimates.
|
|
209
|
+
* @returns The gas fee estimates.
|
|
210
|
+
*/
|
|
211
|
+
_fetchGasFeeEstimateData(options?: FetchGasFeeEstimateOptions): Promise<GasFeeState>;
|
|
212
|
+
/**
|
|
213
|
+
* Remove the poll token, and stop polling if the set of poll tokens is empty.
|
|
214
|
+
*
|
|
215
|
+
* @param pollToken - The poll token to disconnect.
|
|
216
|
+
*/
|
|
217
|
+
disconnectPoller(pollToken: string): void;
|
|
218
|
+
stopPolling(): void;
|
|
219
|
+
/**
|
|
220
|
+
* Prepare to discard this controller.
|
|
221
|
+
*
|
|
222
|
+
* This stops any active polling.
|
|
223
|
+
*/
|
|
224
|
+
destroy(): void;
|
|
225
|
+
private _poll;
|
|
226
|
+
private resetState;
|
|
227
|
+
private getEIP1559Compatibility;
|
|
228
|
+
getTimeEstimate(maxPriorityFeePerGas: string, maxFeePerGas: string): EstimatedGasFeeTimeBounds | Record<string, never>;
|
|
229
|
+
}
|
|
230
|
+
export default GasFeeController;
|
|
231
|
+
//# sourceMappingURL=GasFeeController.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GasFeeController.d.ts","sourceRoot":"","sources":["../src/GasFeeController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAG7D,OAAO,KAAK,EACV,+BAA+B,EAC/B,iCAAiC,EACjC,YAAY,EACZ,aAAa,EACd,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAYnC,eAAO,MAAM,yBAAyB,kDAAkD,CAAC;AAEzF,oBAAY,aAAa,GAAG,SAAS,CAAC;AAItC,oBAAY,qBAAqB,GAAG,YAAY,CAAC;AAIjD,oBAAY,kBAAkB,GAAG,QAAQ,CAAC;AAK1C,oBAAY,uBAAuB,GAAG,cAAc,CAAC;AAGrD,oBAAY,cAAc,GAAG,MAAM,CAAC;AAEpC;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB;;;;;CAK9B,CAAC;AAEF,oBAAY,eAAe,GACvB,qBAAqB,GACrB,uBAAuB,GACvB,kBAAkB,GAClB,cAAc,CAAC;AAEnB,oBAAY,yBAAyB,GAAG;IACtC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,cAAc,EAAE,MAAM,GAAG,aAAa,CAAC;CACxC,CAAC;AAEF;;;;;;;GAOG;AAEH,oBAAY,mBAAmB,GAAG;IAChC,QAAQ,EAAE,MAAM,CAAC;CAClB,CA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AE,MAAM,GAAG,CAAC;QACvB,WAAW,EAAE,MAAM,aAAa,CAAC;QACjC,oBAAoB,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,KAAK,IAAI,CAAC;QACzE,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,kBAAkB,EAAE,MAAM,CAAC;QAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB;IAwCK,YAAY;IAWZ,oBAAoB,CAAC,OAAO,CAAC,EAAE,0BAA0B;IAIzD,iCAAiC,CACrC,SAAS,EAAE,MAAM,GAAG,SAAS,GAC5B,OAAO,CAAC,MAAM,CAAC;IAalB;;;;;;;OAOG;IACG,wBAAwB,CAC5B,OAAO,GAAE,0BAA+B,GACvC,OAAO,CAAC,WAAW,CAAC;IA+CvB;;;;OAIG;IACH,gBAAgB,CAAC,SAAS,EAAE,MAAM;IAOlC,WAAW;IAQX;;;;OAIG;IACM,OAAO;IAKhB,OAAO,CAAC,KAAK;IAUb,OAAO,CAAC,UAAU;YAMJ,uBAAuB;IAWrC,eAAe,CACb,oBAAoB,EAAE,MAAM,EAC5B,YAAY,EAAE,MAAM,GACnB,yBAAyB,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC;CAwBrD;AAED,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
12
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
13
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
14
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
15
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
16
|
+
};
|
|
17
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
18
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
19
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
20
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
21
|
+
};
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
var _GasFeeController_instances, _GasFeeController_getProvider, _GasFeeController_onNetworkControllerStateChange;
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.GasFeeController = exports.GAS_ESTIMATE_TYPES = exports.LEGACY_GAS_PRICES_API_URL = void 0;
|
|
28
|
+
const base_controller_1 = require("@metamask/base-controller");
|
|
29
|
+
const controller_utils_1 = require("@metamask/controller-utils");
|
|
30
|
+
const eth_query_1 = __importDefault(require("@metamask/eth-query"));
|
|
31
|
+
const uuid_1 = require("uuid");
|
|
32
|
+
const determineGasFeeCalculations_1 = __importDefault(require("./determineGasFeeCalculations"));
|
|
33
|
+
const fetchGasEstimatesViaEthFeeHistory_1 = __importDefault(require("./fetchGasEstimatesViaEthFeeHistory"));
|
|
34
|
+
const gas_util_1 = require("./gas-util");
|
|
35
|
+
exports.LEGACY_GAS_PRICES_API_URL = `https://api.metaswap.codefi.network/gasPrices`;
|
|
36
|
+
/**
|
|
37
|
+
* Indicates which type of gasEstimate the controller is currently returning.
|
|
38
|
+
* This is useful as a way of asserting that the shape of gasEstimates matches
|
|
39
|
+
* expectations. NONE is a special case indicating that no previous gasEstimate
|
|
40
|
+
* has been fetched.
|
|
41
|
+
*/
|
|
42
|
+
exports.GAS_ESTIMATE_TYPES = {
|
|
43
|
+
FEE_MARKET: 'fee-market',
|
|
44
|
+
LEGACY: 'legacy',
|
|
45
|
+
ETH_GASPRICE: 'eth_gasPrice',
|
|
46
|
+
NONE: 'none',
|
|
47
|
+
};
|
|
48
|
+
const metadata = {
|
|
49
|
+
gasFeeEstimates: { persist: true, anonymous: false },
|
|
50
|
+
estimatedGasFeeTimeBounds: { persist: true, anonymous: false },
|
|
51
|
+
gasEstimateType: { persist: true, anonymous: false },
|
|
52
|
+
};
|
|
53
|
+
const name = 'GasFeeController';
|
|
54
|
+
const defaultState = {
|
|
55
|
+
gasFeeEstimates: {},
|
|
56
|
+
estimatedGasFeeTimeBounds: {},
|
|
57
|
+
gasEstimateType: exports.GAS_ESTIMATE_TYPES.NONE,
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Controller that retrieves gas fee estimate data and polls for updated data on a set interval
|
|
61
|
+
*/
|
|
62
|
+
class GasFeeController extends base_controller_1.BaseControllerV2 {
|
|
63
|
+
/**
|
|
64
|
+
* Creates a GasFeeController instance.
|
|
65
|
+
*
|
|
66
|
+
* @param options - The controller options.
|
|
67
|
+
* @param options.interval - The time in milliseconds to wait between polls.
|
|
68
|
+
* @param options.messenger - The controller messenger.
|
|
69
|
+
* @param options.state - The initial state.
|
|
70
|
+
* @param options.getCurrentNetworkEIP1559Compatibility - Determines whether or not the current
|
|
71
|
+
* network is EIP-1559 compatible.
|
|
72
|
+
* @param options.getCurrentNetworkLegacyGasAPICompatibility - Determines whether or not the
|
|
73
|
+
* current network is compatible with the legacy gas price API.
|
|
74
|
+
* @param options.getCurrentAccountEIP1559Compatibility - Determines whether or not the current
|
|
75
|
+
* account is EIP-1559 compatible.
|
|
76
|
+
* @param options.getChainId - Returns the current chain ID.
|
|
77
|
+
* @param options.getProvider - Returns a network provider for the current network.
|
|
78
|
+
* @param options.onNetworkStateChange - A function for registering an event handler for the
|
|
79
|
+
* network state change event.
|
|
80
|
+
* @param options.legacyAPIEndpoint - The legacy gas price API URL. This option is primarily for
|
|
81
|
+
* testing purposes.
|
|
82
|
+
* @param options.EIP1559APIEndpoint - The EIP-1559 gas price API URL.
|
|
83
|
+
* @param options.clientId - The client ID used to identify to the gas estimation API who is
|
|
84
|
+
* asking for estimates.
|
|
85
|
+
*/
|
|
86
|
+
constructor({ interval = 15000, messenger, state, getCurrentNetworkEIP1559Compatibility, getCurrentAccountEIP1559Compatibility, getChainId, getCurrentNetworkLegacyGasAPICompatibility, getProvider, onNetworkStateChange, legacyAPIEndpoint = exports.LEGACY_GAS_PRICES_API_URL, EIP1559APIEndpoint, clientId, }) {
|
|
87
|
+
super({
|
|
88
|
+
name,
|
|
89
|
+
metadata,
|
|
90
|
+
messenger,
|
|
91
|
+
state: Object.assign(Object.assign({}, defaultState), state),
|
|
92
|
+
});
|
|
93
|
+
_GasFeeController_instances.add(this);
|
|
94
|
+
_GasFeeController_getProvider.set(this, void 0);
|
|
95
|
+
this.intervalDelay = interval;
|
|
96
|
+
this.pollTokens = new Set();
|
|
97
|
+
this.getCurrentNetworkEIP1559Compatibility =
|
|
98
|
+
getCurrentNetworkEIP1559Compatibility;
|
|
99
|
+
this.getCurrentNetworkLegacyGasAPICompatibility =
|
|
100
|
+
getCurrentNetworkLegacyGasAPICompatibility;
|
|
101
|
+
this.getCurrentAccountEIP1559Compatibility =
|
|
102
|
+
getCurrentAccountEIP1559Compatibility;
|
|
103
|
+
__classPrivateFieldSet(this, _GasFeeController_getProvider, getProvider, "f");
|
|
104
|
+
this.EIP1559APIEndpoint = EIP1559APIEndpoint;
|
|
105
|
+
this.legacyAPIEndpoint = legacyAPIEndpoint;
|
|
106
|
+
this.clientId = clientId;
|
|
107
|
+
this.ethQuery = new eth_query_1.default(__classPrivateFieldGet(this, _GasFeeController_getProvider, "f").call(this));
|
|
108
|
+
if (onNetworkStateChange && getChainId) {
|
|
109
|
+
this.currentChainId = getChainId();
|
|
110
|
+
onNetworkStateChange((networkControllerState) => __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
yield __classPrivateFieldGet(this, _GasFeeController_instances, "m", _GasFeeController_onNetworkControllerStateChange).call(this, networkControllerState);
|
|
112
|
+
}));
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
this.currentChainId = this.messagingSystem.call('NetworkController:getState').providerConfig.chainId;
|
|
116
|
+
this.messagingSystem.subscribe('NetworkController:stateChange', (networkControllerState) => __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
yield __classPrivateFieldGet(this, _GasFeeController_instances, "m", _GasFeeController_onNetworkControllerStateChange).call(this, networkControllerState);
|
|
118
|
+
}));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
resetPolling() {
|
|
122
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
123
|
+
if (this.pollTokens.size !== 0) {
|
|
124
|
+
const tokens = Array.from(this.pollTokens);
|
|
125
|
+
this.stopPolling();
|
|
126
|
+
yield this.getGasFeeEstimatesAndStartPolling(tokens[0]);
|
|
127
|
+
tokens.slice(1).forEach((token) => {
|
|
128
|
+
this.pollTokens.add(token);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
fetchGasFeeEstimates(options) {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
return yield this._fetchGasFeeEstimateData(options);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
getGasFeeEstimatesAndStartPolling(pollToken) {
|
|
139
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
140
|
+
const _pollToken = pollToken || (0, uuid_1.v1)();
|
|
141
|
+
this.pollTokens.add(_pollToken);
|
|
142
|
+
if (this.pollTokens.size === 1) {
|
|
143
|
+
yield this._fetchGasFeeEstimateData();
|
|
144
|
+
this._poll();
|
|
145
|
+
}
|
|
146
|
+
return _pollToken;
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Gets and sets gasFeeEstimates in state.
|
|
151
|
+
*
|
|
152
|
+
* @param options - The gas fee estimate options.
|
|
153
|
+
* @param options.shouldUpdateState - Determines whether the state should be updated with the
|
|
154
|
+
* updated gas estimates.
|
|
155
|
+
* @returns The gas fee estimates.
|
|
156
|
+
*/
|
|
157
|
+
_fetchGasFeeEstimateData(options = {}) {
|
|
158
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
159
|
+
const { shouldUpdateState = true } = options;
|
|
160
|
+
let isEIP1559Compatible;
|
|
161
|
+
const isLegacyGasAPICompatible = this.getCurrentNetworkLegacyGasAPICompatibility();
|
|
162
|
+
const decimalChainId = (0, controller_utils_1.convertHexToDecimal)(this.currentChainId);
|
|
163
|
+
try {
|
|
164
|
+
isEIP1559Compatible = yield this.getEIP1559Compatibility();
|
|
165
|
+
}
|
|
166
|
+
catch (e) {
|
|
167
|
+
console.error(e);
|
|
168
|
+
isEIP1559Compatible = false;
|
|
169
|
+
}
|
|
170
|
+
const gasFeeCalculations = yield (0, determineGasFeeCalculations_1.default)({
|
|
171
|
+
isEIP1559Compatible,
|
|
172
|
+
isLegacyGasAPICompatible,
|
|
173
|
+
fetchGasEstimates: gas_util_1.fetchGasEstimates,
|
|
174
|
+
fetchGasEstimatesUrl: this.EIP1559APIEndpoint.replace('<chain_id>', `${decimalChainId}`),
|
|
175
|
+
fetchGasEstimatesViaEthFeeHistory: fetchGasEstimatesViaEthFeeHistory_1.default,
|
|
176
|
+
fetchLegacyGasPriceEstimates: gas_util_1.fetchLegacyGasPriceEstimates,
|
|
177
|
+
fetchLegacyGasPriceEstimatesUrl: this.legacyAPIEndpoint.replace('<chain_id>', `${decimalChainId}`),
|
|
178
|
+
fetchEthGasPriceEstimate: gas_util_1.fetchEthGasPriceEstimate,
|
|
179
|
+
calculateTimeEstimate: gas_util_1.calculateTimeEstimate,
|
|
180
|
+
clientId: this.clientId,
|
|
181
|
+
ethQuery: this.ethQuery,
|
|
182
|
+
});
|
|
183
|
+
if (shouldUpdateState) {
|
|
184
|
+
this.update((state) => {
|
|
185
|
+
state.gasFeeEstimates = gasFeeCalculations.gasFeeEstimates;
|
|
186
|
+
state.estimatedGasFeeTimeBounds =
|
|
187
|
+
gasFeeCalculations.estimatedGasFeeTimeBounds;
|
|
188
|
+
state.gasEstimateType = gasFeeCalculations.gasEstimateType;
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
return gasFeeCalculations;
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Remove the poll token, and stop polling if the set of poll tokens is empty.
|
|
196
|
+
*
|
|
197
|
+
* @param pollToken - The poll token to disconnect.
|
|
198
|
+
*/
|
|
199
|
+
disconnectPoller(pollToken) {
|
|
200
|
+
this.pollTokens.delete(pollToken);
|
|
201
|
+
if (this.pollTokens.size === 0) {
|
|
202
|
+
this.stopPolling();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
stopPolling() {
|
|
206
|
+
if (this.intervalId) {
|
|
207
|
+
clearInterval(this.intervalId);
|
|
208
|
+
}
|
|
209
|
+
this.pollTokens.clear();
|
|
210
|
+
this.resetState();
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Prepare to discard this controller.
|
|
214
|
+
*
|
|
215
|
+
* This stops any active polling.
|
|
216
|
+
*/
|
|
217
|
+
destroy() {
|
|
218
|
+
super.destroy();
|
|
219
|
+
this.stopPolling();
|
|
220
|
+
}
|
|
221
|
+
_poll() {
|
|
222
|
+
if (this.intervalId) {
|
|
223
|
+
clearInterval(this.intervalId);
|
|
224
|
+
}
|
|
225
|
+
this.intervalId = setInterval(() => __awaiter(this, void 0, void 0, function* () {
|
|
226
|
+
yield (0, controller_utils_1.safelyExecute)(() => this._fetchGasFeeEstimateData());
|
|
227
|
+
}), this.intervalDelay);
|
|
228
|
+
}
|
|
229
|
+
resetState() {
|
|
230
|
+
this.update(() => {
|
|
231
|
+
return defaultState;
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
getEIP1559Compatibility() {
|
|
235
|
+
var _a, _b;
|
|
236
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
237
|
+
const currentNetworkIsEIP1559Compatible = yield this.getCurrentNetworkEIP1559Compatibility();
|
|
238
|
+
const currentAccountIsEIP1559Compatible = (_b = (_a = this.getCurrentAccountEIP1559Compatibility) === null || _a === void 0 ? void 0 : _a.call(this)) !== null && _b !== void 0 ? _b : true;
|
|
239
|
+
return (currentNetworkIsEIP1559Compatible && currentAccountIsEIP1559Compatible);
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
getTimeEstimate(maxPriorityFeePerGas, maxFeePerGas) {
|
|
243
|
+
if (!this.state.gasFeeEstimates ||
|
|
244
|
+
this.state.gasEstimateType !== exports.GAS_ESTIMATE_TYPES.FEE_MARKET) {
|
|
245
|
+
return {};
|
|
246
|
+
}
|
|
247
|
+
return (0, gas_util_1.calculateTimeEstimate)(maxPriorityFeePerGas, maxFeePerGas, this.state.gasFeeEstimates);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
exports.GasFeeController = GasFeeController;
|
|
251
|
+
_GasFeeController_getProvider = new WeakMap(), _GasFeeController_instances = new WeakSet(), _GasFeeController_onNetworkControllerStateChange = function _GasFeeController_onNetworkControllerStateChange(networkControllerState) {
|
|
252
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
253
|
+
const newChainId = networkControllerState.providerConfig.chainId;
|
|
254
|
+
if (newChainId !== this.currentChainId) {
|
|
255
|
+
this.ethQuery = new eth_query_1.default(__classPrivateFieldGet(this, _GasFeeController_getProvider, "f").call(this));
|
|
256
|
+
yield this.resetPolling();
|
|
257
|
+
this.currentChainId = newChainId;
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
};
|
|
261
|
+
exports.default = GasFeeController;
|
|
262
|
+
//# sourceMappingURL=GasFeeController.js.map
|