From 5acb239f21474fa1cbd56dbba00bf0a6d38ac0d3 Mon Sep 17 00:00:00 2001 From: Vicente Dragicevic Date: Fri, 18 Oct 2024 17:50:14 -0300 Subject: [PATCH 01/25] Initial attempt to support deploying libraries needed for modules --- packages/cli/src/deploy/common.ts | 1 + packages/cli/src/deploy/configToModules.ts | 24 ++++++++++++++++++- packages/cli/src/runDeploy.ts | 2 +- .../cli/src/utils/importContractArtifact.ts | 1 + 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/deploy/common.ts b/packages/cli/src/deploy/common.ts index f88db9f65f..1d492e4c07 100644 --- a/packages/cli/src/deploy/common.ts +++ b/packages/cli/src/deploy/common.ts @@ -113,6 +113,7 @@ export type Module = DeterministicContract & { readonly name: string; readonly installAsRoot: boolean; readonly installData: Hex; // TODO: figure out better naming for this + readonly libraries: readonly Library[]; /** * @internal * Optional modules warn instead of throw if they revert while being installed. diff --git a/packages/cli/src/deploy/configToModules.ts b/packages/cli/src/deploy/configToModules.ts index 73f4387f1d..501dcc4b3f 100644 --- a/packages/cli/src/deploy/configToModules.ts +++ b/packages/cli/src/deploy/configToModules.ts @@ -1,5 +1,5 @@ import path from "node:path"; -import { Module } from "./common"; +import { Library, Module } from "./common"; import { encodeField } from "@latticexyz/protocol-parser/internal"; import { SchemaAbiType, SchemaAbiTypeToPrimitiveType } from "@latticexyz/schema-type/internal"; import { bytesToHex } from "viem"; @@ -7,6 +7,10 @@ import { createPrepareDeploy } from "./createPrepareDeploy"; import { World } from "@latticexyz/world"; import { importContractArtifact } from "../utils/importContractArtifact"; import { resolveWithContext } from "@latticexyz/world/internal"; +import { findLibraries } from "./findLibraries"; +import { getContractData } from "../utils/getContractData"; +import { createRequire } from "node:module"; +import { findUp } from "find-up"; /** Please don't add to this list! These are kept for backwards compatibility and assumes the downstream project has this module installed as a dependency. */ const knownModuleArtifacts = { @@ -53,9 +57,26 @@ export async function configToModules( } } + const requirePath = await findUp("package.json", { cwd: process.cwd() }); + if (!requirePath) throw new Error("Could not find package.json to import relative to."); + const require = createRequire(requirePath); + const name = path.basename(artifactPath, ".json"); const artifact = await importContractArtifact({ artifactPath }); + const moduleOutDir = path.join(require.resolve(artifactPath), "../../"); + const libraries = findLibraries(moduleOutDir).map((library): Library => { + // foundry/solc flattens artifacts, so we just use the path basename + const contractData = getContractData(path.basename(library.path), library.name, moduleOutDir); + return { + path: library.path, + name: library.name, + abi: contractData.abi, + prepareDeploy: createPrepareDeploy(contractData.bytecode, contractData.placeholders), + deployedBytecodeSize: contractData.deployedBytecodeSize, + }; + }); + // TODO: replace args with something more strongly typed const installArgs = mod.args .map((arg) => resolveWithContext(arg, { config })) @@ -70,6 +91,7 @@ export async function configToModules( return { name, + libraries, installAsRoot: mod.root, installData: installArgs.length === 0 ? "0x" : installArgs[0], prepareDeploy: createPrepareDeploy(artifact.bytecode, artifact.placeholders), diff --git a/packages/cli/src/runDeploy.ts b/packages/cli/src/runDeploy.ts index 49e4f5c50c..30f9f7abad 100644 --- a/packages/cli/src/runDeploy.ts +++ b/packages/cli/src/runDeploy.ts @@ -150,7 +150,7 @@ export async function runDeploy(opts: DeployOptions): Promise { client, tables, systems, - libraries, + libraries: [...libraries, ...modules.flatMap((mod) => mod.libraries)], modules, artifacts, }); diff --git a/packages/cli/src/utils/importContractArtifact.ts b/packages/cli/src/utils/importContractArtifact.ts index 50c804f750..5920716814 100644 --- a/packages/cli/src/utils/importContractArtifact.ts +++ b/packages/cli/src/utils/importContractArtifact.ts @@ -25,6 +25,7 @@ export async function importContractArtifact({ let artfactJson; try { const requirePath = packageJsonPath ?? (await findUp("package.json", { cwd: process.cwd() })); + console.log({ requirePath }); if (!requirePath) throw new Error("Could not find package.json to import relative to."); const require = createRequire(requirePath); From 06262d0d9b5f3cb4cd3e18ad265d704e7935b6b3 Mon Sep 17 00:00:00 2001 From: Vicente Dragicevic Date: Fri, 18 Oct 2024 17:52:33 -0300 Subject: [PATCH 02/25] Remove console.log --- packages/cli/src/utils/importContractArtifact.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/cli/src/utils/importContractArtifact.ts b/packages/cli/src/utils/importContractArtifact.ts index 5920716814..50c804f750 100644 --- a/packages/cli/src/utils/importContractArtifact.ts +++ b/packages/cli/src/utils/importContractArtifact.ts @@ -25,7 +25,6 @@ export async function importContractArtifact({ let artfactJson; try { const requirePath = packageJsonPath ?? (await findUp("package.json", { cwd: process.cwd() })); - console.log({ requirePath }); if (!requirePath) throw new Error("Could not find package.json to import relative to."); const require = createRequire(requirePath); From 19d2bbb5e78f473522a32dea0c91208192a247eb Mon Sep 17 00:00:00 2001 From: Vicente Dragicevic Date: Fri, 18 Oct 2024 18:19:06 -0300 Subject: [PATCH 03/25] minor changes --- packages/cli/src/deploy/configToModules.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/deploy/configToModules.ts b/packages/cli/src/deploy/configToModules.ts index 501dcc4b3f..d3ace1a416 100644 --- a/packages/cli/src/deploy/configToModules.ts +++ b/packages/cli/src/deploy/configToModules.ts @@ -57,13 +57,13 @@ export async function configToModules( } } + const name = path.basename(artifactPath, ".json"); + const artifact = await importContractArtifact({ artifactPath }); + const requirePath = await findUp("package.json", { cwd: process.cwd() }); if (!requirePath) throw new Error("Could not find package.json to import relative to."); const require = createRequire(requirePath); - const name = path.basename(artifactPath, ".json"); - const artifact = await importContractArtifact({ artifactPath }); - const moduleOutDir = path.join(require.resolve(artifactPath), "../../"); const libraries = findLibraries(moduleOutDir).map((library): Library => { // foundry/solc flattens artifacts, so we just use the path basename From 4569426d45ca0d5f06fa626b678e138d10e3e8cf Mon Sep 17 00:00:00 2001 From: Vicente Dragicevic Date: Mon, 21 Oct 2024 09:52:26 -0300 Subject: [PATCH 04/25] Refactor to do the module library search inside resolveConfig --- packages/cli/src/deploy/common.ts | 1 - packages/cli/src/deploy/configToModules.ts | 24 +--------------------- packages/cli/src/deploy/resolveConfig.ts | 21 +++++++++++++++++++ packages/cli/src/runDeploy.ts | 2 +- 4 files changed, 23 insertions(+), 25 deletions(-) diff --git a/packages/cli/src/deploy/common.ts b/packages/cli/src/deploy/common.ts index 1d492e4c07..f88db9f65f 100644 --- a/packages/cli/src/deploy/common.ts +++ b/packages/cli/src/deploy/common.ts @@ -113,7 +113,6 @@ export type Module = DeterministicContract & { readonly name: string; readonly installAsRoot: boolean; readonly installData: Hex; // TODO: figure out better naming for this - readonly libraries: readonly Library[]; /** * @internal * Optional modules warn instead of throw if they revert while being installed. diff --git a/packages/cli/src/deploy/configToModules.ts b/packages/cli/src/deploy/configToModules.ts index d3ace1a416..73f4387f1d 100644 --- a/packages/cli/src/deploy/configToModules.ts +++ b/packages/cli/src/deploy/configToModules.ts @@ -1,5 +1,5 @@ import path from "node:path"; -import { Library, Module } from "./common"; +import { Module } from "./common"; import { encodeField } from "@latticexyz/protocol-parser/internal"; import { SchemaAbiType, SchemaAbiTypeToPrimitiveType } from "@latticexyz/schema-type/internal"; import { bytesToHex } from "viem"; @@ -7,10 +7,6 @@ import { createPrepareDeploy } from "./createPrepareDeploy"; import { World } from "@latticexyz/world"; import { importContractArtifact } from "../utils/importContractArtifact"; import { resolveWithContext } from "@latticexyz/world/internal"; -import { findLibraries } from "./findLibraries"; -import { getContractData } from "../utils/getContractData"; -import { createRequire } from "node:module"; -import { findUp } from "find-up"; /** Please don't add to this list! These are kept for backwards compatibility and assumes the downstream project has this module installed as a dependency. */ const knownModuleArtifacts = { @@ -60,23 +56,6 @@ export async function configToModules( const name = path.basename(artifactPath, ".json"); const artifact = await importContractArtifact({ artifactPath }); - const requirePath = await findUp("package.json", { cwd: process.cwd() }); - if (!requirePath) throw new Error("Could not find package.json to import relative to."); - const require = createRequire(requirePath); - - const moduleOutDir = path.join(require.resolve(artifactPath), "../../"); - const libraries = findLibraries(moduleOutDir).map((library): Library => { - // foundry/solc flattens artifacts, so we just use the path basename - const contractData = getContractData(path.basename(library.path), library.name, moduleOutDir); - return { - path: library.path, - name: library.name, - abi: contractData.abi, - prepareDeploy: createPrepareDeploy(contractData.bytecode, contractData.placeholders), - deployedBytecodeSize: contractData.deployedBytecodeSize, - }; - }); - // TODO: replace args with something more strongly typed const installArgs = mod.args .map((arg) => resolveWithContext(arg, { config })) @@ -91,7 +70,6 @@ export async function configToModules( return { name, - libraries, installAsRoot: mod.root, installData: installArgs.length === 0 ? "0x" : installArgs[0], prepareDeploy: createPrepareDeploy(artifact.bytecode, artifact.placeholders), diff --git a/packages/cli/src/deploy/resolveConfig.ts b/packages/cli/src/deploy/resolveConfig.ts index dee1d554ef..2a0433d8d5 100644 --- a/packages/cli/src/deploy/resolveConfig.ts +++ b/packages/cli/src/deploy/resolveConfig.ts @@ -24,7 +24,11 @@ export async function resolveConfig({ readonly systems: readonly System[]; readonly libraries: readonly Library[]; }> { +<<<<<<< HEAD const requirePath = await findUp("package.json"); +======= + const requirePath = await findUp("package.json", { cwd: process.cwd() }); +>>>>>>> ba714287d (Refactor to do the module library search inside resolveConfig) if (!requirePath) throw new Error("Could not find package.json to import relative to."); const require = createRequire(requirePath); @@ -33,9 +37,26 @@ export async function resolveConfig({ return []; } +<<<<<<< HEAD // Navigate up two dirs to get the contract output directory const moduleOutDir = path.join(require.resolve(mod.artifactPath), "../../"); return [moduleOutDir]; +======= + const moduleOutDir = path.join(require.resolve(mod.artifactPath), "../../"); + return [moduleOutDir]; + }); + + const libraries = [forgeOutDir, ...moduleOutDirs].flatMap(findLibraries).map((library): Library => { + // foundry/solc flattens artifacts, so we just use the path basename + const contractData = getContractData(path.basename(library.path), library.name, forgeOutDir); + return { + path: library.path, + name: library.name, + abi: contractData.abi, + prepareDeploy: createPrepareDeploy(contractData.bytecode, contractData.placeholders), + deployedBytecodeSize: contractData.deployedBytecodeSize, + }; +>>>>>>> ba714287d (Refactor to do the module library search inside resolveConfig) }); const libraries = [forgeOutDir, ...moduleOutDirs].flatMap((outDir) => diff --git a/packages/cli/src/runDeploy.ts b/packages/cli/src/runDeploy.ts index 30f9f7abad..49e4f5c50c 100644 --- a/packages/cli/src/runDeploy.ts +++ b/packages/cli/src/runDeploy.ts @@ -150,7 +150,7 @@ export async function runDeploy(opts: DeployOptions): Promise { client, tables, systems, - libraries: [...libraries, ...modules.flatMap((mod) => mod.libraries)], + libraries, modules, artifacts, }); From 680b3339fbdac181135a4598cd63d76825f9a91d Mon Sep 17 00:00:00 2001 From: Vicente Dragicevic Date: Mon, 21 Oct 2024 11:48:08 -0300 Subject: [PATCH 05/25] PR feedback --- packages/cli/src/deploy/resolveConfig.ts | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/packages/cli/src/deploy/resolveConfig.ts b/packages/cli/src/deploy/resolveConfig.ts index 2a0433d8d5..dee1d554ef 100644 --- a/packages/cli/src/deploy/resolveConfig.ts +++ b/packages/cli/src/deploy/resolveConfig.ts @@ -24,11 +24,7 @@ export async function resolveConfig({ readonly systems: readonly System[]; readonly libraries: readonly Library[]; }> { -<<<<<<< HEAD const requirePath = await findUp("package.json"); -======= - const requirePath = await findUp("package.json", { cwd: process.cwd() }); ->>>>>>> ba714287d (Refactor to do the module library search inside resolveConfig) if (!requirePath) throw new Error("Could not find package.json to import relative to."); const require = createRequire(requirePath); @@ -37,26 +33,9 @@ export async function resolveConfig({ return []; } -<<<<<<< HEAD // Navigate up two dirs to get the contract output directory const moduleOutDir = path.join(require.resolve(mod.artifactPath), "../../"); return [moduleOutDir]; -======= - const moduleOutDir = path.join(require.resolve(mod.artifactPath), "../../"); - return [moduleOutDir]; - }); - - const libraries = [forgeOutDir, ...moduleOutDirs].flatMap(findLibraries).map((library): Library => { - // foundry/solc flattens artifacts, so we just use the path basename - const contractData = getContractData(path.basename(library.path), library.name, forgeOutDir); - return { - path: library.path, - name: library.name, - abi: contractData.abi, - prepareDeploy: createPrepareDeploy(contractData.bytecode, contractData.placeholders), - deployedBytecodeSize: contractData.deployedBytecodeSize, - }; ->>>>>>> ba714287d (Refactor to do the module library search inside resolveConfig) }); const libraries = [forgeOutDir, ...moduleOutDirs].flatMap((outDir) => From e8659c256ddd61b72d76bc7a98be1ebcf65081aa Mon Sep 17 00:00:00 2001 From: Vicente Dragicevic Date: Mon, 21 Oct 2024 13:24:35 -0300 Subject: [PATCH 06/25] Add pupet modules to e2e mud config --- e2e/packages/contracts/mud.config.ts | 48 ++++++++++++++++++++++++++++ e2e/packages/contracts/worlds.json | 2 +- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/e2e/packages/contracts/mud.config.ts b/e2e/packages/contracts/mud.config.ts index db69f40144..cad7c7eab2 100644 --- a/e2e/packages/contracts/mud.config.ts +++ b/e2e/packages/contracts/mud.config.ts @@ -1,4 +1,27 @@ import { defineWorld } from "@latticexyz/world"; +import { encodeAbiParameters, stringToHex } from "viem"; + +const erc20ModuleArgs = encodeAbiParameters( + [ + { type: "bytes14" }, + { + type: "tuple", + components: [{ type: "uint8" }, { type: "string" }, { type: "string" }], + }, + ], + [stringToHex("MyToken", { size: 14 }), [18, "Worthless Token", "WT"]], +); + +const erc721ModuleArgs = encodeAbiParameters( + [ + { type: "bytes14" }, + { + type: "tuple", + components: [{ type: "string" }, { type: "string" }, { type: "string" }], + }, + ], + [stringToHex("MyNFT", { size: 14 }), ["No Valuable Token", "NVT", "http://www.example.com/base/uri/goes/here"]], +); export default defineWorld({ tables: { @@ -71,5 +94,30 @@ export default defineWorld({ "@latticexyz/world-modules/out/Unstable_CallWithSignatureModule.sol/Unstable_CallWithSignatureModule.json", root: true, }, + { + artifactPath: "@latticexyz/world-modules/out/PuppetModule.sol/PuppetModule.json", + root: false, + args: [], + }, + { + artifactPath: "@latticexyz/world-modules/out/ERC20Module.sol/ERC20Module.json", + root: false, + args: [ + { + type: "bytes", + value: erc20ModuleArgs, + }, + ], + }, + { + artifactPath: "@latticexyz/world-modules/out/ERC721Module.sol/ERC721Module.json", + root: false, + args: [ + { + type: "bytes", + value: erc721ModuleArgs, + }, + ], + }, ], }); diff --git a/e2e/packages/contracts/worlds.json b/e2e/packages/contracts/worlds.json index 436a70cafe..b6d469afda 100644 --- a/e2e/packages/contracts/worlds.json +++ b/e2e/packages/contracts/worlds.json @@ -1,5 +1,5 @@ { "31337": { - "address": "0x7de562d80d6c8672aa32654af67884f411976593" + "address": "0xa9ffe180fd843a0a598d4bfb1c1fd6e155f45724" } } \ No newline at end of file From ce3cea090a346fd7501a539599199a1df3c1f4dd Mon Sep 17 00:00:00 2001 From: Vicente Dragicevic Date: Mon, 21 Oct 2024 14:09:18 -0300 Subject: [PATCH 07/25] Update e2e worlds.json --- e2e/packages/contracts/worlds.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/packages/contracts/worlds.json b/e2e/packages/contracts/worlds.json index b6d469afda..21b4fe2251 100644 --- a/e2e/packages/contracts/worlds.json +++ b/e2e/packages/contracts/worlds.json @@ -1,5 +1,5 @@ { "31337": { - "address": "0xa9ffe180fd843a0a598d4bfb1c1fd6e155f45724" + "address": "0x7f09fa90db320f61bd649661f5f97aa079c1a736" } } \ No newline at end of file From 08ff3f662237ef37bc82c112074e3cd6916b520d Mon Sep 17 00:00:00 2001 From: Vicente Dragicevic Date: Mon, 21 Oct 2024 18:31:49 -0300 Subject: [PATCH 08/25] Add erc20 module to e2e tests, local e2e tests working --- e2e/packages/contracts/mud.config.ts | 6 ++++++ e2e/packages/contracts/package.json | 1 + e2e/packages/contracts/worlds.json | 2 +- e2e/pnpm-lock.yaml | 3 +++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/e2e/packages/contracts/mud.config.ts b/e2e/packages/contracts/mud.config.ts index cad7c7eab2..31466add2e 100644 --- a/e2e/packages/contracts/mud.config.ts +++ b/e2e/packages/contracts/mud.config.ts @@ -1,4 +1,5 @@ import { defineWorld } from "@latticexyz/world"; +import { defineERC20Config } from "@latticexyz/world-module-erc20"; import { encodeAbiParameters, stringToHex } from "viem"; const erc20ModuleArgs = encodeAbiParameters( @@ -119,5 +120,10 @@ export default defineWorld({ }, ], }, + defineERC20Config({ + namespace: "erc20Namespace", + name: "MyToken", + symbol: "MTK", + }), ], }); diff --git a/e2e/packages/contracts/package.json b/e2e/packages/contracts/package.json index 6863f55a98..ca08068992 100644 --- a/e2e/packages/contracts/package.json +++ b/e2e/packages/contracts/package.json @@ -16,6 +16,7 @@ "@latticexyz/schema-type": "link:../../../packages/schema-type", "@latticexyz/store": "link:../../../packages/store", "@latticexyz/world": "link:../../../packages/world", + "@latticexyz/world-module-erc20": "link:../../../packages/world-module-erc20", "@latticexyz/world-modules": "link:../../../packages/world-modules", "dotenv": "^16.0.3", "ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0", diff --git a/e2e/packages/contracts/worlds.json b/e2e/packages/contracts/worlds.json index 21b4fe2251..d5c4c41b3b 100644 --- a/e2e/packages/contracts/worlds.json +++ b/e2e/packages/contracts/worlds.json @@ -1,5 +1,5 @@ { "31337": { - "address": "0x7f09fa90db320f61bd649661f5f97aa079c1a736" + "address": "0x086627188fe4cb73c04bedeace1281e74a6b76d1" } } \ No newline at end of file diff --git a/e2e/pnpm-lock.yaml b/e2e/pnpm-lock.yaml index efc3d77c56..ed033d6956 100644 --- a/e2e/pnpm-lock.yaml +++ b/e2e/pnpm-lock.yaml @@ -96,6 +96,9 @@ importers: '@latticexyz/world': specifier: link:../../../packages/world version: link:../../../packages/world + '@latticexyz/world-module-erc20': + specifier: link:../../../packages/world-module-erc20 + version: link:../../../packages/world-module-erc20 '@latticexyz/world-modules': specifier: link:../../../packages/world-modules version: link:../../../packages/world-modules From 78b1c21cd35a547ec47ae3b35dcf26f2f64b90d5 Mon Sep 17 00:00:00 2001 From: Vicente Dragicevic Date: Mon, 21 Oct 2024 19:07:27 -0300 Subject: [PATCH 09/25] Update worlds.json --- e2e/packages/contracts/worlds.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/packages/contracts/worlds.json b/e2e/packages/contracts/worlds.json index d5c4c41b3b..4848458434 100644 --- a/e2e/packages/contracts/worlds.json +++ b/e2e/packages/contracts/worlds.json @@ -1,5 +1,5 @@ { "31337": { - "address": "0x086627188fe4cb73c04bedeace1281e74a6b76d1" + "address": "0xcbf80e1b5bafec05410e47033d74c6ec4479d385" } } \ No newline at end of file From b00e6d3f67d136f2421fe94503c6610d5a46cbef Mon Sep 17 00:00:00 2001 From: Vicente Dragicevic Date: Mon, 21 Oct 2024 19:31:29 -0300 Subject: [PATCH 10/25] Add erc20 module dev dependency to store-sync, as it needs to be resolved in tests --- packages/store-sync/package.json | 1 + pnpm-lock.yaml | 3 +++ 2 files changed, 4 insertions(+) diff --git a/packages/store-sync/package.json b/packages/store-sync/package.json index 44d4c8647c..9d3799930c 100644 --- a/packages/store-sync/package.json +++ b/packages/store-sync/package.json @@ -92,6 +92,7 @@ "zustand": "^4.3.7" }, "devDependencies": { + "@latticexyz/world-module-erc20": "workspace:*", "@types/debug": "^4.1.7", "@types/node": "20.12.12", "@types/sql.js": "^1.4.4", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7c622f31c2..2305631796 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1185,6 +1185,9 @@ importers: specifier: ^4.3.7 version: 4.3.7(react@18.2.0) devDependencies: + '@latticexyz/world-module-erc20': + specifier: workspace:* + version: link:../world-module-erc20 '@types/debug': specifier: ^4.1.7 version: 4.1.7 From a8097932e21698e1f57ba4efd2398665becb59c8 Mon Sep 17 00:00:00 2001 From: Vicente Dragicevic Date: Tue, 22 Oct 2024 08:24:02 -0300 Subject: [PATCH 11/25] Remove modules to better understand e2e failures --- e2e/packages/contracts/mud.config.ts | 110 +++++++++++++-------------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/e2e/packages/contracts/mud.config.ts b/e2e/packages/contracts/mud.config.ts index 31466add2e..990059a680 100644 --- a/e2e/packages/contracts/mud.config.ts +++ b/e2e/packages/contracts/mud.config.ts @@ -1,29 +1,29 @@ import { defineWorld } from "@latticexyz/world"; -import { defineERC20Config } from "@latticexyz/world-module-erc20"; -import { encodeAbiParameters, stringToHex } from "viem"; - -const erc20ModuleArgs = encodeAbiParameters( - [ - { type: "bytes14" }, - { - type: "tuple", - components: [{ type: "uint8" }, { type: "string" }, { type: "string" }], - }, - ], - [stringToHex("MyToken", { size: 14 }), [18, "Worthless Token", "WT"]], -); - -const erc721ModuleArgs = encodeAbiParameters( - [ - { type: "bytes14" }, - { - type: "tuple", - components: [{ type: "string" }, { type: "string" }, { type: "string" }], - }, - ], - [stringToHex("MyNFT", { size: 14 }), ["No Valuable Token", "NVT", "http://www.example.com/base/uri/goes/here"]], -); - +// import { defineERC20Config } from "@latticexyz/world-module-erc20"; +// import { encodeAbiParameters, stringToHex } from "viem"; +// +// const erc20ModuleArgs = encodeAbiParameters( +// [ +// { type: "bytes14" }, +// { +// type: "tuple", +// components: [{ type: "uint8" }, { type: "string" }, { type: "string" }], +// }, +// ], +// [stringToHex("MyToken", { size: 14 }), [18, "Worthless Token", "WT"]], +// ); +// +// const erc721ModuleArgs = encodeAbiParameters( +// [ +// { type: "bytes14" }, +// { +// type: "tuple", +// components: [{ type: "string" }, { type: "string" }, { type: "string" }], +// }, +// ], +// [stringToHex("MyNFT", { size: 14 }), ["No Valuable Token", "NVT", "http://www.example.com/base/uri/goes/here"]], +// ); +// export default defineWorld({ tables: { Number: { @@ -95,35 +95,35 @@ export default defineWorld({ "@latticexyz/world-modules/out/Unstable_CallWithSignatureModule.sol/Unstable_CallWithSignatureModule.json", root: true, }, - { - artifactPath: "@latticexyz/world-modules/out/PuppetModule.sol/PuppetModule.json", - root: false, - args: [], - }, - { - artifactPath: "@latticexyz/world-modules/out/ERC20Module.sol/ERC20Module.json", - root: false, - args: [ - { - type: "bytes", - value: erc20ModuleArgs, - }, - ], - }, - { - artifactPath: "@latticexyz/world-modules/out/ERC721Module.sol/ERC721Module.json", - root: false, - args: [ - { - type: "bytes", - value: erc721ModuleArgs, - }, - ], - }, - defineERC20Config({ - namespace: "erc20Namespace", - name: "MyToken", - symbol: "MTK", - }), + // { + // artifactPath: "@latticexyz/world-modules/out/PuppetModule.sol/PuppetModule.json", + // root: false, + // args: [], + // }, + // { + // artifactPath: "@latticexyz/world-modules/out/ERC20Module.sol/ERC20Module.json", + // root: false, + // args: [ + // { + // type: "bytes", + // value: erc20ModuleArgs, + // }, + // ], + // }, + // { + // artifactPath: "@latticexyz/world-modules/out/ERC721Module.sol/ERC721Module.json", + // root: false, + // args: [ + // { + // type: "bytes", + // value: erc721ModuleArgs, + // }, + // ], + // }, + // defineERC20Config({ + // namespace: "erc20Namespace", + // name: "MyToken", + // symbol: "MTK", + // }), ], }); From 6e2369d6fe5d4cb42cb94b4ad286a67547ab9002 Mon Sep 17 00:00:00 2001 From: Vicente Dragicevic Date: Tue, 22 Oct 2024 11:21:43 -0300 Subject: [PATCH 12/25] Add e2e module test package --- e2e/packages/contracts/mud.config.ts | 56 +---------------- e2e/packages/contracts/package.json | 2 - e2e/packages/module-test/.gitignore | 9 +++ e2e/packages/module-test/foundry.toml | 21 +++++++ e2e/packages/module-test/mud.config.ts | 60 +++++++++++++++++++ e2e/packages/module-test/package.json | 24 ++++++++ e2e/packages/module-test/remappings.txt | 3 + .../module-test/src/codegen/world/IWorld.sol | 15 +++++ e2e/packages/module-test/test/Modules.t.sol | 19 ++++++ e2e/pnpm-lock.yaml | 39 ++++++++++-- 10 files changed, 185 insertions(+), 63 deletions(-) create mode 100644 e2e/packages/module-test/.gitignore create mode 100644 e2e/packages/module-test/foundry.toml create mode 100644 e2e/packages/module-test/mud.config.ts create mode 100644 e2e/packages/module-test/package.json create mode 100644 e2e/packages/module-test/remappings.txt create mode 100644 e2e/packages/module-test/src/codegen/world/IWorld.sol create mode 100644 e2e/packages/module-test/test/Modules.t.sol diff --git a/e2e/packages/contracts/mud.config.ts b/e2e/packages/contracts/mud.config.ts index 990059a680..db69f40144 100644 --- a/e2e/packages/contracts/mud.config.ts +++ b/e2e/packages/contracts/mud.config.ts @@ -1,29 +1,5 @@ import { defineWorld } from "@latticexyz/world"; -// import { defineERC20Config } from "@latticexyz/world-module-erc20"; -// import { encodeAbiParameters, stringToHex } from "viem"; -// -// const erc20ModuleArgs = encodeAbiParameters( -// [ -// { type: "bytes14" }, -// { -// type: "tuple", -// components: [{ type: "uint8" }, { type: "string" }, { type: "string" }], -// }, -// ], -// [stringToHex("MyToken", { size: 14 }), [18, "Worthless Token", "WT"]], -// ); -// -// const erc721ModuleArgs = encodeAbiParameters( -// [ -// { type: "bytes14" }, -// { -// type: "tuple", -// components: [{ type: "string" }, { type: "string" }, { type: "string" }], -// }, -// ], -// [stringToHex("MyNFT", { size: 14 }), ["No Valuable Token", "NVT", "http://www.example.com/base/uri/goes/here"]], -// ); -// + export default defineWorld({ tables: { Number: { @@ -95,35 +71,5 @@ export default defineWorld({ "@latticexyz/world-modules/out/Unstable_CallWithSignatureModule.sol/Unstable_CallWithSignatureModule.json", root: true, }, - // { - // artifactPath: "@latticexyz/world-modules/out/PuppetModule.sol/PuppetModule.json", - // root: false, - // args: [], - // }, - // { - // artifactPath: "@latticexyz/world-modules/out/ERC20Module.sol/ERC20Module.json", - // root: false, - // args: [ - // { - // type: "bytes", - // value: erc20ModuleArgs, - // }, - // ], - // }, - // { - // artifactPath: "@latticexyz/world-modules/out/ERC721Module.sol/ERC721Module.json", - // root: false, - // args: [ - // { - // type: "bytes", - // value: erc721ModuleArgs, - // }, - // ], - // }, - // defineERC20Config({ - // namespace: "erc20Namespace", - // name: "MyToken", - // symbol: "MTK", - // }), ], }); diff --git a/e2e/packages/contracts/package.json b/e2e/packages/contracts/package.json index ca08068992..58ec1e8474 100644 --- a/e2e/packages/contracts/package.json +++ b/e2e/packages/contracts/package.json @@ -16,8 +16,6 @@ "@latticexyz/schema-type": "link:../../../packages/schema-type", "@latticexyz/store": "link:../../../packages/store", "@latticexyz/world": "link:../../../packages/world", - "@latticexyz/world-module-erc20": "link:../../../packages/world-module-erc20", - "@latticexyz/world-modules": "link:../../../packages/world-modules", "dotenv": "^16.0.3", "ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0", "forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1", diff --git a/e2e/packages/module-test/.gitignore b/e2e/packages/module-test/.gitignore new file mode 100644 index 0000000000..d2b0438d96 --- /dev/null +++ b/e2e/packages/module-test/.gitignore @@ -0,0 +1,9 @@ +out/ +cache/ +node_modules/ +bindings/ +artifacts/ +broadcast/ + +# Ignore all deploy artifacts +deploys/**/*.json diff --git a/e2e/packages/module-test/foundry.toml b/e2e/packages/module-test/foundry.toml new file mode 100644 index 0000000000..6ecb883f45 --- /dev/null +++ b/e2e/packages/module-test/foundry.toml @@ -0,0 +1,21 @@ +[profile.default] +solc = "0.8.24" +ffi = false +fuzz_runs = 256 +optimizer = true +optimizer_runs = 3000 +verbosity = 2 +src = "src" +test = "test" +out = "out" +allow_paths = [ + # pnpm symlinks to the project root's node_modules + "../../node_modules", + # we're also using linked mud packages from the monorepo + "../../../packages" +] +extra_output_files = [ + "abi", + "evm.bytecode" +] +fs_permissions = [{ access = "read", path = "./"}] diff --git a/e2e/packages/module-test/mud.config.ts b/e2e/packages/module-test/mud.config.ts new file mode 100644 index 0000000000..ab3f67c630 --- /dev/null +++ b/e2e/packages/module-test/mud.config.ts @@ -0,0 +1,60 @@ +import { defineWorld } from "@latticexyz/world"; +import { encodeAbiParameters, stringToHex } from "viem"; +import { defineERC20Config } from "@latticexyz/world-module-erc20"; + +const erc20ModuleArgs = encodeAbiParameters( + [ + { type: "bytes14" }, + { + type: "tuple", + components: [{ type: "uint8" }, { type: "string" }, { type: "string" }], + }, + ], + [stringToHex("MyToken", { size: 14 }), [18, "Worthless Token", "WT"]], +); + +const erc721ModuleArgs = encodeAbiParameters( + [ + { type: "bytes14" }, + { + type: "tuple", + components: [{ type: "string" }, { type: "string" }, { type: "string" }], + }, + ], + [stringToHex("MyNFT", { size: 14 }), ["No Valuable Token", "NVT", "http://www.example.com/base/uri/goes/here"]], +); + +export default defineWorld({ + modules: [ + { + artifactPath: "@latticexyz/world-modules/out/PuppetModule.sol/PuppetModule.json", + root: false, + args: [], + }, + { + artifactPath: "@latticexyz/world-modules/out/ERC20Module.sol/ERC20Module.json", + root: false, + args: [ + { + type: "bytes", + value: erc20ModuleArgs, + }, + ], + }, + { + artifactPath: "@latticexyz/world-modules/out/ERC721Module.sol/ERC721Module.json", + root: false, + args: [ + { + type: "bytes", + value: erc721ModuleArgs, + }, + ], + }, + defineERC20Config({ + namespace: "erc20Namespace", + name: "MyToken", + symbol: "MTK", + }), + ], +}); diff --git a/e2e/packages/module-test/package.json b/e2e/packages/module-test/package.json new file mode 100644 index 0000000000..0909408211 --- /dev/null +++ b/e2e/packages/module-test/package.json @@ -0,0 +1,24 @@ +{ + "name": "module-test", + "version": "0.0.0", + "private": true, + "license": "MIT", + "scripts": { + "build": "mud build", + "clean": "forge clean && shx rm -rf src/**/codegen", + "test": "mud test", + "test:ci": "pnpm run test" + }, + "devDependencies": { + "@latticexyz/cli": "link:../../../packages/cli", + "@latticexyz/store": "link:../../../packages/store", + "@latticexyz/world": "link:../../../packages/world", + "@latticexyz/world-module-erc20": "link:../../../packages/world-module-erc20", + "@latticexyz/world-modules": "link:../../../packages/world-modules", + "dotenv": "^16.0.3", + "ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0", + "forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1", + "prettier": "3.2.5", + "typescript": "5.4.2" + } +} diff --git a/e2e/packages/module-test/remappings.txt b/e2e/packages/module-test/remappings.txt new file mode 100644 index 0000000000..c4d992480e --- /dev/null +++ b/e2e/packages/module-test/remappings.txt @@ -0,0 +1,3 @@ +ds-test/=node_modules/ds-test/src/ +forge-std/=node_modules/forge-std/src/ +@latticexyz/=node_modules/@latticexyz/ diff --git a/e2e/packages/module-test/src/codegen/world/IWorld.sol b/e2e/packages/module-test/src/codegen/world/IWorld.sol new file mode 100644 index 0000000000..4761e84790 --- /dev/null +++ b/e2e/packages/module-test/src/codegen/world/IWorld.sol @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.24; + +/* Autogenerated file. Do not edit manually. */ + +import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.sol"; + +/** + * @title IWorld + * @author MUD (https://mud.dev) by Lattice (https://lattice.xyz) + * @notice This interface integrates all systems and associated function selectors + * that are dynamically registered in the World during deployment. + * @dev This is an autogenerated file; do not edit manually. + */ +interface IWorld is IBaseWorld {} diff --git a/e2e/packages/module-test/test/Modules.t.sol b/e2e/packages/module-test/test/Modules.t.sol new file mode 100644 index 0000000000..a6ce2c7560 --- /dev/null +++ b/e2e/packages/module-test/test/Modules.t.sol @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.24; +import { ResourceIds } from "@latticexyz/store/src/codegen/index.sol"; + +import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.sol"; +import { ResourceId, WorldResourceIdLib } from "@latticexyz/world/src/WorldResourceId.sol"; +import { MudTest } from "@latticexyz/world/test/MudTest.t.sol"; + +contract ModulesTest is MudTest { + function testModulesInstalled() public { + ResourceId erc20PuppetNamespaceId = WorldResourceIdLib.encodeNamespace("MyToken"); + ResourceId erc721PuppetNamespaceId = WorldResourceIdLib.encodeNamespace("MyNFT"); + ResourceId erc20NamespaceId = WorldResourceIdLib.encodeNamespace("erc20Namespace"); + + assertTrue(ResourceIds.getExists(erc20PuppetNamespaceId)); + assertTrue(ResourceIds.getExists(erc721PuppetNamespaceId)); + assertTrue(ResourceIds.getExists(erc20NamespaceId)); + } +} diff --git a/e2e/pnpm-lock.yaml b/e2e/pnpm-lock.yaml index ed033d6956..b309f1e7a4 100644 --- a/e2e/pnpm-lock.yaml +++ b/e2e/pnpm-lock.yaml @@ -96,12 +96,6 @@ importers: '@latticexyz/world': specifier: link:../../../packages/world version: link:../../../packages/world - '@latticexyz/world-module-erc20': - specifier: link:../../../packages/world-module-erc20 - version: link:../../../packages/world-module-erc20 - '@latticexyz/world-modules': - specifier: link:../../../packages/world-modules - version: link:../../../packages/world-modules dotenv: specifier: ^16.0.3 version: 16.0.3 @@ -124,6 +118,39 @@ importers: specifier: 0.34.6 version: 0.34.6(happy-dom@12.10.3) + packages/module-test: + devDependencies: + '@latticexyz/cli': + specifier: link:../../../packages/cli + version: link:../../../packages/cli + '@latticexyz/store': + specifier: link:../../../packages/store + version: link:../../../packages/store + '@latticexyz/world': + specifier: link:../../../packages/world + version: link:../../../packages/world + '@latticexyz/world-module-erc20': + specifier: link:../../../packages/world-module-erc20 + version: link:../../../packages/world-module-erc20 + '@latticexyz/world-modules': + specifier: link:../../../packages/world-modules + version: link:../../../packages/world-modules + dotenv: + specifier: ^16.0.3 + version: 16.0.3 + ds-test: + specifier: https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0 + version: https://codeload.github.com/dapphub/ds-test/tar.gz/e282159d5170298eb2455a6c05280ab5a73a4ef0 + forge-std: + specifier: https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1 + version: https://codeload.github.com/foundry-rs/forge-std/tar.gz/74cfb77e308dd188d2f58864aaf44963ae6b88b1 + prettier: + specifier: 3.2.5 + version: 3.2.5 + typescript: + specifier: 5.4.2 + version: 5.4.2 + packages/sync-test: devDependencies: '@latticexyz/cli': From c912ceff67c5c2db20f3a6bc91dfac1089f4845b Mon Sep 17 00:00:00 2001 From: Vicente Dragicevic Date: Tue, 22 Oct 2024 11:30:01 -0300 Subject: [PATCH 13/25] Remove erc20 module from store-sync deps --- packages/store-sync/package.json | 1 - pnpm-lock.yaml | 3 --- 2 files changed, 4 deletions(-) diff --git a/packages/store-sync/package.json b/packages/store-sync/package.json index 9d3799930c..44d4c8647c 100644 --- a/packages/store-sync/package.json +++ b/packages/store-sync/package.json @@ -92,7 +92,6 @@ "zustand": "^4.3.7" }, "devDependencies": { - "@latticexyz/world-module-erc20": "workspace:*", "@types/debug": "^4.1.7", "@types/node": "20.12.12", "@types/sql.js": "^1.4.4", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2305631796..7c622f31c2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1185,9 +1185,6 @@ importers: specifier: ^4.3.7 version: 4.3.7(react@18.2.0) devDependencies: - '@latticexyz/world-module-erc20': - specifier: workspace:* - version: link:../world-module-erc20 '@types/debug': specifier: ^4.1.7 version: 4.1.7 From 1545b94a32b2459bfe53ab0195cae8a1293f5568 Mon Sep 17 00:00:00 2001 From: Vicente Dragicevic Date: Tue, 22 Oct 2024 11:32:24 -0300 Subject: [PATCH 14/25] Add missing dep to module-test --- e2e/packages/module-test/package.json | 1 + e2e/pnpm-lock.yaml | 3 +++ 2 files changed, 4 insertions(+) diff --git a/e2e/packages/module-test/package.json b/e2e/packages/module-test/package.json index 0909408211..59e7722f45 100644 --- a/e2e/packages/module-test/package.json +++ b/e2e/packages/module-test/package.json @@ -11,6 +11,7 @@ }, "devDependencies": { "@latticexyz/cli": "link:../../../packages/cli", + "@latticexyz/schema-type": "link:../../../packages/schema-type", "@latticexyz/store": "link:../../../packages/store", "@latticexyz/world": "link:../../../packages/world", "@latticexyz/world-module-erc20": "link:../../../packages/world-module-erc20", diff --git a/e2e/pnpm-lock.yaml b/e2e/pnpm-lock.yaml index b309f1e7a4..48f0bd3655 100644 --- a/e2e/pnpm-lock.yaml +++ b/e2e/pnpm-lock.yaml @@ -123,6 +123,9 @@ importers: '@latticexyz/cli': specifier: link:../../../packages/cli version: link:../../../packages/cli + '@latticexyz/schema-type': + specifier: link:../../../packages/schema-type + version: link:../../../packages/schema-type '@latticexyz/store': specifier: link:../../../packages/store version: link:../../../packages/store From 348287af119452d1882407d4826ac22d36202c98 Mon Sep 17 00:00:00 2001 From: Vicente Dragicevic Date: Tue, 22 Oct 2024 11:40:57 -0300 Subject: [PATCH 15/25] Change anvil port so it doesn't conflict with contracts package tests --- e2e/packages/module-test/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/packages/module-test/package.json b/e2e/packages/module-test/package.json index 59e7722f45..5768d37df7 100644 --- a/e2e/packages/module-test/package.json +++ b/e2e/packages/module-test/package.json @@ -6,7 +6,7 @@ "scripts": { "build": "mud build", "clean": "forge clean && shx rm -rf src/**/codegen", - "test": "mud test", + "test": "mud test --port 4243", "test:ci": "pnpm run test" }, "devDependencies": { From 19011d722926a448a00ac459e62a35851b10897c Mon Sep 17 00:00:00 2001 From: Vicente Dragicevic Date: Tue, 22 Oct 2024 11:51:34 -0300 Subject: [PATCH 16/25] Add back missing dep to e2e contracts package --- e2e/packages/contracts/package.json | 1 + e2e/pnpm-lock.yaml | 3 +++ 2 files changed, 4 insertions(+) diff --git a/e2e/packages/contracts/package.json b/e2e/packages/contracts/package.json index 58ec1e8474..6863f55a98 100644 --- a/e2e/packages/contracts/package.json +++ b/e2e/packages/contracts/package.json @@ -16,6 +16,7 @@ "@latticexyz/schema-type": "link:../../../packages/schema-type", "@latticexyz/store": "link:../../../packages/store", "@latticexyz/world": "link:../../../packages/world", + "@latticexyz/world-modules": "link:../../../packages/world-modules", "dotenv": "^16.0.3", "ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0", "forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1", diff --git a/e2e/pnpm-lock.yaml b/e2e/pnpm-lock.yaml index 48f0bd3655..492d29a78b 100644 --- a/e2e/pnpm-lock.yaml +++ b/e2e/pnpm-lock.yaml @@ -96,6 +96,9 @@ importers: '@latticexyz/world': specifier: link:../../../packages/world version: link:../../../packages/world + '@latticexyz/world-modules': + specifier: link:../../../packages/world-modules + version: link:../../../packages/world-modules dotenv: specifier: ^16.0.3 version: 16.0.3 From 7c781b9b7d97399dd32deea6a836d8c8556b0d4b Mon Sep 17 00:00:00 2001 From: Vicente Dragicevic Date: Tue, 22 Oct 2024 14:00:36 -0300 Subject: [PATCH 17/25] Move puppet modules test to main test directory, and turn it into a package --- e2e/packages/contracts/worlds.json | 4 +- e2e/packages/module-test/.gitignore | 9 --- e2e/packages/module-test/foundry.toml | 21 ------- e2e/packages/module-test/mud.config.ts | 60 ------------------- e2e/packages/module-test/package.json | 25 -------- e2e/packages/module-test/remappings.txt | 3 - .../module-test/src/codegen/world/IWorld.sol | 15 ----- e2e/packages/module-test/test/Modules.t.sol | 19 ------ e2e/pnpm-lock.yaml | 36 ----------- 9 files changed, 2 insertions(+), 190 deletions(-) delete mode 100644 e2e/packages/module-test/.gitignore delete mode 100644 e2e/packages/module-test/foundry.toml delete mode 100644 e2e/packages/module-test/mud.config.ts delete mode 100644 e2e/packages/module-test/package.json delete mode 100644 e2e/packages/module-test/remappings.txt delete mode 100644 e2e/packages/module-test/src/codegen/world/IWorld.sol delete mode 100644 e2e/packages/module-test/test/Modules.t.sol diff --git a/e2e/packages/contracts/worlds.json b/e2e/packages/contracts/worlds.json index 4848458434..fd5f58e5e9 100644 --- a/e2e/packages/contracts/worlds.json +++ b/e2e/packages/contracts/worlds.json @@ -1,5 +1,5 @@ { "31337": { - "address": "0xcbf80e1b5bafec05410e47033d74c6ec4479d385" + "address": "0x7de562d80d6c8672aa32654af67884f411976593" } -} \ No newline at end of file +} diff --git a/e2e/packages/module-test/.gitignore b/e2e/packages/module-test/.gitignore deleted file mode 100644 index d2b0438d96..0000000000 --- a/e2e/packages/module-test/.gitignore +++ /dev/null @@ -1,9 +0,0 @@ -out/ -cache/ -node_modules/ -bindings/ -artifacts/ -broadcast/ - -# Ignore all deploy artifacts -deploys/**/*.json diff --git a/e2e/packages/module-test/foundry.toml b/e2e/packages/module-test/foundry.toml deleted file mode 100644 index 6ecb883f45..0000000000 --- a/e2e/packages/module-test/foundry.toml +++ /dev/null @@ -1,21 +0,0 @@ -[profile.default] -solc = "0.8.24" -ffi = false -fuzz_runs = 256 -optimizer = true -optimizer_runs = 3000 -verbosity = 2 -src = "src" -test = "test" -out = "out" -allow_paths = [ - # pnpm symlinks to the project root's node_modules - "../../node_modules", - # we're also using linked mud packages from the monorepo - "../../../packages" -] -extra_output_files = [ - "abi", - "evm.bytecode" -] -fs_permissions = [{ access = "read", path = "./"}] diff --git a/e2e/packages/module-test/mud.config.ts b/e2e/packages/module-test/mud.config.ts deleted file mode 100644 index ab3f67c630..0000000000 --- a/e2e/packages/module-test/mud.config.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { defineWorld } from "@latticexyz/world"; -import { encodeAbiParameters, stringToHex } from "viem"; -import { defineERC20Config } from "@latticexyz/world-module-erc20"; - -const erc20ModuleArgs = encodeAbiParameters( - [ - { type: "bytes14" }, - { - type: "tuple", - components: [{ type: "uint8" }, { type: "string" }, { type: "string" }], - }, - ], - [stringToHex("MyToken", { size: 14 }), [18, "Worthless Token", "WT"]], -); - -const erc721ModuleArgs = encodeAbiParameters( - [ - { type: "bytes14" }, - { - type: "tuple", - components: [{ type: "string" }, { type: "string" }, { type: "string" }], - }, - ], - [stringToHex("MyNFT", { size: 14 }), ["No Valuable Token", "NVT", "http://www.example.com/base/uri/goes/here"]], -); - -export default defineWorld({ - modules: [ - { - artifactPath: "@latticexyz/world-modules/out/PuppetModule.sol/PuppetModule.json", - root: false, - args: [], - }, - { - artifactPath: "@latticexyz/world-modules/out/ERC20Module.sol/ERC20Module.json", - root: false, - args: [ - { - type: "bytes", - value: erc20ModuleArgs, - }, - ], - }, - { - artifactPath: "@latticexyz/world-modules/out/ERC721Module.sol/ERC721Module.json", - root: false, - args: [ - { - type: "bytes", - value: erc721ModuleArgs, - }, - ], - }, - defineERC20Config({ - namespace: "erc20Namespace", - name: "MyToken", - symbol: "MTK", - }), - ], -}); diff --git a/e2e/packages/module-test/package.json b/e2e/packages/module-test/package.json deleted file mode 100644 index 5768d37df7..0000000000 --- a/e2e/packages/module-test/package.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "name": "module-test", - "version": "0.0.0", - "private": true, - "license": "MIT", - "scripts": { - "build": "mud build", - "clean": "forge clean && shx rm -rf src/**/codegen", - "test": "mud test --port 4243", - "test:ci": "pnpm run test" - }, - "devDependencies": { - "@latticexyz/cli": "link:../../../packages/cli", - "@latticexyz/schema-type": "link:../../../packages/schema-type", - "@latticexyz/store": "link:../../../packages/store", - "@latticexyz/world": "link:../../../packages/world", - "@latticexyz/world-module-erc20": "link:../../../packages/world-module-erc20", - "@latticexyz/world-modules": "link:../../../packages/world-modules", - "dotenv": "^16.0.3", - "ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0", - "forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1", - "prettier": "3.2.5", - "typescript": "5.4.2" - } -} diff --git a/e2e/packages/module-test/remappings.txt b/e2e/packages/module-test/remappings.txt deleted file mode 100644 index c4d992480e..0000000000 --- a/e2e/packages/module-test/remappings.txt +++ /dev/null @@ -1,3 +0,0 @@ -ds-test/=node_modules/ds-test/src/ -forge-std/=node_modules/forge-std/src/ -@latticexyz/=node_modules/@latticexyz/ diff --git a/e2e/packages/module-test/src/codegen/world/IWorld.sol b/e2e/packages/module-test/src/codegen/world/IWorld.sol deleted file mode 100644 index 4761e84790..0000000000 --- a/e2e/packages/module-test/src/codegen/world/IWorld.sol +++ /dev/null @@ -1,15 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity >=0.8.24; - -/* Autogenerated file. Do not edit manually. */ - -import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.sol"; - -/** - * @title IWorld - * @author MUD (https://mud.dev) by Lattice (https://lattice.xyz) - * @notice This interface integrates all systems and associated function selectors - * that are dynamically registered in the World during deployment. - * @dev This is an autogenerated file; do not edit manually. - */ -interface IWorld is IBaseWorld {} diff --git a/e2e/packages/module-test/test/Modules.t.sol b/e2e/packages/module-test/test/Modules.t.sol deleted file mode 100644 index a6ce2c7560..0000000000 --- a/e2e/packages/module-test/test/Modules.t.sol +++ /dev/null @@ -1,19 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity >=0.8.24; -import { ResourceIds } from "@latticexyz/store/src/codegen/index.sol"; - -import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.sol"; -import { ResourceId, WorldResourceIdLib } from "@latticexyz/world/src/WorldResourceId.sol"; -import { MudTest } from "@latticexyz/world/test/MudTest.t.sol"; - -contract ModulesTest is MudTest { - function testModulesInstalled() public { - ResourceId erc20PuppetNamespaceId = WorldResourceIdLib.encodeNamespace("MyToken"); - ResourceId erc721PuppetNamespaceId = WorldResourceIdLib.encodeNamespace("MyNFT"); - ResourceId erc20NamespaceId = WorldResourceIdLib.encodeNamespace("erc20Namespace"); - - assertTrue(ResourceIds.getExists(erc20PuppetNamespaceId)); - assertTrue(ResourceIds.getExists(erc721PuppetNamespaceId)); - assertTrue(ResourceIds.getExists(erc20NamespaceId)); - } -} diff --git a/e2e/pnpm-lock.yaml b/e2e/pnpm-lock.yaml index 492d29a78b..efc3d77c56 100644 --- a/e2e/pnpm-lock.yaml +++ b/e2e/pnpm-lock.yaml @@ -121,42 +121,6 @@ importers: specifier: 0.34.6 version: 0.34.6(happy-dom@12.10.3) - packages/module-test: - devDependencies: - '@latticexyz/cli': - specifier: link:../../../packages/cli - version: link:../../../packages/cli - '@latticexyz/schema-type': - specifier: link:../../../packages/schema-type - version: link:../../../packages/schema-type - '@latticexyz/store': - specifier: link:../../../packages/store - version: link:../../../packages/store - '@latticexyz/world': - specifier: link:../../../packages/world - version: link:../../../packages/world - '@latticexyz/world-module-erc20': - specifier: link:../../../packages/world-module-erc20 - version: link:../../../packages/world-module-erc20 - '@latticexyz/world-modules': - specifier: link:../../../packages/world-modules - version: link:../../../packages/world-modules - dotenv: - specifier: ^16.0.3 - version: 16.0.3 - ds-test: - specifier: https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0 - version: https://codeload.github.com/dapphub/ds-test/tar.gz/e282159d5170298eb2455a6c05280ab5a73a4ef0 - forge-std: - specifier: https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1 - version: https://codeload.github.com/foundry-rs/forge-std/tar.gz/74cfb77e308dd188d2f58864aaf44963ae6b88b1 - prettier: - specifier: 3.2.5 - version: 3.2.5 - typescript: - specifier: 5.4.2 - version: 5.4.2 - packages/sync-test: devDependencies: '@latticexyz/cli': From a6dde7c0dfaa8d762c70ab6df3ffeaa3a7c17fe2 Mon Sep 17 00:00:00 2001 From: Vicente Dragicevic Date: Tue, 22 Oct 2024 14:08:50 -0300 Subject: [PATCH 18/25] Revert change to worlds.json --- e2e/packages/contracts/worlds.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/packages/contracts/worlds.json b/e2e/packages/contracts/worlds.json index fd5f58e5e9..436a70cafe 100644 --- a/e2e/packages/contracts/worlds.json +++ b/e2e/packages/contracts/worlds.json @@ -2,4 +2,4 @@ "31337": { "address": "0x7de562d80d6c8672aa32654af67884f411976593" } -} +} \ No newline at end of file From f7f05c0ae5b360c3f519f750be30ff9fe54f88e9 Mon Sep 17 00:00:00 2001 From: Vicente Dragicevic Date: Tue, 22 Oct 2024 15:11:08 -0300 Subject: [PATCH 19/25] Remove puppet module test from changeset --- .changeset/gentle-carrots-kneel.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.changeset/gentle-carrots-kneel.md b/.changeset/gentle-carrots-kneel.md index 6280003cfc..47fc401e21 100644 --- a/.changeset/gentle-carrots-kneel.md +++ b/.changeset/gentle-carrots-kneel.md @@ -1,5 +1,10 @@ --- "@latticexyz/cli": patch +<<<<<<< HEAD +======= +"@latticexyz/world-module-erc20": patch +"@latticexyz/world-modules": patch +>>>>>>> f1e6e2dbd (Remove puppet module test from changeset) --- Added support for deploying public libraries used within modules. From d9ff22109e68c37b0acf828c3f20cb1b03144169 Mon Sep 17 00:00:00 2001 From: Vicente Dragicevic Date: Tue, 22 Oct 2024 17:02:27 -0300 Subject: [PATCH 20/25] Split changeset in two (one for cli and one for token modules) --- .changeset/gentle-carrots-kneel.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.changeset/gentle-carrots-kneel.md b/.changeset/gentle-carrots-kneel.md index 47fc401e21..6280003cfc 100644 --- a/.changeset/gentle-carrots-kneel.md +++ b/.changeset/gentle-carrots-kneel.md @@ -1,10 +1,5 @@ --- "@latticexyz/cli": patch -<<<<<<< HEAD -======= -"@latticexyz/world-module-erc20": patch -"@latticexyz/world-modules": patch ->>>>>>> f1e6e2dbd (Remove puppet module test from changeset) --- Added support for deploying public libraries used within modules. From 9b7233d8f57dfbe03f4f2b8a73e3e74056d812c3 Mon Sep 17 00:00:00 2001 From: Vicente Dragicevic Date: Tue, 22 Oct 2024 18:03:23 -0300 Subject: [PATCH 21/25] Refactor findLibraries to accept an array of paths --- packages/cli/src/commands/verify.ts | 3 ++- packages/cli/src/deploy/findLibraries.ts | 6 +++-- packages/cli/src/deploy/resolveConfig.ts | 31 ++++++++++++----------- packages/cli/src/utils/getContractData.ts | 13 +++++----- 4 files changed, 28 insertions(+), 25 deletions(-) diff --git a/packages/cli/src/commands/verify.ts b/packages/cli/src/commands/verify.ts index cfaa6e625c..f746930d2e 100644 --- a/packages/cli/src/commands/verify.ts +++ b/packages/cli/src/commands/verify.ts @@ -72,7 +72,8 @@ const commandModule: CommandModule = { // TODO: replace with `resolveConfig` and support for linked libs const configSystems = await resolveSystems({ rootDir, config }); const systems = configSystems.map((system) => { - const contractData = getContractData(`${system.name}.sol`, system.name, outDir); + const contractDataPath = path.join(outDir, `${system.name}.sol`, `${system.name}.json`); + const contractData = getContractData(contractDataPath); return { name: system.name, bytecode: contractData.bytecode, diff --git a/packages/cli/src/deploy/findLibraries.ts b/packages/cli/src/deploy/findLibraries.ts index 40609a0f98..dc75aae490 100644 --- a/packages/cli/src/deploy/findLibraries.ts +++ b/packages/cli/src/deploy/findLibraries.ts @@ -3,11 +3,13 @@ import { globSync } from "glob"; import { orderByDependencies } from "./orderByDependencies"; import { LinkReferences } from "../utils/findPlaceholders"; -export function findLibraries(forgeOutDir: string): readonly { +export function findLibraries(forgeOutDirs: string | string[]): readonly { readonly path: string; readonly name: string; }[] { - const artifacts = globSync(`${forgeOutDir}/**/*.json`, { ignore: "**/*.abi.json" }) + const dirs = Array.isArray(forgeOutDirs) ? forgeOutDirs : [forgeOutDirs]; + const globs = dirs.map((dir) => `${dir}/**/*.json`); + const artifacts = globSync(globs, { ignore: "**/*.abi.json" }) .sort() .map((path) => JSON.parse(readFileSync(path, "utf8"))); diff --git a/packages/cli/src/deploy/resolveConfig.ts b/packages/cli/src/deploy/resolveConfig.ts index dee1d554ef..0f6edfb5f7 100644 --- a/packages/cli/src/deploy/resolveConfig.ts +++ b/packages/cli/src/deploy/resolveConfig.ts @@ -38,21 +38,21 @@ export async function resolveConfig({ return [moduleOutDir]; }); - const libraries = [forgeOutDir, ...moduleOutDirs].flatMap((outDir) => - findLibraries(outDir).map((library): Library => { - // foundry/solc flattens artifacts, so we just use the path basename - const contractData = getContractData(path.basename(library.path), library.name, outDir); - return { - path: library.path, - name: library.name, - abi: contractData.abi, - prepareDeploy: createPrepareDeploy(contractData.bytecode, contractData.placeholders), - deployedBytecodeSize: contractData.deployedBytecodeSize, - }; - }), - ); + // TODO: we can even make findLibraries return Library directly, not sure why this step was needed. + const libraries = findLibraries([forgeOutDir, ...moduleOutDirs]).map((library): Library => { + // foundry/solc flattens artifacts, so we just use the path basename + const contractData = getContractData(library.path); + return { + path: library.path, + name: library.name, + abi: contractData.abi, + prepareDeploy: createPrepareDeploy(contractData.bytecode, contractData.placeholders), + deployedBytecodeSize: contractData.deployedBytecodeSize, + }; + }); - const baseSystemContractData = getContractData("System.sol", "System", forgeOutDir); + const baseSystemPath = path.join(forgeOutDir, "System.sol", "System.json"); + const baseSystemContractData = getContractData(baseSystemPath); const baseSystemFunctions = baseSystemContractData.abi .filter((item): item is typeof item & { type: "function" } => item.type === "function") .map(toFunctionSignature); @@ -70,7 +70,8 @@ export async function resolveConfig({ ); } - const contractData = getContractData(`${system.label}.sol`, system.label, forgeOutDir); + const contractDataPath = path.join(forgeOutDir, `${system.label}.sol`, `${system.label}.json`); + const contractData = getContractData(contractDataPath); // 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 0681a6e5bd..b413e29556 100644 --- a/packages/cli/src/utils/getContractData.ts +++ b/packages/cli/src/utils/getContractData.ts @@ -1,5 +1,4 @@ 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"; @@ -9,14 +8,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( - filename: string, - contractName: string, - forgeOutDirectory: string, -): { bytecode: Hex; placeholders: readonly LibraryPlaceholder[]; abi: Abi; deployedBytecodeSize: number } { +export function getContractData(contractDataPath: 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) { From e2bcd67871af98f4703c153fef0f66de52901285 Mon Sep 17 00:00:00 2001 From: Vicente Dragicevic Date: Tue, 22 Oct 2024 18:53:44 -0300 Subject: [PATCH 22/25] Return Library[] from findLibraries --- packages/cli/src/deploy/findLibraries.ts | 39 ++++++++++++++++++------ packages/cli/src/deploy/resolveConfig.ts | 13 +------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/packages/cli/src/deploy/findLibraries.ts b/packages/cli/src/deploy/findLibraries.ts index dc75aae490..1a1ee5d5a7 100644 --- a/packages/cli/src/deploy/findLibraries.ts +++ b/packages/cli/src/deploy/findLibraries.ts @@ -2,18 +2,24 @@ import { readFileSync } from "fs"; import { globSync } from "glob"; import { orderByDependencies } from "./orderByDependencies"; import { LinkReferences } from "../utils/findPlaceholders"; +import { Library } from "./common"; +import { getContractData } from "../utils/getContractData"; +import { createPrepareDeploy } from "./createPrepareDeploy"; +import path from "path"; -export function findLibraries(forgeOutDirs: string | string[]): readonly { - readonly path: string; - readonly name: string; -}[] { +export function findLibraries(forgeOutDirs: string | string[]): Library[] { const dirs = Array.isArray(forgeOutDirs) ? forgeOutDirs : [forgeOutDirs]; - const globs = dirs.map((dir) => `${dir}/**/*.json`); - const artifacts = globSync(globs, { ignore: "**/*.abi.json" }) - .sort() - .map((path) => JSON.parse(readFileSync(path, "utf8"))); - const libraries = artifacts.flatMap((artifact) => { + // Deduplicate output directories and get all the artifacts + const artifactsWithDirs = [...new Set(dirs)].flatMap((dir) => { + const files = globSync(`${dir}/**/*.json`, { ignore: "/**/*.abi.json" }).sort(); + return files.map((filePath) => ({ + forgeOutDir: dir, + artifact: JSON.parse(readFileSync(filePath, "utf8")), + })); + }); + + const libraries = artifactsWithDirs.flatMap(({ artifact, forgeOutDir }) => { if (!artifact.metadata) return []; const contractPath = Object.keys(artifact.metadata.settings.compilationTarget)[0]; @@ -26,13 +32,26 @@ export function findLibraries(forgeOutDirs: string | string[]): readonly { name: libraryName, dependentPath: contractPath, dependentName: contractName, + forgeOutDir, })), ); }); - return orderByDependencies( + const orderedByDeps = orderByDependencies( libraries, (lib) => `${lib.path}:${lib.name}`, (lib) => [`${lib.dependentPath}:${lib.dependentName}`], ); + + return orderedByDeps.map((library) => { + const contractDataPath = path.join(library.forgeOutDir, path.basename(library.path), `${library.name}.json`); + const contractData = getContractData(contractDataPath); + return { + path: library.path, + name: library.name, + abi: contractData.abi, + prepareDeploy: createPrepareDeploy(contractData.bytecode, contractData.placeholders), + deployedBytecodeSize: contractData.deployedBytecodeSize, + }; + }); } diff --git a/packages/cli/src/deploy/resolveConfig.ts b/packages/cli/src/deploy/resolveConfig.ts index 0f6edfb5f7..51b99c9e31 100644 --- a/packages/cli/src/deploy/resolveConfig.ts +++ b/packages/cli/src/deploy/resolveConfig.ts @@ -38,18 +38,7 @@ export async function resolveConfig({ return [moduleOutDir]; }); - // TODO: we can even make findLibraries return Library directly, not sure why this step was needed. - const libraries = findLibraries([forgeOutDir, ...moduleOutDirs]).map((library): Library => { - // foundry/solc flattens artifacts, so we just use the path basename - const contractData = getContractData(library.path); - return { - path: library.path, - name: library.name, - abi: contractData.abi, - prepareDeploy: createPrepareDeploy(contractData.bytecode, contractData.placeholders), - deployedBytecodeSize: contractData.deployedBytecodeSize, - }; - }); + const libraries = findLibraries([forgeOutDir, ...moduleOutDirs]); const baseSystemPath = path.join(forgeOutDir, "System.sol", "System.json"); const baseSystemContractData = getContractData(baseSystemPath); From ebe292a3f3c367418b1e0358aa26141606c2dfcd Mon Sep 17 00:00:00 2001 From: Vicente Dragicevic Date: Tue, 22 Oct 2024 19:00:31 -0300 Subject: [PATCH 23/25] 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) { From 5d4f83f9359d3becc43b0e7170b2c7c2dcce9b95 Mon Sep 17 00:00:00 2001 From: Vicente Dragicevic Date: Tue, 22 Oct 2024 19:14:59 -0300 Subject: [PATCH 24/25] Only deduplicate output dirs if input is an array --- packages/cli/src/deploy/findLibraries.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/deploy/findLibraries.ts b/packages/cli/src/deploy/findLibraries.ts index 739fbeb2b8..af8c53312f 100644 --- a/packages/cli/src/deploy/findLibraries.ts +++ b/packages/cli/src/deploy/findLibraries.ts @@ -8,10 +8,10 @@ import { createPrepareDeploy } from "./createPrepareDeploy"; import path from "path"; export function findLibraries(forgeOutDirs: string | string[]): Library[] { - const dirs = Array.isArray(forgeOutDirs) ? forgeOutDirs : [forgeOutDirs]; + const dirs = Array.isArray(forgeOutDirs) ? [...new Set(forgeOutDirs)] : [forgeOutDirs]; // Deduplicate output directories and get all the artifacts - const artifactsWithDirs = [...new Set(dirs)].flatMap((dir) => { + const artifactsWithDirs = dirs.flatMap((dir) => { const files = globSync(`${dir}/**/*.json`, { ignore: "/**/*.abi.json" }).sort(); return files.map((filePath) => ({ forgeOutDir: dir, From 48591d07c172d456d944e7b6949e6d26cd7d5e8d Mon Sep 17 00:00:00 2001 From: V Date: Thu, 24 Oct 2024 20:27:47 -0300 Subject: [PATCH 25/25] Create dull-spiders-hear.md --- .changeset/dull-spiders-hear.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/dull-spiders-hear.md diff --git a/.changeset/dull-spiders-hear.md b/.changeset/dull-spiders-hear.md new file mode 100644 index 0000000000..a93a161f6f --- /dev/null +++ b/.changeset/dull-spiders-hear.md @@ -0,0 +1,5 @@ +--- +"@latticexyz/cli": patch +--- + +Refactored findLibraries to accept an array of paths.