@lukso/lsp-smart-contracts 0.10.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.
- package/README.md +14 -0
- package/artifacts/LSP0ERC725Account.json +3 -3
- package/artifacts/LSP0ERC725AccountInit.json +3 -3
- package/artifacts/LSP16UniversalFactory.json +27 -21
- package/artifacts/UniversalProfile.json +3 -3
- package/artifacts/UniversalProfileInit.json +3 -3
- package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +10 -5
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +15 -5
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +11 -6
- package/contracts/LSP16UniversalFactory/LSP16UniversalFactory.sol +262 -115
- package/contracts/UniversalProfile.sol +10 -4
- package/contracts/UniversalProfileInit.sol +15 -5
- package/contracts/UniversalProfileInitAbstract.sol +5 -6
- package/devdocs/LSP0ERC725Account.json +2 -2
- package/devdocs/LSP0ERC725AccountInit.json +3 -3
- package/devdocs/LSP16UniversalFactory.json +87 -22
- package/devdocs/UniversalProfile.json +2 -1
- package/devdocs/UniversalProfileInit.json +3 -2
- package/dist/constants.cjs.js +168 -80
- package/dist/constants.d.ts +116 -38
- package/dist/constants.es.js +168 -80
- package/package.json +3 -2
- package/userdocs/LSP0ERC725Account.json +3 -0
- package/userdocs/LSP0ERC725AccountInit.json +6 -0
- package/userdocs/UniversalProfile.json +1 -1
- package/userdocs/UniversalProfileInit.json +4 -1
|
@@ -8,90 +8,96 @@ import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";
|
|
|
8
8
|
// errors
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* @dev
|
|
11
|
+
* @dev Reverts when there is no revert reason bubbled up by the contract created when initializing
|
|
12
12
|
*/
|
|
13
|
-
error
|
|
13
|
+
error ContractInitializationFailed();
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* @dev
|
|
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
|
|
19
|
+
error InvalidValueSum();
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
* @
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
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
|
-
*
|
|
29
|
-
*
|
|
30
|
-
|
|
31
|
-
*
|
|
32
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
38
|
-
*
|
|
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
|
|
47
|
-
*
|
|
48
|
-
* @param
|
|
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
|
-
|
|
75
|
+
bytes32 generatedSalt,
|
|
76
|
+
bool indexed initialized,
|
|
54
77
|
bytes initializeCalldata
|
|
55
78
|
);
|
|
56
79
|
|
|
57
80
|
/**
|
|
58
|
-
* @dev
|
|
59
|
-
*
|
|
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
|
|
91
|
-
* chains with the same parameters.
|
|
84
|
+
* This function deploys contracts without initialization (external call after deployment).
|
|
92
85
|
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
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
|
|
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
|
|
111
|
-
* can be known in advance via {
|
|
112
|
-
*
|
|
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
|
-
*
|
|
115
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
120
|
-
*
|
|
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
|
-
*
|
|
123
|
-
*
|
|
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
|
|
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
|
|
153
|
+
bytes32 generatedSalt = generateSalt(providedSalt, true, initializeCalldata);
|
|
136
154
|
address contractCreated = Create2.deploy(constructorMsgValue, generatedSalt, byteCode);
|
|
137
|
-
emit ContractCreated(
|
|
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
|
|
149
|
-
*
|
|
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
|
-
*
|
|
152
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
159
|
-
* the
|
|
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
|
|
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
|
|
198
|
+
bytes32 generatedSalt = generateSalt(providedSalt, false, _EMPTY_BYTE);
|
|
167
199
|
|
|
168
|
-
address proxy = Clones.cloneDeterministic(
|
|
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
|
|
176
|
-
*
|
|
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
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
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
|
-
*
|
|
183
|
-
*
|
|
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
|
-
*
|
|
186
|
-
* the clones cannot be deployed twice at the same address.
|
|
228
|
+
* @return The address of the minimal proxy deployed
|
|
187
229
|
*/
|
|
188
|
-
function
|
|
189
|
-
address
|
|
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
|
|
235
|
+
bytes32 generatedSalt = generateSalt(providedSalt, true, initializeCalldata);
|
|
194
236
|
|
|
195
|
-
address proxy = Clones.cloneDeterministic(
|
|
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
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
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
|
|
217
|
-
bytes32 providedSalt
|
|
364
|
+
bytes memory initializeCalldata
|
|
218
365
|
) public pure virtual returns (bytes32) {
|
|
219
366
|
if (initializable) {
|
|
220
|
-
return keccak256(abi.encodePacked(
|
|
367
|
+
return keccak256(abi.encodePacked(true, initializeCalldata, providedSalt));
|
|
221
368
|
} else {
|
|
222
|
-
return keccak256(abi.encodePacked(
|
|
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 `
|
|
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
|
|
389
|
+
revert ContractInitializationFailed();
|
|
243
390
|
}
|
|
244
391
|
}
|
|
245
392
|
}
|
|
@@ -17,11 +17,17 @@ import {
|
|
|
17
17
|
*/
|
|
18
18
|
contract UniversalProfile is LSP0ERC725Account {
|
|
19
19
|
/**
|
|
20
|
-
* @notice
|
|
21
|
-
* @
|
|
20
|
+
* @notice Deploying the contract with owner set to: `initialOwner`
|
|
21
|
+
* @dev Set `initialOwner` as the contract owner and set the `SupportedStandards:LSP3UniversalProfile` data key
|
|
22
|
+
* in the ERC725Y data key/value store. The `constructor` also allows funding the contract on deployment.
|
|
23
|
+
*
|
|
24
|
+
* Emitted Events:
|
|
25
|
+
* - ValueReceived: when the contract is funded on deployment.
|
|
26
|
+
*
|
|
27
|
+
* @param initialOwner the owner of the contract
|
|
22
28
|
*/
|
|
23
|
-
constructor(address
|
|
24
|
-
// set key SupportedStandards:LSP3UniversalProfile
|
|
29
|
+
constructor(address initialOwner) payable LSP0ERC725Account(initialOwner) {
|
|
30
|
+
// set data key SupportedStandards:LSP3UniversalProfile
|
|
25
31
|
_setData(_LSP3_SUPPORTED_STANDARDS_KEY, _LSP3_SUPPORTED_STANDARDS_VALUE);
|
|
26
32
|
}
|
|
27
33
|
}
|
|
@@ -11,17 +11,27 @@ import {UniversalProfileInitAbstract} from "./UniversalProfileInitAbstract.sol";
|
|
|
11
11
|
*/
|
|
12
12
|
contract UniversalProfileInit is UniversalProfileInitAbstract {
|
|
13
13
|
/**
|
|
14
|
-
* @
|
|
14
|
+
* @notice deploying a `UniversalProfileInit` base contract to be used behind proxy
|
|
15
|
+
* @dev Locks the base contract on deployment, so that it cannot be initialized, owned and controlled by anyone
|
|
16
|
+
* after it has been deployed. This is intended so that the sole purpose of this contract is to be used as a base
|
|
17
|
+
* contract behind a proxy.
|
|
15
18
|
*/
|
|
16
19
|
constructor() {
|
|
17
20
|
_disableInitializers();
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
/**
|
|
21
|
-
* @notice
|
|
22
|
-
* @
|
|
24
|
+
* @notice Initializing the contract owner to: `initialOwner`
|
|
25
|
+
* @dev Set `initialOwner` as the contract owner and set the `SupportedStandards:LSP3UniversalProfile` data key in the ERC725Y data key/value store.
|
|
26
|
+
* The `initialOwner` will then be allowed to call protected functions marked with the `onlyOwner` modifier.
|
|
27
|
+
* The `initialize(address)` function also allows funding the contract on initialization.
|
|
28
|
+
*
|
|
29
|
+
* Emitted Events:
|
|
30
|
+
* - ValueReceived: when the contract is funded on initialization.
|
|
31
|
+
*
|
|
32
|
+
* @param initialOwner the owner of the contract
|
|
23
33
|
*/
|
|
24
|
-
function initialize(address
|
|
25
|
-
UniversalProfileInitAbstract._initialize(
|
|
34
|
+
function initialize(address initialOwner) external payable virtual initializer {
|
|
35
|
+
UniversalProfileInitAbstract._initialize(initialOwner);
|
|
26
36
|
}
|
|
27
37
|
}
|
|
@@ -17,14 +17,13 @@ import {
|
|
|
17
17
|
*/
|
|
18
18
|
abstract contract UniversalProfileInitAbstract is LSP0ERC725AccountInitAbstract {
|
|
19
19
|
/**
|
|
20
|
-
* @
|
|
21
|
-
* @dev
|
|
22
|
-
* @param newOwner the owner of the contract
|
|
20
|
+
* @inheritdoc LSP0ERC725AccountInitAbstract
|
|
21
|
+
* @dev Set the `SupportedStandards:LSP3UniversalProfile` data key in the ERC725Y data key/value store.
|
|
23
22
|
*/
|
|
24
|
-
function _initialize(address
|
|
25
|
-
LSP0ERC725AccountInitAbstract._initialize(
|
|
23
|
+
function _initialize(address initialOwner) internal virtual override onlyInitializing {
|
|
24
|
+
LSP0ERC725AccountInitAbstract._initialize(initialOwner);
|
|
26
25
|
|
|
27
|
-
// set key SupportedStandards:LSP3UniversalProfile
|
|
26
|
+
// set data key SupportedStandards:LSP3UniversalProfile
|
|
28
27
|
_setData(_LSP3_SUPPORTED_STANDARDS_KEY, _LSP3_SUPPORTED_STANDARDS_VALUE);
|
|
29
28
|
}
|
|
30
29
|
}
|
|
@@ -103,9 +103,9 @@
|
|
|
103
103
|
}
|
|
104
104
|
},
|
|
105
105
|
"constructor": {
|
|
106
|
-
"details": "
|
|
106
|
+
"details": "Set `initialOwner` as the contract owner. The `constructor` also allows funding the contract on deployment. Emitted Events: - ValueReceived: when the contract is funded on deployment.",
|
|
107
107
|
"params": {
|
|
108
|
-
"
|
|
108
|
+
"initialOwner": "The owner of the contract"
|
|
109
109
|
}
|
|
110
110
|
},
|
|
111
111
|
"execute(uint256,address,uint256,bytes)": {
|
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
}
|
|
104
104
|
},
|
|
105
105
|
"constructor": {
|
|
106
|
-
"details": "
|
|
106
|
+
"details": "Locks the base contract on deployment, so that it cannot be initialized, owned and controlled by anyone after it has been deployed. This is intended so that the sole purpose of this contract is to be used as a base contract behind a proxy."
|
|
107
107
|
},
|
|
108
108
|
"execute(uint256,address,uint256,bytes)": {
|
|
109
109
|
"details": "Executes any call on other addresses.",
|
|
@@ -140,9 +140,9 @@
|
|
|
140
140
|
}
|
|
141
141
|
},
|
|
142
142
|
"initialize(address)": {
|
|
143
|
-
"details": "
|
|
143
|
+
"details": "Set `initialOwner` as the contract owner. The `initialOwner` will then be allowed to call protected functions marked with the `onlyOwner` modifier. The `initialize(address)` function also allows funding the contract on initialization. Emitted Events: - ValueReceived: when the contract is funded on initialization.",
|
|
144
144
|
"params": {
|
|
145
|
-
"
|
|
145
|
+
"initialOwner": "the owner of the contract"
|
|
146
146
|
}
|
|
147
147
|
},
|
|
148
148
|
"isValidSignature(bytes32,bytes)": {
|