@lukso/lsp8-contracts 0.15.0-rc.5 → 0.16.2

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 (50) hide show
  1. package/README.md +15 -1
  2. package/artifacts/ILSP8IdentifiableDigitalAsset.json +0 -112
  3. package/artifacts/LSP8Burnable.json +0 -11
  4. package/artifacts/LSP8BurnableInitAbstract.json +0 -16
  5. package/artifacts/LSP8CappedSupply.json +0 -11
  6. package/artifacts/LSP8CappedSupplyInitAbstract.json +0 -16
  7. package/artifacts/LSP8Enumerable.json +0 -11
  8. package/artifacts/LSP8EnumerableInitAbstract.json +0 -16
  9. package/artifacts/LSP8IdentifiableDigitalAsset.json +0 -11
  10. package/artifacts/LSP8IdentifiableDigitalAssetInitAbstract.json +0 -16
  11. package/artifacts/LSP8Mintable.json +2 -13
  12. package/artifacts/LSP8MintableInit.json +2 -13
  13. package/artifacts/LSP8Votes.json +1230 -0
  14. package/artifacts/LSP8VotesInitAbstract.json +1222 -0
  15. package/compatibility-abis/LSP8IdentifiableDigitalAsset-v0.12.0.json +739 -748
  16. package/compatibility-abis/LSP8IdentifiableDigitalAsset-v0.13.0.json +890 -899
  17. package/compatibility-abis/LSP8IdentifiableDigitalAsset-v0.14.0.json +890 -899
  18. package/compatibility-abis/LSP8IdentifiableDigitalAsset.json +927 -0
  19. package/compatibility-abis/README.md +34 -0
  20. package/contracts/ILSP8IdentifiableDigitalAsset.sol +2 -8
  21. package/contracts/LSP8Constants.sol +4 -0
  22. package/contracts/LSP8IdentifiableDigitalAsset.sol +796 -36
  23. package/contracts/LSP8IdentifiableDigitalAssetInitAbstract.sol +806 -36
  24. package/contracts/extensions/LSP8CappedSupply.sol +1 -1
  25. package/contracts/extensions/LSP8CappedSupplyInitAbstract.sol +1 -1
  26. package/contracts/extensions/LSP8Enumerable.sol +6 -5
  27. package/contracts/extensions/LSP8EnumerableInitAbstract.sol +5 -5
  28. package/contracts/extensions/LSP8Votes.sol +94 -0
  29. package/contracts/extensions/LSP8VotesConstants.sol +8 -0
  30. package/contracts/extensions/LSP8VotesInitAbstract.sol +116 -0
  31. package/dist/index.cjs +10 -1
  32. package/dist/index.d.cts +23 -17
  33. package/dist/index.d.mts +23 -17
  34. package/dist/index.d.ts +23 -17
  35. package/dist/index.mjs +10 -2
  36. package/package.json +7 -8
  37. package/types/index.ts +3958 -1854
  38. package/contracts/LSP8IdentifiableDigitalAssetCore.sol +0 -806
  39. package/types/common.ts +0 -131
  40. package/types/contracts/ILSP8IdentifiableDigitalAsset.ts +0 -706
  41. package/types/contracts/LSP8IdentifiableDigitalAsset.ts +0 -778
  42. package/types/contracts/LSP8IdentifiableDigitalAssetInitAbstract.ts +0 -813
  43. package/types/contracts/extensions/LSP8Burnable.ts +0 -797
  44. package/types/contracts/extensions/LSP8BurnableInitAbstract.ts +0 -829
  45. package/types/contracts/extensions/LSP8CappedSupply.ts +0 -792
  46. package/types/contracts/extensions/LSP8CappedSupplyInitAbstract.ts +0 -824
  47. package/types/contracts/extensions/LSP8Enumerable.ts +0 -790
  48. package/types/contracts/extensions/LSP8EnumerableInitAbstract.ts +0 -821
  49. package/types/contracts/presets/LSP8Mintable.ts +0 -797
  50. package/types/contracts/presets/LSP8MintableInit.ts +0 -860
@@ -1,806 +0,0 @@
1
- // SPDX-License-Identifier: Apache-2.0
2
- pragma solidity ^0.8.12;
3
-
4
- // interfaces
5
- import {
6
- ILSP1UniversalReceiver as ILSP1
7
- } from "@lukso/lsp1-contracts/contracts/ILSP1UniversalReceiver.sol";
8
- import {
9
- ILSP8IdentifiableDigitalAsset
10
- } from "./ILSP8IdentifiableDigitalAsset.sol";
11
-
12
- // modules
13
-
14
- import {
15
- LSP4DigitalAssetMetadataCore
16
- } from "@lukso/lsp4-contracts/contracts/LSP4DigitalAssetMetadataCore.sol";
17
-
18
- // libraries
19
- import {
20
- EnumerableSet
21
- } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
22
- import {
23
- ERC165Checker
24
- } from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
25
- import {LSP1Utils} from "@lukso/lsp1-contracts/contracts/LSP1Utils.sol";
26
-
27
- // errors
28
- import {
29
- LSP8NonExistentTokenId,
30
- LSP8NotTokenOwner,
31
- LSP8CannotUseAddressZeroAsOperator,
32
- LSP8TokenOwnerCannotBeOperator,
33
- LSP8OperatorAlreadyAuthorized,
34
- LSP8NotTokenOperator,
35
- LSP8InvalidTransferBatch,
36
- LSP8NonExistingOperator,
37
- LSP8CannotSendToAddressZero,
38
- LSP8TokenIdAlreadyMinted,
39
- LSP8NotifyTokenReceiverContractMissingLSP1Interface,
40
- LSP8NotifyTokenReceiverIsEOA,
41
- LSP8TokenIdsDataLengthMismatch,
42
- LSP8TokenIdsDataEmptyArray,
43
- LSP8BatchCallFailed,
44
- LSP8TokenOwnerChanged,
45
- LSP8RevokeOperatorNotAuthorized
46
- } from "./LSP8Errors.sol";
47
-
48
- // constants
49
- import {
50
- _INTERFACEID_LSP1
51
- } from "@lukso/lsp1-contracts/contracts/LSP1Constants.sol";
52
- import {
53
- _TYPEID_LSP8_TOKENOPERATOR,
54
- _TYPEID_LSP8_TOKENSSENDER,
55
- _TYPEID_LSP8_TOKENSRECIPIENT
56
- } from "./LSP8Constants.sol";
57
-
58
- /**
59
- * @title LSP8IdentifiableDigitalAsset contract
60
- * @author Matthew Stevens
61
- * @dev Core Implementation of a LSP8 compliant contract.
62
- */
63
- abstract contract LSP8IdentifiableDigitalAssetCore is
64
- LSP4DigitalAssetMetadataCore,
65
- ILSP8IdentifiableDigitalAsset
66
- {
67
- using EnumerableSet for EnumerableSet.AddressSet;
68
- using EnumerableSet for EnumerableSet.Bytes32Set;
69
-
70
- // --- Storage
71
-
72
- uint256 internal _existingTokens;
73
-
74
- // Mapping from `tokenId` to `tokenOwner`
75
- mapping(bytes32 => address) internal _tokenOwners;
76
-
77
- // Mapping `tokenOwner` to owned tokenIds
78
- mapping(address => EnumerableSet.Bytes32Set) internal _ownedTokens;
79
-
80
- // Mapping a `tokenId` to its authorized operator addresses.
81
- mapping(bytes32 => EnumerableSet.AddressSet) internal _operators;
82
-
83
- // --- Token queries
84
-
85
- /**
86
- * @inheritdoc ILSP8IdentifiableDigitalAsset
87
- */
88
- function totalSupply() public view virtual override returns (uint256) {
89
- return _existingTokens;
90
- }
91
-
92
- // --- Token owner queries
93
-
94
- /**
95
- * @inheritdoc ILSP8IdentifiableDigitalAsset
96
- */
97
- function balanceOf(
98
- address tokenOwner
99
- ) public view virtual override returns (uint256) {
100
- return _ownedTokens[tokenOwner].length();
101
- }
102
-
103
- /**
104
- * @inheritdoc ILSP8IdentifiableDigitalAsset
105
- */
106
- function tokenOwnerOf(
107
- bytes32 tokenId
108
- ) public view virtual override returns (address) {
109
- address tokenOwner = _tokenOwners[tokenId];
110
-
111
- if (tokenOwner == address(0)) {
112
- revert LSP8NonExistentTokenId(tokenId);
113
- }
114
-
115
- return tokenOwner;
116
- }
117
-
118
- /**
119
- * @inheritdoc ILSP8IdentifiableDigitalAsset
120
- */
121
- function tokenIdsOf(
122
- address tokenOwner
123
- ) public view virtual override returns (bytes32[] memory) {
124
- return _ownedTokens[tokenOwner].values();
125
- }
126
-
127
- // --- TokenId Metadata functionality
128
-
129
- /**
130
- * @inheritdoc ILSP8IdentifiableDigitalAsset
131
- */
132
- function getDataForTokenId(
133
- bytes32 tokenId,
134
- bytes32 dataKey
135
- ) public view virtual override returns (bytes memory dataValue) {
136
- return _getDataForTokenId(tokenId, dataKey);
137
- }
138
-
139
- /**
140
- * @inheritdoc ILSP8IdentifiableDigitalAsset
141
- */
142
- function getDataBatchForTokenIds(
143
- bytes32[] memory tokenIds,
144
- bytes32[] memory dataKeys
145
- ) public view virtual override returns (bytes[] memory dataValues) {
146
- if (tokenIds.length != dataKeys.length) {
147
- revert LSP8TokenIdsDataLengthMismatch();
148
- }
149
-
150
- dataValues = new bytes[](tokenIds.length);
151
-
152
- for (uint256 i; i < tokenIds.length; ) {
153
- dataValues[i] = _getDataForTokenId(tokenIds[i], dataKeys[i]);
154
-
155
- // Increment the iterator in unchecked block to save gas
156
- unchecked {
157
- ++i;
158
- }
159
- }
160
-
161
- return dataValues;
162
- }
163
-
164
- /**
165
- * @inheritdoc ILSP8IdentifiableDigitalAsset
166
- */
167
- function setDataForTokenId(
168
- bytes32 tokenId,
169
- bytes32 dataKey,
170
- bytes memory dataValue
171
- ) public virtual override onlyOwner {
172
- _setDataForTokenId(tokenId, dataKey, dataValue);
173
- }
174
-
175
- /**
176
- * @inheritdoc ILSP8IdentifiableDigitalAsset
177
- */
178
- function setDataBatchForTokenIds(
179
- bytes32[] memory tokenIds,
180
- bytes32[] memory dataKeys,
181
- bytes[] memory dataValues
182
- ) public virtual override onlyOwner {
183
- if (
184
- tokenIds.length != dataKeys.length ||
185
- dataKeys.length != dataValues.length
186
- ) {
187
- revert LSP8TokenIdsDataLengthMismatch();
188
- }
189
-
190
- if (tokenIds.length == 0) {
191
- revert LSP8TokenIdsDataEmptyArray();
192
- }
193
-
194
- for (uint256 i; i < tokenIds.length; ) {
195
- _setDataForTokenId(tokenIds[i], dataKeys[i], dataValues[i]);
196
-
197
- // Increment the iterator in unchecked block to save gas
198
- unchecked {
199
- ++i;
200
- }
201
- }
202
- }
203
-
204
- // --- General functionality
205
-
206
- /**
207
- * @inheritdoc ILSP8IdentifiableDigitalAsset
208
- *
209
- * @custom:info It's not possible to send value along the functions call due to the use of `delegatecall`.
210
- */
211
- function batchCalls(
212
- bytes[] calldata data
213
- ) public virtual override returns (bytes[] memory results) {
214
- results = new bytes[](data.length);
215
- for (uint256 i; i < data.length; ) {
216
- (bool success, bytes memory result) = address(this).delegatecall(
217
- data[i]
218
- );
219
-
220
- if (!success) {
221
- // Look for revert reason and bubble it up if present
222
- if (result.length != 0) {
223
- // The easiest way to bubble the revert reason is using memory via assembly
224
- // solhint-disable no-inline-assembly
225
- /// @solidity memory-safe-assembly
226
- assembly {
227
- let returndata_size := mload(result)
228
- revert(add(32, result), returndata_size)
229
- }
230
- } else {
231
- revert LSP8BatchCallFailed({callIndex: i});
232
- }
233
- }
234
-
235
- results[i] = result;
236
-
237
- unchecked {
238
- ++i;
239
- }
240
- }
241
- }
242
-
243
- // --- Operator functionality
244
-
245
- /**
246
- * @inheritdoc ILSP8IdentifiableDigitalAsset
247
- */
248
- function authorizeOperator(
249
- address operator,
250
- bytes32 tokenId,
251
- bytes memory operatorNotificationData
252
- ) public virtual override {
253
- address tokenOwner = tokenOwnerOf(tokenId);
254
-
255
- if (tokenOwner != msg.sender) {
256
- revert LSP8NotTokenOwner(tokenOwner, tokenId, msg.sender);
257
- }
258
-
259
- if (operator == address(0)) {
260
- revert LSP8CannotUseAddressZeroAsOperator();
261
- }
262
-
263
- if (tokenOwner == operator) {
264
- revert LSP8TokenOwnerCannotBeOperator();
265
- }
266
-
267
- bool isAdded = _operators[tokenId].add(operator);
268
- if (!isAdded) revert LSP8OperatorAlreadyAuthorized(operator, tokenId);
269
-
270
- emit OperatorAuthorizationChanged(
271
- operator,
272
- tokenOwner,
273
- tokenId,
274
- operatorNotificationData
275
- );
276
-
277
- bytes memory lsp1Data = abi.encode(
278
- msg.sender,
279
- tokenId,
280
- true, // authorized
281
- operatorNotificationData
282
- );
283
-
284
- _notifyTokenOperator(operator, lsp1Data);
285
- }
286
-
287
- /**
288
- * @inheritdoc ILSP8IdentifiableDigitalAsset
289
- */
290
- function revokeOperator(
291
- address operator,
292
- bytes32 tokenId,
293
- bool notify,
294
- bytes memory operatorNotificationData
295
- ) public virtual override {
296
- address tokenOwner = tokenOwnerOf(tokenId);
297
-
298
- if (msg.sender != tokenOwner) {
299
- if (operator != msg.sender) {
300
- revert LSP8RevokeOperatorNotAuthorized(
301
- msg.sender,
302
- tokenOwner,
303
- tokenId
304
- );
305
- }
306
- }
307
-
308
- if (operator == address(0)) {
309
- revert LSP8CannotUseAddressZeroAsOperator();
310
- }
311
-
312
- if (tokenOwner == operator) {
313
- revert LSP8TokenOwnerCannotBeOperator();
314
- }
315
-
316
- _revokeOperator(
317
- operator,
318
- tokenOwner,
319
- tokenId,
320
- notify,
321
- operatorNotificationData
322
- );
323
-
324
- if (notify) {
325
- bytes memory lsp1Data = abi.encode(
326
- tokenOwner,
327
- tokenId,
328
- false, // unauthorized
329
- operatorNotificationData
330
- );
331
-
332
- _notifyTokenOperator(operator, lsp1Data);
333
- }
334
- }
335
-
336
- /**
337
- * @inheritdoc ILSP8IdentifiableDigitalAsset
338
- */
339
- function isOperatorFor(
340
- address operator,
341
- bytes32 tokenId
342
- ) public view virtual override returns (bool) {
343
- return _isOperatorOrOwner(operator, tokenId);
344
- }
345
-
346
- /**
347
- * @inheritdoc ILSP8IdentifiableDigitalAsset
348
- */
349
- function getOperatorsOf(
350
- bytes32 tokenId
351
- ) public view virtual override returns (address[] memory) {
352
- _existsOrError(tokenId);
353
-
354
- return _operators[tokenId].values();
355
- }
356
-
357
- /**
358
- * @dev verifies if the `caller` is operator or owner for the `tokenId`
359
- * @return true if `caller` is either operator or owner
360
- */
361
- function _isOperatorOrOwner(
362
- address caller,
363
- bytes32 tokenId
364
- ) internal view virtual returns (bool) {
365
- return (caller == tokenOwnerOf(tokenId) ||
366
- _operators[tokenId].contains(caller));
367
- }
368
-
369
- // --- Transfer functionality
370
-
371
- /**
372
- * @inheritdoc ILSP8IdentifiableDigitalAsset
373
- */
374
- function transfer(
375
- address from,
376
- address to,
377
- bytes32 tokenId,
378
- bool force,
379
- bytes memory data
380
- ) public virtual override {
381
- if (!_isOperatorOrOwner(msg.sender, tokenId)) {
382
- revert LSP8NotTokenOperator(tokenId, msg.sender);
383
- }
384
-
385
- _transfer(from, to, tokenId, force, data);
386
- }
387
-
388
- /**
389
- * @inheritdoc ILSP8IdentifiableDigitalAsset
390
- */
391
- function transferBatch(
392
- address[] memory from,
393
- address[] memory to,
394
- bytes32[] memory tokenId,
395
- bool[] memory force,
396
- bytes[] memory data
397
- ) public virtual override {
398
- uint256 fromLength = from.length;
399
- if (
400
- fromLength != to.length ||
401
- fromLength != tokenId.length ||
402
- fromLength != force.length ||
403
- fromLength != data.length
404
- ) {
405
- revert LSP8InvalidTransferBatch();
406
- }
407
-
408
- for (uint256 i; i < fromLength; ) {
409
- transfer(from[i], to[i], tokenId[i], force[i], data[i]);
410
-
411
- unchecked {
412
- ++i;
413
- }
414
- }
415
- }
416
-
417
- /**
418
- * @dev removes `operator` from the list of operators for the `tokenId`
419
- */
420
- function _revokeOperator(
421
- address operator,
422
- address tokenOwner,
423
- bytes32 tokenId,
424
- bool notified,
425
- bytes memory operatorNotificationData
426
- ) internal virtual {
427
- bool isRemoved = _operators[tokenId].remove(operator);
428
- if (!isRemoved) revert LSP8NonExistingOperator(operator, tokenId);
429
-
430
- emit OperatorRevoked(
431
- operator,
432
- tokenOwner,
433
- tokenId,
434
- notified,
435
- operatorNotificationData
436
- );
437
- }
438
-
439
- /**
440
- * @dev revoke all the current operators for a specific `tokenId` token which belongs to `tokenOwner`.
441
- *
442
- * @param tokenOwner The address that is the owner of the `tokenId`.
443
- * @param tokenId The token to remove the associated operators for.
444
- */
445
- function _clearOperators(
446
- address tokenOwner,
447
- bytes32 tokenId
448
- ) internal virtual {
449
- // here is a good example of why having multiple operators will be expensive.. we
450
- // need to clear them on token transfer
451
- //
452
- // NOTE: this may cause a tx to fail if there is too many operators to clear, in which case
453
- // the tokenOwner needs to call `revokeOperator` until there is less operators to clear and
454
- // the desired `transfer` or `burn` call can succeed.
455
- EnumerableSet.AddressSet storage operatorsForTokenId = _operators[
456
- tokenId
457
- ];
458
-
459
- uint256 operatorListLength = operatorsForTokenId.length();
460
- address operator;
461
- for (uint256 i; i < operatorListLength; ) {
462
- // we are emptying the list, always remove from index 0
463
- operator = operatorsForTokenId.at(0);
464
- _revokeOperator(operator, tokenOwner, tokenId, false, "");
465
-
466
- unchecked {
467
- ++i;
468
- }
469
- }
470
- }
471
-
472
- /**
473
- * @dev Returns whether `tokenId` exists.
474
- *
475
- * Tokens start existing when they are minted ({_mint}), and stop existing when they are burned ({_burn}).
476
- */
477
- function _exists(bytes32 tokenId) internal view virtual returns (bool) {
478
- return _tokenOwners[tokenId] != address(0);
479
- }
480
-
481
- /**
482
- * @dev When `tokenId` does not exist then revert with an error.
483
- */
484
- function _existsOrError(bytes32 tokenId) internal view virtual {
485
- if (!_exists(tokenId)) {
486
- revert LSP8NonExistentTokenId(tokenId);
487
- }
488
- }
489
-
490
- /**
491
- * @dev Create `tokenId` by minting it and transfers it to `to`.
492
- *
493
- * @custom:info Any logic in the:
494
- * - {_beforeTokenTransfer} function will run before updating the balances and ownership of `tokenId`s.
495
- * - {_afterTokenTransfer} function will run after updating the balances and ownership of `tokenId`s, **but before notifying the recipient via LSP1**.
496
- *
497
- * @param to The address that will receive the minted `tokenId`.
498
- * @param tokenId The token ID to create (= mint).
499
- * @param force When set to `true`, `to` may be any address. When set to `false`, `to` must be a contract that supports the LSP1 standard.
500
- * @param data Any additional data the caller wants included in the emitted event, and sent in the hook of the `to` address.
501
- *
502
- * @custom:requirements
503
- * - `tokenId` must not exist and not have been already minted.
504
- * - `to` cannot be the zero address.
505
-
506
- * @custom:events {Transfer} event with `address(0)` as `from` address.
507
- */
508
- function _mint(
509
- address to,
510
- bytes32 tokenId,
511
- bool force,
512
- bytes memory data
513
- ) internal virtual {
514
- if (to == address(0)) {
515
- revert LSP8CannotSendToAddressZero();
516
- }
517
-
518
- // Check that `tokenId` is not already minted
519
- if (_exists(tokenId)) {
520
- revert LSP8TokenIdAlreadyMinted(tokenId);
521
- }
522
-
523
- _beforeTokenTransfer(address(0), to, tokenId, data);
524
-
525
- // Check that `tokenId` was not minted inside the `_beforeTokenTransfer` hook
526
- if (_exists(tokenId)) {
527
- revert LSP8TokenIdAlreadyMinted(tokenId);
528
- }
529
-
530
- // token being minted
531
- ++_existingTokens;
532
-
533
- _ownedTokens[to].add(tokenId);
534
- _tokenOwners[tokenId] = to;
535
-
536
- emit Transfer(msg.sender, address(0), to, tokenId, force, data);
537
-
538
- _afterTokenTransfer(address(0), to, tokenId, data);
539
-
540
- bytes memory lsp1Data = abi.encode(
541
- msg.sender,
542
- address(0),
543
- to,
544
- tokenId,
545
- data
546
- );
547
- _notifyTokenReceiver(to, force, lsp1Data);
548
- }
549
-
550
- /**
551
- * @dev Burn a specific `tokenId`, removing the `tokenId` from the {tokenIdsOf} the caller and decreasing its {balanceOf} by -1.
552
- * This will also clear all the operators allowed to transfer the `tokenId`.
553
- *
554
- * The owner of the `tokenId` will be notified about the `tokenId` being transferred through its LSP1 {universalReceiver}
555
- * function, if it is a contract that supports the LSP1 interface. Its {universalReceiver} function will receive
556
- * all the parameters in the calldata packed encoded.
557
- *
558
- * @custom:info Any logic in the:
559
- * - {_beforeTokenTransfer} function will run before updating the balances and ownership of `tokenId`s.
560
- * - {_afterTokenTransfer} function will run after updating the balances and ownership of `tokenId`s, **but before notifying the sender via LSP1**.
561
- *
562
- * @param tokenId The token to burn.
563
- * @param data Any additional data the caller wants included in the emitted event, and sent in the LSP1 hook on the token owner's address.
564
- *
565
- * @custom:hint In dApps, you can know which addresses are burning tokens by listening for the `Transfer` event and filter with the zero address as `to`.
566
- *
567
- * @custom:requirements
568
- * - `tokenId` must exist.
569
- *
570
- * @custom:events {Transfer} event with `address(0)` as the `to` address.
571
- */
572
- function _burn(bytes32 tokenId, bytes memory data) internal virtual {
573
- address tokenOwner = tokenOwnerOf(tokenId);
574
-
575
- _beforeTokenTransfer(tokenOwner, address(0), tokenId, data);
576
-
577
- // Re-fetch and update `tokenOwner` in case `tokenId`
578
- // was transferred inside the `_beforeTokenTransfer` hook
579
- tokenOwner = tokenOwnerOf(tokenId);
580
-
581
- // token being burned
582
- --_existingTokens;
583
-
584
- _clearOperators(tokenOwner, tokenId);
585
-
586
- _ownedTokens[tokenOwner].remove(tokenId);
587
- delete _tokenOwners[tokenId];
588
-
589
- emit Transfer(msg.sender, tokenOwner, address(0), tokenId, false, data);
590
-
591
- _afterTokenTransfer(tokenOwner, address(0), tokenId, data);
592
-
593
- bytes memory lsp1Data = abi.encode(
594
- msg.sender,
595
- tokenOwner,
596
- address(0),
597
- tokenId,
598
- data
599
- );
600
-
601
- _notifyTokenSender(tokenOwner, lsp1Data);
602
- }
603
-
604
- /**
605
- * @dev Change the owner of the `tokenId` from `from` to `to`.
606
- *
607
- * Both the sender and recipient will be notified of the `tokenId` being transferred through their LSP1 {universalReceiver}
608
- * function, if they are contracts that support the LSP1 interface. Their `universalReceiver` function will receive
609
- * all the parameters in the calldata packed encoded.
610
- *
611
- * @custom:info Any logic in the:
612
- * - {_beforeTokenTransfer} function will run before updating the balances and ownership of `tokenId`s.
613
- * - {_afterTokenTransfer} function will run after updating the balances and ownership of `tokenId`s, **but before notifying the sender/recipient via LSP1**.
614
- *
615
- * @param from The sender address.
616
- * @param to The recipient address.
617
- * @param tokenId The token to transfer.
618
- * @param force When set to `true`, `to` may be any address. When set to `false`, `to` must be a contract that supports the LSP1 standard.
619
- * @param data Additional data the caller wants included in the emitted event, and sent in the hooks to `from` and `to` addresses.
620
- *
621
- * @custom:requirements
622
- * - `to` cannot be the zero address.
623
- * - `tokenId` token must be owned by `from`.
624
- *
625
- * @custom:events {Transfer} event.
626
- *
627
- * @custom:danger This internal function does not check if the sender is authorized or not to operate on the `tokenId`.
628
- */
629
- function _transfer(
630
- address from,
631
- address to,
632
- bytes32 tokenId,
633
- bool force,
634
- bytes memory data
635
- ) internal virtual {
636
- address tokenOwner = tokenOwnerOf(tokenId);
637
- if (tokenOwner != from) {
638
- revert LSP8NotTokenOwner(tokenOwner, tokenId, from);
639
- }
640
-
641
- if (to == address(0)) {
642
- revert LSP8CannotSendToAddressZero();
643
- }
644
-
645
- _beforeTokenTransfer(from, to, tokenId, data);
646
-
647
- // Check that `tokenId`'s owner was not changed inside the `_beforeTokenTransfer` hook
648
- address currentTokenOwner = tokenOwnerOf(tokenId);
649
- if (tokenOwner != currentTokenOwner) {
650
- revert LSP8TokenOwnerChanged(
651
- tokenId,
652
- tokenOwner,
653
- currentTokenOwner
654
- );
655
- }
656
-
657
- _clearOperators(from, tokenId);
658
-
659
- _ownedTokens[from].remove(tokenId);
660
- _ownedTokens[to].add(tokenId);
661
- _tokenOwners[tokenId] = to;
662
-
663
- emit Transfer(msg.sender, from, to, tokenId, force, data);
664
-
665
- _afterTokenTransfer(from, to, tokenId, data);
666
-
667
- bytes memory lsp1Data = abi.encode(msg.sender, from, to, tokenId, data);
668
-
669
- _notifyTokenSender(from, lsp1Data);
670
- _notifyTokenReceiver(to, force, lsp1Data);
671
- }
672
-
673
- /**
674
- * @dev Sets data for a specific `tokenId` and `dataKey` in the ERC725Y storage
675
- * The ERC725Y data key is the hash of the `tokenId` and `dataKey` concatenated
676
- * @param tokenId The unique identifier for a token.
677
- * @param dataKey The key for the data to set.
678
- * @param dataValue The value to set for the given data key.
679
- * @custom:events {TokenIdDataChanged} event.
680
- */
681
- function _setDataForTokenId(
682
- bytes32 tokenId,
683
- bytes32 dataKey,
684
- bytes memory dataValue
685
- ) internal virtual {
686
- _store[keccak256(bytes.concat(tokenId, dataKey))] = dataValue;
687
- emit TokenIdDataChanged(tokenId, dataKey, dataValue);
688
- }
689
-
690
- /**
691
- * @dev Retrieves data for a specific `tokenId` and `dataKey` from the ERC725Y storage
692
- * The ERC725Y data key is the hash of the `tokenId` and `dataKey` concatenated
693
- * @param tokenId The unique identifier for a token.
694
- * @param dataKey The key for the data to retrieve.
695
- * @return dataValues The data value associated with the given `tokenId` and `dataKey`.
696
- */
697
- function _getDataForTokenId(
698
- bytes32 tokenId,
699
- bytes32 dataKey
700
- ) internal view virtual returns (bytes memory dataValues) {
701
- return _store[keccak256(bytes.concat(tokenId, dataKey))];
702
- }
703
-
704
- /**
705
- * @dev Hook that is called before any token transfer, including minting and burning.
706
- * Allows to run custom logic before updating balances and notifiying sender/recipient by overriding this function.
707
- *
708
- * @param from The sender address
709
- * @param to The recipient address
710
- * @param tokenId The tokenId to transfer
711
- * @param data The data sent alongside the transfer
712
- */
713
- function _beforeTokenTransfer(
714
- address from,
715
- address to,
716
- bytes32 tokenId,
717
- bytes memory data // solhint-disable-next-line no-empty-blocks
718
- ) internal virtual {}
719
-
720
- /**
721
- * @dev Hook that is called after any token transfer, including minting and burning.
722
- * Allows to run custom logic after updating balances, but **before notifiying sender/recipient via LSP1** by overriding this function.
723
- *
724
- * @param from The sender address
725
- * @param to The recipient address
726
- * @param tokenId The tokenId to transfer
727
- * @param data The data sent alongside the transfer
728
- */
729
- function _afterTokenTransfer(
730
- address from,
731
- address to,
732
- bytes32 tokenId,
733
- bytes memory data // solhint-disable-next-line no-empty-blocks
734
- ) internal virtual {}
735
-
736
- /**
737
- * @dev Attempt to notify the operator `operator` about the `tokenId` being authorized.
738
- * This is done by calling its {universalReceiver} function with the `_TYPEID_LSP8_TOKENOPERATOR` as typeId, if `operator` is a contract that supports the LSP1 interface.
739
- * If `operator` is an EOA or a contract that does not support the LSP1 interface, nothing will happen and no notification will be sent.
740
-
741
- * @param operator The address to call the {universalReceiver} function on.
742
- * @param lsp1Data the data to be sent to the `operator` address in the `universalReceiver` call.
743
- */
744
- function _notifyTokenOperator(
745
- address operator,
746
- bytes memory lsp1Data
747
- ) internal virtual {
748
- LSP1Utils.notifyUniversalReceiver(
749
- operator,
750
- _TYPEID_LSP8_TOKENOPERATOR,
751
- lsp1Data
752
- );
753
- }
754
-
755
- /**
756
- * @dev Attempt to notify the token sender `from` about the `tokenId` being transferred.
757
- * This is done by calling its {universalReceiver} function with the `_TYPEID_LSP8_TOKENSSENDER` as typeId, if `from` is a contract that supports the LSP1 interface.
758
- * If `from` is an EOA or a contract that does not support the LSP1 interface, nothing will happen and no notification will be sent.
759
-
760
- * @param from The address to call the {universalReceiver} function on.
761
- * @param lsp1Data the data to be sent to the `from` address in the `universalReceiver` call.
762
- */
763
- function _notifyTokenSender(
764
- address from,
765
- bytes memory lsp1Data
766
- ) internal virtual {
767
- LSP1Utils.notifyUniversalReceiver(
768
- from,
769
- _TYPEID_LSP8_TOKENSSENDER,
770
- lsp1Data
771
- );
772
- }
773
-
774
- /**
775
- * @dev Attempt to notify the token receiver `to` about the `tokenId` being received.
776
- * This is done by calling its {universalReceiver} function with the `_TYPEID_LSP8_TOKENSRECIPIENT` as typeId, if `to` is a contract that supports the LSP1 interface.
777
- *
778
- * If `to` is is an EOA or a contract that does not support the LSP1 interface, the behaviour will depend on the `force` boolean flag.
779
- * - if `force` is set to `true`, nothing will happen and no notification will be sent.
780
- * - if `force` is set to `false, the transaction will revert.
781
- *
782
- * @param to The address to call the {universalReceiver} function on.
783
- * @param force A boolean that describe if transfer to a `to` address that does not support LSP1 is allowed or not.
784
- * @param lsp1Data The data to be sent to the `to` address in the `universalReceiver(...)` call.
785
- */
786
- function _notifyTokenReceiver(
787
- address to,
788
- bool force,
789
- bytes memory lsp1Data
790
- ) internal virtual {
791
- if (
792
- ERC165Checker.supportsERC165InterfaceUnchecked(
793
- to,
794
- _INTERFACEID_LSP1
795
- )
796
- ) {
797
- ILSP1(to).universalReceiver(_TYPEID_LSP8_TOKENSRECIPIENT, lsp1Data);
798
- } else if (!force) {
799
- if (to.code.length != 0) {
800
- revert LSP8NotifyTokenReceiverContractMissingLSP1Interface(to);
801
- } else {
802
- revert LSP8NotifyTokenReceiverIsEOA(to);
803
- }
804
- }
805
- }
806
- }