diff --git a/package.json b/package.json index ebd9319..d3a1b44 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@zerodev/orchestra", - "version": "0.0.9", + "version": "0.0.10", "description": "", "main": "dist/index.js", "type": "module", diff --git a/src/command/index.ts b/src/command/index.ts index 500cf63..4025f2f 100644 --- a/src/command/index.ts +++ b/src/command/index.ts @@ -24,6 +24,11 @@ import { export const program = new Command() +const fileOption = [ + "-f, --file ", + "file path of bytecode to deploy, a.k.a. init code, or a JSON file containing the bytecode of the contract (such as the output file by Forge), in which case it's assumed that the constructor takes no arguments." +] as [string, string] + program .name("zerodev") .description( @@ -73,10 +78,7 @@ program program .command("compute-address") .description("Compute the address to be deployed") - .option( - "-f, --file ", - "file path of bytecode to deploy, a.k.a. init code" - ) + .option(...fileOption) .option("-b, --bytecode ", "bytecode to deploy") .option( "-s, --salt ", @@ -114,10 +116,7 @@ program .description( "Deploy contracts deterministically using CREATE2, in order of the chains specified" ) - .option( - "-f, --file ", - "file path of bytecode to deploy, a.k.a. init code" - ) + .option(...fileOption) .option("-b, --bytecode ", "bytecode to deploy") .option( "-s, --salt ", @@ -169,10 +168,7 @@ program .description( "check whether the contract has already been deployed on the specified networks" ) - .option( - "-f, --file ", - "file path of bytecode used for deployment, a.k.a. init code" - ) + .option(...fileOption) .option("-b, --bytecode ", "deployed bytecode") .option( "-s, --salt ", diff --git a/src/utils/file.ts b/src/utils/file.ts index e835ff2..4356b8f 100644 --- a/src/utils/file.ts +++ b/src/utils/file.ts @@ -1,10 +1,35 @@ import fs from "fs" import path from "path" +import { encodeDeployData } from "viem" export const readBytecodeFromFile = (pathToBytecode: string): string => { - return fs + const content = fs .readFileSync(path.resolve(process.cwd(), pathToBytecode), "utf8") .replace(/\n+$/, "") + + // Check if this is a JSON file. + // If it is, we assume that it's a compilation artifact as outputted by Forge. + if (pathToBytecode.endsWith(".json")) { + try { + const json = JSON.parse(content) + return ( + encodeDeployData({ + abi: json.abi, + bytecode: json.bytecode, + args: [] + // biome-ignore lint/suspicious/noExplicitAny: reason + }) as any + ).object + } catch (error) { + console.error( + `Error: Failed to parse JSON file ${pathToBytecode}.\nPlease ensure that this is a compilation artifact as outputted by tools such as Forge.` + ) + console.error(error) + process.exit(1) + } + } else { + return content + } } export const writeErrorLogToFile = (chainName: string, error: Error): void => {