diff --git a/examples/minimal/packages/contracts/mud.config.ts b/examples/minimal/packages/contracts/mud.config.ts index 6bc3086ca2..0e1c00dd3c 100644 --- a/examples/minimal/packages/contracts/mud.config.ts +++ b/examples/minimal/packages/contracts/mud.config.ts @@ -17,11 +17,11 @@ export default mudConfig({ name: "increment", openAccess: true, }, + ChatNamespacedSystem: { + namespace: "namespace", + openAccess: true, + }, }, - excludeSystems: [ - // Until namespace overrides, this system must be manually deployed in PostDeploy - "ChatNamespacedSystem", - ], tables: { CounterTable: { schema: { diff --git a/examples/minimal/packages/contracts/script/PostDeploy.s.sol b/examples/minimal/packages/contracts/script/PostDeploy.s.sol index 10ab5bf924..2e6558b65e 100644 --- a/examples/minimal/packages/contracts/script/PostDeploy.s.sol +++ b/examples/minimal/packages/contracts/script/PostDeploy.s.sol @@ -4,6 +4,7 @@ pragma solidity >=0.8.0; import { Script } from "forge-std/Script.sol"; import { console } from "forge-std/console.sol"; import { ResourceSelector } from "@latticexyz/world/src/ResourceSelector.sol"; +import { Systems } from "@latticexyz/world/src/modules/core/tables/Systems.sol"; import { IWorld } from "../src/codegen/world/IWorld.sol"; import { MessageTable, MessageTableTableId } from "../src/codegen/Tables.sol"; @@ -17,15 +18,11 @@ contract PostDeploy is Script { // Start broadcasting transactions from the deployer account vm.startBroadcast(deployerPrivateKey); - // Manually deploy a system with another namespace - ChatNamespacedSystem chatNamespacedSystem = new ChatNamespacedSystem(); - IWorld(worldAddress).registerSystem("namespace", "ChatNamespaced", chatNamespacedSystem, true); - IWorld(worldAddress).registerFunctionSelector("namespace", "ChatNamespaced", "sendMessage", "(string)"); - // Grant this system access to MessageTable + // Grant a system with an overridden namespace access to MessageTable IWorld(worldAddress).grantAccess( ResourceSelector.getNamespace(MessageTableTableId), ResourceSelector.getName(MessageTableTableId), - address(chatNamespacedSystem) + Systems.getSystem(IWorld(worldAddress), ResourceSelector.from("namespace", "ChatNamespacedSy")) ); // ------------------ EXAMPLES ------------------ diff --git a/examples/minimal/packages/contracts/src/codegen/world/IChatNamespacedSystem.sol b/examples/minimal/packages/contracts/src/codegen/world/IChatNamespacedSystem.sol new file mode 100644 index 0000000000..f34275db04 --- /dev/null +++ b/examples/minimal/packages/contracts/src/codegen/world/IChatNamespacedSystem.sol @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +interface IChatNamespacedSystem { + function namespace_ChatNamespacedSy_sendMessage(string memory message) external; +} diff --git a/examples/minimal/packages/contracts/src/codegen/world/IWorld.sol b/examples/minimal/packages/contracts/src/codegen/world/IWorld.sol index eca91d275d..ff6b13f18e 100644 --- a/examples/minimal/packages/contracts/src/codegen/world/IWorld.sol +++ b/examples/minimal/packages/contracts/src/codegen/world/IWorld.sol @@ -5,6 +5,7 @@ pragma solidity >=0.8.0; import { IBaseWorld } from "@latticexyz/world/src/interfaces/IBaseWorld.sol"; +import { IChatNamespacedSystem } from "./IChatNamespacedSystem.sol"; import { IChatSystem } from "./IChatSystem.sol"; import { IIncrementSystem } from "./IIncrementSystem.sol"; import { IInventorySystem } from "./IInventorySystem.sol"; @@ -14,6 +15,6 @@ import { IStructSystem } from "./IStructSystem.sol"; * The IWorld interface includes all systems dynamically added to the World * during the deploy process. */ -interface IWorld is IBaseWorld, IChatSystem, IIncrementSystem, IInventorySystem, IStructSystem { +interface IWorld is IBaseWorld, IChatNamespacedSystem, IChatSystem, IIncrementSystem, IInventorySystem, IStructSystem { } diff --git a/examples/minimal/packages/contracts/src/interfaces/IChatNamespacedSystem.sol b/examples/minimal/packages/contracts/src/interfaces/IChatNamespacedSystem.sol deleted file mode 100644 index 9177496daf..0000000000 --- a/examples/minimal/packages/contracts/src/interfaces/IChatNamespacedSystem.sol +++ /dev/null @@ -1,7 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity >=0.8.0; - -// TODO allow overriding namespace per-system -interface IChatNamespacedSystem { - function namespace_ChatNamespaced_sendMessage(string memory message) external; -} diff --git a/examples/minimal/packages/contracts/test/ChatNamespaced.t.sol b/examples/minimal/packages/contracts/test/ChatNamespaced.t.sol index c7dfa0ff9e..b11d77743d 100644 --- a/examples/minimal/packages/contracts/test/ChatNamespaced.t.sol +++ b/examples/minimal/packages/contracts/test/ChatNamespaced.t.sol @@ -8,13 +8,13 @@ import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; import { IWorld } from "../src/codegen/world/IWorld.sol"; import { MessageTable, MessageTableTableId } from "../src/codegen/Tables.sol"; -import { IChatNamespacedSystem } from "../src/interfaces/IChatNamespacedSystem.sol"; +import { IChatNamespacedSystem } from "../src/codegen/world/IChatNamespacedSystem.sol"; contract ChatNamespacedTest is MudV2Test { function testEmitEphemeral() public { bytes32[] memory keyTuple; vm.expectEmit(true, true, true, true); emit StoreCore.StoreEphemeralRecord(MessageTableTableId, keyTuple, MessageTable.encode("test")); - IChatNamespacedSystem(worldAddress).namespace_ChatNamespaced_sendMessage("test"); + IChatNamespacedSystem(worldAddress).namespace_ChatNamespacedSy_sendMessage("test"); } } diff --git a/examples/minimal/packages/contracts/types/ethers-contracts/IWorld.ts b/examples/minimal/packages/contracts/types/ethers-contracts/IWorld.ts index 386ad0b860..133caf6ddc 100644 --- a/examples/minimal/packages/contracts/types/ethers-contracts/IWorld.ts +++ b/examples/minimal/packages/contracts/types/ethers-contracts/IWorld.ts @@ -57,6 +57,7 @@ export interface IWorldInterface extends utils.Interface { "installModule(address,bytes)": FunctionFragment; "installRootModule(address,bytes)": FunctionFragment; "isStore()": FunctionFragment; + "namespace_ChatNamespacedSy_sendMessage(string)": FunctionFragment; "pickUp(uint32,uint32)": FunctionFragment; "popFromField(bytes16,bytes16,bytes32[],uint8,uint256)": FunctionFragment; "popFromField(bytes32,bytes32[],uint8,uint256)": FunctionFragment; @@ -108,6 +109,7 @@ export interface IWorldInterface extends utils.Interface { | "installModule" | "installRootModule" | "isStore" + | "namespace_ChatNamespacedSy_sendMessage" | "pickUp" | "popFromField(bytes16,bytes16,bytes32[],uint8,uint256)" | "popFromField(bytes32,bytes32[],uint8,uint256)" @@ -249,6 +251,10 @@ export interface IWorldInterface extends utils.Interface { values: [PromiseOrValue, PromiseOrValue] ): string; encodeFunctionData(functionFragment: "isStore", values?: undefined): string; + encodeFunctionData( + functionFragment: "namespace_ChatNamespacedSy_sendMessage", + values: [PromiseOrValue] + ): string; encodeFunctionData( functionFragment: "pickUp", values: [PromiseOrValue, PromiseOrValue] @@ -527,6 +533,10 @@ export interface IWorldInterface extends utils.Interface { data: BytesLike ): Result; decodeFunctionResult(functionFragment: "isStore", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "namespace_ChatNamespacedSy_sendMessage", + data: BytesLike + ): Result; decodeFunctionResult(functionFragment: "pickUp", data: BytesLike): Result; decodeFunctionResult( functionFragment: "popFromField(bytes16,bytes16,bytes32[],uint8,uint256)", @@ -849,6 +859,11 @@ export interface IWorld extends BaseContract { isStore(overrides?: CallOverrides): Promise<[void]>; + namespace_ChatNamespacedSy_sendMessage( + message: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + pickUp( item: PromiseOrValue, itemVariant: PromiseOrValue, @@ -1171,6 +1186,11 @@ export interface IWorld extends BaseContract { isStore(overrides?: CallOverrides): Promise; + namespace_ChatNamespacedSy_sendMessage( + message: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + pickUp( item: PromiseOrValue, itemVariant: PromiseOrValue, @@ -1491,6 +1511,11 @@ export interface IWorld extends BaseContract { isStore(overrides?: CallOverrides): Promise; + namespace_ChatNamespacedSy_sendMessage( + message: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + pickUp( item: PromiseOrValue, itemVariant: PromiseOrValue, @@ -1858,6 +1883,11 @@ export interface IWorld extends BaseContract { isStore(overrides?: CallOverrides): Promise; + namespace_ChatNamespacedSy_sendMessage( + message: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + pickUp( item: PromiseOrValue, itemVariant: PromiseOrValue, @@ -2181,6 +2211,11 @@ export interface IWorld extends BaseContract { isStore(overrides?: CallOverrides): Promise; + namespace_ChatNamespacedSy_sendMessage( + message: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + pickUp( item: PromiseOrValue, itemVariant: PromiseOrValue, diff --git a/examples/minimal/packages/contracts/types/ethers-contracts/factories/IWorld__factory.ts b/examples/minimal/packages/contracts/types/ethers-contracts/factories/IWorld__factory.ts index 65d99da0a2..16f812ce4c 100644 --- a/examples/minimal/packages/contracts/types/ethers-contracts/factories/IWorld__factory.ts +++ b/examples/minimal/packages/contracts/types/ethers-contracts/factories/IWorld__factory.ts @@ -739,6 +739,19 @@ const _abi = [ stateMutability: "view", type: "function", }, + { + inputs: [ + { + internalType: "string", + name: "message", + type: "string", + }, + ], + name: "namespace_ChatNamespacedSy_sendMessage", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, { inputs: [ {