@metamask-previews/transaction-controller 69.6.1-preview-4f4c98e → 69.6.1-preview-eb263b0ee

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 (492) hide show
  1. package/CHANGELOG.md +0 -5
  2. package/dist/TransactionController-method-action-types.cjs +7 -0
  3. package/dist/TransactionController-method-action-types.cjs.map +1 -0
  4. package/dist/{TransactionController-method-action-types.d.ts → TransactionController-method-action-types.d.cts} +2 -2
  5. package/dist/TransactionController-method-action-types.d.cts.map +1 -0
  6. package/dist/TransactionController-method-action-types.d.mts +413 -0
  7. package/dist/TransactionController-method-action-types.d.mts.map +1 -0
  8. package/dist/{TransactionController-method-action-types.js → TransactionController-method-action-types.mjs} +1 -1
  9. package/dist/TransactionController-method-action-types.mjs.map +1 -0
  10. package/dist/TransactionController.cjs +2444 -0
  11. package/dist/TransactionController.cjs.map +1 -0
  12. package/dist/{TransactionController.d.ts → TransactionController.d.cts} +18 -18
  13. package/dist/TransactionController.d.cts.map +1 -0
  14. package/dist/TransactionController.d.mts +751 -0
  15. package/dist/TransactionController.d.mts.map +1 -0
  16. package/dist/{TransactionController.js → TransactionController.mjs} +50 -49
  17. package/dist/TransactionController.mjs.map +1 -0
  18. package/dist/api/accounts-api.cjs +57 -0
  19. package/dist/api/accounts-api.cjs.map +1 -0
  20. package/dist/api/{accounts-api.d.ts → accounts-api.d.cts} +1 -1
  21. package/dist/api/accounts-api.d.cts.map +1 -0
  22. package/dist/api/accounts-api.d.mts +44 -0
  23. package/dist/api/accounts-api.d.mts.map +1 -0
  24. package/dist/api/{accounts-api.js → accounts-api.mjs} +5 -5
  25. package/dist/api/accounts-api.mjs.map +1 -0
  26. package/dist/api/simulation-api.cjs +116 -0
  27. package/dist/api/simulation-api.cjs.map +1 -0
  28. package/dist/api/{simulation-api.d.ts → simulation-api.d.cts} +3 -3
  29. package/dist/api/simulation-api.d.cts.map +1 -0
  30. package/dist/api/simulation-api.d.mts +196 -0
  31. package/dist/api/simulation-api.d.mts.map +1 -0
  32. package/dist/api/{simulation-api.js → simulation-api.mjs} +8 -7
  33. package/dist/api/simulation-api.mjs.map +1 -0
  34. package/dist/constants.cjs +111 -0
  35. package/dist/constants.cjs.map +1 -0
  36. package/dist/{constants.d.ts → constants.d.cts} +37 -37
  37. package/dist/constants.d.cts.map +1 -0
  38. package/dist/constants.d.mts +78 -0
  39. package/dist/constants.d.mts.map +1 -0
  40. package/dist/{constants.js → constants.mjs} +1 -1
  41. package/dist/constants.mjs.map +1 -0
  42. package/dist/errors.cjs +37 -0
  43. package/dist/errors.cjs.map +1 -0
  44. package/dist/{errors.d.ts → errors.d.cts} +2 -2
  45. package/dist/errors.d.cts.map +1 -0
  46. package/dist/errors.d.mts +19 -0
  47. package/dist/errors.d.mts.map +1 -0
  48. package/dist/{errors.js → errors.mjs} +2 -2
  49. package/dist/errors.mjs.map +1 -0
  50. package/dist/gas-flows/DefaultGasFeeFlow.cjs +85 -0
  51. package/dist/gas-flows/{DefaultGasFeeFlow.js.map → DefaultGasFeeFlow.cjs.map} +1 -1
  52. package/dist/gas-flows/{DefaultGasFeeFlow.d.ts → DefaultGasFeeFlow.d.cts} +2 -2
  53. package/dist/gas-flows/DefaultGasFeeFlow.d.cts.map +1 -0
  54. package/dist/gas-flows/DefaultGasFeeFlow.d.mts +10 -0
  55. package/dist/gas-flows/DefaultGasFeeFlow.d.mts.map +1 -0
  56. package/dist/gas-flows/{DefaultGasFeeFlow.js → DefaultGasFeeFlow.mjs} +6 -6
  57. package/dist/gas-flows/DefaultGasFeeFlow.mjs.map +1 -0
  58. package/dist/gas-flows/LineaGasFeeFlow.cjs +111 -0
  59. package/dist/gas-flows/LineaGasFeeFlow.cjs.map +1 -0
  60. package/dist/gas-flows/{LineaGasFeeFlow.d.ts → LineaGasFeeFlow.d.cts} +3 -3
  61. package/dist/gas-flows/LineaGasFeeFlow.d.cts.map +1 -0
  62. package/dist/gas-flows/LineaGasFeeFlow.d.mts +16 -0
  63. package/dist/gas-flows/LineaGasFeeFlow.d.mts.map +1 -0
  64. package/dist/gas-flows/{LineaGasFeeFlow.js → LineaGasFeeFlow.mjs} +7 -7
  65. package/dist/gas-flows/LineaGasFeeFlow.mjs.map +1 -0
  66. package/dist/gas-flows/MantleLayer1GasFeeFlow.cjs +66 -0
  67. package/dist/gas-flows/MantleLayer1GasFeeFlow.cjs.map +1 -0
  68. package/dist/gas-flows/{MantleLayer1GasFeeFlow.d.ts → MantleLayer1GasFeeFlow.d.cts} +5 -5
  69. package/dist/gas-flows/MantleLayer1GasFeeFlow.d.cts.map +1 -0
  70. package/dist/gas-flows/MantleLayer1GasFeeFlow.d.mts +21 -0
  71. package/dist/gas-flows/MantleLayer1GasFeeFlow.d.mts.map +1 -0
  72. package/dist/gas-flows/{MantleLayer1GasFeeFlow.js → MantleLayer1GasFeeFlow.mjs} +6 -6
  73. package/dist/gas-flows/MantleLayer1GasFeeFlow.mjs.map +1 -0
  74. package/dist/gas-flows/OptimismLayer1GasFeeFlow.cjs +59 -0
  75. package/dist/gas-flows/OptimismLayer1GasFeeFlow.cjs.map +1 -0
  76. package/dist/gas-flows/{OptimismLayer1GasFeeFlow.d.ts → OptimismLayer1GasFeeFlow.d.cts} +4 -4
  77. package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.cts.map +1 -0
  78. package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.mts +14 -0
  79. package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.mts.map +1 -0
  80. package/dist/gas-flows/{OptimismLayer1GasFeeFlow.js → OptimismLayer1GasFeeFlow.mjs} +5 -5
  81. package/dist/gas-flows/OptimismLayer1GasFeeFlow.mjs.map +1 -0
  82. package/dist/gas-flows/OracleLayer1GasFeeFlow.cjs +201 -0
  83. package/dist/gas-flows/OracleLayer1GasFeeFlow.cjs.map +1 -0
  84. package/dist/gas-flows/{OracleLayer1GasFeeFlow.d.ts → OracleLayer1GasFeeFlow.d.cts} +5 -5
  85. package/dist/gas-flows/OracleLayer1GasFeeFlow.d.cts.map +1 -0
  86. package/dist/gas-flows/OracleLayer1GasFeeFlow.d.mts +57 -0
  87. package/dist/gas-flows/OracleLayer1GasFeeFlow.d.mts.map +1 -0
  88. package/dist/gas-flows/{OracleLayer1GasFeeFlow.js → OracleLayer1GasFeeFlow.mjs} +15 -8
  89. package/dist/gas-flows/OracleLayer1GasFeeFlow.mjs.map +1 -0
  90. package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.cjs +123 -0
  91. package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.cjs.map +1 -0
  92. package/dist/gas-flows/{RandomisedEstimationsGasFeeFlow.d.ts → RandomisedEstimationsGasFeeFlow.d.cts} +4 -4
  93. package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.d.cts.map +1 -0
  94. package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.d.mts +28 -0
  95. package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.d.mts.map +1 -0
  96. package/dist/gas-flows/{RandomisedEstimationsGasFeeFlow.js → RandomisedEstimationsGasFeeFlow.mjs} +8 -8
  97. package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.mjs.map +1 -0
  98. package/dist/gas-flows/ScrollLayer1GasFeeFlow.cjs +24 -0
  99. package/dist/gas-flows/ScrollLayer1GasFeeFlow.cjs.map +1 -0
  100. package/dist/gas-flows/{ScrollLayer1GasFeeFlow.d.ts → ScrollLayer1GasFeeFlow.d.cts} +5 -5
  101. package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.cts.map +1 -0
  102. package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.mts +16 -0
  103. package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.mts.map +1 -0
  104. package/dist/gas-flows/{ScrollLayer1GasFeeFlow.js → ScrollLayer1GasFeeFlow.mjs} +3 -3
  105. package/dist/gas-flows/ScrollLayer1GasFeeFlow.mjs.map +1 -0
  106. package/dist/gas-flows/TestGasFeeFlow.cjs +73 -0
  107. package/dist/gas-flows/TestGasFeeFlow.cjs.map +1 -0
  108. package/dist/gas-flows/{TestGasFeeFlow.d.ts → TestGasFeeFlow.d.cts} +2 -2
  109. package/dist/gas-flows/TestGasFeeFlow.d.cts.map +1 -0
  110. package/dist/gas-flows/TestGasFeeFlow.d.mts +12 -0
  111. package/dist/gas-flows/TestGasFeeFlow.d.mts.map +1 -0
  112. package/dist/gas-flows/{TestGasFeeFlow.js → TestGasFeeFlow.mjs} +3 -3
  113. package/dist/gas-flows/TestGasFeeFlow.mjs.map +1 -0
  114. package/dist/helpers/GasFeePoller.cjs +334 -0
  115. package/dist/helpers/GasFeePoller.cjs.map +1 -0
  116. package/dist/helpers/{GasFeePoller.d.ts → GasFeePoller.d.cts} +10 -7
  117. package/dist/helpers/GasFeePoller.d.cts.map +1 -0
  118. package/dist/helpers/GasFeePoller.d.mts +66 -0
  119. package/dist/helpers/GasFeePoller.d.mts.map +1 -0
  120. package/dist/helpers/{GasFeePoller.js → GasFeePoller.mjs} +9 -9
  121. package/dist/helpers/GasFeePoller.mjs.map +1 -0
  122. package/dist/helpers/MethodDataHelper.cjs +84 -0
  123. package/dist/helpers/MethodDataHelper.cjs.map +1 -0
  124. package/dist/helpers/{MethodDataHelper.d.ts → MethodDataHelper.d.cts} +7 -4
  125. package/dist/helpers/MethodDataHelper.d.cts.map +1 -0
  126. package/dist/helpers/MethodDataHelper.d.mts +16 -0
  127. package/dist/helpers/MethodDataHelper.d.mts.map +1 -0
  128. package/dist/helpers/{MethodDataHelper.js → MethodDataHelper.mjs} +7 -7
  129. package/dist/helpers/MethodDataHelper.mjs.map +1 -0
  130. package/dist/helpers/MultichainTrackingHelper.cjs +231 -0
  131. package/dist/helpers/MultichainTrackingHelper.cjs.map +1 -0
  132. package/dist/helpers/{MultichainTrackingHelper.d.ts → MultichainTrackingHelper.d.cts} +5 -5
  133. package/dist/helpers/MultichainTrackingHelper.d.cts.map +1 -0
  134. package/dist/helpers/MultichainTrackingHelper.d.mts +56 -0
  135. package/dist/helpers/MultichainTrackingHelper.d.mts.map +1 -0
  136. package/dist/helpers/{MultichainTrackingHelper.js → MultichainTrackingHelper.mjs} +8 -8
  137. package/dist/helpers/MultichainTrackingHelper.mjs.map +1 -0
  138. package/dist/helpers/PendingTransactionTracker.cjs +407 -0
  139. package/dist/helpers/PendingTransactionTracker.cjs.map +1 -0
  140. package/dist/helpers/{PendingTransactionTracker.d.ts → PendingTransactionTracker.d.cts} +8 -5
  141. package/dist/helpers/PendingTransactionTracker.d.cts.map +1 -0
  142. package/dist/helpers/PendingTransactionTracker.d.mts +54 -0
  143. package/dist/helpers/PendingTransactionTracker.d.mts.map +1 -0
  144. package/dist/helpers/{PendingTransactionTracker.js → PendingTransactionTracker.mjs} +15 -14
  145. package/dist/helpers/PendingTransactionTracker.mjs.map +1 -0
  146. package/dist/helpers/ResimulateHelper.cjs +274 -0
  147. package/dist/helpers/ResimulateHelper.cjs.map +1 -0
  148. package/dist/helpers/{ResimulateHelper.d.ts → ResimulateHelper.d.cts} +3 -3
  149. package/dist/helpers/ResimulateHelper.d.cts.map +1 -0
  150. package/dist/helpers/ResimulateHelper.d.mts +36 -0
  151. package/dist/helpers/ResimulateHelper.d.mts.map +1 -0
  152. package/dist/helpers/{ResimulateHelper.js → ResimulateHelper.mjs} +8 -7
  153. package/dist/helpers/ResimulateHelper.mjs.map +1 -0
  154. package/dist/helpers/TransactionPoller.cjs +175 -0
  155. package/dist/helpers/TransactionPoller.cjs.map +1 -0
  156. package/dist/helpers/{TransactionPoller.d.ts → TransactionPoller.d.cts} +5 -5
  157. package/dist/helpers/TransactionPoller.d.cts.map +1 -0
  158. package/dist/helpers/TransactionPoller.d.mts +37 -0
  159. package/dist/helpers/TransactionPoller.d.mts.map +1 -0
  160. package/dist/helpers/{TransactionPoller.js → TransactionPoller.mjs} +11 -10
  161. package/dist/helpers/TransactionPoller.mjs.map +1 -0
  162. package/dist/hooks/CollectPublishHook.cjs +94 -0
  163. package/dist/hooks/CollectPublishHook.cjs.map +1 -0
  164. package/dist/hooks/{CollectPublishHook.d.ts → CollectPublishHook.d.cts} +3 -3
  165. package/dist/hooks/CollectPublishHook.d.cts.map +1 -0
  166. package/dist/hooks/CollectPublishHook.d.mts +29 -0
  167. package/dist/hooks/CollectPublishHook.d.mts.map +1 -0
  168. package/dist/hooks/{CollectPublishHook.js → CollectPublishHook.mjs} +5 -4
  169. package/dist/hooks/CollectPublishHook.mjs.map +1 -0
  170. package/dist/hooks/ExtraTransactionsPublishHook.cjs +126 -0
  171. package/dist/hooks/ExtraTransactionsPublishHook.cjs.map +1 -0
  172. package/dist/hooks/{ExtraTransactionsPublishHook.d.ts → ExtraTransactionsPublishHook.d.cts} +3 -3
  173. package/dist/hooks/ExtraTransactionsPublishHook.d.cts.map +1 -0
  174. package/dist/hooks/ExtraTransactionsPublishHook.d.mts +19 -0
  175. package/dist/hooks/ExtraTransactionsPublishHook.d.mts.map +1 -0
  176. package/dist/hooks/{ExtraTransactionsPublishHook.js → ExtraTransactionsPublishHook.mjs} +3 -3
  177. package/dist/hooks/ExtraTransactionsPublishHook.mjs.map +1 -0
  178. package/dist/hooks/SequentialPublishBatchHook.cjs +112 -0
  179. package/dist/hooks/SequentialPublishBatchHook.cjs.map +1 -0
  180. package/dist/hooks/{SequentialPublishBatchHook.d.ts → SequentialPublishBatchHook.d.cts} +4 -4
  181. package/dist/hooks/SequentialPublishBatchHook.d.cts.map +1 -0
  182. package/dist/hooks/SequentialPublishBatchHook.d.mts +22 -0
  183. package/dist/hooks/SequentialPublishBatchHook.d.mts.map +1 -0
  184. package/dist/hooks/{SequentialPublishBatchHook.js → SequentialPublishBatchHook.mjs} +4 -4
  185. package/dist/hooks/SequentialPublishBatchHook.mjs.map +1 -0
  186. package/dist/index.cjs +40 -0
  187. package/dist/index.cjs.map +1 -0
  188. package/dist/{index.d.ts → index.d.cts} +16 -16
  189. package/dist/index.d.cts.map +1 -0
  190. package/dist/index.d.mts +16 -0
  191. package/dist/index.d.mts.map +1 -0
  192. package/dist/index.mjs +12 -0
  193. package/dist/index.mjs.map +1 -0
  194. package/dist/logger.cjs +9 -0
  195. package/dist/logger.cjs.map +1 -0
  196. package/dist/{logger.d.ts → logger.d.cts} +3 -2
  197. package/dist/logger.d.cts.map +1 -0
  198. package/dist/logger.d.mts +6 -0
  199. package/dist/logger.d.mts.map +1 -0
  200. package/dist/{logger.js → logger.mjs} +2 -2
  201. package/dist/logger.mjs.map +1 -0
  202. package/dist/types.cjs +382 -0
  203. package/dist/types.cjs.map +1 -0
  204. package/dist/{types.d.ts → types.d.cts} +8 -8
  205. package/dist/types.d.cts.map +1 -0
  206. package/dist/types.d.mts +1887 -0
  207. package/dist/types.d.mts.map +1 -0
  208. package/dist/{types.js → types.mjs} +1 -1
  209. package/dist/types.mjs.map +1 -0
  210. package/dist/utils/balance-changes.cjs +592 -0
  211. package/dist/utils/balance-changes.cjs.map +1 -0
  212. package/dist/utils/{balance-changes.d.ts → balance-changes.d.cts} +5 -5
  213. package/dist/utils/balance-changes.d.cts.map +1 -0
  214. package/dist/utils/balance-changes.d.mts +38 -0
  215. package/dist/utils/balance-changes.d.mts.map +1 -0
  216. package/dist/utils/{balance-changes.js → balance-changes.mjs} +20 -13
  217. package/dist/utils/balance-changes.mjs.map +1 -0
  218. package/dist/utils/balance.cjs +44 -0
  219. package/dist/utils/balance.cjs.map +1 -0
  220. package/dist/utils/{balance.d.ts → balance.d.cts} +5 -5
  221. package/dist/utils/balance.d.cts.map +1 -0
  222. package/dist/utils/balance.d.mts +26 -0
  223. package/dist/utils/balance.d.mts.map +1 -0
  224. package/dist/utils/{balance.js → balance.mjs} +3 -3
  225. package/dist/utils/balance.mjs.map +1 -0
  226. package/dist/utils/batch.cjs +712 -0
  227. package/dist/utils/batch.cjs.map +1 -0
  228. package/dist/utils/{batch.d.ts → batch.d.cts} +8 -8
  229. package/dist/utils/batch.d.cts.map +1 -0
  230. package/dist/utils/batch.d.mts +58 -0
  231. package/dist/utils/batch.d.mts.map +1 -0
  232. package/dist/utils/{batch.js → batch.mjs} +18 -18
  233. package/dist/utils/batch.mjs.map +1 -0
  234. package/dist/utils/eip7702.cjs +354 -0
  235. package/dist/utils/eip7702.cjs.map +1 -0
  236. package/dist/utils/{eip7702.d.ts → eip7702.d.cts} +5 -5
  237. package/dist/utils/eip7702.d.cts.map +1 -0
  238. package/dist/utils/eip7702.d.mts +137 -0
  239. package/dist/utils/eip7702.d.mts.map +1 -0
  240. package/dist/utils/{eip7702.js → eip7702.mjs} +12 -12
  241. package/dist/utils/eip7702.mjs.map +1 -0
  242. package/dist/utils/external-transactions.cjs +36 -0
  243. package/dist/utils/external-transactions.cjs.map +1 -0
  244. package/dist/utils/{external-transactions.d.ts → external-transactions.d.cts} +2 -2
  245. package/dist/utils/external-transactions.d.cts.map +1 -0
  246. package/dist/utils/external-transactions.d.mts +10 -0
  247. package/dist/utils/external-transactions.d.mts.map +1 -0
  248. package/dist/utils/{external-transactions.js → external-transactions.mjs} +3 -3
  249. package/dist/utils/external-transactions.mjs.map +1 -0
  250. package/dist/utils/feature-flags.cjs +255 -0
  251. package/dist/utils/feature-flags.cjs.map +1 -0
  252. package/dist/utils/{feature-flags.d.ts → feature-flags.d.cts} +3 -3
  253. package/dist/utils/feature-flags.d.cts.map +1 -0
  254. package/dist/utils/feature-flags.d.mts +313 -0
  255. package/dist/utils/feature-flags.d.mts.map +1 -0
  256. package/dist/utils/{feature-flags.js → feature-flags.mjs} +5 -5
  257. package/dist/utils/feature-flags.mjs.map +1 -0
  258. package/dist/utils/first-time-interaction.cjs +69 -0
  259. package/dist/utils/first-time-interaction.cjs.map +1 -0
  260. package/dist/utils/{first-time-interaction.d.ts → first-time-interaction.d.cts} +3 -3
  261. package/dist/utils/first-time-interaction.d.cts.map +1 -0
  262. package/dist/utils/first-time-interaction.d.mts +30 -0
  263. package/dist/utils/first-time-interaction.d.mts.map +1 -0
  264. package/dist/utils/{first-time-interaction.js → first-time-interaction.mjs} +6 -6
  265. package/dist/utils/first-time-interaction.mjs.map +1 -0
  266. package/dist/utils/gas-fee-tokens.cjs +174 -0
  267. package/dist/utils/gas-fee-tokens.cjs.map +1 -0
  268. package/dist/utils/{gas-fee-tokens.d.ts → gas-fee-tokens.d.cts} +5 -5
  269. package/dist/utils/gas-fee-tokens.d.cts.map +1 -0
  270. package/dist/utils/gas-fee-tokens.d.mts +46 -0
  271. package/dist/utils/gas-fee-tokens.d.mts.map +1 -0
  272. package/dist/utils/{gas-fee-tokens.js → gas-fee-tokens.mjs} +9 -9
  273. package/dist/utils/gas-fee-tokens.mjs.map +1 -0
  274. package/dist/utils/gas-fees.cjs +424 -0
  275. package/dist/utils/gas-fees.cjs.map +1 -0
  276. package/dist/utils/{gas-fees.d.ts → gas-fees.d.cts} +5 -5
  277. package/dist/utils/gas-fees.d.cts.map +1 -0
  278. package/dist/utils/gas-fees.d.mts +57 -0
  279. package/dist/utils/gas-fees.d.mts.map +1 -0
  280. package/dist/utils/{gas-fees.js → gas-fees.mjs} +9 -9
  281. package/dist/utils/gas-fees.mjs.map +1 -0
  282. package/dist/utils/gas-flow.cjs +81 -0
  283. package/dist/utils/gas-flow.cjs.map +1 -0
  284. package/dist/utils/{gas-flow.d.ts → gas-flow.d.cts} +6 -6
  285. package/dist/utils/gas-flow.d.cts.map +1 -0
  286. package/dist/utils/gas-flow.d.mts +29 -0
  287. package/dist/utils/gas-flow.d.mts.map +1 -0
  288. package/dist/utils/{gas-flow.js → gas-flow.mjs} +3 -3
  289. package/dist/utils/gas-flow.mjs.map +1 -0
  290. package/dist/utils/gas.cjs +545 -0
  291. package/dist/utils/gas.cjs.map +1 -0
  292. package/dist/utils/{gas.d.ts → gas.d.cts} +6 -5
  293. package/dist/utils/gas.d.cts.map +1 -0
  294. package/dist/utils/gas.d.mts +116 -0
  295. package/dist/utils/gas.d.mts.map +1 -0
  296. package/dist/utils/{gas.js → gas.mjs} +11 -11
  297. package/dist/utils/gas.mjs.map +1 -0
  298. package/dist/utils/layer1-gas-fee-flow.cjs +73 -0
  299. package/dist/utils/layer1-gas-fee-flow.cjs.map +1 -0
  300. package/dist/utils/{layer1-gas-fee-flow.d.ts → layer1-gas-fee-flow.d.cts} +4 -4
  301. package/dist/utils/layer1-gas-fee-flow.d.cts.map +1 -0
  302. package/dist/utils/layer1-gas-fee-flow.d.mts +28 -0
  303. package/dist/utils/layer1-gas-fee-flow.d.mts.map +1 -0
  304. package/dist/utils/{layer1-gas-fee-flow.js → layer1-gas-fee-flow.mjs} +3 -3
  305. package/dist/utils/layer1-gas-fee-flow.mjs.map +1 -0
  306. package/dist/utils/nonce.cjs +93 -0
  307. package/dist/utils/nonce.cjs.map +1 -0
  308. package/dist/utils/{nonce.d.ts → nonce.d.cts} +3 -3
  309. package/dist/utils/nonce.d.cts.map +1 -0
  310. package/dist/utils/nonce.d.mts +26 -0
  311. package/dist/utils/nonce.d.mts.map +1 -0
  312. package/dist/utils/{nonce.js → nonce.mjs} +4 -4
  313. package/dist/utils/nonce.mjs.map +1 -0
  314. package/dist/utils/prepare.cjs +97 -0
  315. package/dist/utils/prepare.cjs.map +1 -0
  316. package/dist/utils/{prepare.d.ts → prepare.d.cts} +5 -5
  317. package/dist/utils/prepare.d.cts.map +1 -0
  318. package/dist/utils/prepare.d.mts +22 -0
  319. package/dist/utils/prepare.d.mts.map +1 -0
  320. package/dist/utils/{prepare.js → prepare.mjs} +6 -5
  321. package/dist/utils/prepare.mjs.map +1 -0
  322. package/dist/utils/provider.cjs +106 -0
  323. package/dist/utils/provider.cjs.map +1 -0
  324. package/dist/utils/{provider.d.ts → provider.d.cts} +4 -4
  325. package/dist/utils/provider.d.cts.map +1 -0
  326. package/dist/utils/provider.d.mts +65 -0
  327. package/dist/utils/provider.d.mts.map +1 -0
  328. package/dist/utils/{provider.js → provider.mjs} +3 -3
  329. package/dist/utils/provider.mjs.map +1 -0
  330. package/dist/utils/recipient.cjs +31 -0
  331. package/dist/utils/recipient.cjs.map +1 -0
  332. package/dist/utils/{recipient.d.ts → recipient.d.cts} +2 -2
  333. package/dist/utils/recipient.d.cts.map +1 -0
  334. package/dist/utils/recipient.d.mts +13 -0
  335. package/dist/utils/recipient.d.mts.map +1 -0
  336. package/dist/utils/{recipient.js → recipient.mjs} +3 -3
  337. package/dist/utils/recipient.mjs.map +1 -0
  338. package/dist/utils/retry.cjs +93 -0
  339. package/dist/utils/retry.cjs.map +1 -0
  340. package/dist/utils/{retry.d.ts → retry.d.cts} +2 -2
  341. package/dist/utils/retry.d.cts.map +1 -0
  342. package/dist/utils/retry.d.mts +11 -0
  343. package/dist/utils/retry.d.mts.map +1 -0
  344. package/dist/utils/{retry.js → retry.mjs} +3 -3
  345. package/dist/utils/retry.mjs.map +1 -0
  346. package/dist/utils/revert-reason.cjs +192 -0
  347. package/dist/utils/revert-reason.cjs.map +1 -0
  348. package/dist/utils/{revert-reason.d.ts → revert-reason.d.cts} +5 -5
  349. package/dist/utils/revert-reason.d.cts.map +1 -0
  350. package/dist/utils/revert-reason.d.mts +57 -0
  351. package/dist/utils/revert-reason.d.mts.map +1 -0
  352. package/dist/utils/{revert-reason.js → revert-reason.mjs} +4 -4
  353. package/dist/utils/revert-reason.mjs.map +1 -0
  354. package/dist/utils/signature.cjs +26 -0
  355. package/dist/utils/signature.cjs.map +1 -0
  356. package/dist/utils/{signature.d.ts → signature.d.cts} +2 -2
  357. package/dist/utils/signature.d.cts.map +1 -0
  358. package/dist/utils/signature.d.mts +11 -0
  359. package/dist/utils/signature.d.mts.map +1 -0
  360. package/dist/utils/{signature.js → signature.mjs} +3 -3
  361. package/dist/utils/signature.mjs.map +1 -0
  362. package/dist/utils/swaps.cjs +332 -0
  363. package/dist/utils/swaps.cjs.map +1 -0
  364. package/dist/utils/{swaps.d.ts → swaps.d.cts} +5 -5
  365. package/dist/utils/swaps.d.cts.map +1 -0
  366. package/dist/utils/swaps.d.mts +90 -0
  367. package/dist/utils/swaps.d.mts.map +1 -0
  368. package/dist/utils/{swaps.js → swaps.mjs} +8 -7
  369. package/dist/utils/swaps.mjs.map +1 -0
  370. package/dist/utils/transaction-type.cjs +159 -0
  371. package/dist/utils/transaction-type.cjs.map +1 -0
  372. package/dist/utils/{transaction-type.d.ts → transaction-type.d.cts} +6 -6
  373. package/dist/utils/transaction-type.d.cts.map +1 -0
  374. package/dist/utils/transaction-type.d.mts +44 -0
  375. package/dist/utils/transaction-type.d.mts.map +1 -0
  376. package/dist/utils/{transaction-type.js → transaction-type.mjs} +6 -6
  377. package/dist/utils/transaction-type.mjs.map +1 -0
  378. package/dist/utils/utils.cjs +287 -0
  379. package/dist/utils/utils.cjs.map +1 -0
  380. package/dist/utils/{utils.d.ts → utils.d.cts} +4 -4
  381. package/dist/utils/utils.d.cts.map +1 -0
  382. package/dist/utils/utils.d.mts +101 -0
  383. package/dist/utils/utils.d.mts.map +1 -0
  384. package/dist/utils/{utils.js → utils.mjs} +12 -5
  385. package/dist/utils/utils.mjs.map +1 -0
  386. package/dist/utils/validation.cjs +389 -0
  387. package/dist/utils/validation.cjs.map +1 -0
  388. package/dist/utils/{validation.d.ts → validation.d.cts} +4 -4
  389. package/dist/utils/validation.d.cts.map +1 -0
  390. package/dist/utils/validation.d.mts +66 -0
  391. package/dist/utils/validation.d.mts.map +1 -0
  392. package/dist/utils/{validation.js → validation.mjs} +8 -8
  393. package/dist/utils/validation.mjs.map +1 -0
  394. package/package.json +19 -15
  395. package/dist/TransactionController-method-action-types.d.ts.map +0 -1
  396. package/dist/TransactionController-method-action-types.js.map +0 -1
  397. package/dist/TransactionController.d.ts.map +0 -1
  398. package/dist/TransactionController.js.map +0 -1
  399. package/dist/api/accounts-api.d.ts.map +0 -1
  400. package/dist/api/accounts-api.js.map +0 -1
  401. package/dist/api/simulation-api.d.ts.map +0 -1
  402. package/dist/api/simulation-api.js.map +0 -1
  403. package/dist/constants.d.ts.map +0 -1
  404. package/dist/constants.js.map +0 -1
  405. package/dist/errors.d.ts.map +0 -1
  406. package/dist/errors.js.map +0 -1
  407. package/dist/gas-flows/DefaultGasFeeFlow.d.ts.map +0 -1
  408. package/dist/gas-flows/LineaGasFeeFlow.d.ts.map +0 -1
  409. package/dist/gas-flows/LineaGasFeeFlow.js.map +0 -1
  410. package/dist/gas-flows/MantleLayer1GasFeeFlow.d.ts.map +0 -1
  411. package/dist/gas-flows/MantleLayer1GasFeeFlow.js.map +0 -1
  412. package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.ts.map +0 -1
  413. package/dist/gas-flows/OptimismLayer1GasFeeFlow.js.map +0 -1
  414. package/dist/gas-flows/OracleLayer1GasFeeFlow.d.ts.map +0 -1
  415. package/dist/gas-flows/OracleLayer1GasFeeFlow.js.map +0 -1
  416. package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.d.ts.map +0 -1
  417. package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.js.map +0 -1
  418. package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.ts.map +0 -1
  419. package/dist/gas-flows/ScrollLayer1GasFeeFlow.js.map +0 -1
  420. package/dist/gas-flows/TestGasFeeFlow.d.ts.map +0 -1
  421. package/dist/gas-flows/TestGasFeeFlow.js.map +0 -1
  422. package/dist/helpers/GasFeePoller.d.ts.map +0 -1
  423. package/dist/helpers/GasFeePoller.js.map +0 -1
  424. package/dist/helpers/MethodDataHelper.d.ts.map +0 -1
  425. package/dist/helpers/MethodDataHelper.js.map +0 -1
  426. package/dist/helpers/MultichainTrackingHelper.d.ts.map +0 -1
  427. package/dist/helpers/MultichainTrackingHelper.js.map +0 -1
  428. package/dist/helpers/PendingTransactionTracker.d.ts.map +0 -1
  429. package/dist/helpers/PendingTransactionTracker.js.map +0 -1
  430. package/dist/helpers/ResimulateHelper.d.ts.map +0 -1
  431. package/dist/helpers/ResimulateHelper.js.map +0 -1
  432. package/dist/helpers/TransactionPoller.d.ts.map +0 -1
  433. package/dist/helpers/TransactionPoller.js.map +0 -1
  434. package/dist/hooks/CollectPublishHook.d.ts.map +0 -1
  435. package/dist/hooks/CollectPublishHook.js.map +0 -1
  436. package/dist/hooks/ExtraTransactionsPublishHook.d.ts.map +0 -1
  437. package/dist/hooks/ExtraTransactionsPublishHook.js.map +0 -1
  438. package/dist/hooks/SequentialPublishBatchHook.d.ts.map +0 -1
  439. package/dist/hooks/SequentialPublishBatchHook.js.map +0 -1
  440. package/dist/index.d.ts.map +0 -1
  441. package/dist/index.js +0 -12
  442. package/dist/index.js.map +0 -1
  443. package/dist/logger.d.ts.map +0 -1
  444. package/dist/logger.js.map +0 -1
  445. package/dist/types.d.ts.map +0 -1
  446. package/dist/types.js.map +0 -1
  447. package/dist/utils/balance-changes.d.ts.map +0 -1
  448. package/dist/utils/balance-changes.js.map +0 -1
  449. package/dist/utils/balance.d.ts.map +0 -1
  450. package/dist/utils/balance.js.map +0 -1
  451. package/dist/utils/batch.d.ts.map +0 -1
  452. package/dist/utils/batch.js.map +0 -1
  453. package/dist/utils/eip7702.d.ts.map +0 -1
  454. package/dist/utils/eip7702.js.map +0 -1
  455. package/dist/utils/external-transactions.d.ts.map +0 -1
  456. package/dist/utils/external-transactions.js.map +0 -1
  457. package/dist/utils/feature-flags.d.ts.map +0 -1
  458. package/dist/utils/feature-flags.js.map +0 -1
  459. package/dist/utils/first-time-interaction.d.ts.map +0 -1
  460. package/dist/utils/first-time-interaction.js.map +0 -1
  461. package/dist/utils/gas-fee-tokens.d.ts.map +0 -1
  462. package/dist/utils/gas-fee-tokens.js.map +0 -1
  463. package/dist/utils/gas-fees.d.ts.map +0 -1
  464. package/dist/utils/gas-fees.js.map +0 -1
  465. package/dist/utils/gas-flow.d.ts.map +0 -1
  466. package/dist/utils/gas-flow.js.map +0 -1
  467. package/dist/utils/gas.d.ts.map +0 -1
  468. package/dist/utils/gas.js.map +0 -1
  469. package/dist/utils/layer1-gas-fee-flow.d.ts.map +0 -1
  470. package/dist/utils/layer1-gas-fee-flow.js.map +0 -1
  471. package/dist/utils/nonce.d.ts.map +0 -1
  472. package/dist/utils/nonce.js.map +0 -1
  473. package/dist/utils/prepare.d.ts.map +0 -1
  474. package/dist/utils/prepare.js.map +0 -1
  475. package/dist/utils/provider.d.ts.map +0 -1
  476. package/dist/utils/provider.js.map +0 -1
  477. package/dist/utils/recipient.d.ts.map +0 -1
  478. package/dist/utils/recipient.js.map +0 -1
  479. package/dist/utils/retry.d.ts.map +0 -1
  480. package/dist/utils/retry.js.map +0 -1
  481. package/dist/utils/revert-reason.d.ts.map +0 -1
  482. package/dist/utils/revert-reason.js.map +0 -1
  483. package/dist/utils/signature.d.ts.map +0 -1
  484. package/dist/utils/signature.js.map +0 -1
  485. package/dist/utils/swaps.d.ts.map +0 -1
  486. package/dist/utils/swaps.js.map +0 -1
  487. package/dist/utils/transaction-type.d.ts.map +0 -1
  488. package/dist/utils/transaction-type.js.map +0 -1
  489. package/dist/utils/utils.d.ts.map +0 -1
  490. package/dist/utils/utils.js.map +0 -1
  491. package/dist/utils/validation.d.ts.map +0 -1
  492. package/dist/utils/validation.js.map +0 -1
@@ -0,0 +1,424 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.gweiDecimalToWeiDecimal = exports.gweiDecimalToWeiHex = exports.updateGasFees = void 0;
4
+ const controller_utils_1 = require("@metamask/controller-utils");
5
+ const utils_1 = require("@metamask/utils");
6
+ const logger_js_1 = require("../logger.cjs");
7
+ const types_js_1 = require("../types.cjs");
8
+ const feature_flags_js_1 = require("./feature-flags.cjs");
9
+ const gas_flow_js_1 = require("./gas-flow.cjs");
10
+ const provider_js_1 = require("./provider.cjs");
11
+ const swaps_js_1 = require("./swaps.cjs");
12
+ const log = (0, utils_1.createModuleLogger)(logger_js_1.projectLogger, 'gas-fees');
13
+ const SAVED_GAS_FEES_IGNORED_TRANSACTION_TYPES = [
14
+ ...swaps_js_1.SWAP_TRANSACTION_TYPES,
15
+ types_js_1.TransactionType.bridge,
16
+ types_js_1.TransactionType.bridgeApproval,
17
+ ];
18
+ /**
19
+ * Update the gas fee properties of the provided transaction meta.
20
+ *
21
+ * @param request - The request object.
22
+ */
23
+ async function updateGasFees(request) {
24
+ const { txMeta } = request;
25
+ const initialParams = { ...txMeta.txParams };
26
+ const shouldIgnoreSavedGasFees = SAVED_GAS_FEES_IGNORED_TRANSACTION_TYPES.includes(txMeta.type);
27
+ let savedGasFees = shouldIgnoreSavedGasFees || hasInitialGasFeeParams(initialParams)
28
+ ? undefined
29
+ : request.getSavedGasFees(txMeta);
30
+ const suggestedGasFees = await getSuggestedGasFees({
31
+ ...request,
32
+ savedGasFees,
33
+ });
34
+ log('Suggested gas fees', suggestedGasFees);
35
+ if (shouldIgnoreUnderpricedSavedGasFees(savedGasFees, suggestedGasFees, request)) {
36
+ log('Ignoring saved custom gas fees below low estimate', savedGasFees?.maxBaseFee, suggestedGasFees.low?.maxFeePerGas);
37
+ savedGasFees = undefined;
38
+ }
39
+ const getGasFeeRequest = {
40
+ ...request,
41
+ initialParams,
42
+ savedGasFees,
43
+ suggestedGasFees,
44
+ };
45
+ txMeta.txParams.maxFeePerGas = getMaxFeePerGas(getGasFeeRequest);
46
+ txMeta.txParams.maxPriorityFeePerGas =
47
+ getMaxPriorityFeePerGas(getGasFeeRequest);
48
+ txMeta.txParams.gasPrice = getGasPrice(getGasFeeRequest);
49
+ txMeta.userFeeLevel = getUserFeeLevel(getGasFeeRequest);
50
+ log('Updated gas fee properties', {
51
+ maxFeePerGas: txMeta.txParams.maxFeePerGas,
52
+ maxPriorityFeePerGas: txMeta.txParams.maxPriorityFeePerGas,
53
+ gasPrice: txMeta.txParams.gasPrice,
54
+ });
55
+ if (txMeta.txParams.maxFeePerGas || txMeta.txParams.maxPriorityFeePerGas) {
56
+ delete txMeta.txParams.gasPrice;
57
+ }
58
+ if (txMeta.txParams.gasPrice) {
59
+ delete txMeta.txParams.maxFeePerGas;
60
+ delete txMeta.txParams.maxPriorityFeePerGas;
61
+ }
62
+ updateDefaultGasEstimates(txMeta);
63
+ }
64
+ exports.updateGasFees = updateGasFees;
65
+ /**
66
+ * Convert GWEI from decimal string to WEI as hex string.
67
+ *
68
+ * @param value - The GWEI value as a decimal string.
69
+ * @returns The WEI value in hex.
70
+ */
71
+ function gweiDecimalToWeiHex(value) {
72
+ return (0, controller_utils_1.toHex)((0, controller_utils_1.gweiDecToWEIBN)(value));
73
+ }
74
+ exports.gweiDecimalToWeiHex = gweiDecimalToWeiHex;
75
+ /**
76
+ * Converts a value from Gwei decimal representation to Wei decimal representation
77
+ *
78
+ * @param gweiDecimal - The value in Gwei as a string or number
79
+ * @returns The value in Wei as a string
80
+ *
81
+ * @example
82
+ * // Convert 1.5 Gwei to Wei
83
+ * gweiDecimalToWeiDecimal("1.5")
84
+ * // Returns "1500000000"
85
+ */
86
+ function gweiDecimalToWeiDecimal(gweiDecimal) {
87
+ const weiValue = Number(gweiDecimal) * 1e9;
88
+ return weiValue.toString().split('.')[0];
89
+ }
90
+ exports.gweiDecimalToWeiDecimal = gweiDecimalToWeiDecimal;
91
+ /**
92
+ * Determine whether saved (advanced) gas fee preferences should be ignored in
93
+ * favour of the suggested gas fees, as the saved custom `maxBaseFee` is below
94
+ * the current low estimate and hence unlikely to result in timely inclusion in
95
+ * a block. Level-based saved preferences track current estimates and are never
96
+ * ignored.
97
+ *
98
+ * @param savedGasFees - The saved gas fee preferences.
99
+ * @param suggestedGasFees - The suggested gas fees.
100
+ * @param request - The request object.
101
+ * @returns Whether the saved gas fee preferences should be ignored.
102
+ */
103
+ function shouldIgnoreUnderpricedSavedGasFees(savedGasFees, suggestedGasFees, request) {
104
+ const { eip1559, messenger, txMeta } = request;
105
+ if (!eip1559 ||
106
+ !savedGasFees?.maxBaseFee ||
107
+ !(0, feature_flags_js_1.getReplaceUnderpricedSavedGasFeesEnabled)(txMeta.chainId, messenger)) {
108
+ return false;
109
+ }
110
+ const lowMaxFeePerGas = suggestedGasFees.low?.maxFeePerGas;
111
+ const hasReplacement = Boolean(suggestedGasFees.maxFeePerGas) &&
112
+ Boolean(suggestedGasFees.maxPriorityFeePerGas);
113
+ if (!lowMaxFeePerGas || !hasReplacement) {
114
+ return false;
115
+ }
116
+ return isFeeBelowLowEstimate(gweiDecimalToWeiHex(savedGasFees.maxBaseFee), lowMaxFeePerGas);
117
+ }
118
+ /**
119
+ * Determine whether a fee value is below the low estimate.
120
+ *
121
+ * @param valueHex - The fee value as a hex string.
122
+ * @param lowMaxFeePerGasHex - The low estimate `maxFeePerGas` as a hex string.
123
+ * @returns Whether the fee value is below the low estimate.
124
+ */
125
+ function isFeeBelowLowEstimate(valueHex, lowMaxFeePerGasHex) {
126
+ try {
127
+ return BigInt(valueHex) < BigInt(lowMaxFeePerGasHex);
128
+ }
129
+ catch {
130
+ return false;
131
+ }
132
+ }
133
+ /**
134
+ * Determine whether dapp-suggested gas fees should be ignored in favour of the
135
+ * suggested gas fees, as the dapp-suggested `maxFeePerGas` is below the current
136
+ * low estimate and hence unlikely to result in timely inclusion in a block.
137
+ *
138
+ * @param request - The request object.
139
+ * @returns Whether the dapp-suggested gas fees should be ignored.
140
+ */
141
+ function shouldIgnoreDappGasFees(request) {
142
+ const { eip1559, initialParams, messenger, savedGasFees, suggestedGasFees, txMeta, } = request;
143
+ if (!eip1559 ||
144
+ savedGasFees ||
145
+ txMeta.isInternal ||
146
+ !(0, feature_flags_js_1.getReplaceUnderpricedDappGasFeesEnabled)(txMeta.chainId, messenger)) {
147
+ return false;
148
+ }
149
+ const dappMaxFeePerGas = initialParams.maxFeePerGas ??
150
+ (initialParams.gasPrice && !initialParams.maxPriorityFeePerGas
151
+ ? initialParams.gasPrice
152
+ : undefined);
153
+ const lowMaxFeePerGas = suggestedGasFees.low?.maxFeePerGas;
154
+ const hasReplacement = Boolean(suggestedGasFees.maxFeePerGas) &&
155
+ Boolean(suggestedGasFees.maxPriorityFeePerGas);
156
+ if (!dappMaxFeePerGas || !lowMaxFeePerGas || !hasReplacement) {
157
+ return false;
158
+ }
159
+ return isFeeBelowLowEstimate(dappMaxFeePerGas, lowMaxFeePerGas);
160
+ }
161
+ /**
162
+ * Determine the maxFeePerGas value for the transaction.
163
+ *
164
+ * @param request - The request object.
165
+ * @returns The maxFeePerGas value.
166
+ */
167
+ function getMaxFeePerGas(request) {
168
+ const { savedGasFees, eip1559, initialParams, suggestedGasFees } = request;
169
+ if (!eip1559) {
170
+ return undefined;
171
+ }
172
+ if (savedGasFees?.maxBaseFee) {
173
+ const maxFeePerGas = gweiDecimalToWeiHex(savedGasFees.maxBaseFee);
174
+ log('Using maxFeePerGas from savedGasFees', maxFeePerGas);
175
+ return maxFeePerGas;
176
+ }
177
+ const ignoreDappGasFees = shouldIgnoreDappGasFees(request);
178
+ if (initialParams.maxFeePerGas && !ignoreDappGasFees) {
179
+ log('Using maxFeePerGas from request', initialParams.maxFeePerGas);
180
+ return initialParams.maxFeePerGas;
181
+ }
182
+ if (initialParams.gasPrice &&
183
+ !initialParams.maxPriorityFeePerGas &&
184
+ !ignoreDappGasFees) {
185
+ log('Setting maxFeePerGas to gasPrice from request', initialParams.gasPrice);
186
+ return initialParams.gasPrice;
187
+ }
188
+ if (ignoreDappGasFees) {
189
+ log('Ignoring dapp-suggested maxFeePerGas below low estimate', initialParams.maxFeePerGas ?? initialParams.gasPrice, suggestedGasFees.low?.maxFeePerGas);
190
+ }
191
+ if (suggestedGasFees.maxFeePerGas) {
192
+ log('Using suggested maxFeePerGas', suggestedGasFees.maxFeePerGas);
193
+ return suggestedGasFees.maxFeePerGas;
194
+ }
195
+ if (suggestedGasFees.gasPrice) {
196
+ log('Setting maxFeePerGas to suggested gasPrice', suggestedGasFees.gasPrice);
197
+ return suggestedGasFees.gasPrice;
198
+ }
199
+ log('maxFeePerGas not set');
200
+ return undefined;
201
+ }
202
+ /**
203
+ * Determine the maxPriorityFeePerGas value for the transaction.
204
+ *
205
+ * @param request - The request object.
206
+ * @returns The maxPriorityFeePerGas value.
207
+ */
208
+ function getMaxPriorityFeePerGas(request) {
209
+ const { eip1559, initialParams, savedGasFees, suggestedGasFees, txMeta } = request;
210
+ if (!eip1559) {
211
+ return undefined;
212
+ }
213
+ if (savedGasFees?.priorityFee) {
214
+ const maxPriorityFeePerGas = gweiDecimalToWeiHex(savedGasFees.priorityFee);
215
+ log('Using maxPriorityFeePerGas from savedGasFees.priorityFee', maxPriorityFeePerGas);
216
+ return maxPriorityFeePerGas;
217
+ }
218
+ const ignoreDappGasFees = shouldIgnoreDappGasFees(request);
219
+ if (initialParams.maxPriorityFeePerGas && !ignoreDappGasFees) {
220
+ log('Using maxPriorityFeePerGas from request', initialParams.maxPriorityFeePerGas);
221
+ return initialParams.maxPriorityFeePerGas;
222
+ }
223
+ if (initialParams.gasPrice &&
224
+ !initialParams.maxFeePerGas &&
225
+ !ignoreDappGasFees) {
226
+ log('Setting maxPriorityFeePerGas to gasPrice from request', initialParams.gasPrice);
227
+ return initialParams.gasPrice;
228
+ }
229
+ if (suggestedGasFees.maxPriorityFeePerGas) {
230
+ log('Using suggested maxPriorityFeePerGas', suggestedGasFees.maxPriorityFeePerGas);
231
+ return suggestedGasFees.maxPriorityFeePerGas;
232
+ }
233
+ if (txMeta.txParams.maxFeePerGas) {
234
+ log('Setting maxPriorityFeePerGas to maxFeePerGas', txMeta.txParams.maxFeePerGas);
235
+ return txMeta.txParams.maxFeePerGas;
236
+ }
237
+ log('maxPriorityFeePerGas not set');
238
+ return undefined;
239
+ }
240
+ /**
241
+ * Determine the gasPrice value for the transaction.
242
+ *
243
+ * @param request - The request object.
244
+ * @returns The gasPrice value.
245
+ */
246
+ function getGasPrice(request) {
247
+ const { eip1559, initialParams, savedGasFees, suggestedGasFees } = request;
248
+ if (eip1559) {
249
+ return undefined;
250
+ }
251
+ if (savedGasFees?.gasPrice) {
252
+ const gasPrice = gweiDecimalToWeiHex(savedGasFees.gasPrice);
253
+ log('Using gasPrice from savedGasFees.gasPrice', gasPrice);
254
+ return gasPrice;
255
+ }
256
+ if (initialParams.gasPrice) {
257
+ log('Using gasPrice from request', initialParams.gasPrice);
258
+ return initialParams.gasPrice;
259
+ }
260
+ if (suggestedGasFees.maxFeePerGas) {
261
+ log('Using suggested maxFeePerGas', suggestedGasFees.maxFeePerGas);
262
+ return suggestedGasFees.maxFeePerGas;
263
+ }
264
+ if (suggestedGasFees.gasPrice) {
265
+ log('Using suggested gasPrice', suggestedGasFees.gasPrice);
266
+ return suggestedGasFees.gasPrice;
267
+ }
268
+ log('gasPrice not set');
269
+ return undefined;
270
+ }
271
+ /**
272
+ * Determine the user fee level.
273
+ *
274
+ * @param request - The request object.
275
+ * @returns The user fee level.
276
+ */
277
+ function getUserFeeLevel(request) {
278
+ const { initialParams, savedGasFees, suggestedGasFees, txMeta } = request;
279
+ if (savedGasFees) {
280
+ const hasCustomOverride = savedGasFees.maxBaseFee !== undefined ||
281
+ savedGasFees.priorityFee !== undefined ||
282
+ savedGasFees.gasPrice !== undefined;
283
+ const canUseSavedLevel = !hasCustomOverride &&
284
+ savedGasFees.level !== undefined &&
285
+ suggestedGasFees.isEstimateLevelApplied;
286
+ // A custom override on any field, or an estimate type that does not
287
+ // support per-level pricing (e.g. a flat eth_gasPrice value), means the
288
+ // fee is no longer purely level-derived, so it must not be tracked as a
289
+ // live estimate level by the gas fee poller, which would otherwise
290
+ // overwrite the override or misrepresent the fee as matching the level.
291
+ return canUseSavedLevel ? savedGasFees.level : types_js_1.UserFeeLevel.CUSTOM;
292
+ }
293
+ // Underpriced dapp-suggested fees are replaced with the suggested medium
294
+ // values, so also use the medium fee level to keep the values updated while
295
+ // the transaction is unapproved.
296
+ if (shouldIgnoreDappGasFees(request)) {
297
+ return types_js_1.UserFeeLevel.MEDIUM;
298
+ }
299
+ if (!initialParams.maxFeePerGas &&
300
+ !initialParams.maxPriorityFeePerGas &&
301
+ initialParams.gasPrice) {
302
+ return txMeta.isInternal
303
+ ? types_js_1.UserFeeLevel.CUSTOM
304
+ : types_js_1.UserFeeLevel.DAPP_SUGGESTED;
305
+ }
306
+ if (!initialParams.maxFeePerGas &&
307
+ !initialParams.maxPriorityFeePerGas &&
308
+ suggestedGasFees.maxFeePerGas &&
309
+ suggestedGasFees.maxPriorityFeePerGas) {
310
+ return types_js_1.UserFeeLevel.MEDIUM;
311
+ }
312
+ if (!initialParams.maxFeePerGas &&
313
+ !initialParams.maxPriorityFeePerGas &&
314
+ suggestedGasFees.gasPrice) {
315
+ return types_js_1.UserFeeLevel.MEDIUM;
316
+ }
317
+ if (txMeta.isInternal) {
318
+ return types_js_1.UserFeeLevel.MEDIUM;
319
+ }
320
+ return types_js_1.UserFeeLevel.DAPP_SUGGESTED;
321
+ }
322
+ /**
323
+ * Update the default gas estimates for the provided transaction.
324
+ *
325
+ * @param txMeta - The transaction metadata.
326
+ */
327
+ function updateDefaultGasEstimates(txMeta) {
328
+ txMeta.defaultGasEstimates ?? (txMeta.defaultGasEstimates = {});
329
+ txMeta.defaultGasEstimates.maxFeePerGas = txMeta.txParams.maxFeePerGas;
330
+ txMeta.defaultGasEstimates.maxPriorityFeePerGas =
331
+ txMeta.txParams.maxPriorityFeePerGas;
332
+ txMeta.defaultGasEstimates.gasPrice = txMeta.txParams.gasPrice;
333
+ txMeta.defaultGasEstimates.estimateType = txMeta.userFeeLevel;
334
+ }
335
+ /**
336
+ * Retrieve the suggested gas fees using the gas fee flows.
337
+ *
338
+ * @param request - The request object.
339
+ * @returns The suggested gas fees.
340
+ */
341
+ async function getSuggestedGasFees(request) {
342
+ const { eip1559, gasFeeFlows, getGasFeeEstimates, messenger, savedGasFees, txMeta, } = request;
343
+ const { networkClientId } = txMeta;
344
+ const hasCompleteDappFees = eip1559 &&
345
+ Boolean(txMeta.txParams.maxFeePerGas) &&
346
+ Boolean(txMeta.txParams.maxPriorityFeePerGas);
347
+ // Estimates are still required for transactions with complete dapp-suggested
348
+ // fees if they may be replaced due to being underpriced.
349
+ const isEstimateRequiredForDappFees = hasCompleteDappFees &&
350
+ !txMeta.isInternal &&
351
+ (0, feature_flags_js_1.getReplaceUnderpricedDappGasFeesEnabled)(txMeta.chainId, messenger);
352
+ if ((!eip1559 && txMeta.txParams.gasPrice) ||
353
+ (hasCompleteDappFees && !isEstimateRequiredForDappFees)) {
354
+ return {};
355
+ }
356
+ const gasFeeFlow = (0, gas_flow_js_1.getGasFeeFlow)(txMeta, gasFeeFlows, messenger);
357
+ try {
358
+ const gasFeeControllerData = await getGasFeeEstimates({ networkClientId });
359
+ const response = await gasFeeFlow.getGasFees({
360
+ gasFeeControllerData,
361
+ messenger,
362
+ transactionMeta: txMeta,
363
+ });
364
+ const gasFeeEstimateType = response.estimates?.type;
365
+ const savedGasFeeEstimateLevel = getSavedGasFeeEstimateLevel(savedGasFees);
366
+ switch (gasFeeEstimateType) {
367
+ case types_js_1.GasFeeEstimateType.FeeMarket:
368
+ return {
369
+ ...(response.estimates[savedGasFeeEstimateLevel] ??
370
+ response.estimates.medium),
371
+ isEstimateLevelApplied: true,
372
+ low: response.estimates.low,
373
+ };
374
+ case types_js_1.GasFeeEstimateType.Legacy:
375
+ return {
376
+ gasPrice: response.estimates[savedGasFeeEstimateLevel] ??
377
+ response.estimates.medium,
378
+ isEstimateLevelApplied: true,
379
+ };
380
+ case types_js_1.GasFeeEstimateType.GasPrice:
381
+ return {
382
+ gasPrice: response.estimates.gasPrice,
383
+ isEstimateLevelApplied: false,
384
+ };
385
+ default:
386
+ throw new Error(
387
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
388
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
389
+ `Unsupported gas fee estimate type returned from flow: ${gasFeeEstimateType}`);
390
+ }
391
+ }
392
+ catch (error) {
393
+ log('Failed to get suggested gas fees', error);
394
+ }
395
+ // Estimates on this path are only needed to check complete dapp-suggested
396
+ // fees, so no fallback is required and any failure must not block
397
+ // transaction creation.
398
+ if (hasCompleteDappFees) {
399
+ return {};
400
+ }
401
+ const gasPriceHex = (await (0, provider_js_1.rpcRequest)({
402
+ messenger,
403
+ networkClientId,
404
+ method: 'eth_gasPrice',
405
+ }));
406
+ const gasPrice = gasPriceHex ? (0, utils_1.add0x)(gasPriceHex) : undefined;
407
+ return { gasPrice };
408
+ }
409
+ function hasInitialGasFeeParams(initialParams) {
410
+ return [
411
+ initialParams.maxFeePerGas,
412
+ initialParams.maxPriorityFeePerGas,
413
+ initialParams.gasPrice,
414
+ ].some(Boolean);
415
+ }
416
+ function getSavedGasFeeEstimateLevel(savedGasFees) {
417
+ return isGasFeeEstimateLevel(savedGasFees?.level)
418
+ ? savedGasFees.level
419
+ : types_js_1.GasFeeEstimateLevel.Medium;
420
+ }
421
+ function isGasFeeEstimateLevel(level) {
422
+ return Object.values(types_js_1.GasFeeEstimateLevel).includes(level);
423
+ }
424
+ //# sourceMappingURL=gas-fees.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gas-fees.cjs","sourceRoot":"","sources":["../../src/utils/gas-fees.ts"],"names":[],"mappings":";;;AAAA,iEAAmE;AAMnE,2CAA4D;AAE5D,6CAA6C;AAS7C,2CAKqB;AACrB,0DAG4B;AAC5B,gDAA8C;AAC9C,gDAA2C;AAC3C,0CAAoD;AAqCpD,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,yBAAa,EAAE,UAAU,CAAC,CAAC;AAE1D,MAAM,wCAAwC,GAAG;IAC/C,GAAG,iCAAsB;IACzB,0BAAe,CAAC,MAAM;IACtB,0BAAe,CAAC,cAAc;CAC/B,CAAC;AAEF;;;;GAIG;AACI,KAAK,UAAU,aAAa,CACjC,OAA6B;IAE7B,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC3B,MAAM,aAAa,GAAG,EAAE,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;IAE7C,MAAM,wBAAwB,GAC5B,wCAAwC,CAAC,QAAQ,CAC/C,MAAM,CAAC,IAAuB,CAC/B,CAAC;IAEJ,IAAI,YAAY,GACd,wBAAwB,IAAI,sBAAsB,CAAC,aAAa,CAAC;QAC/D,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;IAEtC,MAAM,gBAAgB,GAAG,MAAM,m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AI,mBAAmB,EAAE,CAAC;QACxB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,WAAW,GAAG,CAAC,MAAM,IAAA,wBAAU,EAAC;QACpC,SAAS;QACT,eAAe;QACf,MAAM,EAAE,cAAc;KACvB,CAAC,CAAoB,CAAC;IAEvB,MAAM,QAAQ,GAAG,WAAW,CAAC,CAAC,CAAC,IAAA,aAAK,EAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAE9D,OAAO,EAAE,QAAQ,EAAE,CAAC;AACtB,CAAC;AAED,SAAS,sBAAsB,CAAC,aAAgC;IAC9D,OAAO;QACL,aAAa,CAAC,YAAY;QAC1B,aAAa,CAAC,oBAAoB;QAClC,aAAa,CAAC,QAAQ;KACvB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAClB,CAAC;AAED,SAAS,2BAA2B,CAClC,YAAsC;IAEtC,OAAO,qBAAqB,CAAC,YAAY,EAAE,KAAK,CAAC;QAC/C,CAAC,CAAC,YAAY,CAAC,KAAK;QACpB,CAAC,CAAC,8BAAmB,CAAC,MAAM,CAAC;AACjC,CAAC;AAED,SAAS,qBAAqB,CAAC,KAAc;IAC3C,OAAO,MAAM,CAAC,MAAM,CAAC,8BAAmB,CAAC,CAAC,QAAQ,CAChD,KAA4B,CAC7B,CAAC;AACJ,CAAC","sourcesContent":["import { gweiDecToWEIBN, toHex } from '@metamask/controller-utils';\nimport type {\n FetchGasFeeEstimateOptions,\n GasFeeState,\n} from '@metamask/gas-fee-controller';\nimport type { Hex } from '@metamask/utils';\nimport { add0x, createModuleLogger } from '@metamask/utils';\n\nimport { projectLogger } from '../logger.js';\nimport type { TransactionControllerMessenger } from '../TransactionController.js';\nimport type {\n FeeMarketGasFeeEstimateForLevel,\n SavedGasFees,\n TransactionParams,\n TransactionMeta,\n GasFeeFlow,\n} from '../types.js';\nimport {\n GasFeeEstimateLevel,\n GasFeeEstimateType,\n TransactionType,\n UserFeeLevel,\n} from '../types.js';\nimport {\n getReplaceUnderpricedDappGasFeesEnabled,\n getReplaceUnderpricedSavedGasFeesEnabled,\n} from './feature-flags.js';\nimport { getGasFeeFlow } from './gas-flow.js';\nimport { rpcRequest } from './provider.js';\nimport { SWAP_TRANSACTION_TYPES } from './swaps.js';\n\nexport type UpdateGasFeesRequest = {\n eip1559: boolean;\n gasFeeFlows: GasFeeFlow[];\n getGasFeeEstimates: (\n options: FetchGasFeeEstimateOptions,\n ) => Promise<GasFeeState>;\n getSavedGasFees: (\n transactionMeta: TransactionMeta,\n ) => SavedGasFees | undefined;\n messenger: TransactionControllerMessenger;\n txMeta: TransactionMeta;\n};\n\nexport type GetGasFeeRequest = UpdateGasFeesRequest & {\n initialParams: TransactionParams;\n savedGasFees?: SavedGasFees;\n suggestedGasFees: SuggestedGasFees;\n};\n\ntype SuggestedGasFees = {\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n gasPrice?: string;\n\n /**\n * Whether the suggested fee was derived from a specific estimate level,\n * such as `low`/`medium`/`high`. This is `false` for estimate types that\n * do not support per-level pricing, such as a flat `eth_gasPrice` value,\n * or when the gas fee flow failed and a raw RPC fallback was used.\n */\n isEstimateLevelApplied?: boolean;\n\n low?: FeeMarketGasFeeEstimateForLevel;\n};\n\nconst log = createModuleLogger(projectLogger, 'gas-fees');\n\nconst SAVED_GAS_FEES_IGNORED_TRANSACTION_TYPES = [\n ...SWAP_TRANSACTION_TYPES,\n TransactionType.bridge,\n TransactionType.bridgeApproval,\n];\n\n/**\n * Update the gas fee properties of the provided transaction meta.\n *\n * @param request - The request object.\n */\nexport async function updateGasFees(\n request: UpdateGasFeesRequest,\n): Promise<void> {\n const { txMeta } = request;\n const initialParams = { ...txMeta.txParams };\n\n const shouldIgnoreSavedGasFees =\n SAVED_GAS_FEES_IGNORED_TRANSACTION_TYPES.includes(\n txMeta.type as TransactionType,\n );\n\n let savedGasFees =\n shouldIgnoreSavedGasFees || hasInitialGasFeeParams(initialParams)\n ? undefined\n : request.getSavedGasFees(txMeta);\n\n const suggestedGasFees = await getSuggestedGasFees({\n ...request,\n savedGasFees,\n });\n\n log('Suggested gas fees', suggestedGasFees);\n\n if (\n shouldIgnoreUnderpricedSavedGasFees(savedGasFees, suggestedGasFees, request)\n ) {\n log(\n 'Ignoring saved custom gas fees below low estimate',\n savedGasFees?.maxBaseFee,\n suggestedGasFees.low?.maxFeePerGas,\n );\n savedGasFees = undefined;\n }\n\n const getGasFeeRequest: GetGasFeeRequest = {\n ...request,\n initialParams,\n savedGasFees,\n suggestedGasFees,\n };\n\n txMeta.txParams.maxFeePerGas = getMaxFeePerGas(getGasFeeRequest);\n\n txMeta.txParams.maxPriorityFeePerGas =\n getMaxPriorityFeePerGas(getGasFeeRequest);\n\n txMeta.txParams.gasPrice = getGasPrice(getGasFeeRequest);\n txMeta.userFeeLevel = getUserFeeLevel(getGasFeeRequest);\n\n log('Updated gas fee properties', {\n maxFeePerGas: txMeta.txParams.maxFeePerGas,\n maxPriorityFeePerGas: txMeta.txParams.maxPriorityFeePerGas,\n gasPrice: txMeta.txParams.gasPrice,\n });\n\n if (txMeta.txParams.maxFeePerGas || txMeta.txParams.maxPriorityFeePerGas) {\n delete txMeta.txParams.gasPrice;\n }\n\n if (txMeta.txParams.gasPrice) {\n delete txMeta.txParams.maxFeePerGas;\n delete txMeta.txParams.maxPriorityFeePerGas;\n }\n\n updateDefaultGasEstimates(txMeta);\n}\n\n/**\n * Convert GWEI from decimal string to WEI as hex string.\n *\n * @param value - The GWEI value as a decimal string.\n * @returns The WEI value in hex.\n */\nexport function gweiDecimalToWeiHex(value: string): Hex {\n return toHex(gweiDecToWEIBN(value));\n}\n\n/**\n * Converts a value from Gwei decimal representation to Wei decimal representation\n *\n * @param gweiDecimal - The value in Gwei as a string or number\n * @returns The value in Wei as a string\n *\n * @example\n * // Convert 1.5 Gwei to Wei\n * gweiDecimalToWeiDecimal(\"1.5\")\n * // Returns \"1500000000\"\n */\nexport function gweiDecimalToWeiDecimal(gweiDecimal: string | number): string {\n const weiValue = Number(gweiDecimal) * 1e9;\n\n return weiValue.toString().split('.')[0];\n}\n\n/**\n * Determine whether saved (advanced) gas fee preferences should be ignored in\n * favour of the suggested gas fees, as the saved custom `maxBaseFee` is below\n * the current low estimate and hence unlikely to result in timely inclusion in\n * a block. Level-based saved preferences track current estimates and are never\n * ignored.\n *\n * @param savedGasFees - The saved gas fee preferences.\n * @param suggestedGasFees - The suggested gas fees.\n * @param request - The request object.\n * @returns Whether the saved gas fee preferences should be ignored.\n */\nfunction shouldIgnoreUnderpricedSavedGasFees(\n savedGasFees: SavedGasFees | undefined,\n suggestedGasFees: SuggestedGasFees,\n request: UpdateGasFeesRequest,\n): boolean {\n const { eip1559, messenger, txMeta } = request;\n\n if (\n !eip1559 ||\n !savedGasFees?.maxBaseFee ||\n !getReplaceUnderpricedSavedGasFeesEnabled(txMeta.chainId, messenger)\n ) {\n return false;\n }\n\n const lowMaxFeePerGas = suggestedGasFees.low?.maxFeePerGas;\n\n const hasReplacement =\n Boolean(suggestedGasFees.maxFeePerGas) &&\n Boolean(suggestedGasFees.maxPriorityFeePerGas);\n\n if (!lowMaxFeePerGas || !hasReplacement) {\n return false;\n }\n\n return isFeeBelowLowEstimate(\n gweiDecimalToWeiHex(savedGasFees.maxBaseFee),\n lowMaxFeePerGas,\n );\n}\n\n/**\n * Determine whether a fee value is below the low estimate.\n *\n * @param valueHex - The fee value as a hex string.\n * @param lowMaxFeePerGasHex - The low estimate `maxFeePerGas` as a hex string.\n * @returns Whether the fee value is below the low estimate.\n */\nfunction isFeeBelowLowEstimate(\n valueHex: string,\n lowMaxFeePerGasHex: string,\n): boolean {\n try {\n return BigInt(valueHex) < BigInt(lowMaxFeePerGasHex);\n } catch {\n return false;\n }\n}\n\n/**\n * Determine whether dapp-suggested gas fees should be ignored in favour of the\n * suggested gas fees, as the dapp-suggested `maxFeePerGas` is below the current\n * low estimate and hence unlikely to result in timely inclusion in a block.\n *\n * @param request - The request object.\n * @returns Whether the dapp-suggested gas fees should be ignored.\n */\nfunction shouldIgnoreDappGasFees(request: GetGasFeeRequest): boolean {\n const {\n eip1559,\n initialParams,\n messenger,\n savedGasFees,\n suggestedGasFees,\n txMeta,\n } = request;\n\n if (\n !eip1559 ||\n savedGasFees ||\n txMeta.isInternal ||\n !getReplaceUnderpricedDappGasFeesEnabled(txMeta.chainId, messenger)\n ) {\n return false;\n }\n\n const dappMaxFeePerGas =\n initialParams.maxFeePerGas ??\n (initialParams.gasPrice && !initialParams.maxPriorityFeePerGas\n ? initialParams.gasPrice\n : undefined);\n\n const lowMaxFeePerGas = suggestedGasFees.low?.maxFeePerGas;\n\n const hasReplacement =\n Boolean(suggestedGasFees.maxFeePerGas) &&\n Boolean(suggestedGasFees.maxPriorityFeePerGas);\n\n if (!dappMaxFeePerGas || !lowMaxFeePerGas || !hasReplacement) {\n return false;\n }\n\n return isFeeBelowLowEstimate(dappMaxFeePerGas, lowMaxFeePerGas);\n}\n\n/**\n * Determine the maxFeePerGas value for the transaction.\n *\n * @param request - The request object.\n * @returns The maxFeePerGas value.\n */\nfunction getMaxFeePerGas(request: GetGasFeeRequest): string | undefined {\n const { savedGasFees, eip1559, initialParams, suggestedGasFees } = request;\n\n if (!eip1559) {\n return undefined;\n }\n\n if (savedGasFees?.maxBaseFee) {\n const maxFeePerGas = gweiDecimalToWeiHex(savedGasFees.maxBaseFee);\n log('Using maxFeePerGas from savedGasFees', maxFeePerGas);\n return maxFeePerGas;\n }\n\n const ignoreDappGasFees = shouldIgnoreDappGasFees(request);\n\n if (initialParams.maxFeePerGas && !ignoreDappGasFees) {\n log('Using maxFeePerGas from request', initialParams.maxFeePerGas);\n return initialParams.maxFeePerGas;\n }\n\n if (\n initialParams.gasPrice &&\n !initialParams.maxPriorityFeePerGas &&\n !ignoreDappGasFees\n ) {\n log(\n 'Setting maxFeePerGas to gasPrice from request',\n initialParams.gasPrice,\n );\n return initialParams.gasPrice;\n }\n\n if (ignoreDappGasFees) {\n log(\n 'Ignoring dapp-suggested maxFeePerGas below low estimate',\n initialParams.maxFeePerGas ?? initialParams.gasPrice,\n suggestedGasFees.low?.maxFeePerGas,\n );\n }\n\n if (suggestedGasFees.maxFeePerGas) {\n log('Using suggested maxFeePerGas', suggestedGasFees.maxFeePerGas);\n return suggestedGasFees.maxFeePerGas;\n }\n\n if (suggestedGasFees.gasPrice) {\n log(\n 'Setting maxFeePerGas to suggested gasPrice',\n suggestedGasFees.gasPrice,\n );\n return suggestedGasFees.gasPrice;\n }\n\n log('maxFeePerGas not set');\n return undefined;\n}\n\n/**\n * Determine the maxPriorityFeePerGas value for the transaction.\n *\n * @param request - The request object.\n * @returns The maxPriorityFeePerGas value.\n */\nfunction getMaxPriorityFeePerGas(\n request: GetGasFeeRequest,\n): string | undefined {\n const { eip1559, initialParams, savedGasFees, suggestedGasFees, txMeta } =\n request;\n\n if (!eip1559) {\n return undefined;\n }\n\n if (savedGasFees?.priorityFee) {\n const maxPriorityFeePerGas = gweiDecimalToWeiHex(savedGasFees.priorityFee);\n log(\n 'Using maxPriorityFeePerGas from savedGasFees.priorityFee',\n maxPriorityFeePerGas,\n );\n return maxPriorityFeePerGas;\n }\n\n const ignoreDappGasFees = shouldIgnoreDappGasFees(request);\n\n if (initialParams.maxPriorityFeePerGas && !ignoreDappGasFees) {\n log(\n 'Using maxPriorityFeePerGas from request',\n initialParams.maxPriorityFeePerGas,\n );\n return initialParams.maxPriorityFeePerGas;\n }\n\n if (\n initialParams.gasPrice &&\n !initialParams.maxFeePerGas &&\n !ignoreDappGasFees\n ) {\n log(\n 'Setting maxPriorityFeePerGas to gasPrice from request',\n initialParams.gasPrice,\n );\n return initialParams.gasPrice;\n }\n\n if (suggestedGasFees.maxPriorityFeePerGas) {\n log(\n 'Using suggested maxPriorityFeePerGas',\n suggestedGasFees.maxPriorityFeePerGas,\n );\n return suggestedGasFees.maxPriorityFeePerGas;\n }\n\n if (txMeta.txParams.maxFeePerGas) {\n log(\n 'Setting maxPriorityFeePerGas to maxFeePerGas',\n txMeta.txParams.maxFeePerGas,\n );\n return txMeta.txParams.maxFeePerGas;\n }\n\n log('maxPriorityFeePerGas not set');\n return undefined;\n}\n\n/**\n * Determine the gasPrice value for the transaction.\n *\n * @param request - The request object.\n * @returns The gasPrice value.\n */\nfunction getGasPrice(request: GetGasFeeRequest): string | undefined {\n const { eip1559, initialParams, savedGasFees, suggestedGasFees } = request;\n\n if (eip1559) {\n return undefined;\n }\n\n if (savedGasFees?.gasPrice) {\n const gasPrice = gweiDecimalToWeiHex(savedGasFees.gasPrice);\n log('Using gasPrice from savedGasFees.gasPrice', gasPrice);\n return gasPrice;\n }\n\n if (initialParams.gasPrice) {\n log('Using gasPrice from request', initialParams.gasPrice);\n return initialParams.gasPrice;\n }\n\n if (suggestedGasFees.maxFeePerGas) {\n log('Using suggested maxFeePerGas', suggestedGasFees.maxFeePerGas);\n return suggestedGasFees.maxFeePerGas;\n }\n\n if (suggestedGasFees.gasPrice) {\n log('Using suggested gasPrice', suggestedGasFees.gasPrice);\n return suggestedGasFees.gasPrice;\n }\n\n log('gasPrice not set');\n return undefined;\n}\n\n/**\n * Determine the user fee level.\n *\n * @param request - The request object.\n * @returns The user fee level.\n */\nfunction getUserFeeLevel(request: GetGasFeeRequest): string | undefined {\n const { initialParams, savedGasFees, suggestedGasFees, txMeta } = request;\n\n if (savedGasFees) {\n const hasCustomOverride =\n savedGasFees.maxBaseFee !== undefined ||\n savedGasFees.priorityFee !== undefined ||\n savedGasFees.gasPrice !== undefined;\n\n const canUseSavedLevel =\n !hasCustomOverride &&\n savedGasFees.level !== undefined &&\n suggestedGasFees.isEstimateLevelApplied;\n\n // A custom override on any field, or an estimate type that does not\n // support per-level pricing (e.g. a flat eth_gasPrice value), means the\n // fee is no longer purely level-derived, so it must not be tracked as a\n // live estimate level by the gas fee poller, which would otherwise\n // overwrite the override or misrepresent the fee as matching the level.\n return canUseSavedLevel ? savedGasFees.level : UserFeeLevel.CUSTOM;\n }\n\n // Underpriced dapp-suggested fees are replaced with the suggested medium\n // values, so also use the medium fee level to keep the values updated while\n // the transaction is unapproved.\n if (shouldIgnoreDappGasFees(request)) {\n return UserFeeLevel.MEDIUM;\n }\n\n if (\n !initialParams.maxFeePerGas &&\n !initialParams.maxPriorityFeePerGas &&\n initialParams.gasPrice\n ) {\n return txMeta.isInternal\n ? UserFeeLevel.CUSTOM\n : UserFeeLevel.DAPP_SUGGESTED;\n }\n\n if (\n !initialParams.maxFeePerGas &&\n !initialParams.maxPriorityFeePerGas &&\n suggestedGasFees.maxFeePerGas &&\n suggestedGasFees.maxPriorityFeePerGas\n ) {\n return UserFeeLevel.MEDIUM;\n }\n\n if (\n !initialParams.maxFeePerGas &&\n !initialParams.maxPriorityFeePerGas &&\n suggestedGasFees.gasPrice\n ) {\n return UserFeeLevel.MEDIUM;\n }\n\n if (txMeta.isInternal) {\n return UserFeeLevel.MEDIUM;\n }\n\n return UserFeeLevel.DAPP_SUGGESTED;\n}\n\n/**\n * Update the default gas estimates for the provided transaction.\n *\n * @param txMeta - The transaction metadata.\n */\nfunction updateDefaultGasEstimates(txMeta: TransactionMeta): void {\n txMeta.defaultGasEstimates ??= {};\n txMeta.defaultGasEstimates.maxFeePerGas = txMeta.txParams.maxFeePerGas;\n\n txMeta.defaultGasEstimates.maxPriorityFeePerGas =\n txMeta.txParams.maxPriorityFeePerGas;\n\n txMeta.defaultGasEstimates.gasPrice = txMeta.txParams.gasPrice;\n txMeta.defaultGasEstimates.estimateType = txMeta.userFeeLevel;\n}\n\n/**\n * Retrieve the suggested gas fees using the gas fee flows.\n *\n * @param request - The request object.\n * @returns The suggested gas fees.\n */\nasync function getSuggestedGasFees(\n request: UpdateGasFeesRequest & { savedGasFees?: SavedGasFees },\n): Promise<SuggestedGasFees> {\n const {\n eip1559,\n gasFeeFlows,\n getGasFeeEstimates,\n messenger,\n savedGasFees,\n txMeta,\n } = request;\n const { networkClientId } = txMeta;\n\n const hasCompleteDappFees =\n eip1559 &&\n Boolean(txMeta.txParams.maxFeePerGas) &&\n Boolean(txMeta.txParams.maxPriorityFeePerGas);\n\n // Estimates are still required for transactions with complete dapp-suggested\n // fees if they may be replaced due to being underpriced.\n const isEstimateRequiredForDappFees =\n hasCompleteDappFees &&\n !txMeta.isInternal &&\n getReplaceUnderpricedDappGasFeesEnabled(txMeta.chainId, messenger);\n\n if (\n (!eip1559 && txMeta.txParams.gasPrice) ||\n (hasCompleteDappFees && !isEstimateRequiredForDappFees)\n ) {\n return {};\n }\n\n const gasFeeFlow = getGasFeeFlow(\n txMeta,\n gasFeeFlows,\n messenger,\n ) as GasFeeFlow;\n\n try {\n const gasFeeControllerData = await getGasFeeEstimates({ networkClientId });\n\n const response = await gasFeeFlow.getGasFees({\n gasFeeControllerData,\n messenger,\n transactionMeta: txMeta,\n });\n\n const gasFeeEstimateType = response.estimates?.type;\n const savedGasFeeEstimateLevel = getSavedGasFeeEstimateLevel(savedGasFees);\n\n switch (gasFeeEstimateType) {\n case GasFeeEstimateType.FeeMarket:\n return {\n ...(response.estimates[savedGasFeeEstimateLevel] ??\n response.estimates.medium),\n isEstimateLevelApplied: true,\n low: response.estimates.low,\n };\n case GasFeeEstimateType.Legacy:\n return {\n gasPrice:\n response.estimates[savedGasFeeEstimateLevel] ??\n response.estimates.medium,\n isEstimateLevelApplied: true,\n };\n case GasFeeEstimateType.GasPrice:\n return {\n gasPrice: response.estimates.gasPrice,\n isEstimateLevelApplied: false,\n };\n default:\n throw new Error(\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n `Unsupported gas fee estimate type returned from flow: ${gasFeeEstimateType}`,\n );\n }\n } catch (error) {\n log('Failed to get suggested gas fees', error);\n }\n\n // Estimates on this path are only needed to check complete dapp-suggested\n // fees, so no fallback is required and any failure must not block\n // transaction creation.\n if (hasCompleteDappFees) {\n return {};\n }\n\n const gasPriceHex = (await rpcRequest({\n messenger,\n networkClientId,\n method: 'eth_gasPrice',\n })) as Hex | undefined;\n\n const gasPrice = gasPriceHex ? add0x(gasPriceHex) : undefined;\n\n return { gasPrice };\n}\n\nfunction hasInitialGasFeeParams(initialParams: TransactionParams): boolean {\n return [\n initialParams.maxFeePerGas,\n initialParams.maxPriorityFeePerGas,\n initialParams.gasPrice,\n ].some(Boolean);\n}\n\nfunction getSavedGasFeeEstimateLevel(\n savedGasFees: SavedGasFees | undefined,\n): GasFeeEstimateLevel {\n return isGasFeeEstimateLevel(savedGasFees?.level)\n ? savedGasFees.level\n : GasFeeEstimateLevel.Medium;\n}\n\nfunction isGasFeeEstimateLevel(level: unknown): level is GasFeeEstimateLevel {\n return Object.values(GasFeeEstimateLevel).includes(\n level as GasFeeEstimateLevel,\n );\n}\n"]}
@@ -1,7 +1,7 @@
1
- import type { FetchGasFeeEstimateOptions, GasFeeState } from '@metamask/gas-fee-controller';
2
- import type { Hex } from '@metamask/utils';
3
- import type { TransactionControllerMessenger } from '../TransactionController.js';
4
- import type { FeeMarketGasFeeEstimateForLevel, SavedGasFees, TransactionParams, TransactionMeta, GasFeeFlow } from '../types.js';
1
+ import type { FetchGasFeeEstimateOptions, GasFeeState } from "@metamask/gas-fee-controller";
2
+ import type { Hex } from "@metamask/utils";
3
+ import type { TransactionControllerMessenger } from "../TransactionController.cjs";
4
+ import type { FeeMarketGasFeeEstimateForLevel, SavedGasFees, TransactionParams, TransactionMeta, GasFeeFlow } from "../types.cjs";
5
5
  export type UpdateGasFeesRequest = {
6
6
  eip1559: boolean;
7
7
  gasFeeFlows: GasFeeFlow[];
@@ -54,4 +54,4 @@ export declare function gweiDecimalToWeiHex(value: string): Hex;
54
54
  */
55
55
  export declare function gweiDecimalToWeiDecimal(gweiDecimal: string | number): string;
56
56
  export {};
57
- //# sourceMappingURL=gas-fees.d.ts.map
57
+ //# sourceMappingURL=gas-fees.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gas-fees.d.cts","sourceRoot":"","sources":["../../src/utils/gas-fees.ts"],"names":[],"mappings":"AACA,OAAO,KAAK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GAAG,MAAM,CAI5E"}
@@ -0,0 +1,57 @@
1
+ import type { FetchGasFeeEstimateOptions, GasFeeState } from "@metamask/gas-fee-controller";
2
+ import type { Hex } from "@metamask/utils";
3
+ import type { TransactionControllerMessenger } from "../TransactionController.mjs";
4
+ import type { FeeMarketGasFeeEstimateForLevel, SavedGasFees, TransactionParams, TransactionMeta, GasFeeFlow } from "../types.mjs";
5
+ export type UpdateGasFeesRequest = {
6
+ eip1559: boolean;
7
+ gasFeeFlows: GasFeeFlow[];
8
+ getGasFeeEstimates: (options: FetchGasFeeEstimateOptions) => Promise<GasFeeState>;
9
+ getSavedGasFees: (transactionMeta: TransactionMeta) => SavedGasFees | undefined;
10
+ messenger: TransactionControllerMessenger;
11
+ txMeta: TransactionMeta;
12
+ };
13
+ export type GetGasFeeRequest = UpdateGasFeesRequest & {
14
+ initialParams: TransactionParams;
15
+ savedGasFees?: SavedGasFees;
16
+ suggestedGasFees: SuggestedGasFees;
17
+ };
18
+ type SuggestedGasFees = {
19
+ maxFeePerGas?: string;
20
+ maxPriorityFeePerGas?: string;
21
+ gasPrice?: string;
22
+ /**
23
+ * Whether the suggested fee was derived from a specific estimate level,
24
+ * such as `low`/`medium`/`high`. This is `false` for estimate types that
25
+ * do not support per-level pricing, such as a flat `eth_gasPrice` value,
26
+ * or when the gas fee flow failed and a raw RPC fallback was used.
27
+ */
28
+ isEstimateLevelApplied?: boolean;
29
+ low?: FeeMarketGasFeeEstimateForLevel;
30
+ };
31
+ /**
32
+ * Update the gas fee properties of the provided transaction meta.
33
+ *
34
+ * @param request - The request object.
35
+ */
36
+ export declare function updateGasFees(request: UpdateGasFeesRequest): Promise<void>;
37
+ /**
38
+ * Convert GWEI from decimal string to WEI as hex string.
39
+ *
40
+ * @param value - The GWEI value as a decimal string.
41
+ * @returns The WEI value in hex.
42
+ */
43
+ export declare function gweiDecimalToWeiHex(value: string): Hex;
44
+ /**
45
+ * Converts a value from Gwei decimal representation to Wei decimal representation
46
+ *
47
+ * @param gweiDecimal - The value in Gwei as a string or number
48
+ * @returns The value in Wei as a string
49
+ *
50
+ * @example
51
+ * // Convert 1.5 Gwei to Wei
52
+ * gweiDecimalToWeiDecimal("1.5")
53
+ * // Returns "1500000000"
54
+ */
55
+ export declare function gweiDecimalToWeiDecimal(gweiDecimal: string | number): string;
56
+ export {};
57
+ //# sourceMappingURL=gas-fees.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gas-fees.d.mts","sourceRoot":"","sources":["../../src/utils/gas-fees.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,0BAA0B,EAC1B,WAAW,EACZ,qCAAqC;AACtC,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAI3C,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAoC;AAClF,OAAO,KAAK,EACV,+BAA+B,EAC/B,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,UAAU,EACX,qBAAoB;AAerB,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,kBAAkB,EAAE,CAClB,OAAO,EAAE,0BAA0B,KAChC,OAAO,CAAC,WAAW,CAAC,CAAC;IAC1B,eAAe,EAAE,CACf,eAAe,EAAE,eAAe,KAC7B,YAAY,GAAG,SAAS,CAAC;IAC9B,SAAS,EAAE,8BAA8B,CAAC;IAC1C,MAAM,EAAE,eAAe,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,oBAAoB,GAAG;IACpD,aAAa,EAAE,iBAAiB,CAAC;IACjC,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,gBAAgB,EAAE,gBAAgB,CAAC;CACpC,CAAC;AAEF,KAAK,gBAAgB,GAAG;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;;;OAKG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;IAEjC,GAAG,CAAC,EAAE,+BAA+B,CAAC;CACvC,CAAC;AAUF;;;;GAIG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,IAAI,CAAC,CA+Df;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,CAEtD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAI5E"}
@@ -1,11 +1,11 @@
1
- import { gweiDecToWEIBN, toHex } from '@metamask/controller-utils';
2
- import { add0x, createModuleLogger } from '@metamask/utils';
3
- import { projectLogger } from '../logger.js';
4
- import { GasFeeEstimateLevel, GasFeeEstimateType, TransactionType, UserFeeLevel, } from '../types.js';
5
- import { getReplaceUnderpricedDappGasFeesEnabled, getReplaceUnderpricedSavedGasFeesEnabled, } from './feature-flags.js';
6
- import { getGasFeeFlow } from './gas-flow.js';
7
- import { rpcRequest } from './provider.js';
8
- import { SWAP_TRANSACTION_TYPES } from './swaps.js';
1
+ import { gweiDecToWEIBN, toHex } from "@metamask/controller-utils";
2
+ import { add0x, createModuleLogger } from "@metamask/utils";
3
+ import { projectLogger } from "../logger.mjs";
4
+ import { GasFeeEstimateLevel, GasFeeEstimateType, TransactionType, UserFeeLevel } from "../types.mjs";
5
+ import { getReplaceUnderpricedDappGasFeesEnabled, getReplaceUnderpricedSavedGasFeesEnabled } from "./feature-flags.mjs";
6
+ import { getGasFeeFlow } from "./gas-flow.mjs";
7
+ import { rpcRequest } from "./provider.mjs";
8
+ import { SWAP_TRANSACTION_TYPES } from "./swaps.mjs";
9
9
  const log = createModuleLogger(projectLogger, 'gas-fees');
10
10
  const SAVED_GAS_FEES_IGNORED_TRANSACTION_TYPES = [
11
11
  ...SWAP_TRANSACTION_TYPES,
@@ -415,4 +415,4 @@ function getSavedGasFeeEstimateLevel(savedGasFees) {
415
415
  function isGasFeeEstimateLevel(level) {
416
416
  return Object.values(GasFeeEstimateLevel).includes(level);
417
417
  }
418
- //# sourceMappingURL=gas-fees.js.map
418
+ //# sourceMappingURL=gas-fees.mjs.map