@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
@@ -13,141 +13,215 @@ import {UtilsLib} from "../Utils/UtilsLib.sol";
13
13
  // constants
14
14
  import {_TYPEID_LSP7_TOKENSSENDER} from "../LSP7DigitalAsset/LSP7Constants.sol";
15
15
 
16
+ /**
17
+ * @dev reverts when the value stored under the 'LSP5ReceivedAssets[]' data key is not valid.
18
+ * The value stored under this data key should be exactly 32 bytes long.
19
+ *
20
+ * Only possible valid values are:
21
+ * - any valid uint256 values
22
+ * i.e. 0x0000000000000000000000000000000000000000000000000000000000000000 (zero), meaning empty array, no assets received.
23
+ * i.e. 0x0000000000000000000000000000000000000000000000000000000000000005 (non-zero), meaning 5 array elements, 5 assets received.
24
+ *
25
+ * - 0x (nothing stored under this data key, equivalent to empty array)
26
+ *
27
+ * @param invalidValue the invalid value stored under the LSP5ReceivedAssets[] data key
28
+ * @param invalidValueLength the invalid number of bytes stored under the LSP5ReceivedAssets[] data key (MUST be 32)
29
+ */
30
+ error InvalidLSP5ReceivedAssetsArrayLength(bytes invalidValue, uint256 invalidValueLength);
31
+
32
+ /**
33
+ * @title LSP5Utils
34
+ * @author Yamen Merhi <YamenMerhi>, Jean Cavallera <CJ42>
35
+ * @dev LSP5Utils is a library of functions that are used to register and manage assets received by an ERC725Y smart contract
36
+ * based on the LSP5 - Received Assets standard
37
+ * https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-5-ReceivedAssets.md
38
+ */
16
39
  library LSP5Utils {
17
40
  /**
18
- * @dev Initiates Map and ArrayKey and sets the length of the Array to `1` if it's not set before,
19
- * If it's already set, it decodes the arrayLength, increment it and adds Map and ArrayKey
41
+ * @dev Generating the data keys/values to be set on the account after receiving assets/vaults
42
+ *
43
+ * @param account The account where the Keys should be added
44
+ * @param arrayLengthKey The arrayLengthKey containing the number of the received assets/vaults
45
+ * @param mapKey The mapKey containing the interfaceID and the index of the asset in the `element in arrayKey`
46
+ * @param caller The address of the asset/vault received
47
+ * @param interfaceID The interfaceID of the asset/vault received
20
48
  */
21
49
  function addMapAndArrayKey(
22
- IERC725Y _account,
23
- bytes32 _arrayKey,
24
- bytes32 _mapKey,
25
- address _sender,
26
- bytes4 _appendix
50
+ IERC725Y account,
51
+ bytes32 arrayLengthKey,
52
+ bytes32 mapKey,
53
+ address caller,
54
+ bytes4 interfaceID
27
55
  ) internal view returns (bytes32[] memory keys, bytes[] memory values) {
56
+ /**
57
+ * We will be setting 3 keys:
58
+ * - Keys[0]: The arrayLengthKey containing the number of the received assets/vaults
59
+ * - Keys[1]: The element in arrayKey containing the address of each received asset/vault for a specific index
60
+ * - Keys[2]: The mapKey containing the interfaceID and the index of the asset in the `element in arrayKey`
61
+ */
28
62
  keys = new bytes32[](3);
29
63
  values = new bytes[](3);
30
64
 
31
- bytes memory rawArrayLength = _account.getData(_arrayKey);
65
+ bytes memory encodedArrayLength = account.getData(arrayLengthKey);
32
66
 
33
- keys[0] = _arrayKey;
34
- keys[2] = _mapKey;
67
+ // If it's the first asset to receive
68
+ if (encodedArrayLength.length == 0) {
69
+ keys[0] = arrayLengthKey;
70
+ values[0] = UtilsLib.uint256ToBytes(1);
35
71
 
36
- values[1] = UtilsLib.addressToBytes(_sender);
72
+ keys[1] = LSP2Utils.generateArrayElementKeyAtIndex(arrayLengthKey, 0);
73
+ values[1] = UtilsLib.addressToBytes(caller);
37
74
 
38
- if (rawArrayLength.length != 32) {
39
- keys[1] = LSP2Utils.generateArrayKeyAtIndex(_arrayKey, 0);
75
+ keys[2] = mapKey;
76
+ values[2] = bytes.concat(interfaceID, bytes8(0));
40
77
 
41
- values[0] = UtilsLib.uint256ToBytes(1);
42
- values[2] = bytes.concat(_appendix, bytes8(0));
43
- } else if (rawArrayLength.length == 32) {
44
- uint256 arrayLength = abi.decode(rawArrayLength, (uint256));
78
+ // If the storage is already initiated
79
+ } else if (encodedArrayLength.length == 32) {
80
+ uint256 arrayLength = abi.decode(encodedArrayLength, (uint256));
45
81
  uint256 newArrayLength = arrayLength + 1;
46
82
 
47
- keys[1] = LSP2Utils.generateArrayKeyAtIndex(_arrayKey, newArrayLength - 1);
48
-
83
+ keys[0] = arrayLengthKey;
49
84
  values[0] = UtilsLib.uint256ToBytes(newArrayLength);
50
- values[2] = bytes.concat(_appendix, bytes8(uint64(arrayLength)));
85
+
86
+ keys[1] = LSP2Utils.generateArrayElementKeyAtIndex(arrayLengthKey, newArrayLength - 1);
87
+ values[1] = UtilsLib.addressToBytes(caller);
88
+
89
+ keys[2] = mapKey;
90
+ values[2] = bytes.concat(interfaceID, bytes8(uint64(arrayLength)));
91
+ } else {
92
+ revert InvalidLSP5ReceivedAssetsArrayLength(
93
+ encodedArrayLength,
94
+ encodedArrayLength.length
95
+ );
51
96
  }
52
97
  }
53
98
 
54
99
  /**
55
- * @dev Decrements the arrayLength, removes the Map, swaps the arrayKey that need to be removed with
56
- * the last `arrayKey` in the array and removes the last arrayKey with updating all modified entries
100
+ * @dev Generating the data keys/values to be removed/changed on the account after sending assets/vaults
101
+ *
102
+ * @param account The account where the Keys should be added
103
+ * @param arrayLengthKey The arrayLengthKey containing the number of the received assets/vaults
104
+ * @param mapKeyPrefix The mapKey prefix relative to LSP5ReceivedAssetsMap or LSP10VaultsMap Keys
105
+ * @param mapKeyToRemove The mapKey of the asset sent
106
+ * @param mapValue The mapValue of the asset/vault sent
57
107
  */
58
108
  function removeMapAndArrayKey(
59
- IERC725Y _account,
60
- bytes32 _arrayKey,
61
- bytes12 mapPrefix,
62
- bytes32 _mapKeyToRemove,
109
+ IERC725Y account,
110
+ bytes32 arrayLengthKey,
111
+ bytes10 mapKeyPrefix,
112
+ bytes32 mapKeyToRemove,
63
113
  bytes memory mapValue
64
114
  ) internal view returns (bytes32[] memory keys, bytes[] memory values) {
65
- uint64 index = extractIndexFromMap(mapValue);
66
- bytes32 arrayKeyToRemove = LSP2Utils.generateArrayKeyAtIndex(_arrayKey, index);
67
-
68
- bytes memory rawArrayLength = _account.getData(_arrayKey);
69
-
70
- uint256 arrayLength = abi.decode(rawArrayLength, (uint256));
71
-
115
+ // Updating the number of the received assets/vaults
116
+ bytes memory encodedArrayLength = account.getData(arrayLengthKey);
117
+ uint256 arrayLength = abi.decode(encodedArrayLength, (uint256));
72
118
  uint256 newLength = arrayLength - 1;
73
119
 
120
+ uint64 index = extractIndexFromMap(mapValue);
121
+ bytes32 arrayElementKeyToRemove = LSP2Utils.generateArrayElementKeyAtIndex(
122
+ arrayLengthKey,
123
+ index
124
+ );
125
+
74
126
  if (index == (arrayLength - 1)) {
127
+ /**
128
+ * We will be updating/removing 3 keys:
129
+ * - Keys[0]: [Update] The arrayLengthKey to contain the new number of the received assets/vaults
130
+ * - Keys[1]: [Remove] The element in arrayKey (Remove the address of the asset sent)
131
+ * - Keys[2]: [Remove] The mapKey (Remove the interfaceId and the index of the asset sent)
132
+ */
75
133
  keys = new bytes32[](3);
76
134
  values = new bytes[](3);
77
135
 
78
- keys[0] = _arrayKey;
136
+ keys[0] = arrayLengthKey;
79
137
  values[0] = UtilsLib.uint256ToBytes(newLength);
80
138
 
81
- keys[1] = _mapKeyToRemove;
139
+ keys[1] = mapKeyToRemove;
82
140
  values[1] = "";
83
141
 
84
- keys[2] = arrayKeyToRemove;
142
+ keys[2] = arrayElementKeyToRemove;
85
143
  values[2] = "";
144
+
145
+ // Swapping last element in ArrayKey with the element in ArrayKey to remove || {Swap and pop} method;
146
+ // check https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/structs/EnumerableSet.sol#L80
86
147
  } else {
148
+ /**
149
+ * We will be updating/removing 5 keys:
150
+ * - Keys[0]: [Update] The arrayLengthKey to contain the new number of the received assets/vaults
151
+ * - Keys[1]: [Remove] The mapKey of the asset to remove (Remove the interfaceId and the index of the asset sent)
152
+ * - Keys[2]: [Update] The element in arrayKey to remove (Swap with the address of the last element in Array)
153
+ * - Keys[3]: [Remove] The last element in arrayKey (Remove (pop) the address of the last element as it's already swapped)
154
+ * - Keys[4]: [Update] The mapKey of the last element in array (Update the new index and the interfaceID)
155
+ */
87
156
  keys = new bytes32[](5);
88
157
  values = new bytes[](5);
89
158
 
90
- keys[0] = _arrayKey;
159
+ keys[0] = arrayLengthKey;
91
160
  values[0] = UtilsLib.uint256ToBytes(newLength);
92
161
 
93
- keys[1] = _mapKeyToRemove;
162
+ keys[1] = mapKeyToRemove;
94
163
  values[1] = "";
95
164
 
96
- bytes32 lastKey = LSP2Utils.generateArrayKeyAtIndex(_arrayKey, newLength);
97
-
98
- bytes memory lastKeyValue = _account.getData(lastKey);
99
-
100
- bytes32 mapOfLastkey = LSP2Utils.generateMappingKey(mapPrefix, bytes20(lastKeyValue));
101
-
102
- bytes memory mapValueOfLastkey = _account.getData(mapOfLastkey);
103
-
104
- bytes memory appendix = BytesLib.slice(mapValueOfLastkey, 0, 4);
105
-
106
- keys[2] = arrayKeyToRemove;
107
- values[2] = lastKeyValue;
108
-
109
- keys[3] = lastKey;
165
+ // Generate all data Keys/values of the last element in Array to swap
166
+ // with data Keys/values of the asset to remove
167
+ bytes32 lastArrayElementKey = LSP2Utils.generateArrayElementKeyAtIndex(
168
+ arrayLengthKey,
169
+ newLength
170
+ );
171
+ bytes memory lastArrayElementValue = account.getData(lastArrayElementKey);
172
+
173
+ bytes32 lastArrayElementMapKey = LSP2Utils.generateMappingKey(
174
+ mapKeyPrefix,
175
+ bytes20(lastArrayElementValue)
176
+ );
177
+ bytes memory lastArrayElementMapValue = account.getData(lastArrayElementMapKey);
178
+ bytes memory interfaceID = BytesLib.slice(lastArrayElementMapValue, 0, 4);
179
+
180
+ keys[2] = arrayElementKeyToRemove;
181
+ values[2] = lastArrayElementValue;
182
+
183
+ keys[3] = lastArrayElementKey;
110
184
  values[3] = "";
111
185
 
112
- keys[4] = mapOfLastkey;
113
- values[4] = bytes.concat(appendix, bytes8(index));
186
+ keys[4] = lastArrayElementMapKey;
187
+ values[4] = bytes.concat(interfaceID, bytes8(index));
114
188
  }
115
189
  }
116
190
 
117
191
  function addMapAndArrayKeyViaKeyManager(
118
- IERC725Y _account,
119
- bytes32 _arrayKey,
120
- bytes32 _mapKey,
121
- address _sender,
122
- bytes4 _appendix,
123
- address _keyManager
192
+ IERC725Y account,
193
+ bytes32 arrayLengthKey,
194
+ bytes32 mapKey,
195
+ address caller,
196
+ bytes4 interfaceID,
197
+ address keyManager
124
198
  ) internal returns (bytes memory result) {
125
- (bytes32[] memory _keys, bytes[] memory _values) = addMapAndArrayKey(
126
- _account,
127
- _arrayKey,
128
- _mapKey,
129
- _sender,
130
- _appendix
199
+ (bytes32[] memory keys, bytes[] memory values) = addMapAndArrayKey(
200
+ account,
201
+ arrayLengthKey,
202
+ mapKey,
203
+ caller,
204
+ interfaceID
131
205
  );
132
- result = LSP6Utils.setDataViaKeyManager(_keyManager, _keys, _values);
206
+ result = LSP6Utils.setDataViaKeyManager(keyManager, keys, values);
133
207
  }
134
208
 
135
209
  function removeMapAndArrayKeyViaKeyManager(
136
- IERC725Y _account,
137
- bytes32 _arrayKey,
138
- bytes12 mapPrefix,
139
- bytes32 _mapKeyToRemove,
210
+ IERC725Y account,
211
+ bytes32 arrayLengthKey,
212
+ bytes10 mapKeyPrefix,
213
+ bytes32 mapKeyToRemove,
140
214
  bytes memory mapValue,
141
215
  address keyManager
142
216
  ) internal returns (bytes memory result) {
143
- (bytes32[] memory _keys, bytes[] memory _values) = removeMapAndArrayKey(
144
- _account,
145
- _arrayKey,
146
- mapPrefix,
147
- _mapKeyToRemove,
217
+ (bytes32[] memory keys, bytes[] memory values) = removeMapAndArrayKey(
218
+ account,
219
+ arrayLengthKey,
220
+ mapKeyPrefix,
221
+ mapKeyToRemove,
148
222
  mapValue
149
223
  );
150
- result = LSP6Utils.setDataViaKeyManager(keyManager, _keys, _values);
224
+ result = LSP6Utils.setDataViaKeyManager(keyManager, keys, values);
151
225
  }
152
226
 
153
227
  function extractIndexFromMap(bytes memory mapValue) internal pure returns (uint64) {
@@ -11,7 +11,7 @@ interface ILSP6KeyManager is
11
11
  IERC1271
12
12
  /* is ERC165 */
13
13
  {
14
- event Executed(uint256 indexed _value, bytes4 _selector);
14
+ event Executed(uint256 indexed value, bytes4 selector);
15
15
 
16
16
  /**
17
17
  * @notice returns the address of the account linked to this KeyManager
@@ -25,31 +25,31 @@ interface ILSP6KeyManager is
25
25
  function target() external view returns (address);
26
26
 
27
27
  /**
28
- * @notice get latest nonce for `_from` for channel ID: `_channel`
28
+ * @notice get latest nonce for `from` for channel ID: `channelId`
29
29
  * @dev use channel ID = 0 for sequential nonces, any other number for out-of-order execution (= execution in parallel)
30
- * @param _address caller address
31
- * @param _channel channel id
30
+ * @param from caller address
31
+ * @param channelId channel id
32
32
  */
33
- function getNonce(address _address, uint256 _channel) external view returns (uint256);
33
+ function getNonce(address from, uint256 channelId) external view returns (uint256);
34
34
 
35
35
  /**
36
- * @notice execute the following payload on the ERC725Account: `_calldata`
36
+ * @notice execute the following payload on the ERC725Account: `payload`
37
37
  * @dev the ERC725Account will return some data on successful call, or revert on failure
38
- * @param _calldata the payload to execute. Obtained in web3 via encodeABI()
39
- * @return result_ the data being returned by the ERC725 Account
38
+ * @param payload the payload to execute. Obtained in web3 via encodeABI()
39
+ * @return the data being returned by the ERC725 Account
40
40
  */
41
- function execute(bytes calldata _calldata) external payable returns (bytes memory);
41
+ function execute(bytes calldata payload) external payable returns (bytes memory);
42
42
 
43
43
  /**
44
44
  * @dev allows anybody to execute given they have a signed message from an executor
45
- * @param _signature bytes32 ethereum signature
46
- * @param _nonce the address' nonce (in a specific `_channel`), obtained via `getNonce(...)`. Used to prevent replay attack
47
- * @param _calldata obtained via encodeABI() in web3
48
- * @return result_ the data being returned by the ERC725 Account
45
+ * @param signature bytes32 ethereum signature
46
+ * @param nonce the address' nonce (in a specific `_channel`), obtained via `getNonce(...)`. Used to prevent replay attack
47
+ * @param payload obtained via encodeABI() in web3
48
+ * @return the data being returned by the ERC725 Account
49
49
  */
50
50
  function executeRelayCall(
51
- bytes memory _signature,
52
- uint256 _nonce,
53
- bytes calldata _calldata
51
+ bytes memory signature,
52
+ uint256 nonce,
53
+ bytes calldata payload
54
54
  ) external payable returns (bytes memory);
55
55
  }
@@ -17,20 +17,20 @@ bytes16 constant _LSP6KEY_ADDRESSPERMISSIONS_ARRAY_PREFIX = 0xdf30dba06db6a30e65
17
17
  // AddressPermissions:...
18
18
  bytes6 constant _LSP6KEY_ADDRESSPERMISSIONS_PREFIX = 0x4b80742de2bf;
19
19
 
20
- // bytes6(keccak256('AddressPermissions')) + bytes4(keccak256('Permissions')) + bytes2(0)
21
- bytes12 constant _LSP6KEY_ADDRESSPERMISSIONS_PERMISSIONS_PREFIX = 0x4b80742de2bf82acb3630000; // AddressPermissions:Permissions:<address> --> bytes32
20
+ // bytes6(keccak256('AddressPermissions')) + bytes4(keccak256('Permissions'))
21
+ bytes10 constant _LSP6KEY_ADDRESSPERMISSIONS_PERMISSIONS_PREFIX = 0x4b80742de2bf82acb363; // AddressPermissions:Permissions:<address> --> bytes32
22
22
 
23
- // bytes6(keccak256('AddressPermissions')) + bytes4(keccak256('AllowedAddresses')) + bytes2(0)
24
- bytes12 constant _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDADDRESSES_PREFIX = 0x4b80742de2bfc6dd6b3c0000; // AddressPermissions:AllowedAddresses:<address> --> address[]
23
+ // bytes6(keccak256('AddressPermissions')) + bytes4(keccak256('AllowedAddresses'))
24
+ bytes10 constant _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDADDRESSES_PREFIX = 0x4b80742de2bfc6dd6b3c; // AddressPermissions:AllowedAddresses:<address> --> address[]
25
25
 
26
- // bytes6(keccak256('AddressPermissions')) + bytes4(keccak256('AllowedFunctions')) + bytes2(0)
27
- bytes12 constant _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDFUNCTIONS_PREFIX = 0x4b80742de2bf8efea1e80000; // AddressPermissions:AllowedFunctions:<address> --> bytes4[]
26
+ // bytes6(keccak256('AddressPermissions')) + bytes4(keccak256('AllowedFunctions'))
27
+ bytes10 constant _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDFUNCTIONS_PREFIX = 0x4b80742de2bf8efea1e8; // AddressPermissions:AllowedFunctions:<address> --> bytes4[]
28
28
 
29
- // bytes6(keccak256('AddressPermissions')) + bytes4(keccak256('AllowedStandards')) + bytes2(0)
30
- bytes12 constant _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDSTANDARDS_PREFIX = 0x4b80742de2bf3efa94a30000; // AddressPermissions:AllowedStandards:<address> --> bytes4[]
29
+ // bytes6(keccak256('AddressPermissions')) + bytes4(keccak256('AllowedStandards'))
30
+ bytes10 constant _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDSTANDARDS_PREFIX = 0x4b80742de2bf3efa94a3; // AddressPermissions:AllowedStandards:<address> --> bytes4[]
31
31
 
32
- // bytes6(keccak256('AddressPermissions')) + bytes4(keccak256('AllowedERC725YKeys')) + bytes2(0)
33
- bytes12 constant _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDERC725YKEYS_PREFIX = 0x4b80742de2bf90b8b4850000; // AddressPermissions:AllowedERC725YKeys:<address> --> bytes32[]
32
+ // bytes6(keccak256('AddressPermissions')) + bytes4(keccak256('AllowedERC725YKeys'))
33
+ bytes10 constant _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDERC725YKEYS_PREFIX = 0x4b80742de2bf90b8b485; // AddressPermissions:AllowedERC725YKeys:<address> --> bytes32[]
34
34
 
35
35
  // DEFAULT PERMISSIONS VALUES
36
36
  bytes32 constant _PERMISSION_CHANGEOWNER = 0x0000000000000000000000000000000000000000000000000000000000000001;
@@ -43,23 +43,18 @@ bytes32 constant _PERMISSION_DELEGATECALL = 0x0000000000000000000000000000
43
43
  bytes32 constant _PERMISSION_DEPLOY = 0x0000000000000000000000000000000000000000000000000000000000000080;
44
44
  bytes32 constant _PERMISSION_TRANSFERVALUE = 0x0000000000000000000000000000000000000000000000000000000000000100;
45
45
  bytes32 constant _PERMISSION_SIGN = 0x0000000000000000000000000000000000000000000000000000000000000200;
46
+ bytes32 constant _PERMISSION_ENCRYPT = 0x0000000000000000000000000000000000000000000000000000000000000400;
46
47
 
47
48
  // SUPER PERMISSIONS
48
49
  // -----
49
50
  // allow to not check for AddressPermissions:AllowedERC725YKeys:...
50
- bytes32 constant _PERMISSION_SUPER_SETDATA = 0x0000000000000000000000000000000000000000000000000000000000000400;
51
+ bytes32 constant _PERMISSION_SUPER_SETDATA = 0x0000000000000000000000000000000000000000000000000000000000000800;
51
52
 
52
53
  // allow to not check for:
53
54
  // - AddressPermissions:AllowedAddress:...
54
55
  // - AddressPermissions:AllowedStandards:...
55
56
  // - AddressPermissions:AllowedFunctions:...
56
- bytes32 constant _PERMISSION_SUPER_TRANSFERVALUE = 0x0000000000000000000000000000000000000000000000000000000000000800;
57
- bytes32 constant _PERMISSION_SUPER_CALL = 0x0000000000000000000000000000000000000000000000000000000000001000;
58
- bytes32 constant _PERMISSION_SUPER_STATICCALL = 0x0000000000000000000000000000000000000000000000000000000000002000;
59
- bytes32 constant _PERMISSION_SUPER_DELEGATECALL = 0x0000000000000000000000000000000000000000000000000000000000004000;
60
-
61
-
62
- /// @dev see IERC725Y interface
63
- /// https://github.com/ERC725Alliance/ERC725/blob/main/implementations/contracts/interfaces/IERC725Y.sol
64
- bytes4 constant setDataSingleSelector = bytes4(keccak256("setData(bytes32,bytes)"));
65
- bytes4 constant setDataMultipleSelector = bytes4(keccak256("setData(bytes32[],bytes[])"));
57
+ bytes32 constant _PERMISSION_SUPER_TRANSFERVALUE = 0x0000000000000000000000000000000000000000000000000000000000001000;
58
+ bytes32 constant _PERMISSION_SUPER_CALL = 0x0000000000000000000000000000000000000000000000000000000000002000;
59
+ bytes32 constant _PERMISSION_SUPER_STATICCALL = 0x0000000000000000000000000000000000000000000000000000000000004000;
60
+ bytes32 constant _PERMISSION_SUPER_DELEGATECALL = 0x0000000000000000000000000000000000000000000000000000000000008000;
@@ -2,36 +2,73 @@
2
2
  pragma solidity ^0.8.0;
3
3
 
4
4
  /**
5
- * @dev revert when address `from` does not have any permissions set
5
+ * @dev reverts when address `from` does not have any permissions set
6
6
  * on the account linked to this Key Manager
7
7
  * @param from the address that does not have permissions
8
8
  */
9
9
  error NoPermissionsSet(address from);
10
10
 
11
11
  /**
12
- * @dev address `from` is not authorised to `permission`
12
+ * @dev reverts when address `from` is not authorised to perform `permission` on the linked account
13
13
  * @param permission permission required
14
14
  * @param from address not-authorised
15
15
  */
16
16
  error NotAuthorised(address from, string permission);
17
17
 
18
18
  /**
19
- * @dev address `from` is not authorised to interact with `disallowedAddress` via account
19
+ * @dev reverts when address `from` is not authorised to interact with `disallowedAddress` via the linked account
20
20
  * @param from address making the request
21
21
  * @param disallowedAddress address that `from` is not authorised to call
22
22
  */
23
23
  error NotAllowedAddress(address from, address disallowedAddress);
24
24
 
25
25
  /**
26
- * @dev address `from` is not authorised to run `disallowedFunction` via account
26
+ * @dev reverts when address `from` is restricted to interact only with smart contracts implementing specific standard interface(s)
27
+ * and try to call an address `addressNotImplementingAllowedStandard` that does not implement one of this restricted standard interfaces.
28
+ * @param from address making the request
29
+ * @param addressNotImplementingAllowedStandard the address of the smart contract that `from` is trying to interact with,
30
+ * and that does not implement an allowed interface.
31
+ */
32
+ error NotAllowedStandard(address from, address addressNotImplementingAllowedStandard);
33
+
34
+ /**
35
+ * @dev reverts when address `from` is not authorised to run `disallowedFunction` via the linked account
27
36
  * @param from address making the request
28
37
  * @param disallowedFunction bytes4 function selector that `from` is not authorised to run
29
38
  */
30
39
  error NotAllowedFunction(address from, bytes4 disallowedFunction);
31
40
 
32
41
  /**
33
- * @dev address `from` is not authorised to set the key `disallowedKey` on the account
42
+ * @dev reverts when address `from` is not authorised to set the key `disallowedKey` on the linked account
34
43
  * @param from address making the request
35
44
  * @param disallowedKey a bytes32 key that `from` is not authorised to set on the ERC725Y storage
36
45
  */
37
46
  error NotAllowedERC725YKey(address from, bytes32 disallowedKey);
47
+
48
+ /**
49
+ * @dev reverts when `dataKey` is a bytes32 that does not adhere to any of the
50
+ * permission data keys specified by the LSP6 standard
51
+ *
52
+ * @param dataKey the dataKey that does not match with any of the standard LSP6 permission data keys
53
+ */
54
+ error NotRecognisedPermissionKey(bytes32 dataKey);
55
+
56
+ /**
57
+ * @dev reverts when the address provided as a target (= account) linked to this KeyManager is invalid
58
+ * e.g. address(0)
59
+ */
60
+ error InvalidLSP6Target();
61
+
62
+ /**
63
+ * @dev reverts when the `signer` address retrieved from the `signature` has an invalid nonce: `invalidNonce`.
64
+ * @param signer the address of the signer
65
+ * @param invalidNonce the nonce retrieved for the `signer` address
66
+ * @param signature the signature used to retrieve the `signer` address
67
+ */
68
+ error InvalidRelayNonce(address signer, uint256 invalidNonce, bytes signature);
69
+
70
+ /**
71
+ * @dev reverts when trying to run an invalid function on the linked target account via the Key Manager.
72
+ * @param invalidFunction the bytes4 selector of the invalid function
73
+ */
74
+ error InvalidERC725Function(bytes4 invalidFunction);
@@ -1,8 +1,9 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
- pragma solidity ^0.8.6;
2
+ pragma solidity ^0.8.5;
3
3
 
4
4
  // modules
5
5
  import {LSP6KeyManagerCore} from "./LSP6KeyManagerCore.sol";
6
+ import {InvalidLSP6Target} from "./LSP6Errors.sol";
6
7
 
7
8
  /**
8
9
  * @title Implementation of a contract acting as a controller of an ERC725 Account, using permissions stored in the ERC725Y storage
@@ -12,9 +13,10 @@ import {LSP6KeyManagerCore} from "./LSP6KeyManagerCore.sol";
12
13
  contract LSP6KeyManager is LSP6KeyManagerCore {
13
14
  /**
14
15
  * @notice Initiate the account with the address of the ERC725Account contract and sets LSP6KeyManager InterfaceId
15
- * @param _account The address of the ER725Account to control
16
+ * @param target_ The address of the ER725Account to control
16
17
  */
17
- constructor(address _account) {
18
- target = _account;
18
+ constructor(address target_) {
19
+ if (target_ == address(0)) revert InvalidLSP6Target();
20
+ target = target_;
19
21
  }
20
22
  }