@metamask/transaction-controller 46.0.0 → 48.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 +39 -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 +9 -7
@@ -1 +1 @@
1
- {"version":3,"file":"retry.mjs","sourceRoot":"","sources":["../../src/utils/retry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,mCAAmC;AAEjE,OAAO,EAAE,KAAK,EAAE,wBAAwB;AAKxC;;;;;;GAMG;AACH,MAAM,UAAU,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,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WAAW,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;AAC5C,CAAC;AAED;;;;;GAKG;AACH,SAAS,WAAW,CAAC,KAAsB,EAAE,UAAkB;IAC7D,MAAM,YAAY,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC;IAChD,MAAM,aAAa,GAAG,QAAQ,CAAC,GAAG,YAAY,GAAG,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC;IAEnE,OAAO,KAAK,CAAC,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.mjs","sourceRoot":"","sources":["../../src/utils/retry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,mCAAmC;AAEjE,OAAO,EAAE,KAAK,EAAE,wBAAwB;AAKxC;;;;;;;GAOG;AACH,MAAM,UAAU,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;AAED;;;;;;;GAOG;AACH,SAAS,sBAAsB,CAC7B,yBAA4C,EAC5C,IAAY,EACZ,YAAqD;IAErD,IACE,YAAY;QACZ,cAAc,IAAI,YAAY;QAC9B,sBAAsB,IAAI,YAAY,EACtC;QACA,OAAO,YAAY,CAAC;KACrB;IAED,MAAM,mBAAmB,GAAG,yBAAyB,CAAC,YAEzC,CAAC;IAEd,MAAM,2BAA2B,GAC/B,yBAAyB,CAAC,oBAAuC,CAAC;IAEpE,IACE,CAAC,mBAAmB;QACpB,CAAC,2BAA2B;QAC5B,mBAAmB,KAAK,KAAK;QAC7B,2BAA2B,KAAK,KAAK,EACrC;QACA,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,YAAY,GAAG,WAAW,CAAC,mBAAmB,EAAE,IAAI,CAAC,CAAC;IAC5D,MAAM,oBAAoB,GAAG,WAAW,CAAC,2BAA2B,EAAE,IAAI,CAAC,CAAC;IAE5E,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,CAAC;AAChD,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,oBAAoB,CAC3B,yBAA4C,EAC5C,IAAY,EACZ,YAAqD;IAErD,IAAI,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;;;;;;GAMG;AACH,SAAS,WAAW,CAAC,KAAsB,EAAE,UAAkB;IAC7D,MAAM,YAAY,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC;IAChD,MAAM,aAAa,GAAG,QAAQ,CAAC,GAAG,YAAY,GAAG,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC;IAEnE,OAAO,KAAK,CAAC,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 *\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"]}
@@ -12,8 +12,10 @@ const ENDPOINT_NETWORKS = 'networks';
12
12
  let requestIdCounter = 0;
13
13
  /**
14
14
  * Simulate transactions using the transaction simulation API.
15
+ *
15
16
  * @param chainId - The chain ID to simulate transactions on.
16
17
  * @param request - The request to simulate transactions.
18
+ * @returns The response from the simulation API.
17
19
  */
18
20
  async function simulateTransactions(chainId, request) {
19
21
  const url = await getSimulationUrl(chainId);
@@ -40,6 +42,7 @@ async function simulateTransactions(chainId, request) {
40
42
  exports.simulateTransactions = simulateTransactions;
41
43
  /**
42
44
  * Get the URL for the transaction simulation API.
45
+ *
43
46
  * @param chainId - The chain ID to get the URL for.
44
47
  * @returns The URL for the transaction simulation API.
45
48
  */
@@ -55,6 +58,8 @@ async function getSimulationUrl(chainId) {
55
58
  }
56
59
  /**
57
60
  * Retrieve the supported network data from the simulation API.
61
+ *
62
+ * @returns The network data response from the simulation API.
58
63
  */
59
64
  async function getNetworkData() {
60
65
  const url = `${getUrl('ethereum-mainnet')}${ENDPOINT_NETWORKS}`;
@@ -63,6 +68,7 @@ async function getNetworkData() {
63
68
  }
64
69
  /**
65
70
  * Generate the URL for the specified subdomain in the simulation API.
71
+ *
66
72
  * @param subdomain - The subdomain to generate the URL for.
67
73
  * @returns The URL for the transaction simulation API.
68
74
  */
@@ -1 +1 @@
1
- {"version":3,"file":"simulation-api.cjs","sourceRoot":"","sources":["../../src/utils/simulation-api.ts"],"names":[],"mappings":";;;AAAA,iEAAiE;AACjE,2CAA+D;AAE/D,0CAA8E;AAC9E,0CAA0C;AAE1C,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAa,EAAE,gBAAgB,CAAC,CAAC;AAEhE,MAAM,UAAU,GAAG,6BAA6B,CAAC;AACjD,MAAM,QAAQ,GAAG,6CAA6C,CAAC;AAC/D,MAAM,iBAAiB,GAAG,UAAU,CAAC;AAgJrC,IAAI,gBAAgB,GAAG,CAAC,CAAC;AAEzB;;;;GAIG;AACI,KAAK,UAAU,oBAAoB,CACxC,OAAY,EACZ,OAA0B;IAE1B,MAAM,GAAG,GAAG,MAAM,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAE5C,GAAG,CAAC,iBAAiB,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IAErC,MAAM,SAAS,GAAG,gBAAgB,CAAC;IACnC,gBAAgB,IAAI,CAAC,CAAC;IAEtB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;QAChC,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;YACnB,EAAE,EAAE,MAAM,CAAC,SAAS,CAAC;YACrB,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,UAAU;YAClB,MAAM,EAAE,CAA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-utils';\nimport { createModuleLogger, type Hex } from '@metamask/utils';\n\nimport { SimulationChainNotSupportedError, SimulationError } from '../errors';\nimport { projectLogger } from '../logger';\n\nconst log = createModuleLogger(projectLogger, 'simulation-api');\n\nconst RPC_METHOD = 'infura_simulateTransactions';\nconst BASE_URL = 'https://tx-sentinel-{0}.api.cx.metamask.io/';\nconst ENDPOINT_NETWORKS = 'networks';\n\n/** Single transaction to simulate in a simulation API request. */\nexport type SimulationRequestTransaction = {\n /** Data to send with the transaction. */\n data?: Hex;\n\n /** Sender of the transaction. */\n from: Hex;\n\n /** Gas limit for the transaction. */\n gas?: Hex;\n\n /** Maximum fee per gas for the transaction. */\n maxFeePerGas?: Hex;\n\n /** Maximum priority fee per gas for the transaction. */\n maxPriorityFeePerGas?: Hex;\n\n /** Recipient of the transaction. */\n to?: Hex;\n\n /** Value to send with the transaction. */\n value?: Hex;\n};\n\n/** Request to the simulation API to simulate transactions. */\nexport type SimulationRequest = {\n /**\n * Transactions to be sequentially simulated.\n * State changes impact subsequent transactions in the list.\n */\n transactions: SimulationRequestTransaction[];\n\n blockOverrides?: {\n time?: Hex;\n };\n\n /**\n * Overrides to the state of the blockchain, keyed by smart contract address.\n */\n overrides?: {\n [address: Hex]: {\n /** Overrides to the storage slots for a smart contract account. */\n stateDiff: {\n [slot: Hex]: Hex;\n };\n };\n };\n\n /**\n * Whether to include call traces in the response.\n * Defaults to false.\n */\n withCallTrace?: boolean;\n\n /**\n * Whether to include event logs in the response.\n * Defaults to false.\n */\n withLogs?: boolean;\n};\n\n/** Raw event log emitted by a simulated transaction. */\nexport type SimulationResponseLog = {\n /** Address of the account that created the event. */\n address: Hex;\n\n /** Raw data in the event that is not indexed. */\n data: Hex;\n\n /** Raw indexed data from the event. */\n topics: Hex[];\n};\n\n/** Call trace of a single simulated transaction. */\nexport type SimulationResponseCallTrace = {\n /** Nested calls. */\n calls: SimulationResponseCallTrace[];\n\n /** Raw event logs created by the call. */\n logs: SimulationResponseLog[];\n};\n\n/**\n * Changes to the blockchain state.\n * Keyed by account address.\n */\nexport type SimulationResponseStateDiff = {\n [address: Hex]: {\n /** Native balance of the account. */\n balance?: Hex;\n\n /** Nonce of the account. */\n nonce?: Hex;\n\n /** Storage values per slot. */\n storage?: {\n [slot: Hex]: Hex;\n };\n };\n};\n\n/** Response from the simulation API for a single transaction. */\nexport type SimulationResponseTransaction = {\n /** An error message indicating the transaction could not be simulated. */\n error?: string;\n\n /** Return value of the transaction, such as the balance if calling balanceOf. */\n return: Hex;\n\n /** Hierarchy of call data including nested calls and logs. */\n callTrace?: SimulationResponseCallTrace;\n\n /** Changes to the blockchain state. */\n stateDiff?: {\n /** Initial blockchain state before the transaction. */\n pre?: SimulationResponseStateDiff;\n\n /** Updated blockchain state after the transaction. */\n post?: SimulationResponseStateDiff;\n };\n};\n\n/** Response from the simulation API. */\nexport type SimulationResponse = {\n /** Simulation data for each transaction in the request. */\n transactions: SimulationResponseTransaction[];\n};\n\n/** Data for a network supported by the Simulation API. */\ntype SimulationNetwork = {\n /** Subdomain of the API for the network. */\n network: string;\n\n /** Whether the network supports confirmation simulations. */\n confirmations: boolean;\n};\n\n/** Response from the simulation API containing supported networks. */\ntype SimulationNetworkResponse = {\n [chainIdDecimal: string]: SimulationNetwork;\n};\n\nlet requestIdCounter = 0;\n\n/**\n * Simulate transactions using the transaction simulation API.\n * @param chainId - The chain ID to simulate transactions on.\n * @param request - The request to simulate transactions.\n */\nexport async function simulateTransactions(\n chainId: Hex,\n request: SimulationRequest,\n): Promise<SimulationResponse> {\n const url = await getSimulationUrl(chainId);\n\n log('Sending request', url, request);\n\n const requestId = requestIdCounter;\n requestIdCounter += 1;\n\n const response = await fetch(url, {\n method: 'POST',\n body: JSON.stringify({\n id: String(requestId),\n jsonrpc: '2.0',\n method: RPC_METHOD,\n params: [request],\n }),\n });\n\n const responseJson = await response.json();\n\n log('Received response', responseJson);\n\n if (responseJson.error) {\n const { code, message } = responseJson.error;\n throw new SimulationError(message, code);\n }\n\n return responseJson?.result;\n}\n\n/**\n * Get the URL for the transaction simulation API.\n * @param chainId - The chain ID to get the URL for.\n * @returns The URL for the transaction simulation API.\n */\nasync function getSimulationUrl(chainId: Hex): Promise<string> {\n const networkData = await getNetworkData();\n const chainIdDecimal = convertHexToDecimal(chainId);\n const network = networkData[chainIdDecimal];\n\n if (!network?.confirmations) {\n log('Chain is not supported', chainId);\n throw new SimulationChainNotSupportedError(chainId);\n }\n\n return getUrl(network.network);\n}\n\n/**\n * Retrieve the supported network data from the simulation API.\n */\nasync function getNetworkData(): Promise<SimulationNetworkResponse> {\n const url = `${getUrl('ethereum-mainnet')}${ENDPOINT_NETWORKS}`;\n const response = await fetch(url);\n return response.json();\n}\n\n/**\n * Generate the URL for the specified subdomain in the simulation API.\n * @param subdomain - The subdomain to generate the URL for.\n * @returns The URL for the transaction simulation API.\n */\nfunction getUrl(subdomain: string): string {\n return BASE_URL.replace('{0}', subdomain);\n}\n"]}
1
+ {"version":3,"file":"simulation-api.cjs","sourceRoot":"","sources":["../../src/utils/simulation-api.ts"],"names":[],"mappings":";;;AAAA,iEAAiE;AACjE,2CAA+D;AAE/D,0CAA8E;AAC9E,0CAA0C;AAE1C,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAa,EAAE,gBAAgB,CAAC,CAAC;AAEhE,MAAM,UAAU,GAAG,6BAA6B,CAAC;AACjD,MAAM,QAAQ,GAAG,6CAA6C,CAAC;AAC/D,MAAM,iBAAiB,GAAG,UAAU,CAAC;AAgJrC,IAAI,gBAAgB,GAAG,CAAC,CAAC;AAEzB;;;;;;GAMG;AACI,KAAK,UAAU,oBAAoB,CACxC,OAAY,EACZ,OAA0B;IAE1B,MAAM,GAAG,GAAG,MAAM,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAE5C,GAAG,CAAC,iBAAiB,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IAErC,MAAM,SAAS,GAAG,gBAAgB,CAAC;IACnC,gBAAgB,IAAI,CAAC,CAA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AC,GAAG,CAAC,CAAC;IAClC,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;AACzB,CAAC;AAED;;;;;GAKG;AACH,SAAS,MAAM,CAAC,SAAiB;IAC/B,OAAO,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;AAC5C,CAAC","sourcesContent":["import { convertHexToDecimal } from '@metamask/controller-utils';\nimport { createModuleLogger, type Hex } from '@metamask/utils';\n\nimport { SimulationChainNotSupportedError, SimulationError } from '../errors';\nimport { projectLogger } from '../logger';\n\nconst log = createModuleLogger(projectLogger, 'simulation-api');\n\nconst RPC_METHOD = 'infura_simulateTransactions';\nconst BASE_URL = 'https://tx-sentinel-{0}.api.cx.metamask.io/';\nconst ENDPOINT_NETWORKS = 'networks';\n\n/** Single transaction to simulate in a simulation API request. */\nexport type SimulationRequestTransaction = {\n /** Data to send with the transaction. */\n data?: Hex;\n\n /** Sender of the transaction. */\n from: Hex;\n\n /** Gas limit for the transaction. */\n gas?: Hex;\n\n /** Maximum fee per gas for the transaction. */\n maxFeePerGas?: Hex;\n\n /** Maximum priority fee per gas for the transaction. */\n maxPriorityFeePerGas?: Hex;\n\n /** Recipient of the transaction. */\n to?: Hex;\n\n /** Value to send with the transaction. */\n value?: Hex;\n};\n\n/** Request to the simulation API to simulate transactions. */\nexport type SimulationRequest = {\n /**\n * Transactions to be sequentially simulated.\n * State changes impact subsequent transactions in the list.\n */\n transactions: SimulationRequestTransaction[];\n\n blockOverrides?: {\n time?: Hex;\n };\n\n /**\n * Overrides to the state of the blockchain, keyed by smart contract address.\n */\n overrides?: {\n [address: Hex]: {\n /** Overrides to the storage slots for a smart contract account. */\n stateDiff: {\n [slot: Hex]: Hex;\n };\n };\n };\n\n /**\n * Whether to include call traces in the response.\n * Defaults to false.\n */\n withCallTrace?: boolean;\n\n /**\n * Whether to include event logs in the response.\n * Defaults to false.\n */\n withLogs?: boolean;\n};\n\n/** Raw event log emitted by a simulated transaction. */\nexport type SimulationResponseLog = {\n /** Address of the account that created the event. */\n address: Hex;\n\n /** Raw data in the event that is not indexed. */\n data: Hex;\n\n /** Raw indexed data from the event. */\n topics: Hex[];\n};\n\n/** Call trace of a single simulated transaction. */\nexport type SimulationResponseCallTrace = {\n /** Nested calls. */\n calls: SimulationResponseCallTrace[];\n\n /** Raw event logs created by the call. */\n logs: SimulationResponseLog[];\n};\n\n/**\n * Changes to the blockchain state.\n * Keyed by account address.\n */\nexport type SimulationResponseStateDiff = {\n [address: Hex]: {\n /** Native balance of the account. */\n balance?: Hex;\n\n /** Nonce of the account. */\n nonce?: Hex;\n\n /** Storage values per slot. */\n storage?: {\n [slot: Hex]: Hex;\n };\n };\n};\n\n/** Response from the simulation API for a single transaction. */\nexport type SimulationResponseTransaction = {\n /** An error message indicating the transaction could not be simulated. */\n error?: string;\n\n /** Return value of the transaction, such as the balance if calling balanceOf. */\n return: Hex;\n\n /** Hierarchy of call data including nested calls and logs. */\n callTrace?: SimulationResponseCallTrace;\n\n /** Changes to the blockchain state. */\n stateDiff?: {\n /** Initial blockchain state before the transaction. */\n pre?: SimulationResponseStateDiff;\n\n /** Updated blockchain state after the transaction. */\n post?: SimulationResponseStateDiff;\n };\n};\n\n/** Response from the simulation API. */\nexport type SimulationResponse = {\n /** Simulation data for each transaction in the request. */\n transactions: SimulationResponseTransaction[];\n};\n\n/** Data for a network supported by the Simulation API. */\ntype SimulationNetwork = {\n /** Subdomain of the API for the network. */\n network: string;\n\n /** Whether the network supports confirmation simulations. */\n confirmations: boolean;\n};\n\n/** Response from the simulation API containing supported networks. */\ntype SimulationNetworkResponse = {\n [chainIdDecimal: string]: SimulationNetwork;\n};\n\nlet requestIdCounter = 0;\n\n/**\n * Simulate transactions using the transaction simulation API.\n *\n * @param chainId - The chain ID to simulate transactions on.\n * @param request - The request to simulate transactions.\n * @returns The response from the simulation API.\n */\nexport async function simulateTransactions(\n chainId: Hex,\n request: SimulationRequest,\n): Promise<SimulationResponse> {\n const url = await getSimulationUrl(chainId);\n\n log('Sending request', url, request);\n\n const requestId = requestIdCounter;\n requestIdCounter += 1;\n\n const response = await fetch(url, {\n method: 'POST',\n body: JSON.stringify({\n id: String(requestId),\n jsonrpc: '2.0',\n method: RPC_METHOD,\n params: [request],\n }),\n });\n\n const responseJson = await response.json();\n\n log('Received response', responseJson);\n\n if (responseJson.error) {\n const { code, message } = responseJson.error;\n throw new SimulationError(message, code);\n }\n\n return responseJson?.result;\n}\n\n/**\n * Get the URL for the transaction simulation API.\n *\n * @param chainId - The chain ID to get the URL for.\n * @returns The URL for the transaction simulation API.\n */\nasync function getSimulationUrl(chainId: Hex): Promise<string> {\n const networkData = await getNetworkData();\n const chainIdDecimal = convertHexToDecimal(chainId);\n const network = networkData[chainIdDecimal];\n\n if (!network?.confirmations) {\n log('Chain is not supported', chainId);\n throw new SimulationChainNotSupportedError(chainId);\n }\n\n return getUrl(network.network);\n}\n\n/**\n * Retrieve the supported network data from the simulation API.\n *\n * @returns The network data response from the simulation API.\n */\nasync function getNetworkData(): Promise<SimulationNetworkResponse> {\n const url = `${getUrl('ethereum-mainnet')}${ENDPOINT_NETWORKS}`;\n const response = await fetch(url);\n return response.json();\n}\n\n/**\n * Generate the URL for the specified subdomain in the simulation API.\n *\n * @param subdomain - The subdomain to generate the URL for.\n * @returns The URL for the transaction simulation API.\n */\nfunction getUrl(subdomain: string): string {\n return BASE_URL.replace('{0}', subdomain);\n}\n"]}
@@ -103,8 +103,10 @@ export type SimulationResponse = {
103
103
  };
104
104
  /**
105
105
  * Simulate transactions using the transaction simulation API.
106
+ *
106
107
  * @param chainId - The chain ID to simulate transactions on.
107
108
  * @param request - The request to simulate transactions.
109
+ * @returns The response from the simulation API.
108
110
  */
109
111
  export declare function simulateTransactions(chainId: Hex, request: SimulationRequest): Promise<SimulationResponse>;
110
112
  //# sourceMappingURL=simulation-api.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"simulation-api.d.cts","sourceRoot":"","sources":["../../src/utils/simulation-api.ts"],"names":[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AAC,EAAE,GAAG,CAAC;QAEd,4BAA4B;QAC5B,KAAK,CAAC,EAAE,GAAG,CAAC;QAEZ,+BAA+B;QAC/B,OAAO,CAAC,EAAE;YACR,CAAC,IAAI,EAAE,GAAG,GAAG,GAAG,CAAC;SAClB,CAAC;KACH,CAAC;CACH,CAAC;AAEF,iEAAiE;AACjE,MAAM,MAAM,6BAA6B,GAAG;IAC1C,0EAA0E;IAC1E,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,iFAAiF;IACjF,MAAM,EAAE,GAAG,CAAC;IAEZ,8DAA8D;IAC9D,SAAS,CAAC,EAAE,2BAA2B,CAAC;IAExC,uCAAuC;IACvC,SAAS,CAAC,EAAE;QACV,uDAAuD;QACvD,GAAG,CAAC,EAAE,2BAA2B,CAAC;QAElC,sDAAsD;QACtD,IAAI,CAAC,EAAE,2BAA2B,CAAC;KACpC,CAAC;CACH,CAAC;AAEF,wCAAwC;AACxC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,2DAA2D;IAC3D,YAAY,EAAE,6BAA6B,EAAE,CAAC;CAC/C,CAAC;AAkBF;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,GAAG,EACZ,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,kBAAkB,CAAC,CA4B7B"}
@@ -103,8 +103,10 @@ export type SimulationResponse = {
103
103
  };
104
104
  /**
105
105
  * Simulate transactions using the transaction simulation API.
106
+ *
106
107
  * @param chainId - The chain ID to simulate transactions on.
107
108
  * @param request - The request to simulate transactions.
109
+ * @returns The response from the simulation API.
108
110
  */
109
111
  export declare function simulateTransactions(chainId: Hex, request: SimulationRequest): Promise<SimulationResponse>;
110
112
  //# sourceMappingURL=simulation-api.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"simulation-api.d.mts","sourceRoot":"","sources":["../../src/utils/simulation-api.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,KAAK,GAAG,EAAE,wBAAwB;AAW/D,mEAAm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G,CAAC;QAEZ,+BAA+B;QAC/B,OAAO,CAAC,EAAE;YACR,CAAC,IAAI,EAAE,GAAG,GAAG,GAAG,CAAC;SAClB,CAAC;KACH,CAAC;CACH,CAAC;AAEF,iEAAiE;AACjE,MAAM,MAAM,6BAA6B,GAAG;IAC1C,0EAA0E;IAC1E,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,iFAAiF;IACjF,MAAM,EAAE,GAAG,CAAC;IAEZ,8DAA8D;IAC9D,SAAS,CAAC,EAAE,2BAA2B,CAAC;IAExC,uCAAuC;IACvC,SAAS,CAAC,EAAE;QACV,uDAAuD;QACvD,GAAG,CAAC,EAAE,2BAA2B,CAAC;QAElC,sDAAsD;QACtD,IAAI,CAAC,EAAE,2BAA2B,CAAC;KACpC,CAAC;CACH,CAAC;AAEF,wCAAwC;AACxC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,2DAA2D;IAC3D,YAAY,EAAE,6BAA6B,EAAE,CAAC;CAC/C,CAAC;AAkBF;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,GAAG,EACZ,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,kBAAkB,CAAC,CA4B7B"}
@@ -9,8 +9,10 @@ const ENDPOINT_NETWORKS = 'networks';
9
9
  let requestIdCounter = 0;
10
10
  /**
11
11
  * Simulate transactions using the transaction simulation API.
12
+ *
12
13
  * @param chainId - The chain ID to simulate transactions on.
13
14
  * @param request - The request to simulate transactions.
15
+ * @returns The response from the simulation API.
14
16
  */
15
17
  export async function simulateTransactions(chainId, request) {
16
18
  const url = await getSimulationUrl(chainId);
@@ -36,6 +38,7 @@ export async function simulateTransactions(chainId, request) {
36
38
  }
37
39
  /**
38
40
  * Get the URL for the transaction simulation API.
41
+ *
39
42
  * @param chainId - The chain ID to get the URL for.
40
43
  * @returns The URL for the transaction simulation API.
41
44
  */
@@ -51,6 +54,8 @@ async function getSimulationUrl(chainId) {
51
54
  }
52
55
  /**
53
56
  * Retrieve the supported network data from the simulation API.
57
+ *
58
+ * @returns The network data response from the simulation API.
54
59
  */
55
60
  async function getNetworkData() {
56
61
  const url = `${getUrl('ethereum-mainnet')}${ENDPOINT_NETWORKS}`;
@@ -59,6 +64,7 @@ async function getNetworkData() {
59
64
  }
60
65
  /**
61
66
  * Generate the URL for the specified subdomain in the simulation API.
67
+ *
62
68
  * @param subdomain - The subdomain to generate the URL for.
63
69
  * @returns The URL for the transaction simulation API.
64
70
  */
@@ -1 +1 @@
1
- {"version":3,"file":"simulation-api.mjs","sourceRoot":"","sources":["../../src/utils/simulation-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,mCAAmC;AACjE,OAAO,EAAE,kBAAkB,EAAY,wBAAwB;AAE/D,OAAO,EAAE,gCAAgC,EAAE,eAAe,EAAE,sBAAkB;AAC9E,OAAO,EAAE,aAAa,EAAE,sBAAkB;AAE1C,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,gBAAgB,CAAC,CAAC;AAEhE,MAAM,UAAU,GAAG,6BAA6B,CAAC;AACjD,MAAM,QAAQ,GAAG,6CAA6C,CAAC;AAC/D,MAAM,iBAAiB,GAAG,UAAU,CAAC;AAgJrC,IAAI,gBAAgB,GAAG,CAAC,CAAC;AAEzB;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,OAAY,EACZ,OAA0B;IAE1B,MAAM,GAAG,GAAG,MAAM,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAE5C,GAAG,CAAC,iBAAiB,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IAErC,MAAM,SAAS,GAAG,gBAAgB,CAAC;IACnC,gBAAgB,IAAI,CAAC,CAAC;IAEtB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;QAChC,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;YACnB,EAAE,EAAE,MAAM,CAAC,SAAS,CAAC;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C5C,CAAC","sourcesContent":["import { convertHexToDecimal } from '@metamask/controller-utils';\nimport { createModuleLogger, type Hex } from '@metamask/utils';\n\nimport { SimulationChainNotSupportedError, SimulationError } from '../errors';\nimport { projectLogger } from '../logger';\n\nconst log = createModuleLogger(projectLogger, 'simulation-api');\n\nconst RPC_METHOD = 'infura_simulateTransactions';\nconst BASE_URL = 'https://tx-sentinel-{0}.api.cx.metamask.io/';\nconst ENDPOINT_NETWORKS = 'networks';\n\n/** Single transaction to simulate in a simulation API request. */\nexport type SimulationRequestTransaction = {\n /** Data to send with the transaction. */\n data?: Hex;\n\n /** Sender of the transaction. */\n from: Hex;\n\n /** Gas limit for the transaction. */\n gas?: Hex;\n\n /** Maximum fee per gas for the transaction. */\n maxFeePerGas?: Hex;\n\n /** Maximum priority fee per gas for the transaction. */\n maxPriorityFeePerGas?: Hex;\n\n /** Recipient of the transaction. */\n to?: Hex;\n\n /** Value to send with the transaction. */\n value?: Hex;\n};\n\n/** Request to the simulation API to simulate transactions. */\nexport type SimulationRequest = {\n /**\n * Transactions to be sequentially simulated.\n * State changes impact subsequent transactions in the list.\n */\n transactions: SimulationRequestTransaction[];\n\n blockOverrides?: {\n time?: Hex;\n };\n\n /**\n * Overrides to the state of the blockchain, keyed by smart contract address.\n */\n overrides?: {\n [address: Hex]: {\n /** Overrides to the storage slots for a smart contract account. */\n stateDiff: {\n [slot: Hex]: Hex;\n };\n };\n };\n\n /**\n * Whether to include call traces in the response.\n * Defaults to false.\n */\n withCallTrace?: boolean;\n\n /**\n * Whether to include event logs in the response.\n * Defaults to false.\n */\n withLogs?: boolean;\n};\n\n/** Raw event log emitted by a simulated transaction. */\nexport type SimulationResponseLog = {\n /** Address of the account that created the event. */\n address: Hex;\n\n /** Raw data in the event that is not indexed. */\n data: Hex;\n\n /** Raw indexed data from the event. */\n topics: Hex[];\n};\n\n/** Call trace of a single simulated transaction. */\nexport type SimulationResponseCallTrace = {\n /** Nested calls. */\n calls: SimulationResponseCallTrace[];\n\n /** Raw event logs created by the call. */\n logs: SimulationResponseLog[];\n};\n\n/**\n * Changes to the blockchain state.\n * Keyed by account address.\n */\nexport type SimulationResponseStateDiff = {\n [address: Hex]: {\n /** Native balance of the account. */\n balance?: Hex;\n\n /** Nonce of the account. */\n nonce?: Hex;\n\n /** Storage values per slot. */\n storage?: {\n [slot: Hex]: Hex;\n };\n };\n};\n\n/** Response from the simulation API for a single transaction. */\nexport type SimulationResponseTransaction = {\n /** An error message indicating the transaction could not be simulated. */\n error?: string;\n\n /** Return value of the transaction, such as the balance if calling balanceOf. */\n return: Hex;\n\n /** Hierarchy of call data including nested calls and logs. */\n callTrace?: SimulationResponseCallTrace;\n\n /** Changes to the blockchain state. */\n stateDiff?: {\n /** Initial blockchain state before the transaction. */\n pre?: SimulationResponseStateDiff;\n\n /** Updated blockchain state after the transaction. */\n post?: SimulationResponseStateDiff;\n };\n};\n\n/** Response from the simulation API. */\nexport type SimulationResponse = {\n /** Simulation data for each transaction in the request. */\n transactions: SimulationResponseTransaction[];\n};\n\n/** Data for a network supported by the Simulation API. */\ntype SimulationNetwork = {\n /** Subdomain of the API for the network. */\n network: string;\n\n /** Whether the network supports confirmation simulations. */\n confirmations: boolean;\n};\n\n/** Response from the simulation API containing supported networks. */\ntype SimulationNetworkResponse = {\n [chainIdDecimal: string]: SimulationNetwork;\n};\n\nlet requestIdCounter = 0;\n\n/**\n * Simulate transactions using the transaction simulation API.\n * @param chainId - The chain ID to simulate transactions on.\n * @param request - The request to simulate transactions.\n */\nexport async function simulateTransactions(\n chainId: Hex,\n request: SimulationRequest,\n): Promise<SimulationResponse> {\n const url = await getSimulationUrl(chainId);\n\n log('Sending request', url, request);\n\n const requestId = requestIdCounter;\n requestIdCounter += 1;\n\n const response = await fetch(url, {\n method: 'POST',\n body: JSON.stringify({\n id: String(requestId),\n jsonrpc: '2.0',\n method: RPC_METHOD,\n params: [request],\n }),\n });\n\n const responseJson = await response.json();\n\n log('Received response', responseJson);\n\n if (responseJson.error) {\n const { code, message } = responseJson.error;\n throw new SimulationError(message, code);\n }\n\n return responseJson?.result;\n}\n\n/**\n * Get the URL for the transaction simulation API.\n * @param chainId - The chain ID to get the URL for.\n * @returns The URL for the transaction simulation API.\n */\nasync function getSimulationUrl(chainId: Hex): Promise<string> {\n const networkData = await getNetworkData();\n const chainIdDecimal = convertHexToDecimal(chainId);\n const network = networkData[chainIdDecimal];\n\n if (!network?.confirmations) {\n log('Chain is not supported', chainId);\n throw new SimulationChainNotSupportedError(chainId);\n }\n\n return getUrl(network.network);\n}\n\n/**\n * Retrieve the supported network data from the simulation API.\n */\nasync function getNetworkData(): Promise<SimulationNetworkResponse> {\n const url = `${getUrl('ethereum-mainnet')}${ENDPOINT_NETWORKS}`;\n const response = await fetch(url);\n return response.json();\n}\n\n/**\n * Generate the URL for the specified subdomain in the simulation API.\n * @param subdomain - The subdomain to generate the URL for.\n * @returns The URL for the transaction simulation API.\n */\nfunction getUrl(subdomain: string): string {\n return BASE_URL.replace('{0}', subdomain);\n}\n"]}
1
+ {"version":3,"file":"simulation-api.mjs","sourceRoot":"","sources":["../../src/utils/simulation-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,mCAAmC;AACjE,OAAO,EAAE,kBAAkB,EAAY,wBAAwB;AAE/D,OAAO,EAAE,gCAAgC,EAAE,eAAe,EAAE,sBAAkB;AAC9E,OAAO,EAAE,aAAa,EAAE,sBAAkB;AAE1C,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,gBAAgB,CAAC,CAAC;AAEhE,MAAM,UAAU,GAAG,6BAA6B,CAAC;AACjD,MAAM,QAAQ,GAAG,6CAA6C,CAAC;AAC/D,MAAM,iBAAiB,GAAG,UAAU,CAAC;AAgJrC,IAAI,gBAAgB,GAAG,CAAC,CAAC;AAEzB;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,OAAY,EACZ,OAA0B;IAE1B,MAAM,GAAG,GAAG,MAAM,g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AAK,UAAU,cAAc;IAC3B,MAAM,GAAG,GAAG,GAAG,MAAM,CAAC,kBAAkB,CAAC,GAAG,iBAAiB,EAAE,CAAC;IAChE,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;IAClC,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;AACzB,CAAC;AAED;;;;;GAKG;AACH,SAAS,MAAM,CAAC,SAAiB;IAC/B,OAAO,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;AAC5C,CAAC","sourcesContent":["import { convertHexToDecimal } from '@metamask/controller-utils';\nimport { createModuleLogger, type Hex } from '@metamask/utils';\n\nimport { SimulationChainNotSupportedError, SimulationError } from '../errors';\nimport { projectLogger } from '../logger';\n\nconst log = createModuleLogger(projectLogger, 'simulation-api');\n\nconst RPC_METHOD = 'infura_simulateTransactions';\nconst BASE_URL = 'https://tx-sentinel-{0}.api.cx.metamask.io/';\nconst ENDPOINT_NETWORKS = 'networks';\n\n/** Single transaction to simulate in a simulation API request. */\nexport type SimulationRequestTransaction = {\n /** Data to send with the transaction. */\n data?: Hex;\n\n /** Sender of the transaction. */\n from: Hex;\n\n /** Gas limit for the transaction. */\n gas?: Hex;\n\n /** Maximum fee per gas for the transaction. */\n maxFeePerGas?: Hex;\n\n /** Maximum priority fee per gas for the transaction. */\n maxPriorityFeePerGas?: Hex;\n\n /** Recipient of the transaction. */\n to?: Hex;\n\n /** Value to send with the transaction. */\n value?: Hex;\n};\n\n/** Request to the simulation API to simulate transactions. */\nexport type SimulationRequest = {\n /**\n * Transactions to be sequentially simulated.\n * State changes impact subsequent transactions in the list.\n */\n transactions: SimulationRequestTransaction[];\n\n blockOverrides?: {\n time?: Hex;\n };\n\n /**\n * Overrides to the state of the blockchain, keyed by smart contract address.\n */\n overrides?: {\n [address: Hex]: {\n /** Overrides to the storage slots for a smart contract account. */\n stateDiff: {\n [slot: Hex]: Hex;\n };\n };\n };\n\n /**\n * Whether to include call traces in the response.\n * Defaults to false.\n */\n withCallTrace?: boolean;\n\n /**\n * Whether to include event logs in the response.\n * Defaults to false.\n */\n withLogs?: boolean;\n};\n\n/** Raw event log emitted by a simulated transaction. */\nexport type SimulationResponseLog = {\n /** Address of the account that created the event. */\n address: Hex;\n\n /** Raw data in the event that is not indexed. */\n data: Hex;\n\n /** Raw indexed data from the event. */\n topics: Hex[];\n};\n\n/** Call trace of a single simulated transaction. */\nexport type SimulationResponseCallTrace = {\n /** Nested calls. */\n calls: SimulationResponseCallTrace[];\n\n /** Raw event logs created by the call. */\n logs: SimulationResponseLog[];\n};\n\n/**\n * Changes to the blockchain state.\n * Keyed by account address.\n */\nexport type SimulationResponseStateDiff = {\n [address: Hex]: {\n /** Native balance of the account. */\n balance?: Hex;\n\n /** Nonce of the account. */\n nonce?: Hex;\n\n /** Storage values per slot. */\n storage?: {\n [slot: Hex]: Hex;\n };\n };\n};\n\n/** Response from the simulation API for a single transaction. */\nexport type SimulationResponseTransaction = {\n /** An error message indicating the transaction could not be simulated. */\n error?: string;\n\n /** Return value of the transaction, such as the balance if calling balanceOf. */\n return: Hex;\n\n /** Hierarchy of call data including nested calls and logs. */\n callTrace?: SimulationResponseCallTrace;\n\n /** Changes to the blockchain state. */\n stateDiff?: {\n /** Initial blockchain state before the transaction. */\n pre?: SimulationResponseStateDiff;\n\n /** Updated blockchain state after the transaction. */\n post?: SimulationResponseStateDiff;\n };\n};\n\n/** Response from the simulation API. */\nexport type SimulationResponse = {\n /** Simulation data for each transaction in the request. */\n transactions: SimulationResponseTransaction[];\n};\n\n/** Data for a network supported by the Simulation API. */\ntype SimulationNetwork = {\n /** Subdomain of the API for the network. */\n network: string;\n\n /** Whether the network supports confirmation simulations. */\n confirmations: boolean;\n};\n\n/** Response from the simulation API containing supported networks. */\ntype SimulationNetworkResponse = {\n [chainIdDecimal: string]: SimulationNetwork;\n};\n\nlet requestIdCounter = 0;\n\n/**\n * Simulate transactions using the transaction simulation API.\n *\n * @param chainId - The chain ID to simulate transactions on.\n * @param request - The request to simulate transactions.\n * @returns The response from the simulation API.\n */\nexport async function simulateTransactions(\n chainId: Hex,\n request: SimulationRequest,\n): Promise<SimulationResponse> {\n const url = await getSimulationUrl(chainId);\n\n log('Sending request', url, request);\n\n const requestId = requestIdCounter;\n requestIdCounter += 1;\n\n const response = await fetch(url, {\n method: 'POST',\n body: JSON.stringify({\n id: String(requestId),\n jsonrpc: '2.0',\n method: RPC_METHOD,\n params: [request],\n }),\n });\n\n const responseJson = await response.json();\n\n log('Received response', responseJson);\n\n if (responseJson.error) {\n const { code, message } = responseJson.error;\n throw new SimulationError(message, code);\n }\n\n return responseJson?.result;\n}\n\n/**\n * Get the URL for the transaction simulation API.\n *\n * @param chainId - The chain ID to get the URL for.\n * @returns The URL for the transaction simulation API.\n */\nasync function getSimulationUrl(chainId: Hex): Promise<string> {\n const networkData = await getNetworkData();\n const chainIdDecimal = convertHexToDecimal(chainId);\n const network = networkData[chainIdDecimal];\n\n if (!network?.confirmations) {\n log('Chain is not supported', chainId);\n throw new SimulationChainNotSupportedError(chainId);\n }\n\n return getUrl(network.network);\n}\n\n/**\n * Retrieve the supported network data from the simulation API.\n *\n * @returns The network data response from the simulation API.\n */\nasync function getNetworkData(): Promise<SimulationNetworkResponse> {\n const url = `${getUrl('ethereum-mainnet')}${ENDPOINT_NETWORKS}`;\n const response = await fetch(url);\n return response.json();\n}\n\n/**\n * Generate the URL for the specified subdomain in the simulation API.\n *\n * @param subdomain - The subdomain to generate the URL for.\n * @returns The URL for the transaction simulation API.\n */\nfunction getUrl(subdomain: string): string {\n return BASE_URL.replace('{0}', subdomain);\n}\n"]}
@@ -5,21 +5,17 @@ const abi_1 = require("@ethersproject/abi");
5
5
  const controller_utils_1 = require("@metamask/controller-utils");
6
6
  const metamask_eth_abis_1 = require("@metamask/metamask-eth-abis");
7
7
  const utils_1 = require("@metamask/utils");
8
+ const simulation_api_1 = require("./simulation-api.cjs");
8
9
  const constants_1 = require("../constants.cjs");
9
10
  const errors_1 = require("../errors.cjs");
10
11
  const logger_1 = require("../logger.cjs");
11
12
  const types_1 = require("../types.cjs");
12
- const simulation_api_1 = require("./simulation-api.cjs");
13
13
  var SupportedToken;
14
14
  (function (SupportedToken) {
15
15
  SupportedToken["ERC20"] = "erc20";
16
16
  SupportedToken["ERC721"] = "erc721";
17
17
  SupportedToken["ERC1155"] = "erc1155";
18
- // TODO: Either fix this lint violation or explain why it's necessary to ignore.
19
- // eslint-disable-next-line @typescript-eslint/naming-convention
20
18
  SupportedToken["ERC20_WRAPPED"] = "erc20Wrapped";
21
- // TODO: Either fix this lint violation or explain why it's necessary to ignore.
22
- // eslint-disable-next-line @typescript-eslint/naming-convention
23
19
  SupportedToken["ERC721_LEGACY"] = "erc721Legacy";
24
20
  })(SupportedToken || (exports.SupportedToken = SupportedToken = {}));
25
21
  const log = (0, utils_1.createModuleLogger)(logger_1.projectLogger, 'simulation');
@@ -55,6 +51,7 @@ const SUPPORTED_TOKEN_ABIS = {
55
51
  const REVERTED_ERRORS = ['execution reverted', 'insufficient funds for gas'];
56
52
  /**
57
53
  * Generate simulation data for a transaction.
54
+ *
58
55
  * @param request - The transaction to simulate.
59
56
  * @param request.chainId - The chain ID of the transaction.
60
57
  * @param request.from - The sender of the transaction.
@@ -121,6 +118,7 @@ async function getSimulationData(request, options = {}) {
121
118
  exports.getSimulationData = getSimulationData;
122
119
  /**
123
120
  * Extract the native balance change from a simulation response.
121
+ *
124
122
  * @param userAddress - The user's account address.
125
123
  * @param response - The simulation response.
126
124
  * @returns The native balance change or undefined if unchanged.
@@ -141,6 +139,7 @@ function getNativeBalanceChange(userAddress, response) {
141
139
  }
142
140
  /**
143
141
  * Extract events from a simulation response.
142
+ *
144
143
  * @param response - The simulation response.
145
144
  * @returns The parsed events.
146
145
  */
@@ -182,6 +181,7 @@ function getEvents(response) {
182
181
  exports.getEvents = getEvents;
183
182
  /**
184
183
  * Normalize event arguments using ABI input definitions.
184
+ *
185
185
  * @param args - The raw event arguments.
186
186
  * @param abiInputs - The ABI input definitions.
187
187
  * @returns The normalized event arguments.
@@ -196,6 +196,7 @@ function normalizeEventArgs(args, abiInputs) {
196
196
  }
197
197
  /**
198
198
  * Normalize an event argument value.
199
+ *
199
200
  * @param value - The event argument value.
200
201
  * @returns The normalized event argument value.
201
202
  */
@@ -211,6 +212,7 @@ function normalizeEventArgValue(value) {
211
212
  }
212
213
  /**
213
214
  * Generate token balance changes from parsed events.
215
+ *
214
216
  * @param request - The transaction that was simulated.
215
217
  * @param events - The parsed events.
216
218
  * @param options - Additional options.
@@ -264,6 +266,7 @@ async function getTokenBalanceChanges(request, events, options) {
264
266
  }
265
267
  /**
266
268
  * Generate transactions to check token balances.
269
+ *
267
270
  * @param request - The transaction that was simulated.
268
271
  * @param events - The parsed events.
269
272
  * @returns A map of token balance transactions keyed by token.
@@ -308,6 +311,7 @@ function getTokenBalanceTransactions(request, events) {
308
311
  }
309
312
  /**
310
313
  * Check if an event needs to check the previous balance.
314
+ *
311
315
  * @param event - The parsed event.
312
316
  * @returns True if the prior balance check should be skipped.
313
317
  */
@@ -320,6 +324,7 @@ function skipPriorBalanceCheck(event) {
320
324
  }
321
325
  /**
322
326
  * Extract token IDs from a parsed event.
327
+ *
323
328
  * @param event - The parsed event.
324
329
  * @returns An array of token IDs.
325
330
  */
@@ -340,6 +345,7 @@ function getEventTokenIds(event) {
340
345
  }
341
346
  /**
342
347
  * Get the interface for a token standard.
348
+ *
343
349
  * @param tokenStandard - The token standard.
344
350
  * @returns The interface for the token standard.
345
351
  */
@@ -355,6 +361,7 @@ function getContractInterface(tokenStandard) {
355
361
  }
356
362
  /**
357
363
  * Extract the value from a balance transaction response using the correct ABI.
364
+ *
358
365
  * @param from - The address to check the balance of.
359
366
  * @param token - The token to check the balance of.
360
367
  * @param response - The balance transaction response.
@@ -378,6 +385,7 @@ function getAmountFromBalanceTransactionResult(from, token, response) {
378
385
  }
379
386
  /**
380
387
  * Generate the balance transaction data for a token.
388
+ *
381
389
  * @param tokenStandard - The token standard.
382
390
  * @param from - The address to check the balance of.
383
391
  * @param tokenId - The token ID to check the balance of.
@@ -396,6 +404,7 @@ function getBalanceTransactionData(tokenStandard, from, tokenId) {
396
404
  }
397
405
  /**
398
406
  * Parse a raw event log using known ABIs.
407
+ *
399
408
  * @param eventLog - The raw event log.
400
409
  * @param interfaces - The contract interfaces.
401
410
  * @returns The parsed event log or undefined if it could not be parsed.
@@ -411,6 +420,8 @@ function parseLog(eventLog, interfaces) {
411
420
  abi,
412
421
  standard,
413
422
  };
423
+ // Not used
424
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
414
425
  }
415
426
  catch (e) {
416
427
  continue;
@@ -420,6 +431,7 @@ function parseLog(eventLog, interfaces) {
420
431
  }
421
432
  /**
422
433
  * Extract all logs from a call trace tree.
434
+ *
423
435
  * @param call - The root call trace.
424
436
  * @returns An array of logs.
425
437
  */
@@ -435,6 +447,7 @@ function extractLogs(call) {
435
447
  }
436
448
  /**
437
449
  * Generate balance change data from previous and new balances.
450
+ *
438
451
  * @param previousBalance - The previous balance.
439
452
  * @param newBalance - The new balance.
440
453
  * @returns The balance change data or undefined if unchanged.
@@ -456,6 +469,7 @@ function getSimulationBalanceChange(previousBalance, newBalance) {
456
469
  }
457
470
  /**
458
471
  * Get the contract interfaces for all supported tokens.
472
+ *
459
473
  * @returns A map of supported tokens to their contract interfaces.
460
474
  */
461
475
  function getContractInterfaces() {
@@ -1 +1 @@
1
- {"version":3,"file":"simulation.cjs","sourceRoot":"","sources":["../../src/utils/simulation.ts"],"names":[],"mappings":";;;AACA,4CAA+C;AAC/C,iEAA4D;AAC5D,mEAA8E;AAC9E,2CAA+D;AAE/D,gDAGsB;AACtB,0CAImB;AACnB,0CAA0C;AAO1C,wCAAmD;AACnD,yDAAwD;AASxD,IAAY,cAUX;AAVD,WAAY,cAAc;IACxB,iCAAe,CAAA;IACf,mCAAiB,CAAA;IACjB,qCAAmB,CAAA;IACnB,gFAAgF;IAChF,gEAAgE;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AAED;;;;;GAKG;AACH,SAAS,0BAA0B,CACjC,eAAoB,EACpB,UAAe;IAEf,MAAM,YAAY,GAAG,IAAA,0BAAO,EAAC,UAAU,CAAC,CAAC,GAAG,CAAC,IAAA,0BAAO,EAAC,eAAe,CAAC,CAAC,CAAC;IACvE,MAAM,UAAU,GAAG,YAAY,CAAC,KAAK,EAAE,CAAC;IACxC,MAAM,UAAU,GAAG,IAAA,wBAAK,EAAC,YAAY,CAAC,GAAG,EAAE,CAAC,CAAC;IAE7C,IAAI,YAAY,CAAC,MAAM,EAAE,EAAE;QACzB,GAAG,CAAC,wBAAwB,CAAC,CAAC;QAC9B,OAAO,SAAS,CAAC;KAClB;IAED,OAAO;QACL,eAAe;QACf,UAAU;QACV,UAAU;QACV,UAAU;KACX,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAS,qBAAqB;IAC5B,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IAEtD,OAAO,IAAI,GAAG,CACZ,eAAe,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE;QAChC,MAAM,EAAE,GAAG,EAAE,GAAG,oBAAoB,CAAC,SAAS,CAAC,CAAC;QAChD,MAAM,iBAAiB,GAAG,IAAI,eAAS,CAAC,GAAG,CAAC,CAAC;QAC7C,OAAO,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAC;IACxC,CAAC,CAAC,CACH,CAAC;AACJ,CAAC","sourcesContent":["import type { Fragment, LogDescription, Result } from '@ethersproject/abi';\nimport { Interface } from '@ethersproject/abi';\nimport { hexToBN, toHex } from '@metamask/controller-utils';\nimport { abiERC20, abiERC721, abiERC1155 } from '@metamask/metamask-eth-abis';\nimport { createModuleLogger, type Hex } from '@metamask/utils';\n\nimport {\n ABI_SIMULATION_ERC20_WRAPPED,\n ABI_SIMULATION_ERC721_LEGACY,\n} from '../constants';\nimport {\n SimulationError,\n SimulationInvalidResponseError,\n SimulationRevertedError,\n} from '../errors';\nimport { projectLogger } from '../logger';\nimport type {\n SimulationBalanceChange,\n SimulationData,\n SimulationTokenBalanceChange,\n SimulationToken,\n} from '../types';\nimport { SimulationTokenStandard } from '../types';\nimport { simulateTransactions } from './simulation-api';\nimport type {\n SimulationResponseLog,\n SimulationRequestTransaction,\n SimulationResponse,\n SimulationResponseCallTrace,\n SimulationResponseTransaction,\n} from './simulation-api';\n\nexport enum SupportedToken {\n ERC20 = 'erc20',\n ERC721 = 'erc721',\n ERC1155 = 'erc1155',\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ERC20_WRAPPED = 'erc20Wrapped',\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ERC721_LEGACY = 'erc721Legacy',\n}\n\ntype ABI = Fragment[];\n\nexport type GetSimulationDataRequest = {\n chainId: Hex;\n data?: Hex;\n from: Hex;\n to?: Hex;\n value?: Hex;\n};\n\ntype ParsedEvent = {\n contractAddress: Hex;\n tokenStandard: SimulationTokenStandard;\n name: string;\n args: Record<string, Hex | Hex[]>;\n abi: ABI;\n};\n\ntype GetSimulationDataOptions = {\n blockTime?: number;\n};\n\nconst log = createModuleLogger(projectLogger, 'simulation');\n\nconst SUPPORTED_EVENTS = [\n 'Transfer',\n 'TransferSingle',\n 'TransferBatch',\n 'Deposit',\n 'Withdrawal',\n];\n\nconst SUPPORTED_TOKEN_ABIS = {\n [SupportedToken.ERC20]: {\n abi: abiERC20,\n standard: SimulationTokenStandard.erc20,\n },\n [SupportedToken.ERC721]: {\n abi: abiERC721,\n standard: SimulationTokenStandard.erc721,\n },\n [SupportedToken.ERC1155]: {\n abi: abiERC1155,\n standard: SimulationTokenStandard.erc1155,\n },\n [SupportedToken.ERC20_WRAPPED]: {\n abi: ABI_SIMULATION_ERC20_WRAPPED,\n standard: SimulationTokenStandard.erc20,\n },\n [SupportedToken.ERC721_LEGACY]: {\n abi: ABI_SIMULATION_ERC721_LEGACY,\n standard: SimulationTokenStandard.erc721,\n },\n};\n\nconst REVERTED_ERRORS = ['execution reverted', 'insufficient funds for gas'];\n\ntype BalanceTransactionMap = Map<SimulationToken, SimulationRequestTransaction>;\n\n/**\n * Generate simulation data for a transaction.\n * @param request - The transaction to simulate.\n * @param request.chainId - The chain ID of the transaction.\n * @param request.from - The sender of the transaction.\n * @param request.to - The recipient of the transaction.\n * @param request.value - The value of the transaction.\n * @param request.data - The data of the transaction.\n * @param options - Additional options.\n * @param options.blockTime - An optional block time to simulate the transaction at.\n * @returns The simulation data.\n */\nexport async function getSimulationData(\n request: GetSimulationDataRequest,\n options: GetSimulationDataOptions = {},\n): Promise<SimulationData> {\n const { chainId, from, to, value, data } = request;\n const { blockTime } = options;\n\n log('Getting simulation data', request);\n\n try {\n const response = await simulateTransactions(chainId, {\n transactions: [\n {\n data,\n from,\n maxFeePerGas: '0x0',\n maxPriorityFeePerGas: '0x0',\n to,\n value,\n },\n ],\n withCallTrace: true,\n withLogs: true,\n ...(blockTime && {\n blockOverrides: {\n time: toHex(blockTime),\n },\n }),\n });\n\n const transactionError = response.transactions?.[0]?.error;\n\n if (transactionError) {\n throw new SimulationError(transactionError);\n }\n\n const nativeBalanceChange = getNativeBalanceChange(request.from, response);\n const events = getEvents(response);\n\n log('Parsed events', events);\n\n const tokenBalanceChanges = await getTokenBalanceChanges(\n request,\n events,\n options,\n );\n\n return {\n nativeBalanceChange,\n tokenBalanceChanges,\n };\n } catch (error) {\n log('Failed to get simulation data', error, request);\n\n let simulationError = error as SimulationError;\n\n if (\n REVERTED_ERRORS.some((revertErrorMessage) =>\n simulationError.message?.includes(revertErrorMessage),\n )\n ) {\n simulationError = new SimulationRevertedError();\n }\n\n const { code, message } = simulationError;\n\n return {\n tokenBalanceChanges: [],\n error: {\n code,\n message,\n },\n };\n }\n}\n\n/**\n * Extract the native balance change from a simulation response.\n * @param userAddress - The user's account address.\n * @param response - The simulation response.\n * @returns The native balance change or undefined if unchanged.\n */\nfunction getNativeBalanceChange(\n userAddress: Hex,\n response: SimulationResponse,\n): SimulationBalanceChange | undefined {\n const transactionResponse = response.transactions[0];\n\n /* istanbul ignore next */\n if (!transactionResponse) {\n return undefined;\n }\n\n const { stateDiff } = transactionResponse;\n const previousBalance = stateDiff?.pre?.[userAddress]?.balance;\n const newBalance = stateDiff?.post?.[userAddress]?.balance;\n\n if (!previousBalance || !newBalance) {\n return undefined;\n }\n\n return getSimulationBalanceChange(previousBalance, newBalance);\n}\n\n/**\n * Extract events from a simulation response.\n * @param response - The simulation response.\n * @returns The parsed events.\n */\nexport function getEvents(response: SimulationResponse): ParsedEvent[] {\n /* istanbul ignore next */\n const logs = extractLogs(\n response.transactions[0]?.callTrace ?? ({} as SimulationResponseCallTrace),\n );\n\n log('Extracted logs', logs);\n\n const interfaces = getContractInterfaces();\n\n return logs\n .map((currentLog) => {\n const event = parseLog(currentLog, interfaces);\n\n if (!event) {\n log('Failed to parse log', currentLog);\n return undefined;\n }\n\n /* istanbul ignore next */\n const inputs = event.abi.find((e) => e.name === event.name)?.inputs;\n\n /* istanbul ignore if */\n if (!inputs) {\n log('Failed to find inputs for event', event);\n return undefined;\n }\n\n if (!SUPPORTED_EVENTS.includes(event.name)) {\n log('Ignoring unsupported event', event.name, event);\n return undefined;\n }\n\n log('Normalizing event args', event.name, event);\n\n const args = normalizeEventArgs(event.args, inputs);\n\n return {\n contractAddress: currentLog.address,\n tokenStandard: event.standard,\n name: event.name,\n args,\n abi: event.abi,\n };\n })\n .filter((e) => e !== undefined) as ParsedEvent[];\n}\n\n/**\n * Normalize event arguments using ABI input definitions.\n * @param args - The raw event arguments.\n * @param abiInputs - The ABI input definitions.\n * @returns The normalized event arguments.\n */\nfunction normalizeEventArgs(\n args: Result,\n abiInputs: { name: string }[],\n): Record<string, Hex | Hex[]> {\n return args.reduce((result, arg, index) => {\n const name = abiInputs[index].name.replace('_', '');\n const value = normalizeEventArgValue(arg);\n\n result[name] = value;\n\n return result;\n }, {});\n}\n\n/**\n * Normalize an event argument value.\n * @param value - The event argument value.\n * @returns The normalized event argument value.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction normalizeEventArgValue(value: any): any {\n if (Array.isArray(value)) {\n return value.map(normalizeEventArgValue);\n }\n\n let normalizedValue = value;\n\n normalizedValue = normalizedValue.toHexString?.() ?? normalizedValue;\n normalizedValue = normalizedValue.toLowerCase?.() ?? normalizedValue;\n\n return normalizedValue;\n}\n\n/**\n * Generate token balance changes from parsed events.\n * @param request - The transaction that was simulated.\n * @param events - The parsed events.\n * @param options - Additional options.\n * @param options.blockTime - An optional block time to simulate the transaction at.\n * @returns An array of token balance changes.\n */\nasync function getTokenBalanceChanges(\n request: GetSimulationDataRequest,\n events: ParsedEvent[],\n options: GetSimulationDataOptions,\n): Promise<SimulationTokenBalanceChange[]> {\n const { blockTime } = options;\n const balanceTxs = getTokenBalanceTransactions(request, events);\n\n log('Generated balance transactions', [...balanceTxs.after.values()]);\n\n const transactions = [\n ...balanceTxs.before.values(),\n request,\n ...balanceTxs.after.values(),\n ];\n\n if (transactions.length === 1) {\n return [];\n }\n\n const response = await simulateTransactions(request.chainId as Hex, {\n transactions,\n ...(blockTime && {\n blockOverrides: {\n time: toHex(blockTime),\n },\n }),\n });\n\n log('Balance simulation response', response);\n\n if (response.transactions.length !== transactions.length) {\n throw new SimulationInvalidResponseError();\n }\n\n let prevBalanceTxIndex = 0;\n return [...balanceTxs.after.keys()]\n .map((token, index) => {\n const previousBalanceCheckSkipped = !balanceTxs.before.get(token);\n const previousBalance = previousBalanceCheckSkipped\n ? '0x0'\n : getAmountFromBalanceTransactionResult(\n request.from,\n token,\n // eslint-disable-next-line no-plusplus\n response.transactions[prevBalanceTxIndex++],\n );\n\n const newBalance = getAmountFromBalanceTransactionResult(\n request.from,\n token,\n response.transactions[index + balanceTxs.before.size + 1],\n );\n\n const balanceChange = getSimulationBalanceChange(\n previousBalance,\n newBalance,\n );\n\n if (!balanceChange) {\n return undefined;\n }\n\n return {\n ...token,\n ...balanceChange,\n };\n })\n .filter((change) => change !== undefined) as SimulationTokenBalanceChange[];\n}\n\n/**\n * Generate transactions to check token balances.\n * @param request - The transaction that was simulated.\n * @param events - The parsed events.\n * @returns A map of token balance transactions keyed by token.\n */\nfunction getTokenBalanceTransactions(\n request: GetSimulationDataRequest,\n events: ParsedEvent[],\n): {\n before: BalanceTransactionMap;\n after: BalanceTransactionMap;\n} {\n const tokenKeys = new Set();\n const before = new Map();\n const after = new Map();\n\n const userEvents = events.filter((event) =>\n [event.args.from, event.args.to].includes(request.from),\n );\n\n log('Filtered user events', userEvents);\n\n for (const event of userEvents) {\n const tokenIds = getEventTokenIds(event);\n\n log('Extracted token IDs', tokenIds);\n\n for (const tokenId of tokenIds) {\n const simulationToken: SimulationToken = {\n address: event.contractAddress,\n standard: event.tokenStandard,\n id: tokenId,\n };\n\n const tokenKey = JSON.stringify(simulationToken);\n\n if (tokenKeys.has(tokenKey)) {\n log(\n 'Ignoring additional event with same contract and token ID',\n simulationToken,\n );\n continue;\n }\n\n tokenKeys.add(tokenKey);\n\n const data = getBalanceTransactionData(\n event.tokenStandard,\n request.from,\n tokenId,\n );\n\n const transaction: SimulationRequestTransaction = {\n from: request.from,\n to: event.contractAddress,\n data,\n };\n\n if (skipPriorBalanceCheck(event)) {\n after.set(simulationToken, transaction);\n } else {\n before.set(simulationToken, transaction);\n after.set(simulationToken, transaction);\n }\n }\n }\n\n return { before, after };\n}\n\n/**\n * Check if an event needs to check the previous balance.\n * @param event - The parsed event.\n * @returns True if the prior balance check should be skipped.\n */\nfunction skipPriorBalanceCheck(event: ParsedEvent): boolean {\n // In the case of an NFT mint, we cannot check the NFT owner before the mint\n // as the balance check transaction would revert.\n return (\n event.name === 'Transfer' &&\n event.tokenStandard === SimulationTokenStandard.erc721 &&\n parseInt(event.args.from as string, 16) === 0\n );\n}\n\n/**\n * Extract token IDs from a parsed event.\n * @param event - The parsed event.\n * @returns An array of token IDs.\n */\nfunction getEventTokenIds(event: ParsedEvent): (Hex | undefined)[] {\n if (event.tokenStandard === SimulationTokenStandard.erc721) {\n return [event.args.tokenId as Hex];\n }\n\n if (\n event.tokenStandard === SimulationTokenStandard.erc1155 &&\n event.name === 'TransferSingle'\n ) {\n return [event.args.id as Hex];\n }\n\n if (\n event.tokenStandard === SimulationTokenStandard.erc1155 &&\n event.name === 'TransferBatch'\n ) {\n return event.args.ids as Hex[];\n }\n\n // ERC-20 does not have a token ID so default to undefined.\n return [undefined];\n}\n\n/**\n * Get the interface for a token standard.\n * @param tokenStandard - The token standard.\n * @returns The interface for the token standard.\n */\nfunction getContractInterface(\n tokenStandard: SimulationTokenStandard,\n): Interface {\n switch (tokenStandard) {\n case SimulationTokenStandard.erc721:\n return new Interface(abiERC721);\n case SimulationTokenStandard.erc1155:\n return new Interface(abiERC1155);\n default:\n return new Interface(abiERC20);\n }\n}\n\n/**\n * Extract the value from a balance transaction response using the correct ABI.\n * @param from - The address to check the balance of.\n * @param token - The token to check the balance of.\n * @param response - The balance transaction response.\n * @returns The value of the balance transaction as Hex.\n */\nfunction getAmountFromBalanceTransactionResult(\n from: Hex,\n token: SimulationToken,\n response: SimulationResponseTransaction,\n): Hex {\n const contract = getContractInterface(token.standard);\n\n try {\n if (token.standard === SimulationTokenStandard.erc721) {\n const result = contract.decodeFunctionResult('ownerOf', response.return);\n const owner = result[0];\n return owner.toLowerCase() === from.toLowerCase() ? '0x1' : '0x0';\n }\n\n const result = contract.decodeFunctionResult('balanceOf', response.return);\n return toHex(result[0]);\n } catch (error) {\n log('Failed to decode balance transaction', error, { token, response });\n throw new SimulationError(\n `Failed to decode balance transaction for token ${\n token.address\n }: ${String(error)}`,\n );\n }\n}\n\n/**\n * Generate the balance transaction data for a token.\n * @param tokenStandard - The token standard.\n * @param from - The address to check the balance of.\n * @param tokenId - The token ID to check the balance of.\n * @returns The balance transaction data.\n */\nfunction getBalanceTransactionData(\n tokenStandard: SimulationTokenStandard,\n from: Hex,\n tokenId?: Hex,\n): Hex {\n const contract = getContractInterface(tokenStandard);\n switch (tokenStandard) {\n case SimulationTokenStandard.erc721:\n return contract.encodeFunctionData('ownerOf', [tokenId]) as Hex;\n\n case SimulationTokenStandard.erc1155:\n return contract.encodeFunctionData('balanceOf', [from, tokenId]) as Hex;\n\n default:\n return contract.encodeFunctionData('balanceOf', [from]) as Hex;\n }\n}\n\n/**\n * Parse a raw event log using known ABIs.\n * @param eventLog - The raw event log.\n * @param interfaces - The contract interfaces.\n * @returns The parsed event log or undefined if it could not be parsed.\n */\nfunction parseLog(\n eventLog: SimulationResponseLog,\n interfaces: Map<SupportedToken, Interface>,\n):\n | (LogDescription & { abi: ABI; standard: SimulationTokenStandard })\n | undefined {\n const supportedTokens = Object.values(SupportedToken);\n\n for (const token of supportedTokens) {\n try {\n const contractInterface = interfaces.get(token) as Interface;\n const { abi, standard } = SUPPORTED_TOKEN_ABIS[token];\n\n return {\n ...contractInterface.parseLog(eventLog),\n abi,\n standard,\n };\n } catch (e) {\n continue;\n }\n }\n\n return undefined;\n}\n\n/**\n * Extract all logs from a call trace tree.\n * @param call - The root call trace.\n * @returns An array of logs.\n */\nfunction extractLogs(\n call: SimulationResponseCallTrace,\n): SimulationResponseLog[] {\n /* istanbul ignore next */\n const logs = call.logs ?? [];\n\n /* istanbul ignore next */\n const nestedCalls = call.calls ?? [];\n\n return [\n ...logs,\n ...nestedCalls.map((nestedCall) => extractLogs(nestedCall)).flat(),\n ];\n}\n\n/**\n * Generate balance change data from previous and new balances.\n * @param previousBalance - The previous balance.\n * @param newBalance - The new balance.\n * @returns The balance change data or undefined if unchanged.\n */\nfunction getSimulationBalanceChange(\n previousBalance: Hex,\n newBalance: Hex,\n): SimulationBalanceChange | undefined {\n const differenceBN = hexToBN(newBalance).sub(hexToBN(previousBalance));\n const isDecrease = differenceBN.isNeg();\n const difference = toHex(differenceBN.abs());\n\n if (differenceBN.isZero()) {\n log('Balance change is zero');\n return undefined;\n }\n\n return {\n previousBalance,\n newBalance,\n difference,\n isDecrease,\n };\n}\n\n/**\n * Get the contract interfaces for all supported tokens.\n * @returns A map of supported tokens to their contract interfaces.\n */\nfunction getContractInterfaces(): Map<SupportedToken, Interface> {\n const supportedTokens = Object.values(SupportedToken);\n\n return new Map(\n supportedTokens.map((tokenType) => {\n const { abi } = SUPPORTED_TOKEN_ABIS[tokenType];\n const contractInterface = new Interface(abi);\n return [tokenType, contractInterface];\n }),\n );\n}\n"]}
1
+ {"version":3,"file":"simulation.cjs","sourceRoot":"","sources":["../../src/utils/simulation.ts"],"names":[],"mappings":";;;AACA,4CAA+C;AAC/C,iEAA4D;AAC5D,mEAA8E;AAC9E,2CAA+D;AAE/D,yDAAwD;AAQxD,gDAGsB;AACtB,0CAImB;AACnB,0CAA0C;AAO1C,wCAAmD;AAEnD,IAAY,cAMX;AAND,WAAY,cAAc;IACxB,iCAAe,CAAA;IACf,mCAAiB,CAAA;IACjB,qCAAmB,CAAA;IACnB,gDAA8B,CAAA;IAC9B,gDAA8B,CAAA;AAChC,CAAC,EANW,cAAc,8BAAd,cAAc,QAMzB;AAwBD,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAa,EAAE,YAAY,CAAC,CAAC;AAE5D,MAAM,gBAAgB,GAAG;IACvB,UAAU;IACV,gBAAgB;IAChB,eAAe;IACf,SAAS;IACT,YAAY;CACb,CAAC;AAEF,MAAM,oBAAoB,GAAG;IAC3B,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE;QACtB,GAAG,EAAE,4BAAQ;QACb,QAAQ,EAAE,+BAAuB,CAAC,KAAK;KACxC;IACD,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE;QACvB,GAAG,EAAE,6BAAS;QACd,QAAQ,EAAE,+BAAuB,CAAC,MAAM;KACzC;IACD,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE;QACxB,GAAG,EAAE,8BAAU;QACf,QAAQ,EAAE,+BAAuB,CAAC,OAAO;KAC1C;IACD,CAAC,cAAc,CAAC,aAAa,CAA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AC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE;QAChC,MAAM,EAAE,GAAG,EAAE,GAAG,oBAAoB,CAAC,SAAS,CAAC,CAAC;QAChD,MAAM,iBAAiB,GAAG,IAAI,eAAS,CAAC,GAAG,CAAC,CAAC;QAC7C,OAAO,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAC;IACxC,CAAC,CAAC,CACH,CAAC;AACJ,CAAC","sourcesContent":["import type { Fragment, LogDescription, Result } from '@ethersproject/abi';\nimport { Interface } from '@ethersproject/abi';\nimport { hexToBN, toHex } from '@metamask/controller-utils';\nimport { abiERC20, abiERC721, abiERC1155 } from '@metamask/metamask-eth-abis';\nimport { createModuleLogger, type Hex } from '@metamask/utils';\n\nimport { simulateTransactions } from './simulation-api';\nimport type {\n SimulationResponseLog,\n SimulationRequestTransaction,\n SimulationResponse,\n SimulationResponseCallTrace,\n SimulationResponseTransaction,\n} from './simulation-api';\nimport {\n ABI_SIMULATION_ERC20_WRAPPED,\n ABI_SIMULATION_ERC721_LEGACY,\n} from '../constants';\nimport {\n SimulationError,\n SimulationInvalidResponseError,\n SimulationRevertedError,\n} from '../errors';\nimport { projectLogger } from '../logger';\nimport type {\n SimulationBalanceChange,\n SimulationData,\n SimulationTokenBalanceChange,\n SimulationToken,\n} from '../types';\nimport { SimulationTokenStandard } from '../types';\n\nexport enum SupportedToken {\n ERC20 = 'erc20',\n ERC721 = 'erc721',\n ERC1155 = 'erc1155',\n ERC20_WRAPPED = 'erc20Wrapped',\n ERC721_LEGACY = 'erc721Legacy',\n}\n\ntype ABI = Fragment[];\n\nexport type GetSimulationDataRequest = {\n chainId: Hex;\n data?: Hex;\n from: Hex;\n to?: Hex;\n value?: Hex;\n};\n\ntype ParsedEvent = {\n contractAddress: Hex;\n tokenStandard: SimulationTokenStandard;\n name: string;\n args: Record<string, Hex | Hex[]>;\n abi: ABI;\n};\n\ntype GetSimulationDataOptions = {\n blockTime?: number;\n};\n\nconst log = createModuleLogger(projectLogger, 'simulation');\n\nconst SUPPORTED_EVENTS = [\n 'Transfer',\n 'TransferSingle',\n 'TransferBatch',\n 'Deposit',\n 'Withdrawal',\n];\n\nconst SUPPORTED_TOKEN_ABIS = {\n [SupportedToken.ERC20]: {\n abi: abiERC20,\n standard: SimulationTokenStandard.erc20,\n },\n [SupportedToken.ERC721]: {\n abi: abiERC721,\n standard: SimulationTokenStandard.erc721,\n },\n [SupportedToken.ERC1155]: {\n abi: abiERC1155,\n standard: SimulationTokenStandard.erc1155,\n },\n [SupportedToken.ERC20_WRAPPED]: {\n abi: ABI_SIMULATION_ERC20_WRAPPED,\n standard: SimulationTokenStandard.erc20,\n },\n [SupportedToken.ERC721_LEGACY]: {\n abi: ABI_SIMULATION_ERC721_LEGACY,\n standard: SimulationTokenStandard.erc721,\n },\n};\n\nconst REVERTED_ERRORS = ['execution reverted', 'insufficient funds for gas'];\n\ntype BalanceTransactionMap = Map<SimulationToken, SimulationRequestTransaction>;\n\n/**\n * Generate simulation data for a transaction.\n *\n * @param request - The transaction to simulate.\n * @param request.chainId - The chain ID of the transaction.\n * @param request.from - The sender of the transaction.\n * @param request.to - The recipient of the transaction.\n * @param request.value - The value of the transaction.\n * @param request.data - The data of the transaction.\n * @param options - Additional options.\n * @param options.blockTime - An optional block time to simulate the transaction at.\n * @returns The simulation data.\n */\nexport async function getSimulationData(\n request: GetSimulationDataRequest,\n options: GetSimulationDataOptions = {},\n): Promise<SimulationData> {\n const { chainId, from, to, value, data } = request;\n const { blockTime } = options;\n\n log('Getting simulation data', request);\n\n try {\n const response = await simulateTransactions(chainId, {\n transactions: [\n {\n data,\n from,\n maxFeePerGas: '0x0',\n maxPriorityFeePerGas: '0x0',\n to,\n value,\n },\n ],\n withCallTrace: true,\n withLogs: true,\n ...(blockTime && {\n blockOverrides: {\n time: toHex(blockTime),\n },\n }),\n });\n\n const transactionError = response.transactions?.[0]?.error;\n\n if (transactionError) {\n throw new SimulationError(transactionError);\n }\n\n const nativeBalanceChange = getNativeBalanceChange(request.from, response);\n const events = getEvents(response);\n\n log('Parsed events', events);\n\n const tokenBalanceChanges = await getTokenBalanceChanges(\n request,\n events,\n options,\n );\n\n return {\n nativeBalanceChange,\n tokenBalanceChanges,\n };\n } catch (error) {\n log('Failed to get simulation data', error, request);\n\n let simulationError = error as SimulationError;\n\n if (\n REVERTED_ERRORS.some((revertErrorMessage) =>\n simulationError.message?.includes(revertErrorMessage),\n )\n ) {\n simulationError = new SimulationRevertedError();\n }\n\n const { code, message } = simulationError;\n\n return {\n tokenBalanceChanges: [],\n error: {\n code,\n message,\n },\n };\n }\n}\n\n/**\n * Extract the native balance change from a simulation response.\n *\n * @param userAddress - The user's account address.\n * @param response - The simulation response.\n * @returns The native balance change or undefined if unchanged.\n */\nfunction getNativeBalanceChange(\n userAddress: Hex,\n response: SimulationResponse,\n): SimulationBalanceChange | undefined {\n const transactionResponse = response.transactions[0];\n\n /* istanbul ignore next */\n if (!transactionResponse) {\n return undefined;\n }\n\n const { stateDiff } = transactionResponse;\n const previousBalance = stateDiff?.pre?.[userAddress]?.balance;\n const newBalance = stateDiff?.post?.[userAddress]?.balance;\n\n if (!previousBalance || !newBalance) {\n return undefined;\n }\n\n return getSimulationBalanceChange(previousBalance, newBalance);\n}\n\n/**\n * Extract events from a simulation response.\n *\n * @param response - The simulation response.\n * @returns The parsed events.\n */\nexport function getEvents(response: SimulationResponse): ParsedEvent[] {\n /* istanbul ignore next */\n const logs = extractLogs(\n response.transactions[0]?.callTrace ?? ({} as SimulationResponseCallTrace),\n );\n\n log('Extracted logs', logs);\n\n const interfaces = getContractInterfaces();\n\n return logs\n .map((currentLog) => {\n const event = parseLog(currentLog, interfaces);\n\n if (!event) {\n log('Failed to parse log', currentLog);\n return undefined;\n }\n\n /* istanbul ignore next */\n const inputs = event.abi.find((e) => e.name === event.name)?.inputs;\n\n /* istanbul ignore if */\n if (!inputs) {\n log('Failed to find inputs for event', event);\n return undefined;\n }\n\n if (!SUPPORTED_EVENTS.includes(event.name)) {\n log('Ignoring unsupported event', event.name, event);\n return undefined;\n }\n\n log('Normalizing event args', event.name, event);\n\n const args = normalizeEventArgs(event.args, inputs);\n\n return {\n contractAddress: currentLog.address,\n tokenStandard: event.standard,\n name: event.name,\n args,\n abi: event.abi,\n };\n })\n .filter((e) => e !== undefined) as ParsedEvent[];\n}\n\n/**\n * Normalize event arguments using ABI input definitions.\n *\n * @param args - The raw event arguments.\n * @param abiInputs - The ABI input definitions.\n * @returns The normalized event arguments.\n */\nfunction normalizeEventArgs(\n args: Result,\n abiInputs: { name: string }[],\n): Record<string, Hex | Hex[]> {\n return args.reduce((result, arg, index) => {\n const name = abiInputs[index].name.replace('_', '');\n const value = normalizeEventArgValue(arg);\n\n result[name] = value;\n\n return result;\n }, {});\n}\n\n/**\n * Normalize an event argument value.\n *\n * @param value - The event argument value.\n * @returns The normalized event argument value.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction normalizeEventArgValue(value: any): any {\n if (Array.isArray(value)) {\n return value.map(normalizeEventArgValue);\n }\n\n let normalizedValue = value;\n\n normalizedValue = normalizedValue.toHexString?.() ?? normalizedValue;\n normalizedValue = normalizedValue.toLowerCase?.() ?? normalizedValue;\n\n return normalizedValue;\n}\n\n/**\n * Generate token balance changes from parsed events.\n *\n * @param request - The transaction that was simulated.\n * @param events - The parsed events.\n * @param options - Additional options.\n * @param options.blockTime - An optional block time to simulate the transaction at.\n * @returns An array of token balance changes.\n */\nasync function getTokenBalanceChanges(\n request: GetSimulationDataRequest,\n events: ParsedEvent[],\n options: GetSimulationDataOptions,\n): Promise<SimulationTokenBalanceChange[]> {\n const { blockTime } = options;\n const balanceTxs = getTokenBalanceTransactions(request, events);\n\n log('Generated balance transactions', [...balanceTxs.after.values()]);\n\n const transactions = [\n ...balanceTxs.before.values(),\n request,\n ...balanceTxs.after.values(),\n ];\n\n if (transactions.length === 1) {\n return [];\n }\n\n const response = await simulateTransactions(request.chainId as Hex, {\n transactions,\n ...(blockTime && {\n blockOverrides: {\n time: toHex(blockTime),\n },\n }),\n });\n\n log('Balance simulation response', response);\n\n if (response.transactions.length !== transactions.length) {\n throw new SimulationInvalidResponseError();\n }\n\n let prevBalanceTxIndex = 0;\n return [...balanceTxs.after.keys()]\n .map((token, index) => {\n const previousBalanceCheckSkipped = !balanceTxs.before.get(token);\n const previousBalance = previousBalanceCheckSkipped\n ? '0x0'\n : getAmountFromBalanceTransactionResult(\n request.from,\n token,\n // eslint-disable-next-line no-plusplus\n response.transactions[prevBalanceTxIndex++],\n );\n\n const newBalance = getAmountFromBalanceTransactionResult(\n request.from,\n token,\n response.transactions[index + balanceTxs.before.size + 1],\n );\n\n const balanceChange = getSimulationBalanceChange(\n previousBalance,\n newBalance,\n );\n\n if (!balanceChange) {\n return undefined;\n }\n\n return {\n ...token,\n ...balanceChange,\n };\n })\n .filter((change) => change !== undefined) as SimulationTokenBalanceChange[];\n}\n\n/**\n * Generate transactions to check token balances.\n *\n * @param request - The transaction that was simulated.\n * @param events - The parsed events.\n * @returns A map of token balance transactions keyed by token.\n */\nfunction getTokenBalanceTransactions(\n request: GetSimulationDataRequest,\n events: ParsedEvent[],\n): {\n before: BalanceTransactionMap;\n after: BalanceTransactionMap;\n} {\n const tokenKeys = new Set();\n const before = new Map();\n const after = new Map();\n\n const userEvents = events.filter((event) =>\n [event.args.from, event.args.to].includes(request.from),\n );\n\n log('Filtered user events', userEvents);\n\n for (const event of userEvents) {\n const tokenIds = getEventTokenIds(event);\n\n log('Extracted token IDs', tokenIds);\n\n for (const tokenId of tokenIds) {\n const simulationToken: SimulationToken = {\n address: event.contractAddress,\n standard: event.tokenStandard,\n id: tokenId,\n };\n\n const tokenKey = JSON.stringify(simulationToken);\n\n if (tokenKeys.has(tokenKey)) {\n log(\n 'Ignoring additional event with same contract and token ID',\n simulationToken,\n );\n continue;\n }\n\n tokenKeys.add(tokenKey);\n\n const data = getBalanceTransactionData(\n event.tokenStandard,\n request.from,\n tokenId,\n );\n\n const transaction: SimulationRequestTransaction = {\n from: request.from,\n to: event.contractAddress,\n data,\n };\n\n if (skipPriorBalanceCheck(event)) {\n after.set(simulationToken, transaction);\n } else {\n before.set(simulationToken, transaction);\n after.set(simulationToken, transaction);\n }\n }\n }\n\n return { before, after };\n}\n\n/**\n * Check if an event needs to check the previous balance.\n *\n * @param event - The parsed event.\n * @returns True if the prior balance check should be skipped.\n */\nfunction skipPriorBalanceCheck(event: ParsedEvent): boolean {\n // In the case of an NFT mint, we cannot check the NFT owner before the mint\n // as the balance check transaction would revert.\n return (\n event.name === 'Transfer' &&\n event.tokenStandard === SimulationTokenStandard.erc721 &&\n parseInt(event.args.from as string, 16) === 0\n );\n}\n\n/**\n * Extract token IDs from a parsed event.\n *\n * @param event - The parsed event.\n * @returns An array of token IDs.\n */\nfunction getEventTokenIds(event: ParsedEvent): (Hex | undefined)[] {\n if (event.tokenStandard === SimulationTokenStandard.erc721) {\n return [event.args.tokenId as Hex];\n }\n\n if (\n event.tokenStandard === SimulationTokenStandard.erc1155 &&\n event.name === 'TransferSingle'\n ) {\n return [event.args.id as Hex];\n }\n\n if (\n event.tokenStandard === SimulationTokenStandard.erc1155 &&\n event.name === 'TransferBatch'\n ) {\n return event.args.ids as Hex[];\n }\n\n // ERC-20 does not have a token ID so default to undefined.\n return [undefined];\n}\n\n/**\n * Get the interface for a token standard.\n *\n * @param tokenStandard - The token standard.\n * @returns The interface for the token standard.\n */\nfunction getContractInterface(\n tokenStandard: SimulationTokenStandard,\n): Interface {\n switch (tokenStandard) {\n case SimulationTokenStandard.erc721:\n return new Interface(abiERC721);\n case SimulationTokenStandard.erc1155:\n return new Interface(abiERC1155);\n default:\n return new Interface(abiERC20);\n }\n}\n\n/**\n * Extract the value from a balance transaction response using the correct ABI.\n *\n * @param from - The address to check the balance of.\n * @param token - The token to check the balance of.\n * @param response - The balance transaction response.\n * @returns The value of the balance transaction as Hex.\n */\nfunction getAmountFromBalanceTransactionResult(\n from: Hex,\n token: SimulationToken,\n response: SimulationResponseTransaction,\n): Hex {\n const contract = getContractInterface(token.standard);\n\n try {\n if (token.standard === SimulationTokenStandard.erc721) {\n const result = contract.decodeFunctionResult('ownerOf', response.return);\n const owner = result[0];\n return owner.toLowerCase() === from.toLowerCase() ? '0x1' : '0x0';\n }\n\n const result = contract.decodeFunctionResult('balanceOf', response.return);\n return toHex(result[0]);\n } catch (error) {\n log('Failed to decode balance transaction', error, { token, response });\n throw new SimulationError(\n `Failed to decode balance transaction for token ${\n token.address\n }: ${String(error)}`,\n );\n }\n}\n\n/**\n * Generate the balance transaction data for a token.\n *\n * @param tokenStandard - The token standard.\n * @param from - The address to check the balance of.\n * @param tokenId - The token ID to check the balance of.\n * @returns The balance transaction data.\n */\nfunction getBalanceTransactionData(\n tokenStandard: SimulationTokenStandard,\n from: Hex,\n tokenId?: Hex,\n): Hex {\n const contract = getContractInterface(tokenStandard);\n switch (tokenStandard) {\n case SimulationTokenStandard.erc721:\n return contract.encodeFunctionData('ownerOf', [tokenId]) as Hex;\n\n case SimulationTokenStandard.erc1155:\n return contract.encodeFunctionData('balanceOf', [from, tokenId]) as Hex;\n\n default:\n return contract.encodeFunctionData('balanceOf', [from]) as Hex;\n }\n}\n\n/**\n * Parse a raw event log using known ABIs.\n *\n * @param eventLog - The raw event log.\n * @param interfaces - The contract interfaces.\n * @returns The parsed event log or undefined if it could not be parsed.\n */\nfunction parseLog(\n eventLog: SimulationResponseLog,\n interfaces: Map<SupportedToken, Interface>,\n):\n | (LogDescription & { abi: ABI; standard: SimulationTokenStandard })\n | undefined {\n const supportedTokens = Object.values(SupportedToken);\n\n for (const token of supportedTokens) {\n try {\n const contractInterface = interfaces.get(token) as Interface;\n const { abi, standard } = SUPPORTED_TOKEN_ABIS[token];\n\n return {\n ...contractInterface.parseLog(eventLog),\n abi,\n standard,\n };\n // Not used\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (e) {\n continue;\n }\n }\n\n return undefined;\n}\n\n/**\n * Extract all logs from a call trace tree.\n *\n * @param call - The root call trace.\n * @returns An array of logs.\n */\nfunction extractLogs(\n call: SimulationResponseCallTrace,\n): SimulationResponseLog[] {\n /* istanbul ignore next */\n const logs = call.logs ?? [];\n\n /* istanbul ignore next */\n const nestedCalls = call.calls ?? [];\n\n return [\n ...logs,\n ...nestedCalls.map((nestedCall) => extractLogs(nestedCall)).flat(),\n ];\n}\n\n/**\n * Generate balance change data from previous and new balances.\n *\n * @param previousBalance - The previous balance.\n * @param newBalance - The new balance.\n * @returns The balance change data or undefined if unchanged.\n */\nfunction getSimulationBalanceChange(\n previousBalance: Hex,\n newBalance: Hex,\n): SimulationBalanceChange | undefined {\n const differenceBN = hexToBN(newBalance).sub(hexToBN(previousBalance));\n const isDecrease = differenceBN.isNeg();\n const difference = toHex(differenceBN.abs());\n\n if (differenceBN.isZero()) {\n log('Balance change is zero');\n return undefined;\n }\n\n return {\n previousBalance,\n newBalance,\n difference,\n isDecrease,\n };\n}\n\n/**\n * Get the contract interfaces for all supported tokens.\n *\n * @returns A map of supported tokens to their contract interfaces.\n */\nfunction getContractInterfaces(): Map<SupportedToken, Interface> {\n const supportedTokens = Object.values(SupportedToken);\n\n return new Map(\n supportedTokens.map((tokenType) => {\n const { abi } = SUPPORTED_TOKEN_ABIS[tokenType];\n const contractInterface = new Interface(abi);\n return [tokenType, contractInterface];\n }),\n );\n}\n"]}
@@ -1,8 +1,8 @@
1
1
  import type { Fragment } from "@ethersproject/abi";
2
2
  import { type Hex } from "@metamask/utils";
3
+ import type { SimulationResponse } from "./simulation-api.cjs";
3
4
  import type { SimulationData } from "../types.cjs";
4
5
  import { SimulationTokenStandard } from "../types.cjs";
5
- import type { SimulationResponse } from "./simulation-api.cjs";
6
6
  export declare enum SupportedToken {
7
7
  ERC20 = "erc20",
8
8
  ERC721 = "erc721",
@@ -30,6 +30,7 @@ type GetSimulationDataOptions = {
30
30
  };
31
31
  /**
32
32
  * Generate simulation data for a transaction.
33
+ *
33
34
  * @param request - The transaction to simulate.
34
35
  * @param request.chainId - The chain ID of the transaction.
35
36
  * @param request.from - The sender of the transaction.
@@ -43,6 +44,7 @@ type GetSimulationDataOptions = {
43
44
  export declare function getSimulationData(request: GetSimulationDataRequest, options?: GetSimulationDataOptions): Promise<SimulationData>;
44
45
  /**
45
46
  * Extract events from a simulation response.
47
+ *
46
48
  * @param response - The simulation response.
47
49
  * @returns The parsed events.
48
50
  */
@@ -1 +1 @@
1
- {"version":3,"file":"simulation.d.cts","sourceRoot":"","sources":["../../src/utils/simulation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAA0B,2BAA2B;AAI3E,OAAO,EAAsB,KAAK,GAAG,EAAE,wBAAwB;AAY/D,OAAO,KAAK,EAEV,cAAc,EAGf,qBAAiB;AAClB,OAAO,EAAE,uBAAuB,EAAE,qBAAiB;AAEnD,OAAO,KAAK,EAGV,kBAAkB,EAGnB,6BAAyB;AAE1B,oBAAY,cAAc;IACxB,KAAK,UAAU;IACf,MAAM,WAAW;IACjB,OAAO,YAAY;IAGnB,aAAa,iBAAiB;IAG9B,aAAa,iBAAiB;CAC/B;AAED,KAAK,GAAG,GAAG,QAAQ,EAAE,CAAC;AAEtB,MAAM,MAAM,wBAAwB,GAAG;IACrC,OAAO,EAAE,GAAG,CAAC;IACb,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,IAAI,EAAE,GAAG,CAAC;IACV,EAAE,CAAC,EAAE,GAAG,CAAC;IACT,KAAK,CAAC,EAAE,GAAG,CAAC;CACb,CAAC;AAEF,KAAK,WAAW,GAAG;IACjB,eAAe,EAAE,GAAG,CAAC;IACrB,aAAa,EAAE,uBAAuB,CAAC;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,GAAG,GAAG,EAAE,CAAC,CAAC;IAClC,GAAG,EAAE,GAAG,CAAC;CACV,CAAC;AAEF,KAAK,wBAAwB,GAAG;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAu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;;;GAYG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,wBAAwB,EACjC,OAAO,GAAE,wBAA6B,GACrC,OAAO,CAAC,cAAc,CAAC,CAuEzB;AA+BD;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,kBAAkB,GAAG,WAAW,EAAE,CA8CrE"}
@@ -1,8 +1,8 @@
1
1
  import type { Fragment } from "@ethersproject/abi";
2
2
  import { type Hex } from "@metamask/utils";
3
+ import type { SimulationResponse } from "./simulation-api.mjs";
3
4
  import type { SimulationData } from "../types.mjs";
4
5
  import { SimulationTokenStandard } from "../types.mjs";
5
- import type { SimulationResponse } from "./simulation-api.mjs";
6
6
  export declare enum SupportedToken {
7
7
  ERC20 = "erc20",
8
8
  ERC721 = "erc721",
@@ -30,6 +30,7 @@ type GetSimulationDataOptions = {
30
30
  };
31
31
  /**
32
32
  * Generate simulation data for a transaction.
33
+ *
33
34
  * @param request - The transaction to simulate.
34
35
  * @param request.chainId - The chain ID of the transaction.
35
36
  * @param request.from - The sender of the transaction.
@@ -43,6 +44,7 @@ type GetSimulationDataOptions = {
43
44
  export declare function getSimulationData(request: GetSimulationDataRequest, options?: GetSimulationDataOptions): Promise<SimulationData>;
44
45
  /**
45
46
  * Extract events from a simulation response.
47
+ *
46
48
  * @param response - The simulation response.
47
49
  * @returns The parsed events.
48
50
  */
@@ -1 +1 @@
1
- {"version":3,"file":"simulation.d.mts","sourceRoot":"","sources":["../../src/utils/simulation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAA0B,2BAA2B;AAI3E,OAAO,EAAsB,KAAK,GAAG,EAAE,wBAAwB;AAY/D,OAAO,KAAK,EAEV,cAAc,EAGf,qBAAiB;AAClB,OAAO,EAAE,uBAAuB,EAAE,qBAAiB;AAEnD,OAAO,KAAK,EAGV,kBAAkB,EAGnB,6BAAyB;AAE1B,oBAAY,cAAc;IACxB,KAAK,UAAU;IACf,MAAM,WAAW;IACjB,OAA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