@latticexyz/world-modules 2.0.12-type-resolutions-effc7ab1 → 2.0.12-type-resolutions-8538f80e
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 -1
- package/package.json +9 -8
- package/src/index.sol +25 -0
- package/src/interfaces/IBaseWorld.sol +16 -0
- package/src/interfaces/IERC20System.sol +33 -0
- package/src/interfaces/IERC721System.sol +43 -0
- package/src/interfaces/IPuppetFactorySystem.sol +15 -0
- package/src/interfaces/IUniqueEntitySystem.sol +13 -0
- package/src/interfaces/IUnstable_CallWithSignatureSystem.sol +20 -0
- package/src/modules/callwithsignature/ECDSA.sol +174 -0
- package/src/modules/callwithsignature/IERC1271.sol +17 -0
- package/src/modules/callwithsignature/IUnstable_CallWithSignatureErrors.sol +9 -0
- package/src/modules/callwithsignature/SignatureChecker.sol +50 -0
- package/src/modules/callwithsignature/Unstable_CallWithSignatureModule.sol +48 -0
- package/src/modules/callwithsignature/Unstable_CallWithSignatureSystem.sol +36 -0
- package/src/modules/callwithsignature/constants.sol +10 -0
- package/src/modules/callwithsignature/getSignedMessageHash.sol +54 -0
- package/src/modules/callwithsignature/tables/CallWithSignatureNonces.sol +199 -0
- package/src/modules/callwithsignature/validateCallWithSignature.sol +31 -0
- package/src/modules/erc20-puppet/ERC20Module.sol +88 -0
- package/src/modules/erc20-puppet/ERC20System.sol +286 -0
- package/src/modules/erc20-puppet/IERC20.sol +94 -0
- package/src/modules/erc20-puppet/IERC20Errors.sol +49 -0
- package/src/modules/erc20-puppet/IERC20Events.sol +18 -0
- package/src/modules/erc20-puppet/IERC20Mintable.sol +25 -0
- package/src/modules/erc20-puppet/constants.sol +20 -0
- package/src/modules/erc20-puppet/registerERC20.sol +35 -0
- package/src/modules/erc20-puppet/tables/Allowances.sol +208 -0
- package/src/modules/erc20-puppet/tables/ERC20Metadata.sol +604 -0
- package/src/modules/erc20-puppet/tables/ERC20Registry.sol +199 -0
- package/src/modules/erc20-puppet/tables/TotalSupply.sol +184 -0
- package/src/modules/erc20-puppet/utils.sol +30 -0
- package/src/modules/erc721-puppet/ERC721Module.sol +95 -0
- package/src/modules/erc721-puppet/ERC721System.sol +531 -0
- package/src/modules/erc721-puppet/IERC721.sol +120 -0
- package/src/modules/erc721-puppet/IERC721Errors.sol +61 -0
- package/src/modules/erc721-puppet/IERC721Events.sol +23 -0
- package/src/modules/erc721-puppet/IERC721Metadata.sol +27 -0
- package/src/modules/erc721-puppet/IERC721Mintable.sol +53 -0
- package/src/modules/erc721-puppet/IERC721Receiver.sol +28 -0
- package/src/modules/erc721-puppet/constants.sol +23 -0
- package/src/modules/erc721-puppet/libraries/LibString.sol +77 -0
- package/src/modules/erc721-puppet/registerERC721.sol +37 -0
- package/src/modules/erc721-puppet/tables/ERC721Metadata.sol +703 -0
- package/src/modules/erc721-puppet/tables/ERC721Registry.sol +199 -0
- package/src/modules/erc721-puppet/tables/OperatorApproval.sol +220 -0
- package/src/modules/erc721-puppet/tables/Owners.sol +196 -0
- package/src/modules/erc721-puppet/tables/TokenApproval.sol +196 -0
- package/src/modules/erc721-puppet/tables/TokenURI.sol +450 -0
- package/src/modules/erc721-puppet/utils.sol +38 -0
- package/src/modules/keysintable/KeysInTableHook.sol +141 -0
- package/src/modules/keysintable/KeysInTableModule.sol +110 -0
- package/src/modules/keysintable/constants.sol +7 -0
- package/src/modules/keysintable/getKeysInTable.sol +81 -0
- package/src/modules/keysintable/hasKey.sol +28 -0
- package/src/modules/keysintable/query.sol +200 -0
- package/src/modules/keysintable/tables/KeysInTable.sol +1638 -0
- package/src/modules/keysintable/tables/UsedKeysIndex.sol +414 -0
- package/src/modules/keyswithvalue/KeysWithValueHook.sol +158 -0
- package/src/modules/keyswithvalue/KeysWithValueModule.sol +103 -0
- package/src/modules/keyswithvalue/constants.sol +7 -0
- package/src/modules/keyswithvalue/getKeysWithValue.sol +58 -0
- package/src/modules/keyswithvalue/getTargetTableId.sol +32 -0
- package/src/modules/keyswithvalue/tables/KeysWithValue.sol +668 -0
- package/src/modules/puppet/Puppet.sol +80 -0
- package/src/modules/puppet/PuppetDelegationControl.sol +17 -0
- package/src/modules/puppet/PuppetFactorySystem.sol +25 -0
- package/src/modules/puppet/PuppetMaster.sol +19 -0
- package/src/modules/puppet/PuppetModule.sol +64 -0
- package/src/modules/puppet/constants.sol +23 -0
- package/src/modules/puppet/createPuppet.sol +24 -0
- package/src/modules/puppet/tables/PuppetRegistry.sol +199 -0
- package/src/modules/puppet/utils.sol +10 -0
- package/src/modules/std-delegations/CallboundDelegationControl.sol +64 -0
- package/src/modules/std-delegations/StandardDelegationsModule.sol +55 -0
- package/src/modules/std-delegations/SystemboundDelegationControl.sol +54 -0
- package/src/modules/std-delegations/TimeboundDelegationControl.sol +27 -0
- package/src/modules/std-delegations/constants.sol +21 -0
- package/src/modules/std-delegations/tables/CallboundDelegations.sol +287 -0
- package/src/modules/std-delegations/tables/SystemboundDelegations.sol +256 -0
- package/src/modules/std-delegations/tables/TimeboundDelegations.sol +211 -0
- package/src/modules/tokens/tables/Balances.sol +196 -0
- package/src/modules/uniqueentity/UniqueEntityModule.sol +73 -0
- package/src/modules/uniqueentity/UniqueEntitySystem.sol +18 -0
- package/src/modules/uniqueentity/constants.sol +13 -0
- package/src/modules/uniqueentity/getUniqueEntity.sol +26 -0
- package/src/modules/uniqueentity/tables/UniqueEntity.sol +238 -0
- package/src/modules/utils/ArrayLib.sol +55 -0
- package/src/utils/AccessControlLib.sol +55 -0
- package/src/utils/SystemSwitch.sol +80 -0
@@ -0,0 +1,211 @@
|
|
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 TimeboundDelegations {
|
20
|
+
// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "TimeboundDelegat", typeId: RESOURCE_TABLE });`
|
21
|
+
ResourceId constant _tableId = ResourceId.wrap(0x7462000000000000000000000000000054696d65626f756e6444656c65676174);
|
22
|
+
|
23
|
+
FieldLayout constant _fieldLayout =
|
24
|
+
FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000);
|
25
|
+
|
26
|
+
// Hex-encoded key schema of (address, address)
|
27
|
+
Schema constant _keySchema = Schema.wrap(0x0028020061610000000000000000000000000000000000000000000000000000);
|
28
|
+
// Hex-encoded value schema of (uint256)
|
29
|
+
Schema constant _valueSchema = Schema.wrap(0x002001001f000000000000000000000000000000000000000000000000000000);
|
30
|
+
|
31
|
+
/**
|
32
|
+
* @notice Get the table's key field names.
|
33
|
+
* @return keyNames An array of strings with the names of key fields.
|
34
|
+
*/
|
35
|
+
function getKeyNames() internal pure returns (string[] memory keyNames) {
|
36
|
+
keyNames = new string[](2);
|
37
|
+
keyNames[0] = "delegator";
|
38
|
+
keyNames[1] = "delegatee";
|
39
|
+
}
|
40
|
+
|
41
|
+
/**
|
42
|
+
* @notice Get the table's value field names.
|
43
|
+
* @return fieldNames An array of strings with the names of value fields.
|
44
|
+
*/
|
45
|
+
function getFieldNames() internal pure returns (string[] memory fieldNames) {
|
46
|
+
fieldNames = new string[](1);
|
47
|
+
fieldNames[0] = "maxTimestamp";
|
48
|
+
}
|
49
|
+
|
50
|
+
/**
|
51
|
+
* @notice Register the table with its config.
|
52
|
+
*/
|
53
|
+
function register() internal {
|
54
|
+
StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
|
55
|
+
}
|
56
|
+
|
57
|
+
/**
|
58
|
+
* @notice Register the table with its config.
|
59
|
+
*/
|
60
|
+
function _register() internal {
|
61
|
+
StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
|
62
|
+
}
|
63
|
+
|
64
|
+
/**
|
65
|
+
* @notice Get maxTimestamp.
|
66
|
+
*/
|
67
|
+
function getMaxTimestamp(address delegator, address delegatee) internal view returns (uint256 maxTimestamp) {
|
68
|
+
bytes32[] memory _keyTuple = new bytes32[](2);
|
69
|
+
_keyTuple[0] = bytes32(uint256(uint160(delegator)));
|
70
|
+
_keyTuple[1] = bytes32(uint256(uint160(delegatee)));
|
71
|
+
|
72
|
+
bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
73
|
+
return (uint256(bytes32(_blob)));
|
74
|
+
}
|
75
|
+
|
76
|
+
/**
|
77
|
+
* @notice Get maxTimestamp.
|
78
|
+
*/
|
79
|
+
function _getMaxTimestamp(address delegator, address delegatee) internal view returns (uint256 maxTimestamp) {
|
80
|
+
bytes32[] memory _keyTuple = new bytes32[](2);
|
81
|
+
_keyTuple[0] = bytes32(uint256(uint160(delegator)));
|
82
|
+
_keyTuple[1] = bytes32(uint256(uint160(delegatee)));
|
83
|
+
|
84
|
+
bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
85
|
+
return (uint256(bytes32(_blob)));
|
86
|
+
}
|
87
|
+
|
88
|
+
/**
|
89
|
+
* @notice Get maxTimestamp.
|
90
|
+
*/
|
91
|
+
function get(address delegator, address delegatee) internal view returns (uint256 maxTimestamp) {
|
92
|
+
bytes32[] memory _keyTuple = new bytes32[](2);
|
93
|
+
_keyTuple[0] = bytes32(uint256(uint160(delegator)));
|
94
|
+
_keyTuple[1] = bytes32(uint256(uint160(delegatee)));
|
95
|
+
|
96
|
+
bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
97
|
+
return (uint256(bytes32(_blob)));
|
98
|
+
}
|
99
|
+
|
100
|
+
/**
|
101
|
+
* @notice Get maxTimestamp.
|
102
|
+
*/
|
103
|
+
function _get(address delegator, address delegatee) internal view returns (uint256 maxTimestamp) {
|
104
|
+
bytes32[] memory _keyTuple = new bytes32[](2);
|
105
|
+
_keyTuple[0] = bytes32(uint256(uint160(delegator)));
|
106
|
+
_keyTuple[1] = bytes32(uint256(uint160(delegatee)));
|
107
|
+
|
108
|
+
bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
109
|
+
return (uint256(bytes32(_blob)));
|
110
|
+
}
|
111
|
+
|
112
|
+
/**
|
113
|
+
* @notice Set maxTimestamp.
|
114
|
+
*/
|
115
|
+
function setMaxTimestamp(address delegator, address delegatee, uint256 maxTimestamp) internal {
|
116
|
+
bytes32[] memory _keyTuple = new bytes32[](2);
|
117
|
+
_keyTuple[0] = bytes32(uint256(uint160(delegator)));
|
118
|
+
_keyTuple[1] = bytes32(uint256(uint160(delegatee)));
|
119
|
+
|
120
|
+
StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((maxTimestamp)), _fieldLayout);
|
121
|
+
}
|
122
|
+
|
123
|
+
/**
|
124
|
+
* @notice Set maxTimestamp.
|
125
|
+
*/
|
126
|
+
function _setMaxTimestamp(address delegator, address delegatee, uint256 maxTimestamp) internal {
|
127
|
+
bytes32[] memory _keyTuple = new bytes32[](2);
|
128
|
+
_keyTuple[0] = bytes32(uint256(uint160(delegator)));
|
129
|
+
_keyTuple[1] = bytes32(uint256(uint160(delegatee)));
|
130
|
+
|
131
|
+
StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((maxTimestamp)), _fieldLayout);
|
132
|
+
}
|
133
|
+
|
134
|
+
/**
|
135
|
+
* @notice Set maxTimestamp.
|
136
|
+
*/
|
137
|
+
function set(address delegator, address delegatee, uint256 maxTimestamp) internal {
|
138
|
+
bytes32[] memory _keyTuple = new bytes32[](2);
|
139
|
+
_keyTuple[0] = bytes32(uint256(uint160(delegator)));
|
140
|
+
_keyTuple[1] = bytes32(uint256(uint160(delegatee)));
|
141
|
+
|
142
|
+
StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((maxTimestamp)), _fieldLayout);
|
143
|
+
}
|
144
|
+
|
145
|
+
/**
|
146
|
+
* @notice Set maxTimestamp.
|
147
|
+
*/
|
148
|
+
function _set(address delegator, address delegatee, uint256 maxTimestamp) internal {
|
149
|
+
bytes32[] memory _keyTuple = new bytes32[](2);
|
150
|
+
_keyTuple[0] = bytes32(uint256(uint160(delegator)));
|
151
|
+
_keyTuple[1] = bytes32(uint256(uint160(delegatee)));
|
152
|
+
|
153
|
+
StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((maxTimestamp)), _fieldLayout);
|
154
|
+
}
|
155
|
+
|
156
|
+
/**
|
157
|
+
* @notice Delete all data for given keys.
|
158
|
+
*/
|
159
|
+
function deleteRecord(address delegator, address delegatee) internal {
|
160
|
+
bytes32[] memory _keyTuple = new bytes32[](2);
|
161
|
+
_keyTuple[0] = bytes32(uint256(uint160(delegator)));
|
162
|
+
_keyTuple[1] = bytes32(uint256(uint160(delegatee)));
|
163
|
+
|
164
|
+
StoreSwitch.deleteRecord(_tableId, _keyTuple);
|
165
|
+
}
|
166
|
+
|
167
|
+
/**
|
168
|
+
* @notice Delete all data for given keys.
|
169
|
+
*/
|
170
|
+
function _deleteRecord(address delegator, address delegatee) internal {
|
171
|
+
bytes32[] memory _keyTuple = new bytes32[](2);
|
172
|
+
_keyTuple[0] = bytes32(uint256(uint160(delegator)));
|
173
|
+
_keyTuple[1] = bytes32(uint256(uint160(delegatee)));
|
174
|
+
|
175
|
+
StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout);
|
176
|
+
}
|
177
|
+
|
178
|
+
/**
|
179
|
+
* @notice Tightly pack static (fixed length) data using this table's schema.
|
180
|
+
* @return The static data, encoded into a sequence of bytes.
|
181
|
+
*/
|
182
|
+
function encodeStatic(uint256 maxTimestamp) internal pure returns (bytes memory) {
|
183
|
+
return abi.encodePacked(maxTimestamp);
|
184
|
+
}
|
185
|
+
|
186
|
+
/**
|
187
|
+
* @notice Encode all of a record's fields.
|
188
|
+
* @return The static (fixed length) data, encoded into a sequence of bytes.
|
189
|
+
* @return The lengths of the dynamic fields (packed into a single bytes32 value).
|
190
|
+
* @return The dynamic (variable length) data, encoded into a sequence of bytes.
|
191
|
+
*/
|
192
|
+
function encode(uint256 maxTimestamp) internal pure returns (bytes memory, EncodedLengths, bytes memory) {
|
193
|
+
bytes memory _staticData = encodeStatic(maxTimestamp);
|
194
|
+
|
195
|
+
EncodedLengths _encodedLengths;
|
196
|
+
bytes memory _dynamicData;
|
197
|
+
|
198
|
+
return (_staticData, _encodedLengths, _dynamicData);
|
199
|
+
}
|
200
|
+
|
201
|
+
/**
|
202
|
+
* @notice Encode keys as a bytes32 array using this table's field layout.
|
203
|
+
*/
|
204
|
+
function encodeKeyTuple(address delegator, address delegatee) internal pure returns (bytes32[] memory) {
|
205
|
+
bytes32[] memory _keyTuple = new bytes32[](2);
|
206
|
+
_keyTuple[0] = bytes32(uint256(uint160(delegator)));
|
207
|
+
_keyTuple[1] = bytes32(uint256(uint160(delegatee)));
|
208
|
+
|
209
|
+
return _keyTuple;
|
210
|
+
}
|
211
|
+
}
|
@@ -0,0 +1,196 @@
|
|
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 Balances {
|
20
|
+
FieldLayout constant _fieldLayout =
|
21
|
+
FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000);
|
22
|
+
|
23
|
+
// Hex-encoded key schema of (address)
|
24
|
+
Schema constant _keySchema = Schema.wrap(0x0014010061000000000000000000000000000000000000000000000000000000);
|
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[](1);
|
34
|
+
keyNames[0] = "account";
|
35
|
+
}
|
36
|
+
|
37
|
+
/**
|
38
|
+
* @notice Get the table's value field names.
|
39
|
+
* @return fieldNames An array of strings with the names of value fields.
|
40
|
+
*/
|
41
|
+
function getFieldNames() internal pure returns (string[] memory fieldNames) {
|
42
|
+
fieldNames = new string[](1);
|
43
|
+
fieldNames[0] = "value";
|
44
|
+
}
|
45
|
+
|
46
|
+
/**
|
47
|
+
* @notice Register the table with its config.
|
48
|
+
*/
|
49
|
+
function register(ResourceId _tableId) internal {
|
50
|
+
StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
|
51
|
+
}
|
52
|
+
|
53
|
+
/**
|
54
|
+
* @notice Register the table with its config.
|
55
|
+
*/
|
56
|
+
function _register(ResourceId _tableId) internal {
|
57
|
+
StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
|
58
|
+
}
|
59
|
+
|
60
|
+
/**
|
61
|
+
* @notice Get value.
|
62
|
+
*/
|
63
|
+
function getValue(ResourceId _tableId, address account) internal view returns (uint256 value) {
|
64
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
65
|
+
_keyTuple[0] = bytes32(uint256(uint160(account)));
|
66
|
+
|
67
|
+
bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
68
|
+
return (uint256(bytes32(_blob)));
|
69
|
+
}
|
70
|
+
|
71
|
+
/**
|
72
|
+
* @notice Get value.
|
73
|
+
*/
|
74
|
+
function _getValue(ResourceId _tableId, address account) internal view returns (uint256 value) {
|
75
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
76
|
+
_keyTuple[0] = bytes32(uint256(uint160(account)));
|
77
|
+
|
78
|
+
bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
79
|
+
return (uint256(bytes32(_blob)));
|
80
|
+
}
|
81
|
+
|
82
|
+
/**
|
83
|
+
* @notice Get value.
|
84
|
+
*/
|
85
|
+
function get(ResourceId _tableId, address account) internal view returns (uint256 value) {
|
86
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
87
|
+
_keyTuple[0] = bytes32(uint256(uint160(account)));
|
88
|
+
|
89
|
+
bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
90
|
+
return (uint256(bytes32(_blob)));
|
91
|
+
}
|
92
|
+
|
93
|
+
/**
|
94
|
+
* @notice Get value.
|
95
|
+
*/
|
96
|
+
function _get(ResourceId _tableId, address account) internal view returns (uint256 value) {
|
97
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
98
|
+
_keyTuple[0] = bytes32(uint256(uint160(account)));
|
99
|
+
|
100
|
+
bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
101
|
+
return (uint256(bytes32(_blob)));
|
102
|
+
}
|
103
|
+
|
104
|
+
/**
|
105
|
+
* @notice Set value.
|
106
|
+
*/
|
107
|
+
function setValue(ResourceId _tableId, address account, uint256 value) internal {
|
108
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
109
|
+
_keyTuple[0] = bytes32(uint256(uint160(account)));
|
110
|
+
|
111
|
+
StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout);
|
112
|
+
}
|
113
|
+
|
114
|
+
/**
|
115
|
+
* @notice Set value.
|
116
|
+
*/
|
117
|
+
function _setValue(ResourceId _tableId, address account, uint256 value) internal {
|
118
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
119
|
+
_keyTuple[0] = bytes32(uint256(uint160(account)));
|
120
|
+
|
121
|
+
StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout);
|
122
|
+
}
|
123
|
+
|
124
|
+
/**
|
125
|
+
* @notice Set value.
|
126
|
+
*/
|
127
|
+
function set(ResourceId _tableId, address account, uint256 value) internal {
|
128
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
129
|
+
_keyTuple[0] = bytes32(uint256(uint160(account)));
|
130
|
+
|
131
|
+
StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout);
|
132
|
+
}
|
133
|
+
|
134
|
+
/**
|
135
|
+
* @notice Set value.
|
136
|
+
*/
|
137
|
+
function _set(ResourceId _tableId, address account, uint256 value) internal {
|
138
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
139
|
+
_keyTuple[0] = bytes32(uint256(uint160(account)));
|
140
|
+
|
141
|
+
StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout);
|
142
|
+
}
|
143
|
+
|
144
|
+
/**
|
145
|
+
* @notice Delete all data for given keys.
|
146
|
+
*/
|
147
|
+
function deleteRecord(ResourceId _tableId, address account) internal {
|
148
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
149
|
+
_keyTuple[0] = bytes32(uint256(uint160(account)));
|
150
|
+
|
151
|
+
StoreSwitch.deleteRecord(_tableId, _keyTuple);
|
152
|
+
}
|
153
|
+
|
154
|
+
/**
|
155
|
+
* @notice Delete all data for given keys.
|
156
|
+
*/
|
157
|
+
function _deleteRecord(ResourceId _tableId, address account) internal {
|
158
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
159
|
+
_keyTuple[0] = bytes32(uint256(uint160(account)));
|
160
|
+
|
161
|
+
StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout);
|
162
|
+
}
|
163
|
+
|
164
|
+
/**
|
165
|
+
* @notice Tightly pack static (fixed length) data using this table's schema.
|
166
|
+
* @return The static data, encoded into a sequence of bytes.
|
167
|
+
*/
|
168
|
+
function encodeStatic(uint256 value) internal pure returns (bytes memory) {
|
169
|
+
return abi.encodePacked(value);
|
170
|
+
}
|
171
|
+
|
172
|
+
/**
|
173
|
+
* @notice Encode all of a record's fields.
|
174
|
+
* @return The static (fixed length) data, encoded into a sequence of bytes.
|
175
|
+
* @return The lengths of the dynamic fields (packed into a single bytes32 value).
|
176
|
+
* @return The dynamic (variable length) data, encoded into a sequence of bytes.
|
177
|
+
*/
|
178
|
+
function encode(uint256 value) internal pure returns (bytes memory, EncodedLengths, bytes memory) {
|
179
|
+
bytes memory _staticData = encodeStatic(value);
|
180
|
+
|
181
|
+
EncodedLengths _encodedLengths;
|
182
|
+
bytes memory _dynamicData;
|
183
|
+
|
184
|
+
return (_staticData, _encodedLengths, _dynamicData);
|
185
|
+
}
|
186
|
+
|
187
|
+
/**
|
188
|
+
* @notice Encode keys as a bytes32 array using this table's field layout.
|
189
|
+
*/
|
190
|
+
function encodeKeyTuple(address account) internal pure returns (bytes32[] memory) {
|
191
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
192
|
+
_keyTuple[0] = bytes32(uint256(uint160(account)));
|
193
|
+
|
194
|
+
return _keyTuple;
|
195
|
+
}
|
196
|
+
}
|
@@ -0,0 +1,73 @@
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
2
|
+
pragma solidity >=0.8.24;
|
3
|
+
|
4
|
+
import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.sol";
|
5
|
+
import { InstalledModules } from "@latticexyz/world/src/codegen/index.sol";
|
6
|
+
|
7
|
+
import { Module } from "@latticexyz/world/src/Module.sol";
|
8
|
+
import { WorldContextConsumer } from "@latticexyz/world/src/WorldContext.sol";
|
9
|
+
import { revertWithBytes } from "@latticexyz/world/src/revertWithBytes.sol";
|
10
|
+
|
11
|
+
import { UniqueEntity } from "./tables/UniqueEntity.sol";
|
12
|
+
import { UniqueEntitySystem } from "./UniqueEntitySystem.sol";
|
13
|
+
|
14
|
+
import { TABLE_ID, SYSTEM_ID, NAMESPACE_ID } from "./constants.sol";
|
15
|
+
|
16
|
+
/**
|
17
|
+
* This module creates a table that stores a nonce, and
|
18
|
+
* a public system that returns an incremented nonce each time.
|
19
|
+
*/
|
20
|
+
contract UniqueEntityModule is Module {
|
21
|
+
// Since the UniqueEntitySystem only exists once per World and writes to
|
22
|
+
// known tables, we can deploy it once and register it in multiple Worlds.
|
23
|
+
UniqueEntitySystem private immutable uniqueEntitySystem = new UniqueEntitySystem();
|
24
|
+
|
25
|
+
function installRoot(bytes memory encodedArgs) public {
|
26
|
+
// Naive check to ensure this is only installed once
|
27
|
+
// TODO: only revert if there's nothing to do
|
28
|
+
requireNotInstalled(__self, encodedArgs);
|
29
|
+
|
30
|
+
IBaseWorld world = IBaseWorld(_world());
|
31
|
+
|
32
|
+
// Register namespace
|
33
|
+
(bool success, bytes memory data) = address(world).delegatecall(
|
34
|
+
abi.encodeCall(world.registerNamespace, (NAMESPACE_ID))
|
35
|
+
);
|
36
|
+
if (!success) revertWithBytes(data);
|
37
|
+
|
38
|
+
// Register table
|
39
|
+
UniqueEntity._register(TABLE_ID);
|
40
|
+
|
41
|
+
// Register system
|
42
|
+
(success, data) = address(world).delegatecall(
|
43
|
+
abi.encodeCall(world.registerSystem, (SYSTEM_ID, uniqueEntitySystem, true))
|
44
|
+
);
|
45
|
+
if (!success) revertWithBytes(data);
|
46
|
+
|
47
|
+
// Register system's functions
|
48
|
+
(success, data) = address(world).delegatecall(
|
49
|
+
abi.encodeCall(world.registerFunctionSelector, (SYSTEM_ID, "getUniqueEntity()"))
|
50
|
+
);
|
51
|
+
if (!success) revertWithBytes(data);
|
52
|
+
}
|
53
|
+
|
54
|
+
function install(bytes memory encodedArgs) public {
|
55
|
+
// Naive check to ensure this is only installed once
|
56
|
+
// TODO: only revert if there's nothing to do
|
57
|
+
requireNotInstalled(__self, encodedArgs);
|
58
|
+
|
59
|
+
IBaseWorld world = IBaseWorld(_world());
|
60
|
+
|
61
|
+
// Register namespace
|
62
|
+
world.registerNamespace(NAMESPACE_ID);
|
63
|
+
|
64
|
+
// Register table
|
65
|
+
UniqueEntity.register(TABLE_ID);
|
66
|
+
|
67
|
+
// Register system
|
68
|
+
world.registerSystem(SYSTEM_ID, uniqueEntitySystem, true);
|
69
|
+
|
70
|
+
// Register system's functions
|
71
|
+
world.registerFunctionSelector(SYSTEM_ID, "getUniqueEntity()");
|
72
|
+
}
|
73
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
2
|
+
pragma solidity >=0.8.24;
|
3
|
+
|
4
|
+
import { System } from "@latticexyz/world/src/System.sol";
|
5
|
+
import { TABLE_ID } from "./constants.sol";
|
6
|
+
import { UniqueEntity } from "./tables/UniqueEntity.sol";
|
7
|
+
|
8
|
+
contract UniqueEntitySystem is System {
|
9
|
+
/**
|
10
|
+
* Increment and get an entity nonce.
|
11
|
+
*/
|
12
|
+
function getUniqueEntity() public virtual returns (bytes32) {
|
13
|
+
uint256 uniqueEntity = UniqueEntity.get(TABLE_ID) + 1;
|
14
|
+
UniqueEntity.set(TABLE_ID, uniqueEntity);
|
15
|
+
|
16
|
+
return bytes32(uniqueEntity);
|
17
|
+
}
|
18
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
2
|
+
pragma solidity >=0.8.24;
|
3
|
+
|
4
|
+
import { ResourceId } from "@latticexyz/world/src/WorldResourceId.sol";
|
5
|
+
import { RESOURCE_TABLE, RESOURCE_SYSTEM, RESOURCE_NAMESPACE } from "@latticexyz/world/src/worldResourceTypes.sol";
|
6
|
+
|
7
|
+
bytes14 constant NAMESPACE = bytes14("uniqueEntity");
|
8
|
+
bytes16 constant SYSTEM_NAME = bytes16("system");
|
9
|
+
bytes16 constant TABLE_NAME = bytes16("table");
|
10
|
+
|
11
|
+
ResourceId constant NAMESPACE_ID = ResourceId.wrap(bytes32(abi.encodePacked(RESOURCE_NAMESPACE, NAMESPACE)));
|
12
|
+
ResourceId constant TABLE_ID = ResourceId.wrap(bytes32(abi.encodePacked(RESOURCE_TABLE, NAMESPACE, TABLE_NAME)));
|
13
|
+
ResourceId constant SYSTEM_ID = ResourceId.wrap((bytes32(abi.encodePacked(RESOURCE_SYSTEM, NAMESPACE, SYSTEM_NAME))));
|
@@ -0,0 +1,26 @@
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
2
|
+
pragma solidity >=0.8.24;
|
3
|
+
|
4
|
+
import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.sol";
|
5
|
+
|
6
|
+
import { UniqueEntitySystem } from "./UniqueEntitySystem.sol";
|
7
|
+
|
8
|
+
import { SystemSwitch } from "../../utils/SystemSwitch.sol";
|
9
|
+
import { SYSTEM_ID } from "./constants.sol";
|
10
|
+
|
11
|
+
/**
|
12
|
+
* Increment and get an entity nonce.
|
13
|
+
*
|
14
|
+
* Note: this util can only be called within the context of a World (e.g. from a System or Module).
|
15
|
+
* For usage outside of a World, use the overload that takes an explicit store argument.
|
16
|
+
*/
|
17
|
+
function getUniqueEntity() returns (bytes32 uniqueEntity) {
|
18
|
+
return abi.decode(SystemSwitch.call(SYSTEM_ID, abi.encodeCall(UniqueEntitySystem.getUniqueEntity, ())), (bytes32));
|
19
|
+
}
|
20
|
+
|
21
|
+
/**
|
22
|
+
* Increment and get an entity nonce.
|
23
|
+
*/
|
24
|
+
function getUniqueEntity(IBaseWorld world) returns (bytes32 uniqueEntity) {
|
25
|
+
return abi.decode(world.call(SYSTEM_ID, abi.encodeCall(UniqueEntitySystem.getUniqueEntity, ())), (bytes32));
|
26
|
+
}
|