diff --git a/packages/world/package.json b/packages/world/package.json index ffb779a9df..5a81a2301f 100644 --- a/packages/world/package.json +++ b/packages/world/package.json @@ -10,7 +10,7 @@ "license": "MIT", "type": "module", "exports": { - ".": "./dist/ts/library/index.js", + ".": "./dist/ts/index.js", "./register": "./dist/ts/register/index.js", "./node": "./dist/ts/node/index.js", "./out/*": "./out/*", @@ -19,7 +19,7 @@ "typesVersions": { "*": { "index": [ - "./ts/library/index.ts" + "./ts/index.ts" ], "register": [ "./ts/register/index.ts" @@ -50,6 +50,7 @@ "@latticexyz/config": "workspace:*", "@latticexyz/schema-type": "workspace:*", "@latticexyz/store": "workspace:*", + "abitype": "0.9.8", "zod": "^3.21.4" }, "devDependencies": { diff --git a/packages/world/ts/library/config/defaults.ts b/packages/world/ts/config/defaults.ts similarity index 100% rename from packages/world/ts/library/config/defaults.ts rename to packages/world/ts/config/defaults.ts diff --git a/packages/world/ts/library/config/resolveWorldConfig.ts b/packages/world/ts/config/resolveWorldConfig.ts similarity index 100% rename from packages/world/ts/library/config/resolveWorldConfig.ts rename to packages/world/ts/config/resolveWorldConfig.ts diff --git a/packages/world/ts/library/config/types.ts b/packages/world/ts/config/types.ts similarity index 100% rename from packages/world/ts/library/config/types.ts rename to packages/world/ts/config/types.ts diff --git a/packages/world/ts/library/config/worldConfig.test-d.ts b/packages/world/ts/config/worldConfig.test-d.ts similarity index 100% rename from packages/world/ts/library/config/worldConfig.test-d.ts rename to packages/world/ts/config/worldConfig.test-d.ts diff --git a/packages/world/ts/library/config/worldConfig.ts b/packages/world/ts/config/worldConfig.ts similarity index 100% rename from packages/world/ts/library/config/worldConfig.ts rename to packages/world/ts/config/worldConfig.ts diff --git a/packages/world/ts/index.ts b/packages/world/ts/index.ts new file mode 100644 index 0000000000..f5fa677ff8 --- /dev/null +++ b/packages/world/ts/index.ts @@ -0,0 +1,5 @@ +export * from "./config/defaults"; +export * from "./config/resolveWorldConfig"; +export * from "./config/types"; +export * from "./config/worldConfig"; +export * from "./worldEvents"; diff --git a/packages/world/ts/library/config/index.ts b/packages/world/ts/library/config/index.ts deleted file mode 100644 index 8509da16f9..0000000000 --- a/packages/world/ts/library/config/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from "./defaults"; -export * from "./resolveWorldConfig"; -export * from "./types"; -export * from "./worldConfig"; diff --git a/packages/world/ts/library/index.ts b/packages/world/ts/library/index.ts deleted file mode 100644 index 5c62e04f5e..0000000000 --- a/packages/world/ts/library/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./config"; diff --git a/packages/world/ts/node/render-solidity/worldgen.ts b/packages/world/ts/node/render-solidity/worldgen.ts index a24e790cde..7c67686170 100644 --- a/packages/world/ts/node/render-solidity/worldgen.ts +++ b/packages/world/ts/node/render-solidity/worldgen.ts @@ -4,7 +4,8 @@ import { formatAndWriteSolidity, contractToInterface, type RelativeImportDatum } import { StoreConfig } from "@latticexyz/store"; import { renderSystemInterface } from "./renderSystemInterface"; import { renderWorld } from "./renderWorld"; -import { resolveWorldConfig, WorldConfig } from "../../library/config"; +import { resolveWorldConfig } from "../../config/resolveWorldConfig"; +import { WorldConfig } from "../../config/types"; export async function worldgen( config: StoreConfig & WorldConfig, diff --git a/packages/world/ts/register/configExtensions.ts b/packages/world/ts/register/configExtensions.ts index 75be2a7ac7..917c46465a 100644 --- a/packages/world/ts/register/configExtensions.ts +++ b/packages/world/ts/register/configExtensions.ts @@ -1,6 +1,6 @@ import { extendMUDCoreConfig, fromZodErrorCustom } from "@latticexyz/config"; import { ZodError } from "zod"; -import { zPluginWorldConfig } from "../library"; +import { zPluginWorldConfig } from "../config/worldConfig"; extendMUDCoreConfig((config) => { // This function gets called within mudConfig. diff --git a/packages/world/ts/register/index.test.ts b/packages/world/ts/register/index.test.ts index 71d4d0c8e7..64d43f89ef 100644 --- a/packages/world/ts/register/index.test.ts +++ b/packages/world/ts/register/index.test.ts @@ -1,6 +1,6 @@ import { expect, test } from "vitest"; import { mudConfig } from "."; -import { resolveWorldConfig } from "../library"; +import { resolveWorldConfig } from "../config/resolveWorldConfig"; test("resolveWorldConfig requires unique table and system names", () => { expect(() => diff --git a/packages/world/ts/register/typeExtensions.ts b/packages/world/ts/register/typeExtensions.ts index f9215ef873..9d986fa33c 100644 --- a/packages/world/ts/register/typeExtensions.ts +++ b/packages/world/ts/register/typeExtensions.ts @@ -1,8 +1,9 @@ import { OrDefaults } from "@latticexyz/common/type-utils"; import { MUDCoreUserConfig } from "@latticexyz/config"; -import { ExpandSystemsConfig, WorldConfig, WorldUserConfig, WORLD_DEFAULTS } from "../library"; import "@latticexyz/store/register"; +import { WORLD_DEFAULTS } from "../config/defaults"; +import { WorldUserConfig, WorldConfig, ExpandSystemsConfig } from "../config/types"; // Inject the plugin options into the core config. // Re-exporting an interface of an existing module merges them, adding new options to the interface. diff --git a/packages/world/ts/scripts/worldgen.ts b/packages/world/ts/scripts/worldgen.ts index 6a88cfa7e7..6eedbc3706 100644 --- a/packages/world/ts/scripts/worldgen.ts +++ b/packages/world/ts/scripts/worldgen.ts @@ -3,9 +3,9 @@ import path, { basename } from "path"; import { rmSync } from "fs"; import { loadConfig } from "@latticexyz/config/node"; import { getSrcDirectory } from "@latticexyz/common/foundry"; -import { WorldConfig } from "../library"; import { worldgen } from "../node"; import { StoreConfig } from "@latticexyz/store"; +import { WorldConfig } from "../config/types"; // TODO dedupe this and cli's worldgen command const configPath = undefined; diff --git a/packages/world/ts/worldEvents.test.ts b/packages/world/ts/worldEvents.test.ts new file mode 100644 index 0000000000..080a1740fa --- /dev/null +++ b/packages/world/ts/worldEvents.test.ts @@ -0,0 +1,33 @@ +import { describe, expect, it } from "vitest"; +import IWorldFactoryAbi from "../out/IWorldFactory.sol/IWorldFactory.abi.json"; +import IBaseWorldAbi from "../out/IBaseWorld.sol/IBaseWorld.abi.json"; +import { helloWorldEvent, worldDeployedEvent } from "./worldEvents"; +import { parseAbiItem, AbiEvent } from "abitype"; + +function normalizeAbiEvent(event: AbiEvent) { + return { + type: event.type, + name: event.name, + inputs: event.inputs.map((input) => ({ + type: input.type, + name: input.name, + ...(input.indexed ? { indexed: true } : null), + })), + } as const; +} + +describe("WorldFactory events", () => { + it("should match the ABI", () => { + const forgeAbiItem = IWorldFactoryAbi.find( + (item) => item.type === "event" && item.name === "WorldDeployed" + ) as AbiEvent; + expect(normalizeAbiEvent(parseAbiItem(worldDeployedEvent))).toMatchObject(normalizeAbiEvent(forgeAbiItem)); + }); +}); + +describe("World events", () => { + it("should match the ABI", () => { + const forgeAbiItem = IBaseWorldAbi.find((item) => item.type === "event" && item.name === "HelloWorld") as AbiEvent; + expect(normalizeAbiEvent(parseAbiItem(helloWorldEvent))).toMatchObject(normalizeAbiEvent(forgeAbiItem)); + }); +}); diff --git a/packages/world/ts/worldEvents.ts b/packages/world/ts/worldEvents.ts new file mode 100644 index 0000000000..626b7cfbfd --- /dev/null +++ b/packages/world/ts/worldEvents.ts @@ -0,0 +1,5 @@ +// from WorldFactory +export const worldDeployedEvent = "event WorldDeployed(address indexed newContract)"; + +// from World +export const helloWorldEvent = "event HelloWorld(bytes32 indexed worldVersion)"; diff --git a/packages/world/tsconfig.json b/packages/world/tsconfig.json index e915cf3f6a..9060822400 100644 --- a/packages/world/tsconfig.json +++ b/packages/world/tsconfig.json @@ -15,6 +15,5 @@ "strict": true, "skipLibCheck": true }, - "include": ["mud.config.ts", "ts"], - "exclude": ["ts/plugins"] + "include": ["mud.config.ts", "ts"] } diff --git a/packages/world/tsup.config.ts b/packages/world/tsup.config.ts index 8217d6fa02..4d76cecf16 100644 --- a/packages/world/tsup.config.ts +++ b/packages/world/tsup.config.ts @@ -1,7 +1,7 @@ import { defineConfig } from "tsup"; export default defineConfig({ - entry: ["mud.config.ts", "ts/library/index.ts", "ts/register/index.ts", "ts/node/index.ts"], + entry: ["mud.config.ts", "ts/index.ts", "ts/register/index.ts", "ts/node/index.ts"], target: "esnext", format: ["esm"], dts: false, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e57b291ce2..6e83dd89fb 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -986,6 +986,9 @@ importers: '@latticexyz/store': specifier: workspace:* version: link:../store + abitype: + specifier: 0.9.8 + version: 0.9.8(typescript@5.1.6)(zod@3.21.4) zod: specifier: ^3.21.4 version: 3.21.4