UNPKG

@kadena/hardhat-chainweb

Version:
76 lines 4.12 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createHardhatProvider = createHardhatProvider; const provider_1 = require("hardhat/internal/hardhat-network/provider/provider"); // import { applyProviderWrappers } from "hardhat/internal/core/providers/construction"; const util_1 = require("hardhat/internal/core/providers/util"); const backwards_compatibility_1 = require("hardhat/internal/core/providers/backwards-compatibility"); const path_1 = __importDefault(require("path")); const getForkCacheDirPath = (cache) => { return path_1.default.join(cache, 'kadena-hardhat-fork-cache'); }; /** * Hardhat exposes "createHardhatNetworkProvider," which creates an in-process Ethereum provider * (including the Ethereum client). * * The client itself is a Rust-based client, also available via the `@nomicfoundation/edr` package. * This means we don’t need to run a separate Hardhat node. * * This function uses the network configuration to create the providers. */ async function createHardhatProvider(hardhatNetConfig, logger, artifacts) { var _a, _b, _c, _d, _e, _f, _g; let forkConfig; const cachePath = `./cache/chainweb/${hardhatNetConfig.chainwebChainId}`; if (((_a = hardhatNetConfig.forking) === null || _a === void 0 ? void 0 : _a.enabled) === true && ((_b = hardhatNetConfig.forking) === null || _b === void 0 ? void 0 : _b.url) !== undefined) { forkConfig = { jsonRpcUrl: (_c = hardhatNetConfig.forking) === null || _c === void 0 ? void 0 : _c.url, blockNumber: (_d = hardhatNetConfig.forking) === null || _d === void 0 ? void 0 : _d.blockNumber, httpHeaders: hardhatNetConfig.forking.httpHeaders, }; logger.info(`Forking from ${hardhatNetConfig.forking.url}`); } const accounts = (0, util_1.normalizeHardhatNetworkAccountsConfig)(hardhatNetConfig.accounts); const eip1193Provider = await (0, provider_1.createHardhatNetworkProvider)({ chainId: hardhatNetConfig.chainId, networkId: hardhatNetConfig.chainId, hardfork: hardhatNetConfig.hardfork, blockGasLimit: hardhatNetConfig.blockGasLimit, initialBaseFeePerGas: hardhatNetConfig.initialBaseFeePerGas, minGasPrice: hardhatNetConfig.minGasPrice, throwOnTransactionFailures: hardhatNetConfig.throwOnTransactionFailures, throwOnCallFailures: hardhatNetConfig.throwOnCallFailures, automine: hardhatNetConfig.mining.auto, intervalMining: hardhatNetConfig.mining.interval, // This cast is valid because of the config validation and resolution mempoolOrder: hardhatNetConfig.mining.mempool.order, chains: hardhatNetConfig.chains, coinbase: hardhatNetConfig.coinbase, genesisAccounts: accounts, allowUnlimitedContractSize: hardhatNetConfig.allowUnlimitedContractSize, allowBlocksWithSameTimestamp: (_e = hardhatNetConfig.allowBlocksWithSameTimestamp) !== null && _e !== void 0 ? _e : false, initialDate: hardhatNetConfig.initialDate !== undefined ? new Date(hardhatNetConfig.initialDate) : undefined, forkConfig, forkCachePath: getForkCacheDirPath(cachePath), enableTransientStorage: (_f = hardhatNetConfig.enableTransientStorage) !== null && _f !== void 0 ? _f : false, enableRip7212: (_g = hardhatNetConfig.enableRip7212) !== null && _g !== void 0 ? _g : false, }, { enabled: hardhatNetConfig.loggingEnabled, printLineFn: (line) => logger.info(line), replaceLastLineFn: (line) => { process.stdout.clearLine(0); process.stdout.cursorTo(0); logger.info(line); }, }, artifacts); const wrappedProvider = eip1193Provider; console.log('Creating provider'); return new backwards_compatibility_1.BackwardsCompatibilityProviderAdapter(wrappedProvider); } //# sourceMappingURL=create-hardhat-provider.js.map