@lukso/lsp-smart-contracts 0.8.0 → 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 (81) hide show
  1. package/CONTRIBUTING.md +8 -0
  2. package/README.md +34 -21
  3. package/artifacts/LSP0ERC725Account.json +51 -5
  4. package/artifacts/LSP0ERC725AccountInit.json +51 -5
  5. package/artifacts/LSP11BasicSocialRecovery.json +2 -2
  6. package/artifacts/LSP11BasicSocialRecoveryInit.json +2 -2
  7. package/artifacts/LSP16UniversalFactory.json +31 -2
  8. package/artifacts/LSP1UniversalReceiverDelegateUP.json +19 -35
  9. package/artifacts/LSP1UniversalReceiverDelegateVault.json +13 -13
  10. package/artifacts/LSP4Compatibility.json +7 -2
  11. package/artifacts/LSP4DigitalAssetMetadata.json +7 -2
  12. package/artifacts/LSP4DigitalAssetMetadataInitAbstract.json +7 -2
  13. package/artifacts/LSP6KeyManager.json +91 -6
  14. package/artifacts/LSP6KeyManagerInit.json +103 -18
  15. package/artifacts/LSP7CappedSupply.json +12 -2
  16. package/artifacts/LSP7CappedSupplyInitAbstract.json +12 -2
  17. package/artifacts/LSP7CompatibleERC20.json +12 -2
  18. package/artifacts/LSP7CompatibleERC20InitAbstract.json +12 -2
  19. package/artifacts/LSP7CompatibleERC20Mintable.json +14 -4
  20. package/artifacts/LSP7CompatibleERC20MintableInit.json +14 -4
  21. package/artifacts/LSP7DigitalAsset.json +12 -2
  22. package/artifacts/LSP7DigitalAssetInitAbstract.json +12 -2
  23. package/artifacts/LSP7Mintable.json +14 -4
  24. package/artifacts/LSP7MintableInit.json +14 -4
  25. package/artifacts/LSP8CappedSupply.json +12 -2
  26. package/artifacts/LSP8CappedSupplyInitAbstract.json +12 -2
  27. package/artifacts/LSP8CompatibleERC721.json +12 -2
  28. package/artifacts/LSP8CompatibleERC721InitAbstract.json +12 -2
  29. package/artifacts/LSP8CompatibleERC721Mintable.json +14 -4
  30. package/artifacts/LSP8CompatibleERC721MintableInit.json +14 -4
  31. package/artifacts/LSP8IdentifiableDigitalAsset.json +12 -2
  32. package/artifacts/LSP8IdentifiableDigitalAssetInitAbstract.json +12 -2
  33. package/artifacts/LSP8Mintable.json +14 -4
  34. package/artifacts/LSP8MintableInit.json +14 -4
  35. package/artifacts/LSP9Vault.json +29 -5
  36. package/artifacts/LSP9VaultInit.json +29 -5
  37. package/artifacts/UniversalProfile.json +51 -5
  38. package/artifacts/UniversalProfileInit.json +51 -5
  39. package/common/constants.d.ts +461 -0
  40. package/common/constants.js +789 -0
  41. package/contracts/LSP0ERC725Account/ILSP0ERC725Account.sol +27 -0
  42. package/contracts/LSP0ERC725Account/LSP0Constants.sol +1 -1
  43. package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +353 -145
  44. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +1 -1
  45. package/contracts/LSP0ERC725Account/LSP0Utils.sol +50 -0
  46. package/contracts/LSP10ReceivedVaults/LSP10Utils.sol +48 -54
  47. package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryCore.sol +5 -6
  48. package/contracts/LSP14Ownable2Step/ILSP14Ownable2Step.sol +27 -4
  49. package/contracts/LSP14Ownable2Step/LSP14Ownable2Step.sol +36 -77
  50. package/contracts/LSP16UniversalFactory/LSP16UniversalFactory.sol +8 -8
  51. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +50 -57
  52. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +18 -8
  53. package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +12 -0
  54. package/contracts/LSP20CallVerification/ILSP20CallVerification.sol +30 -0
  55. package/contracts/LSP20CallVerification/LSP20CallVerification.sol +74 -0
  56. package/contracts/LSP20CallVerification/LSP20Errors.sol +15 -0
  57. package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +7 -7
  58. package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +50 -56
  59. package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +1 -1
  60. package/contracts/LSP6KeyManager/LSP6Constants.sol +8 -2
  61. package/contracts/LSP6KeyManager/LSP6Errors.sol +18 -1
  62. package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +126 -745
  63. package/contracts/LSP6KeyManager/LSP6Modules/LSP6ExecuteModule.sol +407 -0
  64. package/contracts/LSP6KeyManager/LSP6Modules/LSP6OwnershipModule.sol +25 -0
  65. package/contracts/LSP6KeyManager/LSP6Modules/LSP6SetDataModule.sol +633 -0
  66. package/contracts/LSP6KeyManager/LSP6Utils.sol +60 -15
  67. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +14 -23
  68. package/contracts/LSP7DigitalAsset/LSP7Errors.sol +5 -0
  69. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Errors.sol +5 -0
  70. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +19 -30
  71. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol +1 -3
  72. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol +1 -3
  73. package/contracts/LSP9Vault/ILSP9Vault.sol +19 -0
  74. package/contracts/LSP9Vault/LSP9Constants.sol +1 -1
  75. package/contracts/LSP9Vault/LSP9Vault.sol +11 -2
  76. package/contracts/LSP9Vault/LSP9VaultCore.sol +166 -83
  77. package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +11 -2
  78. package/module/constants.d.ts +461 -0
  79. package/module/constants.js +786 -0
  80. package/package.json +30 -6
  81. package/constants.js +0 -856
@@ -12,7 +12,6 @@ import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
12
12
  import {ERC725Y} from "@erc725/smart-contracts/contracts/ERC725Y.sol";
13
13
 
14
14
  // libraries
15
- import {Address} from "@openzeppelin/contracts/utils/Address.sol";
16
15
  import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
17
16
  import {LSP1Utils} from "../LSP1Utils.sol";
18
17
  import {LSP2Utils} from "../../LSP2ERC725YJSONSchema/LSP2Utils.sol";
@@ -43,7 +42,6 @@ import "../LSP1Errors.sol";
43
42
  */
44
43
  contract LSP1UniversalReceiverDelegateUP is ERC165, ILSP1UniversalReceiver {
45
44
  using ERC165Checker for address;
46
- using Address for address;
47
45
 
48
46
  /**
49
47
  * @inheritdoc ILSP1UniversalReceiver
@@ -69,32 +67,27 @@ contract LSP1UniversalReceiverDelegateUP is ERC165, ILSP1UniversalReceiver {
69
67
  // solhint-disable avoid-tx-origin
70
68
  if (notifier == tx.origin) revert CannotRegisterEOAsAsAssets(notifier);
71
69
 
72
- (address keyManager, bool ownerIsKeyManager) = _validateCallerViaKeyManager();
73
- if (!ownerIsKeyManager) return "LSP1: account owner is not a LSP6KeyManager";
74
-
75
70
  // if the contract being transferred doesn't support LSP9, do not register it as a received vault
76
- if (mapPrefix == _LSP10_VAULTS_MAP_KEY_PREFIX) {
77
- if (notifier.isContract()) {
78
- if (!notifier.supportsERC165InterfaceUnchecked(_INTERFACEID_LSP9))
79
- return "LSP1: not an LSP9Vault ownership transfer";
80
- }
71
+ if (
72
+ mapPrefix == _LSP10_VAULTS_MAP_KEY_PREFIX &&
73
+ notifier.code.length > 0 &&
74
+ !notifier.supportsERC165InterfaceUnchecked(_INTERFACEID_LSP9)
75
+ ) {
76
+ return "LSP1: not an LSP9Vault ownership transfer";
81
77
  }
82
78
 
83
79
  bytes32 notifierMapKey = LSP2Utils.generateMappingKey(mapPrefix, bytes20(notifier));
84
80
  bytes memory notifierMapValue = IERC725Y(msg.sender).getData(notifierMapKey);
81
+ bool isMapValueSet = bytes20(notifierMapValue) != bytes20(0);
85
82
 
86
83
  if (isReceiving) {
87
- // if the map value is already set, then do nothing
88
- if (bytes12(notifierMapValue) != bytes12(0))
89
- return "LSP1: asset received is already registered";
84
+ if (isMapValueSet) return "LSP1: asset received is already registered";
90
85
 
91
- result = _whenReceiving(typeId, notifier, keyManager, notifierMapKey, interfaceID);
86
+ return _whenReceiving(typeId, notifier, notifierMapKey, interfaceID);
92
87
  } else {
93
- // if there is no map value for the asset/vault to remove, then do nothing
94
- if (bytes12(notifierMapValue) == bytes12(0))
95
- return "LSP1: asset sent is not registered";
88
+ if (!isMapValueSet) return "LSP1: asset sent is not registered";
96
89
 
97
- result = _whenSending(typeId, notifier, keyManager, notifierMapKey, notifierMapValue);
90
+ return _whenSending(typeId, notifier, notifierMapKey, notifierMapValue);
98
91
  }
99
92
  }
100
93
 
@@ -108,25 +101,36 @@ contract LSP1UniversalReceiverDelegateUP is ERC165, ILSP1UniversalReceiver {
108
101
  function _whenReceiving(
109
102
  bytes32 typeId,
110
103
  address notifier,
111
- address keyManager,
112
104
  bytes32 notifierMapKey,
113
105
  bytes4 interfaceID
114
- ) internal virtual returns (bytes memory result) {
106
+ ) internal virtual returns (bytes memory) {
107
+ bytes32[] memory dataKeys;
108
+ bytes[] memory dataValues;
109
+
115
110
  // if it's a token transfer (LSP7/LSP8)
116
111
  if (typeId != _TYPEID_LSP9_OwnershipTransferred_RecipientNotification) {
117
112
  // if the amount sent is 0, then do not update the keys
118
113
  uint256 balance = ILSP7DigitalAsset(notifier).balanceOf(msg.sender);
119
114
  if (balance == 0) return "LSP1: balance not updated";
120
115
 
121
- (bytes32[] memory dataKeys, bytes[] memory dataValues) = LSP5Utils
122
- .generateReceivedAssetKeys(msg.sender, notifier, notifierMapKey, interfaceID);
116
+ (dataKeys, dataValues) = LSP5Utils.generateReceivedAssetKeys(
117
+ msg.sender,
118
+ notifier,
119
+ notifierMapKey,
120
+ interfaceID
121
+ );
123
122
 
124
- result = LSP6Utils.setDataViaKeyManager(keyManager, dataKeys, dataValues);
123
+ IERC725Y(msg.sender).setData(dataKeys, dataValues);
124
+ return "";
125
125
  } else {
126
- (bytes32[] memory dataKeys, bytes[] memory dataValues) = LSP10Utils
127
- .generateReceivedVaultKeys(msg.sender, notifier, notifierMapKey, interfaceID);
128
-
129
- result = LSP6Utils.setDataViaKeyManager(keyManager, dataKeys, dataValues);
126
+ (dataKeys, dataValues) = LSP10Utils.generateReceivedVaultKeys(
127
+ msg.sender,
128
+ notifier,
129
+ notifierMapKey
130
+ );
131
+
132
+ IERC725Y(msg.sender).setData(dataKeys, dataValues);
133
+ return "";
130
134
  }
131
135
  }
132
136
 
@@ -138,46 +142,35 @@ contract LSP1UniversalReceiverDelegateUP is ERC165, ILSP1UniversalReceiver {
138
142
  function _whenSending(
139
143
  bytes32 typeId,
140
144
  address notifier,
141
- address keyManager,
142
145
  bytes32 notifierMapKey,
143
146
  bytes memory notifierMapValue
144
- ) internal virtual returns (bytes memory result) {
147
+ ) internal virtual returns (bytes memory) {
148
+ bytes32[] memory dataKeys;
149
+ bytes[] memory dataValues;
150
+
145
151
  // if it's a token transfer (LSP7/LSP8)
146
152
  if (typeId != _TYPEID_LSP9_OwnershipTransferred_SenderNotification) {
147
153
  // if the amount sent is not the full balance, then do not update the keys
148
154
  uint256 balance = ILSP7DigitalAsset(notifier).balanceOf(msg.sender);
149
155
  if (balance != 0) return "LSP1: full balance is not sent";
150
156
 
151
- (bytes32[] memory dataKeys, bytes[] memory dataValues) = LSP5Utils
152
- .generateSentAssetKeys(msg.sender, notifierMapKey, notifierMapValue);
157
+ (dataKeys, dataValues) = LSP5Utils.generateSentAssetKeys(
158
+ msg.sender,
159
+ notifierMapKey,
160
+ notifierMapValue
161
+ );
153
162
 
154
- result = LSP6Utils.setDataViaKeyManager(keyManager, dataKeys, dataValues);
163
+ IERC725Y(msg.sender).setData(dataKeys, dataValues);
164
+ return "";
155
165
  } else {
156
- (bytes32[] memory dataKeys, bytes[] memory dataValues) = LSP10Utils
157
- .generateSentVaultKeys(msg.sender, notifierMapKey, notifierMapValue);
158
-
159
- result = LSP6Utils.setDataViaKeyManager(keyManager, dataKeys, dataValues);
160
- }
161
- }
162
-
163
- /**
164
- * @dev Check if the caller is owned by an LSP6KeyManager and linked to
165
- * the owner returned
166
- */
167
- function _validateCallerViaKeyManager()
168
- internal
169
- view
170
- virtual
171
- returns (address accountOwner, bool ownerIsKeyManager)
172
- {
173
- accountOwner = ERC725Y(msg.sender).owner();
174
- if (accountOwner.supportsERC165InterfaceUnchecked(_INTERFACEID_LSP6))
175
- ownerIsKeyManager = true;
176
-
177
- if (ownerIsKeyManager) {
178
- address target = ILSP6KeyManager(accountOwner).target();
179
- // check if the caller is the same account controlled by the keyManager
180
- if (target != msg.sender) revert CallerNotLSP6LinkedTarget(msg.sender, target);
166
+ (dataKeys, dataValues) = LSP10Utils.generateSentVaultKeys(
167
+ msg.sender,
168
+ notifierMapKey,
169
+ notifierMapValue
170
+ );
171
+
172
+ IERC725Y(msg.sender).setData(dataKeys, dataValues);
173
+ return "";
181
174
  }
182
175
  }
183
176
 
@@ -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);
@@ -270,13 +270,13 @@ library LSP2Utils {
270
270
  /**
271
271
  * Pointer will always land on these values:
272
272
  *
273
- * ↓↓
274
- * 03 a00000
275
- * 05 fff83a0011
276
- * 20 aa0000000000000000000000000000000000000000000000000000000000cafe
277
- * 12 bb000000000000000000000000000000beef
278
- * 19 cc00000000000000000000000000000000000000000000deed
279
- * ↑↑
273
+ * ↓↓↓↓
274
+ * 0003 a00000
275
+ * 0005 fff83a0011
276
+ * 0020 aa0000000000000000000000000000000000000000000000000000000000cafe
277
+ * 0012 bb000000000000000000000000000000beef
278
+ * 0019 cc00000000000000000000000000000000000000000000deed
279
+ * ↑↑↑↑
280
280
  *
281
281
  * The pointer can only land on the length of the following bytes value.
282
282
  */
@@ -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();