-
Notifications
You must be signed in to change notification settings - Fork 23
/
CMTAT_UUPS_FACTORY.sol
92 lines (81 loc) · 3.48 KB
/
CMTAT_UUPS_FACTORY.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//SPDX-License-Identifier: MPL-2.0
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import "../CMTAT_PROXY_UUPS.sol";
import "@openzeppelin/contracts/utils/Create2.sol";
import "./libraries/CMTATFactoryInvariant.sol";
import "./libraries/CMTATFactoryBase.sol";
/**
* @notice Factory to deploy CMTAT with a UUPS proxy
*
*/
contract CMTAT_UUPS_FACTORY is CMTATFactoryBase {
/**
* @param logic_ contract implementation, cannot be zero
* @param factoryAdmin admin
* @param useCustomSalt_ custom salt with create2 or not
*/
constructor(address logic_, address factoryAdmin, bool useCustomSalt_) CMTATFactoryBase(logic_, factoryAdmin,useCustomSalt_){}
/*//////////////////////////////////////////////////////////////
PUBLIC/EXTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////*/
/**
* @notice deploy a transparent proxy with a proxy admin contract
*/
function deployCMTAT(
bytes32 deploymentSaltInput,
// CMTAT function initialize
CMTAT_ARGUMENT calldata cmtatArgument
) public onlyRole(CMTAT_DEPLOYER_ROLE) returns(ERC1967Proxy cmtat) {
bytes32 deploymentSalt = _checkAndDetermineDeploymentSalt(deploymentSaltInput);
bytes memory bytecode = _getBytecode(
// CMTAT function initialize
cmtatArgument);
cmtat = _deployBytecode(bytecode, deploymentSalt);
return cmtat;
}
/**
* @param deploymentSalt salt for the deployment
* @param cmtatArgument argument for the function initialize
* @notice get the proxy address depending on a particular salt
*/
function computedProxyAddress(
bytes32 deploymentSalt,
// CMTAT function initialize
CMTAT_ARGUMENT calldata cmtatArgument) public view returns (address) {
bytes memory bytecode = _getBytecode(
// CMTAT function initialize
cmtatArgument);
return Create2.computeAddress(deploymentSalt, keccak256(bytecode), address(this) );
}
/*//////////////////////////////////////////////////////////////
INTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////*/
/**
* @notice Deploy CMTAT and push the created CMTAT in the list
*/
function _deployBytecode(bytes memory bytecode, bytes32 deploymentSalt) internal returns (ERC1967Proxy cmtat) {
address cmtatAddress = Create2.deploy(0, deploymentSalt, bytecode);
cmtat = ERC1967Proxy(payable(cmtatAddress));
cmtats[cmtatCounterId] = address(cmtat);
emit CMTAT(address(cmtat), cmtatCounterId);
++cmtatCounterId;
cmtatsList.push(address(cmtat));
return cmtat;
}
/**
* @notice return the smart contract bytecode
*/
function _getBytecode(
// CMTAT function initialize
CMTAT_ARGUMENT calldata cmtatArgument) internal view returns(bytes memory bytecode) {
bytes memory implementation = abi.encodeWithSelector(
CMTAT_PROXY_UUPS(address(0)).initialize.selector,
cmtatArgument.CMTATAdmin,
cmtatArgument.ERC20Attributes,
cmtatArgument.baseModuleAttributes,
cmtatArgument.engines
);
bytecode = abi.encodePacked(type(ERC1967Proxy).creationCode, abi.encode(logic, implementation));
}
}