@lukso/lsp-smart-contracts 0.5.0 → 0.6.2

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 (161) hide show
  1. package/README.md +38 -9
  2. package/artifacts/Create2Factory.json +2 -2
  3. package/artifacts/LSP0ERC725Account.json +398 -0
  4. package/artifacts/LSP0ERC725AccountInit.json +444 -0
  5. package/artifacts/LSP1UniversalReceiverDelegateUP.json +21 -5
  6. package/artifacts/LSP1UniversalReceiverDelegateVault.json +21 -5
  7. package/artifacts/LSP4Compatibility.json +195 -0
  8. package/artifacts/LSP4DigitalAssetMetadata.json +179 -0
  9. package/artifacts/LSP4DigitalAssetMetadataInit.json +241 -0
  10. package/artifacts/LSP6KeyManager.json +110 -35
  11. package/artifacts/LSP6KeyManagerInit.json +123 -30
  12. package/artifacts/LSP7CappedSupply.json +146 -11
  13. package/artifacts/LSP7CappedSupplyInit.json +167 -57
  14. package/artifacts/LSP7CompatibleERC20.json +714 -0
  15. package/artifacts/LSP7CompatibleERC20Init.json +760 -0
  16. package/artifacts/LSP7CompatibleERC20Mintable.json +742 -0
  17. package/artifacts/LSP7CompatibleERC20MintableInit.json +783 -0
  18. package/artifacts/LSP7DigitalAsset.json +138 -13
  19. package/artifacts/LSP7DigitalAssetInit.json +167 -34
  20. package/artifacts/LSP7Mintable.json +139 -14
  21. package/artifacts/LSP7MintableInit.json +168 -35
  22. package/artifacts/LSP8CappedSupply.json +147 -11
  23. package/artifacts/LSP8CappedSupplyInit.json +176 -37
  24. package/artifacts/LSP8CompatibleERC721.json +842 -0
  25. package/artifacts/LSP8CompatibleERC721Init.json +883 -0
  26. package/artifacts/LSP8CompatibleERC721Mintable.json +881 -0
  27. package/artifacts/LSP8CompatibleERC721MintableInit.json +922 -0
  28. package/artifacts/LSP8IdentifiableDigitalAsset.json +139 -13
  29. package/artifacts/LSP8IdentifiableDigitalAssetInit.json +176 -19
  30. package/artifacts/LSP8Mintable.json +151 -14
  31. package/artifacts/LSP8MintableInit.json +188 -20
  32. package/artifacts/LSP9Vault.json +374 -0
  33. package/artifacts/LSP9VaultInit.json +420 -0
  34. package/artifacts/UniversalFactory.json +127 -0
  35. package/artifacts/UniversalProfile.json +89 -32
  36. package/artifacts/UniversalProfileInit.json +133 -32
  37. package/artifacts/UniversalReceiverAddressStore.json +209 -0
  38. package/constants.js +535 -0
  39. package/contracts/Custom/ClaimOwnership.sol +34 -0
  40. package/contracts/Custom/ERC165Checker.sol +130 -0
  41. package/contracts/Custom/IClaimOwnership.sol +10 -0
  42. package/contracts/Factories/Create2Factory.sol +3 -13
  43. package/contracts/Factories/UniversalFactory.sol +164 -0
  44. package/contracts/LSP0ERC725Account/LSP0Constants.sol +5 -9
  45. package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +7 -9
  46. package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +108 -55
  47. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +11 -4
  48. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +6 -21
  49. package/contracts/LSP10ReceivedVaults/LSP10Constants.sol +10 -0
  50. package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiver.sol +3 -0
  51. package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol +4 -2
  52. package/contracts/LSP1UniversalReceiver/LSP1Constants.sol +3 -9
  53. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/Handling/TokenAndVaultHandling.sol +67 -184
  54. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +58 -6
  55. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/Handling/TokenHandling.sol +51 -89
  56. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +46 -6
  57. package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +62 -0
  58. package/contracts/LSP2ERC725YJSONSchema/LSP2Errors.sol +9 -0
  59. package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +201 -0
  60. package/contracts/LSP3UniversalProfile/LSP3Constants.sol +11 -0
  61. package/contracts/LSP4DigitalAssetMetadata/ILSP4Compatibility.sol +1 -1
  62. package/contracts/LSP4DigitalAssetMetadata/LSP4Compatibility.sol +5 -14
  63. package/contracts/LSP4DigitalAssetMetadata/LSP4Constants.sol +10 -4
  64. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol +22 -8
  65. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInit.sol +9 -13
  66. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +26 -20
  67. package/contracts/LSP4DigitalAssetMetadata/LSP4Errors.sol +16 -0
  68. package/contracts/LSP5ReceivedAssets/LSP5Constants.sol +10 -0
  69. package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +231 -0
  70. package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +28 -25
  71. package/contracts/LSP6KeyManager/LSP6Constants.sol +61 -25
  72. package/contracts/LSP6KeyManager/LSP6Errors.sol +66 -0
  73. package/contracts/LSP6KeyManager/LSP6KeyManager.sol +7 -6
  74. package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +465 -378
  75. package/contracts/LSP6KeyManager/LSP6KeyManagerInit.sol +13 -5
  76. package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +9 -15
  77. package/contracts/LSP6KeyManager/LSP6Utils.sol +107 -0
  78. package/contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol +3 -8
  79. package/contracts/LSP7DigitalAsset/LSP7Constants.sol +5 -4
  80. package/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol +27 -9
  81. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +73 -95
  82. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInit.sol +19 -9
  83. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol +27 -23
  84. package/contracts/LSP7DigitalAsset/LSP7Errors.sol +23 -0
  85. package/contracts/LSP7DigitalAsset/extensions/ILSP7CappedSupply.sol +1 -1
  86. package/contracts/LSP7DigitalAsset/extensions/{ILSP7CompatibilityForERC20.sol → ILSP7CompatibleERC20.sol} +7 -9
  87. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.sol +8 -7
  88. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyCore.sol +14 -12
  89. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInit.sol +3 -8
  90. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +10 -15
  91. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20.sol +67 -0
  92. package/contracts/LSP7DigitalAsset/extensions/{LSP7CompatibilityForERC20Core.sol → LSP7CompatibleERC20Core.sol} +36 -50
  93. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20Init.sol +29 -0
  94. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20InitAbstract.sol +67 -0
  95. package/contracts/LSP7DigitalAsset/{extensions → presets}/ILSP7Mintable.sol +1 -1
  96. package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20Mintable.sol +22 -0
  97. package/contracts/LSP7DigitalAsset/{extensions/LSP7CompatibilityForERC20Init.sol → presets/LSP7CompatibleERC20MintableInit.sol} +6 -5
  98. package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInitAbstract.sol +27 -0
  99. package/contracts/LSP7DigitalAsset/{extensions → presets}/LSP7Mintable.sol +4 -3
  100. package/contracts/LSP7DigitalAsset/{extensions → presets}/LSP7MintableCore.sol +5 -5
  101. package/contracts/LSP7DigitalAsset/{extensions → presets}/LSP7MintableInit.sol +11 -3
  102. package/contracts/LSP7DigitalAsset/presets/LSP7MintableInitAbstract.sol +34 -0
  103. package/contracts/LSP8IdentifiableDigitalAsset/ILSP8IdentifiableDigitalAsset.sol +5 -16
  104. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Constants.sol +6 -3
  105. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Errors.sol +22 -0
  106. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAsset.sol +23 -10
  107. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +103 -136
  108. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInit.sol +17 -11
  109. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInitAbstract.sol +26 -21
  110. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CappedSupply.sol +1 -1
  111. package/contracts/LSP8IdentifiableDigitalAsset/extensions/{ILSP8CompatibilityForERC721.sol → ILSP8CompatibleERC721.sol} +4 -12
  112. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupply.sol +9 -15
  113. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyCore.sol +14 -12
  114. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInit.sol +3 -8
  115. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +13 -20
  116. package/contracts/LSP8IdentifiableDigitalAsset/extensions/{LSP8CompatibilityConstants.sol → LSP8CompatibleConstants.sol} +0 -0
  117. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol +101 -0
  118. package/contracts/LSP8IdentifiableDigitalAsset/extensions/{LSP8CompatibilityForERC721Core.sol → LSP8CompatibleERC721Core.sol} +38 -95
  119. package/contracts/LSP8IdentifiableDigitalAsset/extensions/{LSP8CompatibilityForERC721Init.sol → LSP8CompatibleERC721Init.sol} +4 -6
  120. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol +93 -0
  121. package/contracts/LSP8IdentifiableDigitalAsset/{extensions → presets}/ILSP8Mintable.sol +1 -1
  122. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721Mintable.sol +22 -0
  123. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInit.sol +23 -0
  124. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInitAbstract.sol +27 -0
  125. package/contracts/LSP8IdentifiableDigitalAsset/{extensions → presets}/LSP8Mintable.sol +4 -3
  126. package/contracts/LSP8IdentifiableDigitalAsset/{extensions → presets}/LSP8MintableCore.sol +5 -8
  127. package/contracts/LSP8IdentifiableDigitalAsset/{extensions → presets}/LSP8MintableInit.sol +11 -3
  128. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInitAbstract.sol +37 -0
  129. package/contracts/LSP9Vault/LSP9Constants.sol +14 -5
  130. package/contracts/LSP9Vault/LSP9Vault.sol +20 -38
  131. package/contracts/LSP9Vault/LSP9VaultCore.sol +123 -92
  132. package/contracts/LSP9Vault/LSP9VaultInit.sol +12 -4
  133. package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +20 -46
  134. package/contracts/Legacy/Registries/AddressRegistry.sol +43 -0
  135. package/contracts/Legacy/Registries/AddressRegistryRequiresERC725.sol +33 -0
  136. package/contracts/Legacy/UniversalReceiverAddressStore.sol +62 -0
  137. package/contracts/UniversalProfile.sol +11 -7
  138. package/contracts/UniversalProfileInit.sol +12 -4
  139. package/contracts/UniversalProfileInitAbstract.sol +12 -20
  140. package/contracts/Utils/UtilsLib.sol +21 -13
  141. package/package.json +23 -9
  142. package/artifacts/LSP1UniversalReceiverDelegateUPInit.json +0 -66
  143. package/artifacts/LSP1UniversalReceiverDelegateVaultInit.json +0 -66
  144. package/artifacts/LSP7CompatibilityForERC20.json +0 -571
  145. package/artifacts/LSP8CompatibilityForERC721.json +0 -716
  146. package/constants.ts +0 -356
  147. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUPCore.sol +0 -52
  148. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUPInit.sol +0 -26
  149. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUPInitAbstract.sol +0 -28
  150. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVaultCore.sol +0 -41
  151. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVaultInit.sol +0 -23
  152. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVaultInitAbstract.sol +0 -25
  153. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20.sol +0 -56
  154. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20InitAbstract.sol +0 -55
  155. package/contracts/LSP7DigitalAsset/extensions/LSP7MintableInitAbstract.sol +0 -47
  156. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721.sol +0 -92
  157. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721InitAbstract.sol +0 -90
  158. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8MintableInitAbstract.sol +0 -44
  159. package/contracts/Utils/ERC725Utils.sol +0 -169
  160. package/contracts/Utils/LSP2Utils.sol +0 -127
  161. package/contracts/Utils/LSP6Utils.sol +0 -63
@@ -0,0 +1,10 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ bytes4 constant _INTERFACEID_CLAIM_OWNERSHIP = 0xd225f160;
5
+
6
+ interface IClaimOwnership {
7
+ function pendingOwner() external view returns (address);
8
+
9
+ function claimOwnership() external;
10
+ }
@@ -43,11 +43,7 @@ contract Create2Factory {
43
43
  * - `bytecode` must not be empty.
44
44
  * - `salt` must have not been used for `bytecode` already.
45
45
  */
46
- function deploy(bytes32 salt, bytes memory bytecode)
47
- public
48
- payable
49
- returns (address)
50
- {
46
+ function deploy(bytes32 salt, bytes memory bytecode) public payable returns (address) {
51
47
  address addr;
52
48
  uint256 amount = msg.value;
53
49
 
@@ -67,11 +63,7 @@ contract Create2Factory {
67
63
  * @dev Returns the address where a contract will be stored if deployed via {deploy}. Any change in the
68
64
  * `bytecodeHash` or `salt` will result in a new destination address.
69
65
  */
70
- function computeAddress(bytes32 salt, bytes32 bytecodeHash)
71
- public
72
- view
73
- returns (address)
74
- {
66
+ function computeAddress(bytes32 salt, bytes32 bytecodeHash) public view returns (address) {
75
67
  return computeAddress(salt, bytecodeHash, address(this));
76
68
  }
77
69
 
@@ -84,9 +76,7 @@ contract Create2Factory {
84
76
  bytes32 bytecodeHash,
85
77
  address deployer
86
78
  ) public pure returns (address) {
87
- bytes32 _data = keccak256(
88
- abi.encodePacked(bytes1(0xff), deployer, salt, bytecodeHash)
89
- );
79
+ bytes32 _data = keccak256(abi.encodePacked(bytes1(0xff), deployer, salt, bytecodeHash));
90
80
  return address(uint160(uint256(_data)));
91
81
  }
92
82
  }
@@ -0,0 +1,164 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ // libraries
5
+ import {Create2} from "@openzeppelin/contracts/utils/Create2.sol";
6
+ import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";
7
+ import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol";
8
+ import {Address} from "@openzeppelin/contracts/utils/Address.sol";
9
+
10
+ /**
11
+ * @dev UniversalFactory contract can be used to deploy CREATE2 contracts; normal contracts and minimal
12
+ * proxies (EIP-1167) with the ability to deploy the same contract at the same address on different chains.
13
+ * If the contract has a constructor, the arguments will be part of the byteCode
14
+ * If the contract has an `initialize` function, the parameters of this function will be included in
15
+ * the salt to ensure that the parameters of the contract should be the same on each chain.
16
+ *
17
+ * Security measures were taken to avoid deploying proxies from the `deployCreate2(..)` function
18
+ * to prevent the problem mentioned above.
19
+ *
20
+ * This contract should be deployed using Nick's Method.
21
+ * More information: https://weka.medium.com/how-to-send-ether-to-11-440-people-187e332566b7
22
+ */
23
+ contract UniversalFactory {
24
+ using BytesLib for bytes;
25
+
26
+ // The bytecode hash of EIP-1167 Minimal Proxy
27
+ bytes32 private constant _MINIMAL_PROXY_BYTECODE_HASH_PT1 =
28
+ 0x72307939328b75c6e301a012c75e0a4e690a99036b95f6e6f4f1b5aba02a9ce4;
29
+
30
+ bytes32 private constant _MINIMAL_PROXY_BYTECODE_HASH_PT2 =
31
+ 0x11a195f66c9175f46895bae2006d40848a680c7068b9fc4af248ff9a54a47e45;
32
+
33
+ /**
34
+ * @dev Throws if the `byteCode` passed to the function is the EIP-1167 Minimal Proxy bytecode
35
+ */
36
+ modifier notMinimalProxy(bytes memory byteCode) virtual {
37
+ if (byteCode.length == 55) {
38
+ if (
39
+ keccak256(byteCode.slice(0, 20)) == _MINIMAL_PROXY_BYTECODE_HASH_PT1 &&
40
+ keccak256(byteCode.slice(40, 15)) == _MINIMAL_PROXY_BYTECODE_HASH_PT2
41
+ ) {
42
+ revert("Minimal Proxies deployment not allowed");
43
+ }
44
+ }
45
+ _;
46
+ }
47
+
48
+ /**
49
+ * @dev Returns the address where a contract will be stored if deployed via `CREATE2`. The address is
50
+ * constructed using the parameters below. Any change in one of them will result in a new destination address.
51
+ */
52
+ function calculateAddress(
53
+ bytes32 byteCodeHash,
54
+ bytes32 salt,
55
+ bytes memory initializeCallData
56
+ ) public view returns (address) {
57
+ bytes32 generatedSalt = _generateSalt(initializeCallData, salt);
58
+ return Create2.computeAddress(generatedSalt, byteCodeHash);
59
+ }
60
+
61
+ /**
62
+ * @dev Returns the address of an EIP1167 proxy contract. The address is constructed using
63
+ * the parameters below. Any change in one of them will result in a new destination address.
64
+ */
65
+ function calculateProxyAddress(
66
+ address baseContract,
67
+ bytes32 salt,
68
+ bytes memory initializeCallData
69
+ ) public view returns (address) {
70
+ bytes32 generatedSalt = _generateSalt(initializeCallData, salt);
71
+ return Clones.predictDeterministicAddress(baseContract, generatedSalt);
72
+ }
73
+
74
+ /**
75
+ * @dev Deploys a contract using `CREATE2`. The address where the contract will be deployed
76
+ * can be known in advance via {calculateAddress}. The salt is a combination between an initializable
77
+ * boolean, `salt` and the `initializeCallData` if the contract is initializable. This method allow users
78
+ * to have the same contracts at the same address across different chains with the same parameters.
79
+ *
80
+ * Using the same `byteCode` and salt multiple time will revert, since
81
+ * the contract cannot be deployed twice at the same address.
82
+ *
83
+ * Deploying a minimal proxy from this function will revert.
84
+ */
85
+ function deployCreate2(
86
+ bytes memory byteCode,
87
+ bytes32 salt,
88
+ bytes memory initializeCallData
89
+ ) public payable notMinimalProxy(byteCode) returns (address contractCreated) {
90
+ bytes32 generatedSalt = _generateSalt(initializeCallData, salt);
91
+ contractCreated = Create2.deploy(msg.value, generatedSalt, byteCode);
92
+
93
+ if (initializeCallData.length > 0) {
94
+ // solhint-disable avoid-low-level-calls
95
+ (bool success, bytes memory returnData) = contractCreated.call(initializeCallData);
96
+ Address.verifyCallResult(
97
+ success,
98
+ returnData,
99
+ "UniversalFactory: could not initialize the created contract"
100
+ );
101
+ }
102
+ }
103
+
104
+ /**
105
+ * @dev Deploys and returns the address of a clone that mimics the behaviour of `baseContract`.
106
+ * The address where the contract will be deployed can be known in advance via {calculateProxyAddress}.
107
+ *
108
+ * This function uses the CREATE2 opcode and a salt to deterministically deploy
109
+ * the clone. The salt is a combination between an initializable boolean, `salt`
110
+ * and the `initializeCallData` if the contract is initializable. This method allow users
111
+ * to have the same contracts at the same address across different chains with the same parameters.
112
+ *
113
+ * Using the same `baseContract` and salt multiple time will revert, since
114
+ * the clones cannot be deployed twice at the same address.
115
+ */
116
+ function deployCreate2Proxy(
117
+ address baseContract,
118
+ bytes32 salt,
119
+ bytes memory initializeCallData
120
+ ) public payable returns (address proxy) {
121
+ bytes32 generatedSalt = _generateSalt(initializeCallData, salt);
122
+ proxy = Clones.cloneDeterministic(baseContract, generatedSalt);
123
+
124
+ if (initializeCallData.length > 0) {
125
+ // solhint-disable avoid-low-level-calls
126
+ (bool success, bytes memory returnData) = proxy.call{value: msg.value}(
127
+ initializeCallData
128
+ );
129
+ Address.verifyCallResult(
130
+ success,
131
+ returnData,
132
+ "UniversalFactory: could not initialize the created contract"
133
+ );
134
+ } else {
135
+ // @todo check if this part make sense
136
+ // Return value sent
137
+ if (msg.value > 0) {
138
+ // solhint-disable avoid-low-level-calls
139
+ (bool success, bytes memory returnData) = payable(msg.sender).call{
140
+ value: msg.value
141
+ }("");
142
+ Address.verifyCallResult(success, returnData, "UniversalFactory: Unknow Error");
143
+ }
144
+ }
145
+ }
146
+
147
+ /** internal functions */
148
+
149
+ /**
150
+ * @dev Calculates the salt including the initializeCallData, or without but hashing it with a zero bytes padding.
151
+ */
152
+ function _generateSalt(bytes memory initializeCallData, bytes32 salt)
153
+ internal
154
+ pure
155
+ returns (bytes32)
156
+ {
157
+ bool initializable = initializeCallData.length > 0;
158
+ if (initializable) {
159
+ return keccak256(abi.encodePacked(initializable, initializeCallData, salt));
160
+ } else {
161
+ return keccak256(abi.encodePacked(initializable, salt));
162
+ }
163
+ }
164
+ }
@@ -1,14 +1,10 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.0;
3
3
 
4
- // >> INTERFACES
5
-
6
- bytes4 constant _INTERFACE_ID_ERC725ACCOUNT = 0x63cb749b;
7
-
8
- bytes4 constant _INTERFACE_ID_ERC1271 = 0x1626ba7e;
9
-
10
- // >> OTHER
4
+ // --- ERC165 interface ids
5
+ bytes4 constant _INTERFACEID_LSP0 = 0x9a3bfe88;
6
+ bytes4 constant _INTERFACEID_ERC1271 = 0x1626ba7e;
11
7
 
12
8
  // ERC1271 - Standard Signature Validation
13
- bytes4 constant _ERC1271MAGICVALUE = 0x1626ba7e;
14
- bytes4 constant _ERC1271FAILVALUE = 0xffffffff;
9
+ bytes4 constant _ERC1271_MAGICVALUE = 0x1626ba7e;
10
+ bytes4 constant _ERC1271_FAILVALUE = 0xffffffff;
@@ -2,22 +2,20 @@
2
2
  pragma solidity ^0.8.0;
3
3
 
4
4
  // modules
5
- import "./LSP0ERC725AccountCore.sol";
6
- import "@erc725/smart-contracts/contracts/ERC725.sol";
5
+ import {LSP0ERC725AccountCore} from "./LSP0ERC725AccountCore.sol";
6
+ import {OwnableUnset} from "@erc725/smart-contracts/contracts/custom/OwnableUnset.sol";
7
7
 
8
8
  /**
9
9
  * @title Implementation of ERC725Account
10
10
  * @author Fabian Vogelsteller <fabian@lukso.network>, Jean Cavallera (CJ42), Yamen Merhi (YamenMerhi)
11
11
  * @dev Bundles ERC725X and ERC725Y, ERC1271 and LSP1UniversalReceiver and allows receiving native tokens
12
12
  */
13
- contract LSP0ERC725Account is LSP0ERC725AccountCore, ERC725 {
13
+ contract LSP0ERC725Account is LSP0ERC725AccountCore {
14
14
  /**
15
- * @notice Sets the owner of the contract and register ERC725Account, ERC1271 and LSP1UniversalReceiver interfacesId
16
- * @param _newOwner the owner of the contract
15
+ * @notice Sets the owner of the contract
16
+ * @param newOwner the owner of the contract
17
17
  */
18
- constructor(address _newOwner) ERC725(_newOwner) {
19
- _registerInterface(_INTERFACE_ID_ERC725ACCOUNT);
20
- _registerInterface(_INTERFACE_ID_ERC1271);
21
- _registerInterface(_INTERFACEID_LSP1);
18
+ constructor(address newOwner) payable {
19
+ OwnableUnset._setOwner(newOwner);
22
20
  }
23
21
  }
@@ -2,23 +2,34 @@
2
2
  pragma solidity ^0.8.0;
3
3
 
4
4
  // interfaces
5
- import "@openzeppelin/contracts/interfaces/IERC1271.sol";
6
- import "../LSP1UniversalReceiver/ILSP1UniversalReceiver.sol";
7
- import "../LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol";
8
-
9
- // modules
10
-
11
- import "@erc725/smart-contracts/contracts/ERC725YCore.sol";
12
- import "@erc725/smart-contracts/contracts/ERC725XCore.sol";
5
+ import {IERC1271} from "@openzeppelin/contracts/interfaces/IERC1271.sol";
6
+ import {ILSP1UniversalReceiver} from "../LSP1UniversalReceiver/ILSP1UniversalReceiver.sol";
7
+ import {
8
+ ILSP1UniversalReceiverDelegate
9
+ } from "../LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol";
13
10
 
14
11
  // libraries
15
- import "../Utils/UtilsLib.sol";
16
- import "../Utils/ERC725Utils.sol";
17
- import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
12
+ import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
13
+ import {ERC165Checker} from "../Custom/ERC165Checker.sol";
14
+
15
+ // modules
16
+ import {ERC725YCore} from "@erc725/smart-contracts/contracts/ERC725YCore.sol";
17
+ import {ERC725XCore} from "@erc725/smart-contracts/contracts/ERC725XCore.sol";
18
+ import {OwnableUnset} from "@erc725/smart-contracts/contracts/custom/OwnableUnset.sol";
19
+ import {ClaimOwnership} from "../Custom/ClaimOwnership.sol";
18
20
 
19
21
  // constants
20
- import "../LSP1UniversalReceiver/LSP1Constants.sol";
21
- import "../LSP0ERC725Account/LSP0Constants.sol";
22
+ import {
23
+ _INTERFACEID_LSP0,
24
+ _INTERFACEID_ERC1271,
25
+ _ERC1271_FAILVALUE
26
+ } from "../LSP0ERC725Account/LSP0Constants.sol";
27
+ import {
28
+ _INTERFACEID_LSP1,
29
+ _INTERFACEID_LSP1_DELEGATE,
30
+ _LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY
31
+ } from "../LSP1UniversalReceiver/LSP1Constants.sol";
32
+ import {_INTERFACEID_CLAIM_OWNERSHIP} from "../Custom/IClaimOwnership.sol";
22
33
 
23
34
  /**
24
35
  * @title Core Implementation of ERC725Account
@@ -26,17 +37,24 @@ import "../LSP0ERC725Account/LSP0Constants.sol";
26
37
  * @dev Bundles ERC725X and ERC725Y, ERC1271 and LSP1UniversalReceiver and allows receiving native tokens
27
38
  */
28
39
  abstract contract LSP0ERC725AccountCore is
29
- IERC1271,
30
- ILSP1UniversalReceiver,
31
40
  ERC725XCore,
32
- ERC725YCore
41
+ ERC725YCore,
42
+ ClaimOwnership,
43
+ IERC1271,
44
+ ILSP1UniversalReceiver
33
45
  {
34
- using ERC725Utils for IERC725Y;
35
-
46
+ /**
47
+ * @notice Emitted when receiving native tokens
48
+ * @param sender The address of the sender
49
+ * @param value The amount of value sent
50
+ */
36
51
  event ValueReceived(address indexed sender, uint256 indexed value);
37
52
 
38
- receive() external payable {
39
- emit ValueReceived(_msgSender(), msg.value);
53
+ /**
54
+ * @dev Emits an event when receiving native tokens
55
+ */
56
+ fallback() external payable virtual {
57
+ if (msg.value > 0) emit ValueReceived(msg.sender, msg.value);
40
58
  }
41
59
 
42
60
  // TODO to be discussed
@@ -54,66 +72,101 @@ abstract contract LSP0ERC725AccountCore is
54
72
  // }
55
73
  // }
56
74
 
75
+ // ERC165
76
+
77
+ /**
78
+ * @dev See {IERC165-supportsInterface}.
79
+ */
80
+ function supportsInterface(bytes4 interfaceId)
81
+ public
82
+ view
83
+ virtual
84
+ override(ERC725XCore, ERC725YCore)
85
+ returns (bool)
86
+ {
87
+ return
88
+ interfaceId == _INTERFACEID_ERC1271 ||
89
+ interfaceId == _INTERFACEID_LSP0 ||
90
+ interfaceId == _INTERFACEID_LSP1 ||
91
+ interfaceId == _INTERFACEID_CLAIM_OWNERSHIP ||
92
+ super.supportsInterface(interfaceId);
93
+ }
94
+
95
+ // ERC173 - Modified ClaimOwnership
96
+
97
+ /**
98
+ * @dev Sets the pending owner
99
+ */
100
+ function transferOwnership(address _newOwner)
101
+ public
102
+ virtual
103
+ override(ClaimOwnership, OwnableUnset)
104
+ onlyOwner
105
+ {
106
+ ClaimOwnership._transferOwnership(_newOwner);
107
+ }
108
+
109
+ // ERC1271
110
+
57
111
  /**
58
112
  * @notice Checks if an owner signed `_data`.
59
113
  * ERC1271 interface.
60
114
  *
61
- * @param _hash hash of the data signed//Arbitrary length data signed on the behalf of address(this)
62
- * @param _signature owner's signature(s) of the data
115
+ * @param dataHash hash of the data signed//Arbitrary length data signed on the behalf of address(this)
116
+ * @param signature owner's signature(s) of the data
63
117
  */
64
- function isValidSignature(bytes32 _hash, bytes memory _signature)
118
+ function isValidSignature(bytes32 dataHash, bytes memory signature)
65
119
  public
66
120
  view
67
121
  override
68
122
  returns (bytes4 magicValue)
69
123
  {
70
- // prettier-ignore
124
+ address _owner = owner();
71
125
  // if OWNER is a contract
72
- if (UtilsLib.isContract(owner())) {
73
- return
74
- supportsInterface(_INTERFACE_ID_ERC1271)
75
- ? IERC1271(owner()).isValidSignature(_hash, _signature)
76
- : _ERC1271FAILVALUE;
77
- // if OWNER is a key
126
+ if (_owner.code.length != 0) {
127
+ return
128
+ ERC165Checker.supportsERC165Interface(_owner, _INTERFACEID_ERC1271)
129
+ ? IERC1271(_owner).isValidSignature(dataHash, signature)
130
+ : _ERC1271_FAILVALUE;
131
+ // if OWNER is a key
78
132
  } else {
79
- return
80
- owner() == ECDSA.recover(_hash, _signature)
81
- ? _INTERFACE_ID_ERC1271
82
- : _ERC1271FAILVALUE;
133
+ return
134
+ _owner == ECDSA.recover(dataHash, signature)
135
+ ? _INTERFACEID_ERC1271
136
+ : _ERC1271_FAILVALUE;
83
137
  }
84
138
  }
85
139
 
86
- function universalReceiver(bytes32 _typeId, bytes calldata _data)
87
- external
140
+ // LSP1
141
+
142
+ /**
143
+ * @notice Triggers the UniversalReceiver event when this function gets executed successfully.
144
+ * @dev Forwards the call to the UniversalReceiverDelegate if set.
145
+ * @param typeId The type of call received.
146
+ * @param data The data received.
147
+ */
148
+ function universalReceiver(bytes32 typeId, bytes calldata data)
149
+ public
150
+ payable
88
151
  virtual
89
152
  override
90
153
  returns (bytes memory returnValue)
91
154
  {
92
- bytes memory receiverData = IERC725Y(this).getDataSingle(
93
- _LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY
94
- );
95
- returnValue = "";
96
-
97
- // call external contract
98
- if (receiverData.length == 20) {
99
- address universalReceiverAddress = BytesLib.toAddress(
100
- receiverData,
101
- 0
102
- );
155
+ bytes memory lsp1DelegateValue = _getData(_LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY);
156
+
157
+ if (lsp1DelegateValue.length >= 20) {
158
+ address universalReceiverDelegate = address(bytes20(lsp1DelegateValue));
103
159
 
104
160
  if (
105
- ERC165(universalReceiverAddress).supportsInterface(
161
+ ERC165Checker.supportsERC165Interface(
162
+ universalReceiverDelegate,
106
163
  _INTERFACEID_LSP1_DELEGATE
107
164
  )
108
165
  ) {
109
- returnValue = ILSP1UniversalReceiverDelegate(
110
- universalReceiverAddress
111
- ).universalReceiverDelegate(_msgSender(), _typeId, _data);
166
+ returnValue = ILSP1UniversalReceiverDelegate(universalReceiverDelegate)
167
+ .universalReceiverDelegate(msg.sender, msg.value, typeId, data);
112
168
  }
113
169
  }
114
-
115
- emit UniversalReceiver(_msgSender(), _typeId, returnValue, _data);
116
-
117
- return returnValue;
170
+ emit UniversalReceiver(msg.sender, msg.value, typeId, returnValue, data);
118
171
  }
119
172
  }
@@ -2,7 +2,7 @@
2
2
  pragma solidity ^0.8.0;
3
3
 
4
4
  // modules
5
- import "./LSP0ERC725AccountInitAbstract.sol";
5
+ import {LSP0ERC725AccountInitAbstract} from "./LSP0ERC725AccountInitAbstract.sol";
6
6
 
7
7
  /**
8
8
  * @title Deployable Proxy Implementation of ERC725Account
@@ -11,10 +11,17 @@ import "./LSP0ERC725AccountInitAbstract.sol";
11
11
  */
12
12
  contract LSP0ERC725AccountInit is LSP0ERC725AccountInitAbstract {
13
13
  /**
14
- * @inheritdoc LSP0ERC725AccountInitAbstract
14
+ * @dev @dev initialize (= lock) base implementation contract on deployment
15
15
  */
16
+ constructor() {
17
+ _disableInitializers();
18
+ }
16
19
 
17
- function initialize(address _newOwner) public virtual override initializer {
18
- LSP0ERC725AccountInitAbstract.initialize(_newOwner);
20
+ /**
21
+ * @notice Sets the owner of the contract
22
+ * @param newOwner the owner of the contract
23
+ */
24
+ function initialize(address newOwner) public payable virtual initializer {
25
+ LSP0ERC725AccountInitAbstract._initialize(newOwner);
19
26
  }
20
27
  }
@@ -2,32 +2,17 @@
2
2
  pragma solidity ^0.8.0;
3
3
 
4
4
  // modules
5
- import "@erc725/smart-contracts/contracts/ERC725InitAbstract.sol";
6
- import "./LSP0ERC725AccountCore.sol";
5
+ import {LSP0ERC725AccountCore} from "./LSP0ERC725AccountCore.sol";
6
+ import {Initializable} from "@erc725/smart-contracts/contracts/custom/Initializable.sol";
7
+ import {OwnableUnset} from "@erc725/smart-contracts/contracts/custom/OwnableUnset.sol";
7
8
 
8
9
  /**
9
10
  * @title Inheritable Proxy Implementation of ERC725Account
10
11
  * @author Fabian Vogelsteller <fabian@lukso.network>, Jean Cavallera (CJ42), Yamen Merhi (YamenMerhi)
11
12
  * @dev Bundles ERC725X and ERC725Y, ERC1271 and LSP1UniversalReceiver and allows receiving native tokens
12
13
  */
13
- abstract contract LSP0ERC725AccountInitAbstract is
14
- LSP0ERC725AccountCore,
15
- ERC725InitAbstract
16
- {
17
- /**
18
- * @notice Sets the owner of the contract and register ERC725Account, ERC1271 and LSP1UniversalReceiver interfacesId
19
- * @param _newOwner the owner of the contract
20
- */
21
- function initialize(address _newOwner)
22
- public
23
- virtual
24
- override
25
- onlyInitializing
26
- {
27
- ERC725InitAbstract.initialize(_newOwner);
28
-
29
- _registerInterface(_INTERFACE_ID_ERC725ACCOUNT);
30
- _registerInterface(_INTERFACE_ID_ERC1271);
31
- _registerInterface(_INTERFACEID_LSP1);
14
+ abstract contract LSP0ERC725AccountInitAbstract is Initializable, LSP0ERC725AccountCore {
15
+ function _initialize(address newOwner) internal virtual onlyInitializing {
16
+ OwnableUnset._setOwner(newOwner);
32
17
  }
33
18
  }
@@ -0,0 +1,10 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.0;
3
+
4
+ // --- ERC725Y Keys
5
+
6
+ // keccak256('LSP10Vaults[]')
7
+ bytes32 constant _LSP10_VAULTS_ARRAY_KEY = 0x55482936e01da86729a45d2b87a6b1d3bc582bea0ec00e38bdb340e3af6f9f06;
8
+
9
+ // bytes10(keccak256('LSP10VaultsMap')) + bytes2(0)
10
+ bytes12 constant _LSP10_VAULTS_MAP_KEY_PREFIX = 0x192448c3c0f88c7f238c0000;
@@ -9,12 +9,14 @@ interface ILSP1UniversalReceiver {
9
9
  /**
10
10
  * @notice Emitted when the universalReceiver function is succesfully executed
11
11
  * @param from The address calling the universalReceiver function
12
+ * @param value The amount sent to the universalReceiver function
12
13
  * @param typeId The hash of a specific standard or a hook
13
14
  * @param returnedValue The return value of universalReceiver function
14
15
  * @param receivedData The arbitrary data passed to universalReceiver function
15
16
  */
16
17
  event UniversalReceiver(
17
18
  address indexed from,
19
+ uint256 value,
18
20
  bytes32 indexed typeId,
19
21
  bytes indexed returnedValue,
20
22
  bytes receivedData
@@ -33,5 +35,6 @@ interface ILSP1UniversalReceiver {
33
35
  */
34
36
  function universalReceiver(bytes32 typeId, bytes calldata data)
35
37
  external
38
+ payable
36
39
  returns (bytes memory);
37
40
  }
@@ -9,13 +9,15 @@ pragma solidity ^0.8.0;
9
9
  interface ILSP1UniversalReceiverDelegate {
10
10
  /**
11
11
  * @dev Get called by the universalReceiver function, can be customized to have a specific logic
12
- * @param sender The address calling the universalReceiver function
12
+ * @param caller The address calling the universalReceiver function
13
+ * @param value The amount sent to the universalReceiver function
13
14
  * @param typeId The hash of a specific standard or a hook
14
15
  * @param data The arbitrary data received with the call
15
16
  * @return result Any useful data could be returned
16
17
  */
17
18
  function universalReceiverDelegate(
18
- address sender,
19
+ address caller,
20
+ uint256 value,
19
21
  bytes32 typeId,
20
22
  bytes memory data
21
23
  ) external returns (bytes memory result);
@@ -3,15 +3,9 @@ pragma solidity ^0.8.0;
3
3
 
4
4
  // --- ERC165 interface ids
5
5
  bytes4 constant _INTERFACEID_LSP1 = 0x6bb56a14;
6
- bytes4 constant _INTERFACEID_LSP1_DELEGATE = 0xc2d7bcc1;
6
+ bytes4 constant _INTERFACEID_LSP1_DELEGATE = 0xa245bbda;
7
7
 
8
8
  // --- ERC725Y Keys
9
- bytes32 constant _LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY = 0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47; // keccak256("LSP1UniversalReceiverDelegate")
10
9
 
11
- bytes32 constant _ARRAYKEY_LSP5 = 0x6460ee3c0aac563ccbf76d6e1d07bada78e3a9514e6382b736ed3f478ab7b90b; // keccak256("LSP5ReceivedAssets[]")
12
-
13
- bytes32 constant _MAPHASH_LSP5 = 0x812c4334633eb816c80deebfa5fb7d2509eb438ca1b6418106442cb5ccc62f6c; // keccak256("LSP5ReceivedAssetsMap")
14
-
15
- bytes32 constant _ARRAYKEY_LSP10 = 0x55482936e01da86729a45d2b87a6b1d3bc582bea0ec00e38bdb340e3af6f9f06; // keccak256("LSP10Vaults[]")
16
-
17
- bytes32 constant _MAPHASH_LSP10 = 0x192448c3c0f88c7f238c7f70449c270032f9752568e88cc8936ce3a2cb18e3ec; // keccak256("LSP10VaultsMap")
10
+ // keccak256('LSP1UniversalReceiverDelegate')
11
+ bytes32 constant _LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY = 0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47;