-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
15 additions
and
5 deletions.
There are no files selected for viewing
16 changes: 12 additions & 4 deletions
16
packages/world-modules/src/modules/puppet/createPuppet.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,31 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.21; | ||
import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; | ||
import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.sol"; | ||
import { IWorldRegistrationSystem } from "@latticexyz/world/src/codegen/interfaces/IWorldRegistrationSystem.sol"; | ||
import { WorldResourceIdInstance } from "@latticexyz/world/src/WorldResourceId.sol"; | ||
import { PUPPET_DELEGATION, PUPPET_FACTORY } from "./constants.sol"; | ||
import { PuppetDelegationControl } from "./PuppetDelegationControl.sol"; | ||
import { Puppet } from "./Puppet.sol"; | ||
import { PuppetFactorySystem } from "./PuppetFactorySystem.sol"; | ||
import { SystemSwitch } from "../../utils/SystemSwitch.sol"; | ||
|
||
using WorldResourceIdInstance for ResourceId; | ||
|
||
/** | ||
* This free function can be used to create a puppet and register it with the puppet delegation control. | ||
* Since it is inlined in the caller's context, the calls originate from the caller's address. | ||
* The function expects to be called from a World context | ||
* (i.e. `StoreSwitch.setStoreAddress(world)` is set up in the calling contract) | ||
*/ | ||
function createPuppet(IBaseWorld world, ResourceId systemId) returns (address puppet) { | ||
function createPuppet(ResourceId systemId) returns (address puppet) { | ||
puppet = abi.decode( | ||
world.call(PUPPET_FACTORY, abi.encodeCall(PuppetFactorySystem.createPuppet, (systemId))), | ||
SystemSwitch.call(PUPPET_FACTORY, abi.encodeCall(PuppetFactorySystem.createPuppet, (systemId))), | ||
(address) | ||
); | ||
world.registerNamespaceDelegation(systemId.getNamespaceId(), PUPPET_DELEGATION, new bytes(0)); | ||
SystemSwitch.call( | ||
abi.encodeCall( | ||
IWorldRegistrationSystem.registerNamespaceDelegation, | ||
(systemId.getNamespaceId(), PUPPET_DELEGATION, new bytes(0)) | ||
) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters