@latticexyz/world-modules 2.0.12-main-ecc8f658 → 2.0.12-type-resolutions-effc7ab1
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/cache/solidity-files-cache.json +1 -0
- package/dist/mud.config.d.ts +0 -2
- package/package.json +9 -9
- package/src/index.sol +0 -25
- package/src/interfaces/IBaseWorld.sol +0 -16
- package/src/interfaces/IERC20System.sol +0 -33
- package/src/interfaces/IERC721System.sol +0 -43
- package/src/interfaces/IPuppetFactorySystem.sol +0 -15
- package/src/interfaces/IUniqueEntitySystem.sol +0 -13
- package/src/interfaces/IUnstable_CallWithSignatureSystem.sol +0 -20
- package/src/modules/callwithsignature/ECDSA.sol +0 -174
- package/src/modules/callwithsignature/IERC1271.sol +0 -17
- package/src/modules/callwithsignature/IUnstable_CallWithSignatureErrors.sol +0 -9
- package/src/modules/callwithsignature/SignatureChecker.sol +0 -50
- package/src/modules/callwithsignature/Unstable_CallWithSignatureModule.sol +0 -48
- package/src/modules/callwithsignature/Unstable_CallWithSignatureSystem.sol +0 -36
- package/src/modules/callwithsignature/constants.sol +0 -10
- package/src/modules/callwithsignature/getSignedMessageHash.sol +0 -54
- package/src/modules/callwithsignature/tables/CallWithSignatureNonces.sol +0 -199
- package/src/modules/callwithsignature/validateCallWithSignature.sol +0 -31
- package/src/modules/erc20-puppet/ERC20Module.sol +0 -88
- package/src/modules/erc20-puppet/ERC20System.sol +0 -286
- package/src/modules/erc20-puppet/IERC20.sol +0 -94
- package/src/modules/erc20-puppet/IERC20Errors.sol +0 -49
- package/src/modules/erc20-puppet/IERC20Events.sol +0 -18
- package/src/modules/erc20-puppet/IERC20Mintable.sol +0 -25
- package/src/modules/erc20-puppet/constants.sol +0 -20
- package/src/modules/erc20-puppet/registerERC20.sol +0 -35
- package/src/modules/erc20-puppet/tables/Allowances.sol +0 -208
- package/src/modules/erc20-puppet/tables/ERC20Metadata.sol +0 -604
- package/src/modules/erc20-puppet/tables/ERC20Registry.sol +0 -199
- package/src/modules/erc20-puppet/tables/TotalSupply.sol +0 -184
- package/src/modules/erc20-puppet/utils.sol +0 -30
- package/src/modules/erc721-puppet/ERC721Module.sol +0 -95
- package/src/modules/erc721-puppet/ERC721System.sol +0 -531
- package/src/modules/erc721-puppet/IERC721.sol +0 -120
- package/src/modules/erc721-puppet/IERC721Errors.sol +0 -61
- package/src/modules/erc721-puppet/IERC721Events.sol +0 -23
- package/src/modules/erc721-puppet/IERC721Metadata.sol +0 -27
- package/src/modules/erc721-puppet/IERC721Mintable.sol +0 -53
- package/src/modules/erc721-puppet/IERC721Receiver.sol +0 -28
- package/src/modules/erc721-puppet/constants.sol +0 -23
- package/src/modules/erc721-puppet/libraries/LibString.sol +0 -77
- package/src/modules/erc721-puppet/registerERC721.sol +0 -37
- package/src/modules/erc721-puppet/tables/ERC721Metadata.sol +0 -703
- package/src/modules/erc721-puppet/tables/ERC721Registry.sol +0 -199
- package/src/modules/erc721-puppet/tables/OperatorApproval.sol +0 -220
- package/src/modules/erc721-puppet/tables/Owners.sol +0 -196
- package/src/modules/erc721-puppet/tables/TokenApproval.sol +0 -196
- package/src/modules/erc721-puppet/tables/TokenURI.sol +0 -450
- package/src/modules/erc721-puppet/utils.sol +0 -38
- package/src/modules/keysintable/KeysInTableHook.sol +0 -141
- package/src/modules/keysintable/KeysInTableModule.sol +0 -110
- package/src/modules/keysintable/constants.sol +0 -7
- package/src/modules/keysintable/getKeysInTable.sol +0 -81
- package/src/modules/keysintable/hasKey.sol +0 -28
- package/src/modules/keysintable/query.sol +0 -200
- package/src/modules/keysintable/tables/KeysInTable.sol +0 -1638
- package/src/modules/keysintable/tables/UsedKeysIndex.sol +0 -414
- package/src/modules/keyswithvalue/KeysWithValueHook.sol +0 -158
- package/src/modules/keyswithvalue/KeysWithValueModule.sol +0 -103
- package/src/modules/keyswithvalue/constants.sol +0 -7
- package/src/modules/keyswithvalue/getKeysWithValue.sol +0 -58
- package/src/modules/keyswithvalue/getTargetTableId.sol +0 -32
- package/src/modules/keyswithvalue/tables/KeysWithValue.sol +0 -668
- package/src/modules/puppet/Puppet.sol +0 -80
- package/src/modules/puppet/PuppetDelegationControl.sol +0 -17
- package/src/modules/puppet/PuppetFactorySystem.sol +0 -25
- package/src/modules/puppet/PuppetMaster.sol +0 -19
- package/src/modules/puppet/PuppetModule.sol +0 -64
- package/src/modules/puppet/constants.sol +0 -23
- package/src/modules/puppet/createPuppet.sol +0 -24
- package/src/modules/puppet/tables/PuppetRegistry.sol +0 -199
- package/src/modules/puppet/utils.sol +0 -10
- package/src/modules/std-delegations/CallboundDelegationControl.sol +0 -64
- package/src/modules/std-delegations/StandardDelegationsModule.sol +0 -55
- package/src/modules/std-delegations/SystemboundDelegationControl.sol +0 -54
- package/src/modules/std-delegations/TimeboundDelegationControl.sol +0 -27
- package/src/modules/std-delegations/constants.sol +0 -21
- package/src/modules/std-delegations/tables/CallboundDelegations.sol +0 -287
- package/src/modules/std-delegations/tables/SystemboundDelegations.sol +0 -256
- package/src/modules/std-delegations/tables/TimeboundDelegations.sol +0 -211
- package/src/modules/tokens/tables/Balances.sol +0 -196
- package/src/modules/uniqueentity/UniqueEntityModule.sol +0 -73
- package/src/modules/uniqueentity/UniqueEntitySystem.sol +0 -18
- package/src/modules/uniqueentity/constants.sol +0 -13
- package/src/modules/uniqueentity/getUniqueEntity.sol +0 -26
- package/src/modules/uniqueentity/tables/UniqueEntity.sol +0 -238
- package/src/modules/utils/ArrayLib.sol +0 -55
- package/src/utils/AccessControlLib.sol +0 -55
- package/src/utils/SystemSwitch.sol +0 -80
@@ -1,238 +0,0 @@
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
2
|
-
pragma solidity >=0.8.24;
|
3
|
-
|
4
|
-
/* Autogenerated file. Do not edit manually. */
|
5
|
-
|
6
|
-
// Import store internals
|
7
|
-
import { IStore } from "@latticexyz/store/src/IStore.sol";
|
8
|
-
import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol";
|
9
|
-
import { StoreCore } from "@latticexyz/store/src/StoreCore.sol";
|
10
|
-
import { Bytes } from "@latticexyz/store/src/Bytes.sol";
|
11
|
-
import { Memory } from "@latticexyz/store/src/Memory.sol";
|
12
|
-
import { SliceLib } from "@latticexyz/store/src/Slice.sol";
|
13
|
-
import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol";
|
14
|
-
import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol";
|
15
|
-
import { Schema } from "@latticexyz/store/src/Schema.sol";
|
16
|
-
import { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol";
|
17
|
-
import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";
|
18
|
-
|
19
|
-
library UniqueEntity {
|
20
|
-
FieldLayout constant _fieldLayout =
|
21
|
-
FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000);
|
22
|
-
|
23
|
-
// Hex-encoded key schema of ()
|
24
|
-
Schema constant _keySchema = Schema.wrap(0x0000000000000000000000000000000000000000000000000000000000000000);
|
25
|
-
// Hex-encoded value schema of (uint256)
|
26
|
-
Schema constant _valueSchema = Schema.wrap(0x002001001f000000000000000000000000000000000000000000000000000000);
|
27
|
-
|
28
|
-
/**
|
29
|
-
* @notice Get the table's key field names.
|
30
|
-
* @return keyNames An array of strings with the names of key fields.
|
31
|
-
*/
|
32
|
-
function getKeyNames() internal pure returns (string[] memory keyNames) {
|
33
|
-
keyNames = new string[](0);
|
34
|
-
}
|
35
|
-
|
36
|
-
/**
|
37
|
-
* @notice Get the table's value field names.
|
38
|
-
* @return fieldNames An array of strings with the names of value fields.
|
39
|
-
*/
|
40
|
-
function getFieldNames() internal pure returns (string[] memory fieldNames) {
|
41
|
-
fieldNames = new string[](1);
|
42
|
-
fieldNames[0] = "value";
|
43
|
-
}
|
44
|
-
|
45
|
-
/**
|
46
|
-
* @notice Register the table with its config.
|
47
|
-
*/
|
48
|
-
function register(ResourceId _tableId) internal {
|
49
|
-
StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
|
50
|
-
}
|
51
|
-
|
52
|
-
/**
|
53
|
-
* @notice Register the table with its config.
|
54
|
-
*/
|
55
|
-
function _register(ResourceId _tableId) internal {
|
56
|
-
StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
|
57
|
-
}
|
58
|
-
|
59
|
-
/**
|
60
|
-
* @notice Register the table with its config (using the specified store).
|
61
|
-
*/
|
62
|
-
function register(IStore _store, ResourceId _tableId) internal {
|
63
|
-
_store.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
|
64
|
-
}
|
65
|
-
|
66
|
-
/**
|
67
|
-
* @notice Get value.
|
68
|
-
*/
|
69
|
-
function getValue(ResourceId _tableId) internal view returns (uint256 value) {
|
70
|
-
bytes32[] memory _keyTuple = new bytes32[](0);
|
71
|
-
|
72
|
-
bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
73
|
-
return (uint256(bytes32(_blob)));
|
74
|
-
}
|
75
|
-
|
76
|
-
/**
|
77
|
-
* @notice Get value.
|
78
|
-
*/
|
79
|
-
function _getValue(ResourceId _tableId) internal view returns (uint256 value) {
|
80
|
-
bytes32[] memory _keyTuple = new bytes32[](0);
|
81
|
-
|
82
|
-
bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
83
|
-
return (uint256(bytes32(_blob)));
|
84
|
-
}
|
85
|
-
|
86
|
-
/**
|
87
|
-
* @notice Get value (using the specified store).
|
88
|
-
*/
|
89
|
-
function getValue(IStore _store, ResourceId _tableId) internal view returns (uint256 value) {
|
90
|
-
bytes32[] memory _keyTuple = new bytes32[](0);
|
91
|
-
|
92
|
-
bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
93
|
-
return (uint256(bytes32(_blob)));
|
94
|
-
}
|
95
|
-
|
96
|
-
/**
|
97
|
-
* @notice Get value.
|
98
|
-
*/
|
99
|
-
function get(ResourceId _tableId) internal view returns (uint256 value) {
|
100
|
-
bytes32[] memory _keyTuple = new bytes32[](0);
|
101
|
-
|
102
|
-
bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
103
|
-
return (uint256(bytes32(_blob)));
|
104
|
-
}
|
105
|
-
|
106
|
-
/**
|
107
|
-
* @notice Get value.
|
108
|
-
*/
|
109
|
-
function _get(ResourceId _tableId) internal view returns (uint256 value) {
|
110
|
-
bytes32[] memory _keyTuple = new bytes32[](0);
|
111
|
-
|
112
|
-
bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
113
|
-
return (uint256(bytes32(_blob)));
|
114
|
-
}
|
115
|
-
|
116
|
-
/**
|
117
|
-
* @notice Get value (using the specified store).
|
118
|
-
*/
|
119
|
-
function get(IStore _store, ResourceId _tableId) internal view returns (uint256 value) {
|
120
|
-
bytes32[] memory _keyTuple = new bytes32[](0);
|
121
|
-
|
122
|
-
bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
123
|
-
return (uint256(bytes32(_blob)));
|
124
|
-
}
|
125
|
-
|
126
|
-
/**
|
127
|
-
* @notice Set value.
|
128
|
-
*/
|
129
|
-
function setValue(ResourceId _tableId, uint256 value) internal {
|
130
|
-
bytes32[] memory _keyTuple = new bytes32[](0);
|
131
|
-
|
132
|
-
StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout);
|
133
|
-
}
|
134
|
-
|
135
|
-
/**
|
136
|
-
* @notice Set value.
|
137
|
-
*/
|
138
|
-
function _setValue(ResourceId _tableId, uint256 value) internal {
|
139
|
-
bytes32[] memory _keyTuple = new bytes32[](0);
|
140
|
-
|
141
|
-
StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout);
|
142
|
-
}
|
143
|
-
|
144
|
-
/**
|
145
|
-
* @notice Set value (using the specified store).
|
146
|
-
*/
|
147
|
-
function setValue(IStore _store, ResourceId _tableId, uint256 value) internal {
|
148
|
-
bytes32[] memory _keyTuple = new bytes32[](0);
|
149
|
-
|
150
|
-
_store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout);
|
151
|
-
}
|
152
|
-
|
153
|
-
/**
|
154
|
-
* @notice Set value.
|
155
|
-
*/
|
156
|
-
function set(ResourceId _tableId, uint256 value) internal {
|
157
|
-
bytes32[] memory _keyTuple = new bytes32[](0);
|
158
|
-
|
159
|
-
StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout);
|
160
|
-
}
|
161
|
-
|
162
|
-
/**
|
163
|
-
* @notice Set value.
|
164
|
-
*/
|
165
|
-
function _set(ResourceId _tableId, uint256 value) internal {
|
166
|
-
bytes32[] memory _keyTuple = new bytes32[](0);
|
167
|
-
|
168
|
-
StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout);
|
169
|
-
}
|
170
|
-
|
171
|
-
/**
|
172
|
-
* @notice Set value (using the specified store).
|
173
|
-
*/
|
174
|
-
function set(IStore _store, ResourceId _tableId, uint256 value) internal {
|
175
|
-
bytes32[] memory _keyTuple = new bytes32[](0);
|
176
|
-
|
177
|
-
_store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout);
|
178
|
-
}
|
179
|
-
|
180
|
-
/**
|
181
|
-
* @notice Delete all data for given keys.
|
182
|
-
*/
|
183
|
-
function deleteRecord(ResourceId _tableId) internal {
|
184
|
-
bytes32[] memory _keyTuple = new bytes32[](0);
|
185
|
-
|
186
|
-
StoreSwitch.deleteRecord(_tableId, _keyTuple);
|
187
|
-
}
|
188
|
-
|
189
|
-
/**
|
190
|
-
* @notice Delete all data for given keys.
|
191
|
-
*/
|
192
|
-
function _deleteRecord(ResourceId _tableId) internal {
|
193
|
-
bytes32[] memory _keyTuple = new bytes32[](0);
|
194
|
-
|
195
|
-
StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout);
|
196
|
-
}
|
197
|
-
|
198
|
-
/**
|
199
|
-
* @notice Delete all data for given keys (using the specified store).
|
200
|
-
*/
|
201
|
-
function deleteRecord(IStore _store, ResourceId _tableId) internal {
|
202
|
-
bytes32[] memory _keyTuple = new bytes32[](0);
|
203
|
-
|
204
|
-
_store.deleteRecord(_tableId, _keyTuple);
|
205
|
-
}
|
206
|
-
|
207
|
-
/**
|
208
|
-
* @notice Tightly pack static (fixed length) data using this table's schema.
|
209
|
-
* @return The static data, encoded into a sequence of bytes.
|
210
|
-
*/
|
211
|
-
function encodeStatic(uint256 value) internal pure returns (bytes memory) {
|
212
|
-
return abi.encodePacked(value);
|
213
|
-
}
|
214
|
-
|
215
|
-
/**
|
216
|
-
* @notice Encode all of a record's fields.
|
217
|
-
* @return The static (fixed length) data, encoded into a sequence of bytes.
|
218
|
-
* @return The lengths of the dynamic fields (packed into a single bytes32 value).
|
219
|
-
* @return The dynamic (variable length) data, encoded into a sequence of bytes.
|
220
|
-
*/
|
221
|
-
function encode(uint256 value) internal pure returns (bytes memory, EncodedLengths, bytes memory) {
|
222
|
-
bytes memory _staticData = encodeStatic(value);
|
223
|
-
|
224
|
-
EncodedLengths _encodedLengths;
|
225
|
-
bytes memory _dynamicData;
|
226
|
-
|
227
|
-
return (_staticData, _encodedLengths, _dynamicData);
|
228
|
-
}
|
229
|
-
|
230
|
-
/**
|
231
|
-
* @notice Encode keys as a bytes32 array using this table's field layout.
|
232
|
-
*/
|
233
|
-
function encodeKeyTuple() internal pure returns (bytes32[] memory) {
|
234
|
-
bytes32[] memory _keyTuple = new bytes32[](0);
|
235
|
-
|
236
|
-
return _keyTuple;
|
237
|
-
}
|
238
|
-
}
|
@@ -1,55 +0,0 @@
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
2
|
-
pragma solidity >=0.8.24;
|
3
|
-
|
4
|
-
library ArrayLib {
|
5
|
-
function equal(bytes32[] memory arr1, bytes32[] memory arr2) internal pure returns (bool) {
|
6
|
-
if (arr1.length != arr2.length) {
|
7
|
-
return false;
|
8
|
-
}
|
9
|
-
|
10
|
-
for (uint256 i; i < arr1.length; i++) {
|
11
|
-
if (arr1[i] != arr2[i]) {
|
12
|
-
return false;
|
13
|
-
}
|
14
|
-
}
|
15
|
-
|
16
|
-
return true;
|
17
|
-
}
|
18
|
-
|
19
|
-
function includes(bytes32[] memory arr, bytes32 element) internal pure returns (bool) {
|
20
|
-
for (uint256 i; i < arr.length; i++) {
|
21
|
-
if (arr[i] == element) {
|
22
|
-
return true;
|
23
|
-
}
|
24
|
-
}
|
25
|
-
return false;
|
26
|
-
}
|
27
|
-
|
28
|
-
function includes(bytes32[][] memory arr, bytes32[] memory element) internal pure returns (bool) {
|
29
|
-
for (uint256 i; i < arr.length; i++) {
|
30
|
-
if (equal(arr[i], element)) {
|
31
|
-
return true;
|
32
|
-
}
|
33
|
-
}
|
34
|
-
return false;
|
35
|
-
}
|
36
|
-
|
37
|
-
function filter(bytes32[] memory arr, bytes32 element) internal pure returns (bytes32[] memory) {
|
38
|
-
bytes32[] memory filtered = new bytes32[](arr.length);
|
39
|
-
uint256 filteredIndex;
|
40
|
-
for (uint256 i; i < arr.length; i++) {
|
41
|
-
if (arr[i] != element) {
|
42
|
-
filtered[filteredIndex] = arr[i];
|
43
|
-
filteredIndex++;
|
44
|
-
}
|
45
|
-
}
|
46
|
-
|
47
|
-
// In-place update the length of the array
|
48
|
-
// (Note: this does not update the free memory pointer)
|
49
|
-
assembly {
|
50
|
-
mstore(filtered, filteredIndex)
|
51
|
-
}
|
52
|
-
|
53
|
-
return filtered;
|
54
|
-
}
|
55
|
-
}
|
@@ -1,55 +0,0 @@
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
2
|
-
pragma solidity >=0.8.24;
|
3
|
-
|
4
|
-
import { ResourceId, WorldResourceIdInstance } from "@latticexyz/world/src/WorldResourceId.sol";
|
5
|
-
import { IWorldErrors } from "@latticexyz/world/src/IWorldErrors.sol";
|
6
|
-
import { ResourceAccess } from "@latticexyz/world/src/codegen/tables/ResourceAccess.sol";
|
7
|
-
import { NamespaceOwner } from "@latticexyz/world/src/codegen/tables/NamespaceOwner.sol";
|
8
|
-
|
9
|
-
/**
|
10
|
-
* @title AccessControlLib
|
11
|
-
* @author MUD (https://mud.dev) by Lattice (https://lattice.xyz)
|
12
|
-
* @dev Provides access control functions for checking permissions and ownership within a namespace.
|
13
|
-
* This library is functionally equivalent with the AccessControl library from world,
|
14
|
-
* but uses StoreSwitch instead of always reading from own storage.
|
15
|
-
*/
|
16
|
-
library AccessControlLib {
|
17
|
-
using WorldResourceIdInstance for ResourceId;
|
18
|
-
|
19
|
-
/**
|
20
|
-
* @notice Checks if the caller has access to the given resource ID or its namespace.
|
21
|
-
* @param resourceId The resource ID to check access for.
|
22
|
-
* @param caller The address of the caller.
|
23
|
-
* @return true if the caller has access, false otherwise.
|
24
|
-
*/
|
25
|
-
function hasAccess(ResourceId resourceId, address caller) internal view returns (bool) {
|
26
|
-
return
|
27
|
-
// First check access based on the namespace. If caller has no namespace access, check access on the resource.
|
28
|
-
ResourceAccess.get(resourceId.getNamespaceId(), caller) || ResourceAccess.get(resourceId, caller);
|
29
|
-
}
|
30
|
-
|
31
|
-
/**
|
32
|
-
* @notice Check for access at the given namespace or resource.
|
33
|
-
* @param resourceId The resource ID to check access for.
|
34
|
-
* @param caller The address of the caller.
|
35
|
-
* @dev Reverts with IWorldErrors.World_AccessDenied if access is denied.
|
36
|
-
*/
|
37
|
-
function requireAccess(ResourceId resourceId, address caller) internal view {
|
38
|
-
// Check if the given caller has access to the given namespace or name
|
39
|
-
if (!hasAccess(resourceId, caller)) {
|
40
|
-
revert IWorldErrors.World_AccessDenied(resourceId.toString(), caller);
|
41
|
-
}
|
42
|
-
}
|
43
|
-
|
44
|
-
/**
|
45
|
-
* @notice Check for ownership of the namespace of the given resource ID.
|
46
|
-
* @dev Reverts with IWorldErrors.World_AccessDenied if caller is not owner of the namespace of the resource.
|
47
|
-
* @param resourceId The resource ID to check ownership for.
|
48
|
-
* @param caller The address of the caller.
|
49
|
-
*/
|
50
|
-
function requireOwner(ResourceId resourceId, address caller) internal view {
|
51
|
-
if (NamespaceOwner.get(resourceId.getNamespaceId()) != caller) {
|
52
|
-
revert IWorldErrors.World_AccessDenied(resourceId.toString(), caller);
|
53
|
-
}
|
54
|
-
}
|
55
|
-
}
|
@@ -1,80 +0,0 @@
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
2
|
-
pragma solidity >=0.8.24;
|
3
|
-
|
4
|
-
import { Hook } from "@latticexyz/store/src/Hook.sol";
|
5
|
-
import { Bytes } from "@latticexyz/store/src/Bytes.sol";
|
6
|
-
|
7
|
-
import { IWorldKernel } from "@latticexyz/world/src/IWorldKernel.sol";
|
8
|
-
import { ResourceId, WorldResourceIdInstance } from "@latticexyz/world/src/WorldResourceId.sol";
|
9
|
-
import { WorldContextProviderLib, WorldContextConsumerLib } from "@latticexyz/world/src/WorldContext.sol";
|
10
|
-
import { AccessControl } from "@latticexyz/world/src/AccessControl.sol";
|
11
|
-
import { ROOT_NAMESPACE } from "@latticexyz/world/src/constants.sol";
|
12
|
-
import { revertWithBytes } from "@latticexyz/world/src/revertWithBytes.sol";
|
13
|
-
import { BEFORE_CALL_SYSTEM, AFTER_CALL_SYSTEM } from "@latticexyz/world/src/systemHookTypes.sol";
|
14
|
-
import { SystemCall } from "@latticexyz/world/src/SystemCall.sol";
|
15
|
-
|
16
|
-
import { IWorldErrors } from "@latticexyz/world/src/IWorldErrors.sol";
|
17
|
-
import { ISystemHook } from "@latticexyz/world/src/ISystemHook.sol";
|
18
|
-
|
19
|
-
import { FunctionSelectors } from "@latticexyz/world/src/codegen/tables/FunctionSelectors.sol";
|
20
|
-
import { Systems } from "@latticexyz/world/src/codegen/tables/Systems.sol";
|
21
|
-
import { SystemHooks } from "@latticexyz/world/src/codegen/tables/SystemHooks.sol";
|
22
|
-
import { Balances } from "@latticexyz/world/src/codegen/tables/Balances.sol";
|
23
|
-
|
24
|
-
/**
|
25
|
-
* @title SystemSwitch
|
26
|
-
* @author MUD (https://mud.dev) by Lattice (https://lattice.xyz)
|
27
|
-
* @dev The SystemSwitch library provides functions for interacting with systems from other systems.
|
28
|
-
*/
|
29
|
-
library SystemSwitch {
|
30
|
-
using WorldResourceIdInstance for ResourceId;
|
31
|
-
|
32
|
-
/**
|
33
|
-
* @notice Calls a system identified by its Resource ID.
|
34
|
-
* @dev Reverts if the system is not found, or if the system call reverts.
|
35
|
-
* If the call is executed from the root context, the system is called directly via delegatecall.
|
36
|
-
* Otherwise, the call is executed via an external call to the World contract.
|
37
|
-
* @param systemId The unique Resource ID of the system being called.
|
38
|
-
* @param callData The calldata to be executed in the system.
|
39
|
-
* @return returnData The return data from the system call.
|
40
|
-
*/
|
41
|
-
function call(ResourceId systemId, bytes memory callData) internal returns (bytes memory returnData) {
|
42
|
-
address worldAddress = WorldContextConsumerLib._world();
|
43
|
-
|
44
|
-
// If we're in the World context, call via the internal library
|
45
|
-
if (address(this) == worldAddress) {
|
46
|
-
bool success;
|
47
|
-
(success, returnData) = SystemCall.call({
|
48
|
-
caller: WorldContextConsumerLib._msgSender(),
|
49
|
-
value: 0,
|
50
|
-
systemId: systemId,
|
51
|
-
callData: callData
|
52
|
-
});
|
53
|
-
|
54
|
-
if (!success) revertWithBytes(returnData);
|
55
|
-
return returnData;
|
56
|
-
}
|
57
|
-
|
58
|
-
// Otherwise, call the system via world.call
|
59
|
-
returnData = IWorldKernel(worldAddress).call(systemId, callData);
|
60
|
-
}
|
61
|
-
|
62
|
-
/**
|
63
|
-
* @notice Calls a system via the function selector registered for it in the World contract.
|
64
|
-
* @dev Reverts if the system is not found, or if the system call reverts.
|
65
|
-
* If the call is executed from the root context, the system is called directly via delegatecall.
|
66
|
-
* Otherwise, the call is executed via an external call to the World contract.
|
67
|
-
* @param callData The world function selector, and call data to be forwarded to the system.
|
68
|
-
* @return returnData The return data from the system call.
|
69
|
-
*/
|
70
|
-
function call(bytes memory callData) internal returns (bytes memory returnData) {
|
71
|
-
// Get the systemAddress and systemFunctionSelector from the worldFunctionSelector encoded in the calldata
|
72
|
-
(ResourceId systemId, bytes4 systemFunctionSelector) = FunctionSelectors.get(bytes4(callData));
|
73
|
-
|
74
|
-
// Revert if the function selector is not found
|
75
|
-
if (ResourceId.unwrap(systemId) == 0) revert IWorldErrors.World_FunctionSelectorNotFound(msg.sig);
|
76
|
-
|
77
|
-
// Replace function selector in the calldata with the system function selector, and call the system
|
78
|
-
return call({ systemId: systemId, callData: Bytes.setBytes4(callData, 0, systemFunctionSelector) });
|
79
|
-
}
|
80
|
-
}
|