hardhat
Version:
Hardhat is an extensible developer tool that helps smart contract developers increase productivity by reliably bringing together the tools they want.
42 lines • 2.17 kB
JavaScript
import { styleText } from "node:util";
import { assertHardhatInvariant } from "@nomicfoundation/hardhat-errors";
import { getCurrentHardfork, hardforkGte, L1HardforkName, OpHardforkName, } from "../types/hardfork.js";
export function getL1HardforkName(name) {
const hardforkName = Object.values(L1HardforkName)[Object.values(L1HardforkName).indexOf(name)];
assertHardhatInvariant(hardforkName !== undefined, `Invalid hardfork name ${name}`);
return hardforkName;
}
// Tracks which (chainType, hardfork) pairs have already been warned about, so
// we only print the experimental-hardfork warning once per process.
const warnedHardforks = new Set();
/**
* Prints a warning if `hardfork` is strictly beyond the latest stable hardfork
* for the given chain type (i.e. an experimental fork that EDR supports but
* hasn't promoted to latest yet). The warning is emitted at
* most once per (chainType, hardfork) pair for the lifetime of the process.
*/
export function warnIfExperimentalHardfork(hardfork, chainType, warn = (message) => console.error(message)) {
const latestStable = getCurrentHardfork(chainType);
// Only warn for hardforks strictly beyond the latest stable one.
if (hardfork === latestStable ||
!hardforkGte(hardfork, latestStable, chainType)) {
return;
}
const key = `${chainType}:${hardfork}`;
if (warnedHardforks.has(key)) {
return;
}
warnedHardforks.add(key);
warn(styleText(["bold", "yellow"], "Warning:") +
` you have configured the "${hardfork}" hardfork, which is experimental ` +
`and not yet finalized, so its behavior may change or be incomplete. ` +
`The latest stable hardfork is "${latestStable}". ` +
`Keep Hardhat up to date to track changes to "${hardfork}" and to pick up ` +
`its stable version once it activates on mainnet.\n`);
}
export function getOpHardforkName(name) {
const hardforkName = Object.values(OpHardforkName)[Object.values(OpHardforkName).indexOf(name)];
assertHardhatInvariant(hardforkName !== undefined, `Invalid hardfork name ${name}`);
return hardforkName;
}
//# sourceMappingURL=hardfork.js.map