@metamask/transaction-controller 28.1.0 → 29.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +39 -1
- package/dist/TransactionController.js +12 -11
- package/dist/TransactionController.mjs +11 -10
- package/dist/{chunk-LDXTSESK.mjs → chunk-4M7FHI4S.mjs} +20 -4
- package/dist/chunk-4M7FHI4S.mjs.map +1 -0
- package/dist/{chunk-FK7AP6SH.js → chunk-5C3CSQAD.js} +12 -5
- package/dist/{chunk-YEJJKWT2.mjs.map → chunk-5C3CSQAD.js.map} +1 -1
- package/dist/{chunk-V6UIRCOF.js → chunk-7DJO6UZA.js} +48 -13
- package/dist/chunk-7DJO6UZA.js.map +1 -0
- package/dist/{chunk-MG7HTD3H.mjs → chunk-7TPXSDXL.mjs} +121 -35
- package/dist/chunk-7TPXSDXL.mjs.map +1 -0
- package/dist/{chunk-TWND5SFD.mjs → chunk-AGJNOOBN.mjs} +17 -12
- package/dist/chunk-AGJNOOBN.mjs.map +1 -0
- package/dist/{chunk-LNX4JTOL.js → chunk-DUFOYA4D.js} +7 -7
- package/dist/chunk-DUFOYA4D.js.map +1 -0
- package/dist/{chunk-UH7FNVKS.js → chunk-EMDU4XLM.js} +19 -14
- package/dist/chunk-EMDU4XLM.js.map +1 -0
- package/dist/chunk-FMRLPVFZ.mjs +66 -0
- package/dist/chunk-FMRLPVFZ.mjs.map +1 -0
- package/dist/{chunk-EQNKFFTM.js → chunk-KNYSD4JP.js} +21 -5
- package/dist/chunk-KNYSD4JP.js.map +1 -0
- package/dist/{chunk-IZVRGO3P.mjs → chunk-MDRMMUMS.mjs} +32 -18
- package/dist/chunk-MDRMMUMS.mjs.map +1 -0
- package/dist/{chunk-DMMUAJKY.js → chunk-N55SEKK7.js} +125 -39
- package/dist/chunk-N55SEKK7.js.map +1 -0
- package/dist/{chunk-YEJJKWT2.mjs → chunk-N6JXPWLY.mjs} +11 -4
- package/dist/chunk-N6JXPWLY.mjs.map +1 -0
- package/dist/chunk-REOG6YD4.mjs +112 -0
- package/dist/chunk-REOG6YD4.mjs.map +1 -0
- package/dist/{chunk-HHK4QSNF.mjs → chunk-SL3GHHKG.mjs} +47 -12
- package/dist/chunk-SL3GHHKG.mjs.map +1 -0
- package/dist/chunk-TJMQEH57.js +66 -0
- package/dist/chunk-TJMQEH57.js.map +1 -0
- package/dist/chunk-VJYFB7BM.js +112 -0
- package/dist/chunk-VJYFB7BM.js.map +1 -0
- package/dist/{chunk-JAYYMCBQ.js → chunk-X3KACH5P.js} +32 -18
- package/dist/chunk-X3KACH5P.js.map +1 -0
- package/dist/{chunk-NCRWKI6Y.mjs → chunk-XL3HBKDE.mjs} +4 -4
- package/dist/chunk-XL3HBKDE.mjs.map +1 -0
- package/dist/errors.js +1 -1
- package/dist/errors.mjs +1 -1
- package/dist/gas-flows/DefaultGasFeeFlow.js +5 -5
- package/dist/gas-flows/DefaultGasFeeFlow.mjs +4 -4
- package/dist/gas-flows/LineaGasFeeFlow.js +6 -6
- package/dist/gas-flows/LineaGasFeeFlow.mjs +5 -5
- package/dist/gas-flows/TestGasFeeFlow.js +9 -0
- package/dist/gas-flows/TestGasFeeFlow.js.map +1 -0
- package/dist/gas-flows/TestGasFeeFlow.mjs +9 -0
- package/dist/gas-flows/TestGasFeeFlow.mjs.map +1 -0
- package/dist/helpers/EtherscanRemoteTransactionSource.js +1 -1
- package/dist/helpers/EtherscanRemoteTransactionSource.mjs +1 -1
- package/dist/helpers/GasFeePoller.js +4 -4
- package/dist/helpers/GasFeePoller.mjs +3 -3
- package/dist/helpers/MultichainTrackingHelper.js +1 -1
- package/dist/helpers/MultichainTrackingHelper.mjs +1 -1
- package/dist/helpers/PendingTransactionTracker.js +1 -1
- package/dist/helpers/PendingTransactionTracker.mjs +1 -1
- package/dist/index.js +16 -11
- package/dist/index.mjs +15 -10
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/TransactionController.d.ts +12 -5
- package/dist/types/TransactionController.d.ts.map +1 -1
- package/dist/types/gas-flows/DefaultGasFeeFlow.d.ts.map +1 -1
- package/dist/types/gas-flows/TestGasFeeFlow.d.ts +12 -0
- package/dist/types/gas-flows/TestGasFeeFlow.d.ts.map +1 -0
- package/dist/types/helpers/GasFeePoller.d.ts +5 -3
- package/dist/types/helpers/GasFeePoller.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types.d.ts +36 -18
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/gas-flow.d.ts +8 -14
- package/dist/types/utils/gas-flow.d.ts.map +1 -1
- package/dist/types/utils/simulation.d.ts +18 -0
- package/dist/types/utils/simulation.d.ts.map +1 -1
- package/dist/types.js +4 -2
- package/dist/types.mjs +3 -1
- package/dist/utils/external-transactions.js +1 -1
- package/dist/utils/external-transactions.mjs +1 -1
- package/dist/utils/gas-fees.js +4 -4
- package/dist/utils/gas-fees.mjs +3 -3
- package/dist/utils/gas-flow.js +3 -3
- package/dist/utils/gas-flow.mjs +2 -2
- package/dist/utils/simulation-api.js +1 -1
- package/dist/utils/simulation-api.mjs +1 -1
- package/dist/utils/simulation.js +5 -3
- package/dist/utils/simulation.mjs +4 -2
- package/dist/utils/swaps.js +1 -1
- package/dist/utils/swaps.mjs +1 -1
- package/dist/utils/transaction-type.js +1 -1
- package/dist/utils/transaction-type.mjs +1 -1
- package/dist/utils/utils.js +1 -1
- package/dist/utils/utils.mjs +1 -1
- package/dist/utils/validation.js +1 -1
- package/dist/utils/validation.mjs +1 -1
- package/package.json +4 -4
- package/dist/chunk-4RJXBKSR.js +0 -90
- package/dist/chunk-4RJXBKSR.js.map +0 -1
- package/dist/chunk-DMMUAJKY.js.map +0 -1
- package/dist/chunk-EQNKFFTM.js.map +0 -1
- package/dist/chunk-FK7AP6SH.js.map +0 -1
- package/dist/chunk-HHK4QSNF.mjs.map +0 -1
- package/dist/chunk-IZVRGO3P.mjs.map +0 -1
- package/dist/chunk-JAYYMCBQ.js.map +0 -1
- package/dist/chunk-LDXTSESK.mjs.map +0 -1
- package/dist/chunk-LNX4JTOL.js.map +0 -1
- package/dist/chunk-MG7HTD3H.mjs.map +0 -1
- package/dist/chunk-NCRWKI6Y.mjs.map +0 -1
- package/dist/chunk-NPEXNXSY.mjs +0 -90
- package/dist/chunk-NPEXNXSY.mjs.map +0 -1
- package/dist/chunk-TWND5SFD.mjs.map +0 -1
- package/dist/chunk-UH7FNVKS.js.map +0 -1
- package/dist/chunk-V6UIRCOF.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,42 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [29.0.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Add `estimateGasFee` method ([#4216](https://github.com/MetaMask/core/pull/4216))
|
|
15
|
+
- Add `TestGasFeeFlow` that is activated by optional `testGasFeeFlows` constructor option.
|
|
16
|
+
- Add related types:
|
|
17
|
+
- `FeeMarketGasFeeEstimateForLevel`
|
|
18
|
+
- `FeeMarketGasFeeEstimates`
|
|
19
|
+
- `GasFeeEstimates`
|
|
20
|
+
- `GasFeeEstimateLevel`
|
|
21
|
+
- `GasFeeEstimateType`
|
|
22
|
+
- `GasPriceGasFeeEstimates`
|
|
23
|
+
- `LegacyGasFeeEstimates`
|
|
24
|
+
|
|
25
|
+
### Changed
|
|
26
|
+
|
|
27
|
+
- **BREAKING:** Update `GasFeeEstimates` type to support alternate estimate types ([#4216](https://github.com/MetaMask/core/pull/4216))
|
|
28
|
+
- Bump `@metamask/base-controller` to `^5.0.2` ([#4232](https://github.com/MetaMask/core/pull/4232))
|
|
29
|
+
- Bump `@metamask/approval-controller` to `^6.0.2` ([#4234](https://github.com/MetaMask/core/pull/4234))
|
|
30
|
+
- Bump `@metamask/gas-fee-controller` to `^15.1.1` ([#4234](https://github.com/MetaMask/core/pull/4234))
|
|
31
|
+
|
|
32
|
+
### Removed
|
|
33
|
+
|
|
34
|
+
- **BREAKING:** Remove `gasFeeControllerEstimateType` property from `mergeGasFeeEstimates` function ([#4216](https://github.com/MetaMask/core/pull/4216))
|
|
35
|
+
|
|
36
|
+
## [28.1.1]
|
|
37
|
+
|
|
38
|
+
### Changed
|
|
39
|
+
|
|
40
|
+
- Bump `@metamask/gas-fee-controller` to ^15.1.0 ([#4220](https://github.com/MetaMask/core/pull/4220))
|
|
41
|
+
|
|
42
|
+
### Fixed
|
|
43
|
+
|
|
44
|
+
- Fixed simulating minting NFTs where the nft owner was checked before minting, causing a revert. ([#4217](https://github.com/MetaMask/core/pull/4217))
|
|
45
|
+
|
|
10
46
|
## [28.1.0]
|
|
11
47
|
|
|
12
48
|
### Added
|
|
@@ -780,7 +816,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
780
816
|
|
|
781
817
|
All changes listed after this point were applied to this package following the monorepo conversion.
|
|
782
818
|
|
|
783
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@
|
|
819
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@29.0.0...HEAD
|
|
820
|
+
[29.0.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@28.1.1...@metamask/transaction-controller@29.0.0
|
|
821
|
+
[28.1.1]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@28.1.0...@metamask/transaction-controller@28.1.1
|
|
784
822
|
[28.1.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@28.0.0...@metamask/transaction-controller@28.1.0
|
|
785
823
|
[28.0.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@27.0.1...@metamask/transaction-controller@28.0.0
|
|
786
824
|
[27.0.1]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@27.0.0...@metamask/transaction-controller@27.0.1
|
|
@@ -4,35 +4,36 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
8
|
-
require('./chunk-
|
|
7
|
+
var _chunkN55SEKK7js = require('./chunk-N55SEKK7.js');
|
|
8
|
+
require('./chunk-ZNZEJDOE.js');
|
|
9
|
+
require('./chunk-X3KACH5P.js');
|
|
9
10
|
require('./chunk-KT6UAKBB.js');
|
|
10
11
|
require('./chunk-SD6CWFDF.js');
|
|
11
12
|
require('./chunk-VH47Q6TS.js');
|
|
13
|
+
require('./chunk-5KMU2IAT.js');
|
|
12
14
|
require('./chunk-7LXE4KHV.js');
|
|
13
15
|
require('./chunk-V72C4MCR.js');
|
|
14
16
|
require('./chunk-QP75SWIQ.js');
|
|
15
|
-
require('./chunk-ZNZEJDOE.js');
|
|
16
17
|
require('./chunk-NYKRCWBG.js');
|
|
17
18
|
require('./chunk-WR5F34OW.js');
|
|
18
19
|
require('./chunk-YVCX6Z75.js');
|
|
19
|
-
require('./chunk-
|
|
20
|
+
require('./chunk-TJMQEH57.js');
|
|
21
|
+
require('./chunk-7DJO6UZA.js');
|
|
20
22
|
require('./chunk-2XKEAKQG.js');
|
|
21
23
|
require('./chunk-DTDTOMTB.js');
|
|
22
24
|
require('./chunk-5XQ2KRYL.js');
|
|
23
25
|
require('./chunk-EQT25RSP.js');
|
|
24
26
|
require('./chunk-FDUCRHYT.js');
|
|
25
|
-
require('./chunk-5KMU2IAT.js');
|
|
26
27
|
require('./chunk-HMOSP33F.js');
|
|
27
|
-
require('./chunk-
|
|
28
|
-
require('./chunk-
|
|
29
|
-
require('./chunk-
|
|
28
|
+
require('./chunk-DUFOYA4D.js');
|
|
29
|
+
require('./chunk-VJYFB7BM.js');
|
|
30
|
+
require('./chunk-KNYSD4JP.js');
|
|
30
31
|
require('./chunk-C2LNDHP4.js');
|
|
31
32
|
require('./chunk-UGFBA4GV.js');
|
|
32
|
-
require('./chunk-
|
|
33
|
+
require('./chunk-EMDU4XLM.js');
|
|
33
34
|
require('./chunk-UGN7PBON.js');
|
|
34
35
|
require('./chunk-S6VGOPUY.js');
|
|
35
|
-
require('./chunk-
|
|
36
|
+
require('./chunk-5C3CSQAD.js');
|
|
36
37
|
require('./chunk-Z4BLTVTB.js');
|
|
37
38
|
|
|
38
39
|
|
|
@@ -40,5 +41,5 @@ require('./chunk-Z4BLTVTB.js');
|
|
|
40
41
|
|
|
41
42
|
|
|
42
43
|
|
|
43
|
-
exports.ApprovalState =
|
|
44
|
+
exports.ApprovalState = _chunkN55SEKK7js.ApprovalState; exports.CANCEL_RATE = _chunkN55SEKK7js.CANCEL_RATE; exports.HARDFORK = _chunkN55SEKK7js.HARDFORK; exports.SPEED_UP_RATE = _chunkN55SEKK7js.SPEED_UP_RATE; exports.TransactionController = _chunkN55SEKK7js.TransactionController;
|
|
44
45
|
//# sourceMappingURL=TransactionController.js.map
|
|
@@ -4,35 +4,36 @@ import {
|
|
|
4
4
|
HARDFORK,
|
|
5
5
|
SPEED_UP_RATE,
|
|
6
6
|
TransactionController
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-7TPXSDXL.mjs";
|
|
8
|
+
import "./chunk-NHRBO3LU.mjs";
|
|
9
|
+
import "./chunk-MDRMMUMS.mjs";
|
|
9
10
|
import "./chunk-K4KOSAGM.mjs";
|
|
10
11
|
import "./chunk-KG4UW4K4.mjs";
|
|
11
12
|
import "./chunk-NM6OYEPP.mjs";
|
|
13
|
+
import "./chunk-5YES3V2R.mjs";
|
|
12
14
|
import "./chunk-FRKQ3Z2L.mjs";
|
|
13
15
|
import "./chunk-5G6OHAXI.mjs";
|
|
14
16
|
import "./chunk-XGRAHX6T.mjs";
|
|
15
|
-
import "./chunk-NHRBO3LU.mjs";
|
|
16
17
|
import "./chunk-VEVVBHP3.mjs";
|
|
17
18
|
import "./chunk-Z4GV3YQQ.mjs";
|
|
18
19
|
import "./chunk-FG74Z3F5.mjs";
|
|
19
|
-
import "./chunk-
|
|
20
|
+
import "./chunk-FMRLPVFZ.mjs";
|
|
21
|
+
import "./chunk-SL3GHHKG.mjs";
|
|
20
22
|
import "./chunk-NOHEXQ7Y.mjs";
|
|
21
23
|
import "./chunk-Y7ENNK7L.mjs";
|
|
22
24
|
import "./chunk-F6E3TTR3.mjs";
|
|
23
25
|
import "./chunk-CPMTUMMZ.mjs";
|
|
24
26
|
import "./chunk-QZLPYOGC.mjs";
|
|
25
|
-
import "./chunk-5YES3V2R.mjs";
|
|
26
27
|
import "./chunk-HQSNKCXI.mjs";
|
|
27
|
-
import "./chunk-
|
|
28
|
-
import "./chunk-
|
|
29
|
-
import "./chunk-
|
|
28
|
+
import "./chunk-XL3HBKDE.mjs";
|
|
29
|
+
import "./chunk-REOG6YD4.mjs";
|
|
30
|
+
import "./chunk-4M7FHI4S.mjs";
|
|
30
31
|
import "./chunk-ZGUNOEUQ.mjs";
|
|
31
32
|
import "./chunk-J56A7UCK.mjs";
|
|
32
|
-
import "./chunk-
|
|
33
|
+
import "./chunk-AGJNOOBN.mjs";
|
|
33
34
|
import "./chunk-O6ZZVIFH.mjs";
|
|
34
35
|
import "./chunk-UQQWZT6C.mjs";
|
|
35
|
-
import "./chunk-
|
|
36
|
+
import "./chunk-N6JXPWLY.mjs";
|
|
36
37
|
import "./chunk-XUI43LEZ.mjs";
|
|
37
38
|
export {
|
|
38
39
|
ApprovalState,
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-ZGUNOEUQ.mjs";
|
|
4
4
|
import {
|
|
5
5
|
getGasFeeFlow
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-AGJNOOBN.mjs";
|
|
7
7
|
import {
|
|
8
8
|
projectLogger
|
|
9
9
|
} from "./chunk-UQQWZT6C.mjs";
|
|
@@ -182,17 +182,33 @@ function updateDefaultGasEstimates(txMeta) {
|
|
|
182
182
|
}
|
|
183
183
|
async function getSuggestedGasFees(request) {
|
|
184
184
|
const { eip1559, ethQuery, gasFeeFlows, getGasFeeEstimates, txMeta } = request;
|
|
185
|
+
const { networkClientId } = txMeta;
|
|
185
186
|
if (!eip1559 && txMeta.txParams.gasPrice || eip1559 && txMeta.txParams.maxFeePerGas && txMeta.txParams.maxPriorityFeePerGas) {
|
|
186
187
|
return {};
|
|
187
188
|
}
|
|
188
189
|
const gasFeeFlow = getGasFeeFlow(txMeta, gasFeeFlows);
|
|
189
190
|
try {
|
|
191
|
+
const gasFeeControllerData = await getGasFeeEstimates({ networkClientId });
|
|
190
192
|
const response = await gasFeeFlow.getGasFees({
|
|
191
193
|
ethQuery,
|
|
192
|
-
|
|
194
|
+
gasFeeControllerData,
|
|
193
195
|
transactionMeta: txMeta
|
|
194
196
|
});
|
|
195
|
-
|
|
197
|
+
const gasFeeEstimateType = response.estimates?.type;
|
|
198
|
+
switch (gasFeeEstimateType) {
|
|
199
|
+
case "fee-market" /* FeeMarket */:
|
|
200
|
+
return response.estimates.medium;
|
|
201
|
+
case "legacy" /* Legacy */:
|
|
202
|
+
return {
|
|
203
|
+
gasPrice: response.estimates.medium
|
|
204
|
+
};
|
|
205
|
+
case "eth_gasPrice" /* GasPrice */:
|
|
206
|
+
return { gasPrice: response.estimates.gasPrice };
|
|
207
|
+
default:
|
|
208
|
+
throw new Error(
|
|
209
|
+
`Unsupported gas fee estimate type returned from flow: ${gasFeeEstimateType}`
|
|
210
|
+
);
|
|
211
|
+
}
|
|
196
212
|
} catch (error) {
|
|
197
213
|
log("Failed to get suggested gas fees", error);
|
|
198
214
|
}
|
|
@@ -205,4 +221,4 @@ export {
|
|
|
205
221
|
updateGasFees,
|
|
206
222
|
gweiDecimalToWeiHex
|
|
207
223
|
};
|
|
208
|
-
//# sourceMappingURL=chunk-
|
|
224
|
+
//# sourceMappingURL=chunk-4M7FHI4S.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/gas-fees.ts"],"sourcesContent":["/* eslint-disable jsdoc/require-jsdoc */\n\nimport {\n ORIGIN_METAMASK,\n gweiDecToWEIBN,\n query,\n toHex,\n} from '@metamask/controller-utils';\nimport type EthQuery from '@metamask/eth-query';\nimport type {\n FetchGasFeeEstimateOptions,\n GasFeeState,\n} from '@metamask/gas-fee-controller';\nimport type { Hex } from '@metamask/utils';\nimport { add0x, createModuleLogger } from '@metamask/utils';\n\nimport { projectLogger } from '../logger';\nimport type {\n SavedGasFees,\n TransactionParams,\n TransactionMeta,\n TransactionType,\n GasFeeFlow,\n} from '../types';\nimport { GasFeeEstimateType, UserFeeLevel } from '../types';\nimport { getGasFeeFlow } from './gas-flow';\nimport { SWAP_TRANSACTION_TYPES } from './swaps';\n\nexport type UpdateGasFeesRequest = {\n eip1559: boolean;\n ethQuery: EthQuery;\n gasFeeFlows: GasFeeFlow[];\n getGasFeeEstimates: (\n options: FetchGasFeeEstimateOptions,\n ) => Promise<GasFeeState>;\n getSavedGasFees: (chainId: Hex) => SavedGasFees | undefined;\n txMeta: TransactionMeta;\n};\n\nexport type GetGasFeeRequest = UpdateGasFeesRequest & {\n initialParams: TransactionParams;\n savedGasFees?: SavedGasFees;\n suggestedGasFees: SuggestedGasFees;\n};\n\ntype SuggestedGasFees = {\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n gasPrice?: string;\n};\n\nconst log = createModuleLogger(projectLogger, 'gas-fees');\n\nexport async function updateGasFees(request: UpdateGasFeesRequest) {\n const { txMeta } = request;\n const initialParams = { ...txMeta.txParams };\n\n const isSwap = SWAP_TRANSACTION_TYPES.includes(\n txMeta.type as TransactionType,\n );\n const savedGasFees = isSwap\n ? undefined\n : request.getSavedGasFees(txMeta.chainId);\n\n const suggestedGasFees = await getSuggestedGasFees(request);\n\n log('Suggested gas fees', suggestedGasFees);\n\n const getGasFeeRequest: GetGasFeeRequest = {\n ...request,\n initialParams,\n savedGasFees,\n suggestedGasFees,\n };\n\n txMeta.txParams.maxFeePerGas = getMaxFeePerGas(getGasFeeRequest);\n\n txMeta.txParams.maxPriorityFeePerGas =\n getMaxPriorityFeePerGas(getGasFeeRequest);\n\n txMeta.txParams.gasPrice = getGasPrice(getGasFeeRequest);\n txMeta.userFeeLevel = getUserFeeLevel(getGasFeeRequest);\n\n log('Updated gas fee properties', {\n maxFeePerGas: txMeta.txParams.maxFeePerGas,\n maxPriorityFeePerGas: txMeta.txParams.maxPriorityFeePerGas,\n gasPrice: txMeta.txParams.gasPrice,\n });\n\n if (txMeta.txParams.maxFeePerGas || txMeta.txParams.maxPriorityFeePerGas) {\n delete txMeta.txParams.gasPrice;\n }\n\n if (txMeta.txParams.gasPrice) {\n delete txMeta.txParams.maxFeePerGas;\n delete txMeta.txParams.maxPriorityFeePerGas;\n }\n\n updateDefaultGasEstimates(txMeta);\n}\n\nexport function gweiDecimalToWeiHex(value: string) {\n return toHex(gweiDecToWEIBN(value));\n}\n\nfunction getMaxFeePerGas(request: GetGasFeeRequest): string | undefined {\n const { savedGasFees, eip1559, initialParams, suggestedGasFees } = request;\n\n if (!eip1559) {\n return undefined;\n }\n\n if (savedGasFees) {\n const maxFeePerGas = gweiDecimalToWeiHex(savedGasFees.maxBaseFee as string);\n log('Using maxFeePerGas from savedGasFees', maxFeePerGas);\n return maxFeePerGas;\n }\n\n if (initialParams.maxFeePerGas) {\n log('Using maxFeePerGas from request', initialParams.maxFeePerGas);\n return initialParams.maxFeePerGas;\n }\n\n if (initialParams.gasPrice && !initialParams.maxPriorityFeePerGas) {\n log(\n 'Setting maxFeePerGas to gasPrice from request',\n initialParams.gasPrice,\n );\n return initialParams.gasPrice;\n }\n\n if (suggestedGasFees.maxFeePerGas) {\n log('Using suggested maxFeePerGas', suggestedGasFees.maxFeePerGas);\n return suggestedGasFees.maxFeePerGas;\n }\n\n if (suggestedGasFees.gasPrice) {\n log(\n 'Setting maxFeePerGas to suggested gasPrice',\n suggestedGasFees.gasPrice,\n );\n return suggestedGasFees.gasPrice;\n }\n\n log('maxFeePerGas not set');\n return undefined;\n}\n\nfunction getMaxPriorityFeePerGas(\n request: GetGasFeeRequest,\n): string | undefined {\n const { eip1559, initialParams, savedGasFees, suggestedGasFees, txMeta } =\n request;\n\n if (!eip1559) {\n return undefined;\n }\n\n if (savedGasFees) {\n const maxPriorityFeePerGas = gweiDecimalToWeiHex(savedGasFees.priorityFee);\n log(\n 'Using maxPriorityFeePerGas from savedGasFees.priorityFee',\n maxPriorityFeePerGas,\n );\n return maxPriorityFeePerGas;\n }\n\n if (initialParams.maxPriorityFeePerGas) {\n log(\n 'Using maxPriorityFeePerGas from request',\n initialParams.maxPriorityFeePerGas,\n );\n return initialParams.maxPriorityFeePerGas;\n }\n\n if (initialParams.gasPrice && !initialParams.maxFeePerGas) {\n log(\n 'Setting maxPriorityFeePerGas to gasPrice from request',\n initialParams.gasPrice,\n );\n return initialParams.gasPrice;\n }\n\n if (suggestedGasFees.maxPriorityFeePerGas) {\n log(\n 'Using suggested maxPriorityFeePerGas',\n suggestedGasFees.maxPriorityFeePerGas,\n );\n return suggestedGasFees.maxPriorityFeePerGas;\n }\n\n if (txMeta.txParams.maxFeePerGas) {\n log(\n 'Setting maxPriorityFeePerGas to maxFeePerGas',\n txMeta.txParams.maxFeePerGas,\n );\n return txMeta.txParams.maxFeePerGas;\n }\n\n log('maxPriorityFeePerGas not set');\n return undefined;\n}\n\nfunction getGasPrice(request: GetGasFeeRequest): string | undefined {\n const { eip1559, initialParams, suggestedGasFees } = request;\n\n if (eip1559) {\n return undefined;\n }\n\n if (initialParams.gasPrice) {\n log('Using gasPrice from request', initialParams.gasPrice);\n return initialParams.gasPrice;\n }\n\n if (suggestedGasFees.maxFeePerGas) {\n log('Using suggested maxFeePerGas', suggestedGasFees.maxFeePerGas);\n return suggestedGasFees.maxFeePerGas;\n }\n\n if (suggestedGasFees.gasPrice) {\n log('Using suggested gasPrice', suggestedGasFees.gasPrice);\n return suggestedGasFees.gasPrice;\n }\n\n log('gasPrice not set');\n return undefined;\n}\n\nfunction getUserFeeLevel(request: GetGasFeeRequest): UserFeeLevel | undefined {\n const { eip1559, initialParams, savedGasFees, suggestedGasFees, txMeta } =\n request;\n\n if (!eip1559) {\n return undefined;\n }\n\n if (savedGasFees) {\n return UserFeeLevel.CUSTOM;\n }\n\n if (\n !initialParams.maxFeePerGas &&\n !initialParams.maxPriorityFeePerGas &&\n initialParams.gasPrice\n ) {\n return txMeta.origin === ORIGIN_METAMASK\n ? UserFeeLevel.CUSTOM\n : UserFeeLevel.DAPP_SUGGESTED;\n }\n\n if (\n !initialParams.maxFeePerGas &&\n !initialParams.maxPriorityFeePerGas &&\n suggestedGasFees.maxFeePerGas &&\n suggestedGasFees.maxPriorityFeePerGas\n ) {\n return UserFeeLevel.MEDIUM;\n }\n\n if (txMeta.origin === ORIGIN_METAMASK) {\n return UserFeeLevel.MEDIUM;\n }\n\n return UserFeeLevel.DAPP_SUGGESTED;\n}\n\nfunction updateDefaultGasEstimates(txMeta: TransactionMeta) {\n if (!txMeta.defaultGasEstimates) {\n txMeta.defaultGasEstimates = {};\n }\n\n txMeta.defaultGasEstimates.maxFeePerGas = txMeta.txParams.maxFeePerGas;\n\n txMeta.defaultGasEstimates.maxPriorityFeePerGas =\n txMeta.txParams.maxPriorityFeePerGas;\n\n txMeta.defaultGasEstimates.gasPrice = txMeta.txParams.gasPrice;\n txMeta.defaultGasEstimates.estimateType = txMeta.userFeeLevel;\n}\n\nasync function getSuggestedGasFees(\n request: UpdateGasFeesRequest,\n): Promise<SuggestedGasFees> {\n const { eip1559, ethQuery, gasFeeFlows, getGasFeeEstimates, txMeta } =\n request;\n\n const { networkClientId } = txMeta;\n\n if (\n (!eip1559 && txMeta.txParams.gasPrice) ||\n (eip1559 &&\n txMeta.txParams.maxFeePerGas &&\n txMeta.txParams.maxPriorityFeePerGas)\n ) {\n return {};\n }\n\n const gasFeeFlow = getGasFeeFlow(txMeta, gasFeeFlows) as GasFeeFlow;\n\n try {\n const gasFeeControllerData = await getGasFeeEstimates({ networkClientId });\n\n const response = await gasFeeFlow.getGasFees({\n ethQuery,\n gasFeeControllerData,\n transactionMeta: txMeta,\n });\n\n const gasFeeEstimateType = response.estimates?.type;\n\n switch (gasFeeEstimateType) {\n case GasFeeEstimateType.FeeMarket:\n return response.estimates.medium;\n case GasFeeEstimateType.Legacy:\n return {\n gasPrice: response.estimates.medium,\n };\n case GasFeeEstimateType.GasPrice:\n return { gasPrice: response.estimates.gasPrice };\n default:\n throw new Error(\n `Unsupported gas fee estimate type returned from flow: ${gasFeeEstimateType}`,\n );\n }\n } catch (error) {\n log('Failed to get suggested gas fees', error);\n }\n\n const gasPriceDecimal = (await query(ethQuery, 'gasPrice')) as number;\n\n const gasPrice = gasPriceDecimal\n ? add0x(gasPriceDecimal.toString(16))\n : undefined;\n\n return { gasPrice };\n}\n"],"mappings":";;;;;;;;;;;AAEA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAOP,SAAS,OAAO,0BAA0B;AAqC1C,IAAM,MAAM,mBAAmB,eAAe,UAAU;AAExD,eAAsB,cAAc,SAA+B;AACjE,QAAM,EAAE,OAAO,IAAI;AACnB,QAAM,gBAAgB,EAAE,GAAG,OAAO,SAAS;AAE3C,QAAM,SAAS,uBAAuB;AAAA,IACpC,OAAO;AAAA,EACT;AACA,QAAM,eAAe,SACjB,SACA,QAAQ,gBAAgB,OAAO,OAAO;AAE1C,QAAM,mBAAmB,MAAM,oBAAoB,OAAO;AAE1D,MAAI,sBAAsB,gBAAgB;AAE1C,QAAM,mBAAqC;AAAA,IACzC,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,SAAO,SAAS,eAAe,gBAAgB,gBAAgB;AAE/D,SAAO,SAAS,uBACd,wBAAwB,gBAAgB;AAE1C,SAAO,SAAS,WAAW,YAAY,gBAAgB;AACvD,SAAO,eAAe,gBAAgB,gBAAgB;AAEtD,MAAI,8BAA8B;AAAA,IAChC,cAAc,OAAO,SAAS;AAAA,IAC9B,sBAAsB,OAAO,SAAS;AAAA,IACtC,UAAU,OAAO,SAAS;AAAA,EAC5B,CA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EAAE,SAAS;AACpB;","names":[]}
|
|
@@ -53,11 +53,17 @@ var UserFeeLevel = /* @__PURE__ */ ((UserFeeLevel2) => {
|
|
|
53
53
|
return UserFeeLevel2;
|
|
54
54
|
})(UserFeeLevel || {});
|
|
55
55
|
var GasFeeEstimateLevel = /* @__PURE__ */ ((GasFeeEstimateLevel2) => {
|
|
56
|
-
GasFeeEstimateLevel2["
|
|
57
|
-
GasFeeEstimateLevel2["
|
|
58
|
-
GasFeeEstimateLevel2["
|
|
56
|
+
GasFeeEstimateLevel2["Low"] = "low";
|
|
57
|
+
GasFeeEstimateLevel2["Medium"] = "medium";
|
|
58
|
+
GasFeeEstimateLevel2["High"] = "high";
|
|
59
59
|
return GasFeeEstimateLevel2;
|
|
60
60
|
})(GasFeeEstimateLevel || {});
|
|
61
|
+
var GasFeeEstimateType = /* @__PURE__ */ ((GasFeeEstimateType2) => {
|
|
62
|
+
GasFeeEstimateType2["FeeMarket"] = "fee-market";
|
|
63
|
+
GasFeeEstimateType2["Legacy"] = "legacy";
|
|
64
|
+
GasFeeEstimateType2["GasPrice"] = "eth_gasPrice";
|
|
65
|
+
return GasFeeEstimateType2;
|
|
66
|
+
})(GasFeeEstimateType || {});
|
|
61
67
|
var SimulationTokenStandard = /* @__PURE__ */ ((SimulationTokenStandard2) => {
|
|
62
68
|
SimulationTokenStandard2["erc20"] = "erc20";
|
|
63
69
|
SimulationTokenStandard2["erc721"] = "erc721";
|
|
@@ -81,5 +87,6 @@ var SimulationErrorCode = /* @__PURE__ */ ((SimulationErrorCode2) => {
|
|
|
81
87
|
|
|
82
88
|
|
|
83
89
|
|
|
84
|
-
|
|
85
|
-
|
|
90
|
+
|
|
91
|
+
exports.TransactionStatus = TransactionStatus; exports.WalletDevice = WalletDevice; exports.TransactionType = TransactionType; exports.TransactionEnvelopeType = TransactionEnvelopeType; exports.UserFeeLevel = UserFeeLevel; exports.GasFeeEstimateLevel = GasFeeEstimateLevel; exports.GasFeeEstimateType = GasFeeEstimateType; exports.SimulationTokenStandard = SimulationTokenStandard; exports.SimulationErrorCode = SimulationErrorCode;
|
|
92
|
+
//# sourceMappingURL=chunk-5C3CSQAD.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { AccessList } from '@ethereumjs/tx';\nimport type EthQuery from '@metamask/eth-query';\nimport type {\n FetchGasFeeEstimateOptions,\n GasFeeState,\n} from '@metamask/gas-fee-controller';\nimport type { NetworkClientId, Provider } from '@metamask/network-controller';\nimport type { Hex, Json } from '@metamask/utils';\nimport type { Operation } from 'fast-json-patch';\n\n/**\n * Given a record, ensures that each property matches the `Json` type.\n */\ntype MakeJsonCompatible<T> = T extends Json\n ? T\n : {\n [K in keyof T]: T[K] extends Json ? T[K] : never;\n };\n\n/**\n * `Json` from `@metamask/utils` is defined as a recursive type alias, but\n * `Operation` is defined as an interface, and the two are not compatible with\n * each other. Therefore, this is a variant of Operation from `fast-json-patch`\n * which is guaranteed to be type-compatible with `Json`.\n */\ntype JsonCompatibleOperation = MakeJsonCompatible<Operation>;\n\n/**\n * Representation of transaction metadata.\n */\nexport type TransactionMeta = TransactionMetaBase &\n (\n | {\n status: Exclude<TransactionStatus, TransactionStatus.failed>;\n }\n | {\n status: TransactionStatus.failed;\n error: TransactionError;\n }\n );\n\n/**\n * Information about a single transaction such as status and block number.\n */\ntype TransactionMetaBase = {\n /**\n * ID of the transaction that approved the swap token transfer.\n */\n approvalTxId?: string;\n\n /**\n * Unique ID to prevent duplicate requests.\n */\n actionId?: string;\n\n /**\n * Base fee of the block as a hex value, introduced in EIP-1559.\n */\n baseFeePerGas?: Hex;\n\n /**\n * Number of the block where the transaction has been included.\n */\n blockNumber?: string;\n\n /**\n * The timestamp for when the block was collated.\n */\n blockTimestamp?: string;\n\n /**\n * Network code as per EIP-155 for this transaction.\n */\n chainId: Hex;\n\n /**\n * A string representing a name of transaction contract method.\n */\n contractMethodName?: string;\n\n /**\n * The balance of the token that is being sent.\n */\n currentTokenBalance?: string;\n\n /**\n * Unique ID for custodian transaction.\n */\n custodyId?: string;\n\n /**\n * Custodian transaction status.\n */\n custodyStatus?: string;\n\n /** The optional custom nonce override as a decimal string. */\n customNonceValue?: string;\n\n /**\n * The custom token amount is the amount set by the user.\n */\n customTokenAmount?: string;\n\n /**\n * The dapp proposed token amount.\n */\n dappProposedTokenAmount?: string;\n\n /**\n * Gas values provided by the dApp.\n */\n dappSuggestedGasFees?: DappSuggestedGasFees;\n\n /**\n * The initial gas values set when the transaction was first created.\n */\n defaultGasEstimates?: DefaultGasEstimates;\n\n /**\n * String to indicate what device the transaction was confirmed on.\n */\n deviceConfirmedOn?: WalletDevice;\n\n /**\n * The address of the token being received of swap transaction.\n */\n destinationTokenAddress?: string;\n\n /**\n * The decimals of the token being received of swap transaction.\n */\n destinationTokenDecimals?: number;\n\n /**\n * The symbol of the token being received with swap.\n */\n destinationTokenSymbol?: string;\n\n /**\n * The estimated base fee of the transaction.\n */\n estimatedBaseFee?: string;\n\n /**\n * Which estimate level that the API suggested.\n */\n estimateSuggested?: string;\n\n /**\n * Which estimate level was used\n */\n estimateUsed?: string;\n\n /**\n * The chosen amount which will be the same as the originally proposed token\n * amount if the user does not edit the amount or will be a custom token\n * amount set by the user.\n */\n finalApprovalAmount?: string;\n\n /**\n * The number of the latest block when the transaction submit was first retried.\n */\n firstRetryBlockNumber?: string;\n\n /** Alternate EIP-1559 gas fee estimates for multiple priority levels. */\n gasFeeEstimates?: GasFeeEstimates;\n\n /** Whether the gas fee estimates have been checked at least once. */\n gasFeeEstimatesLoaded?: boolean;\n\n /**\n * A hex string of the transaction hash, used to identify the transaction on the network.\n */\n hash?: string;\n\n /**\n * A history of mutations to TransactionMeta.\n */\n history?: TransactionHistory;\n\n /**\n * Generated UUID associated with this transaction.\n */\n id: string;\n\n /**\n * Whether the transaction is a transfer.\n */\n isTransfer?: boolean;\n\n /**\n * Whether the transaction entry is generated from a user operation.\n */\n isUserOperation?: boolean;\n\n /**\n * Additional gas fees to cover the cost of persisting data on layer 1 for layer 2 networks.\n */\n layer1GasFee?: Hex;\n\n /**\n * The ID of the network client used by the transaction.\n */\n networkClientId?: NetworkClientId;\n\n /**\n * Network code as per EIP-155 for this transaction\n *\n * @deprecated Use `chainId` instead.\n */\n readonly networkID?: string;\n\n /**\n * Origin this transaction was sent from.\n */\n origin?: string;\n\n /**\n * The original dapp proposed token approval amount before edit by user.\n */\n originalApprovalAmount?: string;\n\n /**\n * The original gas estimation of the transaction.\n */\n originalGasEstimate?: string;\n\n /**\n * When we speed up a transaction, we set the type as Retry and we lose\n * information about type of transaction that is being set up, so we use\n * original type to track that information.\n */\n originalType?: TransactionType;\n\n /**\n * Account transaction balance after swap.\n */\n postTxBalance?: string;\n\n /**\n * Account transaction balance before swap.\n */\n preTxBalance?: string;\n\n /**\n * The previous gas properties before they were updated.\n */\n previousGas?: {\n /**\n * Maxmimum number of units of gas to use for this transaction.\n */\n gasLimit?: string;\n\n /**\n * Maximum amount per gas to pay for the transaction, including the priority fee.\n */\n maxFeePerGas?: string;\n\n /**\n * Maximum amount per gas to give to validator as incentive.\n */\n maxPriorityFeePerGas?: string;\n };\n\n /**\n * The transaction's 'r' value as a hex string.\n */\n r?: string;\n\n /**\n * Hex representation of the underlying transaction.\n */\n rawTx?: string;\n\n /**\n * When the transaction is dropped, this is the replacement transaction hash.\n */\n replacedBy?: string;\n\n /**\n * When the transaction is dropped, this is the replacement transaction ID.\n */\n replacedById?: string;\n\n /**\n * The number of times that the transaction submit has been retried.\n */\n retryCount?: number;\n\n /**\n * The transaction's 's' value as a hex string.\n */\n s?: string;\n\n /**\n * Response from security validator.\n */\n securityAlertResponse?: SecurityAlertResponse;\n\n /**\n * Response from security provider.\n */\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n securityProviderResponse?: Record<string, any>;\n\n /**\n * An array of entries that describe the user's journey through the send flow.\n * This is purely attached to state logs for troubleshooting and support.\n */\n sendFlowHistory?: SendFlowHistoryEntry[];\n\n /**\n * Simulation data for the transaction used to predict its outcome.\n */\n simulationData?: SimulationData;\n\n /**\n * If the gas estimation fails, an object containing error and block information.\n */\n simulationFails?: {\n reason?: string;\n errorKey?: string;\n debug: {\n blockNumber?: string;\n blockGasLimit?: string;\n };\n };\n\n /**\n * The time the transaction was submitted to the network, in Unix epoch time (ms).\n */\n submittedTime?: number;\n\n /**\n * The symbol of the token being swapped.\n */\n sourceTokenSymbol?: string;\n\n /**\n * The metadata of the swap transaction.\n */\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n swapMetaData?: Record<string, any>;\n\n /**\n * The value of the token being swapped.\n */\n swapTokenValue?: string;\n\n /**\n * Timestamp associated with this transaction.\n */\n time: number;\n\n /**\n * Whether transaction recipient is a smart contract.\n */\n toSmartContract?: boolean;\n\n /**\n * Additional transfer information.\n */\n transferInformation?: {\n contractAddress: string;\n decimals: number;\n symbol: string;\n };\n\n /**\n * Underlying Transaction object.\n */\n txParams: TransactionParams;\n\n /**\n * Transaction receipt.\n */\n txReceipt?: TransactionReceipt;\n\n /**\n * The type of transaction such as `cancel` or `swap`.\n */\n type?: TransactionType;\n\n /**\n * The gas limit supplied by user.\n */\n userEditedGasLimit?: boolean;\n\n /**\n * Estimate level user selected.\n */\n userFeeLevel?: string;\n\n /**\n * The transaction's 'v' value as a hex string.\n */\n v?: string;\n\n /**\n * Whether the transaction is verified on the blockchain.\n */\n verifiedOnBlockchain?: boolean;\n\n /**\n * Warning information for the transaction.\n */\n warning?: {\n error: string;\n message: string;\n };\n};\n\nexport type SendFlowHistoryEntry = {\n /**\n * String to indicate user interaction information.\n */\n entry: string;\n\n /**\n * Timestamp associated with this entry.\n */\n timestamp: number;\n};\n\n/**\n * The status of the transaction. Each status represents the state of the transaction internally\n * in the wallet. Some of these correspond with the state of the transaction on the network, but\n * some are wallet-specific.\n */\nexport enum TransactionStatus {\n approved = 'approved',\n /** @deprecated Determined by the clients using the transaction type. No longer used. */\n cancelled = 'cancelled',\n confirmed = 'confirmed',\n dropped = 'dropped',\n failed = 'failed',\n rejected = 'rejected',\n signed = 'signed',\n submitted = 'submitted',\n unapproved = 'unapproved',\n}\n\n/**\n * Options for wallet device.\n */\nexport enum WalletDevice {\n MM_MOBILE = 'metamask_mobile',\n MM_EXTENSION = 'metamask_extension',\n OTHER = 'other_device',\n}\n\n/**\n * The type of the transaction.\n */\nexport enum TransactionType {\n /**\n * A transaction sending a network's native asset to a recipient.\n */\n cancel = 'cancel',\n\n /**\n * A transaction that is interacting with a smart contract's methods that we\n * have not treated as a special case, such as approve, transfer, and\n * transferfrom.\n */\n contractInteraction = 'contractInteraction',\n\n /**\n * A transaction that deployed a smart contract.\n */\n deployContract = 'contractDeployment',\n\n /**\n * A transaction for Ethereum decryption.\n */\n ethDecrypt = 'eth_decrypt',\n\n /**\n * A transaction for getting an encryption public key.\n */\n ethGetEncryptionPublicKey = 'eth_getEncryptionPublicKey',\n\n /**\n * An incoming (deposit) transaction.\n */\n incoming = 'incoming',\n\n /**\n * A transaction for personal sign.\n */\n personalSign = 'personal_sign',\n\n /**\n * When a transaction is failed it can be retried by\n * resubmitting the same transaction with a higher gas fee. This type is also used\n * to speed up pending transactions. This is accomplished by creating a new tx with\n * the same nonce and higher gas fees.\n */\n retry = 'retry',\n\n /**\n * A transaction sending a network's native asset to a recipient.\n */\n simpleSend = 'simpleSend',\n\n /**\n * A transaction that is signing a message.\n */\n sign = 'eth_sign',\n\n /**\n * A transaction that is signing typed data.\n */\n signTypedData = 'eth_signTypedData',\n\n /**\n * A transaction sending a network's native asset to a recipient.\n */\n smart = 'smart',\n\n /**\n * A transaction swapping one token for another through MetaMask Swaps.\n */\n swap = 'swap',\n\n /**\n * Similar to the approve type, a swap approval is a special case of ERC20\n * approve method that requests an allowance of the token to spend on behalf\n * of the user for the MetaMask Swaps contract. The first swap for any token\n * will have an accompanying swapApproval transaction.\n */\n swapApproval = 'swapApproval',\n\n /**\n * A token transaction requesting an allowance of the token to spend on\n * behalf of the user.\n */\n tokenMethodApprove = 'approve',\n\n /**\n * A token transaction transferring tokens from an account that the sender\n * has an allowance of. The method is prefixed with safe because when calling\n * this method the contract checks to ensure that the receiver is an address\n * capable of handling the token being sent.\n */\n tokenMethodSafeTransferFrom = 'safetransferfrom',\n\n /**\n * A token transaction where the user is sending tokens that they own to\n * another address.\n */\n tokenMethodTransfer = 'transfer',\n\n /**\n * A token transaction transferring tokens from an account that the sender\n * has an allowance of. For more information on allowances, see the approve\n * type.\n */\n tokenMethodTransferFrom = 'transferfrom',\n\n /**\n * A token transaction requesting an allowance of all of a user's tokens to\n * spend on behalf of the user.\n */\n tokenMethodSetApprovalForAll = 'setapprovalforall',\n\n /**\n * Increase the allowance by a given increment\n */\n tokenMethodIncreaseAllowance = 'increaseAllowance',\n}\n\n/**\n * Standard data concerning a transaction to be processed by the blockchain.\n */\nexport type TransactionParams = {\n /**\n * A list of addresses and storage keys that the transaction plans to access.\n */\n accessList?: AccessList;\n\n /**\n * Network ID as per EIP-155.\n */\n chainId?: Hex;\n\n /**\n * Data to pass with this transaction.\n */\n data?: string;\n\n /**\n * Error message for gas estimation failure.\n */\n estimateGasError?: string;\n\n /**\n * Estimated base fee for this transaction.\n */\n estimatedBaseFee?: string;\n\n /**\n * Which estimate level that the API suggested.\n */\n estimateSuggested?: string;\n\n /**\n * Which estimate level was used\n */\n estimateUsed?: string;\n\n /**\n * Address to send this transaction from.\n */\n from: string;\n\n /**\n * same as gasLimit?\n */\n gas?: string;\n\n /**\n * Maxmimum number of units of gas to use for this transaction.\n */\n gasLimit?: string;\n\n /**\n * Price per gas for legacy txs\n */\n gasPrice?: string;\n\n /**\n * Gas used in the transaction.\n */\n gasUsed?: string;\n\n /**\n * Maximum amount per gas to pay for the transaction, including the priority\n * fee.\n */\n maxFeePerGas?: string;\n\n /**\n * Maximum amount per gas to give to validator as incentive.\n */\n maxPriorityFeePerGas?: string;\n\n /**\n * Unique number to prevent replay attacks.\n */\n nonce?: string;\n\n /**\n * Address to send this transaction to.\n */\n to?: string;\n\n /**\n * Value associated with this transaction.\n */\n value?: string;\n\n /**\n * Type of transaction.\n * 0x0 indicates a legacy transaction.\n */\n type?: string;\n};\n\n/**\n * Standard data concerning a transaction processed by the blockchain.\n */\nexport type TransactionReceipt = {\n /**\n * The block hash of the block that this transaction was included in.\n */\n blockHash?: string;\n\n /**\n * The block number of the block that this transaction was included in.\n */\n blockNumber?: string;\n\n /**\n * Effective gas price the transaction was charged at.\n */\n effectiveGasPrice?: string;\n\n /**\n * Gas used in the transaction.\n */\n gasUsed?: string;\n\n /**\n * Total used gas in hex.\n */\n l1Fee?: string;\n\n /**\n * All the logs emitted by this transaction.\n */\n logs?: Log[];\n\n /**\n * The status of the transaction.\n */\n status?: string;\n\n /**\n * The hexadecimal index of this transaction in the list of transactions included in the block this transaction was mined in.\n */\n transactionIndex?: string;\n};\n\n/**\n * Represents an event that has been included in a transaction using the EVM `LOG` opcode.\n */\nexport type Log = {\n /**\n * Address of the contract that generated log.\n */\n address?: string;\n /**\n * List of topics for log.\n */\n topics?: string;\n};\n\n/**\n * The configuration required to fetch transaction data from a RemoteTransactionSource.\n */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface RemoteTransactionSourceRequest {\n /**\n * The address of the account to fetch transactions for.\n */\n address: string;\n\n /**\n * The chainId of the current network.\n */\n currentChainId: Hex;\n\n /**\n * Block number to start fetching transactions from.\n */\n fromBlock?: number;\n\n /**\n * Maximum number of transactions to retrieve.\n */\n limit?: number;\n}\n\n/**\n * An object capable of fetching transaction data from a remote source.\n * Used by the IncomingTransactionHelper to retrieve remote transaction data.\n */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface RemoteTransactionSource {\n /**\n * @param chainId - The chainId of the current network.\n * @returns Whether the remote transaction source supports the specified network.\n */\n isSupportedNetwork: (chainId: Hex) => boolean;\n\n /**\n * @returns An array of additional keys to use when caching the last fetched block number.\n */\n getLastBlockVariations?: () => string[];\n\n /**\n * @param request - A request object containing data such as the address and chain ID.\n * @returns An array of transaction metadata for the retrieved transactions.\n */\n fetchTransactions: (\n request: RemoteTransactionSourceRequest,\n ) => Promise<TransactionMeta[]>;\n}\n\n/**\n * Gas values initially suggested by the dApp.\n */\nexport type DappSuggestedGasFees = {\n gas?: string;\n gasPrice?: string;\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n};\n\n/**\n * Gas values saved by the user for a specific chain.\n */\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface SavedGasFees {\n maxBaseFee: string;\n priorityFee: string;\n}\n\n/**\n * A transaction history operation that includes a note and timestamp.\n */\ntype ExtendedHistoryOperation = JsonCompatibleOperation & {\n note?: string;\n timestamp?: number;\n};\n\n/**\n * A transaction history entry that includes the ExtendedHistoryOperation as the first element.\n */\nexport type TransactionHistoryEntry = [\n ExtendedHistoryOperation,\n ...JsonCompatibleOperation[],\n];\n\n/**\n * A transaction history that includes the transaction meta as the first element.\n * And the rest of the elements are the operation arrays that were applied to the transaction meta.\n */\nexport type TransactionHistory = [\n TransactionMeta,\n ...TransactionHistoryEntry[],\n];\n\n/**\n * Result of inferring the transaction type.\n */\nexport type InferTransactionTypeResult = {\n /**\n * The contract code, in hex format if it exists. '0x0' or\n * '0x' are also indicators of non-existent contract code.\n */\n getCodeResponse?: string | null;\n\n /**\n * The type of transaction\n */\n type: TransactionType;\n};\n\n/**\n * A function for verifying a transaction, whether it is malicious or not.\n */\nexport type SecurityProviderRequest = (\n requestData: TransactionMeta,\n messageType: string,\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n) => Promise<any>;\n\n/**\n * Specifies the shape of the base transaction parameters.\n * Added in EIP-2718.\n */\nexport enum TransactionEnvelopeType {\n /**\n * A legacy transaction, the very first type.\n */\n legacy = '0x0',\n\n /**\n * EIP-2930 defined the access list transaction type that allowed for\n * specifying the state that a transaction would act upon in advance and\n * theoretically save on gas fees.\n */\n accessList = '0x1',\n\n /**\n * The type introduced comes from EIP-1559, Fee Market describes the addition\n * of a baseFee to blocks that will be burned instead of distributed to\n * miners. Transactions of this type have both a maxFeePerGas (maximum total\n * amount in gwei per gas to spend on the transaction) which is inclusive of\n * the maxPriorityFeePerGas (maximum amount of gwei per gas from the\n * transaction fee to distribute to miner).\n */\n feeMarket = '0x2',\n}\n\n/**\n * The source of the gas fee parameters on a transaction.\n */\nexport enum UserFeeLevel {\n CUSTOM = 'custom',\n DAPP_SUGGESTED = 'dappSuggested',\n MEDIUM = 'medium',\n}\n\n/**\n * Initial gas values set when the transaction was first created.\n */\nexport type DefaultGasEstimates = {\n /**\n * Source of the gas fee values, such as `dappSuggested` or `medium`.\n */\n estimateType?: string;\n\n /**\n * Maxmimum number of units of gas to use for this transaction.\n */\n gas?: string;\n\n /**\n * Price per gas for legacy transactions.\n */\n gasPrice?: string;\n\n /**\n * Maximum amount per gas to pay for the transaction, including the priority fee.\n */\n maxFeePerGas?: string;\n\n /**\n * Maximum amount per gas to give to validator as incentive.\n */\n maxPriorityFeePerGas?: string;\n};\n\n/**\n * Data concerning an error while processing a transaction.\n */\nexport type TransactionError = {\n /**\n * A descriptive error name.\n */\n name: string;\n\n /**\n * A descriptive error message providing details about the encountered error.\n */\n message: string;\n\n /**\n * The stack trace associated with the error, if available.\n */\n stack?: string;\n\n /**\n * An optional error code associated with the error.\n */\n code?: string;\n\n /**\n * The rpc property holds additional information related to the error.\n */\n // We are intentionally using `any` here instead of `Json` because it causes\n // `WritableDraft<TransactionMeta>` from Immer to cause TypeScript to error\n // with \"Type instantiation is excessively deep and possibly infinite\". See:\n // <https://github.com/immerjs/immer/issues/839>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rpc?: any;\n};\n\n/**\n * Type for security alert response from transaction validator.\n */\nexport type SecurityAlertResponse = {\n reason: string;\n features?: string[];\n result_type: string;\n providerRequestsCount?: Record<string, number>;\n};\n\n/** Gas fee estimates for a specific priority level. */\nexport type GasFeeEstimatesForLevel = {\n /** Maximum amount to pay per gas. */\n maxFeePerGas: Hex;\n\n /** Maximum amount per gas to give to the validator as an incentive. */\n maxPriorityFeePerGas: Hex;\n};\n\n/** Alternate priority levels for which values are provided in gas fee estimates. */\nexport enum GasFeeEstimateLevel {\n low = 'low',\n medium = 'medium',\n high = 'high',\n}\n\n/** Gas fee estimates for a transaction. */\nexport type GasFeeEstimates = {\n /** The gas fee estimate for a low priority transaction. */\n [GasFeeEstimateLevel.low]: GasFeeEstimatesForLevel;\n\n /** The gas fee estimate for a medium priority transaction. */\n [GasFeeEstimateLevel.medium]: GasFeeEstimatesForLevel;\n\n /** The gas fee estimate for a high priority transaction. */\n [GasFeeEstimateLevel.high]: GasFeeEstimatesForLevel;\n};\n\n/** Request to a gas fee flow to obtain gas fee estimates. */\nexport type GasFeeFlowRequest = {\n /** An EthQuery instance to enable queries to the associated RPC provider. */\n ethQuery: EthQuery;\n\n /** Callback to get the GasFeeController estimates. */\n getGasFeeControllerEstimates: (\n options: FetchGasFeeEstimateOptions,\n ) => Promise<GasFeeState>;\n\n /** The metadata of the transaction to obtain estimates for. */\n transactionMeta: TransactionMeta;\n};\n\n/** Response from a gas fee flow containing gas fee estimates. */\nexport type GasFeeFlowResponse = {\n /** The gas fee estimates for the transaction. */\n estimates: GasFeeEstimates;\n};\n\n/** A method of obtaining gas fee estimates for a specific transaction. */\nexport type GasFeeFlow = {\n /**\n * Determine if the gas fee flow supports the specified transaction.\n * @param transactionMeta - The transaction metadata.\n * @returns Whether the gas fee flow supports the transaction.\n */\n matchesTransaction(transactionMeta: TransactionMeta): boolean;\n\n /**\n * Get gas fee estimates for a specific transaction.\n * @param request - The gas fee flow request.\n * @returns The gas fee flow response containing the gas fee estimates.\n */\n getGasFees: (request: GasFeeFlowRequest) => Promise<GasFeeFlowResponse>;\n};\n\n/** Request to a layer 1 gas fee flow to obtain layer 1 fee estimate. */\nexport type Layer1GasFeeFlowRequest = {\n /** RPC Provider instance. */\n provider: Provider;\n\n /** The metadata of the transaction to obtain estimates for. */\n transactionMeta: TransactionMeta;\n};\n\n/** Response from a layer 1 gas fee flow containing layer 1 fee estimate. */\nexport type Layer1GasFeeFlowResponse = {\n /** The gas fee estimates for the transaction. */\n layer1Fee: Hex;\n};\n\n/** A method of obtaining layer 1 gas fee estimates for a specific transaction. */\nexport type Layer1GasFeeFlow = {\n /**\n * Determine if the gas fee flow supports the specified transaction.\n * @param transactionMeta - The transaction metadata.\n * @returns Whether the layer1 gas fee flow supports the transaction.\n */\n matchesTransaction(transactionMeta: TransactionMeta): boolean;\n\n /**\n * Get layer 1 gas fee estimates for a specific transaction.\n * @param request - The gas fee flow request.\n * @returns The gas fee flow response containing the layer 1 gas fee estimate.\n */\n getLayer1Fee: (\n request: Layer1GasFeeFlowRequest,\n ) => Promise<Layer1GasFeeFlowResponse>;\n};\n\n/** Simulation data concerning an update to a native or token balance. */\nexport type SimulationBalanceChange = {\n /** The balance before the transaction. */\n previousBalance: Hex;\n\n /** The balance after the transaction. */\n newBalance: Hex;\n\n /** The difference in balance. */\n difference: Hex;\n\n /** Whether the balance is increasing or decreasing. */\n isDecrease: boolean;\n};\n\n/** Token standards supported by simulation. */\nexport enum SimulationTokenStandard {\n erc20 = 'erc20',\n erc721 = 'erc721',\n erc1155 = 'erc1155',\n}\n\n/** Simulation data concerning an updated token. */\nexport type SimulationToken = {\n /** The token's contract address. */\n address: Hex;\n\n /** The standard of the token. */\n standard: SimulationTokenStandard;\n\n /** The ID of the token if supported by the standard. */\n id?: Hex;\n};\n\n/** Simulation data concerning a change to the a token balance. */\nexport type SimulationTokenBalanceChange = SimulationToken &\n SimulationBalanceChange;\n\nexport enum SimulationErrorCode {\n ChainNotSupported = 'chain-not-supported',\n Disabled = 'disabled',\n InvalidResponse = 'invalid-response',\n Reverted = 'reverted',\n}\n\n/** Error data for a failed simulation. */\nexport type SimulationError = {\n /** Error code to identify the error type. */\n code?: string | number;\n\n /** Error message to describe the error. */\n message?: string;\n};\n\n/** Simulation data for a transaction. */\nexport type SimulationData = {\n /** Error data if the simulation failed or the transaction reverted. */\n error?: SimulationError;\n\n /** Data concerning a change to the user's native balance. */\n nativeBalanceChange?: SimulationBalanceChange;\n\n /** Data concerning a change to the user's token balances. */\n tokenBalanceChanges: SimulationTokenBalanceChange[];\n};\n"],"mappings":";AAgbO,IAAK,oBAAL,kBAAKA,uBAAL;AACL,EAAAA,mBAAA,cAAW;AAEX,EAAAA,mBAAA,eAAY;AACZ,EAAAA,mBAAA,eAAY;AACZ,EAAAA,mBAAA,aAAU;AACV,EAAAA,mBAAA,YAAS;AACT,EAAAA,mBAAA,cAAW;AACX,EAAAA,mBAAA,YAAS;AACT,EAAAA,mBAAA,eAAY;AACZ,EAAAA,mBAAA,gBAAa;AAVH,SAAAA;AAAA,GAAA;AAgBL,IAAK,eAAL,kBAAKC,kBAAL;AACL,EAAAA,cAAA,eAAY;AACZ,EAAAA,cAAA,kBAAe;AACf,EAAAA,cAAA,WAAQ;AAHE,SAAAA;AAAA,GAAA;AASL,IAAK,kBAAL,kBAAKC,qBAAL;AAIL,EAAAA,iBAAA,YAAS;AAOT,EAAAA,iBAAA,yBAAsB;AAKtB,EAAAA,iBAAA,oBAAiB;AAKjB,EAAAA,iBAAA,gBAAa;AAKb,EAAAA,iBAAA,+BAA4B;AAK5B,EAAAA,iBAAA,cAAW;AAKX,EAAAA,iBAAA,kBAAe;AAQf,EAAAA,iBAAA,WAAQ;AAKR,EAAAA,iBAAA,gBAAa;AAKb,EAAAA,iBAAA,UAAO;AAKP,EAAAA,iBAAA,mBAAgB;AAKhB,EAAAA,iBAAA,WAAQ;AAKR,EAAAA,iBAAA,UAAO;AAQP,EAAAA,iBAAA,kBAAe;AAMf,EAAAA,iBAAA,wBAAqB;AAQrB,EAAAA,iBAAA,iCAA8B;AAM9B,EAAAA,iBAAA,yBAAsB;AAOtB,EAAAA,iBAAA,6BAA0B;AAM1B,EAAAA,iBAAA,kCAA+B;AAK/B,EAAAA,iBAAA,kCAA+B;AAnHrB,SAAAA;AAAA,GAAA;AAqZL,IAAK,0BAAL,kBAAKC,6BAAL;AAIL,EAAAA,yBAAA,YAAS;AAOT,EAAAA,yBAAA,gBAAa;AAUb,EAAAA,yBAAA,eAAY;AArBF,SAAAA;AAAA,GAAA;AA2BL,IAAK,eAAL,kBAAKC,kBAAL;AACL,EAAAA,cAAA,YAAS;AACT,EAAAA,cAAA,oBAAiB;AACjB,EAAAA,cAAA,YAAS;AAHC,SAAAA;AAAA,GAAA;AA2FL,IAAK,sBAAL,kBAAKC,yBAAL;AACL,EAAAA,qBAAA,SAAM;AACN,EAAAA,qBAAA,YAAS;AACT,EAAAA,qBAAA,UAAO;AAHG,SAAAA;AAAA,GAAA;AAyGL,IAAK,0BAAL,kBAAKC,6BAAL;AACL,EAAAA,yBAAA,WAAQ;AACR,EAAAA,yBAAA,YAAS;AACT,EAAAA,yBAAA,aAAU;AAHA,SAAAA;AAAA,GAAA;AAsBL,IAAK,sBAAL,kBAAKC,yBAAL;AACL,EAAAA,qBAAA,uBAAoB;AACpB,EAAAA,qBAAA,cAAW;AACX,EAAAA,qBAAA,qBAAkB;AAClB,EAAAA,qBAAA,cAAW;AAJD,SAAAA;AAAA,GAAA;","names":["TransactionStatus","WalletDevice","TransactionType","TransactionEnvelopeType","UserFeeLevel","GasFeeEstimateLevel","SimulationTokenStandard","SimulationErrorCode"]}
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"names":["TransactionStatus","WalletDevice","TransactionType","TransactionEnvelopeType","UserFeeLevel","GasFeeEstimateLevel","GasFeeEstimateType","SimulationTokenStandard","SimulationErrorCode"],"mappings":";AA6aO,IAAK,oBAAL,kBAAKA,uBAAL;AACL,EAAAA,mBAAA,cAAW;AAEX,EAAAA,mBAAA,eAAY;AACZ,EAAAA,mBAAA,eAAY;AACZ,EAAAA,mBA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BAAKC,yBAAL;AACL,EAAAA,qBAAA,SAAM;AACN,EAAAA,qBAAA,YAAS;AACT,EAAAA,qBAAA,UAAO;AAHG,SAAAA;AAAA,GAAA;AAOL,IAAK,qBAAL,kBAAKC,wBAAL;AACL,EAAAA,oBAAA,eAAY;AACZ,EAAAA,oBAAA,YAAS;AACT,EAAAA,oBAAA,cAAW;AAHD,SAAAA;AAAA,GAAA;AAgIL,IAAK,0BAAL,kBAAKC,6BAAL;AACL,EAAAA,yBAAA,WAAQ;AACR,EAAAA,yBAAA,YAAS;AACT,EAAAA,yBAAA,aAAU;AAHA,SAAAA;AAAA,GAAA;AAsBL,IAAK,sBAAL,kBAAKC,yBAAL;AACL,EAAAA,qBAAA,uBAAoB;AACpB,EAAAA,qBAAA,cAAW;AACX,EAAAA,qBAAA,qBAAkB;AAClB,EAAAA,qBAAA,cAAW;AAJD,SAAAA;AAAA,GAAA","sourcesContent":["import type { AccessList } from '@ethereumjs/tx';\nimport type EthQuery from '@metamask/eth-query';\nimport type { GasFeeState } from '@metamask/gas-fee-controller';\nimport type { NetworkClientId, Provider } from '@metamask/network-controller';\nimport type { Hex, Json } from '@metamask/utils';\nimport type { Operation } from 'fast-json-patch';\n\n/**\n * Given a record, ensures that each property matches the `Json` type.\n */\ntype MakeJsonCompatible<T> = T extends Json\n ? T\n : {\n [K in keyof T]: T[K] extends Json ? T[K] : never;\n };\n\n/**\n * `Json` from `@metamask/utils` is defined as a recursive type alias, but\n * `Operation` is defined as an interface, and the two are not compatible with\n * each other. Therefore, this is a variant of Operation from `fast-json-patch`\n * which is guaranteed to be type-compatible with `Json`.\n */\ntype JsonCompatibleOperation = MakeJsonCompatible<Operation>;\n\n/**\n * Representation of transaction metadata.\n */\nexport type TransactionMeta = TransactionMetaBase &\n (\n | {\n status: Exclude<TransactionStatus, TransactionStatus.failed>;\n }\n | {\n status: TransactionStatus.failed;\n error: TransactionError;\n }\n );\n\n/**\n * Information about a single transaction such as status and block number.\n */\ntype TransactionMetaBase = {\n /**\n * ID of the transaction that approved the swap token transfer.\n */\n approvalTxId?: string;\n\n /**\n * Unique ID to prevent duplicate requests.\n */\n actionId?: string;\n\n /**\n * Base fee of the block as a hex value, introduced in EIP-1559.\n */\n baseFeePerGas?: Hex;\n\n /**\n * Number of the block where the transaction has been included.\n */\n blockNumber?: string;\n\n /**\n * The timestamp for when the block was collated.\n */\n blockTimestamp?: string;\n\n /**\n * Network code as per EIP-155 for this transaction.\n */\n chainId: Hex;\n\n /**\n * A string representing a name of transaction contract method.\n */\n contractMethodName?: string;\n\n /**\n * The balance of the token that is being sent.\n */\n currentTokenBalance?: string;\n\n /**\n * Unique ID for custodian transaction.\n */\n custodyId?: string;\n\n /**\n * Custodian transaction status.\n */\n custodyStatus?: string;\n\n /** The optional custom nonce override as a decimal string. */\n customNonceValue?: string;\n\n /**\n * The custom token amount is the amount set by the user.\n */\n customTokenAmount?: string;\n\n /**\n * The dapp proposed token amount.\n */\n dappProposedTokenAmount?: string;\n\n /**\n * Gas values provided by the dApp.\n */\n dappSuggestedGasFees?: DappSuggestedGasFees;\n\n /**\n * The initial gas values set when the transaction was first created.\n */\n defaultGasEstimates?: DefaultGasEstimates;\n\n /**\n * String to indicate what device the transaction was confirmed on.\n */\n deviceConfirmedOn?: WalletDevice;\n\n /**\n * The address of the token being received of swap transaction.\n */\n destinationTokenAddress?: string;\n\n /**\n * The decimals of the token being received of swap transaction.\n */\n destinationTokenDecimals?: number;\n\n /**\n * The symbol of the token being received with swap.\n */\n destinationTokenSymbol?: string;\n\n /**\n * The estimated base fee of the transaction.\n */\n estimatedBaseFee?: string;\n\n /**\n * Which estimate level that the API suggested.\n */\n estimateSuggested?: string;\n\n /**\n * Which estimate level was used\n */\n estimateUsed?: string;\n\n /**\n * The chosen amount which will be the same as the originally proposed token\n * amount if the user does not edit the amount or will be a custom token\n * amount set by the user.\n */\n finalApprovalAmount?: string;\n\n /**\n * The number of the latest block when the transaction submit was first retried.\n */\n firstRetryBlockNumber?: string;\n\n /** Alternate EIP-1559 gas fee estimates for multiple priority levels. */\n gasFeeEstimates?: GasFeeEstimates;\n\n /** Whether the gas fee estimates have been checked at least once. */\n gasFeeEstimatesLoaded?: boolean;\n\n /**\n * A hex string of the transaction hash, used to identify the transaction on the network.\n */\n hash?: string;\n\n /**\n * A history of mutations to TransactionMeta.\n */\n history?: TransactionHistory;\n\n /**\n * Generated UUID associated with this transaction.\n */\n id: string;\n\n /**\n * Whether the transaction is a transfer.\n */\n isTransfer?: boolean;\n\n /**\n * Whether the transaction entry is generated from a user operation.\n */\n isUserOperation?: boolean;\n\n /**\n * Additional gas fees to cover the cost of persisting data on layer 1 for layer 2 networks.\n */\n layer1GasFee?: Hex;\n\n /**\n * The ID of the network client used by the transaction.\n */\n networkClientId?: NetworkClientId;\n\n /**\n * Network code as per EIP-155 for this transaction\n *\n * @deprecated Use `chainId` instead.\n */\n readonly networkID?: string;\n\n /**\n * Origin this transaction was sent from.\n */\n origin?: string;\n\n /**\n * The original dapp proposed token approval amount before edit by user.\n */\n originalApprovalAmount?: string;\n\n /**\n * The original gas estimation of the transaction.\n */\n originalGasEstimate?: string;\n\n /**\n * When we speed up a transaction, we set the type as Retry and we lose\n * information about type of transaction that is being set up, so we use\n * original type to track that information.\n */\n originalType?: TransactionType;\n\n /**\n * Account transaction balance after swap.\n */\n postTxBalance?: string;\n\n /**\n * Account transaction balance before swap.\n */\n preTxBalance?: string;\n\n /**\n * The previous gas properties before they were updated.\n */\n previousGas?: {\n /**\n * Maxmimum number of units of gas to use for this transaction.\n */\n gasLimit?: string;\n\n /**\n * Maximum amount per gas to pay for the transaction, including the priority fee.\n */\n maxFeePerGas?: string;\n\n /**\n * Maximum amount per gas to give to validator as incentive.\n */\n maxPriorityFeePerGas?: string;\n };\n\n /**\n * The transaction's 'r' value as a hex string.\n */\n r?: string;\n\n /**\n * Hex representation of the underlying transaction.\n */\n rawTx?: string;\n\n /**\n * When the transaction is dropped, this is the replacement transaction hash.\n */\n replacedBy?: string;\n\n /**\n * When the transaction is dropped, this is the replacement transaction ID.\n */\n replacedById?: string;\n\n /**\n * The number of times that the transaction submit has been retried.\n */\n retryCount?: number;\n\n /**\n * The transaction's 's' value as a hex string.\n */\n s?: string;\n\n /**\n * Response from security validator.\n */\n securityAlertResponse?: SecurityAlertResponse;\n\n /**\n * Response from security provider.\n */\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n securityProviderResponse?: Record<string, any>;\n\n /**\n * An array of entries that describe the user's journey through the send flow.\n * This is purely attached to state logs for troubleshooting and support.\n */\n sendFlowHistory?: SendFlowHistoryEntry[];\n\n /**\n * Simulation data for the transaction used to predict its outcome.\n */\n simulationData?: SimulationData;\n\n /**\n * If the gas estimation fails, an object containing error and block information.\n */\n simulationFails?: {\n reason?: string;\n errorKey?: string;\n debug: {\n blockNumber?: string;\n blockGasLimit?: string;\n };\n };\n\n /**\n * The time the transaction was submitted to the network, in Unix epoch time (ms).\n */\n submittedTime?: number;\n\n /**\n * The symbol of the token being swapped.\n */\n sourceTokenSymbol?: string;\n\n /**\n * The metadata of the swap transaction.\n */\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n swapMetaData?: Record<string, any>;\n\n /**\n * The value of the token being swapped.\n */\n swapTokenValue?: string;\n\n /**\n * Timestamp associated with this transaction.\n */\n time: number;\n\n /**\n * Whether transaction recipient is a smart contract.\n */\n toSmartContract?: boolean;\n\n /**\n * Additional transfer information.\n */\n transferInformation?: {\n contractAddress: string;\n decimals: number;\n symbol: string;\n };\n\n /**\n * Underlying Transaction object.\n */\n txParams: TransactionParams;\n\n /**\n * Transaction receipt.\n */\n txReceipt?: TransactionReceipt;\n\n /**\n * The type of transaction such as `cancel` or `swap`.\n */\n type?: TransactionType;\n\n /**\n * The gas limit supplied by user.\n */\n userEditedGasLimit?: boolean;\n\n /**\n * Estimate level user selected.\n */\n userFeeLevel?: string;\n\n /**\n * The transaction's 'v' value as a hex string.\n */\n v?: string;\n\n /**\n * Whether the transaction is verified on the blockchain.\n */\n verifiedOnBlockchain?: boolean;\n\n /**\n * Warning information for the transaction.\n */\n warning?: {\n error: string;\n message: string;\n };\n};\n\nexport type SendFlowHistoryEntry = {\n /**\n * String to indicate user interaction information.\n */\n entry: string;\n\n /**\n * Timestamp associated with this entry.\n */\n timestamp: number;\n};\n\n/**\n * The status of the transaction. Each status represents the state of the transaction internally\n * in the wallet. Some of these correspond with the state of the transaction on the network, but\n * some are wallet-specific.\n */\nexport enum TransactionStatus {\n approved = 'approved',\n /** @deprecated Determined by the clients using the transaction type. No longer used. */\n cancelled = 'cancelled',\n confirmed = 'confirmed',\n dropped = 'dropped',\n failed = 'failed',\n rejected = 'rejected',\n signed = 'signed',\n submitted = 'submitted',\n unapproved = 'unapproved',\n}\n\n/**\n * Options for wallet device.\n */\nexport enum WalletDevice {\n MM_MOBILE = 'metamask_mobile',\n MM_EXTENSION = 'metamask_extension',\n OTHER = 'other_device',\n}\n\n/**\n * The type of the transaction.\n */\nexport enum TransactionType {\n /**\n * A transaction sending a network's native asset to a recipient.\n */\n cancel = 'cancel',\n\n /**\n * A transaction that is interacting with a smart contract's methods that we\n * have not treated as a special case, such as approve, transfer, and\n * transferfrom.\n */\n contractInteraction = 'contractInteraction',\n\n /**\n * A transaction that deployed a smart contract.\n */\n deployContract = 'contractDeployment',\n\n /**\n * A transaction for Ethereum decryption.\n */\n ethDecrypt = 'eth_decrypt',\n\n /**\n * A transaction for getting an encryption public key.\n */\n ethGetEncryptionPublicKey = 'eth_getEncryptionPublicKey',\n\n /**\n * An incoming (deposit) transaction.\n */\n incoming = 'incoming',\n\n /**\n * A transaction for personal sign.\n */\n personalSign = 'personal_sign',\n\n /**\n * When a transaction is failed it can be retried by\n * resubmitting the same transaction with a higher gas fee. This type is also used\n * to speed up pending transactions. This is accomplished by creating a new tx with\n * the same nonce and higher gas fees.\n */\n retry = 'retry',\n\n /**\n * A transaction sending a network's native asset to a recipient.\n */\n simpleSend = 'simpleSend',\n\n /**\n * A transaction that is signing a message.\n */\n sign = 'eth_sign',\n\n /**\n * A transaction that is signing typed data.\n */\n signTypedData = 'eth_signTypedData',\n\n /**\n * A transaction sending a network's native asset to a recipient.\n */\n smart = 'smart',\n\n /**\n * A transaction swapping one token for another through MetaMask Swaps.\n */\n swap = 'swap',\n\n /**\n * Similar to the approve type, a swap approval is a special case of ERC20\n * approve method that requests an allowance of the token to spend on behalf\n * of the user for the MetaMask Swaps contract. The first swap for any token\n * will have an accompanying swapApproval transaction.\n */\n swapApproval = 'swapApproval',\n\n /**\n * A token transaction requesting an allowance of the token to spend on\n * behalf of the user.\n */\n tokenMethodApprove = 'approve',\n\n /**\n * A token transaction transferring tokens from an account that the sender\n * has an allowance of. The method is prefixed with safe because when calling\n * this method the contract checks to ensure that the receiver is an address\n * capable of handling the token being sent.\n */\n tokenMethodSafeTransferFrom = 'safetransferfrom',\n\n /**\n * A token transaction where the user is sending tokens that they own to\n * another address.\n */\n tokenMethodTransfer = 'transfer',\n\n /**\n * A token transaction transferring tokens from an account that the sender\n * has an allowance of. For more information on allowances, see the approve\n * type.\n */\n tokenMethodTransferFrom = 'transferfrom',\n\n /**\n * A token transaction requesting an allowance of all of a user's tokens to\n * spend on behalf of the user.\n */\n tokenMethodSetApprovalForAll = 'setapprovalforall',\n\n /**\n * Increase the allowance by a given increment\n */\n tokenMethodIncreaseAllowance = 'increaseAllowance',\n}\n\n/**\n * Standard data concerning a transaction to be processed by the blockchain.\n */\nexport type TransactionParams = {\n /**\n * A list of addresses and storage keys that the transaction plans to access.\n */\n accessList?: AccessList;\n\n /**\n * Network ID as per EIP-155.\n */\n chainId?: Hex;\n\n /**\n * Data to pass with this transaction.\n */\n data?: string;\n\n /**\n * Error message for gas estimation failure.\n */\n estimateGasError?: string;\n\n /**\n * Estimated base fee for this transaction.\n */\n estimatedBaseFee?: string;\n\n /**\n * Which estimate level that the API suggested.\n */\n estimateSuggested?: string;\n\n /**\n * Which estimate level was used\n */\n estimateUsed?: string;\n\n /**\n * Address to send this transaction from.\n */\n from: string;\n\n /**\n * same as gasLimit?\n */\n gas?: string;\n\n /**\n * Maxmimum number of units of gas to use for this transaction.\n */\n gasLimit?: string;\n\n /**\n * Price per gas for legacy txs\n */\n gasPrice?: string;\n\n /**\n * Gas used in the transaction.\n */\n gasUsed?: string;\n\n /**\n * Maximum amount per gas to pay for the transaction, including the priority\n * fee.\n */\n maxFeePerGas?: string;\n\n /**\n * Maximum amount per gas to give to validator as incentive.\n */\n maxPriorityFeePerGas?: string;\n\n /**\n * Unique number to prevent replay attacks.\n */\n nonce?: string;\n\n /**\n * Address to send this transaction to.\n */\n to?: string;\n\n /**\n * Value associated with this transaction.\n */\n value?: string;\n\n /**\n * Type of transaction.\n * 0x0 indicates a legacy transaction.\n */\n type?: string;\n};\n\n/**\n * Standard data concerning a transaction processed by the blockchain.\n */\nexport type TransactionReceipt = {\n /**\n * The block hash of the block that this transaction was included in.\n */\n blockHash?: string;\n\n /**\n * The block number of the block that this transaction was included in.\n */\n blockNumber?: string;\n\n /**\n * Effective gas price the transaction was charged at.\n */\n effectiveGasPrice?: string;\n\n /**\n * Gas used in the transaction.\n */\n gasUsed?: string;\n\n /**\n * Total used gas in hex.\n */\n l1Fee?: string;\n\n /**\n * All the logs emitted by this transaction.\n */\n logs?: Log[];\n\n /**\n * The status of the transaction.\n */\n status?: string;\n\n /**\n * The hexadecimal index of this transaction in the list of transactions included in the block this transaction was mined in.\n */\n transactionIndex?: string;\n};\n\n/**\n * Represents an event that has been included in a transaction using the EVM `LOG` opcode.\n */\nexport type Log = {\n /**\n * Address of the contract that generated log.\n */\n address?: string;\n /**\n * List of topics for log.\n */\n topics?: string;\n};\n\n/**\n * The configuration required to fetch transaction data from a RemoteTransactionSource.\n */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface RemoteTransactionSourceRequest {\n /**\n * The address of the account to fetch transactions for.\n */\n address: string;\n\n /**\n * The chainId of the current network.\n */\n currentChainId: Hex;\n\n /**\n * Block number to start fetching transactions from.\n */\n fromBlock?: number;\n\n /**\n * Maximum number of transactions to retrieve.\n */\n limit?: number;\n}\n\n/**\n * An object capable of fetching transaction data from a remote source.\n * Used by the IncomingTransactionHelper to retrieve remote transaction data.\n */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface RemoteTransactionSource {\n /**\n * @param chainId - The chainId of the current network.\n * @returns Whether the remote transaction source supports the specified network.\n */\n isSupportedNetwork: (chainId: Hex) => boolean;\n\n /**\n * @returns An array of additional keys to use when caching the last fetched block number.\n */\n getLastBlockVariations?: () => string[];\n\n /**\n * @param request - A request object containing data such as the address and chain ID.\n * @returns An array of transaction metadata for the retrieved transactions.\n */\n fetchTransactions: (\n request: RemoteTransactionSourceRequest,\n ) => Promise<TransactionMeta[]>;\n}\n\n/**\n * Gas values initially suggested by the dApp.\n */\nexport type DappSuggestedGasFees = {\n gas?: string;\n gasPrice?: string;\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n};\n\n/**\n * Gas values saved by the user for a specific chain.\n */\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface SavedGasFees {\n maxBaseFee: string;\n priorityFee: string;\n}\n\n/**\n * A transaction history operation that includes a note and timestamp.\n */\ntype ExtendedHistoryOperation = JsonCompatibleOperation & {\n note?: string;\n timestamp?: number;\n};\n\n/**\n * A transaction history entry that includes the ExtendedHistoryOperation as the first element.\n */\nexport type TransactionHistoryEntry = [\n ExtendedHistoryOperation,\n ...JsonCompatibleOperation[],\n];\n\n/**\n * A transaction history that includes the transaction meta as the first element.\n * And the rest of the elements are the operation arrays that were applied to the transaction meta.\n */\nexport type TransactionHistory = [\n TransactionMeta,\n ...TransactionHistoryEntry[],\n];\n\n/**\n * Result of inferring the transaction type.\n */\nexport type InferTransactionTypeResult = {\n /**\n * The contract code, in hex format if it exists. '0x0' or\n * '0x' are also indicators of non-existent contract code.\n */\n getCodeResponse?: string | null;\n\n /**\n * The type of transaction\n */\n type: TransactionType;\n};\n\n/**\n * A function for verifying a transaction, whether it is malicious or not.\n */\nexport type SecurityProviderRequest = (\n requestData: TransactionMeta,\n messageType: string,\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n) => Promise<any>;\n\n/**\n * Specifies the shape of the base transaction parameters.\n * Added in EIP-2718.\n */\nexport enum TransactionEnvelopeType {\n /**\n * A legacy transaction, the very first type.\n */\n legacy = '0x0',\n\n /**\n * EIP-2930 defined the access list transaction type that allowed for\n * specifying the state that a transaction would act upon in advance and\n * theoretically save on gas fees.\n */\n accessList = '0x1',\n\n /**\n * The type introduced comes from EIP-1559, Fee Market describes the addition\n * of a baseFee to blocks that will be burned instead of distributed to\n * miners. Transactions of this type have both a maxFeePerGas (maximum total\n * amount in gwei per gas to spend on the transaction) which is inclusive of\n * the maxPriorityFeePerGas (maximum amount of gwei per gas from the\n * transaction fee to distribute to miner).\n */\n feeMarket = '0x2',\n}\n\n/**\n * The source of the gas fee parameters on a transaction.\n */\nexport enum UserFeeLevel {\n CUSTOM = 'custom',\n DAPP_SUGGESTED = 'dappSuggested',\n MEDIUM = 'medium',\n}\n\n/**\n * Initial gas values set when the transaction was first created.\n */\nexport type DefaultGasEstimates = {\n /**\n * Source of the gas fee values, such as `dappSuggested` or `medium`.\n */\n estimateType?: string;\n\n /**\n * Maxmimum number of units of gas to use for this transaction.\n */\n gas?: string;\n\n /**\n * Price per gas for legacy transactions.\n */\n gasPrice?: string;\n\n /**\n * Maximum amount per gas to pay for the transaction, including the priority fee.\n */\n maxFeePerGas?: string;\n\n /**\n * Maximum amount per gas to give to validator as incentive.\n */\n maxPriorityFeePerGas?: string;\n};\n\n/**\n * Data concerning an error while processing a transaction.\n */\nexport type TransactionError = {\n /**\n * A descriptive error name.\n */\n name: string;\n\n /**\n * A descriptive error message providing details about the encountered error.\n */\n message: string;\n\n /**\n * The stack trace associated with the error, if available.\n */\n stack?: string;\n\n /**\n * An optional error code associated with the error.\n */\n code?: string;\n\n /**\n * The rpc property holds additional information related to the error.\n */\n // We are intentionally using `any` here instead of `Json` because it causes\n // `WritableDraft<TransactionMeta>` from Immer to cause TypeScript to error\n // with \"Type instantiation is excessively deep and possibly infinite\". See:\n // <https://github.com/immerjs/immer/issues/839>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rpc?: any;\n};\n\n/**\n * Type for security alert response from transaction validator.\n */\nexport type SecurityAlertResponse = {\n reason: string;\n features?: string[];\n result_type: string;\n providerRequestsCount?: Record<string, number>;\n};\n\n/** Alternate priority levels for which values are provided in gas fee estimates. */\nexport enum GasFeeEstimateLevel {\n Low = 'low',\n Medium = 'medium',\n High = 'high',\n}\n\n/** Type of gas fee estimate generated by a GasFeeFlow. */\nexport enum GasFeeEstimateType {\n FeeMarket = 'fee-market',\n Legacy = 'legacy',\n GasPrice = 'eth_gasPrice',\n}\n\n/** Gas fee estimates for a specific priority level. */\nexport type FeeMarketGasFeeEstimateForLevel = {\n /** Maximum amount to pay per gas. */\n maxFeePerGas: Hex;\n\n /** Maximum amount per gas to give to the validator as an incentive. */\n maxPriorityFeePerGas: Hex;\n};\n\n/** Gas fee estimates for a EIP-1559 transaction. */\nexport type FeeMarketGasFeeEstimates = {\n type: GasFeeEstimateType.FeeMarket;\n [GasFeeEstimateLevel.Low]: FeeMarketGasFeeEstimateForLevel;\n [GasFeeEstimateLevel.Medium]: FeeMarketGasFeeEstimateForLevel;\n [GasFeeEstimateLevel.High]: FeeMarketGasFeeEstimateForLevel;\n};\n\n/** Gas fee estimates for a legacy transaction. */\nexport type LegacyGasFeeEstimates = {\n type: GasFeeEstimateType.Legacy;\n [GasFeeEstimateLevel.Low]: Hex;\n [GasFeeEstimateLevel.Medium]: Hex;\n [GasFeeEstimateLevel.High]: Hex;\n};\n\n/** Gas fee estimates for a transaction retrieved with the eth_gasPrice method. */\nexport type GasPriceGasFeeEstimates = {\n type: GasFeeEstimateType.GasPrice;\n gasPrice: Hex;\n};\n\n/** Gas fee estimates for a transaction. */\nexport type GasFeeEstimates =\n | FeeMarketGasFeeEstimates\n | LegacyGasFeeEstimates\n | GasPriceGasFeeEstimates;\n\n/** Request to a gas fee flow to obtain gas fee estimates. */\nexport type GasFeeFlowRequest = {\n /** An EthQuery instance to enable queries to the associated RPC provider. */\n ethQuery: EthQuery;\n\n /** Gas fee controller data matching the chain ID of the transaction. */\n gasFeeControllerData: GasFeeState;\n\n /** The metadata of the transaction to obtain estimates for. */\n transactionMeta: TransactionMeta;\n};\n\n/** Response from a gas fee flow containing gas fee estimates. */\nexport type GasFeeFlowResponse = {\n /** The gas fee estimates for the transaction. */\n estimates: GasFeeEstimates;\n};\n\n/** A method of obtaining gas fee estimates for a specific transaction. */\nexport type GasFeeFlow = {\n /**\n * Determine if the gas fee flow supports the specified transaction.\n * @param transactionMeta - The transaction metadata.\n * @returns Whether the gas fee flow supports the transaction.\n */\n matchesTransaction(transactionMeta: TransactionMeta): boolean;\n\n /**\n * Get gas fee estimates for a specific transaction.\n * @param request - The gas fee flow request.\n * @returns The gas fee flow response containing the gas fee estimates.\n */\n getGasFees: (request: GasFeeFlowRequest) => Promise<GasFeeFlowResponse>;\n};\n\n/** Request to a layer 1 gas fee flow to obtain layer 1 fee estimate. */\nexport type Layer1GasFeeFlowRequest = {\n /** RPC Provider instance. */\n provider: Provider;\n\n /** The metadata of the transaction to obtain estimates for. */\n transactionMeta: TransactionMeta;\n};\n\n/** Response from a layer 1 gas fee flow containing layer 1 fee estimate. */\nexport type Layer1GasFeeFlowResponse = {\n /** The gas fee estimates for the transaction. */\n layer1Fee: Hex;\n};\n\n/** A method of obtaining layer 1 gas fee estimates for a specific transaction. */\nexport type Layer1GasFeeFlow = {\n /**\n * Determine if the gas fee flow supports the specified transaction.\n * @param transactionMeta - The transaction metadata.\n * @returns Whether the layer1 gas fee flow supports the transaction.\n */\n matchesTransaction(transactionMeta: TransactionMeta): boolean;\n\n /**\n * Get layer 1 gas fee estimates for a specific transaction.\n * @param request - The gas fee flow request.\n * @returns The gas fee flow response containing the layer 1 gas fee estimate.\n */\n getLayer1Fee: (\n request: Layer1GasFeeFlowRequest,\n ) => Promise<Layer1GasFeeFlowResponse>;\n};\n\n/** Simulation data concerning an update to a native or token balance. */\nexport type SimulationBalanceChange = {\n /** The balance before the transaction. */\n previousBalance: Hex;\n\n /** The balance after the transaction. */\n newBalance: Hex;\n\n /** The difference in balance. */\n difference: Hex;\n\n /** Whether the balance is increasing or decreasing. */\n isDecrease: boolean;\n};\n\n/** Token standards supported by simulation. */\nexport enum SimulationTokenStandard {\n erc20 = 'erc20',\n erc721 = 'erc721',\n erc1155 = 'erc1155',\n}\n\n/** Simulation data concerning an updated token. */\nexport type SimulationToken = {\n /** The token's contract address. */\n address: Hex;\n\n /** The standard of the token. */\n standard: SimulationTokenStandard;\n\n /** The ID of the token if supported by the standard. */\n id?: Hex;\n};\n\n/** Simulation data concerning a change to the a token balance. */\nexport type SimulationTokenBalanceChange = SimulationToken &\n SimulationBalanceChange;\n\nexport enum SimulationErrorCode {\n ChainNotSupported = 'chain-not-supported',\n Disabled = 'disabled',\n InvalidResponse = 'invalid-response',\n Reverted = 'reverted',\n}\n\n/** Error data for a failed simulation. */\nexport type SimulationError = {\n /** Error code to identify the error type. */\n code?: string | number;\n\n /** Error message to describe the error. */\n message?: string;\n};\n\n/** Simulation data for a transaction. */\nexport type SimulationData = {\n /** Error data if the simulation failed or the transaction reverted. */\n error?: SimulationError;\n\n /** Data concerning a change to the user's native balance. */\n nativeBalanceChange?: SimulationBalanceChange;\n\n /** Data concerning a change to the user's token balances. */\n tokenBalanceChanges: SimulationTokenBalanceChange[];\n};\n"]}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var _chunk2XKEAKQGjs = require('./chunk-2XKEAKQG.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkEMDU4XLMjs = require('./chunk-EMDU4XLM.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
var _chunkS6VGOPUYjs = require('./chunk-S6VGOPUY.js');
|
|
@@ -20,11 +20,12 @@ var _utils = require('@metamask/utils');
|
|
|
20
20
|
var _events = require('events'); var _events2 = _interopRequireDefault(_events);
|
|
21
21
|
var log = _utils.createModuleLogger.call(void 0, _chunkS6VGOPUYjs.projectLogger, "gas-fee-poller");
|
|
22
22
|
var INTERVAL_MILLISECONDS = 1e4;
|
|
23
|
-
var _gasFeeFlows, _getGasFeeControllerEstimates, _getProvider, _getTransactions, _layer1GasFeeFlows, _timeout, _running, _start, start_fn, _stop, stop_fn, _onTimeout, onTimeout_fn, _updateUnapprovedTransactions, updateUnapprovedTransactions_fn, _updateUnapprovedTransaction, updateUnapprovedTransaction_fn, _updateTransactionGasFeeEstimates, updateTransactionGasFeeEstimates_fn, _updateTransactionLayer1GasFee, updateTransactionLayer1GasFee_fn, _getUnapprovedTransactions, getUnapprovedTransactions_fn;
|
|
23
|
+
var _findNetworkClientIdByChainId, _gasFeeFlows, _getGasFeeControllerEstimates, _getProvider, _getTransactions, _layer1GasFeeFlows, _timeout, _running, _start, start_fn, _stop, stop_fn, _onTimeout, onTimeout_fn, _updateUnapprovedTransactions, updateUnapprovedTransactions_fn, _updateUnapprovedTransaction, updateUnapprovedTransaction_fn, _updateTransactionGasFeeEstimates, updateTransactionGasFeeEstimates_fn, _updateTransactionLayer1GasFee, updateTransactionLayer1GasFee_fn, _getUnapprovedTransactions, getUnapprovedTransactions_fn, _getGasFeeControllerData, getGasFeeControllerData_fn;
|
|
24
24
|
var GasFeePoller = class {
|
|
25
25
|
/**
|
|
26
26
|
* Constructs a new instance of the GasFeePoller.
|
|
27
27
|
* @param options - The options for this instance.
|
|
28
|
+
* @param options.findNetworkClientIdByChainId - Callback to find the network client ID by chain ID.
|
|
28
29
|
* @param options.gasFeeFlows - The gas fee flows to use to obtain suitable gas fees.
|
|
29
30
|
* @param options.getGasFeeControllerEstimates - Callback to obtain the default fee estimates.
|
|
30
31
|
* @param options.getProvider - Callback to obtain a provider instance.
|
|
@@ -33,6 +34,7 @@ var GasFeePoller = class {
|
|
|
33
34
|
* @param options.onStateChange - Callback to register a listener for controller state changes.
|
|
34
35
|
*/
|
|
35
36
|
constructor({
|
|
37
|
+
findNetworkClientIdByChainId,
|
|
36
38
|
gasFeeFlows,
|
|
37
39
|
getGasFeeControllerEstimates,
|
|
38
40
|
getProvider,
|
|
@@ -48,7 +50,9 @@ var GasFeePoller = class {
|
|
|
48
50
|
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _updateTransactionGasFeeEstimates);
|
|
49
51
|
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _updateTransactionLayer1GasFee);
|
|
50
52
|
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _getUnapprovedTransactions);
|
|
53
|
+
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _getGasFeeControllerData);
|
|
51
54
|
this.hub = new (0, _events2.default)();
|
|
55
|
+
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _findNetworkClientIdByChainId, void 0);
|
|
52
56
|
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _gasFeeFlows, void 0);
|
|
53
57
|
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _getGasFeeControllerEstimates, void 0);
|
|
54
58
|
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _getProvider, void 0);
|
|
@@ -56,6 +60,7 @@ var GasFeePoller = class {
|
|
|
56
60
|
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _layer1GasFeeFlows, void 0);
|
|
57
61
|
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _timeout, void 0);
|
|
58
62
|
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _running, false);
|
|
63
|
+
_chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _findNetworkClientIdByChainId, findNetworkClientIdByChainId);
|
|
59
64
|
_chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _gasFeeFlows, gasFeeFlows);
|
|
60
65
|
_chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _layer1GasFeeFlows, layer1GasFeeFlows);
|
|
61
66
|
_chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _getGasFeeControllerEstimates, getGasFeeControllerEstimates);
|
|
@@ -71,6 +76,7 @@ var GasFeePoller = class {
|
|
|
71
76
|
});
|
|
72
77
|
}
|
|
73
78
|
};
|
|
79
|
+
_findNetworkClientIdByChainId = new WeakMap();
|
|
74
80
|
_gasFeeFlows = new WeakMap();
|
|
75
81
|
_getGasFeeControllerEstimates = new WeakMap();
|
|
76
82
|
_getProvider = new WeakMap();
|
|
@@ -105,20 +111,27 @@ onTimeout_fn = async function() {
|
|
|
105
111
|
_updateUnapprovedTransactions = new WeakSet();
|
|
106
112
|
updateUnapprovedTransactions_fn = async function() {
|
|
107
113
|
const unapprovedTransactions = _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getUnapprovedTransactions, getUnapprovedTransactions_fn).call(this);
|
|
108
|
-
if (unapprovedTransactions.length) {
|
|
109
|
-
|
|
114
|
+
if (!unapprovedTransactions.length) {
|
|
115
|
+
return;
|
|
110
116
|
}
|
|
117
|
+
log("Found unapproved transactions", unapprovedTransactions.length);
|
|
118
|
+
const gasFeeControllerDataByChainId = await _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getGasFeeControllerData, getGasFeeControllerData_fn).call(this, unapprovedTransactions);
|
|
119
|
+
log("Retrieved gas fee controller data", gasFeeControllerDataByChainId);
|
|
111
120
|
await Promise.all(
|
|
112
|
-
unapprovedTransactions.flatMap(
|
|
113
|
-
|
|
114
|
-
|
|
121
|
+
unapprovedTransactions.flatMap((tx) => {
|
|
122
|
+
const { chainId } = tx;
|
|
123
|
+
const gasFeeControllerData = gasFeeControllerDataByChainId.get(
|
|
124
|
+
chainId
|
|
125
|
+
);
|
|
126
|
+
return _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _updateUnapprovedTransaction, updateUnapprovedTransaction_fn).call(this, tx, gasFeeControllerData);
|
|
127
|
+
})
|
|
115
128
|
);
|
|
116
129
|
};
|
|
117
130
|
_updateUnapprovedTransaction = new WeakSet();
|
|
118
|
-
updateUnapprovedTransaction_fn = async function(transactionMeta) {
|
|
131
|
+
updateUnapprovedTransaction_fn = async function(transactionMeta, gasFeeControllerData) {
|
|
119
132
|
const { id } = transactionMeta;
|
|
120
133
|
const [gasFeeEstimatesResponse, layer1GasFee] = await Promise.all([
|
|
121
|
-
_chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _updateTransactionGasFeeEstimates, updateTransactionGasFeeEstimates_fn).call(this, transactionMeta),
|
|
134
|
+
_chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _updateTransactionGasFeeEstimates, updateTransactionGasFeeEstimates_fn).call(this, transactionMeta, gasFeeControllerData),
|
|
122
135
|
_chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _updateTransactionLayer1GasFee, updateTransactionLayer1GasFee_fn).call(this, transactionMeta)
|
|
123
136
|
]);
|
|
124
137
|
if (!gasFeeEstimatesResponse && !layer1GasFee) {
|
|
@@ -132,10 +145,10 @@ updateUnapprovedTransaction_fn = async function(transactionMeta) {
|
|
|
132
145
|
});
|
|
133
146
|
};
|
|
134
147
|
_updateTransactionGasFeeEstimates = new WeakSet();
|
|
135
|
-
updateTransactionGasFeeEstimates_fn = async function(transactionMeta) {
|
|
148
|
+
updateTransactionGasFeeEstimates_fn = async function(transactionMeta, gasFeeControllerData) {
|
|
136
149
|
const { chainId, networkClientId } = transactionMeta;
|
|
137
150
|
const ethQuery = new (0, _ethquery2.default)(_chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _getProvider).call(this, chainId, networkClientId));
|
|
138
|
-
const gasFeeFlow =
|
|
151
|
+
const gasFeeFlow = _chunkEMDU4XLMjs.getGasFeeFlow.call(void 0, transactionMeta, _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _gasFeeFlows));
|
|
139
152
|
if (gasFeeFlow) {
|
|
140
153
|
log(
|
|
141
154
|
"Found gas fee flow",
|
|
@@ -145,7 +158,7 @@ updateTransactionGasFeeEstimates_fn = async function(transactionMeta) {
|
|
|
145
158
|
}
|
|
146
159
|
const request = {
|
|
147
160
|
ethQuery,
|
|
148
|
-
|
|
161
|
+
gasFeeControllerData,
|
|
149
162
|
transactionMeta
|
|
150
163
|
};
|
|
151
164
|
let gasFeeEstimates;
|
|
@@ -186,8 +199,30 @@ getUnapprovedTransactions_fn = function() {
|
|
|
186
199
|
(tx) => tx.status === "unapproved" /* unapproved */
|
|
187
200
|
);
|
|
188
201
|
};
|
|
202
|
+
_getGasFeeControllerData = new WeakSet();
|
|
203
|
+
getGasFeeControllerData_fn = async function(transactions) {
|
|
204
|
+
const networkClientIdsByChainId = /* @__PURE__ */ new Map();
|
|
205
|
+
for (const transaction of transactions) {
|
|
206
|
+
const { chainId, networkClientId: transactionNetworkClientId } = transaction;
|
|
207
|
+
if (networkClientIdsByChainId.has(chainId)) {
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
const networkClientId = transactionNetworkClientId ?? _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _findNetworkClientIdByChainId).call(this, chainId);
|
|
211
|
+
networkClientIdsByChainId.set(chainId, networkClientId);
|
|
212
|
+
}
|
|
213
|
+
log("Extracted network client IDs by chain ID", networkClientIdsByChainId);
|
|
214
|
+
const entryPromises = Array.from(networkClientIdsByChainId.entries()).map(
|
|
215
|
+
async ([chainId, networkClientId]) => {
|
|
216
|
+
return [
|
|
217
|
+
chainId,
|
|
218
|
+
await _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _getGasFeeControllerEstimates).call(this, { networkClientId })
|
|
219
|
+
];
|
|
220
|
+
}
|
|
221
|
+
);
|
|
222
|
+
return new Map(await Promise.all(entryPromises));
|
|
223
|
+
};
|
|
189
224
|
|
|
190
225
|
|
|
191
226
|
|
|
192
227
|
exports.GasFeePoller = GasFeePoller;
|
|
193
|
-
//# sourceMappingURL=chunk-
|
|
228
|
+
//# sourceMappingURL=chunk-7DJO6UZA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/helpers/GasFeePoller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,OAAO,cAAc;AAOrB,SAAS,0BAA0B;AACnC,OAAO,kBAAkB;AAazB,IAAM,MAAM,mBAAmB,eAAe,gBAAgB;AAE9D,IAAM,wBAAwB;AAvB9B;AA4BO,IAAM,eAAN,MAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgCxB,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAUG;AAmBH;AAcA;AAaA,uBAAM;AAON,uBAAM;AA4BN,uBAAM;AA0BN,uBAAM;AAiDN,uBAAM;AAmBN;AAMA,uBAAM;AAtON,eAAoB,IAAI,aAAa;AAErC;AAEA;AAEA;AAIA;AAEA;AAEA;AAEA;AAEA,iCAAW;AAgCT,uBAAK,+BAAgC;AACrC,uBAAK,cAAe;AACpB,uBAAK,oBAAqB;AAC1B,uBAAK,+BAAgC;AACrC,uBAAK,cAAe;AACpB,uBAAK,kBAAmB;AAExB,kBAAc,MAAM;AAClB,YAAM,yBAAyB,sBAAK,0DAAL;AAE/B,UAAI,uBAAuB,QAAQ;AACjC,8BAAK,kBAAL;AAAA,MACF,OAAO;AACL,8BAAK,gBAAL;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AAqMF;AArQE;AAEA;AAEA;AAIA;AAEA;AAEA;AAEA;AAEA;AAkDA;AAAA,WAAM,WAAG;AACP,MAAI,mBAAK,WAAU;AACjB;AAAA,EACF;AAIA,wBAAK,0BAAL;AAEA,qBA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IAC3D;AAEF,QAAI,0BAA0B,IAAI,OAAO,GAAG;AAC1C;AAAA,IACF;AAEA,UAAM,kBACJ,8BACC,mBAAK,+BAAL,WAAmC;AAEtC,8BAA0B,IAAI,SAAS,eAAe;AAAA,EACxD;AAEA,MAAI,4CAA4C,yBAAyB;AAEzE,QAAM,gBAAgB,MAAM,KAAK,0BAA0B,QAAQ,CAAC,EAAE;AAAA,IACpE,OAAO,CAAC,SAAS,eAAe,MAAM;AACpC,aAAO;AAAA,QACL;AAAA,QACA,MAAM,mBAAK,+BAAL,WAAmC,EAAE,gBAAgB;AAAA,MAC7D;AAAA,IACF;AAAA,EACF;AAEA,SAAO,IAAI,IAAI,MAAM,QAAQ,IAAI,aAAa,CAAC;AACjD","sourcesContent":["import EthQuery from '@metamask/eth-query';\nimport type {\n FetchGasFeeEstimateOptions,\n GasFeeState,\n} from '@metamask/gas-fee-controller';\nimport type { NetworkClientId, Provider } from '@metamask/network-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\nimport EventEmitter from 'events';\n\nimport { projectLogger } from '../logger';\nimport type {\n GasFeeEstimates,\n GasFeeFlow,\n GasFeeFlowRequest,\n Layer1GasFeeFlow,\n} from '../types';\nimport { TransactionStatus, type TransactionMeta } from '../types';\nimport { getGasFeeFlow } from '../utils/gas-flow';\nimport { getTransactionLayer1GasFee } from '../utils/layer1-gas-fee-flow';\n\nconst log = createModuleLogger(projectLogger, 'gas-fee-poller');\n\nconst INTERVAL_MILLISECONDS = 10000;\n\n/**\n * Automatically polls and updates suggested gas fees on unapproved transactions.\n */\nexport class GasFeePoller {\n hub: EventEmitter = new EventEmitter();\n\n #findNetworkClientIdByChainId: (chainId: Hex) => NetworkClientId | undefined;\n\n #gasFeeFlows: GasFeeFlow[];\n\n #getGasFeeControllerEstimates: (\n options: FetchGasFeeEstimateOptions,\n ) => Promise<GasFeeState>;\n\n #getProvider: (chainId: Hex, networkClientId?: NetworkClientId) => Provider;\n\n #getTransactions: () => TransactionMeta[];\n\n #layer1GasFeeFlows: Layer1GasFeeFlow[];\n\n #timeout: ReturnType<typeof setTimeout> | undefined;\n\n #running = false;\n\n /**\n * Constructs a new instance of the GasFeePoller.\n * @param options - The options for this instance.\n * @param options.findNetworkClientIdByChainId - Callback to find the network client ID by chain ID.\n * @param options.gasFeeFlows - The gas fee flows to use to obtain suitable gas fees.\n * @param options.getGasFeeControllerEstimates - Callback to obtain the default fee estimates.\n * @param options.getProvider - Callback to obtain a provider instance.\n * @param options.getTransactions - Callback to obtain the transaction data.\n * @param options.layer1GasFeeFlows - The layer 1 gas fee flows to use to obtain suitable layer 1 gas fees.\n * @param options.onStateChange - Callback to register a listener for controller state changes.\n */\n constructor({\n findNetworkClientIdByChainId,\n gasFeeFlows,\n getGasFeeControllerEstimates,\n getProvider,\n getTransactions,\n layer1GasFeeFlows,\n onStateChange,\n }: {\n findNetworkClientIdByChainId: (chainId: Hex) => NetworkClientId | undefined;\n gasFeeFlows: GasFeeFlow[];\n getGasFeeControllerEstimates: (\n options: FetchGasFeeEstimateOptions,\n ) => Promise<GasFeeState>;\n getProvider: (chainId: Hex, networkClientId?: NetworkClientId) => Provider;\n getTransactions: () => TransactionMeta[];\n layer1GasFeeFlows: Layer1GasFeeFlow[];\n onStateChange: (listener: () => void) => void;\n }) {\n this.#findNetworkClientIdByChainId = findNetworkClientIdByChainId;\n this.#gasFeeFlows = gasFeeFlows;\n this.#layer1GasFeeFlows = layer1GasFeeFlows;\n this.#getGasFeeControllerEstimates = getGasFeeControllerEstimates;\n this.#getProvider = getProvider;\n this.#getTransactions = getTransactions;\n\n onStateChange(() => {\n const unapprovedTransactions = this.#getUnapprovedTransactions();\n\n if (unapprovedTransactions.length) {\n this.#start();\n } else {\n this.#stop();\n }\n });\n }\n\n #start() {\n if (this.#running) {\n return;\n }\n\n // Intentionally not awaiting since this starts the timeout chain.\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this.#onTimeout();\n\n this.#running = true;\n\n log('Started polling');\n }\n\n #stop() {\n if (!this.#running) {\n return;\n }\n\n clearTimeout(this.#timeout);\n\n this.#timeout = undefined;\n this.#running = false;\n\n log('Stopped polling');\n }\n\n async #onTimeout() {\n await this.#updateUnapprovedTransactions();\n\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.#timeout = setTimeout(() => this.#onTimeout(), INTERVAL_MILLISECONDS);\n }\n\n async #updateUnapprovedTransactions() {\n const unapprovedTransactions = this.#getUnapprovedTransactions();\n\n if (!unapprovedTransactions.length) {\n return;\n }\n\n log('Found unapproved transactions', unapprovedTransactions.length);\n\n const gasFeeControllerDataByChainId = await this.#getGasFeeControllerData(\n unapprovedTransactions,\n );\n\n log('Retrieved gas fee controller data', gasFeeControllerDataByChainId);\n\n await Promise.all(\n unapprovedTransactions.flatMap((tx) => {\n const { chainId } = tx;\n\n const gasFeeControllerData = gasFeeControllerDataByChainId.get(\n chainId,\n ) as GasFeeState;\n\n return this.#updateUnapprovedTransaction(tx, gasFeeControllerData);\n }),\n );\n }\n\n async #updateUnapprovedTransaction(\n transactionMeta: TransactionMeta,\n gasFeeControllerData: GasFeeState,\n ) {\n const { id } = transactionMeta;\n\n const [gasFeeEstimatesResponse, layer1GasFee] = await Promise.all([\n this.#updateTransactionGasFeeEstimates(\n transactionMeta,\n gasFeeControllerData,\n ),\n this.#updateTransactionLayer1GasFee(transactionMeta),\n ]);\n\n if (!gasFeeEstimatesResponse && !layer1GasFee) {\n return;\n }\n\n this.hub.emit('transaction-updated', {\n transactionId: id,\n gasFeeEstimates: gasFeeEstimatesResponse?.gasFeeEstimates,\n gasFeeEstimatesLoaded: gasFeeEstimatesResponse?.gasFeeEstimatesLoaded,\n layer1GasFee,\n });\n }\n\n async #updateTransactionGasFeeEstimates(\n transactionMeta: TransactionMeta,\n gasFeeControllerData: GasFeeState,\n ): Promise<\n | { gasFeeEstimates?: GasFeeEstimates; gasFeeEstimatesLoaded: boolean }\n | undefined\n > {\n const { chainId, networkClientId } = transactionMeta;\n\n const ethQuery = new EthQuery(this.#getProvider(chainId, networkClientId));\n const gasFeeFlow = getGasFeeFlow(transactionMeta, this.#gasFeeFlows);\n\n if (gasFeeFlow) {\n log(\n 'Found gas fee flow',\n gasFeeFlow.constructor.name,\n transactionMeta.id,\n );\n }\n\n const request: GasFeeFlowRequest = {\n ethQuery,\n gasFeeControllerData,\n transactionMeta,\n };\n\n let gasFeeEstimates: GasFeeEstimates | undefined;\n\n if (gasFeeFlow) {\n try {\n const response = await gasFeeFlow.getGasFees(request);\n gasFeeEstimates = response.estimates;\n } catch (error) {\n log('Failed to get suggested gas fees', transactionMeta.id, error);\n }\n }\n\n if (!gasFeeEstimates && transactionMeta.gasFeeEstimatesLoaded) {\n return undefined;\n }\n\n log('Updated gas fee estimates', {\n gasFeeEstimates,\n transaction: transactionMeta.id,\n });\n\n return { gasFeeEstimates, gasFeeEstimatesLoaded: true };\n }\n\n async #updateTransactionLayer1GasFee(\n transactionMeta: TransactionMeta,\n ): Promise<Hex | undefined> {\n const { chainId, networkClientId } = transactionMeta;\n const provider = this.#getProvider(chainId, networkClientId);\n\n const layer1GasFee = await getTransactionLayer1GasFee({\n layer1GasFeeFlows: this.#layer1GasFeeFlows,\n provider,\n transactionMeta,\n });\n\n if (layer1GasFee) {\n log('Updated layer 1 gas fee', layer1GasFee, transactionMeta.id);\n }\n\n return layer1GasFee;\n }\n\n #getUnapprovedTransactions() {\n return this.#getTransactions().filter(\n (tx) => tx.status === TransactionStatus.unapproved,\n );\n }\n\n async #getGasFeeControllerData(\n transactions: TransactionMeta[],\n ): Promise<Map<string, GasFeeState>> {\n const networkClientIdsByChainId = new Map<Hex, NetworkClientId>();\n\n for (const transaction of transactions) {\n const { chainId, networkClientId: transactionNetworkClientId } =\n transaction;\n\n if (networkClientIdsByChainId.has(chainId)) {\n continue;\n }\n\n const networkClientId =\n transactionNetworkClientId ??\n (this.#findNetworkClientIdByChainId(chainId) as string);\n\n networkClientIdsByChainId.set(chainId, networkClientId);\n }\n\n log('Extracted network client IDs by chain ID', networkClientIdsByChainId);\n\n const entryPromises = Array.from(networkClientIdsByChainId.entries()).map(\n async ([chainId, networkClientId]) => {\n return [\n chainId,\n await this.#getGasFeeControllerEstimates({ networkClientId }),\n ] as const;\n },\n );\n\n return new Map(await Promise.all(entryPromises));\n }\n}\n"]}
|