hardhat 2.11.0-dev.0 → 2.11.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 (406) hide show
  1. package/builtin-tasks/clean.js +2 -1
  2. package/builtin-tasks/clean.js.map +1 -1
  3. package/builtin-tasks/compile.js +52 -95
  4. package/builtin-tasks/compile.js.map +1 -1
  5. package/builtin-tasks/flatten.js +2 -21
  6. package/builtin-tasks/flatten.js.map +1 -1
  7. package/builtin-tasks/node.js +1 -1
  8. package/builtin-tasks/node.js.map +1 -1
  9. package/builtin-tasks/test.js +3 -3
  10. package/builtin-tasks/test.js.map +1 -1
  11. package/builtin-tasks/utils/solidity-files-cache.d.ts.map +1 -1
  12. package/builtin-tasks/utils/solidity-files-cache.js +5 -6
  13. package/builtin-tasks/utils/solidity-files-cache.js.map +1 -1
  14. package/internal/artifacts.d.ts +3 -11
  15. package/internal/artifacts.d.ts.map +1 -1
  16. package/internal/artifacts.js +266 -133
  17. package/internal/artifacts.js.map +1 -1
  18. package/internal/cli/cli.js +26 -12
  19. package/internal/cli/cli.js.map +1 -1
  20. package/internal/core/config/config-loading.js +2 -2
  21. package/internal/core/config/config-loading.js.map +1 -1
  22. package/internal/core/config/config-resolution.d.ts.map +1 -1
  23. package/internal/core/config/config-resolution.js +11 -31
  24. package/internal/core/config/config-resolution.js.map +1 -1
  25. package/internal/core/config/default-config.js +1 -1
  26. package/internal/core/config/default-config.js.map +1 -1
  27. package/internal/core/errors-list.d.ts +7 -0
  28. package/internal/core/errors-list.d.ts.map +1 -1
  29. package/internal/core/errors-list.js +28 -11
  30. package/internal/core/errors-list.js.map +1 -1
  31. package/internal/core/errors.d.ts +2 -1
  32. package/internal/core/errors.d.ts.map +1 -1
  33. package/internal/core/errors.js +5 -1
  34. package/internal/core/errors.js.map +1 -1
  35. package/internal/core/execution-mode.d.ts.map +1 -1
  36. package/internal/core/execution-mode.js +2 -21
  37. package/internal/core/execution-mode.js.map +1 -1
  38. package/internal/core/flamegraph.d.ts +4 -0
  39. package/internal/core/flamegraph.d.ts.map +1 -1
  40. package/internal/core/flamegraph.js +13 -3
  41. package/internal/core/flamegraph.js.map +1 -1
  42. package/internal/core/jsonrpc/types/base-types.d.ts.map +1 -1
  43. package/internal/core/jsonrpc/types/base-types.js +12 -12
  44. package/internal/core/jsonrpc/types/base-types.js.map +1 -1
  45. package/internal/core/params/hardhat-params.d.ts.map +1 -1
  46. package/internal/core/params/hardhat-params.js +18 -0
  47. package/internal/core/params/hardhat-params.js.map +1 -1
  48. package/internal/core/providers/accounts.js +9 -9
  49. package/internal/core/providers/accounts.js.map +1 -1
  50. package/internal/core/providers/construction.d.ts.map +1 -1
  51. package/internal/core/providers/construction.js +5 -6
  52. package/internal/core/providers/construction.js.map +1 -1
  53. package/internal/core/providers/gas-providers.d.ts +2 -2
  54. package/internal/core/providers/util.js +1 -1
  55. package/internal/core/providers/util.js.map +1 -1
  56. package/internal/core/runtime-environment.d.ts +6 -0
  57. package/internal/core/runtime-environment.d.ts.map +1 -1
  58. package/internal/core/runtime-environment.js +72 -6
  59. package/internal/core/runtime-environment.js.map +1 -1
  60. package/internal/core/typescript-support.d.ts +1 -1
  61. package/internal/core/typescript-support.d.ts.map +1 -1
  62. package/internal/core/typescript-support.js +6 -2
  63. package/internal/core/typescript-support.js.map +1 -1
  64. package/internal/hardhat-network/jsonrpc/client.d.ts +1 -1
  65. package/internal/hardhat-network/jsonrpc/client.d.ts.map +1 -1
  66. package/internal/hardhat-network/jsonrpc/client.js +10 -10
  67. package/internal/hardhat-network/jsonrpc/client.js.map +1 -1
  68. package/internal/hardhat-network/provider/BlockchainBase.d.ts +4 -4
  69. package/internal/hardhat-network/provider/BlockchainBase.d.ts.map +1 -1
  70. package/internal/hardhat-network/provider/BlockchainBase.js +31 -12
  71. package/internal/hardhat-network/provider/BlockchainBase.js.map +1 -1
  72. package/internal/hardhat-network/provider/BlockchainData.d.ts +3 -3
  73. package/internal/hardhat-network/provider/BlockchainData.d.ts.map +1 -1
  74. package/internal/hardhat-network/provider/BlockchainData.js +15 -15
  75. package/internal/hardhat-network/provider/BlockchainData.js.map +1 -1
  76. package/internal/hardhat-network/provider/HardhatBlockchain.d.ts +3 -3
  77. package/internal/hardhat-network/provider/HardhatBlockchain.d.ts.map +1 -1
  78. package/internal/hardhat-network/provider/HardhatBlockchain.js +2 -2
  79. package/internal/hardhat-network/provider/HardhatBlockchain.js.map +1 -1
  80. package/internal/hardhat-network/provider/PoolState.d.ts +1 -1
  81. package/internal/hardhat-network/provider/PoolState.d.ts.map +1 -1
  82. package/internal/hardhat-network/provider/PoolState.js +21 -2
  83. package/internal/hardhat-network/provider/PoolState.js.map +1 -1
  84. package/internal/hardhat-network/provider/TransactionQueue.d.ts +1 -1
  85. package/internal/hardhat-network/provider/TransactionQueue.d.ts.map +1 -1
  86. package/internal/hardhat-network/provider/TransactionQueue.js +22 -3
  87. package/internal/hardhat-network/provider/TransactionQueue.js.map +1 -1
  88. package/internal/hardhat-network/provider/TxPool.d.ts +4 -4
  89. package/internal/hardhat-network/provider/TxPool.d.ts.map +1 -1
  90. package/internal/hardhat-network/provider/TxPool.js +35 -16
  91. package/internal/hardhat-network/provider/TxPool.js.map +1 -1
  92. package/internal/hardhat-network/provider/ethereumjs-workarounds.js +4 -4
  93. package/internal/hardhat-network/provider/ethereumjs-workarounds.js.map +1 -1
  94. package/internal/hardhat-network/provider/filter.d.ts +1 -1
  95. package/internal/hardhat-network/provider/filter.d.ts.map +1 -1
  96. package/internal/hardhat-network/provider/filter.js +3 -3
  97. package/internal/hardhat-network/provider/filter.js.map +1 -1
  98. package/internal/hardhat-network/provider/fork/ForkBlockchain.d.ts +3 -3
  99. package/internal/hardhat-network/provider/fork/ForkBlockchain.d.ts.map +1 -1
  100. package/internal/hardhat-network/provider/fork/ForkBlockchain.js +13 -12
  101. package/internal/hardhat-network/provider/fork/ForkBlockchain.js.map +1 -1
  102. package/internal/hardhat-network/provider/fork/ForkStateManager.d.ts +3 -5
  103. package/internal/hardhat-network/provider/fork/ForkStateManager.d.ts.map +1 -1
  104. package/internal/hardhat-network/provider/fork/ForkStateManager.js +36 -40
  105. package/internal/hardhat-network/provider/fork/ForkStateManager.js.map +1 -1
  106. package/internal/hardhat-network/provider/fork/rpcToBlockData.d.ts +1 -1
  107. package/internal/hardhat-network/provider/fork/rpcToBlockData.d.ts.map +1 -1
  108. package/internal/hardhat-network/provider/fork/rpcToTxData.d.ts +2 -2
  109. package/internal/hardhat-network/provider/fork/rpcToTxData.d.ts.map +1 -1
  110. package/internal/hardhat-network/provider/fork/rpcToTxData.js.map +1 -1
  111. package/internal/hardhat-network/provider/modules/eth.d.ts +1 -1
  112. package/internal/hardhat-network/provider/modules/eth.d.ts.map +1 -1
  113. package/internal/hardhat-network/provider/modules/eth.js +22 -22
  114. package/internal/hardhat-network/provider/modules/eth.js.map +1 -1
  115. package/internal/hardhat-network/provider/modules/hardhat.d.ts +2 -0
  116. package/internal/hardhat-network/provider/modules/hardhat.d.ts.map +1 -1
  117. package/internal/hardhat-network/provider/modules/hardhat.js +20 -6
  118. package/internal/hardhat-network/provider/modules/hardhat.js.map +1 -1
  119. package/internal/hardhat-network/provider/modules/logger.d.ts +2 -2
  120. package/internal/hardhat-network/provider/modules/logger.d.ts.map +1 -1
  121. package/internal/hardhat-network/provider/modules/logger.js +14 -14
  122. package/internal/hardhat-network/provider/modules/logger.js.map +1 -1
  123. package/internal/hardhat-network/provider/modules/net.d.ts +1 -1
  124. package/internal/hardhat-network/provider/modules/net.d.ts.map +1 -1
  125. package/internal/hardhat-network/provider/modules/personal.js +3 -3
  126. package/internal/hardhat-network/provider/modules/personal.js.map +1 -1
  127. package/internal/hardhat-network/provider/modules/web3.d.ts.map +1 -1
  128. package/internal/hardhat-network/provider/modules/web3.js +4 -5
  129. package/internal/hardhat-network/provider/modules/web3.js.map +1 -1
  130. package/internal/hardhat-network/provider/node-types.d.ts +4 -4
  131. package/internal/hardhat-network/provider/node-types.d.ts.map +1 -1
  132. package/internal/hardhat-network/provider/node.d.ts +5 -4
  133. package/internal/hardhat-network/provider/node.d.ts.map +1 -1
  134. package/internal/hardhat-network/provider/node.js +71 -49
  135. package/internal/hardhat-network/provider/node.js.map +1 -1
  136. package/internal/hardhat-network/provider/output.d.ts +4 -4
  137. package/internal/hardhat-network/provider/output.d.ts.map +1 -1
  138. package/internal/hardhat-network/provider/output.js +24 -5
  139. package/internal/hardhat-network/provider/output.js.map +1 -1
  140. package/internal/hardhat-network/provider/provider.d.ts +2 -2
  141. package/internal/hardhat-network/provider/provider.d.ts.map +1 -1
  142. package/internal/hardhat-network/provider/provider.js +3 -3
  143. package/internal/hardhat-network/provider/provider.js.map +1 -1
  144. package/internal/hardhat-network/provider/return-data.d.ts +1 -1
  145. package/internal/hardhat-network/provider/return-data.d.ts.map +1 -1
  146. package/internal/hardhat-network/provider/return-data.js +5 -4
  147. package/internal/hardhat-network/provider/return-data.js.map +1 -1
  148. package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.d.ts +4 -4
  149. package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.d.ts.map +1 -1
  150. package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.js +8 -8
  151. package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.js.map +1 -1
  152. package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.d.ts +3 -3
  153. package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.d.ts.map +1 -1
  154. package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.js +8 -8
  155. package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.js.map +1 -1
  156. package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.d.ts +3 -3
  157. package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.d.ts.map +1 -1
  158. package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.js +5 -5
  159. package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.js.map +1 -1
  160. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.d.ts +4 -4
  161. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.d.ts.map +1 -1
  162. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.js +25 -6
  163. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.js.map +1 -1
  164. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.d.ts +3 -3
  165. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.d.ts.map +1 -1
  166. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.js +25 -6
  167. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.js.map +1 -1
  168. package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.d.ts +3 -3
  169. package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.d.ts.map +1 -1
  170. package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.js +2 -2
  171. package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.js.map +1 -1
  172. package/internal/hardhat-network/provider/types/HardhatBlockchainInterface.d.ts +2 -2
  173. package/internal/hardhat-network/provider/types/HardhatBlockchainInterface.d.ts.map +1 -1
  174. package/internal/hardhat-network/provider/utils/makeAccount.d.ts +1 -1
  175. package/internal/hardhat-network/provider/utils/makeAccount.d.ts.map +1 -1
  176. package/internal/hardhat-network/provider/utils/makeAccount.js +4 -4
  177. package/internal/hardhat-network/provider/utils/makeAccount.js.map +1 -1
  178. package/internal/hardhat-network/provider/utils/makeCommon.d.ts +1 -1
  179. package/internal/hardhat-network/provider/utils/makeCommon.d.ts.map +1 -1
  180. package/internal/hardhat-network/provider/utils/makeCommon.js +2 -2
  181. package/internal/hardhat-network/provider/utils/makeCommon.js.map +1 -1
  182. package/internal/hardhat-network/provider/utils/makeStateTrie.d.ts +1 -1
  183. package/internal/hardhat-network/provider/utils/makeStateTrie.d.ts.map +1 -1
  184. package/internal/hardhat-network/provider/utils/makeStateTrie.js +4 -4
  185. package/internal/hardhat-network/provider/utils/makeStateTrie.js.map +1 -1
  186. package/internal/hardhat-network/provider/utils/putGenesisBlock.d.ts +3 -3
  187. package/internal/hardhat-network/provider/utils/putGenesisBlock.d.ts.map +1 -1
  188. package/internal/hardhat-network/provider/utils/putGenesisBlock.js +4 -4
  189. package/internal/hardhat-network/provider/utils/putGenesisBlock.js.map +1 -1
  190. package/internal/hardhat-network/provider/utils/random.d.ts +2 -1
  191. package/internal/hardhat-network/provider/utils/random.d.ts.map +1 -1
  192. package/internal/hardhat-network/provider/utils/random.js +10 -9
  193. package/internal/hardhat-network/provider/utils/random.js.map +1 -1
  194. package/internal/hardhat-network/provider/utils/reorganizeTransactionsLists.js +21 -2
  195. package/internal/hardhat-network/provider/utils/reorganizeTransactionsLists.js.map +1 -1
  196. package/internal/hardhat-network/provider/utils/txMapToArray.d.ts +1 -1
  197. package/internal/hardhat-network/provider/utils/txMapToArray.d.ts.map +1 -1
  198. package/internal/hardhat-network/stack-traces/consoleLogger.js +45 -45
  199. package/internal/hardhat-network/stack-traces/consoleLogger.js.map +1 -1
  200. package/internal/hardhat-network/stack-traces/constants.d.ts +1 -1
  201. package/internal/hardhat-network/stack-traces/constants.d.ts.map +1 -1
  202. package/internal/hardhat-network/stack-traces/constants.js +1 -1
  203. package/internal/hardhat-network/stack-traces/constants.js.map +1 -1
  204. package/internal/hardhat-network/stack-traces/contracts-identifier.js +2 -2
  205. package/internal/hardhat-network/stack-traces/contracts-identifier.js.map +1 -1
  206. package/internal/hardhat-network/stack-traces/debug.js +13 -13
  207. package/internal/hardhat-network/stack-traces/debug.js.map +1 -1
  208. package/internal/hardhat-network/stack-traces/error-inferrer.js +2 -2
  209. package/internal/hardhat-network/stack-traces/error-inferrer.js.map +1 -1
  210. package/internal/hardhat-network/stack-traces/message-trace.d.ts +1 -1
  211. package/internal/hardhat-network/stack-traces/message-trace.d.ts.map +1 -1
  212. package/internal/hardhat-network/stack-traces/model.js +6 -6
  213. package/internal/hardhat-network/stack-traces/model.js.map +1 -1
  214. package/internal/hardhat-network/stack-traces/panic-errors.d.ts +1 -1
  215. package/internal/hardhat-network/stack-traces/panic-errors.js +9 -9
  216. package/internal/hardhat-network/stack-traces/panic-errors.js.map +1 -1
  217. package/internal/hardhat-network/stack-traces/solidity-errors.js +3 -3
  218. package/internal/hardhat-network/stack-traces/solidity-errors.js.map +1 -1
  219. package/internal/hardhat-network/stack-traces/solidity-stack-trace.d.ts +1 -1
  220. package/internal/hardhat-network/stack-traces/solidityTracer.d.ts +0 -2
  221. package/internal/hardhat-network/stack-traces/solidityTracer.d.ts.map +1 -1
  222. package/internal/hardhat-network/stack-traces/solidityTracer.js +2 -4
  223. package/internal/hardhat-network/stack-traces/solidityTracer.js.map +1 -1
  224. package/internal/hardhat-network/stack-traces/vm-debug-tracer.d.ts +1 -1
  225. package/internal/hardhat-network/stack-traces/vm-debug-tracer.d.ts.map +1 -1
  226. package/internal/hardhat-network/stack-traces/vm-debug-tracer.js +27 -25
  227. package/internal/hardhat-network/stack-traces/vm-debug-tracer.js.map +1 -1
  228. package/internal/hardhat-network/stack-traces/vm-tracer.d.ts +2 -2
  229. package/internal/hardhat-network/stack-traces/vm-tracer.d.ts.map +1 -1
  230. package/internal/hardhat-network/stack-traces/vm-tracer.js +15 -12
  231. package/internal/hardhat-network/stack-traces/vm-tracer.js.map +1 -1
  232. package/internal/lib/hardhat-lib.d.ts.map +1 -1
  233. package/internal/lib/hardhat-lib.js +0 -2
  234. package/internal/lib/hardhat-lib.js.map +1 -1
  235. package/internal/solidity/compilation-job.d.ts.map +1 -1
  236. package/internal/solidity/compilation-job.js +6 -7
  237. package/internal/solidity/compilation-job.js.map +1 -1
  238. package/internal/solidity/compiler/downloader.d.ts +66 -40
  239. package/internal/solidity/compiler/downloader.d.ts.map +1 -1
  240. package/internal/solidity/compiler/downloader.js +180 -154
  241. package/internal/solidity/compiler/downloader.js.map +1 -1
  242. package/internal/solidity/compiler/index.d.ts +8 -4
  243. package/internal/solidity/compiler/index.d.ts.map +1 -1
  244. package/internal/solidity/compiler/index.js +1 -1
  245. package/internal/solidity/compiler/index.js.map +1 -1
  246. package/internal/solidity/dependencyGraph.d.ts.map +1 -1
  247. package/internal/solidity/dependencyGraph.js +3 -5
  248. package/internal/solidity/dependencyGraph.js.map +1 -1
  249. package/internal/solidity/parse.d.ts.map +1 -1
  250. package/internal/solidity/parse.js +2 -58
  251. package/internal/solidity/parse.js.map +1 -1
  252. package/internal/solidity/resolver.d.ts +1 -0
  253. package/internal/solidity/resolver.d.ts.map +1 -1
  254. package/internal/solidity/resolver.js +33 -8
  255. package/internal/solidity/resolver.js.map +1 -1
  256. package/internal/util/bigint.d.ts +13 -24
  257. package/internal/util/bigint.d.ts.map +1 -1
  258. package/internal/util/bigint.js +22 -29
  259. package/internal/util/bigint.js.map +1 -1
  260. package/internal/util/download.d.ts.map +1 -1
  261. package/internal/util/download.js +1 -1
  262. package/internal/util/download.js.map +1 -1
  263. package/internal/util/fs-utils.d.ts +26 -9
  264. package/internal/util/fs-utils.d.ts.map +1 -1
  265. package/internal/util/fs-utils.js +111 -68
  266. package/internal/util/fs-utils.js.map +1 -1
  267. package/internal/util/glob.d.ts +13 -0
  268. package/internal/util/glob.d.ts.map +1 -1
  269. package/internal/util/glob.js +13 -0
  270. package/internal/util/glob.js.map +1 -1
  271. package/internal/util/keccak.d.ts +3 -0
  272. package/internal/util/keccak.d.ts.map +1 -0
  273. package/internal/util/keccak.js +12 -0
  274. package/internal/util/keccak.js.map +1 -0
  275. package/internal/util/scripts-runner.d.ts.map +1 -1
  276. package/internal/util/scripts-runner.js +7 -4
  277. package/internal/util/scripts-runner.js.map +1 -1
  278. package/package.json +15 -15
  279. package/register.js +1 -3
  280. package/register.js.map +1 -1
  281. package/sample-projects/javascript/contracts/Lock.sol +3 -3
  282. package/sample-projects/typescript/contracts/Lock.sol +3 -3
  283. package/src/builtin-tasks/clean.ts +9 -6
  284. package/src/builtin-tasks/compile.ts +96 -128
  285. package/src/builtin-tasks/flatten.ts +2 -3
  286. package/src/builtin-tasks/node.ts +2 -2
  287. package/src/builtin-tasks/test.ts +7 -3
  288. package/src/builtin-tasks/utils/solidity-files-cache.ts +9 -8
  289. package/src/internal/artifacts.ts +392 -182
  290. package/src/internal/cli/cli.ts +43 -17
  291. package/src/internal/core/config/config-loading.ts +1 -1
  292. package/src/internal/core/config/config-resolution.ts +12 -24
  293. package/src/internal/core/config/default-config.ts +1 -1
  294. package/src/internal/core/errors-list.ts +29 -13
  295. package/src/internal/core/errors.ts +10 -2
  296. package/src/internal/core/execution-mode.ts +2 -3
  297. package/src/internal/core/flamegraph.ts +270 -0
  298. package/src/internal/core/jsonrpc/types/base-types.ts +7 -3
  299. package/src/internal/core/params/hardhat-params.ts +18 -0
  300. package/src/internal/core/providers/accounts.ts +8 -8
  301. package/src/internal/core/providers/construction.ts +10 -8
  302. package/src/internal/core/providers/gas-providers.ts +2 -2
  303. package/src/internal/core/providers/util.ts +1 -1
  304. package/src/internal/core/runtime-environment.ts +103 -10
  305. package/src/internal/core/task-profiling.ts +56 -0
  306. package/src/internal/core/typescript-support.ts +11 -2
  307. package/src/internal/hardhat-network/jsonrpc/client.ts +1 -1
  308. package/src/internal/hardhat-network/provider/BlockchainBase.ts +6 -6
  309. package/src/internal/hardhat-network/provider/BlockchainData.ts +5 -5
  310. package/src/internal/hardhat-network/provider/HardhatBlockchain.ts +4 -4
  311. package/src/internal/hardhat-network/provider/PoolState.ts +2 -2
  312. package/src/internal/hardhat-network/provider/TransactionQueue.ts +2 -2
  313. package/src/internal/hardhat-network/provider/TxPool.ts +12 -5
  314. package/src/internal/hardhat-network/provider/ethereumjs-workarounds.ts +3 -3
  315. package/src/internal/hardhat-network/provider/filter.ts +2 -2
  316. package/src/internal/hardhat-network/provider/fork/ForkBlockchain.ts +10 -10
  317. package/src/internal/hardhat-network/provider/fork/ForkStateManager.ts +12 -18
  318. package/src/internal/hardhat-network/provider/fork/rpcToBlockData.ts +1 -1
  319. package/src/internal/hardhat-network/provider/fork/rpcToTxData.ts +5 -2
  320. package/src/internal/hardhat-network/provider/modules/eth.ts +10 -6
  321. package/src/internal/hardhat-network/provider/modules/hardhat.ts +25 -1
  322. package/src/internal/hardhat-network/provider/modules/logger.ts +3 -3
  323. package/src/internal/hardhat-network/provider/modules/net.ts +1 -1
  324. package/src/internal/hardhat-network/provider/modules/personal.ts +1 -1
  325. package/src/internal/hardhat-network/provider/modules/web3.ts +4 -6
  326. package/src/internal/hardhat-network/provider/node-types.ts +6 -6
  327. package/src/internal/hardhat-network/provider/node.ts +25 -12
  328. package/src/internal/hardhat-network/provider/output.ts +6 -6
  329. package/src/internal/hardhat-network/provider/provider.ts +7 -6
  330. package/src/internal/hardhat-network/provider/return-data.ts +9 -5
  331. package/src/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.ts +9 -5
  332. package/src/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.ts +8 -4
  333. package/src/internal/hardhat-network/provider/transactions/FakeSenderTransaction.ts +4 -4
  334. package/src/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.ts +8 -5
  335. package/src/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.ts +4 -4
  336. package/src/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.ts +3 -3
  337. package/src/internal/hardhat-network/provider/types/HardhatBlockchainInterface.ts +2 -2
  338. package/src/internal/hardhat-network/provider/utils/makeAccount.ts +6 -1
  339. package/src/internal/hardhat-network/provider/utils/makeCommon.ts +1 -1
  340. package/src/internal/hardhat-network/provider/utils/makeStateTrie.ts +7 -3
  341. package/src/internal/hardhat-network/provider/utils/putGenesisBlock.ts +6 -6
  342. package/src/internal/hardhat-network/provider/utils/random.ts +17 -14
  343. package/src/internal/hardhat-network/provider/utils/reorganizeTransactionsLists.ts +1 -1
  344. package/src/internal/hardhat-network/stack-traces/consoleLogger.ts +1 -1
  345. package/src/internal/hardhat-network/stack-traces/constants.ts +2 -0
  346. package/src/internal/hardhat-network/stack-traces/contracts-identifier.ts +1 -1
  347. package/src/internal/hardhat-network/stack-traces/debug.ts +1 -1
  348. package/src/internal/hardhat-network/stack-traces/error-inferrer.ts +3 -3
  349. package/src/internal/hardhat-network/stack-traces/message-trace.ts +1 -1
  350. package/src/internal/hardhat-network/stack-traces/model.ts +1 -1
  351. package/src/internal/hardhat-network/stack-traces/panic-errors.ts +11 -11
  352. package/src/internal/hardhat-network/stack-traces/solidity-errors.ts +1 -1
  353. package/src/internal/hardhat-network/stack-traces/solidity-stack-trace.ts +1 -1
  354. package/src/internal/hardhat-network/stack-traces/solidityTracer.ts +1 -4
  355. package/src/internal/hardhat-network/stack-traces/vm-debug-tracer.ts +31 -17
  356. package/src/internal/hardhat-network/stack-traces/vm-tracer.ts +29 -14
  357. package/src/internal/lib/hardhat-lib.ts +0 -3
  358. package/src/internal/solidity/compilation-job.ts +11 -11
  359. package/src/internal/solidity/compiler/downloader.ts +271 -243
  360. package/src/internal/solidity/compiler/index.ts +13 -7
  361. package/src/internal/solidity/dependencyGraph.ts +12 -8
  362. package/src/internal/solidity/parse.ts +4 -70
  363. package/src/internal/solidity/resolver.ts +36 -8
  364. package/src/internal/util/bigint.ts +25 -43
  365. package/src/internal/util/download.ts +2 -2
  366. package/src/internal/util/fs-utils.ts +223 -0
  367. package/src/internal/util/glob.ts +13 -0
  368. package/src/internal/util/keccak.ts +5 -0
  369. package/src/internal/util/scripts-runner.ts +13 -4
  370. package/src/internal/util/wei-values.ts +1 -1
  371. package/src/internal/{hardhat-network/vendor → vendor}/await-semaphore/index.ts +0 -0
  372. package/src/profiling.ts +37 -0
  373. package/src/register.ts +1 -4
  374. package/src/types/artifacts.ts +21 -0
  375. package/src/types/config.ts +7 -7
  376. package/src/types/runtime.ts +2 -0
  377. package/src/utils/source-names.ts +36 -26
  378. package/types/artifacts.d.ts +19 -0
  379. package/types/artifacts.d.ts.map +1 -1
  380. package/types/config.d.ts +7 -7
  381. package/types/runtime.d.ts +2 -0
  382. package/types/runtime.d.ts.map +1 -1
  383. package/utils/source-names.d.ts.map +1 -1
  384. package/utils/source-names.js +25 -36
  385. package/utils/source-names.js.map +1 -1
  386. package/internal/hardhat-network/provider/fork/random.d.ts +0 -7
  387. package/internal/hardhat-network/provider/fork/random.d.ts.map +0 -1
  388. package/internal/hardhat-network/provider/fork/random.js +0 -32
  389. package/internal/hardhat-network/provider/fork/random.js.map +0 -1
  390. package/internal/hardhat-network/provider/utils/bnToHex.d.ts +0 -3
  391. package/internal/hardhat-network/provider/utils/bnToHex.d.ts.map +0 -1
  392. package/internal/hardhat-network/provider/utils/bnToHex.js +0 -9
  393. package/internal/hardhat-network/provider/utils/bnToHex.js.map +0 -1
  394. package/internal/hardhat-network/provider/utils/makeForkCommon.d.ts +0 -4
  395. package/internal/hardhat-network/provider/utils/makeForkCommon.d.ts.map +0 -1
  396. package/internal/hardhat-network/provider/utils/makeForkCommon.js +0 -16
  397. package/internal/hardhat-network/provider/utils/makeForkCommon.js.map +0 -1
  398. package/internal/hardhat-network/vendor/await-semaphore/index.d.ts +0 -12
  399. package/internal/hardhat-network/vendor/await-semaphore/index.d.ts.map +0 -1
  400. package/internal/hardhat-network/vendor/await-semaphore/index.js +0 -64
  401. package/internal/hardhat-network/vendor/await-semaphore/index.js.map +0 -1
  402. package/internal/util/antlr-prototype-pollution-workaround.d.ts +0 -16
  403. package/internal/util/antlr-prototype-pollution-workaround.d.ts.map +0 -1
  404. package/internal/util/antlr-prototype-pollution-workaround.js +0 -22
  405. package/internal/util/antlr-prototype-pollution-workaround.js.map +0 -1
  406. package/src/internal/util/antlr-prototype-pollution-workaround.ts +0 -17
@@ -2,6 +2,7 @@ import debug from "debug";
2
2
  import fsExtra from "fs-extra";
3
3
  import * as os from "os";
4
4
  import * as path from "path";
5
+ import fsPromises from "fs/promises";
5
6
 
6
7
  import {
7
8
  Artifact,
@@ -28,23 +29,35 @@ import {
28
29
  } from "./constants";
29
30
  import { HardhatError } from "./core/errors";
30
31
  import { ERRORS } from "./core/errors-list";
31
- import { glob, globSync } from "./util/glob";
32
32
  import { createNonCryptographicHashBasedIdentifier } from "./util/hash";
33
+ import {
34
+ FileNotFoundError,
35
+ getAllFilesMatching,
36
+ getAllFilesMatchingSync,
37
+ getFileTrueCase,
38
+ getFileTrueCaseSync,
39
+ } from "./util/fs-utils";
33
40
 
34
41
  const log = debug("hardhat:core:artifacts");
35
42
 
43
+ interface Cache {
44
+ artifactPaths?: string[];
45
+ debugFilePaths?: string[];
46
+ buildInfoPaths?: string[];
47
+ artifactNameToArtifactPathCache: Map<string, string>;
48
+ artifactFQNToBuildInfoPathCache: Map<string, string>;
49
+ }
50
+
36
51
  export class Artifacts implements IArtifacts {
37
- private _buildInfosGlob: string;
38
- private _dbgsGlob: string;
39
52
  private _validArtifacts: Array<{ sourceName: string; artifacts: string[] }>;
40
53
 
54
+ // Undefined means that the cache is disabled.
55
+ private _cache?: Cache = {
56
+ artifactNameToArtifactPathCache: new Map(),
57
+ artifactFQNToBuildInfoPathCache: new Map(),
58
+ };
59
+
41
60
  constructor(private _artifactsPath: string) {
42
- this._buildInfosGlob = path.join(
43
- this._artifactsPath,
44
- BUILD_INFO_DIR_NAME,
45
- "**/*.json"
46
- );
47
- this._dbgsGlob = path.join(this._artifactsPath, "**/*.dbg.json");
48
61
  this._validArtifacts = [];
49
62
  }
50
63
 
@@ -65,12 +78,8 @@ export class Artifacts implements IArtifacts {
65
78
  }
66
79
 
67
80
  public async artifactExists(name: string): Promise<boolean> {
68
- try {
69
- await this.readArtifact(name);
70
- return true;
71
- } catch {
72
- return false;
73
- }
81
+ const artifactPath = await this._getArtifactPath(name);
82
+ return fsExtra.pathExists(artifactPath);
74
83
  }
75
84
 
76
85
  public async getAllFullyQualifiedNames(): Promise<string[]> {
@@ -81,70 +90,134 @@ export class Artifacts implements IArtifacts {
81
90
  public async getBuildInfo(
82
91
  fullyQualifiedName: string
83
92
  ): Promise<BuildInfo | undefined> {
84
- const artifactPath =
85
- this.formArtifactPathFromFullyQualifiedName(fullyQualifiedName);
86
-
87
- const debugFilePath = this._getDebugFilePath(artifactPath);
88
- const buildInfoPath = await this._getBuildInfoFromDebugFile(debugFilePath);
93
+ let buildInfoPath =
94
+ this._cache?.artifactFQNToBuildInfoPathCache.get(fullyQualifiedName);
89
95
 
90
96
  if (buildInfoPath === undefined) {
91
- return undefined;
97
+ const artifactPath =
98
+ this.formArtifactPathFromFullyQualifiedName(fullyQualifiedName);
99
+
100
+ const debugFilePath = this._getDebugFilePath(artifactPath);
101
+ buildInfoPath = await this._getBuildInfoFromDebugFile(debugFilePath);
102
+
103
+ if (buildInfoPath === undefined) {
104
+ return undefined;
105
+ }
106
+
107
+ this._cache?.artifactFQNToBuildInfoPathCache.set(
108
+ fullyQualifiedName,
109
+ buildInfoPath
110
+ );
92
111
  }
93
112
 
94
113
  return fsExtra.readJSON(buildInfoPath);
95
114
  }
96
115
 
97
116
  public async getArtifactPaths(): Promise<string[]> {
98
- const paths = await glob(path.join(this._artifactsPath, "**/*.json"), {
99
- ignore: [this._buildInfosGlob, this._dbgsGlob],
100
- });
117
+ const cached = this._cache?.artifactPaths;
118
+ if (cached !== undefined) {
119
+ return cached;
120
+ }
121
+
122
+ const buildInfosDir = path.join(this._artifactsPath, BUILD_INFO_DIR_NAME);
123
+
124
+ const paths = await getAllFilesMatching(
125
+ this._artifactsPath,
126
+ (f) =>
127
+ f.endsWith(".json") &&
128
+ !f.startsWith(buildInfosDir) &&
129
+ !f.endsWith(".dbg.json")
130
+ );
131
+
132
+ const result = paths.sort();
101
133
 
102
- return paths.sort();
134
+ if (this._cache !== undefined) {
135
+ this._cache.artifactPaths = result;
136
+ }
137
+
138
+ return result;
103
139
  }
104
140
 
105
141
  public async getBuildInfoPaths(): Promise<string[]> {
106
- const paths = await glob(this._buildInfosGlob);
142
+ const cached = this._cache?.buildInfoPaths;
143
+ if (cached !== undefined) {
144
+ return cached;
145
+ }
146
+
147
+ const paths = await getAllFilesMatching(
148
+ path.join(this._artifactsPath, BUILD_INFO_DIR_NAME),
149
+ (f) => f.endsWith(".json")
150
+ );
107
151
 
108
- return paths.sort();
152
+ const result = paths.sort();
153
+
154
+ if (this._cache !== undefined) {
155
+ this._cache.buildInfoPaths = result;
156
+ }
157
+
158
+ return result;
109
159
  }
110
160
 
111
161
  public async getDebugFilePaths(): Promise<string[]> {
112
- const paths = await glob(this._dbgsGlob);
162
+ const cached = this._cache?.debugFilePaths;
163
+ if (cached !== undefined) {
164
+ return cached;
165
+ }
166
+
167
+ const paths = await getAllFilesMatching(
168
+ path.join(this._artifactsPath),
169
+ (f) => f.endsWith(".dbg.json")
170
+ );
171
+
172
+ const result = paths.sort();
113
173
 
114
- return paths.sort();
174
+ if (this._cache !== undefined) {
175
+ this._cache.debugFilePaths = result;
176
+ }
177
+
178
+ return result;
115
179
  }
116
180
 
117
181
  public async saveArtifactAndDebugFile(
118
182
  artifact: Artifact,
119
183
  pathToBuildInfo?: string
120
184
  ) {
121
- // artifact
122
- const fullyQualifiedName = getFullyQualifiedName(
123
- artifact.sourceName,
124
- artifact.contractName
125
- );
185
+ try {
186
+ // artifact
187
+ const fullyQualifiedName = getFullyQualifiedName(
188
+ artifact.sourceName,
189
+ artifact.contractName
190
+ );
126
191
 
127
- const artifactPath =
128
- this.formArtifactPathFromFullyQualifiedName(fullyQualifiedName);
192
+ const artifactPath =
193
+ this.formArtifactPathFromFullyQualifiedName(fullyQualifiedName);
129
194
 
130
- await fsExtra.ensureDir(path.dirname(artifactPath));
195
+ await fsExtra.ensureDir(path.dirname(artifactPath));
131
196
 
132
- // write artifact
133
- await fsExtra.writeJSON(artifactPath, artifact, {
134
- spaces: 2,
135
- });
197
+ await Promise.all([
198
+ fsExtra.writeJSON(artifactPath, artifact, {
199
+ spaces: 2,
200
+ }),
201
+ (async () => {
202
+ if (pathToBuildInfo === undefined) {
203
+ return;
204
+ }
136
205
 
137
- if (pathToBuildInfo === undefined) {
138
- return;
206
+ // save debug file
207
+ const debugFilePath = this._getDebugFilePath(artifactPath);
208
+ const debugFile = this._createDebugFile(
209
+ artifactPath,
210
+ pathToBuildInfo
211
+ );
212
+
213
+ await fsExtra.writeJSON(debugFilePath, debugFile, {
214
+ spaces: 2,
215
+ });
216
+ })(),
217
+ ]);
218
+ } finally {
219
+ this.clearCache();
139
220
  }
140
-
141
- // save debug file
142
- const debugFilePath = this._getDebugFilePath(artifactPath);
143
- const debugFile = this._createDebugFile(artifactPath, pathToBuildInfo);
144
-
145
- await fsExtra.writeJSON(debugFilePath, debugFile, {
146
- spaces: 2,
147
- });
148
221
  }
149
222
 
150
223
  public async saveBuildInfo(
@@ -153,54 +226,159 @@ export class Artifacts implements IArtifacts {
153
226
  input: CompilerInput,
154
227
  output: CompilerOutput
155
228
  ): Promise<string> {
156
- const buildInfoDir = path.join(this._artifactsPath, BUILD_INFO_DIR_NAME);
157
- await fsExtra.ensureDir(buildInfoDir);
229
+ try {
230
+ const buildInfoDir = path.join(this._artifactsPath, BUILD_INFO_DIR_NAME);
231
+ await fsExtra.ensureDir(buildInfoDir);
158
232
 
159
- const buildInfoName = this._getBuildInfoName(
160
- solcVersion,
161
- solcLongVersion,
162
- input
163
- );
233
+ const buildInfoName = this._getBuildInfoName(
234
+ solcVersion,
235
+ solcLongVersion,
236
+ input
237
+ );
164
238
 
165
- const buildInfo = this._createBuildInfo(
166
- buildInfoName,
167
- solcVersion,
168
- solcLongVersion,
169
- input,
170
- output
171
- );
239
+ const buildInfo = this._createBuildInfo(
240
+ buildInfoName,
241
+ solcVersion,
242
+ solcLongVersion,
243
+ input,
244
+ output
245
+ );
172
246
 
173
- const buildInfoPath = path.join(buildInfoDir, `${buildInfoName}.json`);
174
- await fsExtra.writeJson(buildInfoPath, buildInfo, { spaces: 2 });
247
+ const buildInfoPath = path.join(buildInfoDir, `${buildInfoName}.json`);
248
+
249
+ // JSON.stringify of the entire build info can be really slow
250
+ // in larger projects, so we stringify per part and incrementally create
251
+ // the JSON in the file.
252
+ //
253
+ // We split this code into different curly-brace-enclosed scopes so that
254
+ // partial JSON strings get out of scope sooner and hence can be reclaimed
255
+ // by the GC if needed.
256
+ const file = await fsPromises.open(buildInfoPath, "w");
257
+ try {
258
+ {
259
+ const withoutOutput = JSON.stringify({
260
+ ...buildInfo,
261
+ output: undefined,
262
+ });
263
+
264
+ // We write the JSON (without output) except the last }
265
+ await file.write(withoutOutput.slice(0, -1));
266
+ }
267
+
268
+ {
269
+ const outputWithoutSourcesAndContracts = JSON.stringify({
270
+ ...buildInfo.output,
271
+ sources: undefined,
272
+ contracts: undefined,
273
+ });
274
+
275
+ // We start writing the output
276
+ await file.write(',"output":');
277
+
278
+ // Write the output object except for the last }
279
+ await file.write(outputWithoutSourcesAndContracts.slice(0, -1));
280
+
281
+ // If there were other field apart from sources and contracts we need
282
+ // a comma
283
+ if (outputWithoutSourcesAndContracts.length > 2) {
284
+ await file.write(",");
285
+ }
286
+ }
287
+
288
+ // Writing the sources
289
+ await file.write('"sources":{');
290
+
291
+ let isFirst = true;
292
+ for (const [name, value] of Object.entries(
293
+ buildInfo.output.sources ?? {}
294
+ )) {
295
+ if (isFirst) {
296
+ isFirst = false;
297
+ } else {
298
+ await file.write(",");
299
+ }
300
+
301
+ await file.write(`${JSON.stringify(name)}:${JSON.stringify(value)}`);
302
+ }
303
+
304
+ // Close sources object
305
+ await file.write("}");
306
+
307
+ // Writing the contracts
308
+ await file.write(',"contracts":{');
309
+
310
+ isFirst = true;
311
+ for (const [name, value] of Object.entries(
312
+ buildInfo.output.contracts ?? {}
313
+ )) {
314
+ if (isFirst) {
315
+ isFirst = false;
316
+ } else {
317
+ await file.write(",");
318
+ }
175
319
 
176
- return buildInfoPath;
320
+ await file.write(`${JSON.stringify(name)}:${JSON.stringify(value)}`);
321
+ }
322
+
323
+ // close contracts object
324
+ await file.write("}");
325
+ // close output object
326
+ await file.write("}");
327
+ // close build info object
328
+ await file.write("}");
329
+ } finally {
330
+ await file.close();
331
+ }
332
+
333
+ return buildInfoPath;
334
+ } finally {
335
+ this.clearCache();
336
+ }
177
337
  }
178
338
 
179
339
  /**
180
340
  * Remove all artifacts that don't correspond to the current solidity files
181
341
  */
182
342
  public async removeObsoleteArtifacts() {
183
- const validArtifactsPaths = new Set<string>();
343
+ // We clear the cache here, as we want to be sure this runs correctly
344
+ this.clearCache();
184
345
 
185
- for (const { sourceName, artifacts } of this._validArtifacts) {
186
- for (const artifactName of artifacts) {
187
- validArtifactsPaths.add(
188
- this._getArtifactPathSync(
189
- getFullyQualifiedName(sourceName, artifactName)
346
+ try {
347
+ const validArtifactPaths = await Promise.all(
348
+ this._validArtifacts.flatMap(({ sourceName, artifacts }) =>
349
+ artifacts.map((artifactName) =>
350
+ this._getArtifactPath(
351
+ getFullyQualifiedName(sourceName, artifactName)
352
+ )
190
353
  )
191
- );
192
- }
193
- }
354
+ )
355
+ );
194
356
 
195
- const existingArtifactsPaths = await this.getArtifactPaths();
357
+ const validArtifactsPathsSet = new Set<string>(validArtifactPaths);
196
358
 
197
- for (const artifactPath of existingArtifactsPaths) {
198
- if (!validArtifactsPaths.has(artifactPath)) {
199
- await this._removeArtifactFiles(artifactPath);
359
+ for (const { sourceName, artifacts } of this._validArtifacts) {
360
+ for (const artifactName of artifacts) {
361
+ validArtifactsPathsSet.add(
362
+ this.formArtifactPathFromFullyQualifiedName(
363
+ getFullyQualifiedName(sourceName, artifactName)
364
+ )
365
+ );
366
+ }
200
367
  }
201
- }
202
368
 
203
- await this._removeObsoleteBuildInfos();
369
+ const existingArtifactsPaths = await this.getArtifactPaths();
370
+
371
+ await Promise.all(
372
+ existingArtifactsPaths
373
+ .filter((artifactPath) => !validArtifactsPathsSet.has(artifactPath))
374
+ .map((artifactPath) => this._removeArtifactFiles(artifactPath))
375
+ );
376
+
377
+ await this._removeObsoleteBuildInfos();
378
+ } finally {
379
+ // We clear the cache here, as this may have non-existent paths now
380
+ this.clearCache();
381
+ }
204
382
  }
205
383
 
206
384
  /**
@@ -215,30 +393,55 @@ export class Artifacts implements IArtifacts {
215
393
  return path.join(this._artifactsPath, sourceName, `${contractName}.json`);
216
394
  }
217
395
 
396
+ public clearCache() {
397
+ // Avoid accidentally re-enabling the cache
398
+ if (this._cache === undefined) {
399
+ return;
400
+ }
401
+
402
+ this._cache = {
403
+ artifactFQNToBuildInfoPathCache: new Map(),
404
+ artifactNameToArtifactPathCache: new Map(),
405
+ };
406
+ }
407
+
408
+ public disableCache() {
409
+ this._cache = undefined;
410
+ }
411
+
218
412
  /**
219
413
  * Remove all build infos that aren't used by any debug file
220
414
  */
221
415
  private async _removeObsoleteBuildInfos() {
222
416
  const debugFiles = await this.getDebugFilePaths();
223
417
 
224
- const validBuildInfos = new Set<string>();
225
- for (const debugFile of debugFiles) {
226
- const buildInfoFile = await this._getBuildInfoFromDebugFile(debugFile);
227
- if (buildInfoFile !== undefined) {
228
- validBuildInfos.add(
229
- path.resolve(path.dirname(debugFile), buildInfoFile)
230
- );
231
- }
232
- }
418
+ const buildInfos = await Promise.all(
419
+ debugFiles.map(async (debugFile) => {
420
+ const buildInfoFile = await this._getBuildInfoFromDebugFile(debugFile);
421
+ if (buildInfoFile !== undefined) {
422
+ return path.resolve(path.dirname(debugFile), buildInfoFile);
423
+ } else {
424
+ return undefined;
425
+ }
426
+ })
427
+ );
428
+
429
+ const filteredBuildInfos: string[] = buildInfos.filter(
430
+ (bf): bf is string => typeof bf === "string"
431
+ );
432
+
433
+ const validBuildInfos = new Set<string>(filteredBuildInfos);
233
434
 
234
435
  const buildInfoFiles = await this.getBuildInfoPaths();
235
436
 
236
- for (const buildInfoFile of buildInfoFiles) {
237
- if (!validBuildInfos.has(buildInfoFile)) {
238
- log(`Removing buildInfo '${buildInfoFile}'`);
239
- await fsExtra.unlink(buildInfoFile);
240
- }
241
- }
437
+ await Promise.all(
438
+ buildInfoFiles
439
+ .filter((buildInfoFile) => !validBuildInfos.has(buildInfoFile))
440
+ .map(async (buildInfoFile) => {
441
+ log(`Removing buildInfo '${buildInfoFile}'`);
442
+ await fsExtra.unlink(buildInfoFile);
443
+ })
444
+ );
242
445
  }
243
446
 
244
447
  private _getBuildInfoName(
@@ -267,12 +470,21 @@ export class Artifacts implements IArtifacts {
267
470
  * If there is an ambiguity, an error is thrown.
268
471
  */
269
472
  private async _getArtifactPath(name: string): Promise<string> {
473
+ const cached = this._cache?.artifactNameToArtifactPathCache.get(name);
474
+ if (cached !== undefined) {
475
+ return cached;
476
+ }
477
+
478
+ let result: string;
270
479
  if (isFullyQualifiedName(name)) {
271
- return this._getValidArtifactPathFromFullyQualifiedName(name);
480
+ result = await this._getValidArtifactPathFromFullyQualifiedName(name);
481
+ } else {
482
+ const files = await this.getArtifactPaths();
483
+ result = this._getArtifactPathFromFiles(name, files);
272
484
  }
273
485
 
274
- const files = await this.getArtifactPaths();
275
- return this._getArtifactPathFromFiles(name, files);
486
+ this._cache?.artifactNameToArtifactPathCache.set(name, result);
487
+ return result;
276
488
  }
277
489
 
278
490
  private _createBuildInfo(
@@ -307,72 +519,50 @@ export class Artifacts implements IArtifacts {
307
519
  }
308
520
 
309
521
  private _getArtifactPathsSync(): string[] {
310
- const paths = globSync(path.join(this._artifactsPath, "**/*.json"), {
311
- ignore: [this._buildInfosGlob, this._dbgsGlob],
312
- });
313
-
314
- return paths.sort();
315
- }
316
-
317
- /**
318
- * Sync version of _getArtifactPath
319
- */
320
- private _getArtifactPathSync(name: string): string {
321
- if (isFullyQualifiedName(name)) {
322
- return this._getValidArtifactPathFromFullyQualifiedNameSync(name);
522
+ const cached = this._cache?.artifactPaths;
523
+ if (cached !== undefined) {
524
+ return cached;
323
525
  }
324
526
 
325
- const files = this._getArtifactPathsSync();
326
- return this._getArtifactPathFromFiles(name, files);
327
- }
527
+ const buildInfosDir = path.join(this._artifactsPath, BUILD_INFO_DIR_NAME);
328
528
 
329
- /**
330
- * Same signature as imported function, but abstracted to handle the only error we consistently care about
331
- */
332
- private async _trueCasePath(
333
- filePath: string,
334
- basePath?: string
335
- ): Promise<string | null> {
336
- const { trueCasePath } = await import("true-case-path");
529
+ const paths = getAllFilesMatchingSync(
530
+ this._artifactsPath,
531
+ (f) =>
532
+ f.endsWith(".json") &&
533
+ !f.startsWith(buildInfosDir) &&
534
+ !f.endsWith(".dbg.json")
535
+ );
337
536
 
338
- try {
339
- const result = await trueCasePath(filePath, basePath);
340
- return result;
341
- } catch (error) {
342
- if (error instanceof Error) {
343
- if (error.message.includes("no matching file exists")) {
344
- return null;
345
- }
346
- }
537
+ const result = paths.sort();
347
538
 
348
- // eslint-disable-next-line @nomiclabs/hardhat-internal-rules/only-hardhat-error
349
- throw error;
539
+ if (this._cache !== undefined) {
540
+ this._cache.artifactPaths = result;
350
541
  }
542
+
543
+ return result;
351
544
  }
352
545
 
353
546
  /**
354
- * Same signature as imported function, but abstracted to handle the only error we consistently care about
355
- * and synchronous
547
+ * Sync version of _getArtifactPath
356
548
  */
357
- private _trueCasePathSync(
358
- filePath: string,
359
- basePath?: string
360
- ): string | null {
361
- const { trueCasePathSync } = require("true-case-path");
549
+ private _getArtifactPathSync(name: string): string {
550
+ const cached = this._cache?.artifactNameToArtifactPathCache.get(name);
551
+ if (cached !== undefined) {
552
+ return cached;
553
+ }
362
554
 
363
- try {
364
- const result = trueCasePathSync(filePath, basePath);
365
- return result;
366
- } catch (error) {
367
- if (error instanceof Error) {
368
- if (error.message.includes("no matching file exists")) {
369
- return null;
370
- }
371
- }
555
+ let result: string;
372
556
 
373
- // eslint-disable-next-line @nomiclabs/hardhat-internal-rules/only-hardhat-error
374
- throw error;
557
+ if (isFullyQualifiedName(name)) {
558
+ result = this._getValidArtifactPathFromFullyQualifiedNameSync(name);
559
+ } else {
560
+ const files = this._getArtifactPathsSync();
561
+ result = this._getArtifactPathFromFiles(name, files);
375
562
  }
563
+
564
+ this._cache?.artifactNameToArtifactPathCache.set(name, result);
565
+ return result;
376
566
  }
377
567
 
378
568
  /**
@@ -397,23 +587,33 @@ export class Artifacts implements IArtifacts {
397
587
  const artifactPath =
398
588
  this.formArtifactPathFromFullyQualifiedName(fullyQualifiedName);
399
589
 
400
- const trueCaseArtifactPath = await this._trueCasePath(
401
- path.relative(this._artifactsPath, artifactPath),
402
- this._artifactsPath
403
- );
590
+ try {
591
+ const trueCasePath = path.join(
592
+ this._artifactsPath,
593
+ await getFileTrueCase(
594
+ this._artifactsPath,
595
+ path.relative(this._artifactsPath, artifactPath)
596
+ )
597
+ );
404
598
 
405
- if (trueCaseArtifactPath === null) {
406
- return this._handleWrongArtifactForFullyQualifiedName(fullyQualifiedName);
407
- }
599
+ if (artifactPath !== trueCasePath) {
600
+ throw new HardhatError(ERRORS.ARTIFACTS.WRONG_CASING, {
601
+ correct: this._getFullyQualifiedNameFromPath(trueCasePath),
602
+ incorrect: fullyQualifiedName,
603
+ });
604
+ }
408
605
 
409
- if (artifactPath !== trueCaseArtifactPath) {
410
- throw new HardhatError(ERRORS.ARTIFACTS.WRONG_CASING, {
411
- correct: trueCaseArtifactPath,
412
- incorrect: artifactPath,
413
- });
414
- }
606
+ return trueCasePath;
607
+ } catch (e) {
608
+ if (e instanceof FileNotFoundError) {
609
+ return this._handleWrongArtifactForFullyQualifiedName(
610
+ fullyQualifiedName
611
+ );
612
+ }
415
613
 
416
- return artifactPath;
614
+ // eslint-disable-next-line @nomiclabs/hardhat-internal-rules/only-hardhat-error
615
+ throw e;
616
+ }
417
617
  }
418
618
 
419
619
  private _getAllContractNamesFromFiles(files: string[]): string[] {
@@ -558,23 +758,33 @@ Please replace "${contractName}" for the correct contract name wherever you are
558
758
  const artifactPath =
559
759
  this.formArtifactPathFromFullyQualifiedName(fullyQualifiedName);
560
760
 
561
- const trueCaseArtifactPath = this._trueCasePathSync(
562
- path.relative(this._artifactsPath, artifactPath),
563
- this._artifactsPath
564
- );
761
+ try {
762
+ const trueCasePath = path.join(
763
+ this._artifactsPath,
764
+ getFileTrueCaseSync(
765
+ this._artifactsPath,
766
+ path.relative(this._artifactsPath, artifactPath)
767
+ )
768
+ );
565
769
 
566
- if (trueCaseArtifactPath === null) {
567
- return this._handleWrongArtifactForFullyQualifiedName(fullyQualifiedName);
568
- }
770
+ if (artifactPath !== trueCasePath) {
771
+ throw new HardhatError(ERRORS.ARTIFACTS.WRONG_CASING, {
772
+ correct: this._getFullyQualifiedNameFromPath(trueCasePath),
773
+ incorrect: fullyQualifiedName,
774
+ });
775
+ }
569
776
 
570
- if (artifactPath !== trueCaseArtifactPath) {
571
- throw new HardhatError(ERRORS.ARTIFACTS.WRONG_CASING, {
572
- correct: trueCaseArtifactPath,
573
- incorrect: artifactPath,
574
- });
575
- }
777
+ return trueCasePath;
778
+ } catch (e) {
779
+ if (e instanceof FileNotFoundError) {
780
+ return this._handleWrongArtifactForFullyQualifiedName(
781
+ fullyQualifiedName
782
+ );
783
+ }
576
784
 
577
- return artifactPath;
785
+ // eslint-disable-next-line @nomiclabs/hardhat-internal-rules/only-hardhat-error
786
+ throw e;
787
+ }
578
788
  }
579
789
 
580
790
  private _getDebugFilePath(artifactPath: string): string {