UNPKG

@nomicfoundation/hardhat-ignition-viem

Version:

The Viem extension to Hardhat Ignition. Hardhat Ignition is a declarative system for deploying smart contracts on Ethereum. It enables you to define smart contract instances you want to deploy, and any operation you want to run on them. By taking over the

60 lines 2.58 kB
import { HardhatError } from "@nomicfoundation/hardhat-errors"; let ViemIgnitionHelperImpl; class LazyViemIgnitionHelper { type = "viem"; #hardhatConfig; #artifactsManager; #connection; #userInterruptions; #hooks; #config; #viemIgnitionHelper; constructor(hardhatConfig, artifactsManager, connection, userInterruptions, hooks, config) { this.#hardhatConfig = hardhatConfig; this.#artifactsManager = artifactsManager; this.#connection = connection; this.#userInterruptions = userInterruptions; this.#hooks = hooks; this.#config = config; } async deploy(ignitionModule, options) { const viemIgnitionHelper = await this.#getViemIgnitionHelper(); return await viemIgnitionHelper.deploy(ignitionModule, options); } getResolvedConfig(perDeployConfig) { // Note: This duplicates the logic of the actual implementation because it's // a synchronous method, so we can't import the implementation. return { ...this.#config, ...perDeployConfig, }; } async #getViemIgnitionHelper() { // Note: `await import` must run BEFORE the instance cache check so that // concurrent callers share a single microtask-dedupe point — otherwise // each suspended caller re-enters the branch and constructs its own // impl, so callers end up holding different impl instances and state, // which can cause concurrency issues. if (ViemIgnitionHelperImpl === undefined) { ({ ViemIgnitionHelperImpl } = await import("../viem-ignition-helper.js")); } if (this.#viemIgnitionHelper === undefined) { this.#viemIgnitionHelper = new ViemIgnitionHelperImpl(this.#hardhatConfig, this.#artifactsManager, this.#connection, this.#userInterruptions, this.#hooks, this.#config); } return this.#viemIgnitionHelper; } } export default async () => { const handlers = { async newConnection(context, next) { const connection = await next(context); if (connection.ignition !== undefined) { throw new HardhatError(HardhatError.ERRORS.IGNITION.INTERNAL.ONLY_ONE_IGNITION_EXTENSION_PLUGIN_ALLOWED); } connection.ignition = new LazyViemIgnitionHelper(context.config, context.artifacts, connection, context.interruptions, context.hooks, context.config.ignition); return connection; }, }; return handlers; }; //# sourceMappingURL=network.js.map