@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,21 @@
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
2
|
+
pragma solidity >=0.8.24;
|
3
|
+
|
4
|
+
import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";
|
5
|
+
import { RESOURCE_SYSTEM } from "@latticexyz/world/src/worldResourceTypes.sol";
|
6
|
+
import { ROOT_NAMESPACE } from "@latticexyz/world/src/constants.sol";
|
7
|
+
|
8
|
+
// Callbound delegation
|
9
|
+
ResourceId constant CALLBOUND_DELEGATION = ResourceId.wrap(
|
10
|
+
bytes32(abi.encodePacked(RESOURCE_SYSTEM, ROOT_NAMESPACE, bytes16("callbound")))
|
11
|
+
);
|
12
|
+
|
13
|
+
// Systembound delegation
|
14
|
+
ResourceId constant SYSTEMBOUND_DELEGATION = ResourceId.wrap(
|
15
|
+
bytes32(abi.encodePacked(RESOURCE_SYSTEM, ROOT_NAMESPACE, bytes16("systembound")))
|
16
|
+
);
|
17
|
+
|
18
|
+
// Timebound delegation
|
19
|
+
ResourceId constant TIMEBOUND_DELEGATION = ResourceId.wrap(
|
20
|
+
bytes32(abi.encodePacked(RESOURCE_SYSTEM, ROOT_NAMESPACE, bytes16("timebound")))
|
21
|
+
);
|
@@ -0,0 +1,287 @@
|
|
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
|
+
// Import user types
|
20
|
+
import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";
|
21
|
+
|
22
|
+
library CallboundDelegations {
|
23
|
+
// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "CallboundDelegat", typeId: RESOURCE_TABLE });`
|
24
|
+
ResourceId constant _tableId = ResourceId.wrap(0x7462000000000000000000000000000043616c6c626f756e6444656c65676174);
|
25
|
+
|
26
|
+
FieldLayout constant _fieldLayout =
|
27
|
+
FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000);
|
28
|
+
|
29
|
+
// Hex-encoded key schema of (address, address, bytes32, bytes32)
|
30
|
+
Schema constant _keySchema = Schema.wrap(0x0068040061615f5f000000000000000000000000000000000000000000000000);
|
31
|
+
// Hex-encoded value schema of (uint256)
|
32
|
+
Schema constant _valueSchema = Schema.wrap(0x002001001f000000000000000000000000000000000000000000000000000000);
|
33
|
+
|
34
|
+
/**
|
35
|
+
* @notice Get the table's key field names.
|
36
|
+
* @return keyNames An array of strings with the names of key fields.
|
37
|
+
*/
|
38
|
+
function getKeyNames() internal pure returns (string[] memory keyNames) {
|
39
|
+
keyNames = new string[](4);
|
40
|
+
keyNames[0] = "delegator";
|
41
|
+
keyNames[1] = "delegatee";
|
42
|
+
keyNames[2] = "systemId";
|
43
|
+
keyNames[3] = "callDataHash";
|
44
|
+
}
|
45
|
+
|
46
|
+
/**
|
47
|
+
* @notice Get the table's value field names.
|
48
|
+
* @return fieldNames An array of strings with the names of value fields.
|
49
|
+
*/
|
50
|
+
function getFieldNames() internal pure returns (string[] memory fieldNames) {
|
51
|
+
fieldNames = new string[](1);
|
52
|
+
fieldNames[0] = "availableCalls";
|
53
|
+
}
|
54
|
+
|
55
|
+
/**
|
56
|
+
* @notice Register the table with its config.
|
57
|
+
*/
|
58
|
+
function register() internal {
|
59
|
+
StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
|
60
|
+
}
|
61
|
+
|
62
|
+
/**
|
63
|
+
* @notice Register the table with its config.
|
64
|
+
*/
|
65
|
+
function _register() internal {
|
66
|
+
StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
|
67
|
+
}
|
68
|
+
|
69
|
+
/**
|
70
|
+
* @notice Get availableCalls.
|
71
|
+
*/
|
72
|
+
function getAvailableCalls(
|
73
|
+
address delegator,
|
74
|
+
address delegatee,
|
75
|
+
ResourceId systemId,
|
76
|
+
bytes32 callDataHash
|
77
|
+
) internal view returns (uint256 availableCalls) {
|
78
|
+
bytes32[] memory _keyTuple = new bytes32[](4);
|
79
|
+
_keyTuple[0] = bytes32(uint256(uint160(delegator)));
|
80
|
+
_keyTuple[1] = bytes32(uint256(uint160(delegatee)));
|
81
|
+
_keyTuple[2] = ResourceId.unwrap(systemId);
|
82
|
+
_keyTuple[3] = callDataHash;
|
83
|
+
|
84
|
+
bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
85
|
+
return (uint256(bytes32(_blob)));
|
86
|
+
}
|
87
|
+
|
88
|
+
/**
|
89
|
+
* @notice Get availableCalls.
|
90
|
+
*/
|
91
|
+
function _getAvailableCalls(
|
92
|
+
address delegator,
|
93
|
+
address delegatee,
|
94
|
+
ResourceId systemId,
|
95
|
+
bytes32 callDataHash
|
96
|
+
) internal view returns (uint256 availableCalls) {
|
97
|
+
bytes32[] memory _keyTuple = new bytes32[](4);
|
98
|
+
_keyTuple[0] = bytes32(uint256(uint160(delegator)));
|
99
|
+
_keyTuple[1] = bytes32(uint256(uint160(delegatee)));
|
100
|
+
_keyTuple[2] = ResourceId.unwrap(systemId);
|
101
|
+
_keyTuple[3] = callDataHash;
|
102
|
+
|
103
|
+
bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
104
|
+
return (uint256(bytes32(_blob)));
|
105
|
+
}
|
106
|
+
|
107
|
+
/**
|
108
|
+
* @notice Get availableCalls.
|
109
|
+
*/
|
110
|
+
function get(
|
111
|
+
address delegator,
|
112
|
+
address delegatee,
|
113
|
+
ResourceId systemId,
|
114
|
+
bytes32 callDataHash
|
115
|
+
) internal view returns (uint256 availableCalls) {
|
116
|
+
bytes32[] memory _keyTuple = new bytes32[](4);
|
117
|
+
_keyTuple[0] = bytes32(uint256(uint160(delegator)));
|
118
|
+
_keyTuple[1] = bytes32(uint256(uint160(delegatee)));
|
119
|
+
_keyTuple[2] = ResourceId.unwrap(systemId);
|
120
|
+
_keyTuple[3] = callDataHash;
|
121
|
+
|
122
|
+
bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
123
|
+
return (uint256(bytes32(_blob)));
|
124
|
+
}
|
125
|
+
|
126
|
+
/**
|
127
|
+
* @notice Get availableCalls.
|
128
|
+
*/
|
129
|
+
function _get(
|
130
|
+
address delegator,
|
131
|
+
address delegatee,
|
132
|
+
ResourceId systemId,
|
133
|
+
bytes32 callDataHash
|
134
|
+
) internal view returns (uint256 availableCalls) {
|
135
|
+
bytes32[] memory _keyTuple = new bytes32[](4);
|
136
|
+
_keyTuple[0] = bytes32(uint256(uint160(delegator)));
|
137
|
+
_keyTuple[1] = bytes32(uint256(uint160(delegatee)));
|
138
|
+
_keyTuple[2] = ResourceId.unwrap(systemId);
|
139
|
+
_keyTuple[3] = callDataHash;
|
140
|
+
|
141
|
+
bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
142
|
+
return (uint256(bytes32(_blob)));
|
143
|
+
}
|
144
|
+
|
145
|
+
/**
|
146
|
+
* @notice Set availableCalls.
|
147
|
+
*/
|
148
|
+
function setAvailableCalls(
|
149
|
+
address delegator,
|
150
|
+
address delegatee,
|
151
|
+
ResourceId systemId,
|
152
|
+
bytes32 callDataHash,
|
153
|
+
uint256 availableCalls
|
154
|
+
) internal {
|
155
|
+
bytes32[] memory _keyTuple = new bytes32[](4);
|
156
|
+
_keyTuple[0] = bytes32(uint256(uint160(delegator)));
|
157
|
+
_keyTuple[1] = bytes32(uint256(uint160(delegatee)));
|
158
|
+
_keyTuple[2] = ResourceId.unwrap(systemId);
|
159
|
+
_keyTuple[3] = callDataHash;
|
160
|
+
|
161
|
+
StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((availableCalls)), _fieldLayout);
|
162
|
+
}
|
163
|
+
|
164
|
+
/**
|
165
|
+
* @notice Set availableCalls.
|
166
|
+
*/
|
167
|
+
function _setAvailableCalls(
|
168
|
+
address delegator,
|
169
|
+
address delegatee,
|
170
|
+
ResourceId systemId,
|
171
|
+
bytes32 callDataHash,
|
172
|
+
uint256 availableCalls
|
173
|
+
) internal {
|
174
|
+
bytes32[] memory _keyTuple = new bytes32[](4);
|
175
|
+
_keyTuple[0] = bytes32(uint256(uint160(delegator)));
|
176
|
+
_keyTuple[1] = bytes32(uint256(uint160(delegatee)));
|
177
|
+
_keyTuple[2] = ResourceId.unwrap(systemId);
|
178
|
+
_keyTuple[3] = callDataHash;
|
179
|
+
|
180
|
+
StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((availableCalls)), _fieldLayout);
|
181
|
+
}
|
182
|
+
|
183
|
+
/**
|
184
|
+
* @notice Set availableCalls.
|
185
|
+
*/
|
186
|
+
function set(
|
187
|
+
address delegator,
|
188
|
+
address delegatee,
|
189
|
+
ResourceId systemId,
|
190
|
+
bytes32 callDataHash,
|
191
|
+
uint256 availableCalls
|
192
|
+
) internal {
|
193
|
+
bytes32[] memory _keyTuple = new bytes32[](4);
|
194
|
+
_keyTuple[0] = bytes32(uint256(uint160(delegator)));
|
195
|
+
_keyTuple[1] = bytes32(uint256(uint160(delegatee)));
|
196
|
+
_keyTuple[2] = ResourceId.unwrap(systemId);
|
197
|
+
_keyTuple[3] = callDataHash;
|
198
|
+
|
199
|
+
StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((availableCalls)), _fieldLayout);
|
200
|
+
}
|
201
|
+
|
202
|
+
/**
|
203
|
+
* @notice Set availableCalls.
|
204
|
+
*/
|
205
|
+
function _set(
|
206
|
+
address delegator,
|
207
|
+
address delegatee,
|
208
|
+
ResourceId systemId,
|
209
|
+
bytes32 callDataHash,
|
210
|
+
uint256 availableCalls
|
211
|
+
) internal {
|
212
|
+
bytes32[] memory _keyTuple = new bytes32[](4);
|
213
|
+
_keyTuple[0] = bytes32(uint256(uint160(delegator)));
|
214
|
+
_keyTuple[1] = bytes32(uint256(uint160(delegatee)));
|
215
|
+
_keyTuple[2] = ResourceId.unwrap(systemId);
|
216
|
+
_keyTuple[3] = callDataHash;
|
217
|
+
|
218
|
+
StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((availableCalls)), _fieldLayout);
|
219
|
+
}
|
220
|
+
|
221
|
+
/**
|
222
|
+
* @notice Delete all data for given keys.
|
223
|
+
*/
|
224
|
+
function deleteRecord(address delegator, address delegatee, ResourceId systemId, bytes32 callDataHash) internal {
|
225
|
+
bytes32[] memory _keyTuple = new bytes32[](4);
|
226
|
+
_keyTuple[0] = bytes32(uint256(uint160(delegator)));
|
227
|
+
_keyTuple[1] = bytes32(uint256(uint160(delegatee)));
|
228
|
+
_keyTuple[2] = ResourceId.unwrap(systemId);
|
229
|
+
_keyTuple[3] = callDataHash;
|
230
|
+
|
231
|
+
StoreSwitch.deleteRecord(_tableId, _keyTuple);
|
232
|
+
}
|
233
|
+
|
234
|
+
/**
|
235
|
+
* @notice Delete all data for given keys.
|
236
|
+
*/
|
237
|
+
function _deleteRecord(address delegator, address delegatee, ResourceId systemId, bytes32 callDataHash) internal {
|
238
|
+
bytes32[] memory _keyTuple = new bytes32[](4);
|
239
|
+
_keyTuple[0] = bytes32(uint256(uint160(delegator)));
|
240
|
+
_keyTuple[1] = bytes32(uint256(uint160(delegatee)));
|
241
|
+
_keyTuple[2] = ResourceId.unwrap(systemId);
|
242
|
+
_keyTuple[3] = callDataHash;
|
243
|
+
|
244
|
+
StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout);
|
245
|
+
}
|
246
|
+
|
247
|
+
/**
|
248
|
+
* @notice Tightly pack static (fixed length) data using this table's schema.
|
249
|
+
* @return The static data, encoded into a sequence of bytes.
|
250
|
+
*/
|
251
|
+
function encodeStatic(uint256 availableCalls) internal pure returns (bytes memory) {
|
252
|
+
return abi.encodePacked(availableCalls);
|
253
|
+
}
|
254
|
+
|
255
|
+
/**
|
256
|
+
* @notice Encode all of a record's fields.
|
257
|
+
* @return The static (fixed length) data, encoded into a sequence of bytes.
|
258
|
+
* @return The lengths of the dynamic fields (packed into a single bytes32 value).
|
259
|
+
* @return The dynamic (variable length) data, encoded into a sequence of bytes.
|
260
|
+
*/
|
261
|
+
function encode(uint256 availableCalls) internal pure returns (bytes memory, EncodedLengths, bytes memory) {
|
262
|
+
bytes memory _staticData = encodeStatic(availableCalls);
|
263
|
+
|
264
|
+
EncodedLengths _encodedLengths;
|
265
|
+
bytes memory _dynamicData;
|
266
|
+
|
267
|
+
return (_staticData, _encodedLengths, _dynamicData);
|
268
|
+
}
|
269
|
+
|
270
|
+
/**
|
271
|
+
* @notice Encode keys as a bytes32 array using this table's field layout.
|
272
|
+
*/
|
273
|
+
function encodeKeyTuple(
|
274
|
+
address delegator,
|
275
|
+
address delegatee,
|
276
|
+
ResourceId systemId,
|
277
|
+
bytes32 callDataHash
|
278
|
+
) internal pure returns (bytes32[] memory) {
|
279
|
+
bytes32[] memory _keyTuple = new bytes32[](4);
|
280
|
+
_keyTuple[0] = bytes32(uint256(uint160(delegator)));
|
281
|
+
_keyTuple[1] = bytes32(uint256(uint160(delegatee)));
|
282
|
+
_keyTuple[2] = ResourceId.unwrap(systemId);
|
283
|
+
_keyTuple[3] = callDataHash;
|
284
|
+
|
285
|
+
return _keyTuple;
|
286
|
+
}
|
287
|
+
}
|
@@ -0,0 +1,256 @@
|
|
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
|
+
// Import user types
|
20
|
+
import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";
|
21
|
+
|
22
|
+
library SystemboundDelegations {
|
23
|
+
// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "SystemboundDeleg", typeId: RESOURCE_TABLE });`
|
24
|
+
ResourceId constant _tableId = ResourceId.wrap(0x7462000000000000000000000000000053797374656d626f756e6444656c6567);
|
25
|
+
|
26
|
+
FieldLayout constant _fieldLayout =
|
27
|
+
FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000);
|
28
|
+
|
29
|
+
// Hex-encoded key schema of (address, address, bytes32)
|
30
|
+
Schema constant _keySchema = Schema.wrap(0x0048030061615f00000000000000000000000000000000000000000000000000);
|
31
|
+
// Hex-encoded value schema of (uint256)
|
32
|
+
Schema constant _valueSchema = Schema.wrap(0x002001001f000000000000000000000000000000000000000000000000000000);
|
33
|
+
|
34
|
+
/**
|
35
|
+
* @notice Get the table's key field names.
|
36
|
+
* @return keyNames An array of strings with the names of key fields.
|
37
|
+
*/
|
38
|
+
function getKeyNames() internal pure returns (string[] memory keyNames) {
|
39
|
+
keyNames = new string[](3);
|
40
|
+
keyNames[0] = "delegator";
|
41
|
+
keyNames[1] = "delegatee";
|
42
|
+
keyNames[2] = "systemId";
|
43
|
+
}
|
44
|
+
|
45
|
+
/**
|
46
|
+
* @notice Get the table's value field names.
|
47
|
+
* @return fieldNames An array of strings with the names of value fields.
|
48
|
+
*/
|
49
|
+
function getFieldNames() internal pure returns (string[] memory fieldNames) {
|
50
|
+
fieldNames = new string[](1);
|
51
|
+
fieldNames[0] = "availableCalls";
|
52
|
+
}
|
53
|
+
|
54
|
+
/**
|
55
|
+
* @notice Register the table with its config.
|
56
|
+
*/
|
57
|
+
function register() internal {
|
58
|
+
StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
|
59
|
+
}
|
60
|
+
|
61
|
+
/**
|
62
|
+
* @notice Register the table with its config.
|
63
|
+
*/
|
64
|
+
function _register() internal {
|
65
|
+
StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
|
66
|
+
}
|
67
|
+
|
68
|
+
/**
|
69
|
+
* @notice Get availableCalls.
|
70
|
+
*/
|
71
|
+
function getAvailableCalls(
|
72
|
+
address delegator,
|
73
|
+
address delegatee,
|
74
|
+
ResourceId systemId
|
75
|
+
) internal view returns (uint256 availableCalls) {
|
76
|
+
bytes32[] memory _keyTuple = new bytes32[](3);
|
77
|
+
_keyTuple[0] = bytes32(uint256(uint160(delegator)));
|
78
|
+
_keyTuple[1] = bytes32(uint256(uint160(delegatee)));
|
79
|
+
_keyTuple[2] = ResourceId.unwrap(systemId);
|
80
|
+
|
81
|
+
bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
82
|
+
return (uint256(bytes32(_blob)));
|
83
|
+
}
|
84
|
+
|
85
|
+
/**
|
86
|
+
* @notice Get availableCalls.
|
87
|
+
*/
|
88
|
+
function _getAvailableCalls(
|
89
|
+
address delegator,
|
90
|
+
address delegatee,
|
91
|
+
ResourceId systemId
|
92
|
+
) internal view returns (uint256 availableCalls) {
|
93
|
+
bytes32[] memory _keyTuple = new bytes32[](3);
|
94
|
+
_keyTuple[0] = bytes32(uint256(uint160(delegator)));
|
95
|
+
_keyTuple[1] = bytes32(uint256(uint160(delegatee)));
|
96
|
+
_keyTuple[2] = ResourceId.unwrap(systemId);
|
97
|
+
|
98
|
+
bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
99
|
+
return (uint256(bytes32(_blob)));
|
100
|
+
}
|
101
|
+
|
102
|
+
/**
|
103
|
+
* @notice Get availableCalls.
|
104
|
+
*/
|
105
|
+
function get(
|
106
|
+
address delegator,
|
107
|
+
address delegatee,
|
108
|
+
ResourceId systemId
|
109
|
+
) internal view returns (uint256 availableCalls) {
|
110
|
+
bytes32[] memory _keyTuple = new bytes32[](3);
|
111
|
+
_keyTuple[0] = bytes32(uint256(uint160(delegator)));
|
112
|
+
_keyTuple[1] = bytes32(uint256(uint160(delegatee)));
|
113
|
+
_keyTuple[2] = ResourceId.unwrap(systemId);
|
114
|
+
|
115
|
+
bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
116
|
+
return (uint256(bytes32(_blob)));
|
117
|
+
}
|
118
|
+
|
119
|
+
/**
|
120
|
+
* @notice Get availableCalls.
|
121
|
+
*/
|
122
|
+
function _get(
|
123
|
+
address delegator,
|
124
|
+
address delegatee,
|
125
|
+
ResourceId systemId
|
126
|
+
) internal view returns (uint256 availableCalls) {
|
127
|
+
bytes32[] memory _keyTuple = new bytes32[](3);
|
128
|
+
_keyTuple[0] = bytes32(uint256(uint160(delegator)));
|
129
|
+
_keyTuple[1] = bytes32(uint256(uint160(delegatee)));
|
130
|
+
_keyTuple[2] = ResourceId.unwrap(systemId);
|
131
|
+
|
132
|
+
bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
133
|
+
return (uint256(bytes32(_blob)));
|
134
|
+
}
|
135
|
+
|
136
|
+
/**
|
137
|
+
* @notice Set availableCalls.
|
138
|
+
*/
|
139
|
+
function setAvailableCalls(
|
140
|
+
address delegator,
|
141
|
+
address delegatee,
|
142
|
+
ResourceId systemId,
|
143
|
+
uint256 availableCalls
|
144
|
+
) internal {
|
145
|
+
bytes32[] memory _keyTuple = new bytes32[](3);
|
146
|
+
_keyTuple[0] = bytes32(uint256(uint160(delegator)));
|
147
|
+
_keyTuple[1] = bytes32(uint256(uint160(delegatee)));
|
148
|
+
_keyTuple[2] = ResourceId.unwrap(systemId);
|
149
|
+
|
150
|
+
StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((availableCalls)), _fieldLayout);
|
151
|
+
}
|
152
|
+
|
153
|
+
/**
|
154
|
+
* @notice Set availableCalls.
|
155
|
+
*/
|
156
|
+
function _setAvailableCalls(
|
157
|
+
address delegator,
|
158
|
+
address delegatee,
|
159
|
+
ResourceId systemId,
|
160
|
+
uint256 availableCalls
|
161
|
+
) internal {
|
162
|
+
bytes32[] memory _keyTuple = new bytes32[](3);
|
163
|
+
_keyTuple[0] = bytes32(uint256(uint160(delegator)));
|
164
|
+
_keyTuple[1] = bytes32(uint256(uint160(delegatee)));
|
165
|
+
_keyTuple[2] = ResourceId.unwrap(systemId);
|
166
|
+
|
167
|
+
StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((availableCalls)), _fieldLayout);
|
168
|
+
}
|
169
|
+
|
170
|
+
/**
|
171
|
+
* @notice Set availableCalls.
|
172
|
+
*/
|
173
|
+
function set(address delegator, address delegatee, ResourceId systemId, uint256 availableCalls) internal {
|
174
|
+
bytes32[] memory _keyTuple = new bytes32[](3);
|
175
|
+
_keyTuple[0] = bytes32(uint256(uint160(delegator)));
|
176
|
+
_keyTuple[1] = bytes32(uint256(uint160(delegatee)));
|
177
|
+
_keyTuple[2] = ResourceId.unwrap(systemId);
|
178
|
+
|
179
|
+
StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((availableCalls)), _fieldLayout);
|
180
|
+
}
|
181
|
+
|
182
|
+
/**
|
183
|
+
* @notice Set availableCalls.
|
184
|
+
*/
|
185
|
+
function _set(address delegator, address delegatee, ResourceId systemId, uint256 availableCalls) internal {
|
186
|
+
bytes32[] memory _keyTuple = new bytes32[](3);
|
187
|
+
_keyTuple[0] = bytes32(uint256(uint160(delegator)));
|
188
|
+
_keyTuple[1] = bytes32(uint256(uint160(delegatee)));
|
189
|
+
_keyTuple[2] = ResourceId.unwrap(systemId);
|
190
|
+
|
191
|
+
StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((availableCalls)), _fieldLayout);
|
192
|
+
}
|
193
|
+
|
194
|
+
/**
|
195
|
+
* @notice Delete all data for given keys.
|
196
|
+
*/
|
197
|
+
function deleteRecord(address delegator, address delegatee, ResourceId systemId) internal {
|
198
|
+
bytes32[] memory _keyTuple = new bytes32[](3);
|
199
|
+
_keyTuple[0] = bytes32(uint256(uint160(delegator)));
|
200
|
+
_keyTuple[1] = bytes32(uint256(uint160(delegatee)));
|
201
|
+
_keyTuple[2] = ResourceId.unwrap(systemId);
|
202
|
+
|
203
|
+
StoreSwitch.deleteRecord(_tableId, _keyTuple);
|
204
|
+
}
|
205
|
+
|
206
|
+
/**
|
207
|
+
* @notice Delete all data for given keys.
|
208
|
+
*/
|
209
|
+
function _deleteRecord(address delegator, address delegatee, ResourceId systemId) internal {
|
210
|
+
bytes32[] memory _keyTuple = new bytes32[](3);
|
211
|
+
_keyTuple[0] = bytes32(uint256(uint160(delegator)));
|
212
|
+
_keyTuple[1] = bytes32(uint256(uint160(delegatee)));
|
213
|
+
_keyTuple[2] = ResourceId.unwrap(systemId);
|
214
|
+
|
215
|
+
StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout);
|
216
|
+
}
|
217
|
+
|
218
|
+
/**
|
219
|
+
* @notice Tightly pack static (fixed length) data using this table's schema.
|
220
|
+
* @return The static data, encoded into a sequence of bytes.
|
221
|
+
*/
|
222
|
+
function encodeStatic(uint256 availableCalls) internal pure returns (bytes memory) {
|
223
|
+
return abi.encodePacked(availableCalls);
|
224
|
+
}
|
225
|
+
|
226
|
+
/**
|
227
|
+
* @notice Encode all of a record's fields.
|
228
|
+
* @return The static (fixed length) data, encoded into a sequence of bytes.
|
229
|
+
* @return The lengths of the dynamic fields (packed into a single bytes32 value).
|
230
|
+
* @return The dynamic (variable length) data, encoded into a sequence of bytes.
|
231
|
+
*/
|
232
|
+
function encode(uint256 availableCalls) internal pure returns (bytes memory, EncodedLengths, bytes memory) {
|
233
|
+
bytes memory _staticData = encodeStatic(availableCalls);
|
234
|
+
|
235
|
+
EncodedLengths _encodedLengths;
|
236
|
+
bytes memory _dynamicData;
|
237
|
+
|
238
|
+
return (_staticData, _encodedLengths, _dynamicData);
|
239
|
+
}
|
240
|
+
|
241
|
+
/**
|
242
|
+
* @notice Encode keys as a bytes32 array using this table's field layout.
|
243
|
+
*/
|
244
|
+
function encodeKeyTuple(
|
245
|
+
address delegator,
|
246
|
+
address delegatee,
|
247
|
+
ResourceId systemId
|
248
|
+
) internal pure returns (bytes32[] memory) {
|
249
|
+
bytes32[] memory _keyTuple = new bytes32[](3);
|
250
|
+
_keyTuple[0] = bytes32(uint256(uint160(delegator)));
|
251
|
+
_keyTuple[1] = bytes32(uint256(uint160(delegatee)));
|
252
|
+
_keyTuple[2] = ResourceId.unwrap(systemId);
|
253
|
+
|
254
|
+
return _keyTuple;
|
255
|
+
}
|
256
|
+
}
|