Skip to content

Commit

Permalink
Merge pull request #259 from CMTA/beacon-factory
Browse files Browse the repository at this point in the history
Contract factory
  • Loading branch information
rya-sge authored Jan 18, 2024
2 parents d4f3bc4 + bcef1ea commit a24c322
Show file tree
Hide file tree
Showing 16 changed files with 884 additions and 72 deletions.
87 changes: 87 additions & 0 deletions contracts/deployment/CMTAT_BEACON_FACTORY.sol
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();
}
}
75 changes: 75 additions & 0 deletions contracts/deployment/CMTAT_TP_FACTORY.sol
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_];
}
}
18 changes: 9 additions & 9 deletions contracts/modules/CMTAT_BASE.sol
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,15 @@ abstract contract CMTAT_BASE is
}

/**
@notice burn and mint atomically
@param from current token holder to burn tokens
@param to receiver to send the new minted tokens
@param amountToBurn number of tokens to burn
@param amountToMint number of tokens to mint
@dev
- The access control is managed by the functions burn (ERC20BurnModule) and mint (ERC20MintModule)
- Input validation is also managed by the functions burn and mint
- You can mint more tokens than burnt
* @notice burn and mint atomically
* @param from current token holder to burn tokens
* @param to receiver to send the new minted tokens
* @param amountToBurn number of tokens to burn
* @param amountToMint number of tokens to mint
* @dev
* - The access control is managed by the functions burn (ERC20BurnModule) and mint (ERC20MintModule)
* - Input validation is also managed by the functions burn and mint
* - You can mint more tokens than burnt
*/
function burnAndMint(address from, address to, uint256 amountToBurn, uint256 amountToMint, string calldata reason) public {
burn(from, amountToBurn, reason);
Expand Down
6 changes: 3 additions & 3 deletions contracts/modules/internal/ValidationModuleInternal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ abstract contract ValidationModuleInternal is
}

/**
@dev before making a call to this function, you have to check if a ruleEngine is set.
* @dev before making a call to this function, you have to check if a ruleEngine is set.
*/
function _validateTransfer(
address from,
Expand All @@ -43,7 +43,7 @@ abstract contract ValidationModuleInternal is
}

/**
@dev before making a call to this function, you have to check if a ruleEngine is set.
* @dev before making a call to this function, you have to check if a ruleEngine is set.
*/
function _messageForTransferRestriction(
uint8 restrictionCode
Expand All @@ -52,7 +52,7 @@ abstract contract ValidationModuleInternal is
}

/**
@dev before making a call to this function, you have to check if a ruleEngine is set.
* @dev before making a call to this function, you have to check if a ruleEngine is set.
*/
function _detectTransferRestriction(
address from,
Expand Down
Loading

0 comments on commit a24c322

Please sign in to comment.