@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,199 @@
|
|
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 ERC20Registry {
|
23
|
+
FieldLayout constant _fieldLayout =
|
24
|
+
FieldLayout.wrap(0x0014010014000000000000000000000000000000000000000000000000000000);
|
25
|
+
|
26
|
+
// Hex-encoded key schema of (bytes32)
|
27
|
+
Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000);
|
28
|
+
// Hex-encoded value schema of (address)
|
29
|
+
Schema constant _valueSchema = Schema.wrap(0x0014010061000000000000000000000000000000000000000000000000000000);
|
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[](1);
|
37
|
+
keyNames[0] = "namespaceId";
|
38
|
+
}
|
39
|
+
|
40
|
+
/**
|
41
|
+
* @notice Get the table's value field names.
|
42
|
+
* @return fieldNames An array of strings with the names of value fields.
|
43
|
+
*/
|
44
|
+
function getFieldNames() internal pure returns (string[] memory fieldNames) {
|
45
|
+
fieldNames = new string[](1);
|
46
|
+
fieldNames[0] = "tokenAddress";
|
47
|
+
}
|
48
|
+
|
49
|
+
/**
|
50
|
+
* @notice Register the table with its config.
|
51
|
+
*/
|
52
|
+
function register(ResourceId _tableId) internal {
|
53
|
+
StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
|
54
|
+
}
|
55
|
+
|
56
|
+
/**
|
57
|
+
* @notice Register the table with its config.
|
58
|
+
*/
|
59
|
+
function _register(ResourceId _tableId) internal {
|
60
|
+
StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
|
61
|
+
}
|
62
|
+
|
63
|
+
/**
|
64
|
+
* @notice Get tokenAddress.
|
65
|
+
*/
|
66
|
+
function getTokenAddress(ResourceId _tableId, ResourceId namespaceId) internal view returns (address tokenAddress) {
|
67
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
68
|
+
_keyTuple[0] = ResourceId.unwrap(namespaceId);
|
69
|
+
|
70
|
+
bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
71
|
+
return (address(bytes20(_blob)));
|
72
|
+
}
|
73
|
+
|
74
|
+
/**
|
75
|
+
* @notice Get tokenAddress.
|
76
|
+
*/
|
77
|
+
function _getTokenAddress(ResourceId _tableId, ResourceId namespaceId) internal view returns (address tokenAddress) {
|
78
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
79
|
+
_keyTuple[0] = ResourceId.unwrap(namespaceId);
|
80
|
+
|
81
|
+
bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
82
|
+
return (address(bytes20(_blob)));
|
83
|
+
}
|
84
|
+
|
85
|
+
/**
|
86
|
+
* @notice Get tokenAddress.
|
87
|
+
*/
|
88
|
+
function get(ResourceId _tableId, ResourceId namespaceId) internal view returns (address tokenAddress) {
|
89
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
90
|
+
_keyTuple[0] = ResourceId.unwrap(namespaceId);
|
91
|
+
|
92
|
+
bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
93
|
+
return (address(bytes20(_blob)));
|
94
|
+
}
|
95
|
+
|
96
|
+
/**
|
97
|
+
* @notice Get tokenAddress.
|
98
|
+
*/
|
99
|
+
function _get(ResourceId _tableId, ResourceId namespaceId) internal view returns (address tokenAddress) {
|
100
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
101
|
+
_keyTuple[0] = ResourceId.unwrap(namespaceId);
|
102
|
+
|
103
|
+
bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
104
|
+
return (address(bytes20(_blob)));
|
105
|
+
}
|
106
|
+
|
107
|
+
/**
|
108
|
+
* @notice Set tokenAddress.
|
109
|
+
*/
|
110
|
+
function setTokenAddress(ResourceId _tableId, ResourceId namespaceId, address tokenAddress) internal {
|
111
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
112
|
+
_keyTuple[0] = ResourceId.unwrap(namespaceId);
|
113
|
+
|
114
|
+
StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((tokenAddress)), _fieldLayout);
|
115
|
+
}
|
116
|
+
|
117
|
+
/**
|
118
|
+
* @notice Set tokenAddress.
|
119
|
+
*/
|
120
|
+
function _setTokenAddress(ResourceId _tableId, ResourceId namespaceId, address tokenAddress) internal {
|
121
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
122
|
+
_keyTuple[0] = ResourceId.unwrap(namespaceId);
|
123
|
+
|
124
|
+
StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((tokenAddress)), _fieldLayout);
|
125
|
+
}
|
126
|
+
|
127
|
+
/**
|
128
|
+
* @notice Set tokenAddress.
|
129
|
+
*/
|
130
|
+
function set(ResourceId _tableId, ResourceId namespaceId, address tokenAddress) internal {
|
131
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
132
|
+
_keyTuple[0] = ResourceId.unwrap(namespaceId);
|
133
|
+
|
134
|
+
StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((tokenAddress)), _fieldLayout);
|
135
|
+
}
|
136
|
+
|
137
|
+
/**
|
138
|
+
* @notice Set tokenAddress.
|
139
|
+
*/
|
140
|
+
function _set(ResourceId _tableId, ResourceId namespaceId, address tokenAddress) internal {
|
141
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
142
|
+
_keyTuple[0] = ResourceId.unwrap(namespaceId);
|
143
|
+
|
144
|
+
StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((tokenAddress)), _fieldLayout);
|
145
|
+
}
|
146
|
+
|
147
|
+
/**
|
148
|
+
* @notice Delete all data for given keys.
|
149
|
+
*/
|
150
|
+
function deleteRecord(ResourceId _tableId, ResourceId namespaceId) internal {
|
151
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
152
|
+
_keyTuple[0] = ResourceId.unwrap(namespaceId);
|
153
|
+
|
154
|
+
StoreSwitch.deleteRecord(_tableId, _keyTuple);
|
155
|
+
}
|
156
|
+
|
157
|
+
/**
|
158
|
+
* @notice Delete all data for given keys.
|
159
|
+
*/
|
160
|
+
function _deleteRecord(ResourceId _tableId, ResourceId namespaceId) internal {
|
161
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
162
|
+
_keyTuple[0] = ResourceId.unwrap(namespaceId);
|
163
|
+
|
164
|
+
StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout);
|
165
|
+
}
|
166
|
+
|
167
|
+
/**
|
168
|
+
* @notice Tightly pack static (fixed length) data using this table's schema.
|
169
|
+
* @return The static data, encoded into a sequence of bytes.
|
170
|
+
*/
|
171
|
+
function encodeStatic(address tokenAddress) internal pure returns (bytes memory) {
|
172
|
+
return abi.encodePacked(tokenAddress);
|
173
|
+
}
|
174
|
+
|
175
|
+
/**
|
176
|
+
* @notice Encode all of a record's fields.
|
177
|
+
* @return The static (fixed length) data, encoded into a sequence of bytes.
|
178
|
+
* @return The lengths of the dynamic fields (packed into a single bytes32 value).
|
179
|
+
* @return The dynamic (variable length) data, encoded into a sequence of bytes.
|
180
|
+
*/
|
181
|
+
function encode(address tokenAddress) internal pure returns (bytes memory, EncodedLengths, bytes memory) {
|
182
|
+
bytes memory _staticData = encodeStatic(tokenAddress);
|
183
|
+
|
184
|
+
EncodedLengths _encodedLengths;
|
185
|
+
bytes memory _dynamicData;
|
186
|
+
|
187
|
+
return (_staticData, _encodedLengths, _dynamicData);
|
188
|
+
}
|
189
|
+
|
190
|
+
/**
|
191
|
+
* @notice Encode keys as a bytes32 array using this table's field layout.
|
192
|
+
*/
|
193
|
+
function encodeKeyTuple(ResourceId namespaceId) internal pure returns (bytes32[] memory) {
|
194
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
195
|
+
_keyTuple[0] = ResourceId.unwrap(namespaceId);
|
196
|
+
|
197
|
+
return _keyTuple;
|
198
|
+
}
|
199
|
+
}
|
@@ -0,0 +1,184 @@
|
|
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 TotalSupply {
|
20
|
+
FieldLayout constant _fieldLayout =
|
21
|
+
FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000);
|
22
|
+
|
23
|
+
// Hex-encoded key schema of ()
|
24
|
+
Schema constant _keySchema = Schema.wrap(0x0000000000000000000000000000000000000000000000000000000000000000);
|
25
|
+
// Hex-encoded value schema of (uint256)
|
26
|
+
Schema constant _valueSchema = Schema.wrap(0x002001001f000000000000000000000000000000000000000000000000000000);
|
27
|
+
|
28
|
+
/**
|
29
|
+
* @notice Get the table's key field names.
|
30
|
+
* @return keyNames An array of strings with the names of key fields.
|
31
|
+
*/
|
32
|
+
function getKeyNames() internal pure returns (string[] memory keyNames) {
|
33
|
+
keyNames = new string[](0);
|
34
|
+
}
|
35
|
+
|
36
|
+
/**
|
37
|
+
* @notice Get the table's value field names.
|
38
|
+
* @return fieldNames An array of strings with the names of value fields.
|
39
|
+
*/
|
40
|
+
function getFieldNames() internal pure returns (string[] memory fieldNames) {
|
41
|
+
fieldNames = new string[](1);
|
42
|
+
fieldNames[0] = "totalSupply";
|
43
|
+
}
|
44
|
+
|
45
|
+
/**
|
46
|
+
* @notice Register the table with its config.
|
47
|
+
*/
|
48
|
+
function register(ResourceId _tableId) internal {
|
49
|
+
StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
|
50
|
+
}
|
51
|
+
|
52
|
+
/**
|
53
|
+
* @notice Register the table with its config.
|
54
|
+
*/
|
55
|
+
function _register(ResourceId _tableId) internal {
|
56
|
+
StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
|
57
|
+
}
|
58
|
+
|
59
|
+
/**
|
60
|
+
* @notice Get totalSupply.
|
61
|
+
*/
|
62
|
+
function getTotalSupply(ResourceId _tableId) internal view returns (uint256 totalSupply) {
|
63
|
+
bytes32[] memory _keyTuple = new bytes32[](0);
|
64
|
+
|
65
|
+
bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
66
|
+
return (uint256(bytes32(_blob)));
|
67
|
+
}
|
68
|
+
|
69
|
+
/**
|
70
|
+
* @notice Get totalSupply.
|
71
|
+
*/
|
72
|
+
function _getTotalSupply(ResourceId _tableId) internal view returns (uint256 totalSupply) {
|
73
|
+
bytes32[] memory _keyTuple = new bytes32[](0);
|
74
|
+
|
75
|
+
bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
76
|
+
return (uint256(bytes32(_blob)));
|
77
|
+
}
|
78
|
+
|
79
|
+
/**
|
80
|
+
* @notice Get totalSupply.
|
81
|
+
*/
|
82
|
+
function get(ResourceId _tableId) internal view returns (uint256 totalSupply) {
|
83
|
+
bytes32[] memory _keyTuple = new bytes32[](0);
|
84
|
+
|
85
|
+
bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
86
|
+
return (uint256(bytes32(_blob)));
|
87
|
+
}
|
88
|
+
|
89
|
+
/**
|
90
|
+
* @notice Get totalSupply.
|
91
|
+
*/
|
92
|
+
function _get(ResourceId _tableId) internal view returns (uint256 totalSupply) {
|
93
|
+
bytes32[] memory _keyTuple = new bytes32[](0);
|
94
|
+
|
95
|
+
bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
96
|
+
return (uint256(bytes32(_blob)));
|
97
|
+
}
|
98
|
+
|
99
|
+
/**
|
100
|
+
* @notice Set totalSupply.
|
101
|
+
*/
|
102
|
+
function setTotalSupply(ResourceId _tableId, uint256 totalSupply) internal {
|
103
|
+
bytes32[] memory _keyTuple = new bytes32[](0);
|
104
|
+
|
105
|
+
StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((totalSupply)), _fieldLayout);
|
106
|
+
}
|
107
|
+
|
108
|
+
/**
|
109
|
+
* @notice Set totalSupply.
|
110
|
+
*/
|
111
|
+
function _setTotalSupply(ResourceId _tableId, uint256 totalSupply) internal {
|
112
|
+
bytes32[] memory _keyTuple = new bytes32[](0);
|
113
|
+
|
114
|
+
StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((totalSupply)), _fieldLayout);
|
115
|
+
}
|
116
|
+
|
117
|
+
/**
|
118
|
+
* @notice Set totalSupply.
|
119
|
+
*/
|
120
|
+
function set(ResourceId _tableId, uint256 totalSupply) internal {
|
121
|
+
bytes32[] memory _keyTuple = new bytes32[](0);
|
122
|
+
|
123
|
+
StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((totalSupply)), _fieldLayout);
|
124
|
+
}
|
125
|
+
|
126
|
+
/**
|
127
|
+
* @notice Set totalSupply.
|
128
|
+
*/
|
129
|
+
function _set(ResourceId _tableId, uint256 totalSupply) internal {
|
130
|
+
bytes32[] memory _keyTuple = new bytes32[](0);
|
131
|
+
|
132
|
+
StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((totalSupply)), _fieldLayout);
|
133
|
+
}
|
134
|
+
|
135
|
+
/**
|
136
|
+
* @notice Delete all data for given keys.
|
137
|
+
*/
|
138
|
+
function deleteRecord(ResourceId _tableId) internal {
|
139
|
+
bytes32[] memory _keyTuple = new bytes32[](0);
|
140
|
+
|
141
|
+
StoreSwitch.deleteRecord(_tableId, _keyTuple);
|
142
|
+
}
|
143
|
+
|
144
|
+
/**
|
145
|
+
* @notice Delete all data for given keys.
|
146
|
+
*/
|
147
|
+
function _deleteRecord(ResourceId _tableId) internal {
|
148
|
+
bytes32[] memory _keyTuple = new bytes32[](0);
|
149
|
+
|
150
|
+
StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout);
|
151
|
+
}
|
152
|
+
|
153
|
+
/**
|
154
|
+
* @notice Tightly pack static (fixed length) data using this table's schema.
|
155
|
+
* @return The static data, encoded into a sequence of bytes.
|
156
|
+
*/
|
157
|
+
function encodeStatic(uint256 totalSupply) internal pure returns (bytes memory) {
|
158
|
+
return abi.encodePacked(totalSupply);
|
159
|
+
}
|
160
|
+
|
161
|
+
/**
|
162
|
+
* @notice Encode all of a record's fields.
|
163
|
+
* @return The static (fixed length) data, encoded into a sequence of bytes.
|
164
|
+
* @return The lengths of the dynamic fields (packed into a single bytes32 value).
|
165
|
+
* @return The dynamic (variable length) data, encoded into a sequence of bytes.
|
166
|
+
*/
|
167
|
+
function encode(uint256 totalSupply) internal pure returns (bytes memory, EncodedLengths, bytes memory) {
|
168
|
+
bytes memory _staticData = encodeStatic(totalSupply);
|
169
|
+
|
170
|
+
EncodedLengths _encodedLengths;
|
171
|
+
bytes memory _dynamicData;
|
172
|
+
|
173
|
+
return (_staticData, _encodedLengths, _dynamicData);
|
174
|
+
}
|
175
|
+
|
176
|
+
/**
|
177
|
+
* @notice Encode keys as a bytes32 array using this table's field layout.
|
178
|
+
*/
|
179
|
+
function encodeKeyTuple() internal pure returns (bytes32[] memory) {
|
180
|
+
bytes32[] memory _keyTuple = new bytes32[](0);
|
181
|
+
|
182
|
+
return _keyTuple;
|
183
|
+
}
|
184
|
+
}
|
@@ -0,0 +1,30 @@
|
|
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 { ALLOWANCES_NAME, BALANCES_NAME, TOTAL_SUPPLY_NAME, METADATA_NAME, ERC20_SYSTEM_NAME } from "./constants.sol";
|
11
|
+
|
12
|
+
function _allowancesTableId(bytes14 namespace) pure returns (ResourceId) {
|
13
|
+
return WorldResourceIdLib.encode({ typeId: RESOURCE_TABLE, namespace: namespace, name: ALLOWANCES_NAME });
|
14
|
+
}
|
15
|
+
|
16
|
+
function _balancesTableId(bytes14 namespace) pure returns (ResourceId) {
|
17
|
+
return WorldResourceIdLib.encode({ typeId: RESOURCE_TABLE, namespace: namespace, name: BALANCES_NAME });
|
18
|
+
}
|
19
|
+
|
20
|
+
function _totalSupplyTableId(bytes14 namespace) pure returns (ResourceId) {
|
21
|
+
return WorldResourceIdLib.encode({ typeId: RESOURCE_TABLE, namespace: namespace, name: TOTAL_SUPPLY_NAME });
|
22
|
+
}
|
23
|
+
|
24
|
+
function _metadataTableId(bytes14 namespace) pure returns (ResourceId) {
|
25
|
+
return WorldResourceIdLib.encode({ typeId: RESOURCE_TABLE, namespace: namespace, name: METADATA_NAME });
|
26
|
+
}
|
27
|
+
|
28
|
+
function _erc20SystemId(bytes14 namespace) pure returns (ResourceId) {
|
29
|
+
return WorldResourceIdLib.encode({ typeId: RESOURCE_SYSTEM, namespace: namespace, name: ERC20_SYSTEM_NAME });
|
30
|
+
}
|
@@ -0,0 +1,95 @@
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
2
|
+
pragma solidity >=0.8.24;
|
3
|
+
|
4
|
+
import { ResourceIds } from "@latticexyz/store/src/codegen/tables/ResourceIds.sol";
|
5
|
+
import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";
|
6
|
+
import { Module } from "@latticexyz/world/src/Module.sol";
|
7
|
+
import { WorldResourceIdLib } from "@latticexyz/world/src/WorldResourceId.sol";
|
8
|
+
import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.sol";
|
9
|
+
import { InstalledModules } from "@latticexyz/world/src/codegen/tables/InstalledModules.sol";
|
10
|
+
import { revertWithBytes } from "@latticexyz/world/src/revertWithBytes.sol";
|
11
|
+
|
12
|
+
import { Puppet } from "../puppet/Puppet.sol";
|
13
|
+
import { createPuppet } from "../puppet/createPuppet.sol";
|
14
|
+
import { Balances } from "../tokens/tables/Balances.sol";
|
15
|
+
|
16
|
+
import { MODULE_NAMESPACE, MODULE_NAMESPACE_ID, ERC721_REGISTRY_TABLE_ID } from "./constants.sol";
|
17
|
+
import { _erc721SystemId, _balancesTableId, _metadataTableId, _tokenUriTableId, _operatorApprovalTableId, _ownersTableId, _tokenApprovalTableId } from "./utils.sol";
|
18
|
+
import { ERC721System } from "./ERC721System.sol";
|
19
|
+
|
20
|
+
import { OperatorApproval } from "./tables/OperatorApproval.sol";
|
21
|
+
import { Owners } from "./tables/Owners.sol";
|
22
|
+
import { TokenApproval } from "./tables/TokenApproval.sol";
|
23
|
+
import { TokenURI } from "./tables/TokenURI.sol";
|
24
|
+
import { ERC721Registry } from "./tables/ERC721Registry.sol";
|
25
|
+
import { ERC721Metadata, ERC721MetadataData } from "./tables/ERC721Metadata.sol";
|
26
|
+
|
27
|
+
contract ERC721Module is Module {
|
28
|
+
error ERC721Module_InvalidNamespace(bytes14 namespace);
|
29
|
+
|
30
|
+
address immutable registrationLibrary = address(new ERC721ModuleRegistrationLibrary());
|
31
|
+
|
32
|
+
function install(bytes memory encodedArgs) public {
|
33
|
+
// Require the module to not be installed with these args yet
|
34
|
+
requireNotInstalled(__self, encodedArgs);
|
35
|
+
|
36
|
+
// Decode args
|
37
|
+
(bytes14 namespace, ERC721MetadataData memory metadata) = abi.decode(encodedArgs, (bytes14, ERC721MetadataData));
|
38
|
+
|
39
|
+
// Require the namespace to not be the module's namespace
|
40
|
+
if (namespace == MODULE_NAMESPACE) {
|
41
|
+
revert ERC721Module_InvalidNamespace(namespace);
|
42
|
+
}
|
43
|
+
|
44
|
+
// Register the ERC721 tables and system
|
45
|
+
IBaseWorld world = IBaseWorld(_world());
|
46
|
+
(bool success, bytes memory returnData) = registrationLibrary.delegatecall(
|
47
|
+
abi.encodeCall(ERC721ModuleRegistrationLibrary.register, (world, namespace))
|
48
|
+
);
|
49
|
+
if (!success) revertWithBytes(returnData);
|
50
|
+
|
51
|
+
// Initialize the Metadata
|
52
|
+
ERC721Metadata.set(_metadataTableId(namespace), metadata);
|
53
|
+
|
54
|
+
// Deploy and register the ERC721 puppet.
|
55
|
+
ResourceId erc721SystemId = _erc721SystemId(namespace);
|
56
|
+
address puppet = createPuppet(world, erc721SystemId);
|
57
|
+
|
58
|
+
// Transfer ownership of the namespace to the caller
|
59
|
+
ResourceId namespaceId = WorldResourceIdLib.encodeNamespace(namespace);
|
60
|
+
world.transferOwnership(namespaceId, _msgSender());
|
61
|
+
|
62
|
+
// Register the ERC721 in the ERC20Registry
|
63
|
+
if (!ResourceIds.getExists(ERC721_REGISTRY_TABLE_ID)) {
|
64
|
+
world.registerNamespace(MODULE_NAMESPACE_ID);
|
65
|
+
ERC721Registry.register(ERC721_REGISTRY_TABLE_ID);
|
66
|
+
}
|
67
|
+
ERC721Registry.set(ERC721_REGISTRY_TABLE_ID, namespaceId, puppet);
|
68
|
+
}
|
69
|
+
|
70
|
+
function installRoot(bytes memory) public pure {
|
71
|
+
revert Module_RootInstallNotSupported();
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
75
|
+
contract ERC721ModuleRegistrationLibrary {
|
76
|
+
/**
|
77
|
+
* Register systems and tables for a new ERC721 token in a given namespace
|
78
|
+
*/
|
79
|
+
function register(IBaseWorld world, bytes14 namespace) public {
|
80
|
+
// Register the namespace if it doesn't exist yet
|
81
|
+
ResourceId tokenNamespace = WorldResourceIdLib.encodeNamespace(namespace);
|
82
|
+
world.registerNamespace(tokenNamespace);
|
83
|
+
|
84
|
+
// Register the tables
|
85
|
+
OperatorApproval.register(_operatorApprovalTableId(namespace));
|
86
|
+
Owners.register(_ownersTableId(namespace));
|
87
|
+
TokenApproval.register(_tokenApprovalTableId(namespace));
|
88
|
+
TokenURI.register(_tokenUriTableId(namespace));
|
89
|
+
Balances.register(_balancesTableId(namespace));
|
90
|
+
ERC721Metadata.register(_metadataTableId(namespace));
|
91
|
+
|
92
|
+
// Register a new ERC20System
|
93
|
+
world.registerSystem(_erc721SystemId(namespace), new ERC721System(), true);
|
94
|
+
}
|
95
|
+
}
|