From 7987c94d61a2c759916a708774db9f3cf08edca8 Mon Sep 17 00:00:00 2001 From: alvarius Date: Sat, 30 Sep 2023 23:25:01 +0100 Subject: [PATCH] feat(world): return world address from WorldFactory (#1675) --- .changeset/six-kangaroos-sneeze.md | 5 +++++ packages/world/src/IWorldFactory.sol | 3 ++- packages/world/src/WorldFactory.sol | 7 ++++--- 3 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 .changeset/six-kangaroos-sneeze.md diff --git a/.changeset/six-kangaroos-sneeze.md b/.changeset/six-kangaroos-sneeze.md new file mode 100644 index 0000000000..3557002a21 --- /dev/null +++ b/.changeset/six-kangaroos-sneeze.md @@ -0,0 +1,5 @@ +--- +"@latticexyz/world": minor +--- + +Return address of the newly created World from `WorldFactory.deployWorld`. diff --git a/packages/world/src/IWorldFactory.sol b/packages/world/src/IWorldFactory.sol index 8dc363877e..7414130a60 100644 --- a/packages/world/src/IWorldFactory.sol +++ b/packages/world/src/IWorldFactory.sol @@ -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); } diff --git a/packages/world/src/WorldFactory.sol b/packages/world/src/WorldFactory.sol index 1e49c68c78..763811d606 100644 --- a/packages/world/src/WorldFactory.sol +++ b/packages/world/src/WorldFactory.sol @@ -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