-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #259 from CMTA/beacon-factory
Contract factory
- Loading branch information
Showing
16 changed files
with
884 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.20; | ||
|
||
import "@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol"; | ||
|
||
import '@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol'; | ||
import "../CMTAT_PROXY.sol"; | ||
import "../modules/CMTAT_BASE.sol"; | ||
import '@openzeppelin/contracts/access/AccessControl.sol'; | ||
contract CMTAT_BEACON_FACTORY is AccessControl { | ||
// Private | ||
mapping(uint256 => address) private cmtats; | ||
uint256 private cmtatCounterId; | ||
// public | ||
/// @dev Role to deploy CMTAT | ||
bytes32 public constant CMTAT_DEPLOYER_ROLE = keccak256("CMTAT_DEPLOYER_ROLE"); | ||
UpgradeableBeacon public immutable beacon; | ||
address[] public cmtatsList; | ||
event CMTAT(address indexed CMTAT, uint256 id); | ||
|
||
/** | ||
* @param implementation_ contract implementation | ||
* @param factoryAdmin admin | ||
* @param beaconOwner owner | ||
*/ | ||
constructor(address implementation_, address factoryAdmin, address beaconOwner) { | ||
beacon = new UpgradeableBeacon(implementation_, beaconOwner); | ||
_grantRole(DEFAULT_ADMIN_ROLE, factoryAdmin); | ||
_grantRole(CMTAT_DEPLOYER_ROLE, factoryAdmin); | ||
} | ||
|
||
/** | ||
* @notice deploy CMTAT with a beacon proxy | ||
* | ||
*/ | ||
function deployCMTAT( | ||
// CMTAT function initialize | ||
address admin, | ||
IAuthorizationEngine authorizationEngineIrrevocable, | ||
string memory nameIrrevocable, | ||
string memory symbolIrrevocable, | ||
uint8 decimalsIrrevocable, | ||
string memory tokenId_, | ||
string memory terms_, | ||
IRuleEngine ruleEngine_, | ||
string memory information_, | ||
uint256 flag_ | ||
) public onlyRole(CMTAT_DEPLOYER_ROLE) returns(BeaconProxy cmtat) { | ||
cmtat = new BeaconProxy( | ||
address(beacon), | ||
abi.encodeWithSelector( | ||
CMTAT_PROXY(address(0)).initialize.selector, | ||
admin, | ||
authorizationEngineIrrevocable, | ||
nameIrrevocable, | ||
symbolIrrevocable, | ||
decimalsIrrevocable, | ||
tokenId_, | ||
terms_, | ||
ruleEngine_, | ||
information_, | ||
flag_ | ||
) | ||
); | ||
cmtats[cmtatCounterId] = address(cmtat); | ||
emit CMTAT(address(cmtat), cmtatCounterId); | ||
cmtatCounterId++; | ||
cmtatsList.push(address(cmtat)); | ||
return cmtat; | ||
} | ||
|
||
/** | ||
* @notice get CMTAT proxy address | ||
* | ||
*/ | ||
function getAddress(uint256 cmtatID_) external view returns (address) { | ||
return cmtats[cmtatID_]; | ||
} | ||
|
||
/** | ||
* @notice get the implementation address from the beacon | ||
* @return implementation address | ||
*/ | ||
function implementation() public view returns (address) { | ||
return beacon.implementation(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.20; | ||
|
||
import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol"; | ||
import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; | ||
import "../CMTAT_PROXY.sol"; | ||
import '@openzeppelin/contracts/access/AccessControl.sol'; | ||
contract CMTAT_TP_FACTORY is AccessControl { | ||
// Private | ||
mapping(uint256 => address) private cmtats; | ||
uint256 private cmtatID; | ||
event CMTAT(address indexed CMTAT, uint256 id); | ||
// Public | ||
/// @dev Role to deploy CMTAT | ||
bytes32 public constant CMTAT_DEPLOYER_ROLE = keccak256("CMTAT_DEPLOYER_ROLE"); | ||
address public immutable logic; | ||
address[] public cmtatsList; | ||
|
||
|
||
/** | ||
* @param logic_ contract implementation | ||
* @param factoryAdmin admin | ||
*/ | ||
constructor(address logic_, address factoryAdmin) { | ||
logic = logic_; | ||
_grantRole(DEFAULT_ADMIN_ROLE, factoryAdmin); | ||
_grantRole(CMTAT_DEPLOYER_ROLE, factoryAdmin); | ||
} | ||
|
||
function deployCMTAT( | ||
address proxyAdminOwner, | ||
// CMTAT function initialize | ||
address admin, | ||
IAuthorizationEngine authorizationEngineIrrevocable, | ||
string memory nameIrrevocable, | ||
string memory symbolIrrevocable, | ||
uint8 decimalsIrrevocable, | ||
string memory tokenId_, | ||
string memory terms_, | ||
IRuleEngine ruleEngine_, | ||
string memory information_, | ||
uint256 flag_ | ||
) public onlyRole(CMTAT_DEPLOYER_ROLE) returns(TransparentUpgradeableProxy cmtat) { | ||
cmtat = new TransparentUpgradeableProxy( | ||
logic, | ||
proxyAdminOwner, | ||
abi.encodeWithSelector( | ||
CMTAT_PROXY(address(0)).initialize.selector, | ||
admin, | ||
authorizationEngineIrrevocable, | ||
nameIrrevocable, | ||
symbolIrrevocable, | ||
decimalsIrrevocable, | ||
tokenId_, | ||
terms_, | ||
ruleEngine_, | ||
information_, | ||
flag_ | ||
) | ||
); | ||
cmtats[cmtatID] = address(cmtat); | ||
emit CMTAT(address(cmtat), cmtatID); | ||
cmtatID++; | ||
cmtatsList.push(address(cmtat)); | ||
return cmtat; | ||
} | ||
|
||
/** | ||
* @notice get CMTAT proxy address | ||
* | ||
*/ | ||
function getAddress(uint256 cmtatID_) external view returns (address) { | ||
return cmtats[cmtatID_]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.