@lukso/lsp-smart-contracts 0.8.1 → 0.9.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 (72) hide show
  1. package/README.md +14 -1
  2. package/artifacts/LSP0ERC725Account.json +51 -5
  3. package/artifacts/LSP0ERC725AccountInit.json +51 -5
  4. package/artifacts/LSP11BasicSocialRecovery.json +2 -2
  5. package/artifacts/LSP11BasicSocialRecoveryInit.json +2 -2
  6. package/artifacts/LSP16UniversalFactory.json +31 -2
  7. package/artifacts/LSP1UniversalReceiverDelegateUP.json +19 -35
  8. package/artifacts/LSP1UniversalReceiverDelegateVault.json +13 -13
  9. package/artifacts/LSP4Compatibility.json +7 -2
  10. package/artifacts/LSP4DigitalAssetMetadata.json +7 -2
  11. package/artifacts/LSP4DigitalAssetMetadataInitAbstract.json +7 -2
  12. package/artifacts/LSP6KeyManager.json +91 -6
  13. package/artifacts/LSP6KeyManagerInit.json +103 -18
  14. package/artifacts/LSP7CappedSupply.json +7 -2
  15. package/artifacts/LSP7CappedSupplyInitAbstract.json +7 -2
  16. package/artifacts/LSP7CompatibleERC20.json +7 -2
  17. package/artifacts/LSP7CompatibleERC20InitAbstract.json +7 -2
  18. package/artifacts/LSP7CompatibleERC20Mintable.json +9 -4
  19. package/artifacts/LSP7CompatibleERC20MintableInit.json +9 -4
  20. package/artifacts/LSP7DigitalAsset.json +7 -2
  21. package/artifacts/LSP7DigitalAssetInitAbstract.json +7 -2
  22. package/artifacts/LSP7Mintable.json +9 -4
  23. package/artifacts/LSP7MintableInit.json +9 -4
  24. package/artifacts/LSP8CappedSupply.json +7 -2
  25. package/artifacts/LSP8CappedSupplyInitAbstract.json +7 -2
  26. package/artifacts/LSP8CompatibleERC721.json +7 -2
  27. package/artifacts/LSP8CompatibleERC721InitAbstract.json +7 -2
  28. package/artifacts/LSP8CompatibleERC721Mintable.json +9 -4
  29. package/artifacts/LSP8CompatibleERC721MintableInit.json +9 -4
  30. package/artifacts/LSP8IdentifiableDigitalAsset.json +7 -2
  31. package/artifacts/LSP8IdentifiableDigitalAssetInitAbstract.json +7 -2
  32. package/artifacts/LSP8Mintable.json +9 -4
  33. package/artifacts/LSP8MintableInit.json +9 -4
  34. package/artifacts/LSP9Vault.json +29 -5
  35. package/artifacts/LSP9VaultInit.json +29 -5
  36. package/artifacts/UniversalProfile.json +51 -5
  37. package/artifacts/UniversalProfileInit.json +51 -5
  38. package/common/constants.d.ts +50 -327
  39. package/common/constants.js +21 -17
  40. package/contracts/LSP0ERC725Account/ILSP0ERC725Account.sol +27 -0
  41. package/contracts/LSP0ERC725Account/LSP0Constants.sol +1 -1
  42. package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +344 -195
  43. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +1 -1
  44. package/contracts/LSP10ReceivedVaults/LSP10Utils.sol +47 -51
  45. package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryCore.sol +5 -6
  46. package/contracts/LSP14Ownable2Step/ILSP14Ownable2Step.sol +27 -4
  47. package/contracts/LSP14Ownable2Step/LSP14Ownable2Step.sol +36 -77
  48. package/contracts/LSP16UniversalFactory/LSP16UniversalFactory.sol +8 -8
  49. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +50 -55
  50. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +18 -8
  51. package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +12 -0
  52. package/contracts/LSP20CallVerification/ILSP20CallVerification.sol +30 -0
  53. package/contracts/LSP20CallVerification/LSP20CallVerification.sol +74 -0
  54. package/contracts/LSP20CallVerification/LSP20Errors.sol +15 -0
  55. package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +50 -56
  56. package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +1 -1
  57. package/contracts/LSP6KeyManager/LSP6Constants.sol +8 -2
  58. package/contracts/LSP6KeyManager/LSP6Errors.sol +18 -1
  59. package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +83 -12
  60. package/contracts/LSP6KeyManager/LSP6Modules/LSP6ExecuteModule.sol +277 -99
  61. package/contracts/LSP6KeyManager/LSP6Modules/LSP6SetDataModule.sol +36 -9
  62. package/contracts/LSP6KeyManager/LSP6Utils.sol +30 -15
  63. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +12 -17
  64. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +12 -17
  65. package/contracts/LSP9Vault/ILSP9Vault.sol +19 -0
  66. package/contracts/LSP9Vault/LSP9Constants.sol +1 -1
  67. package/contracts/LSP9Vault/LSP9Vault.sol +11 -2
  68. package/contracts/LSP9Vault/LSP9VaultCore.sol +81 -58
  69. package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +11 -2
  70. package/module/constants.d.ts +50 -327
  71. package/module/constants.js +20 -16
  72. package/package.json +6 -4
@@ -57,31 +57,41 @@ contract LSP1UniversalReceiverDelegateVault is ERC165, ILSP1UniversalReceiver {
57
57
  bytes32 notifierMapKey = LSP2Utils.generateMappingKey(mapPrefix, bytes20(notifier));
58
58
  bytes memory notifierMapValue = IERC725Y(msg.sender).getData(notifierMapKey);
59
59
 
60
+ bytes32[] memory dataKeys;
61
+ bytes[] memory dataValues;
62
+
60
63
  if (isReceiving) {
61
64
  // if the map value is already set, then do nothing
62
- if (bytes12(notifierMapValue) != bytes12(0))
65
+ if (bytes20(notifierMapValue) != bytes20(0))
63
66
  return "URD: asset received is already registered";
64
67
 
65
68
  // if the amount sent is 0, then do not update the keys
66
69
  uint256 balance = ILSP7DigitalAsset(notifier).balanceOf(msg.sender);
67
70
  if (balance == 0) return "LSP1: balance not updated";
68
71
 
69
- (bytes32[] memory receiverDataKeys, bytes[] memory receiverDataValues) = LSP5Utils
70
- .generateReceivedAssetKeys(msg.sender, notifier, notifierMapKey, interfaceID);
72
+ (dataKeys, dataValues) = LSP5Utils.generateReceivedAssetKeys(
73
+ msg.sender,
74
+ notifier,
75
+ notifierMapKey,
76
+ interfaceID
77
+ );
71
78
 
72
- IERC725Y(msg.sender).setData(receiverDataKeys, receiverDataValues);
79
+ IERC725Y(msg.sender).setData(dataKeys, dataValues);
73
80
  } else {
74
81
  // if there is no map value for the asset to remove, then do nothing
75
- if (bytes12(notifierMapValue) == bytes12(0))
82
+ if (bytes20(notifierMapValue) == bytes20(0))
76
83
  return "LSP1: asset sent is not registered";
77
84
  // if it's a token transfer (LSP7/LSP8)
78
85
  uint256 balance = ILSP7DigitalAsset(notifier).balanceOf(msg.sender);
79
86
  if (balance != 0) return "LSP1: full balance is not sent";
80
87
 
81
- (bytes32[] memory senderDataKeys, bytes[] memory senderDataValues) = LSP5Utils
82
- .generateSentAssetKeys(msg.sender, notifierMapKey, notifierMapValue);
88
+ (dataKeys, dataValues) = LSP5Utils.generateSentAssetKeys(
89
+ msg.sender,
90
+ notifierMapKey,
91
+ notifierMapValue
92
+ );
83
93
 
84
- IERC725Y(msg.sender).setData(senderDataKeys, senderDataValues);
94
+ IERC725Y(msg.sender).setData(dataKeys, dataValues);
85
95
  }
86
96
  }
87
97
 
@@ -3,9 +3,11 @@ pragma solidity ^0.8.4;
3
3
 
4
4
  // libraries
5
5
  import {Address} from "@openzeppelin/contracts/utils/Address.sol";
6
+ import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
6
7
 
7
8
  // constants
8
9
  import "./ILSP1UniversalReceiver.sol";
10
+ import {_INTERFACEID_LSP1} from "../LSP1UniversalReceiver/LSP1Constants.sol";
9
11
  import "../LSP0ERC725Account/LSP0Constants.sol";
10
12
  import "../LSP5ReceivedAssets/LSP5Constants.sol";
11
13
  import "../LSP7DigitalAsset/LSP7Constants.sol";
@@ -15,6 +17,16 @@ import "../LSP14Ownable2Step/LSP14Constants.sol";
15
17
  import "../LSP10ReceivedVaults/LSP10Constants.sol";
16
18
 
17
19
  library LSP1Utils {
20
+ function tryNotifyUniversalReceiver(
21
+ address lsp1Implementation,
22
+ bytes32 typeId,
23
+ bytes memory data
24
+ ) internal {
25
+ if (ERC165Checker.supportsERC165InterfaceUnchecked(lsp1Implementation, _INTERFACEID_LSP1)) {
26
+ ILSP1UniversalReceiver(lsp1Implementation).universalReceiver(typeId, data);
27
+ }
28
+ }
29
+
18
30
  function callUniversalReceiverWithCallerInfos(
19
31
  address universalReceiverDelegate,
20
32
  bytes32 typeId,
@@ -0,0 +1,30 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.4;
3
+
4
+ /**
5
+ * @dev Interface to be inherited for contract supporting LSP20-CallVerification
6
+ */
7
+ interface ILSP20CallVerification {
8
+ /**
9
+ * @return magicValue MUST return the first 3 bytes of `lsp20VerifyCall(address,uint256,bytes)` function selector if the call to
10
+ * the function is allowed, concatened with a byte that determines if the lsp20VerifyCallResult function should
11
+ * be called after the original function call. The byte that invoke the lsp20VerifyCallResult function is strictly `0x01`.
12
+ *
13
+ * @param caller The address who called the function on the msg.sender
14
+ * @param value The value sent by the caller to the function called on the msg.sender
15
+ * @param receivedCalldata The receivedCalldata sent by the caller to the msg.sender
16
+ */
17
+ function lsp20VerifyCall(
18
+ address caller,
19
+ uint256 value,
20
+ bytes memory receivedCalldata
21
+ ) external returns (bytes4 magicValue);
22
+
23
+ /**
24
+ * @return MUST return the lsp20VerifyCallResult function selector if the call to the function is allowed
25
+ *
26
+ * @param callHash The keccak256 of the parameters of {lsp20VerifyCall} concatenated
27
+ * @param result The value result of the function called on the msg.sender
28
+ */
29
+ function lsp20VerifyCallResult(bytes32 callHash, bytes memory result) external returns (bytes4);
30
+ }
@@ -0,0 +1,74 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.4;
3
+
4
+ // interfaces
5
+
6
+ import {ILSP20CallVerification as ILSP20} from "./ILSP20CallVerification.sol";
7
+
8
+ // errors
9
+ import "./LSP20Errors.sol";
10
+
11
+ /**
12
+ * @title Implementation of contract calling the verification functions according to LSP20CallVerification
13
+ * @dev Module to be inherited used to verify the execution of functions according to a verifier address.
14
+ * Verification can happen before or after execution based on a magicValue.
15
+ */
16
+ abstract contract LSP20CallVerification {
17
+ /**
18
+ * @dev Calls {lsp20VerifyCall} function on the logicVerifier.
19
+ * Reverts in case the value returned does not match the magic value (lsp20VerifyCall selector)
20
+ * Returns whether a verification after the execution should happen based on the last byte of the magicValue
21
+ */
22
+ function _verifyCall(address logicVerifier) internal virtual returns (bool verifyAfter) {
23
+ (bool success, bytes memory returnedData) = logicVerifier.call(
24
+ abi.encodeWithSelector(ILSP20.lsp20VerifyCall.selector, msg.sender, msg.value, msg.data)
25
+ );
26
+
27
+ if (!success) _revert(false, returnedData);
28
+
29
+ if (returnedData.length < 32) revert LSP20InvalidMagicValue(false, returnedData);
30
+
31
+ bytes32 magicValue = abi.decode(returnedData, (bytes32));
32
+
33
+ if (bytes3(magicValue) != bytes3(ILSP20.lsp20VerifyCall.selector))
34
+ revert LSP20InvalidMagicValue(false, returnedData);
35
+
36
+ return bytes1(magicValue[3]) == 0x01 ? true : false;
37
+ }
38
+
39
+ /**
40
+ * @dev Calls {lsp20VerifyCallResult} function on the logicVerifier.
41
+ * Reverts in case the value returned does not match the magic value (lsp20VerifyCallResult selector)
42
+ */
43
+ function _verifyCallResult(address logicVerifier, bytes memory callResult) internal virtual {
44
+ (bool success, bytes memory returnedData) = logicVerifier.call(
45
+ abi.encodeWithSelector(
46
+ ILSP20.lsp20VerifyCallResult.selector,
47
+ keccak256(abi.encodePacked(msg.sender, msg.value, msg.data)),
48
+ callResult
49
+ )
50
+ );
51
+
52
+ if (!success) _revert(true, returnedData);
53
+
54
+ if (
55
+ returnedData.length < 32 ||
56
+ bytes4(abi.decode(returnedData, (bytes32))) != ILSP20.lsp20VerifyCallResult.selector
57
+ ) revert LSP20InvalidMagicValue(true, returnedData);
58
+ }
59
+
60
+ function _revert(bool postCall, bytes memory returnedData) internal pure {
61
+ // Look for revert reason and bubble it up if present
62
+ if (returnedData.length > 0) {
63
+ // The easiest way to bubble the revert reason is using memory via assembly
64
+ // solhint-disable no-inline-assembly
65
+ /// @solidity memory-safe-assembly
66
+ assembly {
67
+ let returndata_size := mload(returnedData)
68
+ revert(add(32, returnedData), returndata_size)
69
+ }
70
+ } else {
71
+ revert LSP20CallingVerifierFailed(postCall);
72
+ }
73
+ }
74
+ }
@@ -0,0 +1,15 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.4;
3
+
4
+ /**
5
+ * @dev reverts when the call to the owner fail with no revert reason
6
+ * @param postCall True if the execution call was done, False otherwise
7
+ */
8
+ error LSP20CallingVerifierFailed(bool postCall);
9
+
10
+ /**
11
+ * @dev reverts when the call to the owner does not return the magic value
12
+ * @param postCall True if the execution call was done, False otherwise
13
+ * @param postCall The data returned by the call to the logic verifier
14
+ */
15
+ error LSP20InvalidMagicValue(bool postCall, bytes returnedData);
@@ -14,25 +14,25 @@ import "../LSP7DigitalAsset/LSP7Constants.sol";
14
14
 
15
15
  /**
16
16
  * @dev reverts when the value stored under the 'LSP5ReceivedAssets[]' data key is not valid.
17
- * The value stored under this data key should be exactly 32 bytes long.
17
+ * The value stored under this data key should be exactly 16 bytes long.
18
18
  *
19
19
  * Only possible valid values are:
20
- * - any valid uint256 values
21
- * i.e. 0x0000000000000000000000000000000000000000000000000000000000000000 (zero), meaning empty array, no assets received.
22
- * i.e. 0x0000000000000000000000000000000000000000000000000000000000000005 (non-zero), meaning 5 array elements, 5 assets received.
20
+ * - any valid uint128 values
21
+ * i.e. 0x00000000000000000000000000000000 (zero), empty array, no assets received.
22
+ * i.e. 0x00000000000000000000000000000005 (non-zero), 5 array elements, 5 assets received.
23
23
  *
24
24
  * - 0x (nothing stored under this data key, equivalent to empty array)
25
25
  *
26
- * @param invalidValue the invalid value stored under the LSP5ReceivedAssets[] data key
27
- * @param invalidValueLength the invalid number of bytes stored under the LSP5ReceivedAssets[] data key (MUST be 32)
26
+ * @param invalidValueStored the invalid value stored under the LSP5ReceivedAssets[] data key
27
+ * @param invalidValueLength the invalid number of bytes stored under the LSP5ReceivedAssets[] data key (MUST be exactly 16 bytes long)
28
28
  */
29
- error InvalidLSP5ReceivedAssetsArrayLength(bytes invalidValue, uint256 invalidValueLength);
29
+ error InvalidLSP5ReceivedAssetsArrayLength(bytes invalidValueStored, uint256 invalidValueLength);
30
30
 
31
31
  /**
32
- * @dev reverts when the received assets index is superior to uint64
33
- * @param index the received assets index
32
+ * @dev reverts when the `LSP5ReceivedAssets[]` array reaches its maximum limit (max(uint128))
33
+ * @param notRegisteredAsset the address of the asset that could not be registered
34
34
  */
35
- error ReceivedAssetsIndexSuperiorToUint64(uint256 index);
35
+ error MaxLSP5ReceivedAssetsCountReached(address notRegisteredAsset);
36
36
 
37
37
  /**
38
38
  * @dev reverts when the received assets index is superior to uint128
@@ -68,44 +68,32 @@ library LSP5Utils {
68
68
  IERC725Y account = IERC725Y(receiver);
69
69
  bytes memory encodedArrayLength = getLSP5ReceivedAssetsCount(account);
70
70
 
71
- // If it's the first asset to receive
72
- if (encodedArrayLength.length == 0) {
73
- keys[0] = _LSP5_RECEIVED_ASSETS_ARRAY_KEY;
74
- values[0] = bytes.concat(bytes32(uint256(1)));
75
-
76
- keys[1] = LSP2Utils.generateArrayElementKeyAtIndex(_LSP5_RECEIVED_ASSETS_ARRAY_KEY, 0);
77
- values[1] = bytes.concat(bytes20(asset));
78
-
79
- keys[2] = assetMapKey;
80
- values[2] = bytes.concat(interfaceID, bytes8(0));
81
-
82
- // If the storage is already initiated
83
- } else if (encodedArrayLength.length == 32) {
84
- uint256 oldArrayLength = uint256(bytes32(encodedArrayLength));
71
+ // CHECK it's either the first asset received,
72
+ // or the storage is already set with a valid `uint128` value
73
+ if (encodedArrayLength.length != 0 && encodedArrayLength.length != 16) {
74
+ revert InvalidLSP5ReceivedAssetsArrayLength({
75
+ invalidValueStored: encodedArrayLength,
76
+ invalidValueLength: encodedArrayLength.length
77
+ });
78
+ }
85
79
 
86
- if (oldArrayLength + 1 >= type(uint64).max) {
87
- revert ReceivedAssetsIndexSuperiorToUint64(oldArrayLength);
88
- }
80
+ uint128 oldArrayLength = uint128(bytes16(encodedArrayLength));
89
81
 
90
- uint128 oldArrayLength128 = uint128(oldArrayLength);
82
+ if (oldArrayLength == type(uint128).max) {
83
+ revert MaxLSP5ReceivedAssetsCountReached({notRegisteredAsset: asset});
84
+ }
91
85
 
92
- keys[0] = _LSP5_RECEIVED_ASSETS_ARRAY_KEY;
93
- values[0] = bytes.concat(bytes32(oldArrayLength + 1));
86
+ keys[0] = _LSP5_RECEIVED_ASSETS_ARRAY_KEY;
87
+ values[0] = bytes.concat(bytes16(oldArrayLength + 1));
94
88
 
95
- keys[1] = LSP2Utils.generateArrayElementKeyAtIndex(
96
- _LSP5_RECEIVED_ASSETS_ARRAY_KEY,
97
- oldArrayLength128
98
- );
99
- values[1] = bytes.concat(bytes20(asset));
89
+ keys[1] = LSP2Utils.generateArrayElementKeyAtIndex(
90
+ _LSP5_RECEIVED_ASSETS_ARRAY_KEY,
91
+ oldArrayLength
92
+ );
93
+ values[1] = bytes.concat(bytes20(asset));
100
94
 
101
- keys[2] = assetMapKey;
102
- values[2] = bytes.concat(interfaceID, bytes8(uint64(oldArrayLength)));
103
- } else {
104
- revert InvalidLSP5ReceivedAssetsArrayLength(
105
- encodedArrayLength,
106
- encodedArrayLength.length
107
- );
108
- }
95
+ keys[2] = assetMapKey;
96
+ values[2] = bytes.concat(interfaceID, bytes16(oldArrayLength));
109
97
  }
110
98
 
111
99
  /**
@@ -121,12 +109,20 @@ library LSP5Utils {
121
109
  bytes memory assetInterfaceIdAndIndex
122
110
  ) internal view returns (bytes32[] memory keys, bytes[] memory values) {
123
111
  IERC725Y account = IERC725Y(sender);
112
+ bytes memory lsp5ReceivedAssetsCountValue = getLSP5ReceivedAssetsCount(account);
113
+
114
+ if (lsp5ReceivedAssetsCountValue.length != 16) {
115
+ revert InvalidLSP5ReceivedAssetsArrayLength({
116
+ invalidValueStored: lsp5ReceivedAssetsCountValue,
117
+ invalidValueLength: lsp5ReceivedAssetsCountValue.length
118
+ });
119
+ }
124
120
 
125
121
  // Updating the number of the received assets
126
- uint256 oldArrayLength = uint256(bytes32(getLSP5ReceivedAssetsCount(account)));
127
- uint256 newArrayLength = oldArrayLength - 1;
122
+ uint128 oldArrayLength = uint128(bytes16(lsp5ReceivedAssetsCountValue));
123
+ uint128 newArrayLength = oldArrayLength - 1;
128
124
 
129
- uint64 index = extractIndexFromMap(assetInterfaceIdAndIndex);
125
+ uint128 index = extractIndexFromMap(assetInterfaceIdAndIndex);
130
126
  bytes32 assetInArrayKey = LSP2Utils.generateArrayElementKeyAtIndex(
131
127
  _LSP5_RECEIVED_ASSETS_ARRAY_KEY,
132
128
  index
@@ -143,7 +139,7 @@ library LSP5Utils {
143
139
  values = new bytes[](3);
144
140
 
145
141
  keys[0] = _LSP5_RECEIVED_ASSETS_ARRAY_KEY;
146
- values[0] = bytes.concat(bytes32(newArrayLength));
142
+ values[0] = bytes.concat(bytes16(newArrayLength));
147
143
 
148
144
  keys[1] = assetInArrayKey;
149
145
  values[1] = "";
@@ -166,7 +162,7 @@ library LSP5Utils {
166
162
  values = new bytes[](5);
167
163
 
168
164
  keys[0] = _LSP5_RECEIVED_ASSETS_ARRAY_KEY;
169
- values[0] = bytes.concat(bytes32(newArrayLength));
165
+ values[0] = bytes.concat(bytes16(newArrayLength));
170
166
 
171
167
  keys[1] = assetMapKey;
172
168
  values[1] = "";
@@ -175,13 +171,11 @@ library LSP5Utils {
175
171
  revert ReceivedAssetsIndexSuperiorToUint128(newArrayLength);
176
172
  }
177
173
 
178
- uint128 newArrayLength128 = uint128(newArrayLength);
179
-
180
174
  // Generate all data Keys/values of the last element in Array to swap
181
175
  // with data Keys/values of the asset to remove
182
176
  bytes32 lastAssetInArrayKey = LSP2Utils.generateArrayElementKeyAtIndex(
183
177
  _LSP5_RECEIVED_ASSETS_ARRAY_KEY,
184
- newArrayLength128
178
+ newArrayLength
185
179
  );
186
180
 
187
181
  bytes20 lastAssetInArrayAddress = bytes20(account.getData(lastAssetInArrayKey));
@@ -201,7 +195,7 @@ library LSP5Utils {
201
195
  values[3] = "";
202
196
 
203
197
  keys[4] = lastAssetInArrayMapKey;
204
- values[4] = bytes.concat(interfaceID, bytes8(index));
198
+ values[4] = bytes.concat(interfaceID, bytes16(index));
205
199
  }
206
200
  }
207
201
 
@@ -210,10 +204,10 @@ library LSP5Utils {
210
204
  }
211
205
 
212
206
  /**
213
- * @dev returns the index from a maping
207
+ * @dev returns the index from the LSP5ReceivedAssetMap
214
208
  */
215
- function extractIndexFromMap(bytes memory mapValue) internal pure returns (uint64) {
216
- bytes memory val = BytesLib.slice(mapValue, 4, 8);
217
- return BytesLib.toUint64(val, 0);
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);
218
212
  }
219
213
  }
@@ -11,7 +11,7 @@ interface ILSP6KeyManager is
11
11
  IERC1271
12
12
  /* is ERC165 */
13
13
  {
14
- event Executed(bytes4 indexed selector, uint256 indexed value);
14
+ event VerifiedCall(address indexed signer, uint256 indexed value, bytes4 indexed selector);
15
15
 
16
16
  /**
17
17
  * @notice returns the address of the account linked to this KeyManager
@@ -33,8 +33,8 @@ bytes10 constant _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDCALLS_PREFIX = 0x4b80742de2b
33
33
  // - AddressPermissions:AllowedERC725YDataKeys:...
34
34
  // - AddressPermissions:AllowedCalls
35
35
  bytes32 constant _PERMISSION_CHANGEOWNER = 0x0000000000000000000000000000000000000000000000000000000000000001;
36
- bytes32 constant _PERMISSION_ADDCONTROLLER = 0x0000000000000000000000000000000000000000000000000000000000000002;
37
- bytes32 constant _PERMISSION_CHANGEPERMISSIONS = 0x0000000000000000000000000000000000000000000000000000000000000004;
36
+ bytes32 constant _PERMISSION_ADDCONTROLLER = 0x0000000000000000000000000000000000000000000000000000000000000002;
37
+ bytes32 constant _PERMISSION_EDITPERMISSIONS = 0x0000000000000000000000000000000000000000000000000000000000000004;
38
38
  bytes32 constant _PERMISSION_ADDEXTENSIONS = 0x0000000000000000000000000000000000000000000000000000000000000008;
39
39
  bytes32 constant _PERMISSION_CHANGEEXTENSIONS = 0x0000000000000000000000000000000000000000000000000000000000000010;
40
40
  bytes32 constant _PERMISSION_ADDUNIVERSALRECEIVERDELEGATE = 0x0000000000000000000000000000000000000000000000000000000000000020;
@@ -63,3 +63,9 @@ bytes4 constant _LSP6_EXECUTE_SELECTOR = 0x09c5eabe;
63
63
  bytes4 constant _LSP6_EXECUTE_BATCH_SELECTOR = 0xbf3e1f7b;
64
64
  bytes4 constant _LSP6_EXECUTE_RELAYCALL_SELECTOR = 0x902d5fa0;
65
65
  bytes4 constant _LSP6_EXECUTE_RELAYCALL_BATCH_SELECTOR = 0xbd68663a;
66
+
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
@@ -88,8 +88,9 @@ error NoCallsAllowed(address from);
88
88
  /**
89
89
  * @dev reverts when `value` is not encoded properly using the CompactBytesArray
90
90
  * @param value the value to check for an CompactBytesArray
91
+ * @param context a brief description of where the error occured
91
92
  */
92
- error InvalidEncodedAllowedERC725YDataKeys(bytes value);
93
+ error InvalidEncodedAllowedERC725YDataKeys(bytes value, string context);
93
94
 
94
95
  /**
95
96
  * @dev a `from` address is not allowed to have 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffff
@@ -141,3 +142,19 @@ error DelegateCallDisallowedViaKeyManager();
141
142
  * @dev reverts when the payload is invalid.
142
143
  */
143
144
  error InvalidPayload(bytes payload);
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
+ /**
153
+ * @dev reverts when sending value to the `setData(..)` functions
154
+ */
155
+ error CannotSendValueToSetData();
156
+
157
+ /**
158
+ * @dev reverts when calling the KeyManager through execute(..)
159
+ */
160
+ error CallingKeyManagerNotAllowed();
@@ -4,6 +4,9 @@ pragma solidity ^0.8.5;
4
4
  // interfaces
5
5
  import {IERC1271} from "@openzeppelin/contracts/interfaces/IERC1271.sol";
6
6
  import {ILSP6KeyManager} from "./ILSP6KeyManager.sol";
7
+ import {
8
+ ILSP20CallVerification as ILSP20
9
+ } from "../LSP20CallVerification/ILSP20CallVerification.sol";
7
10
 
8
11
  // modules
9
12
  import {ILSP14Ownable2Step} from "../LSP14Ownable2Step/ILSP14Ownable2Step.sol";
@@ -31,7 +34,9 @@ import {
31
34
  InvalidRelayNonce,
32
35
  NoPermissionsSet,
33
36
  InvalidERC725Function,
34
- NotAuthorised
37
+ NotAuthorised,
38
+ CallerIsNotTheTarget,
39
+ CannotSendValueToSetData
35
40
  } from "./LSP6Errors.sol";
36
41
 
37
42
  // constants
@@ -61,6 +66,7 @@ import {
61
66
  abstract contract LSP6KeyManagerCore is
62
67
  ERC165,
63
68
  ILSP6KeyManager,
69
+ ILSP20,
64
70
  LSP6SetDataModule,
65
71
  LSP6ExecuteModule,
66
72
  LSP6OwnershipModule
@@ -82,6 +88,45 @@ abstract contract LSP6KeyManagerCore is
82
88
  return _target;
83
89
  }
84
90
 
91
+ /**
92
+ * @inheritdoc ILSP20
93
+ */
94
+ function lsp20VerifyCall(
95
+ address caller,
96
+ uint256 msgValue,
97
+ bytes calldata data
98
+ ) external returns (bytes4) {
99
+ if (msg.sender != _target) revert CallerIsNotTheTarget(msg.sender);
100
+
101
+ bool isSetData = false;
102
+ if (bytes4(data) == SETDATA_SELECTOR || bytes4(data) == SETDATA_ARRAY_SELECTOR) {
103
+ isSetData = true;
104
+ }
105
+
106
+ _nonReentrantBefore(isSetData, caller);
107
+
108
+ _verifyPermissions(caller, msgValue, data);
109
+ emit VerifiedCall(msg.sender, msgValue, bytes4(data));
110
+
111
+ // if it's a setData call, do not invoke the `lsp20VerifyCallResult(..)` function
112
+ return
113
+ isSetData
114
+ ? bytes4(bytes.concat(bytes3(ILSP20.lsp20VerifyCall.selector), hex"00"))
115
+ : bytes4(bytes.concat(bytes3(ILSP20.lsp20VerifyCall.selector), hex"01"));
116
+ }
117
+
118
+ /**
119
+ * @inheritdoc ILSP20
120
+ */
121
+ function lsp20VerifyCallResult(
122
+ bytes32, /*callHash*/
123
+ bytes memory /*result*/
124
+ ) external returns (bytes4) {
125
+ if (msg.sender != _target) revert CallerIsNotTheTarget(msg.sender);
126
+ _nonReentrantAfter();
127
+ return ILSP20.lsp20VerifyCallResult.selector;
128
+ }
129
+
85
130
  /**
86
131
  * @dev See {IERC165-supportsInterface}.
87
132
  */
@@ -210,10 +255,22 @@ abstract contract LSP6KeyManagerCore is
210
255
  revert InvalidPayload(payload);
211
256
  }
212
257
 
213
- _nonReentrantBefore(msg.sender);
214
- _verifyPermissions(msg.sender, payload);
258
+ bool isSetData;
259
+ if (bytes4(payload) == SETDATA_SELECTOR || bytes4(payload) == SETDATA_ARRAY_SELECTOR) {
260
+ isSetData = true;
261
+ }
262
+
263
+ _nonReentrantBefore(isSetData, msg.sender);
264
+
265
+ _verifyPermissions(msg.sender, msgValue, payload);
266
+ emit VerifiedCall(msg.sender, msgValue, bytes4(payload));
267
+
215
268
  bytes memory result = _executePayload(msgValue, payload);
216
- _nonReentrantAfter();
269
+
270
+ if (!isSetData) {
271
+ _nonReentrantAfter();
272
+ }
273
+
217
274
  return result;
218
275
  }
219
276
 
@@ -239,7 +296,12 @@ abstract contract LSP6KeyManagerCore is
239
296
  signature
240
297
  );
241
298
 
242
- _nonReentrantBefore(signer);
299
+ bool isSetData;
300
+ if (bytes4(payload) == SETDATA_SELECTOR || bytes4(payload) == SETDATA_ARRAY_SELECTOR) {
301
+ isSetData = true;
302
+ }
303
+
304
+ _nonReentrantBefore(isSetData, signer);
243
305
 
244
306
  if (!_isValidNonce(signer, nonce)) {
245
307
  revert InvalidRelayNonce(signer, nonce, signature);
@@ -248,11 +310,14 @@ abstract contract LSP6KeyManagerCore is
248
310
  // increase nonce after successful verification
249
311
  _nonceStore[signer][nonce >> 128]++;
250
312
 
251
- _verifyPermissions(signer, payload);
313
+ _verifyPermissions(signer, msgValue, payload);
314
+ emit VerifiedCall(signer, msgValue, bytes4(payload));
252
315
 
253
316
  bytes memory result = _executePayload(msgValue, payload);
254
317
 
255
- _nonReentrantAfter();
318
+ if (!isSetData) {
319
+ _nonReentrantAfter();
320
+ }
256
321
 
257
322
  return result;
258
323
  }
@@ -267,8 +332,6 @@ abstract contract LSP6KeyManagerCore is
267
332
  virtual
268
333
  returns (bytes memory)
269
334
  {
270
- emit Executed(bytes4(payload), msgValue);
271
-
272
335
  (bool success, bytes memory returnData) = _target.call{value: msgValue, gas: gasleft()}(
273
336
  payload
274
337
  );
@@ -301,7 +364,11 @@ abstract contract LSP6KeyManagerCore is
301
364
  * @param from either the caller of `execute(...)` or the signer of `executeRelayCall(...)`.
302
365
  * @param payload the payload to execute on the `target`.
303
366
  */
304
- function _verifyPermissions(address from, bytes calldata payload) internal view virtual {
367
+ function _verifyPermissions(
368
+ address from,
369
+ uint256 msgValue,
370
+ bytes calldata payload
371
+ ) internal view virtual {
305
372
  bytes32 permissions = ERC725Y(_target).getPermissionsFor(from);
306
373
  if (permissions == bytes32(0)) revert NoPermissionsSet(from);
307
374
 
@@ -309,12 +376,14 @@ abstract contract LSP6KeyManagerCore is
309
376
 
310
377
  // ERC725Y.setData(bytes32,bytes)
311
378
  if (erc725Function == SETDATA_SELECTOR) {
379
+ if (msgValue != 0) revert CannotSendValueToSetData();
312
380
  (bytes32 inputKey, bytes memory inputValue) = abi.decode(payload[4:], (bytes32, bytes));
313
381
 
314
382
  LSP6SetDataModule._verifyCanSetData(_target, from, permissions, inputKey, inputValue);
315
383
 
316
384
  // ERC725Y.setData(bytes32[],bytes[])
317
385
  } else if (erc725Function == SETDATA_ARRAY_SELECTOR) {
386
+ if (msgValue != 0) revert CannotSendValueToSetData();
318
387
  (bytes32[] memory inputKeys, bytes[] memory inputValues) = abi.decode(
319
388
  payload[4:],
320
389
  (bytes32[], bytes[])
@@ -347,7 +416,7 @@ abstract contract LSP6KeyManagerCore is
347
416
  * the status is `_ENTERED` in order to revert the call unless the caller has the REENTRANCY permission
348
417
  * Used in the beginning of the `nonReentrant` modifier, before the method execution starts.
349
418
  */
350
- function _nonReentrantBefore(address from) internal virtual {
419
+ function _nonReentrantBefore(bool isSetData, address from) internal virtual {
351
420
  if (_reentrancyStatus) {
352
421
  // CHECK the caller has REENTRANCY permission
353
422
  _requirePermissions(
@@ -356,7 +425,9 @@ abstract contract LSP6KeyManagerCore is
356
425
  _PERMISSION_REENTRANCY
357
426
  );
358
427
  } else {
359
- _reentrancyStatus = true;
428
+ if (!isSetData) {
429
+ _reentrancyStatus = true;
430
+ }
360
431
  }
361
432
  }
362
433