@latticexyz/world-modules 2.0.12-type-resolutions-effc7ab1 → 2.0.12-type-resolutions-ad8cc987
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,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 TokenApproval {
|
20
|
+
FieldLayout constant _fieldLayout =
|
21
|
+
FieldLayout.wrap(0x0014010014000000000000000000000000000000000000000000000000000000);
|
22
|
+
|
23
|
+
// Hex-encoded key schema of (uint256)
|
24
|
+
Schema constant _keySchema = Schema.wrap(0x002001001f000000000000000000000000000000000000000000000000000000);
|
25
|
+
// Hex-encoded value schema of (address)
|
26
|
+
Schema constant _valueSchema = Schema.wrap(0x0014010061000000000000000000000000000000000000000000000000000000);
|
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] = "tokenId";
|
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] = "account";
|
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 account.
|
62
|
+
*/
|
63
|
+
function getAccount(ResourceId _tableId, uint256 tokenId) internal view returns (address account) {
|
64
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
65
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
66
|
+
|
67
|
+
bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
68
|
+
return (address(bytes20(_blob)));
|
69
|
+
}
|
70
|
+
|
71
|
+
/**
|
72
|
+
* @notice Get account.
|
73
|
+
*/
|
74
|
+
function _getAccount(ResourceId _tableId, uint256 tokenId) internal view returns (address account) {
|
75
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
76
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
77
|
+
|
78
|
+
bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
79
|
+
return (address(bytes20(_blob)));
|
80
|
+
}
|
81
|
+
|
82
|
+
/**
|
83
|
+
* @notice Get account.
|
84
|
+
*/
|
85
|
+
function get(ResourceId _tableId, uint256 tokenId) internal view returns (address account) {
|
86
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
87
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
88
|
+
|
89
|
+
bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
90
|
+
return (address(bytes20(_blob)));
|
91
|
+
}
|
92
|
+
|
93
|
+
/**
|
94
|
+
* @notice Get account.
|
95
|
+
*/
|
96
|
+
function _get(ResourceId _tableId, uint256 tokenId) internal view returns (address account) {
|
97
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
98
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
99
|
+
|
100
|
+
bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
101
|
+
return (address(bytes20(_blob)));
|
102
|
+
}
|
103
|
+
|
104
|
+
/**
|
105
|
+
* @notice Set account.
|
106
|
+
*/
|
107
|
+
function setAccount(ResourceId _tableId, uint256 tokenId, address account) internal {
|
108
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
109
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
110
|
+
|
111
|
+
StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((account)), _fieldLayout);
|
112
|
+
}
|
113
|
+
|
114
|
+
/**
|
115
|
+
* @notice Set account.
|
116
|
+
*/
|
117
|
+
function _setAccount(ResourceId _tableId, uint256 tokenId, address account) internal {
|
118
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
119
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
120
|
+
|
121
|
+
StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((account)), _fieldLayout);
|
122
|
+
}
|
123
|
+
|
124
|
+
/**
|
125
|
+
* @notice Set account.
|
126
|
+
*/
|
127
|
+
function set(ResourceId _tableId, uint256 tokenId, address account) internal {
|
128
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
129
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
130
|
+
|
131
|
+
StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((account)), _fieldLayout);
|
132
|
+
}
|
133
|
+
|
134
|
+
/**
|
135
|
+
* @notice Set account.
|
136
|
+
*/
|
137
|
+
function _set(ResourceId _tableId, uint256 tokenId, address account) internal {
|
138
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
139
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
140
|
+
|
141
|
+
StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((account)), _fieldLayout);
|
142
|
+
}
|
143
|
+
|
144
|
+
/**
|
145
|
+
* @notice Delete all data for given keys.
|
146
|
+
*/
|
147
|
+
function deleteRecord(ResourceId _tableId, uint256 tokenId) internal {
|
148
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
149
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
150
|
+
|
151
|
+
StoreSwitch.deleteRecord(_tableId, _keyTuple);
|
152
|
+
}
|
153
|
+
|
154
|
+
/**
|
155
|
+
* @notice Delete all data for given keys.
|
156
|
+
*/
|
157
|
+
function _deleteRecord(ResourceId _tableId, uint256 tokenId) internal {
|
158
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
159
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
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(address account) internal pure returns (bytes memory) {
|
169
|
+
return abi.encodePacked(account);
|
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(address account) internal pure returns (bytes memory, EncodedLengths, bytes memory) {
|
179
|
+
bytes memory _staticData = encodeStatic(account);
|
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(uint256 tokenId) internal pure returns (bytes32[] memory) {
|
191
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
192
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
193
|
+
|
194
|
+
return _keyTuple;
|
195
|
+
}
|
196
|
+
}
|
@@ -0,0 +1,450 @@
|
|
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 TokenURI {
|
20
|
+
FieldLayout constant _fieldLayout =
|
21
|
+
FieldLayout.wrap(0x0000000100000000000000000000000000000000000000000000000000000000);
|
22
|
+
|
23
|
+
// Hex-encoded key schema of (uint256)
|
24
|
+
Schema constant _keySchema = Schema.wrap(0x002001001f000000000000000000000000000000000000000000000000000000);
|
25
|
+
// Hex-encoded value schema of (string)
|
26
|
+
Schema constant _valueSchema = Schema.wrap(0x00000001c5000000000000000000000000000000000000000000000000000000);
|
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] = "tokenId";
|
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] = "tokenURI";
|
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 tokenURI.
|
62
|
+
*/
|
63
|
+
function getTokenURI(ResourceId _tableId, uint256 tokenId) internal view returns (string memory tokenURI) {
|
64
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
65
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
66
|
+
|
67
|
+
bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 0);
|
68
|
+
return (string(_blob));
|
69
|
+
}
|
70
|
+
|
71
|
+
/**
|
72
|
+
* @notice Get tokenURI.
|
73
|
+
*/
|
74
|
+
function _getTokenURI(ResourceId _tableId, uint256 tokenId) internal view returns (string memory tokenURI) {
|
75
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
76
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
77
|
+
|
78
|
+
bytes memory _blob = StoreCore.getDynamicField(_tableId, _keyTuple, 0);
|
79
|
+
return (string(_blob));
|
80
|
+
}
|
81
|
+
|
82
|
+
/**
|
83
|
+
* @notice Get tokenURI.
|
84
|
+
*/
|
85
|
+
function get(ResourceId _tableId, uint256 tokenId) internal view returns (string memory tokenURI) {
|
86
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
87
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
88
|
+
|
89
|
+
bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 0);
|
90
|
+
return (string(_blob));
|
91
|
+
}
|
92
|
+
|
93
|
+
/**
|
94
|
+
* @notice Get tokenURI.
|
95
|
+
*/
|
96
|
+
function _get(ResourceId _tableId, uint256 tokenId) internal view returns (string memory tokenURI) {
|
97
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
98
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
99
|
+
|
100
|
+
bytes memory _blob = StoreCore.getDynamicField(_tableId, _keyTuple, 0);
|
101
|
+
return (string(_blob));
|
102
|
+
}
|
103
|
+
|
104
|
+
/**
|
105
|
+
* @notice Set tokenURI.
|
106
|
+
*/
|
107
|
+
function setTokenURI(ResourceId _tableId, uint256 tokenId, string memory tokenURI) internal {
|
108
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
109
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
110
|
+
|
111
|
+
StoreSwitch.setDynamicField(_tableId, _keyTuple, 0, bytes((tokenURI)));
|
112
|
+
}
|
113
|
+
|
114
|
+
/**
|
115
|
+
* @notice Set tokenURI.
|
116
|
+
*/
|
117
|
+
function _setTokenURI(ResourceId _tableId, uint256 tokenId, string memory tokenURI) internal {
|
118
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
119
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
120
|
+
|
121
|
+
StoreCore.setDynamicField(_tableId, _keyTuple, 0, bytes((tokenURI)));
|
122
|
+
}
|
123
|
+
|
124
|
+
/**
|
125
|
+
* @notice Set tokenURI.
|
126
|
+
*/
|
127
|
+
function set(ResourceId _tableId, uint256 tokenId, string memory tokenURI) internal {
|
128
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
129
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
130
|
+
|
131
|
+
StoreSwitch.setDynamicField(_tableId, _keyTuple, 0, bytes((tokenURI)));
|
132
|
+
}
|
133
|
+
|
134
|
+
/**
|
135
|
+
* @notice Set tokenURI.
|
136
|
+
*/
|
137
|
+
function _set(ResourceId _tableId, uint256 tokenId, string memory tokenURI) internal {
|
138
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
139
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
140
|
+
|
141
|
+
StoreCore.setDynamicField(_tableId, _keyTuple, 0, bytes((tokenURI)));
|
142
|
+
}
|
143
|
+
|
144
|
+
/**
|
145
|
+
* @notice Get the length of tokenURI.
|
146
|
+
*/
|
147
|
+
function lengthTokenURI(ResourceId _tableId, uint256 tokenId) internal view returns (uint256) {
|
148
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
149
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
150
|
+
|
151
|
+
uint256 _byteLength = StoreSwitch.getDynamicFieldLength(_tableId, _keyTuple, 0);
|
152
|
+
unchecked {
|
153
|
+
return _byteLength / 1;
|
154
|
+
}
|
155
|
+
}
|
156
|
+
|
157
|
+
/**
|
158
|
+
* @notice Get the length of tokenURI.
|
159
|
+
*/
|
160
|
+
function _lengthTokenURI(ResourceId _tableId, uint256 tokenId) internal view returns (uint256) {
|
161
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
162
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
163
|
+
|
164
|
+
uint256 _byteLength = StoreCore.getDynamicFieldLength(_tableId, _keyTuple, 0);
|
165
|
+
unchecked {
|
166
|
+
return _byteLength / 1;
|
167
|
+
}
|
168
|
+
}
|
169
|
+
|
170
|
+
/**
|
171
|
+
* @notice Get the length of tokenURI.
|
172
|
+
*/
|
173
|
+
function length(ResourceId _tableId, uint256 tokenId) internal view returns (uint256) {
|
174
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
175
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
176
|
+
|
177
|
+
uint256 _byteLength = StoreSwitch.getDynamicFieldLength(_tableId, _keyTuple, 0);
|
178
|
+
unchecked {
|
179
|
+
return _byteLength / 1;
|
180
|
+
}
|
181
|
+
}
|
182
|
+
|
183
|
+
/**
|
184
|
+
* @notice Get the length of tokenURI.
|
185
|
+
*/
|
186
|
+
function _length(ResourceId _tableId, uint256 tokenId) internal view returns (uint256) {
|
187
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
188
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
189
|
+
|
190
|
+
uint256 _byteLength = StoreCore.getDynamicFieldLength(_tableId, _keyTuple, 0);
|
191
|
+
unchecked {
|
192
|
+
return _byteLength / 1;
|
193
|
+
}
|
194
|
+
}
|
195
|
+
|
196
|
+
/**
|
197
|
+
* @notice Get an item of tokenURI.
|
198
|
+
* @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array.
|
199
|
+
*/
|
200
|
+
function getItemTokenURI(ResourceId _tableId, uint256 tokenId, uint256 _index) internal view returns (string memory) {
|
201
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
202
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
203
|
+
|
204
|
+
unchecked {
|
205
|
+
bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 1, (_index + 1) * 1);
|
206
|
+
return (string(_blob));
|
207
|
+
}
|
208
|
+
}
|
209
|
+
|
210
|
+
/**
|
211
|
+
* @notice Get an item of tokenURI.
|
212
|
+
* @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array.
|
213
|
+
*/
|
214
|
+
function _getItemTokenURI(
|
215
|
+
ResourceId _tableId,
|
216
|
+
uint256 tokenId,
|
217
|
+
uint256 _index
|
218
|
+
) internal view returns (string memory) {
|
219
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
220
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
221
|
+
|
222
|
+
unchecked {
|
223
|
+
bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 1, (_index + 1) * 1);
|
224
|
+
return (string(_blob));
|
225
|
+
}
|
226
|
+
}
|
227
|
+
|
228
|
+
/**
|
229
|
+
* @notice Get an item of tokenURI.
|
230
|
+
* @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array.
|
231
|
+
*/
|
232
|
+
function getItem(ResourceId _tableId, uint256 tokenId, uint256 _index) internal view returns (string memory) {
|
233
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
234
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
235
|
+
|
236
|
+
unchecked {
|
237
|
+
bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 1, (_index + 1) * 1);
|
238
|
+
return (string(_blob));
|
239
|
+
}
|
240
|
+
}
|
241
|
+
|
242
|
+
/**
|
243
|
+
* @notice Get an item of tokenURI.
|
244
|
+
* @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array.
|
245
|
+
*/
|
246
|
+
function _getItem(ResourceId _tableId, uint256 tokenId, uint256 _index) internal view returns (string memory) {
|
247
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
248
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
249
|
+
|
250
|
+
unchecked {
|
251
|
+
bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 1, (_index + 1) * 1);
|
252
|
+
return (string(_blob));
|
253
|
+
}
|
254
|
+
}
|
255
|
+
|
256
|
+
/**
|
257
|
+
* @notice Push a slice to tokenURI.
|
258
|
+
*/
|
259
|
+
function pushTokenURI(ResourceId _tableId, uint256 tokenId, string memory _slice) internal {
|
260
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
261
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
262
|
+
|
263
|
+
StoreSwitch.pushToDynamicField(_tableId, _keyTuple, 0, bytes((_slice)));
|
264
|
+
}
|
265
|
+
|
266
|
+
/**
|
267
|
+
* @notice Push a slice to tokenURI.
|
268
|
+
*/
|
269
|
+
function _pushTokenURI(ResourceId _tableId, uint256 tokenId, string memory _slice) internal {
|
270
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
271
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
272
|
+
|
273
|
+
StoreCore.pushToDynamicField(_tableId, _keyTuple, 0, bytes((_slice)));
|
274
|
+
}
|
275
|
+
|
276
|
+
/**
|
277
|
+
* @notice Push a slice to tokenURI.
|
278
|
+
*/
|
279
|
+
function push(ResourceId _tableId, uint256 tokenId, string memory _slice) internal {
|
280
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
281
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
282
|
+
|
283
|
+
StoreSwitch.pushToDynamicField(_tableId, _keyTuple, 0, bytes((_slice)));
|
284
|
+
}
|
285
|
+
|
286
|
+
/**
|
287
|
+
* @notice Push a slice to tokenURI.
|
288
|
+
*/
|
289
|
+
function _push(ResourceId _tableId, uint256 tokenId, string memory _slice) internal {
|
290
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
291
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
292
|
+
|
293
|
+
StoreCore.pushToDynamicField(_tableId, _keyTuple, 0, bytes((_slice)));
|
294
|
+
}
|
295
|
+
|
296
|
+
/**
|
297
|
+
* @notice Pop a slice from tokenURI.
|
298
|
+
*/
|
299
|
+
function popTokenURI(ResourceId _tableId, uint256 tokenId) internal {
|
300
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
301
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
302
|
+
|
303
|
+
StoreSwitch.popFromDynamicField(_tableId, _keyTuple, 0, 1);
|
304
|
+
}
|
305
|
+
|
306
|
+
/**
|
307
|
+
* @notice Pop a slice from tokenURI.
|
308
|
+
*/
|
309
|
+
function _popTokenURI(ResourceId _tableId, uint256 tokenId) internal {
|
310
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
311
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
312
|
+
|
313
|
+
StoreCore.popFromDynamicField(_tableId, _keyTuple, 0, 1);
|
314
|
+
}
|
315
|
+
|
316
|
+
/**
|
317
|
+
* @notice Pop a slice from tokenURI.
|
318
|
+
*/
|
319
|
+
function pop(ResourceId _tableId, uint256 tokenId) internal {
|
320
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
321
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
322
|
+
|
323
|
+
StoreSwitch.popFromDynamicField(_tableId, _keyTuple, 0, 1);
|
324
|
+
}
|
325
|
+
|
326
|
+
/**
|
327
|
+
* @notice Pop a slice from tokenURI.
|
328
|
+
*/
|
329
|
+
function _pop(ResourceId _tableId, uint256 tokenId) internal {
|
330
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
331
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
332
|
+
|
333
|
+
StoreCore.popFromDynamicField(_tableId, _keyTuple, 0, 1);
|
334
|
+
}
|
335
|
+
|
336
|
+
/**
|
337
|
+
* @notice Update a slice of tokenURI at `_index`.
|
338
|
+
*/
|
339
|
+
function updateTokenURI(ResourceId _tableId, uint256 tokenId, uint256 _index, string memory _slice) internal {
|
340
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
341
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
342
|
+
|
343
|
+
unchecked {
|
344
|
+
bytes memory _encoded = bytes((_slice));
|
345
|
+
StoreSwitch.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 1), uint40(_encoded.length), _encoded);
|
346
|
+
}
|
347
|
+
}
|
348
|
+
|
349
|
+
/**
|
350
|
+
* @notice Update a slice of tokenURI at `_index`.
|
351
|
+
*/
|
352
|
+
function _updateTokenURI(ResourceId _tableId, uint256 tokenId, uint256 _index, string memory _slice) internal {
|
353
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
354
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
355
|
+
|
356
|
+
unchecked {
|
357
|
+
bytes memory _encoded = bytes((_slice));
|
358
|
+
StoreCore.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 1), uint40(_encoded.length), _encoded);
|
359
|
+
}
|
360
|
+
}
|
361
|
+
|
362
|
+
/**
|
363
|
+
* @notice Update a slice of tokenURI at `_index`.
|
364
|
+
*/
|
365
|
+
function update(ResourceId _tableId, uint256 tokenId, uint256 _index, string memory _slice) internal {
|
366
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
367
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
368
|
+
|
369
|
+
unchecked {
|
370
|
+
bytes memory _encoded = bytes((_slice));
|
371
|
+
StoreSwitch.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 1), uint40(_encoded.length), _encoded);
|
372
|
+
}
|
373
|
+
}
|
374
|
+
|
375
|
+
/**
|
376
|
+
* @notice Update a slice of tokenURI at `_index`.
|
377
|
+
*/
|
378
|
+
function _update(ResourceId _tableId, uint256 tokenId, uint256 _index, string memory _slice) internal {
|
379
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
380
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
381
|
+
|
382
|
+
unchecked {
|
383
|
+
bytes memory _encoded = bytes((_slice));
|
384
|
+
StoreCore.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 1), uint40(_encoded.length), _encoded);
|
385
|
+
}
|
386
|
+
}
|
387
|
+
|
388
|
+
/**
|
389
|
+
* @notice Delete all data for given keys.
|
390
|
+
*/
|
391
|
+
function deleteRecord(ResourceId _tableId, uint256 tokenId) internal {
|
392
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
393
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
394
|
+
|
395
|
+
StoreSwitch.deleteRecord(_tableId, _keyTuple);
|
396
|
+
}
|
397
|
+
|
398
|
+
/**
|
399
|
+
* @notice Delete all data for given keys.
|
400
|
+
*/
|
401
|
+
function _deleteRecord(ResourceId _tableId, uint256 tokenId) internal {
|
402
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
403
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
404
|
+
|
405
|
+
StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout);
|
406
|
+
}
|
407
|
+
|
408
|
+
/**
|
409
|
+
* @notice Tightly pack dynamic data lengths using this table's schema.
|
410
|
+
* @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value).
|
411
|
+
*/
|
412
|
+
function encodeLengths(string memory tokenURI) internal pure returns (EncodedLengths _encodedLengths) {
|
413
|
+
// Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits
|
414
|
+
unchecked {
|
415
|
+
_encodedLengths = EncodedLengthsLib.pack(bytes(tokenURI).length);
|
416
|
+
}
|
417
|
+
}
|
418
|
+
|
419
|
+
/**
|
420
|
+
* @notice Tightly pack dynamic (variable length) data using this table's schema.
|
421
|
+
* @return The dynamic data, encoded into a sequence of bytes.
|
422
|
+
*/
|
423
|
+
function encodeDynamic(string memory tokenURI) internal pure returns (bytes memory) {
|
424
|
+
return abi.encodePacked(bytes((tokenURI)));
|
425
|
+
}
|
426
|
+
|
427
|
+
/**
|
428
|
+
* @notice Encode all of a record's fields.
|
429
|
+
* @return The static (fixed length) data, encoded into a sequence of bytes.
|
430
|
+
* @return The lengths of the dynamic fields (packed into a single bytes32 value).
|
431
|
+
* @return The dynamic (variable length) data, encoded into a sequence of bytes.
|
432
|
+
*/
|
433
|
+
function encode(string memory tokenURI) internal pure returns (bytes memory, EncodedLengths, bytes memory) {
|
434
|
+
bytes memory _staticData;
|
435
|
+
EncodedLengths _encodedLengths = encodeLengths(tokenURI);
|
436
|
+
bytes memory _dynamicData = encodeDynamic(tokenURI);
|
437
|
+
|
438
|
+
return (_staticData, _encodedLengths, _dynamicData);
|
439
|
+
}
|
440
|
+
|
441
|
+
/**
|
442
|
+
* @notice Encode keys as a bytes32 array using this table's field layout.
|
443
|
+
*/
|
444
|
+
function encodeKeyTuple(uint256 tokenId) internal pure returns (bytes32[] memory) {
|
445
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
446
|
+
_keyTuple[0] = bytes32(uint256(tokenId));
|
447
|
+
|
448
|
+
return _keyTuple;
|
449
|
+
}
|
450
|
+
}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
2
|
+
pragma solidity >=0.8.24;
|
3
|
+
|
4
|
+
import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";
|
5
|
+
import { RESOURCE_TABLE } from "@latticexyz/store/src/storeResourceTypes.sol";
|
6
|
+
|
7
|
+
import { WorldResourceIdLib } from "@latticexyz/world/src/WorldResourceId.sol";
|
8
|
+
import { RESOURCE_SYSTEM } from "@latticexyz/world/src/worldResourceTypes.sol";
|
9
|
+
|
10
|
+
import { ERC721_SYSTEM_NAME, BALANCES_NAME, METADATA_NAME, OPERATOR_APPROVAL_NAME, OWNERS_NAME, TOKEN_APPROVAL_NAME, TOKEN_URI_NAME } from "./constants.sol";
|
11
|
+
|
12
|
+
function _balancesTableId(bytes14 namespace) pure returns (ResourceId) {
|
13
|
+
return WorldResourceIdLib.encode({ typeId: RESOURCE_TABLE, namespace: namespace, name: BALANCES_NAME });
|
14
|
+
}
|
15
|
+
|
16
|
+
function _metadataTableId(bytes14 namespace) pure returns (ResourceId) {
|
17
|
+
return WorldResourceIdLib.encode({ typeId: RESOURCE_TABLE, namespace: namespace, name: METADATA_NAME });
|
18
|
+
}
|
19
|
+
|
20
|
+
function _operatorApprovalTableId(bytes14 namespace) pure returns (ResourceId) {
|
21
|
+
return WorldResourceIdLib.encode({ typeId: RESOURCE_TABLE, namespace: namespace, name: OPERATOR_APPROVAL_NAME });
|
22
|
+
}
|
23
|
+
|
24
|
+
function _ownersTableId(bytes14 namespace) pure returns (ResourceId) {
|
25
|
+
return WorldResourceIdLib.encode({ typeId: RESOURCE_TABLE, namespace: namespace, name: OWNERS_NAME });
|
26
|
+
}
|
27
|
+
|
28
|
+
function _tokenApprovalTableId(bytes14 namespace) pure returns (ResourceId) {
|
29
|
+
return WorldResourceIdLib.encode({ typeId: RESOURCE_TABLE, namespace: namespace, name: TOKEN_APPROVAL_NAME });
|
30
|
+
}
|
31
|
+
|
32
|
+
function _tokenUriTableId(bytes14 namespace) pure returns (ResourceId) {
|
33
|
+
return WorldResourceIdLib.encode({ typeId: RESOURCE_TABLE, namespace: namespace, name: TOKEN_URI_NAME });
|
34
|
+
}
|
35
|
+
|
36
|
+
function _erc721SystemId(bytes14 namespace) pure returns (ResourceId) {
|
37
|
+
return WorldResourceIdLib.encode({ typeId: RESOURCE_SYSTEM, namespace: namespace, name: ERC721_SYSTEM_NAME });
|
38
|
+
}
|