@metamask-previews/transaction-controller 25.1.0-preview-68beceb0 → 25.2.0-preview-59bf6d5d
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 +20 -1
- package/dist/TransactionController.js +18 -19
- package/dist/TransactionController.mjs +17 -18
- package/dist/{chunk-TJXPMOA6.mjs → chunk-3D3SA6PY.mjs} +2 -2
- package/dist/{chunk-G4743H5H.js → chunk-5IHLDAOF.js} +5 -5
- package/dist/{chunk-QTQSCTQA.js → chunk-5OQ373JS.js} +10 -10
- package/dist/{chunk-WBE2B3XJ.mjs → chunk-5UL3VDFT.mjs} +8 -13
- package/dist/chunk-5UL3VDFT.mjs.map +1 -0
- package/dist/chunk-6XMG522E.mjs +56 -0
- package/dist/chunk-6XMG522E.mjs.map +1 -0
- package/dist/{chunk-BTYBFMZN.js → chunk-7BG5XOXJ.js} +107 -89
- package/dist/chunk-7BG5XOXJ.js.map +1 -0
- package/dist/{chunk-N6STPA6E.mjs → chunk-BYBPZUHS.mjs} +30 -7
- package/dist/chunk-BYBPZUHS.mjs.map +1 -0
- package/dist/{chunk-VP2DBWOT.js → chunk-CXXGL43K.js} +3 -3
- package/dist/{chunk-6KYPLIXG.mjs → chunk-DWHMMJOW.mjs} +2 -2
- package/dist/{chunk-C3UHJPYJ.js → chunk-F3CMU2DM.js} +6 -6
- package/dist/{chunk-2YQGET5U.js → chunk-FHG5GY6F.js} +7 -7
- package/dist/{chunk-NT3WVB4P.js → chunk-GC77BSQZ.js} +32 -9
- package/dist/chunk-GC77BSQZ.js.map +1 -0
- package/dist/chunk-GE57YNGX.js +56 -0
- package/dist/chunk-GE57YNGX.js.map +1 -0
- package/dist/{chunk-TVDU7LVX.mjs → chunk-I6RY3XOG.mjs} +97 -79
- package/dist/chunk-I6RY3XOG.mjs.map +1 -0
- package/dist/{chunk-JZFJUM6S.mjs → chunk-IK55QTGO.mjs} +3 -3
- package/dist/{chunk-WIZVJM2B.js → chunk-ITDY6AIZ.js} +2 -3
- package/dist/chunk-ITDY6AIZ.js.map +1 -0
- package/dist/{chunk-RU6NJIUD.mjs → chunk-IZI7FQIN.mjs} +3 -3
- package/dist/chunk-KFL2GGZC.mjs +48 -0
- package/dist/chunk-KFL2GGZC.mjs.map +1 -0
- package/dist/{chunk-PJV3XYKW.js → chunk-NRWEI43Q.js} +20 -45
- package/dist/chunk-NRWEI43Q.js.map +1 -0
- package/dist/{chunk-I6HCML4F.js → chunk-PF3UOCRW.js} +8 -8
- package/dist/{chunk-2MSXAOTK.mjs → chunk-PGTV7236.mjs} +5 -5
- package/dist/{chunk-JCGCPGGI.js → chunk-QEX3QMSL.js} +8 -13
- package/dist/chunk-QEX3QMSL.js.map +1 -0
- package/dist/{chunk-3HE3FT67.mjs → chunk-QRSTF45Q.mjs} +5 -5
- package/dist/chunk-R7NJVDWN.js +48 -0
- package/dist/chunk-R7NJVDWN.js.map +1 -0
- package/dist/{chunk-GRQB2ARK.js → chunk-RQKICZYP.js} +3 -3
- package/dist/{chunk-2MMWLJXS.js → chunk-TZTP4JVA.js} +4 -4
- package/dist/{chunk-TUW3M44L.js → chunk-VEJ3MIZG.js} +1 -1
- package/dist/chunk-VEJ3MIZG.js.map +1 -0
- package/dist/{chunk-RIYIJTEU.mjs → chunk-VEREDMI2.mjs} +2 -2
- package/dist/{chunk-XOIPXDGX.mjs → chunk-W57BD6NX.mjs} +1 -1
- package/dist/chunk-W57BD6NX.mjs.map +1 -0
- package/dist/{chunk-HLG525BC.mjs → chunk-XKNFL657.mjs} +2 -2
- package/dist/{chunk-DTMKGTYC.mjs → chunk-Z3HHSD5I.mjs} +2 -3
- package/dist/chunk-Z3HHSD5I.mjs.map +1 -0
- package/dist/{chunk-ZM6E4LZJ.mjs → chunk-ZQFMTLZJ.mjs} +19 -44
- package/dist/chunk-ZQFMTLZJ.mjs.map +1 -0
- package/dist/constants.js +2 -2
- package/dist/constants.mjs +1 -1
- 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/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 +1 -1
- package/dist/helpers/PendingTransactionTracker.mjs +1 -1
- package/dist/index.js +23 -22
- package/dist/index.mjs +22 -21
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/TransactionController.d.ts +26 -34
- package/dist/types/TransactionController.d.ts.map +1 -1
- package/dist/types/constants.d.ts +0 -1
- package/dist/types/constants.d.ts.map +1 -1
- package/dist/types/helpers/GasFeePoller.d.ts +2 -4
- package/dist/types/helpers/GasFeePoller.d.ts.map +1 -1
- package/dist/types/helpers/IncomingTransactionHelper.d.ts +1 -1
- package/dist/types/helpers/IncomingTransactionHelper.d.ts.map +1 -1
- package/dist/types/helpers/MultichainTrackingHelper.d.ts +1 -5
- 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 +2 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types.d.ts +43 -32
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/gas-fees.d.ts +3 -3
- package/dist/types/utils/gas-fees.d.ts.map +1 -1
- package/dist/types/utils/gas-flow.d.ts +2 -2
- package/dist/types/utils/gas-flow.d.ts.map +1 -1
- package/dist/types/utils/gas.d.ts +1 -1
- package/dist/types/utils/gas.d.ts.map +1 -1
- package/dist/types/utils/layer1-gas-fee-flow.d.ts +3 -19
- package/dist/types/utils/layer1-gas-fee-flow.d.ts.map +1 -1
- package/dist/types/utils/simulation-api.d.ts +21 -13
- package/dist/types/utils/simulation-api.d.ts.map +1 -1
- package/dist/types/utils/simulation.d.ts +2 -2
- package/dist/types/utils/simulation.d.ts.map +1 -1
- package/dist/types.js +2 -2
- package/dist/types.mjs +1 -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 +2 -6
- package/dist/utils/layer1-gas-fee-flow.mjs +1 -5
- package/dist/utils/simulation-api.js +2 -3
- package/dist/utils/simulation-api.mjs +1 -2
- package/dist/utils/simulation.js +4 -5
- package/dist/utils/simulation.mjs +3 -4
- 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 +2 -4
- package/dist/chunk-BTYBFMZN.js.map +0 -1
- package/dist/chunk-DTMKGTYC.mjs.map +0 -1
- package/dist/chunk-IFNKPDIB.js +0 -46
- package/dist/chunk-IFNKPDIB.js.map +0 -1
- package/dist/chunk-JCGCPGGI.js.map +0 -1
- package/dist/chunk-N6STPA6E.mjs.map +0 -1
- package/dist/chunk-NT3WVB4P.js.map +0 -1
- package/dist/chunk-OXRUL7JF.mjs +0 -74
- package/dist/chunk-OXRUL7JF.mjs.map +0 -1
- package/dist/chunk-PJV3XYKW.js.map +0 -1
- package/dist/chunk-PM22KPVX.mjs +0 -75
- package/dist/chunk-PM22KPVX.mjs.map +0 -1
- package/dist/chunk-R5LEPJW3.js +0 -75
- package/dist/chunk-R5LEPJW3.js.map +0 -1
- package/dist/chunk-S222HWGT.js +0 -74
- package/dist/chunk-S222HWGT.js.map +0 -1
- package/dist/chunk-T6W4OUJD.mjs +0 -46
- package/dist/chunk-T6W4OUJD.mjs.map +0 -1
- package/dist/chunk-TUW3M44L.js.map +0 -1
- package/dist/chunk-TVDU7LVX.mjs.map +0 -1
- package/dist/chunk-WBE2B3XJ.mjs.map +0 -1
- package/dist/chunk-WIZVJM2B.js.map +0 -1
- package/dist/chunk-XOIPXDGX.mjs.map +0 -1
- package/dist/chunk-ZM6E4LZJ.mjs.map +0 -1
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.js +0 -11
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.js.map +0 -1
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.mjs +0 -11
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.mjs.map +0 -1
- package/dist/types/gas-flows/OptimismLayer1GasFeeFlow.d.ts +0 -10
- package/dist/types/gas-flows/OptimismLayer1GasFeeFlow.d.ts.map +0 -1
- /package/dist/{chunk-TJXPMOA6.mjs.map → chunk-3D3SA6PY.mjs.map} +0 -0
- /package/dist/{chunk-G4743H5H.js.map → chunk-5IHLDAOF.js.map} +0 -0
- /package/dist/{chunk-QTQSCTQA.js.map → chunk-5OQ373JS.js.map} +0 -0
- /package/dist/{chunk-VP2DBWOT.js.map → chunk-CXXGL43K.js.map} +0 -0
- /package/dist/{chunk-6KYPLIXG.mjs.map → chunk-DWHMMJOW.mjs.map} +0 -0
- /package/dist/{chunk-C3UHJPYJ.js.map → chunk-F3CMU2DM.js.map} +0 -0
- /package/dist/{chunk-2YQGET5U.js.map → chunk-FHG5GY6F.js.map} +0 -0
- /package/dist/{chunk-JZFJUM6S.mjs.map → chunk-IK55QTGO.mjs.map} +0 -0
- /package/dist/{chunk-RU6NJIUD.mjs.map → chunk-IZI7FQIN.mjs.map} +0 -0
- /package/dist/{chunk-I6HCML4F.js.map → chunk-PF3UOCRW.js.map} +0 -0
- /package/dist/{chunk-2MSXAOTK.mjs.map → chunk-PGTV7236.mjs.map} +0 -0
- /package/dist/{chunk-3HE3FT67.mjs.map → chunk-QRSTF45Q.mjs.map} +0 -0
- /package/dist/{chunk-GRQB2ARK.js.map → chunk-RQKICZYP.js.map} +0 -0
- /package/dist/{chunk-2MMWLJXS.js.map → chunk-TZTP4JVA.js.map} +0 -0
- /package/dist/{chunk-RIYIJTEU.mjs.map → chunk-VEREDMI2.mjs.map} +0 -0
- /package/dist/{chunk-HLG525BC.mjs.map → chunk-XKNFL657.mjs.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [25.2.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Add simulation types ([#4067](https://github.com/MetaMask/core/pull/4067))
|
|
15
|
+
- SimulationBalanceChange
|
|
16
|
+
- SimulationData
|
|
17
|
+
- SimulationError
|
|
18
|
+
- SimulationToken
|
|
19
|
+
- SimulationTokenBalanceChange
|
|
20
|
+
- SimulationTokenStandard
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
|
|
24
|
+
- No longer wait for simulation to complete before creating approval request ([#4067](https://github.com/MetaMask/core/pull/4067))
|
|
25
|
+
- Automatically update simulation data if transaction parameters are updated ([#4067](https://github.com/MetaMask/core/pull/4067))
|
|
26
|
+
- Determine networks supporting simulation dynamically using API ([#4087](https://github.com/MetaMask/core/pull/4087))
|
|
27
|
+
|
|
10
28
|
## [25.1.0]
|
|
11
29
|
|
|
12
30
|
### Added
|
|
@@ -684,7 +702,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
684
702
|
|
|
685
703
|
All changes listed after this point were applied to this package following the monorepo conversion.
|
|
686
704
|
|
|
687
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@25.
|
|
705
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@25.2.0...HEAD
|
|
706
|
+
[25.2.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@25.1.0...@metamask/transaction-controller@25.2.0
|
|
688
707
|
[25.1.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@25.0.0...@metamask/transaction-controller@25.1.0
|
|
689
708
|
[25.0.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@24.0.0...@metamask/transaction-controller@25.0.0
|
|
690
709
|
[24.0.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@23.1.0...@metamask/transaction-controller@24.0.0
|
|
@@ -4,32 +4,31 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
8
|
-
require('./chunk-HS277C77.js');
|
|
7
|
+
var _chunk7BG5XOXJjs = require('./chunk-7BG5XOXJ.js');
|
|
9
8
|
require('./chunk-VH47Q6TS.js');
|
|
10
|
-
require('./chunk-
|
|
9
|
+
require('./chunk-RQKICZYP.js');
|
|
11
10
|
require('./chunk-QP75SWIQ.js');
|
|
12
11
|
require('./chunk-ZNZEJDOE.js');
|
|
13
|
-
require('./chunk-
|
|
14
|
-
require('./chunk-
|
|
15
|
-
require('./chunk-
|
|
12
|
+
require('./chunk-GC77BSQZ.js');
|
|
13
|
+
require('./chunk-GE57YNGX.js');
|
|
14
|
+
require('./chunk-HS277C77.js');
|
|
15
|
+
require('./chunk-QEX3QMSL.js');
|
|
16
|
+
require('./chunk-R7NJVDWN.js');
|
|
16
17
|
require('./chunk-DTDTOMTB.js');
|
|
17
|
-
require('./chunk-
|
|
18
|
-
require('./chunk-C3UHJPYJ.js');
|
|
18
|
+
require('./chunk-NRWEI43Q.js');
|
|
19
19
|
require('./chunk-5XBULBP2.js');
|
|
20
|
-
require('./chunk-VP2DBWOT.js');
|
|
21
20
|
require('./chunk-7LXE4KHV.js');
|
|
22
|
-
require('./chunk-
|
|
23
|
-
require('./chunk-
|
|
24
|
-
require('./chunk-
|
|
25
|
-
require('./chunk-
|
|
21
|
+
require('./chunk-FHG5GY6F.js');
|
|
22
|
+
require('./chunk-PF3UOCRW.js');
|
|
23
|
+
require('./chunk-5IHLDAOF.js');
|
|
24
|
+
require('./chunk-5OQ373JS.js');
|
|
26
25
|
require('./chunk-UGFBA4GV.js');
|
|
27
|
-
require('./chunk-
|
|
28
|
-
require('./chunk-
|
|
29
|
-
require('./chunk-
|
|
30
|
-
require('./chunk-
|
|
31
|
-
require('./chunk-WIZVJM2B.js');
|
|
26
|
+
require('./chunk-TZTP4JVA.js');
|
|
27
|
+
require('./chunk-F3CMU2DM.js');
|
|
28
|
+
require('./chunk-CXXGL43K.js');
|
|
29
|
+
require('./chunk-ITDY6AIZ.js');
|
|
32
30
|
require('./chunk-S6VGOPUY.js');
|
|
31
|
+
require('./chunk-VEJ3MIZG.js');
|
|
33
32
|
require('./chunk-Z4BLTVTB.js');
|
|
34
33
|
|
|
35
34
|
|
|
@@ -37,5 +36,5 @@ require('./chunk-Z4BLTVTB.js');
|
|
|
37
36
|
|
|
38
37
|
|
|
39
38
|
|
|
40
|
-
exports.ApprovalState =
|
|
39
|
+
exports.ApprovalState = _chunk7BG5XOXJjs.ApprovalState; exports.CANCEL_RATE = _chunk7BG5XOXJjs.CANCEL_RATE; exports.HARDFORK = _chunk7BG5XOXJjs.HARDFORK; exports.SPEED_UP_RATE = _chunk7BG5XOXJjs.SPEED_UP_RATE; exports.TransactionController = _chunk7BG5XOXJjs.TransactionController;
|
|
41
40
|
//# sourceMappingURL=TransactionController.js.map
|
|
@@ -4,32 +4,31 @@ import {
|
|
|
4
4
|
HARDFORK,
|
|
5
5
|
SPEED_UP_RATE,
|
|
6
6
|
TransactionController
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-JRBREX22.mjs";
|
|
7
|
+
} from "./chunk-I6RY3XOG.mjs";
|
|
9
8
|
import "./chunk-NM6OYEPP.mjs";
|
|
10
|
-
import "./chunk-
|
|
9
|
+
import "./chunk-XKNFL657.mjs";
|
|
11
10
|
import "./chunk-XGRAHX6T.mjs";
|
|
12
11
|
import "./chunk-NHRBO3LU.mjs";
|
|
13
|
-
import "./chunk-
|
|
14
|
-
import "./chunk-
|
|
15
|
-
import "./chunk-
|
|
12
|
+
import "./chunk-BYBPZUHS.mjs";
|
|
13
|
+
import "./chunk-6XMG522E.mjs";
|
|
14
|
+
import "./chunk-JRBREX22.mjs";
|
|
15
|
+
import "./chunk-5UL3VDFT.mjs";
|
|
16
|
+
import "./chunk-KFL2GGZC.mjs";
|
|
16
17
|
import "./chunk-Y7ENNK7L.mjs";
|
|
17
|
-
import "./chunk-
|
|
18
|
-
import "./chunk-RU6NJIUD.mjs";
|
|
18
|
+
import "./chunk-ZQFMTLZJ.mjs";
|
|
19
19
|
import "./chunk-JRQHIBG5.mjs";
|
|
20
|
-
import "./chunk-RIYIJTEU.mjs";
|
|
21
20
|
import "./chunk-FRKQ3Z2L.mjs";
|
|
22
|
-
import "./chunk-
|
|
23
|
-
import "./chunk-
|
|
24
|
-
import "./chunk-
|
|
25
|
-
import "./chunk-
|
|
21
|
+
import "./chunk-PGTV7236.mjs";
|
|
22
|
+
import "./chunk-QRSTF45Q.mjs";
|
|
23
|
+
import "./chunk-IK55QTGO.mjs";
|
|
24
|
+
import "./chunk-3D3SA6PY.mjs";
|
|
26
25
|
import "./chunk-J56A7UCK.mjs";
|
|
27
|
-
import "./chunk-
|
|
28
|
-
import "./chunk-
|
|
29
|
-
import "./chunk-
|
|
30
|
-
import "./chunk-
|
|
31
|
-
import "./chunk-DTMKGTYC.mjs";
|
|
26
|
+
import "./chunk-DWHMMJOW.mjs";
|
|
27
|
+
import "./chunk-IZI7FQIN.mjs";
|
|
28
|
+
import "./chunk-VEREDMI2.mjs";
|
|
29
|
+
import "./chunk-Z3HHSD5I.mjs";
|
|
32
30
|
import "./chunk-UQQWZT6C.mjs";
|
|
31
|
+
import "./chunk-W57BD6NX.mjs";
|
|
33
32
|
import "./chunk-XUI43LEZ.mjs";
|
|
34
33
|
export {
|
|
35
34
|
ApprovalState,
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-J56A7UCK.mjs";
|
|
4
4
|
import {
|
|
5
5
|
CHAIN_IDS
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-Z3HHSD5I.mjs";
|
|
7
7
|
import {
|
|
8
8
|
createModuleLogger,
|
|
9
9
|
projectLogger
|
|
@@ -208,4 +208,4 @@ export {
|
|
|
208
208
|
updateSwapsTransaction,
|
|
209
209
|
updatePostTransactionBalance
|
|
210
210
|
};
|
|
211
|
-
//# sourceMappingURL=chunk-
|
|
211
|
+
//# sourceMappingURL=chunk-3D3SA6PY.mjs.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunk5OQ373JSjs = require('./chunk-5OQ373JS.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkTZTP4JVAjs = require('./chunk-TZTP4JVA.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
var _chunkS6VGOPUYjs = require('./chunk-S6VGOPUY.js');
|
|
@@ -20,7 +20,7 @@ var log = _utils.createModuleLogger.call(void 0, _chunkS6VGOPUYjs.projectLogger,
|
|
|
20
20
|
async function updateGasFees(request) {
|
|
21
21
|
const { txMeta } = request;
|
|
22
22
|
const initialParams = { ...txMeta.txParams };
|
|
23
|
-
const isSwap =
|
|
23
|
+
const isSwap = _chunk5OQ373JSjs.SWAP_TRANSACTION_TYPES.includes(
|
|
24
24
|
txMeta.type
|
|
25
25
|
);
|
|
26
26
|
const savedGasFees = isSwap ? void 0 : request.getSavedGasFees(txMeta.chainId);
|
|
@@ -185,7 +185,7 @@ async function getSuggestedGasFees(request) {
|
|
|
185
185
|
if (!eip1559 && txMeta.txParams.gasPrice || eip1559 && txMeta.txParams.maxFeePerGas && txMeta.txParams.maxPriorityFeePerGas) {
|
|
186
186
|
return {};
|
|
187
187
|
}
|
|
188
|
-
const gasFeeFlow =
|
|
188
|
+
const gasFeeFlow = _chunkTZTP4JVAjs.getGasFeeFlow.call(void 0, txMeta, gasFeeFlows);
|
|
189
189
|
try {
|
|
190
190
|
const response = await gasFeeFlow.getGasFees({
|
|
191
191
|
ethQuery,
|
|
@@ -205,4 +205,4 @@ async function getSuggestedGasFees(request) {
|
|
|
205
205
|
|
|
206
206
|
|
|
207
207
|
exports.updateGasFees = updateGasFees; exports.gweiDecimalToWeiHex = gweiDecimalToWeiHex;
|
|
208
|
-
//# sourceMappingURL=chunk-
|
|
208
|
+
//# sourceMappingURL=chunk-5IHLDAOF.js.map
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var _chunkUGFBA4GVjs = require('./chunk-UGFBA4GV.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkITDY6AIZjs = require('./chunk-ITDY6AIZ.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
@@ -57,15 +57,15 @@ var ZKSYNC_ERA_SWAPS_TOKEN_OBJECT = {
|
|
|
57
57
|
...ETH_SWAPS_TOKEN_OBJECT
|
|
58
58
|
};
|
|
59
59
|
var SWAPS_CHAINID_DEFAULT_TOKEN_MAP = {
|
|
60
|
-
[
|
|
60
|
+
[_chunkITDY6AIZjs.CHAIN_IDS.MAINNET]: ETH_SWAPS_TOKEN_OBJECT,
|
|
61
61
|
[SWAPS_TESTNET_CHAIN_ID]: TEST_ETH_SWAPS_TOKEN_OBJECT,
|
|
62
|
-
[
|
|
63
|
-
[
|
|
64
|
-
[
|
|
65
|
-
[
|
|
66
|
-
[
|
|
67
|
-
[
|
|
68
|
-
[
|
|
62
|
+
[_chunkITDY6AIZjs.CHAIN_IDS.BSC]: BNB_SWAPS_TOKEN_OBJECT,
|
|
63
|
+
[_chunkITDY6AIZjs.CHAIN_IDS.POLYGON]: MATIC_SWAPS_TOKEN_OBJECT,
|
|
64
|
+
[_chunkITDY6AIZjs.CHAIN_IDS.GOERLI]: GOERLI_SWAPS_TOKEN_OBJECT,
|
|
65
|
+
[_chunkITDY6AIZjs.CHAIN_IDS.AVALANCHE]: AVAX_SWAPS_TOKEN_OBJECT,
|
|
66
|
+
[_chunkITDY6AIZjs.CHAIN_IDS.OPTIMISM]: OPTIMISM_SWAPS_TOKEN_OBJECT,
|
|
67
|
+
[_chunkITDY6AIZjs.CHAIN_IDS.ARBITRUM]: ARBITRUM_SWAPS_TOKEN_OBJECT,
|
|
68
|
+
[_chunkITDY6AIZjs.CHAIN_IDS.ZKSYNC_ERA]: ZKSYNC_ERA_SWAPS_TOKEN_OBJECT
|
|
69
69
|
};
|
|
70
70
|
var SWAP_TRANSACTION_TYPES = [
|
|
71
71
|
"swap" /* swap */,
|
|
@@ -208,4 +208,4 @@ function sleep(ms) {
|
|
|
208
208
|
|
|
209
209
|
|
|
210
210
|
exports.UPDATE_POST_TX_BALANCE_TIMEOUT = UPDATE_POST_TX_BALANCE_TIMEOUT; exports.UPDATE_POST_TX_BALANCE_ATTEMPTS = UPDATE_POST_TX_BALANCE_ATTEMPTS; exports.DEFAULT_TOKEN_ADDRESS = DEFAULT_TOKEN_ADDRESS; exports.SWAPS_CHAINID_DEFAULT_TOKEN_MAP = SWAPS_CHAINID_DEFAULT_TOKEN_MAP; exports.SWAP_TRANSACTION_TYPES = SWAP_TRANSACTION_TYPES; exports.updateSwapsTransaction = updateSwapsTransaction; exports.updatePostTransactionBalance = updatePostTransactionBalance;
|
|
211
|
-
//# sourceMappingURL=chunk-
|
|
211
|
+
//# sourceMappingURL=chunk-5OQ373JS.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getGasFeeFlow
|
|
3
|
-
} from "./chunk-6KYPLIXG.mjs";
|
|
4
1
|
import {
|
|
5
2
|
updateTransactionLayer1GasFee
|
|
6
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-KFL2GGZC.mjs";
|
|
4
|
+
import {
|
|
5
|
+
getGasFeeFlow
|
|
6
|
+
} from "./chunk-DWHMMJOW.mjs";
|
|
7
7
|
import {
|
|
8
8
|
projectLogger
|
|
9
9
|
} from "./chunk-UQQWZT6C.mjs";
|
|
@@ -19,7 +19,7 @@ import { createModuleLogger } from "@metamask/utils";
|
|
|
19
19
|
import EventEmitter from "events";
|
|
20
20
|
var log = createModuleLogger(projectLogger, "gas-fee-poller");
|
|
21
21
|
var INTERVAL_MILLISECONDS = 1e4;
|
|
22
|
-
var _gasFeeFlows, _getEthQuery, _getGasFeeControllerEstimates,
|
|
22
|
+
var _gasFeeFlows, _getEthQuery, _getGasFeeControllerEstimates, _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
23
|
var GasFeePoller = class {
|
|
24
24
|
/**
|
|
25
25
|
* Constructs a new instance of the GasFeePoller.
|
|
@@ -27,7 +27,6 @@ var GasFeePoller = class {
|
|
|
27
27
|
* @param options.gasFeeFlows - The gas fee flows to use to obtain suitable gas fees.
|
|
28
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.
|
|
31
30
|
* @param options.getTransactions - Callback to obtain the transaction data.
|
|
32
31
|
* @param options.layer1GasFeeFlows - The layer 1 gas fee flows to use to obtain suitable layer 1 gas fees.
|
|
33
32
|
* @param options.onStateChange - Callback to register a listener for controller state changes.
|
|
@@ -36,7 +35,6 @@ var GasFeePoller = class {
|
|
|
36
35
|
gasFeeFlows,
|
|
37
36
|
getEthQuery,
|
|
38
37
|
getGasFeeControllerEstimates,
|
|
39
|
-
getProvider,
|
|
40
38
|
getTransactions,
|
|
41
39
|
layer1GasFeeFlows,
|
|
42
40
|
onStateChange
|
|
@@ -52,7 +50,6 @@ var GasFeePoller = class {
|
|
|
52
50
|
__privateAdd(this, _gasFeeFlows, void 0);
|
|
53
51
|
__privateAdd(this, _getEthQuery, void 0);
|
|
54
52
|
__privateAdd(this, _getGasFeeControllerEstimates, void 0);
|
|
55
|
-
__privateAdd(this, _getProvider, void 0);
|
|
56
53
|
__privateAdd(this, _getTransactions, void 0);
|
|
57
54
|
__privateAdd(this, _layer1GasFeeFlows, void 0);
|
|
58
55
|
__privateAdd(this, _timeout, void 0);
|
|
@@ -61,7 +58,6 @@ var GasFeePoller = class {
|
|
|
61
58
|
__privateSet(this, _layer1GasFeeFlows, layer1GasFeeFlows);
|
|
62
59
|
__privateSet(this, _getEthQuery, getEthQuery);
|
|
63
60
|
__privateSet(this, _getGasFeeControllerEstimates, getGasFeeControllerEstimates);
|
|
64
|
-
__privateSet(this, _getProvider, getProvider);
|
|
65
61
|
__privateSet(this, _getTransactions, getTransactions);
|
|
66
62
|
onStateChange(() => {
|
|
67
63
|
const unapprovedTransactions = __privateMethod(this, _getUnapprovedTransactions, getUnapprovedTransactions_fn).call(this);
|
|
@@ -76,7 +72,6 @@ var GasFeePoller = class {
|
|
|
76
72
|
_gasFeeFlows = new WeakMap();
|
|
77
73
|
_getEthQuery = new WeakMap();
|
|
78
74
|
_getGasFeeControllerEstimates = new WeakMap();
|
|
79
|
-
_getProvider = new WeakMap();
|
|
80
75
|
_getTransactions = new WeakMap();
|
|
81
76
|
_layer1GasFeeFlows = new WeakMap();
|
|
82
77
|
_timeout = new WeakMap();
|
|
@@ -163,9 +158,9 @@ updateTransactionSuggestedFees_fn = async function(transactionMeta) {
|
|
|
163
158
|
_updateTransactionLayer1GasFee = new WeakSet();
|
|
164
159
|
updateTransactionLayer1GasFee_fn = async function(transactionMeta) {
|
|
165
160
|
const { chainId, networkClientId } = transactionMeta;
|
|
166
|
-
const
|
|
161
|
+
const ethQuery = __privateGet(this, _getEthQuery).call(this, chainId, networkClientId);
|
|
167
162
|
await updateTransactionLayer1GasFee({
|
|
168
|
-
|
|
163
|
+
ethQuery,
|
|
169
164
|
layer1GasFeeFlows: __privateGet(this, _layer1GasFeeFlows),
|
|
170
165
|
transactionMeta
|
|
171
166
|
});
|
|
@@ -184,4 +179,4 @@ getUnapprovedTransactions_fn = function() {
|
|
|
184
179
|
export {
|
|
185
180
|
GasFeePoller
|
|
186
181
|
};
|
|
187
|
-
//# sourceMappingURL=chunk-
|
|
182
|
+
//# sourceMappingURL=chunk-5UL3VDFT.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/helpers/GasFeePoller.ts"],"sourcesContent":["import type EthQuery from '@metamask/eth-query';\nimport type { GasFeeState } from '@metamask/gas-fee-controller';\nimport type { NetworkClientId } 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 #getEthQuery: (chainId: Hex, networkClientId?: NetworkClientId) => EthQuery;\n\n #getGasFeeControllerEstimates: () => Promise<GasFeeState>;\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.getEthQuery - Callback to obtain an EthQuery instance.\n * @param options.getGasFeeControllerEstimates - Callback to obtain the default fee estimates.\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 getEthQuery,\n getGasFeeControllerEstimates,\n getTransactions,\n layer1GasFeeFlows,\n onStateChange,\n }: {\n gasFeeFlows: GasFeeFlow[];\n getEthQuery: (chainId: Hex, networkClientId?: NetworkClientId) => EthQuery;\n getGasFeeControllerEstimates: () => Promise<GasFeeState>;\n getTransactions: () => TransactionMeta[];\n layer1GasFeeFlows: Layer1GasFeeFlow[];\n onStateChange: (listener: () => void) => void;\n }) {\n this.#gasFeeFlows = gasFeeFlows;\n this.#layer1GasFeeFlows = layer1GasFeeFlows;\n this.#getEthQuery = getEthQuery;\n this.#getGasFeeControllerEstimates = getGasFeeControllerEstimates;\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 = this.#getEthQuery(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 ethQuery = this.#getEthQuery(chainId, networkClientId);\n\n await updateTransactionLayer1GasFee({\n ethQuery,\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":"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","names":[]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {
|
|
2
|
+
projectLogger
|
|
3
|
+
} from "./chunk-UQQWZT6C.mjs";
|
|
4
|
+
|
|
5
|
+
// src/utils/simulation-api.ts
|
|
6
|
+
import { convertHexToDecimal } from "@metamask/controller-utils";
|
|
7
|
+
import { createModuleLogger } from "@metamask/utils";
|
|
8
|
+
var log = createModuleLogger(projectLogger, "simulation-api");
|
|
9
|
+
var RPC_METHOD = "infura_simulateTransactions";
|
|
10
|
+
var BASE_URL = "https://tx-sentinel-{0}.api.cx.metamask.io/";
|
|
11
|
+
var ENDPOINT_NETWORKS = "networks";
|
|
12
|
+
var requestIdCounter = 0;
|
|
13
|
+
async function simulateTransactions(chainId, request) {
|
|
14
|
+
const url = await getSimulationUrl(chainId);
|
|
15
|
+
log("Sending request", url, request);
|
|
16
|
+
const requestId = requestIdCounter;
|
|
17
|
+
requestIdCounter += 1;
|
|
18
|
+
const response = await fetch(url, {
|
|
19
|
+
method: "POST",
|
|
20
|
+
body: JSON.stringify({
|
|
21
|
+
id: String(requestId),
|
|
22
|
+
jsonrpc: "2.0",
|
|
23
|
+
method: RPC_METHOD,
|
|
24
|
+
params: [request]
|
|
25
|
+
})
|
|
26
|
+
});
|
|
27
|
+
const responseJson = await response.json();
|
|
28
|
+
log("Received response", responseJson);
|
|
29
|
+
if (responseJson.error) {
|
|
30
|
+
throw responseJson.error;
|
|
31
|
+
}
|
|
32
|
+
return responseJson?.result;
|
|
33
|
+
}
|
|
34
|
+
async function getSimulationUrl(chainId) {
|
|
35
|
+
const networkData = await getNetworkData();
|
|
36
|
+
const chainIdDecimal = convertHexToDecimal(chainId);
|
|
37
|
+
const network = networkData[chainIdDecimal];
|
|
38
|
+
if (!network?.confirmations) {
|
|
39
|
+
log("Chain is not supported", chainId);
|
|
40
|
+
throw new Error(`Chain is not supported: ${chainId}`);
|
|
41
|
+
}
|
|
42
|
+
return getUrl(network.network);
|
|
43
|
+
}
|
|
44
|
+
async function getNetworkData() {
|
|
45
|
+
const url = `${getUrl("ethereum-mainnet")}${ENDPOINT_NETWORKS}`;
|
|
46
|
+
const response = await fetch(url);
|
|
47
|
+
return response.json();
|
|
48
|
+
}
|
|
49
|
+
function getUrl(subdomain) {
|
|
50
|
+
return BASE_URL.replace("{0}", subdomain);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export {
|
|
54
|
+
simulateTransactions
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=chunk-6XMG522E.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/simulation-api.ts"],"sourcesContent":["import { convertHexToDecimal } from '@metamask/controller-utils';\nimport { createModuleLogger, type Hex } from '@metamask/utils';\n\nimport { projectLogger } from '../logger';\n\nconst log = createModuleLogger(projectLogger, 'simulation-api');\n\nconst RPC_METHOD = 'infura_simulateTransactions';\nconst BASE_URL = 'https://tx-sentinel-{0}.api.cx.metamask.io/';\nconst ENDPOINT_NETWORKS = 'networks';\n\n/** Single transaction to simulate in a simulation API request. */\nexport type SimulationRequestTransaction = {\n /** Data to send with the transaction. */\n data?: Hex;\n\n /** Sender of the transaction. */\n from: Hex;\n\n /** Gas limit for the transaction. */\n gas?: Hex;\n\n /** Maximum fee per gas for the transaction. */\n maxFeePerGas?: Hex;\n\n /** Maximum priority fee per gas for the transaction. */\n maxPriorityFeePerGas?: Hex;\n\n /** Recipient of the transaction. */\n to?: Hex;\n\n /** Value to send with the transaction. */\n value?: Hex;\n};\n\n/** Request to the simulation API to simulate transactions. */\nexport type SimulationRequest = {\n /**\n * Transactions to be sequentially simulated.\n * State changes impact subsequent transactions in the list.\n */\n transactions: SimulationRequestTransaction[];\n\n /**\n * Overrides to the state of the blockchain, keyed by smart contract address.\n */\n overrides?: {\n [address: Hex]: {\n /** Overrides to the storage slots for a smart contract account. */\n stateDiff: {\n [slot: Hex]: Hex;\n };\n };\n };\n\n /**\n * Whether to include call traces in the response.\n * Defaults to false.\n */\n withCallTrace?: boolean;\n\n /**\n * Whether to include event logs in the response.\n * Defaults to false.\n */\n withLogs?: boolean;\n};\n\n/** Raw event log emitted by a simulated transaction. */\nexport type SimulationResponseLog = {\n /** Address of the account that created the event. */\n address: Hex;\n\n /** Raw data in the event that is not indexed. */\n data: Hex;\n\n /** Raw indexed data from the event. */\n topics: Hex[];\n};\n\n/** Call trace of a single simulated transaction. */\nexport type SimulationResponseCallTrace = {\n /** Nested calls. */\n calls: SimulationResponseCallTrace[];\n\n /** Raw event logs created by the call. */\n logs: SimulationResponseLog[];\n};\n\n/**\n * Changes to the blockchain state.\n * Keyed by account address.\n */\nexport type SimulationResponseStateDiff = {\n [address: Hex]: {\n /** Native balance of the account. */\n balance?: Hex;\n\n /** Nonce of the account. */\n nonce?: Hex;\n\n /** Storage values per slot. */\n storage?: {\n [slot: Hex]: Hex;\n };\n };\n};\n\n/** Response from the simulation API for a single transaction. */\nexport type SimulationResponseTransaction = {\n /** An error message indicating the transaction could not be simulated. */\n error?: string;\n\n /** Return value of the transaction, such as the balance if calling balanceOf. */\n return: Hex;\n\n /** Hierarchy of call data including nested calls and logs. */\n callTrace?: SimulationResponseCallTrace;\n\n /** Changes to the blockchain state. */\n stateDiff?: {\n /** Initial blockchain state before the transaction. */\n pre?: SimulationResponseStateDiff;\n\n /** Updated blockchain state after the transaction. */\n post?: SimulationResponseStateDiff;\n };\n};\n\n/** Response from the simulation API. */\nexport type SimulationResponse = {\n /** Simulation data for each transaction in the request. */\n transactions: SimulationResponseTransaction[];\n};\n\n/** Data for a network supported by the Simulation API. */\ntype SimulationNetwork = {\n /** Subdomain of the API for the network. */\n network: string;\n\n /** Whether the network supports confirmation simulations. */\n confirmations: boolean;\n};\n\n/** Response from the simulation API containing supported networks. */\ntype SimulationNetworkResponse = {\n [chainIdDecimal: string]: SimulationNetwork;\n};\n\nlet requestIdCounter = 0;\n\n/**\n * Simulate transactions using the transaction simulation API.\n * @param chainId - The chain ID to simulate transactions on.\n * @param request - The request to simulate transactions.\n */\nexport async function simulateTransactions(\n chainId: Hex,\n request: SimulationRequest,\n): Promise<SimulationResponse> {\n const url = await getSimulationUrl(chainId);\n\n log('Sending request', url, request);\n\n const requestId = requestIdCounter;\n requestIdCounter += 1;\n\n const response = await fetch(url, {\n method: 'POST',\n body: JSON.stringify({\n id: String(requestId),\n jsonrpc: '2.0',\n method: RPC_METHOD,\n params: [request],\n }),\n });\n\n const responseJson = await response.json();\n\n log('Received response', responseJson);\n\n if (responseJson.error) {\n throw responseJson.error;\n }\n\n return responseJson?.result;\n}\n\n/**\n * Get the URL for the transaction simulation API.\n * @param chainId - The chain ID to get the URL for.\n * @returns The URL for the transaction simulation API.\n */\nasync function getSimulationUrl(chainId: Hex): Promise<string> {\n const networkData = await getNetworkData();\n const chainIdDecimal = convertHexToDecimal(chainId);\n const network = networkData[chainIdDecimal];\n\n if (!network?.confirmations) {\n log('Chain is not supported', chainId);\n throw new Error(`Chain is not supported: ${chainId}`);\n }\n\n return getUrl(network.network);\n}\n\n/**\n * Retrieve the supported network data from the simulation API.\n */\nasync function getNetworkData(): Promise<SimulationNetworkResponse> {\n const url = `${getUrl('ethereum-mainnet')}${ENDPOINT_NETWORKS}`;\n const response = await fetch(url);\n return response.json();\n}\n\n/**\n * Generate the URL for the specified subdomain in the simulation API.\n * @param subdomain - The subdomain to generate the URL for.\n * @returns The URL for the transaction simulation API.\n */\nfunction getUrl(subdomain: string): string {\n return BASE_URL.replace('{0}', subdomain);\n}\n"],"mappings":";;;;;AAAA,SAAS,2BAA2B;AACpC,SAAS,0BAAoC;AAI7C,IAAM,MAAM,mBAAmB,eAAe,gBAAgB;AAE9D,IAAM,aAAa;AACnB,IAAM,WAAW;AACjB,IAAM,oBAAoB;AA4I1B,IAAI,mBAAmB;AAOvB,eAAsB,qBACpB,SACA,SAC6B;AAC7B,QAAM,MAAM,MAAM,iBAAiB,OAAO;AAE1C,MAAI,mBAAmB,KAAK,OAAO;AAEnC,QAAM,YAAY;AAClB,sBAAoB;AAEpB,QAAM,WAAW,MAAM,MAAM,KAAK;AAAA,IAChC,QAAQ;AAAA,IACR,MAAM,KAAK,UAAU;AAAA,MACnB,IAAI,OAAO,SAAS;AAAA,MACpB,SAAS;AAAA,MACT,QAAQ;AAAA,MACR,QAAQ,CAAC,OAAO;AAAA,IAClB,CAAC;AAAA,EACH,CAAC;AAED,QAAM,eAAe,MAAM,SAAS,KAAK;AAEzC,MAAI,qBAAqB,YAAY;AAErC,MAAI,aAAa,OAAO;AACtB,UAAM,aAAa;AAAA,EACrB;AAEA,SAAO,cAAc;AACvB;AAOA,eAAe,iBAAiB,SAA+B;AAC7D,QAAM,cAAc,MAAM,eAAe;AACzC,QAAM,iBAAiB,oBAAoB,OAAO;AAClD,QAAM,UAAU,YAAY,cAAc;AAE1C,MAAI,CAAC,SAAS,eAAe;AAC3B,QAAI,0BAA0B,OAAO;AACrC,UAAM,IAAI,MAAM,2BAA2B,OAAO,EAAE;AAAA,EACtD;AAEA,SAAO,OAAO,QAAQ,OAAO;AAC/B;AAKA,eAAe,iBAAqD;AAClE,QAAM,MAAM,GAAG,OAAO,kBAAkB,CAAC,GAAG,iBAAiB;AAC7D,QAAM,WAAW,MAAM,MAAM,GAAG;AAChC,SAAO,SAAS,KAAK;AACvB;AAOA,SAAS,OAAO,WAA2B;AACzC,SAAO,SAAS,QAAQ,OAAO,SAAS;AAC1C;","names":[]}
|