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(world): rename CoreModule to InitModule #2227

Merged
merged 10 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/five-vans-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/world": major
---

Renamed `CoreModule` to `InitModule` and `CoreRegistrationSystem` to `RegistrationSystem`.
5 changes: 5 additions & 0 deletions .changeset/silver-adults-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/cli": patch
---

Updated deployer with world's new `InitModule` naming.
42 changes: 20 additions & 22 deletions packages/cli/src/deploy/ensureWorldFactory.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import accessManagementSystemBuild from "@latticexyz/world/out/AccessManagementSystem.sol/AccessManagementSystem.json" assert { type: "json" };
import balanceTransferSystemBuild from "@latticexyz/world/out/BalanceTransferSystem.sol/BalanceTransferSystem.json" assert { type: "json" };
import batchCallSystemBuild from "@latticexyz/world/out/BatchCallSystem.sol/BatchCallSystem.json" assert { type: "json" };
import coreRegistrationSystemBuild from "@latticexyz/world/out/CoreRegistrationSystem.sol/CoreRegistrationSystem.json" assert { type: "json" };
import coreModuleBuild from "@latticexyz/world/out/CoreModule.sol/CoreModule.json" assert { type: "json" };
import coreModuleAbi from "@latticexyz/world/out/CoreModule.sol/CoreModule.abi.json" assert { type: "json" };
import registrationSystemBuild from "@latticexyz/world/out/RegistrationSystem.sol/RegistrationSystem.json" assert { type: "json" };
import initModuleBuild from "@latticexyz/world/out/InitModule.sol/InitModule.json" assert { type: "json" };
import initModuleAbi from "@latticexyz/world/out/InitModule.sol/InitModule.abi.json" assert { type: "json" };
import worldFactoryBuild from "@latticexyz/world/out/WorldFactory.sol/WorldFactory.json" assert { type: "json" };
import worldFactoryAbi from "@latticexyz/world/out/WorldFactory.sol/WorldFactory.abi.json" assert { type: "json" };
import { Client, Transport, Chain, Account, Hex, getCreate2Address, encodeDeployData, size } from "viem";
Expand Down Expand Up @@ -45,33 +45,31 @@ export const batchCallSystemBytecode = encodeDeployData({
});
export const batchCallSystem = getCreate2Address({ from: deployer, bytecode: batchCallSystemBytecode, salt });

export const coreRegistrationSystemDeployedBytecodeSize = size(
coreRegistrationSystemBuild.deployedBytecode.object as Hex
);
export const coreRegistrationSystemBytecode = encodeDeployData({
bytecode: coreRegistrationSystemBuild.bytecode.object as Hex,
export const registrationDeployedBytecodeSize = size(registrationSystemBuild.deployedBytecode.object as Hex);
export const registrationBytecode = encodeDeployData({
bytecode: registrationSystemBuild.bytecode.object as Hex,
abi: [],
});
export const coreRegistrationSystem = getCreate2Address({
export const registration = getCreate2Address({
from: deployer,
bytecode: coreRegistrationSystemBytecode,
bytecode: registrationBytecode,
salt,
});

export const coreModuleDeployedBytecodeSize = size(coreModuleBuild.deployedBytecode.object as Hex);
export const coreModuleBytecode = encodeDeployData({
bytecode: coreModuleBuild.bytecode.object as Hex,
abi: coreModuleAbi,
args: [accessManagementSystem, balanceTransferSystem, batchCallSystem, coreRegistrationSystem],
export const initModuleDeployedBytecodeSize = size(initModuleBuild.deployedBytecode.object as Hex);
export const initModuleBytecode = encodeDeployData({
bytecode: initModuleBuild.bytecode.object as Hex,
abi: initModuleAbi,
args: [accessManagementSystem, balanceTransferSystem, batchCallSystem, registration],
});

export const coreModule = getCreate2Address({ from: deployer, bytecode: coreModuleBytecode, salt });
export const initModule = getCreate2Address({ from: deployer, bytecode: initModuleBytecode, salt });

export const worldFactoryDeployedBytecodeSize = size(worldFactoryBuild.deployedBytecode.object as Hex);
export const worldFactoryBytecode = encodeDeployData({
bytecode: worldFactoryBuild.bytecode.object as Hex,
abi: worldFactoryAbi,
args: [coreModule],
args: [initModule],
});

export const worldFactory = getCreate2Address({ from: deployer, bytecode: worldFactoryBytecode, salt });
Expand All @@ -93,13 +91,13 @@ export const worldFactoryContracts: readonly Contract[] = [
label: "batch call system",
},
{
bytecode: coreRegistrationSystemBytecode,
deployedBytecodeSize: coreRegistrationSystemDeployedBytecodeSize,
bytecode: registrationBytecode,
deployedBytecodeSize: registrationDeployedBytecodeSize,
label: "core registration system",
},
{
bytecode: coreModuleBytecode,
deployedBytecodeSize: coreModuleDeployedBytecodeSize,
bytecode: initModuleBytecode,
deployedBytecodeSize: initModuleDeployedBytecodeSize,
label: "core module",
},
{
Expand All @@ -112,7 +110,7 @@ export const worldFactoryContracts: readonly Contract[] = [
export async function ensureWorldFactory(
client: Client<Transport, Chain | undefined, Account>
): Promise<readonly Hex[]> {
// WorldFactory constructor doesn't call CoreModule, only sets its address, so we can do these in parallel since the address is deterministic
// WorldFactory constructor doesn't call InitModule, only sets its address, so we can do these in parallel since the address is deterministic
return await ensureContractsDeployed({
client,
contracts: worldFactoryContracts,
Expand Down
5 changes: 2 additions & 3 deletions packages/world-modules/test/ERC20.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";
import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol";
import { World } from "@latticexyz/world/src/World.sol";
import { WorldResourceIdLib } from "@latticexyz/world/src/WorldResourceId.sol";
import { createCoreModule } from "@latticexyz/world/test/createCoreModule.sol";
import { createWorld } from "@latticexyz/world/test/createWorld.sol";
import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.sol";
import { NamespaceOwner } from "@latticexyz/world/src/codegen/tables/NamespaceOwner.sol";
import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol";
Expand All @@ -30,8 +30,7 @@ contract ERC20Test is Test, GasReporter, IERC20Events, IERC20Errors {
IERC20Mintable token;

function setUp() public {
world = IBaseWorld(address(new World()));
world.initialize(createCoreModule());
world = createWorld();
world.installModule(new PuppetModule(), new bytes(0));
StoreSwitch.setStoreAddress(address(world));

Expand Down
5 changes: 2 additions & 3 deletions packages/world-modules/test/ERC721.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";
import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol";
import { World } from "@latticexyz/world/src/World.sol";
import { WorldResourceIdLib, WorldResourceIdInstance } from "@latticexyz/world/src/WorldResourceId.sol";
import { createCoreModule } from "@latticexyz/world/test/createCoreModule.sol";
import { createWorld } from "@latticexyz/world/test/createWorld.sol";
import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.sol";
import { NamespaceOwner } from "@latticexyz/world/src/codegen/tables/NamespaceOwner.sol";
import { IWorldErrors } from "@latticexyz/world/src/IWorldErrors.sol";
Expand Down Expand Up @@ -72,8 +72,7 @@ contract ERC721Test is Test, GasReporter, IERC721Events, IERC721Errors {
IERC721Mintable token;

function setUp() public {
world = IBaseWorld(address(new World()));
world.initialize(createCoreModule());
world = createWorld();
world.installModule(new PuppetModule(), new bytes(0));
StoreSwitch.setStoreAddress(address(world));

Expand Down
5 changes: 2 additions & 3 deletions packages/world-modules/test/KeysInTableModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { ResourceId, WorldResourceIdLib, WorldResourceIdInstance } from "@lattic
import { ROOT_NAMESPACE } from "@latticexyz/world/src/constants.sol";
import { RESOURCE_TABLE } from "@latticexyz/world/src/worldResourceTypes.sol";

import { createCoreModule } from "@latticexyz/world/test/createCoreModule.sol";
import { createWorld } from "@latticexyz/world/test/createWorld.sol";
import { KeysInTableModule } from "../src/modules/keysintable/KeysInTableModule.sol";
import { getKeysInTable } from "../src/modules/keysintable/getKeysInTable.sol";
import { hasKey } from "../src/modules/keysintable/hasKey.sol";
Expand Down Expand Up @@ -62,8 +62,7 @@ contract KeysInTableModuleTest is Test, GasReporter {
compositeKeySchema = SchemaEncodeHelper.encode(SchemaType.BYTES32, SchemaType.BYTES32, SchemaType.BYTES32);
singletonKeySchema = SchemaLib.encode(new SchemaType[](0));

world = IBaseWorld(address(new World()));
world.initialize(createCoreModule());
world = createWorld();
keyTuple1 = new bytes32[](1);
keyTuple1[0] = key1;
keyTuple2 = new bytes32[](1);
Expand Down
5 changes: 2 additions & 3 deletions packages/world-modules/test/KeysWithValueModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { WorldResourceIdLib, WorldResourceIdInstance, NAME_BITS, TYPE_BITS } fro
import { ROOT_NAMESPACE } from "@latticexyz/world/src/constants.sol";
import { RESOURCE_TABLE } from "@latticexyz/world/src/worldResourceTypes.sol";

import { createCoreModule } from "@latticexyz/world/test/createCoreModule.sol";
import { createWorld } from "@latticexyz/world/test/createWorld.sol";
import { KeysWithValueModule } from "../src/modules/keyswithvalue/KeysWithValueModule.sol";
import { MODULE_NAMESPACE } from "../src/modules/keyswithvalue/constants.sol";
import { KeysWithValue } from "../src/modules/keyswithvalue/tables/KeysWithValue.sol";
Expand Down Expand Up @@ -54,8 +54,7 @@ contract KeysWithValueModuleTest is Test, GasReporter {
sourceTableId = WorldResourceIdLib.encode({ typeId: RESOURCE_TABLE, namespace: namespace, name: sourceName });
targetTableId = getTargetTableId(MODULE_NAMESPACE, sourceTableId);

world = IBaseWorld(address(new World()));
world.initialize(createCoreModule());
world = createWorld();
StoreSwitch.setStoreAddress(address(world));

keyTuple1 = new bytes32[](1);
Expand Down
5 changes: 2 additions & 3 deletions packages/world-modules/test/PuppetModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.
import { IWorldErrors } from "@latticexyz/world/src/IWorldErrors.sol";
import { IDelegationControl } from "@latticexyz/world/src/IDelegationControl.sol";

import { createCoreModule } from "@latticexyz/world/test/createCoreModule.sol";
import { createWorld } from "@latticexyz/world/test/createWorld.sol";
import { Systems } from "@latticexyz/world/src/codegen/tables/Systems.sol";

import { PuppetModule } from "../src/modules/puppet/PuppetModule.sol";
Expand Down Expand Up @@ -47,8 +47,7 @@ contract PuppetModuleTest is Test, GasReporter {
PuppetTestSystem private puppet;

function setUp() public {
world = IBaseWorld(address(new World()));
world.initialize(createCoreModule());
world = createWorld();
}

function _setupPuppet() internal {
Expand Down
5 changes: 2 additions & 3 deletions packages/world-modules/test/StandardDelegationsModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.
import { IWorldErrors } from "@latticexyz/world/src/IWorldErrors.sol";
import { IDelegationControl } from "@latticexyz/world/src/IDelegationControl.sol";

import { createCoreModule } from "@latticexyz/world/test/createCoreModule.sol";
import { createWorld } from "@latticexyz/world/test/createWorld.sol";
import { Systems } from "@latticexyz/world/src/codegen/tables/Systems.sol";

import { StandardDelegationsModule } from "../src/modules/std-delegations/StandardDelegationsModule.sol";
Expand All @@ -33,8 +33,7 @@ contract StandardDelegationsModuleTest is Test, GasReporter {
address private delegatee = address(2);

function setUp() public {
world = IBaseWorld(address(new World()));
world.initialize(createCoreModule());
world = createWorld();
world.installRootModule(new StandardDelegationsModule(), new bytes(0));

// Register a new system
Expand Down
6 changes: 2 additions & 4 deletions packages/world-modules/test/SystemSwitch.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol";
import { System } from "@latticexyz/world/src/System.sol";
import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.sol";
import { World } from "@latticexyz/world/src/World.sol";
import { createCoreModule } from "@latticexyz/world/test/createCoreModule.sol";
import { createWorld } from "@latticexyz/world/test/createWorld.sol";
import { ResourceId, WorldResourceIdLib, WorldResourceIdInstance } from "@latticexyz/world/src/WorldResourceId.sol";
import { RESOURCE_SYSTEM } from "@latticexyz/world/src/worldResourceTypes.sol";
import { ROOT_NAMESPACE } from "@latticexyz/world/src/constants.sol";
Expand Down Expand Up @@ -54,9 +54,7 @@ contract SystemSwitchTest is Test, GasReporter {

function setUp() public {
// Deploy world
World _world = new World();
_world.initialize(createCoreModule());
world = IBaseWorld(address(_world));
world = createWorld();

// Deploy systems
systemA = new EchoSystem();
Expand Down
5 changes: 2 additions & 3 deletions packages/world-modules/test/UniqueEntityModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { IWorldErrors } from "@latticexyz/world/src/IWorldErrors.sol";
import { System } from "@latticexyz/world/src/System.sol";
import { RESOURCE_SYSTEM } from "@latticexyz/world/src/worldResourceTypes.sol";

import { createCoreModule } from "@latticexyz/world/test/createCoreModule.sol";
import { createWorld } from "@latticexyz/world/test/createWorld.sol";
import { UniqueEntityModule } from "../src/modules/uniqueentity/UniqueEntityModule.sol";
import { UniqueEntity } from "../src/modules/uniqueentity/tables/UniqueEntity.sol";
import { getUniqueEntity } from "../src/modules/uniqueentity/getUniqueEntity.sol";
Expand All @@ -36,8 +36,7 @@ contract UniqueEntityModuleTest is Test, GasReporter {
ResourceId _tableId = WorldResourceIdLib.encode({ typeId: RESOURCE_TABLE, namespace: NAMESPACE, name: TABLE_NAME });

function setUp() public {
world = IBaseWorld(address(new World()));
world.initialize(createCoreModule());
world = createWorld();
StoreSwitch.setStoreAddress(address(world));
}

Expand Down
5 changes: 2 additions & 3 deletions packages/world-modules/test/query.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { ResourceId, WorldResourceIdLib, WorldResourceIdInstance } from "@lattic
import { ROOT_NAMESPACE } from "@latticexyz/world/src/constants.sol";
import { RESOURCE_TABLE } from "@latticexyz/world/src/worldResourceTypes.sol";

import { createCoreModule } from "@latticexyz/world/test/createCoreModule.sol";
import { createWorld } from "@latticexyz/world/test/createWorld.sol";
import { KeysInTableModule } from "../src/modules/keysintable/KeysInTableModule.sol";
import { KeysWithValueModule } from "../src/modules/keyswithvalue/KeysWithValueModule.sol";
import { query, QueryFragment, QueryType } from "../src/modules/keysintable/query.sol";
Expand Down Expand Up @@ -52,8 +52,7 @@ contract QueryTest is Test, GasReporter {
tableFieldLayout = FieldLayoutEncodeHelper.encode(32, 0);
tableKeySchema = SchemaEncodeHelper.encode(SchemaType.BYTES32);
tableValueSchema = SchemaEncodeHelper.encode(SchemaType.UINT256);
world = IBaseWorld(address(new World()));
world.initialize(createCoreModule());
world = createWorld();

key1[0] = "test1";
key2[0] = "test2";
Expand Down
2 changes: 1 addition & 1 deletion packages/world/gas-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"file": "test/Factories.t.sol",
"test": "testWorldFactoryGas",
"name": "deploy world via WorldFactory",
"gasUsed": 12961878
"gasUsed": 12961889
},
{
"file": "test/World.t.sol",
Expand Down
4 changes: 2 additions & 2 deletions packages/world/mud.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ export default mudConfig({
},
offchainOnly: true,
},
CoreModuleAddress: {
InitModuleAddress: {
keySchema: {},
valueSchema: "address",
},
},
excludeSystems: [
// Worldgen currently does not support systems inheriting logic
// from other contracts, so all parts of CoreRegistrationSystem are named
// from other contracts, so all parts of RegistrationSystem are named
// System too to be included in the IBaseWorld interface.
// However, IStoreRegistrationSystem overlaps with IStore if
// included in IBaseWorld, so it needs to be excluded from worldgen.
Expand Down
6 changes: 3 additions & 3 deletions packages/world/src/IWorldKernel.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ interface IWorldCall {
* @title World Kernel Interface
* @notice The IWorldKernel interface includes all methods that are part of the World contract's
* internal bytecode. Consumers should use the `IBaseWorld` interface instead, which includes dynamically
* registered functions selectors from the `CoreModule`.
* registered functions selectors from the `InitModule`.
*/
interface IWorldKernel is IWorldModuleInstallation, IWorldCall, IWorldErrors {
/**
Expand All @@ -78,7 +78,7 @@ interface IWorldKernel is IWorldModuleInstallation, IWorldCall, IWorldErrors {
/**
* @notice Initializes the World.
* @dev Can only be called once by the creator.
* @param coreModule The CoreModule to be installed during initialization.
* @param initModule The InitModule to be installed during initialization.
*/
function initialize(IModule coreModule) external;
function initialize(IModule initModule) external;
}
12 changes: 6 additions & 6 deletions packages/world/src/World.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { requireInterface } from "./requireInterface.sol";
import { InstalledModules } from "./codegen/tables/InstalledModules.sol";
import { UserDelegationControl } from "./codegen/tables/UserDelegationControl.sol";
import { NamespaceDelegationControl } from "./codegen/tables/NamespaceDelegationControl.sol";
import { CoreModuleAddress } from "./codegen/tables/CoreModuleAddress.sol";
import { InitModuleAddress } from "./codegen/tables/InitModuleAddress.sol";

import { IModule, IModule } from "./IModule.sol";
import { IWorldKernel } from "./IWorldKernel.sol";
Expand Down Expand Up @@ -61,24 +61,24 @@ contract World is StoreData, IWorldKernel {

/**
* @notice Initializes the World by installing the core module.
* @param coreModule The core module to initialize the World with.
* @param initModule The core module to initialize the World with.
* @dev Only the initial creator can initialize. This can be done only once.
*/
function initialize(IModule coreModule) public prohibitDirectCallback {
function initialize(IModule initModule) public prohibitDirectCallback {
// Only the initial creator of the World can initialize it
if (msg.sender != creator) {
revert World_AccessDenied(ROOT_NAMESPACE_ID.toString(), msg.sender);
}

// The World can only be initialized once
if (CoreModuleAddress.get() != address(0)) {
if (InitModuleAddress.get() != address(0)) {
revert World_AlreadyInitialized();
}

CoreModuleAddress.set(address(coreModule));
InitModuleAddress.set(address(initModule));

// Initialize the World by installing the core module
_installRootModule(coreModule, new bytes(0));
_installRootModule(initModule, new bytes(0));
}

/**
Expand Down
16 changes: 8 additions & 8 deletions packages/world/src/WorldFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ import { ROOT_NAMESPACE_ID } from "./constants.sol";
/**
* @title WorldFactory
* @notice A factory contract to deploy new World instances.
* @dev This contract allows users to deploy a new World, install the CoreModule, and transfer the ownership.
* @dev This contract allows users to deploy a new World, install the InitModule, and transfer the ownership.
*/
contract WorldFactory is IWorldFactory {
/// @notice Address of the core module to be set in the World instances.
IModule public immutable coreModule;
/// @notice Address of the init module to be set in the World instances.
IModule public immutable initModule;

/// @notice Counters to keep track of the number of World instances deployed per address.
mapping(address creator => uint256 worldCount) public worldCounts;

/// @param _coreModule The address of the core module.
constructor(IModule _coreModule) {
coreModule = _coreModule;
/// @param _initModule The address of the init module.
constructor(IModule _initModule) {
initModule = _initModule;
}

/**
* @notice Deploys a new World instance, installs the CoreModule and transfers ownership to the caller.
* @notice Deploys a new World instance, installs the InitModule and transfers ownership to the caller.
* @dev Uses the Create2 for deterministic deployment.
* @return worldAddress The address of the newly deployed World contract.
*/
Expand All @@ -38,7 +38,7 @@ contract WorldFactory is IWorldFactory {
IBaseWorld world = IBaseWorld(worldAddress);

// Initialize the World and transfer ownership to the caller
world.initialize(coreModule);
world.initialize(initModule);
world.transferOwnership(ROOT_NAMESPACE_ID, msg.sender);

emit WorldDeployed(worldAddress);
Expand Down
Loading
Loading