@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
@@ -21,7 +21,7 @@ contract LSP6KeyManagerInit is LSP6KeyManagerInitAbstract {
21
21
  * @notice Initiate the account with the address of the ERC725Account contract and sets LSP6KeyManager InterfaceId
22
22
  * @param target_ The address of the ER725Account to control
23
23
  */
24
- function initialize(address target_) public virtual initializer {
24
+ function initialize(address target_) external virtual initializer {
25
25
  LSP6KeyManagerInitAbstract._initialize(target_);
26
26
  }
27
27
  }
@@ -3,7 +3,7 @@ pragma solidity ^0.8.5;
3
3
 
4
4
  // modules
5
5
  import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
6
- import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
6
+ import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
7
7
  import {LSP6KeyManagerCore} from "./LSP6KeyManagerCore.sol";
8
8
  import {InvalidLSP6Target} from "./LSP6Errors.sol";
9
9
 
@@ -15,6 +15,7 @@ import {InvalidLSP6Target} from "./LSP6Errors.sol";
15
15
  abstract contract LSP6KeyManagerInitAbstract is Initializable, LSP6KeyManagerCore {
16
16
  function _initialize(address target_) internal virtual onlyInitializing {
17
17
  if (target_ == address(0)) revert InvalidLSP6Target();
18
- target = target_;
18
+ _target = target_;
19
+ _setupLSP6ReentrancyGuard();
19
20
  }
20
21
  }
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
- pragma solidity ^0.8.0;
2
+ pragma solidity ^0.8.4;
3
3
 
4
4
  // interfaces
5
5
  import {IERC725Y} from "@erc725/smart-contracts/contracts/interfaces/IERC725Y.sol";
@@ -15,6 +15,12 @@ import "../LSP6KeyManager/LSP6Constants.sol";
15
15
  library LSP6Utils {
16
16
  using LSP2Utils for bytes12;
17
17
 
18
+ /**
19
+ * @dev read the permissions of a `caller` on an ERC725Y `target` contract.
20
+ * @param target an `IERC725Y` contract where to read the permissions.
21
+ * @param caller the controller address to read the permissions from.
22
+ * @return a `bytes32` BitArray containing the permissions of a controller address.
23
+ */
18
24
  function getPermissionsFor(IERC725Y target, address caller) internal view returns (bytes32) {
19
25
  bytes memory permissions = target.getData(
20
26
  LSP2Utils.generateMappingWithGroupingKey(
@@ -26,21 +32,7 @@ library LSP6Utils {
26
32
  return bytes32(permissions);
27
33
  }
28
34
 
29
- function getAllowedAddressesFor(IERC725Y target, address caller)
30
- internal
31
- view
32
- returns (bytes memory)
33
- {
34
- return
35
- target.getData(
36
- LSP2Utils.generateMappingWithGroupingKey(
37
- _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDADDRESSES_PREFIX,
38
- bytes20(caller)
39
- )
40
- );
41
- }
42
-
43
- function getAllowedFunctionsFor(IERC725Y target, address caller)
35
+ function getAllowedCallsFor(IERC725Y target, address from)
44
36
  internal
45
37
  view
46
38
  returns (bytes memory)
@@ -48,27 +40,19 @@ library LSP6Utils {
48
40
  return
49
41
  target.getData(
50
42
  LSP2Utils.generateMappingWithGroupingKey(
51
- _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDFUNCTIONS_PREFIX,
52
- bytes20(caller)
43
+ _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDCALLS_PREFIX,
44
+ bytes20(from)
53
45
  )
54
46
  );
55
47
  }
56
48
 
57
- function getAllowedStandardsFor(IERC725Y target, address caller)
58
- internal
59
- view
60
- returns (bytes memory)
61
- {
62
- return
63
- target.getData(
64
- LSP2Utils.generateMappingWithGroupingKey(
65
- _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDSTANDARDS_PREFIX,
66
- bytes20(caller)
67
- )
68
- );
69
- }
70
-
71
- function getAllowedERC725YKeysFor(IERC725Y target, address caller)
49
+ /**
50
+ * @dev read the Allowed ERC725Y data keys of a `caller` on an ERC725Y `target` contract.
51
+ * @param target an `IERC725Y` contract where to read the permissions.
52
+ * @param caller the controller address to read the permissions from.
53
+ * @return an abi-encoded array of allowed ERC725 keys that the controller address is allowed to interact with.
54
+ */
55
+ function getAllowedERC725YDataKeysFor(IERC725Y target, address caller)
72
56
  internal
73
57
  view
74
58
  returns (bytes memory)
@@ -76,7 +60,7 @@ library LSP6Utils {
76
60
  return
77
61
  target.getData(
78
62
  LSP2Utils.generateMappingWithGroupingKey(
79
- _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDERC725YKEYS_PREFIX,
63
+ _LSP6KEY_ADDRESSPERMISSIONS_AllowedERC725YDataKeys_PREFIX,
80
64
  bytes20(caller)
81
65
  )
82
66
  );
@@ -97,6 +81,72 @@ library LSP6Utils {
97
81
  return (addressPermission & permissionToCheck) == permissionToCheck;
98
82
  }
99
83
 
84
+ /**
85
+ * @dev same as LSP2Utils.isCompactBytesArray with the additional requirement that each element must be 28 bytes long.
86
+ *
87
+ * @param allowedCallsCompacted a compact bytes array of tuples (bytes4,address,bytes4) to check.
88
+ * @return true if the value passed is a valid compact bytes array of bytes28 elements according to LSP2, false otherwise.
89
+ */
90
+ function isCompactBytesArrayOfAllowedCalls(bytes memory allowedCallsCompacted)
91
+ internal
92
+ pure
93
+ returns (bool)
94
+ {
95
+ uint256 pointer;
96
+
97
+ while (pointer < allowedCallsCompacted.length) {
98
+ if (pointer + 1 >= allowedCallsCompacted.length) return false;
99
+ uint256 elementLength = uint16(
100
+ bytes2(
101
+ abi.encodePacked(
102
+ allowedCallsCompacted[pointer],
103
+ allowedCallsCompacted[pointer + 1]
104
+ )
105
+ )
106
+ );
107
+ // each entries in the allowedCalls (compact) array must be 28 bytes long
108
+ if (elementLength != 28) return false;
109
+ pointer += elementLength + 2;
110
+ }
111
+ if (pointer == allowedCallsCompacted.length) return true;
112
+ return false;
113
+ }
114
+
115
+ /**
116
+ * @dev same as LSP2Utils.isCompactBytesArray with the additional requirement that each element must be from 1 to 32 bytes long.
117
+ *
118
+ * @param allowedERC725YDataKeysCompacted a compact bytes array of ERC725Y Data Keys (full bytes32 data keys or bytesN prefix) to check.
119
+ * @return true if the value passed is a valid compact bytes array of ERC725Y Data Keys, false otherwise.
120
+ */
121
+ function isCompactBytesArrayOfAllowedERC725YDataKeys(
122
+ bytes memory allowedERC725YDataKeysCompacted
123
+ ) internal pure returns (bool) {
124
+ uint256 pointer;
125
+
126
+ while (pointer < allowedERC725YDataKeysCompacted.length) {
127
+ if (pointer + 1 >= allowedERC725YDataKeysCompacted.length) return false;
128
+ uint256 elementLength = uint16(
129
+ bytes2(
130
+ abi.encodePacked(
131
+ allowedERC725YDataKeysCompacted[pointer],
132
+ allowedERC725YDataKeysCompacted[pointer + 1]
133
+ )
134
+ )
135
+ );
136
+ // the length of the allowed data key must be not under 33 bytes and not 0
137
+ if (elementLength == 0 || elementLength > 32) return false;
138
+ pointer += elementLength + 2;
139
+ }
140
+ if (pointer == allowedERC725YDataKeysCompacted.length) return true;
141
+ return false;
142
+ }
143
+
144
+ /**
145
+ * @dev use the `setData(bytes32[],bytes[])` via the KeyManager of the target
146
+ * @param keyManagerAddress the address of the KeyManager
147
+ * @param keys the array of data keys
148
+ * @param values the array of data values
149
+ */
100
150
  function setDataViaKeyManager(
101
151
  address keyManagerAddress,
102
152
  bytes32[] memory keys,
@@ -105,4 +155,45 @@ library LSP6Utils {
105
155
  bytes memory payload = abi.encodeWithSelector(SETDATA_ARRAY_SELECTOR, keys, values);
106
156
  result = ILSP6KeyManager(keyManagerAddress).execute(payload);
107
157
  }
158
+
159
+ /**
160
+ * @dev combine multiple permissions into a single bytes32
161
+ * Make sure that the sum of the values of the input array is less than 2^256-1 to avoid overflow.
162
+ * @param _permissions the array of permissions to combine
163
+ * @return a bytes32 containing the combined permissions
164
+ */
165
+ function combinePermissions(bytes32[] memory _permissions) internal pure returns (bytes32) {
166
+ uint256 result = 0;
167
+ for (uint256 i = 0; i < _permissions.length; i++) {
168
+ result += uint256(_permissions[i]);
169
+ }
170
+ return bytes32(result);
171
+ }
172
+
173
+ function generatePermissionsKeysForController(
174
+ IERC725Y _account,
175
+ address _address,
176
+ bytes32 permissions
177
+ ) internal view returns (bytes32[] memory keys, bytes[] memory values) {
178
+ keys = new bytes32[](3);
179
+ values = new bytes[](3);
180
+
181
+ uint256 arrayLength = uint256(bytes32(_account.getData(_LSP6KEY_ADDRESSPERMISSIONS_ARRAY)));
182
+ uint256 newArrayLength = arrayLength + 1;
183
+
184
+ keys[0] = _LSP6KEY_ADDRESSPERMISSIONS_ARRAY;
185
+ values[0] = abi.encodePacked(newArrayLength);
186
+
187
+ keys[1] = LSP2Utils.generateArrayElementKeyAtIndex(
188
+ _LSP6KEY_ADDRESSPERMISSIONS_ARRAY,
189
+ uint128(arrayLength)
190
+ );
191
+ values[1] = abi.encodePacked(_address);
192
+
193
+ keys[2] = LSP2Utils.generateMappingWithGroupingKey(
194
+ _LSP6KEY_ADDRESSPERMISSIONS_PERMISSIONS_PREFIX,
195
+ bytes20(_address)
196
+ );
197
+ values[2] = abi.encodePacked(permissions);
198
+ }
108
199
  }
@@ -1,6 +1,6 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
 
3
- pragma solidity ^0.8.0;
3
+ pragma solidity ^0.8.4;
4
4
 
5
5
  // interfaces
6
6
  import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
@@ -18,7 +18,7 @@ interface ILSP7DigitalAsset is IERC165, IERC725Y {
18
18
  * @param from The address which tokens are sent
19
19
  * @param to The receiving address
20
20
  * @param amount The amount of tokens transferred
21
- * @param force When set to TRUE, `to` may be any address but
21
+ * @param allowNonLSP1Recipient When set to TRUE, `to` may be any address but
22
22
  * when set to FALSE `to` must be a contract that supports LSP1 UniversalReceiver
23
23
  * @param data Additional data the caller wants included in the emitted event, and sent in the hooks to `from` and `to` addresses
24
24
  */
@@ -27,7 +27,7 @@ interface ILSP7DigitalAsset is IERC165, IERC725Y {
27
27
  address indexed from,
28
28
  address indexed to,
29
29
  uint256 amount,
30
- bool force,
30
+ bool allowNonLSP1Recipient,
31
31
  bytes data
32
32
  );
33
33
 
@@ -137,11 +137,11 @@ interface ILSP7DigitalAsset is IERC165, IERC725Y {
137
137
  * @param from The sending address.
138
138
  * @param to The receiving address.
139
139
  * @param amount The amount of tokens to transfer.
140
- * @param force When set to TRUE, to may be any address but
140
+ * @param allowNonLSP1Recipient When set to TRUE, to may be any address but
141
141
  * when set to FALSE to must be a contract that supports LSP1 UniversalReceiver
142
142
  * @param data Additional data the caller wants included in the emitted event, and sent in the hooks to `from` and `to` addresses.
143
143
  *
144
- * @dev Transfers `amount` of tokens from `from` to `to`. The `force` parameter will be used
144
+ * @dev Transfers `amount` of tokens from `from` to `to`. The `allowNonLSP1Recipient` parameter will be used
145
145
  * when notifying the token sender and receiver.
146
146
  *
147
147
  * Requirements:
@@ -158,7 +158,7 @@ interface ILSP7DigitalAsset is IERC165, IERC725Y {
158
158
  address from,
159
159
  address to,
160
160
  uint256 amount,
161
- bool force,
161
+ bool allowNonLSP1Recipient,
162
162
  bytes memory data
163
163
  ) external;
164
164
 
@@ -166,7 +166,7 @@ interface ILSP7DigitalAsset is IERC165, IERC725Y {
166
166
  * @param from The list of sending addresses.
167
167
  * @param to The list of receiving addresses.
168
168
  * @param amount The amount of tokens to transfer.
169
- * @param force When set to TRUE, to may be any address but
169
+ * @param allowNonLSP1Recipient When set to TRUE, to may be any address but
170
170
  * when set to FALSE to must be a contract that supports LSP1 UniversalReceiver
171
171
  * @param data Additional data the caller wants included in the emitted event, and sent in the hooks to `from` and `to` addresses.
172
172
  *
@@ -188,7 +188,7 @@ interface ILSP7DigitalAsset is IERC165, IERC725Y {
188
188
  address[] memory from,
189
189
  address[] memory to,
190
190
  uint256[] memory amount,
191
- bool force,
191
+ bool[] memory allowNonLSP1Recipient,
192
192
  bytes[] memory data
193
193
  ) external;
194
194
  }
@@ -1,13 +1,13 @@
1
1
  // SPDX-License-Identifier: CC0-1.0
2
- pragma solidity ^0.8.0;
2
+ pragma solidity ^0.8.4;
3
3
 
4
4
  // --- ERC165 interface ids
5
- bytes4 constant _INTERFACEID_LSP7 = 0x5fcaac27;
5
+ bytes4 constant _INTERFACEID_LSP7 = 0xda1f85e4;
6
6
 
7
7
  // --- Token Hooks
8
8
 
9
- // keccak256('LSP7TokensSender')
10
- bytes32 constant _TYPEID_LSP7_TOKENSSENDER = 0x40b8bec57d7b5ff0dbd9e9acd0a47dfeb0101e1a203766f5ccab00445fbf39e9;
9
+ // keccak256('LSP7Tokens_SenderNotification')
10
+ bytes32 constant _TYPEID_LSP7_TOKENSSENDER = 0x429ac7a06903dbc9c13dfcb3c9d11df8194581fa047c96d7a4171fc7402958ea;
11
11
 
12
- // keccak256('LSP7TokensRecipient')
13
- bytes32 constant _TYPEID_LSP7_TOKENSRECIPIENT = 0xdbe2c314e1aee2970c72666f2ebe8933a8575263ea71e5ff6a9178e95d47a26f;
12
+ // keccak256('LSP7Tokens_RecipientNotification')
13
+ bytes32 constant _TYPEID_LSP7_TOKENSRECIPIENT = 0x20804611b3e2ea21c480dc465142210acf4a2485947541770ec1fb87dee4a55c;
@@ -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,13 +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 {ILSP7DigitalAsset} from "./ILSP7DigitalAsset.sol";
7
7
 
8
8
  // libraries
9
+ import {Address} from "@openzeppelin/contracts/utils/Address.sol";
10
+ import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
9
11
  import {GasLib} from "../Utils/GasLib.sol";
10
- import {ERC165Checker} from "../Custom/ERC165Checker.sol";
11
12
 
12
13
  // modules
13
14
  import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
@@ -29,6 +30,8 @@ import {_TYPEID_LSP7_TOKENSSENDER, _TYPEID_LSP7_TOKENSRECIPIENT} from "./LSP7Con
29
30
  * This contract implement the core logic of the functions for the {ILSP7DigitalAsset} interface.
30
31
  */
31
32
  abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
33
+ using Address for address;
34
+
32
35
  // --- Storage
33
36
 
34
37
  bool internal _isNonDivisible;
@@ -46,14 +49,14 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
46
49
  /**
47
50
  * @inheritdoc ILSP7DigitalAsset
48
51
  */
49
- function decimals() public view returns (uint8) {
52
+ function decimals() public view virtual returns (uint8) {
50
53
  return _isNonDivisible ? 0 : 18;
51
54
  }
52
55
 
53
56
  /**
54
57
  * @inheritdoc ILSP7DigitalAsset
55
58
  */
56
- function totalSupply() public view returns (uint256) {
59
+ function totalSupply() public view virtual returns (uint256) {
57
60
  return _existingTokens;
58
61
  }
59
62
 
@@ -62,7 +65,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
62
65
  /**
63
66
  * @inheritdoc ILSP7DigitalAsset
64
67
  */
65
- function balanceOf(address tokenOwner) public view returns (uint256) {
68
+ function balanceOf(address tokenOwner) public view virtual returns (uint256) {
66
69
  return _tokenOwnerBalances[tokenOwner];
67
70
  }
68
71
 
@@ -117,7 +120,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
117
120
  address from,
118
121
  address to,
119
122
  uint256 amount,
120
- bool force,
123
+ bool allowNonLSP1Recipient,
121
124
  bytes memory data
122
125
  ) public virtual {
123
126
  if (from == to) revert LSP7CannotSendToSelf();
@@ -132,7 +135,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
132
135
  _updateOperator(from, operator, operatorAmount - amount);
133
136
  }
134
137
 
135
- _transfer(from, to, amount, force, data);
138
+ _transfer(from, to, amount, allowNonLSP1Recipient, data);
136
139
  }
137
140
 
138
141
  /**
@@ -142,18 +145,22 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
142
145
  address[] memory from,
143
146
  address[] memory to,
144
147
  uint256[] memory amount,
145
- bool force,
148
+ bool[] memory allowNonLSP1Recipient,
146
149
  bytes[] memory data
147
150
  ) public virtual {
151
+ uint256 fromLength = from.length;
148
152
  if (
149
- from.length != to.length || from.length != amount.length || from.length != data.length
153
+ fromLength != to.length ||
154
+ fromLength != amount.length ||
155
+ fromLength != allowNonLSP1Recipient.length ||
156
+ fromLength != data.length
150
157
  ) {
151
158
  revert LSP7InvalidTransferBatch();
152
159
  }
153
160
 
154
- for (uint256 i = 0; i < from.length; i = GasLib.uncheckedIncrement(i)) {
161
+ for (uint256 i = 0; i < fromLength; i = GasLib.uncheckedIncrement(i)) {
155
162
  // using the public transfer function to handle updates to operator authorized amounts
156
- transfer(from[i], to[i], amount[i], force, data[i]);
163
+ transfer(from[i], to[i], amount[i], allowNonLSP1Recipient[i], data[i]);
157
164
  }
158
165
  }
159
166
 
@@ -205,7 +212,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
205
212
  function _mint(
206
213
  address to,
207
214
  uint256 amount,
208
- bool force,
215
+ bool allowNonLSP1Recipient,
209
216
  bytes memory data
210
217
  ) internal virtual {
211
218
  if (to == address(0)) {
@@ -216,11 +223,14 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
216
223
 
217
224
  _beforeTokenTransfer(address(0), to, amount);
218
225
 
226
+ // tokens being minted
227
+ _existingTokens += amount;
228
+
219
229
  _tokenOwnerBalances[to] += amount;
220
230
 
221
- emit Transfer(operator, address(0), to, amount, force, data);
231
+ emit Transfer(operator, address(0), to, amount, allowNonLSP1Recipient, data);
222
232
 
223
- _notifyTokenReceiver(address(0), to, amount, force, data);
233
+ _notifyTokenReceiver(address(0), to, amount, allowNonLSP1Recipient, data);
224
234
  }
225
235
 
226
236
  /**
@@ -260,6 +270,9 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
260
270
 
261
271
  _beforeTokenTransfer(from, address(0), amount);
262
272
 
273
+ // tokens being burned
274
+ _existingTokens -= amount;
275
+
263
276
  _tokenOwnerBalances[from] -= amount;
264
277
 
265
278
  emit Transfer(operator, from, address(0), amount, false, data);
@@ -284,7 +297,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
284
297
  address from,
285
298
  address to,
286
299
  uint256 amount,
287
- bool force,
300
+ bool allowNonLSP1Recipient,
288
301
  bytes memory data
289
302
  ) internal virtual {
290
303
  if (from == address(0) || to == address(0)) {
@@ -303,10 +316,10 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
303
316
  _tokenOwnerBalances[from] -= amount;
304
317
  _tokenOwnerBalances[to] += amount;
305
318
 
306
- emit Transfer(operator, from, to, amount, force, data);
319
+ emit Transfer(operator, from, to, amount, allowNonLSP1Recipient, data);
307
320
 
308
321
  _notifyTokenSender(from, to, amount, data);
309
- _notifyTokenReceiver(from, to, amount, force, data);
322
+ _notifyTokenReceiver(from, to, amount, allowNonLSP1Recipient, data);
310
323
  }
311
324
 
312
325
  /**
@@ -319,22 +332,13 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
319
332
  * transferred to `to`.
320
333
  * - When `from` is zero, `amount` tokens will be minted for `to`.
321
334
  * - When `to` is zero, ``from``'s `amount` tokens will be burned.
335
+ * - `from` and `to` are never both zero.
322
336
  */
323
337
  function _beforeTokenTransfer(
324
338
  address from,
325
339
  address to,
326
340
  uint256 amount
327
- ) internal virtual {
328
- // tokens being minted
329
- if (from == address(0)) {
330
- _existingTokens += amount;
331
- }
332
-
333
- // tokens being burned
334
- if (to == address(0)) {
335
- _existingTokens -= amount;
336
- }
337
- }
341
+ ) internal virtual {}
338
342
 
339
343
  /**
340
344
  * @dev An attempt is made to notify the token sender about the `amount` tokens changing owners using
@@ -346,7 +350,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
346
350
  uint256 amount,
347
351
  bytes memory data
348
352
  ) internal virtual {
349
- if (ERC165Checker.supportsERC165Interface(from, _INTERFACEID_LSP1)) {
353
+ if (ERC165Checker.supportsERC165InterfaceUnchecked(from, _INTERFACEID_LSP1)) {
350
354
  bytes memory packedData = abi.encodePacked(from, to, amount, data);
351
355
  ILSP1UniversalReceiver(from).universalReceiver(_TYPEID_LSP7_TOKENSSENDER, packedData);
352
356
  }
@@ -354,7 +358,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
354
358
 
355
359
  /**
356
360
  * @dev An attempt is made to notify the token receiver about the `amount` tokens changing owners
357
- * using LSP1 interface. When force is FALSE the token receiver MUST support LSP1.
361
+ * using LSP1 interface. When allowNonLSP1Recipient is FALSE the token receiver MUST support LSP1.
358
362
  *
359
363
  * The receiver may revert when the token being sent is not wanted.
360
364
  */
@@ -362,14 +366,14 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
362
366
  address from,
363
367
  address to,
364
368
  uint256 amount,
365
- bool force,
369
+ bool allowNonLSP1Recipient,
366
370
  bytes memory data
367
371
  ) internal virtual {
368
- if (ERC165Checker.supportsERC165Interface(to, _INTERFACEID_LSP1)) {
372
+ if (ERC165Checker.supportsERC165InterfaceUnchecked(to, _INTERFACEID_LSP1)) {
369
373
  bytes memory packedData = abi.encodePacked(from, to, amount, data);
370
374
  ILSP1UniversalReceiver(to).universalReceiver(_TYPEID_LSP7_TOKENSRECIPIENT, packedData);
371
- } else if (!force) {
372
- if (to.code.length != 0) {
375
+ } else if (!allowNonLSP1Recipient) {
376
+ if (to.isContract()) {
373
377
  revert LSP7NotifyTokenReceiverContractMissingLSP1Interface(to);
374
378
  } else {
375
379
  revert LSP7NotifyTokenReceiverIsEOA(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,17 @@
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 sending an `amount` of tokens larger than the current `balance` of the `tokenOwner`.
8
+ */
6
9
  error LSP7AmountExceedsBalance(uint256 balance, address tokenOwner, uint256 amount);
7
10
 
11
+ /**
12
+ * @dev reverts when `operator` of `tokenOwner` send an `amount` of tokens
13
+ * larger than the `authorizedAmount`.
14
+ */
8
15
  error LSP7AmountExceedsAuthorizedAmount(
9
16
  address tokenOwner,
10
17
  uint256 authorizedAmount,
@@ -12,14 +19,34 @@ error LSP7AmountExceedsAuthorizedAmount(
12
19
  uint256 amount
13
20
  );
14
21
 
22
+ /**
23
+ * @dev reverts when trying to set the zero address as an operator.
24
+ */
15
25
  error LSP7CannotUseAddressZeroAsOperator();
16
26
 
27
+ /**
28
+ * @dev reverts when one tries to send tokens to or from the zero address.
29
+ */
17
30
  error LSP7CannotSendWithAddressZero();
18
31
 
32
+ /**
33
+ * @dev reverts when specifying the same address for `from` or `to` in a token transfer.
34
+ */
19
35
  error LSP7CannotSendToSelf();
20
36
 
37
+ /**
38
+ * @dev reverts when the parameters used for `transferBatch` have different lengths.
39
+ */
21
40
  error LSP7InvalidTransferBatch();
22
41
 
42
+ /**
43
+ * @dev reverts if the `tokenReceiver` does not implement LSP1
44
+ * when minting or transferring tokens with `bool allowNonLSP1Recipient` set as `false`.
45
+ */
23
46
  error LSP7NotifyTokenReceiverContractMissingLSP1Interface(address tokenReceiver);
24
47
 
48
+ /**
49
+ * @dev reverts if the `tokenReceiver` is an EOA
50
+ * when minting or transferring tokens with `bool allowNonLSP1Recipient` set as `false`.
51
+ */
25
52
  error LSP7NotifyTokenReceiverIsEOA(address tokenReceiver);
@@ -1,6 +1,6 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
 
3
- pragma solidity ^0.8.0;
3
+ pragma solidity ^0.8.4;
4
4
 
5
5
  // interfaces
6
6
  import {ILSP7DigitalAsset} from "../ILSP7DigitalAsset.sol";
@@ -0,0 +1,24 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.4;
3
+
4
+ // modules
5
+ import {LSP7DigitalAssetCore} from "../LSP7DigitalAssetCore.sol";
6
+
7
+ /**
8
+ * @dev LSP7 extension that allows token holders to destroy both
9
+ * their own tokens and those that they have an allowance for as an operator.
10
+ */
11
+ abstract contract LSP7Burnable is LSP7DigitalAssetCore {
12
+ /**
13
+ * @dev Destroys `amount` tokens from the `from` address.
14
+ *
15
+ * See internal _burn function for more details
16
+ */
17
+ function burn(
18
+ address from,
19
+ uint256 amount,
20
+ bytes memory data
21
+ ) public {
22
+ _burn(from, amount, data);
23
+ }
24
+ }