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,store): add initialize method, initialize core tables in core module #1472

Merged
merged 12 commits into from
Sep 13, 2023
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
9 changes: 9 additions & 0 deletions .changeset/strong-months-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@latticexyz/store": major
---

- `StoreCore`'s `initialize` function is split into `initialize` (to set the `StoreSwitch`'s `storeAddress`) and `registerCoreTables` (to register the `Tables` and `StoreHooks` tables).
The purpose of this is to give consumers more granular control over the setup flow.

- The `StoreRead` contract no longer calls `StoreCore.initialize` in its constructor.
`StoreCore` consumers are expected to call `StoreCore.initialize` and `StoreCore.registerCoreTable` in their own setup logic.
24 changes: 24 additions & 0 deletions .changeset/tricky-beds-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
"@latticexyz/cli": patch
"@latticexyz/world": minor
---

- The `World` contract now has an `initialize` function, which can be called once by the creator of the World to install the core module.
This change allows the registration of all core tables to happen in the `CoreModule`, so no table metadata has to be included in the `World`'s bytecode.

```solidity
interface IBaseWorld {
function initialize(IModule coreModule) public;
}
```

- The `World` contract now stores the original creator of the `World` in an immutable state variable.
It is used internally to only allow the original creator to initialize the `World` in a separate transaction.

```solidity
interface IBaseWorld {
function creator() external view returns (address);
}
```

- The deploy script is updated to use the `World`'s `initialize` function to install the `CoreModule` instead of `registerRootModule` as before.
4 changes: 2 additions & 2 deletions packages/cli/contracts/test/Tablegen.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
pragma solidity >=0.8.0;

import "forge-std/Test.sol";
import { StoreReadWithStubs } from "@latticexyz/store/src/StoreReadWithStubs.sol";
import { StoreMock } from "@latticexyz/store/test/StoreMock.sol";

import { Statics, StaticsData, Dynamics1, Dynamics1Data, Dynamics2, Dynamics2Data, Singleton, Ephemeral } from "../src/codegen/Tables.sol";

import { Enum1, Enum2 } from "../src/codegen/Types.sol";

contract TablegenTest is Test, StoreReadWithStubs {
contract TablegenTest is Test, StoreMock {
function testStaticsSetAndGet() public {
Statics.register();

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/utils/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export async function deploy(
// Install core Modules
if (!worldAddress) {
console.log(chalk.blue("Installing core World modules"));
await fastTxExecute(WorldContract, "installRootModule", [await modulePromises.CoreModule, "0x"], confirmations);
await fastTxExecute(WorldContract, "initialize", [await modulePromises.CoreModule], confirmations);
console.log(chalk.green("Installed core World modules"));
}

Expand Down
5 changes: 5 additions & 0 deletions packages/store/abi/StoreMock.sol/StoreMock.abi.json

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

5 changes: 5 additions & 0 deletions packages/store/abi/StoreMock.sol/StoreMock.abi.json.d.ts

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

122 changes: 0 additions & 122 deletions packages/store/abi/StoreRead.sol/StoreRead.abi.json

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

122 changes: 0 additions & 122 deletions packages/store/abi/StoreRead.sol/StoreRead.abi.json.d.ts

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

Loading