From 0855738a9eb05cf4023f2f51058733533ae79fa2 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Fri, 12 Jul 2024 14:41:28 +0100 Subject: [PATCH 01/25] move tablegen off of old config --- .../render-solidity/renderEnums.test.ts | 25 +++++++++++++++ .../codegen/render-solidity/renderEnums.ts | 31 ++++++++++--------- packages/store/test/codegen/common.sol | 1 + .../store/ts/codegen/renderTypesFromConfig.ts | 11 ++----- packages/store/ts/codegen/tablegen.ts | 13 +++++--- 5 files changed, 54 insertions(+), 27 deletions(-) create mode 100644 packages/common/src/codegen/render-solidity/renderEnums.test.ts diff --git a/packages/common/src/codegen/render-solidity/renderEnums.test.ts b/packages/common/src/codegen/render-solidity/renderEnums.test.ts new file mode 100644 index 0000000000..e9a41c4472 --- /dev/null +++ b/packages/common/src/codegen/render-solidity/renderEnums.test.ts @@ -0,0 +1,25 @@ +import { describe, expect, it } from "vitest"; +import { renderEnums } from "./renderEnums"; + +describe("renderEnums", () => { + it("renders a Solidity file with enums", () => { + expect( + renderEnums({ + Direction: ["left", "up", "right", "down"], + }), + ).toMatchInlineSnapshot(` + " + // SPDX-License-Identifier: MIT + pragma solidity >=0.8.24; + + /* Autogenerated file. Do not edit manually. */ + + + enum Direction { + left, up, right, down + } + + " + `); + }); +}); diff --git a/packages/common/src/codegen/render-solidity/renderEnums.ts b/packages/common/src/codegen/render-solidity/renderEnums.ts index 74d456d81a..6eec0df37c 100644 --- a/packages/common/src/codegen/render-solidity/renderEnums.ts +++ b/packages/common/src/codegen/render-solidity/renderEnums.ts @@ -1,20 +1,23 @@ -import { renderArguments, renderList, renderedSolidityHeader } from "./common"; -import { RenderEnum } from "./types"; +import { renderedSolidityHeader } from "./common"; + +// importing this from config or store would be a cyclic dependency :( +type Enums = { + readonly [name: string]: readonly [string, ...string[]]; +}; /** * Render a list of enum data as solidity enum definitions */ -export function renderEnums(enums: RenderEnum[]): string { - let result = renderedSolidityHeader; - - result += renderList( - enums, - ({ name, memberNames }) => ` - enum ${name} { - ${renderArguments(memberNames)} - } - `, - ); +export function renderEnums(enums: Enums): string { + return ` + ${renderedSolidityHeader} - return result; + ${Object.entries(enums).map( + ([name, values]) => ` + enum ${name} { + ${values.join(", ")} + } + `, + )} + `; } diff --git a/packages/store/test/codegen/common.sol b/packages/store/test/codegen/common.sol index 88e23a3c6d..3479f63bab 100644 --- a/packages/store/test/codegen/common.sol +++ b/packages/store/test/codegen/common.sol @@ -2,6 +2,7 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ + enum ExampleEnum { None, First, diff --git a/packages/store/ts/codegen/renderTypesFromConfig.ts b/packages/store/ts/codegen/renderTypesFromConfig.ts index 94d660a5ab..982ce0f1e5 100644 --- a/packages/store/ts/codegen/renderTypesFromConfig.ts +++ b/packages/store/ts/codegen/renderTypesFromConfig.ts @@ -1,14 +1,9 @@ import { renderEnums } from "@latticexyz/common/codegen"; -import { StoreConfig } from "../config"; +import { Store } from "../config/v2"; /** * Renders Solidity code for enums defined in the provided config */ -export function renderTypesFromConfig(config: StoreConfig) { - const enums = Object.keys(config.enums).map((name) => ({ - name, - memberNames: config.enums[name], - })); - - return renderEnums(enums); +export function renderTypesFromConfig(config: Store) { + return renderEnums(config.enums); } diff --git a/packages/store/ts/codegen/tablegen.ts b/packages/store/ts/codegen/tablegen.ts index fe547032c3..bcce73ab7d 100644 --- a/packages/store/ts/codegen/tablegen.ts +++ b/packages/store/ts/codegen/tablegen.ts @@ -6,7 +6,7 @@ import { renderTypesFromConfig } from "./renderTypesFromConfig"; import { renderTableIndex } from "./renderTableIndex"; import { rm } from "fs/promises"; import { Store as StoreConfig } from "../config/v2/output"; -import { storeToV1 } from "../config/v2/compat"; +import { mapObject } from "@latticexyz/common/utils"; export type TablegenOptions = { /** @@ -19,8 +19,11 @@ export type TablegenOptions = { export async function tablegen({ rootDir, config, remappings }: TablegenOptions) { const outputDirectory = path.join(rootDir, config.sourceDirectory, config.codegen.outputDirectory); - const configV1 = storeToV1(config); - const solidityUserTypes = loadAndExtractUserTypes(configV1.userTypes, outputDirectory, remappings); + const solidityUserTypes = loadAndExtractUserTypes( + mapObject(config.userTypes, (type) => ({ ...type, internalType: type.type })), + outputDirectory, + remappings, + ); const allTableOptions = getTableOptions(config, solidityUserTypes); const uniqueTableDirectories = Array.from(new Set(allTableOptions.map(({ outputPath }) => path.dirname(outputPath)))); @@ -47,9 +50,9 @@ export async function tablegen({ rootDir, config, remappings }: TablegenOptions) } // write types to file - if (Object.keys(configV1.enums).length > 0) { + if (Object.keys(config.enums).length > 0) { const fullOutputPath = path.join(outputDirectory, config.codegen.userTypesFilename); - const output = renderTypesFromConfig(configV1); + const output = renderTypesFromConfig(config); await formatAndWriteSolidity(output, fullOutputPath, "Generated types file"); } } From 59cede998d03260468b4f6dd3acb8ca311d61e43 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Fri, 12 Jul 2024 14:54:44 +0100 Subject: [PATCH 02/25] remove experimental config resolver --- .../experimental/resolveConfig.test-d.ts | 62 ------- .../config/experimental/resolveConfig.test.ts | 49 ----- .../ts/config/experimental/resolveConfig.ts | 172 ------------------ packages/store/ts/config/index.ts | 2 - 4 files changed, 285 deletions(-) delete mode 100644 packages/store/ts/config/experimental/resolveConfig.test-d.ts delete mode 100644 packages/store/ts/config/experimental/resolveConfig.test.ts delete mode 100644 packages/store/ts/config/experimental/resolveConfig.ts diff --git a/packages/store/ts/config/experimental/resolveConfig.test-d.ts b/packages/store/ts/config/experimental/resolveConfig.test-d.ts deleted file mode 100644 index 80d8c8a960..0000000000 --- a/packages/store/ts/config/experimental/resolveConfig.test-d.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { describe, expectTypeOf } from "vitest"; -import { mudConfig } from "../../register/mudConfig"; -import { resolveConfig } from "./resolveConfig"; -import { Table } from "../../common"; -import storeConfig from "../../../mud.config"; - -describe("resolveConfig", () => { - describe("inline config", () => { - const config = resolveConfig( - mudConfig({ - // Seems like we need `as const` here to keep the strong type. - // Note it resolves to the strong `""` type if no namespace is provided. - // TODO: require the entire input config to be `const` - namespace: "the-namespace" as const, - userTypes: { - ResourceId: { - internalType: "bytes32", - filePath: "", - }, - }, - enums: { - ResourceType: ["namespace", "system", "table"], - }, - tables: { - Shorthand: { - keySchema: { - key: "ResourceId", - }, - valueSchema: "ResourceType", - }, - }, - }), - ); - - expectTypeOf().toEqualTypeOf<"the-namespace">(); - - expectTypeOf().toEqualTypeOf<"Shorthand">(); - - expectTypeOf().toEqualTypeOf<`0x${string}`>(); - - expectTypeOf().toEqualTypeOf<{ - key: { - internalType: "ResourceId"; - type: "bytes32"; - }; - }>(); - - expectTypeOf().toEqualTypeOf<{ - value: { - internalType: "ResourceType"; - type: "uint8"; - }; - }>(); - - expectTypeOf().toMatchTypeOf(); - }); - - describe("store config", () => { - const config = resolveConfig(storeConfig); - expectTypeOf().toMatchTypeOf<{ type: "bytes" }>(); - }); -}); diff --git a/packages/store/ts/config/experimental/resolveConfig.test.ts b/packages/store/ts/config/experimental/resolveConfig.test.ts deleted file mode 100644 index bcfe78a855..0000000000 --- a/packages/store/ts/config/experimental/resolveConfig.test.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { describe, expect, it } from "vitest"; -import { mudConfig } from "../../register/mudConfig"; -import { resolveConfig } from "./resolveConfig"; -import { MUDCoreContext } from "@latticexyz/config/library"; -import { resourceToHex } from "@latticexyz/common"; -MUDCoreContext.createContext(); - -const config = resolveConfig( - mudConfig({ - namespace: "the-namespace", - userTypes: { - ResourceId: { - internalType: "bytes32", - filePath: "", - }, - }, - enums: { - ResourceType: ["namespace", "system", "table"], - }, - tables: { - Shorthand: { - keySchema: { - key: "ResourceId", - }, - valueSchema: "ResourceType", - }, - }, - }), -); - -describe("resolveConfig", () => { - it("should resolve userTypes and enums", () => { - expect(config.tables.Shorthand.namespace).toEqual("the-namespace"); - - expect(config.tables.Shorthand.name).toEqual("Shorthand"); - - expect(config.tables.Shorthand.tableId).toEqual( - resourceToHex({ type: "table", namespace: "the-namespace", name: "Shorthand" }), - ); - - expect(config.tables.Shorthand.keySchema).toEqual({ - key: { internalType: "ResourceId", type: "bytes32" }, - }); - - expect(config.tables.Shorthand.valueSchema).toEqual({ - value: { internalType: "ResourceType", type: "uint8" }, - }); - }); -}); diff --git a/packages/store/ts/config/experimental/resolveConfig.ts b/packages/store/ts/config/experimental/resolveConfig.ts deleted file mode 100644 index 221377c5df..0000000000 --- a/packages/store/ts/config/experimental/resolveConfig.ts +++ /dev/null @@ -1,172 +0,0 @@ -import { StringForUnion } from "@latticexyz/common/type-utils"; -import { StoreConfig, TableConfig, UserTypesConfig } from "../storeConfig"; -import { UserType } from "@latticexyz/common/codegen"; -import { mapObject } from "@latticexyz/common/utils"; -import { resourceToHex } from "@latticexyz/common"; -import { SchemaAbiType } from "@latticexyz/schema-type/internal"; - -/** - * @internal Internal only - * @deprecated Internal only - */ -export type ResolvedStoreConfig = { - tables: { - [TableKey in keyof TStoreConfig["tables"] & string]: ResolvedTableConfig< - TStoreConfig["tables"][TableKey], - TStoreConfig["userTypes"], - keyof TStoreConfig["enums"] & string, - TStoreConfig["namespace"], - TableKey - >; - }; -}; - -type ResolvedTableConfig< - TTableConfig extends TableConfig, - TUserTypes extends UserTypesConfig["userTypes"], - TEnumNames extends StringForUnion, - TNamespace extends string = string, - TName extends string = string, -> = { - keySchema: ResolvedKeySchema; - valueSchema: ResolvedValueSchema; - namespace: TNamespace; - name: TName; - tableId: `0x${string}`; -}; - -type ResolvedKeySchema< - TKeySchema extends TableConfig["keySchema"], - TUserTypes extends UserTypesConfig["userTypes"], - TEnumNames extends StringForUnion, -> = ResolvedSchema; - -type ResolvedValueSchema< - TValueSchema extends TableConfig["valueSchema"], - TUserTypes extends UserTypesConfig["userTypes"], - TEnumNames extends StringForUnion, -> = ResolvedSchema, TUserTypes, TEnumNames>; - -type ResolvedSchema< - TSchema extends Exclude, - TUserTypes extends UserTypesConfig["userTypes"], - TEnumNames extends StringForUnion, -> = { - [key in keyof TSchema]: { - type: TSchema[key] extends SchemaAbiType - ? TSchema[key] - : TSchema[key] extends keyof TUserTypes - ? TUserTypes[TSchema[key]] extends UserType - ? // Note: we mistakenly named the plain ABI type "internalType", - // while in Solidity ABIs the plain ABI type is called "type" and - // and the custom type "internalType". We're planning to - // change our version and align with Solidity ABIs going forward. - TUserTypes[TSchema[key]]["internalType"] - : never - : TSchema[key] extends TEnumNames - ? "uint8" - : never; - internalType: TSchema[key]; - }; -}; - -/** - * @internal Internal only - * @deprecated Internal only - */ -export function resolveConfig( - config: TStoreConfig, -): ResolvedStoreConfig { - const resolvedTables: Record> = {}; - - for (const key of Object.keys(config.tables)) { - resolvedTables[key] = resolveTable( - config.tables[key], - config.userTypes, - Object.keys(config.enums), - config.namespace, - key, - ) as ReturnType; - } - - return { - tables: resolvedTables as ResolvedStoreConfig["tables"], - }; -} - -function resolveTable< - TTableConfig extends TableConfig, - TUserTypes extends UserTypesConfig["userTypes"], - TEnums extends StringForUnion[], - TNamespace extends string, - TName extends string, ->( - tableConfig: TTableConfig, - userTypes: TUserTypes, - enums: TEnums, - namespace: TNamespace, - name: TName, -): ResolvedTableConfig { - const { keySchema, valueSchema } = tableConfig; - - return { - keySchema: resolveKeySchema(keySchema, userTypes, enums), - valueSchema: resolveValueSchema(valueSchema, userTypes, enums) as ResolvedSchema< - Exclude, - TUserTypes, - TEnums[number] - >, - namespace, - name, - tableId: resourceToHex({ type: tableConfig.offchainOnly ? "offchainTable" : "table", namespace, name }), - }; -} - -function resolveKeySchema< - TKeySchema extends TableConfig["keySchema"], - TUserTypes extends UserTypesConfig["userTypes"], - TEnums extends StringForUnion[], ->( - keySchema: TKeySchema, - userTypes: TUserTypes, - enums: TEnums, -): ResolvedKeySchema { - const schema = ( - keySchema == null ? { key: "bytes32" } : typeof keySchema === "string" ? { key: keySchema } : keySchema - ) as TKeySchema extends undefined ? { key: "bytes32" } : TKeySchema; - return resolveSchema(schema, userTypes, enums); -} - -function resolveValueSchema< - TValueSchema extends TableConfig["valueSchema"], - TUserTypes extends UserTypesConfig["userTypes"], - TEnums extends StringForUnion[], ->( - valueSchema: TValueSchema, - userTypes: TUserTypes, - enums: TEnums, -): ResolvedValueSchema { - const schema = ( - typeof valueSchema === "string" ? ({ value: valueSchema } as unknown as TValueSchema) : valueSchema - ) as Exclude; - return resolveSchema(schema, userTypes, enums); -} - -function resolveSchema< - TSchema extends Exclude | TableConfig["valueSchema"], string>, - TUserTypes extends UserTypesConfig["userTypes"], - TEnums extends StringForUnion[], ->(schema: TSchema, userTypes: TUserTypes, enums: TEnums): ResolvedSchema { - return mapObject>(schema, (value, key) => { - const isUserType = userTypes && value in userTypes; - const isEnum = enums.includes(value); - return { - type: (isUserType ? userTypes[value].internalType : isEnum ? ("uint8" as const) : value) as ResolvedSchema< - TSchema, - TUserTypes, - TEnums[number] - >[typeof key]["type"], - internalType: value, - }; - }); -} diff --git a/packages/store/ts/config/index.ts b/packages/store/ts/config/index.ts index a00a9a9cd7..5de71694e7 100644 --- a/packages/store/ts/config/index.ts +++ b/packages/store/ts/config/index.ts @@ -1,4 +1,2 @@ export * from "./defaults"; export * from "./storeConfig"; - -export * from "./experimental/resolveConfig"; From 26c8bd374f8dd91b962a4d7e08597fb908e6178d Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Fri, 12 Jul 2024 15:03:42 +0100 Subject: [PATCH 03/25] remove table transformation --- packages/cli/src/deploy/common.ts | 17 +----- packages/cli/src/deploy/configToTables.ts | 70 ----------------------- packages/cli/src/deploy/deploy.ts | 40 +++++++------ packages/cli/src/runDeploy.ts | 4 +- 4 files changed, 26 insertions(+), 105 deletions(-) delete mode 100644 packages/cli/src/deploy/configToTables.ts diff --git a/packages/cli/src/deploy/common.ts b/packages/cli/src/deploy/common.ts index 0a409b8cbb..804b7db81e 100644 --- a/packages/cli/src/deploy/common.ts +++ b/packages/cli/src/deploy/common.ts @@ -2,22 +2,16 @@ import { Abi, Address, Hex, padHex } from "viem"; import storeConfig from "@latticexyz/store/mud.config"; import worldConfig from "@latticexyz/world/mud.config"; import IBaseWorldAbi from "@latticexyz/world/out/IBaseWorld.sol/IBaseWorld.abi.json" assert { type: "json" }; -import { Tables, configToTables } from "./configToTables"; import { helloStoreEvent } from "@latticexyz/store"; -import { StoreConfig } from "@latticexyz/store/internal"; import { helloWorldEvent } from "@latticexyz/world"; -import { WorldConfig } from "@latticexyz/world/internal"; -import { storeToV1 } from "@latticexyz/store/config/v2"; -import { worldToV1 } from "@latticexyz/world/config/v2"; export const salt = padHex("0x", { size: 32 }); // https://eips.ethereum.org/EIPS/eip-170 export const contractSizeLimit = parseInt("6000", 16); -// TODO: add `as const` to mud config so these get more strongly typed (blocked by current config parsing not using readonly) -export const storeTables = configToTables(storeToV1(storeConfig)); -export const worldTables = configToTables(worldToV1(worldConfig)); +export const storeTables = storeConfig.tables; +export const worldTables = worldConfig.tables; export const worldDeployEvents = [helloStoreEvent, helloWorldEvent] as const; @@ -111,10 +105,3 @@ export type Module = DeterministicContract & { readonly installAsRoot: boolean; readonly installData: Hex; // TODO: figure out better naming for this }; - -export type ConfigInput = StoreConfig & WorldConfig; -export type Config = { - readonly tables: Tables; - readonly systems: readonly System[]; - readonly libraries: readonly Library[]; -}; diff --git a/packages/cli/src/deploy/configToTables.ts b/packages/cli/src/deploy/configToTables.ts deleted file mode 100644 index 82392e1b50..0000000000 --- a/packages/cli/src/deploy/configToTables.ts +++ /dev/null @@ -1,70 +0,0 @@ -import { resourceToHex } from "@latticexyz/common"; -import { KeySchema, ValueSchema } from "@latticexyz/protocol-parser/internal"; -import { SchemaAbiType, StaticAbiType } from "@latticexyz/schema-type/internal"; -import { StoreConfig, resolveUserTypes } from "@latticexyz/store/internal"; -import { Hex } from "viem"; - -// TODO: we shouldn't need this file once our config parsing returns nicely formed tables - -type UserTypes = config["userTypes"]; -// TODO: fix strong enum types and avoid every schema getting `{ [k: string]: "uint8" }` -// type UserTypes = config["userTypes"] & { -// [k in keyof config["enums"]]: { internalType: "uint8" }; -// }; - -export type TableKey< - config extends StoreConfig = StoreConfig, - table extends config["tables"][keyof config["tables"]] = config["tables"][keyof config["tables"]], -> = `${config["namespace"]}_${table["name"]}`; - -export type Table< - config extends StoreConfig = StoreConfig, - table extends config["tables"][keyof config["tables"]] = config["tables"][keyof config["tables"]], -> = { - readonly namespace: config["namespace"]; - readonly name: table["name"]; - readonly tableId: Hex; - readonly keySchema: table["keySchema"] extends KeySchema> - ? KeySchema & { - readonly [k in keyof table["keySchema"]]: UserTypes[table["keySchema"][k]]["internalType"] extends StaticAbiType - ? UserTypes[table["keySchema"][k]]["internalType"] - : table["keySchema"][k]; - } - : KeySchema; - readonly valueSchema: table["valueSchema"] extends ValueSchema> - ? { - readonly [k in keyof table["valueSchema"]]: UserTypes[table["valueSchema"][k]]["internalType"] extends SchemaAbiType - ? UserTypes[table["valueSchema"][k]]["internalType"] - : table["valueSchema"][k]; - } - : ValueSchema; -}; - -export type Tables = { - readonly [k in keyof config["tables"] as TableKey]: Table; -}; - -export function configToTables(config: config): Tables { - const userTypes = { - ...config.userTypes, - ...Object.fromEntries(Object.entries(config.enums).map(([key]) => [key, { internalType: "uint8" }] as const)), - }; - return Object.fromEntries( - Object.entries(config.tables).map(([tableName, table]) => [ - `${config.namespace}_${tableName}` satisfies TableKey, - { - namespace: config.namespace, - name: table.name, - tableId: resourceToHex({ - type: table.offchainOnly ? "offchainTable" : "table", - namespace: config.namespace, - name: table.name, - }), - // eslint-disable-next-line @typescript-eslint/no-explicit-any - keySchema: resolveUserTypes(table.keySchema, userTypes) as any, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - valueSchema: resolveUserTypes(table.valueSchema, userTypes) as any, - } satisfies Table, - ]), - ) as Tables; -} diff --git a/packages/cli/src/deploy/deploy.ts b/packages/cli/src/deploy/deploy.ts index e407a44116..b14378be88 100644 --- a/packages/cli/src/deploy/deploy.ts +++ b/packages/cli/src/deploy/deploy.ts @@ -2,23 +2,25 @@ import { Account, Address, Chain, Client, Hex, Transport } from "viem"; import { ensureDeployer } from "./ensureDeployer"; import { deployWorld } from "./deployWorld"; import { ensureTables } from "./ensureTables"; -import { Config, ConfigInput, Module, WorldDeploy, supportedStoreVersions, supportedWorldVersions } from "./common"; +import { Library, Module, System, WorldDeploy, supportedStoreVersions, supportedWorldVersions } from "./common"; import { ensureSystems } from "./ensureSystems"; import { waitForTransactionReceipt } from "viem/actions"; import { getWorldDeploy } from "./getWorldDeploy"; import { ensureFunctions } from "./ensureFunctions"; import { ensureModules } from "./ensureModules"; -import { Table } from "./configToTables"; import { ensureNamespaceOwner } from "./ensureNamespaceOwner"; import { debug } from "./debug"; import { resourceToLabel } from "@latticexyz/common"; import { ensureContractsDeployed } from "./ensureContractsDeployed"; import { randomBytes } from "crypto"; import { ensureWorldFactory } from "./ensureWorldFactory"; +import { Table } from "@latticexyz/config"; -type DeployOptions = { +type DeployOptions = { client: Client; - config: Config; + tables: readonly Table[]; + systems: readonly System[]; + libraries: readonly Library[]; modules?: readonly Module[]; salt?: Hex; worldAddress?: Address; @@ -38,17 +40,17 @@ type DeployOptions = { * amount of work to make the world match the config (e.g. deploy new tables, * replace systems, etc.) */ -export async function deploy({ +export async function deploy({ client, - config, + tables, + systems, + libraries, modules = [], salt, worldAddress: existingWorldAddress, deployerAddress: initialDeployerAddress, withWorldProxy, -}: DeployOptions): Promise { - const tables = Object.values(config.tables) as Table[]; - +}: DeployOptions): Promise { const deployerAddress = initialDeployerAddress ?? (await ensureDeployer(client)); await ensureWorldFactory(client, deployerAddress, withWorldProxy); @@ -58,18 +60,18 @@ export async function deploy({ client, deployerAddress, contracts: [ - ...config.libraries.map((library) => ({ - bytecode: library.prepareDeploy(deployerAddress, config.libraries).bytecode, + ...libraries.map((library) => ({ + bytecode: library.prepareDeploy(deployerAddress, libraries).bytecode, deployedBytecodeSize: library.deployedBytecodeSize, label: `${library.path}:${library.name} library`, })), - ...config.systems.map((system) => ({ - bytecode: system.prepareDeploy(deployerAddress, config.libraries).bytecode, + ...systems.map((system) => ({ + bytecode: system.prepareDeploy(deployerAddress, libraries).bytecode, deployedBytecodeSize: system.deployedBytecodeSize, label: `${resourceToLabel(system)} system`, })), ...modules.map((mod) => ({ - bytecode: mod.prepareDeploy(deployerAddress, config.libraries).bytecode, + bytecode: mod.prepareDeploy(deployerAddress, libraries).bytecode, deployedBytecodeSize: mod.deployedBytecodeSize, label: `${mod.name} module`, })), @@ -90,7 +92,7 @@ export async function deploy({ const namespaceTxs = await ensureNamespaceOwner({ client, worldDeploy, - resourceIds: [...tables.map((table) => table.tableId), ...config.systems.map((system) => system.systemId)], + resourceIds: [...tables.map((table) => table.tableId), ...systems.map((system) => system.systemId)], }); debug("waiting for all namespace registration transactions to confirm"); @@ -106,19 +108,19 @@ export async function deploy({ const systemTxs = await ensureSystems({ client, deployerAddress, - libraries: config.libraries, + libraries, worldDeploy, - systems: config.systems, + systems, }); const functionTxs = await ensureFunctions({ client, worldDeploy, - functions: config.systems.flatMap((system) => system.functions), + functions: systems.flatMap((system) => system.functions), }); const moduleTxs = await ensureModules({ client, deployerAddress, - libraries: config.libraries, + libraries, worldDeploy, modules, }); diff --git a/packages/cli/src/runDeploy.ts b/packages/cli/src/runDeploy.ts index c8c9c3fa09..2bcb2571d9 100644 --- a/packages/cli/src/runDeploy.ts +++ b/packages/cli/src/runDeploy.ts @@ -133,7 +133,9 @@ export async function runDeploy(opts: DeployOptions): Promise { salt, worldAddress: opts.worldAddress as Hex | undefined, client, - config: resolvedConfig, + tables: Object.values(configV2.tables), + systems: resolvedConfig.systems, + libraries: resolvedConfig.libraries, modules, withWorldProxy: configV2.deploy.upgradeableWorldImplementation, }); From 878e25625a72af7e645e33ce02295e4eeef0b60a Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Fri, 12 Jul 2024 15:11:19 +0100 Subject: [PATCH 04/25] fix enums --- .../src/codegen/render-solidity/renderEnums.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/common/src/codegen/render-solidity/renderEnums.ts b/packages/common/src/codegen/render-solidity/renderEnums.ts index 6eec0df37c..9fa1e46307 100644 --- a/packages/common/src/codegen/render-solidity/renderEnums.ts +++ b/packages/common/src/codegen/render-solidity/renderEnums.ts @@ -9,15 +9,16 @@ type Enums = { * Render a list of enum data as solidity enum definitions */ export function renderEnums(enums: Enums): string { - return ` - ${renderedSolidityHeader} - - ${Object.entries(enums).map( - ([name, values]) => ` + const enumDefinitions = Object.entries(enums).map( + ([name, values]) => ` enum ${name} { ${values.join(", ")} } `, - )} + ); + + return ` + ${renderedSolidityHeader} + ${enumDefinitions.join("")} `; } From 20916378a9e42be53a4be2c05f957deb2aa87756 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Tue, 16 Jul 2024 10:48:05 +0100 Subject: [PATCH 05/25] refactor away from resolveWorldConfig --- packages/cli/contracts/src/codegen/common.sol | 1 + packages/cli/src/build.ts | 10 +-- packages/cli/src/commands/build.ts | 4 +- packages/cli/src/commands/dev-contracts.ts | 1 - packages/cli/src/commands/trace.ts | 58 ++++++------- packages/cli/src/commands/verify.ts | 31 ++++--- packages/cli/src/commands/worldgen.ts | 28 ++----- packages/cli/src/deploy/resolveConfig.ts | 55 +++++++------ packages/cli/src/runDeploy.ts | 17 ++-- packages/store/ts/codegen/tablegen.ts | 2 + packages/world-modules/package.json | 3 +- packages/world-modules/ts/scripts/tablegen.ts | 11 --- packages/world-modules/ts/scripts/worldgen.ts | 33 -------- packages/world/ts/config/resolveSystems.ts | 53 ++++++++++++ .../world/ts/config/resolveWorldConfig.ts | 82 ------------------- packages/world/ts/exports/internal.ts | 2 +- packages/world/ts/node/findSolidityFiles.ts | 1 + packages/world/ts/node/getSystemContracts.ts | 33 ++++++++ packages/world/ts/node/index.ts | 2 + .../world/ts/node/render-solidity/worldgen.ts | 52 ++++++------ packages/world/ts/scripts/build.ts | 19 +---- pnpm-lock.yaml | 3 + .../src/codegen/common.sol | 1 + 23 files changed, 218 insertions(+), 284 deletions(-) delete mode 100644 packages/world-modules/ts/scripts/tablegen.ts delete mode 100644 packages/world-modules/ts/scripts/worldgen.ts create mode 100644 packages/world/ts/config/resolveSystems.ts delete mode 100644 packages/world/ts/config/resolveWorldConfig.ts create mode 100644 packages/world/ts/node/getSystemContracts.ts diff --git a/packages/cli/contracts/src/codegen/common.sol b/packages/cli/contracts/src/codegen/common.sol index 728b16cc27..57a807edd3 100644 --- a/packages/cli/contracts/src/codegen/common.sol +++ b/packages/cli/contracts/src/codegen/common.sol @@ -2,6 +2,7 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ + enum Enum1 { E1, E2, diff --git a/packages/cli/src/build.ts b/packages/cli/src/build.ts index 8d90517bd2..849558b7c1 100644 --- a/packages/cli/src/build.ts +++ b/packages/cli/src/build.ts @@ -1,14 +1,11 @@ -import path from "node:path"; import { tablegen } from "@latticexyz/store/codegen"; import { worldgen } from "@latticexyz/world/node"; import { World as WorldConfig } from "@latticexyz/world"; import { forge, getRemappings } from "@latticexyz/common/foundry"; -import { getExistingContracts } from "./utils/getExistingContracts"; import { execa } from "execa"; type BuildOptions = { foundryProfile?: string; - srcDir: string; /** * MUD project root directory where all other relative paths are resolved from. * @@ -21,16 +18,11 @@ type BuildOptions = { export async function build({ rootDir, config, - srcDir, foundryProfile = process.env.FOUNDRY_PROFILE, }: BuildOptions): Promise { - const outPath = path.join(srcDir, config.codegen.outputDirectory); const remappings = await getRemappings(foundryProfile); - await Promise.all([ - tablegen({ rootDir, config, remappings }), - worldgen(config, getExistingContracts(srcDir), outPath), - ]); + await Promise.all([tablegen({ rootDir, config, remappings }), worldgen({ rootDir, config })]); await forge(["build"], { profile: foundryProfile }); await execa("mud", ["abi-ts"], { stdio: "inherit" }); diff --git a/packages/cli/src/commands/build.ts b/packages/cli/src/commands/build.ts index fba961ee84..6a5187a9f2 100644 --- a/packages/cli/src/commands/build.ts +++ b/packages/cli/src/commands/build.ts @@ -1,7 +1,6 @@ import type { CommandModule } from "yargs"; import { loadConfig, resolveConfigPath } from "@latticexyz/config/node"; import { World as WorldConfig } from "@latticexyz/world"; -import { getSrcDirectory } from "@latticexyz/common/foundry"; import { build } from "../build"; import path from "node:path"; @@ -25,9 +24,8 @@ const commandModule: CommandModule = { async handler(opts) { const configPath = await resolveConfigPath(opts.configPath); const config = (await loadConfig(configPath)) as WorldConfig; - const srcDir = await getSrcDirectory(); - await build({ rootDir: path.dirname(configPath), config, srcDir, foundryProfile: opts.profile }); + await build({ rootDir: path.dirname(configPath), config, foundryProfile: opts.profile }); process.exit(0); }, diff --git a/packages/cli/src/commands/dev-contracts.ts b/packages/cli/src/commands/dev-contracts.ts index ab8d655c7a..dff19975dc 100644 --- a/packages/cli/src/commands/dev-contracts.ts +++ b/packages/cli/src/commands/dev-contracts.ts @@ -90,7 +90,6 @@ const commandModule: CommandModule = { }, configPath: { type: "string", description: "Path to the MUD config file" }, profile: { type: "string", description: "The foundry profile to use" }, - srcDir: { type: "string", description: "Source directory. Defaults to foundry src directory." }, rpc: { type: "string", description: "json rpc endpoint. Defaults to foundry's configured eth_rpc_url" }, }); }, async handler(args) { - args.profile ??= process.env.FOUNDRY_PROFILE; - const { profile } = args; - args.srcDir ??= await getSrcDirectory(profile); - args.rpc ??= await getRpcUrl(profile); - const { tx, configPath, srcDir, rpc } = args; + const configPath = await resolveConfigPath(args.configPath); + const rootDir = path.dirname(configPath); - const existingContracts = getExistingContracts(srcDir); + const profile = args.profile ?? process.env.FOUNDRY_PROFILE; + const rpc = args.rpc ?? (await getRpcUrl(profile)); // Load the config - const configV2 = (await loadConfig(configPath)) as WorldConfig; - const mudConfig = worldToV1(configV2); - - const resolvedConfig = resolveWorldConfig( - mudConfig, - existingContracts.map(({ basename }) => basename), - ); + const config = (await loadConfig(configPath)) as WorldConfig; // Get worldAddress either from args or from worldsFile - const worldAddress = args.worldAddress ?? (await getWorldAddress(mudConfig.worldsFile, rpc)); + const worldAddress = args.worldAddress ?? (await getWorldAddress(config.deploy.worldsFile, rpc)); // Create World contract instance from deployed address const provider = new ethers.providers.StaticJsonRpcProvider(rpc); const WorldContract = new ethers.Contract(worldAddress, IBaseWorldAbi, provider); - // TODO account for multiple namespaces (https://github.com/latticexyz/mud/issues/994) - const namespace = mudConfig.namespace; - const names = Object.values(resolvedConfig.systems).map(({ name }) => name); + // TODO: replace with system.namespace + const namespace = config.namespace; + const systems = await resolveSystems({ rootDir, config }); // Fetch system table field layout from chain const systemTableFieldLayout = await WorldContract.getFieldLayout(systemsTableId); - const labels: { name: string; address: string }[] = []; - for (const name of names) { - const systemSelector = resourceToHex({ type: "system", namespace, name }); - // Get the first field of `Systems` table (the table maps system name to its address and other data) - const address = await WorldContract.getField(systemsTableId, [systemSelector], 0, systemTableFieldLayout); - labels.push({ name, address }); - } + const labels = await Promise.all( + systems.map(async (system) => { + // TODO: replace with system.systemId + const systemId = resourceToHex({ type: "system", namespace, name: system.name }); + // Get the first field of `Systems` table (the table maps system name to its address and other data) + const address = await WorldContract.getField(systemsTableId, [systemId], 0, systemTableFieldLayout); + return { name: system.name, address }; + }), + ); const result = await cast([ "run", "--label", `${worldAddress}:World`, ...labels.map(({ name, address }) => ["--label", `${address}:${name}`]).flat(), - `${tx}`, + `${args.tx}`, ]); console.log(result); diff --git a/packages/cli/src/commands/verify.ts b/packages/cli/src/commands/verify.ts index ba5935ef91..aed74f9cca 100644 --- a/packages/cli/src/commands/verify.ts +++ b/packages/cli/src/commands/verify.ts @@ -1,15 +1,14 @@ import type { CommandModule, InferredOptionTypes } from "yargs"; import { verify } from "../verify"; -import { loadConfig } from "@latticexyz/config/node"; +import { loadConfig, resolveConfigPath } from "@latticexyz/config/node"; import { World as WorldConfig } from "@latticexyz/world"; -import { resolveWorldConfig } from "@latticexyz/world/internal"; -import { worldToV1 } from "@latticexyz/world/config/v2"; -import { getOutDirectory, getRpcUrl, getSrcDirectory } from "@latticexyz/common/foundry"; -import { getExistingContracts } from "../utils/getExistingContracts"; +import { resolveSystems } from "@latticexyz/world/internal"; +import { getOutDirectory, getRpcUrl } from "@latticexyz/common/foundry"; import { getContractData } from "../utils/getContractData"; import { Hex, createWalletClient, http } from "viem"; import chalk from "chalk"; import { configToModules } from "../deploy/configToModules"; +import path from "node:path"; const verifyOptions = { deployerAddress: { @@ -24,7 +23,6 @@ const verifyOptions = { type: "boolean", desc: "Enable batch processing of RPC requests in viem client (defaults to batch size of 100 and wait of 1s)", }, - srcDir: { type: "string", desc: "Source directory. Defaults to foundry src directory." }, verifier: { type: "string", desc: "The verifier to use. Defaults to blockscout", default: "blockscout" }, verifierUrl: { type: "string", @@ -46,10 +44,11 @@ const commandModule: CommandModule = { async handler(opts) { const profile = opts.profile ?? process.env.FOUNDRY_PROFILE; - const configV2 = (await loadConfig(opts.configPath)) as WorldConfig; - const config = worldToV1(configV2); + const configPath = await resolveConfigPath(opts.configPath); + const rootDir = path.dirname(configPath); + + const config = (await loadConfig(configPath)) as WorldConfig; - const srcDir = opts.srcDir ?? (await getSrcDirectory(profile)); const outDir = await getOutDirectory(profile); const rpc = opts.rpc ?? (await getRpcUrl(profile)); @@ -70,19 +69,17 @@ const commandModule: CommandModule = { }), }); - const contractNames = getExistingContracts(srcDir).map(({ basename }) => basename); - const resolvedWorldConfig = resolveWorldConfig(config, contractNames); - - const systems = Object.keys(resolvedWorldConfig.systems).map((name) => { - const contractData = getContractData(`${name}.sol`, name, outDir); - + // 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); return { - name, + name: system.name, bytecode: contractData.bytecode, }; }); - const modules = await configToModules(configV2, outDir); + const modules = await configToModules(config, outDir); await verify({ client, diff --git a/packages/cli/src/commands/worldgen.ts b/packages/cli/src/commands/worldgen.ts index 3a87a7348b..9ebdaa3a0a 100644 --- a/packages/cli/src/commands/worldgen.ts +++ b/packages/cli/src/commands/worldgen.ts @@ -1,17 +1,12 @@ +import path from "node:path"; import type { CommandModule } from "yargs"; -import { loadConfig } from "@latticexyz/config/node"; +import { loadConfig, resolveConfigPath } from "@latticexyz/config/node"; import { World as WorldConfig } from "@latticexyz/world"; import { worldgen } from "@latticexyz/world/node"; -import { getSrcDirectory } from "@latticexyz/common/foundry"; -import path from "path"; -import { rmSync } from "fs"; -import { getExistingContracts } from "../utils/getExistingContracts"; type Options = { configPath?: string; clean?: boolean; - srcDir?: string; - config?: WorldConfig; }; const commandModule: CommandModule = { @@ -37,22 +32,11 @@ const commandModule: CommandModule = { }; export async function worldgenHandler(args: Options) { - const srcDir = args.srcDir ?? (await getSrcDirectory()); + const configPath = await resolveConfigPath(args.configPath); + const config = (await loadConfig(configPath)) as WorldConfig; + const rootDir = path.dirname(configPath); - const existingContracts = getExistingContracts(srcDir); - - // Load the config - const mudConfig = args.config ?? ((await loadConfig(args.configPath)) as WorldConfig); - - const outputBaseDirectory = path.join(srcDir, mudConfig.codegen.outputDirectory); - - // clear the worldgen directory - if (args.clean) { - rmSync(path.join(outputBaseDirectory, mudConfig.codegen.worldgenDirectory), { recursive: true, force: true }); - } - - // generate new interfaces - await worldgen(mudConfig, existingContracts, outputBaseDirectory); + await worldgen({ rootDir, config, clean: args.clean }); } export default commandModule; diff --git a/packages/cli/src/deploy/resolveConfig.ts b/packages/cli/src/deploy/resolveConfig.ts index 0a4466f7dc..23448fd7de 100644 --- a/packages/cli/src/deploy/resolveConfig.ts +++ b/packages/cli/src/deploy/resolveConfig.ts @@ -1,26 +1,28 @@ import path from "path"; -import { resolveWorldConfig } from "@latticexyz/world/internal"; -import { Config, ConfigInput, Library, System, WorldFunction } from "./common"; +import { resolveSystems } from "@latticexyz/world/internal"; +import { Library, System, WorldFunction } from "./common"; import { resourceToHex } from "@latticexyz/common"; -import { Hex, toFunctionSelector, toFunctionSignature } from "viem"; -import { getExistingContracts } from "../utils/getExistingContracts"; +import { Hex, isHex, toFunctionSelector, toFunctionSignature } from "viem"; import { getContractData } from "../utils/getContractData"; -import { configToTables } from "./configToTables"; import { groupBy } from "@latticexyz/common/utils"; import { findLibraries } from "./findLibraries"; import { createPrepareDeploy } from "./createPrepareDeploy"; +import { World } from "@latticexyz/world"; -// TODO: this should be replaced by https://github.com/latticexyz/mud/issues/1668 +// TODO: replace this with a manifest/combined config output -export function resolveConfig({ +export async function resolveConfig({ + rootDir, config, - forgeSourceDir, forgeOutDir, }: { - config: config; - forgeSourceDir: string; + rootDir: string; + config: World; forgeOutDir: string; -}): Config { +}): Promise<{ + readonly systems: readonly System[]; + readonly libraries: readonly Library[]; +}> { const libraries = findLibraries(forgeOutDir).map((library): Library => { // foundry/solc flattens artifacts, so we just use the path basename const contractData = getContractData(path.basename(library.path), library.name, forgeOutDir); @@ -33,21 +35,21 @@ export function resolveConfig({ }; }); - const tables = configToTables(config); - - // TODO: should the config parser/loader help with resolving systems? - const contractNames = getExistingContracts(forgeSourceDir).map(({ basename }) => basename); - const resolvedConfig = resolveWorldConfig(config, contractNames); const baseSystemContractData = getContractData("System.sol", "System", forgeOutDir); const baseSystemFunctions = baseSystemContractData.abi .filter((item): item is typeof item & { type: "function" } => item.type === "function") .map(toFunctionSignature); - const systems = Object.entries(resolvedConfig.systems).map(([systemName, system]): System => { + const configSystems = await resolveSystems({ rootDir, config }); + + const systems = configSystems.map((system): System => { + // TODO: replace with system.namespace const namespace = config.namespace; const name = system.name; + // TODO: replace with system.systemId const systemId = resourceToHex({ type: "system", namespace, name }); - const contractData = getContractData(`${systemName}.sol`, systemName, forgeOutDir); + // TODO: replace system.name with system.label + const contractData = getContractData(`${system.name}.sol`, system.name, forgeOutDir); const systemFunctions = contractData.abi .filter((item): item is typeof item & { type: "function" } => item.type === "function") @@ -65,15 +67,23 @@ export function resolveConfig({ }; }); + // TODO: move to resolveSystems? + const allowedAddresses = system.accessList.filter((target): target is Hex => isHex(target)); + const allowedSystemIds = system.accessList + .filter((target) => !isHex(target)) + .map((label) => { + const system = configSystems.find((s) => s.name === label)!; + // TODO: replace with system.systemId + return resourceToHex({ type: "system", namespace, name: system.name }); + }); + return { namespace, name, systemId, allowAll: system.openAccess, - allowedAddresses: system.accessListAddresses as Hex[], - allowedSystemIds: system.accessListSystems.map((name) => - resourceToHex({ type: "system", namespace, name: resolvedConfig.systems[name].name }), - ), + allowedAddresses, + allowedSystemIds, prepareDeploy: createPrepareDeploy(contractData.bytecode, contractData.placeholders), deployedBytecodeSize: contractData.deployedBytecodeSize, abi: contractData.abi, @@ -97,7 +107,6 @@ export function resolveConfig({ } return { - tables, systems, libraries, }; diff --git a/packages/cli/src/runDeploy.ts b/packages/cli/src/runDeploy.ts index 2bcb2571d9..cef9550e52 100644 --- a/packages/cli/src/runDeploy.ts +++ b/packages/cli/src/runDeploy.ts @@ -7,7 +7,7 @@ import { privateKeyToAccount } from "viem/accounts"; import { loadConfig, resolveConfigPath } from "@latticexyz/config/node"; import { World as WorldConfig } from "@latticexyz/world"; import { worldToV1 } from "@latticexyz/world/config/v2"; -import { getOutDirectory, getRpcUrl, getSrcDirectory } from "@latticexyz/common/foundry"; +import { getOutDirectory, getRpcUrl } from "@latticexyz/common/foundry"; import chalk from "chalk"; import { MUDError } from "@latticexyz/common/errors"; import { resolveConfig } from "./deploy/resolveConfig"; @@ -33,7 +33,6 @@ export const deployOptions = { desc: "Deploy using an existing deterministic deployer (https://github.com/Arachnid/deterministic-deployment-proxy)", }, worldAddress: { type: "string", desc: "Deploy to an existing World at the given address" }, - srcDir: { type: "string", desc: "Source directory. Defaults to foundry src directory." }, skipBuild: { type: "boolean", desc: "Skip rebuilding the contracts before deploying" }, alwaysRunPostDeploy: { type: "boolean", @@ -66,12 +65,12 @@ export async function runDeploy(opts: DeployOptions): Promise { const configPath = await resolveConfigPath(opts.configPath); const configV2 = (await loadConfig(configPath)) as WorldConfig; + const rootDir = path.dirname(configPath); const config = worldToV1(configV2); if (opts.printConfig) { console.log(chalk.green("\nResolved config:\n"), JSON.stringify(config, null, 2)); } - const srcDir = opts.srcDir ?? (await getSrcDirectory(profile)); const outDir = await getOutDirectory(profile); const rpc = opts.rpc ?? (await getRpcUrl(profile)); @@ -83,10 +82,14 @@ export async function runDeploy(opts: DeployOptions): Promise { // Run build if (!opts.skipBuild) { - await build({ rootDir: path.dirname(configPath), config: configV2, srcDir, foundryProfile: profile }); + await build({ rootDir, config: configV2, foundryProfile: profile }); } - const resolvedConfig = resolveConfig({ config, forgeSourceDir: srcDir, forgeOutDir: outDir }); + const { systems, libraries } = await resolveConfig({ + rootDir, + config: configV2, + forgeOutDir: outDir, + }); const modules = await configToModules(configV2, outDir); const account = await (async () => { @@ -134,8 +137,8 @@ export async function runDeploy(opts: DeployOptions): Promise { worldAddress: opts.worldAddress as Hex | undefined, client, tables: Object.values(configV2.tables), - systems: resolvedConfig.systems, - libraries: resolvedConfig.libraries, + systems, + libraries, modules, withWorldProxy: configV2.deploy.upgradeableWorldImplementation, }); diff --git a/packages/store/ts/codegen/tablegen.ts b/packages/store/ts/codegen/tablegen.ts index bcce73ab7d..c8edf6a0ce 100644 --- a/packages/store/ts/codegen/tablegen.ts +++ b/packages/store/ts/codegen/tablegen.ts @@ -8,6 +8,8 @@ import { rm } from "fs/promises"; import { Store as StoreConfig } from "../config/v2/output"; import { mapObject } from "@latticexyz/common/utils"; +// TODO: clean + export type TablegenOptions = { /** * MUD project root directory where all other relative paths are resolved from. diff --git a/packages/world-modules/package.json b/packages/world-modules/package.json index d33320e1ab..63e00e5a33 100644 --- a/packages/world-modules/package.json +++ b/packages/world-modules/package.json @@ -30,7 +30,7 @@ "build:abi": "forge build", "build:abi-ts": "abi-ts", "build:js": "tsup", - "build:mud": "tsx ./ts/scripts/tablegen.ts && tsx ./ts/scripts/worldgen.ts", + "build:mud": "mud build", "clean": "pnpm run clean:abi && pnpm run clean:js && pnpm run clean:mud", "clean:abi": "forge clean", "clean:js": "rimraf dist", @@ -42,6 +42,7 @@ "test:ci": "pnpm run test" }, "dependencies": { + "@latticexyz/cli": "workspace:*", "@latticexyz/common": "workspace:*", "@latticexyz/config": "workspace:*", "@latticexyz/schema-type": "workspace:*", diff --git a/packages/world-modules/ts/scripts/tablegen.ts b/packages/world-modules/ts/scripts/tablegen.ts deleted file mode 100644 index f97cc26648..0000000000 --- a/packages/world-modules/ts/scripts/tablegen.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { loadConfig, resolveConfigPath } from "@latticexyz/config/node"; -import { getRemappings } from "@latticexyz/common/foundry"; -import { Store as StoreConfig } from "@latticexyz/store"; -import { tablegen } from "@latticexyz/store/codegen"; -import path from "node:path"; - -const configPath = await resolveConfigPath(); -const config = (await loadConfig(configPath)) as StoreConfig; -const remappings = await getRemappings(); - -await tablegen({ rootDir: path.dirname(configPath), config, remappings }); diff --git a/packages/world-modules/ts/scripts/worldgen.ts b/packages/world-modules/ts/scripts/worldgen.ts deleted file mode 100644 index 16852d9730..0000000000 --- a/packages/world-modules/ts/scripts/worldgen.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { globSync } from "glob"; -import path, { basename } from "path"; -import { rmSync } from "fs"; -import { loadConfig } from "@latticexyz/config/node"; -import { getSrcDirectory } from "@latticexyz/common/foundry"; -import { World as WorldConfig } from "@latticexyz/world"; -import { worldgen } from "@latticexyz/world/node"; - -// TODO dedupe this and cli's worldgen command -const configPath = undefined; -const clean = false; -const srcDir = await getSrcDirectory(); - -// Get a list of all contract names -const existingContracts = globSync(`${srcDir}/**/*.sol`) - .sort() - .map((path) => ({ - path, - basename: basename(path, ".sol"), - })); - -// Load and resolve the config -const mudConfig = (await loadConfig(configPath)) as WorldConfig; - -const outputBaseDirectory = path.join(srcDir, mudConfig.codegen.outputDirectory); - -// clear the worldgen directory -if (clean) { - rmSync(path.join(outputBaseDirectory, mudConfig.codegen.worldgenDirectory), { recursive: true, force: true }); -} - -// generate new interfaces -await worldgen(mudConfig, existingContracts, outputBaseDirectory); diff --git a/packages/world/ts/config/resolveSystems.ts b/packages/world/ts/config/resolveSystems.ts new file mode 100644 index 0000000000..1304b3d12a --- /dev/null +++ b/packages/world/ts/config/resolveSystems.ts @@ -0,0 +1,53 @@ +import { isHex } from "viem"; +import { getSystemContracts } from "../node"; +import { System, World } from "./v2"; +import { SYSTEM_DEFAULTS } from "./v2/defaults"; + +export type ResolvedSystem = System & { + readonly sourcePath: string; +}; + +export async function resolveSystems({ + rootDir, + config, +}: { + rootDir: string; + config: World; +}): Promise { + const systemContracts = await getSystemContracts({ rootDir, config }); + const contractNames = systemContracts.map((contract) => contract.name); + + // validate every system in config refers to an existing system contract + const missingSystems = Object.keys(config.systems).filter((systemLabel) => !contractNames.includes(systemLabel)); + if (missingSystems.length > 0) { + throw new Error(`Found systems in config with no corresponding system contract: ${missingSystems.join(", ")}`); + } + + const systems = systemContracts + .map((contract): ResolvedSystem => { + // TODO: replace name with label + const systemConfig = config.systems[contract.name] ?? { ...SYSTEM_DEFAULTS, name: contract.name }; + return { + ...systemConfig, + sourcePath: contract.sourcePath, + }; + }) + // TODO: replace `excludeSystems` with `deploy.disabled` or `codegen.disabled` + .filter((system) => !config.excludeSystems.includes(system.name)); + + // TODO: replace `system.name` with `system.label` + const systemLabels = systems.map((system) => system.name); + + // validate every system has a valid access list + for (const system of systems) { + for (const accessListItem of system.accessList) { + if (isHex(accessListItem)) continue; + if (systemLabels.includes(accessListItem)) continue; + throw new Error( + `Access list item (${accessListItem}) for system (${system.name}) had no matching system contract.`, + ); + } + } + + return systems; +} diff --git a/packages/world/ts/config/resolveWorldConfig.ts b/packages/world/ts/config/resolveWorldConfig.ts deleted file mode 100644 index 7dd9766464..0000000000 --- a/packages/world/ts/config/resolveWorldConfig.ts +++ /dev/null @@ -1,82 +0,0 @@ -import { UnrecognizedSystemErrorFactory } from "@latticexyz/config/library"; -import { StoreConfig } from "@latticexyz/store/internal"; -import { SystemConfig, WorldConfig } from "./types"; - -export type ResolvedSystemConfig = ReturnType; - -export type ResolvedWorldConfig = ReturnType; - -/** - * Resolves the world config by combining the default and overridden system configs, - * filtering out excluded systems, validate system names refer to existing contracts, and - * splitting the access list into addresses and system names. - */ -export function resolveWorldConfig( - config: Pick, - existingContracts?: string[], -) { - // Include contract names ending in "System", but not the base "System" contract, and not Interfaces - const defaultSystemNames = - existingContracts?.filter((name) => name.endsWith("System") && name !== "System" && !name.match(/^I[A-Z]/)) ?? []; - const overriddenSystemNames = Object.keys(config.systems); - - // Validate every key in systems refers to an existing system contract (and is not called "World") - if (existingContracts) { - for (const systemName of overriddenSystemNames) { - if (!existingContracts.includes(systemName) || systemName === "World") { - throw UnrecognizedSystemErrorFactory(["systems", systemName], systemName); - } - } - } - - // Combine the default and overridden system names and filter out excluded systems - const systemNames = [...new Set([...defaultSystemNames, ...overriddenSystemNames])].filter( - (name) => !config.excludeSystems.includes(name), - ); - - // Resolve the config - const resolvedSystems: Record = systemNames.reduce((acc, systemName) => { - return { - ...acc, - [systemName]: resolveSystemConfig(systemName, config.systems[systemName], existingContracts), - }; - }, {}); - - return { systems: resolvedSystems }; -} - -/** - * Resolves the system config by combining the default and overridden system configs, - * @param systemName name of the system - * @param config optional SystemConfig object, if none is provided the default config is used - * @param existingContracts optional list of existing contract names, used to validate system names in the access list. If not provided, no validation is performed. - * @returns ResolvedSystemConfig object - * Default value for name is `systemName` - * Default value for registerFunctionSelectors is true - * Default value for openAccess is true - * Default value for accessListAddresses is [] - * Default value for accessListSystems is [] - */ -export function resolveSystemConfig(systemName: string, config?: SystemConfig, existingContracts?: string[]) { - const name = config?.name ?? systemName; - const registerFunctionSelectors = config?.registerFunctionSelectors ?? true; - const openAccess = config?.openAccess ?? true; - const accessListAddresses: string[] = []; - const accessListSystems: string[] = []; - const accessList = config && !config.openAccess ? config.accessList : []; - - // Split the access list into addresses and system names - for (const accessListItem of accessList) { - if (accessListItem.startsWith("0x")) { - accessListAddresses.push(accessListItem); - } else { - // Validate every system refers to an existing system contract - if (existingContracts && !existingContracts.includes(accessListItem)) { - throw UnrecognizedSystemErrorFactory(["systems", systemName, "accessList"], accessListItem); - } - accessListSystems.push(accessListItem); - } - } - - return { name, registerFunctionSelectors, openAccess, accessListAddresses, accessListSystems }; -} diff --git a/packages/world/ts/exports/internal.ts b/packages/world/ts/exports/internal.ts index 64819f4a4d..9c7a3d3915 100644 --- a/packages/world/ts/exports/internal.ts +++ b/packages/world/ts/exports/internal.ts @@ -1,5 +1,5 @@ export * from "../config/defaults"; -export * from "../config/resolveWorldConfig"; +export * from "../config/resolveSystems"; export * from "../config/types"; export * from "../config/worldConfig"; diff --git a/packages/world/ts/node/findSolidityFiles.ts b/packages/world/ts/node/findSolidityFiles.ts index 6e61125fbd..3d37a77360 100644 --- a/packages/world/ts/node/findSolidityFiles.ts +++ b/packages/world/ts/node/findSolidityFiles.ts @@ -2,6 +2,7 @@ import path from "node:path"; import { glob } from "glob"; import { World } from "../config/v2/output"; +// TODO: move to common codegen? export async function findSolidityFiles({ rootDir, config }: { rootDir: string; config: World }) { const files = await glob(path.join(config.sourceDirectory, "**", "*.sol"), { cwd: rootDir, diff --git a/packages/world/ts/node/getSystemContracts.ts b/packages/world/ts/node/getSystemContracts.ts new file mode 100644 index 0000000000..93c0aaa81f --- /dev/null +++ b/packages/world/ts/node/getSystemContracts.ts @@ -0,0 +1,33 @@ +import { World } from "../config/v2/output"; +import { findSolidityFiles } from "./findSolidityFiles"; + +export type SolidityContract = { + readonly sourcePath: string; + readonly name: string; +}; + +export type GetSystemContractsOptions = { + readonly rootDir: string; + readonly config: World; +}; + +export async function getSystemContracts({ + rootDir, + config, +}: GetSystemContractsOptions): Promise { + const solidityFiles = await findSolidityFiles({ rootDir, config }); + + return solidityFiles + .map((file) => ({ + sourcePath: file.filename, + name: file.basename, + })) + .filter( + (file) => + file.name.endsWith("System") && + // exclude the base System contract + file.name !== "System" && + // exclude interfaces + !/^I[A-Z]/.test(file.name), + ); +} diff --git a/packages/world/ts/node/index.ts b/packages/world/ts/node/index.ts index 3fea3930b7..4fcb666777 100644 --- a/packages/world/ts/node/index.ts +++ b/packages/world/ts/node/index.ts @@ -1 +1,3 @@ export * from "./render-solidity"; +export * from "./findSolidityFiles"; +export * from "./getSystemContracts"; diff --git a/packages/world/ts/node/render-solidity/worldgen.ts b/packages/world/ts/node/render-solidity/worldgen.ts index 4f9c096486..5a6adb8b3c 100644 --- a/packages/world/ts/node/render-solidity/worldgen.ts +++ b/packages/world/ts/node/render-solidity/worldgen.ts @@ -1,38 +1,40 @@ -import { readFileSync } from "fs"; +import fs from "fs"; import path from "path"; import { formatAndWriteSolidity, contractToInterface, type RelativeImportDatum } from "@latticexyz/common/codegen"; import { renderSystemInterface } from "./renderSystemInterface"; import { renderWorldInterface } from "./renderWorldInterface"; -import { resolveWorldConfig } from "../../config/resolveWorldConfig"; import { World as WorldConfig } from "../../config/v2/output"; -import { worldToV1 } from "../../config/v2/compat"; +import { resolveSystems } from "../../config/resolveSystems"; -export async function worldgen( - configV2: WorldConfig, - existingContracts: { path: string; basename: string }[], - outputBaseDirectory: string, -) { - const config = worldToV1(configV2); - const resolvedConfig = resolveWorldConfig( - config, - existingContracts.map(({ basename }) => basename), - ); +export async function worldgen({ + rootDir, + config, + clean = true, +}: { + rootDir: string; + config: WorldConfig; + clean?: boolean; +}) { + const outDir = path.join(config.sourceDirectory, config.codegen.outputDirectory, config.codegen.worldgenDirectory); - const worldgenBaseDirectory = path.join(outputBaseDirectory, config.worldgenDirectory); - const systems = existingContracts.filter(({ basename }) => Object.keys(resolvedConfig.systems).includes(basename)); + if (clean) { + fs.rmSync(outDir, { recursive: true, force: true }); + } + + const systems = await resolveSystems({ rootDir, config }); const systemInterfaceImports: RelativeImportDatum[] = []; for (const system of systems) { - const data = readFileSync(system.path, "utf8"); + const data = fs.readFileSync(system.sourcePath, "utf8"); // get external funcions from a contract - const { functions, errors, symbolImports } = contractToInterface(data, system.basename); + const { functions, errors, symbolImports } = contractToInterface(data, system.name); const imports = symbolImports.map((symbolImport) => { if (symbolImport.path[0] === ".") { // relative import return { symbol: symbolImport.symbol, - fromPath: path.join(path.dirname(system.path), symbolImport.path), - usedInPath: worldgenBaseDirectory, + fromPath: path.join(path.dirname(system.sourcePath), symbolImport.path), + usedInPath: outDir, }; } else { // absolute import @@ -42,7 +44,7 @@ export async function worldgen( }; } }); - const systemInterfaceName = `I${system.basename}`; + const systemInterfaceName = `I${system.name}`; const output = renderSystemInterface({ name: systemInterfaceName, functionPrefix: config.namespace === "" ? "" : `${config.namespace}__`, @@ -51,7 +53,7 @@ export async function worldgen( imports, }); // write to file - const fullOutputPath = path.join(worldgenBaseDirectory, systemInterfaceName + ".sol"); + const fullOutputPath = path.join(rootDir, outDir, systemInterfaceName + ".sol"); await formatAndWriteSolidity(output, fullOutputPath, "Generated system interface"); // prepare imports for IWorld @@ -64,12 +66,12 @@ export async function worldgen( // render IWorld const output = renderWorldInterface({ - interfaceName: config.worldInterfaceName, + interfaceName: config.codegen.worldInterfaceName, imports: systemInterfaceImports, - storeImportPath: configV2.codegen.storeImportPath, - worldImportPath: config.worldImportPath, + storeImportPath: config.codegen.storeImportPath, + worldImportPath: config.codegen.worldImportPath, }); // write to file - const fullOutputPath = path.join(worldgenBaseDirectory, config.worldInterfaceName + ".sol"); + const fullOutputPath = path.join(rootDir, outDir, config.codegen.worldInterfaceName + ".sol"); await formatAndWriteSolidity(output, fullOutputPath, "Generated world interface"); } diff --git a/packages/world/ts/scripts/build.ts b/packages/world/ts/scripts/build.ts index 6d9401776e..8a44243225 100644 --- a/packages/world/ts/scripts/build.ts +++ b/packages/world/ts/scripts/build.ts @@ -2,7 +2,6 @@ import path from "node:path"; import { loadConfig, resolveConfigPath } from "@latticexyz/config/node"; import { getRemappings } from "@latticexyz/common/foundry"; import { tablegen } from "@latticexyz/store/codegen"; -import { findSolidityFiles } from "../node/findSolidityFiles"; import { World } from "../config/v2"; import { worldgen } from "../node"; @@ -18,24 +17,14 @@ const rootDir = path.dirname(configPath); const config = (await loadConfig(configPath)) as World; const remappings = await getRemappings(); -// TODO: move this into worldgen -const existingContracts = (await findSolidityFiles({ rootDir, config })).map((file) => ({ - path: file.filename, - basename: file.basename, -})); -const codegenDirectory = path.join(config.sourceDirectory, config.codegen.outputDirectory); - -// TODO: clean - await Promise.all([ tablegen({ rootDir, config, remappings }), - worldgen( - { + worldgen({ + rootDir, + config: { ...config, // override the namespace to be the root namespace for generating the core system interface namespace: "", }, - existingContracts, - codegenDirectory, - ), + }), ]); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 38b03accc0..9236c30209 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1087,6 +1087,9 @@ importers: packages/world-modules: dependencies: + '@latticexyz/cli': + specifier: workspace:* + version: link:../cli '@latticexyz/common': specifier: workspace:* version: link:../common diff --git a/test/mock-game-contracts/src/codegen/common.sol b/test/mock-game-contracts/src/codegen/common.sol index 2c1249cfb8..96d1607fc5 100644 --- a/test/mock-game-contracts/src/codegen/common.sol +++ b/test/mock-game-contracts/src/codegen/common.sol @@ -2,6 +2,7 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ + enum TerrainType { None, Ocean, From 214e2224596598d05eaf40fbc92655f9a2ffd248 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Tue, 16 Jul 2024 12:27:12 +0100 Subject: [PATCH 06/25] clean --- .../src/interfaces/IERC20System.sol | 33 -------------- .../src/interfaces/IERC721System.sol | 43 ------------------- .../src/interfaces/IPuppetFactorySystem.sol | 15 ------- .../src/interfaces/IUniqueEntitySystem.sol | 13 ------ .../IUnstable_CallWithSignatureSystem.sol | 20 --------- 5 files changed, 124 deletions(-) delete mode 100644 packages/world-modules/src/interfaces/IERC20System.sol delete mode 100644 packages/world-modules/src/interfaces/IERC721System.sol delete mode 100644 packages/world-modules/src/interfaces/IPuppetFactorySystem.sol delete mode 100644 packages/world-modules/src/interfaces/IUniqueEntitySystem.sol delete mode 100644 packages/world-modules/src/interfaces/IUnstable_CallWithSignatureSystem.sol diff --git a/packages/world-modules/src/interfaces/IERC20System.sol b/packages/world-modules/src/interfaces/IERC20System.sol deleted file mode 100644 index 18a6bd63a7..0000000000 --- a/packages/world-modules/src/interfaces/IERC20System.sol +++ /dev/null @@ -1,33 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity >=0.8.24; - -/* Autogenerated file. Do not edit manually. */ - -/** - * @title IERC20System - * @author MUD (https://mud.dev) by Lattice (https://lattice.xyz) - * @dev This interface is automatically generated from the corresponding system contract. Do not edit manually. - */ -interface IERC20System { - function name() external view returns (string memory); - - function symbol() external view returns (string memory); - - function decimals() external view returns (uint8); - - function totalSupply() external view returns (uint256); - - function balanceOf(address account) external view returns (uint256); - - function allowance(address owner, address spender) external view returns (uint256); - - function transfer(address to, uint256 value) external returns (bool); - - function approve(address spender, uint256 value) external returns (bool); - - function transferFrom(address from, address to, uint256 value) external returns (bool); - - function mint(address account, uint256 value) external; - - function burn(address account, uint256 value) external; -} diff --git a/packages/world-modules/src/interfaces/IERC721System.sol b/packages/world-modules/src/interfaces/IERC721System.sol deleted file mode 100644 index 58a9e86b41..0000000000 --- a/packages/world-modules/src/interfaces/IERC721System.sol +++ /dev/null @@ -1,43 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity >=0.8.24; - -/* Autogenerated file. Do not edit manually. */ - -/** - * @title IERC721System - * @author MUD (https://mud.dev) by Lattice (https://lattice.xyz) - * @dev This interface is automatically generated from the corresponding system contract. Do not edit manually. - */ -interface IERC721System { - function balanceOf(address owner) external view returns (uint256); - - function ownerOf(uint256 tokenId) external view returns (address); - - function name() external view returns (string memory); - - function symbol() external view returns (string memory); - - function tokenURI(uint256 tokenId) external view returns (string memory); - - function approve(address to, uint256 tokenId) external; - - function getApproved(uint256 tokenId) external view returns (address); - - function setApprovalForAll(address operator, bool approved) external; - - function isApprovedForAll(address owner, address operator) external view returns (bool); - - function transferFrom(address from, address to, uint256 tokenId) external; - - function safeTransferFrom(address from, address to, uint256 tokenId) external; - - function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) external; - - function mint(address to, uint256 tokenId) external; - - function safeMint(address to, uint256 tokenId) external; - - function safeMint(address to, uint256 tokenId, bytes memory data) external; - - function burn(uint256 tokenId) external; -} diff --git a/packages/world-modules/src/interfaces/IPuppetFactorySystem.sol b/packages/world-modules/src/interfaces/IPuppetFactorySystem.sol deleted file mode 100644 index 773b02e31b..0000000000 --- a/packages/world-modules/src/interfaces/IPuppetFactorySystem.sol +++ /dev/null @@ -1,15 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity >=0.8.24; - -/* Autogenerated file. Do not edit manually. */ - -import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; - -/** - * @title IPuppetFactorySystem - * @author MUD (https://mud.dev) by Lattice (https://lattice.xyz) - * @dev This interface is automatically generated from the corresponding system contract. Do not edit manually. - */ -interface IPuppetFactorySystem { - function createPuppet(ResourceId systemId) external returns (address puppet); -} diff --git a/packages/world-modules/src/interfaces/IUniqueEntitySystem.sol b/packages/world-modules/src/interfaces/IUniqueEntitySystem.sol deleted file mode 100644 index 91c66c9208..0000000000 --- a/packages/world-modules/src/interfaces/IUniqueEntitySystem.sol +++ /dev/null @@ -1,13 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity >=0.8.24; - -/* Autogenerated file. Do not edit manually. */ - -/** - * @title IUniqueEntitySystem - * @author MUD (https://mud.dev) by Lattice (https://lattice.xyz) - * @dev This interface is automatically generated from the corresponding system contract. Do not edit manually. - */ -interface IUniqueEntitySystem { - function getUniqueEntity() external returns (bytes32); -} diff --git a/packages/world-modules/src/interfaces/IUnstable_CallWithSignatureSystem.sol b/packages/world-modules/src/interfaces/IUnstable_CallWithSignatureSystem.sol deleted file mode 100644 index 035eb5306a..0000000000 --- a/packages/world-modules/src/interfaces/IUnstable_CallWithSignatureSystem.sol +++ /dev/null @@ -1,20 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity >=0.8.24; - -/* Autogenerated file. Do not edit manually. */ - -import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; - -/** - * @title IUnstable_CallWithSignatureSystem - * @author MUD (https://mud.dev) by Lattice (https://lattice.xyz) - * @dev This interface is automatically generated from the corresponding system contract. Do not edit manually. - */ -interface IUnstable_CallWithSignatureSystem { - function callWithSignature( - address signer, - ResourceId systemId, - bytes memory callData, - bytes memory signature - ) external payable returns (bytes memory); -} From 3e44df6c366008482cf58e05b47a6dba2a97b7c1 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Tue, 16 Jul 2024 12:27:48 +0100 Subject: [PATCH 07/25] update comment --- packages/world/ts/config/v2/input.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/world/ts/config/v2/input.ts b/packages/world/ts/config/v2/input.ts index 2967703ded..6cb5d6321f 100644 --- a/packages/world/ts/config/v2/input.ts +++ b/packages/world/ts/config/v2/input.ts @@ -90,7 +90,7 @@ export type WorldInput = show< * The value is a SystemConfig object. */ systems?: SystemsInput; - /** System names to exclude from automatic deployment */ + /** System names to exclude from codegen and deployment */ excludeSystems?: readonly string[]; /** Modules to in the World */ modules?: readonly ModuleInput[]; From 1c2e85acaa030ab26fadcdc9aeb568d8bbabb97e Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Tue, 16 Jul 2024 12:28:09 +0100 Subject: [PATCH 08/25] typo --- packages/world/ts/config/v2/input.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/world/ts/config/v2/input.ts b/packages/world/ts/config/v2/input.ts index 6cb5d6321f..df9c97f1e1 100644 --- a/packages/world/ts/config/v2/input.ts +++ b/packages/world/ts/config/v2/input.ts @@ -92,7 +92,7 @@ export type WorldInput = show< systems?: SystemsInput; /** System names to exclude from codegen and deployment */ excludeSystems?: readonly string[]; - /** Modules to in the World */ + /** Modules to install in the World */ modules?: readonly ModuleInput[]; /** Deploy config */ deploy?: DeployInput; From 6be45e316494f59e76a2bfa6cc8ed5e8e806ed23 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Tue, 16 Jul 2024 12:33:24 +0100 Subject: [PATCH 09/25] small clean up --- packages/cli/src/commands/trace.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/cli/src/commands/trace.ts b/packages/cli/src/commands/trace.ts index b203d6a33b..901131021c 100644 --- a/packages/cli/src/commands/trace.ts +++ b/packages/cli/src/commands/trace.ts @@ -13,12 +13,7 @@ import { getChainId } from "viem/actions"; import { World as WorldConfig } from "@latticexyz/world"; import { resolveSystems } from "@latticexyz/world/internal"; -// TODO account for multiple namespaces (https://github.com/latticexyz/mud/issues/994) -const systemsTableId = resourceToHex({ - type: "system", - namespace: worldConfig.namespace, - name: worldConfig.tables.world__Systems.name, -}); +const systemsTableId = worldConfig.tables.world__Systems.tableId; type Options = { tx: string; From cfaf5bcfd85f1d6fc57b1ab3646131d462bcbc9b Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Tue, 16 Jul 2024 12:37:13 +0100 Subject: [PATCH 10/25] remove v1 config from deploy --- packages/cli/src/runDeploy.ts | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/packages/cli/src/runDeploy.ts b/packages/cli/src/runDeploy.ts index cef9550e52..9ef63357c9 100644 --- a/packages/cli/src/runDeploy.ts +++ b/packages/cli/src/runDeploy.ts @@ -6,7 +6,6 @@ import { createWalletClient, http, Hex, isHex } from "viem"; import { privateKeyToAccount } from "viem/accounts"; import { loadConfig, resolveConfigPath } from "@latticexyz/config/node"; import { World as WorldConfig } from "@latticexyz/world"; -import { worldToV1 } from "@latticexyz/world/config/v2"; import { getOutDirectory, getRpcUrl } from "@latticexyz/common/foundry"; import chalk from "chalk"; import { MUDError } from "@latticexyz/common/errors"; @@ -64,9 +63,9 @@ export async function runDeploy(opts: DeployOptions): Promise { const profile = opts.profile ?? process.env.FOUNDRY_PROFILE; const configPath = await resolveConfigPath(opts.configPath); - const configV2 = (await loadConfig(configPath)) as WorldConfig; + const config = (await loadConfig(configPath)) as WorldConfig; const rootDir = path.dirname(configPath); - const config = worldToV1(configV2); + if (opts.printConfig) { console.log(chalk.green("\nResolved config:\n"), JSON.stringify(config, null, 2)); } @@ -82,15 +81,15 @@ export async function runDeploy(opts: DeployOptions): Promise { // Run build if (!opts.skipBuild) { - await build({ rootDir, config: configV2, foundryProfile: profile }); + await build({ rootDir, config, foundryProfile: profile }); } const { systems, libraries } = await resolveConfig({ rootDir, - config: configV2, + config, forgeOutDir: outDir, }); - const modules = await configToModules(configV2, outDir); + const modules = await configToModules(config, outDir); const account = await (async () => { if (opts.kms) { @@ -136,15 +135,15 @@ export async function runDeploy(opts: DeployOptions): Promise { salt, worldAddress: opts.worldAddress as Hex | undefined, client, - tables: Object.values(configV2.tables), + tables: Object.values(config.tables), systems, libraries, modules, - withWorldProxy: configV2.deploy.upgradeableWorldImplementation, + withWorldProxy: config.deploy.upgradeableWorldImplementation, }); if (opts.worldAddress == null || opts.alwaysRunPostDeploy) { await postDeploy( - config.postDeployScript, + config.deploy.postDeployScript, worldDeploy.address, rpc, profile, @@ -161,23 +160,27 @@ export async function runDeploy(opts: DeployOptions): Promise { if (opts.saveDeployment) { const chainId = await getChainId(client); - const deploysDir = path.join(config.deploysDirectory, chainId.toString()); + const deploysDir = path.join(config.deploy.deploysDirectory, chainId.toString()); mkdirSync(deploysDir, { recursive: true }); writeFileSync(path.join(deploysDir, "latest.json"), JSON.stringify(deploymentInfo, null, 2)); writeFileSync(path.join(deploysDir, Date.now() + ".json"), JSON.stringify(deploymentInfo, null, 2)); const localChains = [1337, 31337]; - const deploys = existsSync(config.worldsFile) ? JSON.parse(readFileSync(config.worldsFile, "utf-8")) : {}; + const deploys = existsSync(config.deploy.worldsFile) + ? JSON.parse(readFileSync(config.deploy.worldsFile, "utf-8")) + : {}; deploys[chainId] = { address: deploymentInfo.worldAddress, // We expect the worlds file to be committed and since local deployments are often // a consistent address but different block number, we'll ignore the block number. blockNumber: localChains.includes(chainId) ? undefined : deploymentInfo.blockNumber, }; - writeFileSync(config.worldsFile, JSON.stringify(deploys, null, 2)); + writeFileSync(config.deploy.worldsFile, JSON.stringify(deploys, null, 2)); console.log( - chalk.bgGreen(chalk.whiteBright(`\n Deployment result (written to ${config.worldsFile} and ${deploysDir}): \n`)), + chalk.bgGreen( + chalk.whiteBright(`\n Deployment result (written to ${config.deploy.worldsFile} and ${deploysDir}): \n`), + ), ); } From c19be853932b304042c58e4f2ac37725da9c4476 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Tue, 16 Jul 2024 14:10:20 +0100 Subject: [PATCH 11/25] separate system label --- packages/cli/src/deploy/common.ts | 1 + packages/cli/src/deploy/resolveConfig.ts | 5 +++-- packages/world/ts/config/resolveSystems.ts | 10 ++++++---- packages/world/ts/node/render-solidity/worldgen.ts | 4 ++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/cli/src/deploy/common.ts b/packages/cli/src/deploy/common.ts index 804b7db81e..cd0b3f0242 100644 --- a/packages/cli/src/deploy/common.ts +++ b/packages/cli/src/deploy/common.ts @@ -87,6 +87,7 @@ export type Library = DeterministicContract & { }; export type System = DeterministicContract & { + readonly label: string; readonly namespace: string; readonly name: string; readonly systemId: Hex; diff --git a/packages/cli/src/deploy/resolveConfig.ts b/packages/cli/src/deploy/resolveConfig.ts index 23448fd7de..976a845e15 100644 --- a/packages/cli/src/deploy/resolveConfig.ts +++ b/packages/cli/src/deploy/resolveConfig.ts @@ -49,7 +49,7 @@ export async function resolveConfig({ // TODO: replace with system.systemId const systemId = resourceToHex({ type: "system", namespace, name }); // TODO: replace system.name with system.label - const contractData = getContractData(`${system.name}.sol`, system.name, forgeOutDir); + const contractData = getContractData(`${system.label}.sol`, system.label, forgeOutDir); const systemFunctions = contractData.abi .filter((item): item is typeof item & { type: "function" } => item.type === "function") @@ -72,12 +72,13 @@ export async function resolveConfig({ const allowedSystemIds = system.accessList .filter((target) => !isHex(target)) .map((label) => { - const system = configSystems.find((s) => s.name === label)!; + const system = configSystems.find((s) => s.label === label)!; // TODO: replace with system.systemId return resourceToHex({ type: "system", namespace, name: system.name }); }); return { + label: system.label, namespace, name, systemId, diff --git a/packages/world/ts/config/resolveSystems.ts b/packages/world/ts/config/resolveSystems.ts index 1304b3d12a..4a83a4f78c 100644 --- a/packages/world/ts/config/resolveSystems.ts +++ b/packages/world/ts/config/resolveSystems.ts @@ -4,6 +4,8 @@ import { System, World } from "./v2"; import { SYSTEM_DEFAULTS } from "./v2/defaults"; export type ResolvedSystem = System & { + // TODO: move label into System config output + readonly label: string; readonly sourcePath: string; }; @@ -29,14 +31,14 @@ export async function resolveSystems({ const systemConfig = config.systems[contract.name] ?? { ...SYSTEM_DEFAULTS, name: contract.name }; return { ...systemConfig, + label: contract.name, sourcePath: contract.sourcePath, }; }) // TODO: replace `excludeSystems` with `deploy.disabled` or `codegen.disabled` - .filter((system) => !config.excludeSystems.includes(system.name)); + .filter((system) => !config.excludeSystems.includes(system.label)); - // TODO: replace `system.name` with `system.label` - const systemLabels = systems.map((system) => system.name); + const systemLabels = systems.map((system) => system.label); // validate every system has a valid access list for (const system of systems) { @@ -44,7 +46,7 @@ export async function resolveSystems({ if (isHex(accessListItem)) continue; if (systemLabels.includes(accessListItem)) continue; throw new Error( - `Access list item (${accessListItem}) for system (${system.name}) had no matching system contract.`, + `Access list item (${accessListItem}) for system (${system.label}) had no matching system contract.`, ); } } diff --git a/packages/world/ts/node/render-solidity/worldgen.ts b/packages/world/ts/node/render-solidity/worldgen.ts index 5a6adb8b3c..f65725a2d9 100644 --- a/packages/world/ts/node/render-solidity/worldgen.ts +++ b/packages/world/ts/node/render-solidity/worldgen.ts @@ -27,7 +27,7 @@ export async function worldgen({ for (const system of systems) { const data = fs.readFileSync(system.sourcePath, "utf8"); // get external funcions from a contract - const { functions, errors, symbolImports } = contractToInterface(data, system.name); + const { functions, errors, symbolImports } = contractToInterface(data, system.label); const imports = symbolImports.map((symbolImport) => { if (symbolImport.path[0] === ".") { // relative import @@ -44,7 +44,7 @@ export async function worldgen({ }; } }); - const systemInterfaceName = `I${system.name}`; + const systemInterfaceName = `I${system.label}`; const output = renderSystemInterface({ name: systemInterfaceName, functionPrefix: config.namespace === "" ? "" : `${config.namespace}__`, From d389bccf4ea5ba3061b406c1e8d39b1a301e0429 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Tue, 16 Jul 2024 14:37:55 +0100 Subject: [PATCH 12/25] update deploy tables --- packages/cli/src/deploy/ensureTables.ts | 32 ++++++++++----- packages/cli/src/deploy/getResourceIds.ts | 2 +- packages/cli/src/deploy/getTableValue.ts | 19 ++++++--- packages/cli/src/deploy/getTables.ts | 49 +++++++++++++++-------- 4 files changed, 68 insertions(+), 34 deletions(-) diff --git a/packages/cli/src/deploy/ensureTables.ts b/packages/cli/src/deploy/ensureTables.ts index 6fa4416c29..dd55ded9b4 100644 --- a/packages/cli/src/deploy/ensureTables.ts +++ b/packages/cli/src/deploy/ensureTables.ts @@ -1,12 +1,20 @@ import { Client, Transport, Chain, Account, Hex } from "viem"; -import { Table } from "./configToTables"; import { resourceToLabel, writeContract } from "@latticexyz/common"; import { WorldDeploy, worldAbi } from "./common"; -import { valueSchemaToFieldLayoutHex, keySchemaToHex, valueSchemaToHex } from "@latticexyz/protocol-parser/internal"; +import { + valueSchemaToFieldLayoutHex, + keySchemaToHex, + valueSchemaToHex, + getSchemaTypes, + getValueSchema, + getKeySchema, + KeySchema, +} from "@latticexyz/protocol-parser/internal"; import { debug } from "./debug"; import { getTables } from "./getTables"; import pRetry from "p-retry"; import { wait } from "@latticexyz/common/utils"; +import { Table } from "@latticexyz/config"; export async function ensureTables({ client, @@ -29,8 +37,10 @@ export async function ensureTables({ if (missingTables.length) { debug("registering tables", missingTables.map(resourceToLabel).join(", ")); return await Promise.all( - missingTables.map((table) => - pRetry( + missingTables.map((table) => { + const keySchema = getSchemaTypes(getValueSchema(table)); + const valueSchema = getSchemaTypes(getKeySchema(table)); + return pRetry( () => writeContract(client, { chain: client.chain ?? null, @@ -40,11 +50,11 @@ export async function ensureTables({ functionName: "registerTable", args: [ table.tableId, - valueSchemaToFieldLayoutHex(table.valueSchema), - keySchemaToHex(table.keySchema), - valueSchemaToHex(table.valueSchema), - Object.keys(table.keySchema), - Object.keys(table.valueSchema), + valueSchemaToFieldLayoutHex(valueSchema), + keySchemaToHex(keySchema as KeySchema), + valueSchemaToHex(valueSchema), + Object.keys(keySchema), + Object.keys(valueSchema), ], }), { @@ -55,8 +65,8 @@ export async function ensureTables({ await wait(delay); }, }, - ), - ), + ); + }), ); } diff --git a/packages/cli/src/deploy/getResourceIds.ts b/packages/cli/src/deploy/getResourceIds.ts index 239709f0df..d019b25d47 100644 --- a/packages/cli/src/deploy/getResourceIds.ts +++ b/packages/cli/src/deploy/getResourceIds.ts @@ -24,7 +24,7 @@ export async function getResourceIds({ fromBlock: worldDeploy.deployBlock, toBlock: worldDeploy.stateBlock, event: parseAbiItem(storeSpliceStaticDataEvent), - args: { tableId: storeTables.store_ResourceIds.tableId }, + args: { tableId: storeTables.store__ResourceIds.tableId }, }), { retries: 3, diff --git a/packages/cli/src/deploy/getTableValue.ts b/packages/cli/src/deploy/getTableValue.ts index c0bcc5d662..fbc63f5aba 100644 --- a/packages/cli/src/deploy/getTableValue.ts +++ b/packages/cli/src/deploy/getTableValue.ts @@ -1,8 +1,15 @@ -import { SchemaToPrimitives, decodeValueArgs, encodeKey } from "@latticexyz/protocol-parser/internal"; +import { + decodeValueArgs, + encodeKey, + getKeySchema, + getSchemaPrimitives, + getSchemaTypes, + getValueSchema, +} from "@latticexyz/protocol-parser/internal"; import { WorldDeploy, worldAbi } from "./common"; import { Client, Hex } from "viem"; import { readContract } from "viem/actions"; -import { Table } from "./configToTables"; +import { Table } from "@latticexyz/config"; export async function getTableValue
({ client, @@ -13,17 +20,17 @@ export async function getTableValue
({ readonly client: Client; readonly worldDeploy: WorldDeploy; readonly table: table; - readonly key: SchemaToPrimitives; -}): Promise> { + readonly key: getSchemaPrimitives>; +}): Promise>> { const [staticData, encodedLengths, dynamicData] = (await readContract(client, { blockNumber: worldDeploy.stateBlock, address: worldDeploy.address, abi: worldAbi, functionName: "getRecord", - args: [table.tableId, encodeKey(table.keySchema, key)], + args: [table.tableId, encodeKey(getSchemaTypes(getKeySchema(table)) as never, key as never)], // TODO: remove cast once https://github.com/wevm/viem/issues/2125 is resolved })) as [Hex, Hex, Hex]; - return decodeValueArgs(table.valueSchema, { + return decodeValueArgs(getSchemaTypes(getValueSchema(table)), { staticData, encodedLengths, dynamicData, diff --git a/packages/cli/src/deploy/getTables.ts b/packages/cli/src/deploy/getTables.ts index 660c593c1a..8dd07727d7 100644 --- a/packages/cli/src/deploy/getTables.ts +++ b/packages/cli/src/deploy/getTables.ts @@ -1,11 +1,18 @@ import { Client, parseAbiItem, decodeAbiParameters, parseAbiParameters } from "viem"; -import { Table } from "./configToTables"; import { hexToResource } from "@latticexyz/common"; import { WorldDeploy, storeTables } from "./common"; import { debug } from "./debug"; import { storeSetRecordEvent } from "@latticexyz/store"; import { getLogs } from "viem/actions"; -import { KeySchema, ValueSchema, decodeKey, decodeValueArgs, hexToSchema } from "@latticexyz/protocol-parser/internal"; +import { + decodeKey, + decodeValueArgs, + getKeySchema, + getSchemaTypes, + getValueSchema, + hexToSchema, +} from "@latticexyz/protocol-parser/internal"; +import { Schema, Table } from "@latticexyz/config"; export async function getTables({ client, @@ -27,30 +34,40 @@ export async function getTables({ toBlock: worldDeploy.stateBlock, address: worldDeploy.address, event: parseAbiItem(storeSetRecordEvent), - args: { tableId: storeTables.store_Tables.tableId }, + args: { tableId: storeTables.store__Tables.tableId }, }); // TODO: combine with store-sync logToTable and export from somewhere - const tables = logs.map((log) => { - const { tableId } = decodeKey(storeTables.store_Tables.keySchema, log.args.keyTuple); - const { namespace, name } = hexToResource(tableId); - const value = decodeValueArgs(storeTables.store_Tables.valueSchema, log.args); - - // TODO: migrate to better helper - const keySchemaFields = hexToSchema(value.keySchema); - const valueSchemaFields = hexToSchema(value.valueSchema); + const tables = logs.map((log): Table => { + const { tableId } = decodeKey(getSchemaTypes(getKeySchema(storeTables.store__Tables)), log.args.keyTuple); + const { type, namespace, name } = hexToResource(tableId); + const value = decodeValueArgs(getSchemaTypes(getValueSchema(storeTables.store__Tables)), log.args); + + const solidityKeySchema = hexToSchema(value.keySchema); + const solidityValueSchema = hexToSchema(value.valueSchema); const keyNames = decodeAbiParameters(parseAbiParameters("string[]"), value.abiEncodedKeyNames)[0]; const fieldNames = decodeAbiParameters(parseAbiParameters("string[]"), value.abiEncodedFieldNames)[0]; - const valueAbiTypes = [...valueSchemaFields.staticFields, ...valueSchemaFields.dynamicFields]; + const valueAbiTypes = [...solidityValueSchema.staticFields, ...solidityValueSchema.dynamicFields]; const keySchema = Object.fromEntries( - keySchemaFields.staticFields.map((abiType, i) => [keyNames[i], abiType]), - ) as KeySchema; - const valueSchema = Object.fromEntries(valueAbiTypes.map((abiType, i) => [fieldNames[i], abiType])) as ValueSchema; + solidityKeySchema.staticFields.map((abiType, i) => [keyNames[i], { type: abiType, internalType: abiType }]), + ) satisfies Schema; + + const valueSchema = Object.fromEntries( + valueAbiTypes.map((abiType, i) => [fieldNames[i], { type: abiType, internalType: abiType }]), + ) satisfies Schema; - return { namespace, name, tableId, keySchema, valueSchema } as const; + return { + type: type as never, + namespace, + name, + tableId, + schema: { ...keySchema, ...valueSchema }, + key: Object.keys(keySchema), + }; }); + // TODO: filter/detect duplicates? debug("found", tables.length, "tables for", worldDeploy.address); From 396f1a7345145649d1b0402a5a75c6c87a3eaee0 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Tue, 16 Jul 2024 14:48:19 +0100 Subject: [PATCH 13/25] more table updates --- packages/cli/src/deploy/common.ts | 2 +- .../cli/src/deploy/ensureNamespaceOwner.ts | 2 +- packages/cli/src/deploy/getFunctions.ts | 22 +++++++++++++------ packages/cli/src/deploy/getResourceAccess.ts | 10 +++++---- packages/cli/src/deploy/getSystems.ts | 2 +- packages/cli/src/deploy/resolveConfig.ts | 1 - 6 files changed, 24 insertions(+), 15 deletions(-) diff --git a/packages/cli/src/deploy/common.ts b/packages/cli/src/deploy/common.ts index cd0b3f0242..b1d38daefe 100644 --- a/packages/cli/src/deploy/common.ts +++ b/packages/cli/src/deploy/common.ts @@ -87,7 +87,7 @@ export type Library = DeterministicContract & { }; export type System = DeterministicContract & { - readonly label: string; + // TODO: add label readonly namespace: string; readonly name: string; readonly systemId: Hex; diff --git a/packages/cli/src/deploy/ensureNamespaceOwner.ts b/packages/cli/src/deploy/ensureNamespaceOwner.ts index 0771951e90..b90acc1f0f 100644 --- a/packages/cli/src/deploy/ensureNamespaceOwner.ts +++ b/packages/cli/src/deploy/ensureNamespaceOwner.ts @@ -35,7 +35,7 @@ export async function ensureNamespaceOwner({ const { owner } = await getTableValue({ client, worldDeploy, - table: worldTables.world_NamespaceOwner, + table: worldTables.world__NamespaceOwner, key: { namespaceId: resourceToHex({ type: "namespace", namespace, name: "" }) }, }); return [namespace, owner]; diff --git a/packages/cli/src/deploy/getFunctions.ts b/packages/cli/src/deploy/getFunctions.ts index 5508b49480..5d24a0a3f2 100644 --- a/packages/cli/src/deploy/getFunctions.ts +++ b/packages/cli/src/deploy/getFunctions.ts @@ -3,7 +3,13 @@ import { WorldDeploy, WorldFunction, worldTables } from "./common"; import { debug } from "./debug"; import { storeSetRecordEvent } from "@latticexyz/store"; import { getLogs } from "viem/actions"; -import { decodeKey, decodeValueArgs } from "@latticexyz/protocol-parser/internal"; +import { + decodeKey, + decodeValueArgs, + getKeySchema, + getSchemaTypes, + getValueSchema, +} from "@latticexyz/protocol-parser/internal"; export async function getFunctions({ client, @@ -20,13 +26,13 @@ export async function getFunctions({ toBlock: worldDeploy.stateBlock, address: worldDeploy.address, event: parseAbiItem(storeSetRecordEvent), - args: { tableId: worldTables.world_FunctionSelectors.tableId }, + args: { tableId: worldTables.world__FunctionSelectors.tableId }, }); const selectors = selectorLogs.map((log) => { return { - ...decodeValueArgs(worldTables.world_FunctionSelectors.valueSchema, log.args), - ...decodeKey(worldTables.world_FunctionSelectors.keySchema, log.args.keyTuple), + ...decodeValueArgs(getSchemaTypes(getValueSchema(worldTables.world__FunctionSelectors)), log.args), + ...decodeKey(getSchemaTypes(getKeySchema(worldTables.world__FunctionSelectors)), log.args.keyTuple), }; }); debug("found", selectors.length, "function selectors for", worldDeploy.address); @@ -39,14 +45,16 @@ export async function getFunctions({ toBlock: worldDeploy.stateBlock, address: worldDeploy.address, event: parseAbiItem(storeSetRecordEvent), - args: { tableId: worldTables.world_FunctionSignatures.tableId }, + args: { tableId: worldTables.world__FunctionSignatures.tableId }, }); const selectorToSignature = Object.fromEntries( signatureLogs.map((log) => { return [ - decodeKey(worldTables.world_FunctionSignatures.keySchema, log.args.keyTuple).functionSelector, - decodeValueArgs(worldTables.world_FunctionSignatures.valueSchema, log.args).functionSignature, + decodeKey(getSchemaTypes(getKeySchema(worldTables.world__FunctionSignatures)), log.args.keyTuple) + .functionSelector, + decodeValueArgs(getSchemaTypes(getValueSchema(worldTables.world__FunctionSignatures)), log.args) + .functionSignature, ]; }), ); diff --git a/packages/cli/src/deploy/getResourceAccess.ts b/packages/cli/src/deploy/getResourceAccess.ts index 56a2dbba8a..e35a50c9d2 100644 --- a/packages/cli/src/deploy/getResourceAccess.ts +++ b/packages/cli/src/deploy/getResourceAccess.ts @@ -3,7 +3,7 @@ import { WorldDeploy, worldTables } from "./common"; import { debug } from "./debug"; import { storeSpliceStaticDataEvent } from "@latticexyz/store"; import { getLogs } from "viem/actions"; -import { decodeKey } from "@latticexyz/protocol-parser/internal"; +import { decodeKey, getKeySchema, getSchemaTypes } from "@latticexyz/protocol-parser/internal"; import { getTableValue } from "./getTableValue"; export async function getResourceAccess({ @@ -26,16 +26,18 @@ export async function getResourceAccess({ // our usage of `ResourceAccess._set(...)` emits a splice instead of set record // TODO: https://github.com/latticexyz/mud/issues/479 event: parseAbiItem(storeSpliceStaticDataEvent), - args: { tableId: worldTables.world_ResourceAccess.tableId }, + args: { tableId: worldTables.world__ResourceAccess.tableId }, }); - const keys = logs.map((log) => decodeKey(worldTables.world_ResourceAccess.keySchema, log.args.keyTuple)); + const keys = logs.map((log) => + decodeKey(getSchemaTypes(getKeySchema(worldTables.world__ResourceAccess)), log.args.keyTuple), + ); const access = ( await Promise.all( keys.map( async (key) => - [key, await getTableValue({ client, worldDeploy, table: worldTables.world_ResourceAccess, key })] as const, + [key, await getTableValue({ client, worldDeploy, table: worldTables.world__ResourceAccess, key })] as const, ), ) ) diff --git a/packages/cli/src/deploy/getSystems.ts b/packages/cli/src/deploy/getSystems.ts index 1c2831e26e..43454d16e9 100644 --- a/packages/cli/src/deploy/getSystems.ts +++ b/packages/cli/src/deploy/getSystems.ts @@ -27,7 +27,7 @@ export async function getSystems({ const { system: address, publicAccess } = await getTableValue({ client, worldDeploy, - table: worldTables.world_Systems, + table: worldTables.world__Systems, key: { systemId: system.resourceId }, }); const systemFunctions = functions.filter((func) => func.systemId === system.resourceId); diff --git a/packages/cli/src/deploy/resolveConfig.ts b/packages/cli/src/deploy/resolveConfig.ts index 976a845e15..e8721a60e3 100644 --- a/packages/cli/src/deploy/resolveConfig.ts +++ b/packages/cli/src/deploy/resolveConfig.ts @@ -78,7 +78,6 @@ export async function resolveConfig({ }); return { - label: system.label, namespace, name, systemId, From 88b9d412fb8d99985be3bb3c049118c24727b2cc Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Tue, 16 Jul 2024 14:55:14 +0100 Subject: [PATCH 14/25] update snapshot --- packages/common/src/codegen/render-solidity/renderEnums.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/common/src/codegen/render-solidity/renderEnums.test.ts b/packages/common/src/codegen/render-solidity/renderEnums.test.ts index e9a41c4472..937595dc73 100644 --- a/packages/common/src/codegen/render-solidity/renderEnums.test.ts +++ b/packages/common/src/codegen/render-solidity/renderEnums.test.ts @@ -13,7 +13,6 @@ describe("renderEnums", () => { pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ - enum Direction { left, up, right, down From 0bd2e3d5e58c48f42363fd818894032ca6097c07 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Tue, 16 Jul 2024 15:07:47 +0100 Subject: [PATCH 15/25] small import adjustment --- packages/common/src/codegen/utils/formatAndWrite.ts | 12 ++++++------ packages/store/ts/codegen/tablegen.ts | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/common/src/codegen/utils/formatAndWrite.ts b/packages/common/src/codegen/utils/formatAndWrite.ts index 1121d58262..f315eddfd4 100644 --- a/packages/common/src/codegen/utils/formatAndWrite.ts +++ b/packages/common/src/codegen/utils/formatAndWrite.ts @@ -1,5 +1,5 @@ -import { mkdir, writeFile } from "fs/promises"; -import { dirname } from "path"; +import fs from "node:fs/promises"; +import path from "node:path"; import { formatSolidity, formatTypescript } from "./format"; import { debug } from "../debug"; @@ -12,9 +12,9 @@ import { debug } from "../debug"; export async function formatAndWriteSolidity(output: string, fullOutputPath: string, logPrefix: string): Promise { const formattedOutput = await formatSolidity(output); - await mkdir(dirname(fullOutputPath), { recursive: true }); + await fs.mkdir(path.dirname(fullOutputPath), { recursive: true }); - await writeFile(fullOutputPath, formattedOutput); + await fs.writeFile(fullOutputPath, formattedOutput); debug(`${logPrefix}: ${fullOutputPath}`); } @@ -31,8 +31,8 @@ export async function formatAndWriteTypescript( ): Promise { const formattedOutput = await formatTypescript(output); - await mkdir(dirname(fullOutputPath), { recursive: true }); + await fs.mkdir(path.dirname(fullOutputPath), { recursive: true }); - await writeFile(fullOutputPath, formattedOutput); + await fs.writeFile(fullOutputPath, formattedOutput); debug(`${logPrefix}: ${fullOutputPath}`); } diff --git a/packages/store/ts/codegen/tablegen.ts b/packages/store/ts/codegen/tablegen.ts index c8edf6a0ce..62ae3ef503 100644 --- a/packages/store/ts/codegen/tablegen.ts +++ b/packages/store/ts/codegen/tablegen.ts @@ -1,10 +1,10 @@ +import fs from "node:fs/promises"; import path from "node:path"; import { formatAndWriteSolidity, loadAndExtractUserTypes } from "@latticexyz/common/codegen"; import { getTableOptions } from "./tableOptions"; import { renderTable } from "./renderTable"; import { renderTypesFromConfig } from "./renderTypesFromConfig"; import { renderTableIndex } from "./renderTableIndex"; -import { rm } from "fs/promises"; import { Store as StoreConfig } from "../config/v2/output"; import { mapObject } from "@latticexyz/common/utils"; @@ -31,7 +31,7 @@ export async function tablegen({ rootDir, config, remappings }: TablegenOptions) const uniqueTableDirectories = Array.from(new Set(allTableOptions.map(({ outputPath }) => path.dirname(outputPath)))); await Promise.all( uniqueTableDirectories.map(async (tableDir) => { - await rm(path.join(outputDirectory, tableDir), { recursive: true, force: true }); + await fs.rm(path.join(outputDirectory, tableDir), { recursive: true, force: true }); }), ); From 1d7c0cc025839cbca5f309a83193ffe36bf5a224 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Tue, 16 Jul 2024 15:34:20 +0100 Subject: [PATCH 16/25] move to dev dep --- packages/world-modules/package.json | 2 +- pnpm-lock.yaml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/world-modules/package.json b/packages/world-modules/package.json index 63e00e5a33..e8b271611c 100644 --- a/packages/world-modules/package.json +++ b/packages/world-modules/package.json @@ -42,7 +42,6 @@ "test:ci": "pnpm run test" }, "dependencies": { - "@latticexyz/cli": "workspace:*", "@latticexyz/common": "workspace:*", "@latticexyz/config": "workspace:*", "@latticexyz/schema-type": "workspace:*", @@ -52,6 +51,7 @@ }, "devDependencies": { "@latticexyz/abi-ts": "workspace:*", + "@latticexyz/cli": "workspace:*", "@latticexyz/gas-report": "workspace:*", "@types/ejs": "^3.1.1", "@types/mocha": "^9.1.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9236c30209..c35e9cf157 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1087,9 +1087,6 @@ importers: packages/world-modules: dependencies: - '@latticexyz/cli': - specifier: workspace:* - version: link:../cli '@latticexyz/common': specifier: workspace:* version: link:../common @@ -1112,6 +1109,9 @@ importers: '@latticexyz/abi-ts': specifier: workspace:* version: link:../abi-ts + '@latticexyz/cli': + specifier: workspace:* + version: link:../cli '@latticexyz/gas-report': specifier: workspace:* version: link:../gas-report From 90a8fe9959466c411b8ebb562e52d40459815c88 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Tue, 16 Jul 2024 15:37:26 +0100 Subject: [PATCH 17/25] move resolveSystems into node export --- packages/cli/src/commands/trace.ts | 2 +- packages/cli/src/commands/verify.ts | 2 +- packages/cli/src/deploy/resolveConfig.ts | 2 +- packages/world/ts/exports/internal.ts | 1 - packages/world/ts/node/index.ts | 1 + packages/world/ts/node/render-solidity/worldgen.ts | 2 +- packages/world/ts/{config => node}/resolveSystems.ts | 6 +++--- 7 files changed, 8 insertions(+), 8 deletions(-) rename packages/world/ts/{config => node}/resolveSystems.ts (92%) diff --git a/packages/cli/src/commands/trace.ts b/packages/cli/src/commands/trace.ts index 901131021c..d3c5b4b656 100644 --- a/packages/cli/src/commands/trace.ts +++ b/packages/cli/src/commands/trace.ts @@ -11,7 +11,7 @@ import { resourceToHex } from "@latticexyz/common"; import { createClient, http } from "viem"; import { getChainId } from "viem/actions"; import { World as WorldConfig } from "@latticexyz/world"; -import { resolveSystems } from "@latticexyz/world/internal"; +import { resolveSystems } from "@latticexyz/world/node"; const systemsTableId = worldConfig.tables.world__Systems.tableId; diff --git a/packages/cli/src/commands/verify.ts b/packages/cli/src/commands/verify.ts index aed74f9cca..cfaa6e625c 100644 --- a/packages/cli/src/commands/verify.ts +++ b/packages/cli/src/commands/verify.ts @@ -2,7 +2,7 @@ import type { CommandModule, InferredOptionTypes } from "yargs"; import { verify } from "../verify"; import { loadConfig, resolveConfigPath } from "@latticexyz/config/node"; import { World as WorldConfig } from "@latticexyz/world"; -import { resolveSystems } from "@latticexyz/world/internal"; +import { resolveSystems } from "@latticexyz/world/node"; import { getOutDirectory, getRpcUrl } from "@latticexyz/common/foundry"; import { getContractData } from "../utils/getContractData"; import { Hex, createWalletClient, http } from "viem"; diff --git a/packages/cli/src/deploy/resolveConfig.ts b/packages/cli/src/deploy/resolveConfig.ts index e8721a60e3..6855edc344 100644 --- a/packages/cli/src/deploy/resolveConfig.ts +++ b/packages/cli/src/deploy/resolveConfig.ts @@ -1,5 +1,5 @@ import path from "path"; -import { resolveSystems } from "@latticexyz/world/internal"; +import { resolveSystems } from "@latticexyz/world/node"; import { Library, System, WorldFunction } from "./common"; import { resourceToHex } from "@latticexyz/common"; import { Hex, isHex, toFunctionSelector, toFunctionSignature } from "viem"; diff --git a/packages/world/ts/exports/internal.ts b/packages/world/ts/exports/internal.ts index 9c7a3d3915..c2bb98bcd6 100644 --- a/packages/world/ts/exports/internal.ts +++ b/packages/world/ts/exports/internal.ts @@ -1,5 +1,4 @@ export * from "../config/defaults"; -export * from "../config/resolveSystems"; export * from "../config/types"; export * from "../config/worldConfig"; diff --git a/packages/world/ts/node/index.ts b/packages/world/ts/node/index.ts index 4fcb666777..e73f48effc 100644 --- a/packages/world/ts/node/index.ts +++ b/packages/world/ts/node/index.ts @@ -1,3 +1,4 @@ export * from "./render-solidity"; export * from "./findSolidityFiles"; export * from "./getSystemContracts"; +export * from "./resolveSystems"; diff --git a/packages/world/ts/node/render-solidity/worldgen.ts b/packages/world/ts/node/render-solidity/worldgen.ts index f65725a2d9..a2df30ae66 100644 --- a/packages/world/ts/node/render-solidity/worldgen.ts +++ b/packages/world/ts/node/render-solidity/worldgen.ts @@ -4,7 +4,7 @@ import { formatAndWriteSolidity, contractToInterface, type RelativeImportDatum } import { renderSystemInterface } from "./renderSystemInterface"; import { renderWorldInterface } from "./renderWorldInterface"; import { World as WorldConfig } from "../../config/v2/output"; -import { resolveSystems } from "../../config/resolveSystems"; +import { resolveSystems } from "../resolveSystems"; export async function worldgen({ rootDir, diff --git a/packages/world/ts/config/resolveSystems.ts b/packages/world/ts/node/resolveSystems.ts similarity index 92% rename from packages/world/ts/config/resolveSystems.ts rename to packages/world/ts/node/resolveSystems.ts index 4a83a4f78c..1d22ee3e16 100644 --- a/packages/world/ts/config/resolveSystems.ts +++ b/packages/world/ts/node/resolveSystems.ts @@ -1,7 +1,7 @@ import { isHex } from "viem"; -import { getSystemContracts } from "../node"; -import { System, World } from "./v2"; -import { SYSTEM_DEFAULTS } from "./v2/defaults"; +import { getSystemContracts } from "."; +import { System, World } from "../config/v2"; +import { SYSTEM_DEFAULTS } from "../config/v2/defaults"; export type ResolvedSystem = System & { // TODO: move label into System config output From b627ef18ec19feadbd5d79eea4b800c43f5a2621 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Tue, 16 Jul 2024 15:59:02 +0100 Subject: [PATCH 18/25] copy pasta error --- packages/cli/src/deploy/ensureTables.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/deploy/ensureTables.ts b/packages/cli/src/deploy/ensureTables.ts index dd55ded9b4..03ae8ffec6 100644 --- a/packages/cli/src/deploy/ensureTables.ts +++ b/packages/cli/src/deploy/ensureTables.ts @@ -38,8 +38,8 @@ export async function ensureTables({ debug("registering tables", missingTables.map(resourceToLabel).join(", ")); return await Promise.all( missingTables.map((table) => { - const keySchema = getSchemaTypes(getValueSchema(table)); - const valueSchema = getSchemaTypes(getKeySchema(table)); + const keySchema = getSchemaTypes(getKeySchema(table)); + const valueSchema = getSchemaTypes(getValueSchema(table)); return pRetry( () => writeContract(client, { From e1904032715f0cb994bcf985201b85217acf25e6 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Tue, 16 Jul 2024 16:05:55 +0100 Subject: [PATCH 19/25] already cleaning --- packages/store/ts/codegen/tablegen.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/store/ts/codegen/tablegen.ts b/packages/store/ts/codegen/tablegen.ts index 62ae3ef503..af9c7aa1a7 100644 --- a/packages/store/ts/codegen/tablegen.ts +++ b/packages/store/ts/codegen/tablegen.ts @@ -8,8 +8,6 @@ import { renderTableIndex } from "./renderTableIndex"; import { Store as StoreConfig } from "../config/v2/output"; import { mapObject } from "@latticexyz/common/utils"; -// TODO: clean - export type TablegenOptions = { /** * MUD project root directory where all other relative paths are resolved from. From e65ab619f76fdf7e088eb2d063b276686cb5bbcf Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Tue, 16 Jul 2024 08:09:06 -0700 Subject: [PATCH 20/25] Create fuzzy-maps-sin.md --- .changeset/fuzzy-maps-sin.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/fuzzy-maps-sin.md diff --git a/.changeset/fuzzy-maps-sin.md b/.changeset/fuzzy-maps-sin.md new file mode 100644 index 0000000000..18b515c18f --- /dev/null +++ b/.changeset/fuzzy-maps-sin.md @@ -0,0 +1,5 @@ +--- +"@latticexyz/cli": patch +--- + +Refactored package to use the new Store/World configs under the hood, removing compatibility layers. From d6cdfe17cc3cea8743c92050273eda6ae1633001 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Tue, 16 Jul 2024 08:11:44 -0700 Subject: [PATCH 21/25] Create lazy-impalas-rush.md --- .changeset/lazy-impalas-rush.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/lazy-impalas-rush.md diff --git a/.changeset/lazy-impalas-rush.md b/.changeset/lazy-impalas-rush.md new file mode 100644 index 0000000000..54fbf517c0 --- /dev/null +++ b/.changeset/lazy-impalas-rush.md @@ -0,0 +1,5 @@ +--- +"@latticexyz/world": patch +--- + +Refactored how worldgen resolves systems from the config and filesystem. From 5820fa62a2260b2f615ca004a543033f5c382bf9 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Tue, 16 Jul 2024 16:17:50 +0100 Subject: [PATCH 22/25] adjust world codegen dir and gitignore it --- packages/world-modules/.gitignore | 2 ++ packages/world-modules/mud.config.ts | 3 +-- .../world-modules/src/interfaces/IBaseWorld.sol | 16 ---------------- 3 files changed, 3 insertions(+), 18 deletions(-) delete mode 100644 packages/world-modules/src/interfaces/IBaseWorld.sol diff --git a/packages/world-modules/.gitignore b/packages/world-modules/.gitignore index 411b5668db..5ff362ddd2 100644 --- a/packages/world-modules/.gitignore +++ b/packages/world-modules/.gitignore @@ -6,3 +6,5 @@ DOCS.md artifacts yarn-error.log API + +src/codegen diff --git a/packages/world-modules/mud.config.ts b/packages/world-modules/mud.config.ts index c9813db299..d1e6e8430c 100644 --- a/packages/world-modules/mud.config.ts +++ b/packages/world-modules/mud.config.ts @@ -2,8 +2,7 @@ import { defineWorld } from "@latticexyz/world"; export default defineWorld({ codegen: { - worldgenDirectory: "interfaces", - worldInterfaceName: "IBaseWorld", + worldgenDirectory: "codegen/world", outputDirectory: ".", }, userTypes: { diff --git a/packages/world-modules/src/interfaces/IBaseWorld.sol b/packages/world-modules/src/interfaces/IBaseWorld.sol deleted file mode 100644 index c71f2becc9..0000000000 --- a/packages/world-modules/src/interfaces/IBaseWorld.sol +++ /dev/null @@ -1,16 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity >=0.8.24; - -/* Autogenerated file. Do not edit manually. */ - -import { IStore } from "@latticexyz/store/src/IStore.sol"; -import { IWorldKernel } from "@latticexyz/world/src/IWorldKernel.sol"; - -/** - * @title IBaseWorld - * @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 IBaseWorld is IStore, IWorldKernel {} From 991b1d060930185ea66771163ee6efee1bd8f7cc Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Tue, 16 Jul 2024 08:19:08 -0700 Subject: [PATCH 23/25] Create old-waves-juggle.md --- .changeset/old-waves-juggle.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changeset/old-waves-juggle.md diff --git a/.changeset/old-waves-juggle.md b/.changeset/old-waves-juggle.md new file mode 100644 index 0000000000..58f62d1012 --- /dev/null +++ b/.changeset/old-waves-juggle.md @@ -0,0 +1,7 @@ +--- +"@latticexyz/world-modules": patch +--- + +Moved build scripts to `mud build` now that CLI doesn't depend on this package. + +Removed generated world interfaces as this package isn't meant to be used as a "world", but as a set of individual modules. From f8bc980f28b6a0307381c9344a8b09dbdc263f63 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Tue, 16 Jul 2024 16:23:03 +0100 Subject: [PATCH 24/25] another tweak for codegen --- packages/world-modules/mud.config.ts | 44 +++++++++++++--------------- packages/world-modules/src/index.sol | 25 ---------------- 2 files changed, 20 insertions(+), 49 deletions(-) delete mode 100644 packages/world-modules/src/index.sol diff --git a/packages/world-modules/mud.config.ts b/packages/world-modules/mud.config.ts index d1e6e8430c..6bf21c83b2 100644 --- a/packages/world-modules/mud.config.ts +++ b/packages/world-modules/mud.config.ts @@ -1,10 +1,6 @@ import { defineWorld } from "@latticexyz/world"; export default defineWorld({ - codegen: { - worldgenDirectory: "codegen/world", - outputDirectory: ".", - }, userTypes: { ResourceId: { filePath: "@latticexyz/store/src/ResourceId.sol", type: "bytes32" }, }, @@ -21,7 +17,7 @@ export default defineWorld({ }, key: ["valueHash"], codegen: { - outputDirectory: "modules/keyswithvalue/tables", + outputDirectory: "../modules/keyswithvalue/tables", tableIdArgument: true, storeArgument: true, }, @@ -42,7 +38,7 @@ export default defineWorld({ }, key: ["sourceTableId"], codegen: { - outputDirectory: "modules/keysintable/tables", + outputDirectory: "../modules/keysintable/tables", storeArgument: true, }, }, @@ -55,7 +51,7 @@ export default defineWorld({ }, key: ["sourceTableId", "keysHash"], codegen: { - outputDirectory: "modules/keysintable/tables", + outputDirectory: "../modules/keysintable/tables", dataStruct: false, storeArgument: true, }, @@ -71,7 +67,7 @@ export default defineWorld({ }, key: [], codegen: { - outputDirectory: "modules/uniqueentity/tables", + outputDirectory: "../modules/uniqueentity/tables", tableIdArgument: true, storeArgument: true, }, @@ -91,7 +87,7 @@ export default defineWorld({ }, key: ["delegator", "delegatee", "systemId", "callDataHash"], codegen: { - outputDirectory: "modules/std-delegations/tables", + outputDirectory: "../modules/std-delegations/tables", }, }, SystemboundDelegations: { @@ -103,7 +99,7 @@ export default defineWorld({ }, key: ["delegator", "delegatee", "systemId"], codegen: { - outputDirectory: "modules/std-delegations/tables", + outputDirectory: "../modules/std-delegations/tables", }, }, TimeboundDelegations: { @@ -114,7 +110,7 @@ export default defineWorld({ }, key: ["delegator", "delegatee"], codegen: { - outputDirectory: "modules/std-delegations/tables", + outputDirectory: "../modules/std-delegations/tables", }, }, /************************************************************************ @@ -129,7 +125,7 @@ export default defineWorld({ }, key: ["systemId"], codegen: { - outputDirectory: "modules/puppet/tables", + outputDirectory: "../modules/puppet/tables", tableIdArgument: true, }, }, @@ -145,7 +141,7 @@ export default defineWorld({ }, key: ["account"], codegen: { - outputDirectory: "modules/tokens/tables", + outputDirectory: "../modules/tokens/tables", tableIdArgument: true, }, }, @@ -162,7 +158,7 @@ export default defineWorld({ }, key: [], codegen: { - outputDirectory: "modules/erc20-puppet/tables", + outputDirectory: "../modules/erc20-puppet/tables", tableIdArgument: true, }, }, @@ -174,7 +170,7 @@ export default defineWorld({ }, key: ["account", "spender"], codegen: { - outputDirectory: "modules/erc20-puppet/tables", + outputDirectory: "../modules/erc20-puppet/tables", tableIdArgument: true, }, }, @@ -184,7 +180,7 @@ export default defineWorld({ }, key: [], codegen: { - outputDirectory: "modules/erc20-puppet/tables", + outputDirectory: "../modules/erc20-puppet/tables", tableIdArgument: true, }, }, @@ -195,7 +191,7 @@ export default defineWorld({ }, key: ["namespaceId"], codegen: { - outputDirectory: "modules/erc20-puppet/tables", + outputDirectory: "../modules/erc20-puppet/tables", tableIdArgument: true, }, }, @@ -212,7 +208,7 @@ export default defineWorld({ }, key: [], codegen: { - outputDirectory: "modules/erc721-puppet/tables", + outputDirectory: "../modules/erc721-puppet/tables", tableIdArgument: true, }, }, @@ -223,7 +219,7 @@ export default defineWorld({ }, key: ["tokenId"], codegen: { - outputDirectory: "modules/erc721-puppet/tables", + outputDirectory: "../modules/erc721-puppet/tables", tableIdArgument: true, }, }, @@ -234,7 +230,7 @@ export default defineWorld({ }, key: ["tokenId"], codegen: { - outputDirectory: "modules/erc721-puppet/tables", + outputDirectory: "../modules/erc721-puppet/tables", tableIdArgument: true, }, }, @@ -245,7 +241,7 @@ export default defineWorld({ }, key: ["tokenId"], codegen: { - outputDirectory: "modules/erc721-puppet/tables", + outputDirectory: "../modules/erc721-puppet/tables", tableIdArgument: true, }, }, @@ -257,7 +253,7 @@ export default defineWorld({ }, key: ["owner", "operator"], codegen: { - outputDirectory: "modules/erc721-puppet/tables", + outputDirectory: "../modules/erc721-puppet/tables", tableIdArgument: true, }, }, @@ -268,7 +264,7 @@ export default defineWorld({ }, key: ["namespaceId"], codegen: { - outputDirectory: "modules/erc721-puppet/tables", + outputDirectory: "../modules/erc721-puppet/tables", tableIdArgument: true, }, }, @@ -281,7 +277,7 @@ export default defineWorld({ schema: { signer: "address", nonce: "uint256" }, key: ["signer"], codegen: { - outputDirectory: "modules/callwithsignature/tables", + outputDirectory: "../modules/callwithsignature/tables", }, }, }, diff --git a/packages/world-modules/src/index.sol b/packages/world-modules/src/index.sol deleted file mode 100644 index 5fa265ec1f..0000000000 --- a/packages/world-modules/src/index.sol +++ /dev/null @@ -1,25 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity >=0.8.24; - -/* Autogenerated file. Do not edit manually. */ - -import { KeysWithValue } from "./modules/keyswithvalue/tables/KeysWithValue.sol"; -import { KeysInTable, KeysInTableData } from "./modules/keysintable/tables/KeysInTable.sol"; -import { UsedKeysIndex } from "./modules/keysintable/tables/UsedKeysIndex.sol"; -import { UniqueEntity } from "./modules/uniqueentity/tables/UniqueEntity.sol"; -import { CallboundDelegations } from "./modules/std-delegations/tables/CallboundDelegations.sol"; -import { SystemboundDelegations } from "./modules/std-delegations/tables/SystemboundDelegations.sol"; -import { TimeboundDelegations } from "./modules/std-delegations/tables/TimeboundDelegations.sol"; -import { PuppetRegistry } from "./modules/puppet/tables/PuppetRegistry.sol"; -import { Balances } from "./modules/tokens/tables/Balances.sol"; -import { ERC20Metadata, ERC20MetadataData } from "./modules/erc20-puppet/tables/ERC20Metadata.sol"; -import { Allowances } from "./modules/erc20-puppet/tables/Allowances.sol"; -import { TotalSupply } from "./modules/erc20-puppet/tables/TotalSupply.sol"; -import { ERC20Registry } from "./modules/erc20-puppet/tables/ERC20Registry.sol"; -import { ERC721Metadata, ERC721MetadataData } from "./modules/erc721-puppet/tables/ERC721Metadata.sol"; -import { TokenURI } from "./modules/erc721-puppet/tables/TokenURI.sol"; -import { Owners } from "./modules/erc721-puppet/tables/Owners.sol"; -import { TokenApproval } from "./modules/erc721-puppet/tables/TokenApproval.sol"; -import { OperatorApproval } from "./modules/erc721-puppet/tables/OperatorApproval.sol"; -import { ERC721Registry } from "./modules/erc721-puppet/tables/ERC721Registry.sol"; -import { CallWithSignatureNonces } from "./modules/callwithsignature/tables/CallWithSignatureNonces.sol"; From bd299acbf5964787e158f83c8bb05f36c44bb993 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Tue, 16 Jul 2024 08:30:53 -0700 Subject: [PATCH 25/25] Update fuzzy-maps-sin.md --- .changeset/fuzzy-maps-sin.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.changeset/fuzzy-maps-sin.md b/.changeset/fuzzy-maps-sin.md index 18b515c18f..78e690ab5e 100644 --- a/.changeset/fuzzy-maps-sin.md +++ b/.changeset/fuzzy-maps-sin.md @@ -3,3 +3,5 @@ --- Refactored package to use the new Store/World configs under the hood, removing compatibility layers. + +Removed `--srcDir` option from all commands in favor of using `sourceDirectory` in the project's MUD config.