@lukso/lsp-smart-contracts 0.9.0 → 0.10.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 (173) hide show
  1. package/README.md +15 -7
  2. package/artifacts/LSP0ERC725Account.json +62 -68
  3. package/artifacts/LSP0ERC725AccountInit.json +62 -68
  4. package/artifacts/LSP11BasicSocialRecovery.json +2 -2
  5. package/artifacts/LSP11BasicSocialRecoveryInit.json +2 -2
  6. package/artifacts/LSP1UniversalReceiverDelegateUP.json +2 -2
  7. package/artifacts/LSP1UniversalReceiverDelegateVault.json +2 -2
  8. package/artifacts/LSP4Compatibility.json +32 -38
  9. package/artifacts/LSP4DigitalAssetMetadata.json +32 -38
  10. package/artifacts/LSP4DigitalAssetMetadataInitAbstract.json +32 -38
  11. package/artifacts/LSP6KeyManager.json +29 -15
  12. package/artifacts/LSP6KeyManagerInit.json +29 -15
  13. package/artifacts/LSP7CappedSupply.json +71 -36
  14. package/artifacts/LSP7CappedSupplyInitAbstract.json +71 -36
  15. package/artifacts/LSP7CompatibleERC20.json +71 -36
  16. package/artifacts/LSP7CompatibleERC20InitAbstract.json +71 -36
  17. package/artifacts/LSP7CompatibleERC20Mintable.json +73 -38
  18. package/artifacts/LSP7CompatibleERC20MintableInit.json +73 -38
  19. package/artifacts/LSP7DigitalAsset.json +71 -36
  20. package/artifacts/LSP7DigitalAssetInitAbstract.json +71 -36
  21. package/artifacts/LSP7Mintable.json +73 -38
  22. package/artifacts/LSP7MintableInit.json +73 -38
  23. package/artifacts/LSP8CappedSupply.json +32 -38
  24. package/artifacts/LSP8CappedSupplyInitAbstract.json +32 -38
  25. package/artifacts/LSP8CompatibleERC721.json +35 -41
  26. package/artifacts/LSP8CompatibleERC721InitAbstract.json +35 -41
  27. package/artifacts/LSP8CompatibleERC721Mintable.json +37 -43
  28. package/artifacts/LSP8CompatibleERC721MintableInit.json +37 -43
  29. package/artifacts/LSP8IdentifiableDigitalAsset.json +32 -38
  30. package/artifacts/LSP8IdentifiableDigitalAssetInitAbstract.json +32 -38
  31. package/artifacts/LSP8Mintable.json +34 -40
  32. package/artifacts/LSP8MintableInit.json +34 -40
  33. package/artifacts/LSP9Vault.json +61 -67
  34. package/artifacts/LSP9VaultInit.json +61 -67
  35. package/artifacts/UniversalProfile.json +62 -68
  36. package/artifacts/UniversalProfileInit.json +62 -68
  37. package/contracts/LSP0ERC725Account/ILSP0ERC725Account.sol +45 -10
  38. package/contracts/LSP0ERC725Account/LSP0Constants.sol +1 -1
  39. package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +36 -6
  40. package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +361 -124
  41. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +30 -4
  42. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +37 -3
  43. package/contracts/LSP0ERC725Account/LSP0Utils.sol +0 -1
  44. package/contracts/LSP10ReceivedVaults/LSP10Utils.sol +30 -15
  45. package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryCore.sol +0 -1
  46. package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryInit.sol +0 -1
  47. package/contracts/LSP14Ownable2Step/LSP14Ownable2Step.sol +5 -7
  48. package/contracts/LSP17ContractExtension/LSP17Extendable.sol +10 -5
  49. package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiver.sol +0 -4
  50. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +91 -34
  51. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +27 -8
  52. package/contracts/LSP20CallVerification/LSP20CallVerification.sol +18 -9
  53. package/contracts/LSP20CallVerification/LSP20Constants.sol +17 -0
  54. package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +26 -12
  55. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +0 -1
  56. package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +32 -16
  57. package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +11 -2
  58. package/contracts/LSP6KeyManager/LSP6Constants.sol +5 -5
  59. package/contracts/LSP6KeyManager/LSP6Errors.sol +10 -6
  60. package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +140 -68
  61. package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +0 -1
  62. package/contracts/LSP6KeyManager/LSP6Modules/LSP6ExecuteModule.sol +30 -38
  63. package/contracts/LSP6KeyManager/LSP6Modules/LSP6SetDataModule.sol +153 -60
  64. package/contracts/LSP6KeyManager/LSP6Utils.sol +1 -5
  65. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +67 -13
  66. package/contracts/LSP7DigitalAsset/LSP7Errors.sol +5 -0
  67. package/contracts/LSP7DigitalAsset/extensions/LSP7Burnable.sol +2 -2
  68. package/contracts/LSP7DigitalAsset/extensions/LSP7BurnableInitAbstract.sol +24 -0
  69. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.sol +1 -2
  70. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +1 -2
  71. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20.sol +3 -5
  72. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20InitAbstract.sol +3 -5
  73. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +15 -12
  74. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CompatibleERC721.sol +1 -1
  75. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupply.sol +1 -2
  76. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +1 -2
  77. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol +5 -5
  78. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol +6 -6
  79. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Enumerable.sol +2 -2
  80. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8EnumerableInitAbstract.sol +2 -2
  81. package/contracts/LSP9Vault/ILSP9Vault.sol +9 -1
  82. package/contracts/LSP9Vault/LSP9Constants.sol +1 -1
  83. package/contracts/LSP9Vault/LSP9Vault.sol +0 -6
  84. package/contracts/LSP9Vault/LSP9VaultCore.sol +17 -15
  85. package/contracts/LSP9Vault/LSP9VaultInit.sol +2 -1
  86. package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +8 -5
  87. package/contracts/UniversalProfileInitAbstract.sol +5 -0
  88. package/devdocs/Create2Factory.json +16 -0
  89. package/devdocs/LSP0ERC725Account.json +200 -0
  90. package/devdocs/LSP0ERC725AccountInit.json +203 -0
  91. package/devdocs/LSP11BasicSocialRecovery.json +146 -0
  92. package/devdocs/LSP11BasicSocialRecoveryInit.json +146 -0
  93. package/devdocs/LSP16UniversalFactory.json +51 -0
  94. package/devdocs/LSP1UniversalReceiverDelegateUP.json +80 -0
  95. package/devdocs/LSP1UniversalReceiverDelegateVault.json +62 -0
  96. package/devdocs/LSP4Compatibility.json +79 -0
  97. package/devdocs/LSP4DigitalAssetMetadata.json +84 -0
  98. package/devdocs/LSP4DigitalAssetMetadataInitAbstract.json +77 -0
  99. package/devdocs/LSP6KeyManager.json +257 -0
  100. package/devdocs/LSP6KeyManagerInit.json +260 -0
  101. package/devdocs/LSP7CappedSupply.json +211 -0
  102. package/devdocs/LSP7CappedSupplyInitAbstract.json +206 -0
  103. package/devdocs/LSP7CompatibleERC20.json +225 -0
  104. package/devdocs/LSP7CompatibleERC20InitAbstract.json +218 -0
  105. package/devdocs/LSP7CompatibleERC20Mintable.json +217 -0
  106. package/devdocs/LSP7CompatibleERC20MintableInit.json +227 -0
  107. package/devdocs/LSP7DigitalAsset.json +210 -0
  108. package/devdocs/LSP7DigitalAssetInitAbstract.json +202 -0
  109. package/devdocs/LSP7Mintable.json +219 -0
  110. package/devdocs/LSP7MintableInit.json +220 -0
  111. package/devdocs/LSP8CappedSupply.json +232 -0
  112. package/devdocs/LSP8CappedSupplyInitAbstract.json +227 -0
  113. package/devdocs/LSP8CompatibleERC721.json +298 -0
  114. package/devdocs/LSP8CompatibleERC721InitAbstract.json +291 -0
  115. package/devdocs/LSP8CompatibleERC721Mintable.json +290 -0
  116. package/devdocs/LSP8CompatibleERC721MintableInit.json +300 -0
  117. package/devdocs/LSP8IdentifiableDigitalAsset.json +230 -0
  118. package/devdocs/LSP8IdentifiableDigitalAssetInitAbstract.json +223 -0
  119. package/devdocs/LSP8Mintable.json +242 -0
  120. package/devdocs/LSP8MintableInit.json +245 -0
  121. package/devdocs/LSP9Vault.json +171 -0
  122. package/devdocs/LSP9VaultInit.json +175 -0
  123. package/devdocs/UniversalProfile.json +199 -0
  124. package/devdocs/UniversalProfileInit.json +202 -0
  125. package/devdocs/UniversalReceiverAddressStore.json +9 -0
  126. package/dist/constants.cjs.js +31569 -0
  127. package/dist/constants.d.ts +31681 -0
  128. package/dist/constants.es.js +31550 -0
  129. package/package.json +69 -52
  130. package/userdocs/Create2Factory.json +5 -0
  131. package/userdocs/LSP0ERC725Account.json +47 -0
  132. package/userdocs/LSP0ERC725AccountInit.json +47 -0
  133. package/userdocs/LSP11BasicSocialRecovery.json +29 -0
  134. package/userdocs/LSP11BasicSocialRecoveryInit.json +29 -0
  135. package/userdocs/LSP16UniversalFactory.json +5 -0
  136. package/userdocs/LSP1UniversalReceiverDelegateUP.json +10 -0
  137. package/userdocs/LSP1UniversalReceiverDelegateVault.json +10 -0
  138. package/userdocs/LSP4Compatibility.json +20 -0
  139. package/userdocs/LSP4DigitalAssetMetadata.json +23 -0
  140. package/userdocs/LSP4DigitalAssetMetadataInitAbstract.json +20 -0
  141. package/userdocs/LSP6KeyManager.json +18 -0
  142. package/userdocs/LSP6KeyManagerInit.json +18 -0
  143. package/userdocs/LSP7CappedSupply.json +29 -0
  144. package/userdocs/LSP7CappedSupplyInitAbstract.json +26 -0
  145. package/userdocs/LSP7CompatibleERC20.json +35 -0
  146. package/userdocs/LSP7CompatibleERC20InitAbstract.json +32 -0
  147. package/userdocs/LSP7CompatibleERC20Mintable.json +32 -0
  148. package/userdocs/LSP7CompatibleERC20MintableInit.json +35 -0
  149. package/userdocs/LSP7DigitalAsset.json +29 -0
  150. package/userdocs/LSP7DigitalAssetInitAbstract.json +26 -0
  151. package/userdocs/LSP7Mintable.json +29 -0
  152. package/userdocs/LSP7MintableInit.json +29 -0
  153. package/userdocs/LSP8CappedSupply.json +23 -0
  154. package/userdocs/LSP8CappedSupplyInitAbstract.json +20 -0
  155. package/userdocs/LSP8CompatibleERC721.json +29 -0
  156. package/userdocs/LSP8CompatibleERC721InitAbstract.json +26 -0
  157. package/userdocs/LSP8CompatibleERC721Mintable.json +26 -0
  158. package/userdocs/LSP8CompatibleERC721MintableInit.json +29 -0
  159. package/userdocs/LSP8IdentifiableDigitalAsset.json +23 -0
  160. package/userdocs/LSP8IdentifiableDigitalAssetInitAbstract.json +20 -0
  161. package/userdocs/LSP8Mintable.json +23 -0
  162. package/userdocs/LSP8MintableInit.json +23 -0
  163. package/userdocs/LSP9Vault.json +38 -0
  164. package/userdocs/LSP9VaultInit.json +38 -0
  165. package/userdocs/UniversalProfile.json +50 -0
  166. package/userdocs/UniversalProfileInit.json +50 -0
  167. package/userdocs/UniversalReceiverAddressStore.json +5 -0
  168. package/CONTRIBUTING.md +0 -57
  169. package/common/constants.d.ts +0 -461
  170. package/common/constants.js +0 -789
  171. package/contracts/Utils/GasLib.sol +0 -17
  172. package/module/constants.d.ts +0 -461
  173. package/module/constants.js +0 -786
@@ -8,10 +8,8 @@ import {ILSP7DigitalAsset} from "../../LSP7DigitalAsset/ILSP7DigitalAsset.sol";
8
8
 
9
9
  // modules
10
10
  import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
11
- import {ERC725Y} from "@erc725/smart-contracts/contracts/ERC725Y.sol";
12
11
 
13
12
  // libraries
14
- import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
15
13
  import {LSP1Utils} from "../LSP1Utils.sol";
16
14
  import {LSP2Utils} from "../../LSP2ERC725YJSONSchema/LSP2Utils.sol";
17
15
  import {LSP5Utils} from "../../LSP5ReceivedAssets/LSP5Utils.sol";
@@ -65,9 +63,13 @@ contract LSP1UniversalReceiverDelegateVault is ERC165, ILSP1UniversalReceiver {
65
63
  if (bytes20(notifierMapValue) != bytes20(0))
66
64
  return "URD: asset received is already registered";
67
65
 
68
- // if the amount sent is 0, then do not update the keys
69
- uint256 balance = ILSP7DigitalAsset(notifier).balanceOf(msg.sender);
70
- if (balance == 0) return "LSP1: balance not updated";
66
+ // CHECK balance only when the Token contract is already deployed,
67
+ // not when tokens are being transferred on deployment through the `constructor`
68
+ if (notifier.code.length > 0) {
69
+ // if the amount sent is 0, then do not update the keys
70
+ uint256 balance = ILSP7DigitalAsset(notifier).balanceOf(msg.sender);
71
+ if (balance == 0) return "LSP1: balance not updated";
72
+ }
71
73
 
72
74
  (dataKeys, dataValues) = LSP5Utils.generateReceivedAssetKeys(
73
75
  msg.sender,
@@ -76,22 +78,39 @@ contract LSP1UniversalReceiverDelegateVault is ERC165, ILSP1UniversalReceiver {
76
78
  interfaceID
77
79
  );
78
80
 
79
- IERC725Y(msg.sender).setData(dataKeys, dataValues);
81
+ IERC725Y(msg.sender).setDataBatch(dataKeys, dataValues);
80
82
  } else {
81
83
  // if there is no map value for the asset to remove, then do nothing
82
84
  if (bytes20(notifierMapValue) == bytes20(0))
83
85
  return "LSP1: asset sent is not registered";
86
+
84
87
  // if it's a token transfer (LSP7/LSP8)
85
88
  uint256 balance = ILSP7DigitalAsset(notifier).balanceOf(msg.sender);
86
89
  if (balance != 0) return "LSP1: full balance is not sent";
87
90
 
91
+ // if the value under the `LSP5ReceivedAssetsMap:<asset-address>`
92
+ // is not a valid tuple as `(bytes4,uint128)`
93
+ if (notifierMapValue.length < 20) return "LSP1: asset data corrupted";
94
+
95
+ // Identify where the asset is located in the `LSP5ReceivedAssets[]` Array
96
+ // by extracting the index from the tuple value `(bytes4,uint128)`
97
+ // fetched under the LSP5ReceivedAssetsMap/LSP10VaultsMap data key
98
+ uint128 assetIndex = uint128(uint160(bytes20(notifierMapValue)));
99
+
88
100
  (dataKeys, dataValues) = LSP5Utils.generateSentAssetKeys(
89
101
  msg.sender,
90
102
  notifierMapKey,
91
- notifierMapValue
103
+ assetIndex
92
104
  );
93
105
 
94
- IERC725Y(msg.sender).setData(dataKeys, dataValues);
106
+ /**
107
+ * `generateSentAssetKeys(...)` returns empty arrays in the following cases:
108
+ * - the index returned from the data key `notifierMapKey` is bigger than
109
+ * the length of the `LSP5ReceivedAssets[]`, meaning, index is out of bounds.
110
+ */
111
+ if (dataKeys.length == 0 && dataValues.length == 0) return "LSP1: asset data corrupted";
112
+
113
+ IERC725Y(msg.sender).setDataBatch(dataKeys, dataValues);
95
114
  }
96
115
  }
97
116
 
@@ -24,11 +24,9 @@ abstract contract LSP20CallVerification {
24
24
  abi.encodeWithSelector(ILSP20.lsp20VerifyCall.selector, msg.sender, msg.value, msg.data)
25
25
  );
26
26
 
27
- if (!success) _revert(false, returnedData);
27
+ _validateCall(false, success, returnedData);
28
28
 
29
- if (returnedData.length < 32) revert LSP20InvalidMagicValue(false, returnedData);
30
-
31
- bytes32 magicValue = abi.decode(returnedData, (bytes32));
29
+ bytes4 magicValue = abi.decode(returnedData, (bytes4));
32
30
 
33
31
  if (bytes3(magicValue) != bytes3(ILSP20.lsp20VerifyCall.selector))
34
32
  revert LSP20InvalidMagicValue(false, returnedData);
@@ -49,12 +47,23 @@ abstract contract LSP20CallVerification {
49
47
  )
50
48
  );
51
49
 
52
- if (!success) _revert(true, returnedData);
50
+ _validateCall(true, success, returnedData);
51
+
52
+ if (abi.decode(returnedData, (bytes4)) != ILSP20.lsp20VerifyCallResult.selector)
53
+ revert LSP20InvalidMagicValue(true, returnedData);
54
+ }
55
+
56
+ function _validateCall(
57
+ bool postCall,
58
+ bool success,
59
+ bytes memory returnedData
60
+ ) internal pure {
61
+ if (!success) _revert(postCall, returnedData);
53
62
 
54
- if (
55
- returnedData.length < 32 ||
56
- bytes4(abi.decode(returnedData, (bytes32))) != ILSP20.lsp20VerifyCallResult.selector
57
- ) revert LSP20InvalidMagicValue(true, returnedData);
63
+ // check if the returned data contains at least 32 bytes, potentially an abi encoded bytes4 value
64
+ // check if the returned data has in the first 32 bytes an abi encoded bytes4 value
65
+ if (returnedData.length < 32 || bytes28(bytes32(returnedData) << 32) != bytes28(0))
66
+ revert LSP20InvalidMagicValue(postCall, returnedData);
58
67
  }
59
68
 
60
69
  function _revert(bool postCall, bytes memory returnedData) internal pure {
@@ -0,0 +1,17 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.4;
3
+
4
+ // bytes4(keccak256("LSP20CallVerification"))
5
+ bytes4 constant _INTERFACEID_LSP20_CALL_VERIFICATION = 0x1a0eb6a5;
6
+
7
+ // `lsp20VerifyCall(address,uint256,bytes)` selector XOR `lsp20VerifyCallResult(bytes32,bytes)` selector
8
+ bytes4 constant _INTERFACEID_LSP20_CALL_VERIFIER = 0x480c0ec2;
9
+
10
+ // bytes4(bytes.concat(bytes3(ILSP20.lsp20VerifyCall.selector), hex"01"))
11
+ bytes4 constant _LSP20_VERIFY_CALL_MAGIC_VALUE_WITH_POST_VERIFICATION = 0x9bf04b01;
12
+
13
+ // bytes4(bytes.concat(bytes3(ILSP20.lsp20VerifyCall.selector), hex"00"))
14
+ bytes4 constant _LSP20_VERIFY_CALL_MAGIC_VALUE_WITHOUT_POST_VERIFICATION = 0x9bf04b00;
15
+
16
+ // bytes4(ILSP20.lsp20VerifyCallResult.selector)
17
+ bytes4 constant _LSP20_VERIFY_CALL_RESULT_MAGIC_VALUE = 0xd3fc45d3;
@@ -144,6 +144,22 @@ library LSP2Utils {
144
144
  return bytes32(temporaryBytes);
145
145
  }
146
146
 
147
+ /**
148
+ * @dev Generate a data key of keyType MappingWithGrouping
149
+ * <bytes6keyPrefix>:<bytes4mapPrefix>:<bytes2(0)>:<subMapKey>
150
+ * @param keyPrefix the first part of the data key of keyType MappingWithGrouping
151
+ * @param mapPrefix Used for the second part (bytes4) of the data key of keyType MappingWithGrouping
152
+ * @param subMapKey Used for the last part (bytes20) of the data key of keyType MappingWithGrouping
153
+ */
154
+ function generateMappingWithGroupingKey(
155
+ bytes6 keyPrefix,
156
+ bytes4 mapPrefix,
157
+ bytes20 subMapKey
158
+ ) internal pure returns (bytes32) {
159
+ bytes memory generatedKey = bytes.concat(keyPrefix, mapPrefix, bytes2(0), subMapKey);
160
+ return bytes32(generatedKey);
161
+ }
162
+
147
163
  /**
148
164
  * @dev Generate a data key of keyType MappingWithGrouping
149
165
  * <bytes10keyPrefix>:<bytes2(0)>:<bytes20Value>
@@ -225,7 +241,7 @@ library LSP2Utils {
225
241
 
226
242
  uint256 pointer = offset + 32;
227
243
 
228
- for (uint256 ii = 0; ii < arrayLength; ii = uncheckedIncrement(ii)) {
244
+ for (uint256 ii = 0; ii < arrayLength; ) {
229
245
  bytes32 key = data.toBytes32(pointer);
230
246
 
231
247
  // check that the leading bytes are zero bytes "00"
@@ -234,6 +250,10 @@ library LSP2Utils {
234
250
 
235
251
  // increment the pointer
236
252
  pointer += 32;
253
+
254
+ unchecked {
255
+ ++ii;
256
+ }
237
257
  }
238
258
 
239
259
  return true;
@@ -250,7 +270,7 @@ library LSP2Utils {
250
270
  uint256 arrayLength = data.toUint256(offset);
251
271
  uint256 pointer = offset + 32;
252
272
 
253
- for (uint256 ii = 0; ii < arrayLength; ii = uncheckedIncrement(ii)) {
273
+ for (uint256 ii = 0; ii < arrayLength; ) {
254
274
  bytes32 key = data.toBytes32(pointer);
255
275
 
256
276
  // check that the trailing bytes are zero bytes "00"
@@ -258,6 +278,10 @@ library LSP2Utils {
258
278
 
259
279
  // increment the pointer
260
280
  pointer += 32;
281
+
282
+ unchecked {
283
+ ++ii;
284
+ }
261
285
  }
262
286
 
263
287
  return true;
@@ -296,14 +320,4 @@ library LSP2Utils {
296
320
  if (pointer == compactBytesArray.length) return true;
297
321
  return false;
298
322
  }
299
-
300
- /**
301
- * @dev Will return unchecked incremented uint256
302
- * can be used to save gas when iterating over loops
303
- */
304
- function uncheckedIncrement(uint256 i) internal pure returns (uint256) {
305
- unchecked {
306
- return i + 1;
307
- }
308
- }
309
323
  }
@@ -3,7 +3,6 @@ pragma solidity ^0.8.4;
3
3
 
4
4
  // modules
5
5
  import {ERC725YInitAbstract} from "@erc725/smart-contracts/contracts/ERC725YInitAbstract.sol";
6
- import {ERC725YCore} from "@erc725/smart-contracts/contracts/ERC725YCore.sol";
7
6
 
8
7
  // libraries
9
8
  import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol";
@@ -83,15 +83,19 @@ library LSP5Utils {
83
83
  revert MaxLSP5ReceivedAssetsCountReached({notRegisteredAsset: asset});
84
84
  }
85
85
 
86
+ // store the number of received assets incremented by 1
86
87
  keys[0] = _LSP5_RECEIVED_ASSETS_ARRAY_KEY;
87
88
  values[0] = bytes.concat(bytes16(oldArrayLength + 1));
88
89
 
90
+ // store the address of the asset under the element key in the array
89
91
  keys[1] = LSP2Utils.generateArrayElementKeyAtIndex(
90
92
  _LSP5_RECEIVED_ASSETS_ARRAY_KEY,
91
93
  oldArrayLength
92
94
  );
93
95
  values[1] = bytes.concat(bytes20(asset));
94
96
 
97
+ // store the interfaceId and the location in the array of the asset
98
+ // under the LSP5ReceivedAssetMap key
95
99
  keys[2] = assetMapKey;
96
100
  values[2] = bytes.concat(interfaceID, bytes16(oldArrayLength));
97
101
  }
@@ -101,12 +105,12 @@ library LSP5Utils {
101
105
  * @param sender The address sending the asset and where the Keys should be updated
102
106
  * @param assetMapKey The map key of the asset being received containing the interfaceId of the
103
107
  * asset and the index in the array
104
- * @param assetInterfaceIdAndIndex The value of the map key of the asset being sent
108
+ * @param assetIndex The index in the LSP5ReceivedAssets[] array
105
109
  */
106
110
  function generateSentAssetKeys(
107
111
  address sender,
108
112
  bytes32 assetMapKey,
109
- bytes memory assetInterfaceIdAndIndex
113
+ uint128 assetIndex
110
114
  ) internal view returns (bytes32[] memory keys, bytes[] memory values) {
111
115
  IERC725Y account = IERC725Y(sender);
112
116
  bytes memory lsp5ReceivedAssetsCountValue = getLSP5ReceivedAssetsCount(account);
@@ -118,17 +122,19 @@ library LSP5Utils {
118
122
  });
119
123
  }
120
124
 
121
- // Updating the number of the received assets
122
125
  uint128 oldArrayLength = uint128(bytes16(lsp5ReceivedAssetsCountValue));
126
+
127
+ // Updating the number of the received assets (decrementing by 1
123
128
  uint128 newArrayLength = oldArrayLength - 1;
124
129
 
125
- uint128 index = extractIndexFromMap(assetInterfaceIdAndIndex);
130
+ // Generate the element key in the array of the asset
126
131
  bytes32 assetInArrayKey = LSP2Utils.generateArrayElementKeyAtIndex(
127
132
  _LSP5_RECEIVED_ASSETS_ARRAY_KEY,
128
- index
133
+ assetIndex
129
134
  );
130
135
 
131
- if (index == newArrayLength) {
136
+ // If the asset to remove is the last element in the array
137
+ if (assetIndex == newArrayLength) {
132
138
  /**
133
139
  * We will be updating/removing 3 keys:
134
140
  * - Keys[0]: [Update] The arrayLengthKey to contain the new number of the received assets
@@ -138,18 +144,21 @@ library LSP5Utils {
138
144
  keys = new bytes32[](3);
139
145
  values = new bytes[](3);
140
146
 
147
+ // store the number of received assets decremented by 1
141
148
  keys[0] = _LSP5_RECEIVED_ASSETS_ARRAY_KEY;
142
149
  values[0] = bytes.concat(bytes16(newArrayLength));
143
150
 
151
+ // remove the address of the asset from the element key
144
152
  keys[1] = assetInArrayKey;
145
153
  values[1] = "";
146
154
 
155
+ // remove the interfaceId and the location in the array of the asset
147
156
  keys[2] = assetMapKey;
148
157
  values[2] = "";
149
158
 
150
159
  // Swapping last element in ArrayKey with the element in ArrayKey to remove || {Swap and pop} method;
151
160
  // check https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/structs/EnumerableSet.sol#L80
152
- } else {
161
+ } else if (assetIndex < newArrayLength) {
153
162
  /**
154
163
  * We will be updating/removing 5 keys:
155
164
  * - Keys[0]: [Update] The arrayLengthKey to contain the new number of the received assets
@@ -161,9 +170,11 @@ library LSP5Utils {
161
170
  keys = new bytes32[](5);
162
171
  values = new bytes[](5);
163
172
 
173
+ // store the number of received assets decremented by 1
164
174
  keys[0] = _LSP5_RECEIVED_ASSETS_ARRAY_KEY;
165
175
  values[0] = bytes.concat(bytes16(newArrayLength));
166
176
 
177
+ // remove the interfaceId and the location in the array of the asset
167
178
  keys[1] = assetMapKey;
168
179
  values[1] = "";
169
180
 
@@ -173,41 +184,46 @@ library LSP5Utils {
173
184
 
174
185
  // Generate all data Keys/values of the last element in Array to swap
175
186
  // with data Keys/values of the asset to remove
187
+
188
+ // Generate the element key of the last asset in the array
176
189
  bytes32 lastAssetInArrayKey = LSP2Utils.generateArrayElementKeyAtIndex(
177
190
  _LSP5_RECEIVED_ASSETS_ARRAY_KEY,
178
191
  newArrayLength
179
192
  );
180
193
 
194
+ // Get the address of the asset from the element key of the last asset in the array
181
195
  bytes20 lastAssetInArrayAddress = bytes20(account.getData(lastAssetInArrayKey));
182
196
 
197
+ // Generate the map key of the last asset in the array
183
198
  bytes32 lastAssetInArrayMapKey = LSP2Utils.generateMappingKey(
184
199
  _LSP5_RECEIVED_ASSETS_MAP_KEY_PREFIX,
185
200
  lastAssetInArrayAddress
186
201
  );
187
202
 
203
+ // Get the interfaceId and the location in the array of the last asset
188
204
  bytes memory lastAssetInterfaceIdAndIndex = account.getData(lastAssetInArrayMapKey);
189
205
  bytes memory interfaceID = BytesLib.slice(lastAssetInterfaceIdAndIndex, 0, 4);
190
206
 
207
+ // Set the address of the last asset instead of the asset to be sent
208
+ // under the element data key in the array
191
209
  keys[2] = assetInArrayKey;
192
210
  values[2] = bytes.concat(lastAssetInArrayAddress);
193
211
 
212
+ // Remove the address swapped from the last element data key in the array
194
213
  keys[3] = lastAssetInArrayKey;
195
214
  values[3] = "";
196
215
 
216
+ // Update the index and the interfaceId of the address swapped (last element in the array)
217
+ // to point to the new location in the LSP5ReceivedAssets array
197
218
  keys[4] = lastAssetInArrayMapKey;
198
- values[4] = bytes.concat(interfaceID, bytes16(index));
219
+ values[4] = bytes.concat(interfaceID, bytes16(assetIndex));
220
+ } else {
221
+ // If index is bigger than the array length, out of bounds
222
+ return (keys, values);
199
223
  }
200
224
  }
201
225
 
202
226
  function getLSP5ReceivedAssetsCount(IERC725Y account) internal view returns (bytes memory) {
203
227
  return account.getData(_LSP5_RECEIVED_ASSETS_ARRAY_KEY);
204
228
  }
205
-
206
- /**
207
- * @dev returns the index from the LSP5ReceivedAssetMap
208
- */
209
- function extractIndexFromMap(bytes memory mapValue) internal pure returns (uint128) {
210
- bytes memory val = BytesLib.slice(mapValue, 4, 16);
211
- return BytesLib.toUint128(val, 0);
212
- }
213
229
  }
@@ -11,6 +11,12 @@ interface ILSP6KeyManager is
11
11
  IERC1271
12
12
  /* is ERC165 */
13
13
  {
14
+ /**
15
+ * @dev Emitted when a calldata payload that includes `selector` and `value` as msg.value was verified for `signer`
16
+ * @param signer the address of the controller that executed the calldata payload.
17
+ * @param value the amount of native token to be transferred in the calldata payload.
18
+ * @param selector the bytes4 function of the function to run in the calldata payload.
19
+ */
14
20
  event VerifiedCall(address indexed signer, uint256 indexed value, bytes4 indexed selector);
15
21
 
16
22
  /**
@@ -43,7 +49,7 @@ interface ILSP6KeyManager is
43
49
  /**
44
50
  * @dev batch `execute(bytes)`
45
51
  */
46
- function execute(uint256[] calldata values, bytes[] calldata payloads)
52
+ function executeBatch(uint256[] calldata values, bytes[] calldata payloads)
47
53
  external
48
54
  payable
49
55
  returns (bytes[] memory);
@@ -52,21 +58,24 @@ interface ILSP6KeyManager is
52
58
  * @dev allows anybody to execute given they have a signed message from an executor
53
59
  * @param signature bytes32 ethereum signature
54
60
  * @param nonce the address' nonce (in a specific `_channel`), obtained via `getNonce(...)`. Used to prevent replay attack
61
+ * @param validityTimestamps two `uint128` timestamps concatenated, the first timestamp determines from when the payload can be executed, the second timestamp delimits the end of the validity of the payload. If `validityTimestamps` is 0, the checks regardin the timestamps are skipped
55
62
  * @param payload obtained via encodeABI() in web3
56
63
  * @return the data being returned by the ERC725 Account
57
64
  */
58
65
  function executeRelayCall(
59
66
  bytes calldata signature,
60
67
  uint256 nonce,
68
+ uint256 validityTimestamps,
61
69
  bytes calldata payload
62
70
  ) external payable returns (bytes memory);
63
71
 
64
72
  /**
65
73
  * @dev batch `executeRelayCall(...)`
66
74
  */
67
- function executeRelayCall(
75
+ function executeRelayCallBatch(
68
76
  bytes[] calldata signatures,
69
77
  uint256[] calldata nonces,
78
+ uint256[] calldata validityTimestamps,
70
79
  uint256[] calldata values,
71
80
  bytes[] calldata payloads
72
81
  ) external payable returns (bytes[] memory);
@@ -4,7 +4,7 @@ pragma solidity ^0.8.4;
4
4
  uint256 constant LSP6_VERSION = 6;
5
5
 
6
6
  // --- ERC165 interface ids
7
- bytes4 constant _INTERFACEID_LSP6 = 0xfb437414;
7
+ bytes4 constant _INTERFACEID_LSP6 = 0x38bb3cdb;
8
8
 
9
9
  // --- ERC725Y Data Keys
10
10
 
@@ -65,7 +65,7 @@ bytes4 constant _LSP6_EXECUTE_RELAYCALL_SELECTOR = 0x902d5fa0;
65
65
  bytes4 constant _LSP6_EXECUTE_RELAYCALL_BATCH_SELECTOR = 0xbd68663a;
66
66
 
67
67
  // AllowedCalls types
68
- bytes4 constant _ALLOWEDCALLS_VALUE = 0x00000001; // 0000 0001 TRANSFER VALUE
69
- bytes4 constant _ALLOWEDCALLS_WRITE = 0x00000002; // 0000 0010 CALL
70
- bytes4 constant _ALLOWEDCALLS_READ = 0x00000004; // 0000 0100 STATIC CALL
71
- bytes4 constant _ALLOWEDCALLS_EXECUTE = 0x00000008; // 0000 1000 DELEGATE CALL
68
+ bytes4 constant _ALLOWEDCALLS_TRANSFERVALUE = 0x00000001; // 0000 0001
69
+ bytes4 constant _ALLOWEDCALLS_CALL = 0x00000002; // 0000 0010
70
+ bytes4 constant _ALLOWEDCALLS_STATICCALL = 0x00000004; // 0000 0100
71
+ bytes4 constant _ALLOWEDCALLS_DELEGATECALL = 0x00000008; // 0000 1000
@@ -143,12 +143,6 @@ error DelegateCallDisallowedViaKeyManager();
143
143
  */
144
144
  error InvalidPayload(bytes payload);
145
145
 
146
- /**
147
- * @dev reverts when the caller is not the linked target
148
- * @param caller The address calling lsp20 related functions
149
- */
150
- error CallerIsNotTheTarget(address caller);
151
-
152
146
  /**
153
147
  * @dev reverts when sending value to the `setData(..)` functions
154
148
  */
@@ -158,3 +152,13 @@ error CannotSendValueToSetData();
158
152
  * @dev reverts when calling the KeyManager through execute(..)
159
153
  */
160
154
  error CallingKeyManagerNotAllowed();
155
+
156
+ /**
157
+ * @dev reverts when relay call start timestamp is bigger than the current timestamp
158
+ */
159
+ error RelayCallBeforeStartTime();
160
+
161
+ /**
162
+ * @dev reverts when the period to execute the relay call has expired
163
+ */
164
+ error RelayCallExpired();