@lukso/lsp-smart-contracts 0.5.0 → 0.6.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 (138) hide show
  1. package/README.md +29 -9
  2. package/artifacts/LSP0ERC725Account.json +392 -0
  3. package/artifacts/LSP0ERC725AccountInit.json +433 -0
  4. package/artifacts/LSP1UniversalReceiverDelegateUP.json +2 -7
  5. package/artifacts/LSP1UniversalReceiverDelegateVault.json +2 -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 +34 -28
  10. package/artifacts/LSP6KeyManagerInit.json +42 -23
  11. package/artifacts/LSP7CappedSupply.json +133 -8
  12. package/artifacts/LSP7CappedSupplyInit.json +160 -32
  13. package/artifacts/LSP7CompatibilityForERC20.json +125 -10
  14. package/artifacts/LSP7CompatibilityForERC20Init.json +727 -0
  15. package/artifacts/LSP7DigitalAsset.json +125 -10
  16. package/artifacts/LSP7DigitalAssetInit.json +149 -31
  17. package/artifacts/LSP7Mintable.json +126 -11
  18. package/artifacts/LSP7MintableInit.json +150 -32
  19. package/artifacts/LSP8CappedSupply.json +134 -8
  20. package/artifacts/LSP8CappedSupplyInit.json +169 -17
  21. package/artifacts/LSP8CompatibilityForERC721.json +126 -10
  22. package/artifacts/LSP8CompatibilityForERC721Init.json +873 -0
  23. package/artifacts/LSP8IdentifiableDigitalAsset.json +126 -10
  24. package/artifacts/LSP8IdentifiableDigitalAssetInit.json +158 -16
  25. package/artifacts/LSP8Mintable.json +138 -11
  26. package/artifacts/LSP8MintableInit.json +170 -17
  27. package/artifacts/LSP9Vault.json +368 -0
  28. package/artifacts/LSP9VaultInit.json +409 -0
  29. package/artifacts/UniversalFactory.json +127 -0
  30. package/artifacts/UniversalProfile.json +65 -14
  31. package/artifacts/UniversalProfileInit.json +104 -14
  32. package/artifacts/UniversalReceiverAddressStore.json +204 -0
  33. package/constants.js +352 -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 +89 -46
  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/LSP1Constants.sol +2 -8
  45. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/Handling/TokenAndVaultHandling.sol +59 -185
  46. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +48 -6
  47. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/Handling/TokenHandling.sol +45 -92
  48. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +39 -6
  49. package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +47 -0
  50. package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +205 -0
  51. package/contracts/LSP3UniversalProfile/LSP3Constants.sol +11 -0
  52. package/contracts/LSP4DigitalAssetMetadata/ILSP4Compatibility.sol +1 -1
  53. package/contracts/LSP4DigitalAssetMetadata/LSP4Compatibility.sol +5 -14
  54. package/contracts/LSP4DigitalAssetMetadata/LSP4Constants.sol +10 -4
  55. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol +11 -8
  56. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInit.sol +9 -13
  57. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +14 -20
  58. package/contracts/LSP5ReceivedAssets/LSP5Constants.sol +10 -0
  59. package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +157 -0
  60. package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +21 -18
  61. package/contracts/LSP6KeyManager/LSP6Constants.sol +61 -25
  62. package/contracts/LSP6KeyManager/LSP6Errors.sol +37 -0
  63. package/contracts/LSP6KeyManager/LSP6KeyManager.sol +3 -4
  64. package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +429 -332
  65. package/contracts/LSP6KeyManager/LSP6KeyManagerInit.sol +6 -5
  66. package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +7 -15
  67. package/contracts/LSP6KeyManager/LSP6Utils.sol +111 -0
  68. package/contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol +3 -8
  69. package/contracts/LSP7DigitalAsset/LSP7Constants.sol +5 -4
  70. package/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol +23 -9
  71. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +70 -94
  72. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInit.sol +8 -9
  73. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol +25 -23
  74. package/contracts/LSP7DigitalAsset/LSP7Errors.sol +23 -0
  75. package/contracts/LSP7DigitalAsset/extensions/ILSP7CappedSupply.sol +1 -1
  76. package/contracts/LSP7DigitalAsset/extensions/ILSP7CompatibilityForERC20.sol +2 -4
  77. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.sol +8 -7
  78. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyCore.sol +14 -12
  79. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInit.sol +3 -8
  80. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +9 -17
  81. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20.sol +33 -21
  82. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20Core.sol +20 -39
  83. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20Init.sol +3 -3
  84. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20InitAbstract.sol +39 -28
  85. package/contracts/LSP7DigitalAsset/{extensions → presets}/ILSP7Mintable.sol +1 -1
  86. package/contracts/LSP7DigitalAsset/{extensions → presets}/LSP7Mintable.sol +4 -3
  87. package/contracts/LSP7DigitalAsset/{extensions → presets}/LSP7MintableCore.sol +5 -5
  88. package/contracts/LSP7DigitalAsset/{extensions → presets}/LSP7MintableInit.sol +3 -2
  89. package/contracts/LSP7DigitalAsset/presets/LSP7MintableInitAbstract.sol +34 -0
  90. package/contracts/LSP8IdentifiableDigitalAsset/ILSP8IdentifiableDigitalAsset.sol +5 -16
  91. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Constants.sol +6 -3
  92. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Errors.sol +22 -0
  93. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAsset.sol +23 -10
  94. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +102 -135
  95. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInit.sol +8 -11
  96. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInitAbstract.sol +24 -21
  97. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CappedSupply.sol +1 -1
  98. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CompatibilityForERC721.sol +3 -11
  99. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupply.sol +9 -15
  100. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyCore.sol +14 -12
  101. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInit.sol +3 -8
  102. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +11 -20
  103. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721.sol +41 -33
  104. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721Core.sol +27 -84
  105. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721Init.sol +4 -6
  106. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721InitAbstract.sol +40 -41
  107. package/contracts/LSP8IdentifiableDigitalAsset/{extensions → presets}/ILSP8Mintable.sol +1 -1
  108. package/contracts/LSP8IdentifiableDigitalAsset/{extensions → presets}/LSP8Mintable.sol +4 -3
  109. package/contracts/LSP8IdentifiableDigitalAsset/{extensions → presets}/LSP8MintableCore.sol +5 -8
  110. package/contracts/LSP8IdentifiableDigitalAsset/{extensions → presets}/LSP8MintableInit.sol +4 -3
  111. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInitAbstract.sol +35 -0
  112. package/contracts/LSP9Vault/LSP9Constants.sol +13 -4
  113. package/contracts/LSP9Vault/LSP9Vault.sol +15 -37
  114. package/contracts/LSP9Vault/LSP9VaultCore.sol +101 -82
  115. package/contracts/LSP9Vault/LSP9VaultInit.sol +5 -4
  116. package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +15 -45
  117. package/contracts/Legacy/Registries/AddressRegistry.sol +43 -0
  118. package/contracts/Legacy/Registries/AddressRegistryRequiresERC725.sol +33 -0
  119. package/contracts/Legacy/UniversalReceiverAddressStore.sol +59 -0
  120. package/contracts/UniversalProfile.sol +10 -5
  121. package/contracts/UniversalProfileInit.sol +5 -4
  122. package/contracts/UniversalProfileInitAbstract.sol +14 -20
  123. package/contracts/Utils/UtilsLib.sol +47 -11
  124. package/package.json +23 -9
  125. package/artifacts/LSP1UniversalReceiverDelegateUPInit.json +0 -66
  126. package/artifacts/LSP1UniversalReceiverDelegateVaultInit.json +0 -66
  127. package/constants.ts +0 -356
  128. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUPCore.sol +0 -52
  129. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUPInit.sol +0 -26
  130. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUPInitAbstract.sol +0 -28
  131. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVaultCore.sol +0 -41
  132. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVaultInit.sol +0 -23
  133. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVaultInitAbstract.sol +0 -25
  134. package/contracts/LSP7DigitalAsset/extensions/LSP7MintableInitAbstract.sol +0 -47
  135. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8MintableInitAbstract.sol +0 -44
  136. package/contracts/Utils/ERC725Utils.sol +0 -169
  137. package/contracts/Utils/LSP2Utils.sol +0 -127
  138. package/contracts/Utils/LSP6Utils.sol +0 -63
@@ -2,19 +2,16 @@
2
2
 
3
3
  pragma solidity ^0.8.0;
4
4
 
5
- // modules
6
- import "../LSP8IdentifiableDigitalAssetCore.sol";
7
-
8
5
  // interfaces
9
- import "./ILSP8Mintable.sol";
6
+ import {ILSP8Mintable} from "./ILSP8Mintable.sol";
7
+
8
+ // modules
9
+ import {LSP8IdentifiableDigitalAssetCore} from "../LSP8IdentifiableDigitalAssetCore.sol";
10
10
 
11
11
  /**
12
12
  * @dev LSP8 extension
13
13
  */
14
- abstract contract LSP8MintableCore is
15
- ILSP8Mintable,
16
- LSP8IdentifiableDigitalAssetCore
17
- {
14
+ abstract contract LSP8MintableCore is LSP8IdentifiableDigitalAssetCore, ILSP8Mintable {
18
15
  /**
19
16
  * @inheritdoc ILSP8Mintable
20
17
  */
@@ -2,7 +2,8 @@
2
2
 
3
3
  pragma solidity ^0.8.0;
4
4
 
5
- import "./LSP8MintableInitAbstract.sol";
5
+ // modules
6
+ import {LSP8MintableInitAbstract} from "./LSP8MintableInitAbstract.sol";
6
7
 
7
8
  /**
8
9
  * @dev LSP8 extension.
@@ -18,7 +19,7 @@ contract LSP8MintableInit is LSP8MintableInitAbstract {
18
19
  string memory name_,
19
20
  string memory symbol_,
20
21
  address newOwner_
21
- ) public virtual override initializer {
22
- LSP8MintableInitAbstract.initialize(name_, symbol_, newOwner_);
22
+ ) public virtual initializer {
23
+ LSP8MintableInitAbstract._initialize(name_, symbol_, newOwner_);
23
24
  }
24
25
  }
@@ -0,0 +1,35 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity ^0.8.0;
4
+
5
+ // modules
6
+ import {LSP8IdentifiableDigitalAssetInitAbstract} from "../LSP8IdentifiableDigitalAssetInitAbstract.sol";
7
+ import {LSP8MintableCore} from "./LSP8MintableCore.sol";
8
+
9
+ /**
10
+ * @dev LSP8 extension.
11
+ */
12
+ abstract contract LSP8MintableInitAbstract is
13
+ LSP8IdentifiableDigitalAssetInitAbstract,
14
+ LSP8MintableCore
15
+ {
16
+ function _initialize(
17
+ string memory name_,
18
+ string memory symbol_,
19
+ address newOwner_
20
+ ) internal virtual override onlyInitializing {
21
+ LSP8IdentifiableDigitalAssetInitAbstract._initialize(name_, symbol_, newOwner_);
22
+ }
23
+
24
+ /**
25
+ * @inheritdoc LSP8MintableCore
26
+ */
27
+ function mint(
28
+ address to,
29
+ bytes32 tokenId,
30
+ bool force,
31
+ bytes memory data
32
+ ) public virtual override onlyOwner {
33
+ _mint(to, tokenId, force, data);
34
+ }
35
+ }
@@ -2,11 +2,20 @@
2
2
  pragma solidity ^0.8.0;
3
3
 
4
4
  // --- ERC165 interface ids
5
- bytes4 constant _INTERFACEID_LSP9 = 0x75edcee5;
5
+ bytes4 constant _INTERFACEID_LSP9 = 0x8c1d44f6;
6
6
 
7
- // --- ERC725Y entries
7
+ // --- ERC725Y Keys
8
+
9
+ // bytes10(keccak256('SupportedStandard')) + bytes2(0) + bytes20(keccak256('LSP9Vault'))
10
+ bytes32 constant _LSP9_SUPPORTED_STANDARDS_KEY = 0xeafec4d89fa9619884b600007c0334a14085fefa8b51ae5a40895018882bdb90;
11
+
12
+ // bytes4(keccak256('LSP9Vault'))
13
+ bytes constant _LSP9_SUPPORTED_STANDARDS_VALUE = hex"7c0334a1";
8
14
 
9
15
  // --- Token Hooks
10
- bytes32 constant _TYPEID_LSP9_VAULTSENDER = 0x3ca9f769340018257ac15b3a00e502e8fb730d66086f774210f84d0205af31e7; // keccak256("LSP9VaultSender")
11
16
 
12
- bytes32 constant _TYPEID_LSP9_VAULTRECIPIENT = 0x09aaf55960715d8d86b57af40be36b0bfd469c9a3643445d8c65d39e27b4c56f; // keccak256("LSP9VaultRecipient")
17
+ // keccak256("LSP9VaultSender")
18
+ bytes32 constant _TYPEID_LSP9_VAULTSENDER = 0x3ca9f769340018257ac15b3a00e502e8fb730d66086f774210f84d0205af31e7;
19
+
20
+ // keccak256("LSP9VaultRecipient")
21
+ bytes32 constant _TYPEID_LSP9_VAULTRECIPIENT = 0x09aaf55960715d8d86b57af40be36b0bfd469c9a3643445d8c65d39e27b4c56f;
@@ -1,56 +1,34 @@
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/ERC725.sol";
6
- import "./LSP9VaultCore.sol";
8
+ import {OwnableUnset} from "@erc725/smart-contracts/contracts/custom/OwnableUnset.sol";
9
+ import {ERC725} from "@erc725/smart-contracts/contracts/ERC725.sol";
10
+ import {LSP9VaultCore, ClaimOwnership} from "./LSP9VaultCore.sol";
7
11
 
8
12
  // constants
9
- import "../LSP1UniversalReceiver/LSP1Constants.sol";
13
+ import {_INTERFACEID_LSP1} from "../LSP1UniversalReceiver/LSP1Constants.sol";
14
+ import {_INTERFACEID_LSP9, _LSP9_SUPPORTED_STANDARDS_KEY, _LSP9_SUPPORTED_STANDARDS_VALUE} from "../LSP9Vault/LSP9Constants.sol";
10
15
 
11
16
  /**
12
17
  * @title Implementation of LSP9Vault built on top of ERC725, LSP1UniversalReceiver
13
18
  * @author Fabian Vogelsteller, Yamen Merhi, Jean Cavallera
14
19
  * @dev Could be owned by a UniversalProfile and able to register received asset with UniversalReceiverDelegateVault
15
20
  */
16
- contract LSP9Vault is LSP9VaultCore, ERC725 {
21
+ contract LSP9Vault is LSP9VaultCore {
17
22
  /**
18
- * @notice Sets the owner of the contract and sets the SupportedStandards:LSP9Vault key and register
19
- * LSP1UniversalReceiver and LSP9Vault InterfaceId
23
+ * @notice Sets the owner of the contract and sets the SupportedStandards:LSP9Vault key
20
24
  * @param _newOwner the owner of the contract
21
25
  */
22
- constructor(address _newOwner) ERC725(_newOwner) {
23
- // set SupportedStandards:LSP9Vault
24
- bytes32 key = 0xeafec4d89fa9619884b6b891356264550000000000000000000000007c0334a1;
25
- bytes memory value = hex"7c0334a1";
26
- _setData(key, value);
27
-
28
- _notifyVaultReceiver(_newOwner);
26
+ constructor(address _newOwner) {
27
+ OwnableUnset._setOwner(_newOwner);
29
28
 
30
- _registerInterface(_INTERFACEID_LSP1);
31
- _registerInterface(_INTERFACEID_LSP9);
32
- }
29
+ // set key SupportedStandards:LSP9Vault
30
+ _setData(_LSP9_SUPPORTED_STANDARDS_KEY, _LSP9_SUPPORTED_STANDARDS_VALUE);
33
31
 
34
- /**
35
- * @inheritdoc OwnableUnset
36
- */
37
- function transferOwnership(address newOwner)
38
- public
39
- override(OwnableUnset, LSP9VaultCore)
40
- onlyOwner
41
- {
42
- LSP9VaultCore.transferOwnership(newOwner);
43
- }
44
-
45
- /**
46
- * @inheritdoc LSP9VaultCore
47
- */
48
- function setData(bytes32[] memory _keys, bytes[] memory _values)
49
- public
50
- virtual
51
- override(ERC725YCore, LSP9VaultCore)
52
- onlyAllowed
53
- {
54
- LSP9VaultCore.setData(_keys, _values);
32
+ _notifyVaultReceiver(_newOwner);
55
33
  }
56
34
  }
@@ -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 ILSP1UniversalReceiver, ERC725XCore, ERC725YCore {
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 ILSP1UniversalReceiver, ERC725XCore, ERC725YCore {
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 ILSP1UniversalReceiver, ERC725XCore, ERC725YCore {
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
64
59
  */
65
60
  receive() external payable {
66
61
  emit ValueReceived(_msgSender(), msg.value);
67
62
  }
68
63
 
69
- // ERC725Y
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
99
+ */
100
+ function claimOwnership() public virtual override {
101
+ address previousOwner = owner();
102
+ super.claimOwnership();
103
+
104
+ _notifyVaultSender(previousOwner);
105
+ _notifyVaultReceiver(msg.sender);
106
+ }
107
+
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 ILSP1UniversalReceiver, ERC725XCore, ERC725YCore {
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,53 @@ contract LSP9VaultCore is ILSP1UniversalReceiver, ERC725XCore, ERC725YCore {
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
98
152
  virtual
99
153
  override
100
154
  returns (bytes memory returnValue)
101
155
  {
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
- );
156
+ bytes memory data = _getData(_LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY);
157
+
158
+ if (data.length >= 20) {
159
+ address universalReceiverDelegate = address(bytes20(data));
113
160
 
114
161
  if (
115
- ERC165(universalReceiverAddress).supportsInterface(
162
+ ERC165Checker.supportsERC165Interface(
163
+ universalReceiverDelegate,
116
164
  _INTERFACEID_LSP1_DELEGATE
117
165
  )
118
166
  ) {
119
- returnValue = ILSP1UniversalReceiverDelegate(
120
- universalReceiverAddress
121
- ).universalReceiverDelegate(_msgSender(), _typeId, _data);
167
+ returnValue = ILSP1UniversalReceiverDelegate(universalReceiverDelegate)
168
+ .universalReceiverDelegate(_msgSender(), _typeId, _data);
122
169
  }
123
170
  }
124
-
125
171
  emit UniversalReceiver(_msgSender(), _typeId, returnValue, _data);
126
-
127
- return returnValue;
128
172
  }
129
173
 
130
- // ERC173
174
+ // internal functions
131
175
 
132
176
  /**
133
- * @inheritdoc OwnableUnset
134
- * @dev Transfer the ownership and notify the vault sender and vault receiver
177
+ * @dev Calls the universalReceiver function of the sender if supports LSP1 InterfaceId
135
178
  */
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
179
  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
- );
180
+ if (ERC165Checker.supportsERC165Interface(_sender, _INTERFACEID_LSP1)) {
181
+ ILSP1UniversalReceiver(_sender).universalReceiver(_TYPEID_LSP9_VAULTSENDER, "");
160
182
  }
161
183
  }
162
184
 
185
+ /**
186
+ * @dev Calls the universalReceiver function of the recipient if supports LSP1 InterfaceId
187
+ */
163
188
  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
- );
189
+ if (ERC165Checker.supportsERC165Interface(_receiver, _INTERFACEID_LSP1)) {
190
+ ILSP1UniversalReceiver(_receiver).universalReceiver(_TYPEID_LSP9_VAULTRECIPIENT, "");
172
191
  }
173
192
  }
174
193
  }
@@ -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,59 @@
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 = 0xc2d7bcc1;
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
+ bytes32 typeId,
44
+ bytes memory
45
+ ) external override onlyAccount returns (bytes memory) {
46
+ // require(typeId == _TOKENS_RECIPIENT_INTERFACE_HASH, 'UniversalReceiverDelegate: Type not supported');
47
+
48
+ // store tokens only if received, DO NOT revert on _TOKENS_SENDER_INTERFACE_HASH
49
+ if (typeId == _TOKENS_RECIPIENT_INTERFACE_HASH) addAddress(sender);
50
+
51
+ return abi.encodePacked(typeId);
52
+ }
53
+
54
+ /* Modifers */
55
+ modifier onlyAccount() {
56
+ require(msg.sender == account, "Only the connected account call this function");
57
+ _;
58
+ }
59
+ }