-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into holic/world-system-libs
- Loading branch information
Showing
39 changed files
with
281 additions
and
696 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@latticexyz/explorer": patch | ||
--- | ||
|
||
Table names in SQL queries are now automatically enclosed in double quotes by default, allowing support for special characters. |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@latticexyz/world-module-erc20": patch | ||
--- | ||
|
||
Migrated from `store-consumer` to `world-consumer`. |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@latticexyz/world-consumer": patch | ||
--- | ||
|
||
Renamed `store-consumer` package to `world-consumer`. The `world-consumer` package now only includes a single `WorldConsumer` contract that is bound to a `World`. |
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
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
packages/store-consumer/src/experimental/StoreConsumer.sol
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# World Consumer | ||
|
||
> :warning: **Important note: these contracts have not been audited yet, so any production use is discouraged for now.** | ||
The `WorldConsumer` contract allows contracts that inherit from it to be registered as systems while also supporting functions that can be called from outside of the world `World`. | ||
It initializes the store and also registers the provided namespace in the provided World. It provides the `onlyWorld` and `onlyNamespace` modifiers, which can be used to restrict access to certain functions, only allowing calls that come from the world. | ||
|
||
For examples of how it can be used in practice you can check the [examples directory](./src/examples/) and our [ERC20 World Module](../world-module-erc20/). |
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
packages/store-consumer/package.json → packages/world-consumer/package.json
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
File renamed without changes.
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
82 changes: 82 additions & 0 deletions
82
packages/world-consumer/src/experimental/WorldConsumer.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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.24; | ||
|
||
import { RESOURCE_TABLE, RESOURCE_OFFCHAIN_TABLE } from "@latticexyz/store/src/storeResourceTypes.sol"; | ||
import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; | ||
import { ResourceIds } from "@latticexyz/store/src/codegen/tables/ResourceIds.sol"; | ||
import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; | ||
import { ResourceAccess } from "@latticexyz/world/src/codegen/tables/ResourceAccess.sol"; | ||
import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.sol"; | ||
import { WorldResourceIdLib } from "@latticexyz/world/src/WorldResourceId.sol"; | ||
import { WorldContextConsumer } from "@latticexyz/world/src/WorldContext.sol"; | ||
import { System } from "@latticexyz/world/src/System.sol"; | ||
|
||
abstract contract WorldConsumer is System { | ||
bytes14 public immutable namespace; | ||
ResourceId public immutable namespaceId; | ||
|
||
error WorldConsumer_RootNamespaceNotAllowed(address worldAddress); | ||
error WorldConsumer_NamespaceAlreadyExists(address worldAddress, bytes14 namespace); | ||
error WorldConsumer_NamespaceDoesNotExists(address worldAddress, bytes14 namespace); | ||
error WorldConsumer_CallerHasNoNamespaceAccess(address worldAddress, bytes14 namespace, address caller); | ||
error WorldConsumer_CallerIsNotWorld(address worldAddress, address caller); | ||
error WorldConsumer_ValueNotAllowed(address worldAddress); | ||
|
||
modifier onlyWorld() { | ||
address world = _world(); | ||
if (world != msg.sender) { | ||
revert WorldConsumer_CallerIsNotWorld(world, msg.sender); | ||
} | ||
_; | ||
} | ||
|
||
modifier onlyNamespace() { | ||
address world = _world(); | ||
if (world != msg.sender) { | ||
revert WorldConsumer_CallerIsNotWorld(world, msg.sender); | ||
} | ||
|
||
// We use WorldContextConsumer directly as we already know the world is the caller | ||
address sender = WorldContextConsumer._msgSender(); | ||
if (!ResourceAccess.get(namespaceId, sender)) { | ||
revert WorldConsumer_CallerHasNoNamespaceAccess(world, namespace, sender); | ||
} | ||
|
||
_; | ||
} | ||
|
||
constructor(IBaseWorld _world, bytes14 _namespace, bool registerNamespace) { | ||
address worldAddress = address(_world); | ||
StoreSwitch.setStoreAddress(worldAddress); | ||
|
||
if (_namespace == bytes14(0)) { | ||
revert WorldConsumer_RootNamespaceNotAllowed(worldAddress); | ||
} | ||
|
||
namespace = _namespace; | ||
namespaceId = WorldResourceIdLib.encodeNamespace(_namespace); | ||
bool namespaceExists = ResourceIds.getExists(namespaceId); | ||
|
||
if (registerNamespace) { | ||
if (namespaceExists) { | ||
revert WorldConsumer_NamespaceAlreadyExists(worldAddress, _namespace); | ||
} | ||
_world.registerNamespace(namespaceId); | ||
} else if (!namespaceExists) { | ||
revert WorldConsumer_NamespaceDoesNotExists(worldAddress, _namespace); | ||
} | ||
} | ||
|
||
function _msgSender() public view virtual override returns (address sender) { | ||
return _world() == msg.sender ? WorldContextConsumer._msgSender() : msg.sender; | ||
} | ||
|
||
function _msgValue() public view virtual override returns (uint256 value) { | ||
address world = _world(); | ||
if (world != msg.sender) { | ||
revert WorldConsumer_ValueNotAllowed(world); | ||
} | ||
|
||
return WorldContextConsumer._msgValue(); | ||
} | ||
} |
Oops, something went wrong.