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): return world address from WorldFactory #1675

Merged
merged 3 commits into from
Sep 30, 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
5 changes: 5 additions & 0 deletions .changeset/six-kangaroos-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/world": minor
---

Return address of the newly created World from `WorldFactory.deployWorld`.
3 changes: 2 additions & 1 deletion packages/world/src/IWorldFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface IWorldFactory {
/**
* @notice Deploys a new World contract.
* @dev The deployment of the World contract will result in the `WorldDeployed` event being emitted.
* @return worldAddress The address of the newly deployed World contract.
*/
function deployWorld() external;
function deployWorld() external returns (address worldAddress);
}
7 changes: 4 additions & 3 deletions packages/world/src/WorldFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ contract WorldFactory is IWorldFactory {
}

/**
* @notice Deploys a new World instance, sets the CoreModule and transfers its ownership to the caller.
* @notice Deploys a new World instance, installs the CoreModule and transfers ownership to the caller.
* @dev Uses the Create2 for deterministic deployment.
* @return worldAddress The address of the newly deployed World contract.
*/
function deployWorld() public {
function deployWorld() public returns (address worldAddress) {
// Deploy a new World and increase the WorldCount
bytes memory bytecode = type(World).creationCode;
address worldAddress = Create2.deploy(bytecode, worldCount++);
worldAddress = Create2.deploy(bytecode, worldCount++);
IBaseWorld world = IBaseWorld(worldAddress);

// Initialize the World and transfer ownership to the caller
Expand Down