@metamask/transaction-controller 46.0.0 → 47.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 (196) hide show
  1. package/CHANGELOG.md +31 -1
  2. package/dist/TransactionController.cjs +121 -40
  3. package/dist/TransactionController.cjs.map +1 -1
  4. package/dist/TransactionController.d.cts +81 -72
  5. package/dist/TransactionController.d.cts.map +1 -1
  6. package/dist/TransactionController.d.mts +81 -72
  7. package/dist/TransactionController.d.mts.map +1 -1
  8. package/dist/TransactionController.mjs +122 -41
  9. package/dist/TransactionController.mjs.map +1 -1
  10. package/dist/api/accounts-api.cjs +2 -0
  11. package/dist/api/accounts-api.cjs.map +1 -1
  12. package/dist/api/accounts-api.d.cts +2 -0
  13. package/dist/api/accounts-api.d.cts.map +1 -1
  14. package/dist/api/accounts-api.d.mts +2 -0
  15. package/dist/api/accounts-api.d.mts.map +1 -1
  16. package/dist/api/accounts-api.mjs +2 -0
  17. package/dist/api/accounts-api.mjs.map +1 -1
  18. package/dist/constants.cjs +20 -1
  19. package/dist/constants.cjs.map +1 -1
  20. package/dist/constants.d.cts +15 -0
  21. package/dist/constants.d.cts.map +1 -1
  22. package/dist/constants.d.mts +15 -0
  23. package/dist/constants.d.mts.map +1 -1
  24. package/dist/constants.mjs +19 -0
  25. package/dist/constants.mjs.map +1 -1
  26. package/dist/gas-flows/LineaGasFeeFlow.cjs +1 -1
  27. package/dist/gas-flows/LineaGasFeeFlow.cjs.map +1 -1
  28. package/dist/gas-flows/LineaGasFeeFlow.d.cts.map +1 -1
  29. package/dist/gas-flows/LineaGasFeeFlow.d.mts.map +1 -1
  30. package/dist/gas-flows/LineaGasFeeFlow.mjs +1 -1
  31. package/dist/gas-flows/LineaGasFeeFlow.mjs.map +1 -1
  32. package/dist/gas-flows/OptimismLayer1GasFeeFlow.cjs +1 -1
  33. package/dist/gas-flows/OptimismLayer1GasFeeFlow.cjs.map +1 -1
  34. package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.cts +1 -1
  35. package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.cts.map +1 -1
  36. package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.mts +1 -1
  37. package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.mts.map +1 -1
  38. package/dist/gas-flows/OptimismLayer1GasFeeFlow.mjs +1 -1
  39. package/dist/gas-flows/OptimismLayer1GasFeeFlow.mjs.map +1 -1
  40. package/dist/gas-flows/ScrollLayer1GasFeeFlow.cjs +1 -1
  41. package/dist/gas-flows/ScrollLayer1GasFeeFlow.cjs.map +1 -1
  42. package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.cts +1 -1
  43. package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.cts.map +1 -1
  44. package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.mts +1 -1
  45. package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.mts.map +1 -1
  46. package/dist/gas-flows/ScrollLayer1GasFeeFlow.mjs +1 -1
  47. package/dist/gas-flows/ScrollLayer1GasFeeFlow.mjs.map +1 -1
  48. package/dist/helpers/GasFeePoller.cjs +1 -0
  49. package/dist/helpers/GasFeePoller.cjs.map +1 -1
  50. package/dist/helpers/GasFeePoller.d.cts +1 -0
  51. package/dist/helpers/GasFeePoller.d.cts.map +1 -1
  52. package/dist/helpers/GasFeePoller.d.mts +1 -0
  53. package/dist/helpers/GasFeePoller.d.mts.map +1 -1
  54. package/dist/helpers/GasFeePoller.mjs +1 -0
  55. package/dist/helpers/GasFeePoller.mjs.map +1 -1
  56. package/dist/helpers/IncomingTransactionHelper.cjs.map +1 -1
  57. package/dist/helpers/IncomingTransactionHelper.d.cts.map +1 -1
  58. package/dist/helpers/IncomingTransactionHelper.d.mts.map +1 -1
  59. package/dist/helpers/IncomingTransactionHelper.mjs.map +1 -1
  60. package/dist/helpers/MethodDataHelper.cjs.map +1 -1
  61. package/dist/helpers/MethodDataHelper.d.cts.map +1 -1
  62. package/dist/helpers/MethodDataHelper.d.mts.map +1 -1
  63. package/dist/helpers/MethodDataHelper.mjs.map +1 -1
  64. package/dist/helpers/MultichainTrackingHelper.cjs +1 -21
  65. package/dist/helpers/MultichainTrackingHelper.cjs.map +1 -1
  66. package/dist/helpers/MultichainTrackingHelper.d.cts.map +1 -1
  67. package/dist/helpers/MultichainTrackingHelper.d.mts.map +1 -1
  68. package/dist/helpers/MultichainTrackingHelper.mjs +1 -21
  69. package/dist/helpers/MultichainTrackingHelper.mjs.map +1 -1
  70. package/dist/helpers/PendingTransactionTracker.cjs.map +1 -1
  71. package/dist/helpers/PendingTransactionTracker.d.cts.map +1 -1
  72. package/dist/helpers/PendingTransactionTracker.d.mts.map +1 -1
  73. package/dist/helpers/PendingTransactionTracker.mjs.map +1 -1
  74. package/dist/helpers/TransactionPoller.cjs +2 -0
  75. package/dist/helpers/TransactionPoller.cjs.map +1 -1
  76. package/dist/helpers/TransactionPoller.d.cts +2 -0
  77. package/dist/helpers/TransactionPoller.d.cts.map +1 -1
  78. package/dist/helpers/TransactionPoller.d.mts +2 -0
  79. package/dist/helpers/TransactionPoller.d.mts.map +1 -1
  80. package/dist/helpers/TransactionPoller.mjs +2 -0
  81. package/dist/helpers/TransactionPoller.mjs.map +1 -1
  82. package/dist/index.cjs.map +1 -1
  83. package/dist/index.d.cts +1 -1
  84. package/dist/index.d.cts.map +1 -1
  85. package/dist/index.d.mts +1 -1
  86. package/dist/index.d.mts.map +1 -1
  87. package/dist/index.mjs.map +1 -1
  88. package/dist/types.cjs +5 -0
  89. package/dist/types.cjs.map +1 -1
  90. package/dist/types.d.cts +51 -0
  91. package/dist/types.d.cts.map +1 -1
  92. package/dist/types.d.mts +51 -0
  93. package/dist/types.d.mts.map +1 -1
  94. package/dist/types.mjs +5 -0
  95. package/dist/types.mjs.map +1 -1
  96. package/dist/utils/batch.cjs +89 -0
  97. package/dist/utils/batch.cjs.map +1 -0
  98. package/dist/utils/batch.d.cts +33 -0
  99. package/dist/utils/batch.d.cts.map +1 -0
  100. package/dist/utils/batch.d.mts +33 -0
  101. package/dist/utils/batch.d.mts.map +1 -0
  102. package/dist/utils/batch.mjs +84 -0
  103. package/dist/utils/batch.mjs.map +1 -0
  104. package/dist/utils/eip7702.cjs +84 -2
  105. package/dist/utils/eip7702.cjs.map +1 -1
  106. package/dist/utils/eip7702.d.cts +35 -10
  107. package/dist/utils/eip7702.d.cts.map +1 -1
  108. package/dist/utils/eip7702.d.mts +35 -10
  109. package/dist/utils/eip7702.d.mts.map +1 -1
  110. package/dist/utils/eip7702.mjs +82 -3
  111. package/dist/utils/eip7702.mjs.map +1 -1
  112. package/dist/utils/feature-flags.cjs +53 -0
  113. package/dist/utils/feature-flags.cjs.map +1 -0
  114. package/dist/utils/feature-flags.d.cts +39 -0
  115. package/dist/utils/feature-flags.d.cts.map +1 -0
  116. package/dist/utils/feature-flags.d.mts +39 -0
  117. package/dist/utils/feature-flags.d.mts.map +1 -0
  118. package/dist/utils/feature-flags.mjs +47 -0
  119. package/dist/utils/feature-flags.mjs.map +1 -0
  120. package/dist/utils/gas-fees.cjs +48 -3
  121. package/dist/utils/gas-fees.cjs.map +1 -1
  122. package/dist/utils/gas-fees.d.cts +11 -0
  123. package/dist/utils/gas-fees.d.cts.map +1 -1
  124. package/dist/utils/gas-fees.d.mts +11 -0
  125. package/dist/utils/gas-fees.d.mts.map +1 -1
  126. package/dist/utils/gas-fees.mjs +48 -3
  127. package/dist/utils/gas-fees.mjs.map +1 -1
  128. package/dist/utils/gas-flow.cjs +4 -0
  129. package/dist/utils/gas-flow.cjs.map +1 -1
  130. package/dist/utils/gas-flow.d.cts +1 -0
  131. package/dist/utils/gas-flow.d.cts.map +1 -1
  132. package/dist/utils/gas-flow.d.mts +1 -0
  133. package/dist/utils/gas-flow.d.mts.map +1 -1
  134. package/dist/utils/gas-flow.mjs +4 -0
  135. package/dist/utils/gas-flow.mjs.map +1 -1
  136. package/dist/utils/gas.cjs +50 -1
  137. package/dist/utils/gas.cjs.map +1 -1
  138. package/dist/utils/gas.d.cts +22 -0
  139. package/dist/utils/gas.d.cts.map +1 -1
  140. package/dist/utils/gas.d.mts +22 -0
  141. package/dist/utils/gas.d.mts.map +1 -1
  142. package/dist/utils/gas.mjs +50 -1
  143. package/dist/utils/gas.mjs.map +1 -1
  144. package/dist/utils/layer1-gas-fee-flow.cjs +5 -1
  145. package/dist/utils/layer1-gas-fee-flow.cjs.map +1 -1
  146. package/dist/utils/layer1-gas-fee-flow.d.cts +4 -1
  147. package/dist/utils/layer1-gas-fee-flow.d.cts.map +1 -1
  148. package/dist/utils/layer1-gas-fee-flow.d.mts +4 -1
  149. package/dist/utils/layer1-gas-fee-flow.d.mts.map +1 -1
  150. package/dist/utils/layer1-gas-fee-flow.mjs +5 -1
  151. package/dist/utils/layer1-gas-fee-flow.mjs.map +1 -1
  152. package/dist/utils/retry.cjs +4 -0
  153. package/dist/utils/retry.cjs.map +1 -1
  154. package/dist/utils/retry.d.cts +1 -0
  155. package/dist/utils/retry.d.cts.map +1 -1
  156. package/dist/utils/retry.d.mts +1 -0
  157. package/dist/utils/retry.d.mts.map +1 -1
  158. package/dist/utils/retry.mjs +4 -0
  159. package/dist/utils/retry.mjs.map +1 -1
  160. package/dist/utils/simulation-api.cjs +6 -0
  161. package/dist/utils/simulation-api.cjs.map +1 -1
  162. package/dist/utils/simulation-api.d.cts +2 -0
  163. package/dist/utils/simulation-api.d.cts.map +1 -1
  164. package/dist/utils/simulation-api.d.mts +2 -0
  165. package/dist/utils/simulation-api.d.mts.map +1 -1
  166. package/dist/utils/simulation-api.mjs +6 -0
  167. package/dist/utils/simulation-api.mjs.map +1 -1
  168. package/dist/utils/simulation.cjs +19 -5
  169. package/dist/utils/simulation.cjs.map +1 -1
  170. package/dist/utils/simulation.d.cts +3 -1
  171. package/dist/utils/simulation.d.cts.map +1 -1
  172. package/dist/utils/simulation.d.mts +3 -1
  173. package/dist/utils/simulation.d.mts.map +1 -1
  174. package/dist/utils/simulation.mjs +19 -5
  175. package/dist/utils/simulation.mjs.map +1 -1
  176. package/dist/utils/swaps.cjs +2 -1
  177. package/dist/utils/swaps.cjs.map +1 -1
  178. package/dist/utils/swaps.d.cts +1 -0
  179. package/dist/utils/swaps.d.cts.map +1 -1
  180. package/dist/utils/swaps.d.mts +1 -0
  181. package/dist/utils/swaps.d.mts.map +1 -1
  182. package/dist/utils/swaps.mjs +2 -1
  183. package/dist/utils/swaps.mjs.map +1 -1
  184. package/dist/utils/transaction-type.cjs +3 -1
  185. package/dist/utils/transaction-type.cjs.map +1 -1
  186. package/dist/utils/transaction-type.mjs +3 -1
  187. package/dist/utils/transaction-type.mjs.map +1 -1
  188. package/dist/utils/validation.cjs +34 -5
  189. package/dist/utils/validation.cjs.map +1 -1
  190. package/dist/utils/validation.d.cts +19 -3
  191. package/dist/utils/validation.d.cts.map +1 -1
  192. package/dist/utils/validation.d.mts +19 -3
  193. package/dist/utils/validation.d.mts.map +1 -1
  194. package/dist/utils/validation.mjs +33 -5
  195. package/dist/utils/validation.mjs.map +1 -1
  196. package/package.json +7 -5
@@ -1 +1 @@
1
- {"version":3,"file":"gas.cjs","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":";AAAA,wCAAwC;;;AAExC,iEAKoC;AAGpC,2CAA4D;AAE5D,gDAA0D;AAC1D,0CAA0C;AAU7B,QAAA,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAa,EAAE,KAAK,CAAC,CAAC;AAE/C,QAAA,SAAS,GAAG,QAAQ,CAAC;AACrB,QAAA,sBAAsB,GAAG,GAAG,CAAC;AAC7B,QAAA,mCAAmC,GAAG,EAAE,CAAC;AACzC,QAAA,qBAAqB,GAAG,EAAE,CAAC;AAEjC,KAAK,UAAU,SAAS,CAAC,OAAyB;IACvD,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC3B,MAAM,aAAa,GAAG,EAAE,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;IAE7C,MAAM,CAAC,GAA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GACpB,sCAA0B,CACxB,OAAkD,CACnD,IAAI,8BAAsB,CAAC;IAE9B,MAAM,WAAW,GAAG,YAAY,CAC9B,YAAY,EACZ,aAAa,EACb,gBAAgB,CACjB,CAAC;IAEF,OAAO,CAAC,WAAW,EAAE,eAAe,EAAE,YAAY,CAAC,CAAC;AACtD,CAAC;AAED,KAAK,UAAU,gBAAgB,CAAC,EAC9B,QAAQ,EACR,MAAM,EACN,eAAe,GACE;IACjB,MAAM,EACJ,QAAQ,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,GACvB,GAAG,MAAM,CAAC;IAEX,IAAI,eAAe,IAAI,CAAC,EAAE,IAAI,IAAI,EAAE;QAClC,OAAO,KAAK,CAAC;KACd;IAED,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IAEzC,OAAO,CAAC,IAAI,IAAI,IAAI,KAAK,IAAI,CAAC;AAChC,CAAC;AAED,KAAK,UAAU,OAAO,CACpB,QAAkB,EAClB,OAAe;IAEf,OAAO,MAAM,IAAA,wBAAK,EAAC,QAAQ,EAAE,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;AACrD,CAAC;AAED,KAAK,UAAU,cAAc,CAC3B,QAAkB;IAElB,OAAO,MAAM,IAAA,wBAAK,EAAC,QAAQ,EAAE,kBAAkB,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC;AACtE,CAAC","sourcesContent":["/* eslint-disable jsdoc/require-jsdoc */\n\nimport {\n BNToHex,\n fractionBN,\n hexToBN,\n query,\n} from '@metamask/controller-utils';\nimport type EthQuery from '@metamask/eth-query';\nimport type { Hex } from '@metamask/utils';\nimport { add0x, createModuleLogger } from '@metamask/utils';\n\nimport { GAS_BUFFER_CHAIN_OVERRIDES } from '../constants';\nimport { projectLogger } from '../logger';\nimport type { TransactionMeta, TransactionParams } from '../types';\n\nexport type UpdateGasRequest = {\n ethQuery: EthQuery;\n isCustomNetwork: boolean;\n chainId: Hex;\n txMeta: TransactionMeta;\n};\n\nexport const log = createModuleLogger(projectLogger, 'gas');\n\nexport const FIXED_GAS = '0x5208';\nexport const DEFAULT_GAS_MULTIPLIER = 1.5;\nexport const GAS_ESTIMATE_FALLBACK_BLOCK_PERCENT = 35;\nexport const MAX_GAS_BLOCK_PERCENT = 90;\n\nexport async function updateGas(request: UpdateGasRequest) {\n const { txMeta } = request;\n const initialParams = { ...txMeta.txParams };\n\n const [gas, simulationFails, gasLimitNoBuffer] = await getGas(request);\n\n txMeta.txParams.gas = gas;\n txMeta.simulationFails = simulationFails;\n txMeta.gasLimitNoBuffer = gasLimitNoBuffer;\n\n if (!initialParams.gas) {\n txMeta.originalGasEstimate = txMeta.txParams.gas;\n }\n\n if (!txMeta.defaultGasEstimates) {\n txMeta.defaultGasEstimates = {};\n }\n\n txMeta.defaultGasEstimates.gas = txMeta.txParams.gas;\n}\n\nexport async function estimateGas(\n txParams: TransactionParams,\n ethQuery: EthQuery,\n) {\n const request = { ...txParams };\n const { data, value } = request;\n\n const { gasLimit: blockGasLimit, number: blockNumber } = await getLatestBlock(\n ethQuery,\n );\n\n const blockGasLimitBN = hexToBN(blockGasLimit);\n\n const fallback = BNToHex(\n fractionBN(blockGasLimitBN, GAS_ESTIMATE_FALLBACK_BLOCK_PERCENT, 100),\n );\n\n request.data = data ? add0x(data) : data;\n request.value = value || '0x0';\n\n delete request.gasPrice;\n delete request.maxFeePerGas;\n delete request.maxPriorityFeePerGas;\n\n let estimatedGas = fallback;\n let simulationFails: TransactionMeta['simulationFails'];\n\n try {\n estimatedGas = await query(ethQuery, 'estimateGas', [request]);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n simulationFails = {\n reason: error.message,\n errorKey: error.errorKey,\n debug: {\n blockNumber,\n blockGasLimit,\n },\n };\n\n log('Estimation failed', { ...simulationFails, fallback });\n }\n\n return {\n blockGasLimit,\n estimatedGas,\n simulationFails,\n };\n}\n\nexport function addGasBuffer(\n estimatedGas: string,\n blockGasLimit: string,\n multiplier: number,\n) {\n const estimatedGasBN = hexToBN(estimatedGas);\n\n const maxGasBN = fractionBN(\n hexToBN(blockGasLimit),\n MAX_GAS_BLOCK_PERCENT,\n 100,\n );\n\n const paddedGasBN = fractionBN(estimatedGasBN, multiplier * 100, 100);\n\n if (estimatedGasBN.gt(maxGasBN)) {\n const estimatedGasHex = add0x(estimatedGas);\n log('Using estimated value', estimatedGasHex);\n return estimatedGasHex;\n }\n\n if (paddedGasBN.lt(maxGasBN)) {\n const paddedHex = add0x(BNToHex(paddedGasBN));\n log('Using padded estimate', paddedHex, multiplier);\n return paddedHex;\n }\n\n const maxHex = add0x(BNToHex(maxGasBN));\n log('Using 90% of block gas limit', maxHex);\n return maxHex;\n}\n\nasync function getGas(\n request: UpdateGasRequest,\n): Promise<[string, TransactionMeta['simulationFails']?, string?]> {\n const { isCustomNetwork, chainId, txMeta } = request;\n\n if (txMeta.txParams.gas) {\n log('Using value from request', txMeta.txParams.gas);\n return [txMeta.txParams.gas, undefined, txMeta.txParams.gas];\n }\n\n if (await requiresFixedGas(request)) {\n log('Using fixed value', FIXED_GAS);\n return [FIXED_GAS, undefined, FIXED_GAS];\n }\n\n const { blockGasLimit, estimatedGas, simulationFails } = await estimateGas(\n txMeta.txParams,\n request.ethQuery,\n );\n\n if (isCustomNetwork || simulationFails) {\n log(\n isCustomNetwork\n ? 'Using original estimate as custom network'\n : 'Using original fallback estimate as simulation failed',\n );\n return [estimatedGas, simulationFails, estimatedGas];\n }\n\n const bufferMultiplier =\n GAS_BUFFER_CHAIN_OVERRIDES[\n chainId as keyof typeof GAS_BUFFER_CHAIN_OVERRIDES\n ] ?? DEFAULT_GAS_MULTIPLIER;\n\n const bufferedGas = addGasBuffer(\n estimatedGas,\n blockGasLimit,\n bufferMultiplier,\n );\n\n return [bufferedGas, simulationFails, estimatedGas];\n}\n\nasync function requiresFixedGas({\n ethQuery,\n txMeta,\n isCustomNetwork,\n}: UpdateGasRequest): Promise<boolean> {\n const {\n txParams: { to, data },\n } = txMeta;\n\n if (isCustomNetwork || !to || data) {\n return false;\n }\n\n const code = await getCode(ethQuery, to);\n\n return !code || code === '0x';\n}\n\nasync function getCode(\n ethQuery: EthQuery,\n address: string,\n): Promise<string | undefined> {\n return await query(ethQuery, 'getCode', [address]);\n}\n\nasync function getLatestBlock(\n ethQuery: EthQuery,\n): Promise<{ gasLimit: string; number: string }> {\n return await query(ethQuery, 'getBlockByNumber', ['latest', false]);\n}\n"]}
1
+ {"version":3,"file":"gas.cjs","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":";;;AAAA,iEAKoC;AAGpC,2CAA4D;AAE5D,gDAA0D;AAC1D,0CAA0C;AAU7B,QAAA,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAa,EAAE,KAAK,CAAC,CAAC;AAE/C,QAAA,SAAS,GAAG,QAAQ,CAAC;AACrB,QAAA,sBAAsB,GAAG,GAAG,CAAC;AAC7B,QAAA,mCAAmC,GAAG,EAAE,CAAC;AACzC,QAAA,qBAAqB,GAAG,EAAE,CAAC;AAExC;;;;GAIG;AACI,KAAK,UAAU,SAAS,CAAC,OAAyB;IACvD,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC3B,MAAM,aAAa,GAAG,EAAE,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;IAE7C,MAAM,CAAC,GAAG,EAAE,eAAe,EAAE,gBAAgB,CAAC,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC;IAEvE,MAAM,CAAC,QAAQ,CAAC,GAAG,GAAG,GAAG,CAAC;IAC1B,MAAM,CAAC,eAAe,GAAG,eAAe,CAAC;IACzC,MAAM,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;IAE3C,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE;QACtB,MAAM,CAAC,mBAAmB,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC;KAClD;IAED,IAAI,CAAC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MAAM,EACJ,QAAQ,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,GACvB,GAAG,MAAM,CAAC;IAEX,IAAI,eAAe,IAAI,CAAC,EAAE,IAAI,IAAI,EAAE;QAClC,OAAO,KAAK,CAAC;KACd;IAED,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IAEzC,OAAO,CAAC,IAAI,IAAI,IAAI,KAAK,IAAI,CAAC;AAChC,CAAC;AAED;;;;;;GAMG;AACH,KAAK,UAAU,OAAO,CACpB,QAAkB,EAClB,OAAe;IAEf,OAAO,MAAM,IAAA,wBAAK,EAAC,QAAQ,EAAE,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;AACrD,CAAC;AAED;;;;;GAKG;AACH,KAAK,UAAU,cAAc,CAC3B,QAAkB;IAElB,OAAO,MAAM,IAAA,wBAAK,EAAC,QAAQ,EAAE,kBAAkB,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC;AACtE,CAAC","sourcesContent":["import {\n BNToHex,\n fractionBN,\n hexToBN,\n query,\n} from '@metamask/controller-utils';\nimport type EthQuery from '@metamask/eth-query';\nimport type { Hex } from '@metamask/utils';\nimport { add0x, createModuleLogger } from '@metamask/utils';\n\nimport { GAS_BUFFER_CHAIN_OVERRIDES } from '../constants';\nimport { projectLogger } from '../logger';\nimport type { TransactionMeta, TransactionParams } from '../types';\n\nexport type UpdateGasRequest = {\n ethQuery: EthQuery;\n isCustomNetwork: boolean;\n chainId: Hex;\n txMeta: TransactionMeta;\n};\n\nexport const log = createModuleLogger(projectLogger, 'gas');\n\nexport const FIXED_GAS = '0x5208';\nexport const DEFAULT_GAS_MULTIPLIER = 1.5;\nexport const GAS_ESTIMATE_FALLBACK_BLOCK_PERCENT = 35;\nexport const MAX_GAS_BLOCK_PERCENT = 90;\n\n/**\n * Populate the gas properties of the provided transaction meta.\n *\n * @param request - The request object including the necessary parameters.\n */\nexport async function updateGas(request: UpdateGasRequest) {\n const { txMeta } = request;\n const initialParams = { ...txMeta.txParams };\n\n const [gas, simulationFails, gasLimitNoBuffer] = await getGas(request);\n\n txMeta.txParams.gas = gas;\n txMeta.simulationFails = simulationFails;\n txMeta.gasLimitNoBuffer = gasLimitNoBuffer;\n\n if (!initialParams.gas) {\n txMeta.originalGasEstimate = txMeta.txParams.gas;\n }\n\n if (!txMeta.defaultGasEstimates) {\n txMeta.defaultGasEstimates = {};\n }\n\n txMeta.defaultGasEstimates.gas = txMeta.txParams.gas;\n}\n\n/**\n * Estimate the gas for the provided transaction parameters.\n * If the gas estimate fails, the fallback value is returned.\n *\n * @param txParams - The transaction parameters.\n * @param ethQuery - The EthQuery instance to interact with the network.\n * @returns The estimated gas and related info.\n */\nexport async function estimateGas(\n txParams: TransactionParams,\n ethQuery: EthQuery,\n) {\n const request = { ...txParams };\n const { data, value } = request;\n\n const { gasLimit: blockGasLimit, number: blockNumber } =\n await getLatestBlock(ethQuery);\n\n const blockGasLimitBN = hexToBN(blockGasLimit);\n\n const fallback = BNToHex(\n fractionBN(blockGasLimitBN, GAS_ESTIMATE_FALLBACK_BLOCK_PERCENT, 100),\n );\n\n request.data = data ? add0x(data) : data;\n request.value = value || '0x0';\n\n delete request.gasPrice;\n delete request.maxFeePerGas;\n delete request.maxPriorityFeePerGas;\n\n let estimatedGas = fallback;\n let simulationFails: TransactionMeta['simulationFails'];\n\n try {\n estimatedGas = await query(ethQuery, 'estimateGas', [request]);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n simulationFails = {\n reason: error.message,\n errorKey: error.errorKey,\n debug: {\n blockNumber,\n blockGasLimit,\n },\n };\n\n log('Estimation failed', { ...simulationFails, fallback });\n }\n\n return {\n blockGasLimit,\n estimatedGas,\n simulationFails,\n };\n}\n\n/**\n * Add a buffer to the provided estimated gas.\n * The buffer is calculated based on the block gas limit and a multiplier.\n *\n * @param estimatedGas - The estimated gas.\n * @param blockGasLimit - The block gas limit.\n * @param multiplier - The multiplier to apply to the estimated gas.\n * @returns The gas with the buffer applied.\n */\nexport function addGasBuffer(\n estimatedGas: string,\n blockGasLimit: string,\n multiplier: number,\n) {\n const estimatedGasBN = hexToBN(estimatedGas);\n\n const maxGasBN = fractionBN(\n hexToBN(blockGasLimit),\n MAX_GAS_BLOCK_PERCENT,\n 100,\n );\n\n const paddedGasBN = fractionBN(estimatedGasBN, multiplier * 100, 100);\n\n if (estimatedGasBN.gt(maxGasBN)) {\n const estimatedGasHex = add0x(estimatedGas);\n log('Using estimated value', estimatedGasHex);\n return estimatedGasHex;\n }\n\n if (paddedGasBN.lt(maxGasBN)) {\n const paddedHex = add0x(BNToHex(paddedGasBN));\n log('Using padded estimate', paddedHex, multiplier);\n return paddedHex;\n }\n\n const maxHex = add0x(BNToHex(maxGasBN));\n log('Using 90% of block gas limit', maxHex);\n return maxHex;\n}\n\n/**\n * Determine the gas for the provided request.\n *\n * @param request - The request object including the necessary parameters.\n * @returns The final gas value and the estimate used.\n */\nasync function getGas(\n request: UpdateGasRequest,\n): Promise<[string, TransactionMeta['simulationFails']?, string?]> {\n const { isCustomNetwork, chainId, txMeta } = request;\n\n if (txMeta.txParams.gas) {\n log('Using value from request', txMeta.txParams.gas);\n return [txMeta.txParams.gas, undefined, txMeta.txParams.gas];\n }\n\n if (await requiresFixedGas(request)) {\n log('Using fixed value', FIXED_GAS);\n return [FIXED_GAS, undefined, FIXED_GAS];\n }\n\n const { blockGasLimit, estimatedGas, simulationFails } = await estimateGas(\n txMeta.txParams,\n request.ethQuery,\n );\n\n if (isCustomNetwork || simulationFails) {\n log(\n isCustomNetwork\n ? 'Using original estimate as custom network'\n : 'Using original fallback estimate as simulation failed',\n );\n return [estimatedGas, simulationFails, estimatedGas];\n }\n\n const bufferMultiplier =\n GAS_BUFFER_CHAIN_OVERRIDES[\n chainId as keyof typeof GAS_BUFFER_CHAIN_OVERRIDES\n ] ?? DEFAULT_GAS_MULTIPLIER;\n\n const bufferedGas = addGasBuffer(\n estimatedGas,\n blockGasLimit,\n bufferMultiplier,\n );\n\n return [bufferedGas, simulationFails, estimatedGas];\n}\n\n/**\n * Determine if the gas for the provided request should be fixed.\n *\n * @param options - The options object.\n * @param options.ethQuery - The EthQuery instance to interact with the network.\n * @param options.txMeta - The transaction meta object.\n * @param options.isCustomNetwork - Whether the network is a custom network.\n * @returns Whether the gas should be fixed.\n */\nasync function requiresFixedGas({\n ethQuery,\n txMeta,\n isCustomNetwork,\n}: UpdateGasRequest): Promise<boolean> {\n const {\n txParams: { to, data },\n } = txMeta;\n\n if (isCustomNetwork || !to || data) {\n return false;\n }\n\n const code = await getCode(ethQuery, to);\n\n return !code || code === '0x';\n}\n\n/**\n * Get the contract code for the provided address.\n *\n * @param ethQuery - The EthQuery instance to interact with the network.\n * @param address - The address to get the code for.\n * @returns The contract code.\n */\nasync function getCode(\n ethQuery: EthQuery,\n address: string,\n): Promise<string | undefined> {\n return await query(ethQuery, 'getCode', [address]);\n}\n\n/**\n * Get the latest block from the network.\n *\n * @param ethQuery - The EthQuery instance to interact with the network.\n * @returns The latest block number.\n */\nasync function getLatestBlock(\n ethQuery: EthQuery,\n): Promise<{ gasLimit: string; number: string }> {\n return await query(ethQuery, 'getBlockByNumber', ['latest', false]);\n}\n"]}
@@ -13,7 +13,20 @@ export declare const FIXED_GAS = "0x5208";
13
13
  export declare const DEFAULT_GAS_MULTIPLIER = 1.5;
14
14
  export declare const GAS_ESTIMATE_FALLBACK_BLOCK_PERCENT = 35;
15
15
  export declare const MAX_GAS_BLOCK_PERCENT = 90;
16
+ /**
17
+ * Populate the gas properties of the provided transaction meta.
18
+ *
19
+ * @param request - The request object including the necessary parameters.
20
+ */
16
21
  export declare function updateGas(request: UpdateGasRequest): Promise<void>;
22
+ /**
23
+ * Estimate the gas for the provided transaction parameters.
24
+ * If the gas estimate fails, the fallback value is returned.
25
+ *
26
+ * @param txParams - The transaction parameters.
27
+ * @param ethQuery - The EthQuery instance to interact with the network.
28
+ * @returns The estimated gas and related info.
29
+ */
17
30
  export declare function estimateGas(txParams: TransactionParams, ethQuery: EthQuery): Promise<{
18
31
  blockGasLimit: string;
19
32
  estimatedGas: `0x${string}`;
@@ -26,5 +39,14 @@ export declare function estimateGas(txParams: TransactionParams, ethQuery: EthQu
26
39
  };
27
40
  } | undefined;
28
41
  }>;
42
+ /**
43
+ * Add a buffer to the provided estimated gas.
44
+ * The buffer is calculated based on the block gas limit and a multiplier.
45
+ *
46
+ * @param estimatedGas - The estimated gas.
47
+ * @param blockGasLimit - The block gas limit.
48
+ * @param multiplier - The multiplier to apply to the estimated gas.
49
+ * @returns The gas with the buffer applied.
50
+ */
29
51
  export declare function addGasBuffer(estimatedGas: string, blockGasLimit: string, multiplier: number): `0x${string}`;
30
52
  //# sourceMappingURL=gas.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"gas.d.cts","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":";AAQA,OAAO,KAAK,QAAQ,4BAA4B;AAChD,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAK3C,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,qBAAiB;AAEnE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,EAAE,QAAQ,CAAC;IACnB,eAAe,EAAE,OAAO,CAAC;IACzB,OAAO,EAAE,GAAG,CAAC;IACb,MAAM,EAAE,eAAe,CAAC;CACzB,CAAC;AAEF,eAAO,MAAM,GAAG,0BAA2C,CAAC;AAE5D,eAAO,MAAM,SAAS,WAAW,CAAC;AAClC,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAC1C,eAAO,MAAM,mCAAmC,KAAK,CAAC;AACtD,eAAO,MAAM,qBAAqB,KAAK,CAAC;AAExC,wBAAsB,SAAS,CAAC,OAAO,EAAE,gBAAgB,iBAmBxD;AAED,wBAAsB,WAAW,CAC/B,QAAQ,EAAE,iBAAiB,EAC3B,QAAQ,EAAE,QAAQ;;;;;;;;;;;GA8CnB;AAED,wBAAgB,YAAY,CAC1B,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,MAAM,EACrB,UAAU,EAAE,MAAM,iBA2BnB"}
1
+ {"version":3,"file":"gas.d.cts","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":";AAMA,OAAO,KAAK,QAAQ,4BAA4B;AAChD,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAK3C,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,qBAAiB;AAEnE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,EAAE,QAAQ,CAAC;IACnB,eAAe,EAAE,OAAO,CAAC;IACzB,OAAO,EAAE,GAAG,CAAC;IACb,MAAM,EAAE,eAAe,CAAC;CACzB,CAAC;AAEF,eAAO,MAAM,GAAG,0BAA2C,CAAC;AAE5D,eAAO,MAAM,SAAS,WAAW,CAAC;AAClC,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAC1C,eAAO,MAAM,mCAAmC,KAAK,CAAC;AACtD,eAAO,MAAM,qBAAqB,KAAK,CAAC;AAExC;;;;GAIG;AACH,wBAAsB,SAAS,CAAC,OAAO,EAAE,gBAAgB,iBAmBxD;AAED;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAC/B,QAAQ,EAAE,iBAAiB,EAC3B,QAAQ,EAAE,QAAQ;;;;;;;;;;;GA6CnB;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAC1B,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,MAAM,EACrB,UAAU,EAAE,MAAM,iBA2BnB"}
@@ -13,7 +13,20 @@ export declare const FIXED_GAS = "0x5208";
13
13
  export declare const DEFAULT_GAS_MULTIPLIER = 1.5;
14
14
  export declare const GAS_ESTIMATE_FALLBACK_BLOCK_PERCENT = 35;
15
15
  export declare const MAX_GAS_BLOCK_PERCENT = 90;
16
+ /**
17
+ * Populate the gas properties of the provided transaction meta.
18
+ *
19
+ * @param request - The request object including the necessary parameters.
20
+ */
16
21
  export declare function updateGas(request: UpdateGasRequest): Promise<void>;
22
+ /**
23
+ * Estimate the gas for the provided transaction parameters.
24
+ * If the gas estimate fails, the fallback value is returned.
25
+ *
26
+ * @param txParams - The transaction parameters.
27
+ * @param ethQuery - The EthQuery instance to interact with the network.
28
+ * @returns The estimated gas and related info.
29
+ */
17
30
  export declare function estimateGas(txParams: TransactionParams, ethQuery: EthQuery): Promise<{
18
31
  blockGasLimit: string;
19
32
  estimatedGas: `0x${string}`;
@@ -26,5 +39,14 @@ export declare function estimateGas(txParams: TransactionParams, ethQuery: EthQu
26
39
  };
27
40
  } | undefined;
28
41
  }>;
42
+ /**
43
+ * Add a buffer to the provided estimated gas.
44
+ * The buffer is calculated based on the block gas limit and a multiplier.
45
+ *
46
+ * @param estimatedGas - The estimated gas.
47
+ * @param blockGasLimit - The block gas limit.
48
+ * @param multiplier - The multiplier to apply to the estimated gas.
49
+ * @returns The gas with the buffer applied.
50
+ */
29
51
  export declare function addGasBuffer(estimatedGas: string, blockGasLimit: string, multiplier: number): `0x${string}`;
30
52
  //# sourceMappingURL=gas.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"gas.d.mts","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":";AAQA,OAAO,KAAK,QAAQ,4BAA4B;AAChD,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAK3C,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,qBAAiB;AAEnE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,EAAE,QAAQ,CAAC;IACnB,eAAe,EAAE,OAAO,CAAC;IACzB,OAAO,EAAE,GAAG,CAAC;IACb,MAAM,EAAE,eAAe,CAAC;CACzB,CAAC;AAEF,eAAO,MAAM,GAAG,0BAA2C,CAAC;AAE5D,eAAO,MAAM,SAAS,WAAW,CAAC;AAClC,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAC1C,eAAO,MAAM,mCAAmC,K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doc */
2
1
  import { BNToHex, fractionBN, hexToBN, query } from "@metamask/controller-utils";
3
2
  import { add0x, createModuleLogger } from "@metamask/utils";
4
3
  import { GAS_BUFFER_CHAIN_OVERRIDES } from "../constants.mjs";
@@ -8,6 +7,11 @@ export const FIXED_GAS = '0x5208';
8
7
  export const DEFAULT_GAS_MULTIPLIER = 1.5;
9
8
  export const GAS_ESTIMATE_FALLBACK_BLOCK_PERCENT = 35;
10
9
  export const MAX_GAS_BLOCK_PERCENT = 90;
10
+ /**
11
+ * Populate the gas properties of the provided transaction meta.
12
+ *
13
+ * @param request - The request object including the necessary parameters.
14
+ */
11
15
  export async function updateGas(request) {
12
16
  const { txMeta } = request;
13
17
  const initialParams = { ...txMeta.txParams };
@@ -23,6 +27,14 @@ export async function updateGas(request) {
23
27
  }
24
28
  txMeta.defaultGasEstimates.gas = txMeta.txParams.gas;
25
29
  }
30
+ /**
31
+ * Estimate the gas for the provided transaction parameters.
32
+ * If the gas estimate fails, the fallback value is returned.
33
+ *
34
+ * @param txParams - The transaction parameters.
35
+ * @param ethQuery - The EthQuery instance to interact with the network.
36
+ * @returns The estimated gas and related info.
37
+ */
26
38
  export async function estimateGas(txParams, ethQuery) {
27
39
  const request = { ...txParams };
28
40
  const { data, value } = request;
@@ -57,6 +69,15 @@ export async function estimateGas(txParams, ethQuery) {
57
69
  simulationFails,
58
70
  };
59
71
  }
72
+ /**
73
+ * Add a buffer to the provided estimated gas.
74
+ * The buffer is calculated based on the block gas limit and a multiplier.
75
+ *
76
+ * @param estimatedGas - The estimated gas.
77
+ * @param blockGasLimit - The block gas limit.
78
+ * @param multiplier - The multiplier to apply to the estimated gas.
79
+ * @returns The gas with the buffer applied.
80
+ */
60
81
  export function addGasBuffer(estimatedGas, blockGasLimit, multiplier) {
61
82
  const estimatedGasBN = hexToBN(estimatedGas);
62
83
  const maxGasBN = fractionBN(hexToBN(blockGasLimit), MAX_GAS_BLOCK_PERCENT, 100);
@@ -75,6 +96,12 @@ export function addGasBuffer(estimatedGas, blockGasLimit, multiplier) {
75
96
  log('Using 90% of block gas limit', maxHex);
76
97
  return maxHex;
77
98
  }
99
+ /**
100
+ * Determine the gas for the provided request.
101
+ *
102
+ * @param request - The request object including the necessary parameters.
103
+ * @returns The final gas value and the estimate used.
104
+ */
78
105
  async function getGas(request) {
79
106
  const { isCustomNetwork, chainId, txMeta } = request;
80
107
  if (txMeta.txParams.gas) {
@@ -96,6 +123,15 @@ async function getGas(request) {
96
123
  const bufferedGas = addGasBuffer(estimatedGas, blockGasLimit, bufferMultiplier);
97
124
  return [bufferedGas, simulationFails, estimatedGas];
98
125
  }
126
+ /**
127
+ * Determine if the gas for the provided request should be fixed.
128
+ *
129
+ * @param options - The options object.
130
+ * @param options.ethQuery - The EthQuery instance to interact with the network.
131
+ * @param options.txMeta - The transaction meta object.
132
+ * @param options.isCustomNetwork - Whether the network is a custom network.
133
+ * @returns Whether the gas should be fixed.
134
+ */
99
135
  async function requiresFixedGas({ ethQuery, txMeta, isCustomNetwork, }) {
100
136
  const { txParams: { to, data }, } = txMeta;
101
137
  if (isCustomNetwork || !to || data) {
@@ -104,9 +140,22 @@ async function requiresFixedGas({ ethQuery, txMeta, isCustomNetwork, }) {
104
140
  const code = await getCode(ethQuery, to);
105
141
  return !code || code === '0x';
106
142
  }
143
+ /**
144
+ * Get the contract code for the provided address.
145
+ *
146
+ * @param ethQuery - The EthQuery instance to interact with the network.
147
+ * @param address - The address to get the code for.
148
+ * @returns The contract code.
149
+ */
107
150
  async function getCode(ethQuery, address) {
108
151
  return await query(ethQuery, 'getCode', [address]);
109
152
  }
153
+ /**
154
+ * Get the latest block from the network.
155
+ *
156
+ * @param ethQuery - The EthQuery instance to interact with the network.
157
+ * @returns The latest block number.
158
+ */
110
159
  async function getLatestBlock(ethQuery) {
111
160
  return await query(ethQuery, 'getBlockByNumber', ['latest', false]);
112
161
  }
@@ -1 +1 @@
1
- {"version":3,"file":"gas.mjs","sourceRoot":"","sources":["../../src/utils/gas.ts"],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AAO,CAAC,CAAC,CAAC;AACrD,CAAC;AAED,KAAK,UAAU,cAAc,CAC3B,QAAkB;IAElB,OAAO,MAAM,KAAK,CAAC,QAAQ,EAAE,kBAAkB,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC;AACtE,CAAC","sourcesContent":["/* eslint-disable jsdoc/require-jsdoc */\n\nimport {\n BNToHex,\n fractionBN,\n hexToBN,\n query,\n} from '@metamask/controller-utils';\nimport type EthQuery from '@metamask/eth-query';\nimport type { Hex } from '@metamask/utils';\nimport { add0x, createModuleLogger } from '@metamask/utils';\n\nimport { GAS_BUFFER_CHAIN_OVERRIDES } from '../constants';\nimport { projectLogger } from '../logger';\nimport type { TransactionMeta, TransactionParams } from '../types';\n\nexport type UpdateGasRequest = {\n ethQuery: EthQuery;\n isCustomNetwork: boolean;\n chainId: Hex;\n txMeta: TransactionMeta;\n};\n\nexport const log = createModuleLogger(projectLogger, 'gas');\n\nexport const FIXED_GAS = '0x5208';\nexport const DEFAULT_GAS_MULTIPLIER = 1.5;\nexport const GAS_ESTIMATE_FALLBACK_BLOCK_PERCENT = 35;\nexport const MAX_GAS_BLOCK_PERCENT = 90;\n\nexport async function updateGas(request: UpdateGasRequest) {\n const { txMeta } = request;\n const initialParams = { ...txMeta.txParams };\n\n const [gas, simulationFails, gasLimitNoBuffer] = await getGas(request);\n\n txMeta.txParams.gas = gas;\n txMeta.simulationFails = simulationFails;\n txMeta.gasLimitNoBuffer = gasLimitNoBuffer;\n\n if (!initialParams.gas) {\n txMeta.originalGasEstimate = txMeta.txParams.gas;\n }\n\n if (!txMeta.defaultGasEstimates) {\n txMeta.defaultGasEstimates = {};\n }\n\n txMeta.defaultGasEstimates.gas = txMeta.txParams.gas;\n}\n\nexport async function estimateGas(\n txParams: TransactionParams,\n ethQuery: EthQuery,\n) {\n const request = { ...txParams };\n const { data, value } = request;\n\n const { gasLimit: blockGasLimit, number: blockNumber } = await getLatestBlock(\n ethQuery,\n );\n\n const blockGasLimitBN = hexToBN(blockGasLimit);\n\n const fallback = BNToHex(\n fractionBN(blockGasLimitBN, GAS_ESTIMATE_FALLBACK_BLOCK_PERCENT, 100),\n );\n\n request.data = data ? add0x(data) : data;\n request.value = value || '0x0';\n\n delete request.gasPrice;\n delete request.maxFeePerGas;\n delete request.maxPriorityFeePerGas;\n\n let estimatedGas = fallback;\n let simulationFails: TransactionMeta['simulationFails'];\n\n try {\n estimatedGas = await query(ethQuery, 'estimateGas', [request]);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n simulationFails = {\n reason: error.message,\n errorKey: error.errorKey,\n debug: {\n blockNumber,\n blockGasLimit,\n },\n };\n\n log('Estimation failed', { ...simulationFails, fallback });\n }\n\n return {\n blockGasLimit,\n estimatedGas,\n simulationFails,\n };\n}\n\nexport function addGasBuffer(\n estimatedGas: string,\n blockGasLimit: string,\n multiplier: number,\n) {\n const estimatedGasBN = hexToBN(estimatedGas);\n\n const maxGasBN = fractionBN(\n hexToBN(blockGasLimit),\n MAX_GAS_BLOCK_PERCENT,\n 100,\n );\n\n const paddedGasBN = fractionBN(estimatedGasBN, multiplier * 100, 100);\n\n if (estimatedGasBN.gt(maxGasBN)) {\n const estimatedGasHex = add0x(estimatedGas);\n log('Using estimated value', estimatedGasHex);\n return estimatedGasHex;\n }\n\n if (paddedGasBN.lt(maxGasBN)) {\n const paddedHex = add0x(BNToHex(paddedGasBN));\n log('Using padded estimate', paddedHex, multiplier);\n return paddedHex;\n }\n\n const maxHex = add0x(BNToHex(maxGasBN));\n log('Using 90% of block gas limit', maxHex);\n return maxHex;\n}\n\nasync function getGas(\n request: UpdateGasRequest,\n): Promise<[string, TransactionMeta['simulationFails']?, string?]> {\n const { isCustomNetwork, chainId, txMeta } = request;\n\n if (txMeta.txParams.gas) {\n log('Using value from request', txMeta.txParams.gas);\n return [txMeta.txParams.gas, undefined, txMeta.txParams.gas];\n }\n\n if (await requiresFixedGas(request)) {\n log('Using fixed value', FIXED_GAS);\n return [FIXED_GAS, undefined, FIXED_GAS];\n }\n\n const { blockGasLimit, estimatedGas, simulationFails } = await estimateGas(\n txMeta.txParams,\n request.ethQuery,\n );\n\n if (isCustomNetwork || simulationFails) {\n log(\n isCustomNetwork\n ? 'Using original estimate as custom network'\n : 'Using original fallback estimate as simulation failed',\n );\n return [estimatedGas, simulationFails, estimatedGas];\n }\n\n const bufferMultiplier =\n GAS_BUFFER_CHAIN_OVERRIDES[\n chainId as keyof typeof GAS_BUFFER_CHAIN_OVERRIDES\n ] ?? DEFAULT_GAS_MULTIPLIER;\n\n const bufferedGas = addGasBuffer(\n estimatedGas,\n blockGasLimit,\n bufferMultiplier,\n );\n\n return [bufferedGas, simulationFails, estimatedGas];\n}\n\nasync function requiresFixedGas({\n ethQuery,\n txMeta,\n isCustomNetwork,\n}: UpdateGasRequest): Promise<boolean> {\n const {\n txParams: { to, data },\n } = txMeta;\n\n if (isCustomNetwork || !to || data) {\n return false;\n }\n\n const code = await getCode(ethQuery, to);\n\n return !code || code === '0x';\n}\n\nasync function getCode(\n ethQuery: EthQuery,\n address: string,\n): Promise<string | undefined> {\n return await query(ethQuery, 'getCode', [address]);\n}\n\nasync function getLatestBlock(\n ethQuery: EthQuery,\n): Promise<{ gasLimit: string; number: string }> {\n return await query(ethQuery, 'getBlockByNumber', ['latest', false]);\n}\n"]}
1
+ {"version":3,"file":"gas.mjs","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,UAAU,EACV,OAAO,EACP,KAAK,EACN,mCAAmC;AAGpC,OAAO,EAAE,KAAK,EAAE,kBAAkB,EAAE,wBAAwB;AAE5D,OAAO,EAAE,0BAA0B,EAAE,yBAAqB;AAC1D,OAAO,EAAE,aAAa,EAAE,sBAAkB;AAU1C,MAAM,CAAC,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;AAE5D,MAAM,CAAC,MAAM,SAAS,GAAG,QAA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from '@metamask/controller-utils';\nimport type EthQuery from '@metamask/eth-query';\nimport type { Hex } from '@metamask/utils';\nimport { add0x, createModuleLogger } from '@metamask/utils';\n\nimport { GAS_BUFFER_CHAIN_OVERRIDES } from '../constants';\nimport { projectLogger } from '../logger';\nimport type { TransactionMeta, TransactionParams } from '../types';\n\nexport type UpdateGasRequest = {\n ethQuery: EthQuery;\n isCustomNetwork: boolean;\n chainId: Hex;\n txMeta: TransactionMeta;\n};\n\nexport const log = createModuleLogger(projectLogger, 'gas');\n\nexport const FIXED_GAS = '0x5208';\nexport const DEFAULT_GAS_MULTIPLIER = 1.5;\nexport const GAS_ESTIMATE_FALLBACK_BLOCK_PERCENT = 35;\nexport const MAX_GAS_BLOCK_PERCENT = 90;\n\n/**\n * Populate the gas properties of the provided transaction meta.\n *\n * @param request - The request object including the necessary parameters.\n */\nexport async function updateGas(request: UpdateGasRequest) {\n const { txMeta } = request;\n const initialParams = { ...txMeta.txParams };\n\n const [gas, simulationFails, gasLimitNoBuffer] = await getGas(request);\n\n txMeta.txParams.gas = gas;\n txMeta.simulationFails = simulationFails;\n txMeta.gasLimitNoBuffer = gasLimitNoBuffer;\n\n if (!initialParams.gas) {\n txMeta.originalGasEstimate = txMeta.txParams.gas;\n }\n\n if (!txMeta.defaultGasEstimates) {\n txMeta.defaultGasEstimates = {};\n }\n\n txMeta.defaultGasEstimates.gas = txMeta.txParams.gas;\n}\n\n/**\n * Estimate the gas for the provided transaction parameters.\n * If the gas estimate fails, the fallback value is returned.\n *\n * @param txParams - The transaction parameters.\n * @param ethQuery - The EthQuery instance to interact with the network.\n * @returns The estimated gas and related info.\n */\nexport async function estimateGas(\n txParams: TransactionParams,\n ethQuery: EthQuery,\n) {\n const request = { ...txParams };\n const { data, value } = request;\n\n const { gasLimit: blockGasLimit, number: blockNumber } =\n await getLatestBlock(ethQuery);\n\n const blockGasLimitBN = hexToBN(blockGasLimit);\n\n const fallback = BNToHex(\n fractionBN(blockGasLimitBN, GAS_ESTIMATE_FALLBACK_BLOCK_PERCENT, 100),\n );\n\n request.data = data ? add0x(data) : data;\n request.value = value || '0x0';\n\n delete request.gasPrice;\n delete request.maxFeePerGas;\n delete request.maxPriorityFeePerGas;\n\n let estimatedGas = fallback;\n let simulationFails: TransactionMeta['simulationFails'];\n\n try {\n estimatedGas = await query(ethQuery, 'estimateGas', [request]);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n simulationFails = {\n reason: error.message,\n errorKey: error.errorKey,\n debug: {\n blockNumber,\n blockGasLimit,\n },\n };\n\n log('Estimation failed', { ...simulationFails, fallback });\n }\n\n return {\n blockGasLimit,\n estimatedGas,\n simulationFails,\n };\n}\n\n/**\n * Add a buffer to the provided estimated gas.\n * The buffer is calculated based on the block gas limit and a multiplier.\n *\n * @param estimatedGas - The estimated gas.\n * @param blockGasLimit - The block gas limit.\n * @param multiplier - The multiplier to apply to the estimated gas.\n * @returns The gas with the buffer applied.\n */\nexport function addGasBuffer(\n estimatedGas: string,\n blockGasLimit: string,\n multiplier: number,\n) {\n const estimatedGasBN = hexToBN(estimatedGas);\n\n const maxGasBN = fractionBN(\n hexToBN(blockGasLimit),\n MAX_GAS_BLOCK_PERCENT,\n 100,\n );\n\n const paddedGasBN = fractionBN(estimatedGasBN, multiplier * 100, 100);\n\n if (estimatedGasBN.gt(maxGasBN)) {\n const estimatedGasHex = add0x(estimatedGas);\n log('Using estimated value', estimatedGasHex);\n return estimatedGasHex;\n }\n\n if (paddedGasBN.lt(maxGasBN)) {\n const paddedHex = add0x(BNToHex(paddedGasBN));\n log('Using padded estimate', paddedHex, multiplier);\n return paddedHex;\n }\n\n const maxHex = add0x(BNToHex(maxGasBN));\n log('Using 90% of block gas limit', maxHex);\n return maxHex;\n}\n\n/**\n * Determine the gas for the provided request.\n *\n * @param request - The request object including the necessary parameters.\n * @returns The final gas value and the estimate used.\n */\nasync function getGas(\n request: UpdateGasRequest,\n): Promise<[string, TransactionMeta['simulationFails']?, string?]> {\n const { isCustomNetwork, chainId, txMeta } = request;\n\n if (txMeta.txParams.gas) {\n log('Using value from request', txMeta.txParams.gas);\n return [txMeta.txParams.gas, undefined, txMeta.txParams.gas];\n }\n\n if (await requiresFixedGas(request)) {\n log('Using fixed value', FIXED_GAS);\n return [FIXED_GAS, undefined, FIXED_GAS];\n }\n\n const { blockGasLimit, estimatedGas, simulationFails } = await estimateGas(\n txMeta.txParams,\n request.ethQuery,\n );\n\n if (isCustomNetwork || simulationFails) {\n log(\n isCustomNetwork\n ? 'Using original estimate as custom network'\n : 'Using original fallback estimate as simulation failed',\n );\n return [estimatedGas, simulationFails, estimatedGas];\n }\n\n const bufferMultiplier =\n GAS_BUFFER_CHAIN_OVERRIDES[\n chainId as keyof typeof GAS_BUFFER_CHAIN_OVERRIDES\n ] ?? DEFAULT_GAS_MULTIPLIER;\n\n const bufferedGas = addGasBuffer(\n estimatedGas,\n blockGasLimit,\n bufferMultiplier,\n );\n\n return [bufferedGas, simulationFails, estimatedGas];\n}\n\n/**\n * Determine if the gas for the provided request should be fixed.\n *\n * @param options - The options object.\n * @param options.ethQuery - The EthQuery instance to interact with the network.\n * @param options.txMeta - The transaction meta object.\n * @param options.isCustomNetwork - Whether the network is a custom network.\n * @returns Whether the gas should be fixed.\n */\nasync function requiresFixedGas({\n ethQuery,\n txMeta,\n isCustomNetwork,\n}: UpdateGasRequest): Promise<boolean> {\n const {\n txParams: { to, data },\n } = txMeta;\n\n if (isCustomNetwork || !to || data) {\n return false;\n }\n\n const code = await getCode(ethQuery, to);\n\n return !code || code === '0x';\n}\n\n/**\n * Get the contract code for the provided address.\n *\n * @param ethQuery - The EthQuery instance to interact with the network.\n * @param address - The address to get the code for.\n * @returns The contract code.\n */\nasync function getCode(\n ethQuery: EthQuery,\n address: string,\n): Promise<string | undefined> {\n return await query(ethQuery, 'getCode', [address]);\n}\n\n/**\n * Get the latest block from the network.\n *\n * @param ethQuery - The EthQuery instance to interact with the network.\n * @returns The latest block number.\n */\nasync function getLatestBlock(\n ethQuery: EthQuery,\n): Promise<{ gasLimit: string; number: string }> {\n return await query(ethQuery, 'getBlockByNumber', ['latest', false]);\n}\n"]}
@@ -6,6 +6,7 @@ const logger_1 = require("../logger.cjs");
6
6
  const log = (0, utils_1.createModuleLogger)(logger_1.projectLogger, 'layer-1-gas-fee-flow');
7
7
  /**
8
8
  * Updates the given transactionMeta with the layer 1 gas fee.
9
+ *
9
10
  * @param request - The request to use when getting the layer 1 gas fee.
10
11
  * @param request.provider - Provider used to create a new underlying EthQuery instance
11
12
  * @param request.transactionMeta - The transaction to get the layer 1 gas fee for.
@@ -23,6 +24,7 @@ async function updateTransactionLayer1GasFee(request) {
23
24
  exports.updateTransactionLayer1GasFee = updateTransactionLayer1GasFee;
24
25
  /**
25
26
  * Get the layer 1 gas fee flow for a transaction.
27
+ *
26
28
  * @param transactionMeta - The transaction to get the layer 1 gas fee flow for.
27
29
  * @param layer1GasFeeFlows - The layer 1 gas fee flows to search.
28
30
  * @returns The layer 1 gas fee flow for the transaction, or undefined if none match.
@@ -31,11 +33,13 @@ function getLayer1GasFeeFlow(transactionMeta, layer1GasFeeFlows) {
31
33
  return layer1GasFeeFlows.find((layer1GasFeeFlow) => layer1GasFeeFlow.matchesTransaction(transactionMeta));
32
34
  }
33
35
  /**
34
- * Get the layer 1 gas fee for a transaction and return the layer1Fee.
36
+ * Get the layer 1 gas fee for a transaction.
37
+ *
35
38
  * @param request - The request to use when getting the layer 1 gas fee.
36
39
  * @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.
37
40
  * @param request.provider - The provider to use to get the layer 1 gas fee.
38
41
  * @param request.transactionMeta - The transaction to get the layer 1 gas fee for.
42
+ * @returns The layer 1 gas fee.
39
43
  */
40
44
  async function getTransactionLayer1GasFee({ layer1GasFeeFlows, provider, transactionMeta, }) {
41
45
  const layer1GasFeeFlow = getLayer1GasFeeFlow(transactionMeta, layer1GasFeeFlows);
@@ -1 +1 @@
1
- {"version":3,"file":"layer1-gas-fee-flow.cjs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;QACd,GAAG,CAAC,+BAA+B,EAAE,eAAe,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;QAChE,OAAO,SAAS,CAAC;KAClB;AACH,CAAC;AA9BD,gEA8BC","sourcesContent":["import type { Provider } from '@metamask/network-controller';\nimport { createModuleLogger, type Hex } from '@metamask/utils';\n\nimport { projectLogger } from '../logger';\nimport type { Layer1GasFeeFlow, TransactionMeta } from '../types';\n\nconst log = createModuleLogger(projectLogger, 'layer-1-gas-fee-flow');\n\nexport type UpdateLayer1GasFeeRequest = {\n layer1GasFeeFlows: Layer1GasFeeFlow[];\n provider: Provider;\n transactionMeta: TransactionMeta;\n};\n\n/**\n * Updates the given transactionMeta with the layer 1 gas fee.\n * @param request - The request to use when getting the layer 1 gas fee.\n * @param request.provider - Provider used to create a new underlying EthQuery instance\n * @param request.transactionMeta - The transaction to get the layer 1 gas fee for.\n * @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.\n */\nexport async function updateTransactionLayer1GasFee(\n request: UpdateLayer1GasFeeRequest,\n) {\n const layer1GasFee = await getTransactionLayer1GasFee(request);\n\n if (!layer1GasFee) {\n return;\n }\n\n const { transactionMeta } = request;\n\n transactionMeta.layer1GasFee = layer1GasFee;\n\n log('Updated layer 1 gas fee', layer1GasFee, transactionMeta.id);\n}\n\n/**\n * Get the layer 1 gas fee flow for a transaction.\n * @param transactionMeta - The transaction to get the layer 1 gas fee flow for.\n * @param layer1GasFeeFlows - The layer 1 gas fee flows to search.\n * @returns The layer 1 gas fee flow for the transaction, or undefined if none match.\n */\nfunction getLayer1GasFeeFlow(\n transactionMeta: TransactionMeta,\n layer1GasFeeFlows: Layer1GasFeeFlow[],\n): Layer1GasFeeFlow | undefined {\n return layer1GasFeeFlows.find((layer1GasFeeFlow) =>\n layer1GasFeeFlow.matchesTransaction(transactionMeta),\n );\n}\n\n/**\n * Get the layer 1 gas fee for a transaction and return the layer1Fee.\n * @param request - The request to use when getting the layer 1 gas fee.\n * @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.\n * @param request.provider - The provider to use to get the layer 1 gas fee.\n * @param request.transactionMeta - The transaction to get the layer 1 gas fee for.\n */\nexport async function getTransactionLayer1GasFee({\n layer1GasFeeFlows,\n provider,\n transactionMeta,\n}: UpdateLayer1GasFeeRequest): Promise<Hex | undefined> {\n const layer1GasFeeFlow = getLayer1GasFeeFlow(\n transactionMeta,\n layer1GasFeeFlows,\n );\n\n if (!layer1GasFeeFlow) {\n return undefined;\n }\n\n log(\n 'Found layer 1 gas fee flow',\n layer1GasFeeFlow.constructor.name,\n transactionMeta.id,\n );\n\n try {\n const { layer1Fee } = await layer1GasFeeFlow.getLayer1Fee({\n provider,\n transactionMeta,\n });\n return layer1Fee;\n } catch (error) {\n log('Failed to get layer 1 gas fee', transactionMeta.id, error);\n return undefined;\n }\n}\n"]}
1
+ {"version":3,"file":"layer1-gas-fee-flow.cjs","sourceRoot":"","sources":["../../src/utils/layer1-gas-fee-flow.ts"],"names":[],"mappings":";;;AACA,2CAA+D;AAE/D,0CAA0C;AAG1C,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAa,EAAE,sBAAsB,CAAC,CAAC;AAQtE;;;;;;;GAOG;AACI,KAAK,UAAU,6BAA6B,CACjD,OAAkC;IAElC,MAAM,YAAY,GAAG,MAAM,0BAA0B,CAAC,OAAO,CAAC,CAAC;IAE/D,IAAI,CAAC,YAAY,EAAE;QACjB,OAAO;KACR;IAED,MAAM,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC;IAEpC,eAAe,CAAC,YAAY,GAAG,YAAY,CAAC;IAE5C,GAAG,CAAC,yBAAyB,EAAE,YAAY,EAAE,eAAe,CAAC,EAAE,CAAC,CAAC;AACnE,CAAC;AAdD,sEAcC;AAED;;;;;;GAMG;AACH,SAAS,mBAAmB,CAC1B,eAAgC,EAChC,iBAAqC;IAErC,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAC,gBAAgB,EAAE,EAAE,CACjD,gBAAgB,CAAC,kBAAkB,CAAC,eAAe,CAAC,CACrD,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACI,KAAK,UAAU,0BAA0B,CAAC,EAC/C,iBAAiB,EACjB,QAAQ,EACR,eAAe,GACW;IAC1B,MAAM,gBAAgB,GAAG,mBAAmB,CAC1C,eAAe,EACf,iBAAiB,CAClB,CAAC;IAEF,IAAI,CAAC,gBAAgB,EAAE;QACrB,OAAO,SAAS,CAAC;KAClB;IAED,GAAG,CACD,4BAA4B,EAC5B,gBAAgB,CAAC,WAAW,CAAC,IAAI,EACjC,eAAe,CAAC,EAAE,CACnB,CAAC;IAEF,IAAI;QACF,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,gBAAgB,CAAC,YAAY,CAAC;YACxD,QAAQ;YACR,eAAe;SAChB,CAAC,CAAC;QACH,OAAO,SAAS,CAAC;KAClB;IAAC,OAAO,KAAK,EAAE;QACd,GAAG,CAAC,+BAA+B,EAAE,eAAe,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;QAChE,OAAO,SAAS,CAAC;KAClB;AACH,CAAC;AA9BD,gEA8BC","sourcesContent":["import type { Provider } from '@metamask/network-controller';\nimport { createModuleLogger, type Hex } from '@metamask/utils';\n\nimport { projectLogger } from '../logger';\nimport type { Layer1GasFeeFlow, TransactionMeta } from '../types';\n\nconst log = createModuleLogger(projectLogger, 'layer-1-gas-fee-flow');\n\nexport type UpdateLayer1GasFeeRequest = {\n layer1GasFeeFlows: Layer1GasFeeFlow[];\n provider: Provider;\n transactionMeta: TransactionMeta;\n};\n\n/**\n * Updates the given transactionMeta with the layer 1 gas fee.\n *\n * @param request - The request to use when getting the layer 1 gas fee.\n * @param request.provider - Provider used to create a new underlying EthQuery instance\n * @param request.transactionMeta - The transaction to get the layer 1 gas fee for.\n * @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.\n */\nexport async function updateTransactionLayer1GasFee(\n request: UpdateLayer1GasFeeRequest,\n) {\n const layer1GasFee = await getTransactionLayer1GasFee(request);\n\n if (!layer1GasFee) {\n return;\n }\n\n const { transactionMeta } = request;\n\n transactionMeta.layer1GasFee = layer1GasFee;\n\n log('Updated layer 1 gas fee', layer1GasFee, transactionMeta.id);\n}\n\n/**\n * Get the layer 1 gas fee flow for a transaction.\n *\n * @param transactionMeta - The transaction to get the layer 1 gas fee flow for.\n * @param layer1GasFeeFlows - The layer 1 gas fee flows to search.\n * @returns The layer 1 gas fee flow for the transaction, or undefined if none match.\n */\nfunction getLayer1GasFeeFlow(\n transactionMeta: TransactionMeta,\n layer1GasFeeFlows: Layer1GasFeeFlow[],\n): Layer1GasFeeFlow | undefined {\n return layer1GasFeeFlows.find((layer1GasFeeFlow) =>\n layer1GasFeeFlow.matchesTransaction(transactionMeta),\n );\n}\n\n/**\n * Get the layer 1 gas fee for a transaction.\n *\n * @param request - The request to use when getting the layer 1 gas fee.\n * @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.\n * @param request.provider - The provider to use to get the layer 1 gas fee.\n * @param request.transactionMeta - The transaction to get the layer 1 gas fee for.\n * @returns The layer 1 gas fee.\n */\nexport async function getTransactionLayer1GasFee({\n layer1GasFeeFlows,\n provider,\n transactionMeta,\n}: UpdateLayer1GasFeeRequest): Promise<Hex | undefined> {\n const layer1GasFeeFlow = getLayer1GasFeeFlow(\n transactionMeta,\n layer1GasFeeFlows,\n );\n\n if (!layer1GasFeeFlow) {\n return undefined;\n }\n\n log(\n 'Found layer 1 gas fee flow',\n layer1GasFeeFlow.constructor.name,\n transactionMeta.id,\n );\n\n try {\n const { layer1Fee } = await layer1GasFeeFlow.getLayer1Fee({\n provider,\n transactionMeta,\n });\n return layer1Fee;\n } catch (error) {\n log('Failed to get layer 1 gas fee', transactionMeta.id, error);\n return undefined;\n }\n}\n"]}
@@ -8,6 +8,7 @@ export type UpdateLayer1GasFeeRequest = {
8
8
  };
9
9
  /**
10
10
  * Updates the given transactionMeta with the layer 1 gas fee.
11
+ *
11
12
  * @param request - The request to use when getting the layer 1 gas fee.
12
13
  * @param request.provider - Provider used to create a new underlying EthQuery instance
13
14
  * @param request.transactionMeta - The transaction to get the layer 1 gas fee for.
@@ -15,11 +16,13 @@ export type UpdateLayer1GasFeeRequest = {
15
16
  */
16
17
  export declare function updateTransactionLayer1GasFee(request: UpdateLayer1GasFeeRequest): Promise<void>;
17
18
  /**
18
- * Get the layer 1 gas fee for a transaction and return the layer1Fee.
19
+ * Get the layer 1 gas fee for a transaction.
20
+ *
19
21
  * @param request - The request to use when getting the layer 1 gas fee.
20
22
  * @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.
21
23
  * @param request.provider - The provider to use to get the layer 1 gas fee.
22
24
  * @param request.transactionMeta - The transaction to get the layer 1 gas fee for.
25
+ * @returns The layer 1 gas fee.
23
26
  */
24
27
  export declare function getTransactionLayer1GasFee({ layer1GasFeeFlows, provider, transactionMeta, }: UpdateLayer1GasFeeRequest): Promise<Hex | undefined>;
25
28
  //# sourceMappingURL=layer1-gas-fee-flow.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"layer1-gas-fee-flow.d.cts","sourceRoot":"","sources":["../../src/utils/layer1-gas-fee-flow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,qCAAqC;AAC7D,OAAO,EAAsB,KAAK,GAAG,EAAE,wBAAwB;AAG/D,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,qBAAiB;AAIlE,MAAM,MAAM,yBAAyB,GAAG;IACtC,iBAAiB,EAAE,gBAAgB,EAAE,CAAC;IACtC,QAAQ,EAAE,QAAQ,CAAC;IACnB,eAAe,EAAE,eAAe,CAAC;CAClC,CAAC;AAEF;;;;;;GAMG;AACH,wBAAsB,6BAA6B,CACjD,OAAO,EAAE,yBAAyB,iBAanC;AAiBD;;;;;;GAMG;AACH,wBAAsB,0BAA0B,CAAC,EAC/C,iBAAiB,EACjB,QAAQ,EACR,eAAe,GAChB,EAAE,yBAAyB,GAAG,OAAO,CAAC,GAAG,GAAG,SAAS,CAAC,CA0BtD"}
1
+ {"version":3,"file":"layer1-gas-fee-flow.d.cts","sourceRoot":"","sources":["../../src/utils/layer1-gas-fee-flow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,qCAAqC;AAC7D,OAAO,EAAsB,KAAK,GAAG,EAAE,wBAAwB;AAG/D,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,qBAAiB;AAIlE,MAAM,MAAM,yBAAyB,GAAG;IACtC,iBAAiB,EAAE,gBAAgB,EAAE,CAAC;IACtC,QAAQ,EAAE,QAAQ,CAAC;IACnB,eAAe,EAAE,eAAe,CAAC;CAClC,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAsB,6BAA6B,CACjD,OAAO,EAAE,yBAAyB,iBAanC;AAkBD;;;;;;;;GAQG;AACH,wBAAsB,0BAA0B,CAAC,EAC/C,iBAAiB,EACjB,QAAQ,EACR,eAAe,GAChB,EAAE,yBAAyB,GAAG,OAAO,CAAC,GAAG,GAAG,SAAS,CAAC,CA0BtD"}
@@ -8,6 +8,7 @@ export type UpdateLayer1GasFeeRequest = {
8
8
  };
9
9
  /**
10
10
  * Updates the given transactionMeta with the layer 1 gas fee.
11
+ *
11
12
  * @param request - The request to use when getting the layer 1 gas fee.
12
13
  * @param request.provider - Provider used to create a new underlying EthQuery instance
13
14
  * @param request.transactionMeta - The transaction to get the layer 1 gas fee for.
@@ -15,11 +16,13 @@ export type UpdateLayer1GasFeeRequest = {
15
16
  */
16
17
  export declare function updateTransactionLayer1GasFee(request: UpdateLayer1GasFeeRequest): Promise<void>;
17
18
  /**
18
- * Get the layer 1 gas fee for a transaction and return the layer1Fee.
19
+ * Get the layer 1 gas fee for a transaction.
20
+ *
19
21
  * @param request - The request to use when getting the layer 1 gas fee.
20
22
  * @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.
21
23
  * @param request.provider - The provider to use to get the layer 1 gas fee.
22
24
  * @param request.transactionMeta - The transaction to get the layer 1 gas fee for.
25
+ * @returns The layer 1 gas fee.
23
26
  */
24
27
  export declare function getTransactionLayer1GasFee({ layer1GasFeeFlows, provider, transactionMeta, }: UpdateLayer1GasFeeRequest): Promise<Hex | undefined>;
25
28
  //# sourceMappingURL=layer1-gas-fee-flow.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"layer1-gas-fee-flow.d.mts","sourceRoot":"","sources":["../../src/utils/layer1-gas-fee-flow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,qCAAqC;AAC7D,OAAO,EAAsB,KAAK,GAAG,EAAE,wBAAwB;AAG/D,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,qBAAiB;AAIlE,MAAM,MAAM,yBAAyB,GAAG;IACtC,iBAAiB,EAAE,gBAAgB,EAAE,CAAC;IACtC,QAAQ,EAAE,QAAQ,CAAC;IACnB,eAAe,EAAE,eAAe,CAAC;CAClC,CAAC;AAEF;;;;;;GAMG;AACH,wBAAsB,6BAA6B,CACjD,OAAO,EAAE,yBAAyB,iBAanC;AAiBD;;;;;;GAMG;AACH,wBAAsB,0BAA0B,CAAC,EAC/C,iBAAiB,EACjB,QAAQ,EACR,eAAe,GAChB,EAAE,yBAAyB,GAAG,OAAO,CAAC,GAAG,GAAG,SAAS,CAAC,CA0BtD"}
1
+ {"version":3,"file":"layer1-gas-fee-flow.d.mts","sourceRoot":"","sources":["../../src/utils/layer1-gas-fee-flow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,qCAAqC;AAC7D,OAAO,EAAsB,KAAK,GAAG,EAAE,wBAAwB;AAG/D,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,qBAAiB;AAIlE,MAAM,MAAM,yBAAyB,GAAG;IACtC,iBAAiB,EAAE,gBAAgB,EAAE,CAAC;IACtC,QAAQ,EAAE,QAAQ,CAAC;IACnB,eAAe,EAAE,eAAe,CAAC;CAClC,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAsB,6BAA6B,CACjD,OAAO,EAAE,yBAAyB,iBAanC;AAkBD;;;;;;;;GAQG;AACH,wBAAsB,0BAA0B,CAAC,EAC/C,iBAAiB,EACjB,QAAQ,EACR,eAAe,GAChB,EAAE,yBAAyB,GAAG,OAAO,CAAC,GAAG,GAAG,SAAS,CAAC,CA0BtD"}
@@ -3,6 +3,7 @@ import { projectLogger } from "../logger.mjs";
3
3
  const log = createModuleLogger(projectLogger, 'layer-1-gas-fee-flow');
4
4
  /**
5
5
  * Updates the given transactionMeta with the layer 1 gas fee.
6
+ *
6
7
  * @param request - The request to use when getting the layer 1 gas fee.
7
8
  * @param request.provider - Provider used to create a new underlying EthQuery instance
8
9
  * @param request.transactionMeta - The transaction to get the layer 1 gas fee for.
@@ -19,6 +20,7 @@ export async function updateTransactionLayer1GasFee(request) {
19
20
  }
20
21
  /**
21
22
  * Get the layer 1 gas fee flow for a transaction.
23
+ *
22
24
  * @param transactionMeta - The transaction to get the layer 1 gas fee flow for.
23
25
  * @param layer1GasFeeFlows - The layer 1 gas fee flows to search.
24
26
  * @returns The layer 1 gas fee flow for the transaction, or undefined if none match.
@@ -27,11 +29,13 @@ function getLayer1GasFeeFlow(transactionMeta, layer1GasFeeFlows) {
27
29
  return layer1GasFeeFlows.find((layer1GasFeeFlow) => layer1GasFeeFlow.matchesTransaction(transactionMeta));
28
30
  }
29
31
  /**
30
- * Get the layer 1 gas fee for a transaction and return the layer1Fee.
32
+ * Get the layer 1 gas fee for a transaction.
33
+ *
31
34
  * @param request - The request to use when getting the layer 1 gas fee.
32
35
  * @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.
33
36
  * @param request.provider - The provider to use to get the layer 1 gas fee.
34
37
  * @param request.transactionMeta - The transaction to get the layer 1 gas fee for.
38
+ * @returns The layer 1 gas fee.
35
39
  */
36
40
  export async function getTransactionLayer1GasFee({ layer1GasFeeFlows, provider, transactionMeta, }) {
37
41
  const layer1GasFeeFlow = getLayer1GasFeeFlow(transactionMeta, layer1GasFeeFlows);
@@ -1 +1 @@
1
- {"version":3,"file":"layer1-gas-fee-flow.mjs","sourceRoot":"","sources":["../../src/utils/layer1-gas-fee-flow.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAY,wBAAwB;AAE/D,OAAO,EAAE,aAAa,EAAE,sBAAkB;AAG1C,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,sBAAsB,CAAC,CAAC;AAQtE;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,6BAA6B,CACjD,OAAkC;IAElC,MAAM,YAAY,GAAG,MAAM,0BAA0B,CAAC,OAAO,CAAC,CAAC;IAE/D,IAAI,CAAC,YAAY,EAAE;QACjB,OAAO;KACR;IAED,MAAM,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC;IAEpC,eAAe,CAAC,YAAY,GAAG,YAAY,CAAC;IAE5C,GAAG,CAAC,yBAAyB,EAAE,YAAY,EAAE,eAAe,CAAC,EAAE,CAAC,CAAC;AACnE,CAAC;AAED;;;;;GAKG;AACH,SAAS,mBAAmB,CAC1B,eAAgC,EAChC,iBAAqC;IAErC,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAC,gBAAgB,EAAE,EAAE,CACjD,gBAAgB,CAAC,kBAAkB,CAAC,eAAe,CAAC,CACrD,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAAC,EAC/C,iBAAiB,EACjB,QAAQ,EACR,eAAe,GACW;IAC1B,MAAM,gBAAgB,GAAG,mBAAmB,CAC1C,eAAe,EACf,iBAAiB,CAClB,CAAC;IAEF,IAAI,CAAC,gBAAgB,EAAE;QACrB,OAAO,SAAS,CAAC;KAClB;IAED,GAAG,CACD,4BAA4B,EAC5B,gBAAgB,CAAC,WAAW,CAAC,IAAI,EACjC,eAAe,CAAC,EAAE,CACnB,CAAC;IAEF,IAAI;QACF,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,gBAAgB,CAAC,YAAY,CAAC;YACxD,QAAQ;YACR,eAAe;SAChB,CAAC,CAAC;QACH,OAAO,SAAS,CAAC;KAClB;IAAC,OAAO,KAAK,EAAE;QACd,GAAG,CAAC,+BAA+B,EAAE,eAAe,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;QAChE,OAAO,SAAS,CAAC;KAClB;AACH,CAAC","sourcesContent":["import type { Provider } from '@metamask/network-controller';\nimport { createModuleLogger, type Hex } from '@metamask/utils';\n\nimport { projectLogger } from '../logger';\nimport type { Layer1GasFeeFlow, TransactionMeta } from '../types';\n\nconst log = createModuleLogger(projectLogger, 'layer-1-gas-fee-flow');\n\nexport type UpdateLayer1GasFeeRequest = {\n layer1GasFeeFlows: Layer1GasFeeFlow[];\n provider: Provider;\n transactionMeta: TransactionMeta;\n};\n\n/**\n * Updates the given transactionMeta with the layer 1 gas fee.\n * @param request - The request to use when getting the layer 1 gas fee.\n * @param request.provider - Provider used to create a new underlying EthQuery instance\n * @param request.transactionMeta - The transaction to get the layer 1 gas fee for.\n * @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.\n */\nexport async function updateTransactionLayer1GasFee(\n request: UpdateLayer1GasFeeRequest,\n) {\n const layer1GasFee = await getTransactionLayer1GasFee(request);\n\n if (!layer1GasFee) {\n return;\n }\n\n const { transactionMeta } = request;\n\n transactionMeta.layer1GasFee = layer1GasFee;\n\n log('Updated layer 1 gas fee', layer1GasFee, transactionMeta.id);\n}\n\n/**\n * Get the layer 1 gas fee flow for a transaction.\n * @param transactionMeta - The transaction to get the layer 1 gas fee flow for.\n * @param layer1GasFeeFlows - The layer 1 gas fee flows to search.\n * @returns The layer 1 gas fee flow for the transaction, or undefined if none match.\n */\nfunction getLayer1GasFeeFlow(\n transactionMeta: TransactionMeta,\n layer1GasFeeFlows: Layer1GasFeeFlow[],\n): Layer1GasFeeFlow | undefined {\n return layer1GasFeeFlows.find((layer1GasFeeFlow) =>\n layer1GasFeeFlow.matchesTransaction(transactionMeta),\n );\n}\n\n/**\n * Get the layer 1 gas fee for a transaction and return the layer1Fee.\n * @param request - The request to use when getting the layer 1 gas fee.\n * @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.\n * @param request.provider - The provider to use to get the layer 1 gas fee.\n * @param request.transactionMeta - The transaction to get the layer 1 gas fee for.\n */\nexport async function getTransactionLayer1GasFee({\n layer1GasFeeFlows,\n provider,\n transactionMeta,\n}: UpdateLayer1GasFeeRequest): Promise<Hex | undefined> {\n const layer1GasFeeFlow = getLayer1GasFeeFlow(\n transactionMeta,\n layer1GasFeeFlows,\n );\n\n if (!layer1GasFeeFlow) {\n return undefined;\n }\n\n log(\n 'Found layer 1 gas fee flow',\n layer1GasFeeFlow.constructor.name,\n transactionMeta.id,\n );\n\n try {\n const { layer1Fee } = await layer1GasFeeFlow.getLayer1Fee({\n provider,\n transactionMeta,\n });\n return layer1Fee;\n } catch (error) {\n log('Failed to get layer 1 gas fee', transactionMeta.id, error);\n return undefined;\n }\n}\n"]}
1
+ {"version":3,"file":"layer1-gas-fee-flow.mjs","sourceRoot":"","sources":["../../src/utils/layer1-gas-fee-flow.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAY,wBAAwB;AAE/D,OAAO,EAAE,aAAa,EAAE,sBAAkB;AAG1C,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,sBAAsB,CAAC,CAAC;AAQtE;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,6BAA6B,CACjD,OAAkC;IAElC,MAAM,YAAY,GAAG,MAAM,0BAA0B,CAAC,OAAO,CAAC,CAAC;IAE/D,IAAI,CAAC,YAAY,EAAE;QACjB,OAAO;KACR;IAED,MAAM,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC;IAEpC,eAAe,CAAC,YAAY,GAAG,YAAY,CAAC;IAE5C,GAAG,CAAC,yBAAyB,EAAE,YAAY,EAAE,eAAe,CAAC,EAAE,CAAC,CAAC;AACnE,CAAC;AAED;;;;;;GAMG;AACH,SAAS,mBAAmB,CAC1B,eAAgC,EAChC,iBAAqC;IAErC,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAC,gBAAgB,EAAE,EAAE,CACjD,gBAAgB,CAAC,kBAAkB,CAAC,eAAe,CAAC,CACrD,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAAC,EAC/C,iBAAiB,EACjB,QAAQ,EACR,eAAe,GACW;IAC1B,MAAM,gBAAgB,GAAG,mBAAmB,CAC1C,eAAe,EACf,iBAAiB,CAClB,CAAC;IAEF,IAAI,CAAC,gBAAgB,EAAE;QACrB,OAAO,SAAS,CAAC;KAClB;IAED,GAAG,CACD,4BAA4B,EAC5B,gBAAgB,CAAC,WAAW,CAAC,IAAI,EACjC,eAAe,CAAC,EAAE,CACnB,CAAC;IAEF,IAAI;QACF,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,gBAAgB,CAAC,YAAY,CAAC;YACxD,QAAQ;YACR,eAAe;SAChB,CAAC,CAAC;QACH,OAAO,SAAS,CAAC;KAClB;IAAC,OAAO,KAAK,EAAE;QACd,GAAG,CAAC,+BAA+B,EAAE,eAAe,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;QAChE,OAAO,SAAS,CAAC;KAClB;AACH,CAAC","sourcesContent":["import type { Provider } from '@metamask/network-controller';\nimport { createModuleLogger, type Hex } from '@metamask/utils';\n\nimport { projectLogger } from '../logger';\nimport type { Layer1GasFeeFlow, TransactionMeta } from '../types';\n\nconst log = createModuleLogger(projectLogger, 'layer-1-gas-fee-flow');\n\nexport type UpdateLayer1GasFeeRequest = {\n layer1GasFeeFlows: Layer1GasFeeFlow[];\n provider: Provider;\n transactionMeta: TransactionMeta;\n};\n\n/**\n * Updates the given transactionMeta with the layer 1 gas fee.\n *\n * @param request - The request to use when getting the layer 1 gas fee.\n * @param request.provider - Provider used to create a new underlying EthQuery instance\n * @param request.transactionMeta - The transaction to get the layer 1 gas fee for.\n * @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.\n */\nexport async function updateTransactionLayer1GasFee(\n request: UpdateLayer1GasFeeRequest,\n) {\n const layer1GasFee = await getTransactionLayer1GasFee(request);\n\n if (!layer1GasFee) {\n return;\n }\n\n const { transactionMeta } = request;\n\n transactionMeta.layer1GasFee = layer1GasFee;\n\n log('Updated layer 1 gas fee', layer1GasFee, transactionMeta.id);\n}\n\n/**\n * Get the layer 1 gas fee flow for a transaction.\n *\n * @param transactionMeta - The transaction to get the layer 1 gas fee flow for.\n * @param layer1GasFeeFlows - The layer 1 gas fee flows to search.\n * @returns The layer 1 gas fee flow for the transaction, or undefined if none match.\n */\nfunction getLayer1GasFeeFlow(\n transactionMeta: TransactionMeta,\n layer1GasFeeFlows: Layer1GasFeeFlow[],\n): Layer1GasFeeFlow | undefined {\n return layer1GasFeeFlows.find((layer1GasFeeFlow) =>\n layer1GasFeeFlow.matchesTransaction(transactionMeta),\n );\n}\n\n/**\n * Get the layer 1 gas fee for a transaction.\n *\n * @param request - The request to use when getting the layer 1 gas fee.\n * @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.\n * @param request.provider - The provider to use to get the layer 1 gas fee.\n * @param request.transactionMeta - The transaction to get the layer 1 gas fee for.\n * @returns The layer 1 gas fee.\n */\nexport async function getTransactionLayer1GasFee({\n layer1GasFeeFlows,\n provider,\n transactionMeta,\n}: UpdateLayer1GasFeeRequest): Promise<Hex | undefined> {\n const layer1GasFeeFlow = getLayer1GasFeeFlow(\n transactionMeta,\n layer1GasFeeFlows,\n );\n\n if (!layer1GasFeeFlow) {\n return undefined;\n }\n\n log(\n 'Found layer 1 gas fee flow',\n layer1GasFeeFlow.constructor.name,\n transactionMeta.id,\n );\n\n try {\n const { layer1Fee } = await layer1GasFeeFlow.getLayer1Fee({\n provider,\n transactionMeta,\n });\n return layer1Fee;\n } catch (error) {\n log('Failed to get layer 1 gas fee', transactionMeta.id, error);\n return undefined;\n }\n}\n"]}
@@ -5,6 +5,7 @@ const controller_utils_1 = require("@metamask/controller-utils");
5
5
  const utils_1 = require("@metamask/utils");
6
6
  /**
7
7
  * Returns new transaction parameters with increased gas fees.
8
+ *
8
9
  * @param originalTransactionParams - The original transaction parameters.
9
10
  * @param rate - The rate by which to increase the existing gas fee properties.
10
11
  * @param newGasValues - Optional new gas values to use instead of increased the existing values.
@@ -35,6 +36,7 @@ function getTransactionParamsWithIncreasedGasFee(originalTransactionParams, rate
35
36
  exports.getTransactionParamsWithIncreasedGasFee = getTransactionParamsWithIncreasedGasFee;
36
37
  /**
37
38
  * Generate the increased EIP-1559 gas properties.
39
+ *
38
40
  * @param originalTransactionParams - The original transaction parameters.
39
41
  * @param rate - The rate by which to increase the existing gas fee properties.
40
42
  * @param newGasValues - Optional new gas values to use instead of increased the existing values.
@@ -60,6 +62,7 @@ function getIncreased1559Values(originalTransactionParams, rate, newGasValues) {
60
62
  }
61
63
  /**
62
64
  * Generate the increased gas price.
65
+ *
63
66
  * @param originalTransactionParams - The original transaction parameters.
64
67
  * @param rate - The rate by which to increase the existing gas fee properties.
65
68
  * @param newGasValues - Optional new gas values to use instead of increased the existing values.
@@ -77,6 +80,7 @@ function getIncreasedGasPrice(originalTransactionParams, rate, newGasValues) {
77
80
  }
78
81
  /**
79
82
  * Multiply a hex value by a multiplier.
83
+ *
80
84
  * @param value - The hex value to multiply.
81
85
  * @param multiplier - The multiplier.
82
86
  * @returns The multiplied hex value.
@@ -1 +1 @@
1
- {"version":3,"file":"retry.cjs","sourceRoot":"","sources":["../../src/utils/retry.ts"],"names":[],"mappings":";;;AAAA,iEAAiE;AAEjE,2CAAwC;AAKxC;;;;;;GAMG;AACH,SAAgB,uCAAuC,CACrD,yBAA4C,EAC5C,IAAY,EACZ,YAAqD;IAErD,MAAM,WAAW,GAAG,oBAAoB,CACtC,yBAAyB,EACzB,IAAI,EACJ,YAAY,CACb,CAAC;IAEF,MAAM,aAAa,GAAG,s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AAI,YAAY,IAAI,UAAU,IAAI,YAAY,EAAE;QAC9C,OAAO,YAAY,CAAC,QAAe,CAAC;KACrC;IAED,MAAM,eAAe,GAAG,yBAAyB,CAAC,QAA2B,CAAC;IAE9E,IAAI,CAAC,eAAe,IAAI,eAAe,KAAK,KAAK,EAAE;QACjD,OAAO,SAAS,CAAC;KAClB;IAED,OAAO,WAAW,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;AAC5C,CAAC;AAED;;;;;GAKG;AACH,SAAS,WAAW,CAAC,KAAsB,EAAE,UAAkB;IAC7D,MAAM,YAAY,GAAG,IAAA,sCAAmB,EAAC,KAAK,CAAC,CAAC;IAChD,MAAM,aAAa,GAAG,QAAQ,CAAC,GAAG,YAAY,GAAG,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC;IAEnE,OAAO,IAAA,aAAK,EAAC,aAAa,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["import { convertHexToDecimal } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\nimport { add0x } from '@metamask/utils';\n\nimport type { FeeMarketEIP1559Values, GasPriceValue } from '../types';\nimport { type TransactionParams } from '../types';\n\n/**\n * Returns new transaction parameters with increased gas fees.\n * @param originalTransactionParams - The original transaction parameters.\n * @param rate - The rate by which to increase the existing gas fee properties.\n * @param newGasValues - Optional new gas values to use instead of increased the existing values.\n * @returns The new transaction parameters with the increased gas fee properties.\n */\nexport function getTransactionParamsWithIncreasedGasFee(\n originalTransactionParams: TransactionParams,\n rate: number,\n newGasValues?: GasPriceValue | FeeMarketEIP1559Values,\n): TransactionParams {\n const newGasPrice = getIncreasedGasPrice(\n originalTransactionParams,\n rate,\n newGasValues,\n );\n\n const new1559Values = getIncreased1559Values(\n originalTransactionParams,\n rate,\n newGasValues,\n );\n\n if (new1559Values) {\n const newTxParams: TransactionParams = {\n ...originalTransactionParams,\n ...new1559Values,\n };\n\n delete newTxParams.gasPrice;\n\n return newTxParams;\n }\n\n if (newGasPrice) {\n const newTxParams: TransactionParams = {\n ...originalTransactionParams,\n gasPrice: newGasPrice,\n };\n\n delete newTxParams.maxFeePerGas;\n delete newTxParams.maxPriorityFeePerGas;\n\n return newTxParams;\n }\n\n throw new Error(\n 'Cannot increase gas fee as no current values and no new values were provided',\n );\n}\n\n/**\n * Generate the increased EIP-1559 gas properties.\n * @param originalTransactionParams - The original transaction parameters.\n * @param rate - The rate by which to increase the existing gas fee properties.\n * @param newGasValues - Optional new gas values to use instead of increased the existing values.\n * @returns The new EIP-1559 gas properties.\n */\nfunction getIncreased1559Values(\n originalTransactionParams: TransactionParams,\n rate: number,\n newGasValues?: GasPriceValue | FeeMarketEIP1559Values,\n): FeeMarketEIP1559Values | undefined {\n if (\n newGasValues &&\n 'maxFeePerGas' in newGasValues &&\n 'maxPriorityFeePerGas' in newGasValues\n ) {\n return newGasValues;\n }\n\n const currentMaxFeePerGas = originalTransactionParams.maxFeePerGas as\n | Hex\n | undefined;\n\n const currentMaxPriorityFeePerGas =\n originalTransactionParams.maxPriorityFeePerGas as Hex | undefined;\n\n if (\n !currentMaxFeePerGas ||\n !currentMaxPriorityFeePerGas ||\n currentMaxFeePerGas === '0x0' ||\n currentMaxPriorityFeePerGas === '0x0'\n ) {\n return undefined;\n }\n\n const maxFeePerGas = multiplyHex(currentMaxFeePerGas, rate);\n const maxPriorityFeePerGas = multiplyHex(currentMaxPriorityFeePerGas, rate);\n\n return { maxFeePerGas, maxPriorityFeePerGas };\n}\n\n/**\n * Generate the increased gas price.\n * @param originalTransactionParams - The original transaction parameters.\n * @param rate - The rate by which to increase the existing gas fee properties.\n * @param newGasValues - Optional new gas values to use instead of increased the existing values.\n * @returns The new gas price.\n */\nfunction getIncreasedGasPrice(\n originalTransactionParams: TransactionParams,\n rate: number,\n newGasValues?: GasPriceValue | FeeMarketEIP1559Values,\n): Hex | undefined {\n if (newGasValues && 'gasPrice' in newGasValues) {\n return newGasValues.gasPrice as Hex;\n }\n\n const currentGasPrice = originalTransactionParams.gasPrice as Hex | undefined;\n\n if (!currentGasPrice || currentGasPrice === '0x0') {\n return undefined;\n }\n\n return multiplyHex(currentGasPrice, rate);\n}\n\n/**\n * Multiply a hex value by a multiplier.\n * @param value - The hex value to multiply.\n * @param multiplier - The multiplier.\n * @returns The multiplied hex value.\n */\nfunction multiplyHex(value: Hex | undefined, multiplier: number): Hex {\n const decimalValue = convertHexToDecimal(value);\n const decimalResult = parseInt(`${decimalValue * multiplier}`, 10);\n\n return add0x(decimalResult.toString(16));\n}\n"]}
1
+ {"version":3,"file":"retry.cjs","sourceRoot":"","sources":["../../src/utils/retry.ts"],"names":[],"mappings":";;;AAAA,iEAAiE;AAEjE,2CAAwC;AAKxC;;;;;;;GAOG;AACH,SAAgB,uCAAuC,CACrD,yBAA4C,EAC5C,IAAY,EACZ,YAAqD;IAErD,MAAM,WAAW,GAAG,oBAAoB,CACtC,yBAAyB,EACzB,IAAI,EACJ,YAAY,CACb,CAAC;IAEF,MAAM,aAAa,GAAG,sBAAsB,CAC1C,yBAAyB,EACzB,IAAI,EACJ,YAAY,CACb,CAAC;IAEF,IAAI,aAAa,EAAE;QACjB,MAAM,WAAW,GAAsB;YACrC,GAAG,yBAAyB;YAC5B,GAAG,aAAa;SACjB,CAAC;QAEF,OAAO,WAAW,CAAC,QAAQ,CAAC;QAE5B,OAAO,WAAW,CAAC;KACpB;IAED,IAAI,WAAW,EAAE;QACf,MAAM,WAAW,GAAsB;YACrC,GAAG,yBAAyB;YAC5B,QAAQ,EAAE,WAAW;SACtB,CAAC;QAEF,OAAO,WAAW,CAAC,YAAY,CAAC;QAChC,OAAO,WAAW,CAAC,oBAAoB,CAAC;QAExC,OAAO,WAAW,CAAC;KACpB;IAED,MAAM,IAAI,KAAK,CACb,8EAA8E,CAC/E,CAAC;AACJ,CAAC;AA3CD,0FA2CC;AAED;;;;;;;GAOG;AACH,SAAS,sBAAsB,CAC7B,yBAA4C,EAC5C,IAAY,EACZ,YAAqD;IAEr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sourcesContent":["import { convertHexToDecimal } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\nimport { add0x } from '@metamask/utils';\n\nimport type { FeeMarketEIP1559Values, GasPriceValue } from '../types';\nimport { type TransactionParams } from '../types';\n\n/**\n * Returns new transaction parameters with increased gas fees.\n *\n * @param originalTransactionParams - The original transaction parameters.\n * @param rate - The rate by which to increase the existing gas fee properties.\n * @param newGasValues - Optional new gas values to use instead of increased the existing values.\n * @returns The new transaction parameters with the increased gas fee properties.\n */\nexport function getTransactionParamsWithIncreasedGasFee(\n originalTransactionParams: TransactionParams,\n rate: number,\n newGasValues?: GasPriceValue | FeeMarketEIP1559Values,\n): TransactionParams {\n const newGasPrice = getIncreasedGasPrice(\n originalTransactionParams,\n rate,\n newGasValues,\n );\n\n const new1559Values = getIncreased1559Values(\n originalTransactionParams,\n rate,\n newGasValues,\n );\n\n if (new1559Values) {\n const newTxParams: TransactionParams = {\n ...originalTransactionParams,\n ...new1559Values,\n };\n\n delete newTxParams.gasPrice;\n\n return newTxParams;\n }\n\n if (newGasPrice) {\n const newTxParams: TransactionParams = {\n ...originalTransactionParams,\n gasPrice: newGasPrice,\n };\n\n delete newTxParams.maxFeePerGas;\n delete newTxParams.maxPriorityFeePerGas;\n\n return newTxParams;\n }\n\n throw new Error(\n 'Cannot increase gas fee as no current values and no new values were provided',\n );\n}\n\n/**\n * Generate the increased EIP-1559 gas properties.\n *\n * @param originalTransactionParams - The original transaction parameters.\n * @param rate - The rate by which to increase the existing gas fee properties.\n * @param newGasValues - Optional new gas values to use instead of increased the existing values.\n * @returns The new EIP-1559 gas properties.\n */\nfunction getIncreased1559Values(\n originalTransactionParams: TransactionParams,\n rate: number,\n newGasValues?: GasPriceValue | FeeMarketEIP1559Values,\n): FeeMarketEIP1559Values | undefined {\n if (\n newGasValues &&\n 'maxFeePerGas' in newGasValues &&\n 'maxPriorityFeePerGas' in newGasValues\n ) {\n return newGasValues;\n }\n\n const currentMaxFeePerGas = originalTransactionParams.maxFeePerGas as\n | Hex\n | undefined;\n\n const currentMaxPriorityFeePerGas =\n originalTransactionParams.maxPriorityFeePerGas as Hex | undefined;\n\n if (\n !currentMaxFeePerGas ||\n !currentMaxPriorityFeePerGas ||\n currentMaxFeePerGas === '0x0' ||\n currentMaxPriorityFeePerGas === '0x0'\n ) {\n return undefined;\n }\n\n const maxFeePerGas = multiplyHex(currentMaxFeePerGas, rate);\n const maxPriorityFeePerGas = multiplyHex(currentMaxPriorityFeePerGas, rate);\n\n return { maxFeePerGas, maxPriorityFeePerGas };\n}\n\n/**\n * Generate the increased gas price.\n *\n * @param originalTransactionParams - The original transaction parameters.\n * @param rate - The rate by which to increase the existing gas fee properties.\n * @param newGasValues - Optional new gas values to use instead of increased the existing values.\n * @returns The new gas price.\n */\nfunction getIncreasedGasPrice(\n originalTransactionParams: TransactionParams,\n rate: number,\n newGasValues?: GasPriceValue | FeeMarketEIP1559Values,\n): Hex | undefined {\n if (newGasValues && 'gasPrice' in newGasValues) {\n return newGasValues.gasPrice as Hex;\n }\n\n const currentGasPrice = originalTransactionParams.gasPrice as Hex | undefined;\n\n if (!currentGasPrice || currentGasPrice === '0x0') {\n return undefined;\n }\n\n return multiplyHex(currentGasPrice, rate);\n}\n\n/**\n * Multiply a hex value by a multiplier.\n *\n * @param value - The hex value to multiply.\n * @param multiplier - The multiplier.\n * @returns The multiplied hex value.\n */\nfunction multiplyHex(value: Hex | undefined, multiplier: number): Hex {\n const decimalValue = convertHexToDecimal(value);\n const decimalResult = parseInt(`${decimalValue * multiplier}`, 10);\n\n return add0x(decimalResult.toString(16));\n}\n"]}
@@ -2,6 +2,7 @@ import type { FeeMarketEIP1559Values, GasPriceValue } from "../types.cjs";
2
2
  import { type TransactionParams } from "../types.cjs";
3
3
  /**
4
4
  * Returns new transaction parameters with increased gas fees.
5
+ *
5
6
  * @param originalTransactionParams - The original transaction parameters.
6
7
  * @param rate - The rate by which to increase the existing gas fee properties.
7
8
  * @param newGasValues - Optional new gas values to use instead of increased the existing values.
@@ -1 +1 @@
1
- {"version":3,"file":"retry.d.cts","sourceRoot":"","sources":["../../src/utils/retry.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,sBAAsB,EAAE,aAAa,EAAE,qBAAiB;AACtE,OAAO,EAAE,KAAK,iBAAiB,EAAE,qBAAiB;AAElD;;;;;;GAMG;AACH,wBAAgB,uCAAuC,CACrD,yBAAyB,EAAE,iBAAiB,EAC5C,IAAI,EAAE,MAAM,EACZ,YAAY,CAAC,EAAE,aAAa,GAAG,sBAAsB,GACpD,iBAAiB,CAuCnB"}
1
+ {"version":3,"file":"retry.d.cts","sourceRoot":"","sources":["../../src/utils/retry.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,sBAAsB,EAAE,aAAa,EAAE,qBAAiB;AACtE,OAAO,EAAE,KAAK,iBAAiB,EAAE,qBAAiB;AAElD;;;;;;;GAOG;AACH,wBAAgB,uCAAuC,CACrD,yBAAyB,EAAE,iBAAiB,EAC5C,IAAI,EAAE,MAAM,EACZ,YAAY,CAAC,EAAE,aAAa,GAAG,sBAAsB,GACpD,iBAAiB,CAuCnB"}
@@ -2,6 +2,7 @@ import type { FeeMarketEIP1559Values, GasPriceValue } from "../types.mjs";
2
2
  import { type TransactionParams } from "../types.mjs";
3
3
  /**
4
4
  * Returns new transaction parameters with increased gas fees.
5
+ *
5
6
  * @param originalTransactionParams - The original transaction parameters.
6
7
  * @param rate - The rate by which to increase the existing gas fee properties.
7
8
  * @param newGasValues - Optional new gas values to use instead of increased the existing values.
@@ -1 +1 @@
1
- {"version":3,"file":"retry.d.mts","sourceRoot":"","sources":["../../src/utils/retry.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,sBAAsB,EAAE,aAAa,EAAE,qBAAiB;AACtE,OAAO,EAAE,KAAK,iBAAiB,EAAE,qBAAiB;AAElD;;;;;;GAMG;AACH,wBAAgB,uCAAuC,CACrD,yBAAyB,EAAE,iBAAiB,EAC5C,IAAI,EAAE,MAAM,EACZ,YAAY,CAAC,EAAE,aAAa,GAAG,sBAAsB,GACpD,iBAAiB,CAuCnB"}
1
+ {"version":3,"file":"retry.d.mts","sourceRoot":"","sources":["../../src/utils/retry.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,sBAAsB,EAAE,aAAa,EAAE,qBAAiB;AACtE,OAAO,EAAE,KAAK,iBAAiB,EAAE,qBAAiB;AAElD;;;;;;;GAOG;AACH,wBAAgB,uCAAuC,CACrD,yBAAyB,EAAE,iBAAiB,EAC5C,IAAI,EAAE,MAAM,EACZ,YAAY,CAAC,EAAE,aAAa,GAAG,sBAAsB,GACpD,iBAAiB,CAuCnB"}
@@ -2,6 +2,7 @@ import { convertHexToDecimal } from "@metamask/controller-utils";
2
2
  import { add0x } from "@metamask/utils";
3
3
  /**
4
4
  * Returns new transaction parameters with increased gas fees.
5
+ *
5
6
  * @param originalTransactionParams - The original transaction parameters.
6
7
  * @param rate - The rate by which to increase the existing gas fee properties.
7
8
  * @param newGasValues - Optional new gas values to use instead of increased the existing values.
@@ -31,6 +32,7 @@ export function getTransactionParamsWithIncreasedGasFee(originalTransactionParam
31
32
  }
32
33
  /**
33
34
  * Generate the increased EIP-1559 gas properties.
35
+ *
34
36
  * @param originalTransactionParams - The original transaction parameters.
35
37
  * @param rate - The rate by which to increase the existing gas fee properties.
36
38
  * @param newGasValues - Optional new gas values to use instead of increased the existing values.
@@ -56,6 +58,7 @@ function getIncreased1559Values(originalTransactionParams, rate, newGasValues) {
56
58
  }
57
59
  /**
58
60
  * Generate the increased gas price.
61
+ *
59
62
  * @param originalTransactionParams - The original transaction parameters.
60
63
  * @param rate - The rate by which to increase the existing gas fee properties.
61
64
  * @param newGasValues - Optional new gas values to use instead of increased the existing values.
@@ -73,6 +76,7 @@ function getIncreasedGasPrice(originalTransactionParams, rate, newGasValues) {
73
76
  }
74
77
  /**
75
78
  * Multiply a hex value by a multiplier.
79
+ *
76
80
  * @param value - The hex value to multiply.
77
81
  * @param multiplier - The multiplier.
78
82
  * @returns The multiplied hex value.