@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
@@ -14,25 +14,25 @@ import "../LSP9Vault/LSP9Constants.sol";
14
14
 
15
15
  /**
16
16
  * @dev reverts when the value stored under the 'LSP10ReceivedVaults[]' 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 vaults received.
22
- * i.e. 0x0000000000000000000000000000000000000000000000000000000000000005 (non-zero), meaning 5 array elements, 5 vaults received.
20
+ * - any valid uint128 values
21
+ * i.e. 0x00000000000000000000000000000000 (zero), meaning empty array, no vaults received.
22
+ * i.e. 0x00000000000000000000000000000005 (non-zero), meaning 5 array elements, 5 vaults 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 LSP10ReceivedVaults[] data key
27
- * @param invalidValueLength the invalid number of bytes stored under the LSP10ReceivedVaults[] data key (MUST be 32)
26
+ * @param invalidValueStored the invalid value stored under the LSP10ReceivedVaults[] data key
27
+ * @param invalidValueLength the invalid number of bytes stored under the LSP10ReceivedVaults[] data key (MUST be 16 bytes long)
28
28
  */
29
- error InvalidLSP10ReceivedVaultsArrayLength(bytes invalidValue, uint256 invalidValueLength);
29
+ error InvalidLSP10ReceivedVaultsArrayLength(bytes invalidValueStored, uint256 invalidValueLength);
30
30
 
31
31
  /**
32
- * @dev reverts when the vault index is superior to uint64
33
- * @param index the vault index
32
+ * @dev reverts when the `LSP10Vaults[]` array reaches its maximum limit (max(uint128))
33
+ * @param notRegisteredVault the address of the vault that could not be registered
34
34
  */
35
- error VaultIndexSuperiorToUint64(uint256 index);
35
+ error MaxLSP10VaultsCountReached(address notRegisteredVault);
36
36
 
37
37
  /**
38
38
  * @dev reverts when the vault index is superior to uint128
@@ -66,43 +66,31 @@ library LSP10Utils {
66
66
  IERC725Y account = IERC725Y(receiver);
67
67
  bytes memory encodedArrayLength = getLSP10ReceivedVaultsCount(account);
68
68
 
69
- // If it's the first vault to receive
70
- if (encodedArrayLength.length == 0) {
71
- keys[0] = _LSP10_VAULTS_ARRAY_KEY;
72
- values[0] = bytes.concat(bytes32(uint256(1)));
69
+ // CHECK it's either the first vault received,
70
+ // or the storage is already set with a valid `uint128` value
71
+ if (encodedArrayLength.length != 0 && encodedArrayLength.length != 16) {
72
+ revert InvalidLSP10ReceivedVaultsArrayLength({
73
+ invalidValueStored: encodedArrayLength,
74
+ invalidValueLength: encodedArrayLength.length
75
+ });
76
+ }
73
77
 
74
- keys[1] = LSP2Utils.generateArrayElementKeyAtIndex(_LSP10_VAULTS_ARRAY_KEY, 0);
75
- values[1] = bytes.concat(bytes20(vault));
78
+ uint128 oldArrayLength = uint128(bytes16(encodedArrayLength));
76
79
 
77
- keys[2] = vaultMapKey;
78
- values[2] = bytes.concat(_INTERFACEID_LSP9, bytes8(0));
80
+ if (oldArrayLength == type(uint128).max) {
81
+ revert MaxLSP10VaultsCountReached({notRegisteredVault: vault});
82
+ }
79
83
 
80
- // If the storage is already initiated
81
- } else if (encodedArrayLength.length == 32) {
82
- uint256 oldArrayLength = uint256(bytes32(encodedArrayLength));
83
- uint256 newArrayLength = oldArrayLength + 1;
84
+ uint128 newArrayLength = oldArrayLength + 1;
84
85
 
85
- if (newArrayLength > type(uint64).max) {
86
- revert VaultIndexSuperiorToUint64(newArrayLength);
87
- }
86
+ keys[0] = _LSP10_VAULTS_ARRAY_KEY;
87
+ values[0] = bytes.concat(bytes16(newArrayLength));
88
88
 
89
- keys[0] = _LSP10_VAULTS_ARRAY_KEY;
90
- values[0] = bytes.concat(bytes32(newArrayLength));
89
+ keys[1] = LSP2Utils.generateArrayElementKeyAtIndex(_LSP10_VAULTS_ARRAY_KEY, oldArrayLength);
90
+ values[1] = bytes.concat(bytes20(vault));
91
91
 
92
- keys[1] = LSP2Utils.generateArrayElementKeyAtIndex(
93
- _LSP10_VAULTS_ARRAY_KEY,
94
- uint128(oldArrayLength)
95
- );
96
- values[1] = bytes.concat(bytes20(vault));
97
-
98
- keys[2] = vaultMapKey;
99
- values[2] = bytes.concat(_INTERFACEID_LSP9, bytes8(uint64(oldArrayLength)));
100
- } else {
101
- revert InvalidLSP10ReceivedVaultsArrayLength(
102
- encodedArrayLength,
103
- encodedArrayLength.length
104
- );
105
- }
92
+ keys[2] = vaultMapKey;
93
+ values[2] = bytes.concat(_INTERFACEID_LSP9, bytes16(oldArrayLength));
106
94
  }
107
95
 
108
96
  /**
@@ -118,17 +106,25 @@ library LSP10Utils {
118
106
  bytes memory vaultInterfaceIdAndIndex
119
107
  ) internal view returns (bytes32[] memory keys, bytes[] memory values) {
120
108
  IERC725Y account = IERC725Y(sender);
109
+ bytes memory lsp10VaultsCountValue = getLSP10ReceivedVaultsCount(account);
110
+
111
+ if (lsp10VaultsCountValue.length != 16) {
112
+ revert InvalidLSP10ReceivedVaultsArrayLength({
113
+ invalidValueStored: lsp10VaultsCountValue,
114
+ invalidValueLength: lsp10VaultsCountValue.length
115
+ });
116
+ }
121
117
 
122
118
  // Updating the number of the received vaults
123
- uint256 oldArrayLength = uint256(bytes32(account.getData(_LSP10_VAULTS_ARRAY_KEY)));
119
+ uint128 oldArrayLength = uint128(bytes16(lsp10VaultsCountValue));
124
120
 
125
121
  if (oldArrayLength > type(uint128).max) {
126
122
  revert VaultIndexSuperiorToUint128(oldArrayLength);
127
123
  }
128
124
 
129
- uint128 newArrayLength = uint128(oldArrayLength) - 1;
125
+ uint128 newArrayLength = oldArrayLength - 1;
130
126
 
131
- uint64 index = extractIndexFromMap(vaultInterfaceIdAndIndex);
127
+ uint128 index = extractIndexFromMap(vaultInterfaceIdAndIndex);
132
128
  bytes32 vaultInArrayKey = LSP2Utils.generateArrayElementKeyAtIndex(
133
129
  _LSP10_VAULTS_ARRAY_KEY,
134
130
  index
@@ -145,7 +141,7 @@ library LSP10Utils {
145
141
  values = new bytes[](3);
146
142
 
147
143
  keys[0] = _LSP10_VAULTS_ARRAY_KEY;
148
- values[0] = bytes.concat(bytes32(oldArrayLength - 1));
144
+ values[0] = bytes.concat(bytes16(newArrayLength));
149
145
 
150
146
  keys[1] = vaultInArrayKey;
151
147
  values[1] = "";
@@ -168,7 +164,7 @@ library LSP10Utils {
168
164
  values = new bytes[](5);
169
165
 
170
166
  keys[0] = _LSP10_VAULTS_ARRAY_KEY;
171
- values[0] = bytes.concat(bytes32(oldArrayLength - 1));
167
+ values[0] = bytes.concat(bytes16(newArrayLength));
172
168
 
173
169
  keys[1] = vaultMapKey;
174
170
  values[1] = "";
@@ -194,7 +190,7 @@ library LSP10Utils {
194
190
  values[3] = "";
195
191
 
196
192
  keys[4] = lastVaultInArrayMapKey;
197
- values[4] = bytes.concat(_INTERFACEID_LSP9, bytes8(index));
193
+ values[4] = bytes.concat(_INTERFACEID_LSP9, bytes16(index));
198
194
  }
199
195
  }
200
196
 
@@ -203,10 +199,10 @@ library LSP10Utils {
203
199
  }
204
200
 
205
201
  /**
206
- * @dev returns the index from a maping
202
+ * @dev returns the index from the LSP10VaultMap
207
203
  */
208
- function extractIndexFromMap(bytes memory mapValue) internal pure returns (uint64) {
209
- bytes memory val = BytesLib.slice(mapValue, 4, 8);
210
- return BytesLib.toUint64(val, 0);
204
+ function extractIndexFromMap(bytes memory mapValue) internal pure returns (uint128) {
205
+ bytes memory val = BytesLib.slice(mapValue, 4, 16);
206
+ return BytesLib.toUint128(val, 0);
211
207
  }
212
208
  }
@@ -191,12 +191,11 @@ abstract contract LSP11BasicSocialRecoveryCore is OwnableUnset, ERC165, ILSP11Ba
191
191
  address keyManager = ERC725(target_).owner();
192
192
 
193
193
  // Setting permissions for `recoverer`
194
- (bytes32[] memory keys, bytes[] memory values) = LSP6Utils
195
- .generatePermissionsKeysForController(
196
- ERC725(target_),
197
- recoverer,
198
- ALL_REGULAR_PERMISSIONS
199
- );
194
+ (bytes32[] memory keys, bytes[] memory values) = LSP6Utils.generateNewPermissionsKeys(
195
+ ERC725(target_),
196
+ recoverer,
197
+ ALL_REGULAR_PERMISSIONS
198
+ );
200
199
 
201
200
  LSP6Utils.setDataViaKeyManager(keyManager, keys, values);
202
201
 
@@ -32,22 +32,45 @@ interface ILSP14Ownable2Step {
32
32
  */
33
33
 
34
34
  /**
35
- * @dev Returns the address of the current pending owner.
35
+ * @dev The address that ownership of the contract is transferred to.
36
+ * This address may use `acceptOwnership()` to gain ownership of the contract.
36
37
  */
37
38
  function pendingOwner() external view returns (address);
38
39
 
39
40
  /**
40
- * @dev Initiate the process of transferring ownership of the contract by setting the pending owner.
41
+ * @dev Initiate the process of transferring ownership of the contract by setting the new owner as the pending owner.
42
+ *
43
+ * If the new owner is a contract that supports + implements LSP1, this will also attempt to notify the new owner that
44
+ * ownership has been transferred to them by calling the `universalReceiver(...)` function on the `newOwner` contract.
45
+ *
46
+ * @param newOwner the address of the new owner.
47
+ *
48
+ * Requirements:
49
+ * - `newOwner` MUST NOT accept ownership of the contract in the same transaction.
41
50
  */
42
51
  function transferOwnership(address newOwner) external;
43
52
 
44
53
  /**
45
- * @dev Complete the process of transferring ownership. MUST be called by the pendingOwner.
54
+ * @dev Transfer ownership of the contract from the current `owner()` to the `pendingOwner()`.
55
+ *
56
+ * Once this function is called:
57
+ * - the current `owner()` will loose access to the functions restricted to the `owner()` only.
58
+ * - the `pendingOwner()` will gain access to the functions restricted to the `owner()` only.
59
+ *
60
+ * Requirements:
61
+ * - MUST be called by the pendingOwner.
46
62
  */
47
63
  function acceptOwnership() external;
48
64
 
49
65
  /**
50
- * @dev Initiate the process of renouncing ownerhsip on the first call and confirm the renouncement of the ownership on the second call.
66
+ * @dev Renounce ownership of the contract in a 2-step process.
67
+ *
68
+ * 1. the first call will initiate the process of renouncing ownership.
69
+ * 2. the second is used as a confirmation and will leave the contract without an owner.
70
+ *
71
+ * WARNING: once ownership of the contract has been renounced, any functions
72
+ * that are restricted to be called by the owner will be permanently inaccessible,
73
+ * making these functions not callable anymore and unusable.
51
74
  */
52
75
  function renounceOwnership() external;
53
76
  }
@@ -9,6 +9,9 @@ import {ILSP1UniversalReceiver} from "../LSP1UniversalReceiver/ILSP1UniversalRec
9
9
  import {OwnableUnset} from "@erc725/smart-contracts/contracts/custom/OwnableUnset.sol";
10
10
  import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
11
11
 
12
+ // libraries
13
+ import {LSP1Utils} from "../LSP1UniversalReceiver/LSP1Utils.sol";
14
+
12
15
  // errors
13
16
  import "./LSP14Errors.sol";
14
17
 
@@ -28,6 +31,8 @@ import {_INTERFACEID_LSP1} from "../LSP1UniversalReceiver/LSP1Constants.sol";
28
31
  * transferring ownership of the contract, where the control of the contract could be lost forever.
29
32
  */
30
33
  abstract contract LSP14Ownable2Step is ILSP14Ownable2Step, OwnableUnset {
34
+ using LSP1Utils for address;
35
+
31
36
  /**
32
37
  * @dev The number of block that MUST pass before one is able to
33
38
  * confirm renouncing ownership
@@ -40,21 +45,15 @@ abstract contract LSP14Ownable2Step is ILSP14Ownable2Step, OwnableUnset {
40
45
  uint256 public constant RENOUNCE_OWNERSHIP_CONFIRMATION_PERIOD = 100;
41
46
 
42
47
  /**
43
- * @dev The block number saved when initiating the process of
44
- * renouncing ownerhsip
48
+ * @dev The block number saved when initiating the process of renouncing ownerhsip
45
49
  */
46
50
  uint256 private _renounceOwnershipStartedAt;
47
51
 
48
52
  /**
49
- * @dev The address that ownership of the contract is transferred to.
50
- * This address may use `acceptOwnership()` to gain ownership of the contract.
51
- * Meaning that the current owner will lose access to the methods marked as
52
- * `onlyOwner` in favor to the `_pendingOwner`.
53
+ * @dev see `pendingOwner()`
53
54
  */
54
55
  address private _pendingOwner;
55
56
 
56
- // --- General Methods
57
-
58
57
  /**
59
58
  * @inheritdoc ILSP14Ownable2Step
60
59
  */
@@ -72,13 +71,34 @@ abstract contract LSP14Ownable2Step is ILSP14Ownable2Step, OwnableUnset {
72
71
  onlyOwner
73
72
  {
74
73
  _transferOwnership(newOwner);
74
+
75
+ address currentOwner = owner();
76
+ emit OwnershipTransferStarted(currentOwner, newOwner);
77
+
78
+ newOwner.tryNotifyUniversalReceiver(_TYPEID_LSP14_OwnershipTransferStarted, "");
79
+ require(
80
+ currentOwner == owner(),
81
+ "LSP14: newOwner MUST accept ownership in a separate transaction"
82
+ );
75
83
  }
76
84
 
77
85
  /**
78
86
  * @inheritdoc ILSP14Ownable2Step
79
87
  */
80
88
  function acceptOwnership() public virtual {
89
+ address previousOwner = owner();
90
+
81
91
  _acceptOwnership();
92
+
93
+ previousOwner.tryNotifyUniversalReceiver(
94
+ _TYPEID_LSP14_OwnershipTransferred_SenderNotification,
95
+ ""
96
+ );
97
+
98
+ msg.sender.tryNotifyUniversalReceiver(
99
+ _TYPEID_LSP14_OwnershipTransferred_RecipientNotification,
100
+ ""
101
+ );
82
102
  }
83
103
 
84
104
  /**
@@ -96,45 +116,34 @@ abstract contract LSP14Ownable2Step is ILSP14Ownable2Step, OwnableUnset {
96
116
  // --- Internal methods
97
117
 
98
118
  /**
99
- * @dev Start the process of transferring ownership of the contract
100
- * and notify the new owner about it.
119
+ * @dev set the pending owner of the contract and cancel any renounce ownership
120
+ * process that was previously started.
121
+ *
122
+ * @param newOwner The address of the new pending owner.
101
123
  *
102
124
  * Requirements:
103
- * - `newOwner` MUST NOT accept ownership of the contract in the same transaction.
125
+ * - `newOwner` cannot be the address of the contract itself.
104
126
  */
105
127
  function _transferOwnership(address newOwner) internal virtual {
106
128
  if (newOwner == address(this)) revert CannotTransferOwnershipToSelf();
107
129
 
108
130
  _pendingOwner = newOwner;
109
131
  delete _renounceOwnershipStartedAt;
110
- address currentOwner = owner();
111
- emit OwnershipTransferStarted(currentOwner, newOwner);
112
-
113
- _notifyLSP1SenderOnOwnershipTransferStart(newOwner, "");
114
- require(
115
- currentOwner == owner(),
116
- "LSP14: newOwner MUST accept ownership in a separate transaction"
117
- );
118
132
  }
119
133
 
120
134
  /**
121
- * @dev Accept ownership of the contract and notify
122
- * previous owner and the new owner that ownership has been transferred.
135
+ * @dev set the pending owner of the contract as the new owner.
123
136
  */
124
137
  function _acceptOwnership() internal virtual {
125
138
  require(msg.sender == pendingOwner(), "LSP14: caller is not the pendingOwner");
126
139
 
127
- address previousOwner = owner();
128
140
  _setOwner(msg.sender);
129
141
  delete _pendingOwner;
130
-
131
- _notifyLSP1SenderOnOwnershipTransferCompletion(previousOwner, "");
132
- _notifyLSP1RecipientOnOwnershipTransferCompletion(msg.sender, "");
133
142
  }
134
143
 
135
144
  /**
136
- * @dev initiate or confirm the process of renouncing ownership. Leaves the contract
137
- * without an owner, making functions marked as `onlyOwner` not callable anymore.
145
+ * @dev initiate or confirm the process of renouncing ownership
146
+ * after a specific delay of blocks have passed.
138
147
  */
139
148
  function _renounceOwnership() internal virtual {
140
149
  uint256 currentBlock = block.number;
@@ -159,54 +168,4 @@ abstract contract LSP14Ownable2Step is ILSP14Ownable2Step, OwnableUnset {
159
168
  delete _pendingOwner;
160
169
  emit OwnershipRenounced();
161
170
  }
162
-
163
- // --- URD Hooks
164
-
165
- /**
166
- * @dev Calls the universalReceiver function of the sender when ownership transfer starts
167
- * if supports LSP1 InterfaceId
168
- */
169
- function _notifyLSP1SenderOnOwnershipTransferStart(address notifiedContract, bytes memory data)
170
- internal
171
- virtual
172
- {
173
- if (ERC165Checker.supportsERC165InterfaceUnchecked(notifiedContract, _INTERFACEID_LSP1)) {
174
- ILSP1UniversalReceiver(notifiedContract).universalReceiver(
175
- _TYPEID_LSP14_OwnershipTransferStarted,
176
- data
177
- );
178
- }
179
- }
180
-
181
- /**
182
- * @dev Calls the universalReceiver function of the sender when ownerhsip transfer is complete
183
- * if supports LSP1 InterfaceId
184
- */
185
- function _notifyLSP1SenderOnOwnershipTransferCompletion(
186
- address notifiedContract,
187
- bytes memory data
188
- ) internal virtual {
189
- if (ERC165Checker.supportsERC165InterfaceUnchecked(notifiedContract, _INTERFACEID_LSP1)) {
190
- ILSP1UniversalReceiver(notifiedContract).universalReceiver(
191
- _TYPEID_LSP14_OwnershipTransferred_SenderNotification,
192
- data
193
- );
194
- }
195
- }
196
-
197
- /**
198
- * @dev Calls the universalReceiver function of the recipient when ownerhsip transfer is complete
199
- * if supports LSP1 InterfaceId
200
- */
201
- function _notifyLSP1RecipientOnOwnershipTransferCompletion(
202
- address notifiedContract,
203
- bytes memory data
204
- ) internal virtual {
205
- if (ERC165Checker.supportsERC165InterfaceUnchecked(notifiedContract, _INTERFACEID_LSP1)) {
206
- ILSP1UniversalReceiver(notifiedContract).universalReceiver(
207
- _TYPEID_LSP14_OwnershipTransferred_RecipientNotification,
208
- data
209
- );
210
- }
211
- }
212
171
  }
@@ -64,7 +64,7 @@ contract LSP16UniversalFactory {
64
64
  bool initializable,
65
65
  bytes calldata initializeCallData
66
66
  ) public view virtual returns (address) {
67
- bytes32 generatedSalt = _generateSalt(initializable, initializeCallData, providedSalt);
67
+ bytes32 generatedSalt = generateSalt(initializable, initializeCallData, providedSalt);
68
68
  return Create2.computeAddress(generatedSalt, byteCodeHash);
69
69
  }
70
70
 
@@ -78,7 +78,7 @@ contract LSP16UniversalFactory {
78
78
  bool initializable,
79
79
  bytes calldata initializeCallData
80
80
  ) public view virtual returns (address) {
81
- bytes32 generatedSalt = _generateSalt(initializable, initializeCallData, providedSalt);
81
+ bytes32 generatedSalt = generateSalt(initializable, initializeCallData, providedSalt);
82
82
  return Clones.predictDeterministicAddress(baseContract, generatedSalt);
83
83
  }
84
84
 
@@ -99,7 +99,7 @@ contract LSP16UniversalFactory {
99
99
  virtual
100
100
  returns (address)
101
101
  {
102
- bytes32 generatedSalt = _generateSalt(false, _EMPTY_BYTE, providedSalt);
102
+ bytes32 generatedSalt = generateSalt(false, _EMPTY_BYTE, providedSalt);
103
103
  address contractCreated = Create2.deploy(msg.value, generatedSalt, byteCode);
104
104
  emit ContractCreated(contractCreated, providedSalt, false, _EMPTY_BYTE);
105
105
 
@@ -132,7 +132,7 @@ contract LSP16UniversalFactory {
132
132
  if (constructorMsgValue + initializeCalldataMsgValue != msg.value)
133
133
  revert InvalidMsgValueDistribution();
134
134
 
135
- bytes32 generatedSalt = _generateSalt(true, initializeCalldata, providedSalt);
135
+ bytes32 generatedSalt = generateSalt(true, initializeCalldata, providedSalt);
136
136
  address contractCreated = Create2.deploy(constructorMsgValue, generatedSalt, byteCode);
137
137
  emit ContractCreated(contractCreated, providedSalt, true, initializeCalldata);
138
138
 
@@ -163,7 +163,7 @@ contract LSP16UniversalFactory {
163
163
  virtual
164
164
  returns (address)
165
165
  {
166
- bytes32 generatedSalt = _generateSalt(false, _EMPTY_BYTE, providedSalt);
166
+ bytes32 generatedSalt = generateSalt(false, _EMPTY_BYTE, providedSalt);
167
167
 
168
168
  address proxy = Clones.cloneDeterministic(baseContract, generatedSalt);
169
169
  emit ContractCreated(proxy, providedSalt, false, _EMPTY_BYTE);
@@ -190,7 +190,7 @@ contract LSP16UniversalFactory {
190
190
  bytes32 providedSalt,
191
191
  bytes calldata initializeCalldata
192
192
  ) public payable virtual returns (address) {
193
- bytes32 generatedSalt = _generateSalt(true, initializeCalldata, providedSalt);
193
+ bytes32 generatedSalt = generateSalt(true, initializeCalldata, providedSalt);
194
194
 
195
195
  address proxy = Clones.cloneDeterministic(baseContract, generatedSalt);
196
196
  emit ContractCreated(proxy, providedSalt, true, initializeCalldata);
@@ -211,11 +211,11 @@ contract LSP16UniversalFactory {
211
211
  * to deploy the same bytecode + the same salt to get the same address of the contract on
212
212
  * another chain without applying the effect of initializing.
213
213
  */
214
- function _generateSalt(
214
+ function generateSalt(
215
215
  bool initializable,
216
216
  bytes memory initializeCallData,
217
217
  bytes32 providedSalt
218
- ) internal pure virtual returns (bytes32) {
218
+ ) public pure virtual returns (bytes32) {
219
219
  if (initializable) {
220
220
  return keccak256(abi.encodePacked(initializable, initializeCallData, providedSalt));
221
221
  } else {
@@ -67,32 +67,27 @@ contract LSP1UniversalReceiverDelegateUP is ERC165, ILSP1UniversalReceiver {
67
67
  // solhint-disable avoid-tx-origin
68
68
  if (notifier == tx.origin) revert CannotRegisterEOAsAsAssets(notifier);
69
69
 
70
- (address keyManager, bool ownerIsKeyManager) = _validateCallerViaKeyManager();
71
- if (!ownerIsKeyManager) return "LSP1: account owner is not a LSP6KeyManager";
72
-
73
70
  // if the contract being transferred doesn't support LSP9, do not register it as a received vault
74
- if (mapPrefix == _LSP10_VAULTS_MAP_KEY_PREFIX) {
75
- if (notifier.code.length > 0) {
76
- if (!notifier.supportsERC165InterfaceUnchecked(_INTERFACEID_LSP9))
77
- return "LSP1: not an LSP9Vault ownership transfer";
78
- }
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";
79
77
  }
80
78
 
81
79
  bytes32 notifierMapKey = LSP2Utils.generateMappingKey(mapPrefix, bytes20(notifier));
82
80
  bytes memory notifierMapValue = IERC725Y(msg.sender).getData(notifierMapKey);
81
+ bool isMapValueSet = bytes20(notifierMapValue) != bytes20(0);
83
82
 
84
83
  if (isReceiving) {
85
- // if the map value is already set, then do nothing
86
- if (bytes12(notifierMapValue) != bytes12(0))
87
- return "LSP1: asset received is already registered";
84
+ if (isMapValueSet) return "LSP1: asset received is already registered";
88
85
 
89
- result = _whenReceiving(typeId, notifier, keyManager, notifierMapKey, interfaceID);
86
+ return _whenReceiving(typeId, notifier, notifierMapKey, interfaceID);
90
87
  } else {
91
- // if there is no map value for the asset/vault to remove, then do nothing
92
- if (bytes12(notifierMapValue) == bytes12(0))
93
- return "LSP1: asset sent is not registered";
88
+ if (!isMapValueSet) return "LSP1: asset sent is not registered";
94
89
 
95
- result = _whenSending(typeId, notifier, keyManager, notifierMapKey, notifierMapValue);
90
+ return _whenSending(typeId, notifier, notifierMapKey, notifierMapValue);
96
91
  }
97
92
  }
98
93
 
@@ -106,25 +101,36 @@ contract LSP1UniversalReceiverDelegateUP is ERC165, ILSP1UniversalReceiver {
106
101
  function _whenReceiving(
107
102
  bytes32 typeId,
108
103
  address notifier,
109
- address keyManager,
110
104
  bytes32 notifierMapKey,
111
105
  bytes4 interfaceID
112
- ) internal virtual returns (bytes memory result) {
106
+ ) internal virtual returns (bytes memory) {
107
+ bytes32[] memory dataKeys;
108
+ bytes[] memory dataValues;
109
+
113
110
  // if it's a token transfer (LSP7/LSP8)
114
111
  if (typeId != _TYPEID_LSP9_OwnershipTransferred_RecipientNotification) {
115
112
  // if the amount sent is 0, then do not update the keys
116
113
  uint256 balance = ILSP7DigitalAsset(notifier).balanceOf(msg.sender);
117
114
  if (balance == 0) return "LSP1: balance not updated";
118
115
 
119
- (bytes32[] memory dataKeys, bytes[] memory dataValues) = LSP5Utils
120
- .generateReceivedAssetKeys(msg.sender, notifier, notifierMapKey, interfaceID);
116
+ (dataKeys, dataValues) = LSP5Utils.generateReceivedAssetKeys(
117
+ msg.sender,
118
+ notifier,
119
+ notifierMapKey,
120
+ interfaceID
121
+ );
121
122
 
122
- result = LSP6Utils.setDataViaKeyManager(keyManager, dataKeys, dataValues);
123
+ IERC725Y(msg.sender).setData(dataKeys, dataValues);
124
+ return "";
123
125
  } else {
124
- (bytes32[] memory dataKeys, bytes[] memory dataValues) = LSP10Utils
125
- .generateReceivedVaultKeys(msg.sender, notifier, notifierMapKey);
126
-
127
- 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 "";
128
134
  }
129
135
  }
130
136
 
@@ -136,46 +142,35 @@ contract LSP1UniversalReceiverDelegateUP is ERC165, ILSP1UniversalReceiver {
136
142
  function _whenSending(
137
143
  bytes32 typeId,
138
144
  address notifier,
139
- address keyManager,
140
145
  bytes32 notifierMapKey,
141
146
  bytes memory notifierMapValue
142
- ) internal virtual returns (bytes memory result) {
147
+ ) internal virtual returns (bytes memory) {
148
+ bytes32[] memory dataKeys;
149
+ bytes[] memory dataValues;
150
+
143
151
  // if it's a token transfer (LSP7/LSP8)
144
152
  if (typeId != _TYPEID_LSP9_OwnershipTransferred_SenderNotification) {
145
153
  // if the amount sent is not the full balance, then do not update the keys
146
154
  uint256 balance = ILSP7DigitalAsset(notifier).balanceOf(msg.sender);
147
155
  if (balance != 0) return "LSP1: full balance is not sent";
148
156
 
149
- (bytes32[] memory dataKeys, bytes[] memory dataValues) = LSP5Utils
150
- .generateSentAssetKeys(msg.sender, notifierMapKey, notifierMapValue);
157
+ (dataKeys, dataValues) = LSP5Utils.generateSentAssetKeys(
158
+ msg.sender,
159
+ notifierMapKey,
160
+ notifierMapValue
161
+ );
151
162
 
152
- result = LSP6Utils.setDataViaKeyManager(keyManager, dataKeys, dataValues);
163
+ IERC725Y(msg.sender).setData(dataKeys, dataValues);
164
+ return "";
153
165
  } else {
154
- (bytes32[] memory dataKeys, bytes[] memory dataValues) = LSP10Utils
155
- .generateSentVaultKeys(msg.sender, notifierMapKey, notifierMapValue);
156
-
157
- result = LSP6Utils.setDataViaKeyManager(keyManager, dataKeys, dataValues);
158
- }
159
- }
160
-
161
- /**
162
- * @dev Check if the caller is owned by an LSP6KeyManager and linked to
163
- * the owner returned
164
- */
165
- function _validateCallerViaKeyManager()
166
- internal
167
- view
168
- virtual
169
- returns (address accountOwner, bool ownerIsKeyManager)
170
- {
171
- accountOwner = ERC725Y(msg.sender).owner();
172
- if (accountOwner.supportsERC165InterfaceUnchecked(_INTERFACEID_LSP6))
173
- ownerIsKeyManager = true;
174
-
175
- if (ownerIsKeyManager) {
176
- address target = ILSP6KeyManager(accountOwner).target();
177
- // check if the caller is the same account controlled by the keyManager
178
- 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 "";
179
174
  }
180
175
  }
181
176