From d4d4f3add20412a6597ae0dbd0524b42b4d1a224 Mon Sep 17 00:00:00 2001 From: Vicente Dragicevic Date: Tue, 22 Oct 2024 19:00:31 -0300 Subject: [PATCH] Revert change in getContractData --- packages/cli/src/commands/verify.ts | 3 +-- packages/cli/src/deploy/findLibraries.ts | 3 +-- packages/cli/src/deploy/resolveConfig.ts | 6 ++---- packages/cli/src/utils/getContractData.ts | 13 +++++++------ 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/packages/cli/src/commands/verify.ts b/packages/cli/src/commands/verify.ts index f746930d2e..cfaa6e625c 100644 --- a/packages/cli/src/commands/verify.ts +++ b/packages/cli/src/commands/verify.ts @@ -72,8 +72,7 @@ const commandModule: CommandModule = { // TODO: replace with `resolveConfig` and support for linked libs const configSystems = await resolveSystems({ rootDir, config }); const systems = configSystems.map((system) => { - const contractDataPath = path.join(outDir, `${system.name}.sol`, `${system.name}.json`); - const contractData = getContractData(contractDataPath); + const contractData = getContractData(`${system.name}.sol`, system.name, outDir); return { name: system.name, bytecode: contractData.bytecode, diff --git a/packages/cli/src/deploy/findLibraries.ts b/packages/cli/src/deploy/findLibraries.ts index 1a1ee5d5a7..739fbeb2b8 100644 --- a/packages/cli/src/deploy/findLibraries.ts +++ b/packages/cli/src/deploy/findLibraries.ts @@ -44,8 +44,7 @@ export function findLibraries(forgeOutDirs: string | string[]): Library[] { ); return orderedByDeps.map((library) => { - const contractDataPath = path.join(library.forgeOutDir, path.basename(library.path), `${library.name}.json`); - const contractData = getContractData(contractDataPath); + const contractData = getContractData(path.basename(library.path), library.name, library.forgeOutDir); return { path: library.path, name: library.name, diff --git a/packages/cli/src/deploy/resolveConfig.ts b/packages/cli/src/deploy/resolveConfig.ts index 51b99c9e31..2025863ae3 100644 --- a/packages/cli/src/deploy/resolveConfig.ts +++ b/packages/cli/src/deploy/resolveConfig.ts @@ -40,8 +40,7 @@ export async function resolveConfig({ const libraries = findLibraries([forgeOutDir, ...moduleOutDirs]); - const baseSystemPath = path.join(forgeOutDir, "System.sol", "System.json"); - const baseSystemContractData = getContractData(baseSystemPath); + const baseSystemContractData = getContractData("System.sol", "System", forgeOutDir); const baseSystemFunctions = baseSystemContractData.abi .filter((item): item is typeof item & { type: "function" } => item.type === "function") .map(toFunctionSignature); @@ -59,8 +58,7 @@ export async function resolveConfig({ ); } - const contractDataPath = path.join(forgeOutDir, `${system.label}.sol`, `${system.label}.json`); - const contractData = getContractData(contractDataPath); + const contractData = getContractData(`${system.label}.sol`, system.label, forgeOutDir); // TODO: replace this with manifest const worldFunctions = system.deploy.registerWorldFunctions diff --git a/packages/cli/src/utils/getContractData.ts b/packages/cli/src/utils/getContractData.ts index b413e29556..0681a6e5bd 100644 --- a/packages/cli/src/utils/getContractData.ts +++ b/packages/cli/src/utils/getContractData.ts @@ -1,4 +1,5 @@ import { readFileSync } from "fs"; +import path from "path"; import { MUDError } from "@latticexyz/common/errors"; import { Abi, Hex, size } from "viem"; import { LibraryPlaceholder } from "../deploy/common"; @@ -8,14 +9,14 @@ import { findPlaceholders } from "./findPlaceholders"; * Load the contract's abi and bytecode from the file system * @param contractName: Name of the contract to load */ -export function getContractData(contractDataPath: string): { - bytecode: Hex; - placeholders: readonly LibraryPlaceholder[]; - abi: Abi; - deployedBytecodeSize: number; -} { +export function getContractData( + filename: string, + contractName: string, + forgeOutDirectory: string, +): { bytecode: Hex; placeholders: readonly LibraryPlaceholder[]; abi: Abi; deployedBytecodeSize: number } { // eslint-disable-next-line @typescript-eslint/no-explicit-any let data: any; + const contractDataPath = path.join(forgeOutDirectory, filename, contractName + ".json"); try { data = JSON.parse(readFileSync(contractDataPath, "utf8")); } catch (error) {