@metamask/transaction-controller 24.0.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.
Files changed (278) hide show
  1. package/CHANGELOG.md +118 -1
  2. package/dist/TransactionController.js +38 -1816
  3. package/dist/TransactionController.js.map +1 -1
  4. package/dist/TransactionController.mjs +39 -0
  5. package/dist/TransactionController.mjs.map +1 -0
  6. package/dist/chunk-2K7J3EY3.mjs +170 -0
  7. package/dist/chunk-2K7J3EY3.mjs.map +1 -0
  8. package/dist/chunk-5XBULBP2.js +399 -0
  9. package/dist/chunk-5XBULBP2.js.map +1 -0
  10. package/dist/chunk-6MYNWYJK.mjs +158 -0
  11. package/dist/chunk-6MYNWYJK.mjs.map +1 -0
  12. package/dist/chunk-7APMBUKB.js +158 -0
  13. package/dist/chunk-7APMBUKB.js.map +1 -0
  14. package/dist/chunk-7LXE4KHV.js +40 -0
  15. package/dist/chunk-7LXE4KHV.js.map +1 -0
  16. package/dist/chunk-7MZ57ILQ.mjs +62 -0
  17. package/dist/chunk-7MZ57ILQ.mjs.map +1 -0
  18. package/dist/chunk-BJEESIBE.js +2313 -0
  19. package/dist/chunk-BJEESIBE.js.map +1 -0
  20. package/dist/chunk-C67QD5PV.mjs +320 -0
  21. package/dist/chunk-C67QD5PV.mjs.map +1 -0
  22. package/dist/chunk-DE3MZYVY.mjs +2313 -0
  23. package/dist/chunk-DE3MZYVY.mjs.map +1 -0
  24. package/dist/chunk-DEKM6PVG.mjs +46 -0
  25. package/dist/chunk-DEKM6PVG.mjs.map +1 -0
  26. package/dist/chunk-DQP6X25N.mjs +208 -0
  27. package/dist/chunk-DQP6X25N.mjs.map +1 -0
  28. package/dist/chunk-DTDTOMTB.js +238 -0
  29. package/dist/chunk-DTDTOMTB.js.map +1 -0
  30. package/dist/chunk-DTEDYRTL.js +242 -0
  31. package/dist/chunk-DTEDYRTL.js.map +1 -0
  32. package/dist/chunk-EQ3RRHB7.mjs +211 -0
  33. package/dist/chunk-EQ3RRHB7.mjs.map +1 -0
  34. package/dist/chunk-FDJPXQTF.js +46 -0
  35. package/dist/chunk-FDJPXQTF.js.map +1 -0
  36. package/dist/chunk-FRKQ3Z2L.mjs +40 -0
  37. package/dist/chunk-FRKQ3Z2L.mjs.map +1 -0
  38. package/dist/chunk-FS7FRO7B.mjs +90 -0
  39. package/dist/chunk-FS7FRO7B.mjs.map +1 -0
  40. package/dist/chunk-GKTIFXPN.js +170 -0
  41. package/dist/chunk-GKTIFXPN.js.map +1 -0
  42. package/dist/chunk-H4M66BA3.js +62 -0
  43. package/dist/chunk-H4M66BA3.js.map +1 -0
  44. package/dist/chunk-HPNXIKFY.js +76 -0
  45. package/dist/chunk-HPNXIKFY.js.map +1 -0
  46. package/dist/chunk-HS277C77.js +75 -0
  47. package/dist/chunk-HS277C77.js.map +1 -0
  48. package/dist/chunk-I5YZ7QUK.js +121 -0
  49. package/dist/chunk-I5YZ7QUK.js.map +1 -0
  50. package/dist/chunk-IC233ZQS.js +211 -0
  51. package/dist/chunk-IC233ZQS.js.map +1 -0
  52. package/dist/chunk-IUBAETUH.js +137 -0
  53. package/dist/chunk-IUBAETUH.js.map +1 -0
  54. package/dist/chunk-J56A7UCK.mjs +123 -0
  55. package/dist/chunk-J56A7UCK.mjs.map +1 -0
  56. package/dist/chunk-JR6HDRNV.mjs +242 -0
  57. package/dist/chunk-JR6HDRNV.mjs.map +1 -0
  58. package/dist/chunk-JRBREX22.mjs +75 -0
  59. package/dist/chunk-JRBREX22.mjs.map +1 -0
  60. package/dist/chunk-JRQHIBG5.mjs +399 -0
  61. package/dist/chunk-JRQHIBG5.mjs.map +1 -0
  62. package/dist/chunk-LM4NUNMT.mjs +76 -0
  63. package/dist/chunk-LM4NUNMT.mjs.map +1 -0
  64. package/dist/chunk-M7455RU7.js +320 -0
  65. package/dist/chunk-M7455RU7.js.map +1 -0
  66. package/dist/chunk-MHM5LRRF.mjs +122 -0
  67. package/dist/chunk-MHM5LRRF.mjs.map +1 -0
  68. package/dist/chunk-NHRBO3LU.mjs +50 -0
  69. package/dist/chunk-NHRBO3LU.mjs.map +1 -0
  70. package/dist/chunk-NM6OYEPP.mjs +182 -0
  71. package/dist/chunk-NM6OYEPP.mjs.map +1 -0
  72. package/dist/chunk-NUOBUW7C.js +85 -0
  73. package/dist/chunk-NUOBUW7C.js.map +1 -0
  74. package/dist/chunk-QP75SWIQ.js +53 -0
  75. package/dist/chunk-QP75SWIQ.js.map +1 -0
  76. package/dist/chunk-RI6MVJJN.js +122 -0
  77. package/dist/chunk-RI6MVJJN.js.map +1 -0
  78. package/dist/chunk-S6VGOPUY.js +14 -0
  79. package/dist/chunk-S6VGOPUY.js.map +1 -0
  80. package/dist/chunk-UGFBA4GV.js +123 -0
  81. package/dist/chunk-UGFBA4GV.js.map +1 -0
  82. package/dist/chunk-UKYY2RVS.mjs +137 -0
  83. package/dist/chunk-UKYY2RVS.mjs.map +1 -0
  84. package/dist/chunk-UM4ORJ5B.mjs +121 -0
  85. package/dist/chunk-UM4ORJ5B.mjs.map +1 -0
  86. package/dist/chunk-UQQWZT6C.mjs +14 -0
  87. package/dist/chunk-UQQWZT6C.mjs.map +1 -0
  88. package/dist/chunk-VH47Q6TS.js +182 -0
  89. package/dist/chunk-VH47Q6TS.js.map +1 -0
  90. package/dist/chunk-XGRAHX6T.mjs +53 -0
  91. package/dist/chunk-XGRAHX6T.mjs.map +1 -0
  92. package/dist/chunk-XUI43LEZ.mjs +30 -0
  93. package/dist/chunk-XUI43LEZ.mjs.map +1 -0
  94. package/dist/chunk-Y734U4V6.mjs +85 -0
  95. package/dist/chunk-Y734U4V6.mjs.map +1 -0
  96. package/dist/chunk-Y7ENNK7L.mjs +238 -0
  97. package/dist/chunk-Y7ENNK7L.mjs.map +1 -0
  98. package/dist/chunk-Z4BLTVTB.js +30 -0
  99. package/dist/chunk-Z4BLTVTB.js.map +1 -0
  100. package/dist/chunk-ZCQRDZ36.js +208 -0
  101. package/dist/chunk-ZCQRDZ36.js.map +1 -0
  102. package/dist/chunk-ZJLZSFOZ.js +90 -0
  103. package/dist/chunk-ZJLZSFOZ.js.map +1 -0
  104. package/dist/chunk-ZNZEJDOE.js +50 -0
  105. package/dist/chunk-ZNZEJDOE.js.map +1 -0
  106. package/dist/constants.js +15 -110
  107. package/dist/constants.js.map +1 -1
  108. package/dist/constants.mjs +16 -0
  109. package/dist/constants.mjs.map +1 -0
  110. package/dist/gas-flows/DefaultGasFeeFlow.js +14 -77
  111. package/dist/gas-flows/DefaultGasFeeFlow.js.map +1 -1
  112. package/dist/gas-flows/DefaultGasFeeFlow.mjs +15 -0
  113. package/dist/gas-flows/DefaultGasFeeFlow.mjs.map +1 -0
  114. package/dist/gas-flows/LineaGasFeeFlow.js +15 -110
  115. package/dist/gas-flows/LineaGasFeeFlow.js.map +1 -1
  116. package/dist/gas-flows/LineaGasFeeFlow.mjs +16 -0
  117. package/dist/gas-flows/LineaGasFeeFlow.mjs.map +1 -0
  118. package/dist/helpers/EtherscanRemoteTransactionSource.js +11 -145
  119. package/dist/helpers/EtherscanRemoteTransactionSource.js.map +1 -1
  120. package/dist/helpers/EtherscanRemoteTransactionSource.mjs +12 -0
  121. package/dist/helpers/EtherscanRemoteTransactionSource.mjs.map +1 -0
  122. package/dist/helpers/GasFeePoller.js +10 -143
  123. package/dist/helpers/GasFeePoller.js.map +1 -1
  124. package/dist/helpers/GasFeePoller.mjs +11 -0
  125. package/dist/helpers/GasFeePoller.mjs.map +1 -0
  126. package/dist/helpers/IncomingTransactionHelper.js +8 -205
  127. package/dist/helpers/IncomingTransactionHelper.js.map +1 -1
  128. package/dist/helpers/IncomingTransactionHelper.mjs +9 -0
  129. package/dist/helpers/IncomingTransactionHelper.mjs.map +1 -0
  130. package/dist/helpers/MultichainTrackingHelper.js +12 -291
  131. package/dist/helpers/MultichainTrackingHelper.js.map +1 -1
  132. package/dist/helpers/MultichainTrackingHelper.mjs +13 -0
  133. package/dist/helpers/MultichainTrackingHelper.mjs.map +1 -0
  134. package/dist/helpers/PendingTransactionTracker.js +9 -360
  135. package/dist/helpers/PendingTransactionTracker.js.map +1 -1
  136. package/dist/helpers/PendingTransactionTracker.mjs +10 -0
  137. package/dist/helpers/PendingTransactionTracker.mjs.map +1 -0
  138. package/dist/index.js +56 -26
  139. package/dist/index.js.map +1 -1
  140. package/dist/index.mjs +57 -0
  141. package/dist/index.mjs.map +1 -0
  142. package/dist/logger.js +11 -8
  143. package/dist/logger.js.map +1 -1
  144. package/dist/logger.mjs +12 -0
  145. package/dist/logger.mjs.map +1 -0
  146. package/dist/tsconfig.build.tsbuildinfo +1 -0
  147. package/dist/{TransactionController.d.ts → types/TransactionController.d.ts} +235 -46
  148. package/dist/types/TransactionController.d.ts.map +1 -0
  149. package/dist/{constants.d.ts → types/constants.d.ts} +5 -0
  150. package/dist/types/constants.d.ts.map +1 -0
  151. package/dist/types/gas-flows/DefaultGasFeeFlow.d.ts.map +1 -0
  152. package/dist/types/gas-flows/LineaGasFeeFlow.d.ts.map +1 -0
  153. package/dist/types/helpers/EtherscanRemoteTransactionSource.d.ts.map +1 -0
  154. package/dist/types/helpers/GasFeePoller.d.ts.map +1 -0
  155. package/dist/types/helpers/IncomingTransactionHelper.d.ts.map +1 -0
  156. package/dist/types/helpers/MultichainTrackingHelper.d.ts.map +1 -0
  157. package/dist/types/helpers/PendingTransactionTracker.d.ts.map +1 -0
  158. package/dist/types/index.d.ts +9 -0
  159. package/dist/types/index.d.ts.map +1 -0
  160. package/dist/types/logger.d.ts.map +1 -0
  161. package/dist/{types.d.ts → types/types.d.ts} +63 -65
  162. package/dist/types/types.d.ts.map +1 -0
  163. package/dist/types/utils/etherscan.d.ts.map +1 -0
  164. package/dist/types/utils/external-transactions.d.ts.map +1 -0
  165. package/dist/types/utils/gas-fees.d.ts.map +1 -0
  166. package/dist/types/utils/gas-flow.d.ts.map +1 -0
  167. package/dist/types/utils/gas.d.ts.map +1 -0
  168. package/dist/types/utils/history.d.ts +20 -0
  169. package/dist/types/utils/history.d.ts.map +1 -0
  170. package/dist/types/utils/nonce.d.ts.map +1 -0
  171. package/dist/types/utils/simulation-api.d.ts +99 -0
  172. package/dist/types/utils/simulation-api.d.ts.map +1 -0
  173. package/dist/types/utils/simulation.d.ts +21 -0
  174. package/dist/types/utils/simulation.d.ts.map +1 -0
  175. package/dist/{utils → types/utils}/swaps.d.ts +8 -5
  176. package/dist/types/utils/swaps.d.ts.map +1 -0
  177. package/dist/types/utils/transaction-type.d.ts.map +1 -0
  178. package/dist/types/utils/utils.d.ts.map +1 -0
  179. package/dist/types/utils/validation.d.ts.map +1 -0
  180. package/dist/types.js +19 -170
  181. package/dist/types.js.map +1 -1
  182. package/dist/types.mjs +20 -0
  183. package/dist/types.mjs.map +1 -0
  184. package/dist/utils/etherscan.js +13 -118
  185. package/dist/utils/etherscan.js.map +1 -1
  186. package/dist/utils/etherscan.mjs +14 -0
  187. package/dist/utils/etherscan.mjs.map +1 -0
  188. package/dist/utils/external-transactions.js +8 -35
  189. package/dist/utils/external-transactions.js.map +1 -1
  190. package/dist/utils/external-transactions.mjs +9 -0
  191. package/dist/utils/external-transactions.mjs.map +1 -0
  192. package/dist/utils/gas-fees.js +15 -200
  193. package/dist/utils/gas-fees.js.map +1 -1
  194. package/dist/utils/gas-fees.mjs +16 -0
  195. package/dist/utils/gas-fees.mjs.map +1 -0
  196. package/dist/utils/gas-flow.js +10 -52
  197. package/dist/utils/gas-flow.js.map +1 -1
  198. package/dist/utils/gas-flow.mjs +11 -0
  199. package/dist/utils/gas-flow.mjs.map +1 -0
  200. package/dist/utils/gas.js +19 -133
  201. package/dist/utils/gas.js.map +1 -1
  202. package/dist/utils/gas.mjs +20 -0
  203. package/dist/utils/gas.mjs.map +1 -0
  204. package/dist/utils/history.js +9 -83
  205. package/dist/utils/history.js.map +1 -1
  206. package/dist/utils/history.mjs +10 -0
  207. package/dist/utils/history.mjs.map +1 -0
  208. package/dist/utils/nonce.js +10 -76
  209. package/dist/utils/nonce.js.map +1 -1
  210. package/dist/utils/nonce.mjs +11 -0
  211. package/dist/utils/nonce.mjs.map +1 -0
  212. package/dist/utils/simulation-api.js +10 -0
  213. package/dist/utils/simulation-api.js.map +1 -0
  214. package/dist/utils/simulation-api.mjs +10 -0
  215. package/dist/utils/simulation-api.mjs.map +1 -0
  216. package/dist/utils/simulation.js +12 -0
  217. package/dist/utils/simulation.js.map +1 -0
  218. package/dist/utils/simulation.mjs +12 -0
  219. package/dist/utils/simulation.mjs.map +1 -0
  220. package/dist/utils/swaps.js +23 -256
  221. package/dist/utils/swaps.js.map +1 -1
  222. package/dist/utils/swaps.mjs +24 -0
  223. package/dist/utils/swaps.mjs.map +1 -0
  224. package/dist/utils/transaction-type.js +10 -120
  225. package/dist/utils/transaction-type.js.map +1 -1
  226. package/dist/utils/transaction-type.mjs +11 -0
  227. package/dist/utils/transaction-type.mjs.map +1 -0
  228. package/dist/utils/utils.js +32 -160
  229. package/dist/utils/utils.js.map +1 -1
  230. package/dist/utils/utils.mjs +33 -0
  231. package/dist/utils/utils.mjs.map +1 -0
  232. package/dist/utils/validation.js +11 -258
  233. package/dist/utils/validation.js.map +1 -1
  234. package/dist/utils/validation.mjs +12 -0
  235. package/dist/utils/validation.mjs.map +1 -0
  236. package/package.json +21 -9
  237. package/dist/TransactionController.d.ts.map +0 -1
  238. package/dist/constants.d.ts.map +0 -1
  239. package/dist/gas-flows/DefaultGasFeeFlow.d.ts.map +0 -1
  240. package/dist/gas-flows/LineaGasFeeFlow.d.ts.map +0 -1
  241. package/dist/helpers/EtherscanRemoteTransactionSource.d.ts.map +0 -1
  242. package/dist/helpers/GasFeePoller.d.ts.map +0 -1
  243. package/dist/helpers/IncomingTransactionHelper.d.ts.map +0 -1
  244. package/dist/helpers/MultichainTrackingHelper.d.ts.map +0 -1
  245. package/dist/helpers/PendingTransactionTracker.d.ts.map +0 -1
  246. package/dist/index.d.ts +0 -7
  247. package/dist/index.d.ts.map +0 -1
  248. package/dist/logger.d.ts.map +0 -1
  249. package/dist/types.d.ts.map +0 -1
  250. package/dist/utils/etherscan.d.ts.map +0 -1
  251. package/dist/utils/external-transactions.d.ts.map +0 -1
  252. package/dist/utils/gas-fees.d.ts.map +0 -1
  253. package/dist/utils/gas-flow.d.ts.map +0 -1
  254. package/dist/utils/gas.d.ts.map +0 -1
  255. package/dist/utils/history.d.ts +0 -15
  256. package/dist/utils/history.d.ts.map +0 -1
  257. package/dist/utils/nonce.d.ts.map +0 -1
  258. package/dist/utils/swaps.d.ts.map +0 -1
  259. package/dist/utils/transaction-type.d.ts.map +0 -1
  260. package/dist/utils/utils.d.ts.map +0 -1
  261. package/dist/utils/validation.d.ts.map +0 -1
  262. /package/dist/{gas-flows → types/gas-flows}/DefaultGasFeeFlow.d.ts +0 -0
  263. /package/dist/{gas-flows → types/gas-flows}/LineaGasFeeFlow.d.ts +0 -0
  264. /package/dist/{helpers → types/helpers}/EtherscanRemoteTransactionSource.d.ts +0 -0
  265. /package/dist/{helpers → types/helpers}/GasFeePoller.d.ts +0 -0
  266. /package/dist/{helpers → types/helpers}/IncomingTransactionHelper.d.ts +0 -0
  267. /package/dist/{helpers → types/helpers}/MultichainTrackingHelper.d.ts +0 -0
  268. /package/dist/{helpers → types/helpers}/PendingTransactionTracker.d.ts +0 -0
  269. /package/dist/{logger.d.ts → types/logger.d.ts} +0 -0
  270. /package/dist/{utils → types/utils}/etherscan.d.ts +0 -0
  271. /package/dist/{utils → types/utils}/external-transactions.d.ts +0 -0
  272. /package/dist/{utils → types/utils}/gas-fees.d.ts +0 -0
  273. /package/dist/{utils → types/utils}/gas-flow.d.ts +0 -0
  274. /package/dist/{utils → types/utils}/gas.d.ts +0 -0
  275. /package/dist/{utils → types/utils}/nonce.d.ts +0 -0
  276. /package/dist/{utils → types/utils}/transaction-type.d.ts +0 -0
  277. /package/dist/{utils → types/utils}/utils.d.ts +0 -0
  278. /package/dist/{utils → types/utils}/validation.d.ts +0 -0
@@ -0,0 +1,24 @@
1
+ import {
2
+ DEFAULT_TOKEN_ADDRESS,
3
+ SWAPS_CHAINID_DEFAULT_TOKEN_MAP,
4
+ SWAP_TRANSACTION_TYPES,
5
+ UPDATE_POST_TX_BALANCE_ATTEMPTS,
6
+ UPDATE_POST_TX_BALANCE_TIMEOUT,
7
+ updatePostTransactionBalance,
8
+ updateSwapsTransaction
9
+ } from "../chunk-EQ3RRHB7.mjs";
10
+ import "../chunk-J56A7UCK.mjs";
11
+ import "../chunk-MHM5LRRF.mjs";
12
+ import "../chunk-UQQWZT6C.mjs";
13
+ import "../chunk-LM4NUNMT.mjs";
14
+ import "../chunk-XUI43LEZ.mjs";
15
+ export {
16
+ DEFAULT_TOKEN_ADDRESS,
17
+ SWAPS_CHAINID_DEFAULT_TOKEN_MAP,
18
+ SWAP_TRANSACTION_TYPES,
19
+ UPDATE_POST_TX_BALANCE_ATTEMPTS,
20
+ UPDATE_POST_TX_BALANCE_TIMEOUT,
21
+ updatePostTransactionBalance,
22
+ updateSwapsTransaction
23
+ };
24
+ //# sourceMappingURL=swaps.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,121 +1,11 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.determineTransactionType = exports.ESTIMATE_GAS_ERROR = void 0;
13
- const abi_1 = require("@ethersproject/abi");
14
- const controller_utils_1 = require("@metamask/controller-utils");
15
- const metamask_eth_abis_1 = require("@metamask/metamask-eth-abis");
16
- const types_1 = require("../types");
17
- exports.ESTIMATE_GAS_ERROR = 'eth_estimateGas rpc method error';
18
- const ERC20Interface = new abi_1.Interface(metamask_eth_abis_1.abiERC20);
19
- const ERC721Interface = new abi_1.Interface(metamask_eth_abis_1.abiERC721);
20
- const ERC1155Interface = new abi_1.Interface(metamask_eth_abis_1.abiERC1155);
21
- /**
22
- * Determines the type of the transaction by analyzing the txParams.
23
- * It will never return TRANSACTION_TYPE_CANCEL or TRANSACTION_TYPE_RETRY as these
24
- * represent specific events that we specify manually at transaction creation.
25
- *
26
- * @param txParams - Parameters for the transaction.
27
- * @param ethQuery - EthQuery instance.
28
- * @returns A object with the transaction type and the contract code response in Hex.
29
- */
30
- function determineTransactionType(txParams, ethQuery) {
31
- var _a, _b;
32
- return __awaiter(this, void 0, void 0, function* () {
33
- const { data, to } = txParams;
34
- if (data && !to) {
35
- return { type: types_1.TransactionType.deployContract, getCodeResponse: undefined };
36
- }
37
- const { contractCode: getCodeResponse, isContractAddress } = yield readAddressAsContract(ethQuery, to);
38
- if (!isContractAddress) {
39
- return { type: types_1.TransactionType.simpleSend, getCodeResponse };
40
- }
41
- const hasValue = Number((_a = txParams.value) !== null && _a !== void 0 ? _a : '0') !== 0;
42
- const contractInteractionResult = {
43
- type: types_1.TransactionType.contractInteraction,
44
- getCodeResponse,
45
- };
46
- if (!data || hasValue) {
47
- return contractInteractionResult;
48
- }
49
- const name = (_b = parseStandardTokenTransactionData(data)) === null || _b === void 0 ? void 0 : _b.name;
50
- if (!name) {
51
- return contractInteractionResult;
52
- }
53
- const tokenMethodName = [
54
- types_1.TransactionType.tokenMethodApprove,
55
- types_1.TransactionType.tokenMethodSetApprovalForAll,
56
- types_1.TransactionType.tokenMethodTransfer,
57
- types_1.TransactionType.tokenMethodTransferFrom,
58
- types_1.TransactionType.tokenMethodSafeTransferFrom,
59
- ].find((methodName) => methodName.toLowerCase() === name.toLowerCase());
60
- if (tokenMethodName) {
61
- return { type: tokenMethodName, getCodeResponse };
62
- }
63
- return contractInteractionResult;
64
- });
65
- }
66
- exports.determineTransactionType = determineTransactionType;
67
- /**
68
- * Attempts to decode transaction data using ABIs for three different token standards: ERC20, ERC721, ERC1155.
69
- * The data will decode correctly if the transaction is an interaction with a contract that matches one of these
70
- * contract standards
71
- *
72
- * @param data - Encoded transaction data.
73
- * @returns A representation of an ethereum contract call.
74
- */
75
- function parseStandardTokenTransactionData(data) {
76
- if (!data) {
77
- return undefined;
78
- }
79
- try {
80
- return ERC20Interface.parseTransaction({ data });
81
- }
82
- catch (_a) {
83
- // ignore and next try to parse with erc721 ABI
84
- }
85
- try {
86
- return ERC721Interface.parseTransaction({ data });
87
- }
88
- catch (_b) {
89
- // ignore and next try to parse with erc1155 ABI
90
- }
91
- try {
92
- return ERC1155Interface.parseTransaction({ data });
93
- }
94
- catch (_c) {
95
- // ignore and return undefined
96
- }
97
- return undefined;
98
- }
99
- /**
100
- * Reads an Ethereum address and determines if it is a contract address.
101
- *
102
- * @param ethQuery - The Ethereum query object used to interact with the Ethereum blockchain.
103
- * @param address - The Ethereum address.
104
- * @returns An object containing the contract code and a boolean indicating if it is a contract address.
105
- */
106
- function readAddressAsContract(ethQuery, address) {
107
- return __awaiter(this, void 0, void 0, function* () {
108
- let contractCode;
109
- try {
110
- contractCode = yield (0, controller_utils_1.query)(ethQuery, 'getCode', [address]);
111
- }
112
- catch (e) {
113
- contractCode = null;
114
- }
115
- const isContractAddress = contractCode
116
- ? contractCode !== '0x' && contractCode !== '0x0'
117
- : false;
118
- return { contractCode, isContractAddress };
119
- });
120
- }
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+ var _chunkHS277C77js = require('../chunk-HS277C77.js');
5
+ require('../chunk-HPNXIKFY.js');
6
+ require('../chunk-Z4BLTVTB.js');
7
+
8
+
9
+
10
+ exports.ESTIMATE_GAS_ERROR = _chunkHS277C77js.ESTIMATE_GAS_ERROR; exports.determineTransactionType = _chunkHS277C77js.determineTransactionType;
121
11
  //# sourceMappingURL=transaction-type.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"transaction-type.js","sourceRoot":"","sources":["../../src/utils/transaction-type.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,4CAA+C;AAC/C,iEAAmD;AAEnD,mEAA8E;AAG9E,oCAA2C;AAE9B,QAAA,kBAAkB,GAAG,kCAAkC,CAAC;AAErE,MAAM,cAAc,GAAG,IAAI,eAAS,CAAC,4BAAQ,CAAC,CAAC;AAC/C,MAAM,eAAe,GAAG,IAAI,eAAS,CAAC,6BAAS,CAAC,CAAC;AACjD,MAAM,gBAAgB,GAAG,IAAI,eAAS,CAAC,8BAAU,CAAC,CAAC;AAEnD;;;;;;;;GAQG;AACH,SAAsB,wBAAwB,CAC5C,QAA2B,EAC3B,QAAkB;;;QAElB,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,QAAQ,CAAC;QAE9B,IAAI,IAAI,IAAI,CAAC,EAAE,EAAE;YACf,OAAO,EAAE,IAAI,EAAE,uBAAe,CAAC,cAAc,EAAE,eAAe,EAAE,SAAS,EAAE,CAAC;SAC7E;QAED,MAAM,EAAE,YAAY,EAAE,eAAe,EAAE,iBAAiB,EAAE,GACxD,MAAM,qBAAqB,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QAE5C,IAAI,CAAC,iBAAiB,EAAE;YACtB,OAAO,EAAE,IAAI,EAAE,uBAAe,CAAC,UAAU,EAAE,eAAe,EAAE,CAAC;SAC9D;QAED,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAA,QAAQ,CAAC,KAAK,mCAAI,GAAG,CAAC,KAAK,CAAC,CAAC;QAErD,MAAM,yBAAyB,GAAG;YAChC,IAAI,EAAE,uBAAe,CAAC,mBAAmB;YACzC,eAAe;SAChB,CAAC;QAEF,IAAI,CAAC,IAAI,IAAI,QAAQ,EAAE;YACrB,OAAO,yBAAyB,CAAC;SAClC;QAED,MAAM,IAAI,GAAG,MAAA,iCAAiC,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,CAAC,EAAE;YACV,YAAY,GAAG,IAAI,CAAC;SACrB;QAED,MAAM,iBAAiB,GAAG,YAAY;YACpC,CAAC,CAAC,YAAY,KAAK,IAAI,IAAI,YAAY,KAAK,KAAK;YACjD,CAAC,CAAC,KAAK,CAAC;QACV,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,CAAC;IAC7C,CAAC;CAAA","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"]}
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -0,0 +1,11 @@
1
+ import {
2
+ ESTIMATE_GAS_ERROR,
3
+ determineTransactionType
4
+ } from "../chunk-JRBREX22.mjs";
5
+ import "../chunk-LM4NUNMT.mjs";
6
+ import "../chunk-XUI43LEZ.mjs";
7
+ export {
8
+ ESTIMATE_GAS_ERROR,
9
+ determineTransactionType
10
+ };
11
+ //# sourceMappingURL=transaction-type.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,161 +1,33 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.padHexToEvenLength = exports.normalizeGasFeeValues = exports.normalizeTxError = exports.validateIfTransactionUnapproved = exports.validateMinimumIncrease = exports.getIncreasedPriceFromExisting = exports.getIncreasedPriceHex = exports.isGasPriceValue = exports.isFeeMarketEIP1559Values = exports.validateGasValues = exports.isEIP1559Transaction = exports.normalizeTransactionParams = exports.ESTIMATE_GAS_ERROR = void 0;
4
- const controller_utils_1 = require("@metamask/controller-utils");
5
- const utils_1 = require("@metamask/utils");
6
- const types_1 = require("../types");
7
- exports.ESTIMATE_GAS_ERROR = 'eth_estimateGas rpc method error';
8
- // TODO: Replace `any` with type
9
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
- const NORMALIZERS = {
11
- data: (data) => (0, utils_1.add0x)(padHexToEvenLength(data)),
12
- from: (from) => (0, utils_1.add0x)(from).toLowerCase(),
13
- gas: (gas) => (0, utils_1.add0x)(gas),
14
- gasLimit: (gas) => (0, utils_1.add0x)(gas),
15
- gasPrice: (gasPrice) => (0, utils_1.add0x)(gasPrice),
16
- nonce: (nonce) => (0, utils_1.add0x)(nonce),
17
- to: (to) => (0, utils_1.add0x)(to).toLowerCase(),
18
- value: (value) => (0, utils_1.add0x)(value),
19
- maxFeePerGas: (maxFeePerGas) => (0, utils_1.add0x)(maxFeePerGas),
20
- maxPriorityFeePerGas: (maxPriorityFeePerGas) => (0, utils_1.add0x)(maxPriorityFeePerGas),
21
- estimatedBaseFee: (maxPriorityFeePerGas) => (0, utils_1.add0x)(maxPriorityFeePerGas),
22
- type: (type) => (0, utils_1.add0x)(type),
23
- };
24
- /**
25
- * Normalizes properties on transaction params.
26
- *
27
- * @param txParams - The transaction params to normalize.
28
- * @returns Normalized transaction params.
29
- */
30
- function normalizeTransactionParams(txParams) {
31
- const normalizedTxParams = { from: '' };
32
- for (const key of (0, utils_1.getKnownPropertyNames)(NORMALIZERS)) {
33
- if (txParams[key]) {
34
- normalizedTxParams[key] = NORMALIZERS[key](txParams[key]);
35
- }
36
- }
37
- if (!normalizedTxParams.value) {
38
- normalizedTxParams.value = '0x0';
39
- }
40
- return normalizedTxParams;
41
- }
42
- exports.normalizeTransactionParams = normalizeTransactionParams;
43
- /**
44
- * Checks if a transaction is EIP-1559 by checking for the existence of
45
- * maxFeePerGas and maxPriorityFeePerGas within its parameters.
46
- *
47
- * @param txParams - Transaction params object to add.
48
- * @returns Boolean that is true if the transaction is EIP-1559 (has maxFeePerGas and maxPriorityFeePerGas), otherwise returns false.
49
- */
50
- function isEIP1559Transaction(txParams) {
51
- const hasOwnProp = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);
52
- return (hasOwnProp(txParams, 'maxFeePerGas') &&
53
- hasOwnProp(txParams, 'maxPriorityFeePerGas'));
54
- }
55
- exports.isEIP1559Transaction = isEIP1559Transaction;
56
- const validateGasValues = (gasValues) => {
57
- Object.keys(gasValues).forEach((key) => {
58
- // TODO: Replace `any` with type
59
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
60
- const value = gasValues[key];
61
- if (typeof value !== 'string' || !(0, utils_1.isStrictHexString)(value)) {
62
- throw new TypeError(`expected hex string for ${key} but received: ${value}`);
63
- }
64
- });
65
- };
66
- exports.validateGasValues = validateGasValues;
67
- const isFeeMarketEIP1559Values = (gasValues) => (gasValues === null || gasValues === void 0 ? void 0 : gasValues.maxFeePerGas) !== undefined ||
68
- (gasValues === null || gasValues === void 0 ? void 0 : gasValues.maxPriorityFeePerGas) !== undefined;
69
- exports.isFeeMarketEIP1559Values = isFeeMarketEIP1559Values;
70
- const isGasPriceValue = (gasValues) => (gasValues === null || gasValues === void 0 ? void 0 : gasValues.gasPrice) !== undefined;
71
- exports.isGasPriceValue = isGasPriceValue;
72
- const getIncreasedPriceHex = (value, rate) => (0, utils_1.add0x)(`${parseInt(`${value * rate}`, 10).toString(16)}`);
73
- exports.getIncreasedPriceHex = getIncreasedPriceHex;
74
- const getIncreasedPriceFromExisting = (value, rate) => {
75
- return (0, exports.getIncreasedPriceHex)((0, controller_utils_1.convertHexToDecimal)(value), rate);
76
- };
77
- exports.getIncreasedPriceFromExisting = getIncreasedPriceFromExisting;
78
- /**
79
- * Validates that the proposed value is greater than or equal to the minimum value.
80
- *
81
- * @param proposed - The proposed value.
82
- * @param min - The minimum value.
83
- * @returns The proposed value.
84
- * @throws Will throw if the proposed value is too low.
85
- */
86
- function validateMinimumIncrease(proposed, min) {
87
- const proposedDecimal = (0, controller_utils_1.convertHexToDecimal)(proposed);
88
- const minDecimal = (0, controller_utils_1.convertHexToDecimal)(min);
89
- if (proposedDecimal >= minDecimal) {
90
- return proposed;
91
- }
92
- const errorMsg = `The proposed value: ${proposedDecimal} should meet or exceed the minimum value: ${minDecimal}`;
93
- throw new Error(errorMsg);
94
- }
95
- exports.validateMinimumIncrease = validateMinimumIncrease;
96
- /**
97
- * Validates that a transaction is unapproved.
98
- * Throws if the transaction is not unapproved.
99
- *
100
- * @param transactionMeta - The transaction metadata to check.
101
- * @param fnName - The name of the function calling this helper.
102
- */
103
- function validateIfTransactionUnapproved(transactionMeta, fnName) {
104
- if ((transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.status) !== types_1.TransactionStatus.unapproved) {
105
- throw new Error(`TransactionsController: Can only call ${fnName} on an unapproved transaction.
106
- Current tx status: ${transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.status}`);
107
- }
108
- }
109
- exports.validateIfTransactionUnapproved = validateIfTransactionUnapproved;
110
- /**
111
- * Normalizes properties on transaction params.
112
- *
113
- * @param error - The error to be normalize.
114
- * @returns Normalized transaction error.
115
- */
116
- function normalizeTxError(error) {
117
- return {
118
- name: error.name,
119
- message: error.message,
120
- stack: error.stack,
121
- code: error === null || error === void 0 ? void 0 : error.code,
122
- rpc: error === null || error === void 0 ? void 0 : error.value,
123
- };
124
- }
125
- exports.normalizeTxError = normalizeTxError;
126
- /**
127
- * Normalize an object containing gas fee values.
128
- *
129
- * @param gasFeeValues - An object containing gas fee values.
130
- * @returns An object containing normalized gas fee values.
131
- */
132
- function normalizeGasFeeValues(gasFeeValues) {
133
- // TODO: Replace `any` with type
134
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
135
- const normalize = (value) => typeof value === 'string' ? (0, utils_1.add0x)(value) : value;
136
- if ('gasPrice' in gasFeeValues) {
137
- return {
138
- gasPrice: normalize(gasFeeValues.gasPrice),
139
- };
140
- }
141
- return {
142
- maxFeePerGas: normalize(gasFeeValues.maxFeePerGas),
143
- maxPriorityFeePerGas: normalize(gasFeeValues.maxPriorityFeePerGas),
144
- };
145
- }
146
- exports.normalizeGasFeeValues = normalizeGasFeeValues;
147
- /**
148
- * Ensure a hex string is of even length by adding a leading 0 if necessary.
149
- * Any existing `0x` prefix is preserved but is not added if missing.
150
- *
151
- * @param hex - The hex string to ensure is even.
152
- * @returns The hex string with an even length.
153
- */
154
- function padHexToEvenLength(hex) {
155
- const prefix = hex.toLowerCase().startsWith('0x') ? hex.slice(0, 2) : '';
156
- const data = prefix ? hex.slice(2) : hex;
157
- const evenData = data.length % 2 === 0 ? data : `0${data}`;
158
- return prefix + evenData;
159
- }
160
- exports.padHexToEvenLength = padHexToEvenLength;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+ var _chunkUGFBA4GVjs = require('../chunk-UGFBA4GV.js');
16
+ require('../chunk-HPNXIKFY.js');
17
+ require('../chunk-Z4BLTVTB.js');
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+ exports.ESTIMATE_GAS_ERROR = _chunkUGFBA4GVjs.ESTIMATE_GAS_ERROR; exports.getIncreasedPriceFromExisting = _chunkUGFBA4GVjs.getIncreasedPriceFromExisting; exports.getIncreasedPriceHex = _chunkUGFBA4GVjs.getIncreasedPriceHex; exports.isEIP1559Transaction = _chunkUGFBA4GVjs.isEIP1559Transaction; exports.isFeeMarketEIP1559Values = _chunkUGFBA4GVjs.isFeeMarketEIP1559Values; exports.isGasPriceValue = _chunkUGFBA4GVjs.isGasPriceValue; exports.normalizeGasFeeValues = _chunkUGFBA4GVjs.normalizeGasFeeValues; exports.normalizeTransactionParams = _chunkUGFBA4GVjs.normalizeTransactionParams; exports.normalizeTxError = _chunkUGFBA4GVjs.normalizeTxError; exports.padHexToEvenLength = _chunkUGFBA4GVjs.padHexToEvenLength; exports.validateGasValues = _chunkUGFBA4GVjs.validateGasValues; exports.validateIfTransactionUnapproved = _chunkUGFBA4GVjs.validateIfTransactionUnapproved; exports.validateMinimumIncrease = _chunkUGFBA4GVjs.validateMinimumIncrease;
161
33
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":";;;AAAA,iEAAiE;AACjE,2CAIyB;AAMzB,oCAA6C;AAOhC,QAAA,kBAAkB,GAAG,kCAAkC,CAAC;AAErE,gCAAgC;AAChC,8DAA8D;AAC9D,MAAM,WAAW,GAAgD;IAC/D,IAAI,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,IAAA,aAAK,EAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;IACvD,IAAI,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,IAAA,aAAK,EAAC,IAAI,CAAC,CAAC,WAAW,EAAE;IACjD,GAAG,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,IAAA,aAAK,EAAC,GAAG,CAAC;IAChC,QAAQ,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,IAAA,aAAK,EAAC,GA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ask/controller-utils';\nimport {\n add0x,\n getKnownPropertyNames,\n isStrictHexString,\n} from '@metamask/utils';\n\nimport type {\n GasPriceValue,\n FeeMarketEIP1559Values,\n} from '../TransactionController';\nimport { TransactionStatus } from '../types';\nimport type {\n TransactionParams,\n TransactionMeta,\n TransactionError,\n} from '../types';\n\nexport const ESTIMATE_GAS_ERROR = 'eth_estimateGas rpc method error';\n\n// TODO: Replace `any` with type\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst NORMALIZERS: { [param in keyof TransactionParams]: any } = {\n data: (data: string) => add0x(padHexToEvenLength(data)),\n from: (from: string) => add0x(from).toLowerCase(),\n gas: (gas: string) => add0x(gas),\n gasLimit: (gas: string) => add0x(gas),\n gasPrice: (gasPrice: string) => add0x(gasPrice),\n nonce: (nonce: string) => add0x(nonce),\n to: (to: string) => add0x(to).toLowerCase(),\n value: (value: string) => add0x(value),\n maxFeePerGas: (maxFeePerGas: string) => add0x(maxFeePerGas),\n maxPriorityFeePerGas: (maxPriorityFeePerGas: string) =>\n add0x(maxPriorityFeePerGas),\n estimatedBaseFee: (maxPriorityFeePerGas: string) =>\n add0x(maxPriorityFeePerGas),\n type: (type: string) => add0x(type),\n};\n\n/**\n * Normalizes properties on transaction params.\n *\n * @param txParams - The transaction params to normalize.\n * @returns Normalized transaction params.\n */\nexport function normalizeTransactionParams(txParams: TransactionParams) {\n const normalizedTxParams: TransactionParams = { from: '' };\n\n for (const key of getKnownPropertyNames(NORMALIZERS)) {\n if (txParams[key]) {\n normalizedTxParams[key] = NORMALIZERS[key](txParams[key]);\n }\n }\n\n if (!normalizedTxParams.value) {\n normalizedTxParams.value = '0x0';\n }\n\n return normalizedTxParams;\n}\n\n/**\n * Checks if a transaction is EIP-1559 by checking for the existence of\n * maxFeePerGas and maxPriorityFeePerGas within its parameters.\n *\n * @param txParams - Transaction params object to add.\n * @returns Boolean that is true if the transaction is EIP-1559 (has maxFeePerGas and maxPriorityFeePerGas), otherwise returns false.\n */\nexport function isEIP1559Transaction(txParams: TransactionParams): boolean {\n const hasOwnProp = (obj: TransactionParams, key: string) =>\n Object.prototype.hasOwnProperty.call(obj, key);\n return (\n hasOwnProp(txParams, 'maxFeePerGas') &&\n hasOwnProp(txParams, 'maxPriorityFeePerGas')\n );\n}\n\nexport const validateGasValues = (\n gasValues: GasPriceValue | FeeMarketEIP1559Values,\n) => {\n Object.keys(gasValues).forEach((key) => {\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const value = (gasValues as any)[key];\n if (typeof value !== 'string' || !isStrictHexString(value)) {\n throw new TypeError(\n `expected hex string for ${key} but received: ${value}`,\n );\n }\n });\n};\n\nexport const isFeeMarketEIP1559Values = (\n gasValues?: GasPriceValue | FeeMarketEIP1559Values,\n): gasValues is FeeMarketEIP1559Values =>\n (gasValues as FeeMarketEIP1559Values)?.maxFeePerGas !== undefined ||\n (gasValues as FeeMarketEIP1559Values)?.maxPriorityFeePerGas !== undefined;\n\nexport const isGasPriceValue = (\n gasValues?: GasPriceValue | FeeMarketEIP1559Values,\n): gasValues is GasPriceValue =>\n (gasValues as GasPriceValue)?.gasPrice !== undefined;\n\nexport const getIncreasedPriceHex = (value: number, rate: number): string =>\n add0x(`${parseInt(`${value * rate}`, 10).toString(16)}`);\n\nexport const getIncreasedPriceFromExisting = (\n value: string | undefined,\n rate: number,\n): string => {\n return getIncreasedPriceHex(convertHexToDecimal(value), rate);\n};\n\n/**\n * Validates that the proposed value is greater than or equal to the minimum value.\n *\n * @param proposed - The proposed value.\n * @param min - The minimum value.\n * @returns The proposed value.\n * @throws Will throw if the proposed value is too low.\n */\nexport function validateMinimumIncrease(proposed: string, min: string) {\n const proposedDecimal = convertHexToDecimal(proposed);\n const minDecimal = convertHexToDecimal(min);\n if (proposedDecimal >= minDecimal) {\n return proposed;\n }\n const errorMsg = `The proposed value: ${proposedDecimal} should meet or exceed the minimum value: ${minDecimal}`;\n throw new Error(errorMsg);\n}\n\n/**\n * Validates that a transaction is unapproved.\n * Throws if the transaction is not unapproved.\n *\n * @param transactionMeta - The transaction metadata to check.\n * @param fnName - The name of the function calling this helper.\n */\nexport function validateIfTransactionUnapproved(\n transactionMeta: TransactionMeta | undefined,\n fnName: string,\n) {\n if (transactionMeta?.status !== TransactionStatus.unapproved) {\n throw new Error(\n `TransactionsController: Can only call ${fnName} on an unapproved transaction.\n Current tx status: ${transactionMeta?.status}`,\n );\n }\n}\n\n/**\n * Normalizes properties on transaction params.\n *\n * @param error - The error to be normalize.\n * @returns Normalized transaction error.\n */\nexport function normalizeTxError(\n error: Error & { code?: string; value?: unknown },\n): TransactionError {\n return {\n name: error.name,\n message: error.message,\n stack: error.stack,\n code: error?.code,\n rpc: error?.value,\n };\n}\n\n/**\n * Normalize an object containing gas fee values.\n *\n * @param gasFeeValues - An object containing gas fee values.\n * @returns An object containing normalized gas fee values.\n */\nexport function normalizeGasFeeValues(\n gasFeeValues: GasPriceValue | FeeMarketEIP1559Values,\n): GasPriceValue | FeeMarketEIP1559Values {\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const normalize = (value: any) =>\n typeof value === 'string' ? add0x(value) : value;\n\n if ('gasPrice' in gasFeeValues) {\n return {\n gasPrice: normalize(gasFeeValues.gasPrice),\n };\n }\n\n return {\n maxFeePerGas: normalize(gasFeeValues.maxFeePerGas),\n maxPriorityFeePerGas: normalize(gasFeeValues.maxPriorityFeePerGas),\n };\n}\n\n/**\n * Ensure a hex string is of even length by adding a leading 0 if necessary.\n * Any existing `0x` prefix is preserved but is not added if missing.\n *\n * @param hex - The hex string to ensure is even.\n * @returns The hex string with an even length.\n */\nexport function padHexToEvenLength(hex: string) {\n const prefix = hex.toLowerCase().startsWith('0x') ? hex.slice(0, 2) : '';\n const data = prefix ? hex.slice(2) : hex;\n const evenData = data.length % 2 === 0 ? data : `0${data}`;\n\n return prefix + evenData;\n}\n"]}
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -0,0 +1,33 @@
1
+ import {
2
+ ESTIMATE_GAS_ERROR,
3
+ getIncreasedPriceFromExisting,
4
+ getIncreasedPriceHex,
5
+ isEIP1559Transaction,
6
+ isFeeMarketEIP1559Values,
7
+ isGasPriceValue,
8
+ normalizeGasFeeValues,
9
+ normalizeTransactionParams,
10
+ normalizeTxError,
11
+ padHexToEvenLength,
12
+ validateGasValues,
13
+ validateIfTransactionUnapproved,
14
+ validateMinimumIncrease
15
+ } from "../chunk-J56A7UCK.mjs";
16
+ import "../chunk-LM4NUNMT.mjs";
17
+ import "../chunk-XUI43LEZ.mjs";
18
+ export {
19
+ ESTIMATE_GAS_ERROR,
20
+ getIncreasedPriceFromExisting,
21
+ getIncreasedPriceHex,
22
+ isEIP1559Transaction,
23
+ isFeeMarketEIP1559Values,
24
+ isGasPriceValue,
25
+ normalizeGasFeeValues,
26
+ normalizeTransactionParams,
27
+ normalizeTxError,
28
+ padHexToEvenLength,
29
+ validateGasValues,
30
+ validateIfTransactionUnapproved,
31
+ validateMinimumIncrease
32
+ };
33
+ //# sourceMappingURL=utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}