hardhat 2.10.1 → 2.11.0-dev.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 (440) hide show
  1. package/README.md +1 -1
  2. package/builtin-tasks/compile.js +6 -8
  3. package/builtin-tasks/compile.js.map +1 -1
  4. package/builtin-tasks/node.js +9 -12
  5. package/builtin-tasks/node.js.map +1 -1
  6. package/builtin-tasks/test.js +2 -3
  7. package/builtin-tasks/test.js.map +1 -1
  8. package/console.sol +444 -444
  9. package/internal/artifacts.js +1 -1
  10. package/internal/artifacts.js.map +1 -1
  11. package/internal/cli/ArgumentsParser.js +5 -2
  12. package/internal/cli/ArgumentsParser.js.map +1 -1
  13. package/internal/cli/analytics.js +2 -2
  14. package/internal/cli/analytics.js.map +1 -1
  15. package/internal/cli/autocomplete.js +20 -32
  16. package/internal/cli/autocomplete.js.map +1 -1
  17. package/internal/cli/cli.js +1 -1
  18. package/internal/cli/cli.js.map +1 -1
  19. package/internal/cli/project-creation.js +14 -4
  20. package/internal/cli/project-creation.js.map +1 -1
  21. package/internal/constants.d.ts.map +1 -1
  22. package/internal/constants.js +2 -0
  23. package/internal/constants.js.map +1 -1
  24. package/internal/core/config/config-loading.js +2 -3
  25. package/internal/core/config/config-loading.js.map +1 -1
  26. package/internal/core/config/config-resolution.d.ts.map +1 -1
  27. package/internal/core/config/config-resolution.js +84 -35
  28. package/internal/core/config/config-resolution.js.map +1 -1
  29. package/internal/core/config/config-validation.js +38 -20
  30. package/internal/core/config/config-validation.js.map +1 -1
  31. package/internal/core/config/default-config.d.ts.map +1 -1
  32. package/internal/core/config/default-config.js +17 -4
  33. package/internal/core/config/default-config.js.map +1 -1
  34. package/internal/core/errors.js +4 -2
  35. package/internal/core/errors.js.map +1 -1
  36. package/internal/core/execution-mode.js +2 -2
  37. package/internal/core/execution-mode.js.map +1 -1
  38. package/internal/core/flamegraph.d.ts +10 -0
  39. package/internal/core/flamegraph.d.ts.map +1 -0
  40. package/internal/core/flamegraph.js +245 -0
  41. package/internal/core/flamegraph.js.map +1 -0
  42. package/internal/core/jsonrpc/types/base-types.d.ts +7 -8
  43. package/internal/core/jsonrpc/types/base-types.d.ts.map +1 -1
  44. package/internal/core/jsonrpc/types/base-types.js +24 -24
  45. package/internal/core/jsonrpc/types/base-types.js.map +1 -1
  46. package/internal/core/jsonrpc/types/input/blockTag.d.ts +15 -10
  47. package/internal/core/jsonrpc/types/input/blockTag.d.ts.map +1 -1
  48. package/internal/core/jsonrpc/types/input/blockTag.js +2 -0
  49. package/internal/core/jsonrpc/types/input/blockTag.js.map +1 -1
  50. package/internal/core/jsonrpc/types/input/callRequest.d.ts +5 -6
  51. package/internal/core/jsonrpc/types/input/callRequest.d.ts.map +1 -1
  52. package/internal/core/jsonrpc/types/input/callRequest.js.map +1 -1
  53. package/internal/core/jsonrpc/types/input/filterRequest.d.ts +6 -7
  54. package/internal/core/jsonrpc/types/input/filterRequest.d.ts.map +1 -1
  55. package/internal/core/jsonrpc/types/input/filterRequest.js.map +1 -1
  56. package/internal/core/jsonrpc/types/input/transactionRequest.d.ts +7 -8
  57. package/internal/core/jsonrpc/types/input/transactionRequest.d.ts.map +1 -1
  58. package/internal/core/jsonrpc/types/input/transactionRequest.js.map +1 -1
  59. package/internal/core/jsonrpc/types/output/block.d.ts +29 -30
  60. package/internal/core/jsonrpc/types/output/block.d.ts.map +1 -1
  61. package/internal/core/jsonrpc/types/output/block.js +8 -2
  62. package/internal/core/jsonrpc/types/output/block.js.map +1 -1
  63. package/internal/core/jsonrpc/types/output/log.d.ts +3 -4
  64. package/internal/core/jsonrpc/types/output/log.d.ts.map +1 -1
  65. package/internal/core/jsonrpc/types/output/log.js.map +1 -1
  66. package/internal/core/jsonrpc/types/output/receipt.d.ts +10 -11
  67. package/internal/core/jsonrpc/types/output/receipt.d.ts.map +1 -1
  68. package/internal/core/jsonrpc/types/output/receipt.js.map +1 -1
  69. package/internal/core/jsonrpc/types/output/transaction.d.ts +13 -14
  70. package/internal/core/jsonrpc/types/output/transaction.d.ts.map +1 -1
  71. package/internal/core/jsonrpc/types/output/transaction.js.map +1 -1
  72. package/internal/core/providers/accounts.d.ts.map +1 -1
  73. package/internal/core/providers/accounts.js +30 -24
  74. package/internal/core/providers/accounts.js.map +1 -1
  75. package/internal/core/providers/chainId.js +1 -1
  76. package/internal/core/providers/chainId.js.map +1 -1
  77. package/internal/core/providers/construction.d.ts.map +1 -1
  78. package/internal/core/providers/construction.js +5 -5
  79. package/internal/core/providers/construction.js.map +1 -1
  80. package/internal/core/providers/gas-providers.d.ts +4 -4
  81. package/internal/core/providers/gas-providers.d.ts.map +1 -1
  82. package/internal/core/providers/gas-providers.js +16 -15
  83. package/internal/core/providers/gas-providers.js.map +1 -1
  84. package/internal/core/providers/http.js +7 -2
  85. package/internal/core/providers/http.js.map +1 -1
  86. package/internal/core/providers/util.js +5 -8
  87. package/internal/core/providers/util.js.map +1 -1
  88. package/internal/core/runtime-environment.js +1 -1
  89. package/internal/core/runtime-environment.js.map +1 -1
  90. package/internal/core/task-profiling.d.ts +18 -0
  91. package/internal/core/task-profiling.d.ts.map +1 -0
  92. package/internal/core/task-profiling.js +50 -0
  93. package/internal/core/task-profiling.js.map +1 -0
  94. package/internal/core/typescript-support.js +3 -3
  95. package/internal/core/typescript-support.js.map +1 -1
  96. package/internal/hardhat-network/jsonrpc/client.d.ts +39 -39
  97. package/internal/hardhat-network/jsonrpc/client.d.ts.map +1 -1
  98. package/internal/hardhat-network/jsonrpc/client.js +14 -14
  99. package/internal/hardhat-network/jsonrpc/client.js.map +1 -1
  100. package/internal/hardhat-network/provider/BlockchainBase.d.ts +13 -10
  101. package/internal/hardhat-network/provider/BlockchainBase.d.ts.map +1 -1
  102. package/internal/hardhat-network/provider/BlockchainBase.js +38 -16
  103. package/internal/hardhat-network/provider/BlockchainBase.js.map +1 -1
  104. package/internal/hardhat-network/provider/BlockchainData.d.ts +15 -16
  105. package/internal/hardhat-network/provider/BlockchainData.d.ts.map +1 -1
  106. package/internal/hardhat-network/provider/BlockchainData.js +33 -29
  107. package/internal/hardhat-network/provider/BlockchainData.js.map +1 -1
  108. package/internal/hardhat-network/provider/HardhatBlockchain.d.ts +7 -8
  109. package/internal/hardhat-network/provider/HardhatBlockchain.d.ts.map +1 -1
  110. package/internal/hardhat-network/provider/HardhatBlockchain.js +13 -14
  111. package/internal/hardhat-network/provider/HardhatBlockchain.js.map +1 -1
  112. package/internal/hardhat-network/provider/PoolState.d.ts +1 -1
  113. package/internal/hardhat-network/provider/PoolState.d.ts.map +1 -1
  114. package/internal/hardhat-network/provider/PoolState.js +2 -3
  115. package/internal/hardhat-network/provider/PoolState.js.map +1 -1
  116. package/internal/hardhat-network/provider/TransactionQueue.d.ts +2 -3
  117. package/internal/hardhat-network/provider/TransactionQueue.d.ts.map +1 -1
  118. package/internal/hardhat-network/provider/TransactionQueue.js +3 -3
  119. package/internal/hardhat-network/provider/TransactionQueue.js.map +1 -1
  120. package/internal/hardhat-network/provider/TxPool.d.ts +8 -8
  121. package/internal/hardhat-network/provider/TxPool.d.ts.map +1 -1
  122. package/internal/hardhat-network/provider/TxPool.js +66 -68
  123. package/internal/hardhat-network/provider/TxPool.js.map +1 -1
  124. package/internal/hardhat-network/provider/ethereumjs-workarounds.js +2 -2
  125. package/internal/hardhat-network/provider/ethereumjs-workarounds.js.map +1 -1
  126. package/internal/hardhat-network/provider/filter.d.ts +5 -6
  127. package/internal/hardhat-network/provider/filter.d.ts.map +1 -1
  128. package/internal/hardhat-network/provider/filter.js +7 -8
  129. package/internal/hardhat-network/provider/filter.js.map +1 -1
  130. package/internal/hardhat-network/provider/fork/ForkBlockchain.d.ts +10 -11
  131. package/internal/hardhat-network/provider/fork/ForkBlockchain.d.ts.map +1 -1
  132. package/internal/hardhat-network/provider/fork/ForkBlockchain.js +51 -47
  133. package/internal/hardhat-network/provider/fork/ForkBlockchain.js.map +1 -1
  134. package/internal/hardhat-network/provider/fork/ForkStateManager.d.ts +8 -10
  135. package/internal/hardhat-network/provider/fork/ForkStateManager.d.ts.map +1 -1
  136. package/internal/hardhat-network/provider/fork/ForkStateManager.js +51 -69
  137. package/internal/hardhat-network/provider/fork/ForkStateManager.js.map +1 -1
  138. package/internal/hardhat-network/provider/fork/rpcToBlockData.d.ts +1 -1
  139. package/internal/hardhat-network/provider/fork/rpcToBlockData.d.ts.map +1 -1
  140. package/internal/hardhat-network/provider/fork/rpcToBlockData.js +2 -3
  141. package/internal/hardhat-network/provider/fork/rpcToBlockData.js.map +1 -1
  142. package/internal/hardhat-network/provider/fork/rpcToTxData.d.ts +2 -2
  143. package/internal/hardhat-network/provider/fork/rpcToTxData.d.ts.map +1 -1
  144. package/internal/hardhat-network/provider/fork/rpcToTxData.js +7 -11
  145. package/internal/hardhat-network/provider/fork/rpcToTxData.js.map +1 -1
  146. package/internal/hardhat-network/provider/modules/eth.d.ts +2 -1
  147. package/internal/hardhat-network/provider/modules/eth.d.ts.map +1 -1
  148. package/internal/hardhat-network/provider/modules/eth.js +92 -68
  149. package/internal/hardhat-network/provider/modules/eth.js.map +1 -1
  150. package/internal/hardhat-network/provider/modules/evm.d.ts.map +1 -1
  151. package/internal/hardhat-network/provider/modules/evm.js +14 -14
  152. package/internal/hardhat-network/provider/modules/evm.js.map +1 -1
  153. package/internal/hardhat-network/provider/modules/hardhat.d.ts.map +1 -1
  154. package/internal/hardhat-network/provider/modules/hardhat.js +13 -13
  155. package/internal/hardhat-network/provider/modules/hardhat.js.map +1 -1
  156. package/internal/hardhat-network/provider/modules/logger.d.ts +7 -8
  157. package/internal/hardhat-network/provider/modules/logger.d.ts.map +1 -1
  158. package/internal/hardhat-network/provider/modules/logger.js +29 -32
  159. package/internal/hardhat-network/provider/modules/logger.js.map +1 -1
  160. package/internal/hardhat-network/provider/modules/net.d.ts +1 -1
  161. package/internal/hardhat-network/provider/modules/net.d.ts.map +1 -1
  162. package/internal/hardhat-network/provider/modules/personal.d.ts.map +1 -1
  163. package/internal/hardhat-network/provider/modules/personal.js +3 -3
  164. package/internal/hardhat-network/provider/modules/personal.js.map +1 -1
  165. package/internal/hardhat-network/provider/modules/web3.d.ts.map +1 -1
  166. package/internal/hardhat-network/provider/modules/web3.js +5 -4
  167. package/internal/hardhat-network/provider/modules/web3.js.map +1 -1
  168. package/internal/hardhat-network/provider/node-types.d.ts +30 -29
  169. package/internal/hardhat-network/provider/node-types.d.ts.map +1 -1
  170. package/internal/hardhat-network/provider/node.d.ts +47 -42
  171. package/internal/hardhat-network/provider/node.d.ts.map +1 -1
  172. package/internal/hardhat-network/provider/node.js +262 -208
  173. package/internal/hardhat-network/provider/node.js.map +1 -1
  174. package/internal/hardhat-network/provider/output.d.ts +5 -6
  175. package/internal/hardhat-network/provider/output.d.ts.map +1 -1
  176. package/internal/hardhat-network/provider/output.js +39 -36
  177. package/internal/hardhat-network/provider/output.js.map +1 -1
  178. package/internal/hardhat-network/provider/provider.d.ts +1 -2
  179. package/internal/hardhat-network/provider/provider.d.ts.map +1 -1
  180. package/internal/hardhat-network/provider/provider.js.map +1 -1
  181. package/internal/hardhat-network/provider/return-data.d.ts +2 -2
  182. package/internal/hardhat-network/provider/return-data.d.ts.map +1 -1
  183. package/internal/hardhat-network/provider/return-data.js +4 -1
  184. package/internal/hardhat-network/provider/return-data.js.map +1 -1
  185. package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.d.ts +5 -5
  186. package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.d.ts.map +1 -1
  187. package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.js +60 -17
  188. package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.js.map +1 -1
  189. package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.d.ts +4 -4
  190. package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.d.ts.map +1 -1
  191. package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.js +59 -16
  192. package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.js.map +1 -1
  193. package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.d.ts +3 -3
  194. package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.d.ts.map +1 -1
  195. package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.js +41 -9
  196. package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.js.map +1 -1
  197. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.d.ts +4 -4
  198. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.d.ts.map +1 -1
  199. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.js +7 -23
  200. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.js.map +1 -1
  201. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.d.ts +3 -3
  202. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.d.ts.map +1 -1
  203. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.js +7 -22
  204. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.js.map +1 -1
  205. package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.d.ts +3 -3
  206. package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.d.ts.map +1 -1
  207. package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.js +1 -1
  208. package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.js.map +1 -1
  209. package/internal/hardhat-network/provider/types/HardhatBlockchainInterface.d.ts +5 -6
  210. package/internal/hardhat-network/provider/types/HardhatBlockchainInterface.d.ts.map +1 -1
  211. package/internal/hardhat-network/provider/utils/fork-recomendations-banner.js +2 -3
  212. package/internal/hardhat-network/provider/utils/fork-recomendations-banner.js.map +1 -1
  213. package/internal/hardhat-network/provider/utils/getCurrentTimestamp.d.ts +1 -0
  214. package/internal/hardhat-network/provider/utils/getCurrentTimestamp.d.ts.map +1 -1
  215. package/internal/hardhat-network/provider/utils/getCurrentTimestamp.js +5 -1
  216. package/internal/hardhat-network/provider/utils/getCurrentTimestamp.js.map +1 -1
  217. package/internal/hardhat-network/provider/utils/makeAccount.d.ts +1 -1
  218. package/internal/hardhat-network/provider/utils/makeAccount.d.ts.map +1 -1
  219. package/internal/hardhat-network/provider/utils/makeAccount.js +6 -6
  220. package/internal/hardhat-network/provider/utils/makeAccount.js.map +1 -1
  221. package/internal/hardhat-network/provider/utils/makeCommon.d.ts +2 -2
  222. package/internal/hardhat-network/provider/utils/makeCommon.d.ts.map +1 -1
  223. package/internal/hardhat-network/provider/utils/makeCommon.js +7 -23
  224. package/internal/hardhat-network/provider/utils/makeCommon.js.map +1 -1
  225. package/internal/hardhat-network/provider/utils/makeForkClient.d.ts +1 -2
  226. package/internal/hardhat-network/provider/utils/makeForkClient.d.ts.map +1 -1
  227. package/internal/hardhat-network/provider/utils/makeForkClient.js +7 -8
  228. package/internal/hardhat-network/provider/utils/makeForkClient.js.map +1 -1
  229. package/internal/hardhat-network/provider/utils/makeStateTrie.d.ts +1 -1
  230. package/internal/hardhat-network/provider/utils/makeStateTrie.d.ts.map +1 -1
  231. package/internal/hardhat-network/provider/utils/makeStateTrie.js +4 -4
  232. package/internal/hardhat-network/provider/utils/makeStateTrie.js.map +1 -1
  233. package/internal/hardhat-network/provider/utils/putGenesisBlock.d.ts +6 -3
  234. package/internal/hardhat-network/provider/utils/putGenesisBlock.d.ts.map +1 -1
  235. package/internal/hardhat-network/provider/utils/putGenesisBlock.js +22 -4
  236. package/internal/hardhat-network/provider/utils/putGenesisBlock.js.map +1 -1
  237. package/internal/hardhat-network/provider/utils/random.d.ts +15 -0
  238. package/internal/hardhat-network/provider/utils/random.d.ts.map +1 -0
  239. package/internal/hardhat-network/provider/utils/random.js +48 -0
  240. package/internal/hardhat-network/provider/utils/random.js.map +1 -0
  241. package/internal/hardhat-network/provider/utils/reorganizeTransactionsLists.d.ts +1 -2
  242. package/internal/hardhat-network/provider/utils/reorganizeTransactionsLists.d.ts.map +1 -1
  243. package/internal/hardhat-network/provider/utils/reorganizeTransactionsLists.js +5 -4
  244. package/internal/hardhat-network/provider/utils/reorganizeTransactionsLists.js.map +1 -1
  245. package/internal/hardhat-network/provider/utils/reorgs-protection.d.ts +2 -2
  246. package/internal/hardhat-network/provider/utils/reorgs-protection.d.ts.map +1 -1
  247. package/internal/hardhat-network/provider/utils/reorgs-protection.js +7 -7
  248. package/internal/hardhat-network/provider/utils/reorgs-protection.js.map +1 -1
  249. package/internal/hardhat-network/provider/utils/txMapToArray.d.ts +1 -1
  250. package/internal/hardhat-network/provider/utils/txMapToArray.d.ts.map +1 -1
  251. package/internal/hardhat-network/stack-traces/compiler-to-model.js +6 -8
  252. package/internal/hardhat-network/stack-traces/compiler-to-model.js.map +1 -1
  253. package/internal/hardhat-network/stack-traces/consoleLogger.d.ts.map +1 -1
  254. package/internal/hardhat-network/stack-traces/consoleLogger.js +51 -47
  255. package/internal/hardhat-network/stack-traces/consoleLogger.js.map +1 -1
  256. package/internal/hardhat-network/stack-traces/constants.d.ts +3 -0
  257. package/internal/hardhat-network/stack-traces/constants.d.ts.map +1 -0
  258. package/internal/hardhat-network/stack-traces/constants.js +6 -0
  259. package/internal/hardhat-network/stack-traces/constants.js.map +1 -0
  260. package/internal/hardhat-network/stack-traces/contracts-identifier.js +2 -2
  261. package/internal/hardhat-network/stack-traces/contracts-identifier.js.map +1 -1
  262. package/internal/hardhat-network/stack-traces/debug.js +29 -19
  263. package/internal/hardhat-network/stack-traces/debug.js.map +1 -1
  264. package/internal/hardhat-network/stack-traces/error-inferrer.d.ts.map +1 -1
  265. package/internal/hardhat-network/stack-traces/error-inferrer.js +48 -26
  266. package/internal/hardhat-network/stack-traces/error-inferrer.js.map +1 -1
  267. package/internal/hardhat-network/stack-traces/logger.d.ts +223 -2
  268. package/internal/hardhat-network/stack-traces/logger.d.ts.map +1 -1
  269. package/internal/hardhat-network/stack-traces/logger.js +445 -224
  270. package/internal/hardhat-network/stack-traces/logger.js.map +1 -1
  271. package/internal/hardhat-network/stack-traces/message-trace.d.ts +6 -7
  272. package/internal/hardhat-network/stack-traces/message-trace.d.ts.map +1 -1
  273. package/internal/hardhat-network/stack-traces/message-trace.js.map +1 -1
  274. package/internal/hardhat-network/stack-traces/model.js +6 -6
  275. package/internal/hardhat-network/stack-traces/model.js.map +1 -1
  276. package/internal/hardhat-network/stack-traces/panic-errors.d.ts +1 -2
  277. package/internal/hardhat-network/stack-traces/panic-errors.d.ts.map +1 -1
  278. package/internal/hardhat-network/stack-traces/panic-errors.js +1 -1
  279. package/internal/hardhat-network/stack-traces/panic-errors.js.map +1 -1
  280. package/internal/hardhat-network/stack-traces/solidity-errors.d.ts.map +1 -1
  281. package/internal/hardhat-network/stack-traces/solidity-errors.js +21 -12
  282. package/internal/hardhat-network/stack-traces/solidity-errors.js.map +1 -1
  283. package/internal/hardhat-network/stack-traces/solidity-stack-trace.d.ts +6 -5
  284. package/internal/hardhat-network/stack-traces/solidity-stack-trace.d.ts.map +1 -1
  285. package/internal/hardhat-network/stack-traces/solidity-stack-trace.js.map +1 -1
  286. package/internal/hardhat-network/stack-traces/solidityTracer.d.ts +1 -1
  287. package/internal/hardhat-network/stack-traces/solidityTracer.d.ts.map +1 -1
  288. package/internal/hardhat-network/stack-traces/solidityTracer.js +5 -1
  289. package/internal/hardhat-network/stack-traces/solidityTracer.js.map +1 -1
  290. package/internal/hardhat-network/stack-traces/vm-debug-tracer.d.ts +2 -1
  291. package/internal/hardhat-network/stack-traces/vm-debug-tracer.d.ts.map +1 -1
  292. package/internal/hardhat-network/stack-traces/vm-debug-tracer.js +79 -78
  293. package/internal/hardhat-network/stack-traces/vm-debug-tracer.js.map +1 -1
  294. package/internal/hardhat-network/stack-traces/vm-trace-decoder.js +5 -1
  295. package/internal/hardhat-network/stack-traces/vm-trace-decoder.js.map +1 -1
  296. package/internal/hardhat-network/stack-traces/vm-tracer.d.ts +3 -2
  297. package/internal/hardhat-network/stack-traces/vm-tracer.d.ts.map +1 -1
  298. package/internal/hardhat-network/stack-traces/vm-tracer.js +15 -16
  299. package/internal/hardhat-network/stack-traces/vm-tracer.js.map +1 -1
  300. package/internal/reset.js +1 -1
  301. package/internal/reset.js.map +1 -1
  302. package/internal/sentry/anonymizer.js +2 -3
  303. package/internal/sentry/anonymizer.js.map +1 -1
  304. package/internal/sentry/subprocess.js +1 -1
  305. package/internal/sentry/subprocess.js.map +1 -1
  306. package/internal/sentry/transport.js +3 -4
  307. package/internal/sentry/transport.js.map +1 -1
  308. package/internal/solidity/compilation-job.js +2 -4
  309. package/internal/solidity/compilation-job.js.map +1 -1
  310. package/internal/solidity/compiler/downloader.d.ts.map +1 -1
  311. package/internal/solidity/compiler/downloader.js +6 -6
  312. package/internal/solidity/compiler/downloader.js.map +1 -1
  313. package/internal/solidity/dependencyGraph.js +3 -5
  314. package/internal/solidity/dependencyGraph.js.map +1 -1
  315. package/internal/solidity/parse.js +1 -1
  316. package/internal/solidity/parse.js.map +1 -1
  317. package/internal/solidity/resolver.js +4 -1
  318. package/internal/solidity/resolver.js.map +1 -1
  319. package/internal/util/abi-helpers.js +1 -1
  320. package/internal/util/abi-helpers.js.map +1 -1
  321. package/internal/util/bigint.d.ts +25 -0
  322. package/internal/util/bigint.d.ts.map +1 -0
  323. package/internal/util/bigint.js +67 -0
  324. package/internal/util/bigint.js.map +1 -0
  325. package/internal/util/download.js +1 -1
  326. package/internal/util/download.js.map +1 -1
  327. package/internal/util/fs-utils.d.ts +32 -0
  328. package/internal/util/fs-utils.d.ts.map +1 -0
  329. package/internal/util/fs-utils.js +151 -0
  330. package/internal/util/fs-utils.js.map +1 -0
  331. package/internal/util/hardforks.d.ts +3 -3
  332. package/internal/util/hardforks.d.ts.map +1 -1
  333. package/internal/util/hardforks.js +5 -28
  334. package/internal/util/hardforks.js.map +1 -1
  335. package/internal/util/jsonrpc.js +1 -1
  336. package/internal/util/jsonrpc.js.map +1 -1
  337. package/internal/util/lazy.js +2 -2
  338. package/internal/util/lazy.js.map +1 -1
  339. package/internal/util/packageInfo.js +1 -1
  340. package/internal/util/packageInfo.js.map +1 -1
  341. package/internal/util/scripts-runner.js +5 -2
  342. package/internal/util/scripts-runner.js.map +1 -1
  343. package/internal/util/wei-values.d.ts +1 -2
  344. package/internal/util/wei-values.d.ts.map +1 -1
  345. package/internal/util/wei-values.js +9 -10
  346. package/internal/util/wei-values.js.map +1 -1
  347. package/internal/vendor/await-semaphore/index.d.ts +12 -0
  348. package/internal/vendor/await-semaphore/index.d.ts.map +1 -0
  349. package/internal/vendor/await-semaphore/index.js +64 -0
  350. package/internal/vendor/await-semaphore/index.js.map +1 -0
  351. package/package.json +13 -9
  352. package/profiling.d.ts +18 -0
  353. package/profiling.d.ts.map +1 -0
  354. package/profiling.js +32 -0
  355. package/profiling.js.map +1 -0
  356. package/sample-projects/javascript/scripts/deploy.js +3 -1
  357. package/sample-projects/javascript/test/Lock.js +1 -1
  358. package/sample-projects/typescript/scripts/deploy.ts +1 -1
  359. package/sample-projects/typescript/test/Lock.ts +1 -1
  360. package/src/builtin-tasks/node.ts +4 -6
  361. package/src/internal/constants.ts +3 -1
  362. package/src/internal/core/config/config-resolution.ts +30 -7
  363. package/src/internal/core/config/default-config.ts +12 -4
  364. package/src/internal/core/jsonrpc/types/base-types.ts +23 -24
  365. package/src/internal/core/jsonrpc/types/input/blockTag.ts +2 -4
  366. package/src/internal/core/jsonrpc/types/input/callRequest.ts +0 -4
  367. package/src/internal/core/jsonrpc/types/input/filterRequest.ts +0 -4
  368. package/src/internal/core/jsonrpc/types/input/transactionRequest.ts +0 -4
  369. package/src/internal/core/jsonrpc/types/output/block.ts +0 -4
  370. package/src/internal/core/jsonrpc/types/output/log.ts +0 -4
  371. package/src/internal/core/jsonrpc/types/output/receipt.ts +0 -4
  372. package/src/internal/core/jsonrpc/types/output/transaction.ts +0 -4
  373. package/src/internal/core/providers/accounts.ts +16 -26
  374. package/src/internal/core/providers/construction.ts +5 -3
  375. package/src/internal/core/providers/gas-providers.ts +25 -33
  376. package/src/internal/core/providers/util.ts +1 -1
  377. package/src/internal/hardhat-network/jsonrpc/client.ts +22 -22
  378. package/src/internal/hardhat-network/provider/BlockchainBase.ts +62 -25
  379. package/src/internal/hardhat-network/provider/BlockchainData.ts +39 -42
  380. package/src/internal/hardhat-network/provider/HardhatBlockchain.ts +21 -21
  381. package/src/internal/hardhat-network/provider/PoolState.ts +3 -4
  382. package/src/internal/hardhat-network/provider/TransactionQueue.ts +11 -8
  383. package/src/internal/hardhat-network/provider/TxPool.ts +62 -64
  384. package/src/internal/hardhat-network/provider/ethereumjs-workarounds.ts +3 -3
  385. package/src/internal/hardhat-network/provider/filter.ts +9 -12
  386. package/src/internal/hardhat-network/provider/fork/ForkBlockchain.ts +52 -50
  387. package/src/internal/hardhat-network/provider/fork/ForkStateManager.ts +35 -60
  388. package/src/internal/hardhat-network/provider/fork/rpcToBlockData.ts +2 -2
  389. package/src/internal/hardhat-network/provider/fork/rpcToTxData.ts +3 -3
  390. package/src/internal/hardhat-network/provider/modules/eth.ts +88 -63
  391. package/src/internal/hardhat-network/provider/modules/evm.ts +19 -22
  392. package/src/internal/hardhat-network/provider/modules/hardhat.ts +21 -19
  393. package/src/internal/hardhat-network/provider/modules/logger.ts +33 -40
  394. package/src/internal/hardhat-network/provider/modules/net.ts +1 -1
  395. package/src/internal/hardhat-network/provider/modules/personal.ts +2 -1
  396. package/src/internal/hardhat-network/provider/modules/web3.ts +5 -4
  397. package/src/internal/hardhat-network/provider/node-types.ts +32 -31
  398. package/src/internal/hardhat-network/provider/node.ts +379 -343
  399. package/src/internal/hardhat-network/provider/output.ts +32 -37
  400. package/src/internal/hardhat-network/provider/provider.ts +5 -6
  401. package/src/internal/hardhat-network/provider/return-data.ts +6 -3
  402. package/src/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.ts +51 -24
  403. package/src/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.ts +50 -23
  404. package/src/internal/hardhat-network/provider/transactions/FakeSenderTransaction.ts +29 -11
  405. package/src/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.ts +12 -24
  406. package/src/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.ts +11 -22
  407. package/src/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.ts +3 -3
  408. package/src/internal/hardhat-network/provider/types/HardhatBlockchainInterface.ts +8 -9
  409. package/src/internal/hardhat-network/provider/utils/getCurrentTimestamp.ts +4 -0
  410. package/src/internal/hardhat-network/provider/utils/makeAccount.ts +4 -10
  411. package/src/internal/hardhat-network/provider/utils/makeCommon.ts +8 -34
  412. package/src/internal/hardhat-network/provider/utils/makeForkClient.ts +8 -9
  413. package/src/internal/hardhat-network/provider/utils/makeStateTrie.ts +3 -3
  414. package/src/internal/hardhat-network/provider/utils/putGenesisBlock.ts +34 -6
  415. package/src/internal/hardhat-network/provider/utils/random.ts +54 -0
  416. package/src/internal/hardhat-network/provider/utils/reorganizeTransactionsLists.ts +6 -7
  417. package/src/internal/hardhat-network/provider/utils/reorgs-protection.ts +8 -8
  418. package/src/internal/hardhat-network/stack-traces/consoleLogger.ts +16 -6
  419. package/src/internal/hardhat-network/stack-traces/contracts-identifier.ts +1 -1
  420. package/src/internal/hardhat-network/stack-traces/debug.ts +1 -1
  421. package/src/internal/hardhat-network/stack-traces/error-inferrer.ts +11 -7
  422. package/src/internal/hardhat-network/stack-traces/logger.ts +444 -223
  423. package/src/internal/hardhat-network/stack-traces/message-trace.ts +6 -7
  424. package/src/internal/hardhat-network/stack-traces/model.ts +1 -1
  425. package/src/internal/hardhat-network/stack-traces/panic-errors.ts +3 -5
  426. package/src/internal/hardhat-network/stack-traces/solidity-errors.ts +16 -1
  427. package/src/internal/hardhat-network/stack-traces/solidity-stack-trace.ts +6 -6
  428. package/src/internal/hardhat-network/stack-traces/solidityTracer.ts +6 -1
  429. package/src/internal/hardhat-network/stack-traces/vm-debug-tracer.ts +106 -103
  430. package/src/internal/hardhat-network/stack-traces/vm-tracer.ts +23 -18
  431. package/src/internal/solidity/compiler/downloader.ts +5 -2
  432. package/src/internal/util/bigint.ts +84 -0
  433. package/src/internal/util/hardforks.ts +4 -29
  434. package/src/internal/util/wei-values.ts +11 -13
  435. package/src/types/config.ts +8 -10
  436. package/types/config.d.ts +8 -9
  437. package/types/config.d.ts.map +1 -1
  438. package/src/internal/hardhat-network/provider/fork/random.ts +0 -33
  439. package/src/internal/hardhat-network/provider/utils/bnToHex.ts +0 -5
  440. package/src/internal/hardhat-network/provider/utils/makeForkCommon.ts +0 -15
@@ -4,18 +4,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.HardhatNode = void 0;
7
- const block_1 = require("@ethereumjs/block");
8
- const common_1 = __importDefault(require("@ethereumjs/common"));
9
- const tx_1 = require("@ethereumjs/tx");
10
- const vm_1 = __importDefault(require("@ethereumjs/vm"));
11
- const bloom_1 = __importDefault(require("@ethereumjs/vm/dist/bloom"));
12
- const exceptions_1 = require("@ethereumjs/vm/dist/exceptions");
13
- const state_1 = require("@ethereumjs/vm/dist/state");
7
+ const block_1 = require("@ignored/block");
8
+ const common_1 = require("@ignored/common");
9
+ const tx_1 = require("@ignored/tx");
10
+ const util_1 = require("@ignored/util");
11
+ const vm_1 = require("@ignored/vm");
12
+ const evm_1 = require("@ignored/evm");
13
+ const exceptions_1 = require("@ignored/evm/dist/exceptions");
14
+ const statemanager_1 = require("@ignored/statemanager");
14
15
  const eth_sig_util_1 = require("@metamask/eth-sig-util");
15
16
  const chalk_1 = __importDefault(require("chalk"));
16
17
  const debug_1 = __importDefault(require("debug"));
17
- const ethereumjs_util_1 = require("ethereumjs-util");
18
18
  const events_1 = __importDefault(require("events"));
19
+ const bigint_1 = require("../../util/bigint");
19
20
  const constants_1 = require("../../constants");
20
21
  const default_config_1 = require("../../core/config/default-config");
21
22
  const errors_1 = require("../../core/errors");
@@ -51,13 +52,13 @@ const getCurrentTimestamp_1 = require("./utils/getCurrentTimestamp");
51
52
  const makeCommon_1 = require("./utils/makeCommon");
52
53
  const makeForkClient_1 = require("./utils/makeForkClient");
53
54
  const makeStateTrie_1 = require("./utils/makeStateTrie");
54
- const makeForkCommon_1 = require("./utils/makeForkCommon");
55
55
  const putGenesisBlock_1 = require("./utils/putGenesisBlock");
56
56
  const txMapToArray_1 = require("./utils/txMapToArray");
57
+ const random_1 = require("./utils/random");
57
58
  const log = (0, debug_1.default)("hardhat:core:hardhat-network:node");
58
59
  /* eslint-disable @nomiclabs/hardhat-internal-rules/only-hardhat-error */
59
60
  class HardhatNode extends events_1.default {
60
- constructor(_vm, _stateManager, _blockchain, _txPool, _automine, _minGasPrice, _blockTimeOffsetSeconds = new ethereumjs_util_1.BN(0), _mempoolOrder, _coinbase, genesisAccounts, _configNetworkId, _configChainId, _hardforkActivations, tracingConfig, _forkNetworkId, _forkBlockNumber, nextBlockBaseFee, _forkClient) {
61
+ constructor(_vm, _stateManager, _blockchain, _txPool, _automine, _minGasPrice, _blockTimeOffsetSeconds = 0n, _mempoolOrder, _coinbase, genesisAccounts, _configNetworkId, _configChainId, hardfork, _hardforkActivations, _mixHashGenerator, tracingConfig, _forkNetworkId, _forkBlockNumber, nextBlockBaseFee, _forkClient) {
61
62
  super();
62
63
  this._vm = _vm;
63
64
  this._stateManager = _stateManager;
@@ -70,20 +71,23 @@ class HardhatNode extends events_1.default {
70
71
  this._coinbase = _coinbase;
71
72
  this._configNetworkId = _configNetworkId;
72
73
  this._configChainId = _configChainId;
74
+ this.hardfork = hardfork;
73
75
  this._hardforkActivations = _hardforkActivations;
76
+ this._mixHashGenerator = _mixHashGenerator;
74
77
  this._forkNetworkId = _forkNetworkId;
75
78
  this._forkBlockNumber = _forkBlockNumber;
76
79
  this._forkClient = _forkClient;
77
80
  this._localAccounts = new Map(); // address => private key
78
81
  this._impersonatedAccounts = new Set(); // address
79
- this._nextBlockTimestamp = new ethereumjs_util_1.BN(0);
80
- this._lastFilterId = new ethereumjs_util_1.BN(0);
82
+ this._nextBlockTimestamp = 0n;
83
+ this._lastFilterId = 0n;
81
84
  this._filters = new Map();
82
85
  this._nextSnapshotId = 1; // We start in 1 to mimic Ganache
83
86
  this._snapshots = [];
84
87
  this._consoleLogger = new consoleLogger_1.ConsoleLogger();
85
88
  this._failedStackTraces = 0;
86
- this._irregularStatesByBlockNumber = new Map(); // blockNumber as BN.toString() => state root
89
+ // blockNumber => state root
90
+ this._irregularStatesByBlockNumber = new Map();
87
91
  this._initLocalAccounts(genesisAccounts);
88
92
  if (nextBlockBaseFee !== undefined) {
89
93
  this.setUserProvidedNextBlockBaseFeePerGas(nextBlockBaseFee);
@@ -114,7 +118,6 @@ class HardhatNode extends events_1.default {
114
118
  }
115
119
  static async create(config) {
116
120
  const { automine, genesisAccounts, blockGasLimit, allowUnlimitedContractSize, tracingConfig, minGasPrice, mempoolOrder, networkId, chainId, } = config;
117
- let common;
118
121
  let stateManager;
119
122
  let blockchain;
120
123
  let initialBlockTimeOffset;
@@ -123,22 +126,23 @@ class HardhatNode extends events_1.default {
123
126
  let forkBlockNum;
124
127
  let hardforkActivations = new Map();
125
128
  const initialBaseFeePerGasConfig = config.initialBaseFeePerGas !== undefined
126
- ? new ethereumjs_util_1.BN(config.initialBaseFeePerGas)
129
+ ? BigInt(config.initialBaseFeePerGas)
127
130
  : undefined;
128
131
  const hardfork = (0, hardforks_1.getHardforkName)(config.hardfork);
132
+ const mixHashGenerator = random_1.RandomBufferGenerator.create("randomMixHashSeed");
129
133
  let forkClient;
134
+ const common = (0, makeCommon_1.makeCommon)(config);
130
135
  if ((0, node_types_1.isForkedNodeConfig)(config)) {
131
136
  const { forkClient: _forkClient, forkBlockNumber, forkBlockTimestamp, } = await (0, makeForkClient_1.makeForkClient)(config.forkConfig, config.forkCachePath);
132
137
  forkClient = _forkClient;
133
- common = await (0, makeForkCommon_1.makeForkCommon)(config);
134
138
  forkNetworkId = forkClient.getNetworkId();
135
- forkBlockNum = forkBlockNumber.toNumber();
136
- this._validateHardforks(config.forkConfig.blockNumber, common, forkNetworkId);
139
+ forkBlockNum = forkBlockNumber;
140
+ this._validateHardforks(bigint_1.BigIntUtils.mapNumberToBigInt(config.forkConfig.blockNumber), common, forkNetworkId);
137
141
  const forkStateManager = new ForkStateManager_1.ForkStateManager(forkClient, forkBlockNumber);
138
142
  await forkStateManager.initializeGenesisAccounts(genesisAccounts);
139
143
  stateManager = forkStateManager;
140
144
  blockchain = new ForkBlockchain_1.ForkBlockchain(forkClient, forkBlockNumber, common);
141
- initialBlockTimeOffset = new ethereumjs_util_1.BN((0, date_1.getDifferenceInSeconds)(new Date(forkBlockTimestamp), new Date()));
145
+ initialBlockTimeOffset = BigInt((0, date_1.getDifferenceInSeconds)(new Date(forkBlockTimestamp), new Date()));
142
146
  // If the hardfork is London or later we need a base fee per gas for the
143
147
  // first local block. If initialBaseFeePerGas config was provided we use
144
148
  // that. Otherwise, what we do depends on the block we forked from. If
@@ -151,7 +155,7 @@ class HardhatNode extends events_1.default {
151
155
  else {
152
156
  const latestBlock = await blockchain.getLatestBlock();
153
157
  if (latestBlock.header.baseFeePerGas === undefined) {
154
- nextBlockBaseFeePerGas = new ethereumjs_util_1.BN(default_config_1.HARDHAT_NETWORK_DEFAULT_INITIAL_BASE_FEE_PER_GAS);
158
+ nextBlockBaseFeePerGas = BigInt(default_config_1.HARDHAT_NETWORK_DEFAULT_INITIAL_BASE_FEE_PER_GAS);
155
159
  }
156
160
  }
157
161
  }
@@ -161,30 +165,35 @@ class HardhatNode extends events_1.default {
161
165
  }
162
166
  else {
163
167
  const stateTrie = await (0, makeStateTrie_1.makeStateTrie)(genesisAccounts);
164
- common = (0, makeCommon_1.makeCommon)(config, stateTrie);
165
- stateManager = new state_1.DefaultStateManager({
166
- common,
168
+ stateManager = new statemanager_1.DefaultStateManager({
167
169
  trie: stateTrie,
168
170
  });
169
171
  const hardhatBlockchain = new HardhatBlockchain_1.HardhatBlockchain(common);
170
172
  const genesisBlockBaseFeePerGas = (0, hardforks_1.hardforkGte)(hardfork, hardforks_1.HardforkName.LONDON)
171
- ? initialBaseFeePerGasConfig !== null && initialBaseFeePerGasConfig !== void 0 ? initialBaseFeePerGasConfig : new ethereumjs_util_1.BN(default_config_1.HARDHAT_NETWORK_DEFAULT_INITIAL_BASE_FEE_PER_GAS)
173
+ ? initialBaseFeePerGasConfig ??
174
+ BigInt(default_config_1.HARDHAT_NETWORK_DEFAULT_INITIAL_BASE_FEE_PER_GAS)
172
175
  : undefined;
173
- await (0, putGenesisBlock_1.putGenesisBlock)(hardhatBlockchain, common, genesisBlockBaseFeePerGas);
176
+ await (0, putGenesisBlock_1.putGenesisBlock)(hardhatBlockchain, common, config, stateTrie, hardfork, mixHashGenerator.next(), genesisBlockBaseFeePerGas);
174
177
  if (config.initialDate !== undefined) {
175
- initialBlockTimeOffset = new ethereumjs_util_1.BN((0, date_1.getDifferenceInSeconds)(config.initialDate, new Date()));
178
+ initialBlockTimeOffset = BigInt((0, date_1.getDifferenceInSeconds)(config.initialDate, new Date()));
176
179
  }
177
180
  blockchain = hardhatBlockchain;
178
181
  }
179
- const txPool = new TxPool_1.TxPool(stateManager, new ethereumjs_util_1.BN(blockGasLimit), common);
180
- const vm = new vm_1.default({
182
+ const txPool = new TxPool_1.TxPool(stateManager, BigInt(blockGasLimit), common);
183
+ const eei = new vm_1.EEI(stateManager, common, blockchain);
184
+ const evm = await evm_1.EVM.create({
185
+ eei,
186
+ allowUnlimitedContractSize,
181
187
  common,
188
+ });
189
+ const vm = await vm_1.VM.create({
190
+ evm,
182
191
  activatePrecompiles: true,
192
+ common,
183
193
  stateManager,
184
- blockchain: blockchain,
185
- allowUnlimitedContractSize,
194
+ blockchain,
186
195
  });
187
- const node = new HardhatNode(vm, stateManager, blockchain, txPool, automine, minGasPrice, initialBlockTimeOffset, mempoolOrder, config.coinbase, genesisAccounts, networkId, chainId, hardforkActivations, tracingConfig, forkNetworkId, forkBlockNum, nextBlockBaseFeePerGas, forkClient);
196
+ const node = new HardhatNode(vm, stateManager, blockchain, txPool, automine, minGasPrice, initialBlockTimeOffset, mempoolOrder, config.coinbase, genesisAccounts, networkId, chainId, hardfork, hardforkActivations, mixHashGenerator, tracingConfig, forkNetworkId, forkBlockNum, nextBlockBaseFeePerGas, forkClient);
188
197
  return [common, node];
189
198
  }
190
199
  static _validateHardforks(forkBlockNumber, common, remoteChainId) {
@@ -196,9 +205,9 @@ The hardfork must be at least spuriousDragon, but ${common.hardfork()} was given
196
205
  if (forkBlockNumber !== undefined) {
197
206
  let upstreamCommon;
198
207
  try {
199
- upstreamCommon = new common_1.default({ chain: remoteChainId });
208
+ upstreamCommon = new common_1.Common({ chain: remoteChainId });
200
209
  }
201
- catch (_a) {
210
+ catch {
202
211
  // If ethereumjs doesn't have a common it will throw and we won't have
203
212
  // info about the activation block of each hardfork, so we don't run
204
213
  // this validation.
@@ -213,7 +222,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
213
222
  }
214
223
  }
215
224
  async getSignedTransaction(txParams) {
216
- const senderAddress = (0, ethereumjs_util_1.bufferToHex)(txParams.from);
225
+ const senderAddress = (0, util_1.bufferToHex)(txParams.from);
217
226
  const pk = this._localAccounts.get(senderAddress);
218
227
  if (pk !== undefined) {
219
228
  let tx;
@@ -249,10 +258,12 @@ Hardhat Network's forking functionality only works with blocks from at least spu
249
258
  return this._mineTransaction(tx);
250
259
  }
251
260
  async mineBlock(timestamp) {
252
- const [blockTimestamp, offsetShouldChange, newOffset] = this._calculateTimestampAndOffset(timestamp);
261
+ const timestampAndOffset = this._calculateTimestampAndOffset(timestamp);
262
+ let [blockTimestamp] = timestampAndOffset;
263
+ const [, offsetShouldChange, newOffset] = timestampAndOffset;
253
264
  const needsTimestampIncrease = await this._timestampClashesWithPreviousBlockOne(blockTimestamp);
254
265
  if (needsTimestampIncrease) {
255
- blockTimestamp.iaddn(1);
266
+ blockTimestamp += 1n;
256
267
  }
257
268
  let result;
258
269
  try {
@@ -260,7 +271,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
260
271
  }
261
272
  catch (err) {
262
273
  if (err instanceof Error) {
263
- if (err === null || err === void 0 ? void 0 : err.message.includes("sender doesn't have enough funds")) {
274
+ if (err?.message.includes("sender doesn't have enough funds")) {
264
275
  throw new errors_2.InvalidInputError(err.message, err);
265
276
  }
266
277
  // Some network errors are HardhatErrors, and can end up here when forking
@@ -274,7 +285,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
274
285
  }
275
286
  await this._saveBlockAsSuccessfullyRun(result.block, result.blockResult);
276
287
  if (needsTimestampIncrease) {
277
- this.increaseTime(new ethereumjs_util_1.BN(1));
288
+ this.increaseTime(1n);
278
289
  }
279
290
  if (offsetShouldChange) {
280
291
  this.setTimeIncrement(newOffset);
@@ -290,8 +301,8 @@ Hardhat Network's forking functionality only works with blocks from at least spu
290
301
  * Returns an array with the results of the blocks that were really mined (the
291
302
  * ones that were reserved are not included).
292
303
  */
293
- async mineBlocks(count = new ethereumjs_util_1.BN(1), interval = new ethereumjs_util_1.BN(1)) {
294
- if (count.eqn(0)) {
304
+ async mineBlocks(count = 1n, interval = 1n) {
305
+ if (count === 0n) {
295
306
  // nothing to do
296
307
  return [];
297
308
  }
@@ -301,67 +312,77 @@ Hardhat Network's forking functionality only works with blocks from at least spu
301
312
  // helper function to mine a block with a timstamp that respects the
302
313
  // interval
303
314
  const mineBlock = async () => {
304
- const nextTimestamp = (await this.getLatestBlock()).header.timestamp.add(interval);
315
+ const nextTimestamp = (await this.getLatestBlock()).header.timestamp + interval;
305
316
  mineBlockResults.push(await this.mineBlock(nextTimestamp));
306
317
  };
307
318
  // then we mine any pending transactions
308
- while (count.gtn(mineBlockResults.length) &&
319
+ while (count > mineBlockResults.length &&
309
320
  this._txPool.hasPendingTransactions()) {
310
321
  await mineBlock();
311
322
  }
312
323
  // If there is at least one remaining block, we mine one. This way, we
313
324
  // guarantee that there's an empty block immediately before and after the
314
325
  // reservation. This makes the logging easier to get right.
315
- if (count.gtn(mineBlockResults.length)) {
326
+ if (count > mineBlockResults.length) {
316
327
  await mineBlock();
317
328
  }
318
- const remainingBlockCount = count.subn(mineBlockResults.length);
329
+ const remainingBlockCount = count - BigInt(mineBlockResults.length);
319
330
  // There should be at least 2 blocks left for the reservation to work,
320
331
  // because we always mine a block after it. But here we use a bigger
321
332
  // number to err on the safer side.
322
- if (remainingBlockCount.lten(5)) {
333
+ if (remainingBlockCount <= 5) {
323
334
  // if there are few blocks left to mine, we just mine them
324
- while (count.gtn(mineBlockResults.length)) {
335
+ while (count > mineBlockResults.length) {
325
336
  await mineBlock();
326
337
  }
327
338
  return mineBlockResults;
328
339
  }
329
340
  // otherwise, we reserve a range and mine the last one
330
341
  const latestBlock = await this.getLatestBlock();
331
- this._blockchain.reserveBlocks(remainingBlockCount.subn(1), interval, await this._stateManager.getStateRoot(), await this.getBlockTotalDifficulty(latestBlock), (await this.getLatestBlock()).header.baseFeePerGas);
342
+ this._blockchain.reserveBlocks(remainingBlockCount - 1n, interval, await this._stateManager.getStateRoot(), await this.getBlockTotalDifficulty(latestBlock), (await this.getLatestBlock()).header.baseFeePerGas);
332
343
  await mineBlock();
333
344
  return mineBlockResults;
334
345
  }
335
346
  async runCall(call, blockNumberOrPending) {
336
- var _a, _b, _c, _d;
337
347
  let txParams;
338
- const nonce = await this._getNonce(new ethereumjs_util_1.Address(call.from), blockNumberOrPending);
348
+ const nonce = await this._getNonce(new util_1.Address(call.from), blockNumberOrPending);
339
349
  if (call.gasPrice !== undefined ||
340
350
  !this.isEip1559Active(blockNumberOrPending)) {
341
- txParams = Object.assign({ gasPrice: new ethereumjs_util_1.BN(0), nonce }, call);
351
+ txParams = {
352
+ gasPrice: 0n,
353
+ nonce,
354
+ ...call,
355
+ };
342
356
  }
343
357
  else {
344
- const maxFeePerGas = (_b = (_a = call.maxFeePerGas) !== null && _a !== void 0 ? _a : call.maxPriorityFeePerGas) !== null && _b !== void 0 ? _b : new ethereumjs_util_1.BN(0);
345
- const maxPriorityFeePerGas = (_c = call.maxPriorityFeePerGas) !== null && _c !== void 0 ? _c : new ethereumjs_util_1.BN(0);
346
- txParams = Object.assign(Object.assign({}, call), { nonce,
358
+ const maxFeePerGas = call.maxFeePerGas ?? call.maxPriorityFeePerGas ?? 0n;
359
+ const maxPriorityFeePerGas = call.maxPriorityFeePerGas ?? 0n;
360
+ txParams = {
361
+ ...call,
362
+ nonce,
347
363
  maxFeePerGas,
348
- maxPriorityFeePerGas, accessList: (_d = call.accessList) !== null && _d !== void 0 ? _d : [] });
364
+ maxPriorityFeePerGas,
365
+ accessList: call.accessList ?? [],
366
+ };
349
367
  }
350
368
  const tx = await this._getFakeTransaction(txParams);
351
369
  const result = await this._runInBlockContext(blockNumberOrPending, async () => this._runTxAndRevertMutations(tx, blockNumberOrPending, true));
352
370
  const traces = await this._gatherTraces(result.execResult);
353
- return Object.assign(Object.assign({}, traces), { result: new return_data_1.ReturnData(result.execResult.returnValue) });
371
+ return {
372
+ ...traces,
373
+ result: new return_data_1.ReturnData(result.execResult.returnValue),
374
+ };
354
375
  }
355
376
  async getAccountBalance(address, blockNumberOrPending) {
356
377
  if (blockNumberOrPending === undefined) {
357
378
  blockNumberOrPending = this.getLatestBlockNumber();
358
379
  }
359
380
  const account = await this._runInBlockContext(blockNumberOrPending, () => this._stateManager.getAccount(address));
360
- return new ethereumjs_util_1.BN(account.balance);
381
+ return account.balance;
361
382
  }
362
383
  async getNextConfirmedNonce(address, blockNumberOrPending) {
363
384
  const account = await this._runInBlockContext(blockNumberOrPending, () => this._stateManager.getAccount(address));
364
- return new ethereumjs_util_1.BN(account.nonce);
385
+ return account.nonce;
365
386
  }
366
387
  async getAccountNextPendingNonce(address) {
367
388
  return this._txPool.getNextPendingNonce(address);
@@ -372,7 +393,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
372
393
  (0, message_trace_1.isCreateTrace)(trace)) {
373
394
  return Buffer.from("");
374
395
  }
375
- return this.getCode(new ethereumjs_util_1.Address(trace.address), blockNumberOrPending);
396
+ return this.getCode(new util_1.Address(trace.address), blockNumberOrPending);
376
397
  }
377
398
  async getLatestBlock() {
378
399
  return this._blockchain.getLatestBlock();
@@ -394,10 +415,9 @@ Hardhat Network's forking functionality only works with blocks from at least spu
394
415
  return this._txPool.getBlockGasLimit();
395
416
  }
396
417
  async estimateGas(callParams, blockNumberOrPending) {
397
- var _a, _b;
398
418
  // We get the CallParams and transform it into a TransactionParams to be
399
419
  // able to run it.
400
- const nonce = await this._getNonce(new ethereumjs_util_1.Address(callParams.from), blockNumberOrPending);
420
+ const nonce = await this._getNonce(new util_1.Address(callParams.from), blockNumberOrPending);
401
421
  // TODO: This is more complex in Geth, we should make sure we aren't missing
402
422
  // anything here.
403
423
  const feePriceFields = await this._getEstimateGasFeePriceFields(callParams, blockNumberOrPending);
@@ -405,16 +425,31 @@ Hardhat Network's forking functionality only works with blocks from at least spu
405
425
  if ("gasPrice" in feePriceFields) {
406
426
  if (callParams.accessList === undefined) {
407
427
  // Legacy tx
408
- txParams = Object.assign(Object.assign({}, callParams), { nonce, gasPrice: feePriceFields.gasPrice });
428
+ txParams = {
429
+ ...callParams,
430
+ nonce,
431
+ gasPrice: feePriceFields.gasPrice,
432
+ };
409
433
  }
410
434
  else {
411
435
  // Access list tx
412
- txParams = Object.assign(Object.assign({}, callParams), { nonce, gasPrice: feePriceFields.gasPrice, accessList: (_a = callParams.accessList) !== null && _a !== void 0 ? _a : [] });
436
+ txParams = {
437
+ ...callParams,
438
+ nonce,
439
+ gasPrice: feePriceFields.gasPrice,
440
+ accessList: callParams.accessList ?? [],
441
+ };
413
442
  }
414
443
  }
415
444
  else {
416
445
  // EIP-1559 tx
417
- txParams = Object.assign(Object.assign({}, callParams), { nonce, maxFeePerGas: feePriceFields.maxFeePerGas, maxPriorityFeePerGas: feePriceFields.maxPriorityFeePerGas, accessList: (_b = callParams.accessList) !== null && _b !== void 0 ? _b : [] });
446
+ txParams = {
447
+ ...callParams,
448
+ nonce,
449
+ maxFeePerGas: feePriceFields.maxFeePerGas,
450
+ maxPriorityFeePerGas: feePriceFields.maxPriorityFeePerGas,
451
+ accessList: callParams.accessList ?? [],
452
+ };
418
453
  }
419
454
  const tx = await this._getFakeTransaction(txParams);
420
455
  // TODO: This may not work if there are multiple txs in the mempool and
@@ -439,7 +474,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
439
474
  consoleLogMessages,
440
475
  };
441
476
  }
442
- const initialEstimation = result.gasUsed;
477
+ const initialEstimation = result.totalGasSpent;
443
478
  return {
444
479
  estimation: await this._correctInitialEstimation(blockNumberOrPending, txParams, initialEstimation),
445
480
  trace: vmTrace,
@@ -450,19 +485,19 @@ Hardhat Network's forking functionality only works with blocks from at least spu
450
485
  const nextBlockBaseFeePerGas = await this.getNextBlockBaseFeePerGas();
451
486
  if (nextBlockBaseFeePerGas === undefined) {
452
487
  // We return a hardcoded value for networks without EIP-1559
453
- return new ethereumjs_util_1.BN(8e9);
488
+ return 8n * 10n ** 9n;
454
489
  }
455
- const suggestedPriorityFeePerGas = new ethereumjs_util_1.BN(1e9);
456
- return nextBlockBaseFeePerGas.add(suggestedPriorityFeePerGas);
490
+ const suggestedPriorityFeePerGas = 10n ** 9n;
491
+ return nextBlockBaseFeePerGas + suggestedPriorityFeePerGas;
457
492
  }
458
493
  async getMaxPriorityFeePerGas() {
459
- return new ethereumjs_util_1.BN(default_config_1.HARDHAT_NETWORK_DEFAULT_MAX_PRIORITY_FEE_PER_GAS);
494
+ return BigInt(default_config_1.HARDHAT_NETWORK_DEFAULT_MAX_PRIORITY_FEE_PER_GAS);
460
495
  }
461
496
  getCoinbaseAddress() {
462
- return ethereumjs_util_1.Address.fromString(this._coinbase);
497
+ return util_1.Address.fromString(this._coinbase);
463
498
  }
464
499
  async getStorageAt(address, positionIndex, blockNumberOrPending) {
465
- const key = positionIndex.toArrayLike(Buffer, "be", 32);
500
+ const key = (0, util_1.setLengthLeft)((0, util_1.bigIntToBuffer)(positionIndex), 32);
466
501
  const data = await this._runInBlockContext(blockNumberOrPending, () => this._stateManager.getContractStorage(address, key));
467
502
  const EXPECTED_DATA_SIZE = 32;
468
503
  if (data.length < EXPECTED_DATA_SIZE) {
@@ -475,15 +510,15 @@ Hardhat Network's forking functionality only works with blocks from at least spu
475
510
  return this._runInPendingBlockContext(() => this._blockchain.getLatestBlock());
476
511
  }
477
512
  const block = await this._blockchain.getBlock(blockNumberOrPending);
478
- return block !== null && block !== void 0 ? block : undefined;
513
+ return block ?? undefined;
479
514
  }
480
515
  async getBlockByHash(blockHash) {
481
516
  const block = await this._blockchain.getBlock(blockHash);
482
- return block !== null && block !== void 0 ? block : undefined;
517
+ return block ?? undefined;
483
518
  }
484
519
  async getBlockByTransactionHash(hash) {
485
520
  const block = await this._blockchain.getBlockByTransactionHash(hash);
486
- return block !== null && block !== void 0 ? block : undefined;
521
+ return block ?? undefined;
487
522
  }
488
523
  async getBlockTotalDifficulty(block) {
489
524
  return this._blockchain.getTotalDifficulty(block.hash());
@@ -492,19 +527,19 @@ Hardhat Network's forking functionality only works with blocks from at least spu
492
527
  return this._runInBlockContext(blockNumberOrPending, () => this._stateManager.getContractCode(address));
493
528
  }
494
529
  getNextBlockTimestamp() {
495
- return this._nextBlockTimestamp.clone();
530
+ return this._nextBlockTimestamp;
496
531
  }
497
532
  setNextBlockTimestamp(timestamp) {
498
- this._nextBlockTimestamp = new ethereumjs_util_1.BN(timestamp);
533
+ this._nextBlockTimestamp = timestamp;
499
534
  }
500
535
  getTimeIncrement() {
501
- return this._blockTimeOffsetSeconds.clone();
536
+ return this._blockTimeOffsetSeconds;
502
537
  }
503
538
  setTimeIncrement(timeIncrement) {
504
539
  this._blockTimeOffsetSeconds = timeIncrement;
505
540
  }
506
541
  increaseTime(increment) {
507
- this._blockTimeOffsetSeconds = this._blockTimeOffsetSeconds.add(increment);
542
+ this._blockTimeOffsetSeconds += increment;
508
543
  }
509
544
  setUserProvidedNextBlockBaseFeePerGas(baseFeePerGas) {
510
545
  this._userProvidedNextBlockBaseFeePerGas = baseFeePerGas;
@@ -527,13 +562,12 @@ Hardhat Network's forking functionality only works with blocks from at least spu
527
562
  return latestBlock.header.calcNextBaseFee();
528
563
  }
529
564
  async getPendingTransaction(hash) {
530
- var _a;
531
- return (_a = this._txPool.getTransactionByHash(hash)) === null || _a === void 0 ? void 0 : _a.data;
565
+ return this._txPool.getTransactionByHash(hash)?.data;
532
566
  }
533
567
  async getTransactionReceipt(hash) {
534
- const hashBuffer = hash instanceof Buffer ? hash : (0, ethereumjs_util_1.toBuffer)(hash);
568
+ const hashBuffer = hash instanceof Buffer ? hash : (0, util_1.toBuffer)(hash);
535
569
  const receipt = await this._blockchain.getTransactionReceipt(hashBuffer);
536
- return receipt !== null && receipt !== void 0 ? receipt : undefined;
570
+ return receipt ?? undefined;
537
571
  }
538
572
  async getPendingTransactions() {
539
573
  const txPoolPending = (0, txMapToArray_1.txMapToArray)(this._txPool.getPendingTransactions());
@@ -541,9 +575,9 @@ Hardhat Network's forking functionality only works with blocks from at least spu
541
575
  return txPoolPending.concat(txPoolQueued);
542
576
  }
543
577
  async signPersonalMessage(address, data) {
544
- const messageHash = (0, ethereumjs_util_1.hashPersonalMessage)(data);
578
+ const messageHash = (0, util_1.hashPersonalMessage)(data);
545
579
  const privateKey = this._getLocalAccountPrivateKey(address);
546
- return (0, ethereumjs_util_1.ecsign)(messageHash, privateKey);
580
+ return (0, util_1.ecsign)(messageHash, privateKey);
547
581
  }
548
582
  async signTypedDataV4(address, typedData) {
549
583
  const privateKey = this._getLocalAccountPrivateKey(address);
@@ -569,6 +603,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
569
603
  irregularStatesByBlockNumber: this._irregularStatesByBlockNumber,
570
604
  userProvidedNextBlockBaseFeePerGas: this.getUserProvidedNextBlockBaseFeePerGas(),
571
605
  coinbase: this.getCoinbaseAddress().toString(),
606
+ mixHashGenerator: this._mixHashGenerator.clone(),
572
607
  };
573
608
  this._irregularStatesByBlockNumber = new Map(this._irregularStatesByBlockNumber);
574
609
  this._snapshots.push(snapshot);
@@ -586,7 +621,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
586
621
  const now = new Date();
587
622
  const offsetToSnapshotInMillis = snapshot.date.valueOf() - now.valueOf();
588
623
  const offsetToSnapshotInSecs = Math.ceil(offsetToSnapshotInMillis / 1000);
589
- const newOffset = snapshot.blockTimeOffsetSeconds.addn(offsetToSnapshotInSecs);
624
+ const newOffset = snapshot.blockTimeOffsetSeconds + BigInt(offsetToSnapshotInSecs);
590
625
  // We delete all following blocks, changes the state root, and all the
591
626
  // relevant Node fields.
592
627
  //
@@ -594,8 +629,8 @@ Hardhat Network's forking functionality only works with blocks from at least spu
594
629
  // used once
595
630
  this._blockchain.deleteLaterBlocks(snapshot.latestBlock);
596
631
  this._irregularStatesByBlockNumber = snapshot.irregularStatesByBlockNumber;
597
- const irregularStateOrUndefined = this._irregularStatesByBlockNumber.get((await this.getLatestBlock()).header.number.toString());
598
- await this._stateManager.setStateRoot(irregularStateOrUndefined !== null && irregularStateOrUndefined !== void 0 ? irregularStateOrUndefined : snapshot.stateRoot);
632
+ const irregularStateOrUndefined = this._irregularStatesByBlockNumber.get((await this.getLatestBlock()).header.number);
633
+ await this._stateManager.setStateRoot(irregularStateOrUndefined ?? snapshot.stateRoot);
599
634
  this.setTimeIncrement(newOffset);
600
635
  this.setNextBlockTimestamp(snapshot.nextBlockTimestamp);
601
636
  this._txPool.revert(snapshot.txPoolSnapshotId);
@@ -606,6 +641,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
606
641
  this._resetUserProvidedNextBlockBaseFeePerGas();
607
642
  }
608
643
  this._coinbase = snapshot.coinbase;
644
+ this._mixHashGenerator = snapshot.mixHashGenerator;
609
645
  // We delete this and the following snapshots, as they can only be used
610
646
  // once in Ganache
611
647
  this._snapshots.splice(snapshotIndex);
@@ -637,7 +673,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
637
673
  id: filterId,
638
674
  type: filter_1.Type.BLOCK_SUBSCRIPTION,
639
675
  deadline: this._newDeadline(),
640
- hashes: [(0, ethereumjs_util_1.bufferToHex)(block.header.hash())],
676
+ hashes: [(0, util_1.bufferToHex)(block.header.hash())],
641
677
  logs: [],
642
678
  subscription: isSubscription,
643
679
  });
@@ -719,11 +755,11 @@ Hardhat Network's forking functionality only works with blocks from at least spu
719
755
  return true;
720
756
  }
721
757
  addImpersonatedAccount(address) {
722
- this._impersonatedAccounts.add((0, ethereumjs_util_1.bufferToHex)(address));
758
+ this._impersonatedAccounts.add((0, util_1.bufferToHex)(address));
723
759
  return true;
724
760
  }
725
761
  removeImpersonatedAccount(address) {
726
- return this._impersonatedAccounts.delete((0, ethereumjs_util_1.bufferToHex)(address));
762
+ return this._impersonatedAccounts.delete((0, util_1.bufferToHex)(address));
727
763
  }
728
764
  setAutomine(automine) {
729
765
  this._automine = automine;
@@ -745,7 +781,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
745
781
  }
746
782
  const isTransactionMined = await this._isTransactionMined(hash);
747
783
  if (isTransactionMined) {
748
- throw new errors_2.InvalidArgumentsError(`Transaction ${(0, ethereumjs_util_1.bufferToHex)(hash)} cannot be dropped because it's already mined`);
784
+ throw new errors_2.InvalidArgumentsError(`Transaction ${(0, util_1.bufferToHex)(hash)} cannot be dropped because it's already mined`);
749
785
  }
750
786
  return false;
751
787
  }
@@ -764,7 +800,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
764
800
  throw new errors_2.InternalError("Cannot set account nonce when the transaction pool is not empty");
765
801
  }
766
802
  const account = await this._stateManager.getAccount(address);
767
- if (newNonce.lt(account.nonce)) {
803
+ if (newNonce < account.nonce) {
768
804
  throw new errors_2.InvalidInputError(`New nonce (${newNonce.toString()}) must not be smaller than the existing nonce (${account.nonce.toString()})`);
769
805
  }
770
806
  account.nonce = newNonce;
@@ -772,23 +808,23 @@ Hardhat Network's forking functionality only works with blocks from at least spu
772
808
  await this._persistIrregularWorldState();
773
809
  }
774
810
  async setStorageAt(address, positionIndex, value) {
775
- await this._stateManager.putContractStorage(address, positionIndex.toArrayLike(Buffer, "be", 32), value);
811
+ await this._stateManager.putContractStorage(address, (0, util_1.setLengthLeft)((0, util_1.bigIntToBuffer)(positionIndex), 32), value);
776
812
  await this._persistIrregularWorldState();
777
813
  }
778
814
  async traceTransaction(hash, config) {
779
815
  const block = await this.getBlockByTransactionHash(hash);
780
816
  if (block === undefined) {
781
- throw new errors_2.InvalidInputError(`Unable to find a block containing transaction ${(0, ethereumjs_util_1.bufferToHex)(hash)}`);
817
+ throw new errors_2.InvalidInputError(`Unable to find a block containing transaction ${(0, util_1.bufferToHex)(hash)}`);
782
818
  }
783
- return this._runInBlockContext(new ethereumjs_util_1.BN(block.header.number).subn(1), async () => {
784
- const blockNumber = block.header.number.toNumber();
819
+ return this._runInBlockContext(block.header.number - 1n, async () => {
820
+ const blockNumber = block.header.number;
785
821
  const blockchain = this._blockchain;
786
822
  let vm = this._vm;
787
823
  if (blockchain instanceof ForkBlockchain_1.ForkBlockchain &&
788
- blockNumber <= blockchain.getForkBlockNumber().toNumber()) {
824
+ blockNumber <= blockchain.getForkBlockNumber()) {
789
825
  (0, errors_1.assertHardhatInvariant)(this._forkNetworkId !== undefined, "this._forkNetworkId should exist if the blockchain is an instance of ForkBlockchain");
790
826
  const common = this._getCommonForTracing(this._forkNetworkId, blockNumber);
791
- vm = new vm_1.default({
827
+ vm = await vm_1.VM.create({
792
828
  common,
793
829
  activatePrecompiles: true,
794
830
  stateManager: this._vm.stateManager,
@@ -817,7 +853,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
817
853
  });
818
854
  }
819
855
  else if (tx.type === 2) {
820
- txWithCommon = new FakeSenderEIP1559Transaction_1.FakeSenderEIP1559Transaction(sender, Object.assign(Object.assign({}, tx), { gasPrice: undefined }), {
856
+ txWithCommon = new FakeSenderEIP1559Transaction_1.FakeSenderEIP1559Transaction(sender, { ...tx, gasPrice: undefined }, {
821
857
  common: vm._common,
822
858
  });
823
859
  }
@@ -837,23 +873,22 @@ Hardhat Network's forking functionality only works with blocks from at least spu
837
873
  });
838
874
  }
839
875
  async getFeeHistory(blockCount, newestBlock, rewardPercentiles) {
840
- var _a;
841
876
  const latestBlock = this.getLatestBlockNumber();
842
- const pendingBlockNumber = latestBlock.addn(1);
877
+ const pendingBlockNumber = latestBlock + 1n;
843
878
  const resolvedNewestBlock = newestBlock === "pending" ? pendingBlockNumber : newestBlock;
844
- const oldestBlock = ethereumjs_util_1.BN.max(resolvedNewestBlock.sub(blockCount).addn(1), new ethereumjs_util_1.BN(0));
879
+ const oldestBlock = bigint_1.BigIntUtils.max(resolvedNewestBlock - blockCount + 1n, 0n);
845
880
  // This is part of a temporary fix to https://github.com/NomicFoundation/hardhat/issues/2380
846
881
  const rangeIncludesRemoteBlocks = this._forkBlockNumber !== undefined &&
847
- oldestBlock.lten(this._forkBlockNumber);
882
+ oldestBlock <= this._forkBlockNumber;
848
883
  const baseFeePerGas = [];
849
884
  const gasUsedRatio = [];
850
885
  const reward = [];
851
- const lastBlock = resolvedNewestBlock.addn(1);
886
+ const lastBlock = resolvedNewestBlock + 1n;
852
887
  // This is part of a temporary fix to https://github.com/NomicFoundation/hardhat/issues/2380
853
888
  if (rangeIncludesRemoteBlocks) {
854
889
  try {
855
- const lastRemoteBlock = ethereumjs_util_1.BN.min(new ethereumjs_util_1.BN(this._forkBlockNumber), lastBlock);
856
- const remoteBlockCount = lastRemoteBlock.sub(oldestBlock).addn(1);
890
+ const lastRemoteBlock = bigint_1.BigIntUtils.min(BigInt(this._forkBlockNumber), lastBlock);
891
+ const remoteBlockCount = lastRemoteBlock - oldestBlock + 1n;
857
892
  const remoteValues = await this._forkClient.getFeeHistory(remoteBlockCount, lastRemoteBlock, rewardPercentiles);
858
893
  baseFeePerGas.push(...remoteValues.baseFeePerGas);
859
894
  gasUsedRatio.push(...remoteValues.gasUsedRatio);
@@ -869,39 +904,39 @@ Hardhat Network's forking functionality only works with blocks from at least spu
869
904
  // We get the pending block here, and only if necessary, as it's something
870
905
  // costly to do.
871
906
  let pendingBlock;
872
- if (lastBlock.gte(pendingBlockNumber)) {
907
+ if (lastBlock >= pendingBlockNumber) {
873
908
  pendingBlock = await this.getBlockByNumber("pending");
874
909
  }
875
910
  // This is part of a temporary fix to https://github.com/NomicFoundation/hardhat/issues/2380
876
911
  const firstLocalBlock = !rangeIncludesRemoteBlocks
877
912
  ? oldestBlock
878
- : ethereumjs_util_1.BN.min(new ethereumjs_util_1.BN(this._forkBlockNumber), lastBlock).addn(1);
913
+ : bigint_1.BigIntUtils.min(BigInt(this._forkBlockNumber), lastBlock) + 1n;
879
914
  for (let blockNumber = firstLocalBlock; // This is part of a temporary fix to https://github.com/NomicFoundation/hardhat/issues/2380
880
- blockNumber.lte(lastBlock); blockNumber = blockNumber.addn(1)) {
881
- if (blockNumber.lt(pendingBlockNumber)) {
915
+ blockNumber <= lastBlock; blockNumber++) {
916
+ if (blockNumber < pendingBlockNumber) {
882
917
  // We know the block exists
883
918
  const block = (await this.getBlockByNumber(blockNumber));
884
- baseFeePerGas.push((_a = block.header.baseFeePerGas) !== null && _a !== void 0 ? _a : new ethereumjs_util_1.BN(0));
885
- if (blockNumber.lt(lastBlock)) {
919
+ baseFeePerGas.push(block.header.baseFeePerGas ?? 0n);
920
+ if (blockNumber < lastBlock) {
886
921
  gasUsedRatio.push(this._getGasUsedRatio(block));
887
922
  if (rewardPercentiles.length > 0) {
888
923
  reward.push(await this._getRewards(block, rewardPercentiles));
889
924
  }
890
925
  }
891
926
  }
892
- else if (blockNumber.eq(pendingBlockNumber)) {
927
+ else if (blockNumber === pendingBlockNumber) {
893
928
  // This can only be run with EIP-1559, so this exists
894
929
  baseFeePerGas.push((await this.getNextBlockBaseFeePerGas()));
895
- if (blockNumber.lt(lastBlock)) {
930
+ if (blockNumber < lastBlock) {
896
931
  gasUsedRatio.push(this._getGasUsedRatio(pendingBlock));
897
932
  if (rewardPercentiles.length > 0) {
898
933
  // We don't compute this for the pending block, as there's no
899
934
  // effective miner fee yet.
900
- reward.push(rewardPercentiles.map((_) => new ethereumjs_util_1.BN(0)));
935
+ reward.push(rewardPercentiles.map((_) => 0n));
901
936
  }
902
937
  }
903
938
  }
904
- else if (blockNumber.eq(pendingBlockNumber.addn(1))) {
939
+ else if (blockNumber === pendingBlockNumber + 1n) {
905
940
  baseFeePerGas.push(pendingBlock.header.calcNextBaseFee());
906
941
  }
907
942
  else {
@@ -920,49 +955,45 @@ Hardhat Network's forking functionality only works with blocks from at least spu
920
955
  }
921
956
  _getGasUsedRatio(block) {
922
957
  const FLOATS_PRECISION = 100000;
923
- return (block.header.gasUsed
924
- .muln(FLOATS_PRECISION)
925
- .div(block.header.gasLimit)
926
- .toNumber() / FLOATS_PRECISION);
958
+ return (Number((block.header.gasUsed * BigInt(FLOATS_PRECISION)) /
959
+ block.header.gasLimit) / FLOATS_PRECISION);
927
960
  }
928
961
  async _getRewards(block, rewardPercentiles) {
929
962
  const FLOATS_PRECISION = 100000;
930
963
  if (block.transactions.length === 0) {
931
- return rewardPercentiles.map((_) => new ethereumjs_util_1.BN(0));
964
+ return rewardPercentiles.map((_) => 0n);
932
965
  }
933
966
  const receipts = await Promise.all(block.transactions
934
967
  .map((tx) => tx.hash())
935
968
  .map((hash) => this.getTransactionReceipt(hash)));
936
969
  const effectiveGasRewardAndGas = receipts
937
970
  .map((r, i) => {
938
- var _a;
939
971
  const tx = block.transactions[i];
940
- const baseFeePerGas = (_a = block.header.baseFeePerGas) !== null && _a !== void 0 ? _a : new ethereumjs_util_1.BN(0);
972
+ const baseFeePerGas = block.header.baseFeePerGas ?? 0n;
941
973
  // reward = min(maxPriorityFeePerGas, maxFeePerGas - baseFeePerGas)
942
974
  let effectiveGasReward;
943
975
  if ("maxPriorityFeePerGas" in tx) {
944
- effectiveGasReward = tx.maxFeePerGas.sub(baseFeePerGas);
945
- if (tx.maxPriorityFeePerGas.lt(effectiveGasReward)) {
976
+ effectiveGasReward = tx.maxFeePerGas - baseFeePerGas;
977
+ if (tx.maxPriorityFeePerGas < effectiveGasReward) {
946
978
  effectiveGasReward = tx.maxPriorityFeePerGas;
947
979
  }
948
980
  }
949
981
  else {
950
- effectiveGasReward = tx.gasPrice.sub(baseFeePerGas);
982
+ effectiveGasReward = tx.gasPrice - baseFeePerGas;
951
983
  }
952
984
  return {
953
985
  effectiveGasReward,
954
- gasUsed: (0, base_types_1.rpcQuantityToBN)(r === null || r === void 0 ? void 0 : r.gasUsed),
986
+ gasUsed: (0, base_types_1.rpcQuantityToBigInt)(r?.gasUsed),
955
987
  };
956
988
  })
957
- .sort((a, b) => a.effectiveGasReward.cmp(b.effectiveGasReward));
989
+ .sort((a, b) => bigint_1.BigIntUtils.cmp(a.effectiveGasReward, b.effectiveGasReward));
958
990
  return rewardPercentiles.map((p) => {
959
- let gasUsed = new ethereumjs_util_1.BN(0);
960
- const targetGas = block.header.gasLimit
961
- .muln(Math.ceil(p * FLOATS_PRECISION))
962
- .divn(100 * FLOATS_PRECISION);
991
+ let gasUsed = 0n;
992
+ const targetGas = (block.header.gasLimit * BigInt(Math.ceil(p * FLOATS_PRECISION))) /
993
+ BigInt(100 * FLOATS_PRECISION);
963
994
  for (const values of effectiveGasRewardAndGas) {
964
- gasUsed = gasUsed.add(values.gasUsed);
965
- if (targetGas.lte(gasUsed)) {
995
+ gasUsed += values.gasUsed;
996
+ if (targetGas <= gasUsed) {
966
997
  return values.effectiveGasReward;
967
998
  }
968
999
  }
@@ -973,7 +1004,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
973
1004
  async _addPendingTransaction(tx) {
974
1005
  await this._txPool.addTransaction(tx);
975
1006
  await this._notifyPendingTransaction(tx);
976
- return (0, ethereumjs_util_1.bufferToHex)(tx.hash());
1007
+ return (0, util_1.bufferToHex)(tx.hash());
977
1008
  }
978
1009
  async _mineTransaction(tx) {
979
1010
  await this._addPendingTransaction(tx);
@@ -1037,29 +1068,29 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1037
1068
  }
1038
1069
  // validate nonce
1039
1070
  const nextPendingNonce = await this._txPool.getNextPendingNonce(sender);
1040
- const txNonce = new ethereumjs_util_1.BN(tx.nonce);
1071
+ const txNonce = tx.nonce;
1041
1072
  const expectedNonceMsg = `Expected nonce to be ${nextPendingNonce.toString()} but got ${txNonce.toString()}.`;
1042
- if (txNonce.gt(nextPendingNonce)) {
1073
+ if (txNonce > nextPendingNonce) {
1043
1074
  throw new errors_2.InvalidInputError(`Nonce too high. ${expectedNonceMsg} Note that transactions can't be queued when automining.`);
1044
1075
  }
1045
- if (txNonce.lt(nextPendingNonce)) {
1076
+ if (txNonce < nextPendingNonce) {
1046
1077
  throw new errors_2.InvalidInputError(`Nonce too low. ${expectedNonceMsg}`);
1047
1078
  }
1048
1079
  // validate gas price
1049
- const txPriorityFee = new ethereumjs_util_1.BN("gasPrice" in tx ? tx.gasPrice : tx.maxPriorityFeePerGas);
1050
- if (txPriorityFee.lt(this._minGasPrice)) {
1080
+ const txPriorityFee = "gasPrice" in tx ? tx.gasPrice : tx.maxPriorityFeePerGas;
1081
+ if (txPriorityFee < this._minGasPrice) {
1051
1082
  throw new errors_2.InvalidInputError(`Transaction gas price is ${txPriorityFee.toString()}, which is below the minimum of ${this._minGasPrice.toString()}`);
1052
1083
  }
1053
1084
  // Validate that maxFeePerGas >= next block's baseFee
1054
1085
  const nextBlockGasFee = await this.getNextBlockBaseFeePerGas();
1055
1086
  if (nextBlockGasFee !== undefined) {
1056
1087
  if ("maxFeePerGas" in tx) {
1057
- if (nextBlockGasFee.gt(tx.maxFeePerGas)) {
1088
+ if (nextBlockGasFee > tx.maxFeePerGas) {
1058
1089
  throw new errors_2.InvalidInputError(`Transaction maxFeePerGas (${tx.maxFeePerGas.toString()}) is too low for the next block, which has a baseFeePerGas of ${nextBlockGasFee.toString()}`);
1059
1090
  }
1060
1091
  }
1061
1092
  else {
1062
- if (nextBlockGasFee.gt(tx.gasPrice)) {
1093
+ if (nextBlockGasFee > tx.gasPrice) {
1063
1094
  throw new errors_2.InvalidInputError(`Transaction gasPrice (${tx.gasPrice.toString()}) is too low for the next block, which has a baseFeePerGas of ${nextBlockGasFee.toString()}`);
1064
1095
  }
1065
1096
  }
@@ -1076,9 +1107,14 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1076
1107
  const headerData = {
1077
1108
  gasLimit: this.getBlockGasLimit(),
1078
1109
  coinbase: this.getCoinbaseAddress(),
1079
- nonce: "0x0000000000000042",
1110
+ nonce: this.isPostMergeHardfork()
1111
+ ? "0x0000000000000000"
1112
+ : "0x0000000000000042",
1080
1113
  timestamp: blockTimestamp,
1081
1114
  };
1115
+ if (this.isPostMergeHardfork()) {
1116
+ headerData.mixHash = this._getNextMixHash();
1117
+ }
1082
1118
  headerData.baseFeePerGas = await this.getNextBlockBaseFeePerGas();
1083
1119
  const blockBuilder = await this._vm.buildBlock({
1084
1120
  parentBlock,
@@ -1094,10 +1130,10 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1094
1130
  let tx = transactionQueue.getNextTransaction();
1095
1131
  const results = [];
1096
1132
  const receipts = [];
1097
- while (blockGasLimit.sub(blockBuilder.gasUsed).gte(minTxFee) &&
1133
+ while (blockGasLimit - blockBuilder.gasUsed >= minTxFee &&
1098
1134
  tx !== undefined) {
1099
1135
  if (!this._isTxMinable(tx, headerData.baseFeePerGas) ||
1100
- tx.gasLimit.gt(blockGasLimit.sub(blockBuilder.gasUsed))) {
1136
+ tx.gasLimit > blockGasLimit - blockBuilder.gasUsed) {
1101
1137
  transactionQueue.removeLastSenderTransactions();
1102
1138
  }
1103
1139
  else {
@@ -1116,7 +1152,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1116
1152
  results,
1117
1153
  receipts,
1118
1154
  stateRoot: block.header.stateRoot,
1119
- logsBloom: block.header.bloom,
1155
+ logsBloom: block.header.logsBloom,
1120
1156
  receiptRoot: block.header.receiptTrie,
1121
1157
  gasUsed: block.header.gasUsed,
1122
1158
  },
@@ -1130,10 +1166,10 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1130
1166
  }
1131
1167
  _getMinimalTransactionFee() {
1132
1168
  // Typically 21_000 gas
1133
- return new ethereumjs_util_1.BN(this._vm._common.param("gasPrices", "tx"));
1169
+ return this._vm._common.param("gasPrices", "tx");
1134
1170
  }
1135
1171
  async _getFakeTransaction(txParams) {
1136
- const sender = new ethereumjs_util_1.Address(txParams.from);
1172
+ const sender = new util_1.Address(txParams.from);
1137
1173
  if ("maxFeePerGas" in txParams && txParams.maxFeePerGas !== undefined) {
1138
1174
  return new FakeSenderEIP1559Transaction_1.FakeSenderEIP1559Transaction(sender, txParams, {
1139
1175
  common: this._vm._common,
@@ -1168,9 +1204,9 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1168
1204
  this._snapshots.splice(snapshotIndex);
1169
1205
  }
1170
1206
  _initLocalAccounts(genesisAccounts) {
1171
- const privateKeys = genesisAccounts.map((acc) => (0, ethereumjs_util_1.toBuffer)(acc.privateKey));
1207
+ const privateKeys = genesisAccounts.map((acc) => (0, util_1.toBuffer)(acc.privateKey));
1172
1208
  for (const pk of privateKeys) {
1173
- this._localAccounts.set((0, ethereumjs_util_1.bufferToHex)((0, ethereumjs_util_1.privateToAddress)(pk)), pk);
1209
+ this._localAccounts.set((0, util_1.bufferToHex)((0, util_1.privateToAddress)(pk)), pk);
1174
1210
  }
1175
1211
  }
1176
1212
  async _getConsoleLogMessages(vmTrace, vmTracerError) {
@@ -1221,7 +1257,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1221
1257
  returnDataExplanation = `with reason "${returnData.decodeError()}"`;
1222
1258
  }
1223
1259
  else if (returnData.isPanicReturnData()) {
1224
- const panicCode = returnData.decodePanic().toString("hex");
1260
+ const panicCode = returnData.decodePanic().toString(16);
1225
1261
  returnDataExplanation = `with panic code "0x${panicCode}"`;
1226
1262
  }
1227
1263
  else {
@@ -1247,14 +1283,14 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1247
1283
  _calculateTimestampAndOffset(timestamp) {
1248
1284
  let blockTimestamp;
1249
1285
  let offsetShouldChange;
1250
- let newOffset = new ethereumjs_util_1.BN(0);
1251
- const currentTimestamp = new ethereumjs_util_1.BN((0, getCurrentTimestamp_1.getCurrentTimestamp)());
1286
+ let newOffset = 0n;
1287
+ const currentTimestamp = BigInt((0, getCurrentTimestamp_1.getCurrentTimestamp)());
1252
1288
  // if timestamp is not provided, we check nextBlockTimestamp, if it is
1253
1289
  // set, we use it as the timestamp instead. If it is not set, we use
1254
1290
  // time offset + real time as the timestamp.
1255
- if (timestamp === undefined || timestamp.eqn(0)) {
1256
- if (this.getNextBlockTimestamp().eqn(0)) {
1257
- blockTimestamp = currentTimestamp.add(this.getTimeIncrement());
1291
+ if (timestamp === undefined || timestamp === 0n) {
1292
+ if (this.getNextBlockTimestamp() === 0n) {
1293
+ blockTimestamp = currentTimestamp + this.getTimeIncrement();
1258
1294
  offsetShouldChange = false;
1259
1295
  }
1260
1296
  else {
@@ -1267,17 +1303,17 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1267
1303
  blockTimestamp = timestamp;
1268
1304
  }
1269
1305
  if (offsetShouldChange) {
1270
- newOffset = blockTimestamp.sub(currentTimestamp);
1306
+ newOffset = blockTimestamp - currentTimestamp;
1271
1307
  }
1272
1308
  return [blockTimestamp, offsetShouldChange, newOffset];
1273
1309
  }
1274
1310
  _resetNextBlockTimestamp() {
1275
- this.setNextBlockTimestamp(new ethereumjs_util_1.BN(0));
1311
+ this.setNextBlockTimestamp(0n);
1276
1312
  }
1277
1313
  async _notifyPendingTransaction(tx) {
1278
1314
  this._filters.forEach((filter) => {
1279
1315
  if (filter.type === filter_1.Type.PENDING_TRANSACTION_SUBSCRIPTION) {
1280
- const hash = (0, ethereumjs_util_1.bufferToHex)(tx.hash());
1316
+ const hash = (0, util_1.bufferToHex)(tx.hash());
1281
1317
  if (filter.subscription) {
1282
1318
  this._emitEthEvent(filter.id, hash);
1283
1319
  return;
@@ -1316,10 +1352,10 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1316
1352
  this._emitEthEvent(filter.id, (0, output_1.getRpcBlock)(block, td, (0, output_1.shouldShowTransactionTypeForHardfork)(this._vm._common), false));
1317
1353
  return;
1318
1354
  }
1319
- filter.hashes.push((0, ethereumjs_util_1.bufferToHex)(hash));
1355
+ filter.hashes.push((0, util_1.bufferToHex)(hash));
1320
1356
  break;
1321
1357
  case filter_1.Type.LOGS_SUBSCRIPTION:
1322
- if ((0, filter_1.bloomFilter)(new bloom_1.default(block.header.bloom), filter.criteria.addresses, filter.criteria.normalizedTopics)) {
1358
+ if ((0, filter_1.bloomFilter)(new vm_1.Bloom(block.header.logsBloom), filter.criteria.addresses, filter.criteria.normalizedTopics)) {
1323
1359
  const logs = (0, filter_1.filterLogs)(rpcLogs, filter.criteria);
1324
1360
  if (logs.length === 0) {
1325
1361
  return;
@@ -1338,14 +1374,14 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1338
1374
  }
1339
1375
  async _timestampClashesWithPreviousBlockOne(blockTimestamp) {
1340
1376
  const latestBlock = await this.getLatestBlock();
1341
- const latestBlockTimestamp = new ethereumjs_util_1.BN(latestBlock.header.timestamp);
1342
- return latestBlockTimestamp.eq(blockTimestamp);
1377
+ const latestBlockTimestamp = latestBlock.header.timestamp;
1378
+ return latestBlockTimestamp === blockTimestamp;
1343
1379
  }
1344
1380
  async _runInBlockContext(blockNumberOrPending, action) {
1345
1381
  if (blockNumberOrPending === "pending") {
1346
1382
  return this._runInPendingBlockContext(action);
1347
1383
  }
1348
- if (blockNumberOrPending.eq(this.getLatestBlockNumber())) {
1384
+ if (blockNumberOrPending === this.getLatestBlockNumber()) {
1349
1385
  return action();
1350
1386
  }
1351
1387
  const block = await this.getBlockByNumber(blockNumberOrPending);
@@ -1373,11 +1409,11 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1373
1409
  }
1374
1410
  }
1375
1411
  async _setBlockContext(block) {
1376
- const irregularStateOrUndefined = this._irregularStatesByBlockNumber.get(block.header.number.toString());
1412
+ const irregularStateOrUndefined = this._irregularStatesByBlockNumber.get(block.header.number);
1377
1413
  if (this._stateManager instanceof ForkStateManager_1.ForkStateManager) {
1378
1414
  return this._stateManager.setBlockContext(block.header.stateRoot, block.header.number, irregularStateOrUndefined);
1379
1415
  }
1380
- return this._stateManager.setStateRoot(irregularStateOrUndefined !== null && irregularStateOrUndefined !== void 0 ? irregularStateOrUndefined : block.header.stateRoot);
1416
+ return this._stateManager.setStateRoot(irregularStateOrUndefined ?? block.header.stateRoot);
1381
1417
  }
1382
1418
  async _restoreBlockContext(stateRoot) {
1383
1419
  if (this._stateManager instanceof ForkStateManager_1.ForkStateManager) {
@@ -1386,10 +1422,16 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1386
1422
  return this._stateManager.setStateRoot(stateRoot);
1387
1423
  }
1388
1424
  async _correctInitialEstimation(blockNumberOrPending, txParams, initialEstimation) {
1389
- let tx = await this._getFakeTransaction(Object.assign(Object.assign({}, txParams), { gasLimit: initialEstimation }));
1390
- if (tx.getBaseFee().gte(initialEstimation)) {
1391
- initialEstimation = tx.getBaseFee().addn(1);
1392
- tx = await this._getFakeTransaction(Object.assign(Object.assign({}, txParams), { gasLimit: initialEstimation }));
1425
+ let tx = await this._getFakeTransaction({
1426
+ ...txParams,
1427
+ gasLimit: initialEstimation,
1428
+ });
1429
+ if (tx.getBaseFee() >= initialEstimation) {
1430
+ initialEstimation = tx.getBaseFee() + 1n;
1431
+ tx = await this._getFakeTransaction({
1432
+ ...txParams,
1433
+ gasLimit: initialEstimation,
1434
+ });
1393
1435
  }
1394
1436
  const result = await this._runInBlockContext(blockNumberOrPending, () => this._runTxAndRevertMutations(tx, blockNumberOrPending));
1395
1437
  if (result.execResult.exceptionError === undefined) {
@@ -1398,40 +1440,43 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1398
1440
  return this._binarySearchEstimation(blockNumberOrPending, txParams, initialEstimation, this.getBlockGasLimit());
1399
1441
  }
1400
1442
  async _binarySearchEstimation(blockNumberOrPending, txParams, highestFailingEstimation, lowestSuccessfulEstimation, roundNumber = 0) {
1401
- if (lowestSuccessfulEstimation.lte(highestFailingEstimation)) {
1443
+ if (lowestSuccessfulEstimation <= highestFailingEstimation) {
1402
1444
  // This shouldn't happen, but we don't want to go into an infinite loop
1403
1445
  // if it ever happens
1404
1446
  return lowestSuccessfulEstimation;
1405
1447
  }
1406
1448
  const MAX_GAS_ESTIMATION_IMPROVEMENT_ROUNDS = 20;
1407
- const diff = lowestSuccessfulEstimation.sub(highestFailingEstimation);
1408
- const minDiff = highestFailingEstimation.gten(4000000)
1449
+ const diff = lowestSuccessfulEstimation - highestFailingEstimation;
1450
+ const minDiff = highestFailingEstimation >= 4000000n
1409
1451
  ? 50000
1410
- : highestFailingEstimation.gten(1000000)
1452
+ : highestFailingEstimation >= 1000000n
1411
1453
  ? 10000
1412
- : highestFailingEstimation.gten(100000)
1454
+ : highestFailingEstimation >= 100000n
1413
1455
  ? 1000
1414
- : highestFailingEstimation.gten(50000)
1456
+ : highestFailingEstimation >= 50000n
1415
1457
  ? 500
1416
- : highestFailingEstimation.gten(30000)
1458
+ : highestFailingEstimation >= 30000n
1417
1459
  ? 300
1418
1460
  : 200;
1419
- if (diff.lten(minDiff)) {
1461
+ if (diff <= minDiff) {
1420
1462
  return lowestSuccessfulEstimation;
1421
1463
  }
1422
1464
  if (roundNumber > MAX_GAS_ESTIMATION_IMPROVEMENT_ROUNDS) {
1423
1465
  return lowestSuccessfulEstimation;
1424
1466
  }
1425
- const binSearchNewEstimation = highestFailingEstimation.add(diff.divn(2));
1467
+ const binSearchNewEstimation = highestFailingEstimation + diff / 2n;
1426
1468
  const optimizedEstimation = roundNumber === 0
1427
- ? highestFailingEstimation.muln(3)
1469
+ ? 3n * highestFailingEstimation
1428
1470
  : binSearchNewEstimation;
1429
- const newEstimation = optimizedEstimation.gt(binSearchNewEstimation)
1471
+ const newEstimation = optimizedEstimation > binSearchNewEstimation
1430
1472
  ? binSearchNewEstimation
1431
1473
  : optimizedEstimation;
1432
1474
  // Let other things execute
1433
1475
  await new Promise((resolve) => setImmediate(resolve));
1434
- const tx = await this._getFakeTransaction(Object.assign(Object.assign({}, txParams), { gasLimit: newEstimation }));
1476
+ const tx = await this._getFakeTransaction({
1477
+ ...txParams,
1478
+ gasLimit: newEstimation,
1479
+ });
1435
1480
  const result = await this._runInBlockContext(blockNumberOrPending, () => this._runTxAndRevertMutations(tx, blockNumberOrPending));
1436
1481
  if (result.execResult.exceptionError === undefined) {
1437
1482
  return this._binarySearchEstimation(blockNumberOrPending, txParams, highestFailingEstimation, newEstimation, roundNumber + 1);
@@ -1443,7 +1488,6 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1443
1488
  * makes.
1444
1489
  */
1445
1490
  async _runTxAndRevertMutations(tx, blockNumberOrPending, forceBaseFeeZero = false) {
1446
- var _a;
1447
1491
  const initialStateRoot = await this._stateManager.getStateRoot();
1448
1492
  let blockContext;
1449
1493
  let originalCommon;
@@ -1461,7 +1505,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1461
1505
  // we don't need to add the tx to the block because runTx doesn't
1462
1506
  // know anything about the txs in the current block
1463
1507
  }
1464
- // NOTE: This is a workaround of both an @ethereumjs/vm limitation, and
1508
+ // NOTE: This is a workaround of both an @ignored/vm limitation, and
1465
1509
  // a bug in Hardhat Network.
1466
1510
  //
1467
1511
  // See: https://github.com/nomiclabs/hardhat/issues/1666
@@ -1480,14 +1524,16 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1480
1524
  freeze: false,
1481
1525
  common: this._vm._common,
1482
1526
  });
1483
- blockContext.header.baseFeePerGas = new ethereumjs_util_1.BN(0);
1527
+ blockContext.header.baseFeePerGas = 0n;
1484
1528
  }
1485
1529
  originalCommon = this._vm._common;
1486
- this._vm._common = new common_1.default({
1487
- chain: Object.assign(Object.assign({}, this._vm._common["_chainParams"]), { chainId: this._forkBlockNumber === undefined ||
1488
- blockContext.header.number.gte(new ethereumjs_util_1.BN(this._forkBlockNumber))
1489
- ? this._configChainId
1490
- : this._forkNetworkId, networkId: (_a = this._forkNetworkId) !== null && _a !== void 0 ? _a : this._configNetworkId }),
1530
+ this._vm._common = common_1.Common.custom({
1531
+ chainId: this._forkBlockNumber === undefined ||
1532
+ blockContext.header.number >= this._forkBlockNumber
1533
+ ? this._configChainId
1534
+ : this._forkNetworkId,
1535
+ networkId: this._forkNetworkId ?? this._configNetworkId,
1536
+ }, {
1491
1537
  hardfork: this._selectHardfork(blockContext.header.number),
1492
1538
  });
1493
1539
  return await this._vm.runTx({
@@ -1507,17 +1553,17 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1507
1553
  }
1508
1554
  async _computeFilterParams(filterParams, isFilter) {
1509
1555
  const latestBlockNumber = this.getLatestBlockNumber();
1510
- const newFilterParams = Object.assign({}, filterParams);
1556
+ const newFilterParams = { ...filterParams };
1511
1557
  if (newFilterParams.fromBlock === filter_1.LATEST_BLOCK) {
1512
1558
  newFilterParams.fromBlock = latestBlockNumber;
1513
1559
  }
1514
1560
  if (!isFilter && newFilterParams.toBlock === filter_1.LATEST_BLOCK) {
1515
1561
  newFilterParams.toBlock = latestBlockNumber;
1516
1562
  }
1517
- if (newFilterParams.toBlock.gt(latestBlockNumber)) {
1563
+ if (newFilterParams.toBlock > latestBlockNumber) {
1518
1564
  newFilterParams.toBlock = latestBlockNumber;
1519
1565
  }
1520
- if (newFilterParams.fromBlock.gt(latestBlockNumber)) {
1566
+ if (newFilterParams.fromBlock > latestBlockNumber) {
1521
1567
  newFilterParams.fromBlock = latestBlockNumber;
1522
1568
  }
1523
1569
  return newFilterParams;
@@ -1528,7 +1574,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1528
1574
  return dt;
1529
1575
  }
1530
1576
  _getNextFilterId() {
1531
- this._lastFilterId = this._lastFilterId.addn(1);
1577
+ this._lastFilterId++;
1532
1578
  return this._lastFilterId;
1533
1579
  }
1534
1580
  _filterIdToFiltersKey(filterId) {
@@ -1556,13 +1602,13 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1556
1602
  _isTxMinable(tx, nextBlockBaseFeePerGas) {
1557
1603
  const txMaxFee = "gasPrice" in tx ? tx.gasPrice : tx.maxFeePerGas;
1558
1604
  const canPayBaseFee = nextBlockBaseFeePerGas !== undefined
1559
- ? txMaxFee.gte(nextBlockBaseFeePerGas)
1605
+ ? txMaxFee >= nextBlockBaseFeePerGas
1560
1606
  : true;
1561
- const atLeastMinGasPrice = txMaxFee.gte(this._minGasPrice);
1607
+ const atLeastMinGasPrice = txMaxFee >= this._minGasPrice;
1562
1608
  return canPayBaseFee && atLeastMinGasPrice;
1563
1609
  }
1564
1610
  async _persistIrregularWorldState() {
1565
- this._irregularStatesByBlockNumber.set(this.getLatestBlockNumber().toString(), await this._stateManager.getStateRoot());
1611
+ this._irregularStatesByBlockNumber.set(this.getLatestBlockNumber(), await this._stateManager.getStateRoot());
1566
1612
  }
1567
1613
  isEip1559Active(blockNumberOrPending) {
1568
1614
  if (blockNumberOrPending !== undefined &&
@@ -1571,35 +1617,41 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1571
1617
  }
1572
1618
  return this._vm._common.gteHardfork("london");
1573
1619
  }
1620
+ isPostMergeHardfork() {
1621
+ return (0, hardforks_1.hardforkGte)(this.hardfork, hardforks_1.HardforkName.MERGE);
1622
+ }
1623
+ _getNextMixHash() {
1624
+ return this._mixHashGenerator.next();
1625
+ }
1574
1626
  async _getEstimateGasFeePriceFields(callParams, blockNumberOrPending) {
1575
- var _a, _b;
1576
1627
  if (!this.isEip1559Active(blockNumberOrPending) ||
1577
1628
  callParams.gasPrice !== undefined) {
1578
- return { gasPrice: (_a = callParams.gasPrice) !== null && _a !== void 0 ? _a : (await this.getGasPrice()) };
1629
+ return { gasPrice: callParams.gasPrice ?? (await this.getGasPrice()) };
1579
1630
  }
1580
1631
  let maxFeePerGas = callParams.maxFeePerGas;
1581
1632
  let maxPriorityFeePerGas = callParams.maxPriorityFeePerGas;
1582
1633
  if (maxPriorityFeePerGas === undefined) {
1583
1634
  maxPriorityFeePerGas = await this.getMaxPriorityFeePerGas();
1584
- if (maxFeePerGas !== undefined && maxFeePerGas.lt(maxPriorityFeePerGas)) {
1635
+ if (maxFeePerGas !== undefined && maxFeePerGas < maxPriorityFeePerGas) {
1585
1636
  maxPriorityFeePerGas = maxFeePerGas;
1586
1637
  }
1587
1638
  }
1588
1639
  if (maxFeePerGas === undefined) {
1589
1640
  if (blockNumberOrPending === "pending") {
1590
1641
  const baseFeePerGas = await this.getNextBlockBaseFeePerGas();
1591
- maxFeePerGas = baseFeePerGas.muln(2).add(maxPriorityFeePerGas);
1642
+ maxFeePerGas = 2n * baseFeePerGas + maxPriorityFeePerGas;
1592
1643
  }
1593
1644
  else {
1594
1645
  const block = await this.getBlockByNumber(blockNumberOrPending);
1595
- maxFeePerGas = maxPriorityFeePerGas.add((_b = block.header.baseFeePerGas) !== null && _b !== void 0 ? _b : new ethereumjs_util_1.BN(0));
1646
+ maxFeePerGas =
1647
+ maxPriorityFeePerGas + (block.header.baseFeePerGas ?? 0n);
1596
1648
  }
1597
1649
  }
1598
1650
  return { maxFeePerGas, maxPriorityFeePerGas };
1599
1651
  }
1600
1652
  _selectHardfork(blockNumber) {
1601
1653
  if (this._forkBlockNumber === undefined ||
1602
- blockNumber.gte(new ethereumjs_util_1.BN(this._forkBlockNumber))) {
1654
+ blockNumber >= this._forkBlockNumber) {
1603
1655
  return this._vm._common.hardfork();
1604
1656
  }
1605
1657
  if (this._hardforkActivations.size === 0) {
@@ -1609,10 +1661,10 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1609
1661
  * isn't higher than blockNumber, and then return that found block number's
1610
1662
  * associated hardfork name. */
1611
1663
  const hardforkHistory = Array.from(this._hardforkActivations.entries());
1612
- const [hardfork, activationBlock] = hardforkHistory.reduce(([highestHardfork, highestBlock], [thisHardfork, thisBlock]) => thisBlock > highestBlock && new ethereumjs_util_1.BN(thisBlock).lte(blockNumber)
1664
+ const [hardfork, activationBlock] = hardforkHistory.reduce(([highestHardfork, highestBlock], [thisHardfork, thisBlock]) => thisBlock > highestBlock && thisBlock <= blockNumber
1613
1665
  ? [thisHardfork, thisBlock]
1614
1666
  : [highestHardfork, highestBlock]);
1615
- if (hardfork === undefined || blockNumber.ltn(activationBlock)) {
1667
+ if (hardfork === undefined || blockNumber < activationBlock) {
1616
1668
  throw new errors_2.InternalError(`Could not find a hardfork to run for block ${blockNumber.toString()}, after having looked for one in the HardhatNode's hardfork activation history, which was: ${JSON.stringify(hardforkHistory)}. For more information, see https://hardhat.org/hardhat-network/reference/#config`);
1617
1669
  }
1618
1670
  if (!constants_1.HARDHAT_NETWORK_SUPPORTED_HARDFORKS.includes(hardfork)) {
@@ -1622,13 +1674,15 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1622
1674
  }
1623
1675
  _getCommonForTracing(networkId, blockNumber) {
1624
1676
  try {
1625
- const common = new common_1.default({
1626
- chain: Object.assign(Object.assign({}, common_1.default["_getChainParams"]("mainnet")), { chainId: networkId, networkId }),
1627
- hardfork: this._selectHardfork(new ethereumjs_util_1.BN(blockNumber)),
1677
+ const common = common_1.Common.custom({
1678
+ chainId: networkId,
1679
+ networkId,
1680
+ }, {
1681
+ hardfork: this._selectHardfork(BigInt(blockNumber)),
1628
1682
  });
1629
1683
  return common;
1630
1684
  }
1631
- catch (_a) {
1685
+ catch {
1632
1686
  throw new errors_2.InternalError(`Network id ${networkId} does not correspond to a network that Hardhat can trace`);
1633
1687
  }
1634
1688
  }