@lukso/lsp-smart-contracts 0.7.0 → 0.8.1

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 (172) hide show
  1. package/CONTRIBUTING.md +39 -0
  2. package/README.md +93 -40
  3. package/artifacts/Create2Factory.json +2 -2
  4. package/artifacts/LSP0ERC725Account.json +194 -15
  5. package/artifacts/LSP0ERC725AccountInit.json +194 -15
  6. package/artifacts/LSP11BasicSocialRecovery.json +493 -0
  7. package/artifacts/LSP11BasicSocialRecoveryInit.json +513 -0
  8. package/artifacts/LSP16UniversalFactory.json +236 -0
  9. package/artifacts/LSP1UniversalReceiverDelegateUP.json +134 -15
  10. package/artifacts/LSP1UniversalReceiverDelegateVault.json +80 -15
  11. package/artifacts/LSP4Compatibility.json +16 -0
  12. package/artifacts/LSP4DigitalAssetMetadata.json +16 -0
  13. package/artifacts/LSP4DigitalAssetMetadataInitAbstract.json +16 -0
  14. package/artifacts/LSP6KeyManager.json +177 -33
  15. package/artifacts/LSP6KeyManagerInit.json +177 -33
  16. package/artifacts/LSP7CappedSupply.json +26 -5
  17. package/artifacts/LSP7CappedSupplyInitAbstract.json +26 -5
  18. package/artifacts/LSP7CompatibleERC20.json +26 -5
  19. package/artifacts/LSP7CompatibleERC20InitAbstract.json +28 -7
  20. package/artifacts/LSP7CompatibleERC20Mintable.json +29 -8
  21. package/artifacts/LSP7CompatibleERC20MintableInit.json +29 -8
  22. package/artifacts/LSP7DigitalAsset.json +26 -5
  23. package/artifacts/LSP7DigitalAssetInitAbstract.json +26 -5
  24. package/artifacts/LSP7Mintable.json +29 -8
  25. package/artifacts/LSP7MintableInit.json +29 -8
  26. package/artifacts/LSP8CappedSupply.json +27 -6
  27. package/artifacts/LSP8CappedSupplyInitAbstract.json +27 -6
  28. package/artifacts/LSP8CompatibleERC721.json +28 -7
  29. package/artifacts/LSP8CompatibleERC721InitAbstract.json +30 -9
  30. package/artifacts/LSP8CompatibleERC721Mintable.json +31 -10
  31. package/artifacts/LSP8CompatibleERC721MintableInit.json +31 -10
  32. package/artifacts/LSP8IdentifiableDigitalAsset.json +27 -6
  33. package/artifacts/LSP8IdentifiableDigitalAssetInitAbstract.json +27 -6
  34. package/artifacts/LSP8Mintable.json +30 -9
  35. package/artifacts/LSP8MintableInit.json +30 -9
  36. package/artifacts/LSP9Vault.json +202 -17
  37. package/artifacts/LSP9VaultInit.json +202 -17
  38. package/artifacts/UniversalProfile.json +194 -15
  39. package/artifacts/UniversalProfileInit.json +194 -15
  40. package/artifacts/UniversalReceiverAddressStore.json +3 -3
  41. package/common/constants.d.ts +738 -0
  42. package/common/constants.js +785 -0
  43. package/contracts/Custom/EIP191Signer.sol +12 -0
  44. package/contracts/Factories/Create2Factory.sol +1 -3
  45. package/contracts/LSP0ERC725Account/LSP0Constants.sol +13 -2
  46. package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +2 -1
  47. package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +320 -63
  48. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +2 -2
  49. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +2 -1
  50. package/contracts/LSP0ERC725Account/LSP0Utils.sol +50 -0
  51. package/contracts/LSP10ReceivedVaults/LSP10Constants.sol +2 -2
  52. package/contracts/LSP10ReceivedVaults/LSP10Utils.sol +212 -0
  53. package/contracts/LSP11BasicSocialRecovery/ILSP11BasicSocialRecovery.sol +177 -0
  54. package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecovery.sol +23 -0
  55. package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryCore.sol +258 -0
  56. package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryInit.sol +26 -0
  57. package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryInitAbstract.sol +19 -0
  58. package/contracts/LSP11BasicSocialRecovery/LSP11Constants.sol +6 -0
  59. package/contracts/LSP11BasicSocialRecovery/LSP11Errors.sol +60 -0
  60. package/contracts/LSP14Ownable2Step/ILSP14Ownable2Step.sol +53 -0
  61. package/contracts/LSP14Ownable2Step/LSP14Constants.sol +15 -0
  62. package/contracts/LSP14Ownable2Step/LSP14Errors.sol +12 -0
  63. package/contracts/LSP14Ownable2Step/LSP14Ownable2Step.sol +212 -0
  64. package/contracts/LSP16UniversalFactory/LSP16UniversalFactory.sol +246 -0
  65. package/contracts/LSP17ContractExtension/LSP17Constants.sol +17 -0
  66. package/contracts/LSP17ContractExtension/LSP17Errors.sol +7 -0
  67. package/contracts/LSP17ContractExtension/LSP17Extendable.sol +104 -0
  68. package/contracts/LSP17ContractExtension/LSP17Extension.sol +45 -0
  69. package/contracts/LSP17ContractExtension/LSP17Utils.sol +20 -0
  70. package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiver.sol +5 -5
  71. package/contracts/LSP1UniversalReceiver/LSP1Constants.sol +5 -3
  72. package/contracts/LSP1UniversalReceiver/LSP1Errors.sol +21 -0
  73. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +155 -37
  74. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +64 -31
  75. package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +53 -40
  76. package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +45 -23
  77. package/contracts/LSP3UniversalProfile/LSP3Constants.sol +1 -1
  78. package/contracts/LSP4DigitalAssetMetadata/ILSP4Compatibility.sol +1 -1
  79. package/contracts/LSP4DigitalAssetMetadata/LSP4Compatibility.sol +1 -1
  80. package/contracts/LSP4DigitalAssetMetadata/LSP4Constants.sol +1 -1
  81. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol +2 -2
  82. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +2 -2
  83. package/contracts/LSP4DigitalAssetMetadata/LSP4Errors.sol +3 -3
  84. package/contracts/LSP5ReceivedAssets/LSP5Constants.sol +2 -2
  85. package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +102 -114
  86. package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +25 -7
  87. package/contracts/LSP6KeyManager/LSP6Constants.sol +43 -38
  88. package/contracts/LSP6KeyManager/LSP6Errors.sol +90 -21
  89. package/contracts/LSP6KeyManager/LSP6KeyManager.sol +2 -1
  90. package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +224 -506
  91. package/contracts/LSP6KeyManager/LSP6KeyManagerInit.sol +1 -1
  92. package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +3 -2
  93. package/contracts/LSP6KeyManager/LSP6Modules/LSP6ExecuteModule.sol +229 -0
  94. package/contracts/LSP6KeyManager/LSP6Modules/LSP6OwnershipModule.sol +25 -0
  95. package/contracts/LSP6KeyManager/LSP6Modules/LSP6SetDataModule.sol +606 -0
  96. package/contracts/LSP6KeyManager/LSP6Utils.sol +156 -35
  97. package/contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol +8 -8
  98. package/contracts/LSP7DigitalAsset/LSP7Constants.sol +6 -6
  99. package/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol +1 -1
  100. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +36 -36
  101. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol +1 -1
  102. package/contracts/LSP7DigitalAsset/LSP7Errors.sol +33 -1
  103. package/contracts/LSP7DigitalAsset/extensions/ILSP7CompatibleERC20.sol +1 -1
  104. package/contracts/LSP7DigitalAsset/extensions/LSP7Burnable.sol +24 -0
  105. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.sol +28 -8
  106. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +28 -11
  107. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20.sol +87 -20
  108. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20InitAbstract.sol +97 -19
  109. package/contracts/LSP7DigitalAsset/presets/ILSP7Mintable.sol +3 -3
  110. package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20Mintable.sol +3 -4
  111. package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInit.sol +2 -2
  112. package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInitAbstract.sol +3 -3
  113. package/contracts/LSP7DigitalAsset/presets/LSP7Mintable.sol +3 -5
  114. package/contracts/LSP7DigitalAsset/presets/LSP7MintableInit.sol +2 -2
  115. package/contracts/LSP7DigitalAsset/presets/LSP7MintableInitAbstract.sol +3 -3
  116. package/contracts/LSP8IdentifiableDigitalAsset/ILSP8IdentifiableDigitalAsset.sol +7 -7
  117. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Constants.sol +7 -7
  118. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Errors.sol +45 -2
  119. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAsset.sol +2 -2
  120. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +57 -60
  121. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInitAbstract.sol +1 -1
  122. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CompatibleERC721.sol +5 -2
  123. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Burnable.sol +20 -0
  124. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupply.sol +27 -7
  125. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +27 -10
  126. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol +234 -30
  127. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol +238 -30
  128. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Enumerable.sol +32 -4
  129. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8EnumerableInitAbstract.sol +35 -8
  130. package/contracts/LSP8IdentifiableDigitalAsset/presets/ILSP8Mintable.sol +3 -3
  131. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721Mintable.sol +3 -4
  132. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInit.sol +3 -3
  133. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInitAbstract.sol +3 -3
  134. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8Mintable.sol +3 -4
  135. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInit.sol +2 -2
  136. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInitAbstract.sol +3 -3
  137. package/contracts/LSP9Vault/LSP9Constants.sol +10 -10
  138. package/contracts/LSP9Vault/LSP9Errors.sol +8 -0
  139. package/contracts/LSP9Vault/LSP9Vault.sol +6 -4
  140. package/contracts/LSP9Vault/LSP9VaultCore.sol +350 -127
  141. package/contracts/LSP9Vault/LSP9VaultInit.sol +2 -2
  142. package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +4 -3
  143. package/contracts/Legacy/Registries/AddressRegistry.sol +1 -1
  144. package/contracts/Legacy/Registries/AddressRegistryRequiresERC725.sol +1 -1
  145. package/contracts/Legacy/UniversalReceiverAddressStore.sol +4 -14
  146. package/contracts/UniversalProfile.sol +2 -2
  147. package/contracts/UniversalProfileInit.sol +2 -2
  148. package/contracts/UniversalProfileInitAbstract.sol +1 -1
  149. package/contracts/Utils/GasLib.sol +1 -1
  150. package/module/constants.d.ts +738 -0
  151. package/module/constants.js +782 -0
  152. package/package.json +42 -12
  153. package/artifacts/UniversalFactory.json +0 -127
  154. package/constants.js +0 -594
  155. package/contracts/Custom/ClaimOwnership.sol +0 -96
  156. package/contracts/Custom/ERC165Checker.sol +0 -130
  157. package/contracts/Custom/IClaimOwnership.sol +0 -12
  158. package/contracts/Factories/UniversalFactory.sol +0 -159
  159. package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol +0 -24
  160. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/Handling/TokenAndVaultHandling.sol +0 -82
  161. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/Handling/TokenHandling.sol +0 -73
  162. package/contracts/LSP2ERC725YJSONSchema/LSP2Errors.sol +0 -9
  163. package/contracts/LSP7DigitalAsset/extensions/ILSP7CappedSupply.sol +0 -17
  164. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyCore.sol +0 -57
  165. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20Core.sol +0 -111
  166. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CappedSupply.sol +0 -17
  167. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8Enumerable.sol +0 -17
  168. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyCore.sol +0 -58
  169. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleConstants.sol +0 -6
  170. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721Core.sol +0 -211
  171. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8EnumerableCore.sol +0 -50
  172. package/contracts/Utils/UtilsLib.sol +0 -31
@@ -1,28 +1,71 @@
1
1
  // SPDX-License-Identifier: CC0-1.0
2
- pragma solidity ^0.8.0;
2
+ pragma solidity ^0.8.4;
3
3
 
4
4
  // --- Errors
5
5
 
6
+ /**
7
+ * @dev reverts when `tokenId` has not been minted.
8
+ */
6
9
  error LSP8NonExistentTokenId(bytes32 tokenId);
7
10
 
11
+ /**
12
+ * @dev reverts when `caller` is not the `tokenOwner` of the `tokenId`.
13
+ */
8
14
  error LSP8NotTokenOwner(address tokenOwner, bytes32 tokenId, address caller);
9
15
 
16
+ /**
17
+ * @dev reverts when `caller` is not an allowed operator for `tokenId`.
18
+ */
10
19
  error LSP8NotTokenOperator(bytes32 tokenId, address caller);
11
20
 
21
+ /**
22
+ * @dev reverts when `operator` is already authorized for the `tokenId`.
23
+ */
12
24
  error LSP8OperatorAlreadyAuthorized(address operator, bytes32 tokenId);
13
25
 
26
+ /**
27
+ * @dev reverts when trying to set the zero address as an operator.
28
+ */
14
29
  error LSP8CannotUseAddressZeroAsOperator();
15
30
 
31
+ /**
32
+ * @dev reverts when trying to send token to the zero address.
33
+ */
16
34
  error LSP8CannotSendToAddressZero();
17
35
 
36
+ /**
37
+ * @dev reverts when specifying the same address for `from` and `to` in a token transfer.
38
+ */
18
39
  error LSP8CannotSendToSelf();
19
40
 
20
- error LSP8NonExistingOperator(address _address, bytes32 tokenId);
41
+ /**
42
+ * @dev reverts when `operator` is not an operator for the `tokenId`.
43
+ */
44
+ error LSP8NonExistingOperator(address operator, bytes32 tokenId);
21
45
 
46
+ /**
47
+ * @dev reverts when `tokenId` has already been minted.
48
+ */
22
49
  error LSP8TokenIdAlreadyMinted(bytes32 tokenId);
23
50
 
51
+ /**
52
+ * @dev reverts when the parameters used for `transferBatch` have different lengths.
53
+ */
24
54
  error LSP8InvalidTransferBatch();
25
55
 
56
+ /**
57
+ * @dev reverts if the `tokenReceiver` does not implement LSP1
58
+ * when minting or transferring tokens with `bool allowNonLSP1Recipient` set as `false`.
59
+ */
26
60
  error LSP8NotifyTokenReceiverContractMissingLSP1Interface(address tokenReceiver);
27
61
 
62
+ /**
63
+ * @dev reverts if the `tokenReceiver` is an EOA
64
+ * when minting or transferring tokens with `bool allowNonLSP1Recipient` set as `false`.
65
+ */
28
66
  error LSP8NotifyTokenReceiverIsEOA(address tokenReceiver);
67
+
68
+ /**
69
+ * @dev reverts when trying to authorize or revoke the token's owner as an operator.
70
+ */
71
+ error LSP8TokenOwnerCannotBeOperator();
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: CC0-1.0
2
- pragma solidity ^0.8.0;
2
+ pragma solidity ^0.8.4;
3
3
 
4
4
  // interfaces
5
5
  import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
@@ -31,7 +31,7 @@ abstract contract LSP8IdentifiableDigitalAsset is
31
31
  string memory name_,
32
32
  string memory symbol_,
33
33
  address newOwner_
34
- ) LSP4DigitalAssetMetadata(name_, symbol_, newOwner_) {} // solhint-disable no-empty-blocks
34
+ ) LSP4DigitalAssetMetadata(name_, symbol_, newOwner_) {}
35
35
 
36
36
  /**
37
37
  * @dev See {IERC165-supportsInterface}.
@@ -1,14 +1,14 @@
1
1
  // SPDX-License-Identifier: CC0-1.0
2
- pragma solidity ^0.8.0;
2
+ pragma solidity ^0.8.4;
3
3
 
4
4
  // interfaces
5
5
  import {ILSP1UniversalReceiver} from "../LSP1UniversalReceiver/ILSP1UniversalReceiver.sol";
6
6
  import {ILSP8IdentifiableDigitalAsset} from "./ILSP8IdentifiableDigitalAsset.sol";
7
7
 
8
8
  // libraries
9
- import {GasLib} from "../Utils/GasLib.sol";
10
9
  import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
11
- import {ERC165Checker} from "../Custom/ERC165Checker.sol";
10
+ import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
11
+ import {GasLib} from "../Utils/GasLib.sol";
12
12
 
13
13
  // modules
14
14
 
@@ -50,7 +50,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
50
50
  /**
51
51
  * @inheritdoc ILSP8IdentifiableDigitalAsset
52
52
  */
53
- function totalSupply() public view returns (uint256) {
53
+ function totalSupply() public view virtual returns (uint256) {
54
54
  return _existingTokens;
55
55
  }
56
56
 
@@ -59,14 +59,14 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
59
59
  /**
60
60
  * @inheritdoc ILSP8IdentifiableDigitalAsset
61
61
  */
62
- function balanceOf(address tokenOwner) public view returns (uint256) {
62
+ function balanceOf(address tokenOwner) public view virtual returns (uint256) {
63
63
  return _ownedTokens[tokenOwner].length();
64
64
  }
65
65
 
66
66
  /**
67
67
  * @inheritdoc ILSP8IdentifiableDigitalAsset
68
68
  */
69
- function tokenOwnerOf(bytes32 tokenId) public view returns (address) {
69
+ function tokenOwnerOf(bytes32 tokenId) public view virtual returns (address) {
70
70
  address tokenOwner = _tokenOwners[tokenId];
71
71
 
72
72
  if (tokenOwner == address(0)) {
@@ -79,7 +79,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
79
79
  /**
80
80
  * @inheritdoc ILSP8IdentifiableDigitalAsset
81
81
  */
82
- function tokenIdsOf(address tokenOwner) public view returns (bytes32[] memory) {
82
+ function tokenIdsOf(address tokenOwner) public view virtual returns (bytes32[] memory) {
83
83
  return _ownedTokens[tokenOwner].values();
84
84
  }
85
85
 
@@ -90,19 +90,17 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
90
90
  */
91
91
  function authorizeOperator(address operator, bytes32 tokenId) public virtual {
92
92
  address tokenOwner = tokenOwnerOf(tokenId);
93
- address caller = msg.sender;
94
93
 
95
- if (tokenOwner != caller) {
96
- revert LSP8NotTokenOwner(tokenOwner, tokenId, caller);
94
+ if (tokenOwner != msg.sender) {
95
+ revert LSP8NotTokenOwner(tokenOwner, tokenId, msg.sender);
97
96
  }
98
97
 
99
98
  if (operator == address(0)) {
100
99
  revert LSP8CannotUseAddressZeroAsOperator();
101
100
  }
102
101
 
103
- // tokenOwner is always their own operator, no update required
104
102
  if (tokenOwner == operator) {
105
- return;
103
+ revert LSP8TokenOwnerCannotBeOperator();
106
104
  }
107
105
 
108
106
  bool isAdded = _operators[tokenId].add(operator);
@@ -116,19 +114,17 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
116
114
  */
117
115
  function revokeOperator(address operator, bytes32 tokenId) public virtual {
118
116
  address tokenOwner = tokenOwnerOf(tokenId);
119
- address caller = msg.sender;
120
117
 
121
- if (tokenOwner != caller) {
122
- revert LSP8NotTokenOwner(tokenOwner, tokenId, caller);
118
+ if (tokenOwner != msg.sender) {
119
+ revert LSP8NotTokenOwner(tokenOwner, tokenId, msg.sender);
123
120
  }
124
121
 
125
122
  if (operator == address(0)) {
126
123
  revert LSP8CannotUseAddressZeroAsOperator();
127
124
  }
128
125
 
129
- // tokenOwner is always their own operator, no update required
130
126
  if (tokenOwner == operator) {
131
- return;
127
+ revert LSP8TokenOwnerCannotBeOperator();
132
128
  }
133
129
 
134
130
  _revokeOperator(operator, tokenOwner, tokenId);
@@ -137,12 +133,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
137
133
  /**
138
134
  * @inheritdoc ILSP8IdentifiableDigitalAsset
139
135
  */
140
- function isOperatorFor(address operator, bytes32 tokenId)
141
- public
142
- view
143
- virtual
144
- returns (bool)
145
- {
136
+ function isOperatorFor(address operator, bytes32 tokenId) public view virtual returns (bool) {
146
137
  _existsOrError(tokenId);
147
138
 
148
139
  return _isOperatorOrOwner(operator, tokenId);
@@ -151,17 +142,16 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
151
142
  /**
152
143
  * @inheritdoc ILSP8IdentifiableDigitalAsset
153
144
  */
154
- function getOperatorsOf(bytes32 tokenId)
155
- public
156
- view
157
- virtual
158
- returns (address[] memory)
159
- {
145
+ function getOperatorsOf(bytes32 tokenId) public view virtual returns (address[] memory) {
160
146
  _existsOrError(tokenId);
161
147
 
162
148
  return _operators[tokenId].values();
163
149
  }
164
150
 
151
+ /**
152
+ * @dev verifies if the `caller` is operator or owner for the `tokenId`
153
+ * @return true if `caller` is either operator or owner
154
+ */
165
155
  function _isOperatorOrOwner(address caller, bytes32 tokenId)
166
156
  internal
167
157
  view
@@ -182,7 +172,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
182
172
  address from,
183
173
  address to,
184
174
  bytes32 tokenId,
185
- bool force,
175
+ bool allowNonLSP1Recipient,
186
176
  bytes memory data
187
177
  ) public virtual {
188
178
  address operator = msg.sender;
@@ -191,7 +181,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
191
181
  revert LSP8NotTokenOperator(tokenId, operator);
192
182
  }
193
183
 
194
- _transfer(from, to, tokenId, force, data);
184
+ _transfer(from, to, tokenId, allowNonLSP1Recipient, data);
195
185
  }
196
186
 
197
187
  /**
@@ -201,20 +191,27 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
201
191
  address[] memory from,
202
192
  address[] memory to,
203
193
  bytes32[] memory tokenId,
204
- bool force,
194
+ bool[] memory allowNonLSP1Recipient,
205
195
  bytes[] memory data
206
196
  ) public virtual {
197
+ uint256 fromLength = from.length;
207
198
  if (
208
- from.length != to.length || from.length != tokenId.length || from.length != data.length
199
+ fromLength != to.length ||
200
+ fromLength != tokenId.length ||
201
+ fromLength != allowNonLSP1Recipient.length ||
202
+ fromLength != data.length
209
203
  ) {
210
204
  revert LSP8InvalidTransferBatch();
211
205
  }
212
206
 
213
- for (uint256 i = 0; i < from.length; i = GasLib.uncheckedIncrement(i)) {
214
- transfer(from[i], to[i], tokenId[i], force, data[i]);
207
+ for (uint256 i = 0; i < fromLength; i = GasLib.uncheckedIncrement(i)) {
208
+ transfer(from[i], to[i], tokenId[i], allowNonLSP1Recipient[i], data[i]);
215
209
  }
216
210
  }
217
211
 
212
+ /**
213
+ * @dev removes `operator` from the list of operators for the `tokenId`
214
+ */
218
215
  function _revokeOperator(
219
216
  address operator,
220
217
  address tokenOwner,
@@ -225,6 +222,9 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
225
222
  emit RevokedOperator(operator, tokenOwner, tokenId);
226
223
  }
227
224
 
225
+ /**
226
+ * @dev clear all the operators for the `tokenId`
227
+ */
228
228
  function _clearOperators(address tokenOwner, bytes32 tokenId) internal virtual {
229
229
  // here is a good example of why having multiple operators will be expensive.. we
230
230
  // need to clear them on token transfer
@@ -255,7 +255,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
255
255
  /**
256
256
  * @dev When `tokenId` does not exist then revert with an error.
257
257
  */
258
- function _existsOrError(bytes32 tokenId) internal view {
258
+ function _existsOrError(bytes32 tokenId) internal view virtual {
259
259
  if (!_exists(tokenId)) {
260
260
  revert LSP8NonExistentTokenId(tokenId);
261
261
  }
@@ -274,7 +274,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
274
274
  function _mint(
275
275
  address to,
276
276
  bytes32 tokenId,
277
- bool force,
277
+ bool allowNonLSP1Recipient,
278
278
  bytes memory data
279
279
  ) internal virtual {
280
280
  if (to == address(0)) {
@@ -289,12 +289,15 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
289
289
 
290
290
  _beforeTokenTransfer(address(0), to, tokenId);
291
291
 
292
+ // token being minted
293
+ _existingTokens += 1;
294
+
292
295
  _ownedTokens[to].add(tokenId);
293
296
  _tokenOwners[tokenId] = to;
294
297
 
295
- emit Transfer(operator, address(0), to, tokenId, force, data);
298
+ emit Transfer(operator, address(0), to, tokenId, allowNonLSP1Recipient, data);
296
299
 
297
- _notifyTokenReceiver(address(0), to, tokenId, force, data);
300
+ _notifyTokenReceiver(address(0), to, tokenId, allowNonLSP1Recipient, data);
298
301
  }
299
302
 
300
303
  /**
@@ -312,6 +315,9 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
312
315
 
313
316
  _beforeTokenTransfer(tokenOwner, address(0), tokenId);
314
317
 
318
+ // token being burned
319
+ _existingTokens -= 1;
320
+
315
321
  _clearOperators(tokenOwner, tokenId);
316
322
 
317
323
  _ownedTokens[tokenOwner].remove(tokenId);
@@ -336,7 +342,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
336
342
  address from,
337
343
  address to,
338
344
  bytes32 tokenId,
339
- bool force,
345
+ bool allowNonLSP1Recipient,
340
346
  bytes memory data
341
347
  ) internal virtual {
342
348
  if (from == to) {
@@ -362,10 +368,10 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
362
368
  _ownedTokens[to].add(tokenId);
363
369
  _tokenOwners[tokenId] = to;
364
370
 
365
- emit Transfer(operator, from, to, tokenId, force, data);
371
+ emit Transfer(operator, from, to, tokenId, allowNonLSP1Recipient, data);
366
372
 
367
373
  _notifyTokenSender(from, to, tokenId, data);
368
- _notifyTokenReceiver(from, to, tokenId, force, data);
374
+ _notifyTokenReceiver(from, to, tokenId, allowNonLSP1Recipient, data);
369
375
  }
370
376
 
371
377
  /**
@@ -378,22 +384,13 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
378
384
  * transferred to `to`.
379
385
  * - When `from` is zero, `tokenId` will be minted for `to`.
380
386
  * - When `to` is zero, ``from``'s `tokenId` will be burned.
387
+ * - `from` and `to` are never both zero.
381
388
  */
382
389
  function _beforeTokenTransfer(
383
390
  address from,
384
391
  address to,
385
- bytes32 tokenId // solhint-disable no-unused-vars
386
- ) internal virtual {
387
- // token being minted
388
- if (from == address(0)) {
389
- _existingTokens += 1;
390
- }
391
-
392
- // token being burned
393
- if (to == address(0)) {
394
- _existingTokens -= 1;
395
- }
396
- }
392
+ bytes32 tokenId
393
+ ) internal virtual {}
397
394
 
398
395
  /**
399
396
  * @dev An attempt is made to notify the token sender about the `tokenId` changing owners using
@@ -405,7 +402,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
405
402
  bytes32 tokenId,
406
403
  bytes memory data
407
404
  ) internal virtual {
408
- if (ERC165Checker.supportsERC165Interface(from, _INTERFACEID_LSP1)) {
405
+ if (ERC165Checker.supportsERC165InterfaceUnchecked(from, _INTERFACEID_LSP1)) {
409
406
  bytes memory packedData = abi.encodePacked(from, to, tokenId, data);
410
407
  ILSP1UniversalReceiver(from).universalReceiver(_TYPEID_LSP8_TOKENSSENDER, packedData);
411
408
  }
@@ -413,7 +410,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
413
410
 
414
411
  /**
415
412
  * @dev An attempt is made to notify the token receiver about the `tokenId` changing owners
416
- * using LSP1 interface. When force is FALSE the token receiver MUST support LSP1.
413
+ * using LSP1 interface. When allowNonLSP1Recipient is FALSE the token receiver MUST support LSP1.
417
414
  *
418
415
  * The receiver may revert when the token being sent is not wanted.
419
416
  */
@@ -421,14 +418,14 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
421
418
  address from,
422
419
  address to,
423
420
  bytes32 tokenId,
424
- bool force,
421
+ bool allowNonLSP1Recipient,
425
422
  bytes memory data
426
423
  ) internal virtual {
427
- if (ERC165Checker.supportsERC165Interface(to, _INTERFACEID_LSP1)) {
424
+ if (ERC165Checker.supportsERC165InterfaceUnchecked(to, _INTERFACEID_LSP1)) {
428
425
  bytes memory packedData = abi.encodePacked(from, to, tokenId, data);
429
426
  ILSP1UniversalReceiver(to).universalReceiver(_TYPEID_LSP8_TOKENSRECIPIENT, packedData);
430
- } else if (!force) {
431
- if (to.code.length != 0) {
427
+ } else if (!allowNonLSP1Recipient) {
428
+ if (to.code.length > 0) {
432
429
  revert LSP8NotifyTokenReceiverContractMissingLSP1Interface(to);
433
430
  } else {
434
431
  revert LSP8NotifyTokenReceiverIsEOA(to);
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: CC0-1.0
2
- pragma solidity ^0.8.0;
2
+ pragma solidity ^0.8.4;
3
3
 
4
4
  // interfaces
5
5
  import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
@@ -1,10 +1,13 @@
1
1
  // SPDX-License-Identifier: MIT
2
-
3
- pragma solidity ^0.8.0;
2
+ pragma solidity ^0.8.4;
4
3
 
5
4
  // interfaces
6
5
  import {ILSP8IdentifiableDigitalAsset} from "../ILSP8IdentifiableDigitalAsset.sol";
7
6
 
7
+ // --- ERC165 interface ids
8
+ bytes4 constant _INTERFACEID_ERC721 = 0x80ac58cd;
9
+ bytes4 constant _INTERFACEID_ERC721METADATA = 0x5b5e139f;
10
+
8
11
  /**
9
12
  * @dev LSP8 extension, for compatibility for clients / tools that expect ERC721.
10
13
  */
@@ -0,0 +1,20 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.4;
3
+
4
+ import {LSP8IdentifiableDigitalAssetCore} from "../LSP8IdentifiableDigitalAssetCore.sol";
5
+
6
+ // errors
7
+ import {LSP8NotTokenOperator} from "../LSP8Errors.sol";
8
+
9
+ /**
10
+ * @dev LSP8 extension that allows token holders to destroy both
11
+ * their own tokens and those that they have an allowance for as an operator.
12
+ */
13
+ abstract contract LSP8Burnable is LSP8IdentifiableDigitalAssetCore {
14
+ function burn(bytes32 tokenId, bytes memory data) public {
15
+ if (!_isOperatorOrOwner(msg.sender, tokenId)) {
16
+ revert LSP8NotTokenOperator(tokenId, msg.sender);
17
+ }
18
+ _burn(tokenId, data);
19
+ }
20
+ }
@@ -1,16 +1,22 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
 
3
- pragma solidity ^0.8.0;
3
+ pragma solidity ^0.8.4;
4
4
 
5
5
  // modules
6
6
  import {LSP8IdentifiableDigitalAsset} from "../LSP8IdentifiableDigitalAsset.sol";
7
7
  import {LSP8IdentifiableDigitalAssetCore} from "../LSP8IdentifiableDigitalAssetCore.sol";
8
- import {LSP8CappedSupplyCore} from "./LSP8CappedSupplyCore.sol";
9
8
 
10
9
  /**
11
10
  * @dev LSP8 extension, adds token supply cap.
12
11
  */
13
- abstract contract LSP8CappedSupply is LSP8IdentifiableDigitalAsset, LSP8CappedSupplyCore {
12
+ abstract contract LSP8CappedSupply is LSP8IdentifiableDigitalAsset {
13
+ // --- Errors
14
+ error LSP8CappedSupplyRequired();
15
+ error LSP8CappedSupplyCannotMintOverCap();
16
+
17
+ // --- Storage
18
+ uint256 internal _tokenSupplyCap;
19
+
14
20
  /**
15
21
  * @notice Sets the token max supply
16
22
  * @param tokenSupplyCap_ The Token max supply
@@ -23,7 +29,17 @@ abstract contract LSP8CappedSupply is LSP8IdentifiableDigitalAsset, LSP8CappedSu
23
29
  _tokenSupplyCap = tokenSupplyCap_;
24
30
  }
25
31
 
26
- // --- Overrides
32
+ // --- Token queries
33
+
34
+ /**
35
+ * @dev Returns the number of tokens that can be minted.
36
+ * @return The token max supply
37
+ */
38
+ function tokenSupplyCap() public view virtual returns (uint256) {
39
+ return _tokenSupplyCap;
40
+ }
41
+
42
+ // --- Transfer functionality
27
43
 
28
44
  /**
29
45
  * @dev Mints `tokenId` and transfers it to `to`.
@@ -39,9 +55,13 @@ abstract contract LSP8CappedSupply is LSP8IdentifiableDigitalAsset, LSP8CappedSu
39
55
  function _mint(
40
56
  address to,
41
57
  bytes32 tokenId,
42
- bool force,
58
+ bool allowNonLSP1Recipient,
43
59
  bytes memory data
44
- ) internal virtual override(LSP8IdentifiableDigitalAssetCore, LSP8CappedSupplyCore) {
45
- super._mint(to, tokenId, force, data);
60
+ ) internal virtual override {
61
+ if (totalSupply() + 1 > tokenSupplyCap()) {
62
+ revert LSP8CappedSupplyCannotMintOverCap();
63
+ }
64
+
65
+ super._mint(to, tokenId, allowNonLSP1Recipient, data);
46
66
  }
47
67
  }
@@ -1,21 +1,24 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
 
3
- pragma solidity ^0.8.0;
3
+ pragma solidity ^0.8.4;
4
4
 
5
5
  // modules
6
6
  import {LSP8IdentifiableDigitalAssetCore} from "../LSP8IdentifiableDigitalAssetCore.sol";
7
7
  import {
8
8
  LSP8IdentifiableDigitalAssetInitAbstract
9
9
  } from "../LSP8IdentifiableDigitalAssetInitAbstract.sol";
10
- import {LSP8CappedSupplyCore} from "./LSP8CappedSupplyCore.sol";
11
10
 
12
11
  /**
13
12
  * @dev LSP8 extension, adds token supply cap.
14
13
  */
15
- abstract contract LSP8CappedSupplyInitAbstract is
16
- LSP8IdentifiableDigitalAssetInitAbstract,
17
- LSP8CappedSupplyCore
18
- {
14
+ abstract contract LSP8CappedSupplyInitAbstract is LSP8IdentifiableDigitalAssetInitAbstract {
15
+ // --- Errors
16
+ error LSP8CappedSupplyRequired();
17
+ error LSP8CappedSupplyCannotMintOverCap();
18
+
19
+ // --- Storage
20
+ uint256 internal _tokenSupplyCap;
21
+
19
22
  function _initialize(uint256 tokenSupplyCap_) internal virtual onlyInitializing {
20
23
  if (tokenSupplyCap_ == 0) {
21
24
  revert LSP8CappedSupplyRequired();
@@ -24,7 +27,17 @@ abstract contract LSP8CappedSupplyInitAbstract is
24
27
  _tokenSupplyCap = tokenSupplyCap_;
25
28
  }
26
29
 
27
- // --- Overrides
30
+ // --- Token queries
31
+
32
+ /**
33
+ * @dev Returns the number of tokens that can be minted.
34
+ * @return The token max supply
35
+ */
36
+ function tokenSupplyCap() public view virtual returns (uint256) {
37
+ return _tokenSupplyCap;
38
+ }
39
+
40
+ // --- Transfer functionality
28
41
 
29
42
  /**
30
43
  * @dev Mints `tokenId` and transfers it to `to`.
@@ -40,9 +53,13 @@ abstract contract LSP8CappedSupplyInitAbstract is
40
53
  function _mint(
41
54
  address to,
42
55
  bytes32 tokenId,
43
- bool force,
56
+ bool allowNonLSP1Recipient,
44
57
  bytes memory data
45
- ) internal virtual override(LSP8IdentifiableDigitalAssetCore, LSP8CappedSupplyCore) {
46
- super._mint(to, tokenId, force, data);
58
+ ) internal virtual override {
59
+ if (totalSupply() + 1 > tokenSupplyCap()) {
60
+ revert LSP8CappedSupplyCannotMintOverCap();
61
+ }
62
+
63
+ super._mint(to, tokenId, allowNonLSP1Recipient, data);
47
64
  }
48
65
  }