Skip to content

Commit

Permalink
refactor(cli,world,world-modules): split and separately deploy core s…
Browse files Browse the repository at this point in the history
…ystems (#2128)

Co-authored-by: alvarius <alvarius@lattice.xyz>
Co-authored-by: Kevin Ingersoll <kingersoll@gmail.com>
  • Loading branch information
3 people committed Jan 16, 2024
1 parent e3fab07 commit 57d8965
Show file tree
Hide file tree
Showing 28 changed files with 314 additions and 130 deletions.
5 changes: 5 additions & 0 deletions .changeset/quiet-guests-approve.md
@@ -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
@@ -0,0 +1,9 @@
---
"@latticexyz/world": major
---

- Split `CoreSystem` into `AccessManagementSystem`, `BalanceTransferSystem`, `BatchCallSystem`, `CoreRegistrationSystem`
- 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.
79 changes: 76 additions & 3 deletions packages/cli/src/deploy/ensureWorldFactory.ts
@@ -1,29 +1,102 @@
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 worldFactoryBuild from "@latticexyz/world/out/WorldFactory.sol/WorldFactory.json" assert { type: "json" };
import { Client, Transport, Chain, Account, Hex, parseAbi, getCreate2Address, encodeDeployData, size } from "viem";
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";
import { deployer } from "./ensureDeployer";
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: coreModuleAbi,
args: [accessManagementSystem, balanceTransferSystem, batchCallSystem, coreRegistrationSystem],
});

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

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

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
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
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
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
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
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
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
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
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
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

0 comments on commit 57d8965

Please sign in to comment.