diff --git a/packages/hardhat-plugin-ethers/src/ethers-ignition-helper.ts b/packages/hardhat-plugin-ethers/src/ethers-ignition-helper.ts index fef38dfc2..5e0454b25 100644 --- a/packages/hardhat-plugin-ethers/src/ethers-ignition-helper.ts +++ b/packages/hardhat-plugin-ethers/src/ethers-ignition-helper.ts @@ -2,6 +2,7 @@ import { HardhatArtifactResolver, PrettyEventHandler, errorDeploymentResultToExceptionMessage, + resolveConfigPath, resolveDeploymentId, } from "@nomicfoundation/hardhat-ignition/helpers"; import { @@ -81,7 +82,7 @@ export class EthersIgnitionHelper { deploymentId: givenDeploymentId = undefined, displayUi = false, }: { - parameters?: DeploymentParameters; + parameters?: DeploymentParameters | string; config?: Partial; defaultSender?: string; strategy?: StrategyT; @@ -142,6 +143,14 @@ export class EthersIgnitionHelper { ? new PrettyEventHandler() : undefined; + let deploymentParameters: DeploymentParameters; + + if (typeof parameters === "string") { + deploymentParameters = await resolveConfigPath(parameters); + } else { + deploymentParameters = parameters; + } + const result = await deploy({ config: resolvedConfig, provider: this._provider, @@ -149,7 +158,7 @@ export class EthersIgnitionHelper { executionEventListener, artifactResolver, ignitionModule, - deploymentParameters: parameters, + deploymentParameters, accounts, defaultSender, strategy, diff --git a/packages/hardhat-plugin-viem/src/viem-ignition-helper.ts b/packages/hardhat-plugin-viem/src/viem-ignition-helper.ts index 239243381..41e784fa9 100644 --- a/packages/hardhat-plugin-viem/src/viem-ignition-helper.ts +++ b/packages/hardhat-plugin-viem/src/viem-ignition-helper.ts @@ -4,6 +4,7 @@ import { HardhatArtifactResolver, PrettyEventHandler, errorDeploymentResultToExceptionMessage, + resolveConfigPath, resolveDeploymentId, } from "@nomicfoundation/hardhat-ignition/helpers"; import { @@ -74,7 +75,7 @@ export class ViemIgnitionHelper { deploymentId: givenDeploymentId = undefined, displayUi = false, }: { - parameters?: DeploymentParameters; + parameters?: DeploymentParameters | string; config?: Partial; defaultSender?: string; strategy?: StrategyT; @@ -132,6 +133,14 @@ export class ViemIgnitionHelper { ? new PrettyEventHandler() : undefined; + let deploymentParameters: DeploymentParameters; + + if (typeof parameters === "string") { + deploymentParameters = await resolveConfigPath(parameters); + } else { + deploymentParameters = parameters; + } + const result = await deploy({ config: resolvedConfig, provider: this._provider, @@ -139,7 +148,7 @@ export class ViemIgnitionHelper { executionEventListener, artifactResolver, ignitionModule, - deploymentParameters: parameters, + deploymentParameters, accounts, defaultSender, strategy, diff --git a/packages/hardhat-plugin/src/helpers.ts b/packages/hardhat-plugin/src/helpers.ts index 019c0e688..691604bcf 100644 --- a/packages/hardhat-plugin/src/helpers.ts +++ b/packages/hardhat-plugin/src/helpers.ts @@ -2,3 +2,4 @@ export { HardhatArtifactResolver } from "./hardhat-artifact-resolver"; export { errorDeploymentResultToExceptionMessage } from "./utils/error-deployment-result-to-exception-message"; export { resolveDeploymentId } from "./utils/resolve-deployment-id"; export { PrettyEventHandler } from "./ui/pretty-event-handler"; +export { resolveConfigPath } from "./utils/resolve-config-path"; diff --git a/packages/hardhat-plugin/src/index.ts b/packages/hardhat-plugin/src/index.ts index 133df4e0e..703657267 100644 --- a/packages/hardhat-plugin/src/index.ts +++ b/packages/hardhat-plugin/src/index.ts @@ -7,14 +7,7 @@ import { StatusResult, } from "@nomicfoundation/ignition-core"; import debug from "debug"; -import { - ensureDir, - pathExists, - readFile, - readdirSync, - rm, - writeJSON, -} from "fs-extra"; +import { ensureDir, pathExists, readdirSync, rm, writeJSON } from "fs-extra"; import { extendConfig, extendEnvironment, scope } from "hardhat/config"; import { NomicLabsHardhatPluginError } from "hardhat/plugins"; import { parse as json5Parse } from "json5"; @@ -24,6 +17,7 @@ import "./type-extensions"; import { calculateDeploymentStatusDisplay } from "./ui/helpers/calculate-deployment-status-display"; import { bigintReviver } from "./utils/bigintReviver"; import { getApiKeyAndUrls } from "./utils/getApiKeyAndUrls"; +import { resolveConfigPath } from "./utils/resolve-config-path"; import { resolveDeploymentId } from "./utils/resolve-deployment-id"; import { shouldBeHardhatPluginError } from "./utils/shouldBeHardhatPluginError"; import { verifyEtherscanContract } from "./utils/verifyEtherscanContract"; @@ -741,30 +735,6 @@ async function resolveParametersFromFileName( return resolveConfigPath(filepath); } -async function resolveConfigPath( - filepath: string -): Promise { - try { - const rawFile = await readFile(filepath); - - return await json5Parse(rawFile.toString(), bigintReviver); - } catch (e) { - if (e instanceof NomicLabsHardhatPluginError) { - throw e; - } - - if (e instanceof Error) { - throw new NomicLabsHardhatPluginError( - "@nomicfoundation/hardhat-ignition", - `Could not parse parameters from ${filepath}`, - e - ); - } - - throw e; - } -} - function resolveParametersString(paramString: string): DeploymentParameters { try { return json5Parse(paramString, bigintReviver); diff --git a/packages/hardhat-plugin/src/utils/resolve-config-path.ts b/packages/hardhat-plugin/src/utils/resolve-config-path.ts new file mode 100644 index 000000000..40f3e54fc --- /dev/null +++ b/packages/hardhat-plugin/src/utils/resolve-config-path.ts @@ -0,0 +1,30 @@ +import { DeploymentParameters } from "@nomicfoundation/ignition-core"; +import { readFile } from "fs-extra"; +import { NomicLabsHardhatPluginError } from "hardhat/plugins"; +import { parse as json5Parse } from "json5"; + +import { bigintReviver } from "./bigintReviver"; + +export async function resolveConfigPath( + filepath: string +): Promise { + try { + const rawFile = await readFile(filepath); + + return await json5Parse(rawFile.toString(), bigintReviver); + } catch (e) { + if (e instanceof NomicLabsHardhatPluginError) { + throw e; + } + + if (e instanceof Error) { + throw new NomicLabsHardhatPluginError( + "@nomicfoundation/hardhat-ignition", + `Could not parse parameters from ${filepath}`, + e + ); + } + + throw e; + } +}