@lukso/lsp-smart-contracts 0.7.0 → 0.8.0

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 (164) hide show
  1. package/CONTRIBUTING.md +31 -0
  2. package/README.md +73 -20
  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 +21 -5
  17. package/artifacts/LSP7CappedSupplyInitAbstract.json +21 -5
  18. package/artifacts/LSP7CompatibleERC20.json +21 -5
  19. package/artifacts/LSP7CompatibleERC20InitAbstract.json +23 -7
  20. package/artifacts/LSP7CompatibleERC20Mintable.json +24 -8
  21. package/artifacts/LSP7CompatibleERC20MintableInit.json +24 -8
  22. package/artifacts/LSP7DigitalAsset.json +21 -5
  23. package/artifacts/LSP7DigitalAssetInitAbstract.json +21 -5
  24. package/artifacts/LSP7Mintable.json +24 -8
  25. package/artifacts/LSP7MintableInit.json +24 -8
  26. package/artifacts/LSP8CappedSupply.json +22 -6
  27. package/artifacts/LSP8CappedSupplyInitAbstract.json +22 -6
  28. package/artifacts/LSP8CompatibleERC721.json +23 -7
  29. package/artifacts/LSP8CompatibleERC721InitAbstract.json +25 -9
  30. package/artifacts/LSP8CompatibleERC721Mintable.json +26 -10
  31. package/artifacts/LSP8CompatibleERC721MintableInit.json +26 -10
  32. package/artifacts/LSP8IdentifiableDigitalAsset.json +22 -6
  33. package/artifacts/LSP8IdentifiableDigitalAssetInitAbstract.json +22 -6
  34. package/artifacts/LSP8Mintable.json +25 -9
  35. package/artifacts/LSP8MintableInit.json +25 -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/constants.js +377 -115
  42. package/contracts/Custom/EIP191Signer.sol +12 -0
  43. package/contracts/Factories/Create2Factory.sol +1 -3
  44. package/contracts/LSP0ERC725Account/LSP0Constants.sol +13 -2
  45. package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +2 -1
  46. package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +261 -63
  47. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +2 -2
  48. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +2 -1
  49. package/contracts/LSP10ReceivedVaults/LSP10Constants.sol +2 -2
  50. package/contracts/LSP10ReceivedVaults/LSP10Utils.sol +214 -0
  51. package/contracts/LSP11BasicSocialRecovery/ILSP11BasicSocialRecovery.sol +177 -0
  52. package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecovery.sol +23 -0
  53. package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryCore.sol +258 -0
  54. package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryInit.sol +26 -0
  55. package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryInitAbstract.sol +19 -0
  56. package/contracts/LSP11BasicSocialRecovery/LSP11Constants.sol +6 -0
  57. package/contracts/LSP11BasicSocialRecovery/LSP11Errors.sol +60 -0
  58. package/contracts/LSP14Ownable2Step/ILSP14Ownable2Step.sol +53 -0
  59. package/contracts/LSP14Ownable2Step/LSP14Constants.sol +15 -0
  60. package/contracts/LSP14Ownable2Step/LSP14Errors.sol +12 -0
  61. package/contracts/LSP14Ownable2Step/LSP14Ownable2Step.sol +212 -0
  62. package/contracts/LSP16UniversalFactory/LSP16UniversalFactory.sol +246 -0
  63. package/contracts/LSP17ContractExtension/LSP17Constants.sol +17 -0
  64. package/contracts/LSP17ContractExtension/LSP17Errors.sol +7 -0
  65. package/contracts/LSP17ContractExtension/LSP17Extendable.sol +104 -0
  66. package/contracts/LSP17ContractExtension/LSP17Extension.sol +45 -0
  67. package/contracts/LSP17ContractExtension/LSP17Utils.sol +20 -0
  68. package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiver.sol +5 -5
  69. package/contracts/LSP1UniversalReceiver/LSP1Constants.sol +5 -3
  70. package/contracts/LSP1UniversalReceiver/LSP1Errors.sol +21 -0
  71. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +157 -37
  72. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +64 -31
  73. package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +53 -40
  74. package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +45 -23
  75. package/contracts/LSP3UniversalProfile/LSP3Constants.sol +1 -1
  76. package/contracts/LSP4DigitalAssetMetadata/ILSP4Compatibility.sol +1 -1
  77. package/contracts/LSP4DigitalAssetMetadata/LSP4Compatibility.sol +1 -1
  78. package/contracts/LSP4DigitalAssetMetadata/LSP4Constants.sol +1 -1
  79. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol +2 -2
  80. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +2 -2
  81. package/contracts/LSP4DigitalAssetMetadata/LSP4Errors.sol +3 -3
  82. package/contracts/LSP5ReceivedAssets/LSP5Constants.sol +2 -2
  83. package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +102 -114
  84. package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +25 -7
  85. package/contracts/LSP6KeyManager/LSP6Constants.sol +43 -38
  86. package/contracts/LSP6KeyManager/LSP6Errors.sol +90 -21
  87. package/contracts/LSP6KeyManager/LSP6KeyManager.sol +2 -1
  88. package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +772 -364
  89. package/contracts/LSP6KeyManager/LSP6KeyManagerInit.sol +1 -1
  90. package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +3 -2
  91. package/contracts/LSP6KeyManager/LSP6Utils.sol +125 -34
  92. package/contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol +8 -8
  93. package/contracts/LSP7DigitalAsset/LSP7Constants.sol +6 -6
  94. package/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol +1 -1
  95. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +38 -34
  96. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol +1 -1
  97. package/contracts/LSP7DigitalAsset/LSP7Errors.sol +28 -1
  98. package/contracts/LSP7DigitalAsset/extensions/ILSP7CompatibleERC20.sol +1 -1
  99. package/contracts/LSP7DigitalAsset/extensions/LSP7Burnable.sol +24 -0
  100. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.sol +28 -8
  101. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +28 -11
  102. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20.sol +87 -20
  103. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20InitAbstract.sol +97 -19
  104. package/contracts/LSP7DigitalAsset/presets/ILSP7Mintable.sol +3 -3
  105. package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20Mintable.sol +3 -4
  106. package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInit.sol +2 -2
  107. package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInitAbstract.sol +3 -3
  108. package/contracts/LSP7DigitalAsset/presets/LSP7Mintable.sol +3 -5
  109. package/contracts/LSP7DigitalAsset/presets/LSP7MintableInit.sol +2 -2
  110. package/contracts/LSP7DigitalAsset/presets/LSP7MintableInitAbstract.sol +3 -3
  111. package/contracts/LSP8IdentifiableDigitalAsset/ILSP8IdentifiableDigitalAsset.sol +7 -7
  112. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Constants.sol +7 -7
  113. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Errors.sol +40 -2
  114. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAsset.sol +2 -2
  115. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +53 -50
  116. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInitAbstract.sol +1 -1
  117. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CompatibleERC721.sol +5 -2
  118. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Burnable.sol +20 -0
  119. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupply.sol +27 -7
  120. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +27 -10
  121. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol +236 -30
  122. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol +240 -30
  123. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Enumerable.sol +32 -4
  124. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8EnumerableInitAbstract.sol +35 -8
  125. package/contracts/LSP8IdentifiableDigitalAsset/presets/ILSP8Mintable.sol +3 -3
  126. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721Mintable.sol +3 -4
  127. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInit.sol +3 -3
  128. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInitAbstract.sol +3 -3
  129. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8Mintable.sol +3 -4
  130. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInit.sol +2 -2
  131. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInitAbstract.sol +3 -3
  132. package/contracts/LSP9Vault/LSP9Constants.sol +10 -10
  133. package/contracts/LSP9Vault/LSP9Errors.sol +8 -0
  134. package/contracts/LSP9Vault/LSP9Vault.sol +6 -4
  135. package/contracts/LSP9Vault/LSP9VaultCore.sol +289 -126
  136. package/contracts/LSP9Vault/LSP9VaultInit.sol +2 -2
  137. package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +4 -3
  138. package/contracts/Legacy/Registries/AddressRegistry.sol +1 -1
  139. package/contracts/Legacy/Registries/AddressRegistryRequiresERC725.sol +1 -1
  140. package/contracts/Legacy/UniversalReceiverAddressStore.sol +4 -14
  141. package/contracts/UniversalProfile.sol +2 -2
  142. package/contracts/UniversalProfileInit.sol +2 -2
  143. package/contracts/UniversalProfileInitAbstract.sol +1 -1
  144. package/contracts/Utils/GasLib.sol +1 -1
  145. package/package.json +17 -9
  146. package/artifacts/UniversalFactory.json +0 -127
  147. package/contracts/Custom/ClaimOwnership.sol +0 -96
  148. package/contracts/Custom/ERC165Checker.sol +0 -130
  149. package/contracts/Custom/IClaimOwnership.sol +0 -12
  150. package/contracts/Factories/UniversalFactory.sol +0 -159
  151. package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol +0 -24
  152. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/Handling/TokenAndVaultHandling.sol +0 -82
  153. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/Handling/TokenHandling.sol +0 -73
  154. package/contracts/LSP2ERC725YJSONSchema/LSP2Errors.sol +0 -9
  155. package/contracts/LSP7DigitalAsset/extensions/ILSP7CappedSupply.sol +0 -17
  156. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyCore.sol +0 -57
  157. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20Core.sol +0 -111
  158. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CappedSupply.sol +0 -17
  159. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8Enumerable.sol +0 -17
  160. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyCore.sol +0 -58
  161. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleConstants.sol +0 -6
  162. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721Core.sol +0 -211
  163. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8EnumerableCore.sol +0 -50
  164. package/contracts/Utils/UtilsLib.sol +0 -31
@@ -1,28 +1,66 @@
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);
@@ -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,15 @@
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";
9
+ import {Address} from "@openzeppelin/contracts/utils/Address.sol";
10
10
  import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
11
- import {ERC165Checker} from "../Custom/ERC165Checker.sol";
11
+ import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
12
+ import {GasLib} from "../Utils/GasLib.sol";
12
13
 
13
14
  // modules
14
15
 
@@ -29,6 +30,7 @@ import {_TYPEID_LSP8_TOKENSSENDER, _TYPEID_LSP8_TOKENSRECIPIENT} from "./LSP8Con
29
30
  abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAsset {
30
31
  using EnumerableSet for EnumerableSet.AddressSet;
31
32
  using EnumerableSet for EnumerableSet.Bytes32Set;
33
+ using Address for address;
32
34
 
33
35
  // --- Storage
34
36
 
@@ -50,7 +52,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
50
52
  /**
51
53
  * @inheritdoc ILSP8IdentifiableDigitalAsset
52
54
  */
53
- function totalSupply() public view returns (uint256) {
55
+ function totalSupply() public view virtual returns (uint256) {
54
56
  return _existingTokens;
55
57
  }
56
58
 
@@ -59,14 +61,14 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
59
61
  /**
60
62
  * @inheritdoc ILSP8IdentifiableDigitalAsset
61
63
  */
62
- function balanceOf(address tokenOwner) public view returns (uint256) {
64
+ function balanceOf(address tokenOwner) public view virtual returns (uint256) {
63
65
  return _ownedTokens[tokenOwner].length();
64
66
  }
65
67
 
66
68
  /**
67
69
  * @inheritdoc ILSP8IdentifiableDigitalAsset
68
70
  */
69
- function tokenOwnerOf(bytes32 tokenId) public view returns (address) {
71
+ function tokenOwnerOf(bytes32 tokenId) public view virtual returns (address) {
70
72
  address tokenOwner = _tokenOwners[tokenId];
71
73
 
72
74
  if (tokenOwner == address(0)) {
@@ -79,7 +81,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
79
81
  /**
80
82
  * @inheritdoc ILSP8IdentifiableDigitalAsset
81
83
  */
82
- function tokenIdsOf(address tokenOwner) public view returns (bytes32[] memory) {
84
+ function tokenIdsOf(address tokenOwner) public view virtual returns (bytes32[] memory) {
83
85
  return _ownedTokens[tokenOwner].values();
84
86
  }
85
87
 
@@ -137,12 +139,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
137
139
  /**
138
140
  * @inheritdoc ILSP8IdentifiableDigitalAsset
139
141
  */
140
- function isOperatorFor(address operator, bytes32 tokenId)
141
- public
142
- view
143
- virtual
144
- returns (bool)
145
- {
142
+ function isOperatorFor(address operator, bytes32 tokenId) public view virtual returns (bool) {
146
143
  _existsOrError(tokenId);
147
144
 
148
145
  return _isOperatorOrOwner(operator, tokenId);
@@ -151,17 +148,16 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
151
148
  /**
152
149
  * @inheritdoc ILSP8IdentifiableDigitalAsset
153
150
  */
154
- function getOperatorsOf(bytes32 tokenId)
155
- public
156
- view
157
- virtual
158
- returns (address[] memory)
159
- {
151
+ function getOperatorsOf(bytes32 tokenId) public view virtual returns (address[] memory) {
160
152
  _existsOrError(tokenId);
161
153
 
162
154
  return _operators[tokenId].values();
163
155
  }
164
156
 
157
+ /**
158
+ * @dev verifies if the `caller` is operator or owner for the `tokenId`
159
+ * @return true if `caller` is either operator or owner
160
+ */
165
161
  function _isOperatorOrOwner(address caller, bytes32 tokenId)
166
162
  internal
167
163
  view
@@ -182,7 +178,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
182
178
  address from,
183
179
  address to,
184
180
  bytes32 tokenId,
185
- bool force,
181
+ bool allowNonLSP1Recipient,
186
182
  bytes memory data
187
183
  ) public virtual {
188
184
  address operator = msg.sender;
@@ -191,7 +187,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
191
187
  revert LSP8NotTokenOperator(tokenId, operator);
192
188
  }
193
189
 
194
- _transfer(from, to, tokenId, force, data);
190
+ _transfer(from, to, tokenId, allowNonLSP1Recipient, data);
195
191
  }
196
192
 
197
193
  /**
@@ -201,20 +197,27 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
201
197
  address[] memory from,
202
198
  address[] memory to,
203
199
  bytes32[] memory tokenId,
204
- bool force,
200
+ bool[] memory allowNonLSP1Recipient,
205
201
  bytes[] memory data
206
202
  ) public virtual {
203
+ uint256 fromLength = from.length;
207
204
  if (
208
- from.length != to.length || from.length != tokenId.length || from.length != data.length
205
+ fromLength != to.length ||
206
+ fromLength != tokenId.length ||
207
+ fromLength != allowNonLSP1Recipient.length ||
208
+ fromLength != data.length
209
209
  ) {
210
210
  revert LSP8InvalidTransferBatch();
211
211
  }
212
212
 
213
- for (uint256 i = 0; i < from.length; i = GasLib.uncheckedIncrement(i)) {
214
- transfer(from[i], to[i], tokenId[i], force, data[i]);
213
+ for (uint256 i = 0; i < fromLength; i = GasLib.uncheckedIncrement(i)) {
214
+ transfer(from[i], to[i], tokenId[i], allowNonLSP1Recipient[i], data[i]);
215
215
  }
216
216
  }
217
217
 
218
+ /**
219
+ * @dev removes `operator` from the list of operators for the `tokenId`
220
+ */
218
221
  function _revokeOperator(
219
222
  address operator,
220
223
  address tokenOwner,
@@ -225,6 +228,9 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
225
228
  emit RevokedOperator(operator, tokenOwner, tokenId);
226
229
  }
227
230
 
231
+ /**
232
+ * @dev clear all the operators for the `tokenId`
233
+ */
228
234
  function _clearOperators(address tokenOwner, bytes32 tokenId) internal virtual {
229
235
  // here is a good example of why having multiple operators will be expensive.. we
230
236
  // need to clear them on token transfer
@@ -255,7 +261,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
255
261
  /**
256
262
  * @dev When `tokenId` does not exist then revert with an error.
257
263
  */
258
- function _existsOrError(bytes32 tokenId) internal view {
264
+ function _existsOrError(bytes32 tokenId) internal view virtual {
259
265
  if (!_exists(tokenId)) {
260
266
  revert LSP8NonExistentTokenId(tokenId);
261
267
  }
@@ -274,7 +280,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
274
280
  function _mint(
275
281
  address to,
276
282
  bytes32 tokenId,
277
- bool force,
283
+ bool allowNonLSP1Recipient,
278
284
  bytes memory data
279
285
  ) internal virtual {
280
286
  if (to == address(0)) {
@@ -289,12 +295,15 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
289
295
 
290
296
  _beforeTokenTransfer(address(0), to, tokenId);
291
297
 
298
+ // token being minted
299
+ _existingTokens += 1;
300
+
292
301
  _ownedTokens[to].add(tokenId);
293
302
  _tokenOwners[tokenId] = to;
294
303
 
295
- emit Transfer(operator, address(0), to, tokenId, force, data);
304
+ emit Transfer(operator, address(0), to, tokenId, allowNonLSP1Recipient, data);
296
305
 
297
- _notifyTokenReceiver(address(0), to, tokenId, force, data);
306
+ _notifyTokenReceiver(address(0), to, tokenId, allowNonLSP1Recipient, data);
298
307
  }
299
308
 
300
309
  /**
@@ -312,6 +321,9 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
312
321
 
313
322
  _beforeTokenTransfer(tokenOwner, address(0), tokenId);
314
323
 
324
+ // token being burned
325
+ _existingTokens -= 1;
326
+
315
327
  _clearOperators(tokenOwner, tokenId);
316
328
 
317
329
  _ownedTokens[tokenOwner].remove(tokenId);
@@ -336,7 +348,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
336
348
  address from,
337
349
  address to,
338
350
  bytes32 tokenId,
339
- bool force,
351
+ bool allowNonLSP1Recipient,
340
352
  bytes memory data
341
353
  ) internal virtual {
342
354
  if (from == to) {
@@ -362,10 +374,10 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
362
374
  _ownedTokens[to].add(tokenId);
363
375
  _tokenOwners[tokenId] = to;
364
376
 
365
- emit Transfer(operator, from, to, tokenId, force, data);
377
+ emit Transfer(operator, from, to, tokenId, allowNonLSP1Recipient, data);
366
378
 
367
379
  _notifyTokenSender(from, to, tokenId, data);
368
- _notifyTokenReceiver(from, to, tokenId, force, data);
380
+ _notifyTokenReceiver(from, to, tokenId, allowNonLSP1Recipient, data);
369
381
  }
370
382
 
371
383
  /**
@@ -378,22 +390,13 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
378
390
  * transferred to `to`.
379
391
  * - When `from` is zero, `tokenId` will be minted for `to`.
380
392
  * - When `to` is zero, ``from``'s `tokenId` will be burned.
393
+ * - `from` and `to` are never both zero.
381
394
  */
382
395
  function _beforeTokenTransfer(
383
396
  address from,
384
397
  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
- }
398
+ bytes32 tokenId
399
+ ) internal virtual {}
397
400
 
398
401
  /**
399
402
  * @dev An attempt is made to notify the token sender about the `tokenId` changing owners using
@@ -405,7 +408,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
405
408
  bytes32 tokenId,
406
409
  bytes memory data
407
410
  ) internal virtual {
408
- if (ERC165Checker.supportsERC165Interface(from, _INTERFACEID_LSP1)) {
411
+ if (ERC165Checker.supportsERC165InterfaceUnchecked(from, _INTERFACEID_LSP1)) {
409
412
  bytes memory packedData = abi.encodePacked(from, to, tokenId, data);
410
413
  ILSP1UniversalReceiver(from).universalReceiver(_TYPEID_LSP8_TOKENSSENDER, packedData);
411
414
  }
@@ -413,7 +416,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
413
416
 
414
417
  /**
415
418
  * @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.
419
+ * using LSP1 interface. When allowNonLSP1Recipient is FALSE the token receiver MUST support LSP1.
417
420
  *
418
421
  * The receiver may revert when the token being sent is not wanted.
419
422
  */
@@ -421,14 +424,14 @@ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAs
421
424
  address from,
422
425
  address to,
423
426
  bytes32 tokenId,
424
- bool force,
427
+ bool allowNonLSP1Recipient,
425
428
  bytes memory data
426
429
  ) internal virtual {
427
- if (ERC165Checker.supportsERC165Interface(to, _INTERFACEID_LSP1)) {
430
+ if (ERC165Checker.supportsERC165InterfaceUnchecked(to, _INTERFACEID_LSP1)) {
428
431
  bytes memory packedData = abi.encodePacked(from, to, tokenId, data);
429
432
  ILSP1UniversalReceiver(to).universalReceiver(_TYPEID_LSP8_TOKENSRECIPIENT, packedData);
430
- } else if (!force) {
431
- if (to.code.length != 0) {
433
+ } else if (!allowNonLSP1Recipient) {
434
+ if (to.isContract()) {
432
435
  revert LSP8NotifyTokenReceiverContractMissingLSP1Interface(to);
433
436
  } else {
434
437
  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
  }