hardhat 2.23.0-dev.2 → 2.23.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.
- package/README.md +3 -1
- package/builtin-tasks/compile.js +8 -8
- package/builtin-tasks/compile.js.map +1 -1
- package/builtin-tasks/flatten.js +13 -6
- package/builtin-tasks/flatten.js.map +1 -1
- package/builtin-tasks/node.js +7 -7
- package/builtin-tasks/node.js.map +1 -1
- package/builtin-tasks/test.js +2 -2
- package/builtin-tasks/test.js.map +1 -1
- package/builtin-tasks/utils/watch.js +2 -2
- package/builtin-tasks/utils/watch.js.map +1 -1
- package/common/bigInt.d.ts +1 -1
- package/common/bigInt.d.ts.map +1 -1
- package/console.sol +1 -1
- package/internal/cli/autocomplete.js +1 -1
- package/internal/cli/autocomplete.js.map +1 -1
- package/internal/cli/banner-manager.d.ts +12 -0
- package/internal/cli/banner-manager.d.ts.map +1 -0
- package/internal/cli/banner-manager.js +126 -0
- package/internal/cli/banner-manager.js.map +1 -0
- package/internal/cli/bootstrap.js +4 -5
- package/internal/cli/bootstrap.js.map +1 -1
- package/internal/cli/cli.js +14 -9
- package/internal/cli/cli.js.map +1 -1
- package/internal/cli/constants.d.ts.map +1 -1
- package/internal/cli/constants.js +1 -1
- package/internal/cli/constants.js.map +1 -1
- package/internal/cli/is-node-version-to-warn-on.d.ts +13 -0
- package/internal/cli/is-node-version-to-warn-on.d.ts.map +1 -0
- package/internal/cli/is-node-version-to-warn-on.js +46 -0
- package/internal/cli/is-node-version-to-warn-on.js.map +1 -0
- package/internal/cli/project-creation.d.ts +1 -1
- package/internal/cli/project-creation.d.ts.map +1 -1
- package/internal/cli/project-creation.js +31 -21
- package/internal/cli/project-creation.js.map +1 -1
- package/internal/cli/vars.js +10 -10
- package/internal/cli/vars.js.map +1 -1
- package/internal/cli/version-notifier.js +2 -2
- package/internal/cli/version-notifier.js.map +1 -1
- package/internal/constants.d.ts.map +1 -1
- package/internal/constants.js +1 -0
- package/internal/constants.js.map +1 -1
- package/internal/context.d.ts +1 -2
- package/internal/context.d.ts.map +1 -1
- package/internal/context.js +0 -3
- package/internal/context.js.map +1 -1
- package/internal/core/config/config-env.d.ts +1 -2
- package/internal/core/config/config-env.d.ts.map +1 -1
- package/internal/core/config/config-env.js +1 -8
- package/internal/core/config/config-env.js.map +1 -1
- package/internal/core/config/config-loading.d.ts +1 -1
- package/internal/core/config/config-loading.d.ts.map +1 -1
- package/internal/core/config/config-loading.js +14 -8
- package/internal/core/config/config-loading.js.map +1 -1
- package/internal/core/config/config-validation.js +1 -1
- package/internal/core/config/config-validation.js.map +1 -1
- package/internal/core/config/default-config.d.ts.map +1 -1
- package/internal/core/config/default-config.js +57 -32
- package/internal/core/config/default-config.js.map +1 -1
- package/internal/core/errors-list.d.ts +21 -0
- package/internal/core/errors-list.d.ts.map +1 -1
- package/internal/core/errors-list.js +27 -1
- package/internal/core/errors-list.js.map +1 -1
- package/internal/core/jsonrpc/types/authorization-list.d.ts +21 -0
- package/internal/core/jsonrpc/types/authorization-list.d.ts.map +1 -0
- package/internal/{hardhat-network/provider/PoolState.js → core/jsonrpc/types/authorization-list.js} +12 -15
- package/internal/core/jsonrpc/types/authorization-list.js.map +1 -0
- package/internal/core/jsonrpc/types/base-types.d.ts +2 -0
- package/internal/core/jsonrpc/types/base-types.d.ts.map +1 -1
- package/internal/core/jsonrpc/types/base-types.js +12 -8
- package/internal/core/jsonrpc/types/base-types.js.map +1 -1
- package/internal/core/jsonrpc/types/input/logAddress.d.ts +1 -0
- package/internal/core/jsonrpc/types/input/logAddress.d.ts.map +1 -1
- package/internal/core/jsonrpc/types/input/logTopics.d.ts +1 -0
- package/internal/core/jsonrpc/types/input/logTopics.d.ts.map +1 -1
- package/internal/core/jsonrpc/types/input/transactionRequest.d.ts +23 -0
- package/internal/core/jsonrpc/types/input/transactionRequest.d.ts.map +1 -1
- package/internal/core/jsonrpc/types/input/transactionRequest.js +2 -0
- package/internal/core/jsonrpc/types/input/transactionRequest.js.map +1 -1
- package/internal/core/jsonrpc/types/output/block.d.ts +2 -2
- package/internal/core/jsonrpc/types/output/block.d.ts.map +1 -1
- package/internal/core/jsonrpc/types/output/block.js +2 -1
- package/internal/core/jsonrpc/types/output/block.js.map +1 -1
- package/internal/core/project-structure.js +8 -8
- package/internal/core/project-structure.js.map +1 -1
- package/internal/core/providers/accounts.d.ts.map +1 -1
- package/internal/core/providers/accounts.js +76 -34
- package/internal/core/providers/accounts.js.map +1 -1
- package/internal/core/providers/construction.d.ts +2 -2
- package/internal/core/providers/construction.d.ts.map +1 -1
- package/internal/core/providers/construction.js +2 -2
- package/internal/core/providers/construction.js.map +1 -1
- package/internal/core/providers/http.d.ts.map +1 -1
- package/internal/core/providers/http.js +12 -0
- package/internal/core/providers/http.js.map +1 -1
- package/internal/core/providers/lazy-initialization.d.ts.map +1 -1
- package/internal/core/providers/lazy-initialization.js +10 -10
- package/internal/core/providers/lazy-initialization.js.map +1 -1
- package/internal/core/providers/util.d.ts +1 -0
- package/internal/core/providers/util.d.ts.map +1 -1
- package/internal/core/providers/util.js +1 -1
- package/internal/core/providers/util.js.map +1 -1
- package/internal/core/runtime-environment.d.ts +2 -2
- package/internal/core/runtime-environment.d.ts.map +1 -1
- package/internal/core/runtime-environment.js +2 -2
- package/internal/core/runtime-environment.js.map +1 -1
- package/internal/core/typescript-support.d.ts +1 -1
- package/internal/core/typescript-support.js +1 -1
- package/internal/hardhat-network/jsonrpc/client.d.ts +2 -1
- package/internal/hardhat-network/jsonrpc/client.d.ts.map +1 -1
- package/internal/hardhat-network/jsonrpc/client.js +10 -10
- package/internal/hardhat-network/jsonrpc/client.js.map +1 -1
- package/internal/hardhat-network/jsonrpc/handler.d.ts.map +1 -1
- package/internal/hardhat-network/jsonrpc/handler.js +2 -1
- package/internal/hardhat-network/jsonrpc/handler.js.map +1 -1
- package/internal/hardhat-network/provider/node-types.d.ts +0 -52
- package/internal/hardhat-network/provider/node-types.d.ts.map +1 -1
- package/internal/hardhat-network/provider/output.d.ts +12 -1
- package/internal/hardhat-network/provider/output.d.ts.map +1 -1
- package/internal/hardhat-network/provider/provider.d.ts +5 -20
- package/internal/hardhat-network/provider/provider.d.ts.map +1 -1
- package/internal/hardhat-network/provider/provider.js +47 -171
- package/internal/hardhat-network/provider/provider.js.map +1 -1
- package/internal/hardhat-network/provider/return-data.d.ts +2 -15
- package/internal/hardhat-network/provider/return-data.d.ts.map +1 -1
- package/internal/hardhat-network/provider/return-data.js +2 -50
- package/internal/hardhat-network/provider/return-data.js.map +1 -1
- package/internal/hardhat-network/provider/utils/convertToEdr.d.ts.map +1 -1
- package/internal/hardhat-network/provider/utils/convertToEdr.js +10 -7
- package/internal/hardhat-network/provider/utils/convertToEdr.js.map +1 -1
- package/internal/hardhat-network/provider/utils/fork-recomendations-banner.js +2 -2
- package/internal/hardhat-network/provider/utils/fork-recomendations-banner.js.map +1 -1
- package/internal/hardhat-network/provider/utils/makeAccount.d.ts +1 -1
- package/internal/hardhat-network/provider/utils/makeAccount.d.ts.map +1 -1
- package/internal/hardhat-network/provider/utils/makeAccount.js +4 -4
- package/internal/hardhat-network/provider/utils/makeAccount.js.map +1 -1
- package/internal/hardhat-network/provider/utils/makeForkClient.js +2 -2
- package/internal/hardhat-network/provider/utils/makeForkClient.js.map +1 -1
- package/internal/hardhat-network/provider/utils/random.d.ts +4 -3
- package/internal/hardhat-network/provider/utils/random.d.ts.map +1 -1
- package/internal/hardhat-network/provider/utils/random.js +3 -3
- package/internal/hardhat-network/provider/utils/random.js.map +1 -1
- package/internal/hardhat-network/provider/vm/exit.d.ts +2 -21
- package/internal/hardhat-network/provider/vm/exit.d.ts.map +1 -1
- package/internal/hardhat-network/provider/vm/exit.js +3 -93
- package/internal/hardhat-network/provider/vm/exit.js.map +1 -1
- package/internal/hardhat-network/provider/vm/minimal-vm.d.ts +3 -2
- package/internal/hardhat-network/provider/vm/minimal-vm.d.ts.map +1 -1
- package/internal/hardhat-network/provider/vm/minimal-vm.js +10 -4
- package/internal/hardhat-network/provider/vm/minimal-vm.js.map +1 -1
- package/internal/hardhat-network/provider/vm/types.d.ts +2 -1
- package/internal/hardhat-network/provider/vm/types.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/consoleLogger.d.ts +17 -16
- package/internal/hardhat-network/stack-traces/consoleLogger.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/consoleLogger.js +68 -102
- package/internal/hardhat-network/stack-traces/consoleLogger.js.map +1 -1
- package/internal/hardhat-network/stack-traces/constants.d.ts +1 -2
- package/internal/hardhat-network/stack-traces/constants.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/constants.js +2 -3
- package/internal/hardhat-network/stack-traces/constants.js.map +1 -1
- package/internal/hardhat-network/stack-traces/library-utils.d.ts +2 -11
- package/internal/hardhat-network/stack-traces/library-utils.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/library-utils.js +3 -61
- package/internal/hardhat-network/stack-traces/library-utils.js.map +1 -1
- package/internal/hardhat-network/stack-traces/logger.d.ts +2 -598
- package/internal/hardhat-network/stack-traces/logger.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/logger.js +379 -601
- package/internal/hardhat-network/stack-traces/logger.js.map +1 -1
- package/internal/hardhat-network/stack-traces/solidity-errors.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/solidity-errors.js +61 -56
- package/internal/hardhat-network/stack-traces/solidity-errors.js.map +1 -1
- package/internal/hardhat-network/stack-traces/solidity-stack-trace.d.ts +4 -155
- package/internal/hardhat-network/stack-traces/solidity-stack-trace.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/solidity-stack-trace.js +12 -37
- package/internal/hardhat-network/stack-traces/solidity-stack-trace.js.map +1 -1
- package/internal/lib/hardhat-lib.d.ts.map +1 -1
- package/internal/lib/hardhat-lib.js +1 -1
- package/internal/lib/hardhat-lib.js.map +1 -1
- package/internal/sentry/anonymizer.d.ts +1 -1
- package/internal/sentry/anonymizer.d.ts.map +1 -1
- package/internal/sentry/anonymizer.js +1 -1
- package/internal/sentry/anonymizer.js.map +1 -1
- package/internal/solidity/compiler/downloader.js +1 -1
- package/internal/solidity/compiler/downloader.js.map +1 -1
- package/internal/solidity/compiler/solc-info.d.ts.map +1 -1
- package/internal/solidity/compiler/solc-info.js +4 -0
- package/internal/solidity/compiler/solc-info.js.map +1 -1
- package/internal/util/caller-package.js +1 -1
- package/internal/util/caller-package.js.map +1 -1
- package/internal/util/glob.d.ts +1 -1
- package/internal/util/glob.d.ts.map +1 -1
- package/internal/util/glob.js +2 -7
- package/internal/util/glob.js.map +1 -1
- package/internal/util/hardforks.d.ts +2 -1
- package/internal/util/hardforks.d.ts.map +1 -1
- package/internal/util/hardforks.js +2 -0
- package/internal/util/hardforks.js.map +1 -1
- package/internal/util/hash.d.ts +1 -0
- package/internal/util/hash.d.ts.map +1 -1
- package/internal/util/keys-derivation.d.ts +1 -0
- package/internal/util/keys-derivation.d.ts.map +1 -1
- package/internal/util/packageInfo.d.ts +1 -1
- package/internal/util/packageInfo.d.ts.map +1 -1
- package/internal/util/packageInfo.js +3 -3
- package/internal/util/packageInfo.js.map +1 -1
- package/internal/util/request.d.ts +2 -0
- package/internal/util/request.d.ts.map +1 -0
- package/internal/util/request.js +70 -0
- package/internal/util/request.js.map +1 -0
- package/package.json +10 -20
- package/register.js +1 -1
- package/register.js.map +1 -1
- package/sample-projects/javascript/contracts/Lock.sol +1 -1
- package/sample-projects/javascript/hardhat.config.js +1 -1
- package/sample-projects/javascript/ignition/modules/Lock.js +3 -0
- package/sample-projects/javascript-esm/contracts/Lock.sol +1 -1
- package/sample-projects/javascript-esm/hardhat.config.cjs +1 -1
- package/sample-projects/javascript-esm/ignition/modules/Lock.js +3 -0
- package/sample-projects/typescript/contracts/Lock.sol +1 -1
- package/sample-projects/typescript/hardhat.config.ts +1 -1
- package/sample-projects/typescript/ignition/modules/Lock.ts +3 -0
- package/sample-projects/typescript-viem/contracts/Lock.sol +1 -1
- package/sample-projects/typescript-viem/hardhat.config.ts +1 -1
- package/sample-projects/typescript-viem/ignition/modules/Lock.ts +3 -0
- package/src/builtin-tasks/compile.ts +12 -8
- package/src/builtin-tasks/flatten.ts +59 -41
- package/src/builtin-tasks/node.ts +8 -8
- package/src/builtin-tasks/test.ts +2 -2
- package/src/builtin-tasks/utils/watch.ts +2 -2
- package/src/common/bigInt.ts +1 -1
- package/src/internal/cli/autocomplete.ts +1 -1
- package/src/internal/cli/banner-manager.ts +182 -0
- package/src/internal/cli/bootstrap.ts +5 -5
- package/src/internal/cli/cli.ts +24 -15
- package/src/internal/cli/constants.ts +1 -1
- package/src/internal/cli/is-node-version-to-warn-on.ts +54 -0
- package/src/internal/cli/project-creation.ts +48 -22
- package/src/internal/cli/vars.ts +10 -10
- package/src/internal/cli/version-notifier.ts +3 -3
- package/src/internal/constants.ts +1 -0
- package/src/internal/context.ts +0 -5
- package/src/internal/core/config/config-env.ts +0 -10
- package/src/internal/core/config/config-loading.ts +15 -8
- package/src/internal/core/config/config-validation.ts +1 -1
- package/src/internal/core/config/default-config.ts +57 -32
- package/src/internal/core/errors-list.ts +30 -1
- package/src/internal/core/jsonrpc/types/authorization-list.ts +20 -0
- package/src/internal/core/jsonrpc/types/base-types.ts +13 -1
- package/src/internal/core/jsonrpc/types/input/transactionRequest.ts +10 -0
- package/src/internal/core/jsonrpc/types/output/block.ts +2 -1
- package/src/internal/core/project-structure.ts +8 -8
- package/src/internal/core/providers/accounts.ts +95 -50
- package/src/internal/core/providers/construction.ts +1 -3
- package/src/internal/core/providers/http.ts +17 -0
- package/src/internal/core/providers/lazy-initialization.ts +13 -13
- package/src/internal/core/providers/util.ts +1 -1
- package/src/internal/core/runtime-environment.ts +0 -8
- package/src/internal/core/typescript-support.ts +1 -1
- package/src/internal/hardhat-network/jsonrpc/client.ts +1 -4
- package/src/internal/hardhat-network/jsonrpc/handler.ts +2 -1
- package/src/internal/hardhat-network/provider/node-types.ts +0 -70
- package/src/internal/hardhat-network/provider/output.ts +16 -1
- package/src/internal/hardhat-network/provider/provider.ts +57 -236
- package/src/internal/hardhat-network/provider/return-data.ts +5 -73
- package/src/internal/hardhat-network/provider/utils/convertToEdr.ts +6 -3
- package/src/internal/hardhat-network/provider/utils/fork-recomendations-banner.ts +2 -2
- package/src/internal/hardhat-network/provider/utils/makeAccount.ts +1 -6
- package/src/internal/hardhat-network/provider/utils/makeForkClient.ts +2 -2
- package/src/internal/hardhat-network/provider/utils/random.ts +4 -5
- package/src/internal/hardhat-network/provider/vm/exit.ts +4 -112
- package/src/internal/hardhat-network/provider/vm/minimal-vm.ts +8 -3
- package/src/internal/hardhat-network/provider/vm/types.ts +1 -1
- package/src/internal/hardhat-network/stack-traces/consoleLogger.ts +34 -95
- package/src/internal/hardhat-network/stack-traces/constants.ts +1 -2
- package/src/internal/hardhat-network/stack-traces/library-utils.ts +5 -90
- package/src/internal/hardhat-network/stack-traces/logger.ts +378 -600
- package/src/internal/hardhat-network/stack-traces/solidity-errors.ts +17 -16
- package/src/internal/hardhat-network/stack-traces/solidity-stack-trace.ts +83 -186
- package/src/internal/lib/hardhat-lib.ts +0 -1
- package/src/internal/sentry/anonymizer.ts +2 -2
- package/src/internal/solidity/compiler/downloader.ts +1 -1
- package/src/internal/solidity/compiler/solc-info.ts +4 -0
- package/src/internal/util/caller-package.ts +2 -2
- package/src/internal/util/glob.ts +6 -6
- package/src/internal/util/hardforks.ts +2 -0
- package/src/internal/util/packageInfo.ts +4 -4
- package/src/internal/util/request.ts +51 -0
- package/src/register.ts +0 -1
- package/src/types/config.ts +2 -0
- package/src/types/index.ts +0 -1
- package/types/config.d.ts +2 -0
- package/types/config.d.ts.map +1 -1
- package/types/index.d.ts +0 -1
- package/types/index.d.ts.map +1 -1
- package/types/index.js +0 -1
- package/types/index.js.map +1 -1
- package/internal/hardhat-network/provider/BlockchainBase.d.ts +0 -29
- package/internal/hardhat-network/provider/BlockchainBase.d.ts.map +0 -1
- package/internal/hardhat-network/provider/BlockchainBase.js +0 -144
- package/internal/hardhat-network/provider/BlockchainBase.js.map +0 -1
- package/internal/hardhat-network/provider/BlockchainData.d.ts +0 -58
- package/internal/hardhat-network/provider/BlockchainData.d.ts.map +0 -1
- package/internal/hardhat-network/provider/BlockchainData.js +0 -178
- package/internal/hardhat-network/provider/BlockchainData.js.map +0 -1
- package/internal/hardhat-network/provider/HardhatBlockchain.d.ts +0 -24
- package/internal/hardhat-network/provider/HardhatBlockchain.d.ts.map +0 -1
- package/internal/hardhat-network/provider/HardhatBlockchain.js +0 -73
- package/internal/hardhat-network/provider/HardhatBlockchain.js.map +0 -1
- package/internal/hardhat-network/provider/MiningTimer.d.ts +0 -28
- package/internal/hardhat-network/provider/MiningTimer.d.ts.map +0 -1
- package/internal/hardhat-network/provider/MiningTimer.js +0 -96
- package/internal/hardhat-network/provider/MiningTimer.js.map +0 -1
- package/internal/hardhat-network/provider/PoolState.d.ts +0 -26
- package/internal/hardhat-network/provider/PoolState.d.ts.map +0 -1
- package/internal/hardhat-network/provider/PoolState.js.map +0 -1
- package/internal/hardhat-network/provider/TransactionQueue.d.ts +0 -32
- package/internal/hardhat-network/provider/TransactionQueue.d.ts.map +0 -1
- package/internal/hardhat-network/provider/TransactionQueue.js +0 -130
- package/internal/hardhat-network/provider/TransactionQueue.js.map +0 -1
- package/internal/hardhat-network/provider/TxPool.d.ts +0 -83
- package/internal/hardhat-network/provider/TxPool.d.ts.map +0 -1
- package/internal/hardhat-network/provider/TxPool.js +0 -470
- package/internal/hardhat-network/provider/TxPool.js.map +0 -1
- package/internal/hardhat-network/provider/ethereumjs-workarounds.d.ts +0 -2
- package/internal/hardhat-network/provider/ethereumjs-workarounds.d.ts.map +0 -1
- package/internal/hardhat-network/provider/ethereumjs-workarounds.js +0 -15
- package/internal/hardhat-network/provider/ethereumjs-workarounds.js.map +0 -1
- package/internal/hardhat-network/provider/filter.d.ts +0 -29
- package/internal/hardhat-network/provider/filter.d.ts.map +0 -1
- package/internal/hardhat-network/provider/filter.js +0 -97
- package/internal/hardhat-network/provider/filter.js.map +0 -1
- package/internal/hardhat-network/provider/fork/ForkBlockchain.d.ts +0 -33
- package/internal/hardhat-network/provider/fork/ForkBlockchain.d.ts.map +0 -1
- package/internal/hardhat-network/provider/fork/ForkBlockchain.js +0 -272
- package/internal/hardhat-network/provider/fork/ForkBlockchain.js.map +0 -1
- package/internal/hardhat-network/provider/fork/ForkStateManager.d.ts +0 -51
- package/internal/hardhat-network/provider/fork/ForkStateManager.d.ts.map +0 -1
- package/internal/hardhat-network/provider/fork/ForkStateManager.js +0 -300
- package/internal/hardhat-network/provider/fork/ForkStateManager.js.map +0 -1
- package/internal/hardhat-network/provider/fork/rpcToBlockData.d.ts +0 -4
- package/internal/hardhat-network/provider/fork/rpcToBlockData.d.ts.map +0 -1
- package/internal/hardhat-network/provider/fork/rpcToBlockData.js +0 -32
- package/internal/hardhat-network/provider/fork/rpcToBlockData.js.map +0 -1
- package/internal/hardhat-network/provider/fork/rpcToTxData.d.ts +0 -10
- package/internal/hardhat-network/provider/fork/rpcToTxData.d.ts.map +0 -1
- package/internal/hardhat-network/provider/fork/rpcToTxData.js +0 -29
- package/internal/hardhat-network/provider/fork/rpcToTxData.js.map +0 -1
- package/internal/hardhat-network/provider/modules/base.d.ts +0 -17
- package/internal/hardhat-network/provider/modules/base.d.ts.map +0 -1
- package/internal/hardhat-network/provider/modules/base.js +0 -127
- package/internal/hardhat-network/provider/modules/base.js.map +0 -1
- package/internal/hardhat-network/provider/modules/debug.d.ts +0 -12
- package/internal/hardhat-network/provider/modules/debug.d.ts.map +0 -1
- package/internal/hardhat-network/provider/modules/debug.js +0 -52
- package/internal/hardhat-network/provider/modules/debug.js.map +0 -1
- package/internal/hardhat-network/provider/modules/eth.d.ts +0 -107
- package/internal/hardhat-network/provider/modules/eth.d.ts.map +0 -1
- package/internal/hardhat-network/provider/modules/eth.js +0 -1034
- package/internal/hardhat-network/provider/modules/eth.js.map +0 -1
- package/internal/hardhat-network/provider/modules/evm.d.ts +0 -32
- package/internal/hardhat-network/provider/modules/evm.d.ts.map +0 -1
- package/internal/hardhat-network/provider/modules/evm.js +0 -180
- package/internal/hardhat-network/provider/modules/evm.js.map +0 -1
- package/internal/hardhat-network/provider/modules/hardhat.d.ts +0 -54
- package/internal/hardhat-network/provider/modules/hardhat.d.ts.map +0 -1
- package/internal/hardhat-network/provider/modules/hardhat.js +0 -309
- package/internal/hardhat-network/provider/modules/hardhat.js.map +0 -1
- package/internal/hardhat-network/provider/modules/net.d.ts +0 -13
- package/internal/hardhat-network/provider/modules/net.d.ts.map +0 -1
- package/internal/hardhat-network/provider/modules/net.js +0 -47
- package/internal/hardhat-network/provider/modules/net.js.map +0 -1
- package/internal/hardhat-network/provider/modules/personal.d.ts +0 -9
- package/internal/hardhat-network/provider/modules/personal.d.ts.map +0 -1
- package/internal/hardhat-network/provider/modules/personal.js +0 -31
- package/internal/hardhat-network/provider/modules/personal.js.map +0 -1
- package/internal/hardhat-network/provider/modules/web3.d.ts +0 -11
- package/internal/hardhat-network/provider/modules/web3.d.ts.map +0 -1
- package/internal/hardhat-network/provider/modules/web3.js +0 -38
- package/internal/hardhat-network/provider/modules/web3.js.map +0 -1
- package/internal/hardhat-network/provider/node.d.ts +0 -197
- package/internal/hardhat-network/provider/node.d.ts.map +0 -1
- package/internal/hardhat-network/provider/node.js +0 -1866
- package/internal/hardhat-network/provider/node.js.map +0 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.d.ts +0 -29
- package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.d.ts.map +0 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.js +0 -137
- package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.js.map +0 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.d.ts +0 -27
- package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.d.ts.map +0 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.js +0 -137
- package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.js.map +0 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.d.ts +0 -33
- package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.d.ts.map +0 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.js +0 -141
- package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.js.map +0 -1
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.d.ts +0 -30
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.d.ts.map +0 -1
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.js +0 -97
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.js.map +0 -1
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.d.ts +0 -30
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.d.ts.map +0 -1
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.js +0 -98
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.js.map +0 -1
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.d.ts +0 -40
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.d.ts.map +0 -1
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.js +0 -91
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.js.map +0 -1
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.d.ts +0 -32
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.d.ts.map +0 -1
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.js +0 -87
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.js.map +0 -1
- package/internal/hardhat-network/provider/types/HardhatBlockchainInterface.d.ts +0 -17
- package/internal/hardhat-network/provider/types/HardhatBlockchainInterface.d.ts.map +0 -1
- package/internal/hardhat-network/provider/types/HardhatBlockchainInterface.js +0 -3
- package/internal/hardhat-network/provider/types/HardhatBlockchainInterface.js.map +0 -1
- package/internal/hardhat-network/provider/utils/makeCommon.d.ts +0 -4
- package/internal/hardhat-network/provider/utils/makeCommon.d.ts.map +0 -1
- package/internal/hardhat-network/provider/utils/makeCommon.js +0 -17
- package/internal/hardhat-network/provider/utils/makeCommon.js.map +0 -1
- package/internal/hardhat-network/provider/utils/makeFakeSignature.d.ts +0 -7
- package/internal/hardhat-network/provider/utils/makeFakeSignature.d.ts.map +0 -1
- package/internal/hardhat-network/provider/utils/makeFakeSignature.js +0 -31
- package/internal/hardhat-network/provider/utils/makeFakeSignature.js.map +0 -1
- package/internal/hardhat-network/provider/utils/makeStateTrie.d.ts +0 -4
- package/internal/hardhat-network/provider/utils/makeStateTrie.d.ts.map +0 -1
- package/internal/hardhat-network/provider/utils/makeStateTrie.js +0 -20
- package/internal/hardhat-network/provider/utils/makeStateTrie.js.map +0 -1
- package/internal/hardhat-network/provider/utils/putGenesisBlock.d.ts +0 -8
- package/internal/hardhat-network/provider/utils/putGenesisBlock.d.ts.map +0 -1
- package/internal/hardhat-network/provider/utils/putGenesisBlock.js +0 -37
- package/internal/hardhat-network/provider/utils/putGenesisBlock.js.map +0 -1
- package/internal/hardhat-network/provider/utils/reorganizeTransactionsLists.d.ts +0 -12
- package/internal/hardhat-network/provider/utils/reorganizeTransactionsLists.d.ts.map +0 -1
- package/internal/hardhat-network/provider/utils/reorganizeTransactionsLists.js +0 -62
- package/internal/hardhat-network/provider/utils/reorganizeTransactionsLists.js.map +0 -1
- package/internal/hardhat-network/provider/utils/txMapToArray.d.ts +0 -3
- package/internal/hardhat-network/provider/utils/txMapToArray.d.ts.map +0 -1
- package/internal/hardhat-network/provider/utils/txMapToArray.js +0 -12
- package/internal/hardhat-network/provider/utils/txMapToArray.js.map +0 -1
- package/internal/hardhat-network/stack-traces/compiler-to-model.d.ts +0 -4
- package/internal/hardhat-network/stack-traces/compiler-to-model.d.ts.map +0 -1
- package/internal/hardhat-network/stack-traces/compiler-to-model.js +0 -356
- package/internal/hardhat-network/stack-traces/compiler-to-model.js.map +0 -1
- package/internal/hardhat-network/stack-traces/contracts-identifier.d.ts +0 -15
- package/internal/hardhat-network/stack-traces/contracts-identifier.d.ts.map +0 -1
- package/internal/hardhat-network/stack-traces/contracts-identifier.js +0 -166
- package/internal/hardhat-network/stack-traces/contracts-identifier.js.map +0 -1
- package/internal/hardhat-network/stack-traces/debug.d.ts +0 -8
- package/internal/hardhat-network/stack-traces/debug.d.ts.map +0 -1
- package/internal/hardhat-network/stack-traces/debug.js +0 -148
- package/internal/hardhat-network/stack-traces/debug.js.map +0 -1
- package/internal/hardhat-network/stack-traces/error-inferrer.d.ts +0 -85
- package/internal/hardhat-network/stack-traces/error-inferrer.d.ts.map +0 -1
- package/internal/hardhat-network/stack-traces/error-inferrer.js +0 -1168
- package/internal/hardhat-network/stack-traces/error-inferrer.js.map +0 -1
- package/internal/hardhat-network/stack-traces/mapped-inlined-internal-functions-heuristics.d.ts +0 -24
- package/internal/hardhat-network/stack-traces/mapped-inlined-internal-functions-heuristics.d.ts.map +0 -1
- package/internal/hardhat-network/stack-traces/mapped-inlined-internal-functions-heuristics.js +0 -116
- package/internal/hardhat-network/stack-traces/mapped-inlined-internal-functions-heuristics.js.map +0 -1
- package/internal/hardhat-network/stack-traces/message-trace.d.ts +0 -55
- package/internal/hardhat-network/stack-traces/message-trace.d.ts.map +0 -1
- package/internal/hardhat-network/stack-traces/message-trace.js +0 -49
- package/internal/hardhat-network/stack-traces/message-trace.js.map +0 -1
- package/internal/hardhat-network/stack-traces/model.d.ts +0 -140
- package/internal/hardhat-network/stack-traces/model.d.ts.map +0 -1
- package/internal/hardhat-network/stack-traces/model.js +0 -328
- package/internal/hardhat-network/stack-traces/model.js.map +0 -1
- package/internal/hardhat-network/stack-traces/opcodes.d.ts +0 -266
- package/internal/hardhat-network/stack-traces/opcodes.d.ts.map +0 -1
- package/internal/hardhat-network/stack-traces/opcodes.js +0 -320
- package/internal/hardhat-network/stack-traces/opcodes.js.map +0 -1
- package/internal/hardhat-network/stack-traces/solidityTracer.d.ts +0 -14
- package/internal/hardhat-network/stack-traces/solidityTracer.d.ts.map +0 -1
- package/internal/hardhat-network/stack-traces/solidityTracer.js +0 -167
- package/internal/hardhat-network/stack-traces/solidityTracer.js.map +0 -1
- package/internal/hardhat-network/stack-traces/source-maps.d.ts +0 -13
- package/internal/hardhat-network/stack-traces/source-maps.d.ts.map +0 -1
- package/internal/hardhat-network/stack-traces/source-maps.js +0 -106
- package/internal/hardhat-network/stack-traces/source-maps.js.map +0 -1
- package/internal/hardhat-network/stack-traces/vm-debug-tracer.d.ts +0 -46
- package/internal/hardhat-network/stack-traces/vm-debug-tracer.d.ts.map +0 -1
- package/internal/hardhat-network/stack-traces/vm-debug-tracer.js +0 -421
- package/internal/hardhat-network/stack-traces/vm-debug-tracer.js.map +0 -1
- package/internal/hardhat-network/stack-traces/vm-trace-decoder.d.ts +0 -17
- package/internal/hardhat-network/stack-traces/vm-trace-decoder.d.ts.map +0 -1
- package/internal/hardhat-network/stack-traces/vm-trace-decoder.js +0 -91
- package/internal/hardhat-network/stack-traces/vm-trace-decoder.js.map +0 -1
- package/internal/hardhat-network/stack-traces/vm-tracer.d.ts +0 -19
- package/internal/hardhat-network/stack-traces/vm-tracer.d.ts.map +0 -1
- package/internal/hardhat-network/stack-traces/vm-tracer.js +0 -170
- package/internal/hardhat-network/stack-traces/vm-tracer.js.map +0 -1
- package/src/internal/hardhat-network/provider/MiningTimer.ts +0 -118
- package/src/internal/hardhat-network/provider/utils/makeCommon.ts +0 -20
- package/src/internal/hardhat-network/stack-traces/compiler-to-model.ts +0 -699
- package/src/internal/hardhat-network/stack-traces/contracts-identifier.ts +0 -235
- package/src/internal/hardhat-network/stack-traces/debug.ts +0 -220
- package/src/internal/hardhat-network/stack-traces/error-inferrer.ts +0 -1845
- package/src/internal/hardhat-network/stack-traces/mapped-inlined-internal-functions-heuristics.ts +0 -163
- package/src/internal/hardhat-network/stack-traces/message-trace.ts +0 -131
- package/src/internal/hardhat-network/stack-traces/model.ts +0 -409
- package/src/internal/hardhat-network/stack-traces/opcodes.ts +0 -344
- package/src/internal/hardhat-network/stack-traces/solidityTracer.ts +0 -255
- package/src/internal/hardhat-network/stack-traces/source-maps.ts +0 -167
- package/src/internal/hardhat-network/stack-traces/vm-trace-decoder.ts +0 -135
- package/src/internal/hardhat-network/stack-traces/vm-tracer.ts +0 -221
- package/src/types/experimental.ts +0 -18
- package/types/experimental.d.ts +0 -5
- package/types/experimental.d.ts.map +0 -1
- package/types/experimental.js +0 -3
- package/types/experimental.js.map +0 -1
|
@@ -1,1866 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.HardhatNode = void 0;
|
|
30
|
-
const ethereumjs_block_1 = require("@nomicfoundation/ethereumjs-block");
|
|
31
|
-
const ethereumjs_common_1 = require("@nomicfoundation/ethereumjs-common");
|
|
32
|
-
const ethereumjs_tx_1 = require("@nomicfoundation/ethereumjs-tx");
|
|
33
|
-
const ethereumjs_util_1 = require("@nomicfoundation/ethereumjs-util");
|
|
34
|
-
const ethereumjs_vm_1 = require("@nomicfoundation/ethereumjs-vm");
|
|
35
|
-
const ethereumjs_evm_1 = require("@nomicfoundation/ethereumjs-evm");
|
|
36
|
-
const exceptions_1 = require("@nomicfoundation/ethereumjs-evm/dist/exceptions");
|
|
37
|
-
const ethereumjs_statemanager_1 = require("@nomicfoundation/ethereumjs-statemanager");
|
|
38
|
-
const eth_sig_util_1 = require("@metamask/eth-sig-util");
|
|
39
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
40
|
-
const crypto_1 = require("crypto");
|
|
41
|
-
const debug_1 = __importDefault(require("debug"));
|
|
42
|
-
const events_1 = __importDefault(require("events"));
|
|
43
|
-
const BigIntUtils = __importStar(require("../../util/bigint"));
|
|
44
|
-
const constants_1 = require("../../constants");
|
|
45
|
-
const default_config_1 = require("../../core/config/default-config");
|
|
46
|
-
const errors_1 = require("../../core/errors");
|
|
47
|
-
const errors_2 = require("../../core/providers/errors");
|
|
48
|
-
const reporter_1 = require("../../sentry/reporter");
|
|
49
|
-
const date_1 = require("../../util/date");
|
|
50
|
-
const hardforks_1 = require("../../util/hardforks");
|
|
51
|
-
const packageInfo_1 = require("../../util/packageInfo");
|
|
52
|
-
const compiler_to_model_1 = require("../stack-traces/compiler-to-model");
|
|
53
|
-
const consoleLogger_1 = require("../stack-traces/consoleLogger");
|
|
54
|
-
const contracts_identifier_1 = require("../stack-traces/contracts-identifier");
|
|
55
|
-
const message_trace_1 = require("../stack-traces/message-trace");
|
|
56
|
-
const solidity_errors_1 = require("../stack-traces/solidity-errors");
|
|
57
|
-
const solidityTracer_1 = require("../stack-traces/solidityTracer");
|
|
58
|
-
const vm_debug_tracer_1 = require("../stack-traces/vm-debug-tracer");
|
|
59
|
-
const vm_trace_decoder_1 = require("../stack-traces/vm-trace-decoder");
|
|
60
|
-
const vm_tracer_1 = require("../stack-traces/vm-tracer");
|
|
61
|
-
require("./ethereumjs-workarounds");
|
|
62
|
-
const base_types_1 = require("../../core/jsonrpc/types/base-types");
|
|
63
|
-
const filter_1 = require("./filter");
|
|
64
|
-
const ForkBlockchain_1 = require("./fork/ForkBlockchain");
|
|
65
|
-
const ForkStateManager_1 = require("./fork/ForkStateManager");
|
|
66
|
-
const HardhatBlockchain_1 = require("./HardhatBlockchain");
|
|
67
|
-
const node_types_1 = require("./node-types");
|
|
68
|
-
const output_1 = require("./output");
|
|
69
|
-
const return_data_1 = require("./return-data");
|
|
70
|
-
const FakeSenderAccessListEIP2930Transaction_1 = require("./transactions/FakeSenderAccessListEIP2930Transaction");
|
|
71
|
-
const FakeSenderEIP1559Transaction_1 = require("./transactions/FakeSenderEIP1559Transaction");
|
|
72
|
-
const FakeSenderTransaction_1 = require("./transactions/FakeSenderTransaction");
|
|
73
|
-
const TxPool_1 = require("./TxPool");
|
|
74
|
-
const TransactionQueue_1 = require("./TransactionQueue");
|
|
75
|
-
const getCurrentTimestamp_1 = require("./utils/getCurrentTimestamp");
|
|
76
|
-
const makeCommon_1 = require("./utils/makeCommon");
|
|
77
|
-
const makeForkClient_1 = require("./utils/makeForkClient");
|
|
78
|
-
const makeStateTrie_1 = require("./utils/makeStateTrie");
|
|
79
|
-
const putGenesisBlock_1 = require("./utils/putGenesisBlock");
|
|
80
|
-
const txMapToArray_1 = require("./utils/txMapToArray");
|
|
81
|
-
const random_1 = require("./utils/random");
|
|
82
|
-
const log = (0, debug_1.default)("hardhat:core:hardhat-network:node");
|
|
83
|
-
/* eslint-disable @nomicfoundation/hardhat-internal-rules/only-hardhat-error */
|
|
84
|
-
class HardhatNode extends events_1.default {
|
|
85
|
-
static async create(config) {
|
|
86
|
-
const { automine, genesisAccounts, blockGasLimit, tracingConfig, minGasPrice, mempoolOrder, networkId, chainId, allowBlocksWithSameTimestamp, enableTransientStorage, } = config;
|
|
87
|
-
const allowUnlimitedContractSize = config.allowUnlimitedContractSize ?? false;
|
|
88
|
-
let stateManager;
|
|
89
|
-
let blockchain;
|
|
90
|
-
let initialBlockTimeOffset;
|
|
91
|
-
let nextBlockBaseFeePerGas;
|
|
92
|
-
let forkNetworkId;
|
|
93
|
-
let forkBlockNum;
|
|
94
|
-
let forkBlockHash;
|
|
95
|
-
let hardforkActivations = new Map();
|
|
96
|
-
const initialBaseFeePerGasConfig = config.initialBaseFeePerGas !== undefined
|
|
97
|
-
? BigInt(config.initialBaseFeePerGas)
|
|
98
|
-
: undefined;
|
|
99
|
-
const hardfork = (0, hardforks_1.getHardforkName)(config.hardfork);
|
|
100
|
-
const mixHashGenerator = random_1.RandomBufferGenerator.create("randomMixHashSeed");
|
|
101
|
-
let forkClient;
|
|
102
|
-
const common = (0, makeCommon_1.makeCommon)(config);
|
|
103
|
-
if ((0, node_types_1.isForkedNodeConfig)(config)) {
|
|
104
|
-
const { forkClient: _forkClient, forkBlockNumber, forkBlockTimestamp, forkBlockHash: _forkBlockHash, } = await (0, makeForkClient_1.makeForkClient)(config.forkConfig, config.forkCachePath);
|
|
105
|
-
forkClient = _forkClient;
|
|
106
|
-
forkNetworkId = forkClient.getNetworkId();
|
|
107
|
-
forkBlockNum = forkBlockNumber;
|
|
108
|
-
forkBlockHash = _forkBlockHash;
|
|
109
|
-
this._validateHardforks(config.forkConfig.blockNumber, common, forkNetworkId);
|
|
110
|
-
const forkStateManager = new ForkStateManager_1.ForkStateManager(forkClient, forkBlockNumber);
|
|
111
|
-
await forkStateManager.initializeGenesisAccounts(genesisAccounts);
|
|
112
|
-
stateManager = forkStateManager;
|
|
113
|
-
blockchain = new ForkBlockchain_1.ForkBlockchain(forkClient, forkBlockNumber, common);
|
|
114
|
-
initialBlockTimeOffset = BigInt((0, date_1.getDifferenceInSeconds)(new Date(forkBlockTimestamp), new Date()));
|
|
115
|
-
// If the hardfork is London or later we need a base fee per gas for the
|
|
116
|
-
// first local block. If initialBaseFeePerGas config was provided we use
|
|
117
|
-
// that. Otherwise, what we do depends on the block we forked from. If
|
|
118
|
-
// it's an EIP-1559 block we don't need to do anything here, as we'll
|
|
119
|
-
// end up automatically computing the next base fee per gas based on it.
|
|
120
|
-
if ((0, hardforks_1.hardforkGte)(hardfork, hardforks_1.HardforkName.LONDON)) {
|
|
121
|
-
if (initialBaseFeePerGasConfig !== undefined) {
|
|
122
|
-
nextBlockBaseFeePerGas = initialBaseFeePerGasConfig;
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
const latestBlock = await blockchain.getLatestBlock();
|
|
126
|
-
if (latestBlock.header.baseFeePerGas === undefined) {
|
|
127
|
-
nextBlockBaseFeePerGas = BigInt(default_config_1.HARDHAT_NETWORK_DEFAULT_INITIAL_BASE_FEE_PER_GAS);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
if (config.chains.has(forkNetworkId)) {
|
|
132
|
-
hardforkActivations = config.chains.get(forkNetworkId).hardforkHistory;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
const stateTrie = await (0, makeStateTrie_1.makeStateTrie)(genesisAccounts);
|
|
137
|
-
stateManager = new ethereumjs_statemanager_1.DefaultStateManager({
|
|
138
|
-
trie: stateTrie,
|
|
139
|
-
});
|
|
140
|
-
const hardhatBlockchain = new HardhatBlockchain_1.HardhatBlockchain(common);
|
|
141
|
-
const genesisBlockBaseFeePerGas = (0, hardforks_1.hardforkGte)(hardfork, hardforks_1.HardforkName.LONDON)
|
|
142
|
-
? initialBaseFeePerGasConfig ??
|
|
143
|
-
BigInt(default_config_1.HARDHAT_NETWORK_DEFAULT_INITIAL_BASE_FEE_PER_GAS)
|
|
144
|
-
: undefined;
|
|
145
|
-
await (0, putGenesisBlock_1.putGenesisBlock)(hardhatBlockchain, common, config, stateTrie, hardfork, mixHashGenerator.next(), genesisBlockBaseFeePerGas);
|
|
146
|
-
if (config.initialDate !== undefined) {
|
|
147
|
-
initialBlockTimeOffset = BigInt((0, date_1.getDifferenceInSeconds)(config.initialDate, new Date()));
|
|
148
|
-
}
|
|
149
|
-
blockchain = hardhatBlockchain;
|
|
150
|
-
}
|
|
151
|
-
const txPool = new TxPool_1.TxPool(stateManager, BigInt(blockGasLimit), common);
|
|
152
|
-
const eei = new ethereumjs_vm_1.EEI(stateManager, common, blockchain);
|
|
153
|
-
const evm = await ethereumjs_evm_1.EVM.create({
|
|
154
|
-
eei,
|
|
155
|
-
allowUnlimitedContractSize,
|
|
156
|
-
common,
|
|
157
|
-
});
|
|
158
|
-
const vm = await ethereumjs_vm_1.VM.create({
|
|
159
|
-
evm,
|
|
160
|
-
activatePrecompiles: true,
|
|
161
|
-
common,
|
|
162
|
-
stateManager,
|
|
163
|
-
blockchain,
|
|
164
|
-
});
|
|
165
|
-
const instanceId = (0, ethereumjs_util_1.bufferToBigInt)((0, crypto_1.randomBytes)(32));
|
|
166
|
-
const node = new HardhatNode(vm, instanceId, stateManager, blockchain, txPool, automine, minGasPrice, initialBlockTimeOffset, mempoolOrder, config.coinbase, genesisAccounts, networkId, chainId, hardfork, hardforkActivations, mixHashGenerator, allowUnlimitedContractSize, allowBlocksWithSameTimestamp, tracingConfig, forkNetworkId, forkBlockNum, forkBlockHash, nextBlockBaseFeePerGas, forkClient, enableTransientStorage);
|
|
167
|
-
return [common, node];
|
|
168
|
-
}
|
|
169
|
-
static _validateHardforks(forkBlockNumber, common, remoteChainId) {
|
|
170
|
-
if (!common.gteHardfork("spuriousDragon")) {
|
|
171
|
-
throw new errors_2.InternalError(`Invalid hardfork selected in Hardhat Network's config.
|
|
172
|
-
|
|
173
|
-
The hardfork must be at least spuriousDragon, but ${common.hardfork()} was given.`);
|
|
174
|
-
}
|
|
175
|
-
if (forkBlockNumber !== undefined) {
|
|
176
|
-
let upstreamCommon;
|
|
177
|
-
try {
|
|
178
|
-
upstreamCommon = new ethereumjs_common_1.Common({ chain: remoteChainId });
|
|
179
|
-
}
|
|
180
|
-
catch {
|
|
181
|
-
// If ethereumjs doesn't have a common it will throw and we won't have
|
|
182
|
-
// info about the activation block of each hardfork, so we don't run
|
|
183
|
-
// this validation.
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
upstreamCommon.setHardforkByBlockNumber(forkBlockNumber);
|
|
187
|
-
if (!upstreamCommon.gteHardfork("spuriousDragon")) {
|
|
188
|
-
throw new errors_2.InternalError(`Cannot fork ${upstreamCommon.chainName()} from block ${forkBlockNumber}.
|
|
189
|
-
|
|
190
|
-
Hardhat Network's forking functionality only works with blocks from at least spuriousDragon.`);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
constructor(_vm, _instanceId, _stateManager, _blockchain, _txPool, _automine, _minGasPrice, _blockTimeOffsetSeconds = 0n, _mempoolOrder, _coinbase, genesisAccounts, _configNetworkId, _configChainId, hardfork, _hardforkActivations, _mixHashGenerator, allowUnlimitedContractSize, _allowBlocksWithSameTimestamp, tracingConfig, _forkNetworkId, _forkBlockNumber, _forkBlockHash, nextBlockBaseFee, _forkClient, _enableTransientStorage = false) {
|
|
195
|
-
super();
|
|
196
|
-
this._vm = _vm;
|
|
197
|
-
this._instanceId = _instanceId;
|
|
198
|
-
this._stateManager = _stateManager;
|
|
199
|
-
this._blockchain = _blockchain;
|
|
200
|
-
this._txPool = _txPool;
|
|
201
|
-
this._automine = _automine;
|
|
202
|
-
this._minGasPrice = _minGasPrice;
|
|
203
|
-
this._blockTimeOffsetSeconds = _blockTimeOffsetSeconds;
|
|
204
|
-
this._mempoolOrder = _mempoolOrder;
|
|
205
|
-
this._coinbase = _coinbase;
|
|
206
|
-
this._configNetworkId = _configNetworkId;
|
|
207
|
-
this._configChainId = _configChainId;
|
|
208
|
-
this.hardfork = hardfork;
|
|
209
|
-
this._hardforkActivations = _hardforkActivations;
|
|
210
|
-
this._mixHashGenerator = _mixHashGenerator;
|
|
211
|
-
this.allowUnlimitedContractSize = allowUnlimitedContractSize;
|
|
212
|
-
this._allowBlocksWithSameTimestamp = _allowBlocksWithSameTimestamp;
|
|
213
|
-
this._forkNetworkId = _forkNetworkId;
|
|
214
|
-
this._forkBlockNumber = _forkBlockNumber;
|
|
215
|
-
this._forkBlockHash = _forkBlockHash;
|
|
216
|
-
this._forkClient = _forkClient;
|
|
217
|
-
this._enableTransientStorage = _enableTransientStorage;
|
|
218
|
-
this._localAccounts = new Map(); // address => private key
|
|
219
|
-
this._impersonatedAccounts = new Set(); // address
|
|
220
|
-
this._nextBlockTimestamp = 0n;
|
|
221
|
-
this._lastFilterId = 0n;
|
|
222
|
-
this._filters = new Map();
|
|
223
|
-
this._nextSnapshotId = 1; // We start in 1 to mimic Ganache
|
|
224
|
-
this._snapshots = [];
|
|
225
|
-
this._consoleLogger = new consoleLogger_1.ConsoleLogger();
|
|
226
|
-
this._failedStackTraces = 0;
|
|
227
|
-
// blockNumber => state root
|
|
228
|
-
this._irregularStatesByBlockNumber = new Map();
|
|
229
|
-
this._initLocalAccounts(genesisAccounts);
|
|
230
|
-
if (nextBlockBaseFee !== undefined) {
|
|
231
|
-
this.setUserProvidedNextBlockBaseFeePerGas(nextBlockBaseFee);
|
|
232
|
-
}
|
|
233
|
-
this._vmTracer = new vm_tracer_1.VMTracer(this._vm, this._stateManager.getContractCode.bind(this._stateManager), false);
|
|
234
|
-
this._vmTracer.enableTracing();
|
|
235
|
-
const contractsIdentifier = new contracts_identifier_1.ContractsIdentifier();
|
|
236
|
-
this._vmTraceDecoder = new vm_trace_decoder_1.VmTraceDecoder(contractsIdentifier);
|
|
237
|
-
this._solidityTracer = new solidityTracer_1.SolidityTracer();
|
|
238
|
-
if (tracingConfig === undefined || tracingConfig.buildInfos === undefined) {
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
try {
|
|
242
|
-
for (const buildInfo of tracingConfig.buildInfos) {
|
|
243
|
-
const bytecodes = (0, compiler_to_model_1.createModelsAndDecodeBytecodes)(buildInfo.solcVersion, buildInfo.input, buildInfo.output);
|
|
244
|
-
for (const bytecode of bytecodes) {
|
|
245
|
-
this._vmTraceDecoder.addBytecode(bytecode);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
catch (error) {
|
|
250
|
-
console.warn(chalk_1.default.yellow("The Hardhat Network tracing engine could not be initialized. Run Hardhat with --verbose to learn more."));
|
|
251
|
-
log("Hardhat Network tracing disabled: ContractsIdentifier failed to be initialized. Please report this to help us improve Hardhat.\n", error);
|
|
252
|
-
if (error instanceof Error) {
|
|
253
|
-
reporter_1.Reporter.reportError(error);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
async getSignedTransaction(txParams) {
|
|
258
|
-
const senderAddress = (0, ethereumjs_util_1.bufferToHex)(txParams.from);
|
|
259
|
-
const pk = this._localAccounts.get(senderAddress);
|
|
260
|
-
if (pk !== undefined) {
|
|
261
|
-
let tx;
|
|
262
|
-
if ("maxFeePerGas" in txParams) {
|
|
263
|
-
tx = ethereumjs_tx_1.FeeMarketEIP1559Transaction.fromTxData(txParams, {
|
|
264
|
-
common: this._vm._common,
|
|
265
|
-
disableMaxInitCodeSizeCheck: true,
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
else if ("accessList" in txParams) {
|
|
269
|
-
tx = ethereumjs_tx_1.AccessListEIP2930Transaction.fromTxData(txParams, {
|
|
270
|
-
common: this._vm._common,
|
|
271
|
-
disableMaxInitCodeSizeCheck: true,
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
else {
|
|
275
|
-
tx = ethereumjs_tx_1.Transaction.fromTxData(txParams, {
|
|
276
|
-
common: this._vm._common,
|
|
277
|
-
disableMaxInitCodeSizeCheck: true,
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
return tx.sign(pk);
|
|
281
|
-
}
|
|
282
|
-
if (this._impersonatedAccounts.has(senderAddress)) {
|
|
283
|
-
return this._getFakeTransaction(txParams);
|
|
284
|
-
}
|
|
285
|
-
throw new errors_2.InvalidInputError(`unknown account ${senderAddress}`);
|
|
286
|
-
}
|
|
287
|
-
async sendTransaction(tx) {
|
|
288
|
-
if (!this._automine) {
|
|
289
|
-
return this._addPendingTransaction(tx);
|
|
290
|
-
}
|
|
291
|
-
await this._validateAutominedTx(tx);
|
|
292
|
-
if (this._txPool.hasPendingTransactions() ||
|
|
293
|
-
this._txPool.hasQueuedTransactions()) {
|
|
294
|
-
return this._mineTransactionAndPending(tx);
|
|
295
|
-
}
|
|
296
|
-
return this._mineTransaction(tx);
|
|
297
|
-
}
|
|
298
|
-
async mineBlock(timestamp) {
|
|
299
|
-
const timestampAndOffset = this._calculateTimestampAndOffset(timestamp);
|
|
300
|
-
let [blockTimestamp] = timestampAndOffset;
|
|
301
|
-
const [, offsetShouldChange, newOffset] = timestampAndOffset;
|
|
302
|
-
const needsTimestampIncrease = !this._allowBlocksWithSameTimestamp &&
|
|
303
|
-
(await this._timestampClashesWithPreviousBlockOne(blockTimestamp));
|
|
304
|
-
if (needsTimestampIncrease) {
|
|
305
|
-
blockTimestamp += 1n;
|
|
306
|
-
}
|
|
307
|
-
let result;
|
|
308
|
-
try {
|
|
309
|
-
result = await this._mineBlockWithPendingTxs(blockTimestamp);
|
|
310
|
-
}
|
|
311
|
-
catch (err) {
|
|
312
|
-
if (err instanceof Error) {
|
|
313
|
-
if (err?.message.includes("sender doesn't have enough funds")) {
|
|
314
|
-
throw new errors_2.InvalidInputError(err.message, err);
|
|
315
|
-
}
|
|
316
|
-
// Some network errors are HardhatErrors, and can end up here when forking
|
|
317
|
-
if (errors_1.HardhatError.isHardhatError(err)) {
|
|
318
|
-
throw err;
|
|
319
|
-
}
|
|
320
|
-
throw new errors_2.TransactionExecutionError(err);
|
|
321
|
-
}
|
|
322
|
-
// eslint-disable-next-line @nomicfoundation/hardhat-internal-rules/only-hardhat-error
|
|
323
|
-
throw err;
|
|
324
|
-
}
|
|
325
|
-
await this._saveBlockAsSuccessfullyRun(result.block, result.blockResult);
|
|
326
|
-
if (needsTimestampIncrease) {
|
|
327
|
-
this.increaseTime(1n);
|
|
328
|
-
}
|
|
329
|
-
if (offsetShouldChange) {
|
|
330
|
-
this.setTimeIncrement(newOffset);
|
|
331
|
-
}
|
|
332
|
-
this._resetNextBlockTimestamp();
|
|
333
|
-
this._resetUserProvidedNextBlockBaseFeePerGas();
|
|
334
|
-
return result;
|
|
335
|
-
}
|
|
336
|
-
/**
|
|
337
|
-
* Mines `count` blocks with a difference of `interval` seconds between their
|
|
338
|
-
* timestamps.
|
|
339
|
-
*
|
|
340
|
-
* Returns an array with the results of the blocks that were really mined (the
|
|
341
|
-
* ones that were reserved are not included).
|
|
342
|
-
*/
|
|
343
|
-
async mineBlocks(count = 1n, interval = 1n) {
|
|
344
|
-
if (count === 0n) {
|
|
345
|
-
// nothing to do
|
|
346
|
-
return [];
|
|
347
|
-
}
|
|
348
|
-
const mineBlockResults = [];
|
|
349
|
-
// we always mine the first block, and we don't apply the interval for it
|
|
350
|
-
mineBlockResults.push(await this.mineBlock());
|
|
351
|
-
// helper function to mine a block with a timstamp that respects the
|
|
352
|
-
// interval
|
|
353
|
-
const mineBlock = async () => {
|
|
354
|
-
const nextTimestamp = (await this.getLatestBlock()).header.timestamp + interval;
|
|
355
|
-
mineBlockResults.push(await this.mineBlock(nextTimestamp));
|
|
356
|
-
};
|
|
357
|
-
// then we mine any pending transactions
|
|
358
|
-
while (count > mineBlockResults.length &&
|
|
359
|
-
this._txPool.hasPendingTransactions()) {
|
|
360
|
-
await mineBlock();
|
|
361
|
-
}
|
|
362
|
-
// If there is at least one remaining block, we mine one. This way, we
|
|
363
|
-
// guarantee that there's an empty block immediately before and after the
|
|
364
|
-
// reservation. This makes the logging easier to get right.
|
|
365
|
-
if (count > mineBlockResults.length) {
|
|
366
|
-
await mineBlock();
|
|
367
|
-
}
|
|
368
|
-
const remainingBlockCount = count - BigInt(mineBlockResults.length);
|
|
369
|
-
// There should be at least 2 blocks left for the reservation to work,
|
|
370
|
-
// because we always mine a block after it. But here we use a bigger
|
|
371
|
-
// number to err on the safer side.
|
|
372
|
-
if (remainingBlockCount <= 5) {
|
|
373
|
-
// if there are few blocks left to mine, we just mine them
|
|
374
|
-
while (count > mineBlockResults.length) {
|
|
375
|
-
await mineBlock();
|
|
376
|
-
}
|
|
377
|
-
return mineBlockResults;
|
|
378
|
-
}
|
|
379
|
-
// otherwise, we reserve a range and mine the last one
|
|
380
|
-
const latestBlock = await this.getLatestBlock();
|
|
381
|
-
this._blockchain.reserveBlocks(remainingBlockCount - 1n, interval, await this._stateManager.getStateRoot(), await this.getBlockTotalDifficulty(latestBlock), (await this.getLatestBlock()).header.baseFeePerGas);
|
|
382
|
-
await mineBlock();
|
|
383
|
-
return mineBlockResults;
|
|
384
|
-
}
|
|
385
|
-
async runCall(call, blockNumberOrPending, stateOverrideSet = {}) {
|
|
386
|
-
let txParams;
|
|
387
|
-
const nonce = await this._getNonce(new ethereumjs_util_1.Address(call.from), blockNumberOrPending);
|
|
388
|
-
if (call.gasPrice !== undefined ||
|
|
389
|
-
!this.isEip1559Active(blockNumberOrPending)) {
|
|
390
|
-
txParams = {
|
|
391
|
-
gasPrice: 0n,
|
|
392
|
-
nonce,
|
|
393
|
-
...call,
|
|
394
|
-
};
|
|
395
|
-
}
|
|
396
|
-
else {
|
|
397
|
-
const maxFeePerGas = call.maxFeePerGas ?? call.maxPriorityFeePerGas ?? 0n;
|
|
398
|
-
const maxPriorityFeePerGas = call.maxPriorityFeePerGas ?? 0n;
|
|
399
|
-
txParams = {
|
|
400
|
-
...call,
|
|
401
|
-
nonce,
|
|
402
|
-
maxFeePerGas,
|
|
403
|
-
maxPriorityFeePerGas,
|
|
404
|
-
accessList: call.accessList ?? [],
|
|
405
|
-
};
|
|
406
|
-
}
|
|
407
|
-
const tx = await this._getFakeTransaction(txParams);
|
|
408
|
-
const result = await this._runInBlockContext(blockNumberOrPending, async () => this._runTxAndRevertMutations(tx, blockNumberOrPending, true, stateOverrideSet));
|
|
409
|
-
const traces = await this._gatherTraces(result.execResult);
|
|
410
|
-
return {
|
|
411
|
-
...traces,
|
|
412
|
-
result: new return_data_1.ReturnData(result.execResult.returnValue),
|
|
413
|
-
};
|
|
414
|
-
}
|
|
415
|
-
async getAccountBalance(address, blockNumberOrPending) {
|
|
416
|
-
if (blockNumberOrPending === undefined) {
|
|
417
|
-
blockNumberOrPending = this.getLatestBlockNumber();
|
|
418
|
-
}
|
|
419
|
-
const account = await this._runInBlockContext(blockNumberOrPending, () => this._stateManager.getAccount(address));
|
|
420
|
-
return account.balance;
|
|
421
|
-
}
|
|
422
|
-
async getNextConfirmedNonce(address, blockNumberOrPending) {
|
|
423
|
-
const account = await this._runInBlockContext(blockNumberOrPending, () => this._stateManager.getAccount(address));
|
|
424
|
-
return account.nonce;
|
|
425
|
-
}
|
|
426
|
-
async getAccountNextPendingNonce(address) {
|
|
427
|
-
return this._txPool.getNextPendingNonce(address);
|
|
428
|
-
}
|
|
429
|
-
async getCodeFromTrace(trace, blockNumberOrPending) {
|
|
430
|
-
if (trace === undefined ||
|
|
431
|
-
(0, message_trace_1.isPrecompileTrace)(trace) ||
|
|
432
|
-
(0, message_trace_1.isCreateTrace)(trace)) {
|
|
433
|
-
return Buffer.from("");
|
|
434
|
-
}
|
|
435
|
-
return this.getCode(new ethereumjs_util_1.Address(trace.address), blockNumberOrPending);
|
|
436
|
-
}
|
|
437
|
-
async getLatestBlock() {
|
|
438
|
-
return this._blockchain.getLatestBlock();
|
|
439
|
-
}
|
|
440
|
-
getLatestBlockNumber() {
|
|
441
|
-
return this._blockchain.getLatestBlockNumber();
|
|
442
|
-
}
|
|
443
|
-
async getPendingBlockAndTotalDifficulty() {
|
|
444
|
-
return this._runInPendingBlockContext(async () => {
|
|
445
|
-
const block = await this._blockchain.getLatestBlock();
|
|
446
|
-
const totalDifficulty = await this._blockchain.getTotalDifficulty(block.hash());
|
|
447
|
-
return [block, totalDifficulty];
|
|
448
|
-
});
|
|
449
|
-
}
|
|
450
|
-
async getLocalAccountAddresses() {
|
|
451
|
-
return [...this._localAccounts.keys()];
|
|
452
|
-
}
|
|
453
|
-
getBlockGasLimit() {
|
|
454
|
-
return this._txPool.getBlockGasLimit();
|
|
455
|
-
}
|
|
456
|
-
async estimateGas(callParams, blockNumberOrPending) {
|
|
457
|
-
// We get the CallParams and transform it into a TransactionParams to be
|
|
458
|
-
// able to run it.
|
|
459
|
-
const nonce = await this._getNonce(new ethereumjs_util_1.Address(callParams.from), blockNumberOrPending);
|
|
460
|
-
// TODO: This is more complex in Geth, we should make sure we aren't missing
|
|
461
|
-
// anything here.
|
|
462
|
-
const feePriceFields = await this._getEstimateGasFeePriceFields(callParams, blockNumberOrPending);
|
|
463
|
-
let txParams;
|
|
464
|
-
if ("gasPrice" in feePriceFields) {
|
|
465
|
-
if (callParams.accessList === undefined) {
|
|
466
|
-
// Legacy tx
|
|
467
|
-
txParams = {
|
|
468
|
-
...callParams,
|
|
469
|
-
nonce,
|
|
470
|
-
gasPrice: feePriceFields.gasPrice,
|
|
471
|
-
};
|
|
472
|
-
}
|
|
473
|
-
else {
|
|
474
|
-
// Access list tx
|
|
475
|
-
txParams = {
|
|
476
|
-
...callParams,
|
|
477
|
-
nonce,
|
|
478
|
-
gasPrice: feePriceFields.gasPrice,
|
|
479
|
-
accessList: callParams.accessList ?? [],
|
|
480
|
-
};
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
else {
|
|
484
|
-
// EIP-1559 tx
|
|
485
|
-
txParams = {
|
|
486
|
-
...callParams,
|
|
487
|
-
nonce,
|
|
488
|
-
maxFeePerGas: feePriceFields.maxFeePerGas,
|
|
489
|
-
maxPriorityFeePerGas: feePriceFields.maxPriorityFeePerGas,
|
|
490
|
-
accessList: callParams.accessList ?? [],
|
|
491
|
-
};
|
|
492
|
-
}
|
|
493
|
-
const tx = await this._getFakeTransaction(txParams);
|
|
494
|
-
// TODO: This may not work if there are multiple txs in the mempool and
|
|
495
|
-
// the one being estimated won't fit in the first block, or maybe even
|
|
496
|
-
// if the state accessed by the tx changes after it is executed within
|
|
497
|
-
// the first block.
|
|
498
|
-
const result = await this._runInBlockContext(blockNumberOrPending, () => this._runTxAndRevertMutations(tx, blockNumberOrPending));
|
|
499
|
-
let vmTrace = this._vmTracer.getLastTopLevelMessageTrace();
|
|
500
|
-
const vmTracerError = this._vmTracer.getLastError();
|
|
501
|
-
this._vmTracer.clearLastError();
|
|
502
|
-
if (vmTrace !== undefined) {
|
|
503
|
-
vmTrace = this._vmTraceDecoder.tryToDecodeMessageTrace(vmTrace);
|
|
504
|
-
}
|
|
505
|
-
const consoleLogMessages = await this._getConsoleLogMessages(vmTrace, vmTracerError);
|
|
506
|
-
// This is only considered if the call to _runTxAndRevertMutations doesn't
|
|
507
|
-
// manage errors
|
|
508
|
-
if (result.execResult.exceptionError !== undefined) {
|
|
509
|
-
return {
|
|
510
|
-
estimation: this.getBlockGasLimit(),
|
|
511
|
-
trace: vmTrace,
|
|
512
|
-
error: await this._manageErrors(result.execResult, vmTrace, vmTracerError),
|
|
513
|
-
consoleLogMessages,
|
|
514
|
-
};
|
|
515
|
-
}
|
|
516
|
-
const initialEstimation = result.totalGasSpent;
|
|
517
|
-
return {
|
|
518
|
-
estimation: await this._correctInitialEstimation(blockNumberOrPending, txParams, initialEstimation),
|
|
519
|
-
trace: vmTrace,
|
|
520
|
-
consoleLogMessages,
|
|
521
|
-
};
|
|
522
|
-
}
|
|
523
|
-
async getGasPrice() {
|
|
524
|
-
const nextBlockBaseFeePerGas = await this.getNextBlockBaseFeePerGas();
|
|
525
|
-
if (nextBlockBaseFeePerGas === undefined) {
|
|
526
|
-
// We return a hardcoded value for networks without EIP-1559
|
|
527
|
-
return 8n * 10n ** 9n;
|
|
528
|
-
}
|
|
529
|
-
const suggestedPriorityFeePerGas = 10n ** 9n;
|
|
530
|
-
return nextBlockBaseFeePerGas + suggestedPriorityFeePerGas;
|
|
531
|
-
}
|
|
532
|
-
async getMaxPriorityFeePerGas() {
|
|
533
|
-
return BigInt(default_config_1.HARDHAT_NETWORK_DEFAULT_MAX_PRIORITY_FEE_PER_GAS);
|
|
534
|
-
}
|
|
535
|
-
getCoinbaseAddress() {
|
|
536
|
-
return ethereumjs_util_1.Address.fromString(this._coinbase);
|
|
537
|
-
}
|
|
538
|
-
async getStorageAt(address, positionIndex, blockNumberOrPending) {
|
|
539
|
-
const key = (0, ethereumjs_util_1.setLengthLeft)((0, ethereumjs_util_1.bigIntToBuffer)(positionIndex), 32);
|
|
540
|
-
const data = await this._runInBlockContext(blockNumberOrPending, () => this._stateManager.getContractStorage(address, key));
|
|
541
|
-
const EXPECTED_DATA_SIZE = 32;
|
|
542
|
-
if (data.length < EXPECTED_DATA_SIZE) {
|
|
543
|
-
return Buffer.concat([Buffer.alloc(EXPECTED_DATA_SIZE - data.length, 0), data], EXPECTED_DATA_SIZE);
|
|
544
|
-
}
|
|
545
|
-
return data;
|
|
546
|
-
}
|
|
547
|
-
async getBlockByNumber(blockNumberOrPending) {
|
|
548
|
-
if (blockNumberOrPending === "pending") {
|
|
549
|
-
return this._runInPendingBlockContext(() => this._blockchain.getLatestBlock());
|
|
550
|
-
}
|
|
551
|
-
try {
|
|
552
|
-
const block = await this._blockchain.getBlock(blockNumberOrPending);
|
|
553
|
-
return block;
|
|
554
|
-
}
|
|
555
|
-
catch {
|
|
556
|
-
return undefined;
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
async getBlockByHash(blockHash) {
|
|
560
|
-
try {
|
|
561
|
-
const block = await this._blockchain.getBlock(blockHash);
|
|
562
|
-
return block;
|
|
563
|
-
}
|
|
564
|
-
catch {
|
|
565
|
-
return undefined;
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
async getBlockByTransactionHash(hash) {
|
|
569
|
-
const block = await this._blockchain.getBlockByTransactionHash(hash);
|
|
570
|
-
return block ?? undefined;
|
|
571
|
-
}
|
|
572
|
-
async getBlockTotalDifficulty(block) {
|
|
573
|
-
return this._blockchain.getTotalDifficulty(block.hash());
|
|
574
|
-
}
|
|
575
|
-
async getCode(address, blockNumberOrPending) {
|
|
576
|
-
return this._runInBlockContext(blockNumberOrPending, () => this._stateManager.getContractCode(address));
|
|
577
|
-
}
|
|
578
|
-
getNextBlockTimestamp() {
|
|
579
|
-
return this._nextBlockTimestamp;
|
|
580
|
-
}
|
|
581
|
-
setNextBlockTimestamp(timestamp) {
|
|
582
|
-
this._nextBlockTimestamp = timestamp;
|
|
583
|
-
}
|
|
584
|
-
getTimeIncrement() {
|
|
585
|
-
return this._blockTimeOffsetSeconds;
|
|
586
|
-
}
|
|
587
|
-
setTimeIncrement(timeIncrement) {
|
|
588
|
-
this._blockTimeOffsetSeconds = timeIncrement;
|
|
589
|
-
}
|
|
590
|
-
increaseTime(increment) {
|
|
591
|
-
this._blockTimeOffsetSeconds += increment;
|
|
592
|
-
}
|
|
593
|
-
setUserProvidedNextBlockBaseFeePerGas(baseFeePerGas) {
|
|
594
|
-
this._userProvidedNextBlockBaseFeePerGas = baseFeePerGas;
|
|
595
|
-
}
|
|
596
|
-
getUserProvidedNextBlockBaseFeePerGas() {
|
|
597
|
-
return this._userProvidedNextBlockBaseFeePerGas;
|
|
598
|
-
}
|
|
599
|
-
_resetUserProvidedNextBlockBaseFeePerGas() {
|
|
600
|
-
this._userProvidedNextBlockBaseFeePerGas = undefined;
|
|
601
|
-
}
|
|
602
|
-
async getNextBlockBaseFeePerGas() {
|
|
603
|
-
if (!this.isEip1559Active()) {
|
|
604
|
-
return undefined;
|
|
605
|
-
}
|
|
606
|
-
const userDefined = this.getUserProvidedNextBlockBaseFeePerGas();
|
|
607
|
-
if (userDefined !== undefined) {
|
|
608
|
-
return userDefined;
|
|
609
|
-
}
|
|
610
|
-
const latestBlock = await this.getLatestBlock();
|
|
611
|
-
return latestBlock.header.calcNextBaseFee();
|
|
612
|
-
}
|
|
613
|
-
async getPendingTransaction(hash) {
|
|
614
|
-
return this._txPool.getTransactionByHash(hash)?.data;
|
|
615
|
-
}
|
|
616
|
-
async getTransactionReceipt(hash) {
|
|
617
|
-
const hashBuffer = hash instanceof Buffer ? hash : (0, ethereumjs_util_1.toBuffer)(hash);
|
|
618
|
-
const receipt = await this._blockchain.getTransactionReceipt(hashBuffer);
|
|
619
|
-
return receipt ?? undefined;
|
|
620
|
-
}
|
|
621
|
-
async getPendingTransactions() {
|
|
622
|
-
const txPoolPending = (0, txMapToArray_1.txMapToArray)(this._txPool.getPendingTransactions());
|
|
623
|
-
const txPoolQueued = (0, txMapToArray_1.txMapToArray)(this._txPool.getQueuedTransactions());
|
|
624
|
-
return txPoolPending.concat(txPoolQueued);
|
|
625
|
-
}
|
|
626
|
-
async signPersonalMessage(address, data) {
|
|
627
|
-
const messageHash = (0, ethereumjs_util_1.hashPersonalMessage)(data);
|
|
628
|
-
const privateKey = this._getLocalAccountPrivateKey(address);
|
|
629
|
-
return (0, ethereumjs_util_1.ecsign)(messageHash, privateKey);
|
|
630
|
-
}
|
|
631
|
-
async signTypedDataV4(address, typedData) {
|
|
632
|
-
const privateKey = this._getLocalAccountPrivateKey(address);
|
|
633
|
-
return (0, eth_sig_util_1.signTypedData)({
|
|
634
|
-
privateKey,
|
|
635
|
-
version: eth_sig_util_1.SignTypedDataVersion.V4,
|
|
636
|
-
data: typedData,
|
|
637
|
-
});
|
|
638
|
-
}
|
|
639
|
-
getStackTraceFailuresCount() {
|
|
640
|
-
return this._failedStackTraces;
|
|
641
|
-
}
|
|
642
|
-
async takeSnapshot() {
|
|
643
|
-
const id = this._nextSnapshotId;
|
|
644
|
-
const snapshot = {
|
|
645
|
-
id,
|
|
646
|
-
date: new Date(),
|
|
647
|
-
latestBlock: await this.getLatestBlock(),
|
|
648
|
-
stateRoot: await this._stateManager.getStateRoot(),
|
|
649
|
-
txPoolSnapshotId: this._txPool.snapshot(),
|
|
650
|
-
blockTimeOffsetSeconds: this.getTimeIncrement(),
|
|
651
|
-
nextBlockTimestamp: this.getNextBlockTimestamp(),
|
|
652
|
-
irregularStatesByBlockNumber: this._irregularStatesByBlockNumber,
|
|
653
|
-
userProvidedNextBlockBaseFeePerGas: this.getUserProvidedNextBlockBaseFeePerGas(),
|
|
654
|
-
coinbase: this.getCoinbaseAddress().toString(),
|
|
655
|
-
mixHashGenerator: this._mixHashGenerator.clone(),
|
|
656
|
-
};
|
|
657
|
-
this._irregularStatesByBlockNumber = new Map(this._irregularStatesByBlockNumber);
|
|
658
|
-
this._snapshots.push(snapshot);
|
|
659
|
-
this._nextSnapshotId += 1;
|
|
660
|
-
return id;
|
|
661
|
-
}
|
|
662
|
-
async revertToSnapshot(id) {
|
|
663
|
-
const snapshotIndex = this._getSnapshotIndex(id);
|
|
664
|
-
if (snapshotIndex === undefined) {
|
|
665
|
-
return false;
|
|
666
|
-
}
|
|
667
|
-
const snapshot = this._snapshots[snapshotIndex];
|
|
668
|
-
// We compute a new offset such that
|
|
669
|
-
// now + new_offset === snapshot_date + old_offset
|
|
670
|
-
const now = new Date();
|
|
671
|
-
const offsetToSnapshotInMillis = snapshot.date.valueOf() - now.valueOf();
|
|
672
|
-
const offsetToSnapshotInSecs = Math.ceil(offsetToSnapshotInMillis / 1000);
|
|
673
|
-
const newOffset = snapshot.blockTimeOffsetSeconds + BigInt(offsetToSnapshotInSecs);
|
|
674
|
-
// We delete all following blocks, changes the state root, and all the
|
|
675
|
-
// relevant Node fields.
|
|
676
|
-
//
|
|
677
|
-
// Note: There's no need to copy the maps here, as snapshots can only be
|
|
678
|
-
// used once
|
|
679
|
-
this._blockchain.deleteLaterBlocks(snapshot.latestBlock);
|
|
680
|
-
this._irregularStatesByBlockNumber = snapshot.irregularStatesByBlockNumber;
|
|
681
|
-
const irregularStateOrUndefined = this._irregularStatesByBlockNumber.get((await this.getLatestBlock()).header.number);
|
|
682
|
-
await this._stateManager.setStateRoot(irregularStateOrUndefined ?? snapshot.stateRoot);
|
|
683
|
-
this.setTimeIncrement(newOffset);
|
|
684
|
-
this.setNextBlockTimestamp(snapshot.nextBlockTimestamp);
|
|
685
|
-
this._txPool.revert(snapshot.txPoolSnapshotId);
|
|
686
|
-
if (snapshot.userProvidedNextBlockBaseFeePerGas !== undefined) {
|
|
687
|
-
this.setUserProvidedNextBlockBaseFeePerGas(snapshot.userProvidedNextBlockBaseFeePerGas);
|
|
688
|
-
}
|
|
689
|
-
else {
|
|
690
|
-
this._resetUserProvidedNextBlockBaseFeePerGas();
|
|
691
|
-
}
|
|
692
|
-
this._coinbase = snapshot.coinbase;
|
|
693
|
-
this._mixHashGenerator = snapshot.mixHashGenerator;
|
|
694
|
-
// We delete this and the following snapshots, as they can only be used
|
|
695
|
-
// once in Ganache
|
|
696
|
-
this._snapshots.splice(snapshotIndex);
|
|
697
|
-
return true;
|
|
698
|
-
}
|
|
699
|
-
async newFilter(filterParams, isSubscription) {
|
|
700
|
-
filterParams = await this._computeFilterParams(filterParams, true);
|
|
701
|
-
const filterId = this._getNextFilterId();
|
|
702
|
-
this._filters.set(this._filterIdToFiltersKey(filterId), {
|
|
703
|
-
id: filterId,
|
|
704
|
-
type: filter_1.Type.LOGS_SUBSCRIPTION,
|
|
705
|
-
criteria: {
|
|
706
|
-
fromBlock: filterParams.fromBlock,
|
|
707
|
-
toBlock: filterParams.toBlock,
|
|
708
|
-
addresses: filterParams.addresses,
|
|
709
|
-
normalizedTopics: filterParams.normalizedTopics,
|
|
710
|
-
},
|
|
711
|
-
deadline: this._newDeadline(),
|
|
712
|
-
hashes: [],
|
|
713
|
-
logs: await this.getLogs(filterParams),
|
|
714
|
-
subscription: isSubscription,
|
|
715
|
-
});
|
|
716
|
-
return filterId;
|
|
717
|
-
}
|
|
718
|
-
async newBlockFilter(isSubscription) {
|
|
719
|
-
const block = await this.getLatestBlock();
|
|
720
|
-
const filterId = this._getNextFilterId();
|
|
721
|
-
this._filters.set(this._filterIdToFiltersKey(filterId), {
|
|
722
|
-
id: filterId,
|
|
723
|
-
type: filter_1.Type.BLOCK_SUBSCRIPTION,
|
|
724
|
-
deadline: this._newDeadline(),
|
|
725
|
-
hashes: [(0, ethereumjs_util_1.bufferToHex)(block.header.hash())],
|
|
726
|
-
logs: [],
|
|
727
|
-
subscription: isSubscription,
|
|
728
|
-
});
|
|
729
|
-
return filterId;
|
|
730
|
-
}
|
|
731
|
-
async newPendingTransactionFilter(isSubscription) {
|
|
732
|
-
const filterId = this._getNextFilterId();
|
|
733
|
-
this._filters.set(this._filterIdToFiltersKey(filterId), {
|
|
734
|
-
id: filterId,
|
|
735
|
-
type: filter_1.Type.PENDING_TRANSACTION_SUBSCRIPTION,
|
|
736
|
-
deadline: this._newDeadline(),
|
|
737
|
-
hashes: [],
|
|
738
|
-
logs: [],
|
|
739
|
-
subscription: isSubscription,
|
|
740
|
-
});
|
|
741
|
-
return filterId;
|
|
742
|
-
}
|
|
743
|
-
async uninstallFilter(filterId, subscription) {
|
|
744
|
-
const key = this._filterIdToFiltersKey(filterId);
|
|
745
|
-
const filter = this._filters.get(key);
|
|
746
|
-
if (filter === undefined) {
|
|
747
|
-
return false;
|
|
748
|
-
}
|
|
749
|
-
if ((filter.subscription && !subscription) ||
|
|
750
|
-
(!filter.subscription && subscription)) {
|
|
751
|
-
return false;
|
|
752
|
-
}
|
|
753
|
-
this._filters.delete(key);
|
|
754
|
-
return true;
|
|
755
|
-
}
|
|
756
|
-
async getFilterChanges(filterId) {
|
|
757
|
-
const key = this._filterIdToFiltersKey(filterId);
|
|
758
|
-
const filter = this._filters.get(key);
|
|
759
|
-
if (filter === undefined) {
|
|
760
|
-
return undefined;
|
|
761
|
-
}
|
|
762
|
-
filter.deadline = this._newDeadline();
|
|
763
|
-
switch (filter.type) {
|
|
764
|
-
case filter_1.Type.BLOCK_SUBSCRIPTION:
|
|
765
|
-
case filter_1.Type.PENDING_TRANSACTION_SUBSCRIPTION:
|
|
766
|
-
const hashes = filter.hashes;
|
|
767
|
-
filter.hashes = [];
|
|
768
|
-
return hashes;
|
|
769
|
-
case filter_1.Type.LOGS_SUBSCRIPTION:
|
|
770
|
-
const logs = filter.logs;
|
|
771
|
-
filter.logs = [];
|
|
772
|
-
return logs;
|
|
773
|
-
}
|
|
774
|
-
return undefined;
|
|
775
|
-
}
|
|
776
|
-
async getFilterLogs(filterId) {
|
|
777
|
-
const key = this._filterIdToFiltersKey(filterId);
|
|
778
|
-
const filter = this._filters.get(key);
|
|
779
|
-
if (filter === undefined) {
|
|
780
|
-
return undefined;
|
|
781
|
-
}
|
|
782
|
-
const logs = filter.logs;
|
|
783
|
-
filter.logs = [];
|
|
784
|
-
filter.deadline = this._newDeadline();
|
|
785
|
-
return logs;
|
|
786
|
-
}
|
|
787
|
-
async getLogs(filterParams) {
|
|
788
|
-
filterParams = await this._computeFilterParams(filterParams, false);
|
|
789
|
-
return this._blockchain.getLogs(filterParams);
|
|
790
|
-
}
|
|
791
|
-
async addCompilationResult(solcVersion, compilerInput, compilerOutput) {
|
|
792
|
-
let bytecodes;
|
|
793
|
-
try {
|
|
794
|
-
bytecodes = (0, compiler_to_model_1.createModelsAndDecodeBytecodes)(solcVersion, compilerInput, compilerOutput);
|
|
795
|
-
}
|
|
796
|
-
catch (error) {
|
|
797
|
-
console.warn(chalk_1.default.yellow("The Hardhat Network tracing engine could not be updated. Run Hardhat with --verbose to learn more."));
|
|
798
|
-
log("ContractsIdentifier failed to be updated. Please report this to help us improve Hardhat.\n", error);
|
|
799
|
-
return false;
|
|
800
|
-
}
|
|
801
|
-
for (const bytecode of bytecodes) {
|
|
802
|
-
this._vmTraceDecoder.addBytecode(bytecode);
|
|
803
|
-
}
|
|
804
|
-
return true;
|
|
805
|
-
}
|
|
806
|
-
addImpersonatedAccount(address) {
|
|
807
|
-
this._impersonatedAccounts.add((0, ethereumjs_util_1.bufferToHex)(address));
|
|
808
|
-
return true;
|
|
809
|
-
}
|
|
810
|
-
removeImpersonatedAccount(address) {
|
|
811
|
-
return this._impersonatedAccounts.delete((0, ethereumjs_util_1.bufferToHex)(address));
|
|
812
|
-
}
|
|
813
|
-
setAutomine(automine) {
|
|
814
|
-
this._automine = automine;
|
|
815
|
-
}
|
|
816
|
-
getAutomine() {
|
|
817
|
-
return this._automine;
|
|
818
|
-
}
|
|
819
|
-
async setBlockGasLimit(gasLimit) {
|
|
820
|
-
this._txPool.setBlockGasLimit(gasLimit);
|
|
821
|
-
await this._txPool.updatePendingAndQueued();
|
|
822
|
-
}
|
|
823
|
-
async setMinGasPrice(minGasPrice) {
|
|
824
|
-
this._minGasPrice = minGasPrice;
|
|
825
|
-
}
|
|
826
|
-
async dropTransaction(hash) {
|
|
827
|
-
const removed = this._txPool.removeTransaction(hash);
|
|
828
|
-
if (removed) {
|
|
829
|
-
return true;
|
|
830
|
-
}
|
|
831
|
-
const isTransactionMined = await this._isTransactionMined(hash);
|
|
832
|
-
if (isTransactionMined) {
|
|
833
|
-
throw new errors_2.InvalidArgumentsError(`Transaction ${(0, ethereumjs_util_1.bufferToHex)(hash)} cannot be dropped because it's already mined`);
|
|
834
|
-
}
|
|
835
|
-
return false;
|
|
836
|
-
}
|
|
837
|
-
async setAccountBalance(address, newBalance) {
|
|
838
|
-
const account = await this._stateManager.getAccount(address);
|
|
839
|
-
account.balance = newBalance;
|
|
840
|
-
await this._stateManager.putAccount(address, account);
|
|
841
|
-
await this._persistIrregularWorldState();
|
|
842
|
-
}
|
|
843
|
-
async setAccountCode(address, newCode) {
|
|
844
|
-
await this._stateManager.putContractCode(address, newCode);
|
|
845
|
-
await this._persistIrregularWorldState();
|
|
846
|
-
}
|
|
847
|
-
async setNextConfirmedNonce(address, newNonce) {
|
|
848
|
-
if (!this._txPool.isEmpty()) {
|
|
849
|
-
throw new errors_2.InternalError("Cannot set account nonce when the transaction pool is not empty");
|
|
850
|
-
}
|
|
851
|
-
const account = await this._stateManager.getAccount(address);
|
|
852
|
-
if (newNonce < account.nonce) {
|
|
853
|
-
throw new errors_2.InvalidInputError(`New nonce (${newNonce.toString()}) must not be smaller than the existing nonce (${account.nonce.toString()})`);
|
|
854
|
-
}
|
|
855
|
-
account.nonce = newNonce;
|
|
856
|
-
await this._stateManager.putAccount(address, account);
|
|
857
|
-
await this._persistIrregularWorldState();
|
|
858
|
-
}
|
|
859
|
-
async setStorageAt(address, positionIndex, value) {
|
|
860
|
-
await this._stateManager.putContractStorage(address, (0, ethereumjs_util_1.setLengthLeft)((0, ethereumjs_util_1.bigIntToBuffer)(positionIndex), 32), value);
|
|
861
|
-
await this._persistIrregularWorldState();
|
|
862
|
-
}
|
|
863
|
-
async traceCall(callParams, block, traceConfig) {
|
|
864
|
-
const vmDebugTracer = new vm_debug_tracer_1.VMDebugTracer(this._vm);
|
|
865
|
-
return vmDebugTracer.trace(async () => {
|
|
866
|
-
await this.runCall(callParams, block);
|
|
867
|
-
}, traceConfig);
|
|
868
|
-
}
|
|
869
|
-
async traceTransaction(hash, config) {
|
|
870
|
-
const block = await this.getBlockByTransactionHash(hash);
|
|
871
|
-
if (block === undefined) {
|
|
872
|
-
throw new errors_2.InvalidInputError(`Unable to find a block containing transaction ${(0, ethereumjs_util_1.bufferToHex)(hash)}`);
|
|
873
|
-
}
|
|
874
|
-
return this._runInBlockContext(block.header.number - 1n, async () => {
|
|
875
|
-
const blockNumber = block.header.number;
|
|
876
|
-
const blockchain = this._blockchain;
|
|
877
|
-
let vm = this._vm;
|
|
878
|
-
if (blockchain instanceof ForkBlockchain_1.ForkBlockchain &&
|
|
879
|
-
blockNumber <= blockchain.getForkBlockNumber()) {
|
|
880
|
-
(0, errors_1.assertHardhatInvariant)(this._forkNetworkId !== undefined, "this._forkNetworkId should exist if the blockchain is an instance of ForkBlockchain");
|
|
881
|
-
const common = this._getCommonForTracing(this._forkNetworkId, blockNumber);
|
|
882
|
-
vm = await ethereumjs_vm_1.VM.create({
|
|
883
|
-
common,
|
|
884
|
-
activatePrecompiles: true,
|
|
885
|
-
stateManager: this._vm.stateManager,
|
|
886
|
-
blockchain: this._vm.blockchain,
|
|
887
|
-
});
|
|
888
|
-
}
|
|
889
|
-
// We don't support tracing transactions before the spuriousDragon fork
|
|
890
|
-
// to avoid having to distinguish between empty and non-existing accounts.
|
|
891
|
-
// We *could* do it during the non-forked mode, but for simplicity we just
|
|
892
|
-
// don't support it at all.
|
|
893
|
-
const isPreSpuriousDragon = !vm._common.gteHardfork("spuriousDragon");
|
|
894
|
-
if (isPreSpuriousDragon) {
|
|
895
|
-
throw new errors_2.InvalidInputError("Tracing is not supported for transactions using hardforks older than Spurious Dragon. ");
|
|
896
|
-
}
|
|
897
|
-
for (const tx of block.transactions) {
|
|
898
|
-
let txWithCommon;
|
|
899
|
-
const sender = tx.getSenderAddress();
|
|
900
|
-
if (tx.type === 0) {
|
|
901
|
-
txWithCommon = new FakeSenderTransaction_1.FakeSenderTransaction(sender, tx, {
|
|
902
|
-
common: vm._common,
|
|
903
|
-
});
|
|
904
|
-
}
|
|
905
|
-
else if (tx.type === 1) {
|
|
906
|
-
txWithCommon = new FakeSenderAccessListEIP2930Transaction_1.FakeSenderAccessListEIP2930Transaction(sender, tx, { common: vm._common });
|
|
907
|
-
}
|
|
908
|
-
else if (tx.type === 2) {
|
|
909
|
-
txWithCommon = new FakeSenderEIP1559Transaction_1.FakeSenderEIP1559Transaction(sender, { ...tx, gasPrice: undefined }, { common: vm._common });
|
|
910
|
-
}
|
|
911
|
-
else {
|
|
912
|
-
throw new errors_2.InternalError("Only legacy, EIP2930, and EIP1559 txs are supported");
|
|
913
|
-
}
|
|
914
|
-
const txHash = txWithCommon.hash();
|
|
915
|
-
if (txHash.equals(hash)) {
|
|
916
|
-
const vmDebugTracer = new vm_debug_tracer_1.VMDebugTracer(vm);
|
|
917
|
-
return vmDebugTracer.trace(async () => {
|
|
918
|
-
await vm.runTx({
|
|
919
|
-
tx: txWithCommon,
|
|
920
|
-
block,
|
|
921
|
-
skipHardForkValidation: true,
|
|
922
|
-
});
|
|
923
|
-
}, config);
|
|
924
|
-
}
|
|
925
|
-
await vm.runTx({
|
|
926
|
-
tx: txWithCommon,
|
|
927
|
-
block,
|
|
928
|
-
skipHardForkValidation: true,
|
|
929
|
-
});
|
|
930
|
-
}
|
|
931
|
-
throw new errors_2.TransactionExecutionError(`Unable to find a transaction in a block that contains that transaction, this should never happen`);
|
|
932
|
-
});
|
|
933
|
-
}
|
|
934
|
-
async getFeeHistory(blockCount, newestBlock, rewardPercentiles) {
|
|
935
|
-
const latestBlock = this.getLatestBlockNumber();
|
|
936
|
-
const pendingBlockNumber = latestBlock + 1n;
|
|
937
|
-
const resolvedNewestBlock = newestBlock === "pending" ? pendingBlockNumber : newestBlock;
|
|
938
|
-
const oldestBlock = BigIntUtils.max(resolvedNewestBlock - blockCount + 1n, 0n);
|
|
939
|
-
// This is part of a temporary fix to https://github.com/NomicFoundation/hardhat/issues/2380
|
|
940
|
-
const rangeIncludesRemoteBlocks = this._forkBlockNumber !== undefined &&
|
|
941
|
-
oldestBlock <= this._forkBlockNumber;
|
|
942
|
-
const baseFeePerGas = [];
|
|
943
|
-
const gasUsedRatio = [];
|
|
944
|
-
const reward = [];
|
|
945
|
-
const lastBlock = resolvedNewestBlock + 1n;
|
|
946
|
-
// This is part of a temporary fix to https://github.com/NomicFoundation/hardhat/issues/2380
|
|
947
|
-
if (rangeIncludesRemoteBlocks) {
|
|
948
|
-
try {
|
|
949
|
-
const lastRemoteBlock = BigIntUtils.min(BigInt(this._forkBlockNumber), lastBlock);
|
|
950
|
-
const remoteBlockCount = lastRemoteBlock - oldestBlock + 1n;
|
|
951
|
-
const remoteValues = await this._forkClient.getFeeHistory(remoteBlockCount, lastRemoteBlock, rewardPercentiles);
|
|
952
|
-
baseFeePerGas.push(...remoteValues.baseFeePerGas);
|
|
953
|
-
gasUsedRatio.push(...remoteValues.gasUsedRatio);
|
|
954
|
-
if (remoteValues.reward !== undefined) {
|
|
955
|
-
reward.push(...remoteValues.reward);
|
|
956
|
-
}
|
|
957
|
-
}
|
|
958
|
-
catch (e) {
|
|
959
|
-
// TODO: we can return less blocks here still be compliant with the spec
|
|
960
|
-
throw new errors_2.InternalError("Remote node did not answer to eth_feeHistory correctly", e instanceof Error ? e : undefined);
|
|
961
|
-
}
|
|
962
|
-
}
|
|
963
|
-
// We get the pending block here, and only if necessary, as it's something
|
|
964
|
-
// costly to do.
|
|
965
|
-
let pendingBlock;
|
|
966
|
-
if (lastBlock >= pendingBlockNumber) {
|
|
967
|
-
pendingBlock = await this.getBlockByNumber("pending");
|
|
968
|
-
}
|
|
969
|
-
// This is part of a temporary fix to https://github.com/NomicFoundation/hardhat/issues/2380
|
|
970
|
-
const firstLocalBlock = !rangeIncludesRemoteBlocks
|
|
971
|
-
? oldestBlock
|
|
972
|
-
: BigIntUtils.min(BigInt(this._forkBlockNumber), lastBlock) + 1n;
|
|
973
|
-
for (let blockNumber = firstLocalBlock; // This is part of a temporary fix to https://github.com/NomicFoundation/hardhat/issues/2380
|
|
974
|
-
blockNumber <= lastBlock; blockNumber++) {
|
|
975
|
-
if (blockNumber < pendingBlockNumber) {
|
|
976
|
-
// We know the block exists
|
|
977
|
-
const block = (await this.getBlockByNumber(blockNumber));
|
|
978
|
-
baseFeePerGas.push(block.header.baseFeePerGas ?? 0n);
|
|
979
|
-
if (blockNumber < lastBlock) {
|
|
980
|
-
gasUsedRatio.push(this._getGasUsedRatio(block));
|
|
981
|
-
if (rewardPercentiles.length > 0) {
|
|
982
|
-
reward.push(await this._getRewards(block, rewardPercentiles));
|
|
983
|
-
}
|
|
984
|
-
}
|
|
985
|
-
}
|
|
986
|
-
else if (blockNumber === pendingBlockNumber) {
|
|
987
|
-
// This can only be run with EIP-1559, so this exists
|
|
988
|
-
baseFeePerGas.push((await this.getNextBlockBaseFeePerGas()));
|
|
989
|
-
if (blockNumber < lastBlock) {
|
|
990
|
-
gasUsedRatio.push(this._getGasUsedRatio(pendingBlock));
|
|
991
|
-
if (rewardPercentiles.length > 0) {
|
|
992
|
-
// We don't compute this for the pending block, as there's no
|
|
993
|
-
// effective miner fee yet.
|
|
994
|
-
reward.push(rewardPercentiles.map((_) => 0n));
|
|
995
|
-
}
|
|
996
|
-
}
|
|
997
|
-
}
|
|
998
|
-
else if (blockNumber === pendingBlockNumber + 1n) {
|
|
999
|
-
baseFeePerGas.push(pendingBlock.header.calcNextBaseFee());
|
|
1000
|
-
}
|
|
1001
|
-
else {
|
|
1002
|
-
(0, errors_1.assertHardhatInvariant)(false, "This should never happen");
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1005
|
-
return {
|
|
1006
|
-
oldestBlock,
|
|
1007
|
-
baseFeePerGas,
|
|
1008
|
-
gasUsedRatio,
|
|
1009
|
-
reward: rewardPercentiles.length > 0 ? reward : undefined,
|
|
1010
|
-
};
|
|
1011
|
-
}
|
|
1012
|
-
async setCoinbase(coinbase) {
|
|
1013
|
-
this._coinbase = coinbase.toString();
|
|
1014
|
-
}
|
|
1015
|
-
_getGasUsedRatio(block) {
|
|
1016
|
-
const FLOATS_PRECISION = 100000;
|
|
1017
|
-
return (Number((block.header.gasUsed * BigInt(FLOATS_PRECISION)) /
|
|
1018
|
-
block.header.gasLimit) / FLOATS_PRECISION);
|
|
1019
|
-
}
|
|
1020
|
-
async _getRewards(block, rewardPercentiles) {
|
|
1021
|
-
const FLOATS_PRECISION = 100000;
|
|
1022
|
-
if (block.transactions.length === 0) {
|
|
1023
|
-
return rewardPercentiles.map((_) => 0n);
|
|
1024
|
-
}
|
|
1025
|
-
const receipts = await Promise.all(block.transactions
|
|
1026
|
-
.map((tx) => tx.hash())
|
|
1027
|
-
.map((hash) => this.getTransactionReceipt(hash)));
|
|
1028
|
-
const effectiveGasRewardAndGas = receipts
|
|
1029
|
-
.map((r, i) => {
|
|
1030
|
-
const tx = block.transactions[i];
|
|
1031
|
-
const baseFeePerGas = block.header.baseFeePerGas ?? 0n;
|
|
1032
|
-
// reward = min(maxPriorityFeePerGas, maxFeePerGas - baseFeePerGas)
|
|
1033
|
-
let effectiveGasReward;
|
|
1034
|
-
if ("maxPriorityFeePerGas" in tx) {
|
|
1035
|
-
effectiveGasReward = tx.maxFeePerGas - baseFeePerGas;
|
|
1036
|
-
if (tx.maxPriorityFeePerGas < effectiveGasReward) {
|
|
1037
|
-
effectiveGasReward = tx.maxPriorityFeePerGas;
|
|
1038
|
-
}
|
|
1039
|
-
}
|
|
1040
|
-
else {
|
|
1041
|
-
effectiveGasReward = tx.gasPrice - baseFeePerGas;
|
|
1042
|
-
}
|
|
1043
|
-
return {
|
|
1044
|
-
effectiveGasReward,
|
|
1045
|
-
gasUsed: (0, base_types_1.rpcQuantityToBigInt)(r?.gasUsed),
|
|
1046
|
-
};
|
|
1047
|
-
})
|
|
1048
|
-
.sort((a, b) => BigIntUtils.cmp(a.effectiveGasReward, b.effectiveGasReward));
|
|
1049
|
-
return rewardPercentiles.map((p) => {
|
|
1050
|
-
let gasUsed = 0n;
|
|
1051
|
-
const targetGas = (block.header.gasLimit * BigInt(Math.ceil(p * FLOATS_PRECISION))) /
|
|
1052
|
-
BigInt(100 * FLOATS_PRECISION);
|
|
1053
|
-
for (const values of effectiveGasRewardAndGas) {
|
|
1054
|
-
gasUsed += values.gasUsed;
|
|
1055
|
-
if (targetGas <= gasUsed) {
|
|
1056
|
-
return values.effectiveGasReward;
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
return effectiveGasRewardAndGas[effectiveGasRewardAndGas.length - 1]
|
|
1060
|
-
.effectiveGasReward;
|
|
1061
|
-
});
|
|
1062
|
-
}
|
|
1063
|
-
async _addPendingTransaction(tx) {
|
|
1064
|
-
await this._txPool.addTransaction(tx);
|
|
1065
|
-
await this._notifyPendingTransaction(tx);
|
|
1066
|
-
return (0, ethereumjs_util_1.bufferToHex)(tx.hash());
|
|
1067
|
-
}
|
|
1068
|
-
async _mineTransaction(tx) {
|
|
1069
|
-
await this._addPendingTransaction(tx);
|
|
1070
|
-
return this.mineBlock();
|
|
1071
|
-
}
|
|
1072
|
-
async _mineTransactionAndPending(tx) {
|
|
1073
|
-
const snapshotId = await this.takeSnapshot();
|
|
1074
|
-
let result;
|
|
1075
|
-
try {
|
|
1076
|
-
const txHash = await this._addPendingTransaction(tx);
|
|
1077
|
-
result = await this._mineBlocksUntilTransactionIsIncluded(txHash);
|
|
1078
|
-
}
|
|
1079
|
-
catch (err) {
|
|
1080
|
-
await this.revertToSnapshot(snapshotId);
|
|
1081
|
-
throw err;
|
|
1082
|
-
}
|
|
1083
|
-
this._removeSnapshot(snapshotId);
|
|
1084
|
-
return result;
|
|
1085
|
-
}
|
|
1086
|
-
async _mineBlocksUntilTransactionIsIncluded(txHash) {
|
|
1087
|
-
const results = [];
|
|
1088
|
-
let txReceipt;
|
|
1089
|
-
do {
|
|
1090
|
-
if (!this._txPool.hasPendingTransactions()) {
|
|
1091
|
-
throw new errors_2.TransactionExecutionError("Failed to mine transaction for unknown reason, this should never happen");
|
|
1092
|
-
}
|
|
1093
|
-
results.push(await this.mineBlock());
|
|
1094
|
-
txReceipt = await this.getTransactionReceipt(txHash);
|
|
1095
|
-
} while (txReceipt === undefined);
|
|
1096
|
-
while (this._txPool.hasPendingTransactions()) {
|
|
1097
|
-
results.push(await this.mineBlock());
|
|
1098
|
-
}
|
|
1099
|
-
return results;
|
|
1100
|
-
}
|
|
1101
|
-
async _gatherTraces(result) {
|
|
1102
|
-
let vmTrace = this._vmTracer.getLastTopLevelMessageTrace();
|
|
1103
|
-
const vmTracerError = this._vmTracer.getLastError();
|
|
1104
|
-
this._vmTracer.clearLastError();
|
|
1105
|
-
if (vmTrace !== undefined) {
|
|
1106
|
-
vmTrace = this._vmTraceDecoder.tryToDecodeMessageTrace(vmTrace);
|
|
1107
|
-
}
|
|
1108
|
-
const consoleLogMessages = await this._getConsoleLogMessages(vmTrace, vmTracerError);
|
|
1109
|
-
const error = await this._manageErrors(result, vmTrace, vmTracerError);
|
|
1110
|
-
return {
|
|
1111
|
-
trace: vmTrace,
|
|
1112
|
-
consoleLogMessages,
|
|
1113
|
-
error,
|
|
1114
|
-
};
|
|
1115
|
-
}
|
|
1116
|
-
async _validateAutominedTx(tx) {
|
|
1117
|
-
let sender;
|
|
1118
|
-
try {
|
|
1119
|
-
sender = tx.getSenderAddress(); // verifies signature as a side effect
|
|
1120
|
-
}
|
|
1121
|
-
catch (e) {
|
|
1122
|
-
if (e instanceof Error) {
|
|
1123
|
-
throw new errors_2.InvalidInputError(e.message);
|
|
1124
|
-
}
|
|
1125
|
-
// eslint-disable-next-line @nomicfoundation/hardhat-internal-rules/only-hardhat-error
|
|
1126
|
-
throw e;
|
|
1127
|
-
}
|
|
1128
|
-
// validate nonce
|
|
1129
|
-
const nextPendingNonce = await this._txPool.getNextPendingNonce(sender);
|
|
1130
|
-
const txNonce = tx.nonce;
|
|
1131
|
-
const expectedNonceMsg = `Expected nonce to be ${nextPendingNonce.toString()} but got ${txNonce.toString()}.`;
|
|
1132
|
-
if (txNonce > nextPendingNonce) {
|
|
1133
|
-
throw new errors_2.InvalidInputError(`Nonce too high. ${expectedNonceMsg} Note that transactions can't be queued when automining.`);
|
|
1134
|
-
}
|
|
1135
|
-
if (txNonce < nextPendingNonce) {
|
|
1136
|
-
throw new errors_2.InvalidInputError(`Nonce too low. ${expectedNonceMsg}`);
|
|
1137
|
-
}
|
|
1138
|
-
// validate gas price
|
|
1139
|
-
const txPriorityFee = "gasPrice" in tx ? tx.gasPrice : tx.maxPriorityFeePerGas;
|
|
1140
|
-
if (txPriorityFee < this._minGasPrice) {
|
|
1141
|
-
throw new errors_2.InvalidInputError(`Transaction gas price is ${txPriorityFee.toString()}, which is below the minimum of ${this._minGasPrice.toString()}`);
|
|
1142
|
-
}
|
|
1143
|
-
// Validate that maxFeePerGas >= next block's baseFee
|
|
1144
|
-
const nextBlockGasFee = await this.getNextBlockBaseFeePerGas();
|
|
1145
|
-
if (nextBlockGasFee !== undefined) {
|
|
1146
|
-
if ("maxFeePerGas" in tx) {
|
|
1147
|
-
if (nextBlockGasFee > tx.maxFeePerGas) {
|
|
1148
|
-
throw new errors_2.InvalidInputError(`Transaction maxFeePerGas (${tx.maxFeePerGas.toString()}) is too low for the next block, which has a baseFeePerGas of ${nextBlockGasFee.toString()}`);
|
|
1149
|
-
}
|
|
1150
|
-
}
|
|
1151
|
-
else {
|
|
1152
|
-
if (nextBlockGasFee > tx.gasPrice) {
|
|
1153
|
-
throw new errors_2.InvalidInputError(`Transaction gasPrice (${tx.gasPrice.toString()}) is too low for the next block, which has a baseFeePerGas of ${nextBlockGasFee.toString()}`);
|
|
1154
|
-
}
|
|
1155
|
-
}
|
|
1156
|
-
}
|
|
1157
|
-
}
|
|
1158
|
-
/**
|
|
1159
|
-
* Mines a new block with as many pending txs as possible, adding it to
|
|
1160
|
-
* the VM's blockchain.
|
|
1161
|
-
*
|
|
1162
|
-
* This method reverts any modification to the state manager if it throws.
|
|
1163
|
-
*/
|
|
1164
|
-
async _mineBlockWithPendingTxs(blockTimestamp) {
|
|
1165
|
-
const parentBlock = await this.getLatestBlock();
|
|
1166
|
-
const headerData = {
|
|
1167
|
-
gasLimit: this.getBlockGasLimit(),
|
|
1168
|
-
coinbase: this.getCoinbaseAddress(),
|
|
1169
|
-
nonce: this.isPostMergeHardfork()
|
|
1170
|
-
? "0x0000000000000000"
|
|
1171
|
-
: "0x0000000000000042",
|
|
1172
|
-
timestamp: blockTimestamp,
|
|
1173
|
-
};
|
|
1174
|
-
if (this.isPostMergeHardfork()) {
|
|
1175
|
-
headerData.mixHash = this._getNextMixHash();
|
|
1176
|
-
}
|
|
1177
|
-
headerData.baseFeePerGas = await this.getNextBlockBaseFeePerGas();
|
|
1178
|
-
const blockBuilder = await this._vm.buildBlock({
|
|
1179
|
-
parentBlock,
|
|
1180
|
-
headerData,
|
|
1181
|
-
blockOpts: { calcDifficultyFromHeader: parentBlock.header },
|
|
1182
|
-
});
|
|
1183
|
-
try {
|
|
1184
|
-
const traces = [];
|
|
1185
|
-
const blockGasLimit = this.getBlockGasLimit();
|
|
1186
|
-
const minTxFee = this._getMinimalTransactionFee();
|
|
1187
|
-
const pendingTxs = this._txPool.getPendingTransactions();
|
|
1188
|
-
const transactionQueue = new TransactionQueue_1.TransactionQueue(pendingTxs, this._mempoolOrder, headerData.baseFeePerGas);
|
|
1189
|
-
let tx = transactionQueue.getNextTransaction();
|
|
1190
|
-
const results = [];
|
|
1191
|
-
const receipts = [];
|
|
1192
|
-
while (blockGasLimit - blockBuilder.gasUsed >= minTxFee &&
|
|
1193
|
-
tx !== undefined) {
|
|
1194
|
-
if (!this._isTxMinable(tx, headerData.baseFeePerGas) ||
|
|
1195
|
-
tx.gasLimit > blockGasLimit - blockBuilder.gasUsed) {
|
|
1196
|
-
transactionQueue.removeLastSenderTransactions();
|
|
1197
|
-
}
|
|
1198
|
-
else {
|
|
1199
|
-
const txResult = await blockBuilder.addTransaction(tx);
|
|
1200
|
-
traces.push(await this._gatherTraces(txResult.execResult));
|
|
1201
|
-
results.push(txResult);
|
|
1202
|
-
receipts.push(txResult.receipt);
|
|
1203
|
-
}
|
|
1204
|
-
tx = transactionQueue.getNextTransaction();
|
|
1205
|
-
}
|
|
1206
|
-
const block = await blockBuilder.build();
|
|
1207
|
-
await this._txPool.updatePendingAndQueued();
|
|
1208
|
-
return {
|
|
1209
|
-
block,
|
|
1210
|
-
blockResult: {
|
|
1211
|
-
results,
|
|
1212
|
-
receipts,
|
|
1213
|
-
stateRoot: block.header.stateRoot,
|
|
1214
|
-
logsBloom: block.header.logsBloom,
|
|
1215
|
-
receiptsRoot: block.header.receiptTrie,
|
|
1216
|
-
gasUsed: block.header.gasUsed,
|
|
1217
|
-
},
|
|
1218
|
-
traces,
|
|
1219
|
-
};
|
|
1220
|
-
}
|
|
1221
|
-
catch (err) {
|
|
1222
|
-
await blockBuilder.revert();
|
|
1223
|
-
throw err;
|
|
1224
|
-
}
|
|
1225
|
-
}
|
|
1226
|
-
_getMinimalTransactionFee() {
|
|
1227
|
-
// Typically 21_000 gas
|
|
1228
|
-
return this._vm._common.param("gasPrices", "tx");
|
|
1229
|
-
}
|
|
1230
|
-
async _getFakeTransaction(txParams) {
|
|
1231
|
-
const sender = new ethereumjs_util_1.Address(txParams.from);
|
|
1232
|
-
if ("maxFeePerGas" in txParams && txParams.maxFeePerGas !== undefined) {
|
|
1233
|
-
return new FakeSenderEIP1559Transaction_1.FakeSenderEIP1559Transaction(sender, txParams, {
|
|
1234
|
-
common: this._vm._common,
|
|
1235
|
-
});
|
|
1236
|
-
}
|
|
1237
|
-
if ("accessList" in txParams && txParams.accessList !== undefined) {
|
|
1238
|
-
return new FakeSenderAccessListEIP2930Transaction_1.FakeSenderAccessListEIP2930Transaction(sender, txParams, {
|
|
1239
|
-
common: this._vm._common,
|
|
1240
|
-
});
|
|
1241
|
-
}
|
|
1242
|
-
return new FakeSenderTransaction_1.FakeSenderTransaction(sender, txParams, {
|
|
1243
|
-
common: this._vm._common,
|
|
1244
|
-
});
|
|
1245
|
-
}
|
|
1246
|
-
_getSnapshotIndex(id) {
|
|
1247
|
-
for (const [i, snapshot] of this._snapshots.entries()) {
|
|
1248
|
-
if (snapshot.id === id) {
|
|
1249
|
-
return i;
|
|
1250
|
-
}
|
|
1251
|
-
// We already removed the snapshot we are looking for
|
|
1252
|
-
if (snapshot.id > id) {
|
|
1253
|
-
return undefined;
|
|
1254
|
-
}
|
|
1255
|
-
}
|
|
1256
|
-
return undefined;
|
|
1257
|
-
}
|
|
1258
|
-
_removeSnapshot(id) {
|
|
1259
|
-
const snapshotIndex = this._getSnapshotIndex(id);
|
|
1260
|
-
if (snapshotIndex === undefined) {
|
|
1261
|
-
return;
|
|
1262
|
-
}
|
|
1263
|
-
this._snapshots.splice(snapshotIndex);
|
|
1264
|
-
}
|
|
1265
|
-
_initLocalAccounts(genesisAccounts) {
|
|
1266
|
-
const privateKeys = genesisAccounts.map((acc) => (0, ethereumjs_util_1.toBuffer)(acc.privateKey));
|
|
1267
|
-
for (const pk of privateKeys) {
|
|
1268
|
-
this._localAccounts.set((0, ethereumjs_util_1.bufferToHex)((0, ethereumjs_util_1.privateToAddress)(pk)), pk);
|
|
1269
|
-
}
|
|
1270
|
-
}
|
|
1271
|
-
async _getConsoleLogMessages(vmTrace, vmTracerError) {
|
|
1272
|
-
if (vmTrace === undefined || vmTracerError !== undefined) {
|
|
1273
|
-
log("Could not print console log. Please report this to help us improve Hardhat.\n", vmTracerError);
|
|
1274
|
-
return [];
|
|
1275
|
-
}
|
|
1276
|
-
return this._consoleLogger.getLogMessages(vmTrace);
|
|
1277
|
-
}
|
|
1278
|
-
async _manageErrors(vmResult, vmTrace, vmTracerError) {
|
|
1279
|
-
if (vmResult.exceptionError === undefined) {
|
|
1280
|
-
return undefined;
|
|
1281
|
-
}
|
|
1282
|
-
let stackTrace;
|
|
1283
|
-
try {
|
|
1284
|
-
if (vmTrace === undefined || vmTracerError !== undefined) {
|
|
1285
|
-
throw vmTracerError;
|
|
1286
|
-
}
|
|
1287
|
-
stackTrace = this._solidityTracer.getStackTrace(vmTrace);
|
|
1288
|
-
}
|
|
1289
|
-
catch (err) {
|
|
1290
|
-
this._failedStackTraces += 1;
|
|
1291
|
-
log("Could not generate stack trace. Please report this to help us improve Hardhat.\n", err);
|
|
1292
|
-
}
|
|
1293
|
-
const error = vmResult.exceptionError;
|
|
1294
|
-
// we don't use `instanceof` in case someone uses a different VM dependency
|
|
1295
|
-
// see https://github.com/nomiclabs/hardhat/issues/1317
|
|
1296
|
-
const isVmError = "error" in error && typeof error.error === "string";
|
|
1297
|
-
// If this is not a VM error, or if it's an internal VM error, we just
|
|
1298
|
-
// rethrow. An example of a non-VmError being thrown here is an HTTP error
|
|
1299
|
-
// coming from the ForkedStateManager.
|
|
1300
|
-
if (!isVmError || error.error === exceptions_1.ERROR.INTERNAL_ERROR) {
|
|
1301
|
-
throw error;
|
|
1302
|
-
}
|
|
1303
|
-
if (error.error === exceptions_1.ERROR.CODESIZE_EXCEEDS_MAXIMUM) {
|
|
1304
|
-
if (stackTrace !== undefined) {
|
|
1305
|
-
return (0, solidity_errors_1.encodeSolidityStackTrace)("Transaction ran out of gas", stackTrace);
|
|
1306
|
-
}
|
|
1307
|
-
return new errors_2.TransactionExecutionError("Transaction ran out of gas");
|
|
1308
|
-
}
|
|
1309
|
-
if (error.error === exceptions_1.ERROR.OUT_OF_GAS) {
|
|
1310
|
-
// if the error is an out of gas, we ignore the inferred error in the
|
|
1311
|
-
// trace
|
|
1312
|
-
return new errors_2.TransactionExecutionError("Transaction ran out of gas");
|
|
1313
|
-
}
|
|
1314
|
-
const returnData = new return_data_1.ReturnData(vmResult.returnValue);
|
|
1315
|
-
let returnDataExplanation;
|
|
1316
|
-
if (returnData.isEmpty()) {
|
|
1317
|
-
returnDataExplanation = "without reason string";
|
|
1318
|
-
}
|
|
1319
|
-
else if (returnData.isErrorReturnData()) {
|
|
1320
|
-
returnDataExplanation = `with reason "${returnData.decodeError()}"`;
|
|
1321
|
-
}
|
|
1322
|
-
else if (returnData.isPanicReturnData()) {
|
|
1323
|
-
const panicCode = returnData.decodePanic().toString(16);
|
|
1324
|
-
returnDataExplanation = `with panic code "0x${panicCode}"`;
|
|
1325
|
-
}
|
|
1326
|
-
else {
|
|
1327
|
-
returnDataExplanation = "with unrecognized return data or custom error";
|
|
1328
|
-
}
|
|
1329
|
-
if (error.error === exceptions_1.ERROR.REVERT) {
|
|
1330
|
-
const fallbackMessage = `VM Exception while processing transaction: revert ${returnDataExplanation}`;
|
|
1331
|
-
if (stackTrace !== undefined) {
|
|
1332
|
-
return (0, solidity_errors_1.encodeSolidityStackTrace)(fallbackMessage, stackTrace);
|
|
1333
|
-
}
|
|
1334
|
-
return new errors_2.TransactionExecutionError(fallbackMessage);
|
|
1335
|
-
}
|
|
1336
|
-
if (stackTrace !== undefined) {
|
|
1337
|
-
return (0, solidity_errors_1.encodeSolidityStackTrace)(`Transaction failed: revert ${returnDataExplanation}`, stackTrace);
|
|
1338
|
-
}
|
|
1339
|
-
return new errors_2.TransactionExecutionError(`Transaction reverted ${returnDataExplanation}`);
|
|
1340
|
-
}
|
|
1341
|
-
_calculateTimestampAndOffset(timestamp) {
|
|
1342
|
-
let blockTimestamp;
|
|
1343
|
-
let offsetShouldChange;
|
|
1344
|
-
let newOffset = 0n;
|
|
1345
|
-
const currentTimestamp = BigInt((0, getCurrentTimestamp_1.getCurrentTimestamp)());
|
|
1346
|
-
// if timestamp is not provided, we check nextBlockTimestamp, if it is
|
|
1347
|
-
// set, we use it as the timestamp instead. If it is not set, we use
|
|
1348
|
-
// time offset + real time as the timestamp.
|
|
1349
|
-
if (timestamp === undefined || timestamp === 0n) {
|
|
1350
|
-
if (this.getNextBlockTimestamp() === 0n) {
|
|
1351
|
-
blockTimestamp = currentTimestamp + this.getTimeIncrement();
|
|
1352
|
-
offsetShouldChange = false;
|
|
1353
|
-
}
|
|
1354
|
-
else {
|
|
1355
|
-
blockTimestamp = this.getNextBlockTimestamp();
|
|
1356
|
-
offsetShouldChange = true;
|
|
1357
|
-
}
|
|
1358
|
-
}
|
|
1359
|
-
else {
|
|
1360
|
-
offsetShouldChange = true;
|
|
1361
|
-
blockTimestamp = timestamp;
|
|
1362
|
-
}
|
|
1363
|
-
if (offsetShouldChange) {
|
|
1364
|
-
newOffset = blockTimestamp - currentTimestamp;
|
|
1365
|
-
}
|
|
1366
|
-
return [blockTimestamp, offsetShouldChange, newOffset];
|
|
1367
|
-
}
|
|
1368
|
-
_resetNextBlockTimestamp() {
|
|
1369
|
-
this.setNextBlockTimestamp(0n);
|
|
1370
|
-
}
|
|
1371
|
-
async _notifyPendingTransaction(tx) {
|
|
1372
|
-
this._filters.forEach((filter) => {
|
|
1373
|
-
if (filter.type === filter_1.Type.PENDING_TRANSACTION_SUBSCRIPTION) {
|
|
1374
|
-
const hash = (0, ethereumjs_util_1.bufferToHex)(tx.hash());
|
|
1375
|
-
if (filter.subscription) {
|
|
1376
|
-
this._emitEthEvent(filter.id, hash);
|
|
1377
|
-
return;
|
|
1378
|
-
}
|
|
1379
|
-
filter.hashes.push(hash);
|
|
1380
|
-
}
|
|
1381
|
-
});
|
|
1382
|
-
}
|
|
1383
|
-
_getLocalAccountPrivateKey(sender) {
|
|
1384
|
-
const senderAddress = sender.toString();
|
|
1385
|
-
if (!this._localAccounts.has(senderAddress)) {
|
|
1386
|
-
throw new errors_2.InvalidInputError(`unknown account ${senderAddress}`);
|
|
1387
|
-
}
|
|
1388
|
-
return this._localAccounts.get(senderAddress);
|
|
1389
|
-
}
|
|
1390
|
-
/**
|
|
1391
|
-
* Saves a block as successfully run. This method requires that the block
|
|
1392
|
-
* was added to the blockchain.
|
|
1393
|
-
*/
|
|
1394
|
-
async _saveBlockAsSuccessfullyRun(block, runBlockResult) {
|
|
1395
|
-
const receipts = (0, output_1.getRpcReceiptOutputsFromLocalBlockExecution)(block, runBlockResult, (0, output_1.shouldShowTransactionTypeForHardfork)(this._vm._common));
|
|
1396
|
-
this._blockchain.addTransactionReceipts(receipts);
|
|
1397
|
-
const td = await this.getBlockTotalDifficulty(block);
|
|
1398
|
-
const rpcLogs = [];
|
|
1399
|
-
for (const receipt of receipts) {
|
|
1400
|
-
rpcLogs.push(...receipt.logs);
|
|
1401
|
-
}
|
|
1402
|
-
this._filters.forEach((filter, key) => {
|
|
1403
|
-
if (filter.deadline.valueOf() < new Date().valueOf()) {
|
|
1404
|
-
this._filters.delete(key);
|
|
1405
|
-
}
|
|
1406
|
-
switch (filter.type) {
|
|
1407
|
-
case filter_1.Type.BLOCK_SUBSCRIPTION:
|
|
1408
|
-
const hash = block.hash();
|
|
1409
|
-
if (filter.subscription) {
|
|
1410
|
-
this._emitEthEvent(filter.id, (0, output_1.getRpcBlock)(block, td, (0, output_1.shouldShowTransactionTypeForHardfork)(this._vm._common), false));
|
|
1411
|
-
return;
|
|
1412
|
-
}
|
|
1413
|
-
filter.hashes.push((0, ethereumjs_util_1.bufferToHex)(hash));
|
|
1414
|
-
break;
|
|
1415
|
-
case filter_1.Type.LOGS_SUBSCRIPTION:
|
|
1416
|
-
if ((0, filter_1.bloomFilter)(new ethereumjs_vm_1.Bloom(block.header.logsBloom), filter.criteria.addresses, filter.criteria.normalizedTopics)) {
|
|
1417
|
-
const logs = (0, filter_1.filterLogs)(rpcLogs, filter.criteria);
|
|
1418
|
-
if (logs.length === 0) {
|
|
1419
|
-
return;
|
|
1420
|
-
}
|
|
1421
|
-
if (filter.subscription) {
|
|
1422
|
-
logs.forEach((rpcLog) => {
|
|
1423
|
-
this._emitEthEvent(filter.id, rpcLog);
|
|
1424
|
-
});
|
|
1425
|
-
return;
|
|
1426
|
-
}
|
|
1427
|
-
filter.logs.push(...logs);
|
|
1428
|
-
}
|
|
1429
|
-
break;
|
|
1430
|
-
}
|
|
1431
|
-
});
|
|
1432
|
-
}
|
|
1433
|
-
async _timestampClashesWithPreviousBlockOne(blockTimestamp) {
|
|
1434
|
-
const latestBlock = await this.getLatestBlock();
|
|
1435
|
-
const latestBlockTimestamp = latestBlock.header.timestamp;
|
|
1436
|
-
return latestBlockTimestamp === blockTimestamp;
|
|
1437
|
-
}
|
|
1438
|
-
async _runInBlockContext(blockNumberOrPending, action) {
|
|
1439
|
-
if (blockNumberOrPending === "pending") {
|
|
1440
|
-
return this._runInPendingBlockContext(action);
|
|
1441
|
-
}
|
|
1442
|
-
if (blockNumberOrPending === this.getLatestBlockNumber()) {
|
|
1443
|
-
return action();
|
|
1444
|
-
}
|
|
1445
|
-
const block = await this.getBlockByNumber(blockNumberOrPending);
|
|
1446
|
-
if (block === undefined) {
|
|
1447
|
-
// TODO handle this better
|
|
1448
|
-
throw new Error(`Block with number ${blockNumberOrPending.toString()} doesn't exist. This should never happen.`);
|
|
1449
|
-
}
|
|
1450
|
-
const currentStateRoot = await this._stateManager.getStateRoot();
|
|
1451
|
-
await this._setBlockContext(block);
|
|
1452
|
-
try {
|
|
1453
|
-
return await action();
|
|
1454
|
-
}
|
|
1455
|
-
finally {
|
|
1456
|
-
await this._restoreBlockContext(currentStateRoot);
|
|
1457
|
-
}
|
|
1458
|
-
}
|
|
1459
|
-
async _runInPendingBlockContext(action) {
|
|
1460
|
-
const snapshotId = await this.takeSnapshot();
|
|
1461
|
-
try {
|
|
1462
|
-
await this.mineBlock();
|
|
1463
|
-
return await action();
|
|
1464
|
-
}
|
|
1465
|
-
finally {
|
|
1466
|
-
await this.revertToSnapshot(snapshotId);
|
|
1467
|
-
}
|
|
1468
|
-
}
|
|
1469
|
-
async _setBlockContext(block) {
|
|
1470
|
-
const irregularStateOrUndefined = this._irregularStatesByBlockNumber.get(block.header.number);
|
|
1471
|
-
if (this._stateManager instanceof ForkStateManager_1.ForkStateManager) {
|
|
1472
|
-
return this._stateManager.setBlockContext(block.header.stateRoot, block.header.number, irregularStateOrUndefined);
|
|
1473
|
-
}
|
|
1474
|
-
return this._stateManager.setStateRoot(irregularStateOrUndefined ?? block.header.stateRoot);
|
|
1475
|
-
}
|
|
1476
|
-
async _restoreBlockContext(stateRoot) {
|
|
1477
|
-
if (this._stateManager instanceof ForkStateManager_1.ForkStateManager) {
|
|
1478
|
-
return this._stateManager.restoreForkBlockContext(stateRoot);
|
|
1479
|
-
}
|
|
1480
|
-
return this._stateManager.setStateRoot(stateRoot);
|
|
1481
|
-
}
|
|
1482
|
-
async _correctInitialEstimation(blockNumberOrPending, txParams, initialEstimation) {
|
|
1483
|
-
let tx = await this._getFakeTransaction({
|
|
1484
|
-
...txParams,
|
|
1485
|
-
gasLimit: initialEstimation,
|
|
1486
|
-
});
|
|
1487
|
-
if (tx.getBaseFee() >= initialEstimation) {
|
|
1488
|
-
initialEstimation = tx.getBaseFee() + 1n;
|
|
1489
|
-
tx = await this._getFakeTransaction({
|
|
1490
|
-
...txParams,
|
|
1491
|
-
gasLimit: initialEstimation,
|
|
1492
|
-
});
|
|
1493
|
-
}
|
|
1494
|
-
const result = await this._runInBlockContext(blockNumberOrPending, () => this._runTxAndRevertMutations(tx, blockNumberOrPending));
|
|
1495
|
-
if (result.execResult.exceptionError === undefined) {
|
|
1496
|
-
return initialEstimation;
|
|
1497
|
-
}
|
|
1498
|
-
return this._binarySearchEstimation(blockNumberOrPending, txParams, initialEstimation, this.getBlockGasLimit());
|
|
1499
|
-
}
|
|
1500
|
-
async _binarySearchEstimation(blockNumberOrPending, txParams, highestFailingEstimation, lowestSuccessfulEstimation, roundNumber = 0) {
|
|
1501
|
-
if (lowestSuccessfulEstimation <= highestFailingEstimation) {
|
|
1502
|
-
// This shouldn't happen, but we don't want to go into an infinite loop
|
|
1503
|
-
// if it ever happens
|
|
1504
|
-
return lowestSuccessfulEstimation;
|
|
1505
|
-
}
|
|
1506
|
-
const MAX_GAS_ESTIMATION_IMPROVEMENT_ROUNDS = 20;
|
|
1507
|
-
const diff = lowestSuccessfulEstimation - highestFailingEstimation;
|
|
1508
|
-
const minDiff = highestFailingEstimation >= 4000000n
|
|
1509
|
-
? 50000
|
|
1510
|
-
: highestFailingEstimation >= 1000000n
|
|
1511
|
-
? 10000
|
|
1512
|
-
: highestFailingEstimation >= 100000n
|
|
1513
|
-
? 1000
|
|
1514
|
-
: highestFailingEstimation >= 50000n
|
|
1515
|
-
? 500
|
|
1516
|
-
: highestFailingEstimation >= 30000n
|
|
1517
|
-
? 300
|
|
1518
|
-
: 200;
|
|
1519
|
-
if (diff <= minDiff) {
|
|
1520
|
-
return lowestSuccessfulEstimation;
|
|
1521
|
-
}
|
|
1522
|
-
if (roundNumber > MAX_GAS_ESTIMATION_IMPROVEMENT_ROUNDS) {
|
|
1523
|
-
return lowestSuccessfulEstimation;
|
|
1524
|
-
}
|
|
1525
|
-
const binSearchNewEstimation = highestFailingEstimation + diff / 2n;
|
|
1526
|
-
const optimizedEstimation = roundNumber === 0
|
|
1527
|
-
? 3n * highestFailingEstimation
|
|
1528
|
-
: binSearchNewEstimation;
|
|
1529
|
-
const newEstimation = optimizedEstimation > binSearchNewEstimation
|
|
1530
|
-
? binSearchNewEstimation
|
|
1531
|
-
: optimizedEstimation;
|
|
1532
|
-
// Let other things execute
|
|
1533
|
-
await new Promise((resolve) => setImmediate(resolve));
|
|
1534
|
-
const tx = await this._getFakeTransaction({
|
|
1535
|
-
...txParams,
|
|
1536
|
-
gasLimit: newEstimation,
|
|
1537
|
-
});
|
|
1538
|
-
const result = await this._runInBlockContext(blockNumberOrPending, () => this._runTxAndRevertMutations(tx, blockNumberOrPending));
|
|
1539
|
-
if (result.execResult.exceptionError === undefined) {
|
|
1540
|
-
return this._binarySearchEstimation(blockNumberOrPending, txParams, highestFailingEstimation, newEstimation, roundNumber + 1);
|
|
1541
|
-
}
|
|
1542
|
-
return this._binarySearchEstimation(blockNumberOrPending, txParams, newEstimation, lowestSuccessfulEstimation, roundNumber + 1);
|
|
1543
|
-
}
|
|
1544
|
-
async _applyStateOverrideSet(stateOverrideSet) {
|
|
1545
|
-
// Multiple state override set can be configured for different addresses, hence the loop
|
|
1546
|
-
for (const [addrToOverride, stateOverrideOptions] of Object.entries(stateOverrideSet)) {
|
|
1547
|
-
const address = new ethereumjs_util_1.Address((0, ethereumjs_util_1.toBuffer)(addrToOverride));
|
|
1548
|
-
const { balance, nonce, code, state, stateDiff } = stateOverrideOptions;
|
|
1549
|
-
await this._overrideBalanceAndNonce(address, balance, nonce);
|
|
1550
|
-
await this._overrideCode(address, code);
|
|
1551
|
-
await this._overrideStateAndStateDiff(address, state, stateDiff);
|
|
1552
|
-
}
|
|
1553
|
-
}
|
|
1554
|
-
async _overrideBalanceAndNonce(address, balance, nonce) {
|
|
1555
|
-
const MAX_NONCE = 2n ** 64n - 1n;
|
|
1556
|
-
const MAX_BALANCE = 2n ** 256n - 1n;
|
|
1557
|
-
if (nonce !== undefined && nonce > MAX_NONCE) {
|
|
1558
|
-
throw new errors_2.InvalidInputError(`The 'nonce' property should occupy a maximum of 8 bytes (nonce=${nonce}).`);
|
|
1559
|
-
}
|
|
1560
|
-
if (balance !== undefined && balance > MAX_BALANCE) {
|
|
1561
|
-
throw new errors_2.InvalidInputError(`The 'balance' property should occupy a maximum of 32 bytes (balance=${balance}).`);
|
|
1562
|
-
}
|
|
1563
|
-
await this._stateManager.modifyAccountFields(address, {
|
|
1564
|
-
balance,
|
|
1565
|
-
nonce,
|
|
1566
|
-
});
|
|
1567
|
-
}
|
|
1568
|
-
async _overrideCode(address, code) {
|
|
1569
|
-
if (code === undefined)
|
|
1570
|
-
return;
|
|
1571
|
-
await this._stateManager.putContractCode(address, code);
|
|
1572
|
-
}
|
|
1573
|
-
async _overrideStateAndStateDiff(address, state, stateDiff) {
|
|
1574
|
-
let newState;
|
|
1575
|
-
if (state !== undefined && stateDiff === undefined) {
|
|
1576
|
-
await this._stateManager.clearContractStorage(address);
|
|
1577
|
-
newState = state;
|
|
1578
|
-
}
|
|
1579
|
-
else if (state === undefined && stateDiff !== undefined) {
|
|
1580
|
-
newState = stateDiff;
|
|
1581
|
-
}
|
|
1582
|
-
else if (state === undefined && stateDiff === undefined) {
|
|
1583
|
-
// nothing to do
|
|
1584
|
-
return;
|
|
1585
|
-
}
|
|
1586
|
-
else {
|
|
1587
|
-
throw new errors_2.InvalidInputError("The properties 'state' and 'stateDiff' cannot be used simultaneously when configuring the state override set passed to the eth_call method.");
|
|
1588
|
-
}
|
|
1589
|
-
for (const [storageKey, value] of Object.entries(newState)) {
|
|
1590
|
-
await this._stateManager.putContractStorage(address, (0, ethereumjs_util_1.toBuffer)(storageKey), (0, ethereumjs_util_1.setLengthLeft)((0, ethereumjs_util_1.bigIntToBuffer)(value), 32));
|
|
1591
|
-
}
|
|
1592
|
-
}
|
|
1593
|
-
/**
|
|
1594
|
-
* This function runs a transaction and reverts all the modifications that it
|
|
1595
|
-
* makes.
|
|
1596
|
-
*/
|
|
1597
|
-
async _runTxAndRevertMutations(tx, blockNumberOrPending, forceBaseFeeZero = false, stateOverrideSet = {}) {
|
|
1598
|
-
const initialStateRoot = await this._stateManager.getStateRoot();
|
|
1599
|
-
await this._applyStateOverrideSet(stateOverrideSet);
|
|
1600
|
-
let blockContext;
|
|
1601
|
-
let originalCommon;
|
|
1602
|
-
try {
|
|
1603
|
-
if (blockNumberOrPending === "pending") {
|
|
1604
|
-
// the new block has already been mined by _runInBlockContext hence we take latest here
|
|
1605
|
-
blockContext = await this.getLatestBlock();
|
|
1606
|
-
}
|
|
1607
|
-
else {
|
|
1608
|
-
// We know that this block number exists, because otherwise
|
|
1609
|
-
// there would be an error in the RPC layer.
|
|
1610
|
-
const block = await this.getBlockByNumber(blockNumberOrPending);
|
|
1611
|
-
(0, errors_1.assertHardhatInvariant)(block !== undefined, "Tried to run a tx in the context of a non-existent block");
|
|
1612
|
-
blockContext = block;
|
|
1613
|
-
// we don't need to add the tx to the block because runTx doesn't
|
|
1614
|
-
// know anything about the txs in the current block
|
|
1615
|
-
}
|
|
1616
|
-
originalCommon = this._vm._common;
|
|
1617
|
-
this._vm._common = ethereumjs_common_1.Common.custom({
|
|
1618
|
-
chainId: this._forkBlockNumber === undefined ||
|
|
1619
|
-
blockContext.header.number >= this._forkBlockNumber
|
|
1620
|
-
? this._configChainId
|
|
1621
|
-
: this._forkNetworkId,
|
|
1622
|
-
networkId: this._forkNetworkId ?? this._configNetworkId,
|
|
1623
|
-
}, {
|
|
1624
|
-
hardfork: this._selectHardfork(blockContext.header.number),
|
|
1625
|
-
...this._getTransientStorageSettings(),
|
|
1626
|
-
});
|
|
1627
|
-
// If this VM is running without EIP4895, but the block has withdrawals,
|
|
1628
|
-
// we remove them and the withdrawal root from the block
|
|
1629
|
-
if (!this.isEip4895Active(blockNumberOrPending) &&
|
|
1630
|
-
blockContext.withdrawals !== undefined) {
|
|
1631
|
-
blockContext = ethereumjs_block_1.Block.fromBlockData({
|
|
1632
|
-
...blockContext,
|
|
1633
|
-
withdrawals: undefined,
|
|
1634
|
-
header: {
|
|
1635
|
-
...blockContext.header,
|
|
1636
|
-
withdrawalsRoot: undefined,
|
|
1637
|
-
},
|
|
1638
|
-
}, {
|
|
1639
|
-
freeze: false,
|
|
1640
|
-
common: this._vm._common,
|
|
1641
|
-
skipConsensusFormatValidation: true,
|
|
1642
|
-
});
|
|
1643
|
-
}
|
|
1644
|
-
// NOTE: This is a workaround of both an @nomicfoundation/ethereumjs-vm limitation, and
|
|
1645
|
-
// a bug in Hardhat Network.
|
|
1646
|
-
//
|
|
1647
|
-
// See: https://github.com/nomiclabs/hardhat/issues/1666
|
|
1648
|
-
//
|
|
1649
|
-
// If this VM is running with EIP1559 activated, and the block is not
|
|
1650
|
-
// an EIP1559 one, this will crash, so we create a new one that has
|
|
1651
|
-
// baseFeePerGas = 0.
|
|
1652
|
-
//
|
|
1653
|
-
// We also have an option to force the base fee to be zero,
|
|
1654
|
-
// we don't want to debit any balance nor fail any tx when running an
|
|
1655
|
-
// eth_call. This will make the BASEFEE option also return 0, which
|
|
1656
|
-
// shouldn't. See: https://github.com/nomiclabs/hardhat/issues/1688
|
|
1657
|
-
if (this.isEip1559Active(blockNumberOrPending) &&
|
|
1658
|
-
(blockContext.header.baseFeePerGas === undefined || forceBaseFeeZero)) {
|
|
1659
|
-
blockContext = ethereumjs_block_1.Block.fromBlockData(blockContext, {
|
|
1660
|
-
freeze: false,
|
|
1661
|
-
common: this._vm._common,
|
|
1662
|
-
skipConsensusFormatValidation: true,
|
|
1663
|
-
});
|
|
1664
|
-
blockContext.header.baseFeePerGas = 0n;
|
|
1665
|
-
}
|
|
1666
|
-
return await this._vm.runTx({
|
|
1667
|
-
block: blockContext,
|
|
1668
|
-
tx,
|
|
1669
|
-
skipNonce: true,
|
|
1670
|
-
skipBalance: true,
|
|
1671
|
-
skipBlockGasLimitValidation: true,
|
|
1672
|
-
skipHardForkValidation: true,
|
|
1673
|
-
});
|
|
1674
|
-
}
|
|
1675
|
-
finally {
|
|
1676
|
-
if (originalCommon !== undefined) {
|
|
1677
|
-
this._vm._common = originalCommon;
|
|
1678
|
-
}
|
|
1679
|
-
await this._stateManager.setStateRoot(initialStateRoot);
|
|
1680
|
-
}
|
|
1681
|
-
}
|
|
1682
|
-
async _computeFilterParams(filterParams, isFilter) {
|
|
1683
|
-
const latestBlockNumber = this.getLatestBlockNumber();
|
|
1684
|
-
const newFilterParams = { ...filterParams };
|
|
1685
|
-
if (newFilterParams.fromBlock === filter_1.LATEST_BLOCK) {
|
|
1686
|
-
newFilterParams.fromBlock = latestBlockNumber;
|
|
1687
|
-
}
|
|
1688
|
-
if (!isFilter && newFilterParams.toBlock === filter_1.LATEST_BLOCK) {
|
|
1689
|
-
newFilterParams.toBlock = latestBlockNumber;
|
|
1690
|
-
}
|
|
1691
|
-
if (newFilterParams.toBlock > latestBlockNumber) {
|
|
1692
|
-
newFilterParams.toBlock = latestBlockNumber;
|
|
1693
|
-
}
|
|
1694
|
-
if (newFilterParams.fromBlock > latestBlockNumber) {
|
|
1695
|
-
newFilterParams.fromBlock = latestBlockNumber;
|
|
1696
|
-
}
|
|
1697
|
-
return newFilterParams;
|
|
1698
|
-
}
|
|
1699
|
-
_newDeadline() {
|
|
1700
|
-
const dt = new Date();
|
|
1701
|
-
dt.setMinutes(dt.getMinutes() + 5); // This will not overflow
|
|
1702
|
-
return dt;
|
|
1703
|
-
}
|
|
1704
|
-
_getNextFilterId() {
|
|
1705
|
-
this._lastFilterId++;
|
|
1706
|
-
return this._lastFilterId;
|
|
1707
|
-
}
|
|
1708
|
-
_filterIdToFiltersKey(filterId) {
|
|
1709
|
-
return filterId.toString();
|
|
1710
|
-
}
|
|
1711
|
-
_emitEthEvent(filterId, result) {
|
|
1712
|
-
this.emit("ethEvent", {
|
|
1713
|
-
result,
|
|
1714
|
-
filterId,
|
|
1715
|
-
});
|
|
1716
|
-
}
|
|
1717
|
-
async _getNonce(address, blockNumberOrPending) {
|
|
1718
|
-
if (blockNumberOrPending === "pending") {
|
|
1719
|
-
return this.getAccountNextPendingNonce(address);
|
|
1720
|
-
}
|
|
1721
|
-
return this._runInBlockContext(blockNumberOrPending, async () => {
|
|
1722
|
-
const account = await this._stateManager.getAccount(address);
|
|
1723
|
-
return account.nonce;
|
|
1724
|
-
});
|
|
1725
|
-
}
|
|
1726
|
-
async _isTransactionMined(hash) {
|
|
1727
|
-
const txReceipt = await this.getTransactionReceipt(hash);
|
|
1728
|
-
return txReceipt !== undefined;
|
|
1729
|
-
}
|
|
1730
|
-
_isTxMinable(tx, nextBlockBaseFeePerGas) {
|
|
1731
|
-
const txMaxFee = "gasPrice" in tx ? tx.gasPrice : tx.maxFeePerGas;
|
|
1732
|
-
const canPayBaseFee = nextBlockBaseFeePerGas !== undefined
|
|
1733
|
-
? txMaxFee >= nextBlockBaseFeePerGas
|
|
1734
|
-
: true;
|
|
1735
|
-
const atLeastMinGasPrice = txMaxFee >= this._minGasPrice;
|
|
1736
|
-
return canPayBaseFee && atLeastMinGasPrice;
|
|
1737
|
-
}
|
|
1738
|
-
async _persistIrregularWorldState() {
|
|
1739
|
-
this._irregularStatesByBlockNumber.set(this.getLatestBlockNumber(), await this._stateManager.getStateRoot());
|
|
1740
|
-
}
|
|
1741
|
-
isEip1559Active(blockNumberOrPending) {
|
|
1742
|
-
if (blockNumberOrPending !== undefined &&
|
|
1743
|
-
blockNumberOrPending !== "pending") {
|
|
1744
|
-
return this._vm._common.hardforkGteHardfork(this._selectHardfork(blockNumberOrPending), "london");
|
|
1745
|
-
}
|
|
1746
|
-
return this._vm._common.gteHardfork("london");
|
|
1747
|
-
}
|
|
1748
|
-
isEip4895Active(blockNumberOrPending) {
|
|
1749
|
-
if (blockNumberOrPending !== undefined &&
|
|
1750
|
-
blockNumberOrPending !== "pending") {
|
|
1751
|
-
return this._vm._common.hardforkGteHardfork(this._selectHardfork(blockNumberOrPending), "shanghai");
|
|
1752
|
-
}
|
|
1753
|
-
return this._vm._common.gteHardfork("shanghai");
|
|
1754
|
-
}
|
|
1755
|
-
isPostMergeHardfork() {
|
|
1756
|
-
return (0, hardforks_1.hardforkGte)(this.hardfork, hardforks_1.HardforkName.MERGE);
|
|
1757
|
-
}
|
|
1758
|
-
setPrevRandao(prevRandao) {
|
|
1759
|
-
this._mixHashGenerator.setNext(prevRandao);
|
|
1760
|
-
}
|
|
1761
|
-
async getClientVersion() {
|
|
1762
|
-
const hardhatPackage = await (0, packageInfo_1.getPackageJson)();
|
|
1763
|
-
const ethereumjsVMPackage = require("@nomicfoundation/ethereumjs-vm/package.json");
|
|
1764
|
-
return `HardhatNetwork/${hardhatPackage.version}/@nomicfoundation/ethereumjs-vm/${ethereumjsVMPackage.version}`;
|
|
1765
|
-
}
|
|
1766
|
-
async getMetadata() {
|
|
1767
|
-
const clientVersion = await this.getClientVersion();
|
|
1768
|
-
const instanceIdHex = BigIntUtils.toEvmWord(this._instanceId);
|
|
1769
|
-
const instanceId = `0x${instanceIdHex}`;
|
|
1770
|
-
const latestBlock = await this.getLatestBlock();
|
|
1771
|
-
const latestBlockHashHex = latestBlock.header.hash().toString("hex");
|
|
1772
|
-
const latestBlockHash = `0x${latestBlockHashHex}`;
|
|
1773
|
-
const metadata = {
|
|
1774
|
-
clientVersion,
|
|
1775
|
-
chainId: this._configChainId,
|
|
1776
|
-
instanceId,
|
|
1777
|
-
latestBlockNumber: Number(latestBlock.header.number),
|
|
1778
|
-
latestBlockHash,
|
|
1779
|
-
};
|
|
1780
|
-
if (this._forkBlockNumber !== undefined) {
|
|
1781
|
-
(0, errors_1.assertHardhatInvariant)(this._forkNetworkId !== undefined, "this._forkNetworkId should be defined if this._forkBlockNumber is defined");
|
|
1782
|
-
(0, errors_1.assertHardhatInvariant)(this._forkBlockHash !== undefined, "this._forkBlockhash should be defined if this._forkBlockNumber is defined");
|
|
1783
|
-
metadata.forkedNetwork = {
|
|
1784
|
-
chainId: this._forkNetworkId,
|
|
1785
|
-
forkBlockNumber: Number(this._forkBlockNumber),
|
|
1786
|
-
forkBlockHash: this._forkBlockHash,
|
|
1787
|
-
};
|
|
1788
|
-
}
|
|
1789
|
-
return metadata;
|
|
1790
|
-
}
|
|
1791
|
-
_getNextMixHash() {
|
|
1792
|
-
return this._mixHashGenerator.next();
|
|
1793
|
-
}
|
|
1794
|
-
async _getEstimateGasFeePriceFields(callParams, blockNumberOrPending) {
|
|
1795
|
-
if (!this.isEip1559Active(blockNumberOrPending) ||
|
|
1796
|
-
callParams.gasPrice !== undefined) {
|
|
1797
|
-
return { gasPrice: callParams.gasPrice ?? (await this.getGasPrice()) };
|
|
1798
|
-
}
|
|
1799
|
-
let maxFeePerGas = callParams.maxFeePerGas;
|
|
1800
|
-
let maxPriorityFeePerGas = callParams.maxPriorityFeePerGas;
|
|
1801
|
-
if (maxPriorityFeePerGas === undefined) {
|
|
1802
|
-
maxPriorityFeePerGas = await this.getMaxPriorityFeePerGas();
|
|
1803
|
-
if (maxFeePerGas !== undefined && maxFeePerGas < maxPriorityFeePerGas) {
|
|
1804
|
-
maxPriorityFeePerGas = maxFeePerGas;
|
|
1805
|
-
}
|
|
1806
|
-
}
|
|
1807
|
-
if (maxFeePerGas === undefined) {
|
|
1808
|
-
if (blockNumberOrPending === "pending") {
|
|
1809
|
-
const baseFeePerGas = await this.getNextBlockBaseFeePerGas();
|
|
1810
|
-
maxFeePerGas = 2n * baseFeePerGas + maxPriorityFeePerGas;
|
|
1811
|
-
}
|
|
1812
|
-
else {
|
|
1813
|
-
const block = await this.getBlockByNumber(blockNumberOrPending);
|
|
1814
|
-
maxFeePerGas =
|
|
1815
|
-
maxPriorityFeePerGas + (block.header.baseFeePerGas ?? 0n);
|
|
1816
|
-
}
|
|
1817
|
-
}
|
|
1818
|
-
return { maxFeePerGas, maxPriorityFeePerGas };
|
|
1819
|
-
}
|
|
1820
|
-
_selectHardfork(blockNumber) {
|
|
1821
|
-
if (this._forkBlockNumber === undefined ||
|
|
1822
|
-
blockNumber >= this._forkBlockNumber) {
|
|
1823
|
-
return this._vm._common.hardfork();
|
|
1824
|
-
}
|
|
1825
|
-
if (this._hardforkActivations.size === 0) {
|
|
1826
|
-
throw new errors_2.InternalError(`No known hardfork for execution on historical block ${blockNumber.toString()} (relative to fork block number ${this._forkBlockNumber}). The node was not configured with a hardfork activation history. See http://hardhat.org/custom-hardfork-history`);
|
|
1827
|
-
}
|
|
1828
|
-
/** search this._hardforkActivations for the highest block number that
|
|
1829
|
-
* isn't higher than blockNumber, and then return that found block number's
|
|
1830
|
-
* associated hardfork name. */
|
|
1831
|
-
const hardforkHistory = Array.from(this._hardforkActivations.entries());
|
|
1832
|
-
const [hardfork, activationBlock] = hardforkHistory.reduce(([highestHardfork, highestBlock], [thisHardfork, thisBlock]) => thisBlock > highestBlock && thisBlock <= blockNumber
|
|
1833
|
-
? [thisHardfork, thisBlock]
|
|
1834
|
-
: [highestHardfork, highestBlock]);
|
|
1835
|
-
if (hardfork === undefined || blockNumber < activationBlock) {
|
|
1836
|
-
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`);
|
|
1837
|
-
}
|
|
1838
|
-
if (!constants_1.HARDHAT_NETWORK_SUPPORTED_HARDFORKS.includes(hardfork)) {
|
|
1839
|
-
throw new errors_2.InternalError(`Tried to run a call or transaction in the context of a block whose hardfork is "${hardfork}", but Hardhat Network only supports the following hardforks: ${constants_1.HARDHAT_NETWORK_SUPPORTED_HARDFORKS.join(", ")}`);
|
|
1840
|
-
}
|
|
1841
|
-
return hardfork;
|
|
1842
|
-
}
|
|
1843
|
-
_getCommonForTracing(networkId, blockNumber) {
|
|
1844
|
-
try {
|
|
1845
|
-
const common = ethereumjs_common_1.Common.custom({
|
|
1846
|
-
chainId: networkId,
|
|
1847
|
-
networkId,
|
|
1848
|
-
}, {
|
|
1849
|
-
hardfork: this._selectHardfork(BigInt(blockNumber)),
|
|
1850
|
-
...this._getTransientStorageSettings(),
|
|
1851
|
-
});
|
|
1852
|
-
return common;
|
|
1853
|
-
}
|
|
1854
|
-
catch {
|
|
1855
|
-
throw new errors_2.InternalError(`Network id ${networkId} does not correspond to a network that Hardhat can trace`);
|
|
1856
|
-
}
|
|
1857
|
-
}
|
|
1858
|
-
_getTransientStorageSettings() {
|
|
1859
|
-
if (this._enableTransientStorage) {
|
|
1860
|
-
return { eips: [1153] };
|
|
1861
|
-
}
|
|
1862
|
-
return {};
|
|
1863
|
-
}
|
|
1864
|
-
}
|
|
1865
|
-
exports.HardhatNode = HardhatNode;
|
|
1866
|
-
//# sourceMappingURL=node.js.map
|