@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
@@ -0,0 +1,155 @@
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 {ErrorHandlerLib} from "@erc725/smart-contracts/contracts/utils/ErrorHandlerLib.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 returnedData) = contractCreated.call(initializeCallData);
96
+ if (!success) ErrorHandlerLib.revertWithParsedError(returnedData);
97
+ }
98
+ }
99
+
100
+ /**
101
+ * @dev Deploys and returns the address of a clone that mimics the behaviour of `baseContract`.
102
+ * The address where the contract will be deployed can be known in advance via {calculateProxyAddress}.
103
+ *
104
+ * This function uses the CREATE2 opcode and a salt to deterministically deploy
105
+ * the clone. The salt is a combination between an initializable boolean, `salt`
106
+ * and the `initializeCallData` if the contract is initializable. This method allow users
107
+ * to have the same contracts at the same address across different chains with the same parameters.
108
+ *
109
+ * Using the same `baseContract` and salt multiple time will revert, since
110
+ * the clones cannot be deployed twice at the same address.
111
+ */
112
+ function deployCreate2Proxy(
113
+ address baseContract,
114
+ bytes32 salt,
115
+ bytes memory initializeCallData
116
+ ) public payable returns (address proxy) {
117
+ bytes32 generatedSalt = _generateSalt(initializeCallData, salt);
118
+ proxy = Clones.cloneDeterministic(baseContract, generatedSalt);
119
+
120
+ if (initializeCallData.length > 0) {
121
+ // solhint-disable avoid-low-level-calls
122
+ (bool success, bytes memory returnedData) = proxy.call{value: msg.value}(
123
+ initializeCallData
124
+ );
125
+ if (!success) ErrorHandlerLib.revertWithParsedError(returnedData);
126
+ } else {
127
+ // Return value sent
128
+ if (msg.value > 0) {
129
+ // solhint-disable avoid-low-level-calls
130
+ (bool success, bytes memory returnedData) = payable(msg.sender).call{
131
+ value: msg.value
132
+ }("");
133
+ if (!success) ErrorHandlerLib.revertWithParsedError(returnedData);
134
+ }
135
+ }
136
+ }
137
+
138
+ /** internal functions */
139
+
140
+ /**
141
+ * @dev Calculates the salt including the initializeCallData, or without but hashing it with a zero bytes padding.
142
+ */
143
+ function _generateSalt(bytes memory initializeCallData, bytes32 salt)
144
+ internal
145
+ pure
146
+ returns (bytes32)
147
+ {
148
+ bool initializable = initializeCallData.length > 0;
149
+ if (initializable) {
150
+ return keccak256(abi.encodePacked(initializable, initializeCallData, salt));
151
+ } else {
152
+ return keccak256(abi.encodePacked(initializable, salt));
153
+ }
154
+ }
155
+ }
@@ -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 ERC725, LSP0ERC725AccountCore {
13
+ contract LSP0ERC725Account is LSP0ERC725AccountCore {
14
14
  /**
15
- * @notice Sets the owner of the contract and register ERC725Account, ERC1271 and LSP1UniversalReceiver interfacesId
15
+ * @notice Sets the owner of the contract
16
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) {
19
+ OwnableUnset._setOwner(_newOwner);
22
20
  }
23
21
  }
@@ -2,23 +2,24 @@
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 {ILSP1UniversalReceiverDelegate} from "../LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol";
13
8
 
14
9
  // libraries
15
- import "../Utils/UtilsLib.sol";
16
- import "../Utils/ERC725Utils.sol";
17
- import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
10
+ import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
11
+ import {ERC165Checker} from "../Custom/ERC165Checker.sol";
12
+
13
+ // modules
14
+ import {ERC725YCore} from "@erc725/smart-contracts/contracts/ERC725YCore.sol";
15
+ import {ERC725XCore} from "@erc725/smart-contracts/contracts/ERC725XCore.sol";
16
+ import {OwnableUnset} from "@erc725/smart-contracts/contracts/custom/OwnableUnset.sol";
17
+ import {ClaimOwnership} from "../Custom/ClaimOwnership.sol";
18
18
 
19
19
  // constants
20
- import "../LSP1UniversalReceiver/LSP1Constants.sol";
21
- import "../LSP0ERC725Account/LSP0Constants.sol";
20
+ import {_INTERFACEID_LSP0, _INTERFACEID_ERC1271, _ERC1271_FAILVALUE} from "../LSP0ERC725Account/LSP0Constants.sol";
21
+ import {_INTERFACEID_LSP1, _INTERFACEID_LSP1_DELEGATE, _LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY} from "../LSP1UniversalReceiver/LSP1Constants.sol";
22
+ import {_INTERFACEID_CLAIM_OWNERSHIP} from "../Custom/IClaimOwnership.sol";
22
23
 
23
24
  /**
24
25
  * @title Core Implementation of ERC725Account
@@ -28,15 +29,22 @@ import "../LSP0ERC725Account/LSP0Constants.sol";
28
29
  abstract contract LSP0ERC725AccountCore is
29
30
  ERC725XCore,
30
31
  ERC725YCore,
31
- ILSP1UniversalReceiver,
32
- IERC1271
32
+ ClaimOwnership,
33
+ IERC1271,
34
+ ILSP1UniversalReceiver
33
35
  {
34
- using ERC725Utils for IERC725Y;
35
-
36
+ /**
37
+ * @notice Emitted when receiving native tokens
38
+ * @param sender The address of the sender
39
+ * @param value The amount of value sent
40
+ */
36
41
  event ValueReceived(address indexed sender, uint256 indexed value);
37
42
 
38
- receive() external payable {
39
- emit ValueReceived(_msgSender(), msg.value);
43
+ /**
44
+ * @dev Emits an event when receiving native tokens
45
+ */
46
+ fallback() external payable {
47
+ if (msg.value > 0) emit ValueReceived(msg.sender, msg.value);
40
48
  }
41
49
 
42
50
  // TODO to be discussed
@@ -54,6 +62,42 @@ abstract contract LSP0ERC725AccountCore is
54
62
  // }
55
63
  // }
56
64
 
65
+ // ERC165
66
+
67
+ /**
68
+ * @dev See {IERC165-supportsInterface}.
69
+ */
70
+ function supportsInterface(bytes4 interfaceId)
71
+ public
72
+ view
73
+ virtual
74
+ override(ERC725XCore, ERC725YCore)
75
+ returns (bool)
76
+ {
77
+ return
78
+ interfaceId == _INTERFACEID_ERC1271 ||
79
+ interfaceId == _INTERFACEID_LSP0 ||
80
+ interfaceId == _INTERFACEID_LSP1 ||
81
+ interfaceId == _INTERFACEID_CLAIM_OWNERSHIP ||
82
+ super.supportsInterface(interfaceId);
83
+ }
84
+
85
+ // ERC173 - Modified ClaimOwnership
86
+
87
+ /**
88
+ * @dev Sets the pending owner
89
+ */
90
+ function transferOwnership(address _newOwner)
91
+ public
92
+ virtual
93
+ override(ClaimOwnership, OwnableUnset)
94
+ onlyOwner
95
+ {
96
+ ClaimOwnership._transferOwnership(_newOwner);
97
+ }
98
+
99
+ // ERC1271
100
+
57
101
  /**
58
102
  * @notice Checks if an owner signed `_data`.
59
103
  * ERC1271 interface.
@@ -68,52 +112,52 @@ abstract contract LSP0ERC725AccountCore is
68
112
  returns (bytes4 magicValue)
69
113
  {
70
114
  // prettier-ignore
115
+ address _owner = owner();
71
116
  // 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
117
+ if (_owner.code.length != 0) {
118
+ return
119
+ ERC165Checker.supportsERC165Interface(_owner, _INTERFACEID_ERC1271)
120
+ ? IERC1271(_owner).isValidSignature(_hash, _signature)
121
+ : _ERC1271_FAILVALUE;
122
+ // if OWNER is a key
78
123
  } else {
79
- return
80
- owner() == ECDSA.recover(_hash, _signature)
81
- ? _INTERFACE_ID_ERC1271
82
- : _ERC1271FAILVALUE;
124
+ return
125
+ _owner == ECDSA.recover(_hash, _signature)
126
+ ? _INTERFACEID_ERC1271
127
+ : _ERC1271_FAILVALUE;
83
128
  }
84
129
  }
85
130
 
131
+ // LSP1
132
+
133
+ /**
134
+ * @notice Triggers the UniversalReceiver event when this function gets executed successfully.
135
+ * @dev Forwards the call to the UniversalReceiverDelegate if set.
136
+ * @param _typeId The type of call received.
137
+ * @param _data The data received.
138
+ */
86
139
  function universalReceiver(bytes32 _typeId, bytes calldata _data)
87
140
  external
141
+ payable
88
142
  virtual
89
143
  override
90
144
  returns (bytes memory returnValue)
91
145
  {
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
- );
146
+ bytes memory data = _getData(_LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY);
147
+
148
+ if (data.length >= 20) {
149
+ address universalReceiverDelegate = address(bytes20(data));
103
150
 
104
151
  if (
105
- ERC165(universalReceiverAddress).supportsInterface(
152
+ ERC165Checker.supportsERC165Interface(
153
+ universalReceiverDelegate,
106
154
  _INTERFACEID_LSP1_DELEGATE
107
155
  )
108
156
  ) {
109
- returnValue = ILSP1UniversalReceiverDelegate(
110
- universalReceiverAddress
111
- ).universalReceiverDelegate(_msgSender(), _typeId, _data);
157
+ returnValue = ILSP1UniversalReceiverDelegate(universalReceiverDelegate)
158
+ .universalReceiverDelegate(msg.sender, msg.value, _typeId, _data);
112
159
  }
113
160
  }
114
-
115
- emit UniversalReceiver(_msgSender(), _typeId, returnValue, _data);
116
-
117
- return returnValue;
161
+ emit UniversalReceiver(msg.sender, msg.value, _typeId, returnValue, _data);
118
162
  }
119
163
  }
@@ -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,10 @@ import "./LSP0ERC725AccountInitAbstract.sol";
11
11
  */
12
12
  contract LSP0ERC725AccountInit is LSP0ERC725AccountInitAbstract {
13
13
  /**
14
- * @inheritdoc LSP0ERC725AccountInitAbstract
14
+ * @notice Sets the owner of the contract
15
+ * @param _newOwner the owner of the contract
15
16
  */
16
-
17
- function initialize(address _newOwner) public virtual override initializer {
18
- LSP0ERC725AccountInitAbstract.initialize(_newOwner);
17
+ function initialize(address _newOwner) public virtual initializer {
18
+ LSP0ERC725AccountInitAbstract._initialize(_newOwner);
19
19
  }
20
20
  }
@@ -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
- ERC725InitAbstract,
15
- LSP0ERC725AccountCore
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;