@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,24 +0,0 @@
1
- // SPDX-License-Identifier: CC0-1.0
2
- pragma solidity ^0.8.0;
3
-
4
- /**
5
- * @title The interface for LSP1UniversalReceiverDelegate
6
- * @dev LSP1UniversalReceiverDelegate allows for an external universal receiver smart contract,
7
- * that is the delegate of the initial universal receiver
8
- */
9
- interface ILSP1UniversalReceiverDelegate {
10
- /**
11
- * @dev Get called by the universalReceiver function, can be customized to have a specific logic
12
- * @param caller The address calling the universalReceiver function
13
- * @param value The amount sent to the universalReceiver function
14
- * @param typeId The hash of a specific standard or a hook
15
- * @param data The arbitrary data received with the call
16
- * @return result Any useful data could be returned
17
- */
18
- function universalReceiverDelegate(
19
- address caller,
20
- uint256 value,
21
- bytes32 typeId,
22
- bytes memory data
23
- ) external returns (bytes memory result);
24
- }
@@ -1,82 +0,0 @@
1
- // SPDX-License-Identifier: CC0-1.0
2
- pragma solidity ^0.8.0;
3
-
4
- // interfaces
5
- import {IERC725Y} from "@erc725/smart-contracts/contracts/interfaces/IERC725Y.sol";
6
- import {ILSP7DigitalAsset} from "../../../LSP7DigitalAsset/ILSP7DigitalAsset.sol";
7
- import {ILSP6KeyManager} from "../../../LSP6KeyManager/ILSP6KeyManager.sol";
8
-
9
- // libraries
10
- import {ERC165Checker} from "../../../Custom/ERC165Checker.sol";
11
- import {LSP1Utils} from "../../LSP1Utils.sol";
12
- import {LSP2Utils} from "../../../LSP2ERC725YJSONSchema/LSP2Utils.sol";
13
- import {LSP5Utils} from "../../../LSP5ReceivedAssets/LSP5Utils.sol";
14
-
15
- // modules
16
- import {ERC725Y} from "@erc725/smart-contracts/contracts/ERC725Y.sol";
17
- import {LSP6KeyManager} from "../../../LSP6KeyManager/LSP6KeyManager.sol";
18
-
19
- // constants
20
- import {_INTERFACEID_LSP6} from "../../../LSP6KeyManager/LSP6Constants.sol";
21
- import {_TYPEID_LSP9_VAULTSENDER} from "../../../LSP9Vault/LSP9Constants.sol";
22
-
23
- /**
24
- * @dev Function logic to add and remove the MapAndArrayKey of incoming assets and vaults
25
- */
26
- abstract contract TokenAndVaultHandling {
27
- function _tokenAndVaultHandling(address caller, bytes32 typeId)
28
- internal
29
- returns (bytes memory result)
30
- {
31
- address keyManager = ERC725Y(msg.sender).owner();
32
- if (!ERC165Checker.supportsERC165Interface(keyManager, _INTERFACEID_LSP6)) return "";
33
-
34
- address target = ILSP6KeyManager(keyManager).target();
35
-
36
- // check if the caller is the same account controlled by the keyManager
37
- if (msg.sender != target) return "";
38
-
39
- (
40
- bool isReceiving,
41
- bytes32 arrayLengthKey,
42
- bytes10 mapPrefix,
43
- bytes4 interfaceID
44
- ) = LSP1Utils.getTransferDetails(typeId);
45
-
46
- bytes32 mapKey = LSP2Utils.generateMappingKey(mapPrefix, bytes20(caller));
47
- bytes memory mapValue = IERC725Y(msg.sender).getData(mapKey);
48
-
49
- if (isReceiving) {
50
- // if the map value is already set, then do nothing
51
- if (bytes12(mapValue) != bytes12(0)) return "";
52
-
53
- result = LSP5Utils.addMapAndArrayKeyViaKeyManager(
54
- IERC725Y(msg.sender),
55
- arrayLengthKey,
56
- mapKey,
57
- caller,
58
- interfaceID,
59
- keyManager
60
- );
61
- } else {
62
- // if there is no map value for the asset to remove, then do nothing
63
- if (bytes12(mapValue) == bytes12(0)) return "";
64
-
65
- // if it's a token transfer (LSP7/LSP8)
66
- if (typeId != _TYPEID_LSP9_VAULTSENDER) {
67
- // if the amount sent is not the full balance, then do not remove the keys
68
- uint256 balance = ILSP7DigitalAsset(caller).balanceOf(msg.sender);
69
- if (balance != 0) return "";
70
- }
71
-
72
- result = LSP5Utils.removeMapAndArrayKeyViaKeyManager(
73
- IERC725Y(msg.sender),
74
- arrayLengthKey,
75
- mapPrefix,
76
- mapKey,
77
- mapValue,
78
- keyManager
79
- );
80
- }
81
- }
82
- }
@@ -1,73 +0,0 @@
1
- // SPDX-License-Identifier: CC0-1.0
2
- pragma solidity ^0.8.0;
3
-
4
- // interfaces
5
- import {IERC725Y} from "@erc725/smart-contracts/contracts/interfaces/IERC725Y.sol";
6
- import {ILSP7DigitalAsset} from "../../../LSP7DigitalAsset/ILSP7DigitalAsset.sol";
7
-
8
- // libraries
9
- import {ERC165Checker} from "../../../Custom/ERC165Checker.sol";
10
- import {LSP1Utils} from "../../LSP1Utils.sol";
11
- import {LSP2Utils} from "../../../LSP2ERC725YJSONSchema/LSP2Utils.sol";
12
- import {LSP5Utils} from "../../../LSP5ReceivedAssets/LSP5Utils.sol";
13
-
14
- // modules
15
- import {ERC725Y} from "@erc725/smart-contracts/contracts/ERC725Y.sol";
16
- import {LSP6KeyManager} from "../../../LSP6KeyManager/LSP6KeyManager.sol";
17
-
18
- // constants
19
- import "../../LSP1Constants.sol";
20
- import "../../../LSP9Vault/LSP9Constants.sol";
21
-
22
- /**
23
- * @dev Function logic to add and remove the MapAndArrayKey of incoming assets and vaults
24
- */
25
- abstract contract TokenHandling {
26
- function _tokenHandling(address caller, bytes32 typeId) internal returns (bytes memory result) {
27
- if (!ERC165Checker.supportsERC165Interface(msg.sender, _INTERFACEID_LSP9)) return "";
28
-
29
- (
30
- bool isReceiving,
31
- bytes32 arrayLengthKey,
32
- bytes10 mapPrefix,
33
- bytes4 interfaceID
34
- ) = LSP1Utils.getTransferDetails(typeId);
35
-
36
- bytes32 mapKey = LSP2Utils.generateMappingKey(mapPrefix, bytes20(caller));
37
- bytes memory mapValue = IERC725Y(msg.sender).getData(mapKey);
38
-
39
- if (isReceiving) {
40
- // if the map value is already set, then do nothing
41
- if (bytes12(mapValue) != bytes12(0)) return "";
42
-
43
- (bytes32[] memory receiverDataKeys, bytes[] memory receiverDataValues) = LSP5Utils
44
- .addMapAndArrayKey(
45
- IERC725Y(msg.sender),
46
- arrayLengthKey,
47
- mapKey,
48
- caller,
49
- interfaceID
50
- );
51
-
52
- IERC725Y(msg.sender).setData(receiverDataKeys, receiverDataValues);
53
- } else {
54
- // if there is no map value for the asset to remove, then do nothing
55
- if (bytes12(mapValue) == bytes12(0)) return "";
56
-
57
- // if the amount sent is not the full balance, then do not remove the keys
58
- uint256 balance = ILSP7DigitalAsset(caller).balanceOf(msg.sender);
59
- if (balance != 0) return "";
60
-
61
- (bytes32[] memory senderDataKeys, bytes[] memory senderDataValues) = LSP5Utils
62
- .removeMapAndArrayKey(
63
- IERC725Y(msg.sender),
64
- arrayLengthKey,
65
- mapPrefix,
66
- mapKey,
67
- mapValue
68
- );
69
-
70
- IERC725Y(msg.sender).setData(senderDataKeys, senderDataValues);
71
- }
72
- }
73
- }
@@ -1,9 +0,0 @@
1
- // SPDX-License-Identifier: Apache-2.0
2
- pragma solidity ^0.8.0;
3
-
4
- /**
5
- * @dev reverts when `value` is not a properly ABI encoded array
6
- * @param value the value to check for an abi-encoded array
7
- * @param valueType the type of the value to check for an abi-encoded array
8
- */
9
- error InvalidABIEncodedArray(bytes value, string valueType);
@@ -1,17 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
-
3
- pragma solidity ^0.8.0;
4
-
5
- // interfaces
6
- import {ILSP7DigitalAsset} from "../ILSP7DigitalAsset.sol";
7
-
8
- /**
9
- * @dev LSP7 extension, adds token supply cap.
10
- */
11
- interface ILSP7CappedSupply is ILSP7DigitalAsset {
12
- /**
13
- * @dev Returns the number of tokens that can be minted
14
- * @return The number of tokens that can be minted
15
- */
16
- function tokenSupplyCap() external view returns (uint256);
17
- }
@@ -1,57 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
-
3
- pragma solidity ^0.8.0;
4
-
5
- // interfaces
6
- import {ILSP7CappedSupply} from "./ILSP7CappedSupply.sol";
7
-
8
- // modules
9
- import {LSP7DigitalAssetCore} from "../LSP7DigitalAssetCore.sol";
10
-
11
- /**
12
- * @dev LSP7 extension, adds token supply cap.
13
- */
14
- abstract contract LSP7CappedSupplyCore is LSP7DigitalAssetCore, ILSP7CappedSupply {
15
- // --- Errors
16
-
17
- error LSP7CappedSupplyRequired();
18
- error LSP7CappedSupplyCannotMintOverCap();
19
-
20
- // --- Storage
21
-
22
- uint256 internal _tokenSupplyCap;
23
-
24
- // --- Token queries
25
-
26
- /**
27
- * @inheritdoc ILSP7CappedSupply
28
- */
29
- function tokenSupplyCap() public view virtual returns (uint256) {
30
- return _tokenSupplyCap;
31
- }
32
-
33
- // --- Transfer functionality
34
-
35
- /**
36
- * @dev Mints `amount` and transfers it to `to`.
37
- *
38
- * Requirements:
39
- *
40
- * - `tokenSupplyCap() - totalSupply()` must be greater than zero.
41
- * - `to` cannot be the zero address.
42
- *
43
- * Emits a {Transfer} event.
44
- */
45
- function _mint(
46
- address to,
47
- uint256 amount,
48
- bool force,
49
- bytes memory data
50
- ) internal virtual override {
51
- if (totalSupply() + amount > tokenSupplyCap()) {
52
- revert LSP7CappedSupplyCannotMintOverCap();
53
- }
54
-
55
- super._mint(to, amount, force, data);
56
- }
57
- }
@@ -1,111 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
-
3
- pragma solidity ^0.8.0;
4
-
5
- // interfaces
6
- import {ILSP7DigitalAsset} from "../ILSP7DigitalAsset.sol";
7
- import {ILSP7CompatibleERC20} from "./ILSP7CompatibleERC20.sol";
8
-
9
- // modules
10
- import {LSP4Compatibility} from "../../LSP4DigitalAssetMetadata/LSP4Compatibility.sol";
11
- import {LSP7DigitalAssetCore} from "../LSP7DigitalAssetCore.sol";
12
-
13
- /**
14
- * @dev LSP7 extension, for compatibility for clients / tools that expect ERC20.
15
- */
16
- abstract contract LSP7CompatibleERC20Core is
17
- LSP4Compatibility,
18
- LSP7DigitalAssetCore,
19
- ILSP7CompatibleERC20
20
- {
21
- // --- Overrides
22
-
23
- /**
24
- * @inheritdoc ILSP7CompatibleERC20
25
- */
26
- function approve(address operator, uint256 amount) public virtual returns (bool) {
27
- authorizeOperator(operator, amount);
28
- return true;
29
- }
30
-
31
- /**
32
- * @inheritdoc ILSP7CompatibleERC20
33
- */
34
- function allowance(address tokenOwner, address operator)
35
- public
36
- view
37
- virtual
38
- returns (uint256)
39
- {
40
- return authorizedAmountFor(operator, tokenOwner);
41
- }
42
-
43
- /**
44
- * @inheritdoc ILSP7CompatibleERC20
45
- * @dev Compatible with ERC20 transfer.
46
- * Using force=true so that EOA and any contract may receive the tokens.
47
- */
48
- function transfer(address to, uint256 amount) public virtual override returns (bool) {
49
- transfer(msg.sender, to, amount, true, "");
50
- return true;
51
- }
52
-
53
- /**
54
- * @inheritdoc ILSP7CompatibleERC20
55
- * @dev Compatible with ERC20 transferFrom.
56
- * Using force=true so that EOA and any contract may receive the tokens.
57
- */
58
- function transferFrom(
59
- address from,
60
- address to,
61
- uint256 amount
62
- ) public virtual returns (bool) {
63
- transfer(from, to, amount, true, "");
64
- return true;
65
- }
66
-
67
- function authorizeOperator(address operator, uint256 amount)
68
- public
69
- virtual
70
- override(ILSP7DigitalAsset, LSP7DigitalAssetCore)
71
- {
72
- super.authorizeOperator(operator, amount);
73
-
74
- emit Approval(msg.sender, operator, amount);
75
- }
76
-
77
- // --- Internals
78
-
79
- function _transfer(
80
- address from,
81
- address to,
82
- uint256 amount,
83
- bool force,
84
- bytes memory data
85
- ) internal virtual override {
86
- super._transfer(from, to, amount, force, data);
87
-
88
- emit Transfer(from, to, amount);
89
- }
90
-
91
- function _mint(
92
- address to,
93
- uint256 amount,
94
- bool force,
95
- bytes memory data
96
- ) internal virtual override {
97
- super._mint(to, amount, force, data);
98
-
99
- emit Transfer(address(0), to, amount);
100
- }
101
-
102
- function _burn(
103
- address from,
104
- uint256 amount,
105
- bytes memory data
106
- ) internal virtual override {
107
- super._burn(from, amount, data);
108
-
109
- emit Transfer(from, address(0), amount);
110
- }
111
- }
@@ -1,17 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
-
3
- pragma solidity ^0.8.0;
4
-
5
- // interfaces
6
- import {ILSP8IdentifiableDigitalAsset} from "../ILSP8IdentifiableDigitalAsset.sol";
7
-
8
- /**
9
- * @dev LSP8 extension, adds token supply cap.
10
- */
11
- interface ILSP8CappedSupply is ILSP8IdentifiableDigitalAsset {
12
- /**
13
- * @dev Returns the number of tokens that can be minted.
14
- * @return The token max supply
15
- */
16
- function tokenSupplyCap() external view returns (uint256);
17
- }
@@ -1,17 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
-
3
- pragma solidity ^0.8.0;
4
-
5
- // interfaces
6
- import {ILSP8IdentifiableDigitalAsset} from "../ILSP8IdentifiableDigitalAsset.sol";
7
-
8
- /**
9
- * @dev LSP8 extension, adds access to a token id by an index.
10
- */
11
- interface ILSP8Enumerable is ILSP8IdentifiableDigitalAsset {
12
- /**
13
- * @dev Returns a token id at index. See totalSupply() to get total number of minted tokens.
14
- * @return TokenId or 0x00 if no token exist at the index `index`
15
- */
16
- function tokenAt(uint256 index) external view returns (bytes32);
17
- }
@@ -1,58 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
-
3
- pragma solidity ^0.8.0;
4
-
5
- // interfaces
6
- import {ILSP8CappedSupply} from "./ILSP8CappedSupply.sol";
7
-
8
- // modules
9
- import {LSP8IdentifiableDigitalAssetCore} from "../LSP8IdentifiableDigitalAssetCore.sol";
10
-
11
- /**
12
- * @dev LSP8 extension, adds token supply cap.
13
- */
14
- abstract contract LSP8CappedSupplyCore is LSP8IdentifiableDigitalAssetCore, ILSP8CappedSupply {
15
- // --- Errors
16
-
17
- error LSP8CappedSupplyRequired();
18
- error LSP8CappedSupplyCannotMintOverCap();
19
-
20
- // --- Storage
21
-
22
- uint256 internal _tokenSupplyCap;
23
-
24
- // --- Token queries
25
-
26
- /**
27
- * @inheritdoc ILSP8CappedSupply
28
- */
29
- function tokenSupplyCap() public view virtual returns (uint256) {
30
- return _tokenSupplyCap;
31
- }
32
-
33
- // --- Transfer functionality
34
-
35
- /**
36
- * @dev Mints `tokenId` and transfers it to `to`.
37
- *
38
- * Requirements:
39
- *
40
- * - `tokenSupplyCap() - totalSupply()` must be greater than zero.
41
- * - `tokenId` must not exist.
42
- * - `to` cannot be the zero address.
43
- *
44
- * Emits a {Transfer} event.
45
- */
46
- function _mint(
47
- address to,
48
- bytes32 tokenId,
49
- bool force,
50
- bytes memory data
51
- ) internal virtual override {
52
- if (totalSupply() + 1 > tokenSupplyCap()) {
53
- revert LSP8CappedSupplyCannotMintOverCap();
54
- }
55
-
56
- super._mint(to, tokenId, force, data);
57
- }
58
- }
@@ -1,6 +0,0 @@
1
- // SPDX-License-Identifier: CC0-1.0
2
- pragma solidity ^0.8.0;
3
-
4
- // --- ERC165 interface ids
5
- bytes4 constant _INTERFACEID_ERC721 = 0x80ac58cd;
6
- bytes4 constant _INTERFACEID_ERC721METADATA = 0x5b5e139f;
@@ -1,211 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
-
3
- pragma solidity ^0.8.0;
4
-
5
- // interfaces
6
- import {ILSP8IdentifiableDigitalAsset} from "../ILSP8IdentifiableDigitalAsset.sol";
7
- import {ILSP8CompatibleERC721} from "./ILSP8CompatibleERC721.sol";
8
-
9
- // libraries
10
- import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
11
- import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol";
12
-
13
- // modules
14
- import {LSP4Compatibility} from "../../LSP4DigitalAssetMetadata/LSP4Compatibility.sol";
15
- import {LSP8IdentifiableDigitalAssetCore} from "../LSP8IdentifiableDigitalAssetCore.sol";
16
-
17
- // errors
18
- import "../LSP8Errors.sol";
19
-
20
- // constants
21
- import {_LSP4_METADATA_KEY} from "../../LSP4DigitalAssetMetadata/LSP4Constants.sol";
22
-
23
- /**
24
- * @dev LSP8 extension, for compatibility for clients / tools that expect ERC721.
25
- */
26
- abstract contract LSP8CompatibleERC721Core is
27
- LSP4Compatibility,
28
- LSP8IdentifiableDigitalAssetCore,
29
- ILSP8CompatibleERC721
30
- {
31
- using EnumerableSet for EnumerableSet.AddressSet;
32
-
33
- /**
34
- * Mapping from owner to operator approvals
35
- * @dev for backward compatibility with ERC721
36
- */
37
- mapping(address => mapping(address => bool)) private _operatorApprovals;
38
-
39
- /*
40
- * @inheritdoc ILSP8CompatibleERC721
41
- */
42
- function tokenURI(
43
- uint256 tokenId // solhint-disable no-unused-vars
44
- ) public view virtual returns (string memory) {
45
- bytes memory data = _getData(_LSP4_METADATA_KEY);
46
-
47
- // offset = bytes4(hashSig) + bytes32(contentHash) -> 4 + 32 = 36
48
- uint256 offset = 36;
49
-
50
- bytes memory uriBytes = BytesLib.slice(data, offset, data.length - offset);
51
- return string(uriBytes);
52
- }
53
-
54
- /**
55
- * @inheritdoc ILSP8CompatibleERC721
56
- */
57
- function ownerOf(uint256 tokenId) public view virtual returns (address) {
58
- return tokenOwnerOf(bytes32(tokenId));
59
- }
60
-
61
- /**
62
- * @inheritdoc ILSP8CompatibleERC721
63
- */
64
- function approve(address operator, uint256 tokenId) public virtual {
65
- authorizeOperator(operator, bytes32(tokenId));
66
-
67
- emit Approval(tokenOwnerOf(bytes32(tokenId)), operator, tokenId);
68
- }
69
-
70
- function setApprovalForAll(address operator, bool approved) public virtual {
71
- _setApprovalForAll(msg.sender, operator, approved);
72
- }
73
-
74
- /**
75
- * @inheritdoc ILSP8CompatibleERC721
76
- */
77
- function getApproved(uint256 tokenId) public view virtual returns (address) {
78
- bytes32 tokenIdAsBytes32 = bytes32(tokenId);
79
- _existsOrError(tokenIdAsBytes32);
80
-
81
- EnumerableSet.AddressSet storage operatorsForTokenId = _operators[tokenIdAsBytes32];
82
- uint256 operatorListLength = operatorsForTokenId.length();
83
-
84
- if (operatorListLength == 0) {
85
- return address(0);
86
- } else {
87
- // Read the last added operator authorized to provide "best" compatibility.
88
- // In ERC721 there is one operator address at a time for a tokenId, so multiple calls to
89
- // `approve` would cause `getApproved` to return the last added operator. In this
90
- // compatibility version the same is true, when the authorized operators were not previously
91
- // authorized. If addresses are removed, then `getApproved` returned address can change due
92
- // to implementation of `EnumberableSet._remove`.
93
- return operatorsForTokenId.at(operatorListLength - 1);
94
- }
95
- }
96
-
97
- /*
98
- * @inheritdoc ILSP8CompatibleERC721
99
- */
100
- function isApprovedForAll(address tokenOwner, address operator)
101
- public
102
- view
103
- virtual
104
- returns (bool)
105
- {
106
- return _operatorApprovals[tokenOwner][operator];
107
- }
108
-
109
- /**
110
- * @inheritdoc ILSP8CompatibleERC721
111
- * @dev Compatible with ERC721 transferFrom.
112
- * Using force=true so that EOA and any contract may receive the tokenId.
113
- */
114
- function transferFrom(
115
- address from,
116
- address to,
117
- uint256 tokenId
118
- ) public virtual {
119
- return _transfer(from, to, bytes32(tokenId), true, "");
120
- }
121
-
122
- /**
123
- * @inheritdoc ILSP8CompatibleERC721
124
- * @dev Compatible with ERC721 safeTransferFrom.
125
- * Using force=false so that no EOA and only contracts supporting LSP1 interface may receive the tokenId.
126
- */
127
- function safeTransferFrom(
128
- address from,
129
- address to,
130
- uint256 tokenId
131
- ) public virtual {
132
- return _transfer(from, to, bytes32(tokenId), false, "");
133
- }
134
-
135
- /*
136
- * @dev Compatible with ERC721 safeTransferFrom.
137
- * Using force=false so that no EOA and only contracts supporting LSP1 interface may receive the tokenId.
138
- */
139
- function safeTransferFrom(
140
- address from,
141
- address to,
142
- uint256 tokenId,
143
- bytes memory data
144
- ) public virtual {
145
- return _transfer(from, to, bytes32(tokenId), false, data);
146
- }
147
-
148
- // --- Overrides
149
-
150
- function authorizeOperator(address operator, bytes32 tokenId)
151
- public
152
- virtual
153
- override(ILSP8IdentifiableDigitalAsset, LSP8IdentifiableDigitalAssetCore)
154
- {
155
- super.authorizeOperator(operator, tokenId);
156
-
157
- emit Approval(tokenOwnerOf(tokenId), operator, uint256(tokenId));
158
- }
159
-
160
- function _transfer(
161
- address from,
162
- address to,
163
- bytes32 tokenId,
164
- bool force,
165
- bytes memory data
166
- ) internal virtual override {
167
- address operator = msg.sender;
168
-
169
- if (!isApprovedForAll(from, operator) && !_isOperatorOrOwner(operator, tokenId)) {
170
- revert LSP8NotTokenOperator(tokenId, operator);
171
- }
172
-
173
- super._transfer(from, to, tokenId, force, data);
174
-
175
- emit Transfer(from, to, uint256(tokenId));
176
- }
177
-
178
- function _mint(
179
- address to,
180
- bytes32 tokenId,
181
- bool force,
182
- bytes memory data
183
- ) internal virtual override {
184
- super._mint(to, tokenId, force, data);
185
-
186
- emit Transfer(address(0), to, uint256(tokenId));
187
- }
188
-
189
- function _burn(bytes32 tokenId, bytes memory data) internal virtual override {
190
- address tokenOwner = tokenOwnerOf(tokenId);
191
-
192
- super._burn(tokenId, data);
193
-
194
- emit Transfer(tokenOwner, address(0), uint256(tokenId));
195
- }
196
-
197
- /**
198
- * @dev Approve `operator` to operate on all of `owner` tokens
199
- *
200
- * Emits an {ApprovalForAll} event.
201
- */
202
- function _setApprovalForAll(
203
- address tokensOwner,
204
- address operator,
205
- bool approved
206
- ) internal virtual {
207
- require(tokensOwner != operator, "LSP8CompatibleERC721: approve to caller");
208
- _operatorApprovals[tokensOwner][operator] = approved;
209
- emit ApprovalForAll(tokensOwner, operator, approved);
210
- }
211
- }