@lukso/lsp-smart-contracts 0.4.3 → 0.6.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 (141) hide show
  1. package/README.md +38 -9
  2. package/artifacts/LSP0ERC725Account.json +398 -0
  3. package/artifacts/LSP0ERC725AccountInit.json +439 -0
  4. package/artifacts/LSP1UniversalReceiverDelegateUP.json +7 -7
  5. package/artifacts/LSP1UniversalReceiverDelegateVault.json +7 -7
  6. package/artifacts/LSP4Compatibility.json +195 -0
  7. package/artifacts/LSP4DigitalAssetMetadata.json +169 -0
  8. package/artifacts/LSP4DigitalAssetMetadataInit.json +231 -0
  9. package/artifacts/LSP6KeyManager.json +50 -28
  10. package/artifacts/LSP6KeyManagerInit.json +58 -23
  11. package/artifacts/LSP7CappedSupply.json +136 -11
  12. package/artifacts/LSP7CappedSupplyInit.json +163 -35
  13. package/artifacts/LSP7CompatibilityForERC20.json +204 -13
  14. package/artifacts/LSP7CompatibilityForERC20Init.json +727 -0
  15. package/artifacts/LSP7DigitalAsset.json +128 -13
  16. package/artifacts/LSP7DigitalAssetInit.json +152 -34
  17. package/artifacts/LSP7Mintable.json +129 -14
  18. package/artifacts/LSP7MintableInit.json +153 -35
  19. package/artifacts/LSP8CappedSupply.json +137 -11
  20. package/artifacts/LSP8CappedSupplyInit.json +172 -20
  21. package/artifacts/LSP8CompatibilityForERC721.json +138 -17
  22. package/artifacts/LSP8CompatibilityForERC721Init.json +873 -0
  23. package/artifacts/LSP8IdentifiableDigitalAsset.json +129 -13
  24. package/artifacts/LSP8IdentifiableDigitalAssetInit.json +161 -19
  25. package/artifacts/LSP8Mintable.json +141 -14
  26. package/artifacts/LSP8MintableInit.json +173 -20
  27. package/artifacts/LSP9Vault.json +374 -0
  28. package/artifacts/LSP9VaultInit.json +415 -0
  29. package/artifacts/UniversalFactory.json +127 -0
  30. package/artifacts/UniversalProfile.json +78 -53
  31. package/artifacts/UniversalProfileInit.json +117 -53
  32. package/artifacts/UniversalReceiverAddressStore.json +209 -0
  33. package/constants.js +500 -0
  34. package/contracts/Custom/ClaimOwnership.sol +31 -0
  35. package/contracts/Custom/ERC165Checker.sol +130 -0
  36. package/contracts/Custom/IClaimOwnership.sol +10 -0
  37. package/contracts/Factories/UniversalFactory.sol +155 -0
  38. package/contracts/LSP0ERC725Account/LSP0Constants.sol +5 -9
  39. package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +6 -8
  40. package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +92 -48
  41. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +5 -5
  42. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +6 -21
  43. package/contracts/LSP10ReceivedVaults/LSP10Constants.sol +10 -0
  44. package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiver.sol +3 -0
  45. package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol +4 -2
  46. package/contracts/LSP1UniversalReceiver/LSP1Constants.sol +3 -9
  47. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/Handling/TokenAndVaultHandling.sol +61 -165
  48. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +49 -6
  49. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/Handling/TokenHandling.sol +50 -90
  50. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +40 -6
  51. package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +48 -0
  52. package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +205 -0
  53. package/contracts/LSP3UniversalProfile/LSP3Constants.sol +11 -0
  54. package/contracts/LSP4DigitalAssetMetadata/ILSP4Compatibility.sol +1 -1
  55. package/contracts/LSP4DigitalAssetMetadata/LSP4Compatibility.sol +6 -15
  56. package/contracts/LSP4DigitalAssetMetadata/LSP4Constants.sol +10 -4
  57. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol +11 -8
  58. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInit.sol +9 -13
  59. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +14 -20
  60. package/contracts/LSP5ReceivedAssets/LSP5Constants.sol +10 -0
  61. package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +205 -0
  62. package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +21 -18
  63. package/contracts/LSP6KeyManager/LSP6Constants.sol +61 -24
  64. package/contracts/LSP6KeyManager/LSP6Errors.sol +37 -0
  65. package/contracts/LSP6KeyManager/LSP6KeyManager.sol +3 -4
  66. package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +475 -260
  67. package/contracts/LSP6KeyManager/LSP6KeyManagerInit.sol +6 -5
  68. package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +7 -15
  69. package/contracts/LSP6KeyManager/LSP6Utils.sol +111 -0
  70. package/contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol +3 -8
  71. package/contracts/LSP7DigitalAsset/LSP7Constants.sol +5 -4
  72. package/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol +22 -8
  73. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +70 -96
  74. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInit.sol +8 -9
  75. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol +23 -21
  76. package/contracts/LSP7DigitalAsset/LSP7Errors.sol +23 -0
  77. package/contracts/LSP7DigitalAsset/extensions/ILSP7CappedSupply.sol +1 -1
  78. package/contracts/LSP7DigitalAsset/extensions/ILSP7CompatibilityForERC20.sol +22 -6
  79. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.sol +7 -6
  80. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyCore.sol +14 -12
  81. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInit.sol +3 -8
  82. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +9 -17
  83. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20.sol +37 -45
  84. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20Core.sol +107 -0
  85. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20Init.sol +22 -0
  86. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20InitAbstract.sol +66 -0
  87. package/contracts/LSP7DigitalAsset/{extensions → presets}/ILSP7Mintable.sol +1 -1
  88. package/contracts/LSP7DigitalAsset/{extensions → presets}/LSP7Mintable.sol +4 -3
  89. package/contracts/LSP7DigitalAsset/{extensions → presets}/LSP7MintableCore.sol +5 -5
  90. package/contracts/LSP7DigitalAsset/{extensions → presets}/LSP7MintableInit.sol +3 -2
  91. package/contracts/LSP7DigitalAsset/presets/LSP7MintableInitAbstract.sol +34 -0
  92. package/contracts/LSP8IdentifiableDigitalAsset/ILSP8IdentifiableDigitalAsset.sol +5 -16
  93. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Constants.sol +6 -3
  94. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Errors.sol +22 -0
  95. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAsset.sol +21 -8
  96. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +102 -135
  97. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInit.sol +8 -11
  98. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInitAbstract.sol +22 -19
  99. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CappedSupply.sol +1 -1
  100. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CompatibilityForERC721.sol +17 -22
  101. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupply.sol +9 -15
  102. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyCore.sol +14 -12
  103. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInit.sol +3 -8
  104. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +9 -18
  105. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721.sol +37 -189
  106. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721Core.sol +187 -0
  107. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721Init.sol +25 -0
  108. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721InitAbstract.sol +89 -0
  109. package/contracts/LSP8IdentifiableDigitalAsset/{extensions → presets}/ILSP8Mintable.sol +1 -1
  110. package/contracts/LSP8IdentifiableDigitalAsset/{extensions → presets}/LSP8Mintable.sol +4 -3
  111. package/contracts/LSP8IdentifiableDigitalAsset/{extensions → presets}/LSP8MintableCore.sol +5 -8
  112. package/contracts/LSP8IdentifiableDigitalAsset/{extensions → presets}/LSP8MintableInit.sol +4 -3
  113. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInitAbstract.sol +35 -0
  114. package/contracts/LSP9Vault/LSP9Constants.sol +14 -5
  115. package/contracts/LSP9Vault/LSP9Vault.sol +15 -37
  116. package/contracts/LSP9Vault/LSP9VaultCore.sol +105 -85
  117. package/contracts/LSP9Vault/LSP9VaultInit.sol +5 -4
  118. package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +15 -45
  119. package/contracts/Legacy/Registries/AddressRegistry.sol +43 -0
  120. package/contracts/Legacy/Registries/AddressRegistryRequiresERC725.sol +33 -0
  121. package/contracts/Legacy/UniversalReceiverAddressStore.sol +60 -0
  122. package/contracts/UniversalProfile.sol +11 -20
  123. package/contracts/UniversalProfileInit.sol +5 -4
  124. package/contracts/UniversalProfileInitAbstract.sol +14 -35
  125. package/contracts/Utils/UtilsLib.sol +47 -11
  126. package/package.json +23 -9
  127. package/artifacts/LSP1UniversalReceiverDelegateUPInit.json +0 -66
  128. package/artifacts/LSP1UniversalReceiverDelegateVaultInit.json +0 -66
  129. package/constants.ts +0 -350
  130. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUPCore.sol +0 -52
  131. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUPInit.sol +0 -26
  132. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUPInitAbstract.sol +0 -28
  133. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVaultCore.sol +0 -41
  134. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVaultInit.sol +0 -23
  135. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVaultInitAbstract.sol +0 -25
  136. package/contracts/LSP7DigitalAsset/extensions/LSP7MintableInitAbstract.sol +0 -47
  137. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8MintableInitAbstract.sol +0 -44
  138. package/contracts/UniversalProfileCore.sol +0 -56
  139. package/contracts/Utils/ERC725Utils.sol +0 -169
  140. package/contracts/Utils/LSP2Utils.sol +0 -127
  141. package/contracts/Utils/LSP6Utils.sol +0 -77
@@ -1,32 +1,33 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.0;
3
3
 
4
- // modules
5
- import "@erc725/smart-contracts/contracts/ERC725X.sol";
6
- import "@erc725/smart-contracts/contracts/ERC725Y.sol";
7
-
8
4
  // interfaces
9
- import "../LSP1UniversalReceiver/ILSP1UniversalReceiver.sol";
10
- import "../LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol";
5
+ import {IERC725Y} from "@erc725/smart-contracts/contracts/interfaces/IERC725Y.sol";
6
+ import {ILSP1UniversalReceiver} from "../LSP1UniversalReceiver/ILSP1UniversalReceiver.sol";
7
+ import {ILSP1UniversalReceiverDelegate} from "../LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol";
11
8
 
12
- // library
13
- import "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
14
- import "../Utils/ERC725Utils.sol";
9
+ // libraries
10
+ import {ERC165Checker} from "../Custom/ERC165Checker.sol";
11
+
12
+ // modules
13
+ import {ERC725XCore} from "@erc725/smart-contracts/contracts/ERC725XCore.sol";
14
+ import {ERC725YCore} from "@erc725/smart-contracts/contracts/ERC725YCore.sol";
15
+ import {OwnableUnset} from "@erc725/smart-contracts/contracts/custom/OwnableUnset.sol";
16
+ import {ClaimOwnership} from "../Custom/ClaimOwnership.sol";
15
17
 
16
18
  // constants
17
- import "../LSP1UniversalReceiver/LSP1Constants.sol";
18
- import "./LSP9Constants.sol";
19
+ import {_INTERFACEID_CLAIM_OWNERSHIP} from "../Custom/IClaimOwnership.sol";
20
+ import {_INTERFACEID_LSP1, _INTERFACEID_LSP1_DELEGATE, _LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY} from "../LSP1UniversalReceiver/LSP1Constants.sol";
21
+ import {_INTERFACEID_LSP9, _TYPEID_LSP9_VAULTRECIPIENT, _TYPEID_LSP9_VAULTSENDER} from "./LSP9Constants.sol";
19
22
 
20
23
  /**
21
24
  * @title Core Implementation of LSP9Vault built on top of ERC725, LSP1UniversalReceiver
22
25
  * @author Fabian Vogelsteller, Yamen Merhi, Jean Cavallera
23
26
  * @dev Could be owned by a UniversalProfile and able to register received asset with UniversalReceiverDelegateVault
24
27
  */
25
- contract LSP9VaultCore is ERC725XCore, ERC725YCore, ILSP1UniversalReceiver {
26
- using ERC725Utils for IERC725Y;
27
-
28
+ contract LSP9VaultCore is ERC725XCore, ERC725YCore, ClaimOwnership, ILSP1UniversalReceiver {
28
29
  /**
29
- * @notice Emitted when a native token is received
30
+ * @notice Emitted when receiving native tokens
30
31
  * @param sender The address of the sender
31
32
  * @param value The amount of value sent
32
33
  */
@@ -40,17 +41,11 @@ contract LSP9VaultCore is ERC725XCore, ERC725YCore, ILSP1UniversalReceiver {
40
41
  modifier onlyAllowed() {
41
42
  if (msg.sender != owner()) {
42
43
  address universalReceiverAddress = address(
43
- bytes20(
44
- IERC725Y(this).getDataSingle(
45
- _LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY
46
- )
47
- )
44
+ bytes20(_getData(_LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY))
48
45
  );
49
46
  require(
50
- ERC165Checker.supportsInterface(
51
- msg.sender,
52
- _INTERFACEID_LSP1_DELEGATE
53
- ) && msg.sender == universalReceiverAddress,
47
+ ERC165Checker.supportsERC165Interface(msg.sender, _INTERFACEID_LSP1_DELEGATE) &&
48
+ msg.sender == universalReceiverAddress,
54
49
  "Only Owner or Universal Receiver Delegate allowed"
55
50
  );
56
51
  }
@@ -60,13 +55,69 @@ contract LSP9VaultCore is ERC725XCore, ERC725YCore, ILSP1UniversalReceiver {
60
55
  // public functions
61
56
 
62
57
  /**
63
- * @dev Emits an event when a native token is received
58
+ * @dev Emits an event when receiving native tokens
59
+ */
60
+ fallback() external payable {
61
+ if (msg.value > 0) emit ValueReceived(msg.sender, msg.value);
62
+ }
63
+
64
+ // ERC165
65
+
66
+ /**
67
+ * @dev See {IERC165-supportsInterface}.
68
+ */
69
+ function supportsInterface(bytes4 interfaceId)
70
+ public
71
+ view
72
+ virtual
73
+ override(ERC725XCore, ERC725YCore)
74
+ returns (bool)
75
+ {
76
+ return
77
+ interfaceId == _INTERFACEID_LSP9 ||
78
+ interfaceId == _INTERFACEID_LSP1 ||
79
+ interfaceId == _INTERFACEID_CLAIM_OWNERSHIP ||
80
+ super.supportsInterface(interfaceId);
81
+ }
82
+
83
+ // ERC173 - Modified ClaimOwnership
84
+
85
+ /**
86
+ * @dev Sets the pending owner
87
+ */
88
+ function transferOwnership(address newOwner)
89
+ public
90
+ virtual
91
+ override(ClaimOwnership, OwnableUnset)
92
+ onlyOwner
93
+ {
94
+ ClaimOwnership._transferOwnership(newOwner);
95
+ }
96
+
97
+ /**
98
+ * @dev Transfer the ownership and notify the vault sender and vault receiver
64
99
  */
65
- receive() external payable {
66
- emit ValueReceived(_msgSender(), msg.value);
100
+ function claimOwnership() public virtual override {
101
+ address previousOwner = owner();
102
+ super.claimOwnership();
103
+
104
+ _notifyVaultSender(previousOwner);
105
+ _notifyVaultReceiver(msg.sender);
67
106
  }
68
107
 
69
- // ERC725Y
108
+ // ERC725
109
+
110
+ /**
111
+ * @inheritdoc IERC725Y
112
+ * @dev Sets data as bytes in the vault storage for a single key.
113
+ * SHOULD only be callable by the owner of the contract set via ERC173
114
+ * and the UniversalReceiverDelegate
115
+ *
116
+ * Emits a {DataChanged} event.
117
+ */
118
+ function setData(bytes32 _key, bytes memory _value) public virtual override onlyAllowed {
119
+ _setData(_key, _value);
120
+ }
70
121
 
71
122
  /**
72
123
  * @inheritdoc IERC725Y
@@ -82,10 +133,7 @@ contract LSP9VaultCore is ERC725XCore, ERC725YCore, ILSP1UniversalReceiver {
82
133
  override
83
134
  onlyAllowed
84
135
  {
85
- require(
86
- _keys.length == _values.length,
87
- "Keys length not equal to values length"
88
- );
136
+ require(_keys.length == _values.length, "Keys length not equal to values length");
89
137
  for (uint256 i = 0; i < _keys.length; i++) {
90
138
  _setData(_keys[i], _values[i]);
91
139
  }
@@ -93,82 +141,54 @@ contract LSP9VaultCore is ERC725XCore, ERC725YCore, ILSP1UniversalReceiver {
93
141
 
94
142
  // LSP1
95
143
 
144
+ /**
145
+ * @notice Triggers the UniversalReceiver event when this function gets executed successfully.
146
+ * @dev Forwards the call to the UniversalReceiverDelegate if set.
147
+ * @param _typeId The type of call received.
148
+ * @param _data The data received.
149
+ */
96
150
  function universalReceiver(bytes32 _typeId, bytes calldata _data)
97
151
  external
152
+ payable
98
153
  virtual
99
154
  override
100
155
  returns (bytes memory returnValue)
101
156
  {
102
- bytes memory receiverData = IERC725Y(this).getDataSingle(
103
- _LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY
104
- );
105
- returnValue = "";
106
-
107
- // call external contract
108
- if (receiverData.length == 20) {
109
- address universalReceiverAddress = BytesLib.toAddress(
110
- receiverData,
111
- 0
112
- );
157
+ bytes memory data = _getData(_LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY);
158
+
159
+ if (data.length >= 20) {
160
+ address universalReceiverDelegate = address(bytes20(data));
113
161
 
114
162
  if (
115
- ERC165(universalReceiverAddress).supportsInterface(
163
+ ERC165Checker.supportsERC165Interface(
164
+ universalReceiverDelegate,
116
165
  _INTERFACEID_LSP1_DELEGATE
117
166
  )
118
167
  ) {
119
- returnValue = ILSP1UniversalReceiverDelegate(
120
- universalReceiverAddress
121
- ).universalReceiverDelegate(_msgSender(), _typeId, _data);
168
+ returnValue = ILSP1UniversalReceiverDelegate(universalReceiverDelegate)
169
+ .universalReceiverDelegate(msg.sender, msg.value, _typeId, _data);
122
170
  }
123
171
  }
124
-
125
- emit UniversalReceiver(_msgSender(), _typeId, returnValue, _data);
126
-
127
- return returnValue;
172
+ emit UniversalReceiver(msg.sender, msg.value, _typeId, returnValue, _data);
128
173
  }
129
174
 
130
- // ERC173
175
+ // internal functions
131
176
 
132
177
  /**
133
- * @inheritdoc OwnableUnset
134
- * @dev Transfer the ownership and notify the vault sender and vault receiver
178
+ * @dev Calls the universalReceiver function of the sender if supports LSP1 InterfaceId
135
179
  */
136
- function transferOwnership(address newOwner)
137
- public
138
- virtual
139
- override
140
- onlyOwner
141
- {
142
- _notifyVaultSender(msg.sender);
143
-
144
- OwnableUnset.transferOwnership(newOwner);
145
-
146
- _notifyVaultReceiver(newOwner);
147
- }
148
-
149
- // internal functions
150
-
151
180
  function _notifyVaultSender(address _sender) internal virtual {
152
- if (
153
- ERC165Checker.supportsERC165(_sender) &&
154
- ERC165Checker.supportsInterface(_sender, _INTERFACEID_LSP1)
155
- ) {
156
- ILSP1UniversalReceiver(_sender).universalReceiver(
157
- _TYPEID_LSP9_VAULTSENDER,
158
- ""
159
- );
181
+ if (ERC165Checker.supportsERC165Interface(_sender, _INTERFACEID_LSP1)) {
182
+ ILSP1UniversalReceiver(_sender).universalReceiver(_TYPEID_LSP9_VAULTSENDER, "");
160
183
  }
161
184
  }
162
185
 
186
+ /**
187
+ * @dev Calls the universalReceiver function of the recipient if supports LSP1 InterfaceId
188
+ */
163
189
  function _notifyVaultReceiver(address _receiver) internal virtual {
164
- if (
165
- ERC165Checker.supportsERC165(_receiver) &&
166
- ERC165Checker.supportsInterface(_receiver, _INTERFACEID_LSP1)
167
- ) {
168
- ILSP1UniversalReceiver(_receiver).universalReceiver(
169
- _TYPEID_LSP9_VAULTRECIPIENT,
170
- ""
171
- );
190
+ if (ERC165Checker.supportsERC165Interface(_receiver, _INTERFACEID_LSP1)) {
191
+ ILSP1UniversalReceiver(_receiver).universalReceiver(_TYPEID_LSP9_VAULTRECIPIENT, "");
172
192
  }
173
193
  }
174
194
  }
@@ -2,7 +2,7 @@
2
2
  pragma solidity ^0.8.0;
3
3
 
4
4
  // modules
5
- import "./LSP9VaultInitAbstract.sol";
5
+ import {LSP9VaultInitAbstract} from "./LSP9VaultInitAbstract.sol";
6
6
 
7
7
  /**
8
8
  * @title Deployable Proxy Implementation of LSP9Vault built on top of ERC725, LSP1UniversalReceiver
@@ -11,9 +11,10 @@ import "./LSP9VaultInitAbstract.sol";
11
11
  */
12
12
  contract LSP9VaultInit is LSP9VaultInitAbstract {
13
13
  /**
14
- * @inheritdoc LSP9VaultInitAbstract
14
+ * @notice Sets the owner of the contract and sets the SupportedStandards:LSP9Vault key
15
+ * @param _newOwner the owner of the contract
15
16
  */
16
- function initialize(address _newOwner) public override initializer {
17
- LSP9VaultInitAbstract.initialize(_newOwner);
17
+ function initialize(address _newOwner) public virtual initializer {
18
+ LSP9VaultInitAbstract._initialize(_newOwner);
18
19
  }
19
20
  }
@@ -1,60 +1,30 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.0;
3
3
 
4
+ // interfaces
5
+ import {IERC725Y} from "@erc725/smart-contracts/contracts/interfaces/IERC725Y.sol";
6
+
4
7
  // modules
5
- import "@erc725/smart-contracts/contracts/ERC725InitAbstract.sol";
6
- import "./LSP9VaultCore.sol";
8
+ import {OwnableUnset} from "@erc725/smart-contracts/contracts/custom/OwnableUnset.sol";
9
+ import {Initializable} from "@erc725/smart-contracts/contracts/custom/Initializable.sol";
10
+ import {LSP9VaultCore, ClaimOwnership} from "./LSP9VaultCore.sol";
11
+
12
+ // constants
13
+ import {_INTERFACEID_LSP1} from "../LSP1UniversalReceiver/LSP1Constants.sol";
14
+ import {_INTERFACEID_LSP9, _LSP9_SUPPORTED_STANDARDS_KEY, _LSP9_SUPPORTED_STANDARDS_VALUE} from "../LSP9Vault/LSP9Constants.sol";
7
15
 
8
16
  /**
9
17
  * @title Inheritable Proxy Implementation of LSP9Vault built on top of ERC725, LSP1UniversalReceiver
10
18
  * @author Fabian Vogelsteller, Yamen Merhi, Jean Cavallera
11
19
  * @dev Could be owned by a UniversalProfile and able to register received asset with UniversalReceiverDelegateVault
12
20
  */
13
- abstract contract LSP9VaultInitAbstract is LSP9VaultCore, ERC725InitAbstract {
14
- /**
15
- * @notice Sets the owner of the contract and sets the SupportedStandards:LSP9Vault key and register
16
- * LSP1UniversalReceiver and LSP9Vault InterfaceId
17
- * @param _newOwner the owner of the contract
18
- */
19
- function initialize(address _newOwner)
20
- public
21
- virtual
22
- override
23
- onlyInitializing
24
- {
25
- ERC725InitAbstract.initialize(_newOwner);
21
+ abstract contract LSP9VaultInitAbstract is Initializable, LSP9VaultCore {
22
+ function _initialize(address _newOwner) internal virtual onlyInitializing {
23
+ OwnableUnset._setOwner(_newOwner);
26
24
 
27
- // set SupportedStandards:LSP9Vault
28
- bytes32 key = 0xeafec4d89fa9619884b6b891356264550000000000000000000000007c0334a1;
29
- bytes memory value = hex"7c0334a1";
30
- _setData(key, value);
25
+ // set key SupportedStandards:LSP9Vault
26
+ _setData(_LSP9_SUPPORTED_STANDARDS_KEY, _LSP9_SUPPORTED_STANDARDS_VALUE);
31
27
 
32
28
  _notifyVaultReceiver(_newOwner);
33
-
34
- _registerInterface(_INTERFACEID_LSP1);
35
- _registerInterface(_INTERFACEID_LSP9);
36
- }
37
-
38
- /**
39
- * @inheritdoc OwnableUnset
40
- */
41
- function transferOwnership(address newOwner)
42
- public
43
- override(OwnableUnset, LSP9VaultCore)
44
- onlyOwner
45
- {
46
- LSP9VaultCore.transferOwnership(newOwner);
47
- }
48
-
49
- /**
50
- * @inheritdoc LSP9VaultCore
51
- */
52
- function setData(bytes32[] memory _keys, bytes[] memory _values)
53
- public
54
- virtual
55
- override(ERC725YCore, LSP9VaultCore)
56
- onlyAllowed
57
- {
58
- LSP9VaultCore.setData(_keys, _values);
59
29
  }
60
30
  }
@@ -0,0 +1,43 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.0;
3
+
4
+ // libraries
5
+ import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
6
+
7
+ // modules
8
+ import {ERC165Storage} from "@openzeppelin/contracts/utils/introspection/ERC165Storage.sol";
9
+
10
+ contract AddressRegistry is ERC165Storage {
11
+ using EnumerableSet for EnumerableSet.AddressSet;
12
+
13
+ EnumerableSet.AddressSet internal _addressStore;
14
+
15
+ function addAddress(address _address) public virtual returns (bool) {
16
+ return _addressStore.add(_address);
17
+ }
18
+
19
+ function removeAddress(address _address) public virtual returns (bool) {
20
+ return _addressStore.remove(_address);
21
+ }
22
+
23
+ function getAddress(uint256 _index) public view returns (address) {
24
+ return _addressStore.at(_index);
25
+ }
26
+
27
+ function getIndex(address _address) public view returns (uint256) {
28
+ require(_addressStore.contains(_address), "EnumerableSet: Index not found");
29
+ return _addressStore._inner._indexes[bytes32(uint256(uint160(_address)))] - 1;
30
+ }
31
+
32
+ function getAllRawValues() public view returns (bytes32[] memory) {
33
+ return _addressStore._inner._values;
34
+ }
35
+
36
+ function containsAddress(address _address) public view returns (bool) {
37
+ return _addressStore.contains(_address);
38
+ }
39
+
40
+ function length() public view returns (uint256) {
41
+ return _addressStore.length();
42
+ }
43
+ }
@@ -0,0 +1,33 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.0;
3
+
4
+ // libraries
5
+ import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
6
+
7
+ // modules
8
+ import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
9
+ import {AddressRegistry} from "./AddressRegistry.sol";
10
+
11
+ // constants
12
+ import {_INTERFACEID_ERC725Y} from "@erc725/smart-contracts/contracts/constants.sol";
13
+
14
+ contract AddressRegistryRequiresERC725 is AddressRegistry {
15
+ using EnumerableSet for EnumerableSet.AddressSet;
16
+
17
+ function addAddress(address _address) public override returns (bool) {
18
+ require(
19
+ ERC165(_address).supportsInterface(_INTERFACEID_ERC725Y),
20
+ "Only ERC725Y addresses can be added"
21
+ );
22
+ return _addressStore.add(_address);
23
+ }
24
+
25
+ function removeAddress(address _address) public override returns (bool) {
26
+ require(
27
+ ERC165(msg.sender).supportsInterface(_INTERFACEID_ERC725Y),
28
+ "Only ERC725Y can call this function"
29
+ );
30
+ require(msg.sender == _address, "Only an address can remove itself.");
31
+ return _addressStore.remove(_address);
32
+ }
33
+ }
@@ -0,0 +1,60 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.0;
3
+
4
+ // interfaces
5
+ import {ILSP1UniversalReceiverDelegate} from "../LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol";
6
+
7
+ // libraries
8
+ import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
9
+
10
+ // modules
11
+ import {ERC165Storage} from "@openzeppelin/contracts/utils/introspection/ERC165Storage.sol";
12
+ import {AddressRegistry} from "./Registries/AddressRegistry.sol";
13
+
14
+ contract UniversalReceiverAddressStore is
15
+ ERC165Storage,
16
+ ILSP1UniversalReceiverDelegate,
17
+ AddressRegistry
18
+ {
19
+ using EnumerableSet for EnumerableSet.AddressSet;
20
+
21
+ bytes4 internal constant _INTERFACE_ID_LSP1DELEGATE = 0xa245bbda;
22
+
23
+ bytes32 internal constant _TOKENS_RECIPIENT_INTERFACE_HASH =
24
+ 0xb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b; // keccak256("ERC777TokensRecipient")
25
+
26
+ address public account;
27
+
28
+ constructor(address _account) {
29
+ account = _account;
30
+ _registerInterface(_INTERFACE_ID_LSP1DELEGATE);
31
+ }
32
+
33
+ function addAddress(address _address) public override onlyAccount returns (bool) {
34
+ return _addressStore.add(_address);
35
+ }
36
+
37
+ function removeAddress(address _address) public override onlyAccount returns (bool) {
38
+ return _addressStore.remove(_address);
39
+ }
40
+
41
+ function universalReceiverDelegate(
42
+ address sender,
43
+ uint256 value,
44
+ bytes32 typeId,
45
+ bytes memory
46
+ ) external override onlyAccount returns (bytes memory) {
47
+ // require(typeId == _TOKENS_RECIPIENT_INTERFACE_HASH, 'UniversalReceiverDelegate: Type not supported');
48
+
49
+ // store tokens only if received, DO NOT revert on _TOKENS_SENDER_INTERFACE_HASH
50
+ if (typeId == _TOKENS_RECIPIENT_INTERFACE_HASH) addAddress(sender);
51
+
52
+ return abi.encodePacked(typeId);
53
+ }
54
+
55
+ /* Modifers */
56
+ modifier onlyAccount() {
57
+ require(msg.sender == account, "Only the connected account call this function");
58
+ _;
59
+ }
60
+ }
@@ -2,36 +2,27 @@
2
2
  pragma solidity ^0.8.0;
3
3
 
4
4
  // modules
5
- import "./UniversalProfileCore.sol";
6
- import "./LSP0ERC725Account/LSP0ERC725Account.sol";
5
+ import {LSP0ERC725Account} from "./LSP0ERC725Account/LSP0ERC725Account.sol";
6
+
7
+ // constants
8
+ // prettier-ignore
9
+ import {
10
+ _LSP3_SUPPORTED_STANDARDS_KEY,
11
+ _LSP3_SUPPORTED_STANDARDS_VALUE
12
+ } from "./LSP3UniversalProfile/LSP3Constants.sol";
7
13
 
8
14
  /**
9
15
  * @title implementation of a LUKSO's Universal Profile based on LSP3
10
16
  * @author Fabian Vogelsteller <fabian@lukso.network>
11
17
  * @dev Implementation of the ERC725Account + LSP1 universalReceiver
12
18
  */
13
- contract UniversalProfile is LSP0ERC725Account, UniversalProfileCore {
19
+ contract UniversalProfile is LSP0ERC725Account {
14
20
  /**
15
21
  * @notice Sets the owner of the contract and sets the SupportedStandards:LSP3UniversalProfile key
16
22
  * @param _newOwner the owner of the contract
17
23
  */
18
24
  constructor(address _newOwner) LSP0ERC725Account(_newOwner) {
19
- // set SupportedStandards:LSP3UniversalProfile
20
- bytes32 key = 0xeafec4d89fa9619884b6b89135626455000000000000000000000000abe425d6;
21
- bytes memory value = hex"abe425d6";
22
- _setData(key, value);
23
-
24
- dataKeys.push(key);
25
- }
26
-
27
- /**
28
- * @inheritdoc UniversalProfileCore
29
- */
30
- function setData(bytes32[] memory _keys, bytes[] memory _values)
31
- public
32
- override(UniversalProfileCore, ERC725YCore)
33
- onlyOwner
34
- {
35
- UniversalProfileCore.setData(_keys, _values);
25
+ // set key SupportedStandards:LSP3UniversalProfile
26
+ _setData(_LSP3_SUPPORTED_STANDARDS_KEY, _LSP3_SUPPORTED_STANDARDS_VALUE);
36
27
  }
37
28
  }
@@ -2,7 +2,7 @@
2
2
  pragma solidity ^0.8.0;
3
3
 
4
4
  // modules
5
- import "./UniversalProfileInitAbstract.sol";
5
+ import {UniversalProfileInitAbstract} from "./UniversalProfileInitAbstract.sol";
6
6
 
7
7
  /**
8
8
  * @title Deployable Proxy implementation of a LUKSO's Universal Profile based on LSP3
@@ -11,9 +11,10 @@ import "./UniversalProfileInitAbstract.sol";
11
11
  */
12
12
  contract UniversalProfileInit is UniversalProfileInitAbstract {
13
13
  /**
14
- * @inheritdoc UniversalProfileInitAbstract
14
+ * @notice Sets the owner of the contract and sets the SupportedStandards:LSP3UniversalProfile key
15
+ * @param _newOwner the owner of the contract
15
16
  */
16
- function initialize(address _newOwner) public virtual override initializer {
17
- UniversalProfileInitAbstract.initialize(_newOwner);
17
+ function initialize(address _newOwner) public virtual initializer {
18
+ UniversalProfileInitAbstract._initialize(_newOwner);
18
19
  }
19
20
  }
@@ -2,47 +2,26 @@
2
2
  pragma solidity ^0.8.0;
3
3
 
4
4
  // modules
5
- import "./UniversalProfileCore.sol";
6
- import "./LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol";
5
+ import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
6
+ import {LSP0ERC725AccountInitAbstract} from "./LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol";
7
+
8
+ // constants
9
+ // prettier-ignore
10
+ import {
11
+ _LSP3_SUPPORTED_STANDARDS_KEY,
12
+ _LSP3_SUPPORTED_STANDARDS_VALUE
13
+ } from "./LSP3UniversalProfile/LSP3Constants.sol";
7
14
 
8
15
  /**
9
16
  * @title Inheritable Proxy implementation of a LUKSO's Universal Profile based on LSP3
10
17
  * @author Fabian Vogelsteller <fabian@lukso.network>
11
18
  * @dev Implementation of the ERC725Account + LSP1 universalReceiver
12
19
  */
13
- abstract contract UniversalProfileInitAbstract is
14
- Initializable,
15
- LSP0ERC725AccountInitAbstract,
16
- UniversalProfileCore
17
- {
18
- /**
19
- * @notice Sets the owner of the contract and sets the SupportedStandards:LSP3UniversalProfile key
20
- * @param _newOwner the owner of the contract
21
- */
22
- function initialize(address _newOwner)
23
- public
24
- virtual
25
- override
26
- onlyInitializing
27
- {
28
- LSP0ERC725AccountInitAbstract.initialize(_newOwner);
29
-
30
- // set SupportedStandards:LSP3UniversalProfile
31
- bytes32 key = 0xeafec4d89fa9619884b6b89135626455000000000000000000000000abe425d6;
32
- bytes memory value = hex"abe425d6";
33
- _setData(key, value);
34
-
35
- dataKeys.push(key);
36
- }
20
+ abstract contract UniversalProfileInitAbstract is LSP0ERC725AccountInitAbstract {
21
+ function _initialize(address _newOwner) internal virtual override onlyInitializing {
22
+ LSP0ERC725AccountInitAbstract._initialize(_newOwner);
37
23
 
38
- /**
39
- * @inheritdoc UniversalProfileCore
40
- */
41
- function setData(bytes32[] memory _keys, bytes[] memory _values)
42
- public
43
- override(UniversalProfileCore, ERC725YCore)
44
- onlyOwner
45
- {
46
- UniversalProfileCore.setData(_keys, _values);
24
+ // set key SupportedStandards:LSP3UniversalProfile
25
+ _setData(_LSP3_SUPPORTED_STANDARDS_KEY, _LSP3_SUPPORTED_STANDARDS_VALUE);
47
26
  }
48
27
  }