@lukso/lsp-smart-contracts 0.10.0 → 0.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -1
- package/artifacts/Create2Factory.json +2 -2
- package/artifacts/LSP0ERC725Account.json +4 -4
- package/artifacts/LSP0ERC725AccountInit.json +4 -4
- package/artifacts/LSP11BasicSocialRecovery.json +2 -2
- package/artifacts/LSP11BasicSocialRecoveryInit.json +2 -2
- package/artifacts/LSP16UniversalFactory.json +27 -21
- package/artifacts/LSP1UniversalReceiverDelegateUP.json +2 -2
- package/artifacts/LSP1UniversalReceiverDelegateVault.json +2 -2
- package/artifacts/LSP6KeyManager.json +2 -2
- package/artifacts/LSP6KeyManagerInit.json +2 -2
- package/artifacts/LSP7CompatibleERC20Mintable.json +2 -2
- package/artifacts/LSP7CompatibleERC20MintableInit.json +2 -2
- package/artifacts/LSP7Mintable.json +2 -2
- package/artifacts/LSP7MintableInit.json +2 -2
- package/artifacts/LSP8CompatibleERC721Mintable.json +2 -2
- package/artifacts/LSP8CompatibleERC721MintableInit.json +2 -2
- package/artifacts/LSP8Mintable.json +2 -2
- package/artifacts/LSP8MintableInit.json +2 -2
- package/artifacts/LSP9Vault.json +2 -2
- package/artifacts/LSP9VaultInit.json +2 -2
- package/artifacts/UniversalProfile.json +4 -4
- package/artifacts/UniversalProfileInit.json +4 -4
- package/artifacts/UniversalReceiverAddressStore.json +2 -2
- package/contracts/Factories/Create2Factory.sol +11 -3
- package/contracts/LSP0ERC725Account/ILSP0ERC725Account.sol +13 -5
- package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +11 -6
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +256 -186
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +20 -6
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +23 -9
- package/contracts/LSP0ERC725Account/LSP0Utils.sol +3 -5
- package/contracts/LSP10ReceivedVaults/LSP10Utils.sol +25 -10
- package/contracts/LSP11BasicSocialRecovery/ILSP11BasicSocialRecovery.sol +4 -2
- package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecovery.sol +3 -1
- package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryCore.sol +65 -23
- package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryInit.sol +7 -2
- package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryInitAbstract.sol +14 -4
- package/contracts/LSP11BasicSocialRecovery/LSP11Errors.sol +4 -1
- package/contracts/LSP14Ownable2Step/ILSP14Ownable2Step.sol +17 -16
- package/contracts/LSP14Ownable2Step/LSP14Errors.sol +4 -1
- package/contracts/LSP14Ownable2Step/LSP14Ownable2Step.sol +22 -11
- package/contracts/LSP16UniversalFactory/LSP16UniversalFactory.sol +333 -128
- package/contracts/LSP17ContractExtension/LSP17Extendable.sol +38 -16
- package/contracts/LSP17ContractExtension/LSP17Extension.sol +20 -8
- package/contracts/LSP17ContractExtension/LSP17Utils.sol +4 -5
- package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiver.sol +5 -5
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +38 -14
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +31 -11
- package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +34 -9
- package/contracts/LSP20CallVerification/{ILSP20CallVerification.sol → ILSP20CallVerifier.sol} +7 -2
- package/contracts/LSP20CallVerification/LSP20CallVerification.sol +24 -9
- package/contracts/LSP20CallVerification/LSP20Errors.sol +1 -1
- package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +62 -36
- package/contracts/LSP4DigitalAssetMetadata/ILSP4Compatibility.sol +3 -1
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol +15 -4
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +18 -5
- package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +32 -12
- package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +17 -8
- package/contracts/LSP6KeyManager/LSP6Constants.sol +3 -9
- package/contracts/LSP6KeyManager/LSP6Errors.sol +4 -1
- package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +114 -72
- package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +7 -2
- package/contracts/LSP6KeyManager/LSP6Modules/LSP6ExecuteModule.sol +96 -46
- package/contracts/LSP6KeyManager/LSP6Modules/LSP6OwnershipModule.sol +10 -5
- package/contracts/LSP6KeyManager/LSP6Modules/LSP6SetDataModule.sol +98 -32
- package/contracts/LSP6KeyManager/LSP6Utils.sol +42 -34
- package/contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol +8 -6
- package/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol +13 -10
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +96 -26
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol +11 -9
- package/contracts/LSP7DigitalAsset/LSP7Errors.sol +8 -2
- package/contracts/LSP7DigitalAsset/extensions/ILSP7CompatibleERC20.sol +9 -2
- package/contracts/LSP7DigitalAsset/extensions/LSP7Burnable.sol +1 -5
- package/contracts/LSP7DigitalAsset/extensions/LSP7BurnableInitAbstract.sol +4 -6
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +6 -2
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20.sol +32 -12
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20InitAbstract.sol +28 -7
- package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInit.sol +8 -2
- package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInitAbstract.sol +6 -2
- package/contracts/LSP7DigitalAsset/presets/LSP7MintableInit.sol +6 -1
- package/contracts/LSP7DigitalAsset/presets/LSP7MintableInitAbstract.sol +13 -3
- package/contracts/LSP8IdentifiableDigitalAsset/ILSP8IdentifiableDigitalAsset.sol +14 -5
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8Errors.sol +3 -1
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAsset.sol +12 -10
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +95 -28
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInitAbstract.sol +14 -10
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CompatibleERC721.sol +23 -10
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Burnable.sol +3 -1
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupply.sol +3 -1
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +6 -2
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol +72 -30
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol +77 -27
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Enumerable.sol +6 -2
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8EnumerableInitAbstract.sol +6 -2
- package/contracts/LSP8IdentifiableDigitalAsset/presets/ILSP8Mintable.sol +3 -1
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInit.sol +8 -2
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInitAbstract.sol +6 -2
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8Mintable.sol +3 -1
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInitAbstract.sol +5 -1
- package/contracts/LSP9Vault/ILSP9Vault.sol +13 -5
- package/contracts/LSP9Vault/LSP9Vault.sol +7 -2
- package/contracts/LSP9Vault/LSP9VaultCore.sol +108 -51
- package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +10 -3
- package/contracts/Legacy/Registries/AddressRegistry.sol +13 -4
- package/contracts/Legacy/Registries/AddressRegistryRequiresERC725.sol +6 -2
- package/contracts/Legacy/UniversalReceiverAddressStore.sol +17 -6
- package/contracts/UniversalProfile.sol +14 -5
- package/contracts/UniversalProfileInit.sol +17 -5
- package/contracts/UniversalProfileInitAbstract.sol +17 -9
- package/devdocs/LSP0ERC725Account.json +33 -19
- package/devdocs/LSP0ERC725AccountInit.json +33 -20
- package/devdocs/LSP16UniversalFactory.json +87 -22
- package/devdocs/LSP9Vault.json +3 -3
- package/devdocs/LSP9VaultInit.json +3 -3
- package/devdocs/UniversalProfile.json +32 -18
- package/devdocs/UniversalProfileInit.json +33 -19
- package/dist/constants.cjs.js +310 -182
- package/dist/constants.d.ts +178 -48
- package/dist/constants.es.js +310 -182
- package/package.json +19 -17
- package/userdocs/LSP0ERC725Account.json +5 -2
- package/userdocs/LSP0ERC725AccountInit.json +8 -2
- package/userdocs/UniversalProfile.json +3 -3
- package/userdocs/UniversalProfileInit.json +6 -3
- package/contracts/Custom/EIP191Signer.sol +0 -12
|
@@ -8,121 +8,148 @@ 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.
|
|
44
|
+
*
|
|
45
|
+
* See {generateSalt} function for more details.
|
|
33
46
|
*
|
|
34
|
-
*
|
|
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
|
-
|
|
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.
|
|
83
|
+
*
|
|
84
|
+
* This function deploys contracts without initialization (external call after deployment).
|
|
89
85
|
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
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.
|
|
92
88
|
*
|
|
93
|
-
* Using the same `byteCode` and
|
|
94
|
-
*
|
|
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
|
-
function deployCreate2(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
102
|
+
function deployCreate2(
|
|
103
|
+
bytes calldata byteCode,
|
|
104
|
+
bytes32 providedSalt
|
|
105
|
+
) public payable virtual returns (address) {
|
|
106
|
+
bytes32 generatedSalt = generateSalt(providedSalt, false, _EMPTY_BYTE);
|
|
107
|
+
address contractCreated = Create2.deploy(
|
|
108
|
+
msg.value,
|
|
109
|
+
generatedSalt,
|
|
110
|
+
byteCode
|
|
111
|
+
);
|
|
112
|
+
emit ContractCreated(
|
|
113
|
+
contractCreated,
|
|
114
|
+
providedSalt,
|
|
115
|
+
generatedSalt,
|
|
116
|
+
false,
|
|
117
|
+
_EMPTY_BYTE
|
|
118
|
+
);
|
|
105
119
|
|
|
106
120
|
return contractCreated;
|
|
107
121
|
}
|
|
108
122
|
|
|
109
123
|
/**
|
|
110
|
-
* @dev Deploys a contract using
|
|
111
|
-
* can be known in advance via {
|
|
112
|
-
*
|
|
124
|
+
* @dev Deploys a contract using the CREATE2 opcode. The address where the contract will be deployed
|
|
125
|
+
* can be known in advance via the {computeAddress} function.
|
|
126
|
+
*
|
|
127
|
+
* This function deploys contracts with initialization (external call after deployment).
|
|
128
|
+
*
|
|
129
|
+
* The `providedSalt` parameter is not used directly as the salt by the CREATE2 opcode. Instead, it is hashed with
|
|
130
|
+
* keccak256: `keccak256(abi.encodePacked(true, initializeCalldata, providedSalt))`.
|
|
131
|
+
* See {generateSalt} function for more details.
|
|
113
132
|
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
133
|
+
* Using the same `byteCode`, `providedSalt` and `initializeCalldata` multiple times will revert, as the
|
|
134
|
+
* contract cannot be deployed twice at the same address.
|
|
116
135
|
*
|
|
117
|
-
*
|
|
136
|
+
* If the constructor or the initialize function of the contract to deploy is payable, value can be sent along
|
|
137
|
+
* with the deployment/initialization to fund the created contract. However, sending value to this function while
|
|
138
|
+
* the constructor/initialize function is not payable will result in a revert.
|
|
118
139
|
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
140
|
+
* Will revert if the `msg.value` sent to the function is not equal to the sum of `constructorMsgValue` and
|
|
141
|
+
* `initializeCalldataMsgValue`.
|
|
121
142
|
*
|
|
122
|
-
*
|
|
123
|
-
* the
|
|
143
|
+
* @param byteCode The bytecode of the contract to be deployed
|
|
144
|
+
* @param providedSalt The salt provided by the deployer, which will be used to generate the final salt
|
|
145
|
+
* that will be used by the `CREATE2` opcode for contract deployment
|
|
146
|
+
* @param initializeCalldata The calldata to be executed on the created contract
|
|
147
|
+
* @param constructorMsgValue The value sent to the contract during deployment
|
|
148
|
+
* @param initializeCalldataMsgValue The value sent to the contract during initialization
|
|
149
|
+
*
|
|
150
|
+
* @return The address of the deployed contract
|
|
124
151
|
*/
|
|
125
|
-
function
|
|
152
|
+
function deployCreate2AndInitialize(
|
|
126
153
|
bytes calldata byteCode,
|
|
127
154
|
bytes32 providedSalt,
|
|
128
155
|
bytes calldata initializeCalldata,
|
|
@@ -130,11 +157,25 @@ contract LSP16UniversalFactory {
|
|
|
130
157
|
uint256 initializeCalldataMsgValue
|
|
131
158
|
) public payable virtual returns (address) {
|
|
132
159
|
if (constructorMsgValue + initializeCalldataMsgValue != msg.value)
|
|
133
|
-
revert
|
|
160
|
+
revert InvalidValueSum();
|
|
134
161
|
|
|
135
|
-
bytes32 generatedSalt = generateSalt(
|
|
136
|
-
|
|
137
|
-
|
|
162
|
+
bytes32 generatedSalt = generateSalt(
|
|
163
|
+
providedSalt,
|
|
164
|
+
true,
|
|
165
|
+
initializeCalldata
|
|
166
|
+
);
|
|
167
|
+
address contractCreated = Create2.deploy(
|
|
168
|
+
constructorMsgValue,
|
|
169
|
+
generatedSalt,
|
|
170
|
+
byteCode
|
|
171
|
+
);
|
|
172
|
+
emit ContractCreated(
|
|
173
|
+
contractCreated,
|
|
174
|
+
providedSalt,
|
|
175
|
+
generatedSalt,
|
|
176
|
+
true,
|
|
177
|
+
initializeCalldata
|
|
178
|
+
);
|
|
138
179
|
|
|
139
180
|
(bool success, bytes memory returndata) = contractCreated.call{
|
|
140
181
|
value: initializeCalldataMsgValue
|
|
@@ -145,89 +186,253 @@ contract LSP16UniversalFactory {
|
|
|
145
186
|
}
|
|
146
187
|
|
|
147
188
|
/**
|
|
148
|
-
* @dev Deploys
|
|
149
|
-
*
|
|
189
|
+
* @dev Deploys an ERC1167 minimal proxy contract using the CREATE2 opcode. The address where the contract will be deployed
|
|
190
|
+
* can be known in advance via the {computeERC1167Address} function.
|
|
191
|
+
*
|
|
192
|
+
* This function deploys contracts without initialization (external call after deployment).
|
|
150
193
|
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
* toegther with an empty byte, to prevent mimicing the `deployCreate2ProxyInit()` and other functions.
|
|
194
|
+
* The `providedSalt` parameter is not used directly as the salt by the CREATE2 opcode. Instead, it is hashed with
|
|
195
|
+
* keccak256: `keccak256(abi.encodePacked(false, providedSalt))`. See {generateSalt} function for more details.
|
|
154
196
|
*
|
|
155
|
-
*
|
|
156
|
-
* chains with the same parameters.
|
|
197
|
+
* See {generateSalt} function for more details.
|
|
157
198
|
*
|
|
158
|
-
* Using the same `
|
|
159
|
-
*
|
|
199
|
+
* Using the same `implementationContract` and `providedSalt` multiple times will revert, as the contract cannot be deployed
|
|
200
|
+
* twice at the same address.
|
|
201
|
+
*
|
|
202
|
+
* Sending value to the contract created is not possible since the constructor of the ERC1167 minimal proxy is not payable.
|
|
203
|
+
*
|
|
204
|
+
* @param implementationContract The contract address to use as the base implementation behind the proxy that will be deployed
|
|
205
|
+
* @param providedSalt The salt provided by the deployer, which will be used to generate the final salt
|
|
206
|
+
* that will be used by the `CREATE2` opcode for contract deployment
|
|
207
|
+
*
|
|
208
|
+
* @return The address of the minimal proxy deployed
|
|
160
209
|
*/
|
|
161
|
-
function
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
bytes32 generatedSalt = generateSalt(false, _EMPTY_BYTE, providedSalt);
|
|
210
|
+
function deployERC1167Proxy(
|
|
211
|
+
address implementationContract,
|
|
212
|
+
bytes32 providedSalt
|
|
213
|
+
) public virtual returns (address) {
|
|
214
|
+
bytes32 generatedSalt = generateSalt(providedSalt, false, _EMPTY_BYTE);
|
|
167
215
|
|
|
168
|
-
address proxy = Clones.cloneDeterministic(
|
|
169
|
-
|
|
216
|
+
address proxy = Clones.cloneDeterministic(
|
|
217
|
+
implementationContract,
|
|
218
|
+
generatedSalt
|
|
219
|
+
);
|
|
220
|
+
emit ContractCreated(
|
|
221
|
+
proxy,
|
|
222
|
+
providedSalt,
|
|
223
|
+
generatedSalt,
|
|
224
|
+
false,
|
|
225
|
+
_EMPTY_BYTE
|
|
226
|
+
);
|
|
170
227
|
|
|
171
228
|
return proxy;
|
|
172
229
|
}
|
|
173
230
|
|
|
174
231
|
/**
|
|
175
|
-
* @dev Deploys
|
|
176
|
-
*
|
|
232
|
+
* @dev Deploys an ERC1167 minimal proxy contract using the CREATE2 opcode. The address where the contract will be deployed
|
|
233
|
+
* can be known in advance via the {computeERC1167Address} function.
|
|
234
|
+
*
|
|
235
|
+
* This function deploys contracts with initialization (external call after deployment).
|
|
177
236
|
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
237
|
+
* The `providedSalt` parameter is not used directly as the salt by the CREATE2 opcode. Instead, it is hashed with
|
|
238
|
+
* keccak256: `keccak256(abi.encodePacked(true, initializeCalldata, providedSalt))`.
|
|
239
|
+
* See {generateSalt} function for more details.
|
|
181
240
|
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
241
|
+
* Using the same `implementationContract`, `providedSalt` and `initializeCalldata` multiple times will revert, as the
|
|
242
|
+
* contract cannot be deployed twice at the same address.
|
|
184
243
|
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
244
|
+
* If the initialize function of the contract to deploy is payable, value can be sent along to fund the created
|
|
245
|
+
* contract while initializing. However, sending value to this function while the initialize function is not
|
|
246
|
+
* payable will result in a revert.
|
|
247
|
+
*
|
|
248
|
+
* @param implementationContract The contract address to use as the base implementation behind the proxy that will be deployed
|
|
249
|
+
* @param providedSalt The salt provided by the deployer, which will be used to generate the final salt
|
|
250
|
+
* that will be used by the `CREATE2` opcode for contract deployment
|
|
251
|
+
* @param initializeCalldata The calldata to be executed on the created contract
|
|
252
|
+
*
|
|
253
|
+
* @return The address of the minimal proxy deployed
|
|
187
254
|
*/
|
|
188
|
-
function
|
|
189
|
-
address
|
|
255
|
+
function deployERC1167ProxyAndInitialize(
|
|
256
|
+
address implementationContract,
|
|
190
257
|
bytes32 providedSalt,
|
|
191
258
|
bytes calldata initializeCalldata
|
|
192
259
|
) public payable virtual returns (address) {
|
|
193
|
-
bytes32 generatedSalt = generateSalt(
|
|
260
|
+
bytes32 generatedSalt = generateSalt(
|
|
261
|
+
providedSalt,
|
|
262
|
+
true,
|
|
263
|
+
initializeCalldata
|
|
264
|
+
);
|
|
194
265
|
|
|
195
|
-
address proxy = Clones.cloneDeterministic(
|
|
196
|
-
|
|
266
|
+
address proxy = Clones.cloneDeterministic(
|
|
267
|
+
implementationContract,
|
|
268
|
+
generatedSalt
|
|
269
|
+
);
|
|
270
|
+
emit ContractCreated(
|
|
271
|
+
proxy,
|
|
272
|
+
providedSalt,
|
|
273
|
+
generatedSalt,
|
|
274
|
+
true,
|
|
275
|
+
initializeCalldata
|
|
276
|
+
);
|
|
197
277
|
|
|
198
|
-
(bool success, bytes memory returndata) = proxy.call{value: msg.value}(
|
|
278
|
+
(bool success, bytes memory returndata) = proxy.call{value: msg.value}(
|
|
279
|
+
initializeCalldata
|
|
280
|
+
);
|
|
199
281
|
_verifyCallResult(success, returndata);
|
|
200
282
|
|
|
201
283
|
return proxy;
|
|
202
284
|
}
|
|
203
285
|
|
|
204
286
|
/**
|
|
205
|
-
* @dev
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
287
|
+
* @dev Computes the address of a contract to be deployed using CREATE2, based on the input parameters.
|
|
288
|
+
* Any change in one of these parameters will result in a different address. When the `initializable`
|
|
289
|
+
* boolean is set to `false`, `initializeCalldata` will not affect the function output.
|
|
290
|
+
*
|
|
291
|
+
* @param byteCodeHash The keccak256 hash of the bytecode to be deployed
|
|
292
|
+
* @param providedSalt The salt provided by the deployer, which will be used to generate the final salt
|
|
293
|
+
* that will be used by the `CREATE2` opcode for contract deployment
|
|
294
|
+
* @param initializable A boolean that indicates whether an external call should be made to initialize the
|
|
295
|
+
* contract after deployment
|
|
296
|
+
* @param initializeCalldata The calldata to be executed on the created contract if `initializable` is set to `true`
|
|
297
|
+
*
|
|
298
|
+
* @return The address where the contract will be deployed
|
|
299
|
+
*/
|
|
300
|
+
function computeAddress(
|
|
301
|
+
bytes32 byteCodeHash,
|
|
302
|
+
bytes32 providedSalt,
|
|
303
|
+
bool initializable,
|
|
304
|
+
bytes calldata initializeCalldata
|
|
305
|
+
) public view virtual returns (address) {
|
|
306
|
+
bytes32 generatedSalt = generateSalt(
|
|
307
|
+
providedSalt,
|
|
308
|
+
initializable,
|
|
309
|
+
initializeCalldata
|
|
310
|
+
);
|
|
311
|
+
return Create2.computeAddress(generatedSalt, byteCodeHash);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* @dev Computes the address of an ERC1167 proxy contract based on the input parameters.
|
|
316
|
+
* Any change in one of these parameters will result in a different address. When the `initializable`
|
|
317
|
+
* boolean is set to `false`, `initializeCalldata` will not affect the function output.
|
|
318
|
+
*
|
|
319
|
+
* @param implementationContract The contract to create a clone of according to ERC1167
|
|
320
|
+
* @param providedSalt The salt provided by the deployer, which will be used to generate the final salt
|
|
321
|
+
* that will be used by the `CREATE2` opcode for contract deployment
|
|
322
|
+
* @param initializable A boolean that indicates whether an external call should be made to initialize the
|
|
323
|
+
* proxy contract after deployment
|
|
324
|
+
* @param initializeCalldata The calldata to be executed on the created contract if `initializable` is set to `true`
|
|
325
|
+
*
|
|
326
|
+
* @return The address where the ERC1167 proxy contract will be deployed
|
|
327
|
+
*/
|
|
328
|
+
function computeERC1167Address(
|
|
329
|
+
address implementationContract,
|
|
330
|
+
bytes32 providedSalt,
|
|
331
|
+
bool initializable,
|
|
332
|
+
bytes calldata initializeCalldata
|
|
333
|
+
) public view virtual returns (address) {
|
|
334
|
+
bytes32 generatedSalt = generateSalt(
|
|
335
|
+
providedSalt,
|
|
336
|
+
initializable,
|
|
337
|
+
initializeCalldata
|
|
338
|
+
);
|
|
339
|
+
return
|
|
340
|
+
Clones.predictDeterministicAddress(
|
|
341
|
+
implementationContract,
|
|
342
|
+
generatedSalt
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* @dev Generates the salt used to deploy the contract by hashing the following parameters (concatenated
|
|
348
|
+
* together) with keccak256:
|
|
349
|
+
*
|
|
350
|
+
* - the `providedSalt`
|
|
351
|
+
* - the `initializable` boolean
|
|
352
|
+
* - the `initializeCalldata`, only if the contract is initializable (the `initializable` boolean is set to `true`)
|
|
353
|
+
*
|
|
354
|
+
* The `providedSalt` parameter is not used directly as the salt by the CREATE2 opcode. Instead, it is
|
|
355
|
+
* used along with these parameters:
|
|
356
|
+
* - `initializable` boolean
|
|
357
|
+
* - `initializeCalldata` (when the contract is initializable and `initializable` is set to `true`).
|
|
358
|
+
* These three parameters are concatenated together and hashed to generate the final salt for CREATE2.
|
|
359
|
+
*
|
|
360
|
+
* This approach ensures that in order to reproduce an initializable contract at the same address on another chain,
|
|
361
|
+
* not only the `providedSalt` is required to be the same, but also the initialize parameters within the `initializeCalldata`
|
|
362
|
+
* must also be the same.
|
|
363
|
+
*
|
|
364
|
+
* This maintains consistent deployment behaviour. Users are required to initialize contracts with the same parameters across
|
|
365
|
+
* different chains to ensure contracts are deployed at the same address across different chains.
|
|
366
|
+
*
|
|
367
|
+
* -----------
|
|
368
|
+
* Example (for initializable contracts)
|
|
369
|
+
*
|
|
370
|
+
* For an existing contract A on chain 1 owned by X, to replicate the same contract at the same address with
|
|
371
|
+
* the same owner X on chain 2, the salt used to generate the address should include the initializeCalldata
|
|
372
|
+
* that assigns X as the owner of contract A.
|
|
373
|
+
*
|
|
374
|
+
* For instance, if another user, Y, tries to deploy the contract at the same address
|
|
375
|
+
* on chain 2 using the same providedSalt, but with a different initializeCalldata to make Y the owner instead of X,
|
|
376
|
+
* the generated address would be different, preventing Y from deploying the contract with different ownership
|
|
377
|
+
* at the same address.
|
|
378
|
+
* -----------
|
|
379
|
+
*
|
|
380
|
+
* However, for non-initializable contracts, if the constructor has arguments that specify the deployment behavior, they
|
|
381
|
+
* will be included in the bytecode. Any change in the constructor arguments will lead to a different contract's bytecode
|
|
382
|
+
* which will result in a different address on other chains.
|
|
383
|
+
*
|
|
384
|
+
* -----------
|
|
385
|
+
* Example (for non-initializable contracts)
|
|
386
|
+
*
|
|
387
|
+
* If a contract is deployed with specific constructor arguments on chain 1, these arguments are embedded within the bytecode.
|
|
388
|
+
* For instance, if contract B is deployed with a specific `tokenName` and `tokenSymbol` on chain 1, and a user wants to deploy
|
|
389
|
+
* the same contract with the same `tokenName` and `tokenSymbol` on chain 2, they must use the same constructor arguments to
|
|
390
|
+
* produce the same bytecode. This ensures that the same deployment behaviour is maintained across different chains,
|
|
391
|
+
* as long as the same bytecode is used.
|
|
392
|
+
*
|
|
393
|
+
* If another user Z, tries to deploy the same contract B at the same address on chain 2 using the same `providedSalt`
|
|
394
|
+
* but different constructor arguments (a different `tokenName` and/or `tokenSymbol`), the generated address will be different.
|
|
395
|
+
* This prevents user Z from deploying the contract with different constructor arguments at the same address on chain 2.
|
|
396
|
+
* -----------
|
|
397
|
+
*
|
|
398
|
+
* The providedSalt was hashed to produce the salt used by CREATE2 opcode to prevent users from deploying initializable contracts
|
|
399
|
+
* using non-initializable functions such as {deployCreate2} without having the initialization call.
|
|
400
|
+
*
|
|
401
|
+
* In other words, if the providedSalt was not hashed and was used as it is as the salt by the CREATE2 opcode, malicious users
|
|
402
|
+
* can check the generated salt used for the already deployed initializable contract on chain 1, and deploy the contract
|
|
403
|
+
* from {deployCreate2} function on chain 2, with passing the generated salt of the deployed contract as providedSalt
|
|
404
|
+
* that will produce the same address but without the initialization, where the malicious user can initialize after.
|
|
405
|
+
*
|
|
406
|
+
* @param initializable The Boolean that specifies if the contract must be initialized or not
|
|
407
|
+
* @param initializeCalldata The calldata to be executed on the created contract if `initializable` is set to `true`
|
|
408
|
+
* @param providedSalt The salt provided by the deployer, which will be used to generate the final salt
|
|
409
|
+
* that will be used by the `CREATE2` opcode for contract deployment
|
|
410
|
+
*
|
|
411
|
+
* @return The generated salt which will be used for CREATE2 deployment
|
|
213
412
|
*/
|
|
214
413
|
function generateSalt(
|
|
414
|
+
bytes32 providedSalt,
|
|
215
415
|
bool initializable,
|
|
216
|
-
bytes memory
|
|
217
|
-
bytes32 providedSalt
|
|
416
|
+
bytes memory initializeCalldata
|
|
218
417
|
) public pure virtual returns (bytes32) {
|
|
219
418
|
if (initializable) {
|
|
220
|
-
return
|
|
419
|
+
return
|
|
420
|
+
keccak256(
|
|
421
|
+
abi.encodePacked(true, initializeCalldata, providedSalt)
|
|
422
|
+
);
|
|
221
423
|
} else {
|
|
222
|
-
return keccak256(abi.encodePacked(
|
|
424
|
+
return keccak256(abi.encodePacked(false, providedSalt));
|
|
223
425
|
}
|
|
224
426
|
}
|
|
225
427
|
|
|
226
428
|
/**
|
|
227
|
-
* @dev Verifies that the contract created was initialized correctly
|
|
228
|
-
* Bubble the revert reason if present, revert with `
|
|
429
|
+
* @dev Verifies that the contract created was initialized correctly.
|
|
430
|
+
* Bubble the revert reason if present, revert with `ContractInitializationFailed` otherwise.
|
|
229
431
|
*/
|
|
230
|
-
function _verifyCallResult(
|
|
432
|
+
function _verifyCallResult(
|
|
433
|
+
bool success,
|
|
434
|
+
bytes memory returndata
|
|
435
|
+
) internal pure virtual {
|
|
231
436
|
if (!success) {
|
|
232
437
|
// Look for revert reason and bubble it up if present
|
|
233
438
|
if (returndata.length != 0) {
|
|
@@ -239,7 +444,7 @@ contract LSP16UniversalFactory {
|
|
|
239
444
|
revert(add(32, returndata), returndata_size)
|
|
240
445
|
}
|
|
241
446
|
} else {
|
|
242
|
-
revert
|
|
447
|
+
revert ContractInitializationFailed();
|
|
243
448
|
}
|
|
244
449
|
}
|
|
245
450
|
}
|