Skip to content

Commit

Permalink
transfer ownership after deploymnt
Browse files Browse the repository at this point in the history
  • Loading branch information
alvrs committed Sep 13, 2023
1 parent 8a5598a commit 790ae47
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 5 deletions.
40 changes: 40 additions & 0 deletions packages/world/abi/Create2Factory.sol/Create2Factory.abi.json.d.ts

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

36 changes: 36 additions & 0 deletions packages/world/abi/IWorldFactory.sol/IWorldFactory.abi.json.d.ts

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

60 changes: 60 additions & 0 deletions packages/world/abi/WorldFactory.sol/WorldFactory.abi.json.d.ts

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

11 changes: 8 additions & 3 deletions packages/world/src/factories/WorldFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { World } from "../World.sol";
import { IWorldFactory } from "./IWorldFactory.sol";
import { IBaseWorld } from "../interfaces/IBaseWorld.sol";
import { IModule } from "../interfaces/IModule.sol";
import { ROOT_NAMESPACE } from "../constants.sol";

contract WorldFactory is IWorldFactory {
IModule public coreModule;
Expand All @@ -16,14 +17,18 @@ contract WorldFactory is IWorldFactory {
}

/**
@dev Deploy a new World and install coreModule.
@dev Deploy a new World, install the CoreModule and transfer ownership to the caller
*/
function deployWorld() public {
// Deploy a new World and increase the WorldCount
bytes memory bytecode = type(World).creationCode;
address worldAddress = Create2.deploy(bytecode, worldCount);
address worldAddress = Create2.deploy(bytecode, worldCount++);
IBaseWorld world = IBaseWorld(worldAddress);

// Initialize the World and transfer ownership to the caller
world.installRootModule(coreModule, new bytes(0));
world.transferOwnership(ROOT_NAMESPACE, msg.sender);

emit WorldDeployed(worldAddress);
worldCount++;
}
}
10 changes: 8 additions & 2 deletions packages/world/test/Factories.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
pragma solidity >=0.8.0;

import { Test, console } from "forge-std/Test.sol";

import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol";
import { World } from "../src/World.sol";
import { CoreModule } from "../src/modules/core/CoreModule.sol";
import { Create2Factory } from "../src/factories/Create2Factory.sol";
import { WorldFactory } from "../src/factories/WorldFactory.sol";
import { IWorldFactory } from "../src/factories/IWorldFactory.sol";
import { CoreModule } from "../src/modules/core/CoreModule.sol";
import { InstalledModules, InstalledModulesData } from "../src/tables/InstalledModules.sol";
import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol";
import { NamespaceOwner } from "../src/tables/NamespaceOwner.sol";
import { ROOT_NAMESPACE } from "../src/constants.sol";

contract FactoriesTest is Test {
event ContractDeployed(address addr, uint256 salt);
Expand Down Expand Up @@ -74,5 +77,8 @@ contract FactoriesTest is Test {

// Confirm worldCount (which is salt) has incremented
assertEq(uint256(worldFactory.worldCount()), uint256(1));

// Confirm the msg.sender is owner of the root namespace of the new world
assertEq(NamespaceOwner.get(ROOT_NAMESPACE), address(this));
}
}

0 comments on commit 790ae47

Please sign in to comment.