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

refactor(cli,world,world-modules): split and separately deploy core systems #2128

Merged
merged 12 commits into from
Jan 16, 2024
5 changes: 5 additions & 0 deletions .changeset/quiet-guests-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/cli": major
---

Separated core systems deployment from `CoreModule`, and added the systems as arguments to `CoreModule`
9 changes: 9 additions & 0 deletions .changeset/silver-ligers-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@latticexyz/world": major
---

- Split `CoreSystem` into `AccessManagementSystem`, `BalanceTransferSystem`, `BatchCallSystem`, `CoreRegistrationSystem`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on CoreRegistrationSystem vs just RegistrationSystem?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CoreRegistrationSystem is less generic, easier to search for, fits CoreModule a bit better
Not a strong opinion

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

none of the other systems are called "core" though 🤷

(I think this is fine either way and easy enough to rename later if we decide to)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I see Core as some aggregation prefix
agree that it's fine either way

- Changed `CoreModule` to receive the addresses of these systems as arguments, instead of deploying them
- Replaced `CORE_SYSTEM_ID` constant with `ACCESS_MANAGEMENT_SYSTEM_ID`, `BALANCE_TRANSFER_SYSTEM_ID`, `BATCH_CALL_SYSTEM_ID`, `CORE_REGISTRATION_SYSTEM_ID`, for each respective system

These changes separate the initcode of `CoreModule` from the bytecode of core systems, which effectively removes a limit on the total bytecode of all core systems.
73 changes: 72 additions & 1 deletion packages/cli/src/deploy/ensureWorldFactory.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
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 worldFactoryBuild from "@latticexyz/world/out/WorldFactory.sol/WorldFactory.json" assert { type: "json" };
import { Client, Transport, Chain, Account, Hex, parseAbi, getCreate2Address, encodeDeployData, size } from "viem";
Expand All @@ -6,10 +10,57 @@ import { salt } from "./common";
import { ensureContractsDeployed } from "./ensureContractsDeployed";
import { Contract } from "./ensureContract";

export const accessManagementSystemDeployedBytecodeSize = size(
accessManagementSystemBuild.deployedBytecode.object as Hex
);
export const accessManagementSystemBytecode = encodeDeployData({
bytecode: accessManagementSystemBuild.bytecode.object as Hex,
abi: [],
});
export const accessManagementSystem = getCreate2Address({
from: deployer,
bytecode: accessManagementSystemBytecode,
salt,
});

export const balanceTransferSystemDeployedBytecodeSize = size(
balanceTransferSystemBuild.deployedBytecode.object as Hex
);
export const balanceTransferSystemBytecode = encodeDeployData({
bytecode: balanceTransferSystemBuild.bytecode.object as Hex,
abi: [],
});
export const balanceTransferSystem = getCreate2Address({
from: deployer,
bytecode: balanceTransferSystemBytecode,
salt,
});

export const batchCallSystemDeployedBytecodeSize = size(batchCallSystemBuild.deployedBytecode.object as Hex);
export const batchCallSystemBytecode = encodeDeployData({
bytecode: batchCallSystemBuild.bytecode.object as Hex,
abi: [],
});
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,
abi: [],
});
export const coreRegistrationSystem = getCreate2Address({
from: deployer,
bytecode: coreRegistrationSystemBytecode,
salt,
});

export const coreModuleDeployedBytecodeSize = size(coreModuleBuild.deployedBytecode.object as Hex);
export const coreModuleBytecode = encodeDeployData({
bytecode: coreModuleBuild.bytecode.object as Hex,
abi: [],
abi: parseAbi(["constructor(address,address,address,address)"]),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to get this form an import of the code module? so this can throw a type error when it changes instead of a runtime error if the abi doesn't match

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe with abitype (we don't have it in cli package yet)
I'd rather not do this as part of this PR, or right now given I wanna move on to codegen refactor

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what he means is importing the typed ABI, i.e.

import coreModuleAbi from "@latticexyz/world/out/CoreModule.sol/CoreModule.abi.json" assert { type: "json" };

export const coreModuleBytecode = encodeDeployData({
  bytecode: coreModuleBuild.bytecode.object as Hex,
  abi: coreModuleAbi,
  ...
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, well yeah point is I remember next to no context for this

args: [accessManagementSystem, balanceTransferSystem, batchCallSystem, coreRegistrationSystem],
});

export const coreModule = getCreate2Address({ from: deployer, bytecode: coreModuleBytecode, salt });
Expand All @@ -24,6 +75,26 @@ export const worldFactoryBytecode = encodeDeployData({
export const worldFactory = getCreate2Address({ from: deployer, bytecode: worldFactoryBytecode, salt });

export const worldFactoryContracts: readonly Contract[] = [
{
bytecode: accessManagementSystemBytecode,
deployedBytecodeSize: accessManagementSystemDeployedBytecodeSize,
label: "access management system",
},
{
bytecode: balanceTransferSystemBytecode,
deployedBytecodeSize: balanceTransferSystemDeployedBytecodeSize,
label: "balance transfer system",
},
{
bytecode: batchCallSystemBytecode,
deployedBytecodeSize: batchCallSystemDeployedBytecodeSize,
label: "batch call system",
},
{
bytecode: coreRegistrationSystemBytecode,
deployedBytecodeSize: coreRegistrationSystemDeployedBytecodeSize,
label: "core registration system",
},
{
bytecode: coreModuleBytecode,
deployedBytecodeSize: coreModuleDeployedBytecodeSize,
Expand Down
28 changes: 14 additions & 14 deletions packages/world-modules/gas-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@
"file": "test/KeysInTableModule.t.sol",
"test": "testInstallComposite",
"name": "install keys in table module",
"gasUsed": 1413360
"gasUsed": 1419104
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testInstallGas",
"name": "install keys in table module",
"gasUsed": 1413360
"gasUsed": 1419104
},
{
"file": "test/KeysInTableModule.t.sol",
Expand All @@ -93,13 +93,13 @@
"file": "test/KeysInTableModule.t.sol",
"test": "testInstallSingleton",
"name": "install keys in table module",
"gasUsed": 1413360
"gasUsed": 1419104
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testSetAndDeleteRecordHookCompositeGas",
"name": "install keys in table module",
"gasUsed": 1413360
"gasUsed": 1419104
},
{
"file": "test/KeysInTableModule.t.sol",
Expand All @@ -117,7 +117,7 @@
"file": "test/KeysInTableModule.t.sol",
"test": "testSetAndDeleteRecordHookGas",
"name": "install keys in table module",
"gasUsed": 1413360
"gasUsed": 1419104
},
{
"file": "test/KeysInTableModule.t.sol",
Expand All @@ -135,7 +135,7 @@
"file": "test/KeysWithValueModule.t.sol",
"test": "testGetKeysWithValueGas",
"name": "install keys with value module",
"gasUsed": 668171
"gasUsed": 674298
},
{
"file": "test/KeysWithValueModule.t.sol",
Expand All @@ -153,7 +153,7 @@
"file": "test/KeysWithValueModule.t.sol",
"test": "testInstall",
"name": "install keys with value module",
"gasUsed": 668171
"gasUsed": 674298
},
{
"file": "test/KeysWithValueModule.t.sol",
Expand All @@ -165,7 +165,7 @@
"file": "test/KeysWithValueModule.t.sol",
"test": "testSetAndDeleteRecordHook",
"name": "install keys with value module",
"gasUsed": 668171
"gasUsed": 674298
},
{
"file": "test/KeysWithValueModule.t.sol",
Expand All @@ -183,7 +183,7 @@
"file": "test/KeysWithValueModule.t.sol",
"test": "testSetField",
"name": "install keys with value module",
"gasUsed": 668171
"gasUsed": 674298
},
{
"file": "test/KeysWithValueModule.t.sol",
Expand Down Expand Up @@ -267,7 +267,7 @@
"file": "test/StandardDelegationsModule.t.sol",
"test": "testCallFromCallboundDelegation",
"name": "register a callbound delegation",
"gasUsed": 118347
"gasUsed": 118172
},
{
"file": "test/StandardDelegationsModule.t.sol",
Expand All @@ -279,7 +279,7 @@
"file": "test/StandardDelegationsModule.t.sol",
"test": "testCallFromSystemDelegation",
"name": "register a systembound delegation",
"gasUsed": 115900
"gasUsed": 115725
},
{
"file": "test/StandardDelegationsModule.t.sol",
Expand All @@ -291,7 +291,7 @@
"file": "test/StandardDelegationsModule.t.sol",
"test": "testCallFromTimeboundDelegation",
"name": "register a timebound delegation",
"gasUsed": 112823
"gasUsed": 112648
},
{
"file": "test/StandardDelegationsModule.t.sol",
Expand All @@ -303,7 +303,7 @@
"file": "test/UniqueEntityModule.t.sol",
"test": "testInstall",
"name": "install unique entity module",
"gasUsed": 694879
"gasUsed": 694710
},
{
"file": "test/UniqueEntityModule.t.sol",
Expand All @@ -315,7 +315,7 @@
"file": "test/UniqueEntityModule.t.sol",
"test": "testInstallRoot",
"name": "installRoot unique entity module",
"gasUsed": 663830
"gasUsed": 663729
},
{
"file": "test/UniqueEntityModule.t.sol",
Expand Down
4 changes: 2 additions & 2 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 { CoreModule } from "@latticexyz/world/src/modules/core/CoreModule.sol";
import { createCoreModule } from "@latticexyz/world/test/createCoreModule.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 @@ -31,7 +31,7 @@ contract ERC20Test is Test, GasReporter, IERC20Events, IERC20Errors {

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

Expand Down
4 changes: 2 additions & 2 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 { CoreModule } from "@latticexyz/world/src/modules/core/CoreModule.sol";
import { createCoreModule } from "@latticexyz/world/test/createCoreModule.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 @@ -73,7 +73,7 @@ contract ERC721Test is Test, GasReporter, IERC721Events, IERC721Errors {

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

Expand Down
4 changes: 2 additions & 2 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 { CoreModule } from "@latticexyz/world/src/modules/core/CoreModule.sol";
import { createCoreModule } from "@latticexyz/world/test/createCoreModule.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 @@ -63,7 +63,7 @@ contract KeysInTableModuleTest is Test, GasReporter {
singletonKeySchema = SchemaLib.encode(new SchemaType[](0));

world = IBaseWorld(address(new World()));
world.initialize(new CoreModule());
world.initialize(createCoreModule());
keyTuple1 = new bytes32[](1);
keyTuple1[0] = key1;
keyTuple2 = new bytes32[](1);
Expand Down
4 changes: 2 additions & 2 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 { CoreModule } from "@latticexyz/world/src/modules/core/CoreModule.sol";
import { createCoreModule } from "@latticexyz/world/test/createCoreModule.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 @@ -56,7 +56,7 @@ contract KeysWithValueModuleTest is Test, GasReporter {
targetTableId = getTargetTableId(MODULE_NAMESPACE, sourceTableId);

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

keyTuple1 = new bytes32[](1);
Expand Down
4 changes: 2 additions & 2 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 { DELEGATION_CONTROL_INTERFACE_ID } from "@latticexyz/world/src/IDelegationControl.sol";

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

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

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

function _setupPuppet() internal {
Expand Down
4 changes: 2 additions & 2 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 { DELEGATION_CONTROL_INTERFACE_ID } from "@latticexyz/world/src/IDelegationControl.sol";

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

import { StandardDelegationsModule } from "../src/modules/std-delegations/StandardDelegationsModule.sol";
Expand All @@ -34,7 +34,7 @@ contract StandardDelegationsModuleTest is Test, GasReporter {

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

// Register a new system
Expand Down
4 changes: 2 additions & 2 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 { CoreModule } from "@latticexyz/world/src/modules/core/CoreModule.sol";
import { createCoreModule } from "@latticexyz/world/test/createCoreModule.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 @@ -55,7 +55,7 @@ contract SystemSwitchTest is Test, GasReporter {
function setUp() public {
// Deploy world
World _world = new World();
_world.initialize(new CoreModule());
_world.initialize(createCoreModule());
world = IBaseWorld(address(_world));

// Deploy systems
Expand Down
4 changes: 2 additions & 2 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 { CoreModule } from "@latticexyz/world/src/modules/core/CoreModule.sol";
import { createCoreModule } from "@latticexyz/world/test/createCoreModule.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 @@ -37,7 +37,7 @@ contract UniqueEntityModuleTest is Test, GasReporter {

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

Expand Down
4 changes: 2 additions & 2 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 { CoreModule } from "@latticexyz/world/src/modules/core/CoreModule.sol";
import { createCoreModule } from "@latticexyz/world/test/createCoreModule.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 @@ -53,7 +53,7 @@ contract QueryTest is Test, GasReporter {
tableKeySchema = SchemaEncodeHelper.encode(SchemaType.BYTES32);
tableValueSchema = SchemaEncodeHelper.encode(SchemaType.UINT256);
world = IBaseWorld(address(new World()));
world.initialize(new CoreModule());
world.initialize(createCoreModule());

key1[0] = "test1";
key2[0] = "test2";
Expand Down
Loading
Loading