@lukso/lsp-smart-contracts 0.8.0 → 0.8.1

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 (57) hide show
  1. package/CONTRIBUTING.md +8 -0
  2. package/README.md +21 -21
  3. package/artifacts/LSP0ERC725Account.json +2 -2
  4. package/artifacts/LSP0ERC725AccountInit.json +2 -2
  5. package/artifacts/LSP11BasicSocialRecovery.json +2 -2
  6. package/artifacts/LSP11BasicSocialRecoveryInit.json +2 -2
  7. package/artifacts/LSP1UniversalReceiverDelegateUP.json +2 -2
  8. package/artifacts/LSP1UniversalReceiverDelegateVault.json +2 -2
  9. package/artifacts/LSP6KeyManager.json +2 -2
  10. package/artifacts/LSP6KeyManagerInit.json +2 -2
  11. package/artifacts/LSP7CappedSupply.json +5 -0
  12. package/artifacts/LSP7CappedSupplyInitAbstract.json +5 -0
  13. package/artifacts/LSP7CompatibleERC20.json +5 -0
  14. package/artifacts/LSP7CompatibleERC20InitAbstract.json +5 -0
  15. package/artifacts/LSP7CompatibleERC20Mintable.json +7 -2
  16. package/artifacts/LSP7CompatibleERC20MintableInit.json +7 -2
  17. package/artifacts/LSP7DigitalAsset.json +5 -0
  18. package/artifacts/LSP7DigitalAssetInitAbstract.json +5 -0
  19. package/artifacts/LSP7Mintable.json +7 -2
  20. package/artifacts/LSP7MintableInit.json +7 -2
  21. package/artifacts/LSP8CappedSupply.json +5 -0
  22. package/artifacts/LSP8CappedSupplyInitAbstract.json +5 -0
  23. package/artifacts/LSP8CompatibleERC721.json +5 -0
  24. package/artifacts/LSP8CompatibleERC721InitAbstract.json +5 -0
  25. package/artifacts/LSP8CompatibleERC721Mintable.json +7 -2
  26. package/artifacts/LSP8CompatibleERC721MintableInit.json +7 -2
  27. package/artifacts/LSP8IdentifiableDigitalAsset.json +5 -0
  28. package/artifacts/LSP8IdentifiableDigitalAssetInitAbstract.json +5 -0
  29. package/artifacts/LSP8Mintable.json +7 -2
  30. package/artifacts/LSP8MintableInit.json +7 -2
  31. package/artifacts/LSP9Vault.json +2 -2
  32. package/artifacts/LSP9VaultInit.json +2 -2
  33. package/artifacts/UniversalProfile.json +2 -2
  34. package/artifacts/UniversalProfileInit.json +2 -2
  35. package/common/constants.d.ts +738 -0
  36. package/common/constants.js +785 -0
  37. package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +87 -28
  38. package/contracts/LSP0ERC725Account/LSP0Utils.sol +50 -0
  39. package/contracts/LSP10ReceivedVaults/LSP10Utils.sol +3 -5
  40. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +2 -4
  41. package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +7 -7
  42. package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +44 -734
  43. package/contracts/LSP6KeyManager/LSP6Modules/LSP6ExecuteModule.sol +229 -0
  44. package/contracts/LSP6KeyManager/LSP6Modules/LSP6OwnershipModule.sol +25 -0
  45. package/contracts/LSP6KeyManager/LSP6Modules/LSP6SetDataModule.sol +606 -0
  46. package/contracts/LSP6KeyManager/LSP6Utils.sol +31 -1
  47. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +2 -6
  48. package/contracts/LSP7DigitalAsset/LSP7Errors.sol +5 -0
  49. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Errors.sol +5 -0
  50. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +7 -13
  51. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol +1 -3
  52. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol +1 -3
  53. package/contracts/LSP9Vault/LSP9VaultCore.sol +85 -25
  54. package/module/constants.d.ts +738 -0
  55. package/module/constants.js +782 -0
  56. package/package.json +26 -4
  57. package/constants.js +0 -856
@@ -41,6 +41,9 @@ import {_INTERFACEID_LSP14} from "../LSP14Ownable2Step/LSP14Constants.sol";
41
41
 
42
42
  import {_LSP17_EXTENSION_PREFIX} from "../LSP17ContractExtension/LSP17Constants.sol";
43
43
 
44
+ // errors
45
+ import "../LSP17ContractExtension/LSP17Errors.sol";
46
+
44
47
  /**
45
48
  * @title Core Implementation of ERC725Account
46
49
  * @author Fabian Vogelsteller <fabian@lukso.network>, Jean Cavallera (CJ42), Yamen Merhi (YamenMerhi)
@@ -68,36 +71,14 @@ abstract contract LSP0ERC725AccountCore is
68
71
  /**
69
72
  * @dev Emits an event when receiving native tokens
70
73
  *
71
- * Executed when receiving native tokens with empty calldata.
74
+ * Executed:
75
+ * - when receiving some native tokens without any additional data.
76
+ * - on empty calls to the contract.
72
77
  */
73
78
  receive() external payable virtual {
74
79
  if (msg.value != 0) emit ValueReceived(msg.sender, msg.value);
75
80
  }
76
81
 
77
- /**
78
- * @dev Returns the extension stored under the `_LSP17_EXTENSION_PREFIX` data key
79
- * mapped to the functionSelector provided.
80
- *
81
- * If no extension is stored, returns the address(0)
82
- */
83
- function _getExtension(bytes4 functionSelector)
84
- internal
85
- view
86
- virtual
87
- override
88
- returns (address)
89
- {
90
- bytes32 mappedExtensionDataKey = LSP2Utils.generateMappingKey(
91
- _LSP17_EXTENSION_PREFIX,
92
- functionSelector
93
- );
94
-
95
- // Check if there is an extension for the function selector provided
96
- address extension = address(bytes20(_getData(mappedExtensionDataKey)));
97
-
98
- return extension;
99
- }
100
-
101
82
  // solhint-disable no-complex-fallback
102
83
 
103
84
  /**
@@ -111,8 +92,7 @@ abstract contract LSP0ERC725AccountCore is
111
92
  * The call to the extension is appended with bytes20 (msg.sender) and bytes32 (msg.value).
112
93
  * Returns the return value on success and revert in case of failure.
113
94
  *
114
- * If the msg.data is shorter than 4 bytes or the first 4 bytes are 0s
115
- * do not check for an extension and return
95
+ * If the msg.data is shorter than 4 bytes do not check for an extension and return
116
96
  *
117
97
  * Executed when:
118
98
  * - the first 4 bytes of the calldata do not match any publicly callable functions from the contract ABI.
@@ -120,11 +100,90 @@ abstract contract LSP0ERC725AccountCore is
120
100
  */
121
101
  fallback() external payable virtual {
122
102
  if (msg.value != 0) emit ValueReceived(msg.sender, msg.value);
123
- if (msg.data.length < 4 || msg.sig == bytes4(0)) return;
103
+ if (msg.data.length < 4) return;
124
104
 
125
105
  _fallbackLSP17Extendable();
126
106
  }
127
107
 
108
+ /**
109
+ * @dev Forwards the call to an extension mapped to a function selector. If no extension address
110
+ * is mapped to the function selector (address(0)), then revert.
111
+ *
112
+ * The bytes4(0) msg.sig is an exception, the function won't revert if there is no extension found
113
+ * mapped to bytes4(0), but will execute the call to the extension in case it existed.
114
+ *
115
+ * The call to the extension is appended with bytes20 (msg.sender) and bytes32 (msg.value).
116
+ * Returns the return value on success and revert in case of failure.
117
+ *
118
+ * Because the function uses assembly {return()/revert()} to terminate the call, it cannot be
119
+ * called before other codes in fallback().
120
+ *
121
+ * Otherwise, the codes after _fallbackLSP17Extendable() may never be reached.
122
+ */
123
+ function _fallbackLSP17Extendable() internal virtual override {
124
+ // If there is a function selector
125
+ address extension = _getExtension(msg.sig);
126
+
127
+ // if no extension was found for bytes4(0) return don't revert
128
+ if (msg.sig == bytes4(0) && extension == address(0)) return;
129
+
130
+ // if no extension was found, revert
131
+ if (extension == address(0)) revert NoExtensionFoundForFunctionSelector(msg.sig);
132
+
133
+ // solhint-disable no-inline-assembly
134
+ // if the extension was found, call the extension with the msg.data
135
+ // appended with bytes20(address) and bytes32(msg.value)
136
+ assembly {
137
+ calldatacopy(0, 0, calldatasize())
138
+
139
+ // The msg.sender address is shifted to the left by 12 bytes to remove the padding
140
+ // Then the address without padding is stored right after the calldata
141
+ mstore(calldatasize(), shl(96, caller()))
142
+
143
+ // The msg.value is stored right after the calldata + msg.sender
144
+ mstore(add(calldatasize(), 20), callvalue())
145
+
146
+ // Add 52 bytes for the msg.sender and msg.value appended at the end of the calldata
147
+ let success := call(gas(), extension, 0, 0, add(calldatasize(), 52), 0, 0)
148
+
149
+ // Copy the returned data
150
+ returndatacopy(0, 0, returndatasize())
151
+
152
+ switch success
153
+ // call returns 0 on failed calls
154
+ case 0 {
155
+ revert(0, returndatasize())
156
+ }
157
+ default {
158
+ return(0, returndatasize())
159
+ }
160
+ }
161
+ }
162
+
163
+ /**
164
+ * @dev Returns the extension stored under the `_LSP17_EXTENSION_PREFIX` data key
165
+ * mapped to the functionSelector provided.
166
+ *
167
+ * If no extension is stored, returns the address(0)
168
+ */
169
+ function _getExtension(bytes4 functionSelector)
170
+ internal
171
+ view
172
+ virtual
173
+ override
174
+ returns (address)
175
+ {
176
+ bytes32 mappedExtensionDataKey = LSP2Utils.generateMappingKey(
177
+ _LSP17_EXTENSION_PREFIX,
178
+ functionSelector
179
+ );
180
+
181
+ // Check if there is an extension for the function selector provided
182
+ address extension = address(bytes20(_getData(mappedExtensionDataKey)));
183
+
184
+ return extension;
185
+ }
186
+
128
187
  /**
129
188
  * @dev Returns true if this contract implements the interface defined by
130
189
  * `interfaceId`.
@@ -0,0 +1,50 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.4;
3
+
4
+ // libraries
5
+ import {LSP2Utils} from "../LSP2ERC725YJSONSchema/LSP2Utils.sol";
6
+
7
+ // constants
8
+ import {
9
+ _INTERFACEID_LSP1,
10
+ _LSP1_UNIVERSAL_RECEIVER_DELEGATE_PREFIX,
11
+ _LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY
12
+ } from "../LSP1UniversalReceiver/LSP1Constants.sol";
13
+
14
+ /**
15
+ * @title Utility functions to query the storage of an LSP0ERC725Account
16
+ * @author Jean Cavallera (CJ42), Yamen Merhi (YamenMerhi)
17
+ */
18
+ library LSP0Utils {
19
+ /**
20
+ * @dev query internally the ERC725Y storage of a LSP0ERC725YContract to retrieve
21
+ * the value set for the `LSP1UniversalReceiverDelegate` data key.
22
+ * @param erc725YStorage a reference to the ERC725Y storage mapping.
23
+ * @return the bytes value stored under the `LSP1UniversalReceiverDelegate` data key.
24
+ */
25
+ function getLSP1DelegateValue(mapping(bytes32 => bytes) storage erc725YStorage)
26
+ internal
27
+ view
28
+ returns (bytes memory)
29
+ {
30
+ return erc725YStorage[_LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY];
31
+ }
32
+
33
+ /**
34
+ * @dev query internally the storage of a LSP0ERC725Account to retrieve
35
+ * the value set for the `LSP1UniversalReceiverDelegate:<bytes32>` data key for a specific typeId.
36
+ * @param erc725YStorage a reference to the ERC725Y storage mapping.
37
+ * @param typeId a bytes32 typeId;
38
+ * @return the bytes value stored under the `LSP1UniversalReceiverDelegate:<bytes32>` data key.
39
+ */
40
+ function getLSP1DelegateValueForTypeId(
41
+ mapping(bytes32 => bytes) storage erc725YStorage,
42
+ bytes32 typeId
43
+ ) internal view returns (bytes memory) {
44
+ bytes32 lsp1TypeIdDataKey = LSP2Utils.generateMappingKey(
45
+ _LSP1_UNIVERSAL_RECEIVER_DELEGATE_PREFIX,
46
+ bytes20(typeId)
47
+ );
48
+ return erc725YStorage[lsp1TypeIdDataKey];
49
+ }
50
+ }
@@ -54,13 +54,11 @@ library LSP10Utils {
54
54
  * @param vault The address of the vault being received
55
55
  * @param vaultMapKey The map key of the vault being received containing the interfaceId of the
56
56
  * vault and the index in the array
57
- * @param interfaceID The interfaceID of the vault being received
58
57
  */
59
58
  function generateReceivedVaultKeys(
60
59
  address receiver,
61
60
  address vault,
62
- bytes32 vaultMapKey,
63
- bytes4 interfaceID
61
+ bytes32 vaultMapKey
64
62
  ) internal view returns (bytes32[] memory keys, bytes[] memory values) {
65
63
  keys = new bytes32[](3);
66
64
  values = new bytes[](3);
@@ -77,7 +75,7 @@ library LSP10Utils {
77
75
  values[1] = bytes.concat(bytes20(vault));
78
76
 
79
77
  keys[2] = vaultMapKey;
80
- values[2] = bytes.concat(interfaceID, bytes8(0));
78
+ values[2] = bytes.concat(_INTERFACEID_LSP9, bytes8(0));
81
79
 
82
80
  // If the storage is already initiated
83
81
  } else if (encodedArrayLength.length == 32) {
@@ -98,7 +96,7 @@ library LSP10Utils {
98
96
  values[1] = bytes.concat(bytes20(vault));
99
97
 
100
98
  keys[2] = vaultMapKey;
101
- values[2] = bytes.concat(interfaceID, bytes8(uint64(oldArrayLength)));
99
+ values[2] = bytes.concat(_INTERFACEID_LSP9, bytes8(uint64(oldArrayLength)));
102
100
  } else {
103
101
  revert InvalidLSP10ReceivedVaultsArrayLength(
104
102
  encodedArrayLength,
@@ -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
@@ -74,7 +72,7 @@ contract LSP1UniversalReceiverDelegateUP is ERC165, ILSP1UniversalReceiver {
74
72
 
75
73
  // if the contract being transferred doesn't support LSP9, do not register it as a received vault
76
74
  if (mapPrefix == _LSP10_VAULTS_MAP_KEY_PREFIX) {
77
- if (notifier.isContract()) {
75
+ if (notifier.code.length > 0) {
78
76
  if (!notifier.supportsERC165InterfaceUnchecked(_INTERFACEID_LSP9))
79
77
  return "LSP1: not an LSP9Vault ownership transfer";
80
78
  }
@@ -124,7 +122,7 @@ contract LSP1UniversalReceiverDelegateUP is ERC165, ILSP1UniversalReceiver {
124
122
  result = LSP6Utils.setDataViaKeyManager(keyManager, dataKeys, dataValues);
125
123
  } else {
126
124
  (bytes32[] memory dataKeys, bytes[] memory dataValues) = LSP10Utils
127
- .generateReceivedVaultKeys(msg.sender, notifier, notifierMapKey, interfaceID);
125
+ .generateReceivedVaultKeys(msg.sender, notifier, notifierMapKey);
128
126
 
129
127
  result = LSP6Utils.setDataViaKeyManager(keyManager, dataKeys, dataValues);
130
128
  }
@@ -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
  */