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): add world factory #1385

Merged
merged 7 commits into from
Sep 13, 2023
Merged

Conversation

johngrantuk
Copy link
Contributor

@johngrantuk johngrantuk commented Sep 1, 2023

WorldFactory allows new worlds to be deployed (with a predefined CoreModule installed) using create2

  • Used an internal count as Salt. Makes it easier for a user. (And allows all previous deployed World addresses to be calculated.)
  • For CoreModule - passed in to Factory constructor so we associate one CoreModule with all pools created from factory.
    Create2Factory is a stand alone helper contract that can be used to deploy any contract using create2. Eventually this could be used to deploy WorldFactory, CoreModule, Systems, etc.

Deploy script will be updated to use factory in a future PR after this and #1384 have been finalised.

@changeset-bot
Copy link

changeset-bot bot commented Sep 1, 2023

⚠️ No Changeset found

Latest commit: 790ae47

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Comment on lines 21 to 28
function deployWorld() public {
bytes memory bytecode = type(World).creationCode;
address worldAddress = Create2.create2Deploy(bytecode, worldCount);
IBaseWorld world = IBaseWorld(worldAddress);
world.installRootModule(coreModule, new bytes(0));
emit WorldDeployed(worldAddress);
worldCount++;
}
Copy link
Member

Choose a reason for hiding this comment

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

Should we transfer the ownership of the root module to the caller after installing the root module? (Or maybe we could make it optional and emit the selected option as part of the event? The interesting thing with a deploy function that does not transfer ownership of the root module is that users can be sure the World behaves exactly as the audited vanilla World)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As it currently stands it would be the Factory address that would be the owner? I imagine the caller would probably assume they will be the owner so maybe that is best although I'm happy to take direction as I don't have a full understanding of the knock on effects.

address calculatedAddress = calculateAddress(address(create2Factory), bytes32(0), combinedBytes);
// Confirm event for deployment
vm.expectEmit(true, false, false, false);
emit ContractDeployed(calculatedAddress, uint256(0));
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 use emit Create2Factory.ContractDeployed here (and in the other places) to avoid having to redefine the events in the test?

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 can't seem to make this work. I noticed in other tests the events are redefined, e.g. World.t.sol. Could you point me to somewhere I can use as an example if it is possible?

Copy link
Member

Choose a reason for hiding this comment

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

seems to not be possible yet, but soon: ethereum/solidity#14274

Copy link
Member

Choose a reason for hiding this comment

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

looks like it's part of the 0.8.21 release: https://github.com/ethereum/solidity/releases/tag/v0.8.21

Allow qualified access to events from other contracts.

@alvrs alvrs changed the title feat(world): Add world factory feat(world): add world factory Sep 13, 2023
@alvrs alvrs marked this pull request as ready for review September 13, 2023 19:09
@alvrs alvrs requested a review from holic as a code owner September 13, 2023 19:09
@alvrs alvrs merged commit 64014e4 into latticexyz:main Sep 13, 2023
9 of 10 checks passed
@dev Helper Contract to facilitate create2 deployment of Contracts.
*/
contract Create2Factory {
event ContractDeployed(address addr, uint256 salt);
Copy link
Member

Choose a reason for hiding this comment

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

is this a standard somewhere? should we have an index on addr?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants