@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
@@ -4,6 +4,7 @@ pragma solidity ^0.8.4;
4
4
  // interfaces
5
5
  import {IERC1271} from "@openzeppelin/contracts/interfaces/IERC1271.sol";
6
6
  import {ILSP1UniversalReceiver} from "../LSP1UniversalReceiver/ILSP1UniversalReceiver.sol";
7
+ import {ILSP20CallVerification} from "../LSP20CallVerification/ILSP20CallVerification.sol";
7
8
 
8
9
  // libraries
9
10
  import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol";
@@ -12,6 +13,7 @@ import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165C
12
13
  import {Address} from "@openzeppelin/contracts/utils/Address.sol";
13
14
  import {LSP1Utils} from "../LSP1UniversalReceiver/LSP1Utils.sol";
14
15
  import {LSP2Utils} from "../LSP2ERC725YJSONSchema/LSP2Utils.sol";
16
+ import {GasLib} from "../Utils/GasLib.sol";
15
17
 
16
18
  // modules
17
19
  import {ERC725YCore} from "@erc725/smart-contracts/contracts/ERC725YCore.sol";
@@ -19,10 +21,10 @@ import {ERC725XCore} from "@erc725/smart-contracts/contracts/ERC725XCore.sol";
19
21
  import {OwnableUnset} from "@erc725/smart-contracts/contracts/custom/OwnableUnset.sol";
20
22
  import {LSP14Ownable2Step} from "../LSP14Ownable2Step/LSP14Ownable2Step.sol";
21
23
  import {LSP17Extendable} from "../LSP17ContractExtension/LSP17Extendable.sol";
24
+ import {LSP20CallVerification} from "../LSP20CallVerification/LSP20CallVerification.sol";
22
25
 
23
26
  // constants
24
27
  import "@erc725/smart-contracts/contracts/constants.sol";
25
- import "@erc725/smart-contracts/contracts/errors.sol";
26
28
  import {
27
29
  _INTERFACEID_LSP0,
28
30
  _INTERFACEID_ERC1271,
@@ -42,6 +44,7 @@ import {_INTERFACEID_LSP14} from "../LSP14Ownable2Step/LSP14Constants.sol";
42
44
  import {_LSP17_EXTENSION_PREFIX} from "../LSP17ContractExtension/LSP17Constants.sol";
43
45
 
44
46
  // errors
47
+ import "@erc725/smart-contracts/contracts/errors.sol";
45
48
  import "../LSP17ContractExtension/LSP17Errors.sol";
46
49
 
47
50
  /**
@@ -52,10 +55,11 @@ import "../LSP17ContractExtension/LSP17Errors.sol";
52
55
  abstract contract LSP0ERC725AccountCore is
53
56
  ERC725XCore,
54
57
  ERC725YCore,
58
+ IERC1271,
59
+ ILSP1UniversalReceiver,
55
60
  LSP14Ownable2Step,
56
61
  LSP17Extendable,
57
- IERC1271,
58
- ILSP1UniversalReceiver
62
+ LSP20CallVerification
59
63
  {
60
64
  using ERC165Checker for address;
61
65
  using LSP1Utils for address;
@@ -106,141 +110,29 @@ abstract contract LSP0ERC725AccountCore is
106
110
  }
107
111
 
108
112
  /**
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.
113
+ * @dev Receives and executes a batch of function calls on this contract.
122
114
  */
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())
115
+ function batchCalls(bytes[] calldata data) public returns (bytes[] memory results) {
116
+ results = new bytes[](data.length);
117
+ for (uint256 i; i < data.length; i = GasLib.uncheckedIncrement(i)) {
118
+ (bool success, bytes memory result) = address(this).delegatecall(data[i]);
119
+
120
+ if (!success) {
121
+ // Look for revert reason and bubble it up if present
122
+ if (result.length > 0) {
123
+ // The easiest way to bubble the revert reason is using memory via assembly
124
+ // solhint-disable no-inline-assembly
125
+ /// @solidity memory-safe-assembly
126
+ assembly {
127
+ let returndata_size := mload(result)
128
+ revert(add(32, result), returndata_size)
129
+ }
130
+ } else {
131
+ revert("LSP0: batchCalls reverted");
132
+ }
159
133
  }
160
- }
161
- }
162
134
 
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
-
187
- /**
188
- * @dev Returns true if this contract implements the interface defined by
189
- * `interfaceId`.
190
- *
191
- * If the contract doesn't support the `interfaceId`, it forwards the call to the
192
- * `supportsInterface` extension according to LSP17, and checks if the extension
193
- * implements the interface defined by `interfaceId`.
194
- */
195
- function supportsInterface(bytes4 interfaceId)
196
- public
197
- view
198
- virtual
199
- override(ERC725XCore, ERC725YCore, LSP17Extendable)
200
- returns (bool)
201
- {
202
- return
203
- interfaceId == _INTERFACEID_ERC1271 ||
204
- interfaceId == _INTERFACEID_LSP0 ||
205
- interfaceId == _INTERFACEID_LSP1 ||
206
- interfaceId == _INTERFACEID_LSP14 ||
207
- super.supportsInterface(interfaceId) ||
208
- _supportsInterfaceInERC165Extension(interfaceId);
209
- }
210
-
211
- /**
212
- * @notice Checks if an owner signed `_data`.
213
- * ERC1271 interface.
214
- *
215
- * @param dataHash hash of the data signed//Arbitrary length data signed on the behalf of address(this)
216
- * @param signature owner's signature(s) of the data
217
- */
218
- function isValidSignature(bytes32 dataHash, bytes memory signature)
219
- public
220
- view
221
- virtual
222
- returns (bytes4 magicValue)
223
- {
224
- address _owner = owner();
225
-
226
- // If owner is a contract
227
- if (_owner.code.length > 0) {
228
- (bool success, bytes memory result) = _owner.staticcall(
229
- abi.encodeWithSelector(IERC1271.isValidSignature.selector, dataHash, signature)
230
- );
231
-
232
- bool isValid = (success &&
233
- result.length == 32 &&
234
- abi.decode(result, (bytes32)) == bytes32(_ERC1271_MAGICVALUE));
235
-
236
- return isValid ? _ERC1271_MAGICVALUE : _ERC1271_FAILVALUE;
237
- }
238
- // If owner is an EOA
239
- else {
240
- return
241
- _owner == ECDSA.recover(dataHash, signature)
242
- ? _ERC1271_MAGICVALUE
243
- : _ERC1271_FAILVALUE;
135
+ results[i] = result;
244
136
  }
245
137
  }
246
138
 
@@ -249,8 +141,10 @@ abstract contract LSP0ERC725AccountCore is
249
141
  * @param target The smart contract or address to interact with, `to` will be unused if a contract is created (operation 1 and 2)
250
142
  * @param value The amount of native tokens to transfer (in Wei).
251
143
  * @param data The call data, or the bytecode of the contract to deploy
252
- * @dev Executes any other smart contract.
253
- * SHOULD only be callable by the owner of the contract set via ERC173
144
+ * @dev Executes any call on other addresses.
145
+ *
146
+ * MUST pass when called by the owner or by an authorised address that pass the verification check performed
147
+ * by LSP20 - CallVerification specification
254
148
  *
255
149
  * Emits a {Executed} event, when a call is executed under `operationType` 0, 3 and 4
256
150
  * Emits a {ContractCreated} event, when a contract is created under `operationType` 1 and 2
@@ -261,24 +155,113 @@ abstract contract LSP0ERC725AccountCore is
261
155
  address target,
262
156
  uint256 value,
263
157
  bytes memory data
264
- ) public payable virtual override onlyOwner returns (bytes memory) {
158
+ ) public payable virtual override returns (bytes memory) {
265
159
  if (msg.value != 0) emit ValueReceived(msg.sender, msg.value);
266
- return _execute(operationType, target, value, data);
160
+
161
+ address _owner = owner();
162
+
163
+ if (msg.sender == _owner) return _execute(operationType, target, value, data);
164
+
165
+ // perform reverse verification if the caller is not the owner
166
+ bool verifyAfter = _verifyCall(_owner);
167
+ bytes memory result = _execute(operationType, target, value, data);
168
+ if (verifyAfter) _verifyCallResult(_owner, result);
169
+
170
+ return result;
267
171
  }
268
172
 
269
173
  /**
270
174
  * @inheritdoc ERC725XCore
271
175
  *
272
- * @dev Emits a {ValueReceived} event when receiving native tokens.
176
+ * @dev MUST pass when called by the owner or by an authorised address that pass the verification check performed
177
+ * by LSP20 - CallVerification specification
178
+ *
179
+ * Emits a {ValueReceived} event when receiving native tokens.
273
180
  */
274
181
  function execute(
275
182
  uint256[] memory operationsType,
276
183
  address[] memory targets,
277
184
  uint256[] memory values,
278
185
  bytes[] memory datas
279
- ) public payable virtual override onlyOwner returns (bytes[] memory) {
186
+ ) public payable virtual override returns (bytes[] memory) {
187
+ if (msg.value != 0) emit ValueReceived(msg.sender, msg.value);
188
+
189
+ address _owner = owner();
190
+
191
+ if (msg.sender == _owner) return _execute(operationsType, targets, values, datas);
192
+
193
+ // perform reverse verification if the caller is not the owner
194
+ bool verifyAfter = _verifyCall(_owner);
195
+ bytes[] memory results = _execute(operationsType, targets, values, datas);
196
+ if (verifyAfter) _verifyCallResult(_owner, abi.encode(results));
197
+
198
+ return results;
199
+ }
200
+
201
+ /**
202
+ * @notice Sets singular data for a given `dataKey`
203
+ * @param dataKey The key to retrieve stored value
204
+ * @param dataValue The value to set
205
+ *
206
+ * MUST pass when called by the owner or by an authorised address that pass the verification check performed
207
+ * by LSP20 - CallVerification specification
208
+ *
209
+ * Emits a {DataChanged} event.
210
+ */
211
+ function setData(bytes32 dataKey, bytes memory dataValue) public payable virtual override {
212
+ if (msg.value != 0) emit ValueReceived(msg.sender, msg.value);
213
+ address _owner = owner();
214
+
215
+ if (msg.sender == _owner) return _setData(dataKey, dataValue);
216
+
217
+ // perform reverse verification if the caller is not the owner
218
+ bool verifyAfter = _verifyCall(_owner);
219
+ _setData(dataKey, dataValue);
220
+
221
+ // The setData function does not return, second parameter of {_verifyCallResult} will be empty
222
+ if (verifyAfter) _verifyCallResult(_owner, "");
223
+ }
224
+
225
+ /**
226
+ * @param dataKeys The array of data keys for values to set
227
+ * @param dataValues The array of values to set
228
+ * @dev Sets array of data for multiple given `dataKeys`
229
+ *
230
+ * MUST pass when called by the owner or by an authorised address that pass the verification check performed
231
+ * by LSP20 - CallVerification specification
232
+ *
233
+ * Emits a {DataChanged} event.
234
+ */
235
+ function setData(bytes32[] memory dataKeys, bytes[] memory dataValues)
236
+ public
237
+ payable
238
+ virtual
239
+ override
240
+ {
280
241
  if (msg.value != 0) emit ValueReceived(msg.sender, msg.value);
281
- return _execute(operationsType, targets, values, datas);
242
+
243
+ if (dataKeys.length != dataValues.length) {
244
+ revert ERC725Y_DataKeysValuesLengthMismatch(dataKeys.length, dataValues.length);
245
+ }
246
+
247
+ address _owner = owner();
248
+
249
+ if (msg.sender == _owner) {
250
+ for (uint256 i = 0; i < dataKeys.length; i = _uncheckedIncrementERC725Y(i)) {
251
+ _setData(dataKeys[i], dataValues[i]);
252
+ }
253
+
254
+ return;
255
+ }
256
+
257
+ // perform reverse verification if the caller is not the owner
258
+ bool verifyAfter = _verifyCall(_owner);
259
+ for (uint256 i = 0; i < dataKeys.length; i = _uncheckedIncrementERC725Y(i)) {
260
+ _setData(dataKeys[i], dataValues[i]);
261
+ }
262
+
263
+ // The setData function does not return, second parameter of {_verifyCallResult} will be empty
264
+ if (verifyAfter) _verifyCallResult(_owner, "");
282
265
  }
283
266
 
284
267
  /**
@@ -342,90 +325,256 @@ abstract contract LSP0ERC725AccountCore is
342
325
  }
343
326
 
344
327
  /**
345
- * @dev Sets the pending owner and notifies the pending owner
328
+ * @inheritdoc LSP14Ownable2Step
346
329
  *
347
- * @param _newOwner The address nofied and set as `pendingOwner`
330
+ * @dev same as ILSP14.transferOwnership with the additional requirement:
331
+ * Requirements:
332
+ *
333
+ * - MUST pass when called by the owner or by an authorised address that pass the verification check performed
334
+ * by LSP20 - CallVerification specification
335
+ *
336
+ * - When notifying the new owner via LSP1, the typeId used MUST be keccak256('LSP0OwnershipTransferStarted')
348
337
  */
349
- function transferOwnership(address _newOwner)
338
+ function transferOwnership(address newOwner)
350
339
  public
351
340
  virtual
352
341
  override(LSP14Ownable2Step, OwnableUnset)
353
- onlyOwner
354
342
  {
355
- LSP14Ownable2Step._transferOwnership(_newOwner);
343
+ address currentOwner = owner();
344
+
345
+ if (msg.sender == currentOwner) {
346
+ // set the pending owner
347
+ LSP14Ownable2Step._transferOwnership(newOwner);
348
+ emit OwnershipTransferStarted(currentOwner, newOwner);
349
+
350
+ // notify the pending owner through LSP1
351
+ newOwner.tryNotifyUniversalReceiver(_TYPEID_LSP0_OwnershipTransferStarted, "");
352
+
353
+ // Require that the owner didn't change after the LSP1 Call
354
+ // (Pending owner didn't automate the acceptOwnership call through LSP1)
355
+ require(
356
+ currentOwner == owner(),
357
+ "LSP14: newOwner MUST accept ownership in a separate transaction"
358
+ );
359
+ } else {
360
+ // If the caller is not the owner, do verification on the owner
361
+ bool verifyAfter = _verifyCall(currentOwner);
362
+
363
+ // Set the pending owner if the call is allowed
364
+ LSP14Ownable2Step._transferOwnership(newOwner);
365
+ emit OwnershipTransferStarted(currentOwner, newOwner);
366
+
367
+ // notify the pending owner through LSP1
368
+ newOwner.tryNotifyUniversalReceiver(_TYPEID_LSP0_OwnershipTransferStarted, "");
369
+
370
+ // Require that the owner didn't change after the LSP1 Call
371
+ // (Pending owner didn't automate the acceptOwnership call through LSP1)
372
+ require(
373
+ currentOwner == owner(),
374
+ "LSP14: newOwner MUST accept ownership in a separate transaction"
375
+ );
376
+
377
+ // The transferOwnership function does not return, second parameter of {_verifyCallResult} will be empty
378
+ if (verifyAfter) _verifyCallResult(currentOwner, "");
379
+ }
356
380
  }
357
381
 
358
382
  /**
359
- * @dev Renounce ownership of the contract in a 2-step process
383
+ * @inheritdoc LSP14Ownable2Step
384
+ *
385
+ * @dev same as ILSP14.acceptOwnership with the additional requirement:
386
+ *
387
+ * Requirements:
388
+ * - when notifying the previous owner via LSP1, the typeId used MUST be keccak256('LSP0OwnershipTransferred_SenderNotification')
389
+ * - when notifying the new owner via LSP1, the typeId used MUST be keccak256('LSP0OwnershipTransferred_RecipientNotification')
360
390
  */
361
- function renounceOwnership()
362
- public
363
- virtual
364
- override(LSP14Ownable2Step, OwnableUnset)
365
- onlyOwner
366
- {
367
- LSP14Ownable2Step._renounceOwnership();
391
+ function acceptOwnership() public virtual override {
392
+ address previousOwner = owner();
393
+
394
+ _acceptOwnership();
395
+
396
+ previousOwner.tryNotifyUniversalReceiver(
397
+ _TYPEID_LSP0_OwnershipTransferred_SenderNotification,
398
+ ""
399
+ );
400
+
401
+ msg.sender.tryNotifyUniversalReceiver(
402
+ _TYPEID_LSP0_OwnershipTransferred_RecipientNotification,
403
+ ""
404
+ );
368
405
  }
369
406
 
370
407
  /**
371
- * @dev SAVE GAS by emitting the DataChanged event with only the first 256 bytes of dataValue
408
+ * @inheritdoc LSP14Ownable2Step
409
+ *
410
+ * @dev MUST pass when called by the owner or by an authorised address that pass the verification
411
+ * check performed by LSP20 - CallVerification specification
372
412
  */
373
- function _setData(bytes32 dataKey, bytes memory dataValue) internal virtual override {
374
- _store[dataKey] = dataValue;
375
- emit DataChanged(
376
- dataKey,
377
- dataValue.length <= 256 ? dataValue : BytesLib.slice(dataValue, 0, 256)
378
- );
413
+ function renounceOwnership() public virtual override(LSP14Ownable2Step, OwnableUnset) {
414
+ address _owner = owner();
415
+
416
+ if (msg.sender == _owner) return LSP14Ownable2Step._renounceOwnership();
417
+
418
+ bool verifyAfter = _verifyCall(_owner);
419
+ LSP14Ownable2Step._renounceOwnership();
420
+
421
+ // The renounceOwnership function does not return, second parameter of {_verifyCallResult} will be empty
422
+ if (verifyAfter) _verifyCallResult(_owner, "");
379
423
  }
380
424
 
381
- // --- LSP14 URD Hooks
425
+ /**
426
+ * @dev Returns true if this contract implements the interface defined by
427
+ * `interfaceId`.
428
+ *
429
+ * If the contract doesn't support the `interfaceId`, it forwards the call to the
430
+ * `supportsInterface` extension according to LSP17, and checks if the extension
431
+ * implements the interface defined by `interfaceId`.
432
+ */
433
+ function supportsInterface(bytes4 interfaceId)
434
+ public
435
+ view
436
+ virtual
437
+ override(ERC725XCore, ERC725YCore, LSP17Extendable)
438
+ returns (bool)
439
+ {
440
+ return
441
+ interfaceId == _INTERFACEID_ERC1271 ||
442
+ interfaceId == _INTERFACEID_LSP0 ||
443
+ interfaceId == _INTERFACEID_LSP1 ||
444
+ interfaceId == _INTERFACEID_LSP14 ||
445
+ super.supportsInterface(interfaceId) ||
446
+ _supportsInterfaceInERC165Extension(interfaceId);
447
+ }
382
448
 
383
449
  /**
384
- * @dev Calls the universalReceiver function of the sender when ownerhsip transfer starts
385
- * if supports LSP1 InterfaceId
450
+ * @notice Checks if an owner signed `_data`.
451
+ * ERC1271 interface.
452
+ *
453
+ * @param dataHash hash of the data signed//Arbitrary length data signed on the behalf of address(this)
454
+ * @param signature owner's signature(s) of the data
386
455
  */
387
- function _notifyLSP1SenderOnOwnershipTransferStart(address notifiedContract, bytes memory data)
388
- internal
456
+ function isValidSignature(bytes32 dataHash, bytes memory signature)
457
+ public
458
+ view
389
459
  virtual
390
- override
460
+ returns (bytes4 magicValue)
391
461
  {
392
- if (ERC165Checker.supportsERC165InterfaceUnchecked(notifiedContract, _INTERFACEID_LSP1)) {
393
- ILSP1UniversalReceiver(notifiedContract).universalReceiver(
394
- _TYPEID_LSP0_OwnershipTransferStarted,
395
- data
462
+ address _owner = owner();
463
+
464
+ // If owner is a contract
465
+ if (_owner.code.length > 0) {
466
+ (bool success, bytes memory result) = _owner.staticcall(
467
+ abi.encodeWithSelector(IERC1271.isValidSignature.selector, dataHash, signature)
396
468
  );
469
+
470
+ bool isValid = (success &&
471
+ result.length == 32 &&
472
+ abi.decode(result, (bytes32)) == bytes32(_ERC1271_MAGICVALUE));
473
+
474
+ return isValid ? _ERC1271_MAGICVALUE : _ERC1271_FAILVALUE;
475
+ }
476
+ // If owner is an EOA
477
+ else {
478
+ return
479
+ _owner == ECDSA.recover(dataHash, signature)
480
+ ? _ERC1271_MAGICVALUE
481
+ : _ERC1271_FAILVALUE;
397
482
  }
398
483
  }
399
484
 
485
+ // Internal functions
486
+
487
+ // Fallback
488
+
400
489
  /**
401
- * @dev Calls the universalReceiver function of the sender when ownerhsip transfer is complete
402
- * if supports LSP1 InterfaceId
490
+ * @dev Forwards the call to an extension mapped to a function selector. If no extension address
491
+ * is mapped to the function selector (address(0)), then revert.
492
+ *
493
+ * The bytes4(0) msg.sig is an exception, the function won't revert if there is no extension found
494
+ * mapped to bytes4(0), but will execute the call to the extension in case it existed.
495
+ *
496
+ * The call to the extension is appended with bytes20 (msg.sender) and bytes32 (msg.value).
497
+ * Returns the return value on success and revert in case of failure.
498
+ *
499
+ * Because the function uses assembly {return()/revert()} to terminate the call, it cannot be
500
+ * called before other codes in fallback().
501
+ *
502
+ * Otherwise, the codes after _fallbackLSP17Extendable() may never be reached.
403
503
  */
404
- function _notifyLSP1SenderOnOwnershipTransferCompletion(
405
- address notifiedContract,
406
- bytes memory data
407
- ) internal virtual override {
408
- if (ERC165Checker.supportsERC165InterfaceUnchecked(notifiedContract, _INTERFACEID_LSP1)) {
409
- ILSP1UniversalReceiver(notifiedContract).universalReceiver(
410
- _TYPEID_LSP0_OwnershipTransferred_SenderNotification,
411
- data
412
- );
504
+ function _fallbackLSP17Extendable() internal virtual override {
505
+ // If there is a function selector
506
+ address extension = _getExtension(msg.sig);
507
+
508
+ // if no extension was found for bytes4(0) return don't revert
509
+ if (msg.sig == bytes4(0) && extension == address(0)) return;
510
+
511
+ // if no extension was found, revert
512
+ if (extension == address(0)) revert NoExtensionFoundForFunctionSelector(msg.sig);
513
+
514
+ // solhint-disable no-inline-assembly
515
+ // if the extension was found, call the extension with the msg.data
516
+ // appended with bytes20(address) and bytes32(msg.value)
517
+ assembly {
518
+ calldatacopy(0, 0, calldatasize())
519
+
520
+ // The msg.sender address is shifted to the left by 12 bytes to remove the padding
521
+ // Then the address without padding is stored right after the calldata
522
+ mstore(calldatasize(), shl(96, caller()))
523
+
524
+ // The msg.value is stored right after the calldata + msg.sender
525
+ mstore(add(calldatasize(), 20), callvalue())
526
+
527
+ // Add 52 bytes for the msg.sender and msg.value appended at the end of the calldata
528
+ let success := call(gas(), extension, 0, 0, add(calldatasize(), 52), 0, 0)
529
+
530
+ // Copy the returned data
531
+ returndatacopy(0, 0, returndatasize())
532
+
533
+ switch success
534
+ // call returns 0 on failed calls
535
+ case 0 {
536
+ revert(0, returndatasize())
537
+ }
538
+ default {
539
+ return(0, returndatasize())
540
+ }
413
541
  }
414
542
  }
415
543
 
416
544
  /**
417
- * @dev Calls the universalReceiver function of the recipient when ownerhsip transfer is complete
418
- * if supports LSP1 InterfaceId
545
+ * @dev Returns the extension stored under the `_LSP17_EXTENSION_PREFIX` data key
546
+ * mapped to the functionSelector provided.
547
+ *
548
+ * If no extension is stored, returns the address(0)
419
549
  */
420
- function _notifyLSP1RecipientOnOwnershipTransferCompletion(
421
- address notifiedContract,
422
- bytes memory data
423
- ) internal virtual override {
424
- if (ERC165Checker.supportsERC165InterfaceUnchecked(notifiedContract, _INTERFACEID_LSP1)) {
425
- ILSP1UniversalReceiver(notifiedContract).universalReceiver(
426
- _TYPEID_LSP0_OwnershipTransferred_RecipientNotification,
427
- data
428
- );
429
- }
550
+ function _getExtension(bytes4 functionSelector)
551
+ internal
552
+ view
553
+ virtual
554
+ override
555
+ returns (address)
556
+ {
557
+ bytes32 mappedExtensionDataKey = LSP2Utils.generateMappingKey(
558
+ _LSP17_EXTENSION_PREFIX,
559
+ functionSelector
560
+ );
561
+
562
+ // Check if there is an extension for the function selector provided
563
+ address extension = address(bytes20(_getData(mappedExtensionDataKey)));
564
+
565
+ return extension;
566
+ }
567
+
568
+ // ERC725Y
569
+
570
+ /**
571
+ * @dev SAVE GAS by emitting the DataChanged event with only the first 256 bytes of dataValue
572
+ */
573
+ function _setData(bytes32 dataKey, bytes memory dataValue) internal virtual override {
574
+ _store[dataKey] = dataValue;
575
+ emit DataChanged(
576
+ dataKey,
577
+ dataValue.length <= 256 ? dataValue : BytesLib.slice(dataValue, 0, 256)
578
+ );
430
579
  }
431
580
  }
@@ -11,7 +11,7 @@ import {LSP0ERC725AccountInitAbstract} from "./LSP0ERC725AccountInitAbstract.sol
11
11
  */
12
12
  contract LSP0ERC725AccountInit is LSP0ERC725AccountInitAbstract {
13
13
  /**
14
- * @dev @dev initialize (= lock) base implementation contract on deployment
14
+ * @dev initialize (= lock) base implementation contract on deployment
15
15
  */
16
16
  constructor() {
17
17
  _disableInitializers();