@metamask/transaction-controller 25.3.0 → 27.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 +34 -1
- package/dist/TransactionController.js +21 -19
- package/dist/TransactionController.mjs +20 -18
- package/dist/{chunk-UVKK5JBJ.mjs → chunk-35MG26Y3.mjs} +13 -12
- package/dist/chunk-35MG26Y3.mjs.map +1 -0
- package/dist/{chunk-5XBULBP2.js → chunk-5KMU2IAT.js} +3 -3
- package/dist/chunk-5KMU2IAT.js.map +1 -0
- package/dist/{chunk-R7NJVDWN.js → chunk-5WFLNKCL.js} +7 -6
- package/dist/chunk-5WFLNKCL.js.map +1 -0
- package/dist/{chunk-JRQHIBG5.mjs → chunk-5YES3V2R.mjs} +3 -3
- package/dist/chunk-5YES3V2R.mjs.map +1 -0
- package/dist/{chunk-US7NQPYE.js → chunk-6V2LR6JL.js} +7 -7
- package/dist/{chunk-CSQPJCBP.mjs → chunk-7HNSDVVO.mjs} +3 -3
- package/dist/{chunk-BYBPZUHS.mjs → chunk-A4P4B3OF.mjs} +14 -6
- package/dist/chunk-A4P4B3OF.mjs.map +1 -0
- package/dist/{chunk-F3CMU2DM.js → chunk-C3UHJPYJ.js} +6 -6
- package/dist/{chunk-Z3HHSD5I.mjs → chunk-DTMKGTYC.mjs} +3 -2
- package/dist/chunk-DTMKGTYC.mjs.map +1 -0
- package/dist/{chunk-MXQLW52B.js → chunk-FK7AP6SH.js} +10 -2
- package/dist/chunk-FK7AP6SH.js.map +1 -0
- package/dist/{chunk-ZQFMTLZJ.mjs → chunk-FTB6MCSH.mjs} +39 -24
- package/dist/chunk-FTB6MCSH.mjs.map +1 -0
- package/dist/{chunk-RQKICZYP.js → chunk-GRQB2ARK.js} +3 -3
- package/dist/{chunk-M6Q3DVMJ.mjs → chunk-H7O3Y7EQ.mjs} +63 -27
- package/dist/chunk-H7O3Y7EQ.mjs.map +1 -0
- package/dist/{chunk-XKNFL657.mjs → chunk-HLG525BC.mjs} +2 -2
- package/dist/chunk-HMOSP33F.js +36 -0
- package/dist/chunk-HMOSP33F.js.map +1 -0
- package/dist/chunk-HQSNKCXI.mjs +36 -0
- package/dist/chunk-HQSNKCXI.mjs.map +1 -0
- package/dist/{chunk-7YLATOE4.js → chunk-HUVOOFOM.js} +15 -14
- package/dist/chunk-HUVOOFOM.js.map +1 -0
- package/dist/{chunk-NRWEI43Q.js → chunk-I7VD6IET.js} +40 -25
- package/dist/chunk-I7VD6IET.js.map +1 -0
- package/dist/chunk-JW6P2G5A.mjs +132 -0
- package/dist/chunk-JW6P2G5A.mjs.map +1 -0
- package/dist/{chunk-6XMG522E.mjs → chunk-K4KOSAGM.mjs} +8 -3
- package/dist/chunk-K4KOSAGM.mjs.map +1 -0
- package/dist/{chunk-PVO55HHW.mjs → chunk-KKCD5UMP.mjs} +3 -3
- package/dist/{chunk-GE57YNGX.js → chunk-KT6UAKBB.js} +8 -3
- package/dist/chunk-KT6UAKBB.js.map +1 -0
- package/dist/chunk-QG2WVQE3.js +132 -0
- package/dist/chunk-QG2WVQE3.js.map +1 -0
- package/dist/{chunk-5OQ373JS.js → chunk-QTQSCTQA.js} +10 -10
- package/dist/{chunk-VEREDMI2.mjs → chunk-RIYIJTEU.mjs} +2 -2
- package/dist/{chunk-IZI7FQIN.mjs → chunk-RU6NJIUD.mjs} +3 -3
- package/dist/{chunk-3D3SA6PY.mjs → chunk-TJXPMOA6.mjs} +2 -2
- package/dist/{chunk-HXPG3DIX.mjs → chunk-TWND5SFD.mjs} +2 -2
- package/dist/{chunk-Z4FIWEAJ.mjs → chunk-TZEAWUXE.mjs} +3 -3
- package/dist/{chunk-GQYELPS3.js → chunk-UH7FNVKS.js} +4 -4
- package/dist/{chunk-SSYRMQ63.js → chunk-UUSYJGGQ.js} +5 -5
- package/dist/{chunk-GC77BSQZ.js → chunk-V5X6MZHN.js} +16 -8
- package/dist/chunk-V5X6MZHN.js.map +1 -0
- package/dist/{chunk-CXXGL43K.js → chunk-VP2DBWOT.js} +3 -3
- package/dist/{chunk-KFL2GGZC.mjs → chunk-W3CS5GRD.mjs} +7 -6
- package/dist/chunk-W3CS5GRD.mjs.map +1 -0
- package/dist/{chunk-ITDY6AIZ.js → chunk-WIZVJM2B.js} +3 -2
- package/dist/chunk-WIZVJM2B.js.map +1 -0
- package/dist/{chunk-CWJBSWH3.js → chunk-XZILQVNW.js} +6 -6
- package/dist/{chunk-LADOJTK4.mjs → chunk-YEJJKWT2.mjs} +10 -2
- package/dist/chunk-YEJJKWT2.mjs.map +1 -0
- package/dist/{chunk-7QOACSQU.js → chunk-YS23EOJX.js} +77 -41
- package/dist/chunk-YS23EOJX.js.map +1 -0
- package/dist/constants.js +2 -2
- package/dist/constants.mjs +1 -1
- package/dist/errors.js +15 -0
- package/dist/errors.js.map +1 -0
- package/dist/errors.mjs +15 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/gas-flows/DefaultGasFeeFlow.js +7 -7
- package/dist/gas-flows/DefaultGasFeeFlow.mjs +6 -6
- package/dist/gas-flows/LineaGasFeeFlow.js +8 -8
- package/dist/gas-flows/LineaGasFeeFlow.mjs +7 -7
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.js +10 -0
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.js.map +1 -0
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.mjs +10 -0
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.mjs.map +1 -0
- package/dist/helpers/EtherscanRemoteTransactionSource.js +5 -5
- package/dist/helpers/EtherscanRemoteTransactionSource.mjs +4 -4
- package/dist/helpers/GasFeePoller.js +5 -5
- package/dist/helpers/GasFeePoller.mjs +4 -4
- package/dist/helpers/MultichainTrackingHelper.js +6 -6
- package/dist/helpers/MultichainTrackingHelper.mjs +5 -5
- package/dist/helpers/PendingTransactionTracker.js +3 -3
- package/dist/helpers/PendingTransactionTracker.mjs +2 -2
- package/dist/index.js +25 -21
- package/dist/index.mjs +24 -20
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/TransactionController.d.ts +9 -1
- package/dist/types/TransactionController.d.ts.map +1 -1
- package/dist/types/constants.d.ts +1 -0
- package/dist/types/constants.d.ts.map +1 -1
- package/dist/types/errors.d.ts +15 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/gas-flows/OptimismLayer1GasFeeFlow.d.ts +10 -0
- package/dist/types/gas-flows/OptimismLayer1GasFeeFlow.d.ts.map +1 -0
- package/dist/types/helpers/GasFeePoller.d.ts +4 -5
- package/dist/types/helpers/GasFeePoller.d.ts.map +1 -1
- package/dist/types/helpers/MultichainTrackingHelper.d.ts +4 -0
- package/dist/types/helpers/MultichainTrackingHelper.d.ts.map +1 -1
- package/dist/types/helpers/PendingTransactionTracker.d.ts +1 -1
- package/dist/types/helpers/PendingTransactionTracker.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types.d.ts +10 -6
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/layer1-gas-fee-flow.d.ts +11 -2
- package/dist/types/utils/layer1-gas-fee-flow.d.ts.map +1 -1
- package/dist/types/utils/simulation-api.d.ts.map +1 -1
- 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/etherscan.js +3 -3
- package/dist/utils/etherscan.mjs +2 -2
- package/dist/utils/external-transactions.js +1 -1
- package/dist/utils/external-transactions.mjs +1 -1
- package/dist/utils/gas-fees.js +6 -6
- package/dist/utils/gas-fees.mjs +5 -5
- package/dist/utils/gas-flow.js +3 -3
- package/dist/utils/gas-flow.mjs +2 -2
- package/dist/utils/gas.js +3 -3
- package/dist/utils/gas.mjs +2 -2
- package/dist/utils/layer1-gas-fee-flow.js +4 -2
- package/dist/utils/layer1-gas-fee-flow.mjs +3 -1
- package/dist/utils/simulation-api.js +4 -2
- package/dist/utils/simulation-api.mjs +3 -1
- package/dist/utils/simulation.js +5 -4
- package/dist/utils/simulation.mjs +4 -3
- package/dist/utils/swaps.js +4 -4
- package/dist/utils/swaps.mjs +3 -3
- 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 +6 -4
- package/dist/chunk-5XBULBP2.js.map +0 -1
- package/dist/chunk-6XMG522E.mjs.map +0 -1
- package/dist/chunk-7QOACSQU.js.map +0 -1
- package/dist/chunk-7YLATOE4.js.map +0 -1
- package/dist/chunk-BYBPZUHS.mjs.map +0 -1
- package/dist/chunk-GC77BSQZ.js.map +0 -1
- package/dist/chunk-GE57YNGX.js.map +0 -1
- package/dist/chunk-ITDY6AIZ.js.map +0 -1
- package/dist/chunk-JRQHIBG5.mjs.map +0 -1
- package/dist/chunk-KFL2GGZC.mjs.map +0 -1
- package/dist/chunk-LADOJTK4.mjs.map +0 -1
- package/dist/chunk-M6Q3DVMJ.mjs.map +0 -1
- package/dist/chunk-MXQLW52B.js.map +0 -1
- package/dist/chunk-NRWEI43Q.js.map +0 -1
- package/dist/chunk-R7NJVDWN.js.map +0 -1
- package/dist/chunk-UVKK5JBJ.mjs.map +0 -1
- package/dist/chunk-Z3HHSD5I.mjs.map +0 -1
- package/dist/chunk-ZQFMTLZJ.mjs.map +0 -1
- /package/dist/{chunk-US7NQPYE.js.map → chunk-6V2LR6JL.js.map} +0 -0
- /package/dist/{chunk-CSQPJCBP.mjs.map → chunk-7HNSDVVO.mjs.map} +0 -0
- /package/dist/{chunk-F3CMU2DM.js.map → chunk-C3UHJPYJ.js.map} +0 -0
- /package/dist/{chunk-RQKICZYP.js.map → chunk-GRQB2ARK.js.map} +0 -0
- /package/dist/{chunk-XKNFL657.mjs.map → chunk-HLG525BC.mjs.map} +0 -0
- /package/dist/{chunk-PVO55HHW.mjs.map → chunk-KKCD5UMP.mjs.map} +0 -0
- /package/dist/{chunk-5OQ373JS.js.map → chunk-QTQSCTQA.js.map} +0 -0
- /package/dist/{chunk-VEREDMI2.mjs.map → chunk-RIYIJTEU.mjs.map} +0 -0
- /package/dist/{chunk-IZI7FQIN.mjs.map → chunk-RU6NJIUD.mjs.map} +0 -0
- /package/dist/{chunk-3D3SA6PY.mjs.map → chunk-TJXPMOA6.mjs.map} +0 -0
- /package/dist/{chunk-HXPG3DIX.mjs.map → chunk-TWND5SFD.mjs.map} +0 -0
- /package/dist/{chunk-Z4FIWEAJ.mjs.map → chunk-TZEAWUXE.mjs.map} +0 -0
- /package/dist/{chunk-GQYELPS3.js.map → chunk-UH7FNVKS.js.map} +0 -0
- /package/dist/{chunk-SSYRMQ63.js.map → chunk-UUSYJGGQ.js.map} +0 -0
- /package/dist/{chunk-CXXGL43K.js.map → chunk-VP2DBWOT.js.map} +0 -0
- /package/dist/{chunk-CWJBSWH3.js.map → chunk-XZILQVNW.js.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,37 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [27.0.0]
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- **BREAKING:** Change `pendingTransactions.isResubmitEnabled` from optional `boolean` to optional callback ([#4113](https://github.com/MetaMask/core/pull/4113))
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- Check pending transactions on startup ([#4113](https://github.com/MetaMask/core/pull/4113))
|
|
19
|
+
|
|
20
|
+
## [26.0.0]
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
|
|
24
|
+
- Run `OptimismLayer1GasFeeFlow` on Optimism stack based transactions in order to add `layer1GasFee` property to transaction meta. ([#4055](https://github.com/MetaMask/core/pull/4055))
|
|
25
|
+
- Add `getLayer1GasFee` method to `TransactionController` to get the layer 1 gas fee for the given transaction params ([#4055](https://github.com/MetaMask/core/pull/4055))
|
|
26
|
+
- Add `SimulationErrorCode` enum ([#4106](https://github.com/MetaMask/core/pull/4106))
|
|
27
|
+
|
|
28
|
+
### Changed
|
|
29
|
+
|
|
30
|
+
- **BREAKING:** Bump peer dependency `@metamask/gas-fee-controller` to `^15.0.0` ([#4121](https://github.com/MetaMask/core/pull/4121))
|
|
31
|
+
- Update `addTransaction` to skip simulation if `requireApproval` is specified as `false` ([#4106](https://github.com/MetaMask/core/pull/4106))
|
|
32
|
+
- Provide simulation error code in locally generated errors (under the `code` property) ([#4106](https://github.com/MetaMask/core/pull/4106))
|
|
33
|
+
- Add dependency `@ethersproject/contracts` `^5.7.0` ([#4055](https://github.com/MetaMask/core/pull/4055))
|
|
34
|
+
- Add dependency `@ethersproject/providers` `^5.7.0` ([#4055](https://github.com/MetaMask/core/pull/4055))
|
|
35
|
+
- Bump dependency `@metamask/network-controller` to `^18.1.0` ([#4121](https://github.com/MetaMask/core/pull/4121))
|
|
36
|
+
|
|
37
|
+
### Removed
|
|
38
|
+
|
|
39
|
+
- **BREAKING**: Remove `isReverted` property from `SimulationError` type. ([#4106](https://github.com/MetaMask/core/pull/4106))
|
|
40
|
+
|
|
10
41
|
## [25.3.0]
|
|
11
42
|
|
|
12
43
|
### Added
|
|
@@ -727,7 +758,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
727
758
|
|
|
728
759
|
All changes listed after this point were applied to this package following the monorepo conversion.
|
|
729
760
|
|
|
730
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@
|
|
761
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@27.0.0...HEAD
|
|
762
|
+
[27.0.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@26.0.0...@metamask/transaction-controller@27.0.0
|
|
763
|
+
[26.0.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@25.3.0...@metamask/transaction-controller@26.0.0
|
|
731
764
|
[25.3.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@25.2.1...@metamask/transaction-controller@25.3.0
|
|
732
765
|
[25.2.1]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@25.2.0...@metamask/transaction-controller@25.2.1
|
|
733
766
|
[25.2.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@25.1.0...@metamask/transaction-controller@25.2.0
|
|
@@ -4,31 +4,33 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkYS23EOJXjs = require('./chunk-YS23EOJX.js');
|
|
8
|
+
require('./chunk-SD6CWFDF.js');
|
|
8
9
|
require('./chunk-VH47Q6TS.js');
|
|
9
|
-
require('./chunk-
|
|
10
|
+
require('./chunk-GRQB2ARK.js');
|
|
10
11
|
require('./chunk-QP75SWIQ.js');
|
|
11
12
|
require('./chunk-ZNZEJDOE.js');
|
|
12
|
-
require('./chunk-
|
|
13
|
-
require('./chunk-
|
|
14
|
-
require('./chunk-
|
|
15
|
-
require('./chunk-
|
|
16
|
-
require('./chunk-
|
|
13
|
+
require('./chunk-V5X6MZHN.js');
|
|
14
|
+
require('./chunk-KT6UAKBB.js');
|
|
15
|
+
require('./chunk-QG2WVQE3.js');
|
|
16
|
+
require('./chunk-HUVOOFOM.js');
|
|
17
|
+
require('./chunk-5WFLNKCL.js');
|
|
17
18
|
require('./chunk-DTDTOMTB.js');
|
|
18
|
-
require('./chunk-
|
|
19
|
-
require('./chunk-
|
|
19
|
+
require('./chunk-I7VD6IET.js');
|
|
20
|
+
require('./chunk-C3UHJPYJ.js');
|
|
21
|
+
require('./chunk-5KMU2IAT.js');
|
|
22
|
+
require('./chunk-VP2DBWOT.js');
|
|
20
23
|
require('./chunk-7LXE4KHV.js');
|
|
21
|
-
require('./chunk-
|
|
22
|
-
require('./chunk-
|
|
23
|
-
require('./chunk-
|
|
24
|
-
require('./chunk-
|
|
24
|
+
require('./chunk-HMOSP33F.js');
|
|
25
|
+
require('./chunk-XZILQVNW.js');
|
|
26
|
+
require('./chunk-6V2LR6JL.js');
|
|
27
|
+
require('./chunk-UUSYJGGQ.js');
|
|
28
|
+
require('./chunk-QTQSCTQA.js');
|
|
25
29
|
require('./chunk-UGFBA4GV.js');
|
|
26
|
-
require('./chunk-
|
|
27
|
-
require('./chunk-
|
|
28
|
-
require('./chunk-CXXGL43K.js');
|
|
29
|
-
require('./chunk-ITDY6AIZ.js');
|
|
30
|
+
require('./chunk-UH7FNVKS.js');
|
|
31
|
+
require('./chunk-WIZVJM2B.js');
|
|
30
32
|
require('./chunk-S6VGOPUY.js');
|
|
31
|
-
require('./chunk-
|
|
33
|
+
require('./chunk-FK7AP6SH.js');
|
|
32
34
|
require('./chunk-Z4BLTVTB.js');
|
|
33
35
|
|
|
34
36
|
|
|
@@ -36,5 +38,5 @@ require('./chunk-Z4BLTVTB.js');
|
|
|
36
38
|
|
|
37
39
|
|
|
38
40
|
|
|
39
|
-
exports.ApprovalState =
|
|
41
|
+
exports.ApprovalState = _chunkYS23EOJXjs.ApprovalState; exports.CANCEL_RATE = _chunkYS23EOJXjs.CANCEL_RATE; exports.HARDFORK = _chunkYS23EOJXjs.HARDFORK; exports.SPEED_UP_RATE = _chunkYS23EOJXjs.SPEED_UP_RATE; exports.TransactionController = _chunkYS23EOJXjs.TransactionController;
|
|
40
42
|
//# sourceMappingURL=TransactionController.js.map
|
|
@@ -4,31 +4,33 @@ import {
|
|
|
4
4
|
HARDFORK,
|
|
5
5
|
SPEED_UP_RATE,
|
|
6
6
|
TransactionController
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-H7O3Y7EQ.mjs";
|
|
8
|
+
import "./chunk-KG4UW4K4.mjs";
|
|
8
9
|
import "./chunk-NM6OYEPP.mjs";
|
|
9
|
-
import "./chunk-
|
|
10
|
+
import "./chunk-HLG525BC.mjs";
|
|
10
11
|
import "./chunk-XGRAHX6T.mjs";
|
|
11
12
|
import "./chunk-NHRBO3LU.mjs";
|
|
12
|
-
import "./chunk-
|
|
13
|
-
import "./chunk-
|
|
14
|
-
import "./chunk-
|
|
15
|
-
import "./chunk-
|
|
16
|
-
import "./chunk-
|
|
13
|
+
import "./chunk-A4P4B3OF.mjs";
|
|
14
|
+
import "./chunk-K4KOSAGM.mjs";
|
|
15
|
+
import "./chunk-JW6P2G5A.mjs";
|
|
16
|
+
import "./chunk-35MG26Y3.mjs";
|
|
17
|
+
import "./chunk-W3CS5GRD.mjs";
|
|
17
18
|
import "./chunk-Y7ENNK7L.mjs";
|
|
18
|
-
import "./chunk-
|
|
19
|
-
import "./chunk-
|
|
19
|
+
import "./chunk-FTB6MCSH.mjs";
|
|
20
|
+
import "./chunk-RU6NJIUD.mjs";
|
|
21
|
+
import "./chunk-5YES3V2R.mjs";
|
|
22
|
+
import "./chunk-RIYIJTEU.mjs";
|
|
20
23
|
import "./chunk-FRKQ3Z2L.mjs";
|
|
21
|
-
import "./chunk-
|
|
22
|
-
import "./chunk-
|
|
23
|
-
import "./chunk-
|
|
24
|
-
import "./chunk-
|
|
24
|
+
import "./chunk-HQSNKCXI.mjs";
|
|
25
|
+
import "./chunk-7HNSDVVO.mjs";
|
|
26
|
+
import "./chunk-KKCD5UMP.mjs";
|
|
27
|
+
import "./chunk-TZEAWUXE.mjs";
|
|
28
|
+
import "./chunk-TJXPMOA6.mjs";
|
|
25
29
|
import "./chunk-J56A7UCK.mjs";
|
|
26
|
-
import "./chunk-
|
|
27
|
-
import "./chunk-
|
|
28
|
-
import "./chunk-VEREDMI2.mjs";
|
|
29
|
-
import "./chunk-Z3HHSD5I.mjs";
|
|
30
|
+
import "./chunk-TWND5SFD.mjs";
|
|
31
|
+
import "./chunk-DTMKGTYC.mjs";
|
|
30
32
|
import "./chunk-UQQWZT6C.mjs";
|
|
31
|
-
import "./chunk-
|
|
33
|
+
import "./chunk-YEJJKWT2.mjs";
|
|
32
34
|
import "./chunk-XUI43LEZ.mjs";
|
|
33
35
|
export {
|
|
34
36
|
ApprovalState,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
updateTransactionLayer1GasFee
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-W3CS5GRD.mjs";
|
|
4
4
|
import {
|
|
5
5
|
getGasFeeFlow
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-TWND5SFD.mjs";
|
|
7
7
|
import {
|
|
8
8
|
projectLogger
|
|
9
9
|
} from "./chunk-UQQWZT6C.mjs";
|
|
@@ -15,26 +15,27 @@ import {
|
|
|
15
15
|
} from "./chunk-XUI43LEZ.mjs";
|
|
16
16
|
|
|
17
17
|
// src/helpers/GasFeePoller.ts
|
|
18
|
+
import EthQuery from "@metamask/eth-query";
|
|
18
19
|
import { createModuleLogger } from "@metamask/utils";
|
|
19
20
|
import EventEmitter from "events";
|
|
20
21
|
var log = createModuleLogger(projectLogger, "gas-fee-poller");
|
|
21
22
|
var INTERVAL_MILLISECONDS = 1e4;
|
|
22
|
-
var _gasFeeFlows,
|
|
23
|
+
var _gasFeeFlows, _getGasFeeControllerEstimates, _getProvider, _getTransactions, _layer1GasFeeFlows, _timeout, _running, _start, start_fn, _stop, stop_fn, _onTimeout, onTimeout_fn, _updateTransactionGasFeeEstimates, updateTransactionGasFeeEstimates_fn, _updateTransactionSuggestedFees, updateTransactionSuggestedFees_fn, _updateTransactionLayer1GasFee, updateTransactionLayer1GasFee_fn, _getUnapprovedTransactions, getUnapprovedTransactions_fn;
|
|
23
24
|
var GasFeePoller = class {
|
|
24
25
|
/**
|
|
25
26
|
* Constructs a new instance of the GasFeePoller.
|
|
26
27
|
* @param options - The options for this instance.
|
|
27
28
|
* @param options.gasFeeFlows - The gas fee flows to use to obtain suitable gas fees.
|
|
28
|
-
* @param options.getEthQuery - Callback to obtain an EthQuery instance.
|
|
29
29
|
* @param options.getGasFeeControllerEstimates - Callback to obtain the default fee estimates.
|
|
30
|
+
* @param options.getProvider - Callback to obtain a provider instance.
|
|
30
31
|
* @param options.getTransactions - Callback to obtain the transaction data.
|
|
31
32
|
* @param options.layer1GasFeeFlows - The layer 1 gas fee flows to use to obtain suitable layer 1 gas fees.
|
|
32
33
|
* @param options.onStateChange - Callback to register a listener for controller state changes.
|
|
33
34
|
*/
|
|
34
35
|
constructor({
|
|
35
36
|
gasFeeFlows,
|
|
36
|
-
getEthQuery,
|
|
37
37
|
getGasFeeControllerEstimates,
|
|
38
|
+
getProvider,
|
|
38
39
|
getTransactions,
|
|
39
40
|
layer1GasFeeFlows,
|
|
40
41
|
onStateChange
|
|
@@ -48,16 +49,16 @@ var GasFeePoller = class {
|
|
|
48
49
|
__privateAdd(this, _getUnapprovedTransactions);
|
|
49
50
|
this.hub = new EventEmitter();
|
|
50
51
|
__privateAdd(this, _gasFeeFlows, void 0);
|
|
51
|
-
__privateAdd(this, _getEthQuery, void 0);
|
|
52
52
|
__privateAdd(this, _getGasFeeControllerEstimates, void 0);
|
|
53
|
+
__privateAdd(this, _getProvider, void 0);
|
|
53
54
|
__privateAdd(this, _getTransactions, void 0);
|
|
54
55
|
__privateAdd(this, _layer1GasFeeFlows, void 0);
|
|
55
56
|
__privateAdd(this, _timeout, void 0);
|
|
56
57
|
__privateAdd(this, _running, false);
|
|
57
58
|
__privateSet(this, _gasFeeFlows, gasFeeFlows);
|
|
58
59
|
__privateSet(this, _layer1GasFeeFlows, layer1GasFeeFlows);
|
|
59
|
-
__privateSet(this, _getEthQuery, getEthQuery);
|
|
60
60
|
__privateSet(this, _getGasFeeControllerEstimates, getGasFeeControllerEstimates);
|
|
61
|
+
__privateSet(this, _getProvider, getProvider);
|
|
61
62
|
__privateSet(this, _getTransactions, getTransactions);
|
|
62
63
|
onStateChange(() => {
|
|
63
64
|
const unapprovedTransactions = __privateMethod(this, _getUnapprovedTransactions, getUnapprovedTransactions_fn).call(this);
|
|
@@ -70,8 +71,8 @@ var GasFeePoller = class {
|
|
|
70
71
|
}
|
|
71
72
|
};
|
|
72
73
|
_gasFeeFlows = new WeakMap();
|
|
73
|
-
_getEthQuery = new WeakMap();
|
|
74
74
|
_getGasFeeControllerEstimates = new WeakMap();
|
|
75
|
+
_getProvider = new WeakMap();
|
|
75
76
|
_getTransactions = new WeakMap();
|
|
76
77
|
_layer1GasFeeFlows = new WeakMap();
|
|
77
78
|
_timeout = new WeakMap();
|
|
@@ -116,7 +117,7 @@ updateTransactionGasFeeEstimates_fn = async function() {
|
|
|
116
117
|
_updateTransactionSuggestedFees = new WeakSet();
|
|
117
118
|
updateTransactionSuggestedFees_fn = async function(transactionMeta) {
|
|
118
119
|
const { chainId, networkClientId } = transactionMeta;
|
|
119
|
-
const ethQuery = __privateGet(this,
|
|
120
|
+
const ethQuery = new EthQuery(__privateGet(this, _getProvider).call(this, chainId, networkClientId));
|
|
120
121
|
const gasFeeFlow = getGasFeeFlow(transactionMeta, __privateGet(this, _gasFeeFlows));
|
|
121
122
|
if (!gasFeeFlow) {
|
|
122
123
|
log("No gas fee flow found", transactionMeta.id);
|
|
@@ -158,9 +159,9 @@ updateTransactionSuggestedFees_fn = async function(transactionMeta) {
|
|
|
158
159
|
_updateTransactionLayer1GasFee = new WeakSet();
|
|
159
160
|
updateTransactionLayer1GasFee_fn = async function(transactionMeta) {
|
|
160
161
|
const { chainId, networkClientId } = transactionMeta;
|
|
161
|
-
const
|
|
162
|
+
const provider = __privateGet(this, _getProvider).call(this, chainId, networkClientId);
|
|
162
163
|
await updateTransactionLayer1GasFee({
|
|
163
|
-
|
|
164
|
+
provider,
|
|
164
165
|
layer1GasFeeFlows: __privateGet(this, _layer1GasFeeFlows),
|
|
165
166
|
transactionMeta
|
|
166
167
|
});
|
|
@@ -179,4 +180,4 @@ getUnapprovedTransactions_fn = function() {
|
|
|
179
180
|
export {
|
|
180
181
|
GasFeePoller
|
|
181
182
|
};
|
|
182
|
-
//# sourceMappingURL=chunk-
|
|
183
|
+
//# sourceMappingURL=chunk-35MG26Y3.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/helpers/GasFeePoller.ts"],"sourcesContent":["import EthQuery from '@metamask/eth-query';\nimport type { GasFeeState } 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 { updateTransactionLayer1GasFee } 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 #gasFeeFlows: GasFeeFlow[];\n\n #getGasFeeControllerEstimates: () => 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.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 gasFeeFlows,\n getGasFeeControllerEstimates,\n getProvider,\n getTransactions,\n layer1GasFeeFlows,\n onStateChange,\n }: {\n gasFeeFlows: GasFeeFlow[];\n getGasFeeControllerEstimates: () => Promise<GasFeeState>;\n getProvider: (chainId: Hex, networkClientId?: NetworkClientId) => Provider;\n getTransactions: () => TransactionMeta[];\n layer1GasFeeFlows: Layer1GasFeeFlow[];\n onStateChange: (listener: () => void) => void;\n }) {\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.#updateTransactionGasFeeEstimates();\n\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.#timeout = setTimeout(() => this.#onTimeout(), INTERVAL_MILLISECONDS);\n }\n\n async #updateTransactionGasFeeEstimates() {\n const unapprovedTransactions = this.#getUnapprovedTransactions();\n\n log('Found unapproved transactions', {\n count: unapprovedTransactions.length,\n });\n\n await Promise.all(\n unapprovedTransactions.flatMap((tx) => [\n this.#updateTransactionSuggestedFees(tx),\n this.#updateTransactionLayer1GasFee(tx),\n ]),\n );\n }\n\n async #updateTransactionSuggestedFees(transactionMeta: TransactionMeta) {\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('No gas fee flow found', transactionMeta.id);\n } else {\n log(\n 'Found gas fee flow',\n gasFeeFlow.constructor.name,\n transactionMeta.id,\n );\n }\n\n const request: GasFeeFlowRequest = {\n ethQuery,\n getGasFeeControllerEstimates: this.#getGasFeeControllerEstimates,\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;\n }\n\n const updatedTransactionMeta: TransactionMeta = {\n ...transactionMeta,\n gasFeeEstimates,\n gasFeeEstimatesLoaded: true,\n };\n\n this.hub.emit('transaction-updated', updatedTransactionMeta);\n\n log('Updated suggested gas fees', {\n gasFeeEstimates: updatedTransactionMeta.gasFeeEstimates,\n transaction: updatedTransactionMeta.id,\n });\n }\n\n async #updateTransactionLayer1GasFee(transactionMeta: TransactionMeta) {\n const { chainId, networkClientId } = transactionMeta;\n const provider = this.#getProvider(chainId, networkClientId);\n\n await updateTransactionLayer1GasFee({\n provider,\n layer1GasFeeFlows: this.#layer1GasFeeFlows,\n transactionMeta,\n });\n\n if (transactionMeta.layer1GasFee === undefined) {\n return;\n }\n\n this.hub.emit('transaction-updated', transactionMeta);\n }\n\n #getUnapprovedTransactions() {\n return this.#getTransactions().filter(\n (tx) => tx.status === TransactionStatus.unapproved,\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA,OAAO,cAAc;AAIrB,SAAS,0BAA0B;AACnC,OAAO,kBAAkB;AAazB,IAAM,MAAM,mBAAmB,eAAe,gBAAgB;AAE9D,IAAM,wBAAwB;AApB9B;AAyBO,IAAM,eAAN,MAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA2BxB,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AA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kBAAL,WAAwB;AAAA,IAC7B,CAAC,OAAO,GAAG;AAAA,EACb;AACF;","names":[]}
|
|
@@ -89,7 +89,7 @@ var PendingTransactionTracker = class {
|
|
|
89
89
|
_chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _getChainId, getChainId);
|
|
90
90
|
_chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _getEthQuery, getEthQuery);
|
|
91
91
|
_chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _getTransactions, getTransactions);
|
|
92
|
-
_chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _isResubmitEnabled, isResubmitEnabled ?? true);
|
|
92
|
+
_chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _isResubmitEnabled, isResubmitEnabled ?? (() => true));
|
|
93
93
|
_chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _listener, _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _onLatestBlock, onLatestBlock_fn).bind(this));
|
|
94
94
|
_chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _getGlobalLock, getGlobalLock);
|
|
95
95
|
_chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _publishTransaction, publishTransaction);
|
|
@@ -177,7 +177,7 @@ checkTransactions_fn = async function() {
|
|
|
177
177
|
};
|
|
178
178
|
_resubmitTransactions = new WeakSet();
|
|
179
179
|
resubmitTransactions_fn = async function(latestBlockNumber) {
|
|
180
|
-
if (!_chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _isResubmitEnabled) || !_chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _running)) {
|
|
180
|
+
if (!_chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _isResubmitEnabled).call(this) || !_chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _running)) {
|
|
181
181
|
return;
|
|
182
182
|
}
|
|
183
183
|
log("Resubmitting transactions");
|
|
@@ -396,4 +396,4 @@ getCurrentChainTransactions_fn = function() {
|
|
|
396
396
|
|
|
397
397
|
|
|
398
398
|
exports.PendingTransactionTracker = PendingTransactionTracker;
|
|
399
|
-
//# sourceMappingURL=chunk-
|
|
399
|
+
//# sourceMappingURL=chunk-5KMU2IAT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/helpers/PendingTransactionTracker.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,SAAS,aAAa;AAMtB,OAAO,kBAAkB;AACzB,SAAS,WAAW,aAAa;AAUjC,IAAM,sBAAsB;AAE5B,IAAM,yBAAyB;AAC/B,IAAM,yBAAyB;AAC/B,IAAM,2BAA2B;AAEjC,IAAM,2BAA2B;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,IAAM,MAAM,mBAAmB,eAAe,sBAAsB;AAhCpE;AA0DO,IAAM,4BAAN,MAAgC;AAAA,EA+BrC,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAeG;AA+CH;AAsBA,uBAAM;AAoBN,uBAAM;AAoBN,uBAAM;AA2CN;AAMA,uBAAM;AA+BN;AA8BA,uBAAM;AAmEN,uBAAM;AA+BN,uBAAM;AAuCN;AAaA;AASA;AAUA;AAKA;AAKA;AAIA,uBAAM;AAMN,uBAAM;AAYN,uBAAM;AAIN;AA7dA;AAEA;AAEA;AAEA;AAEA;AAEA;AAEA;AAIA;AAAA;AAAA;AAEA;AAEA;AAEA;AAEA;AAEA;AA8CA,sCAA6B,MAAM;AACjC,YAAM,sBAAsB,sBAAK,oDAAL;AAE5B,UAAI,oBAAoB,QAAQ;AAC9B,8BAAK,kBAAL;AAAA,MACF,OAAO;AACL,aAAK,KAAK;AAAA,MACZ;AAAA,IACF;AA1BE,SAAK,MAAM,IAAI,aAAa;AAE5B,uBAAK,qBAAsB;AAC3B,uBAAK,eAAgB;AACrB,uBAAK,0BAA2B,oBAAI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A;AAAA,qBAAgB,SAAC,QAAyB,OAAc;AACtD,MAAI,sBAAsB,OAAO,IAAI,KAAK;AAC1C,OAAK,IAAI,KAAK,sBAAsB,QAAQ,KAAK;AACnD;AAEA;AAAA,qBAAgB,SAAC,QAAyB;AACxC,MAAI,uBAAuB,OAAO,EAAE;AACpC,OAAK,IAAI,KAAK,uBAAuB,MAAM;AAC7C;AAEA;AAAA,uBAAkB,SAAC,QAAyB,MAAc;AACxD,OAAK,IAAI,KAAK,uBAAuB,QAAQ,IAAI;AACnD;AAEM;AAAA,2BAAsB,eAC1B,QACyC;AACzC,SAAO,MAAM,MAAM,mBAAK,cAAL,YAAqB,yBAAyB,CAAC,MAAM,CAAC;AAC3E;AAEM;AAAA,oBAAe,eACnB,WACA,2BAGc;AACd,SAAO,MAAM,MAAM,mBAAK,cAAL,YAAqB,kBAAkB;AAAA,IACxD;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAEM;AAAA,gCAA2B,eAAC,SAAkC;AAClE,SAAO,MAAM,MAAM,mBAAK,cAAL,YAAqB,uBAAuB,CAAC,OAAO,CAAC;AAC1E;AAEA;AAAA,iCAA4B,WAAsB;AAChD,QAAM,iBAAiB,mBAAK,aAAL;AAEvB,SAAO,mBAAK,kBAAL,WAAwB;AAAA,IAC7B,CAAC,OAAO,GAAG,YAAY;AAAA,EACzB;AACF","sourcesContent":["import { query } from '@metamask/controller-utils';\nimport type EthQuery from '@metamask/eth-query';\nimport type {\n BlockTracker,\n NetworkClientId,\n} from '@metamask/network-controller';\nimport EventEmitter from 'events';\nimport { cloneDeep, merge } from 'lodash';\n\nimport { createModuleLogger, projectLogger } from '../logger';\nimport type { TransactionMeta, TransactionReceipt } from '../types';\nimport { TransactionStatus, TransactionType } from '../types';\n\n/**\n * We wait this many blocks before emitting a 'transaction-dropped' event\n * This is because we could be talking to a node that is out of sync\n */\nconst DROPPED_BLOCK_COUNT = 3;\n\nconst RECEIPT_STATUS_SUCCESS = '0x1';\nconst RECEIPT_STATUS_FAILURE = '0x0';\nconst MAX_RETRY_BLOCK_DISTANCE = 50;\n\nconst KNOWN_TRANSACTION_ERRORS = [\n 'replacement transaction underpriced',\n 'known transaction',\n 'gas price too low to replace',\n 'transaction with the same hash was already imported',\n 'gateway timeout',\n 'nonce too low',\n];\n\nconst log = createModuleLogger(projectLogger, 'pending-transactions');\n\ntype SuccessfulTransactionReceipt = TransactionReceipt & {\n blockNumber: string;\n blockHash: string;\n};\n\ntype Events = {\n 'transaction-confirmed': [txMeta: TransactionMeta];\n 'transaction-dropped': [txMeta: TransactionMeta];\n 'transaction-failed': [txMeta: TransactionMeta, error: Error];\n 'transaction-updated': [txMeta: TransactionMeta, note: string];\n};\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 PendingTransactionTrackerEventEmitter extends EventEmitter {\n on<T extends keyof Events>(\n eventName: T,\n listener: (...args: Events[T]) => void,\n ): this;\n\n emit<T extends keyof Events>(eventName: T, ...args: Events[T]): boolean;\n}\n\nexport class PendingTransactionTracker {\n hub: PendingTransactionTrackerEventEmitter;\n\n #approveTransaction: (transactionId: string) => Promise<void>;\n\n #blockTracker: BlockTracker;\n\n #droppedBlockCountByHash: Map<string, number>;\n\n #getChainId: () => string;\n\n #getEthQuery: (networkClientId?: NetworkClientId) => EthQuery;\n\n #getTransactions: () => TransactionMeta[];\n\n #isResubmitEnabled: () => boolean;\n\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n #listener: any;\n\n #getGlobalLock: () => Promise<() => void>;\n\n #publishTransaction: (ethQuery: EthQuery, rawTx: string) => Promise<string>;\n\n #running: boolean;\n\n #beforeCheckPendingTransaction: (transactionMeta: TransactionMeta) => boolean;\n\n #beforePublish: (transactionMeta: TransactionMeta) => boolean;\n\n constructor({\n approveTransaction,\n blockTracker,\n getChainId,\n getEthQuery,\n getTransactions,\n isResubmitEnabled,\n getGlobalLock,\n publishTransaction,\n hooks,\n }: {\n approveTransaction: (transactionId: string) => Promise<void>;\n blockTracker: BlockTracker;\n getChainId: () => string;\n getEthQuery: (networkClientId?: NetworkClientId) => EthQuery;\n getTransactions: () => TransactionMeta[];\n isResubmitEnabled?: () => boolean;\n getGlobalLock: () => Promise<() => void>;\n publishTransaction: (ethQuery: EthQuery, rawTx: string) => Promise<string>;\n hooks?: {\n beforeCheckPendingTransaction?: (\n transactionMeta: TransactionMeta,\n ) => boolean;\n beforePublish?: (transactionMeta: TransactionMeta) => boolean;\n };\n }) {\n this.hub = new EventEmitter() as PendingTransactionTrackerEventEmitter;\n\n this.#approveTransaction = approveTransaction;\n this.#blockTracker = blockTracker;\n this.#droppedBlockCountByHash = new Map();\n this.#getChainId = getChainId;\n this.#getEthQuery = getEthQuery;\n this.#getTransactions = getTransactions;\n this.#isResubmitEnabled = isResubmitEnabled ?? (() => true);\n this.#listener = this.#onLatestBlock.bind(this);\n this.#getGlobalLock = getGlobalLock;\n this.#publishTransaction = publishTransaction;\n this.#running = false;\n this.#beforePublish = hooks?.beforePublish ?? (() => true);\n this.#beforeCheckPendingTransaction =\n hooks?.beforeCheckPendingTransaction ?? (() => true);\n }\n\n startIfPendingTransactions = () => {\n const pendingTransactions = this.#getPendingTransactions();\n\n if (pendingTransactions.length) {\n this.#start();\n } else {\n this.stop();\n }\n };\n\n /**\n * Force checks the network if the given transaction is confirmed and updates it's status.\n *\n * @param txMeta - The transaction to check\n */\n async forceCheckTransaction(txMeta: TransactionMeta) {\n const releaseLock = await this.#getGlobalLock();\n\n try {\n await this.#checkTransaction(txMeta);\n } catch (error) {\n /* istanbul ignore next */\n log('Failed to check transaction', error);\n } finally {\n releaseLock();\n }\n }\n\n #start() {\n if (this.#running) {\n return;\n }\n\n this.#blockTracker.on('latest', this.#listener);\n this.#running = true;\n\n log('Started polling');\n }\n\n stop() {\n if (!this.#running) {\n return;\n }\n\n this.#blockTracker.removeListener('latest', this.#listener);\n this.#running = false;\n\n log('Stopped polling');\n }\n\n async #onLatestBlock(latestBlockNumber: string) {\n const releaseLock = await this.#getGlobalLock();\n\n try {\n await this.#checkTransactions();\n } catch (error) {\n /* istanbul ignore next */\n log('Failed to check transactions', error);\n } finally {\n releaseLock();\n }\n\n try {\n await this.#resubmitTransactions(latestBlockNumber);\n } catch (error) {\n /* istanbul ignore next */\n log('Failed to resubmit transactions', error);\n }\n }\n\n async #checkTransactions() {\n log('Checking transactions');\n\n const pendingTransactions = this.#getPendingTransactions();\n\n if (!pendingTransactions.length) {\n log('No pending transactions to check');\n return;\n }\n\n log('Found pending transactions to check', {\n count: pendingTransactions.length,\n ids: pendingTransactions.map((tx) => tx.id),\n });\n\n await Promise.all(\n pendingTransactions.map((tx) => this.#checkTransaction(tx)),\n );\n }\n\n async #resubmitTransactions(latestBlockNumber: string) {\n if (!this.#isResubmitEnabled() || !this.#running) {\n return;\n }\n\n log('Resubmitting transactions');\n\n const pendingTransactions = this.#getPendingTransactions();\n\n if (!pendingTransactions.length) {\n log('No pending transactions to resubmit');\n return;\n }\n\n log('Found pending transactions to resubmit', {\n count: pendingTransactions.length,\n ids: pendingTransactions.map((tx) => tx.id),\n });\n\n for (const txMeta of pendingTransactions) {\n try {\n await this.#resubmitTransaction(txMeta, latestBlockNumber);\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n /* istanbul ignore next */\n const errorMessage =\n error.value?.message?.toLowerCase() || error.message.toLowerCase();\n\n if (this.#isKnownTransactionError(errorMessage)) {\n log('Ignoring known transaction error', errorMessage);\n return;\n }\n\n this.#warnTransaction(\n txMeta,\n error.message,\n 'There was an error when resubmitting this transaction.',\n );\n }\n }\n }\n\n #isKnownTransactionError(errorMessage: string) {\n return KNOWN_TRANSACTION_ERRORS.some((knownError) =>\n errorMessage.includes(knownError),\n );\n }\n\n async #resubmitTransaction(\n txMeta: TransactionMeta,\n latestBlockNumber: string,\n ) {\n if (!this.#isResubmitDue(txMeta, latestBlockNumber)) {\n return;\n }\n\n const { rawTx } = txMeta;\n\n if (!this.#beforePublish(txMeta)) {\n return;\n }\n\n if (!rawTx?.length) {\n log('Approving transaction as no raw value');\n await this.#approveTransaction(txMeta.id);\n return;\n }\n\n const ethQuery = this.#getEthQuery(txMeta.networkClientId);\n await this.#publishTransaction(ethQuery, rawTx);\n\n const retryCount = (txMeta.retryCount ?? 0) + 1;\n\n this.#updateTransaction(\n merge({}, txMeta, { retryCount }),\n 'PendingTransactionTracker:transaction-retry - Retry count increased',\n );\n }\n\n #isResubmitDue(txMeta: TransactionMeta, latestBlockNumber: string): boolean {\n const txMetaWithFirstRetryBlockNumber = cloneDeep(txMeta);\n\n if (!txMetaWithFirstRetryBlockNumber.firstRetryBlockNumber) {\n txMetaWithFirstRetryBlockNumber.firstRetryBlockNumber = latestBlockNumber;\n\n this.#updateTransaction(\n txMetaWithFirstRetryBlockNumber,\n 'PendingTransactionTracker:#isResubmitDue - First retry block number set',\n );\n }\n\n const { firstRetryBlockNumber } = txMetaWithFirstRetryBlockNumber;\n\n const blocksSinceFirstRetry =\n Number.parseInt(latestBlockNumber, 16) -\n Number.parseInt(firstRetryBlockNumber, 16);\n\n const retryCount = txMeta.retryCount || 0;\n\n // Exponential backoff to limit retries at publishing\n // Capped at ~15 minutes between retries\n const requiredBlocksSinceFirstRetry = Math.min(\n MAX_RETRY_BLOCK_DISTANCE,\n Math.pow(2, retryCount),\n );\n\n return blocksSinceFirstRetry >= requiredBlocksSinceFirstRetry;\n }\n\n async #checkTransaction(txMeta: TransactionMeta) {\n const { hash, id } = txMeta;\n\n if (!hash && this.#beforeCheckPendingTransaction(txMeta)) {\n const error = new Error(\n 'We had an error while submitting this transaction, please try again.',\n );\n\n error.name = 'NoTxHashError';\n\n this.#failTransaction(txMeta, error);\n\n return;\n }\n\n if (this.#isNonceTaken(txMeta)) {\n log('Nonce already taken', id);\n this.#dropTransaction(txMeta);\n return;\n }\n\n try {\n const receipt = await this.#getTransactionReceipt(hash);\n const isSuccess = receipt?.status === RECEIPT_STATUS_SUCCESS;\n const isFailure = receipt?.status === RECEIPT_STATUS_FAILURE;\n\n if (isFailure) {\n log('Transaction receipt has failed status');\n\n this.#failTransaction(\n txMeta,\n new Error('Transaction dropped or replaced'),\n );\n\n return;\n }\n\n const { blockNumber, blockHash } = receipt || {};\n\n if (isSuccess && blockNumber && blockHash) {\n await this.#onTransactionConfirmed(txMeta, {\n ...receipt,\n blockNumber,\n blockHash,\n });\n\n return;\n }\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n log('Failed to check transaction', id, error);\n\n this.#warnTransaction(\n txMeta,\n error.message,\n 'There was a problem loading this transaction.',\n );\n\n return;\n }\n\n if (await this.#isTransactionDropped(txMeta)) {\n this.#dropTransaction(txMeta);\n }\n }\n\n async #onTransactionConfirmed(\n txMeta: TransactionMeta,\n receipt: SuccessfulTransactionReceipt,\n ) {\n const { id } = txMeta;\n const { blockHash } = receipt;\n\n log('Transaction confirmed', id);\n\n const { baseFeePerGas, timestamp: blockTimestamp } =\n await this.#getBlockByHash(blockHash, false);\n\n const updatedTxMeta = cloneDeep(txMeta);\n updatedTxMeta.baseFeePerGas = baseFeePerGas;\n updatedTxMeta.blockTimestamp = blockTimestamp;\n updatedTxMeta.status = TransactionStatus.confirmed;\n updatedTxMeta.txParams = {\n ...updatedTxMeta.txParams,\n gasUsed: receipt.gasUsed,\n };\n updatedTxMeta.txReceipt = receipt;\n updatedTxMeta.verifiedOnBlockchain = true;\n\n this.#updateTransaction(\n updatedTxMeta,\n 'PendingTransactionTracker:#onTransactionConfirmed - Transaction confirmed',\n );\n\n this.hub.emit('transaction-confirmed', updatedTxMeta);\n }\n\n async #isTransactionDropped(txMeta: TransactionMeta) {\n const {\n hash,\n id,\n txParams: { nonce, from },\n } = txMeta;\n\n /* istanbul ignore next */\n if (!nonce || !hash) {\n return false;\n }\n\n const networkNextNonceHex = await this.#getNetworkTransactionCount(from);\n const networkNextNonceNumber = parseInt(networkNextNonceHex, 16);\n const nonceNumber = parseInt(nonce, 16);\n\n if (nonceNumber >= networkNextNonceNumber) {\n return false;\n }\n\n let droppedBlockCount = this.#droppedBlockCountByHash.get(hash);\n\n if (droppedBlockCount === undefined) {\n droppedBlockCount = 0;\n this.#droppedBlockCountByHash.set(hash, droppedBlockCount);\n }\n\n if (droppedBlockCount < DROPPED_BLOCK_COUNT) {\n log('Incrementing dropped block count', { id, droppedBlockCount });\n this.#droppedBlockCountByHash.set(hash, droppedBlockCount + 1);\n return false;\n }\n\n log('Hit dropped block count', id);\n\n this.#droppedBlockCountByHash.delete(hash);\n return true;\n }\n\n #isNonceTaken(txMeta: TransactionMeta): boolean {\n const { id, txParams } = txMeta;\n\n return this.#getCurrentChainTransactions().some(\n (tx) =>\n tx.id !== id &&\n tx.txParams.from === txParams.from &&\n tx.status === TransactionStatus.confirmed &&\n tx.txParams.nonce === txParams.nonce &&\n tx.type !== TransactionType.incoming,\n );\n }\n\n #getPendingTransactions(): TransactionMeta[] {\n return this.#getCurrentChainTransactions().filter(\n (tx) =>\n tx.status === TransactionStatus.submitted &&\n !tx.verifiedOnBlockchain &&\n !tx.isUserOperation,\n );\n }\n\n #warnTransaction(txMeta: TransactionMeta, error: string, message: string) {\n this.#updateTransaction(\n {\n ...txMeta,\n warning: { error, message },\n },\n 'PendingTransactionTracker:#warnTransaction - Warning added',\n );\n }\n\n #failTransaction(txMeta: TransactionMeta, error: Error) {\n log('Transaction failed', txMeta.id, error);\n this.hub.emit('transaction-failed', txMeta, error);\n }\n\n #dropTransaction(txMeta: TransactionMeta) {\n log('Transaction dropped', txMeta.id);\n this.hub.emit('transaction-dropped', txMeta);\n }\n\n #updateTransaction(txMeta: TransactionMeta, note: string) {\n this.hub.emit('transaction-updated', txMeta, note);\n }\n\n async #getTransactionReceipt(\n txHash?: string,\n ): Promise<TransactionReceipt | undefined> {\n return await query(this.#getEthQuery(), 'getTransactionReceipt', [txHash]);\n }\n\n async #getBlockByHash(\n blockHash: string,\n includeTransactionDetails: boolean,\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): Promise<any> {\n return await query(this.#getEthQuery(), 'getBlockByHash', [\n blockHash,\n includeTransactionDetails,\n ]);\n }\n\n async #getNetworkTransactionCount(address: string): Promise<string> {\n return await query(this.#getEthQuery(), 'getTransactionCount', [address]);\n }\n\n #getCurrentChainTransactions(): TransactionMeta[] {\n const currentChainId = this.#getChainId();\n\n return this.#getTransactions().filter(\n (tx) => tx.chainId === currentChainId,\n );\n }\n}\n"]}
|
|
@@ -18,9 +18,9 @@ function getLayer1GasFeeFlow(transactionMeta, layer1GasFeeFlows) {
|
|
|
18
18
|
);
|
|
19
19
|
}
|
|
20
20
|
async function getTransactionLayer1GasFee({
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
layer1GasFeeFlows,
|
|
22
|
+
provider,
|
|
23
|
+
transactionMeta
|
|
24
24
|
}) {
|
|
25
25
|
const layer1GasFeeFlow = getLayer1GasFeeFlow(
|
|
26
26
|
transactionMeta,
|
|
@@ -32,7 +32,7 @@ async function getTransactionLayer1GasFee({
|
|
|
32
32
|
}
|
|
33
33
|
try {
|
|
34
34
|
const { layer1Fee } = await layer1GasFeeFlow.getLayer1Fee({
|
|
35
|
-
|
|
35
|
+
provider,
|
|
36
36
|
transactionMeta
|
|
37
37
|
});
|
|
38
38
|
return layer1Fee;
|
|
@@ -44,5 +44,6 @@ async function getTransactionLayer1GasFee({
|
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
|
|
48
|
+
exports.updateTransactionLayer1GasFee = updateTransactionLayer1GasFee; exports.getTransactionLayer1GasFee = getTransactionLayer1GasFee;
|
|
49
|
+
//# sourceMappingURL=chunk-5WFLNKCL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/layer1-gas-fee-flow.ts"],"names":[],"mappings":";;;;;AACA,SAAS,0BAAoC;AAK7C,IAAM,MAAM,mBAAmB,eAAe,sBAAsB;AAepE,eAAsB,8BACpB,SACA;AACA,QAAM,eAAe,MAAM,2BAA2B,OAAO;AAE7D,MAAI,cAAc;AAChB,UAAM,EAAE,gBAAgB,IAAI;AAC5B,oBAAgB,eAAe;AAAA,EACjC;AACF;AAQA,SAAS,oBACP,iBACA,mBAC8B;AAC9B,SAAO,kBAAkB;AAAA,IAAK,CAAC,qBAC7B,iBAAiB,mBAAmB,eAAe;AAAA,EACrD;AACF;AASA,eAAsB,2BAA2B;AAAA,EAC/C;AAAA,EACA;AAAA,EACA;AACF,GAAwD;AACtD,QAAM,mBAAmB;AAAA,IACvB;AAAA,IACA;AAAA,EACF;AACA,MAAI,CAAC,kBAAkB;AACrB,QAAI,kCAAkC,gBAAgB,EAAE;AACxD,WAAO;AAAA,EACT;AAEA,MAAI;AACF,UAAM,EAAE,UAAU,IAAI,MAAM,iBAAiB,aAAa;AAAA,MACxD;AAAA,MACA;AAAA,IACF,CAAC;AACD,WAAO;AAAA,EACT,SAAS,OAAO;AACd,QAAI,iCAAiC,gBAAgB,IAAI,KAAK;AAC9D,WAAO;AAAA,EACT;AACF","sourcesContent":["import type { Provider } from '@metamask/network-controller';\nimport { createModuleLogger, type Hex } from '@metamask/utils';\n\nimport { projectLogger } from '../logger';\nimport type { Layer1GasFeeFlow, TransactionMeta } from '../types';\n\nconst log = createModuleLogger(projectLogger, 'layer-1-gas-fee-flow');\n\nexport type UpdateLayer1GasFeeRequest = {\n layer1GasFeeFlows: Layer1GasFeeFlow[];\n provider: Provider;\n transactionMeta: TransactionMeta;\n};\n\n/**\n * Updates the given transactionMeta with the layer 1 gas fee.\n * @param request - The request to use when getting the layer 1 gas fee.\n * @param request.provider - Provider used to create a new underlying EthQuery instance\n * @param request.transactionMeta - The transaction to get the layer 1 gas fee for.\n * @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.\n */\nexport async function updateTransactionLayer1GasFee(\n request: UpdateLayer1GasFeeRequest,\n) {\n const layer1GasFee = await getTransactionLayer1GasFee(request);\n\n if (layer1GasFee) {\n const { transactionMeta } = request;\n transactionMeta.layer1GasFee = layer1GasFee;\n }\n}\n\n/**\n * Get the layer 1 gas fee flow for a transaction.\n * @param transactionMeta - The transaction to get the layer 1 gas fee flow for.\n * @param layer1GasFeeFlows - The layer 1 gas fee flows to search.\n * @returns The layer 1 gas fee flow for the transaction, or undefined if none match.\n */\nfunction getLayer1GasFeeFlow(\n transactionMeta: TransactionMeta,\n layer1GasFeeFlows: Layer1GasFeeFlow[],\n): Layer1GasFeeFlow | undefined {\n return layer1GasFeeFlows.find((layer1GasFeeFlow) =>\n layer1GasFeeFlow.matchesTransaction(transactionMeta),\n );\n}\n\n/**\n * Get the layer 1 gas fee for a transaction and return the layer1Fee.\n * @param request - The request to use when getting the layer 1 gas fee.\n * @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.\n * @param request.provider - The provider to use to get the layer 1 gas fee.\n * @param request.transactionMeta - The transaction to get the layer 1 gas fee for.\n */\nexport async function getTransactionLayer1GasFee({\n layer1GasFeeFlows,\n provider,\n transactionMeta,\n}: UpdateLayer1GasFeeRequest): Promise<Hex | undefined> {\n const layer1GasFeeFlow = getLayer1GasFeeFlow(\n transactionMeta,\n layer1GasFeeFlows,\n );\n if (!layer1GasFeeFlow) {\n log('Layer 1 gas fee flow not found', transactionMeta.id);\n return undefined;\n }\n\n try {\n const { layer1Fee } = await layer1GasFeeFlow.getLayer1Fee({\n provider,\n transactionMeta,\n });\n return layer1Fee;\n } catch (error) {\n log('Failed to get layer 1 gas fee', transactionMeta.id, error);\n return undefined;\n }\n}\n"]}
|
|
@@ -89,7 +89,7 @@ var PendingTransactionTracker = class {
|
|
|
89
89
|
__privateSet(this, _getChainId, getChainId);
|
|
90
90
|
__privateSet(this, _getEthQuery, getEthQuery);
|
|
91
91
|
__privateSet(this, _getTransactions, getTransactions);
|
|
92
|
-
__privateSet(this, _isResubmitEnabled, isResubmitEnabled ?? true);
|
|
92
|
+
__privateSet(this, _isResubmitEnabled, isResubmitEnabled ?? (() => true));
|
|
93
93
|
__privateSet(this, _listener, __privateMethod(this, _onLatestBlock, onLatestBlock_fn).bind(this));
|
|
94
94
|
__privateSet(this, _getGlobalLock, getGlobalLock);
|
|
95
95
|
__privateSet(this, _publishTransaction, publishTransaction);
|
|
@@ -177,7 +177,7 @@ checkTransactions_fn = async function() {
|
|
|
177
177
|
};
|
|
178
178
|
_resubmitTransactions = new WeakSet();
|
|
179
179
|
resubmitTransactions_fn = async function(latestBlockNumber) {
|
|
180
|
-
if (!__privateGet(this, _isResubmitEnabled) || !__privateGet(this, _running)) {
|
|
180
|
+
if (!__privateGet(this, _isResubmitEnabled).call(this) || !__privateGet(this, _running)) {
|
|
181
181
|
return;
|
|
182
182
|
}
|
|
183
183
|
log("Resubmitting transactions");
|
|
@@ -396,4 +396,4 @@ getCurrentChainTransactions_fn = function() {
|
|
|
396
396
|
export {
|
|
397
397
|
PendingTransactionTracker
|
|
398
398
|
};
|
|
399
|
-
//# sourceMappingURL=chunk-
|
|
399
|
+
//# sourceMappingURL=chunk-5YES3V2R.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/helpers/PendingTransactionTracker.ts"],"sourcesContent":["import { query } from '@metamask/controller-utils';\nimport type EthQuery from '@metamask/eth-query';\nimport type {\n BlockTracker,\n NetworkClientId,\n} from '@metamask/network-controller';\nimport EventEmitter from 'events';\nimport { cloneDeep, merge } from 'lodash';\n\nimport { createModuleLogger, projectLogger } from '../logger';\nimport type { TransactionMeta, TransactionReceipt } from '../types';\nimport { TransactionStatus, TransactionType } from '../types';\n\n/**\n * We wait this many blocks before emitting a 'transaction-dropped' event\n * This is because we could be talking to a node that is out of sync\n */\nconst DROPPED_BLOCK_COUNT = 3;\n\nconst RECEIPT_STATUS_SUCCESS = '0x1';\nconst RECEIPT_STATUS_FAILURE = '0x0';\nconst MAX_RETRY_BLOCK_DISTANCE = 50;\n\nconst KNOWN_TRANSACTION_ERRORS = [\n 'replacement transaction underpriced',\n 'known transaction',\n 'gas price too low to replace',\n 'transaction with the same hash was already imported',\n 'gateway timeout',\n 'nonce too low',\n];\n\nconst log = createModuleLogger(projectLogger, 'pending-transactions');\n\ntype SuccessfulTransactionReceipt = TransactionReceipt & {\n blockNumber: string;\n blockHash: string;\n};\n\ntype Events = {\n 'transaction-confirmed': [txMeta: TransactionMeta];\n 'transaction-dropped': [txMeta: TransactionMeta];\n 'transaction-failed': [txMeta: TransactionMeta, error: Error];\n 'transaction-updated': [txMeta: TransactionMeta, note: string];\n};\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 PendingTransactionTrackerEventEmitter extends EventEmitter {\n on<T extends keyof Events>(\n eventName: T,\n listener: (...args: Events[T]) => void,\n ): this;\n\n emit<T extends keyof Events>(eventName: T, ...args: Events[T]): boolean;\n}\n\nexport class PendingTransactionTracker {\n hub: PendingTransactionTrackerEventEmitter;\n\n #approveTransaction: (transactionId: string) => Promise<void>;\n\n #blockTracker: BlockTracker;\n\n #droppedBlockCountByHash: Map<string, number>;\n\n #getChainId: () => string;\n\n #getEthQuery: (networkClientId?: NetworkClientId) => EthQuery;\n\n #getTransactions: () => TransactionMeta[];\n\n #isResubmitEnabled: () => boolean;\n\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n #listener: any;\n\n #getGlobalLock: () => Promise<() => void>;\n\n #publishTransaction: (ethQuery: EthQuery, rawTx: string) => Promise<string>;\n\n #running: boolean;\n\n #beforeCheckPendingTransaction: (transactionMeta: TransactionMeta) => boolean;\n\n #beforePublish: (transactionMeta: TransactionMeta) => boolean;\n\n constructor({\n approveTransaction,\n blockTracker,\n getChainId,\n getEthQuery,\n getTransactions,\n isResubmitEnabled,\n getGlobalLock,\n publishTransaction,\n hooks,\n }: {\n approveTransaction: (transactionId: string) => Promise<void>;\n blockTracker: BlockTracker;\n getChainId: () => string;\n getEthQuery: (networkClientId?: NetworkClientId) => EthQuery;\n getTransactions: () => TransactionMeta[];\n isResubmitEnabled?: () => boolean;\n getGlobalLock: () => Promise<() => void>;\n publishTransaction: (ethQuery: EthQuery, rawTx: string) => Promise<string>;\n hooks?: {\n beforeCheckPendingTransaction?: (\n transactionMeta: TransactionMeta,\n ) => boolean;\n beforePublish?: (transactionMeta: TransactionMeta) => boolean;\n };\n }) {\n this.hub = new EventEmitter() as PendingTransactionTrackerEventEmitter;\n\n this.#approveTransaction = approveTransaction;\n this.#blockTracker = blockTracker;\n this.#droppedBlockCountByHash = new Map();\n this.#getChainId = getChainId;\n this.#getEthQuery = getEthQuery;\n this.#getTransactions = getTransactions;\n this.#isResubmitEnabled = isResubmitEnabled ?? (() => true);\n this.#listener = this.#onLatestBlock.bind(this);\n this.#getGlobalLock = getGlobalLock;\n this.#publishTransaction = publishTransaction;\n this.#running = false;\n this.#beforePublish = hooks?.beforePublish ?? (() => true);\n this.#beforeCheckPendingTransaction =\n hooks?.beforeCheckPendingTransaction ?? (() => true);\n }\n\n startIfPendingTransactions = () => {\n const pendingTransactions = this.#getPendingTransactions();\n\n if (pendingTransactions.length) {\n this.#start();\n } else {\n this.stop();\n }\n };\n\n /**\n * Force checks the network if the given transaction is confirmed and updates it's status.\n *\n * @param txMeta - The transaction to check\n */\n async forceCheckTransaction(txMeta: TransactionMeta) {\n const releaseLock = await this.#getGlobalLock();\n\n try {\n await this.#checkTransaction(txMeta);\n } catch (error) {\n /* istanbul ignore next */\n log('Failed to check transaction', error);\n } finally {\n releaseLock();\n }\n }\n\n #start() {\n if (this.#running) {\n return;\n }\n\n this.#blockTracker.on('latest', this.#listener);\n this.#running = true;\n\n log('Started polling');\n }\n\n stop() {\n if (!this.#running) {\n return;\n }\n\n this.#blockTracker.removeListener('latest', this.#listener);\n this.#running = false;\n\n log('Stopped polling');\n }\n\n async #onLatestBlock(latestBlockNumber: string) {\n const releaseLock = await this.#getGlobalLock();\n\n try {\n await this.#checkTransactions();\n } catch (error) {\n /* istanbul ignore next */\n log('Failed to check transactions', error);\n } finally {\n releaseLock();\n }\n\n try {\n await this.#resubmitTransactions(latestBlockNumber);\n } catch (error) {\n /* istanbul ignore next */\n log('Failed to resubmit transactions', error);\n }\n }\n\n async #checkTransactions() {\n log('Checking transactions');\n\n const pendingTransactions = this.#getPendingTransactions();\n\n if (!pendingTransactions.length) {\n log('No pending transactions to check');\n return;\n }\n\n log('Found pending transactions to check', {\n count: pendingTransactions.length,\n ids: pendingTransactions.map((tx) => tx.id),\n });\n\n await Promise.all(\n pendingTransactions.map((tx) => this.#checkTransaction(tx)),\n );\n }\n\n async #resubmitTransactions(latestBlockNumber: string) {\n if (!this.#isResubmitEnabled() || !this.#running) {\n return;\n }\n\n log('Resubmitting transactions');\n\n const pendingTransactions = this.#getPendingTransactions();\n\n if (!pendingTransactions.length) {\n log('No pending transactions to resubmit');\n return;\n }\n\n log('Found pending transactions to resubmit', {\n count: pendingTransactions.length,\n ids: pendingTransactions.map((tx) => tx.id),\n });\n\n for (const txMeta of pendingTransactions) {\n try {\n await this.#resubmitTransaction(txMeta, latestBlockNumber);\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n /* istanbul ignore next */\n const errorMessage =\n error.value?.message?.toLowerCase() || error.message.toLowerCase();\n\n if (this.#isKnownTransactionError(errorMessage)) {\n log('Ignoring known transaction error', errorMessage);\n return;\n }\n\n this.#warnTransaction(\n txMeta,\n error.message,\n 'There was an error when resubmitting this transaction.',\n );\n }\n }\n }\n\n #isKnownTransactionError(errorMessage: string) {\n return KNOWN_TRANSACTION_ERRORS.some((knownError) =>\n errorMessage.includes(knownError),\n );\n }\n\n async #resubmitTransaction(\n txMeta: TransactionMeta,\n latestBlockNumber: string,\n ) {\n if (!this.#isResubmitDue(txMeta, latestBlockNumber)) {\n return;\n }\n\n const { rawTx } = txMeta;\n\n if (!this.#beforePublish(txMeta)) {\n return;\n }\n\n if (!rawTx?.length) {\n log('Approving transaction as no raw value');\n await this.#approveTransaction(txMeta.id);\n return;\n }\n\n const ethQuery = this.#getEthQuery(txMeta.networkClientId);\n await this.#publishTransaction(ethQuery, rawTx);\n\n const retryCount = (txMeta.retryCount ?? 0) + 1;\n\n this.#updateTransaction(\n merge({}, txMeta, { retryCount }),\n 'PendingTransactionTracker:transaction-retry - Retry count increased',\n );\n }\n\n #isResubmitDue(txMeta: TransactionMeta, latestBlockNumber: string): boolean {\n const txMetaWithFirstRetryBlockNumber = cloneDeep(txMeta);\n\n if (!txMetaWithFirstRetryBlockNumber.firstRetryBlockNumber) {\n txMetaWithFirstRetryBlockNumber.firstRetryBlockNumber = latestBlockNumber;\n\n this.#updateTransaction(\n txMetaWithFirstRetryBlockNumber,\n 'PendingTransactionTracker:#isResubmitDue - First retry block number set',\n );\n }\n\n const { firstRetryBlockNumber } = txMetaWithFirstRetryBlockNumber;\n\n const blocksSinceFirstRetry =\n Number.parseInt(latestBlockNumber, 16) -\n Number.parseInt(firstRetryBlockNumber, 16);\n\n const retryCount = txMeta.retryCount || 0;\n\n // Exponential backoff to limit retries at publishing\n // Capped at ~15 minutes between retries\n const requiredBlocksSinceFirstRetry = Math.min(\n MAX_RETRY_BLOCK_DISTANCE,\n Math.pow(2, retryCount),\n );\n\n return blocksSinceFirstRetry >= requiredBlocksSinceFirstRetry;\n }\n\n async #checkTransaction(txMeta: TransactionMeta) {\n const { hash, id } = txMeta;\n\n if (!hash && this.#beforeCheckPendingTransaction(txMeta)) {\n const error = new Error(\n 'We had an error while submitting this transaction, please try again.',\n );\n\n error.name = 'NoTxHashError';\n\n this.#failTransaction(txMeta, error);\n\n return;\n }\n\n if (this.#isNonceTaken(txMeta)) {\n log('Nonce already taken', id);\n this.#dropTransaction(txMeta);\n return;\n }\n\n try {\n const receipt = await this.#getTransactionReceipt(hash);\n const isSuccess = receipt?.status === RECEIPT_STATUS_SUCCESS;\n const isFailure = receipt?.status === RECEIPT_STATUS_FAILURE;\n\n if (isFailure) {\n log('Transaction receipt has failed status');\n\n this.#failTransaction(\n txMeta,\n new Error('Transaction dropped or replaced'),\n );\n\n return;\n }\n\n const { blockNumber, blockHash } = receipt || {};\n\n if (isSuccess && blockNumber && blockHash) {\n await this.#onTransactionConfirmed(txMeta, {\n ...receipt,\n blockNumber,\n blockHash,\n });\n\n return;\n }\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n log('Failed to check transaction', id, error);\n\n this.#warnTransaction(\n txMeta,\n error.message,\n 'There was a problem loading this transaction.',\n );\n\n return;\n }\n\n if (await this.#isTransactionDropped(txMeta)) {\n this.#dropTransaction(txMeta);\n }\n }\n\n async #onTransactionConfirmed(\n txMeta: TransactionMeta,\n receipt: SuccessfulTransactionReceipt,\n ) {\n const { id } = txMeta;\n const { blockHash } = receipt;\n\n log('Transaction confirmed', id);\n\n const { baseFeePerGas, timestamp: blockTimestamp } =\n await this.#getBlockByHash(blockHash, false);\n\n const updatedTxMeta = cloneDeep(txMeta);\n updatedTxMeta.baseFeePerGas = baseFeePerGas;\n updatedTxMeta.blockTimestamp = blockTimestamp;\n updatedTxMeta.status = TransactionStatus.confirmed;\n updatedTxMeta.txParams = {\n ...updatedTxMeta.txParams,\n gasUsed: receipt.gasUsed,\n };\n updatedTxMeta.txReceipt = receipt;\n updatedTxMeta.verifiedOnBlockchain = true;\n\n this.#updateTransaction(\n updatedTxMeta,\n 'PendingTransactionTracker:#onTransactionConfirmed - Transaction confirmed',\n );\n\n this.hub.emit('transaction-confirmed', updatedTxMeta);\n }\n\n async #isTransactionDropped(txMeta: TransactionMeta) {\n const {\n hash,\n id,\n txParams: { nonce, from },\n } = txMeta;\n\n /* istanbul ignore next */\n if (!nonce || !hash) {\n return false;\n }\n\n const networkNextNonceHex = await this.#getNetworkTransactionCount(from);\n const networkNextNonceNumber = parseInt(networkNextNonceHex, 16);\n const nonceNumber = parseInt(nonce, 16);\n\n if (nonceNumber >= networkNextNonceNumber) {\n return false;\n }\n\n let droppedBlockCount = this.#droppedBlockCountByHash.get(hash);\n\n if (droppedBlockCount === undefined) {\n droppedBlockCount = 0;\n this.#droppedBlockCountByHash.set(hash, droppedBlockCount);\n }\n\n if (droppedBlockCount < DROPPED_BLOCK_COUNT) {\n log('Incrementing dropped block count', { id, droppedBlockCount });\n this.#droppedBlockCountByHash.set(hash, droppedBlockCount + 1);\n return false;\n }\n\n log('Hit dropped block count', id);\n\n this.#droppedBlockCountByHash.delete(hash);\n return true;\n }\n\n #isNonceTaken(txMeta: TransactionMeta): boolean {\n const { id, txParams } = txMeta;\n\n return this.#getCurrentChainTransactions().some(\n (tx) =>\n tx.id !== id &&\n tx.txParams.from === txParams.from &&\n tx.status === TransactionStatus.confirmed &&\n tx.txParams.nonce === txParams.nonce &&\n tx.type !== TransactionType.incoming,\n );\n }\n\n #getPendingTransactions(): TransactionMeta[] {\n return this.#getCurrentChainTransactions().filter(\n (tx) =>\n tx.status === TransactionStatus.submitted &&\n !tx.verifiedOnBlockchain &&\n !tx.isUserOperation,\n );\n }\n\n #warnTransaction(txMeta: TransactionMeta, error: string, message: string) {\n this.#updateTransaction(\n {\n ...txMeta,\n warning: { error, message },\n },\n 'PendingTransactionTracker:#warnTransaction - Warning added',\n );\n }\n\n #failTransaction(txMeta: TransactionMeta, error: Error) {\n log('Transaction failed', txMeta.id, error);\n this.hub.emit('transaction-failed', txMeta, error);\n }\n\n #dropTransaction(txMeta: TransactionMeta) {\n log('Transaction dropped', txMeta.id);\n this.hub.emit('transaction-dropped', txMeta);\n }\n\n #updateTransaction(txMeta: TransactionMeta, note: string) {\n this.hub.emit('transaction-updated', txMeta, note);\n }\n\n async #getTransactionReceipt(\n txHash?: string,\n ): Promise<TransactionReceipt | undefined> {\n return await query(this.#getEthQuery(), 'getTransactionReceipt', [txHash]);\n }\n\n async #getBlockByHash(\n blockHash: string,\n includeTransactionDetails: boolean,\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): Promise<any> {\n return await query(this.#getEthQuery(), 'getBlockByHash', [\n blockHash,\n includeTransactionDetails,\n ]);\n }\n\n async #getNetworkTransactionCount(address: string): Promise<string> {\n return await query(this.#getEthQuery(), 'getTransactionCount', [address]);\n }\n\n #getCurrentChainTransactions(): TransactionMeta[] {\n const currentChainId = this.#getChainId();\n\n return this.#getTransactions().filter(\n (tx) => tx.chainId === currentChainId,\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;AAAA,SAAS,aAAa;AAMtB,OAAO,kBAAkB;AACzB,SAAS,WAAW,aAAa;AAUjC,IAAM,sBAAsB;AAE5B,IAAM,yBAAyB;AAC/B,IAAM,yBAAyB;AAC/B,IAAM,2BAA2B;AAEjC,IAAM,2BAA2B;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,IAAM,MAAM,mBAAmB,eAAe,sBAAsB;AAhCpE;AA0DO,IAAM,4BAAN,MAAgC;AAAA,EA+BrC,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAeG;AA+CH;AAsBA,uBAAM;AAoBN,uBAAM;AAoBN,uBAAM;AA2CN;AAMA,uBAAM;AA+BN;AA8BA,uBAAM;AAmEN,uBAAM;AA+BN,uBAAM;AAuCN;AAaA;AASA;AAUA;AAKA;AAKA;AAIA,uBAAM;AAMN,uBAAM;AAYN,uBAAM;AAIN;AA7dA;AAEA;AAEA;AAEA;AAEA;AAEA;AAEA;AAIA;AAAA;AAAA;AAEA;AAEA;AAEA;AAEA;AAEA;AA8CA,sCAA6B,MAAM;AACjC,YAAM,sBAAsB,sBAAK,oDAAL;AAE5B,UAAI,oBAAoB,QAAQ;AAC9B,8BAAK,kBAAL;AAAA,MACF,OAAO;AACL,aAAK,KAAK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QAAyB,OAAe,SAAiB;AACxE,wBAAK,0CAAL,WACE;AAAA,IACE,GAAG;AAAA,IACH,SAAS,EAAE,OAAO,QAAQ;AAAA,EAC5B,GACA;AAEJ;AAEA;AAAA,qBAAgB,SAAC,QAAyB,OAAc;AACtD,MAAI,sBAAsB,OAAO,IAAI,KAAK;AAC1C,OAAK,IAAI,KAAK,sBAAsB,QAAQ,KAAK;AACnD;AAEA;AAAA,qBAAgB,SAAC,QAAyB;AACxC,MAAI,uBAAuB,OAAO,EAAE;AACpC,OAAK,IAAI,KAAK,uBAAuB,MAAM;AAC7C;AAEA;AAAA,uBAAkB,SAAC,QAAyB,MAAc;AACxD,OAAK,IAAI,KAAK,uBAAuB,QAAQ,IAAI;AACnD;AAEM;AAAA,2BAAsB,eAC1B,QACyC;AACzC,SAAO,MAAM,MAAM,mBAAK,cAAL,YAAqB,yBAAyB,CAAC,MAAM,CAAC;AAC3E;AAEM;AAAA,oBAAe,eACnB,WACA,2BAGc;AACd,SAAO,MAAM,MAAM,mBAAK,cAAL,YAAqB,kBAAkB;AAAA,IACxD;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAEM;AAAA,gCAA2B,eAAC,SAAkC;AAClE,SAAO,MAAM,MAAM,mBAAK,cAAL,YAAqB,uBAAuB,CAAC,OAAO,CAAC;AAC1E;AAEA;AAAA,iCAA4B,WAAsB;AAChD,QAAM,iBAAiB,mBAAK,aAAL;AAEvB,SAAO,mBAAK,kBAAL,WAAwB;AAAA,IAC7B,CAAC,OAAO,GAAG,YAAY;AAAA,EACzB;AACF;","names":[]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkUUSYJGGQjs = require('./chunk-UUSYJGGQ.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
var _chunkS6VGOPUYjs = require('./chunk-S6VGOPUY.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkFK7AP6SHjs = require('./chunk-FK7AP6SH.js');
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
@@ -37,7 +37,7 @@ var DefaultGasFeeFlow = class {
|
|
|
37
37
|
} else {
|
|
38
38
|
throw new Error(`'No gas fee estimates available`);
|
|
39
39
|
}
|
|
40
|
-
const estimates = Object.values(
|
|
40
|
+
const estimates = Object.values(_chunkFK7AP6SHjs.GasFeeEstimateLevel).reduce(
|
|
41
41
|
(result, level) => ({
|
|
42
42
|
...result,
|
|
43
43
|
[level]: _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getEstimateLevel, getEstimateLevel_fn).call(this, {
|
|
@@ -64,10 +64,10 @@ getEstimateLevel_fn = function({
|
|
|
64
64
|
};
|
|
65
65
|
_getFeeMarketLevel = new WeakSet();
|
|
66
66
|
getFeeMarketLevel_fn = function(gasFeeEstimates, level) {
|
|
67
|
-
const maxFeePerGas =
|
|
67
|
+
const maxFeePerGas = _chunkUUSYJGGQjs.gweiDecimalToWeiHex.call(void 0,
|
|
68
68
|
gasFeeEstimates[level].suggestedMaxFeePerGas
|
|
69
69
|
);
|
|
70
|
-
const maxPriorityFeePerGas =
|
|
70
|
+
const maxPriorityFeePerGas = _chunkUUSYJGGQjs.gweiDecimalToWeiHex.call(void 0,
|
|
71
71
|
gasFeeEstimates[level].suggestedMaxPriorityFeePerGas
|
|
72
72
|
);
|
|
73
73
|
return {
|
|
@@ -77,7 +77,7 @@ getFeeMarketLevel_fn = function(gasFeeEstimates, level) {
|
|
|
77
77
|
};
|
|
78
78
|
_getLegacyLevel = new WeakSet();
|
|
79
79
|
getLegacyLevel_fn = function(gasFeeEstimates, level) {
|
|
80
|
-
const gasPrice =
|
|
80
|
+
const gasPrice = _chunkUUSYJGGQjs.gweiDecimalToWeiHex.call(void 0, gasFeeEstimates[level]);
|
|
81
81
|
return {
|
|
82
82
|
maxFeePerGas: gasPrice,
|
|
83
83
|
maxPriorityFeePerGas: gasPrice
|
|
@@ -87,4 +87,4 @@ getLegacyLevel_fn = function(gasFeeEstimates, level) {
|
|
|
87
87
|
|
|
88
88
|
|
|
89
89
|
exports.DefaultGasFeeFlow = DefaultGasFeeFlow;
|
|
90
|
-
//# sourceMappingURL=chunk-
|
|
90
|
+
//# sourceMappingURL=chunk-6V2LR6JL.js.map
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DefaultGasFeeFlow
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-KKCD5UMP.mjs";
|
|
4
4
|
import {
|
|
5
5
|
projectLogger
|
|
6
6
|
} from "./chunk-UQQWZT6C.mjs";
|
|
7
7
|
import {
|
|
8
8
|
GasFeeEstimateLevel
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-YEJJKWT2.mjs";
|
|
10
10
|
import {
|
|
11
11
|
__privateAdd,
|
|
12
12
|
__privateMethod
|
|
@@ -118,4 +118,4 @@ feesToString_fn = function(fees) {
|
|
|
118
118
|
export {
|
|
119
119
|
LineaGasFeeFlow
|
|
120
120
|
};
|
|
121
|
-
//# sourceMappingURL=chunk-
|
|
121
|
+
//# sourceMappingURL=chunk-7HNSDVVO.mjs.map
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
simulateTransactions
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-K4KOSAGM.mjs";
|
|
4
|
+
import {
|
|
5
|
+
SimulationError,
|
|
6
|
+
SimulationInvalidResponseError,
|
|
7
|
+
SimulationRevertedError
|
|
8
|
+
} from "./chunk-HQSNKCXI.mjs";
|
|
4
9
|
import {
|
|
5
10
|
projectLogger
|
|
6
11
|
} from "./chunk-UQQWZT6C.mjs";
|
|
@@ -11,6 +16,7 @@ import { hexToBN, toHex } from "@metamask/controller-utils";
|
|
|
11
16
|
import { abiERC20, abiERC721, abiERC1155 } from "@metamask/metamask-eth-abis";
|
|
12
17
|
import { createModuleLogger } from "@metamask/utils";
|
|
13
18
|
var log = createModuleLogger(projectLogger, "simulation");
|
|
19
|
+
var REVERTED_ERRORS = ["execution reverted", "insufficient funds for gas"];
|
|
14
20
|
async function getSimulationData(request) {
|
|
15
21
|
const { chainId, from, to, value, data } = request;
|
|
16
22
|
log("Getting simulation data", request);
|
|
@@ -30,8 +36,11 @@ async function getSimulationData(request) {
|
|
|
30
36
|
withLogs: true
|
|
31
37
|
});
|
|
32
38
|
const transactionError = response.transactions?.[0]?.error;
|
|
39
|
+
if (REVERTED_ERRORS.some((error) => transactionError?.includes(error))) {
|
|
40
|
+
throw new SimulationRevertedError();
|
|
41
|
+
}
|
|
33
42
|
if (transactionError) {
|
|
34
|
-
throw
|
|
43
|
+
throw new SimulationError(transactionError);
|
|
35
44
|
}
|
|
36
45
|
const nativeBalanceChange = getNativeBalanceChange(request.from, response);
|
|
37
46
|
const events = getEvents(response);
|
|
@@ -48,8 +57,7 @@ async function getSimulationData(request) {
|
|
|
48
57
|
tokenBalanceChanges: [],
|
|
49
58
|
error: {
|
|
50
59
|
code: rawError.code,
|
|
51
|
-
message: rawError.message
|
|
52
|
-
isReverted: rawError.message?.includes("execution reverted") ?? false
|
|
60
|
+
message: rawError.message
|
|
53
61
|
}
|
|
54
62
|
};
|
|
55
63
|
}
|
|
@@ -130,7 +138,7 @@ async function getTokenBalanceChanges(request, events) {
|
|
|
130
138
|
});
|
|
131
139
|
log("Balance simulation response", response);
|
|
132
140
|
if (response.transactions.length !== balanceTransactions.length * 2 + 1) {
|
|
133
|
-
throw new
|
|
141
|
+
throw new SimulationInvalidResponseError();
|
|
134
142
|
}
|
|
135
143
|
return [...balanceTransactionsByToken.keys()].map((token, index) => {
|
|
136
144
|
const previousBalance = normalizeReturnValue(
|
|
@@ -262,4 +270,4 @@ function normalizeReturnValue(value) {
|
|
|
262
270
|
export {
|
|
263
271
|
getSimulationData
|
|
264
272
|
};
|
|
265
|
-
//# sourceMappingURL=chunk-
|
|
273
|
+
//# sourceMappingURL=chunk-A4P4B3OF.mjs.map
|