@metamask/transaction-controller 23.1.0 → 25.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 +134 -1
- package/dist/TransactionController.js +38 -1816
- package/dist/TransactionController.js.map +1 -1
- package/dist/TransactionController.mjs +39 -0
- package/dist/TransactionController.mjs.map +1 -0
- package/dist/chunk-2K7J3EY3.mjs +170 -0
- package/dist/chunk-2K7J3EY3.mjs.map +1 -0
- package/dist/chunk-5XBULBP2.js +399 -0
- package/dist/chunk-5XBULBP2.js.map +1 -0
- package/dist/chunk-6MYNWYJK.mjs +158 -0
- package/dist/chunk-6MYNWYJK.mjs.map +1 -0
- package/dist/chunk-7APMBUKB.js +158 -0
- package/dist/chunk-7APMBUKB.js.map +1 -0
- package/dist/chunk-7LXE4KHV.js +40 -0
- package/dist/chunk-7LXE4KHV.js.map +1 -0
- package/dist/chunk-7MZ57ILQ.mjs +62 -0
- package/dist/chunk-7MZ57ILQ.mjs.map +1 -0
- package/dist/chunk-BJEESIBE.js +2313 -0
- package/dist/chunk-BJEESIBE.js.map +1 -0
- package/dist/chunk-C67QD5PV.mjs +320 -0
- package/dist/chunk-C67QD5PV.mjs.map +1 -0
- package/dist/chunk-DE3MZYVY.mjs +2313 -0
- package/dist/chunk-DE3MZYVY.mjs.map +1 -0
- package/dist/chunk-DEKM6PVG.mjs +46 -0
- package/dist/chunk-DEKM6PVG.mjs.map +1 -0
- package/dist/chunk-DQP6X25N.mjs +208 -0
- package/dist/chunk-DQP6X25N.mjs.map +1 -0
- package/dist/chunk-DTDTOMTB.js +238 -0
- package/dist/chunk-DTDTOMTB.js.map +1 -0
- package/dist/chunk-DTEDYRTL.js +242 -0
- package/dist/chunk-DTEDYRTL.js.map +1 -0
- package/dist/chunk-EQ3RRHB7.mjs +211 -0
- package/dist/chunk-EQ3RRHB7.mjs.map +1 -0
- package/dist/chunk-FDJPXQTF.js +46 -0
- package/dist/chunk-FDJPXQTF.js.map +1 -0
- package/dist/chunk-FRKQ3Z2L.mjs +40 -0
- package/dist/chunk-FRKQ3Z2L.mjs.map +1 -0
- package/dist/chunk-FS7FRO7B.mjs +90 -0
- package/dist/chunk-FS7FRO7B.mjs.map +1 -0
- package/dist/chunk-GKTIFXPN.js +170 -0
- package/dist/chunk-GKTIFXPN.js.map +1 -0
- package/dist/chunk-H4M66BA3.js +62 -0
- package/dist/chunk-H4M66BA3.js.map +1 -0
- package/dist/chunk-HPNXIKFY.js +76 -0
- package/dist/chunk-HPNXIKFY.js.map +1 -0
- package/dist/chunk-HS277C77.js +75 -0
- package/dist/chunk-HS277C77.js.map +1 -0
- package/dist/chunk-I5YZ7QUK.js +121 -0
- package/dist/chunk-I5YZ7QUK.js.map +1 -0
- package/dist/chunk-IC233ZQS.js +211 -0
- package/dist/chunk-IC233ZQS.js.map +1 -0
- package/dist/chunk-IUBAETUH.js +137 -0
- package/dist/chunk-IUBAETUH.js.map +1 -0
- package/dist/chunk-J56A7UCK.mjs +123 -0
- package/dist/chunk-J56A7UCK.mjs.map +1 -0
- package/dist/chunk-JR6HDRNV.mjs +242 -0
- package/dist/chunk-JR6HDRNV.mjs.map +1 -0
- package/dist/chunk-JRBREX22.mjs +75 -0
- package/dist/chunk-JRBREX22.mjs.map +1 -0
- package/dist/chunk-JRQHIBG5.mjs +399 -0
- package/dist/chunk-JRQHIBG5.mjs.map +1 -0
- package/dist/chunk-LM4NUNMT.mjs +76 -0
- package/dist/chunk-LM4NUNMT.mjs.map +1 -0
- package/dist/chunk-M7455RU7.js +320 -0
- package/dist/chunk-M7455RU7.js.map +1 -0
- package/dist/chunk-MHM5LRRF.mjs +122 -0
- package/dist/chunk-MHM5LRRF.mjs.map +1 -0
- package/dist/chunk-NHRBO3LU.mjs +50 -0
- package/dist/chunk-NHRBO3LU.mjs.map +1 -0
- package/dist/chunk-NM6OYEPP.mjs +182 -0
- package/dist/chunk-NM6OYEPP.mjs.map +1 -0
- package/dist/chunk-NUOBUW7C.js +85 -0
- package/dist/chunk-NUOBUW7C.js.map +1 -0
- package/dist/chunk-QP75SWIQ.js +53 -0
- package/dist/chunk-QP75SWIQ.js.map +1 -0
- package/dist/chunk-RI6MVJJN.js +122 -0
- package/dist/chunk-RI6MVJJN.js.map +1 -0
- package/dist/chunk-S6VGOPUY.js +14 -0
- package/dist/chunk-S6VGOPUY.js.map +1 -0
- package/dist/chunk-UGFBA4GV.js +123 -0
- package/dist/chunk-UGFBA4GV.js.map +1 -0
- package/dist/chunk-UKYY2RVS.mjs +137 -0
- package/dist/chunk-UKYY2RVS.mjs.map +1 -0
- package/dist/chunk-UM4ORJ5B.mjs +121 -0
- package/dist/chunk-UM4ORJ5B.mjs.map +1 -0
- package/dist/chunk-UQQWZT6C.mjs +14 -0
- package/dist/chunk-UQQWZT6C.mjs.map +1 -0
- package/dist/chunk-VH47Q6TS.js +182 -0
- package/dist/chunk-VH47Q6TS.js.map +1 -0
- package/dist/chunk-XGRAHX6T.mjs +53 -0
- package/dist/chunk-XGRAHX6T.mjs.map +1 -0
- package/dist/chunk-XUI43LEZ.mjs +30 -0
- package/dist/chunk-XUI43LEZ.mjs.map +1 -0
- package/dist/chunk-Y734U4V6.mjs +85 -0
- package/dist/chunk-Y734U4V6.mjs.map +1 -0
- package/dist/chunk-Y7ENNK7L.mjs +238 -0
- package/dist/chunk-Y7ENNK7L.mjs.map +1 -0
- package/dist/chunk-Z4BLTVTB.js +30 -0
- package/dist/chunk-Z4BLTVTB.js.map +1 -0
- package/dist/chunk-ZCQRDZ36.js +208 -0
- package/dist/chunk-ZCQRDZ36.js.map +1 -0
- package/dist/chunk-ZJLZSFOZ.js +90 -0
- package/dist/chunk-ZJLZSFOZ.js.map +1 -0
- package/dist/chunk-ZNZEJDOE.js +50 -0
- package/dist/chunk-ZNZEJDOE.js.map +1 -0
- package/dist/constants.js +15 -110
- package/dist/constants.js.map +1 -1
- package/dist/constants.mjs +16 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/gas-flows/DefaultGasFeeFlow.js +14 -77
- package/dist/gas-flows/DefaultGasFeeFlow.js.map +1 -1
- package/dist/gas-flows/DefaultGasFeeFlow.mjs +15 -0
- package/dist/gas-flows/DefaultGasFeeFlow.mjs.map +1 -0
- package/dist/gas-flows/LineaGasFeeFlow.js +15 -110
- package/dist/gas-flows/LineaGasFeeFlow.js.map +1 -1
- package/dist/gas-flows/LineaGasFeeFlow.mjs +16 -0
- package/dist/gas-flows/LineaGasFeeFlow.mjs.map +1 -0
- package/dist/helpers/EtherscanRemoteTransactionSource.js +11 -145
- package/dist/helpers/EtherscanRemoteTransactionSource.js.map +1 -1
- package/dist/helpers/EtherscanRemoteTransactionSource.mjs +12 -0
- package/dist/helpers/EtherscanRemoteTransactionSource.mjs.map +1 -0
- package/dist/helpers/GasFeePoller.js +10 -143
- package/dist/helpers/GasFeePoller.js.map +1 -1
- package/dist/helpers/GasFeePoller.mjs +11 -0
- package/dist/helpers/GasFeePoller.mjs.map +1 -0
- package/dist/helpers/IncomingTransactionHelper.js +8 -205
- package/dist/helpers/IncomingTransactionHelper.js.map +1 -1
- package/dist/helpers/IncomingTransactionHelper.mjs +9 -0
- package/dist/helpers/IncomingTransactionHelper.mjs.map +1 -0
- package/dist/helpers/MultichainTrackingHelper.js +12 -291
- package/dist/helpers/MultichainTrackingHelper.js.map +1 -1
- package/dist/helpers/MultichainTrackingHelper.mjs +13 -0
- package/dist/helpers/MultichainTrackingHelper.mjs.map +1 -0
- package/dist/helpers/PendingTransactionTracker.js +9 -360
- package/dist/helpers/PendingTransactionTracker.js.map +1 -1
- package/dist/helpers/PendingTransactionTracker.mjs +10 -0
- package/dist/helpers/PendingTransactionTracker.mjs.map +1 -0
- package/dist/index.js +56 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +57 -0
- package/dist/index.mjs.map +1 -0
- package/dist/logger.js +11 -8
- package/dist/logger.js.map +1 -1
- package/dist/logger.mjs +12 -0
- package/dist/logger.mjs.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/{TransactionController.d.ts → types/TransactionController.d.ts} +235 -46
- package/dist/types/TransactionController.d.ts.map +1 -0
- package/dist/{constants.d.ts → types/constants.d.ts} +8 -3
- package/dist/types/constants.d.ts.map +1 -0
- package/dist/types/gas-flows/DefaultGasFeeFlow.d.ts.map +1 -0
- package/dist/types/gas-flows/LineaGasFeeFlow.d.ts.map +1 -0
- package/dist/types/helpers/EtherscanRemoteTransactionSource.d.ts.map +1 -0
- package/dist/types/helpers/GasFeePoller.d.ts.map +1 -0
- package/dist/types/helpers/IncomingTransactionHelper.d.ts.map +1 -0
- package/dist/types/helpers/MultichainTrackingHelper.d.ts.map +1 -0
- package/dist/types/helpers/PendingTransactionTracker.d.ts.map +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/logger.d.ts.map +1 -0
- package/dist/{types.d.ts → types/types.d.ts} +63 -65
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/utils/etherscan.d.ts.map +1 -0
- package/dist/types/utils/external-transactions.d.ts.map +1 -0
- package/dist/types/utils/gas-fees.d.ts.map +1 -0
- package/dist/types/utils/gas-flow.d.ts.map +1 -0
- package/dist/types/utils/gas.d.ts.map +1 -0
- package/dist/types/utils/history.d.ts +20 -0
- package/dist/types/utils/history.d.ts.map +1 -0
- package/dist/types/utils/nonce.d.ts.map +1 -0
- package/dist/types/utils/simulation-api.d.ts +99 -0
- package/dist/types/utils/simulation-api.d.ts.map +1 -0
- package/dist/types/utils/simulation.d.ts +21 -0
- package/dist/types/utils/simulation.d.ts.map +1 -0
- package/dist/{utils → types/utils}/swaps.d.ts +8 -5
- package/dist/types/utils/swaps.d.ts.map +1 -0
- package/dist/types/utils/transaction-type.d.ts.map +1 -0
- package/dist/{utils → types/utils}/utils.d.ts +9 -1
- package/dist/types/utils/utils.d.ts.map +1 -0
- package/dist/types/utils/validation.d.ts.map +1 -0
- package/dist/types.js +19 -170
- package/dist/types.js.map +1 -1
- package/dist/types.mjs +20 -0
- package/dist/types.mjs.map +1 -0
- package/dist/utils/etherscan.js +13 -118
- package/dist/utils/etherscan.js.map +1 -1
- package/dist/utils/etherscan.mjs +14 -0
- package/dist/utils/etherscan.mjs.map +1 -0
- package/dist/utils/external-transactions.js +8 -35
- package/dist/utils/external-transactions.js.map +1 -1
- package/dist/utils/external-transactions.mjs +9 -0
- package/dist/utils/external-transactions.mjs.map +1 -0
- package/dist/utils/gas-fees.js +15 -200
- package/dist/utils/gas-fees.js.map +1 -1
- package/dist/utils/gas-fees.mjs +16 -0
- package/dist/utils/gas-fees.mjs.map +1 -0
- package/dist/utils/gas-flow.js +10 -52
- package/dist/utils/gas-flow.js.map +1 -1
- package/dist/utils/gas-flow.mjs +11 -0
- package/dist/utils/gas-flow.mjs.map +1 -0
- package/dist/utils/gas.js +19 -133
- package/dist/utils/gas.js.map +1 -1
- package/dist/utils/gas.mjs +20 -0
- package/dist/utils/gas.mjs.map +1 -0
- package/dist/utils/history.js +9 -83
- package/dist/utils/history.js.map +1 -1
- package/dist/utils/history.mjs +10 -0
- package/dist/utils/history.mjs.map +1 -0
- package/dist/utils/nonce.js +10 -76
- package/dist/utils/nonce.js.map +1 -1
- package/dist/utils/nonce.mjs +11 -0
- package/dist/utils/nonce.mjs.map +1 -0
- package/dist/utils/simulation-api.js +10 -0
- package/dist/utils/simulation-api.js.map +1 -0
- package/dist/utils/simulation-api.mjs +10 -0
- package/dist/utils/simulation-api.mjs.map +1 -0
- package/dist/utils/simulation.js +12 -0
- package/dist/utils/simulation.js.map +1 -0
- package/dist/utils/simulation.mjs +12 -0
- package/dist/utils/simulation.mjs.map +1 -0
- package/dist/utils/swaps.js +23 -256
- package/dist/utils/swaps.js.map +1 -1
- package/dist/utils/swaps.mjs +24 -0
- package/dist/utils/swaps.mjs.map +1 -0
- package/dist/utils/transaction-type.js +10 -120
- package/dist/utils/transaction-type.js.map +1 -1
- package/dist/utils/transaction-type.mjs +11 -0
- package/dist/utils/transaction-type.mjs.map +1 -0
- package/dist/utils/utils.js +32 -146
- package/dist/utils/utils.js.map +1 -1
- package/dist/utils/utils.mjs +33 -0
- package/dist/utils/utils.mjs.map +1 -0
- package/dist/utils/validation.js +11 -258
- package/dist/utils/validation.js.map +1 -1
- package/dist/utils/validation.mjs +12 -0
- package/dist/utils/validation.mjs.map +1 -0
- package/package.json +21 -9
- package/dist/TransactionController.d.ts.map +0 -1
- package/dist/constants.d.ts.map +0 -1
- package/dist/gas-flows/DefaultGasFeeFlow.d.ts.map +0 -1
- package/dist/gas-flows/LineaGasFeeFlow.d.ts.map +0 -1
- package/dist/helpers/EtherscanRemoteTransactionSource.d.ts.map +0 -1
- package/dist/helpers/GasFeePoller.d.ts.map +0 -1
- package/dist/helpers/IncomingTransactionHelper.d.ts.map +0 -1
- package/dist/helpers/MultichainTrackingHelper.d.ts.map +0 -1
- package/dist/helpers/PendingTransactionTracker.d.ts.map +0 -1
- package/dist/index.d.ts +0 -7
- package/dist/index.d.ts.map +0 -1
- package/dist/logger.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/utils/etherscan.d.ts.map +0 -1
- package/dist/utils/external-transactions.d.ts.map +0 -1
- package/dist/utils/gas-fees.d.ts.map +0 -1
- package/dist/utils/gas-flow.d.ts.map +0 -1
- package/dist/utils/gas.d.ts.map +0 -1
- package/dist/utils/history.d.ts +0 -15
- package/dist/utils/history.d.ts.map +0 -1
- package/dist/utils/nonce.d.ts.map +0 -1
- package/dist/utils/swaps.d.ts.map +0 -1
- package/dist/utils/transaction-type.d.ts.map +0 -1
- package/dist/utils/utils.d.ts.map +0 -1
- package/dist/utils/validation.d.ts.map +0 -1
- /package/dist/{gas-flows → types/gas-flows}/DefaultGasFeeFlow.d.ts +0 -0
- /package/dist/{gas-flows → types/gas-flows}/LineaGasFeeFlow.d.ts +0 -0
- /package/dist/{helpers → types/helpers}/EtherscanRemoteTransactionSource.d.ts +0 -0
- /package/dist/{helpers → types/helpers}/GasFeePoller.d.ts +0 -0
- /package/dist/{helpers → types/helpers}/IncomingTransactionHelper.d.ts +0 -0
- /package/dist/{helpers → types/helpers}/MultichainTrackingHelper.d.ts +0 -0
- /package/dist/{helpers → types/helpers}/PendingTransactionTracker.d.ts +0 -0
- /package/dist/{logger.d.ts → types/logger.d.ts} +0 -0
- /package/dist/{utils → types/utils}/etherscan.d.ts +0 -0
- /package/dist/{utils → types/utils}/external-transactions.d.ts +0 -0
- /package/dist/{utils → types/utils}/gas-fees.d.ts +0 -0
- /package/dist/{utils → types/utils}/gas-flow.d.ts +0 -0
- /package/dist/{utils → types/utils}/gas.d.ts +0 -0
- /package/dist/{utils → types/utils}/nonce.d.ts +0 -0
- /package/dist/{utils → types/utils}/transaction-type.d.ts +0 -0
- /package/dist/{utils → types/utils}/validation.d.ts +0 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {
|
|
2
|
+
gweiDecimalToWeiHex
|
|
3
|
+
} from "./chunk-DQP6X25N.mjs";
|
|
4
|
+
import {
|
|
5
|
+
projectLogger
|
|
6
|
+
} from "./chunk-UQQWZT6C.mjs";
|
|
7
|
+
import {
|
|
8
|
+
GasFeeEstimateLevel
|
|
9
|
+
} from "./chunk-LM4NUNMT.mjs";
|
|
10
|
+
import {
|
|
11
|
+
__privateAdd,
|
|
12
|
+
__privateMethod
|
|
13
|
+
} from "./chunk-XUI43LEZ.mjs";
|
|
14
|
+
|
|
15
|
+
// src/gas-flows/DefaultGasFeeFlow.ts
|
|
16
|
+
import { GAS_ESTIMATE_TYPES } from "@metamask/gas-fee-controller";
|
|
17
|
+
import { createModuleLogger } from "@metamask/utils";
|
|
18
|
+
var log = createModuleLogger(projectLogger, "default-gas-fee-flow");
|
|
19
|
+
var _getEstimateLevel, getEstimateLevel_fn, _getFeeMarketLevel, getFeeMarketLevel_fn, _getLegacyLevel, getLegacyLevel_fn;
|
|
20
|
+
var DefaultGasFeeFlow = class {
|
|
21
|
+
constructor() {
|
|
22
|
+
__privateAdd(this, _getEstimateLevel);
|
|
23
|
+
__privateAdd(this, _getFeeMarketLevel);
|
|
24
|
+
__privateAdd(this, _getLegacyLevel);
|
|
25
|
+
}
|
|
26
|
+
matchesTransaction(_transactionMeta) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
async getGasFees(request) {
|
|
30
|
+
const { getGasFeeControllerEstimates, transactionMeta } = request;
|
|
31
|
+
const { networkClientId } = transactionMeta;
|
|
32
|
+
const { gasEstimateType, gasFeeEstimates } = await getGasFeeControllerEstimates({ networkClientId });
|
|
33
|
+
if (gasEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET) {
|
|
34
|
+
log("Using fee market estimates", gasFeeEstimates);
|
|
35
|
+
} else if (gasEstimateType === GAS_ESTIMATE_TYPES.LEGACY) {
|
|
36
|
+
log("Using legacy estimates", gasFeeEstimates);
|
|
37
|
+
} else {
|
|
38
|
+
throw new Error(`'No gas fee estimates available`);
|
|
39
|
+
}
|
|
40
|
+
const estimates = Object.values(GasFeeEstimateLevel).reduce(
|
|
41
|
+
(result, level) => ({
|
|
42
|
+
...result,
|
|
43
|
+
[level]: __privateMethod(this, _getEstimateLevel, getEstimateLevel_fn).call(this, {
|
|
44
|
+
gasEstimateType,
|
|
45
|
+
gasFeeEstimates,
|
|
46
|
+
level
|
|
47
|
+
})
|
|
48
|
+
}),
|
|
49
|
+
{}
|
|
50
|
+
);
|
|
51
|
+
return { estimates };
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
_getEstimateLevel = new WeakSet();
|
|
55
|
+
getEstimateLevel_fn = function({
|
|
56
|
+
gasEstimateType,
|
|
57
|
+
gasFeeEstimates,
|
|
58
|
+
level
|
|
59
|
+
}) {
|
|
60
|
+
if (gasEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET) {
|
|
61
|
+
return __privateMethod(this, _getFeeMarketLevel, getFeeMarketLevel_fn).call(this, gasFeeEstimates, level);
|
|
62
|
+
}
|
|
63
|
+
return __privateMethod(this, _getLegacyLevel, getLegacyLevel_fn).call(this, gasFeeEstimates, level);
|
|
64
|
+
};
|
|
65
|
+
_getFeeMarketLevel = new WeakSet();
|
|
66
|
+
getFeeMarketLevel_fn = function(gasFeeEstimates, level) {
|
|
67
|
+
const maxFeePerGas = gweiDecimalToWeiHex(
|
|
68
|
+
gasFeeEstimates[level].suggestedMaxFeePerGas
|
|
69
|
+
);
|
|
70
|
+
const maxPriorityFeePerGas = gweiDecimalToWeiHex(
|
|
71
|
+
gasFeeEstimates[level].suggestedMaxPriorityFeePerGas
|
|
72
|
+
);
|
|
73
|
+
return {
|
|
74
|
+
maxFeePerGas,
|
|
75
|
+
maxPriorityFeePerGas
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
_getLegacyLevel = new WeakSet();
|
|
79
|
+
getLegacyLevel_fn = function(gasFeeEstimates, level) {
|
|
80
|
+
const gasPrice = gweiDecimalToWeiHex(gasFeeEstimates[level]);
|
|
81
|
+
return {
|
|
82
|
+
maxFeePerGas: gasPrice,
|
|
83
|
+
maxPriorityFeePerGas: gasPrice
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export {
|
|
88
|
+
DefaultGasFeeFlow
|
|
89
|
+
};
|
|
90
|
+
//# sourceMappingURL=chunk-FS7FRO7B.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/gas-flows/DefaultGasFeeFlow.ts"],"sourcesContent":["import type {\n LegacyGasPriceEstimate,\n GasFeeEstimates as FeeMarketGasPriceEstimate,\n} from '@metamask/gas-fee-controller';\nimport { GAS_ESTIMATE_TYPES } from '@metamask/gas-fee-controller';\nimport { createModuleLogger } from '@metamask/utils';\n\nimport { projectLogger } from '../logger';\nimport type {\n GasFeeEstimates,\n GasFeeEstimatesForLevel,\n GasFeeFlow,\n GasFeeFlowRequest,\n GasFeeFlowResponse,\n TransactionMeta,\n} from '../types';\nimport { GasFeeEstimateLevel } from '../types';\nimport { gweiDecimalToWeiHex } from '../utils/gas-fees';\n\nconst log = createModuleLogger(projectLogger, 'default-gas-fee-flow');\n\ntype FeeMarketGetEstimateLevelRequest = {\n gasEstimateType: 'fee-market';\n gasFeeEstimates: FeeMarketGasPriceEstimate;\n level: GasFeeEstimateLevel;\n};\n\ntype LegacyGetEstimateLevelRequest = {\n gasEstimateType: 'legacy';\n gasFeeEstimates: LegacyGasPriceEstimate;\n level: GasFeeEstimateLevel;\n};\n\n/**\n * The standard implementation of a gas fee flow that obtains gas fee estimates using only the GasFeeController.\n */\nexport class DefaultGasFeeFlow implements GasFeeFlow {\n matchesTransaction(_transactionMeta: TransactionMeta): boolean {\n return true;\n }\n\n async getGasFees(request: GasFeeFlowRequest): Promise<GasFeeFlowResponse> {\n const { getGasFeeControllerEstimates, transactionMeta } = request;\n const { networkClientId } = transactionMeta;\n\n const { gasEstimateType, gasFeeEstimates } =\n await getGasFeeControllerEstimates({ networkClientId });\n\n if (gasEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET) {\n log('Using fee market estimates', gasFeeEstimates);\n } else if (gasEstimateType === GAS_ESTIMATE_TYPES.LEGACY) {\n log('Using legacy estimates', gasFeeEstimates);\n } else {\n throw new Error(`'No gas fee estimates available`);\n }\n\n const estimates = Object.values(GasFeeEstimateLevel).reduce(\n (result, level) => ({\n ...result,\n [level]: this.#getEstimateLevel({\n gasEstimateType,\n gasFeeEstimates,\n level,\n } as FeeMarketGetEstimateLevelRequest | LegacyGetEstimateLevelRequest),\n }),\n {} as GasFeeEstimates,\n );\n\n return { estimates };\n }\n\n #getEstimateLevel({\n gasEstimateType,\n gasFeeEstimates,\n level,\n }:\n | FeeMarketGetEstimateLevelRequest\n | LegacyGetEstimateLevelRequest): GasFeeEstimatesForLevel {\n if (gasEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET) {\n return this.#getFeeMarketLevel(gasFeeEstimates, level);\n }\n\n return this.#getLegacyLevel(gasFeeEstimates, level);\n }\n\n #getFeeMarketLevel(\n gasFeeEstimates: FeeMarketGasPriceEstimate,\n level: GasFeeEstimateLevel,\n ): GasFeeEstimatesForLevel {\n const maxFeePerGas = gweiDecimalToWeiHex(\n gasFeeEstimates[level].suggestedMaxFeePerGas,\n );\n\n const maxPriorityFeePerGas = gweiDecimalToWeiHex(\n gasFeeEstimates[level].suggestedMaxPriorityFeePerGas,\n );\n\n return {\n maxFeePerGas,\n maxPriorityFeePerGas,\n };\n }\n\n #getLegacyLevel(\n gasFeeEstimates: LegacyGasPriceEstimate,\n level: GasFeeEstimateLevel,\n ): GasFeeEstimatesForLevel {\n const gasPrice = gweiDecimalToWeiHex(gasFeeEstimates[level]);\n\n return {\n maxFeePerGas: gasPrice,\n maxPriorityFeePerGas: gasPrice,\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAIA,SAAS,0BAA0B;AACnC,SAAS,0BAA0B;AAcnC,IAAM,MAAM,mBAAmB,eAAe,sBAAsB;AAnBpE;AAoCO,IAAM,oBAAN,MAA8C;AAAA,EAA9C;AAmCL;AAcA;AAkBA;AAAA;AAAA,EAlEA,mBAAmB,kBAA4C;AAC7D,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,WAAW,SAAyD;AACxE,UAAM,EAAE,8BAA8B,gBAAgB,IAAI;AAC1D,UAAM,EAAE,gBAAgB,IAAI;AAE5B,UAAM,EAAE,iBAAiB,gBAAgB,IACvC,MAAM,6BAA6B,EAAE,gBAAgB,CAAC;AAExD,QAAI,oBAAoB,mBAAmB,YAAY;AACrD,UAAI,8BAA8B,eAAe;AAAA,IACnD,WAAW,oBAAoB,mBAAmB,QAAQ;AACxD,UAAI,0BAA0B,eAAe;AAAA,IAC/C,OAAO;AACL,YAAM,IAAI,MAAM,iCAAiC;AAAA,IACnD;AAEA,UAAM,YAAY,OAAO,OAAO,mBAAmB,EAAE;AAAA,MACnD,CAAC,QAAQ,WAAW;AAAA,QAClB,GAAG;AAAA,QACH,CAAC,KAAK,GAAG,sBAAK,wCAAL,WAAuB;AAAA,UAC9B;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,MACA,CAAC;AAAA,IACH;AAEA,WAAO,EAAE,UAAU;AAAA,EACrB;AA6CF;AA3CE;AAAA,sBAAiB,SAAC;AAAA,EAChB;AAAA,EACA;AAAA,EACA;AACF,GAE4D;AAC1D,MAAI,oBAAoB,mBAAmB,YAAY;AACrD,WAAO,sBAAK,0CAAL,WAAwB,iBAAiB;AAAA,EAClD;AAEA,SAAO,sBAAK,oCAAL,WAAqB,iBAAiB;AAC/C;AAEA;AAAA,uBAAkB,SAChB,iBACA,OACyB;AACzB,QAAM,eAAe;AAAA,IACnB,gBAAgB,KAAK,EAAE;AAAA,EACzB;AAEA,QAAM,uBAAuB;AAAA,IAC3B,gBAAgB,KAAK,EAAE;AAAA,EACzB;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;AAEA;AAAA,oBAAe,SACb,iBACA,OACyB;AACzB,QAAM,WAAW,oBAAoB,gBAAgB,KAAK,CAAC;AAE3D,SAAO;AAAA,IACL,cAAc;AAAA,IACd,sBAAsB;AAAA,EACxB;AACF;","names":[]}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkNUOBUW7Cjs = require('./chunk-NUOBUW7C.js');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
var _chunkRI6MVJJNjs = require('./chunk-RI6MVJJN.js');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
var _chunkS6VGOPUYjs = require('./chunk-S6VGOPUY.js');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
var _chunkZ4BLTVTBjs = require('./chunk-Z4BLTVTB.js');
|
|
17
|
+
|
|
18
|
+
// src/helpers/EtherscanRemoteTransactionSource.ts
|
|
19
|
+
var _controllerutils = require('@metamask/controller-utils');
|
|
20
|
+
var _asyncmutex = require('async-mutex');
|
|
21
|
+
var _bnjs = require('bn.js'); var _bnjs2 = _interopRequireDefault(_bnjs);
|
|
22
|
+
var _uuid = require('uuid');
|
|
23
|
+
var ETHERSCAN_RATE_LIMIT_INTERVAL = 5e3;
|
|
24
|
+
var _includeTokenTransfers, _isTokenRequestPending, _mutex, _releaseLockAfterInterval, releaseLockAfterInterval_fn, _fetchNormalTransactions, _fetchTokenTransactions, _getResponseTransactions, getResponseTransactions_fn, _normalizeTransaction, normalizeTransaction_fn, _normalizeTokenTransaction, normalizeTokenTransaction_fn, _normalizeTransactionBase, normalizeTransactionBase_fn;
|
|
25
|
+
var EtherscanRemoteTransactionSource = class {
|
|
26
|
+
constructor({
|
|
27
|
+
includeTokenTransfers
|
|
28
|
+
} = {}) {
|
|
29
|
+
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _releaseLockAfterInterval);
|
|
30
|
+
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _getResponseTransactions);
|
|
31
|
+
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _normalizeTransaction);
|
|
32
|
+
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _normalizeTokenTransaction);
|
|
33
|
+
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _normalizeTransactionBase);
|
|
34
|
+
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _includeTokenTransfers, void 0);
|
|
35
|
+
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _isTokenRequestPending, void 0);
|
|
36
|
+
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _mutex, new (0, _asyncmutex.Mutex)());
|
|
37
|
+
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _fetchNormalTransactions, async (request, etherscanRequest) => {
|
|
38
|
+
const { currentChainId } = request;
|
|
39
|
+
const etherscanTransactions = await _chunkNUOBUW7Cjs.fetchEtherscanTransactions.call(void 0,
|
|
40
|
+
etherscanRequest
|
|
41
|
+
);
|
|
42
|
+
return _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getResponseTransactions, getResponseTransactions_fn).call(this, etherscanTransactions).map(
|
|
43
|
+
(tx) => _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _normalizeTransaction, normalizeTransaction_fn).call(this, tx, currentChainId)
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _fetchTokenTransactions, async (request, etherscanRequest) => {
|
|
47
|
+
const { currentChainId } = request;
|
|
48
|
+
const etherscanTransactions = await _chunkNUOBUW7Cjs.fetchEtherscanTokenTransactions.call(void 0,
|
|
49
|
+
etherscanRequest
|
|
50
|
+
);
|
|
51
|
+
return _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getResponseTransactions, getResponseTransactions_fn).call(this, etherscanTransactions).map(
|
|
52
|
+
(tx) => _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _normalizeTokenTransaction, normalizeTokenTransaction_fn).call(this, tx, currentChainId)
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
_chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _includeTokenTransfers, includeTokenTransfers ?? true);
|
|
56
|
+
_chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _isTokenRequestPending, false);
|
|
57
|
+
}
|
|
58
|
+
isSupportedNetwork(chainId) {
|
|
59
|
+
return Object.keys(_chunkRI6MVJJNjs.ETHERSCAN_SUPPORTED_NETWORKS).includes(chainId);
|
|
60
|
+
}
|
|
61
|
+
getLastBlockVariations() {
|
|
62
|
+
return [_chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _isTokenRequestPending) ? "token" : "normal"];
|
|
63
|
+
}
|
|
64
|
+
async fetchTransactions(request) {
|
|
65
|
+
const releaseLock = await _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _mutex).acquire();
|
|
66
|
+
const acquiredTime = Date.now();
|
|
67
|
+
const etherscanRequest = {
|
|
68
|
+
...request,
|
|
69
|
+
chainId: request.currentChainId
|
|
70
|
+
};
|
|
71
|
+
try {
|
|
72
|
+
const transactions = _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _isTokenRequestPending) ? await _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _fetchTokenTransactions).call(this, request, etherscanRequest) : await _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _fetchNormalTransactions).call(this, request, etherscanRequest);
|
|
73
|
+
if (_chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _includeTokenTransfers)) {
|
|
74
|
+
_chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _isTokenRequestPending, !_chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _isTokenRequestPending));
|
|
75
|
+
}
|
|
76
|
+
return transactions;
|
|
77
|
+
} finally {
|
|
78
|
+
_chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _releaseLockAfterInterval, releaseLockAfterInterval_fn).call(this, acquiredTime, releaseLock);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
_includeTokenTransfers = new WeakMap();
|
|
83
|
+
_isTokenRequestPending = new WeakMap();
|
|
84
|
+
_mutex = new WeakMap();
|
|
85
|
+
_releaseLockAfterInterval = new WeakSet();
|
|
86
|
+
releaseLockAfterInterval_fn = function(acquireTime, releaseLock) {
|
|
87
|
+
const elapsedTime = Date.now() - acquireTime;
|
|
88
|
+
const remainingTime = Math.max(
|
|
89
|
+
0,
|
|
90
|
+
ETHERSCAN_RATE_LIMIT_INTERVAL - elapsedTime
|
|
91
|
+
);
|
|
92
|
+
if (remainingTime > 0) {
|
|
93
|
+
setTimeout(releaseLock, remainingTime);
|
|
94
|
+
} else {
|
|
95
|
+
releaseLock();
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
_fetchNormalTransactions = new WeakMap();
|
|
99
|
+
_fetchTokenTransactions = new WeakMap();
|
|
100
|
+
_getResponseTransactions = new WeakSet();
|
|
101
|
+
getResponseTransactions_fn = function(response) {
|
|
102
|
+
let result = response.result;
|
|
103
|
+
if (response.status === "0") {
|
|
104
|
+
result = [];
|
|
105
|
+
if (response.result.length) {
|
|
106
|
+
_chunkS6VGOPUYjs.incomingTransactionsLogger.call(void 0, "Ignored Etherscan request error", {
|
|
107
|
+
message: response.result,
|
|
108
|
+
type: _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _isTokenRequestPending) ? "token" : "normal"
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return result;
|
|
113
|
+
};
|
|
114
|
+
_normalizeTransaction = new WeakSet();
|
|
115
|
+
normalizeTransaction_fn = function(txMeta, currentChainId) {
|
|
116
|
+
const base = _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _normalizeTransactionBase, normalizeTransactionBase_fn).call(this, txMeta, currentChainId);
|
|
117
|
+
return {
|
|
118
|
+
...base,
|
|
119
|
+
txParams: {
|
|
120
|
+
...base.txParams,
|
|
121
|
+
data: txMeta.input
|
|
122
|
+
},
|
|
123
|
+
...txMeta.isError === "0" ? { status: "confirmed" /* confirmed */ } : {
|
|
124
|
+
error: new Error("Transaction failed"),
|
|
125
|
+
status: "failed" /* failed */
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
_normalizeTokenTransaction = new WeakSet();
|
|
130
|
+
normalizeTokenTransaction_fn = function(txMeta, currentChainId) {
|
|
131
|
+
const base = _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _normalizeTransactionBase, normalizeTransactionBase_fn).call(this, txMeta, currentChainId);
|
|
132
|
+
return {
|
|
133
|
+
...base,
|
|
134
|
+
isTransfer: true,
|
|
135
|
+
transferInformation: {
|
|
136
|
+
contractAddress: txMeta.contractAddress,
|
|
137
|
+
decimals: Number(txMeta.tokenDecimal),
|
|
138
|
+
symbol: txMeta.tokenSymbol
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
_normalizeTransactionBase = new WeakSet();
|
|
143
|
+
normalizeTransactionBase_fn = function(txMeta, currentChainId) {
|
|
144
|
+
const time = parseInt(txMeta.timeStamp, 10) * 1e3;
|
|
145
|
+
return {
|
|
146
|
+
blockNumber: txMeta.blockNumber,
|
|
147
|
+
chainId: currentChainId,
|
|
148
|
+
hash: txMeta.hash,
|
|
149
|
+
id: _uuid.v1.call(void 0, { msecs: time }),
|
|
150
|
+
status: "confirmed" /* confirmed */,
|
|
151
|
+
time,
|
|
152
|
+
txParams: {
|
|
153
|
+
chainId: currentChainId,
|
|
154
|
+
from: txMeta.from,
|
|
155
|
+
gas: _controllerutils.BNToHex.call(void 0, new (0, _bnjs2.default)(txMeta.gas)),
|
|
156
|
+
gasPrice: _controllerutils.BNToHex.call(void 0, new (0, _bnjs2.default)(txMeta.gasPrice)),
|
|
157
|
+
gasUsed: _controllerutils.BNToHex.call(void 0, new (0, _bnjs2.default)(txMeta.gasUsed)),
|
|
158
|
+
nonce: _controllerutils.BNToHex.call(void 0, new (0, _bnjs2.default)(txMeta.nonce)),
|
|
159
|
+
to: txMeta.to,
|
|
160
|
+
value: _controllerutils.BNToHex.call(void 0, new (0, _bnjs2.default)(txMeta.value))
|
|
161
|
+
},
|
|
162
|
+
type: "incoming" /* incoming */,
|
|
163
|
+
verifiedOnBlockchain: false
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
exports.EtherscanRemoteTransactionSource = EtherscanRemoteTransactionSource;
|
|
170
|
+
//# sourceMappingURL=chunk-GKTIFXPN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/helpers/EtherscanRemoteTransactionSource.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,SAAS,eAAe;AAExB,SAAS,aAAa;AACtB,OAAO,QAAQ;AACf,SAAS,MAAM,cAAc;AAsB7B,IAAM,gCAAgC;AA1BtC;AA8BO,IAAM,mCAAN,MAEP;AAAA,EAOE,YAAY;AAAA,IACV;AAAA,EACF,IAAyC,CAAC,GAAG;AAuC7C;AA4CA;AAmBA;AAqBA;AAiBA;AApJA;AAEA;AAEA,+BAAS,IAAI,MAAM;AAyDnB,iDAA2B,OACzB,SACA,qBACG;AACH,YAAM,EAAE,eAAe,IAAI;AAE3B,YAAM,wBAAwB,MAAM;AAAA,QAClC;AAAA,MACF;AAEA,aAAO,sBAAK,sDAAL,WAA8B,uBAAuB;AAAA,QAAI,CAAC,OAC/D,sBAAK,gDAAL,WAA2B,IAAI;AAAA,MACjC;AAAA,IACF;AAEA,gDAA0B,OACxB,SACA,qBACG;AACH,YAAM,EAAE,eAAe,IAAI;AAE3B,YAAM,wBAAwB,MAAM;AAAA,QAClC;AAAA,MACF;AAEA,aAAO,sBAAK,sDAAL,WAA8B,uBAAuB;AAAA,QAAI,CAAC,OAC/D,sBAAK,0DAAL,WAAgC,IAAI;AAAA,MACtC;AAAA,IACF;AAhFE,uBAAK,wBAAyB,yBAAyB;AACvD,uBAAK,wBAAyB;AAAA,EAChC;AAAA,EAEA,mBAAmB,SAAuB;AACxC,WAAO,OAAO,KAAK,4BAA4B,EAAE,SAAS,OAAO;AAAA,EACnE;AAAA,EAEA,yBAAmC;AACjC,WAAO,CAAC,mBAAK,0BAAyB,UAAU,QAAQ;AAAA,EAC1D;AAAA,EAEA,MAAM,kBACJ,SAC4B;AAC5B,UAAM,cAAc,MAAM,mBAAK,QAAO,QAAQ;AAC9C,UAAM,eAAe,KAAK,IAAI;AAE9B,UAAM,mBAAgD;AAAA,MACpD,GAAG;AAAA,MACH,SAAS,QAAQ;AAAA,IACnB;AAEA,QAAI;AACF,YAAM,eAAe,mBAAK,0BACtB,MAAM,mBAAK,yBAAL,WAA6B,SAAS,oBAC5C,MAAM,mBAAK,0BAAL,WAA8B,SAAS;AAEjD,UAAI,mBAAK,yBAAwB;AAC/B,2BAAK,wBAAyB,CAAC,mBAAK;AAAA,MACtC;AAEA,aAAO;AAAA,IACT,UAAE;AACA,4BAAK,wDAAL,WAA+B,cAAc;AAAA,IAC/C;AAAA,EACF;AAkIF;AA/KE;AAEA;AAEA;AA2CA;AAAA,8BAAyB,SAAC,aAAqB,aAAyB;AACtE,QAAM,cAAc,KAAK,IAAI,IAAI;AACjC,QAAM,gBAAgB,KAAK;AAAA,IACzB;AAAA,IACA,gCAAgC;AAAA,EAClC;AAEA,MAAI,gBAAgB,GAAG;AACrB,eAAW,aAAa,aAAa;AAAA,EACvC,OAAO;AACL,gBAAY;AAAA,EACd;AACF;AAEA;AAeA;AAeA;AAAA,6BAAgE,SAC9D,UACK;AACL,MAAI,SAAS,SAAS;AAEtB,MAAI,SAAS,WAAW,KAAK;AAC3B,aAAS,CAAC;AAEV,QAAI,SAAS,OAAO,QAAQ;AAC1B,iCAAI,mCAAmC;AAAA,QACrC,SAAS,SAAS;AAAA,QAClB,MAAM,mBAAK,0BAAyB,UAAU;AAAA,MAChD,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;AAEA;AAAA,0BAAqB,SACnB,QACA,gBACiB;AACjB,QAAM,OAAO,sBAAK,wDAAL,WAA+B,QAAQ;AAEpD,SAAO;AAAA,IACL,GAAG;AAAA,IACH,UAAU;AAAA,MACR,GAAG,KAAK;AAAA,MACR,MAAM,OAAO;AAAA,IACf;AAAA,IACA,GAAI,OAAO,YAAY,MACnB,EAAE,oCAAoC,IACtC;AAAA,MACE,OAAO,IAAI,MAAM,oBAAoB;AAAA,MACrC;AAAA,IACF;AAAA,EACN;AACF;AAEA;AAAA,+BAA0B,SACxB,QACA,gBACiB;AACjB,QAAM,OAAO,sBAAK,wDAAL,WAA+B,QAAQ;AAEpD,SAAO;AAAA,IACL,GAAG;AAAA,IACH,YAAY;AAAA,IACZ,qBAAqB;AAAA,MACnB,iBAAiB,OAAO;AAAA,MACxB,UAAU,OAAO,OAAO,YAAY;AAAA,MACpC,QAAQ,OAAO;AAAA,IACjB;AAAA,EACF;AACF;AAEA;AAAA,8BAAyB,SACvB,QACA,gBACiB;AACjB,QAAM,OAAO,SAAS,OAAO,WAAW,EAAE,IAAI;AAE9C,SAAO;AAAA,IACL,aAAa,OAAO;AAAA,IACpB,SAAS;AAAA,IACT,MAAM,OAAO;AAAA,IACb,IAAI,OAAO,EAAE,OAAO,KAAK,CAAC;AAAA,IAC1B;AAAA,IACA;AAAA,IACA,UAAU;AAAA,MACR,SAAS;AAAA,MACT,MAAM,OAAO;AAAA,MACb,KAAK,QAAQ,IAAI,GAAG,OAAO,GAAG,CAAC;AAAA,MAC/B,UAAU,QAAQ,IAAI,GAAG,OAAO,QAAQ,CAAC;AAAA,MACzC,SAAS,QAAQ,IAAI,GAAG,OAAO,OAAO,CAAC;AAAA,MACvC,OAAO,QAAQ,IAAI,GAAG,OAAO,KAAK,CAAC;AAAA,MACnC,IAAI,OAAO;AAAA,MACX,OAAO,QAAQ,IAAI,GAAG,OAAO,KAAK,CAAC;AAAA,IACrC;AAAA,IACA;AAAA,IACA,sBAAsB;AAAA,EACxB;AACF","sourcesContent":["import { BNToHex } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\nimport BN from 'bn.js';\nimport { v1 as random } from 'uuid';\n\nimport { ETHERSCAN_SUPPORTED_NETWORKS } from '../constants';\nimport { incomingTransactionsLogger as log } from '../logger';\nimport type {\n RemoteTransactionSource,\n RemoteTransactionSourceRequest,\n TransactionMeta,\n} from '../types';\nimport { TransactionStatus, TransactionType } from '../types';\nimport {\n fetchEtherscanTokenTransactions,\n fetchEtherscanTransactions,\n} from '../utils/etherscan';\nimport type {\n EtherscanTokenTransactionMeta,\n EtherscanTransactionMeta,\n EtherscanTransactionMetaBase,\n EtherscanTransactionRequest,\n EtherscanTransactionResponse,\n} from '../utils/etherscan';\n\nconst ETHERSCAN_RATE_LIMIT_INTERVAL = 5000;\n/**\n * A RemoteTransactionSource that fetches transaction data from Etherscan.\n */\nexport class EtherscanRemoteTransactionSource\n implements RemoteTransactionSource\n{\n #includeTokenTransfers: boolean;\n\n #isTokenRequestPending: boolean;\n\n #mutex = new Mutex();\n\n constructor({\n includeTokenTransfers,\n }: { includeTokenTransfers?: boolean } = {}) {\n this.#includeTokenTransfers = includeTokenTransfers ?? true;\n this.#isTokenRequestPending = false;\n }\n\n isSupportedNetwork(chainId: Hex): boolean {\n return Object.keys(ETHERSCAN_SUPPORTED_NETWORKS).includes(chainId);\n }\n\n getLastBlockVariations(): string[] {\n return [this.#isTokenRequestPending ? 'token' : 'normal'];\n }\n\n async fetchTransactions(\n request: RemoteTransactionSourceRequest,\n ): Promise<TransactionMeta[]> {\n const releaseLock = await this.#mutex.acquire();\n const acquiredTime = Date.now();\n\n const etherscanRequest: EtherscanTransactionRequest = {\n ...request,\n chainId: request.currentChainId,\n };\n\n try {\n const transactions = this.#isTokenRequestPending\n ? await this.#fetchTokenTransactions(request, etherscanRequest)\n : await this.#fetchNormalTransactions(request, etherscanRequest);\n\n if (this.#includeTokenTransfers) {\n this.#isTokenRequestPending = !this.#isTokenRequestPending;\n }\n\n return transactions;\n } finally {\n this.#releaseLockAfterInterval(acquiredTime, releaseLock);\n }\n }\n\n #releaseLockAfterInterval(acquireTime: number, releaseLock: () => void) {\n const elapsedTime = Date.now() - acquireTime;\n const remainingTime = Math.max(\n 0,\n ETHERSCAN_RATE_LIMIT_INTERVAL - elapsedTime,\n );\n // Wait for the remaining time if it hasn't been 5 seconds yet\n if (remainingTime > 0) {\n setTimeout(releaseLock, remainingTime);\n } else {\n releaseLock();\n }\n }\n\n #fetchNormalTransactions = async (\n request: RemoteTransactionSourceRequest,\n etherscanRequest: EtherscanTransactionRequest,\n ) => {\n const { currentChainId } = request;\n\n const etherscanTransactions = await fetchEtherscanTransactions(\n etherscanRequest,\n );\n\n return this.#getResponseTransactions(etherscanTransactions).map((tx) =>\n this.#normalizeTransaction(tx, currentChainId),\n );\n };\n\n #fetchTokenTransactions = async (\n request: RemoteTransactionSourceRequest,\n etherscanRequest: EtherscanTransactionRequest,\n ) => {\n const { currentChainId } = request;\n\n const etherscanTransactions = await fetchEtherscanTokenTransactions(\n etherscanRequest,\n );\n\n return this.#getResponseTransactions(etherscanTransactions).map((tx) =>\n this.#normalizeTokenTransaction(tx, currentChainId),\n );\n };\n\n #getResponseTransactions<T extends EtherscanTransactionMetaBase>(\n response: EtherscanTransactionResponse<T>,\n ): T[] {\n let result = response.result as T[];\n\n if (response.status === '0') {\n result = [];\n\n if (response.result.length) {\n log('Ignored Etherscan request error', {\n message: response.result,\n type: this.#isTokenRequestPending ? 'token' : 'normal',\n });\n }\n }\n\n return result;\n }\n\n #normalizeTransaction(\n txMeta: EtherscanTransactionMeta,\n currentChainId: Hex,\n ): TransactionMeta {\n const base = this.#normalizeTransactionBase(txMeta, currentChainId);\n\n return {\n ...base,\n txParams: {\n ...base.txParams,\n data: txMeta.input,\n },\n ...(txMeta.isError === '0'\n ? { status: TransactionStatus.confirmed }\n : {\n error: new Error('Transaction failed'),\n status: TransactionStatus.failed,\n }),\n };\n }\n\n #normalizeTokenTransaction(\n txMeta: EtherscanTokenTransactionMeta,\n currentChainId: Hex,\n ): TransactionMeta {\n const base = this.#normalizeTransactionBase(txMeta, currentChainId);\n\n return {\n ...base,\n isTransfer: true,\n transferInformation: {\n contractAddress: txMeta.contractAddress,\n decimals: Number(txMeta.tokenDecimal),\n symbol: txMeta.tokenSymbol,\n },\n };\n }\n\n #normalizeTransactionBase(\n txMeta: EtherscanTransactionMetaBase,\n currentChainId: Hex,\n ): TransactionMeta {\n const time = parseInt(txMeta.timeStamp, 10) * 1000;\n\n return {\n blockNumber: txMeta.blockNumber,\n chainId: currentChainId,\n hash: txMeta.hash,\n id: random({ msecs: time }),\n status: TransactionStatus.confirmed,\n time,\n txParams: {\n chainId: currentChainId,\n from: txMeta.from,\n gas: BNToHex(new BN(txMeta.gas)),\n gasPrice: BNToHex(new BN(txMeta.gasPrice)),\n gasUsed: BNToHex(new BN(txMeta.gasUsed)),\n nonce: BNToHex(new BN(txMeta.nonce)),\n to: txMeta.to,\n value: BNToHex(new BN(txMeta.value)),\n },\n type: TransactionType.incoming,\n verifiedOnBlockchain: false,\n };\n }\n}\n"]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkHPNXIKFYjs = require('./chunk-HPNXIKFY.js');
|
|
4
|
+
|
|
5
|
+
// src/utils/gas-flow.ts
|
|
6
|
+
var _controllerutils = require('@metamask/controller-utils');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _gasfeecontroller = require('@metamask/gas-fee-controller');
|
|
10
|
+
function getGasFeeFlow(transactionMeta, gasFeeFlows) {
|
|
11
|
+
return gasFeeFlows.find(
|
|
12
|
+
(gasFeeFlow) => gasFeeFlow.matchesTransaction(transactionMeta)
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
function mergeGasFeeEstimates({
|
|
16
|
+
gasFeeControllerEstimateType,
|
|
17
|
+
gasFeeControllerEstimates,
|
|
18
|
+
transactionGasFeeEstimates
|
|
19
|
+
}) {
|
|
20
|
+
if (gasFeeControllerEstimateType === _gasfeecontroller.GAS_ESTIMATE_TYPES.FEE_MARKET) {
|
|
21
|
+
return Object.values(_chunkHPNXIKFYjs.GasFeeEstimateLevel).reduce(
|
|
22
|
+
(result, level) => ({
|
|
23
|
+
...result,
|
|
24
|
+
[level]: mergeFeeMarketEstimate(
|
|
25
|
+
gasFeeControllerEstimates[level],
|
|
26
|
+
transactionGasFeeEstimates[level]
|
|
27
|
+
)
|
|
28
|
+
}),
|
|
29
|
+
{ ...gasFeeControllerEstimates }
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
if (gasFeeControllerEstimateType === _gasfeecontroller.GAS_ESTIMATE_TYPES.LEGACY) {
|
|
33
|
+
return Object.values(_chunkHPNXIKFYjs.GasFeeEstimateLevel).reduce(
|
|
34
|
+
(result, level) => ({
|
|
35
|
+
...result,
|
|
36
|
+
[level]: getLegacyEstimate(transactionGasFeeEstimates[level])
|
|
37
|
+
}),
|
|
38
|
+
{}
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
return gasFeeControllerEstimates;
|
|
42
|
+
}
|
|
43
|
+
function mergeFeeMarketEstimate(gasFeeControllerEstimate, transactionGasFeeEstimate) {
|
|
44
|
+
return {
|
|
45
|
+
...gasFeeControllerEstimate,
|
|
46
|
+
suggestedMaxFeePerGas: _controllerutils.weiHexToGweiDec.call(void 0,
|
|
47
|
+
transactionGasFeeEstimate.maxFeePerGas
|
|
48
|
+
),
|
|
49
|
+
suggestedMaxPriorityFeePerGas: _controllerutils.weiHexToGweiDec.call(void 0,
|
|
50
|
+
transactionGasFeeEstimate.maxPriorityFeePerGas
|
|
51
|
+
)
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function getLegacyEstimate(transactionGasFeeEstimate) {
|
|
55
|
+
return _controllerutils.weiHexToGweiDec.call(void 0, transactionGasFeeEstimate.maxFeePerGas);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
exports.getGasFeeFlow = getGasFeeFlow; exports.mergeGasFeeEstimates = mergeGasFeeEstimates;
|
|
62
|
+
//# sourceMappingURL=chunk-H4M66BA3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/gas-flow.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,uBAAuB;AAMhC;AAAA,EACE;AAAA,OAEK;AAiBA,SAAS,cACd,iBACA,aACwB;AACxB,SAAO,YAAY;AAAA,IAAK,CAAC,eACvB,WAAW,mBAAmB,eAAe;AAAA,EAC/C;AACF;AAsBO,SAAS,qBAAqB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AACF,GAEuE;AACrE,MAAI,iCAAiC,mBAAmB,YAAY;AAClE,WAAO,OAAO,OAAO,mBAAmB,EAAE;AAAA,MACxC,CAAC,QAAQ,WAAW;AAAA,QAClB,GAAG;AAAA,QACH,CAAC,KAAK,GAAG;AAAA,UACP,0BAA0B,KAAK;AAAA,UAC/B,2BAA2B,KAAK;AAAA,QAClC;AAAA,MACF;AAAA,MACA,EAAE,GAAG,0BAA0B;AAAA,IACjC;AAAA,EACF;AAEA,MAAI,iCAAiC,mBAAmB,QAAQ;AAC9D,WAAO,OAAO,OAAO,mBAAmB,EAAE;AAAA,MACxC,CAAC,QAAQ,WAAW;AAAA,QAClB,GAAG;AAAA,QACH,CAAC,KAAK,GAAG,kBAAkB,2BAA2B,KAAK,CAAC;AAAA,MAC9D;AAAA,MACA,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;AAQA,SAAS,uBACP,0BACA,2BACe;AACf,SAAO;AAAA,IACL,GAAG;AAAA,IACH,uBAAuB;AAAA,MACrB,0BAA0B;AAAA,IAC5B;AAAA,IACA,+BAA+B;AAAA,MAC7B,0BAA0B;AAAA,IAC5B;AAAA,EACF;AACF;AAOA,SAAS,kBACP,2BACQ;AACR,SAAO,gBAAgB,0BAA0B,YAAY;AAC/D","sourcesContent":["import { weiHexToGweiDec } from '@metamask/controller-utils';\nimport type {\n Eip1559GasFee,\n GasFeeEstimates,\n LegacyGasPriceEstimate,\n} from '@metamask/gas-fee-controller';\nimport {\n GAS_ESTIMATE_TYPES,\n type GasFeeState,\n} from '@metamask/gas-fee-controller';\n\nimport {\n type GasFeeEstimates as TransactionGasFeeEstimates,\n type GasFeeFlow,\n type TransactionMeta,\n type GasFeeEstimatesForLevel,\n GasFeeEstimateLevel,\n} from '../types';\n\n/**\n * Returns the first gas fee flow that matches the transaction.\n *\n * @param transactionMeta - The transaction metadata to find a gas fee flow for.\n * @param gasFeeFlows - The gas fee flows to search.\n * @returns The first gas fee flow that matches the transaction, or undefined if none match.\n */\nexport function getGasFeeFlow(\n transactionMeta: TransactionMeta,\n gasFeeFlows: GasFeeFlow[],\n): GasFeeFlow | undefined {\n return gasFeeFlows.find((gasFeeFlow) =>\n gasFeeFlow.matchesTransaction(transactionMeta),\n );\n}\n\ntype FeeMarketMergeGasFeeEstimatesRequest = {\n gasFeeControllerEstimateType: 'fee-market';\n gasFeeControllerEstimates: GasFeeEstimates;\n transactionGasFeeEstimates: TransactionGasFeeEstimates;\n};\n\ntype LegacyMergeGasFeeEstimatesRequest = {\n gasFeeControllerEstimateType: 'legacy';\n gasFeeControllerEstimates: LegacyGasPriceEstimate;\n transactionGasFeeEstimates: TransactionGasFeeEstimates;\n};\n\n/**\n * Merge the gas fee estimates from the gas fee controller with the gas fee estimates from a transaction.\n * @param request - Data required to merge gas fee estimates.\n * @param request.gasFeeControllerEstimateType - Gas fee estimate type from the gas fee controller.\n * @param request.gasFeeControllerEstimates - Gas fee estimates from the GasFeeController.\n * @param request.transactionGasFeeEstimates - Gas fee estimates from the transaction.\n * @returns The merged gas fee estimates.\n */\nexport function mergeGasFeeEstimates({\n gasFeeControllerEstimateType,\n gasFeeControllerEstimates,\n transactionGasFeeEstimates,\n}:\n | FeeMarketMergeGasFeeEstimatesRequest\n | LegacyMergeGasFeeEstimatesRequest): GasFeeState['gasFeeEstimates'] {\n if (gasFeeControllerEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET) {\n return Object.values(GasFeeEstimateLevel).reduce(\n (result, level) => ({\n ...result,\n [level]: mergeFeeMarketEstimate(\n gasFeeControllerEstimates[level],\n transactionGasFeeEstimates[level],\n ),\n }),\n { ...gasFeeControllerEstimates } as GasFeeEstimates,\n );\n }\n\n if (gasFeeControllerEstimateType === GAS_ESTIMATE_TYPES.LEGACY) {\n return Object.values(GasFeeEstimateLevel).reduce(\n (result, level) => ({\n ...result,\n [level]: getLegacyEstimate(transactionGasFeeEstimates[level]),\n }),\n {} as LegacyGasPriceEstimate,\n );\n }\n\n return gasFeeControllerEstimates;\n}\n\n/**\n * Merge a specific priority level of EIP-1559 gas fee estimates.\n * @param gasFeeControllerEstimate - The gas fee estimate from the gas fee controller.\n * @param transactionGasFeeEstimate - The gas fee estimate from the transaction.\n * @returns The merged gas fee estimate.\n */\nfunction mergeFeeMarketEstimate(\n gasFeeControllerEstimate: Eip1559GasFee,\n transactionGasFeeEstimate: GasFeeEstimatesForLevel,\n): Eip1559GasFee {\n return {\n ...gasFeeControllerEstimate,\n suggestedMaxFeePerGas: weiHexToGweiDec(\n transactionGasFeeEstimate.maxFeePerGas,\n ),\n suggestedMaxPriorityFeePerGas: weiHexToGweiDec(\n transactionGasFeeEstimate.maxPriorityFeePerGas,\n ),\n };\n}\n\n/**\n * Generate a specific priority level for a legacy gas fee estimate.\n * @param transactionGasFeeEstimate - The gas fee estimate from the transaction.\n * @returns The legacy gas fee estimate.\n */\nfunction getLegacyEstimate(\n transactionGasFeeEstimate: GasFeeEstimatesForLevel,\n): string {\n return weiHexToGweiDec(transactionGasFeeEstimate.maxFeePerGas);\n}\n"]}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/types.ts
|
|
2
|
+
var TransactionStatus = /* @__PURE__ */ ((TransactionStatus2) => {
|
|
3
|
+
TransactionStatus2["approved"] = "approved";
|
|
4
|
+
TransactionStatus2["cancelled"] = "cancelled";
|
|
5
|
+
TransactionStatus2["confirmed"] = "confirmed";
|
|
6
|
+
TransactionStatus2["dropped"] = "dropped";
|
|
7
|
+
TransactionStatus2["failed"] = "failed";
|
|
8
|
+
TransactionStatus2["rejected"] = "rejected";
|
|
9
|
+
TransactionStatus2["signed"] = "signed";
|
|
10
|
+
TransactionStatus2["submitted"] = "submitted";
|
|
11
|
+
TransactionStatus2["unapproved"] = "unapproved";
|
|
12
|
+
return TransactionStatus2;
|
|
13
|
+
})(TransactionStatus || {});
|
|
14
|
+
var WalletDevice = /* @__PURE__ */ ((WalletDevice2) => {
|
|
15
|
+
WalletDevice2["MM_MOBILE"] = "metamask_mobile";
|
|
16
|
+
WalletDevice2["MM_EXTENSION"] = "metamask_extension";
|
|
17
|
+
WalletDevice2["OTHER"] = "other_device";
|
|
18
|
+
return WalletDevice2;
|
|
19
|
+
})(WalletDevice || {});
|
|
20
|
+
var TransactionType = /* @__PURE__ */ ((TransactionType2) => {
|
|
21
|
+
TransactionType2["cancel"] = "cancel";
|
|
22
|
+
TransactionType2["contractInteraction"] = "contractInteraction";
|
|
23
|
+
TransactionType2["deployContract"] = "contractDeployment";
|
|
24
|
+
TransactionType2["ethDecrypt"] = "eth_decrypt";
|
|
25
|
+
TransactionType2["ethGetEncryptionPublicKey"] = "eth_getEncryptionPublicKey";
|
|
26
|
+
TransactionType2["incoming"] = "incoming";
|
|
27
|
+
TransactionType2["personalSign"] = "personal_sign";
|
|
28
|
+
TransactionType2["retry"] = "retry";
|
|
29
|
+
TransactionType2["simpleSend"] = "simpleSend";
|
|
30
|
+
TransactionType2["sign"] = "eth_sign";
|
|
31
|
+
TransactionType2["signTypedData"] = "eth_signTypedData";
|
|
32
|
+
TransactionType2["smart"] = "smart";
|
|
33
|
+
TransactionType2["swap"] = "swap";
|
|
34
|
+
TransactionType2["swapApproval"] = "swapApproval";
|
|
35
|
+
TransactionType2["tokenMethodApprove"] = "approve";
|
|
36
|
+
TransactionType2["tokenMethodSafeTransferFrom"] = "safetransferfrom";
|
|
37
|
+
TransactionType2["tokenMethodTransfer"] = "transfer";
|
|
38
|
+
TransactionType2["tokenMethodTransferFrom"] = "transferfrom";
|
|
39
|
+
TransactionType2["tokenMethodSetApprovalForAll"] = "setapprovalforall";
|
|
40
|
+
return TransactionType2;
|
|
41
|
+
})(TransactionType || {});
|
|
42
|
+
var TransactionEnvelopeType = /* @__PURE__ */ ((TransactionEnvelopeType2) => {
|
|
43
|
+
TransactionEnvelopeType2["legacy"] = "0x0";
|
|
44
|
+
TransactionEnvelopeType2["accessList"] = "0x1";
|
|
45
|
+
TransactionEnvelopeType2["feeMarket"] = "0x2";
|
|
46
|
+
return TransactionEnvelopeType2;
|
|
47
|
+
})(TransactionEnvelopeType || {});
|
|
48
|
+
var UserFeeLevel = /* @__PURE__ */ ((UserFeeLevel2) => {
|
|
49
|
+
UserFeeLevel2["CUSTOM"] = "custom";
|
|
50
|
+
UserFeeLevel2["DAPP_SUGGESTED"] = "dappSuggested";
|
|
51
|
+
UserFeeLevel2["MEDIUM"] = "medium";
|
|
52
|
+
return UserFeeLevel2;
|
|
53
|
+
})(UserFeeLevel || {});
|
|
54
|
+
var GasFeeEstimateLevel = /* @__PURE__ */ ((GasFeeEstimateLevel2) => {
|
|
55
|
+
GasFeeEstimateLevel2["low"] = "low";
|
|
56
|
+
GasFeeEstimateLevel2["medium"] = "medium";
|
|
57
|
+
GasFeeEstimateLevel2["high"] = "high";
|
|
58
|
+
return GasFeeEstimateLevel2;
|
|
59
|
+
})(GasFeeEstimateLevel || {});
|
|
60
|
+
var SimulationTokenStandard = /* @__PURE__ */ ((SimulationTokenStandard2) => {
|
|
61
|
+
SimulationTokenStandard2["erc20"] = "erc20";
|
|
62
|
+
SimulationTokenStandard2["erc721"] = "erc721";
|
|
63
|
+
SimulationTokenStandard2["erc1155"] = "erc1155";
|
|
64
|
+
return SimulationTokenStandard2;
|
|
65
|
+
})(SimulationTokenStandard || {});
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
exports.TransactionStatus = TransactionStatus; exports.WalletDevice = WalletDevice; exports.TransactionType = TransactionType; exports.TransactionEnvelopeType = TransactionEnvelopeType; exports.UserFeeLevel = UserFeeLevel; exports.GasFeeEstimateLevel = GasFeeEstimateLevel; exports.SimulationTokenStandard = SimulationTokenStandard;
|
|
76
|
+
//# sourceMappingURL=chunk-HPNXIKFY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"names":["TransactionStatus","WalletDevice","TransactionType","TransactionEnvelopeType","UserFeeLevel","GasFeeEstimateLevel","SimulationTokenStandard"],"mappings":";AA2aO,IAAK,oBAAL,kBAAKA,uBAAL;AACL,EAAAA,mBAAA,cAAW;AAEX,EAAAA,mBAAA,eAAY;AACZ,EAAAA,mBAAA,eAAY;AACZ,EAAAA,mBAAA,aAAU;AACV,EAAAA,mBAAA,YAAS;AACT,EAAAA,mBAAA,cAAW;AACX,EAAAA,mBAAA,YAAS;AACT,EAAAA,mBAAA,eAAY;AACZ,EAAAA,mBAAA,gBAAa;AAVH,SAAAA;AAAA,GAAA;AAgBL,IAAK,eAAL,kBAAKC,kBAAL;AACL,EAAAA,cAAA,eAAY;AACZ,EAAAA,cAAA,kBAAe;AACf,EAAAA,cAAA,WAAQ;AAHE,SAAAA;AAAA,GAAA;AASL,IAAK,kBAAL,kBAAKC,qBAAL;AAIL,EAAAA,iBAAA,YAAS;AAOT,EAAAA,iBAAA,yBAAsB;AAKtB,EAAAA,iBAAA,oBAAiB;AAKjB,EAAAA,iBAAA,gBAAa;AAKb,EAAAA,iBAAA,+BAA4B;AAK5B,EAAAA,iBAAA,cAAW;AAKX,EAAAA,iBAAA,kBAAe;AAQf,EAAAA,iBAAA,WAAQ;AAKR,EAAAA,iBAAA,gBAAa;AAKb,EAAAA,iBAAA,UAAO;AAKP,EAAAA,iBAAA,mBAAgB;AAKhB,EAAAA,iBAAA,WAAQ;AAKR,EAAAA,iBAAA,UAAO;AAQP,EAAAA,iBAAA,kBAAe;AAMf,EAAAA,iBAAA,wBAAqB;AAQrB,EAAAA,iBAAA,iCAA8B;AAM9B,EAAAA,iBAAA,yBAAsB;AAOtB,EAAAA,iBAAA,6BAA0B;AAM1B,EAAAA,iBAAA,kCAA+B;AA9GrB,SAAAA;AAAA,GAAA;AAgZL,IAAK,0BAAL,kBAAKC,6BAAL;AAIL,EAAAA,yBAAA,YAAS;AAOT,EAAAA,yBAAA,gBAAa;AAUb,EAAAA,yBAAA,eAAY;AArBF,SAAAA;AAAA,GAAA;AA2BL,IAAK,eAAL,kBAAKC,kBAAL;AACL,EAAAA,cAAA,YAAS;AACT,EAAAA,cAAA,oBAAiB;AACjB,EAAAA,cAAA,YAAS;AAHC,SAAAA;AAAA,GAAA;AA2FL,IAAK,sBAAL,kBAAKC,yBAAL;AACL,EAAAA,qBAAA,SAAM;AACN,EAAAA,qBAAA,YAAS;AACT,EAAAA,qBAAA,UAAO;AAHG,SAAAA;AAAA,GAAA;AAuEL,IAAK,0BAAL,kBAAKC,6BAAL;AACL,EAAAA,yBAAA,WAAQ;AACR,EAAAA,yBAAA,YAAS;AACT,EAAAA,yBAAA,aAAU;AAHA,SAAAA;AAAA,GAAA","sourcesContent":["import type { AccessList } from '@ethereumjs/tx';\nimport type EthQuery from '@metamask/eth-query';\nimport type {\n FetchGasFeeEstimateOptions,\n GasFeeState,\n} from '@metamask/gas-fee-controller';\nimport type { NetworkClientId } from '@metamask/network-controller';\nimport type { Hex, Json } from '@metamask/utils';\nimport type { Operation } from 'fast-json-patch';\n\n/**\n * Given a record, ensures that each property matches the `Json` type.\n */\ntype MakeJsonCompatible<T> = T extends Json\n ? T\n : {\n [K in keyof T]: T[K] extends Json ? T[K] : never;\n };\n\n/**\n * `Json` from `@metamask/utils` is defined as a recursive type alias, but\n * `Operation` is defined as an interface, and the two are not compatible with\n * each other. Therefore, this is a variant of Operation from `fast-json-patch`\n * which is guaranteed to be type-compatible with `Json`.\n */\ntype JsonCompatibleOperation = MakeJsonCompatible<Operation>;\n\n/**\n * Representation of transaction metadata.\n */\nexport type TransactionMeta = TransactionMetaBase &\n (\n | {\n status: Exclude<TransactionStatus, TransactionStatus.failed>;\n }\n | {\n status: TransactionStatus.failed;\n error: TransactionError;\n }\n );\n\n/**\n * Information about a single transaction such as status and block number.\n */\ntype TransactionMetaBase = {\n /**\n * ID of the transaction that approved the swap token transfer.\n */\n approvalTxId?: string;\n\n /**\n * Unique ID to prevent duplicate requests.\n */\n actionId?: string;\n\n /**\n * Base fee of the block as a hex value, introduced in EIP-1559.\n */\n baseFeePerGas?: Hex;\n\n /**\n * Number of the block where the transaction has been included.\n */\n blockNumber?: string;\n\n /**\n * The timestamp for when the block was collated.\n */\n blockTimestamp?: string;\n\n /**\n * Network code as per EIP-155 for this transaction.\n */\n chainId: Hex;\n\n /**\n * A string representing a name of transaction contract method.\n */\n contractMethodName?: string;\n\n /**\n * The balance of the token that is being sent.\n */\n currentTokenBalance?: string;\n\n /**\n * Unique ID for custodian transaction.\n */\n custodyId?: string;\n\n /**\n * Custodian transaction status.\n */\n custodyStatus?: string;\n\n /** The optional custom nonce override as a decimal string. */\n customNonceValue?: string;\n\n /**\n * The custom token amount is the amount set by the user.\n */\n customTokenAmount?: string;\n\n /**\n * The dapp proposed token amount.\n */\n dappProposedTokenAmount?: string;\n\n /**\n * Gas values provided by the dApp.\n */\n dappSuggestedGasFees?: DappSuggestedGasFees;\n\n /**\n * The initial gas values set when the transaction was first created.\n */\n defaultGasEstimates?: DefaultGasEstimates;\n\n /**\n * String to indicate what device the transaction was confirmed on.\n */\n deviceConfirmedOn?: WalletDevice;\n\n /**\n * The address of the token being received of swap transaction.\n */\n destinationTokenAddress?: string;\n\n /**\n * The decimals of the token being received of swap transaction.\n */\n destinationTokenDecimals?: number;\n\n /**\n * The symbol of the token being received with swap.\n */\n destinationTokenSymbol?: string;\n\n /**\n * The estimated base fee of the transaction.\n */\n estimatedBaseFee?: string;\n\n /**\n * Which estimate level that the API suggested.\n */\n estimateSuggested?: string;\n\n /**\n * Which estimate level was used\n */\n estimateUsed?: string;\n\n /**\n * The chosen amount which will be the same as the originally proposed token\n * amount if the user does not edit the amount or will be a custom token\n * amount set by the user.\n */\n finalApprovalAmount?: string;\n\n /**\n * The number of the latest block when the transaction submit was first retried.\n */\n firstRetryBlockNumber?: string;\n\n /** Alternate EIP-1559 gas fee estimates for multiple priority levels. */\n gasFeeEstimates?: GasFeeEstimates;\n\n /** Whether the gas fee estimates have been checked at least once. */\n gasFeeEstimatesLoaded?: boolean;\n\n /**\n * A hex string of the transaction hash, used to identify the transaction on the network.\n */\n hash?: string;\n\n /**\n * A history of mutations to TransactionMeta.\n */\n history?: TransactionHistory;\n\n /**\n * Generated UUID associated with this transaction.\n */\n id: string;\n\n /**\n * Whether the transaction is a transfer.\n */\n isTransfer?: boolean;\n\n /**\n * Whether the transaction entry is generated from a user operation.\n */\n isUserOperation?: boolean;\n\n /**\n * The ID of the network client used by the transaction.\n */\n networkClientId?: NetworkClientId;\n\n /**\n * Network code as per EIP-155 for this transaction\n *\n * @deprecated Use `chainId` instead.\n */\n readonly networkID?: string;\n\n /**\n * Origin this transaction was sent from.\n */\n origin?: string;\n\n /**\n * The original dapp proposed token approval amount before edit by user.\n */\n originalApprovalAmount?: string;\n\n /**\n * The original gas estimation of the transaction.\n */\n originalGasEstimate?: string;\n\n /**\n * When we speed up a transaction, we set the type as Retry and we lose\n * information about type of transaction that is being set up, so we use\n * original type to track that information.\n */\n originalType?: TransactionType;\n\n /**\n * Account transaction balance after swap.\n */\n postTxBalance?: string;\n\n /**\n * Account transaction balance before swap.\n */\n preTxBalance?: string;\n\n /**\n * The previous gas properties before they were updated.\n */\n previousGas?: {\n /**\n * Maxmimum number of units of gas to use for this transaction.\n */\n gasLimit?: string;\n\n /**\n * Maximum amount per gas to pay for the transaction, including the priority fee.\n */\n maxFeePerGas?: string;\n\n /**\n * Maximum amount per gas to give to validator as incentive.\n */\n maxPriorityFeePerGas?: string;\n };\n\n /**\n * The transaction's 'r' value as a hex string.\n */\n r?: string;\n\n /**\n * Hex representation of the underlying transaction.\n */\n rawTx?: string;\n\n /**\n * When the transaction is dropped, this is the replacement transaction hash.\n */\n replacedBy?: string;\n\n /**\n * When the transaction is dropped, this is the replacement transaction ID.\n */\n replacedById?: string;\n\n /**\n * The number of times that the transaction submit has been retried.\n */\n retryCount?: number;\n\n /**\n * The transaction's 's' value as a hex string.\n */\n s?: string;\n\n /**\n * Response from security validator.\n */\n securityAlertResponse?: SecurityAlertResponse;\n\n /**\n * Response from security provider.\n */\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n securityProviderResponse?: Record<string, any>;\n\n /**\n * An array of entries that describe the user's journey through the send flow.\n * This is purely attached to state logs for troubleshooting and support.\n */\n sendFlowHistory?: SendFlowHistoryEntry[];\n\n /**\n * Simulation data for the transaction used to predict its outcome.\n */\n simulationData?: SimulationData;\n\n /**\n * If the gas estimation fails, an object containing error and block information.\n */\n simulationFails?: {\n reason?: string;\n errorKey?: string;\n debug: {\n blockNumber?: string;\n blockGasLimit?: string;\n };\n };\n\n /**\n * The time the transaction was submitted to the network, in Unix epoch time (ms).\n */\n submittedTime?: number;\n\n /**\n * The symbol of the token being swapped.\n */\n sourceTokenSymbol?: string;\n\n /**\n * The metadata of the swap transaction.\n */\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n swapMetaData?: Record<string, any>;\n\n /**\n * The value of the token being swapped.\n */\n swapTokenValue?: string;\n\n /**\n * Timestamp associated with this transaction.\n */\n time: number;\n\n /**\n * Whether transaction recipient is a smart contract.\n */\n toSmartContract?: boolean;\n\n /**\n * Additional transfer information.\n */\n transferInformation?: {\n contractAddress: string;\n decimals: number;\n symbol: string;\n };\n\n /**\n * Underlying Transaction object.\n */\n txParams: TransactionParams;\n\n /**\n * Transaction receipt.\n */\n txReceipt?: TransactionReceipt;\n\n /**\n * The type of transaction such as `cancel` or `swap`.\n */\n type?: TransactionType;\n\n /**\n * The gas limit supplied by user.\n */\n userEditedGasLimit?: boolean;\n\n /**\n * Estimate level user selected.\n */\n userFeeLevel?: string;\n\n /**\n * The transaction's 'v' value as a hex string.\n */\n v?: string;\n\n /**\n * Whether the transaction is verified on the blockchain.\n */\n verifiedOnBlockchain?: boolean;\n\n /**\n * Warning information for the transaction.\n */\n warning?: {\n error: string;\n message: string;\n };\n};\n\nexport type SendFlowHistoryEntry = {\n /**\n * String to indicate user interaction information.\n */\n entry: string;\n\n /**\n * Timestamp associated with this entry.\n */\n timestamp: number;\n};\n\n/**\n * The status of the transaction. Each status represents the state of the transaction internally\n * in the wallet. Some of these correspond with the state of the transaction on the network, but\n * some are wallet-specific.\n */\nexport enum TransactionStatus {\n approved = 'approved',\n /** @deprecated Determined by the clients using the transaction type. No longer used. */\n cancelled = 'cancelled',\n confirmed = 'confirmed',\n dropped = 'dropped',\n failed = 'failed',\n rejected = 'rejected',\n signed = 'signed',\n submitted = 'submitted',\n unapproved = 'unapproved',\n}\n\n/**\n * Options for wallet device.\n */\nexport enum WalletDevice {\n MM_MOBILE = 'metamask_mobile',\n MM_EXTENSION = 'metamask_extension',\n OTHER = 'other_device',\n}\n\n/**\n * The type of the transaction.\n */\nexport enum TransactionType {\n /**\n * A transaction sending a network's native asset to a recipient.\n */\n cancel = 'cancel',\n\n /**\n * A transaction that is interacting with a smart contract's methods that we\n * have not treated as a special case, such as approve, transfer, and\n * transferfrom.\n */\n contractInteraction = 'contractInteraction',\n\n /**\n * A transaction that deployed a smart contract.\n */\n deployContract = 'contractDeployment',\n\n /**\n * A transaction for Ethereum decryption.\n */\n ethDecrypt = 'eth_decrypt',\n\n /**\n * A transaction for getting an encryption public key.\n */\n ethGetEncryptionPublicKey = 'eth_getEncryptionPublicKey',\n\n /**\n * An incoming (deposit) transaction.\n */\n incoming = 'incoming',\n\n /**\n * A transaction for personal sign.\n */\n personalSign = 'personal_sign',\n\n /**\n * When a transaction is failed it can be retried by\n * resubmitting the same transaction with a higher gas fee. This type is also used\n * to speed up pending transactions. This is accomplished by creating a new tx with\n * the same nonce and higher gas fees.\n */\n retry = 'retry',\n\n /**\n * A transaction sending a network's native asset to a recipient.\n */\n simpleSend = 'simpleSend',\n\n /**\n * A transaction that is signing a message.\n */\n sign = 'eth_sign',\n\n /**\n * A transaction that is signing typed data.\n */\n signTypedData = 'eth_signTypedData',\n\n /**\n * A transaction sending a network's native asset to a recipient.\n */\n smart = 'smart',\n\n /**\n * A transaction swapping one token for another through MetaMask Swaps.\n */\n swap = 'swap',\n\n /**\n * Similar to the approve type, a swap approval is a special case of ERC20\n * approve method that requests an allowance of the token to spend on behalf\n * of the user for the MetaMask Swaps contract. The first swap for any token\n * will have an accompanying swapApproval transaction.\n */\n swapApproval = 'swapApproval',\n\n /**\n * A token transaction requesting an allowance of the token to spend on\n * behalf of the user.\n */\n tokenMethodApprove = 'approve',\n\n /**\n * A token transaction transferring tokens from an account that the sender\n * has an allowance of. The method is prefixed with safe because when calling\n * this method the contract checks to ensure that the receiver is an address\n * capable of handling the token being sent.\n */\n tokenMethodSafeTransferFrom = 'safetransferfrom',\n\n /**\n * A token transaction where the user is sending tokens that they own to\n * another address.\n */\n tokenMethodTransfer = 'transfer',\n\n /**\n * A token transaction transferring tokens from an account that the sender\n * has an allowance of. For more information on allowances, see the approve\n * type.\n */\n tokenMethodTransferFrom = 'transferfrom',\n\n /**\n * A token transaction requesting an allowance of all of a user's tokens to\n * spend on behalf of the user.\n */\n tokenMethodSetApprovalForAll = 'setapprovalforall',\n}\n\n/**\n * Standard data concerning a transaction to be processed by the blockchain.\n */\nexport type TransactionParams = {\n /**\n * A list of addresses and storage keys that the transaction plans to access.\n */\n accessList?: AccessList;\n\n /**\n * Network ID as per EIP-155.\n */\n chainId?: Hex;\n\n /**\n * Data to pass with this transaction.\n */\n data?: string;\n\n /**\n * Error message for gas estimation failure.\n */\n estimateGasError?: string;\n\n /**\n * Estimated base fee for this transaction.\n */\n estimatedBaseFee?: string;\n\n /**\n * Which estimate level that the API suggested.\n */\n estimateSuggested?: string;\n\n /**\n * Which estimate level was used\n */\n estimateUsed?: string;\n\n /**\n * Address to send this transaction from.\n */\n from: string;\n\n /**\n * same as gasLimit?\n */\n gas?: string;\n\n /**\n * Maxmimum number of units of gas to use for this transaction.\n */\n gasLimit?: string;\n\n /**\n * Price per gas for legacy txs\n */\n gasPrice?: string;\n\n /**\n * Gas used in the transaction.\n */\n gasUsed?: string;\n\n /**\n * Maximum amount per gas to pay for the transaction, including the priority\n * fee.\n */\n maxFeePerGas?: string;\n\n /**\n * Maximum amount per gas to give to validator as incentive.\n */\n maxPriorityFeePerGas?: string;\n\n /**\n * Unique number to prevent replay attacks.\n */\n nonce?: string;\n\n /**\n * Address to send this transaction to.\n */\n to?: string;\n\n /**\n * Value associated with this transaction.\n */\n value?: string;\n\n /**\n * Type of transaction.\n * 0x0 indicates a legacy transaction.\n */\n type?: string;\n};\n\n/**\n * Standard data concerning a transaction processed by the blockchain.\n */\nexport type TransactionReceipt = {\n /**\n * The block hash of the block that this transaction was included in.\n */\n blockHash?: string;\n\n /**\n * The block number of the block that this transaction was included in.\n */\n blockNumber?: string;\n\n /**\n * Effective gas price the transaction was charged at.\n */\n effectiveGasPrice?: string;\n\n /**\n * Gas used in the transaction.\n */\n gasUsed?: string;\n\n /**\n * Total used gas in hex.\n */\n l1Fee?: string;\n\n /**\n * All the logs emitted by this transaction.\n */\n logs?: Log[];\n\n /**\n * The status of the transaction.\n */\n status?: string;\n\n /**\n * The hexadecimal index of this transaction in the list of transactions included in the block this transaction was mined in.\n */\n transactionIndex?: string;\n};\n\n/**\n * Represents an event that has been included in a transaction using the EVM `LOG` opcode.\n */\nexport type Log = {\n /**\n * Address of the contract that generated log.\n */\n address?: string;\n /**\n * List of topics for log.\n */\n topics?: string;\n};\n\n/**\n * The configuration required to fetch transaction data from a RemoteTransactionSource.\n */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface RemoteTransactionSourceRequest {\n /**\n * The address of the account to fetch transactions for.\n */\n address: string;\n\n /**\n * The chainId of the current network.\n */\n currentChainId: Hex;\n\n /**\n * Block number to start fetching transactions from.\n */\n fromBlock?: number;\n\n /**\n * Maximum number of transactions to retrieve.\n */\n limit?: number;\n}\n\n/**\n * An object capable of fetching transaction data from a remote source.\n * Used by the IncomingTransactionHelper to retrieve remote transaction data.\n */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface RemoteTransactionSource {\n /**\n * @param chainId - The chainId of the current network.\n * @returns Whether the remote transaction source supports the specified network.\n */\n isSupportedNetwork: (chainId: Hex) => boolean;\n\n /**\n * @returns An array of additional keys to use when caching the last fetched block number.\n */\n getLastBlockVariations?: () => string[];\n\n /**\n * @param request - A request object containing data such as the address and chain ID.\n * @returns An array of transaction metadata for the retrieved transactions.\n */\n fetchTransactions: (\n request: RemoteTransactionSourceRequest,\n ) => Promise<TransactionMeta[]>;\n}\n\n/**\n * Gas values initially suggested by the dApp.\n */\nexport type DappSuggestedGasFees = {\n gas?: string;\n gasPrice?: string;\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n};\n\n/**\n * Gas values saved by the user for a specific chain.\n */\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface SavedGasFees {\n maxBaseFee: string;\n priorityFee: string;\n}\n\n/**\n * A transaction history operation that includes a note and timestamp.\n */\ntype ExtendedHistoryOperation = JsonCompatibleOperation & {\n note?: string;\n timestamp?: number;\n};\n\n/**\n * A transaction history entry that includes the ExtendedHistoryOperation as the first element.\n */\nexport type TransactionHistoryEntry = [\n ExtendedHistoryOperation,\n ...JsonCompatibleOperation[],\n];\n\n/**\n * A transaction history that includes the transaction meta as the first element.\n * And the rest of the elements are the operation arrays that were applied to the transaction meta.\n */\nexport type TransactionHistory = [\n TransactionMeta,\n ...TransactionHistoryEntry[],\n];\n\n/**\n * Result of inferring the transaction type.\n */\nexport type InferTransactionTypeResult = {\n /**\n * The contract code, in hex format if it exists. '0x0' or\n * '0x' are also indicators of non-existent contract code.\n */\n getCodeResponse?: string | null;\n\n /**\n * The type of transaction\n */\n type: TransactionType;\n};\n\n/**\n * A function for verifying a transaction, whether it is malicious or not.\n */\nexport type SecurityProviderRequest = (\n requestData: TransactionMeta,\n messageType: string,\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n) => Promise<any>;\n\n/**\n * Specifies the shape of the base transaction parameters.\n * Added in EIP-2718.\n */\nexport enum TransactionEnvelopeType {\n /**\n * A legacy transaction, the very first type.\n */\n legacy = '0x0',\n\n /**\n * EIP-2930 defined the access list transaction type that allowed for\n * specifying the state that a transaction would act upon in advance and\n * theoretically save on gas fees.\n */\n accessList = '0x1',\n\n /**\n * The type introduced comes from EIP-1559, Fee Market describes the addition\n * of a baseFee to blocks that will be burned instead of distributed to\n * miners. Transactions of this type have both a maxFeePerGas (maximum total\n * amount in gwei per gas to spend on the transaction) which is inclusive of\n * the maxPriorityFeePerGas (maximum amount of gwei per gas from the\n * transaction fee to distribute to miner).\n */\n feeMarket = '0x2',\n}\n\n/**\n * The source of the gas fee parameters on a transaction.\n */\nexport enum UserFeeLevel {\n CUSTOM = 'custom',\n DAPP_SUGGESTED = 'dappSuggested',\n MEDIUM = 'medium',\n}\n\n/**\n * Initial gas values set when the transaction was first created.\n */\nexport type DefaultGasEstimates = {\n /**\n * Source of the gas fee values, such as `dappSuggested` or `medium`.\n */\n estimateType?: string;\n\n /**\n * Maxmimum number of units of gas to use for this transaction.\n */\n gas?: string;\n\n /**\n * Price per gas for legacy transactions.\n */\n gasPrice?: string;\n\n /**\n * Maximum amount per gas to pay for the transaction, including the priority fee.\n */\n maxFeePerGas?: string;\n\n /**\n * Maximum amount per gas to give to validator as incentive.\n */\n maxPriorityFeePerGas?: string;\n};\n\n/**\n * Data concerning an error while processing a transaction.\n */\nexport type TransactionError = {\n /**\n * A descriptive error name.\n */\n name: string;\n\n /**\n * A descriptive error message providing details about the encountered error.\n */\n message: string;\n\n /**\n * The stack trace associated with the error, if available.\n */\n stack?: string;\n\n /**\n * An optional error code associated with the error.\n */\n code?: string;\n\n /**\n * The rpc property holds additional information related to the error.\n */\n // We are intentionally using `any` here instead of `Json` because it causes\n // `WritableDraft<TransactionMeta>` from Immer to cause TypeScript to error\n // with \"Type instantiation is excessively deep and possibly infinite\". See:\n // <https://github.com/immerjs/immer/issues/839>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rpc?: any;\n};\n\n/**\n * Type for security alert response from transaction validator.\n */\nexport type SecurityAlertResponse = {\n reason: string;\n features?: string[];\n result_type: string;\n providerRequestsCount?: Record<string, number>;\n};\n\n/** Gas fee estimates for a specific priority level. */\nexport type GasFeeEstimatesForLevel = {\n /** Maximum amount to pay per gas. */\n maxFeePerGas: Hex;\n\n /** Maximum amount per gas to give to the validator as an incentive. */\n maxPriorityFeePerGas: Hex;\n};\n\n/** Alternate priority levels for which values are provided in gas fee estimates. */\nexport enum GasFeeEstimateLevel {\n low = 'low',\n medium = 'medium',\n high = 'high',\n}\n\n/** Gas fee estimates for a transaction. */\nexport type GasFeeEstimates = {\n /** The gas fee estimate for a low priority transaction. */\n [GasFeeEstimateLevel.low]: GasFeeEstimatesForLevel;\n\n /** The gas fee estimate for a medium priority transaction. */\n [GasFeeEstimateLevel.medium]: GasFeeEstimatesForLevel;\n\n /** The gas fee estimate for a high priority transaction. */\n [GasFeeEstimateLevel.high]: GasFeeEstimatesForLevel;\n};\n\n/** Request to a gas fee flow to obtain gas fee estimates. */\nexport type GasFeeFlowRequest = {\n /** An EthQuery instance to enable queries to the associated RPC provider. */\n ethQuery: EthQuery;\n\n /** Callback to get the GasFeeController estimates. */\n getGasFeeControllerEstimates: (\n options: FetchGasFeeEstimateOptions,\n ) => Promise<GasFeeState>;\n\n /** The metadata of the transaction to obtain estimates for. */\n transactionMeta: TransactionMeta;\n};\n\n/** Response from a gas fee flow containing gas fee estimates. */\nexport type GasFeeFlowResponse = {\n /** The gas fee estimates for the transaction. */\n estimates: GasFeeEstimates;\n};\n\n/** A method of obtaining gas fee estimates for a specific transaction. */\nexport type GasFeeFlow = {\n /**\n * Determine if the gas fee flow supports the specified transaction.\n * @param transactionMeta - The transaction metadata.\n * @returns Whether the gas fee flow supports the transaction.\n */\n matchesTransaction(transactionMeta: TransactionMeta): boolean;\n\n /**\n * Get gas fee estimates for a specific transaction.\n * @param request - The gas fee flow request.\n * @returns The gas fee flow response containing the gas fee estimates.\n */\n getGasFees: (request: GasFeeFlowRequest) => Promise<GasFeeFlowResponse>;\n};\n\n/** Simulation data concerning an update to a native or token balance. */\nexport type SimulationBalanceChange = {\n /** The balance before the transaction. */\n previousBalance: Hex;\n\n /** The balance after the transaction. */\n newBalance: Hex;\n\n /** The difference in balance. */\n difference: Hex;\n\n /** Whether the balance is increasing or decreasing. */\n isDecrease: boolean;\n};\n\n/** Token standards supported by simulation. */\nexport enum SimulationTokenStandard {\n erc20 = 'erc20',\n erc721 = 'erc721',\n erc1155 = 'erc1155',\n}\n\n/** Simulation data concerning an updated token. */\nexport type SimulationToken = {\n /** The token's contract address. */\n address: Hex;\n\n /** The standard of the token. */\n standard: SimulationTokenStandard;\n\n /** The ID of the token if supported by the standard. */\n id?: Hex;\n};\n\n/** Simulation data concerning a change to the a token balance. */\nexport type SimulationTokenBalanceChange = SimulationToken &\n SimulationBalanceChange;\n\n/** Simulation data for a transaction. */\nexport type SimulationData = {\n /** Data concerning a change to the user's native balance. */\n nativeBalanceChange?: SimulationBalanceChange;\n\n /** Data concerning a change to the user's token balances. */\n tokenBalanceChanges: SimulationTokenBalanceChange[];\n};\n"]}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/utils/transaction-type.ts
|
|
2
|
+
var _abi = require('@ethersproject/abi');
|
|
3
|
+
var _controllerutils = require('@metamask/controller-utils');
|
|
4
|
+
var _metamaskethabis = require('@metamask/metamask-eth-abis');
|
|
5
|
+
var ESTIMATE_GAS_ERROR = "eth_estimateGas rpc method error";
|
|
6
|
+
var ERC20Interface = new (0, _abi.Interface)(_metamaskethabis.abiERC20);
|
|
7
|
+
var ERC721Interface = new (0, _abi.Interface)(_metamaskethabis.abiERC721);
|
|
8
|
+
var ERC1155Interface = new (0, _abi.Interface)(_metamaskethabis.abiERC1155);
|
|
9
|
+
async function determineTransactionType(txParams, ethQuery) {
|
|
10
|
+
const { data, to } = txParams;
|
|
11
|
+
if (data && !to) {
|
|
12
|
+
return { type: "contractDeployment" /* deployContract */, getCodeResponse: void 0 };
|
|
13
|
+
}
|
|
14
|
+
const { contractCode: getCodeResponse, isContractAddress } = await readAddressAsContract(ethQuery, to);
|
|
15
|
+
if (!isContractAddress) {
|
|
16
|
+
return { type: "simpleSend" /* simpleSend */, getCodeResponse };
|
|
17
|
+
}
|
|
18
|
+
const hasValue = Number(txParams.value ?? "0") !== 0;
|
|
19
|
+
const contractInteractionResult = {
|
|
20
|
+
type: "contractInteraction" /* contractInteraction */,
|
|
21
|
+
getCodeResponse
|
|
22
|
+
};
|
|
23
|
+
if (!data || hasValue) {
|
|
24
|
+
return contractInteractionResult;
|
|
25
|
+
}
|
|
26
|
+
const name = parseStandardTokenTransactionData(data)?.name;
|
|
27
|
+
if (!name) {
|
|
28
|
+
return contractInteractionResult;
|
|
29
|
+
}
|
|
30
|
+
const tokenMethodName = [
|
|
31
|
+
"approve" /* tokenMethodApprove */,
|
|
32
|
+
"setapprovalforall" /* tokenMethodSetApprovalForAll */,
|
|
33
|
+
"transfer" /* tokenMethodTransfer */,
|
|
34
|
+
"transferfrom" /* tokenMethodTransferFrom */,
|
|
35
|
+
"safetransferfrom" /* tokenMethodSafeTransferFrom */
|
|
36
|
+
].find((methodName) => methodName.toLowerCase() === name.toLowerCase());
|
|
37
|
+
if (tokenMethodName) {
|
|
38
|
+
return { type: tokenMethodName, getCodeResponse };
|
|
39
|
+
}
|
|
40
|
+
return contractInteractionResult;
|
|
41
|
+
}
|
|
42
|
+
function parseStandardTokenTransactionData(data) {
|
|
43
|
+
if (!data) {
|
|
44
|
+
return void 0;
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
return ERC20Interface.parseTransaction({ data });
|
|
48
|
+
} catch {
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
return ERC721Interface.parseTransaction({ data });
|
|
52
|
+
} catch {
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
return ERC1155Interface.parseTransaction({ data });
|
|
56
|
+
} catch {
|
|
57
|
+
}
|
|
58
|
+
return void 0;
|
|
59
|
+
}
|
|
60
|
+
async function readAddressAsContract(ethQuery, address) {
|
|
61
|
+
let contractCode;
|
|
62
|
+
try {
|
|
63
|
+
contractCode = await _controllerutils.query.call(void 0, ethQuery, "getCode", [address]);
|
|
64
|
+
} catch (e) {
|
|
65
|
+
contractCode = null;
|
|
66
|
+
}
|
|
67
|
+
const isContractAddress = contractCode ? contractCode !== "0x" && contractCode !== "0x0" : false;
|
|
68
|
+
return { contractCode, isContractAddress };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
exports.ESTIMATE_GAS_ERROR = ESTIMATE_GAS_ERROR; exports.determineTransactionType = determineTransactionType;
|
|
75
|
+
//# sourceMappingURL=chunk-HS277C77.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/transaction-type.ts"],"names":[],"mappings":";AACA,SAAS,iBAAiB;AAC1B,SAAS,aAAa;AAEtB,SAAS,WAAW,UAAU,kBAAkB;AAKzC,IAAM,qBAAqB;AAElC,IAAM,iBAAiB,IAAI,UAAU,QAAQ;AAC7C,IAAM,kBAAkB,IAAI,UAAU,SAAS;AAC/C,IAAM,mBAAmB,IAAI,UAAU,UAAU;AAWjD,eAAsB,yBACpB,UACA,UACqC;AACrC,QAAM,EAAE,MAAM,GAAG,IAAI;AAErB,MAAI,QAAQ,CAAC,IAAI;AACf,WAAO,EAAE,iDAAsC,iBAAiB,OAAU;AAAA,EAC5E;AAEA,QAAM,EAAE,cAAc,iBAAiB,kBAAkB,IACvD,MAAM,sBAAsB,UAAU,EAAE;AAE1C,MAAI,CAAC,mBAAmB;AACtB,WAAO,EAAE,qCAAkC,gBAAgB;AAAA,EAC7D;AAEA,QAAM,WAAW,OAAO,SAAS,SAAS,GAAG,MAAM;AAEnD,QAAM,4BAA4B;AAAA,IAChC;AAAA,IACA;AAAA,EACF;AAEA,MAAI,CAAC,QAAQ,UAAU;AACrB,WAAO;AAAA,EACT;AAEA,QAAM,OAAO,kCAAkC,IAAI,GAAG;AAEtD,MAAI,CAAC,MAAM;AACT,WAAO;AAAA,EACT;AAEA,QAAM,kBAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMxB,EAAE,KAAK,CAAC,eAAe,WAAW,YAAY,MAAM,KAAK,YAAY,CAAC;AAEtE,MAAI,iBAAiB;AACnB,WAAO,EAAE,MAAM,iBAAiB,gBAAgB;AAAA,EAClD;AAEA,SAAO;AACT;AAUA,SAAS,kCACP,MACoC;AACpC,MAAI,CAAC,MAAM;AACT,WAAO;AAAA,EACT;AAEA,MAAI;AACF,WAAO,eAAe,iBAAiB,EAAE,KAAK,CAAC;AAAA,EACjD,QAAQ;AAAA,EAER;AAEA,MAAI;AACF,WAAO,gBAAgB,iBAAiB,EAAE,KAAK,CAAC;AAAA,EAClD,QAAQ;AAAA,EAER;AAEA,MAAI;AACF,WAAO,iBAAiB,iBAAiB,EAAE,KAAK,CAAC;AAAA,EACnD,QAAQ;AAAA,EAER;AAEA,SAAO;AACT;AASA,eAAe,sBACb,UACA,SAIC;AACD,MAAI;AACJ,MAAI;AACF,mBAAe,MAAM,MAAM,UAAU,WAAW,CAAC,OAAO,CAAC;AAAA,EAC3D,SAAS,GAAG;AACV,mBAAe;AAAA,EACjB;AAEA,QAAM,oBAAoB,eACtB,iBAAiB,QAAQ,iBAAiB,QAC1C;AACJ,SAAO,EAAE,cAAc,kBAAkB;AAC3C","sourcesContent":["import type { TransactionDescription } from '@ethersproject/abi';\nimport { Interface } from '@ethersproject/abi';\nimport { query } from '@metamask/controller-utils';\nimport type EthQuery from '@metamask/eth-query';\nimport { abiERC721, abiERC20, abiERC1155 } from '@metamask/metamask-eth-abis';\n\nimport type { InferTransactionTypeResult, TransactionParams } from '../types';\nimport { TransactionType } from '../types';\n\nexport const ESTIMATE_GAS_ERROR = 'eth_estimateGas rpc method error';\n\nconst ERC20Interface = new Interface(abiERC20);\nconst ERC721Interface = new Interface(abiERC721);\nconst ERC1155Interface = new Interface(abiERC1155);\n\n/**\n * Determines the type of the transaction by analyzing the txParams.\n * It will never return TRANSACTION_TYPE_CANCEL or TRANSACTION_TYPE_RETRY as these\n * represent specific events that we specify manually at transaction creation.\n *\n * @param txParams - Parameters for the transaction.\n * @param ethQuery - EthQuery instance.\n * @returns A object with the transaction type and the contract code response in Hex.\n */\nexport async function determineTransactionType(\n txParams: TransactionParams,\n ethQuery: EthQuery,\n): Promise<InferTransactionTypeResult> {\n const { data, to } = txParams;\n\n if (data && !to) {\n return { type: TransactionType.deployContract, getCodeResponse: undefined };\n }\n\n const { contractCode: getCodeResponse, isContractAddress } =\n await readAddressAsContract(ethQuery, to);\n\n if (!isContractAddress) {\n return { type: TransactionType.simpleSend, getCodeResponse };\n }\n\n const hasValue = Number(txParams.value ?? '0') !== 0;\n\n const contractInteractionResult = {\n type: TransactionType.contractInteraction,\n getCodeResponse,\n };\n\n if (!data || hasValue) {\n return contractInteractionResult;\n }\n\n const name = parseStandardTokenTransactionData(data)?.name;\n\n if (!name) {\n return contractInteractionResult;\n }\n\n const tokenMethodName = [\n TransactionType.tokenMethodApprove,\n TransactionType.tokenMethodSetApprovalForAll,\n TransactionType.tokenMethodTransfer,\n TransactionType.tokenMethodTransferFrom,\n TransactionType.tokenMethodSafeTransferFrom,\n ].find((methodName) => methodName.toLowerCase() === name.toLowerCase());\n\n if (tokenMethodName) {\n return { type: tokenMethodName, getCodeResponse };\n }\n\n return contractInteractionResult;\n}\n\n/**\n * Attempts to decode transaction data using ABIs for three different token standards: ERC20, ERC721, ERC1155.\n * The data will decode correctly if the transaction is an interaction with a contract that matches one of these\n * contract standards\n *\n * @param data - Encoded transaction data.\n * @returns A representation of an ethereum contract call.\n */\nfunction parseStandardTokenTransactionData(\n data?: string,\n): TransactionDescription | undefined {\n if (!data) {\n return undefined;\n }\n\n try {\n return ERC20Interface.parseTransaction({ data });\n } catch {\n // ignore and next try to parse with erc721 ABI\n }\n\n try {\n return ERC721Interface.parseTransaction({ data });\n } catch {\n // ignore and next try to parse with erc1155 ABI\n }\n\n try {\n return ERC1155Interface.parseTransaction({ data });\n } catch {\n // ignore and return undefined\n }\n\n return undefined;\n}\n\n/**\n * Reads an Ethereum address and determines if it is a contract address.\n *\n * @param ethQuery - The Ethereum query object used to interact with the Ethereum blockchain.\n * @param address - The Ethereum address.\n * @returns An object containing the contract code and a boolean indicating if it is a contract address.\n */\nasync function readAddressAsContract(\n ethQuery: EthQuery,\n address?: string,\n): Promise<{\n contractCode: string | null;\n isContractAddress: boolean;\n}> {\n let contractCode;\n try {\n contractCode = await query(ethQuery, 'getCode', [address]);\n } catch (e) {\n contractCode = null;\n }\n\n const isContractAddress = contractCode\n ? contractCode !== '0x' && contractCode !== '0x0'\n : false;\n return { contractCode, isContractAddress };\n}\n"]}
|