@lukso/lsp-smart-contracts 0.6.0 → 0.7.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 (140) hide show
  1. package/README.md +13 -12
  2. package/artifacts/Create2Factory.json +2 -2
  3. package/artifacts/LSP0ERC725Account.json +66 -27
  4. package/artifacts/LSP0ERC725AccountInit.json +71 -53
  5. package/artifacts/LSP1UniversalReceiverDelegateUP.json +23 -2
  6. package/artifacts/LSP1UniversalReceiverDelegateVault.json +23 -2
  7. package/artifacts/LSP4Compatibility.json +15 -9
  8. package/artifacts/LSP4DigitalAssetMetadata.json +25 -9
  9. package/artifacts/{LSP4DigitalAssetMetadataInit.json → LSP4DigitalAssetMetadataInitAbstract.json} +27 -60
  10. package/artifacts/LSP6KeyManager.json +93 -13
  11. package/artifacts/LSP6KeyManagerInit.json +98 -13
  12. package/artifacts/LSP7CappedSupply.json +56 -35
  13. package/artifacts/{LSP7CappedSupplyInit.json → LSP7CappedSupplyInitAbstract.json} +58 -104
  14. package/artifacts/LSP7CompatibleERC20.json +704 -0
  15. package/artifacts/LSP7CompatibleERC20InitAbstract.json +717 -0
  16. package/artifacts/LSP7CompatibleERC20Mintable.json +753 -0
  17. package/artifacts/LSP7CompatibleERC20MintableInit.json +773 -0
  18. package/artifacts/LSP7DigitalAsset.json +56 -61
  19. package/artifacts/LSP7DigitalAssetInitAbstract.json +540 -0
  20. package/artifacts/LSP7Mintable.json +59 -38
  21. package/artifacts/LSP7MintableInit.json +64 -64
  22. package/artifacts/LSP8CappedSupply.json +62 -9
  23. package/artifacts/{LSP8CappedSupplyInit.json → LSP8CappedSupplyInitAbstract.json} +64 -73
  24. package/artifacts/LSP8CompatibleERC721.json +907 -0
  25. package/artifacts/LSP8CompatibleERC721InitAbstract.json +920 -0
  26. package/artifacts/LSP8CompatibleERC721Mintable.json +967 -0
  27. package/artifacts/LSP8CompatibleERC721MintableInit.json +987 -0
  28. package/artifacts/LSP8IdentifiableDigitalAsset.json +62 -30
  29. package/artifacts/LSP8IdentifiableDigitalAssetInitAbstract.json +628 -0
  30. package/artifacts/LSP8Mintable.json +64 -11
  31. package/artifacts/LSP8MintableInit.json +69 -37
  32. package/artifacts/LSP9Vault.json +63 -24
  33. package/artifacts/LSP9VaultInit.json +68 -50
  34. package/artifacts/UniversalFactory.json +2 -2
  35. package/artifacts/UniversalProfile.json +66 -27
  36. package/artifacts/UniversalProfileInit.json +71 -53
  37. package/artifacts/UniversalReceiverAddressStore.json +7 -2
  38. package/constants.js +273 -31
  39. package/contracts/Custom/ClaimOwnership.sol +74 -9
  40. package/contracts/Custom/ERC165Checker.sol +1 -1
  41. package/contracts/Custom/IClaimOwnership.sol +3 -1
  42. package/contracts/Factories/Create2Factory.sol +3 -13
  43. package/contracts/Factories/UniversalFactory.sol +20 -16
  44. package/contracts/LSP0ERC725Account/LSP0Constants.sol +1 -1
  45. package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +3 -3
  46. package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +49 -37
  47. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +10 -3
  48. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +3 -3
  49. package/contracts/LSP10ReceivedVaults/LSP10Constants.sol +2 -2
  50. package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiver.sol +3 -0
  51. package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol +4 -2
  52. package/contracts/LSP1UniversalReceiver/LSP1Constants.sol +1 -1
  53. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/Handling/TokenAndVaultHandling.sol +22 -16
  54. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +14 -10
  55. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/Handling/TokenHandling.sol +35 -29
  56. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +10 -3
  57. package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +24 -9
  58. package/contracts/LSP2ERC725YJSONSchema/LSP2Errors.sol +9 -0
  59. package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +157 -75
  60. package/contracts/LSP3UniversalProfile/LSP3Constants.sol +1 -1
  61. package/contracts/LSP4DigitalAssetMetadata/LSP4Constants.sol +1 -1
  62. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol +24 -4
  63. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +26 -5
  64. package/contracts/LSP4DigitalAssetMetadata/LSP4Errors.sol +16 -0
  65. package/contracts/LSP5ReceivedAssets/LSP5Constants.sol +2 -2
  66. package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +151 -77
  67. package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +16 -16
  68. package/contracts/LSP6KeyManager/LSP6Constants.sol +16 -21
  69. package/contracts/LSP6KeyManager/LSP6Errors.sol +42 -5
  70. package/contracts/LSP6KeyManager/LSP6KeyManager.sol +6 -4
  71. package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +293 -284
  72. package/contracts/LSP6KeyManager/LSP6KeyManagerInit.sol +11 -4
  73. package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +5 -3
  74. package/contracts/LSP6KeyManager/LSP6Utils.sol +24 -27
  75. package/contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol +18 -5
  76. package/contracts/LSP7DigitalAsset/LSP7Constants.sol +1 -1
  77. package/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol +8 -4
  78. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +35 -24
  79. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol +5 -3
  80. package/contracts/LSP7DigitalAsset/LSP7Errors.sol +2 -0
  81. package/contracts/LSP7DigitalAsset/extensions/{ILSP7CompatibilityForERC20.sol → ILSP7CompatibleERC20.sol} +6 -6
  82. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyCore.sol +1 -1
  83. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +5 -2
  84. package/contracts/LSP7DigitalAsset/extensions/{LSP7CompatibilityForERC20.sol → LSP7CompatibleERC20.sol} +6 -7
  85. package/contracts/LSP7DigitalAsset/extensions/{LSP7CompatibilityForERC20Core.sol → LSP7CompatibleERC20Core.sol} +23 -19
  86. package/contracts/LSP7DigitalAsset/extensions/{LSP7CompatibilityForERC20InitAbstract.sol → LSP7CompatibleERC20InitAbstract.sol} +11 -10
  87. package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20Mintable.sol +22 -0
  88. package/contracts/{LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721Init.sol → LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInit.sol} +12 -7
  89. package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInitAbstract.sol +27 -0
  90. package/contracts/LSP7DigitalAsset/presets/LSP7Mintable.sol +9 -7
  91. package/contracts/LSP7DigitalAsset/presets/LSP7MintableInit.sol +11 -4
  92. package/contracts/LSP7DigitalAsset/presets/LSP7MintableInitAbstract.sol +8 -7
  93. package/contracts/LSP8IdentifiableDigitalAsset/ILSP8IdentifiableDigitalAsset.sol +3 -1
  94. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Constants.sol +4 -4
  95. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Errors.sol +6 -0
  96. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAsset.sol +1 -1
  97. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +31 -30
  98. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInitAbstract.sol +3 -1
  99. package/contracts/LSP8IdentifiableDigitalAsset/extensions/{ILSP8CompatibilityForERC721.sol → ILSP8CompatibleERC721.sol} +16 -2
  100. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8Enumerable.sol +17 -0
  101. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyCore.sol +1 -1
  102. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +4 -2
  103. package/contracts/LSP8IdentifiableDigitalAsset/extensions/{LSP8CompatibilityConstants.sol → LSP8CompatibleConstants.sol} +0 -0
  104. package/contracts/LSP8IdentifiableDigitalAsset/extensions/{LSP8CompatibilityForERC721.sol → LSP8CompatibleERC721.sol} +12 -11
  105. package/contracts/LSP8IdentifiableDigitalAsset/extensions/{LSP8CompatibilityForERC721Core.sol → LSP8CompatibleERC721Core.sol} +61 -37
  106. package/contracts/LSP8IdentifiableDigitalAsset/extensions/{LSP8CompatibilityForERC721InitAbstract.sol → LSP8CompatibleERC721InitAbstract.sol} +13 -9
  107. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Enumerable.sol +21 -0
  108. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8EnumerableCore.sol +50 -0
  109. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8EnumerableInitAbstract.sol +24 -0
  110. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721Mintable.sol +22 -0
  111. package/contracts/{LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20Init.sol → LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInit.sol} +12 -4
  112. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInitAbstract.sol +27 -0
  113. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8Mintable.sol +6 -4
  114. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInit.sol +7 -0
  115. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInitAbstract.sol +8 -5
  116. package/contracts/LSP9Vault/LSP9Constants.sol +6 -3
  117. package/contracts/LSP9Vault/LSP9Vault.sol +9 -5
  118. package/contracts/LSP9Vault/LSP9VaultCore.sol +152 -69
  119. package/contracts/LSP9Vault/LSP9VaultInit.sol +10 -3
  120. package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +9 -5
  121. package/contracts/Legacy/UniversalReceiverAddressStore.sol +6 -2
  122. package/contracts/UniversalProfile.sol +3 -4
  123. package/contracts/UniversalProfileInit.sol +10 -3
  124. package/contracts/UniversalProfileInitAbstract.sol +3 -5
  125. package/contracts/Utils/GasLib.sol +17 -0
  126. package/contracts/Utils/UtilsLib.sol +6 -34
  127. package/package.json +27 -30
  128. package/artifacts/LSP7CompatibilityForERC20.json +0 -686
  129. package/artifacts/LSP7CompatibilityForERC20Init.json +0 -727
  130. package/artifacts/LSP7DigitalAssetInit.json +0 -573
  131. package/artifacts/LSP8CompatibilityForERC721.json +0 -832
  132. package/artifacts/LSP8CompatibilityForERC721Init.json +0 -873
  133. package/artifacts/LSP8IdentifiableDigitalAssetInit.json +0 -624
  134. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInit.sol +0 -26
  135. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInit.sol +0 -28
  136. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInit.sol +0 -19
  137. package/contracts/LSP7DigitalAsset/presets/LSP7MintableCore.sol +0 -26
  138. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInit.sol +0 -26
  139. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInit.sol +0 -19
  140. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableCore.sol +0 -26
@@ -16,142 +16,206 @@ library LSP2Utils {
16
16
 
17
17
  /* solhint-disable no-inline-assembly */
18
18
 
19
- function generateBytes32Key(bytes memory _rawKey) internal pure returns (bytes32 key) {
20
- // solhint-disable-next-line
21
- assembly {
22
- key := mload(add(_rawKey, 32))
23
- }
24
- }
25
-
26
- function generateSingletonKey(string memory _keyName) internal pure returns (bytes32) {
27
- return keccak256(bytes(_keyName));
19
+ /**
20
+ * @dev Generates a data key of keyType Singleton
21
+ * @param keyName The string to hash to generate a Singleton data key
22
+ * @return a bytes32 dataKey
23
+ *
24
+ */
25
+ function generateSingletonKey(string memory keyName) internal pure returns (bytes32) {
26
+ return keccak256(bytes(keyName));
28
27
  }
29
28
 
30
- function generateArrayKey(string memory _keyName) internal pure returns (bytes32) {
31
- bytes memory keyName = bytes(_keyName);
29
+ /**
30
+ * @dev Generates a data key of keyType Array by hashing `keyName`.
31
+ * @param keyName The string that will be used to generate an data key of keyType Array
32
+ */
33
+ function generateArrayKey(string memory keyName) internal pure returns (bytes32) {
34
+ bytes memory dataKey = bytes(keyName);
32
35
 
33
- // prettier-ignore
34
36
  require(
35
- keyName[keyName.length - 2] == 0x5b && // "[" in utf8 encoded
36
- keyName[keyName.length - 1] == 0x5d, // "]" in utf8
37
- "Missing empty square brackets \"[]\" at the end of the key name"
37
+ dataKey[dataKey.length - 2] == 0x5b && // "[" in utf8 encoded
38
+ dataKey[dataKey.length - 1] == 0x5d, // "]" in utf8
39
+ "Missing empty square brackets '[]' at the end of the key name"
38
40
  );
39
41
 
40
- return keccak256(keyName);
42
+ return keccak256(dataKey);
41
43
  }
42
44
 
43
- function generateArrayKeyAtIndex(bytes32 _arrayKey, uint256 _index)
45
+ /**
46
+ * @dev Generates a Array index data key by concatenating the first 16 bytes of `arrayKey`
47
+ * and `index` transformed from uint256 to bytes16 (uint256 -> uint128 -> bytes16)
48
+ * @param arrayKey The key from which we're getting the first half of the Array index data key from
49
+ * @param index Used to generate the second half of the Array index data key
50
+ */
51
+ function generateArrayElementKeyAtIndex(bytes32 arrayKey, uint256 index)
44
52
  internal
45
53
  pure
46
54
  returns (bytes32)
47
55
  {
48
56
  bytes memory elementInArray = UtilsLib.concatTwoBytes16(
49
- bytes16(_arrayKey),
50
- bytes16(uint128(_index))
57
+ bytes16(arrayKey),
58
+ bytes16(uint128(index))
51
59
  );
52
- return generateBytes32Key(elementInArray);
60
+ return bytes32(elementInArray);
53
61
  }
54
62
 
55
- function generateMappingKey(string memory _firstWord, string memory _lastWord)
63
+ /**
64
+ * @dev @dev Generates a data key of keyType Mapping by hashing two strings:
65
+ * <bytes10(keccak256(firstWord))>:<bytes2(0)>:<bytes20(keccak256(firstWord))>
66
+ * @param firstWord Used to generate a hash and its first 10 bytes
67
+ * are used for the first part of the data key of keyType Mapping
68
+ * @param lastWord Used to generate a hash and its first 20 bytes
69
+ * are used for the last part of the data key of keyType Mapping
70
+ */
71
+ function generateMappingKey(string memory firstWord, string memory lastWord)
56
72
  internal
57
73
  pure
58
74
  returns (bytes32)
59
75
  {
60
- bytes32 firstWordHash = keccak256(bytes(_firstWord));
61
- bytes32 lastWordHash = keccak256(bytes(_lastWord));
76
+ bytes32 firstWordHash = keccak256(bytes(firstWord));
77
+ bytes32 lastWordHash = keccak256(bytes(lastWord));
62
78
 
63
- bytes memory temporaryBytes = abi.encodePacked(
79
+ bytes memory temporaryBytes = bytes.concat(
64
80
  bytes10(firstWordHash),
65
81
  bytes2(0),
66
82
  bytes20(lastWordHash)
67
83
  );
68
84
 
69
- return generateBytes32Key(temporaryBytes);
85
+ return bytes32(temporaryBytes);
70
86
  }
71
87
 
72
- function generateMappingKey(string memory _firstWord, address _address)
88
+ /**
89
+ * @dev Generates a data key of keyType Mapping by hashing a string and concatenating it with an address:
90
+ * <bytes10(keccak256(firstWord))>:<bytes2(0)>:<bytes20(addr)>
91
+ * @param firstWord Used to generate a hash and its first 10 bytes
92
+ * are used for the first part of the data key of keyType Mapping
93
+ * @param addr used for the last part of the data key of keyType Mapping
94
+ */
95
+ function generateMappingKey(string memory firstWord, address addr)
73
96
  internal
74
97
  pure
75
98
  returns (bytes32)
76
99
  {
77
- bytes32 firstWordHash = keccak256(bytes(_firstWord));
100
+ bytes32 firstWordHash = keccak256(bytes(firstWord));
78
101
 
79
- bytes memory temporaryBytes = abi.encodePacked(bytes10(firstWordHash), bytes2(0), _address);
102
+ bytes memory temporaryBytes = bytes.concat(
103
+ bytes10(firstWordHash),
104
+ bytes2(0),
105
+ bytes20(addr)
106
+ );
80
107
 
81
- return generateBytes32Key(temporaryBytes);
108
+ return bytes32(temporaryBytes);
82
109
  }
83
110
 
84
- function generateMappingKey(bytes12 _keyPrefix, bytes20 _bytes20)
111
+ /**
112
+ * @dev Generate a data key of keyType Mapping
113
+ * <bytes10keyPrefix>:<bytes2(0)>:<bytes20Value>
114
+ * @param keyPrefix First part of the data key of keyType Mapping
115
+ * @param bytes20Value Second part of the data key of keyType Mapping
116
+ */
117
+ function generateMappingKey(bytes10 keyPrefix, bytes20 bytes20Value)
85
118
  internal
86
119
  pure
87
120
  returns (bytes32)
88
121
  {
89
- bytes memory generatedKey = bytes.concat(_keyPrefix, _bytes20);
90
- return generateBytes32Key(generatedKey);
122
+ bytes memory generatedKey = bytes.concat(keyPrefix, bytes2(0), bytes20Value);
123
+ return bytes32(generatedKey);
91
124
  }
92
125
 
126
+ /**
127
+ * @dev Generate a data key of keyType MappingWithGrouping by using two strings and an address
128
+ * <bytes6(keccak256(firstWord))>:<bytes4(keccak256(secondWord))>:<bytes2(0)>:<bytes20(addr)>
129
+ * @param firstWord Used to generate a hash and its first 6 bytes
130
+ * are used for the first part of the data key of keyType MappingWithGrouping
131
+ * @param secondWord Used to generate a hash and its first 4 bytes
132
+ * are used for the second part of the data key of keyType MappingWithGrouping
133
+ * @param addr Used for the last part of the data key of keyType MappingWithGrouping
134
+ */
93
135
  function generateMappingWithGroupingKey(
94
- string memory _firstWord,
95
- string memory _secondWord,
96
- address _address
136
+ string memory firstWord,
137
+ string memory secondWord,
138
+ address addr
97
139
  ) internal pure returns (bytes32) {
98
- bytes32 firstWordHash = keccak256(bytes(_firstWord));
99
- bytes32 secondWordHash = keccak256(bytes(_secondWord));
140
+ bytes32 firstWordHash = keccak256(bytes(firstWord));
141
+ bytes32 secondWordHash = keccak256(bytes(secondWord));
100
142
 
101
- bytes memory temporaryBytes = abi.encodePacked(
143
+ bytes memory temporaryBytes = bytes.concat(
102
144
  bytes6(firstWordHash),
103
145
  bytes4(secondWordHash),
104
146
  bytes2(0),
105
- _address
147
+ bytes20(addr)
106
148
  );
107
149
 
108
- return generateBytes32Key(temporaryBytes);
150
+ return bytes32(temporaryBytes);
109
151
  }
110
152
 
111
- function generateMappingWithGroupingKey(bytes12 _keyPrefix, bytes20 _bytes20)
153
+ /**
154
+ * @dev Generate a data key of keyType MappingWithGrouping
155
+ * <bytes10keyPrefix>:<bytes2(0)>:<bytes20Value>
156
+ * @param keyPrefix Used for the first part of the data key of keyType MappingWithGrouping
157
+ * @param bytes20Value Used for the first last of the data key of keyType MappingWithGrouping
158
+ */
159
+ function generateMappingWithGroupingKey(bytes10 keyPrefix, bytes20 bytes20Value)
112
160
  internal
113
161
  pure
114
162
  returns (bytes32)
115
163
  {
116
- bytes memory generatedKey = bytes.concat(_keyPrefix, _bytes20);
117
- return generateBytes32Key(generatedKey);
164
+ bytes memory generatedKey = bytes.concat(keyPrefix, bytes2(0), bytes20Value);
165
+ return bytes32(generatedKey);
118
166
  }
119
167
 
168
+ /**
169
+ * @dev Generate a JSONURL valueContent
170
+ * @param hashFunction The function used to hash the JSON file
171
+ * @param json Bytes value of the JSON file
172
+ * @param url The URL where the JSON file is hosted
173
+ */
120
174
  function generateJSONURLValue(
121
- string memory _hashFunction,
122
- string memory _json,
123
- string memory _url
124
- ) internal pure returns (bytes memory key_) {
125
- bytes32 hashFunctionDigest = keccak256(bytes(_hashFunction));
126
- bytes32 jsonDigest = keccak256(bytes(_json));
127
-
128
- key_ = abi.encodePacked(bytes4(hashFunctionDigest), jsonDigest, _url);
175
+ string memory hashFunction,
176
+ string memory json,
177
+ string memory url
178
+ ) internal pure returns (bytes memory key) {
179
+ bytes32 hashFunctionDigest = keccak256(bytes(hashFunction));
180
+ bytes32 jsonDigest = keccak256(bytes(json));
181
+
182
+ key = abi.encodePacked(bytes4(hashFunctionDigest), jsonDigest, url);
129
183
  }
130
184
 
185
+ /**
186
+ * @dev Generate a ASSETURL valueContent
187
+ * @param hashFunction The function used to hash the JSON file
188
+ * @param assetBytes Bytes value of the JSON file
189
+ * @param url The URL where the JSON file is hosted
190
+ */
131
191
  function generateASSETURLValue(
132
- string memory _hashFunction,
133
- string memory _assetBytes,
134
- string memory _url
135
- ) internal pure returns (bytes memory key_) {
136
- bytes32 hashFunctionDigest = keccak256(bytes(_hashFunction));
137
- bytes32 jsonDigest = keccak256(bytes(_assetBytes));
138
-
139
- key_ = abi.encodePacked(bytes4(hashFunctionDigest), jsonDigest, _url);
192
+ string memory hashFunction,
193
+ string memory assetBytes,
194
+ string memory url
195
+ ) internal pure returns (bytes memory key) {
196
+ bytes32 hashFunctionDigest = keccak256(bytes(hashFunction));
197
+ bytes32 jsonDigest = keccak256(bytes(assetBytes));
198
+
199
+ key = abi.encodePacked(bytes4(hashFunctionDigest), jsonDigest, url);
140
200
  }
141
201
 
142
- function isEncodedArray(bytes memory _data) internal pure returns (bool) {
143
- uint256 nbOfBytes = _data.length;
202
+ /**
203
+ * Verifing if `data` is an encoded array
204
+ * @param data The value that is to be verified
205
+ */
206
+ function isEncodedArray(bytes memory data) internal pure returns (bool) {
207
+ uint256 nbOfBytes = data.length;
144
208
 
145
209
  // 1) there must be at least 32 bytes to store the offset
146
210
  if (nbOfBytes < 32) return false;
147
211
 
148
212
  // 2) there must be at least the same number of bytes specified by
149
213
  // the offset value (otherwise, the offset points to nowhere)
150
- uint256 offset = uint256(bytes32(_data));
214
+ uint256 offset = uint256(bytes32(data));
151
215
  if (nbOfBytes < offset) return false;
152
216
 
153
217
  // 3) there must be at least 32 x length bytes after offset
154
- uint256 arrayLength = _data.toUint256(offset);
218
+ uint256 arrayLength = data.toUint256(offset);
155
219
 
156
220
  // 32 bytes word (= offset)
157
221
  // + 32 bytes word (= array length)
@@ -161,16 +225,20 @@ library LSP2Utils {
161
225
  return true;
162
226
  }
163
227
 
164
- function isEncodedArrayOfAddresses(bytes memory _data) internal pure returns (bool) {
165
- if (!isEncodedArray(_data)) return false;
228
+ /**
229
+ * Verifing if `data` is an encoded array of addresses (address[])
230
+ * @param data The value that is to be verified
231
+ */
232
+ function isEncodedArrayOfAddresses(bytes memory data) internal pure returns (bool) {
233
+ if (!isEncodedArray(data)) return false;
166
234
 
167
- uint256 offset = uint256(bytes32(_data));
168
- uint256 arrayLength = _data.toUint256(offset);
235
+ uint256 offset = uint256(bytes32(data));
236
+ uint256 arrayLength = data.toUint256(offset);
169
237
 
170
238
  uint256 pointer = offset + 32;
171
239
 
172
- for (uint256 ii = 0; ii < arrayLength; ii++) {
173
- bytes32 key = _data.toBytes32(pointer);
240
+ for (uint256 ii = 0; ii < arrayLength; ii = uncheckedIncrement(ii)) {
241
+ bytes32 key = data.toBytes32(pointer);
174
242
 
175
243
  // check that the leading bytes are zero bytes "00"
176
244
  // NB: address type is padded on the left (unlike bytes20 type that is padded on the right)
@@ -183,15 +251,19 @@ library LSP2Utils {
183
251
  return true;
184
252
  }
185
253
 
186
- function isBytes4EncodedArray(bytes memory _data) internal pure returns (bool) {
187
- if (!isEncodedArray(_data)) return false;
254
+ /**
255
+ * @dev verify that `data` is an array of bytes4 (bytes4[]) encoded according to the Solidity ABI specs.
256
+ * @param data The value that is to be verified
257
+ */
258
+ function isBytes4EncodedArray(bytes memory data) internal pure returns (bool) {
259
+ if (!isEncodedArray(data)) return false;
188
260
 
189
- uint256 offset = uint256(bytes32(_data));
190
- uint256 arrayLength = _data.toUint256(offset);
261
+ uint256 offset = uint256(bytes32(data));
262
+ uint256 arrayLength = data.toUint256(offset);
191
263
  uint256 pointer = offset + 32;
192
264
 
193
- for (uint256 ii = 0; ii < arrayLength; ii++) {
194
- bytes32 key = _data.toBytes32(pointer);
265
+ for (uint256 ii = 0; ii < arrayLength; ii = uncheckedIncrement(ii)) {
266
+ bytes32 key = data.toBytes32(pointer);
195
267
 
196
268
  // check that the trailing bytes are zero bytes "00"
197
269
  if (uint224(uint256(key)) != 0) return false;
@@ -202,4 +274,14 @@ library LSP2Utils {
202
274
 
203
275
  return true;
204
276
  }
277
+
278
+ /**
279
+ * @dev Will return unchecked incremented uint256
280
+ * can be used to save gas when iterating over loops
281
+ */
282
+ function uncheckedIncrement(uint256 i) internal pure returns (uint256) {
283
+ unchecked {
284
+ return i + 1;
285
+ }
286
+ }
205
287
  }
@@ -1,7 +1,7 @@
1
1
  // SPDX-License-Identifier: CC0-1.0
2
2
  pragma solidity ^0.8.0;
3
3
 
4
- // bytes10(keccak256('SupportedStandard')) + bytes2(0) + bytes20(keccak256('LSP3UniversalProfile'))
4
+ // bytes10(keccak256('SupportedStandards')) + bytes2(0) + bytes20(keccak256('LSP3UniversalProfile'))
5
5
  bytes32 constant _LSP3_SUPPORTED_STANDARDS_KEY = 0xeafec4d89fa9619884b60000abe425d64acd861a49b8ddf5c0b6962110481f38;
6
6
 
7
7
  // bytes4(keccak256('LSP3UniversalProfile'))
@@ -3,7 +3,7 @@ pragma solidity ^0.8.0;
3
3
 
4
4
  // --- ERC725Y entries
5
5
 
6
- // bytes10(keccak256('SupportedStandard')) + bytes2(0) + bytes20(keccak256('LSP4DigitalAsset'))
6
+ // bytes10(keccak256('SupportedStandards')) + bytes2(0) + bytes20(keccak256('LSP4DigitalAsset'))
7
7
  bytes32 constant _LSP4_SUPPORTED_STANDARDS_KEY = 0xeafec4d89fa9619884b60000a4d96624a38f7ac2d8d9a604ecf07c12c77e480c;
8
8
 
9
9
  // bytes4(keccak256('LSP4DigitalAsset'))
@@ -4,9 +4,15 @@ pragma solidity ^0.8.0;
4
4
  // modules
5
5
  import {ERC725Y} from "@erc725/smart-contracts/contracts/ERC725Y.sol";
6
6
 
7
+ // libraries
8
+ import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol";
9
+
7
10
  // constants
8
11
  import "./LSP4Constants.sol";
9
12
 
13
+ // errors
14
+ import {LSP4TokenNameNotEditable, LSP4TokenSymbolNotEditable} from "./LSP4Errors.sol";
15
+
10
16
  /**
11
17
  * @title LSP4DigitalAssetMetadata
12
18
  * @author Matthew Stevens
@@ -31,9 +37,23 @@ abstract contract LSP4DigitalAssetMetadata is ERC725Y {
31
37
  super._setData(_LSP4_TOKEN_SYMBOL_KEY, bytes(symbol_));
32
38
  }
33
39
 
34
- function _setData(bytes32 key, bytes memory value) internal virtual override {
35
- require(key != _LSP4_TOKEN_NAME_KEY, "LSP4: cannot edit Token Name after deployment");
36
- require(key != _LSP4_TOKEN_SYMBOL_KEY, "LSP4: cannot edit Token Symbol after deployment");
37
- super._setData(key, value);
40
+ /**
41
+ * @dev The ERC725Y data keys `LSP4TokenName` and `LSP4TokenSymbol` cannot be changed
42
+ * via this function once the digital asset contract has been deployed.
43
+ *
44
+ * @dev SAVE GAS by emitting the DataChanged event with only the first 256 bytes of dataValue
45
+ */
46
+ function _setData(bytes32 dataKey, bytes memory dataValue) internal virtual override {
47
+ if (dataKey == _LSP4_TOKEN_NAME_KEY) {
48
+ revert LSP4TokenNameNotEditable();
49
+ } else if (dataKey == _LSP4_TOKEN_SYMBOL_KEY) {
50
+ revert LSP4TokenSymbolNotEditable();
51
+ } else {
52
+ store[dataKey] = dataValue;
53
+ emit DataChanged(
54
+ dataKey,
55
+ dataValue.length <= 256 ? dataValue : BytesLib.slice(dataValue, 0, 256)
56
+ );
57
+ }
38
58
  }
39
59
  }
@@ -2,11 +2,18 @@
2
2
  pragma solidity ^0.8.0;
3
3
 
4
4
  // modules
5
- import {ERC725YInitAbstract, ERC725YCore} from "@erc725/smart-contracts/contracts/ERC725YInitAbstract.sol";
5
+ import {ERC725YInitAbstract} from "@erc725/smart-contracts/contracts/ERC725YInitAbstract.sol";
6
+ import {ERC725YCore} from "@erc725/smart-contracts/contracts/ERC725YCore.sol";
7
+
8
+ // libraries
9
+ import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol";
6
10
 
7
11
  // constants
8
12
  import "./LSP4Constants.sol";
9
13
 
14
+ // errors
15
+ import {LSP4TokenNameNotEditable, LSP4TokenSymbolNotEditable} from "./LSP4Errors.sol";
16
+
10
17
  /**
11
18
  * @title LSP4DigitalAssetMetadata
12
19
  * @author Matthew Stevens
@@ -27,9 +34,23 @@ abstract contract LSP4DigitalAssetMetadataInitAbstract is ERC725YInitAbstract {
27
34
  super._setData(_LSP4_TOKEN_SYMBOL_KEY, bytes(symbol_));
28
35
  }
29
36
 
30
- function _setData(bytes32 key, bytes memory value) internal virtual override {
31
- require(key != _LSP4_TOKEN_NAME_KEY, "LSP4: cannot edit Token Name after deployment");
32
- require(key != _LSP4_TOKEN_SYMBOL_KEY, "LSP4: cannot edit Token Symbol after deployment");
33
- super._setData(key, value);
37
+ /**
38
+ * @dev the ERC725Y data keys `LSP4TokenName` and `LSP4TokenSymbol` cannot be changed
39
+ * via this function once the digital asset contract has been deployed.
40
+ *
41
+ * @dev SAVE GAS by emitting the DataChanged event with only the first 256 bytes of dataValue
42
+ */
43
+ function _setData(bytes32 dataKey, bytes memory dataValue) internal virtual override {
44
+ if (dataKey == _LSP4_TOKEN_NAME_KEY) {
45
+ revert LSP4TokenNameNotEditable();
46
+ } else if (dataKey == _LSP4_TOKEN_SYMBOL_KEY) {
47
+ revert LSP4TokenSymbolNotEditable();
48
+ } else {
49
+ store[dataKey] = dataValue;
50
+ emit DataChanged(
51
+ dataKey,
52
+ dataValue.length <= 256 ? dataValue : BytesLib.slice(dataValue, 0, 256)
53
+ );
54
+ }
34
55
  }
35
56
  }
@@ -0,0 +1,16 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.0;
3
+
4
+ /**
5
+ * @dev Reverts when trying to edit the data key `LSP4TokenName` after the digital asset contract has been deployed.
6
+ * The `LSP4TokenName` data key is located inside the ERC725Y key-value store of the digital asset contract.
7
+ * It can be set only once inside the constructor/initializer when the digital asset contract is being deployed.
8
+ */
9
+ error LSP4TokenNameNotEditable();
10
+
11
+ /**
12
+ * @dev Reverts when trying to edit the data key `LSP4TokenSymbol` after the digital asset contract has been deployed.
13
+ * The `LSP4TokenSymbol` data key is located inside the ERC725Y key-value store of the digital asset contract.
14
+ * It can be set only once inside the constructor/initializer when the digital asset contract is being deployed.
15
+ */
16
+ error LSP4TokenSymbolNotEditable();
@@ -6,5 +6,5 @@ pragma solidity ^0.8.0;
6
6
  // keccak256('LSP5ReceivedAssets[]')
7
7
  bytes32 constant _LSP5_RECEIVED_ASSETS_ARRAY_KEY = 0x6460ee3c0aac563ccbf76d6e1d07bada78e3a9514e6382b736ed3f478ab7b90b;
8
8
 
9
- // bytes10(keccak256('LSP5ReceivedAssetsMap')) + bytes2(0)
10
- bytes12 constant _LSP5_RECEIVED_ASSETS_MAP_KEY_PREFIX = 0x812c4334633eb816c80d0000;
9
+ // bytes10(keccak256('LSP5ReceivedAssetsMap'))
10
+ bytes10 constant _LSP5_RECEIVED_ASSETS_MAP_KEY_PREFIX = 0x812c4334633eb816c80d;