@latticexyz/world-consumer 2.2.21-041031d271b62a7f41f7c6dc0098c1c0ae222bd5 → 2.2.21-581228bd857077023efdb496a9a44fa62ff89936
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/SimpleVault.sol/IERC20.json +1 -1
- package/out/SimpleVault.sol/SimpleVault.abi.json +46 -9
- package/out/SimpleVault.sol/SimpleVault.abi.json.d.ts +46 -9
- package/out/SimpleVault.sol/SimpleVault.json +1 -1
- package/out/WorldConsumer.sol/WorldConsumer.abi.json +45 -8
- package/out/WorldConsumer.sol/WorldConsumer.abi.json.d.ts +45 -8
- package/out/WorldConsumer.sol/WorldConsumer.json +1 -1
- package/out/WorldConsumer.t.sol/MockWorldConsumer.abi.json +73 -12
- package/out/WorldConsumer.t.sol/MockWorldConsumer.abi.json.d.ts +73 -12
- package/out/WorldConsumer.t.sol/MockWorldConsumer.json +1 -1
- package/out/WorldConsumer.t.sol/WorldConsumerTest.abi.json +1 -15
- package/out/WorldConsumer.t.sol/WorldConsumerTest.abi.json.d.ts +1 -15
- package/out/WorldConsumer.t.sol/WorldConsumerTest.json +1 -1
- package/out/build-info/{83e2a919446e0dcf0f3773965a164f69.json → 035195f71f276cfc878db57a98c5269a.json} +1 -1
- package/package.json +6 -6
- package/src/examples/SimpleVault.sol +3 -6
- package/src/experimental/WorldConsumer.sol +29 -24
|
@@ -1 +1 @@
|
|
|
1
|
-
{"id":"
|
|
1
|
+
{"id":"035195f71f276cfc878db57a98c5269a","source_id_to_path":{"0":"node_modules/@latticexyz/gas-report/src/GasReporter.sol","1":"node_modules/@latticexyz/schema-type/src/solidity/SchemaType.sol","2":"node_modules/@latticexyz/store/src/Bytes.sol","3":"node_modules/@latticexyz/store/src/EncodedLengths.sol","4":"node_modules/@latticexyz/store/src/FieldLayout.sol","5":"node_modules/@latticexyz/store/src/Hook.sol","6":"node_modules/@latticexyz/store/src/IERC165.sol","7":"node_modules/@latticexyz/store/src/IEncodedLengthsErrors.sol","8":"node_modules/@latticexyz/store/src/IFieldLayoutErrors.sol","9":"node_modules/@latticexyz/store/src/ISchemaErrors.sol","10":"node_modules/@latticexyz/store/src/ISliceErrors.sol","11":"node_modules/@latticexyz/store/src/IStore.sol","12":"node_modules/@latticexyz/store/src/IStoreErrors.sol","13":"node_modules/@latticexyz/store/src/IStoreEvents.sol","14":"node_modules/@latticexyz/store/src/IStoreHook.sol","15":"node_modules/@latticexyz/store/src/IStoreKernel.sol","16":"node_modules/@latticexyz/store/src/IStoreRead.sol","17":"node_modules/@latticexyz/store/src/IStoreRegistration.sol","18":"node_modules/@latticexyz/store/src/IStoreWrite.sol","19":"node_modules/@latticexyz/store/src/Memory.sol","20":"node_modules/@latticexyz/store/src/ResourceId.sol","21":"node_modules/@latticexyz/store/src/Schema.sol","22":"node_modules/@latticexyz/store/src/Slice.sol","23":"node_modules/@latticexyz/store/src/Storage.sol","24":"node_modules/@latticexyz/store/src/Store.sol","25":"node_modules/@latticexyz/store/src/StoreCore.sol","26":"node_modules/@latticexyz/store/src/StoreKernel.sol","27":"node_modules/@latticexyz/store/src/StoreRead.sol","28":"node_modules/@latticexyz/store/src/StoreSwitch.sol","29":"node_modules/@latticexyz/store/src/codegen/index.sol","30":"node_modules/@latticexyz/store/src/codegen/tables/Hooks.sol","31":"node_modules/@latticexyz/store/src/codegen/tables/ResourceIds.sol","32":"node_modules/@latticexyz/store/src/codegen/tables/StoreHooks.sol","33":"node_modules/@latticexyz/store/src/codegen/tables/Tables.sol","34":"node_modules/@latticexyz/store/src/constants.sol","35":"node_modules/@latticexyz/store/src/rightMask.sol","36":"node_modules/@latticexyz/store/src/storeHookTypes.sol","37":"node_modules/@latticexyz/store/src/storeResourceTypes.sol","38":"node_modules/@latticexyz/store/src/tightcoder/DecodeSlice.sol","39":"node_modules/@latticexyz/store/src/tightcoder/EncodeArray.sol","40":"node_modules/@latticexyz/store/src/tightcoder/TightCoder.sol","41":"node_modules/@latticexyz/store/src/version.sol","42":"node_modules/@latticexyz/world/src/AccessControl.sol","43":"node_modules/@latticexyz/world/src/Delegation.sol","44":"node_modules/@latticexyz/world/src/ERC165Checker.sol","45":"node_modules/@latticexyz/world/src/IDelegationControl.sol","46":"node_modules/@latticexyz/world/src/IERC165.sol","47":"node_modules/@latticexyz/world/src/IModule.sol","48":"node_modules/@latticexyz/world/src/IModuleErrors.sol","49":"node_modules/@latticexyz/world/src/ISystemHook.sol","50":"node_modules/@latticexyz/world/src/IWorldContextConsumer.sol","51":"node_modules/@latticexyz/world/src/IWorldErrors.sol","52":"node_modules/@latticexyz/world/src/IWorldEvents.sol","53":"node_modules/@latticexyz/world/src/IWorldKernel.sol","54":"node_modules/@latticexyz/world/src/Module.sol","55":"node_modules/@latticexyz/world/src/System.sol","56":"node_modules/@latticexyz/world/src/SystemCall.sol","57":"node_modules/@latticexyz/world/src/World.sol","58":"node_modules/@latticexyz/world/src/WorldContext.sol","59":"node_modules/@latticexyz/world/src/WorldResourceId.sol","60":"node_modules/@latticexyz/world/src/codegen/interfaces/IAccessManagementSystem.sol","61":"node_modules/@latticexyz/world/src/codegen/interfaces/IBalanceTransferSystem.sol","62":"node_modules/@latticexyz/world/src/codegen/interfaces/IBaseWorld.sol","63":"node_modules/@latticexyz/world/src/codegen/interfaces/IBatchCallSystem.sol","64":"node_modules/@latticexyz/world/src/codegen/interfaces/IModuleInstallationSystem.sol","65":"node_modules/@latticexyz/world/src/codegen/interfaces/IRegistrationSystem.sol","66":"node_modules/@latticexyz/world/src/codegen/interfaces/IWorldRegistrationSystem.sol","67":"node_modules/@latticexyz/world/src/codegen/tables/Balances.sol","68":"node_modules/@latticexyz/world/src/codegen/tables/FunctionSelectors.sol","69":"node_modules/@latticexyz/world/src/codegen/tables/FunctionSignatures.sol","70":"node_modules/@latticexyz/world/src/codegen/tables/InitModuleAddress.sol","71":"node_modules/@latticexyz/world/src/codegen/tables/InstalledModules.sol","72":"node_modules/@latticexyz/world/src/codegen/tables/NamespaceDelegationControl.sol","73":"node_modules/@latticexyz/world/src/codegen/tables/NamespaceOwner.sol","74":"node_modules/@latticexyz/world/src/codegen/tables/ResourceAccess.sol","75":"node_modules/@latticexyz/world/src/codegen/tables/SystemHooks.sol","76":"node_modules/@latticexyz/world/src/codegen/tables/SystemRegistry.sol","77":"node_modules/@latticexyz/world/src/codegen/tables/Systems.sol","78":"node_modules/@latticexyz/world/src/codegen/tables/UserDelegationControl.sol","79":"node_modules/@latticexyz/world/src/constants.sol","80":"node_modules/@latticexyz/world/src/modules/init/InitModule.sol","81":"node_modules/@latticexyz/world/src/modules/init/LimitedCallContext.sol","82":"node_modules/@latticexyz/world/src/modules/init/RegistrationSystem.sol","83":"node_modules/@latticexyz/world/src/modules/init/constants.sol","84":"node_modules/@latticexyz/world/src/modules/init/functionSignatures.sol","85":"node_modules/@latticexyz/world/src/modules/init/implementations/AccessManagementSystem.sol","86":"node_modules/@latticexyz/world/src/modules/init/implementations/BalanceTransferSystem.sol","87":"node_modules/@latticexyz/world/src/modules/init/implementations/BatchCallSystem.sol","88":"node_modules/@latticexyz/world/src/modules/init/implementations/ModuleInstallationSystem.sol","89":"node_modules/@latticexyz/world/src/modules/init/implementations/StoreRegistrationSystem.sol","90":"node_modules/@latticexyz/world/src/modules/init/implementations/WorldRegistrationSystem.sol","91":"node_modules/@latticexyz/world/src/modules/init/implementations/createDelegation.sol","92":"node_modules/@latticexyz/world/src/modules/init/types.sol","93":"node_modules/@latticexyz/world/src/requireInterface.sol","94":"node_modules/@latticexyz/world/src/requireNamespace.sol","95":"node_modules/@latticexyz/world/src/requireValidNamespace.sol","96":"node_modules/@latticexyz/world/src/revertWithBytes.sol","97":"node_modules/@latticexyz/world/src/systemHookTypes.sol","98":"node_modules/@latticexyz/world/src/version.sol","99":"node_modules/@latticexyz/world/src/worldResourceTypes.sol","100":"node_modules/@latticexyz/world/test/createInitModule.sol","101":"node_modules/@latticexyz/world/test/createWorld.sol","102":"node_modules/forge-std/src/Base.sol","103":"node_modules/forge-std/src/StdAssertions.sol","104":"node_modules/forge-std/src/StdChains.sol","105":"node_modules/forge-std/src/StdCheats.sol","106":"node_modules/forge-std/src/StdError.sol","107":"node_modules/forge-std/src/StdInvariant.sol","108":"node_modules/forge-std/src/StdJson.sol","109":"node_modules/forge-std/src/StdMath.sol","110":"node_modules/forge-std/src/StdStorage.sol","111":"node_modules/forge-std/src/StdStyle.sol","112":"node_modules/forge-std/src/StdToml.sol","113":"node_modules/forge-std/src/StdUtils.sol","114":"node_modules/forge-std/src/Test.sol","115":"node_modules/forge-std/src/Vm.sol","116":"node_modules/forge-std/src/console.sol","117":"node_modules/forge-std/src/console2.sol","118":"node_modules/forge-std/src/interfaces/IERC165.sol","119":"node_modules/forge-std/src/interfaces/IERC20.sol","120":"node_modules/forge-std/src/interfaces/IERC721.sol","121":"node_modules/forge-std/src/interfaces/IMulticall3.sol","122":"node_modules/forge-std/src/mocks/MockERC20.sol","123":"node_modules/forge-std/src/mocks/MockERC721.sol","124":"node_modules/forge-std/src/safeconsole.sol","125":"src/examples/SimpleVault.sol","126":"src/experimental/WorldConsumer.sol","127":"test/WorldConsumer.t.sol"},"language":"Solidity"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@latticexyz/world-consumer",
|
|
3
|
-
"version": "2.2.21-
|
|
3
|
+
"version": "2.2.21-581228bd857077023efdb496a9a44fa62ff89936",
|
|
4
4
|
"description": "World Consumer Contracts",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -20,15 +20,15 @@
|
|
|
20
20
|
"src"
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@latticexyz/schema-type": "2.2.21-
|
|
24
|
-
"@latticexyz/
|
|
25
|
-
"@latticexyz/
|
|
23
|
+
"@latticexyz/schema-type": "2.2.21-581228bd857077023efdb496a9a44fa62ff89936",
|
|
24
|
+
"@latticexyz/store": "2.2.21-581228bd857077023efdb496a9a44fa62ff89936",
|
|
25
|
+
"@latticexyz/world": "2.2.21-581228bd857077023efdb496a9a44fa62ff89936"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"forge-std": "https://github.com/foundry-rs/forge-std.git#1eea5bae12ae557d589f9f0f0edae2faa47cb262",
|
|
29
29
|
"solhint": "^3.3.7",
|
|
30
|
-
"@latticexyz/abi-ts": "2.2.21-
|
|
31
|
-
"@latticexyz/gas-report": "2.2.21-
|
|
30
|
+
"@latticexyz/abi-ts": "2.2.21-581228bd857077023efdb496a9a44fa62ff89936",
|
|
31
|
+
"@latticexyz/gas-report": "2.2.21-581228bd857077023efdb496a9a44fa62ff89936"
|
|
32
32
|
},
|
|
33
33
|
"publishConfig": {
|
|
34
34
|
"access": "public"
|
|
@@ -17,18 +17,15 @@ interface IERC20 {
|
|
|
17
17
|
/**
|
|
18
18
|
* @title SimpleVault (NOT AUDITED)
|
|
19
19
|
* @dev Simple example of a Vault that allows accounts with namespace access to transfer its tokens out
|
|
20
|
+
* IMPORTANT: this contract expects an existing namespace
|
|
20
21
|
*/
|
|
21
22
|
contract SimpleVault is WorldConsumer {
|
|
22
23
|
error SimpleVault_TransferFailed();
|
|
23
24
|
|
|
24
|
-
bytes14
|
|
25
|
-
|
|
26
|
-
constructor(IBaseWorld world, bytes14 _namespace) WorldConsumer(world) {
|
|
27
|
-
namespace = _namespace;
|
|
28
|
-
}
|
|
25
|
+
constructor(IBaseWorld world, bytes14 namespace) WorldConsumer(world, namespace, false) {}
|
|
29
26
|
|
|
30
27
|
// Only accounts with namespace access (e.g. namespace systems) can transfer the ERC20 tokens held by this contract
|
|
31
|
-
function transferTo(IERC20 token, address to, uint256 amount) external
|
|
28
|
+
function transferTo(IERC20 token, address to, uint256 amount) external onlyWorld {
|
|
32
29
|
require(token.transfer(to, amount), "Transfer failed");
|
|
33
30
|
}
|
|
34
31
|
|
|
@@ -6,54 +6,65 @@ import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol";
|
|
|
6
6
|
import { ResourceIds } from "@latticexyz/store/src/codegen/tables/ResourceIds.sol";
|
|
7
7
|
import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";
|
|
8
8
|
import { ResourceAccess } from "@latticexyz/world/src/codegen/tables/ResourceAccess.sol";
|
|
9
|
-
import { NamespaceOwner } from "@latticexyz/world/src/codegen/tables/NamespaceOwner.sol";
|
|
10
9
|
import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.sol";
|
|
11
10
|
import { WorldResourceIdLib } from "@latticexyz/world/src/WorldResourceId.sol";
|
|
12
11
|
import { WorldContextConsumer } from "@latticexyz/world/src/WorldContext.sol";
|
|
13
12
|
import { System } from "@latticexyz/world/src/System.sol";
|
|
14
13
|
|
|
15
14
|
abstract contract WorldConsumer is System {
|
|
15
|
+
bytes14 public immutable namespace;
|
|
16
|
+
ResourceId public immutable namespaceId;
|
|
17
|
+
|
|
16
18
|
error WorldConsumer_RootNamespaceNotAllowed(address worldAddress);
|
|
19
|
+
error WorldConsumer_NamespaceAlreadyExists(address worldAddress, bytes14 namespace);
|
|
20
|
+
error WorldConsumer_NamespaceDoesNotExists(address worldAddress, bytes14 namespace);
|
|
17
21
|
error WorldConsumer_CallerHasNoNamespaceAccess(address worldAddress, bytes14 namespace, address caller);
|
|
18
|
-
error WorldConsumer_CallerIsNotNamespaceOwner(address worldAddress, bytes14 namespace, address caller);
|
|
19
22
|
error WorldConsumer_CallerIsNotWorld(address worldAddress, address caller);
|
|
20
23
|
error WorldConsumer_ValueNotAllowed(address worldAddress);
|
|
21
24
|
|
|
22
25
|
modifier onlyWorld() {
|
|
23
26
|
address world = _world();
|
|
24
|
-
|
|
27
|
+
if (world != msg.sender) {
|
|
28
|
+
revert WorldConsumer_CallerIsNotWorld(world, msg.sender);
|
|
29
|
+
}
|
|
25
30
|
_;
|
|
26
31
|
}
|
|
27
32
|
|
|
28
|
-
modifier onlyNamespace(
|
|
33
|
+
modifier onlyNamespace() {
|
|
29
34
|
address world = _world();
|
|
30
|
-
|
|
35
|
+
if (world != msg.sender) {
|
|
36
|
+
revert WorldConsumer_CallerIsNotWorld(world, msg.sender);
|
|
37
|
+
}
|
|
31
38
|
|
|
32
39
|
// We use WorldContextConsumer directly as we already know the world is the caller
|
|
33
40
|
address sender = WorldContextConsumer._msgSender();
|
|
34
|
-
if (!ResourceAccess.get(
|
|
41
|
+
if (!ResourceAccess.get(namespaceId, sender)) {
|
|
35
42
|
revert WorldConsumer_CallerHasNoNamespaceAccess(world, namespace, sender);
|
|
36
43
|
}
|
|
37
44
|
|
|
38
45
|
_;
|
|
39
46
|
}
|
|
40
47
|
|
|
41
|
-
|
|
42
|
-
address
|
|
43
|
-
|
|
48
|
+
constructor(IBaseWorld _world, bytes14 _namespace, bool registerNamespace) {
|
|
49
|
+
address worldAddress = address(_world);
|
|
50
|
+
StoreSwitch.setStoreAddress(worldAddress);
|
|
44
51
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (NamespaceOwner.get(WorldResourceIdLib.encodeNamespace(namespace)) != sender) {
|
|
48
|
-
revert WorldConsumer_CallerIsNotNamespaceOwner(world, namespace, sender);
|
|
52
|
+
if (_namespace == bytes14(0)) {
|
|
53
|
+
revert WorldConsumer_RootNamespaceNotAllowed(worldAddress);
|
|
49
54
|
}
|
|
50
55
|
|
|
51
|
-
|
|
52
|
-
|
|
56
|
+
namespace = _namespace;
|
|
57
|
+
namespaceId = WorldResourceIdLib.encodeNamespace(_namespace);
|
|
58
|
+
bool namespaceExists = ResourceIds.getExists(namespaceId);
|
|
53
59
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
60
|
+
if (registerNamespace) {
|
|
61
|
+
if (namespaceExists) {
|
|
62
|
+
revert WorldConsumer_NamespaceAlreadyExists(worldAddress, _namespace);
|
|
63
|
+
}
|
|
64
|
+
_world.registerNamespace(namespaceId);
|
|
65
|
+
} else if (!namespaceExists) {
|
|
66
|
+
revert WorldConsumer_NamespaceDoesNotExists(worldAddress, _namespace);
|
|
67
|
+
}
|
|
57
68
|
}
|
|
58
69
|
|
|
59
70
|
function _msgSender() public view virtual override returns (address sender) {
|
|
@@ -68,10 +79,4 @@ abstract contract WorldConsumer is System {
|
|
|
68
79
|
|
|
69
80
|
return WorldContextConsumer._msgValue();
|
|
70
81
|
}
|
|
71
|
-
|
|
72
|
-
function checkWorldIsCaller(address world) internal view {
|
|
73
|
-
if (world != msg.sender) {
|
|
74
|
-
revert WorldConsumer_CallerIsNotWorld(world, msg.sender);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
82
|
}
|