@lukso/lsp-smart-contracts 0.9.0 → 0.10.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 (177) hide show
  1. package/README.md +29 -7
  2. package/artifacts/LSP0ERC725Account.json +63 -69
  3. package/artifacts/LSP0ERC725AccountInit.json +63 -69
  4. package/artifacts/LSP11BasicSocialRecovery.json +2 -2
  5. package/artifacts/LSP11BasicSocialRecoveryInit.json +2 -2
  6. package/artifacts/LSP16UniversalFactory.json +27 -21
  7. package/artifacts/LSP1UniversalReceiverDelegateUP.json +2 -2
  8. package/artifacts/LSP1UniversalReceiverDelegateVault.json +2 -2
  9. package/artifacts/LSP4Compatibility.json +32 -38
  10. package/artifacts/LSP4DigitalAssetMetadata.json +32 -38
  11. package/artifacts/LSP4DigitalAssetMetadataInitAbstract.json +32 -38
  12. package/artifacts/LSP6KeyManager.json +29 -15
  13. package/artifacts/LSP6KeyManagerInit.json +29 -15
  14. package/artifacts/LSP7CappedSupply.json +71 -36
  15. package/artifacts/LSP7CappedSupplyInitAbstract.json +71 -36
  16. package/artifacts/LSP7CompatibleERC20.json +71 -36
  17. package/artifacts/LSP7CompatibleERC20InitAbstract.json +71 -36
  18. package/artifacts/LSP7CompatibleERC20Mintable.json +73 -38
  19. package/artifacts/LSP7CompatibleERC20MintableInit.json +73 -38
  20. package/artifacts/LSP7DigitalAsset.json +71 -36
  21. package/artifacts/LSP7DigitalAssetInitAbstract.json +71 -36
  22. package/artifacts/LSP7Mintable.json +73 -38
  23. package/artifacts/LSP7MintableInit.json +73 -38
  24. package/artifacts/LSP8CappedSupply.json +32 -38
  25. package/artifacts/LSP8CappedSupplyInitAbstract.json +32 -38
  26. package/artifacts/LSP8CompatibleERC721.json +35 -41
  27. package/artifacts/LSP8CompatibleERC721InitAbstract.json +35 -41
  28. package/artifacts/LSP8CompatibleERC721Mintable.json +37 -43
  29. package/artifacts/LSP8CompatibleERC721MintableInit.json +37 -43
  30. package/artifacts/LSP8IdentifiableDigitalAsset.json +32 -38
  31. package/artifacts/LSP8IdentifiableDigitalAssetInitAbstract.json +32 -38
  32. package/artifacts/LSP8Mintable.json +34 -40
  33. package/artifacts/LSP8MintableInit.json +34 -40
  34. package/artifacts/LSP9Vault.json +61 -67
  35. package/artifacts/LSP9VaultInit.json +61 -67
  36. package/artifacts/UniversalProfile.json +63 -69
  37. package/artifacts/UniversalProfileInit.json +63 -69
  38. package/contracts/LSP0ERC725Account/ILSP0ERC725Account.sol +45 -10
  39. package/contracts/LSP0ERC725Account/LSP0Constants.sol +1 -1
  40. package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +43 -8
  41. package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +361 -124
  42. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +44 -8
  43. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +45 -6
  44. package/contracts/LSP0ERC725Account/LSP0Utils.sol +0 -1
  45. package/contracts/LSP10ReceivedVaults/LSP10Utils.sol +30 -15
  46. package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryCore.sol +0 -1
  47. package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryInit.sol +0 -1
  48. package/contracts/LSP14Ownable2Step/LSP14Ownable2Step.sol +5 -7
  49. package/contracts/LSP16UniversalFactory/LSP16UniversalFactory.sol +262 -115
  50. package/contracts/LSP17ContractExtension/LSP17Extendable.sol +10 -5
  51. package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiver.sol +0 -4
  52. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +91 -34
  53. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +27 -8
  54. package/contracts/LSP20CallVerification/LSP20CallVerification.sol +18 -9
  55. package/contracts/LSP20CallVerification/LSP20Constants.sol +17 -0
  56. package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +26 -12
  57. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +0 -1
  58. package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +32 -16
  59. package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +11 -2
  60. package/contracts/LSP6KeyManager/LSP6Constants.sol +5 -5
  61. package/contracts/LSP6KeyManager/LSP6Errors.sol +10 -6
  62. package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +140 -68
  63. package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +0 -1
  64. package/contracts/LSP6KeyManager/LSP6Modules/LSP6ExecuteModule.sol +30 -38
  65. package/contracts/LSP6KeyManager/LSP6Modules/LSP6SetDataModule.sol +153 -60
  66. package/contracts/LSP6KeyManager/LSP6Utils.sol +1 -5
  67. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +67 -13
  68. package/contracts/LSP7DigitalAsset/LSP7Errors.sol +5 -0
  69. package/contracts/LSP7DigitalAsset/extensions/LSP7Burnable.sol +2 -2
  70. package/contracts/LSP7DigitalAsset/extensions/LSP7BurnableInitAbstract.sol +24 -0
  71. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.sol +1 -2
  72. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +1 -2
  73. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20.sol +3 -5
  74. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20InitAbstract.sol +3 -5
  75. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +15 -12
  76. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CompatibleERC721.sol +1 -1
  77. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupply.sol +1 -2
  78. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +1 -2
  79. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol +5 -5
  80. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol +6 -6
  81. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Enumerable.sol +2 -2
  82. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8EnumerableInitAbstract.sol +2 -2
  83. package/contracts/LSP9Vault/ILSP9Vault.sol +9 -1
  84. package/contracts/LSP9Vault/LSP9Constants.sol +1 -1
  85. package/contracts/LSP9Vault/LSP9Vault.sol +0 -6
  86. package/contracts/LSP9Vault/LSP9VaultCore.sol +17 -15
  87. package/contracts/LSP9Vault/LSP9VaultInit.sol +2 -1
  88. package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +8 -5
  89. package/contracts/UniversalProfile.sol +10 -4
  90. package/contracts/UniversalProfileInit.sol +15 -5
  91. package/contracts/UniversalProfileInitAbstract.sol +7 -3
  92. package/devdocs/Create2Factory.json +16 -0
  93. package/devdocs/LSP0ERC725Account.json +200 -0
  94. package/devdocs/LSP0ERC725AccountInit.json +203 -0
  95. package/devdocs/LSP11BasicSocialRecovery.json +146 -0
  96. package/devdocs/LSP11BasicSocialRecoveryInit.json +146 -0
  97. package/devdocs/LSP16UniversalFactory.json +116 -0
  98. package/devdocs/LSP1UniversalReceiverDelegateUP.json +80 -0
  99. package/devdocs/LSP1UniversalReceiverDelegateVault.json +62 -0
  100. package/devdocs/LSP4Compatibility.json +79 -0
  101. package/devdocs/LSP4DigitalAssetMetadata.json +84 -0
  102. package/devdocs/LSP4DigitalAssetMetadataInitAbstract.json +77 -0
  103. package/devdocs/LSP6KeyManager.json +257 -0
  104. package/devdocs/LSP6KeyManagerInit.json +260 -0
  105. package/devdocs/LSP7CappedSupply.json +211 -0
  106. package/devdocs/LSP7CappedSupplyInitAbstract.json +206 -0
  107. package/devdocs/LSP7CompatibleERC20.json +225 -0
  108. package/devdocs/LSP7CompatibleERC20InitAbstract.json +218 -0
  109. package/devdocs/LSP7CompatibleERC20Mintable.json +217 -0
  110. package/devdocs/LSP7CompatibleERC20MintableInit.json +227 -0
  111. package/devdocs/LSP7DigitalAsset.json +210 -0
  112. package/devdocs/LSP7DigitalAssetInitAbstract.json +202 -0
  113. package/devdocs/LSP7Mintable.json +219 -0
  114. package/devdocs/LSP7MintableInit.json +220 -0
  115. package/devdocs/LSP8CappedSupply.json +232 -0
  116. package/devdocs/LSP8CappedSupplyInitAbstract.json +227 -0
  117. package/devdocs/LSP8CompatibleERC721.json +298 -0
  118. package/devdocs/LSP8CompatibleERC721InitAbstract.json +291 -0
  119. package/devdocs/LSP8CompatibleERC721Mintable.json +290 -0
  120. package/devdocs/LSP8CompatibleERC721MintableInit.json +300 -0
  121. package/devdocs/LSP8IdentifiableDigitalAsset.json +230 -0
  122. package/devdocs/LSP8IdentifiableDigitalAssetInitAbstract.json +223 -0
  123. package/devdocs/LSP8Mintable.json +242 -0
  124. package/devdocs/LSP8MintableInit.json +245 -0
  125. package/devdocs/LSP9Vault.json +171 -0
  126. package/devdocs/LSP9VaultInit.json +175 -0
  127. package/devdocs/UniversalProfile.json +200 -0
  128. package/devdocs/UniversalProfileInit.json +203 -0
  129. package/devdocs/UniversalReceiverAddressStore.json +9 -0
  130. package/dist/constants.cjs.js +31657 -0
  131. package/dist/constants.d.ts +31759 -0
  132. package/dist/constants.es.js +31638 -0
  133. package/package.json +71 -53
  134. package/userdocs/Create2Factory.json +5 -0
  135. package/userdocs/LSP0ERC725Account.json +50 -0
  136. package/userdocs/LSP0ERC725AccountInit.json +53 -0
  137. package/userdocs/LSP11BasicSocialRecovery.json +29 -0
  138. package/userdocs/LSP11BasicSocialRecoveryInit.json +29 -0
  139. package/userdocs/LSP16UniversalFactory.json +5 -0
  140. package/userdocs/LSP1UniversalReceiverDelegateUP.json +10 -0
  141. package/userdocs/LSP1UniversalReceiverDelegateVault.json +10 -0
  142. package/userdocs/LSP4Compatibility.json +20 -0
  143. package/userdocs/LSP4DigitalAssetMetadata.json +23 -0
  144. package/userdocs/LSP4DigitalAssetMetadataInitAbstract.json +20 -0
  145. package/userdocs/LSP6KeyManager.json +18 -0
  146. package/userdocs/LSP6KeyManagerInit.json +18 -0
  147. package/userdocs/LSP7CappedSupply.json +29 -0
  148. package/userdocs/LSP7CappedSupplyInitAbstract.json +26 -0
  149. package/userdocs/LSP7CompatibleERC20.json +35 -0
  150. package/userdocs/LSP7CompatibleERC20InitAbstract.json +32 -0
  151. package/userdocs/LSP7CompatibleERC20Mintable.json +32 -0
  152. package/userdocs/LSP7CompatibleERC20MintableInit.json +35 -0
  153. package/userdocs/LSP7DigitalAsset.json +29 -0
  154. package/userdocs/LSP7DigitalAssetInitAbstract.json +26 -0
  155. package/userdocs/LSP7Mintable.json +29 -0
  156. package/userdocs/LSP7MintableInit.json +29 -0
  157. package/userdocs/LSP8CappedSupply.json +23 -0
  158. package/userdocs/LSP8CappedSupplyInitAbstract.json +20 -0
  159. package/userdocs/LSP8CompatibleERC721.json +29 -0
  160. package/userdocs/LSP8CompatibleERC721InitAbstract.json +26 -0
  161. package/userdocs/LSP8CompatibleERC721Mintable.json +26 -0
  162. package/userdocs/LSP8CompatibleERC721MintableInit.json +29 -0
  163. package/userdocs/LSP8IdentifiableDigitalAsset.json +23 -0
  164. package/userdocs/LSP8IdentifiableDigitalAssetInitAbstract.json +20 -0
  165. package/userdocs/LSP8Mintable.json +23 -0
  166. package/userdocs/LSP8MintableInit.json +23 -0
  167. package/userdocs/LSP9Vault.json +38 -0
  168. package/userdocs/LSP9VaultInit.json +38 -0
  169. package/userdocs/UniversalProfile.json +50 -0
  170. package/userdocs/UniversalProfileInit.json +53 -0
  171. package/userdocs/UniversalReceiverAddressStore.json +5 -0
  172. package/CONTRIBUTING.md +0 -57
  173. package/common/constants.d.ts +0 -461
  174. package/common/constants.js +0 -789
  175. package/contracts/Utils/GasLib.sol +0 -17
  176. package/module/constants.d.ts +0 -461
  177. package/module/constants.js +0 -786
@@ -8,90 +8,96 @@ import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";
8
8
  // errors
9
9
 
10
10
  /**
11
- * @dev reverts with this error when there is no revert reason bubbled up by the target contract when initializing
11
+ * @dev Reverts when there is no revert reason bubbled up by the contract created when initializing
12
12
  */
13
- error CannotInitializeContract();
13
+ error ContractInitializationFailed();
14
14
 
15
15
  /**
16
- * @dev reverts when msg.value sent to {deployCreate2Init} function is not equal to the sum of the
16
+ * @dev Reverts when msg.value sent to {deployCreate2AndInitialize} function is not equal to the sum of the
17
17
  * `initializeCalldataMsgValue` and `constructorMsgValue`
18
18
  */
19
- error InvalidMsgValueDistribution();
19
+ error InvalidValueSum();
20
20
 
21
21
  /**
22
- * @dev UniversalFactory contract can be used to deploy normal or minimal proxy contracts (EIP-1167) using CREATE2.
23
- * This gives the ability to deploy the same contract at the same address on different chains.
24
- * If the contract has a constructor, the arguments will be part of the bytecode
25
- * If the contract has an `initialize` function, the parameters of this function will be included in
26
- * the salt to ensure that the parameters of the contract should be the same on each chain.
22
+ * @title LSP16 Universal Factory
23
+ * @dev Factory contract to deploy different types of contracts using the CREATE2 opcode
24
+ * standardized as LSP16 - UniversalFactory:
25
+ * https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-16-UniversalFactory.md
27
26
  *
28
- * When initializeCallData or the constructor includes non-crosschain parameters, the deployed contract
29
- * will not be recreated at the same address on another network, thus defeating the purpose of LSP16UniversalFactory.
30
-
31
- * Therefore, the initializeCallData and the constructor must not include any network-specific parameters,
32
- * such as a local non-crosschain token contract address, chain-id, etc ..
27
+ * The UniversalFactory will be deployed using Nick's Factory (0x4e59b44847b379578588920ca78fbf26c0b4956c)
28
+ *
29
+ * The deployed address can be found in the LSP16 specification.
30
+ * Please refer to the LSP16 Specification to obtain the exact bytecode and salt that
31
+ * should be used to produce the address of the UniversalFactory on different chains.
32
+ *
33
+ * This factory contract is designed to deploy contracts at the same address on multiple chains.
34
+ *
35
+ * The UniversalFactory can deploy 2 types of contracts:
36
+ * - non-initializable (normal deployment)
37
+ * - initializable (external call after deployment, e.g: proxy contracts)
38
+ *
39
+ * The `providedSalt` parameter given by the deployer is not used directly as the salt by the CREATE2 opcode.
40
+ * Instead, it is used along with these parameters:
41
+ * - `initializable` boolean
42
+ * - `initializeCalldata` (when the contract is initializable and `initializable` is set to `true`).
43
+ * These three parameters are concatenated together and hashed to generate the final salt for CREATE2.
33
44
  *
34
- * One way to solve this problem is to set an EOA owner in the initializeCallData/constructor
45
+ * See {generateSalt} function for more details.
46
+ *
47
+ * The constructor and `initializeCalldata` SHOULD NOT include any network-specific parameters (e.g: chain-id,
48
+ * a local token contract address), otherwise the deployed contract will not be recreated at the same address
49
+ * across different networks, thus defeating the purpose of the UniversalFactory.
50
+ *
51
+ * One way to solve this problem is to set an EOA owner in the `initializeCalldata`/constructor
35
52
  * that can later call functions that set these parameters as variables in the contract.
36
53
  *
37
- * This contract should be deployed using Nick's Method.
38
- * More information: https://weka.medium.com/how-to-send-ether-to-11-440-people-187e332566b7
54
+ * The UniversalFactory must be deployed at the same address on different chains to successfully deploy
55
+ * contracts at the same address across different chains.
39
56
  */
40
57
  contract LSP16UniversalFactory {
58
+ /**
59
+ * @dev placeholder for the `initializeCallData` param when the `initializable` boolean is set to `false`.
60
+ */
41
61
  bytes private constant _EMPTY_BYTE = "";
42
62
 
43
63
  /**
44
64
  * @dev Emitted whenever a contract is created
45
65
  * @param contractCreated The address of the contract created
46
- * @param providedSalt The bytes32 salt provided by the deployer
47
- * @param initializable The Boolean that specifies if the contract is a initializable or not
48
- * @param initializeCalldata The bytes provided as initializeCalldata
66
+ * @param providedSalt The salt provided by the deployer, which will be used to generate the final salt
67
+ * that will be used by the `CREATE2` opcode for contract deployment
68
+ * @param generatedSalt The salt used by the `CREATE2` opcode for contract deployment
69
+ * @param initialized The Boolean that specifies if the contract must be initialized or not
70
+ * @param initializeCalldata The bytes provided as initializeCalldata (Empty string when `initialized` is set to false)
49
71
  */
50
72
  event ContractCreated(
51
73
  address indexed contractCreated,
52
74
  bytes32 indexed providedSalt,
53
- bool indexed initializable,
75
+ bytes32 generatedSalt,
76
+ bool indexed initialized,
54
77
  bytes initializeCalldata
55
78
  );
56
79
 
57
80
  /**
58
- * @dev Returns the address where a contract will be stored if deployed via `CREATE2`. The address is
59
- * constructed using the parameters below. Any change in one of them will result in a new destination address.
60
- */
61
- function calculateAddress(
62
- bytes32 byteCodeHash,
63
- bytes32 providedSalt,
64
- bool initializable,
65
- bytes calldata initializeCallData
66
- ) public view virtual returns (address) {
67
- bytes32 generatedSalt = generateSalt(initializable, initializeCallData, providedSalt);
68
- return Create2.computeAddress(generatedSalt, byteCodeHash);
69
- }
70
-
71
- /**
72
- * @dev Returns the address of an EIP1167 proxy contract. The address is constructed using
73
- * the parameters below. Any change in one of them will result in a new destination address.
74
- */
75
- function calculateProxyAddress(
76
- address baseContract,
77
- bytes32 providedSalt,
78
- bool initializable,
79
- bytes calldata initializeCallData
80
- ) public view virtual returns (address) {
81
- bytes32 generatedSalt = generateSalt(initializable, initializeCallData, providedSalt);
82
- return Clones.predictDeterministicAddress(baseContract, generatedSalt);
83
- }
84
-
85
- /**
86
- * @dev Deploys a contract using `CREATE2`. The address where the contract will be deployed
87
- * can be known in advance via {calculateAddress}. The salt is a hash of the `providedSalt`
88
- * together with an empty byte, to prevent mimicing the `deployCreate2Init()` and other functions.
81
+ * @dev Deploys a contract using the CREATE2 opcode. The address where the contract will be deployed
82
+ * can be known in advance via the {computeAddress} function.
89
83
  *
90
- * This method allow users to have the same contracts at the same address across different
91
- * chains with the same parameters.
84
+ * This function deploys contracts without initialization (external call after deployment).
92
85
  *
93
- * Using the same `byteCode` and salt multiple time will revert, since
94
- * the contract cannot be deployed twice at the same address.
86
+ * The `providedSalt` parameter is not used directly as the salt by the CREATE2 opcode. Instead, it is hashed with
87
+ * keccak256: `keccak256(abi.encodePacked(false, providedSalt))`. See {generateSalt} function for more details.
88
+ *
89
+ * Using the same `byteCode` and `providedSalt` multiple times will revert, as the contract cannot be deployed
90
+ * twice at the same address.
91
+ *
92
+ * If the constructor of the contract to deploy is payable, value can be sent to this function to fund
93
+ * the created contract. However, sending value to this function while the constructor is not payable will
94
+ * result in a revert.
95
+ *
96
+ * @param byteCode The bytecode of the contract to be deployed
97
+ * @param providedSalt The salt provided by the deployer, which will be used to generate the final salt
98
+ * that will be used by the `CREATE2` opcode for contract deployment
99
+ *
100
+ * @return The address of the deployed contract
95
101
  */
96
102
  function deployCreate2(bytes calldata byteCode, bytes32 providedSalt)
97
103
  public
@@ -99,42 +105,60 @@ contract LSP16UniversalFactory {
99
105
  virtual
100
106
  returns (address)
101
107
  {
102
- bytes32 generatedSalt = generateSalt(false, _EMPTY_BYTE, providedSalt);
108
+ bytes32 generatedSalt = generateSalt(providedSalt, false, _EMPTY_BYTE);
103
109
  address contractCreated = Create2.deploy(msg.value, generatedSalt, byteCode);
104
- emit ContractCreated(contractCreated, providedSalt, false, _EMPTY_BYTE);
110
+ emit ContractCreated(contractCreated, providedSalt, generatedSalt, false, _EMPTY_BYTE);
105
111
 
106
112
  return contractCreated;
107
113
  }
108
114
 
109
115
  /**
110
- * @dev Deploys a contract using `CREATE2`. The address where the contract will be deployed
111
- * can be known in advance via {calculateAddress}. The salt is a hash of the `providedSalt` and
112
- * and the `initializeCallData`.
116
+ * @dev Deploys a contract using the CREATE2 opcode. The address where the contract will be deployed
117
+ * can be known in advance via the {computeAddress} function.
118
+ *
119
+ * This function deploys contracts with initialization (external call after deployment).
113
120
  *
114
- * This method allow users
115
- * to have the same contracts at the same address across different chains with the same parameters.
121
+ * The `providedSalt` parameter is not used directly as the salt by the CREATE2 opcode. Instead, it is hashed with
122
+ * keccak256: `keccak256(abi.encodePacked(true, initializeCalldata, providedSalt))`.
123
+ * See {generateSalt} function for more details.
116
124
  *
117
- * The msg.value is split according to the parameters of the function
125
+ * Using the same `byteCode`, `providedSalt` and `initializeCalldata` multiple times will revert, as the
126
+ * contract cannot be deployed twice at the same address.
118
127
  *
119
- * The msg.value sent to this contract MUST be the sum of the two parameters: `constructorMsgValue`
120
- * and `initializeCalldataMsgValue`
128
+ * If the constructor or the initialize function of the contract to deploy is payable, value can be sent along
129
+ * with the deployment/initialization to fund the created contract. However, sending value to this function while
130
+ * the constructor/initialize function is not payable will result in a revert.
121
131
  *
122
- * Using the same `byteCode` and salt multiple time will revert, since
123
- * the contract cannot be deployed twice at the same address.
132
+ * Will revert if the `msg.value` sent to the function is not equal to the sum of `constructorMsgValue` and
133
+ * `initializeCalldataMsgValue`.
134
+ *
135
+ * @param byteCode The bytecode of the contract to be deployed
136
+ * @param providedSalt The salt provided by the deployer, which will be used to generate the final salt
137
+ * that will be used by the `CREATE2` opcode for contract deployment
138
+ * @param initializeCalldata The calldata to be executed on the created contract
139
+ * @param constructorMsgValue The value sent to the contract during deployment
140
+ * @param initializeCalldataMsgValue The value sent to the contract during initialization
141
+ *
142
+ * @return The address of the deployed contract
124
143
  */
125
- function deployCreate2Init(
144
+ function deployCreate2AndInitialize(
126
145
  bytes calldata byteCode,
127
146
  bytes32 providedSalt,
128
147
  bytes calldata initializeCalldata,
129
148
  uint256 constructorMsgValue,
130
149
  uint256 initializeCalldataMsgValue
131
150
  ) public payable virtual returns (address) {
132
- if (constructorMsgValue + initializeCalldataMsgValue != msg.value)
133
- revert InvalidMsgValueDistribution();
151
+ if (constructorMsgValue + initializeCalldataMsgValue != msg.value) revert InvalidValueSum();
134
152
 
135
- bytes32 generatedSalt = generateSalt(true, initializeCalldata, providedSalt);
153
+ bytes32 generatedSalt = generateSalt(providedSalt, true, initializeCalldata);
136
154
  address contractCreated = Create2.deploy(constructorMsgValue, generatedSalt, byteCode);
137
- emit ContractCreated(contractCreated, providedSalt, true, initializeCalldata);
155
+ emit ContractCreated(
156
+ contractCreated,
157
+ providedSalt,
158
+ generatedSalt,
159
+ true,
160
+ initializeCalldata
161
+ );
138
162
 
139
163
  (bool success, bytes memory returndata) = contractCreated.call{
140
164
  value: initializeCalldataMsgValue
@@ -145,55 +169,73 @@ contract LSP16UniversalFactory {
145
169
  }
146
170
 
147
171
  /**
148
- * @dev Deploys and returns the address of a clone that mimics the behaviour of `baseContract`.
149
- * The address where the contract will be deployed can be known in advance via {calculateProxyAddress}.
172
+ * @dev Deploys an ERC1167 minimal proxy contract using the CREATE2 opcode. The address where the contract will be deployed
173
+ * can be known in advance via the {computeERC1167Address} function.
174
+ *
175
+ * This function deploys contracts without initialization (external call after deployment).
176
+ *
177
+ * The `providedSalt` parameter is not used directly as the salt by the CREATE2 opcode. Instead, it is hashed with
178
+ * keccak256: `keccak256(abi.encodePacked(false, providedSalt))`. See {generateSalt} function for more details.
179
+ *
180
+ * See {generateSalt} function for more details.
150
181
  *
151
- * This function uses the CREATE2 opcode and a salt to deterministically deploy
152
- * the clone. The salt is a hash of the `providedSalt`
153
- * toegther with an empty byte, to prevent mimicing the `deployCreate2ProxyInit()` and other functions.
182
+ * Using the same `implementationContract` and `providedSalt` multiple times will revert, as the contract cannot be deployed
183
+ * twice at the same address.
154
184
  *
155
- * This method allow users to have the same contracts at the same address across different
156
- * chains with the same parameters.
185
+ * Sending value to the contract created is not possible since the constructor of the ERC1167 minimal proxy is not payable.
157
186
  *
158
- * Using the same `baseContract` and salt multiple time will revert, since
159
- * the clones cannot be deployed twice at the same address.
187
+ * @param implementationContract The contract address to use as the base implementation behind the proxy that will be deployed
188
+ * @param providedSalt The salt provided by the deployer, which will be used to generate the final salt
189
+ * that will be used by the `CREATE2` opcode for contract deployment
190
+ *
191
+ * @return The address of the minimal proxy deployed
160
192
  */
161
- function deployCreate2Proxy(address baseContract, bytes32 providedSalt)
193
+ function deployERC1167Proxy(address implementationContract, bytes32 providedSalt)
162
194
  public
163
195
  virtual
164
196
  returns (address)
165
197
  {
166
- bytes32 generatedSalt = generateSalt(false, _EMPTY_BYTE, providedSalt);
198
+ bytes32 generatedSalt = generateSalt(providedSalt, false, _EMPTY_BYTE);
167
199
 
168
- address proxy = Clones.cloneDeterministic(baseContract, generatedSalt);
169
- emit ContractCreated(proxy, providedSalt, false, _EMPTY_BYTE);
200
+ address proxy = Clones.cloneDeterministic(implementationContract, generatedSalt);
201
+ emit ContractCreated(proxy, providedSalt, generatedSalt, false, _EMPTY_BYTE);
170
202
 
171
203
  return proxy;
172
204
  }
173
205
 
174
206
  /**
175
- * @dev Deploys and returns the address of a clone that mimics the behaviour of `baseContract`.
176
- * The address where the contract will be deployed can be known in advance via {calculateProxyAddress}.
207
+ * @dev Deploys an ERC1167 minimal proxy contract using the CREATE2 opcode. The address where the contract will be deployed
208
+ * can be known in advance via the {computeERC1167Address} function.
209
+ *
210
+ * This function deploys contracts with initialization (external call after deployment).
211
+ *
212
+ * The `providedSalt` parameter is not used directly as the salt by the CREATE2 opcode. Instead, it is hashed with
213
+ * keccak256: `keccak256(abi.encodePacked(true, initializeCalldata, providedSalt))`.
214
+ * See {generateSalt} function for more details.
215
+ *
216
+ * Using the same `implementationContract`, `providedSalt` and `initializeCalldata` multiple times will revert, as the
217
+ * contract cannot be deployed twice at the same address.
177
218
  *
178
- * This function uses the CREATE2 opcode and a salt to deterministically deploy
179
- * the clone. The salt is a hash of the `providedSalt` and
180
- * and the `initializeCallData`.
219
+ * If the initialize function of the contract to deploy is payable, value can be sent along to fund the created
220
+ * contract while initializing. However, sending value to this function while the initialize function is not
221
+ * payable will result in a revert.
181
222
  *
182
- * This method allow users to have the same contracts at the same address
183
- * across different chains with the same parameters.
223
+ * @param implementationContract The contract address to use as the base implementation behind the proxy that will be deployed
224
+ * @param providedSalt The salt provided by the deployer, which will be used to generate the final salt
225
+ * that will be used by the `CREATE2` opcode for contract deployment
226
+ * @param initializeCalldata The calldata to be executed on the created contract
184
227
  *
185
- * Using the same `baseContract` and salt multiple time will revert, since
186
- * the clones cannot be deployed twice at the same address.
228
+ * @return The address of the minimal proxy deployed
187
229
  */
188
- function deployCreate2ProxyInit(
189
- address baseContract,
230
+ function deployERC1167ProxyAndInitialize(
231
+ address implementationContract,
190
232
  bytes32 providedSalt,
191
233
  bytes calldata initializeCalldata
192
234
  ) public payable virtual returns (address) {
193
- bytes32 generatedSalt = generateSalt(true, initializeCalldata, providedSalt);
235
+ bytes32 generatedSalt = generateSalt(providedSalt, true, initializeCalldata);
194
236
 
195
- address proxy = Clones.cloneDeterministic(baseContract, generatedSalt);
196
- emit ContractCreated(proxy, providedSalt, true, initializeCalldata);
237
+ address proxy = Clones.cloneDeterministic(implementationContract, generatedSalt);
238
+ emit ContractCreated(proxy, providedSalt, generatedSalt, true, initializeCalldata);
197
239
 
198
240
  (bool success, bytes memory returndata) = proxy.call{value: msg.value}(initializeCalldata);
199
241
  _verifyCallResult(success, returndata);
@@ -202,30 +244,135 @@ contract LSP16UniversalFactory {
202
244
  }
203
245
 
204
246
  /**
205
- * @dev Calculates the salt used to deploy the contract by hashing (Keccak256) the following parameters
206
- * as packed encoded respectively: an initializable boolean, the initializeCallData if and only if
207
- * the contract is initializable, and the salt provided by the deployer.
208
- *
209
- * The initializable boolean was added before the provided arguments as if it was not used,
210
- * and we are deploying proxies on another chain, people can use the `deployCreate2(..)` function
211
- * to deploy the same bytecode + the same salt to get the same address of the contract on
212
- * another chain without applying the effect of initializing.
247
+ * @dev Computes the address of a contract to be deployed using CREATE2, based on the input parameters.
248
+ * Any change in one of these parameters will result in a different address. When the `initializable`
249
+ * boolean is set to `false`, `initializeCalldata` will not affect the function output.
250
+ *
251
+ * @param byteCodeHash The keccak256 hash of the bytecode to be deployed
252
+ * @param providedSalt The salt provided by the deployer, which will be used to generate the final salt
253
+ * that will be used by the `CREATE2` opcode for contract deployment
254
+ * @param initializable A boolean that indicates whether an external call should be made to initialize the
255
+ * contract after deployment
256
+ * @param initializeCalldata The calldata to be executed on the created contract if `initializable` is set to `true`
257
+ *
258
+ * @return The address where the contract will be deployed
259
+ */
260
+ function computeAddress(
261
+ bytes32 byteCodeHash,
262
+ bytes32 providedSalt,
263
+ bool initializable,
264
+ bytes calldata initializeCalldata
265
+ ) public view virtual returns (address) {
266
+ bytes32 generatedSalt = generateSalt(providedSalt, initializable, initializeCalldata);
267
+ return Create2.computeAddress(generatedSalt, byteCodeHash);
268
+ }
269
+
270
+ /**
271
+ * @dev Computes the address of an ERC1167 proxy contract based on the input parameters.
272
+ * Any change in one of these parameters will result in a different address. When the `initializable`
273
+ * boolean is set to `false`, `initializeCalldata` will not affect the function output.
274
+ *
275
+ * @param implementationContract The contract to create a clone of according to ERC1167
276
+ * @param providedSalt The salt provided by the deployer, which will be used to generate the final salt
277
+ * that will be used by the `CREATE2` opcode for contract deployment
278
+ * @param initializable A boolean that indicates whether an external call should be made to initialize the
279
+ * proxy contract after deployment
280
+ * @param initializeCalldata The calldata to be executed on the created contract if `initializable` is set to `true`
281
+ *
282
+ * @return The address where the ERC1167 proxy contract will be deployed
283
+ */
284
+ function computeERC1167Address(
285
+ address implementationContract,
286
+ bytes32 providedSalt,
287
+ bool initializable,
288
+ bytes calldata initializeCalldata
289
+ ) public view virtual returns (address) {
290
+ bytes32 generatedSalt = generateSalt(providedSalt, initializable, initializeCalldata);
291
+ return Clones.predictDeterministicAddress(implementationContract, generatedSalt);
292
+ }
293
+
294
+ /**
295
+ * @dev Generates the salt used to deploy the contract by hashing the following parameters (concatenated
296
+ * together) with keccak256:
297
+ *
298
+ * - the `providedSalt`
299
+ * - the `initializable` boolean
300
+ * - the `initializeCalldata`, only if the contract is initializable (the `initializable` boolean is set to `true`)
301
+ *
302
+ * The `providedSalt` parameter is not used directly as the salt by the CREATE2 opcode. Instead, it is
303
+ * used along with these parameters:
304
+ * - `initializable` boolean
305
+ * - `initializeCalldata` (when the contract is initializable and `initializable` is set to `true`).
306
+ * These three parameters are concatenated together and hashed to generate the final salt for CREATE2.
307
+ *
308
+ * This approach ensures that in order to reproduce an initializable contract at the same address on another chain,
309
+ * not only the `providedSalt` is required to be the same, but also the initialize parameters within the `initializeCalldata`
310
+ * must also be the same.
311
+ *
312
+ * This maintains consistent deployment behaviour. Users are required to initialize contracts with the same parameters across
313
+ * different chains to ensure contracts are deployed at the same address across different chains.
314
+ *
315
+ * -----------
316
+ * Example (for initializable contracts)
317
+ *
318
+ * For an existing contract A on chain 1 owned by X, to replicate the same contract at the same address with
319
+ * the same owner X on chain 2, the salt used to generate the address should include the initializeCalldata
320
+ * that assigns X as the owner of contract A.
321
+ *
322
+ * For instance, if another user, Y, tries to deploy the contract at the same address
323
+ * on chain 2 using the same providedSalt, but with a different initializeCalldata to make Y the owner instead of X,
324
+ * the generated address would be different, preventing Y from deploying the contract with different ownership
325
+ * at the same address.
326
+ * -----------
327
+ *
328
+ * However, for non-initializable contracts, if the constructor has arguments that specify the deployment behavior, they
329
+ * will be included in the bytecode. Any change in the constructor arguments will lead to a different contract's bytecode
330
+ * which will result in a different address on other chains.
331
+ *
332
+ * -----------
333
+ * Example (for non-initializable contracts)
334
+ *
335
+ * If a contract is deployed with specific constructor arguments on chain 1, these arguments are embedded within the bytecode.
336
+ * For instance, if contract B is deployed with a specific `tokenName` and `tokenSymbol` on chain 1, and a user wants to deploy
337
+ * the same contract with the same `tokenName` and `tokenSymbol` on chain 2, they must use the same constructor arguments to
338
+ * produce the same bytecode. This ensures that the same deployment behaviour is maintained across different chains,
339
+ * as long as the same bytecode is used.
340
+ *
341
+ * If another user Z, tries to deploy the same contract B at the same address on chain 2 using the same `providedSalt`
342
+ * but different constructor arguments (a different `tokenName` and/or `tokenSymbol`), the generated address will be different.
343
+ * This prevents user Z from deploying the contract with different constructor arguments at the same address on chain 2.
344
+ * -----------
345
+ *
346
+ * The providedSalt was hashed to produce the salt used by CREATE2 opcode to prevent users from deploying initializable contracts
347
+ * using non-initializable functions such as {deployCreate2} without having the initialization call.
348
+ *
349
+ * In other words, if the providedSalt was not hashed and was used as it is as the salt by the CREATE2 opcode, malicious users
350
+ * can check the generated salt used for the already deployed initializable contract on chain 1, and deploy the contract
351
+ * from {deployCreate2} function on chain 2, with passing the generated salt of the deployed contract as providedSalt
352
+ * that will produce the same address but without the initialization, where the malicious user can initialize after.
353
+ *
354
+ * @param initializable The Boolean that specifies if the contract must be initialized or not
355
+ * @param initializeCalldata The calldata to be executed on the created contract if `initializable` is set to `true`
356
+ * @param providedSalt The salt provided by the deployer, which will be used to generate the final salt
357
+ * that will be used by the `CREATE2` opcode for contract deployment
358
+ *
359
+ * @return The generated salt which will be used for CREATE2 deployment
213
360
  */
214
361
  function generateSalt(
362
+ bytes32 providedSalt,
215
363
  bool initializable,
216
- bytes memory initializeCallData,
217
- bytes32 providedSalt
364
+ bytes memory initializeCalldata
218
365
  ) public pure virtual returns (bytes32) {
219
366
  if (initializable) {
220
- return keccak256(abi.encodePacked(initializable, initializeCallData, providedSalt));
367
+ return keccak256(abi.encodePacked(true, initializeCalldata, providedSalt));
221
368
  } else {
222
- return keccak256(abi.encodePacked(initializable, providedSalt));
369
+ return keccak256(abi.encodePacked(false, providedSalt));
223
370
  }
224
371
  }
225
372
 
226
373
  /**
227
- * @dev Verifies that the contract created was initialized correctly
228
- * Bubble the revert reason if present, revert with `CannotInitializeContract` otherwise
374
+ * @dev Verifies that the contract created was initialized correctly.
375
+ * Bubble the revert reason if present, revert with `ContractInitializationFailed` otherwise.
229
376
  */
230
377
  function _verifyCallResult(bool success, bytes memory returndata) internal pure virtual {
231
378
  if (!success) {
@@ -239,7 +386,7 @@ contract LSP16UniversalFactory {
239
386
  revert(add(32, returndata), returndata_size)
240
387
  }
241
388
  } else {
242
- revert CannotInitializeContract();
389
+ revert ContractInitializationFailed();
243
390
  }
244
391
  }
245
392
  }
@@ -54,13 +54,18 @@ abstract contract LSP17Extendable is ERC165 {
54
54
  function _getExtension(bytes4 functionSelector) internal view virtual returns (address);
55
55
 
56
56
  /**
57
- * @dev Forwards the call to an extension mapped to a function selector. If no extension address
58
- * is mapped to the function selector (address(0)), then revert.
57
+ * @dev Forwards the call to an extension mapped to a function selector.
59
58
  *
60
- * The call to the extension is appended with bytes20 (msg.sender) and bytes32 (msg.value).
61
- * Returns the return value on success and revert in case of failure.
59
+ * Calls {_getExtension} to get the address of the extension mapped to the function selector being
60
+ * called on the account. If there is no extension, the address(0) will be returned.
62
61
  *
63
- * As the function uses assembly {return()/revert()} to terminate the call, it cannot be
62
+ * Reverts if there is no extension for the function being called.
63
+ *
64
+ * If there is an extension for the function selector being called, it calls the extension with the
65
+ * CALL opcode, passing the {msg.data} appended with the 20 bytes of the {msg.sender} and
66
+ * 32 bytes of the {msg.value}
67
+ *
68
+ * Because the function uses assembly {return()/revert()} to terminate the call, it cannot be
64
69
  * called before other codes in fallback().
65
70
  *
66
71
  * Otherwise, the codes after _fallbackLSP17Extendable() may never be reached.
@@ -27,10 +27,6 @@ interface ILSP1UniversalReceiver {
27
27
  * @param data The arbitrary data received with the call
28
28
  * @dev Emits an event when it's succesfully executed
29
29
  *
30
- * Call the universalReceiverDelegate function in the UniversalReceiverDelegate (URD) contract, if the address of the URD
31
- * was set as a value for the `_UniversalReceiverKey` in the account key/value value store of the same contract implementing
32
- * the universalReceiver function and if the URD contract has the LSP1UniversalReceiverDelegate Interface Id registred using ERC165
33
- *
34
30
  * Emits a {UniversalReceiver} event
35
31
  */
36
32
  function universalReceiver(bytes32 typeId, bytes calldata data)