Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use new config #2483

Merged
merged 17 commits into from
Mar 20, 2024
11 changes: 11 additions & 0 deletions .changeset/yellow-bulldogs-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@latticexyz/cli": major
"@latticexyz/dev-tools": major
"@latticexyz/store-sync": major
"@latticexyz/store": major
"@latticexyz/world-modules": major
"@latticexyz/world": major
"create-mud": major
---

Migrated to new config format.
8 changes: 2 additions & 6 deletions e2e/packages/client-vanilla/src/mud/setupNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { encodeEntity, syncToRecs } from "@latticexyz/store-sync/recs";
import { getNetworkConfig } from "./getNetworkConfig";
import { world } from "./world";
import IWorldAbi from "contracts/out/IWorld.sol/IWorld.abi.json";
import { createBurnerAccount, getContract, resourceToHex, transportObserver } from "@latticexyz/common";
import { createBurnerAccount, getContract, transportObserver } from "@latticexyz/common";
import mudConfig from "contracts/mud.config";

export type SetupNetworkResult = Awaited<ReturnType<typeof setupNetwork>>;
Expand Down Expand Up @@ -40,11 +40,7 @@ export async function setupNetwork() {
startBlock: BigInt(networkConfig.initialBlockNumber),
indexerUrl: networkConfig.indexerUrl ?? undefined,
filters: Object.entries(mudConfig.tables).map(([, table]) => {
const tableId = resourceToHex({
type: table.offchainOnly ? "offchainTable" : "table",
namespace: mudConfig.namespace,
name: table.name,
});
const tableId = table.tableId;
if (table.name === mudConfig.tables.Position.name) {
return {
tableId,
Expand Down
34 changes: 16 additions & 18 deletions e2e/packages/contracts/mud.config.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,53 @@
import { mudConfig } from "@latticexyz/world/register";
import { defineWorld } from "@latticexyz/world/config/v2";

export default mudConfig({
export default defineWorld({
tables: {
Number: {
keySchema: {
schema: {
key: "uint32",
},
valueSchema: {
value: "uint32",
},
key: ["key"],
},
Vector: {
keySchema: {
schema: {
key: "uint32",
},
valueSchema: {
x: "int32",
y: "int32",
},
key: ["key"],
},
NumberList: {
keySchema: {},
valueSchema: {
schema: {
value: "uint32[]",
},
key: [],
},
Multi: {
keySchema: {
schema: {
a: "uint32",
b: "bool",
c: "uint256",
d: "int120",
},
valueSchema: {
num: "int256",
value: "bool",
},
key: ["a", "b", "c", "d"],
},
Position: {
keySchema: {
schema: {
zone: "bytes32",
x: "int32",
y: "int32",
},
valueSchema: {
player: "address",
},
key: ["zone", "x", "y"],
},
StaticArray: {
keySchema: {},
valueSchema: "uint256[3]",
schema: {
value: "uint256[3]",
},
key: [],
},
},
});
5 changes: 4 additions & 1 deletion e2e/packages/sync-test/data/encodeTestData.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { mapObject } from "@latticexyz/utils";
import { encodeKey, encodeValueArgs, valueSchemaToFieldLayoutHex } from "@latticexyz/protocol-parser/internal";
import { Data, EncodedData } from "./types";
import config from "../../contracts/mud.config";
import configV2 from "../../contracts/mud.config";
import { worldToV1 } from "@latticexyz/world/config/v2";

const config = worldToV1(configV2);

/**
* Turns the typed data into encoded data in the format expected by `world.setRecord`
Expand Down
5 changes: 4 additions & 1 deletion e2e/packages/sync-test/data/expectClientData.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { Page, expect } from "@playwright/test";
import { Data } from "./types";
import config from "../../contracts/mud.config";
import configV2 from "../../contracts/mud.config";
import { encodeEntity } from "@latticexyz/store-sync/recs";
import { callPageFunction } from "./callPageFunction";
import { worldToV1 } from "@latticexyz/world/config/v2";

const config = worldToV1(configV2);

/**
* Confirms that the client state equals the given state by reading from the client's data store
Expand Down
6 changes: 5 additions & 1 deletion e2e/packages/sync-test/data/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// Note: this expects the config to not use shortcuts but the full definitions for table schemas
import { SchemaAbiType, SchemaAbiTypeToPrimitiveType } from "@latticexyz/schema-type/internal";
import config from "../../contracts/mud.config";
import configV2 from "../../contracts/mud.config";
import { Hex } from "viem";
import { worldToV1 } from "@latticexyz/world/config/v2";

const config = worldToV1(configV2);

type SchemaToPrimitive<Schema> =
Schema extends Record<string, SchemaAbiType>
? { [key in keyof Schema]: SchemaAbiTypeToPrimitiveType<Schema[key]> }
Expand Down
1 change: 1 addition & 0 deletions e2e/packages/sync-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@latticexyz/store": "link:../../../packages/store",
"@latticexyz/store-sync": "link:../../../packages/store-sync",
"@latticexyz/utils": "link:../../../packages/utils",
"@latticexyz/world": "link:../../../packages/world",
"@viem/anvil": "^0.0.6",
"abitype": "1.0.0",
"chalk": "^5.2.0",
Expand Down
3 changes: 3 additions & 0 deletions e2e/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions examples/minimal/packages/contracts/mud.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { mudConfig } from "@latticexyz/world/register";

import { defineWorld } from "@latticexyz/world/config/v2";
import { resolveTableId } from "@latticexyz/config/library";

export default mudConfig({
export default defineWorld({
systems: {
IncrementSystem: {
name: "increment",
Expand All @@ -15,26 +14,27 @@ export default mudConfig({
],
tables: {
CounterTable: {
keySchema: {},
valueSchema: {
schema: {
value: "uint32",
},
storeArgument: true,
key: [],
codegen: { storeArgument: true },
},
MessageTable: {
keySchema: {},
valueSchema: {
type: "offchainTable",
schema: {
value: "string",
},
offchainOnly: true,
key: [],
},
Inventory: {
keySchema: {
schema: {
owner: "address",
item: "uint32",
itemVariant: "uint32",
amount: "uint32",
},
valueSchema: { amount: "uint32" },
key: ["owner", "item", "itemVariant"],
},
},
modules: [
Expand Down
9 changes: 4 additions & 5 deletions examples/multiple-accounts/packages/contracts/mud.config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { mudConfig } from "@latticexyz/world/register";
import { defineWorld } from "@latticexyz/world/config/v2";

export default mudConfig({
export default defineWorld({
namespace: "LastCall",
tables: {
LastCall: {
keySchema: {
schema: {
caller: "address",
},
valueSchema: {
callTime: "uint256",
sender: "address",
},
key: ["caller"],
},
},
});
Loading
Loading