@latticexyz/world-modules 2.0.12-main-ecc8f658 → 2.0.12-type-resolutions-effc7ab1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/cache/solidity-files-cache.json +1 -0
  2. package/dist/mud.config.d.ts +0 -2
  3. package/package.json +9 -9
  4. package/src/index.sol +0 -25
  5. package/src/interfaces/IBaseWorld.sol +0 -16
  6. package/src/interfaces/IERC20System.sol +0 -33
  7. package/src/interfaces/IERC721System.sol +0 -43
  8. package/src/interfaces/IPuppetFactorySystem.sol +0 -15
  9. package/src/interfaces/IUniqueEntitySystem.sol +0 -13
  10. package/src/interfaces/IUnstable_CallWithSignatureSystem.sol +0 -20
  11. package/src/modules/callwithsignature/ECDSA.sol +0 -174
  12. package/src/modules/callwithsignature/IERC1271.sol +0 -17
  13. package/src/modules/callwithsignature/IUnstable_CallWithSignatureErrors.sol +0 -9
  14. package/src/modules/callwithsignature/SignatureChecker.sol +0 -50
  15. package/src/modules/callwithsignature/Unstable_CallWithSignatureModule.sol +0 -48
  16. package/src/modules/callwithsignature/Unstable_CallWithSignatureSystem.sol +0 -36
  17. package/src/modules/callwithsignature/constants.sol +0 -10
  18. package/src/modules/callwithsignature/getSignedMessageHash.sol +0 -54
  19. package/src/modules/callwithsignature/tables/CallWithSignatureNonces.sol +0 -199
  20. package/src/modules/callwithsignature/validateCallWithSignature.sol +0 -31
  21. package/src/modules/erc20-puppet/ERC20Module.sol +0 -88
  22. package/src/modules/erc20-puppet/ERC20System.sol +0 -286
  23. package/src/modules/erc20-puppet/IERC20.sol +0 -94
  24. package/src/modules/erc20-puppet/IERC20Errors.sol +0 -49
  25. package/src/modules/erc20-puppet/IERC20Events.sol +0 -18
  26. package/src/modules/erc20-puppet/IERC20Mintable.sol +0 -25
  27. package/src/modules/erc20-puppet/constants.sol +0 -20
  28. package/src/modules/erc20-puppet/registerERC20.sol +0 -35
  29. package/src/modules/erc20-puppet/tables/Allowances.sol +0 -208
  30. package/src/modules/erc20-puppet/tables/ERC20Metadata.sol +0 -604
  31. package/src/modules/erc20-puppet/tables/ERC20Registry.sol +0 -199
  32. package/src/modules/erc20-puppet/tables/TotalSupply.sol +0 -184
  33. package/src/modules/erc20-puppet/utils.sol +0 -30
  34. package/src/modules/erc721-puppet/ERC721Module.sol +0 -95
  35. package/src/modules/erc721-puppet/ERC721System.sol +0 -531
  36. package/src/modules/erc721-puppet/IERC721.sol +0 -120
  37. package/src/modules/erc721-puppet/IERC721Errors.sol +0 -61
  38. package/src/modules/erc721-puppet/IERC721Events.sol +0 -23
  39. package/src/modules/erc721-puppet/IERC721Metadata.sol +0 -27
  40. package/src/modules/erc721-puppet/IERC721Mintable.sol +0 -53
  41. package/src/modules/erc721-puppet/IERC721Receiver.sol +0 -28
  42. package/src/modules/erc721-puppet/constants.sol +0 -23
  43. package/src/modules/erc721-puppet/libraries/LibString.sol +0 -77
  44. package/src/modules/erc721-puppet/registerERC721.sol +0 -37
  45. package/src/modules/erc721-puppet/tables/ERC721Metadata.sol +0 -703
  46. package/src/modules/erc721-puppet/tables/ERC721Registry.sol +0 -199
  47. package/src/modules/erc721-puppet/tables/OperatorApproval.sol +0 -220
  48. package/src/modules/erc721-puppet/tables/Owners.sol +0 -196
  49. package/src/modules/erc721-puppet/tables/TokenApproval.sol +0 -196
  50. package/src/modules/erc721-puppet/tables/TokenURI.sol +0 -450
  51. package/src/modules/erc721-puppet/utils.sol +0 -38
  52. package/src/modules/keysintable/KeysInTableHook.sol +0 -141
  53. package/src/modules/keysintable/KeysInTableModule.sol +0 -110
  54. package/src/modules/keysintable/constants.sol +0 -7
  55. package/src/modules/keysintable/getKeysInTable.sol +0 -81
  56. package/src/modules/keysintable/hasKey.sol +0 -28
  57. package/src/modules/keysintable/query.sol +0 -200
  58. package/src/modules/keysintable/tables/KeysInTable.sol +0 -1638
  59. package/src/modules/keysintable/tables/UsedKeysIndex.sol +0 -414
  60. package/src/modules/keyswithvalue/KeysWithValueHook.sol +0 -158
  61. package/src/modules/keyswithvalue/KeysWithValueModule.sol +0 -103
  62. package/src/modules/keyswithvalue/constants.sol +0 -7
  63. package/src/modules/keyswithvalue/getKeysWithValue.sol +0 -58
  64. package/src/modules/keyswithvalue/getTargetTableId.sol +0 -32
  65. package/src/modules/keyswithvalue/tables/KeysWithValue.sol +0 -668
  66. package/src/modules/puppet/Puppet.sol +0 -80
  67. package/src/modules/puppet/PuppetDelegationControl.sol +0 -17
  68. package/src/modules/puppet/PuppetFactorySystem.sol +0 -25
  69. package/src/modules/puppet/PuppetMaster.sol +0 -19
  70. package/src/modules/puppet/PuppetModule.sol +0 -64
  71. package/src/modules/puppet/constants.sol +0 -23
  72. package/src/modules/puppet/createPuppet.sol +0 -24
  73. package/src/modules/puppet/tables/PuppetRegistry.sol +0 -199
  74. package/src/modules/puppet/utils.sol +0 -10
  75. package/src/modules/std-delegations/CallboundDelegationControl.sol +0 -64
  76. package/src/modules/std-delegations/StandardDelegationsModule.sol +0 -55
  77. package/src/modules/std-delegations/SystemboundDelegationControl.sol +0 -54
  78. package/src/modules/std-delegations/TimeboundDelegationControl.sol +0 -27
  79. package/src/modules/std-delegations/constants.sol +0 -21
  80. package/src/modules/std-delegations/tables/CallboundDelegations.sol +0 -287
  81. package/src/modules/std-delegations/tables/SystemboundDelegations.sol +0 -256
  82. package/src/modules/std-delegations/tables/TimeboundDelegations.sol +0 -211
  83. package/src/modules/tokens/tables/Balances.sol +0 -196
  84. package/src/modules/uniqueentity/UniqueEntityModule.sol +0 -73
  85. package/src/modules/uniqueentity/UniqueEntitySystem.sol +0 -18
  86. package/src/modules/uniqueentity/constants.sol +0 -13
  87. package/src/modules/uniqueentity/getUniqueEntity.sol +0 -26
  88. package/src/modules/uniqueentity/tables/UniqueEntity.sol +0 -238
  89. package/src/modules/utils/ArrayLib.sol +0 -55
  90. package/src/utils/AccessControlLib.sol +0 -55
  91. package/src/utils/SystemSwitch.sol +0 -80
@@ -1,531 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity >=0.8.24;
3
-
4
- import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";
5
- import { System } from "@latticexyz/world/src/System.sol";
6
- import { WorldResourceIdInstance } from "@latticexyz/world/src/WorldResourceId.sol";
7
- import { SystemRegistry } from "@latticexyz/world/src/codegen/tables/SystemRegistry.sol";
8
-
9
- import { AccessControlLib } from "../../utils/AccessControlLib.sol";
10
- import { PuppetMaster } from "../puppet/PuppetMaster.sol";
11
- import { toTopic } from "../puppet/utils.sol";
12
- import { Balances } from "../tokens/tables/Balances.sol";
13
-
14
- import { IERC721Mintable } from "./IERC721Mintable.sol";
15
- import { IERC721Receiver } from "./IERC721Receiver.sol";
16
-
17
- import { ERC721Metadata } from "./tables/ERC721Metadata.sol";
18
- import { OperatorApproval } from "./tables/OperatorApproval.sol";
19
- import { Owners } from "./tables/Owners.sol";
20
- import { TokenApproval } from "./tables/TokenApproval.sol";
21
- import { TokenURI } from "./tables/TokenURI.sol";
22
-
23
- import { _balancesTableId, _metadataTableId, _tokenUriTableId, _operatorApprovalTableId, _ownersTableId, _tokenApprovalTableId } from "./utils.sol";
24
- import { LibString } from "./libraries/LibString.sol";
25
-
26
- contract ERC721System is IERC721Mintable, System, PuppetMaster {
27
- using WorldResourceIdInstance for ResourceId;
28
- using LibString for uint256;
29
-
30
- /**
31
- * @dev See {IERC721-balanceOf}.
32
- */
33
- function balanceOf(address owner) public view virtual returns (uint256) {
34
- if (owner == address(0)) {
35
- revert ERC721InvalidOwner(address(0));
36
- }
37
- return Balances.get(_balancesTableId(_namespace()), owner);
38
- }
39
-
40
- /**
41
- * @dev See {IERC721-ownerOf}.
42
- */
43
- function ownerOf(uint256 tokenId) public view virtual returns (address) {
44
- return _requireOwned(tokenId);
45
- }
46
-
47
- /**
48
- * @dev See {IERC721Metadata-name}.
49
- */
50
- function name() public view virtual returns (string memory) {
51
- return ERC721Metadata.getName(_metadataTableId(_namespace()));
52
- }
53
-
54
- /**
55
- * @dev See {IERC721Metadata-symbol}.
56
- */
57
- function symbol() public view virtual returns (string memory) {
58
- return ERC721Metadata.getSymbol(_metadataTableId(_namespace()));
59
- }
60
-
61
- /**
62
- * @dev See {IERC721Metadata-tokenURI}.
63
- */
64
- function tokenURI(uint256 tokenId) public view virtual returns (string memory) {
65
- _requireOwned(tokenId);
66
-
67
- string memory baseURI = _baseURI();
68
- string memory _tokenURI = TokenURI.get(_tokenUriTableId(_namespace()), tokenId);
69
- _tokenURI = bytes(_tokenURI).length > 0 ? _tokenURI : tokenId.toString();
70
- return bytes(baseURI).length > 0 ? string.concat(baseURI, _tokenURI) : _tokenURI;
71
- }
72
-
73
- /**
74
- * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
75
- * token will be the concatenation of the `baseURI` and the `tokenId`.
76
- */
77
- function _baseURI() internal view virtual returns (string memory) {
78
- return ERC721Metadata.getBaseURI(_metadataTableId(_namespace()));
79
- }
80
-
81
- /**
82
- * @dev See {IERC721-approve}.
83
- */
84
- function approve(address to, uint256 tokenId) public virtual {
85
- _approve(to, tokenId, _msgSender());
86
- }
87
-
88
- /**
89
- * @dev See {IERC721-getApproved}.
90
- */
91
- function getApproved(uint256 tokenId) public view virtual returns (address) {
92
- _requireOwned(tokenId);
93
-
94
- return _getApproved(tokenId);
95
- }
96
-
97
- /**
98
- * @dev See {IERC721-setApprovalForAll}.
99
- */
100
- function setApprovalForAll(address operator, bool approved) public virtual {
101
- _setApprovalForAll(_msgSender(), operator, approved);
102
- }
103
-
104
- /**
105
- * @dev See {IERC721-isApprovedForAll}.
106
- */
107
- function isApprovedForAll(address owner, address operator) public view virtual returns (bool) {
108
- return OperatorApproval.get(_operatorApprovalTableId(_namespace()), owner, operator);
109
- }
110
-
111
- /**
112
- * @dev See {IERC721-transferFrom}.
113
- */
114
- function transferFrom(address from, address to, uint256 tokenId) public virtual {
115
- if (to == address(0)) {
116
- revert ERC721InvalidReceiver(address(0));
117
- }
118
- // Setting an "auth" arguments enables the `_isAuthorized` check which verifies that the token exists
119
- // (from != 0). Therefore, it is not needed to verify that the return value is not 0 here.
120
- address previousOwner = _update(to, tokenId, _msgSender());
121
- if (previousOwner != from) {
122
- revert ERC721IncorrectOwner(from, tokenId, previousOwner);
123
- }
124
- }
125
-
126
- /**
127
- * @dev See {IERC721-safeTransferFrom}.
128
- */
129
- function safeTransferFrom(address from, address to, uint256 tokenId) public {
130
- safeTransferFrom(from, to, tokenId, "");
131
- }
132
-
133
- /**
134
- * @dev See {IERC721-safeTransferFrom}.
135
- */
136
- function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public virtual {
137
- transferFrom(from, to, tokenId);
138
- _checkOnERC721Received(from, to, tokenId, data);
139
- }
140
-
141
- /**
142
- * @dev Mints `tokenId` and transfers it to `to`.
143
- *
144
- * Requirements:
145
- *
146
- * - caller must own the namespace
147
- * - `tokenId` must not exist.
148
- * - `to` cannot be the zero address.
149
- *
150
- * Emits a {Transfer} event.
151
- */
152
- function mint(address to, uint256 tokenId) public virtual {
153
- _requireOwner();
154
- _mint(to, tokenId);
155
- }
156
-
157
- /**
158
- * @dev Mints `tokenId`, transfers it to `to` and checks for `to` acceptance.
159
- *
160
- * Requirements:
161
- *
162
- * - caller must own the namespace
163
- * - `tokenId` must not exist.
164
- * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
165
- *
166
- * Emits a {Transfer} event.
167
- */
168
- function safeMint(address to, uint256 tokenId) public {
169
- _requireOwner();
170
- _safeMint(to, tokenId, "");
171
- }
172
-
173
- /**
174
- * @dev Same as {xref-ERC721-safeMint-address-uint256-}[`safeMint`], with an additional `data` parameter which is
175
- * forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
176
- */
177
- function safeMint(address to, uint256 tokenId, bytes memory data) public virtual {
178
- _requireOwner();
179
- _safeMint(to, tokenId, data);
180
- }
181
-
182
- /**
183
- * @dev Destroys `tokenId`.
184
- * The approval is cleared when the token is burned.
185
- *
186
- * Requirements:
187
- * - caller must own the namespace
188
- * - `tokenId` must exist.
189
- *
190
- * Emits a {Transfer} event.
191
- */
192
- function burn(uint256 tokenId) public {
193
- _requireOwner();
194
- _burn(tokenId);
195
- }
196
-
197
- /**
198
- * @dev Returns the owner of the `tokenId`. Does NOT revert if token doesn't exist
199
- *
200
- * IMPORTANT: Any overrides to this function that add ownership of tokens not tracked by the
201
- * core ERC721 logic MUST be matched with the use of {_increaseBalance} to keep balances
202
- * consistent with ownership. The invariant to preserve is that for any address `a` the value returned by
203
- * `balanceOf(a)` must be equal to the number of tokens such that `_ownerOf(tokenId)` is `a`.
204
- */
205
- function _ownerOf(uint256 tokenId) internal view virtual returns (address) {
206
- return Owners.get(_ownersTableId(_namespace()), tokenId);
207
- }
208
-
209
- /**
210
- * @dev Returns the approved address for `tokenId`. Returns 0 if `tokenId` is not minted.
211
- */
212
- function _getApproved(uint256 tokenId) internal view virtual returns (address) {
213
- return TokenApproval.get(_tokenApprovalTableId(_namespace()), tokenId);
214
- }
215
-
216
- /**
217
- * @dev Returns whether `spender` is allowed to manage `owner`'s tokens, or `tokenId` in
218
- * particular (ignoring whether it is owned by `owner`).
219
- *
220
- * WARNING: This function assumes that `owner` is the actual owner of `tokenId` and does not verify this
221
- * assumption.
222
- */
223
- function _isAuthorized(address owner, address spender, uint256 tokenId) internal view virtual returns (bool) {
224
- return
225
- spender != address(0) &&
226
- (owner == spender || isApprovedForAll(owner, spender) || _getApproved(tokenId) == spender);
227
- }
228
-
229
- /**
230
- * @dev Checks if `spender` can operate on `tokenId`, assuming the provided `owner` is the actual owner.
231
- * Reverts if `spender` does not have approval from the provided `owner` for the given token or for all its assets
232
- * the `spender` for the specific `tokenId`.
233
- *
234
- * WARNING: This function assumes that `owner` is the actual owner of `tokenId` and does not verify this
235
- * assumption.
236
- */
237
- function _checkAuthorized(address owner, address spender, uint256 tokenId) internal view virtual {
238
- if (!_isAuthorized(owner, spender, tokenId)) {
239
- if (owner == address(0)) {
240
- revert ERC721NonexistentToken(tokenId);
241
- } else {
242
- revert ERC721InsufficientApproval(spender, tokenId);
243
- }
244
- }
245
- }
246
-
247
- /**
248
- * @dev Unsafe write access to the balances, used by extensions that "mint" tokens using an {ownerOf} override.
249
- *
250
- * NOTE: the value is limited to type(uint128).max. This protect against _balance overflow. It is unrealistic that
251
- * a uint256 would ever overflow from increments when these increments are bounded to uint128 values.
252
- *
253
- * WARNING: Increasing an account's balance using this function tends to be paired with an override of the
254
- * {_ownerOf} function to resolve the ownership of the corresponding tokens so that balances and ownership
255
- * remain consistent with one another.
256
- */
257
- function _increaseBalance(address account, uint128 value) internal virtual {
258
- ResourceId balanceTableId = _balancesTableId(_namespace());
259
- unchecked {
260
- Balances.set(balanceTableId, account, Balances.get(balanceTableId, account) + value);
261
- }
262
- }
263
-
264
- /**
265
- * @dev Transfers `tokenId` from its current owner to `to`, or alternatively mints (or burns) if the current owner
266
- * (or `to`) is the zero address. Returns the owner of the `tokenId` before the update.
267
- *
268
- * The `auth` argument is optional. If the value passed is non 0, then this function will check that
269
- * `auth` is either the owner of the token, or approved to operate on the token (by the owner).
270
- *
271
- * Emits a {Transfer} event.
272
- *
273
- * NOTE: If overriding this function in a way that tracks balances, see also {_increaseBalance}.
274
- */
275
- function _update(address to, uint256 tokenId, address auth) internal virtual returns (address) {
276
- ResourceId balanceTableId = _balancesTableId(_namespace());
277
- address from = _ownerOf(tokenId);
278
-
279
- // Perform (optional) operator check
280
- if (auth != address(0)) {
281
- _checkAuthorized(from, auth, tokenId);
282
- }
283
-
284
- // Execute the update
285
- if (from != address(0)) {
286
- // Clear approval. No need to re-authorize or emit the Approval event
287
- _approve(address(0), tokenId, address(0), false);
288
-
289
- unchecked {
290
- Balances.set(balanceTableId, from, Balances.get(balanceTableId, from) - 1);
291
- }
292
- }
293
-
294
- if (to != address(0)) {
295
- unchecked {
296
- Balances.set(balanceTableId, to, Balances.get(balanceTableId, to) + 1);
297
- }
298
- }
299
-
300
- Owners.set(_ownersTableId(_namespace()), tokenId, to);
301
-
302
- // Emit Transfer event on puppet
303
- puppet().log(Transfer.selector, toTopic(from), toTopic(to), toTopic(tokenId), new bytes(0));
304
-
305
- return from;
306
- }
307
-
308
- /**
309
- * @dev Mints `tokenId` and transfers it to `to`.
310
- *
311
- * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
312
- *
313
- * Requirements:
314
- *
315
- * - `tokenId` must not exist.
316
- * - `to` cannot be the zero address.
317
- *
318
- * Emits a {Transfer} event.
319
- */
320
- function _mint(address to, uint256 tokenId) internal {
321
- if (to == address(0)) {
322
- revert ERC721InvalidReceiver(address(0));
323
- }
324
- address previousOwner = _update(to, tokenId, address(0));
325
- if (previousOwner != address(0)) {
326
- revert ERC721InvalidSender(address(0));
327
- }
328
- }
329
-
330
- /**
331
- * @dev Mints `tokenId`, transfers it to `to` and checks for `to` acceptance.
332
- *
333
- * Requirements:
334
- *
335
- * - `tokenId` must not exist.
336
- * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
337
- *
338
- * Emits a {Transfer} event.
339
- */
340
- function _safeMint(address to, uint256 tokenId) internal {
341
- _safeMint(to, tokenId, "");
342
- }
343
-
344
- /**
345
- * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
346
- * forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
347
- */
348
- function _safeMint(address to, uint256 tokenId, bytes memory data) internal virtual {
349
- _mint(to, tokenId);
350
- _checkOnERC721Received(address(0), to, tokenId, data);
351
- }
352
-
353
- /**
354
- * @dev Destroys `tokenId`.
355
- * The approval is cleared when the token is burned.
356
- * This is an internal function that does not check if the sender is authorized to operate on the token.
357
- *
358
- * Requirements:
359
- *
360
- * - `tokenId` must exist.
361
- *
362
- * Emits a {Transfer} event.
363
- */
364
- function _burn(uint256 tokenId) internal {
365
- address previousOwner = _update(address(0), tokenId, address(0));
366
- if (previousOwner == address(0)) {
367
- revert ERC721NonexistentToken(tokenId);
368
- }
369
- }
370
-
371
- /**
372
- * @dev Transfers `tokenId` from `from` to `to`.
373
- * As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
374
- *
375
- * Requirements:
376
- *
377
- * - `to` cannot be the zero address.
378
- * - `tokenId` token must be owned by `from`.
379
- *
380
- * Emits a {Transfer} event.
381
- */
382
- function _transfer(address from, address to, uint256 tokenId) internal {
383
- if (to == address(0)) {
384
- revert ERC721InvalidReceiver(address(0));
385
- }
386
- address previousOwner = _update(to, tokenId, address(0));
387
- if (previousOwner == address(0)) {
388
- revert ERC721NonexistentToken(tokenId);
389
- } else if (previousOwner != from) {
390
- revert ERC721IncorrectOwner(from, tokenId, previousOwner);
391
- }
392
- }
393
-
394
- /**
395
- * @dev Safely transfers `tokenId` token from `from` to `to`, checking that contract recipients
396
- * are aware of the ERC721 standard to prevent tokens from being forever locked.
397
- *
398
- * `data` is additional data, it has no specified format and it is sent in call to `to`.
399
- *
400
- * This internal function is like {safeTransferFrom} in the sense that it invokes
401
- * {IERC721Receiver-onERC721Received} on the receiver, and can be used to e.g.
402
- * implement alternative mechanisms to perform token transfer, such as signature-based.
403
- *
404
- * Requirements:
405
- *
406
- * - `tokenId` token must exist and be owned by `from`.
407
- * - `to` cannot be the zero address.
408
- * - `from` cannot be the zero address.
409
- * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
410
- *
411
- * Emits a {Transfer} event.
412
- */
413
- function _safeTransfer(address from, address to, uint256 tokenId) internal {
414
- _safeTransfer(from, to, tokenId, "");
415
- }
416
-
417
- /**
418
- * @dev Same as {xref-ERC721-_safeTransfer-address-address-uint256-}[`_safeTransfer`], with an additional `data` parameter which is
419
- * forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
420
- */
421
- function _safeTransfer(address from, address to, uint256 tokenId, bytes memory data) internal virtual {
422
- _transfer(from, to, tokenId);
423
- _checkOnERC721Received(from, to, tokenId, data);
424
- }
425
-
426
- /**
427
- * @dev Approve `to` to operate on `tokenId`
428
- *
429
- * The `auth` argument is optional. If the value passed is non 0, then this function will check that `auth` is
430
- * either the owner of the token, or approved to operate on all tokens held by this owner.
431
- *
432
- * Emits an {Approval} event.
433
- *
434
- * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
435
- */
436
- function _approve(address to, uint256 tokenId, address auth) internal {
437
- _approve(to, tokenId, auth, true);
438
- }
439
-
440
- /**
441
- * @dev Variant of `_approve` with an optional flag to enable or disable the {Approval} event. The event is not
442
- * emitted in the context of transfers.
443
- */
444
- function _approve(address to, uint256 tokenId, address auth, bool emitEvent) internal virtual {
445
- // Avoid reading the owner unless necessary
446
- if (emitEvent || auth != address(0)) {
447
- address owner = _requireOwned(tokenId);
448
-
449
- // We do not use _isAuthorized because single-token approvals should not be able to call approve
450
- if (auth != address(0) && owner != auth && !isApprovedForAll(owner, auth)) {
451
- revert ERC721InvalidApprover(auth);
452
- }
453
-
454
- if (emitEvent) {
455
- // Emit Approval event on puppet
456
- puppet().log(Approval.selector, toTopic(owner), toTopic(to), toTopic(tokenId), new bytes(0));
457
- }
458
- }
459
-
460
- TokenApproval.set(_tokenApprovalTableId(_namespace()), tokenId, to);
461
- }
462
-
463
- /**
464
- * @dev Approve `operator` to operate on all of `owner` tokens
465
- *
466
- * Requirements:
467
- * - operator can't be the address zero.
468
- *
469
- * Emits an {ApprovalForAll} event.
470
- */
471
- function _setApprovalForAll(address owner, address operator, bool approved) internal virtual {
472
- if (operator == address(0)) {
473
- revert ERC721InvalidOperator(operator);
474
- }
475
- OperatorApproval.set(_operatorApprovalTableId(_namespace()), owner, operator, approved);
476
-
477
- // Emit ApprovalForAll event on puppet
478
- puppet().log(ApprovalForAll.selector, toTopic(owner), toTopic(operator), abi.encode(approved));
479
- }
480
-
481
- /**
482
- * @dev Reverts if the `tokenId` doesn't have a current owner (it hasn't been minted, or it has been burned).
483
- * Returns the owner.
484
- *
485
- * Overrides to ownership logic should be done to {_ownerOf}.
486
- */
487
- function _requireOwned(uint256 tokenId) internal view returns (address) {
488
- address owner = _ownerOf(tokenId);
489
- if (owner == address(0)) {
490
- revert ERC721NonexistentToken(tokenId);
491
- }
492
- return owner;
493
- }
494
-
495
- /**
496
- * @dev Private function to invoke {IERC721Receiver-onERC721Received} on a target address. This will revert if the
497
- * recipient doesn't accept the token transfer. The call is not executed if the target address is not a contract.
498
- *
499
- * @param from address representing the previous owner of the given token ID
500
- * @param to target address that will receive the tokens
501
- * @param tokenId uint256 ID of the token to be transferred
502
- * @param data bytes optional data to send along with the call
503
- */
504
- function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory data) private {
505
- if (to.code.length > 0) {
506
- try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, data) returns (bytes4 retval) {
507
- if (retval != IERC721Receiver.onERC721Received.selector) {
508
- revert ERC721InvalidReceiver(to);
509
- }
510
- } catch (bytes memory reason) {
511
- if (reason.length == 0) {
512
- revert ERC721InvalidReceiver(to);
513
- } else {
514
- /// @solidity memory-safe-assembly
515
- assembly {
516
- revert(add(32, reason), mload(reason))
517
- }
518
- }
519
- }
520
- }
521
- }
522
-
523
- function _namespace() internal view returns (bytes14 namespace) {
524
- ResourceId systemId = SystemRegistry.get(address(this));
525
- return systemId.getNamespace();
526
- }
527
-
528
- function _requireOwner() internal view {
529
- AccessControlLib.requireOwner(SystemRegistry.get(address(this)), _msgSender());
530
- }
531
- }
@@ -1,120 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721.sol)
3
- pragma solidity >=0.8.24;
4
-
5
- import { IERC721Events } from "./IERC721Events.sol";
6
- import { IERC721Errors } from "./IERC721Errors.sol";
7
-
8
- /**
9
- * @dev Required interface of an ERC721 compliant contract.
10
- */
11
- interface IERC721 is IERC721Events, IERC721Errors {
12
- /**
13
- * @dev Returns the number of tokens in ``owner``'s account.
14
- */
15
- function balanceOf(address owner) external view returns (uint256 balance);
16
-
17
- /**
18
- * @dev Returns the owner of the `tokenId` token.
19
- *
20
- * Requirements:
21
- *
22
- * - `tokenId` must exist.
23
- */
24
- function ownerOf(uint256 tokenId) external view returns (address owner);
25
-
26
- /**
27
- * @dev Safely transfers `tokenId` token from `from` to `to`.
28
- *
29
- * Requirements:
30
- *
31
- * - `from` cannot be the zero address.
32
- * - `to` cannot be the zero address.
33
- * - `tokenId` token must exist and be owned by `from`.
34
- * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
35
- * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
36
- * a safe transfer.
37
- *
38
- * Emits a {Transfer} event.
39
- */
40
- function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
41
-
42
- /**
43
- * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
44
- * are aware of the ERC721 protocol to prevent tokens from being forever locked.
45
- *
46
- * Requirements:
47
- *
48
- * - `from` cannot be the zero address.
49
- * - `to` cannot be the zero address.
50
- * - `tokenId` token must exist and be owned by `from`.
51
- * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or
52
- * {setApprovalForAll}.
53
- * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
54
- * a safe transfer.
55
- *
56
- * Emits a {Transfer} event.
57
- */
58
- function safeTransferFrom(address from, address to, uint256 tokenId) external;
59
-
60
- /**
61
- * @dev Transfers `tokenId` token from `from` to `to`.
62
- *
63
- * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
64
- * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
65
- * understand this adds an external call which potentially creates a reentrancy vulnerability.
66
- *
67
- * Requirements:
68
- *
69
- * - `from` cannot be the zero address.
70
- * - `to` cannot be the zero address.
71
- * - `tokenId` token must be owned by `from`.
72
- * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
73
- *
74
- * Emits a {Transfer} event.
75
- */
76
- function transferFrom(address from, address to, uint256 tokenId) external;
77
-
78
- /**
79
- * @dev Gives permission to `to` to transfer `tokenId` token to another account.
80
- * The approval is cleared when the token is transferred.
81
- *
82
- * Only a single account can be approved at a time, so approving the zero address clears previous approvals.
83
- *
84
- * Requirements:
85
- *
86
- * - The caller must own the token or be an approved operator.
87
- * - `tokenId` must exist.
88
- *
89
- * Emits an {Approval} event.
90
- */
91
- function approve(address to, uint256 tokenId) external;
92
-
93
- /**
94
- * @dev Approve or remove `operator` as an operator for the caller.
95
- * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
96
- *
97
- * Requirements:
98
- *
99
- * - The `operator` cannot be the address zero.
100
- *
101
- * Emits an {ApprovalForAll} event.
102
- */
103
- function setApprovalForAll(address operator, bool approved) external;
104
-
105
- /**
106
- * @dev Returns the account approved for `tokenId` token.
107
- *
108
- * Requirements:
109
- *
110
- * - `tokenId` must exist.
111
- */
112
- function getApproved(uint256 tokenId) external view returns (address operator);
113
-
114
- /**
115
- * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
116
- *
117
- * See {setApprovalForAll}
118
- */
119
- function isApprovedForAll(address owner, address operator) external view returns (bool);
120
- }