@lukso/lsp-smart-contracts 0.10.3 → 0.11.0-rc.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 (40) hide show
  1. package/CONTRIBUTING.md +184 -0
  2. package/artifacts/LSP0ERC725Account.json +2 -2
  3. package/artifacts/LSP0ERC725AccountInit.json +2 -2
  4. package/artifacts/LSP6KeyManager.json +2 -2
  5. package/artifacts/LSP6KeyManagerInit.json +2 -2
  6. package/artifacts/LSP7CompatibleERC20Mintable.json +2 -2
  7. package/artifacts/LSP7CompatibleERC20MintableInit.json +2 -2
  8. package/artifacts/LSP8CompatibleERC721Mintable.json +2 -2
  9. package/artifacts/LSP8CompatibleERC721MintableInit.json +2 -2
  10. package/artifacts/LSP9Vault.json +2 -2
  11. package/artifacts/LSP9VaultInit.json +2 -2
  12. package/artifacts/LinkedContractsFactory.json +544 -0
  13. package/artifacts/UniversalProfile.json +2 -2
  14. package/artifacts/UniversalProfileInit.json +2 -2
  15. package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +1 -1
  16. package/contracts/LSP20CallVerification/LSP20CallVerification.sol +6 -3
  17. package/contracts/LSP23LinkedContractsDeployment/ILinkedContractsFactory.sol +174 -0
  18. package/contracts/LSP23LinkedContractsDeployment/IPostDeploymentModule.sol +10 -0
  19. package/contracts/LSP23LinkedContractsDeployment/LSP23Errors.sol +24 -0
  20. package/contracts/LSP23LinkedContractsDeployment/LinkedContractsFactory.sol +384 -0
  21. package/contracts/LSP23LinkedContractsDeployment/modules/UniversalProfileInitPostDeploymentModule.sol +59 -0
  22. package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +5 -5
  23. package/contracts/LSP6KeyManager/LSP6Modules/LSP6ExecuteModule.sol +4 -4
  24. package/contracts/LSP6KeyManager/LSP6Modules/LSP6SetDataModule.sol +1 -1
  25. package/contracts/LSP7DigitalAsset/extensions/LSP7Burnable.sol +5 -1
  26. package/contracts/LSP7DigitalAsset/extensions/LSP7BurnableInitAbstract.sol +5 -1
  27. package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20Mintable.sol +1 -1
  28. package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInitAbstract.sol +1 -1
  29. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Burnable.sol +1 -1
  30. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol +23 -23
  31. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol +23 -23
  32. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721Mintable.sol +1 -1
  33. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInitAbstract.sol +1 -1
  34. package/contracts/LSP9Vault/LSP9VaultCore.sol +7 -2
  35. package/devdocs/LinkedContractsFactory.json +81 -0
  36. package/dist/constants.cjs.js +602 -0
  37. package/dist/constants.d.ts +338 -0
  38. package/dist/constants.es.js +602 -0
  39. package/package.json +2 -1
  40. package/userdocs/LinkedContractsFactory.json +29 -0
@@ -0,0 +1,174 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.4;
3
+
4
+ interface ILinkedContractsFactory {
5
+ event DeployedContracts(
6
+ address indexed primaryContract,
7
+ address indexed secondaryContract,
8
+ PrimaryContractDeployment primaryContractDeployment,
9
+ SecondaryContractDeployment secondaryContractDeployment,
10
+ address postDeploymentModule,
11
+ bytes postDeploymentModuleCalldata
12
+ );
13
+
14
+ event DeployedERC1167Proxies(
15
+ address indexed primaryContract,
16
+ address indexed secondaryContract,
17
+ PrimaryContractDeploymentInit primaryContractDeploymentInit,
18
+ SecondaryContractDeploymentInit secondaryContractDeploymentInit,
19
+ address postDeploymentModule,
20
+ bytes postDeploymentModuleCalldata
21
+ );
22
+
23
+ /**
24
+ * @param salt A unique value used to ensure each created proxies are unique. (Can be used to deploy the contract at a desired address.)
25
+ * @param fundingAmount The value to be sent with the deployment transaction.
26
+ * @param creationBytecode The bytecode of the contract with the constructor params.
27
+ */
28
+ struct PrimaryContractDeployment {
29
+ bytes32 salt;
30
+ uint256 fundingAmount;
31
+ bytes creationBytecode;
32
+ }
33
+
34
+ /**
35
+ * @param fundingAmount The value to be sent with the deployment transaction.
36
+ * @param creationBytecode The constructor + runtime bytecode (without the primary contract's address as param)
37
+ * @param addPrimaryContractAddress If set to `true`, this will append the primary contract's address + the `extraConstructorParams` to the `creationBytecode`.
38
+ * @param extraConstructorParams Params to be appended to the `creationBytecode` (after the primary contract address) if `addPrimaryContractAddress` is set to `true`.
39
+ */
40
+ struct SecondaryContractDeployment {
41
+ uint256 fundingAmount;
42
+ bytes creationBytecode;
43
+ bool addPrimaryContractAddress;
44
+ bytes extraConstructorParams;
45
+ }
46
+
47
+ /**
48
+ * @param salt A unique value used to ensure each created proxies are unique. (Can be used to deploy the contract at a desired address.)
49
+ * @param fundingAmount The value to be sent with the deployment transaction.
50
+ * @param implementationContract The address of the contract that will be used as a base contract for the proxy.
51
+ * @param initializationCalldata The calldata used to initialise the contract. (initialization should be similar to a constructor in a normal contract.)
52
+ */
53
+ struct PrimaryContractDeploymentInit {
54
+ bytes32 salt;
55
+ uint256 fundingAmount;
56
+ address implementationContract;
57
+ bytes initializationCalldata;
58
+ }
59
+
60
+ /**
61
+ * @param fundingAmount The value to be sent with the deployment transaction.
62
+ * @param implementationContract The address of the contract that will be used as a base contract for the proxy.
63
+ * @param initializationCalldata The first part of the initialisation calldata, everything before the primary contract address.
64
+ * @param addPrimaryContractAddress If set to `true`, this will append the primary contract's address + the `extraInitializationParams` to the `initializationCalldata`.
65
+ * @param extraInitializationParams Params to be appended to the `initializationCalldata` (after the primary contract address) if `addPrimaryContractAddress` is set to `true`
66
+ */
67
+ struct SecondaryContractDeploymentInit {
68
+ uint256 fundingAmount;
69
+ address implementationContract;
70
+ bytes initializationCalldata;
71
+ bool addPrimaryContractAddress;
72
+ bytes extraInitializationParams;
73
+ }
74
+
75
+ /**
76
+ * @dev Deploys a primary and a secondary linked contract.
77
+ * @notice Contracts deployed. Contract Address: `primaryContractAddress`. Primary Contract Address: `primaryContractAddress`
78
+ *
79
+ * @param primaryContractDeployment Contains the needed parameter to deploy a contract. (`salt`, `fundingAmount`, `creationBytecode`)
80
+ * @param secondaryContractDeployment Contains the needed parameter to deploy the secondary contract. (`fundingAmount`, `creationBytecode`, `addPrimaryContractAddress`, `extraConstructorParams`)
81
+ * @param postDeploymentModule The module to be executed after deployment
82
+ * @param postDeploymentModuleCalldata The data to be passed to the post deployment module
83
+ *
84
+ * @return primaryContractAddress The address of the primary contract.
85
+ * @return secondaryContractAddress The address of the secondary contract.
86
+ */
87
+ function deployContracts(
88
+ PrimaryContractDeployment calldata primaryContractDeployment,
89
+ SecondaryContractDeployment calldata secondaryContractDeployment,
90
+ address postDeploymentModule,
91
+ bytes calldata postDeploymentModuleCalldata
92
+ )
93
+ external
94
+ payable
95
+ returns (
96
+ address primaryContractAddress,
97
+ address secondaryContractAddress
98
+ );
99
+
100
+ /**
101
+ * @dev Deploys proxies of a primary contract and a secondary linked contract
102
+ * @notice Contract proxies deployed. Primary Proxy Address: `primaryContractAddress`. Secondary Contract Proxy Address: `secondaryContractAddress`
103
+ *
104
+ * @param primaryContractDeploymentInit Contains the needed parameters to deploy a proxy contract. (`salt`, `fundingAmount`, `implementationContract`, `initializationCalldata`)
105
+ * @param secondaryContractDeploymentInit Contains the needed parameters to deploy the secondary proxy contract. (`fundingAmount`, `implementationContract`, `addPrimaryContractAddress`, `initializationCalldata`, `extraInitializationParams`)
106
+ * @param postDeploymentModule The module to be executed after deployment.
107
+ * @param postDeploymentModuleCalldata The data to be passed to the post deployment module.
108
+ *
109
+ * @return primaryContractAddress The address of the deployed primary contract proxy
110
+ * @return secondaryContractAddress The address of the deployed secondary contract proxy
111
+ */
112
+ function deployERC1167Proxies(
113
+ PrimaryContractDeploymentInit calldata primaryContractDeploymentInit,
114
+ SecondaryContractDeploymentInit
115
+ calldata secondaryContractDeploymentInit,
116
+ address postDeploymentModule,
117
+ bytes calldata postDeploymentModuleCalldata
118
+ )
119
+ external
120
+ payable
121
+ returns (
122
+ address primaryContractAddress,
123
+ address secondaryContractAddress
124
+ );
125
+
126
+ /**
127
+ * @dev Computes the addresses of a primary contract and a secondary linked contract
128
+ *
129
+ * @param primaryContractDeployment Contains the needed parameter to deploy the primary contract. (`salt`, `fundingAmount`, `creationBytecode`)
130
+ * @param secondaryContractDeployment Contains the needed parameter to deploy the secondary contract. (`fundingAmount`, `creationBytecode`, `addPrimaryContractAddress`, `extraConstructorParams`)
131
+ * @param postDeploymentModule The module to be executed after deployment
132
+ * @param postDeploymentModuleCalldata The data to be passed to the post deployment module
133
+ *
134
+ * @return primaryContractAddress The address of the deployed primary contract.
135
+ * @return secondaryContractAddress The address of the deployed secondary contract.
136
+ */
137
+ function computeAddresses(
138
+ PrimaryContractDeployment calldata primaryContractDeployment,
139
+ SecondaryContractDeployment calldata secondaryContractDeployment,
140
+ address postDeploymentModule,
141
+ bytes calldata postDeploymentModuleCalldata
142
+ )
143
+ external
144
+ view
145
+ returns (
146
+ address primaryContractAddress,
147
+ address secondaryContractAddress
148
+ );
149
+
150
+ /**
151
+ * @dev Computes the addresses of a primary and a secondary linked contracts proxies to be created
152
+ *
153
+ * @param primaryContractDeploymentInit Contains the needed parameters to deploy a primary proxy contract. (`salt`, `fundingAmount`, `implementationContract`, `initializationCalldata`)
154
+ * @param secondaryContractDeploymentInit Contains the needed parameters to deploy the secondary proxy contract. (`fundingAmount`, `implementationContract`, `addPrimaryContractAddress`, `initializationCalldata`, `extraInitializationParams`)
155
+ * @param postDeploymentModule The module to be executed after deployment.
156
+ * @param postDeploymentModuleCalldata The data to be passed to the post deployment module.
157
+ *
158
+ * @return primaryContractAddress The address of the deployed primary contract proxy
159
+ * @return secondaryContractAddress The address of the deployed secondary contract proxy
160
+ */
161
+ function computeERC1167Addresses(
162
+ PrimaryContractDeploymentInit calldata primaryContractDeploymentInit,
163
+ SecondaryContractDeploymentInit
164
+ calldata secondaryContractDeploymentInit,
165
+ address postDeploymentModule,
166
+ bytes calldata postDeploymentModuleCalldata
167
+ )
168
+ external
169
+ view
170
+ returns (
171
+ address primaryContractAddress,
172
+ address secondaryContractAddress
173
+ );
174
+ }
@@ -0,0 +1,10 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.4;
3
+
4
+ interface IPostDeploymentModule {
5
+ function executePostDeployment(
6
+ address primaryContract,
7
+ address secondaryContract,
8
+ bytes calldata calldataToPostDeploymentModule
9
+ ) external;
10
+ }
@@ -0,0 +1,24 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.4;
3
+
4
+ /**
5
+ * @dev Reverts when the `msg.value` sent is not equal to the sum of value used for the deployment of the contract & its owner contract.
6
+ * @notice Invalid value sent.
7
+ */
8
+ error InvalidValueSum();
9
+
10
+ /**
11
+ * @dev Reverts when the deployment & intialisation of the contract has failed.
12
+ * @notice Failed to deploy & initialise the Primary Contract Proxy. Error: `errorData`.
13
+ *
14
+ * @param errorData Potentially information about why the deployment & intialisation have failed.
15
+ */
16
+ error PrimaryContractProxyInitFailureError(bytes errorData);
17
+
18
+ /**
19
+ * @dev Reverts when the deployment & intialisation of the secondary contract has failed.
20
+ * @notice Failed to deploy & initialise the Secondary Contract Proxy. Error: `errorData`.
21
+ *
22
+ * @param errorData Potentially information about why the deployment & intialisation have failed.
23
+ */
24
+ error SecondaryContractProxyInitFailureError(bytes errorData);
@@ -0,0 +1,384 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.4;
3
+
4
+ import {Create2} from "@openzeppelin/contracts/utils/Create2.sol";
5
+ import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";
6
+ import {IPostDeploymentModule} from "./IPostDeploymentModule.sol";
7
+ import {ILinkedContractsFactory} from "./ILinkedContractsFactory.sol";
8
+ import {
9
+ InvalidValueSum,
10
+ PrimaryContractProxyInitFailureError,
11
+ SecondaryContractProxyInitFailureError
12
+ } from "./LSP23Errors.sol";
13
+
14
+ contract LinkedContractsFactory is ILinkedContractsFactory {
15
+ /**
16
+ * @inheritdoc ILinkedContractsFactory
17
+ */
18
+ function deployContracts(
19
+ PrimaryContractDeployment calldata primaryContractDeployment,
20
+ SecondaryContractDeployment calldata secondaryContractDeployment,
21
+ address postDeploymentModule,
22
+ bytes calldata postDeploymentModuleCalldata
23
+ )
24
+ public
25
+ payable
26
+ returns (
27
+ address primaryContractAddress,
28
+ address secondaryContractAddress
29
+ )
30
+ {
31
+ /* check that the msg.value is equal to the sum of the values of the primary and secondary contracts */
32
+ if (
33
+ msg.value !=
34
+ primaryContractDeployment.fundingAmount +
35
+ secondaryContractDeployment.fundingAmount
36
+ ) {
37
+ revert InvalidValueSum();
38
+ }
39
+
40
+ primaryContractAddress = _deployPrimaryContract(
41
+ primaryContractDeployment,
42
+ secondaryContractDeployment,
43
+ postDeploymentModule,
44
+ postDeploymentModuleCalldata
45
+ );
46
+
47
+ secondaryContractAddress = _deploySecondaryContract(
48
+ secondaryContractDeployment,
49
+ primaryContractAddress
50
+ );
51
+
52
+ emit DeployedContracts(
53
+ primaryContractAddress,
54
+ secondaryContractAddress,
55
+ primaryContractDeployment,
56
+ secondaryContractDeployment,
57
+ postDeploymentModule,
58
+ postDeploymentModuleCalldata
59
+ );
60
+
61
+ /* execute the post deployment module logic in the postDeploymentModule */
62
+ IPostDeploymentModule(postDeploymentModule).executePostDeployment(
63
+ primaryContractAddress,
64
+ secondaryContractAddress,
65
+ postDeploymentModuleCalldata
66
+ );
67
+ }
68
+
69
+ /**
70
+ * @inheritdoc ILinkedContractsFactory
71
+ */
72
+ function deployERC1167Proxies(
73
+ PrimaryContractDeploymentInit calldata primaryContractDeploymentInit,
74
+ SecondaryContractDeploymentInit
75
+ calldata secondaryContractDeploymentInit,
76
+ address postDeploymentModule,
77
+ bytes calldata postDeploymentModuleCalldata
78
+ )
79
+ public
80
+ payable
81
+ returns (
82
+ address primaryContractAddress,
83
+ address secondaryContractAddress
84
+ )
85
+ {
86
+ /* check that the msg.value is equal to the sum of the values of the primary and secondary contracts */
87
+ if (
88
+ msg.value !=
89
+ primaryContractDeploymentInit.fundingAmount +
90
+ secondaryContractDeploymentInit.fundingAmount
91
+ ) {
92
+ revert InvalidValueSum();
93
+ }
94
+
95
+ /* deploy the primary contract proxy with the primaryContractGeneratedSalt */
96
+ primaryContractAddress = _deployAndInitializePrimaryContractProxy(
97
+ primaryContractDeploymentInit,
98
+ secondaryContractDeploymentInit,
99
+ postDeploymentModule,
100
+ postDeploymentModuleCalldata
101
+ );
102
+
103
+ /* deploy the secondary contract proxy */
104
+ secondaryContractAddress = _deployAndInitializeSecondaryContractProxy(
105
+ secondaryContractDeploymentInit,
106
+ primaryContractAddress
107
+ );
108
+
109
+ emit DeployedERC1167Proxies(
110
+ primaryContractAddress,
111
+ secondaryContractAddress,
112
+ primaryContractDeploymentInit,
113
+ secondaryContractDeploymentInit,
114
+ postDeploymentModule,
115
+ postDeploymentModuleCalldata
116
+ );
117
+
118
+ /* execute the post deployment logic in the postDeploymentModule */
119
+ IPostDeploymentModule(postDeploymentModule).executePostDeployment(
120
+ primaryContractAddress,
121
+ secondaryContractAddress,
122
+ postDeploymentModuleCalldata
123
+ );
124
+ }
125
+
126
+ /**
127
+ * @inheritdoc ILinkedContractsFactory
128
+ */
129
+ function computeAddresses(
130
+ PrimaryContractDeployment calldata primaryContractDeployment,
131
+ SecondaryContractDeployment calldata secondaryContractDeployment,
132
+ address postDeploymentModule,
133
+ bytes calldata postDeploymentModuleCalldata
134
+ )
135
+ public
136
+ view
137
+ returns (
138
+ address primaryContractAddress,
139
+ address secondaryContractAddress
140
+ )
141
+ {
142
+ bytes32 primaryContractGeneratedSalt = _generatePrimaryContractSalt(
143
+ primaryContractDeployment,
144
+ secondaryContractDeployment,
145
+ postDeploymentModule,
146
+ postDeploymentModuleCalldata
147
+ );
148
+
149
+ primaryContractAddress = Create2.computeAddress(
150
+ primaryContractGeneratedSalt,
151
+ keccak256(primaryContractDeployment.creationBytecode)
152
+ );
153
+
154
+ bytes memory secondaryContractByteCodeWithAllParams;
155
+ if (secondaryContractDeployment.addPrimaryContractAddress) {
156
+ secondaryContractByteCodeWithAllParams = abi.encodePacked(
157
+ secondaryContractDeployment.creationBytecode,
158
+ abi.encode(primaryContractAddress),
159
+ secondaryContractDeployment.extraConstructorParams
160
+ );
161
+ } else {
162
+ secondaryContractByteCodeWithAllParams = secondaryContractDeployment
163
+ .creationBytecode;
164
+ }
165
+
166
+ secondaryContractAddress = Create2.computeAddress(
167
+ keccak256(abi.encodePacked(primaryContractAddress)),
168
+ keccak256(secondaryContractByteCodeWithAllParams)
169
+ );
170
+ }
171
+
172
+ /**
173
+ * @inheritdoc ILinkedContractsFactory
174
+ */
175
+ function computeERC1167Addresses(
176
+ PrimaryContractDeploymentInit calldata primaryContractDeploymentInit,
177
+ SecondaryContractDeploymentInit
178
+ calldata secondaryContractDeploymentInit,
179
+ address postDeploymentModule,
180
+ bytes calldata postDeploymentModuleCalldata
181
+ )
182
+ public
183
+ view
184
+ returns (
185
+ address primaryContractAddress,
186
+ address secondaryContractAddress
187
+ )
188
+ {
189
+ bytes32 primaryContractGeneratedSalt = _generatePrimaryContractProxySalt(
190
+ primaryContractDeploymentInit,
191
+ secondaryContractDeploymentInit,
192
+ postDeploymentModule,
193
+ postDeploymentModuleCalldata
194
+ );
195
+
196
+ primaryContractAddress = Clones.predictDeterministicAddress(
197
+ primaryContractDeploymentInit.implementationContract,
198
+ primaryContractGeneratedSalt
199
+ );
200
+
201
+ secondaryContractAddress = Clones.predictDeterministicAddress(
202
+ secondaryContractDeploymentInit.implementationContract,
203
+ keccak256(abi.encodePacked(primaryContractAddress))
204
+ );
205
+ }
206
+
207
+ function _deployPrimaryContract(
208
+ PrimaryContractDeployment calldata primaryContractDeployment,
209
+ SecondaryContractDeployment calldata secondaryContractDeployment,
210
+ address postDeploymentModule,
211
+ bytes calldata postDeploymentModuleCalldata
212
+ ) internal returns (address primaryContractAddress) {
213
+ bytes32 primaryContractGeneratedSalt = _generatePrimaryContractSalt(
214
+ primaryContractDeployment,
215
+ secondaryContractDeployment,
216
+ postDeploymentModule,
217
+ postDeploymentModuleCalldata
218
+ );
219
+
220
+ /* deploy the primary contract */
221
+ primaryContractAddress = Create2.deploy(
222
+ primaryContractDeployment.fundingAmount,
223
+ primaryContractGeneratedSalt,
224
+ primaryContractDeployment.creationBytecode
225
+ );
226
+ }
227
+
228
+ function _deploySecondaryContract(
229
+ SecondaryContractDeployment calldata secondaryContractDeployment,
230
+ address primaryContractAddress
231
+ ) internal returns (address secondaryContractAddress) {
232
+ /**
233
+ * If `addPrimaryContractAddress` is `true`, the following will be appended to the constructor params:
234
+ * - The primary contract address
235
+ * - `extraConstructorParams`
236
+ */
237
+ bytes memory secondaryContractByteCode = secondaryContractDeployment
238
+ .creationBytecode;
239
+
240
+ if (secondaryContractDeployment.addPrimaryContractAddress) {
241
+ secondaryContractByteCode = abi.encodePacked(
242
+ secondaryContractByteCode,
243
+ abi.encode(primaryContractAddress),
244
+ secondaryContractDeployment.extraConstructorParams
245
+ );
246
+ }
247
+
248
+ secondaryContractAddress = Create2.deploy(
249
+ secondaryContractDeployment.fundingAmount,
250
+ keccak256(abi.encodePacked(primaryContractAddress)),
251
+ secondaryContractByteCode
252
+ );
253
+ }
254
+
255
+ function _deployAndInitializePrimaryContractProxy(
256
+ PrimaryContractDeploymentInit calldata primaryContractDeploymentInit,
257
+ SecondaryContractDeploymentInit
258
+ calldata secondaryContractDeploymentInit,
259
+ address postDeploymentModule,
260
+ bytes calldata postDeploymentModuleCalldata
261
+ ) internal returns (address primaryContractAddress) {
262
+ bytes32 primaryContractGeneratedSalt = _generatePrimaryContractProxySalt(
263
+ primaryContractDeploymentInit,
264
+ secondaryContractDeploymentInit,
265
+ postDeploymentModule,
266
+ postDeploymentModuleCalldata
267
+ );
268
+
269
+ /* deploy the primary contract proxy with the primaryContractGeneratedSalt */
270
+ primaryContractAddress = Clones.cloneDeterministic(
271
+ primaryContractDeploymentInit.implementationContract,
272
+ primaryContractGeneratedSalt
273
+ );
274
+
275
+ /* initialize the primary contract proxy */
276
+ (bool success, bytes memory returnedData) = primaryContractAddress.call{
277
+ value: msg.value
278
+ }(primaryContractDeploymentInit.initializationCalldata);
279
+ if (!success) {
280
+ revert PrimaryContractProxyInitFailureError(returnedData);
281
+ }
282
+ }
283
+
284
+ function _deployAndInitializeSecondaryContractProxy(
285
+ SecondaryContractDeploymentInit
286
+ calldata secondaryContractDeploymentInit,
287
+ address primaryContractAddress
288
+ ) internal returns (address secondaryContractAddress) {
289
+ /* deploy the secondary contract proxy with the primaryContractGeneratedSalt */
290
+ secondaryContractAddress = Clones.cloneDeterministic(
291
+ secondaryContractDeploymentInit.implementationContract,
292
+ keccak256(abi.encodePacked(primaryContractAddress))
293
+ );
294
+
295
+ /**
296
+ * If `addPrimaryContractAddress` is `true`, the following will be appended to the `initializationCalldata`:
297
+ * - The primary contract address
298
+ * - `extraInitialisationBytes`
299
+ */
300
+ bytes
301
+ memory secondaryInitializationBytes = secondaryContractDeploymentInit
302
+ .initializationCalldata;
303
+
304
+ if (secondaryContractDeploymentInit.addPrimaryContractAddress) {
305
+ secondaryInitializationBytes = abi.encodePacked(
306
+ secondaryInitializationBytes,
307
+ abi.encode(primaryContractAddress),
308
+ secondaryContractDeploymentInit.extraInitializationParams
309
+ );
310
+ }
311
+
312
+ /* initialize the primary contract proxy */
313
+ (bool success, bytes memory returnedData) = secondaryContractAddress
314
+ .call{value: msg.value}(secondaryInitializationBytes);
315
+ if (!success) {
316
+ revert SecondaryContractProxyInitFailureError(returnedData);
317
+ }
318
+ }
319
+
320
+ function _generatePrimaryContractSalt(
321
+ PrimaryContractDeployment calldata primaryContractDeployment,
322
+ SecondaryContractDeployment calldata secondaryContractDeployment,
323
+ address postDeploymentModule,
324
+ bytes calldata postDeploymentModuleCalldata
325
+ ) internal pure virtual returns (bytes32 primaryContractGeneratedSalt) {
326
+ /* generate salt for the primary contract
327
+ * the salt is generated by hashing the following elements:
328
+ * - the salt
329
+ * - the secondary contract bytecode
330
+ * - the secondary addPrimaryContractAddress boolean
331
+ * - the secondary extraConstructorParams
332
+ * - the postDeploymentModule address
333
+ * - the postDeploymentModuleCalldata
334
+ *
335
+ */
336
+ primaryContractGeneratedSalt = keccak256(
337
+ abi.encode(
338
+ primaryContractDeployment.salt,
339
+ secondaryContractDeployment.creationBytecode,
340
+ secondaryContractDeployment.addPrimaryContractAddress,
341
+ secondaryContractDeployment.extraConstructorParams,
342
+ postDeploymentModule,
343
+ postDeploymentModuleCalldata
344
+ )
345
+ );
346
+ }
347
+
348
+ function _generatePrimaryContractProxySalt(
349
+ PrimaryContractDeploymentInit calldata primaryContractDeploymentInit,
350
+ SecondaryContractDeploymentInit
351
+ calldata secondaryContractDeploymentInit,
352
+ address postDeploymentModule,
353
+ bytes calldata postDeploymentModuleCalldata
354
+ )
355
+ internal
356
+ pure
357
+ virtual
358
+ returns (bytes32 primaryContractProxyGeneratedSalt)
359
+ {
360
+ /**
361
+ * Generate the salt for the primary contract
362
+ * The salt is generated by hashing the following elements:
363
+ * - the salt
364
+ * - the secondary implementation contract address
365
+ * - the secondary contract addPrimaryContractAddress boolean
366
+ * - the secondary contract initialization calldata
367
+ * - the secondary contract extra initialization params (if any)
368
+ * - the postDeploymentModule address
369
+ * - the callda to the post deployment module
370
+ *
371
+ */
372
+ primaryContractProxyGeneratedSalt = keccak256(
373
+ abi.encode(
374
+ primaryContractDeploymentInit.salt,
375
+ secondaryContractDeploymentInit.implementationContract,
376
+ secondaryContractDeploymentInit.initializationCalldata,
377
+ secondaryContractDeploymentInit.addPrimaryContractAddress,
378
+ secondaryContractDeploymentInit.extraInitializationParams,
379
+ postDeploymentModule,
380
+ postDeploymentModuleCalldata
381
+ )
382
+ );
383
+ }
384
+ }
@@ -0,0 +1,59 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.4;
3
+
4
+ import {UniversalProfileInit} from "../../UniversalProfileInit.sol";
5
+
6
+ contract UniversalProfileInitPostDeploymentModule is UniversalProfileInit {
7
+ constructor() {
8
+ _disableInitializers();
9
+ }
10
+
11
+ function setDataAndTransferOwnership(
12
+ bytes32[] memory dataKeys,
13
+ bytes[] memory dataValues,
14
+ address newOwner
15
+ ) public payable {
16
+ // check that the msg.sender is the owner
17
+ require(
18
+ msg.sender == owner(),
19
+ "UniversalProfileInitPostDeploymentModule: setDataAndTransferOwnership only allowed through delegate call"
20
+ );
21
+
22
+ // update the dataKeys and dataValues in the UniversalProfile contract
23
+ for (uint256 i = 0; i < dataKeys.length; ) {
24
+ _setData(dataKeys[i], dataValues[i]);
25
+
26
+ unchecked {
27
+ ++i;
28
+ }
29
+ }
30
+
31
+ // transfer the ownership of the UniversalProfile contract to the newOwner
32
+ _setOwner(newOwner);
33
+ }
34
+
35
+ function executePostDeployment(
36
+ address universalProfile,
37
+ address keyManager,
38
+ bytes calldata setDataBatchBytes
39
+ ) public {
40
+ // retrieve the dataKeys and dataValues to setData from the initializationCalldata bytes
41
+ (bytes32[] memory dataKeys, bytes[] memory dataValues) = abi.decode(
42
+ setDataBatchBytes,
43
+ (bytes32[], bytes[])
44
+ );
45
+
46
+ // call the execute function with delegate_call on the universalProfile contract to setData and transferOwnership
47
+ UniversalProfileInit(payable(universalProfile)).execute(
48
+ 4,
49
+ address(this),
50
+ 0,
51
+ abi.encodeWithSignature(
52
+ "setDataAndTransferOwnership(bytes32[],bytes[],address)",
53
+ dataKeys,
54
+ dataValues,
55
+ keyManager
56
+ )
57
+ );
58
+ }
59
+ }
@@ -78,11 +78,11 @@ abstract contract LSP6KeyManagerCore is
78
78
 
79
79
  // Variables, methods and modifier used for ReentrancyGuard are taken from the link below and modified accordingly.
80
80
  // https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v4.8/contracts/security/ReentrancyGuard.sol
81
- bool private _reentrancyStatus;
81
+ bool internal _reentrancyStatus;
82
82
 
83
83
  mapping(address => mapping(uint256 => uint256)) internal _nonceStore;
84
84
 
85
- function target() public view returns (address) {
85
+ function target() public view virtual returns (address) {
86
86
  return _target;
87
87
  }
88
88
 
@@ -116,7 +116,7 @@ abstract contract LSP6KeyManagerCore is
116
116
  function isValidSignature(
117
117
  bytes32 dataHash,
118
118
  bytes memory signature
119
- ) public view returns (bytes4 magicValue) {
119
+ ) public view virtual returns (bytes4 magicValue) {
120
120
  // if isValidSignature fail, the error is catched in returnedError
121
121
  (address recoveredAddress, ECDSA.RecoverError returnedError) = ECDSA
122
122
  .tryRecover(dataHash, signature);
@@ -250,7 +250,7 @@ abstract contract LSP6KeyManagerCore is
250
250
  address caller,
251
251
  uint256 msgValue,
252
252
  bytes calldata data
253
- ) external returns (bytes4) {
253
+ ) external virtual returns (bytes4) {
254
254
  bool isSetData = false;
255
255
  if (
256
256
  bytes4(data) == IERC725Y.setData.selector ||
@@ -301,7 +301,7 @@ abstract contract LSP6KeyManagerCore is
301
301
  function lsp20VerifyCallResult(
302
302
  bytes32 /*callHash*/,
303
303
  bytes memory /*result*/
304
- ) external returns (bytes4) {
304
+ ) external virtual returns (bytes4) {
305
305
  // If it's the target calling, set back the reentrancy guard
306
306
  // to false, if not return the magic value
307
307
  if (msg.sender == _target) {