Skip to content

Commit

Permalink
Add engine as argument + ERC-7201
Browse files Browse the repository at this point in the history
  • Loading branch information
rya-sge committed Aug 5, 2024
1 parent 51e0f0c commit a0c082b
Show file tree
Hide file tree
Showing 26 changed files with 180 additions and 169 deletions.
17 changes: 6 additions & 11 deletions contracts/CMTAT_PROXY_UUPS.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
pragma solidity ^0.8.20;
import "../openzeppelin-contracts-upgradeable/contracts/proxy/utils/UUPSUpgradeable.sol";
import "./modules/CMTAT_BASE.sol";

import "./interfaces/engine/IEngine.sol";
contract CMTAT_PROXY_UUPS is CMTAT_BASE, UUPSUpgradeable {
/**
* @notice Contract version for the deployment with a proxy
Expand All @@ -27,30 +27,25 @@ contract CMTAT_PROXY_UUPS is CMTAT_BASE, UUPSUpgradeable {
* @param decimalsIrrevocable number of decimals of the token, must be 0 to be compliant with Swiss law as per CMTAT specifications (non-zero decimal number may be needed for other use cases)
* @param tokenId_ name of the tokenId
* @param terms_ terms associated with the token
* @param ruleEngine_ address of the ruleEngine to apply rules to transfers
* @param information_ additional information to describe the token
* @param flag_ add information under the form of bit(0, 1)
* @param engines list of engines
*/
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 override initializer {
string memory information_,
IEngine.Engine memory engines) public override initializer {
CMTAT_BASE.initialize( admin,
authorizationEngineIrrevocable,
nameIrrevocable,
symbolIrrevocable,
decimalsIrrevocable,
tokenId_,
terms_,
ruleEngine_,
information_,
flag_);
information_,
engines);
__UUPSUpgradeable_init_unchained();
}

Expand Down
10 changes: 2 additions & 8 deletions contracts/CMTAT_STANDALONE.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,31 @@ contract CMTAT_STANDALONE is CMTAT_BASE {
* @param decimalsIrrevocable number of decimals used to get its user representation, should be 0 to be compliant with the CMTAT specifications.
* @param tokenId_ name of the tokenId
* @param terms_ terms associated with the token
* @param ruleEngine_ address of the ruleEngine to apply rules to transfers
* @param information_ additional information to describe the token
* @param flag_ add information under the form of bit(0, 1)
*/
/// @custom:oz-upgrades-unsafe-allow constructor
constructor(
address forwarderIrrevocable,
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_
IEngine.Engine memory engine_
) MetaTxModule(forwarderIrrevocable) {
// Initialize the contract to avoid front-running
// Warning : do not initialize the proxy
initialize(
admin,
authorizationEngineIrrevocable,
nameIrrevocable,
symbolIrrevocable,
decimalsIrrevocable,
tokenId_,
terms_,
ruleEngine_,
information_,
flag_
engine_
);
}

Expand Down
11 changes: 4 additions & 7 deletions contracts/deployment/CMTAT_BEACON_FACTORY.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import "../CMTAT_PROXY.sol";
import "../modules/CMTAT_BASE.sol";
import "../libraries/FactoryErrors.sol";
import '@openzeppelin/contracts/access/AccessControl.sol';
import "../interfaces/engine/IEngine.sol";

/**
* @notice Factory to deploy beacon proxy
Expand Down Expand Up @@ -51,30 +52,26 @@ contract CMTAT_BEACON_FACTORY is AccessControl {
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_
IEngine.Engine memory engines
) 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_
information_,
engines
)
);
cmtats[cmtatCounterId] = address(cmtat);
Expand Down
21 changes: 7 additions & 14 deletions contracts/deployment/CMTAT_TP_FACTORY.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "../CMTAT_PROXY.sol";
import "../libraries/FactoryErrors.sol";
import '@openzeppelin/contracts/utils/Create2.sol';
import '@openzeppelin/contracts/access/AccessControl.sol';
import "../interfaces/engine/IEngine.sol";

/**
* @notice Factory to deploy CMTAT with a transparent proxy
Expand All @@ -25,15 +26,13 @@ contract CMTAT_TP_FACTORY is AccessControl {

struct CMTAT_ARGUMENT{
address CMTATAdmin;
IAuthorizationEngine authorizationEngineIrrevocable;
string nameIrrevocable;
string symbolIrrevocable;
uint8 decimalsIrrevocable;
string tokenId;
string terms;
IRuleEngine ruleEngine;
string information;
uint256 flag;
string information;
IEngine.Engine engines;
}
event CMTAT(address indexed CMTAT, uint256 id);

Expand Down Expand Up @@ -140,42 +139,36 @@ contract CMTAT_TP_FACTORY is AccessControl {
CMTAT_ARGUMENT calldata cmtatArgument) internal view returns(bytes memory bytecode) {
bytes memory implementation = _encodeImplementationArgument(
cmtatArgument.CMTATAdmin,
cmtatArgument.authorizationEngineIrrevocable,
cmtatArgument.nameIrrevocable,
cmtatArgument.symbolIrrevocable,
cmtatArgument.decimalsIrrevocable,
cmtatArgument.tokenId,
cmtatArgument.terms,
cmtatArgument.ruleEngine,
cmtatArgument.information,
cmtatArgument.flag
cmtatArgument.engines
);
bytecode = abi.encodePacked(type(TransparentUpgradeableProxy).creationCode, abi.encode(logic, proxyAdminOwner, implementation));
}


function _encodeImplementationArgument( 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_) internal pure returns(bytes memory){
IEngine.Engine memory engines) internal pure returns(bytes memory){
return abi.encodeWithSelector(
CMTAT_PROXY(address(0)).initialize.selector,
admin,
authorizationEngineIrrevocable,
nameIrrevocable,
symbolIrrevocable,
decimalsIrrevocable,
tokenId_,
terms_,
ruleEngine_,
information_,
flag_
information_,
engines
);
}
}
21 changes: 21 additions & 0 deletions contracts/interfaces/engine/IEngine.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//SPDX-License-Identifier: MPL-2.0
import "./IDebtEngine.sol";
import "./IRuleEngine.sol";
import "./IAuthorizationEngine.sol";
import "./draft-IERC1643.sol";

pragma solidity ^0.8.20;

/**
* @notice interface to represent debt tokens
*/
interface IEngine {
struct Engine {
IRuleEngine ruleEngine;
IDebtEngine debtEngine;
IAuthorizationEngine authorizationEngine;
IERC1643 documentEngine;
}


}
File renamed without changes.
27 changes: 10 additions & 17 deletions contracts/modules/CMTAT_BASE.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import "./wrapper/extensions/MetaTxModule.sol";
import "./wrapper/extensions/DebtModule.sol";
import "./wrapper/extensions/DocumentModule.sol";
import "./security/AuthorizationModule.sol";

import "../interfaces/engine/IEngine.sol";
import "../libraries/Errors.sol";

abstract contract CMTAT_BASE is
Expand Down Expand Up @@ -53,33 +53,27 @@ abstract contract CMTAT_BASE is
* @param decimalsIrrevocable number of decimals of the token, must be 0 to be compliant with Swiss law as per CMTAT specifications (non-zero decimal number may be needed for other use cases)
* @param tokenId_ name of the tokenId
* @param terms_ terms associated with the token
* @param ruleEngine_ address of the ruleEngine to apply rules to transfers
* @param information_ additional information to describe the token
* @param flag_ add information under the form of bit(0, 1)
*/
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_
string memory information_,
IEngine.Engine memory engines
) public virtual initializer {
__CMTAT_init(
admin,
authorizationEngineIrrevocable,
nameIrrevocable,
symbolIrrevocable,
decimalsIrrevocable,
tokenId_,
terms_,
ruleEngine_,
information_,
flag_
engines
);
}

Expand All @@ -88,15 +82,13 @@ abstract contract CMTAT_BASE is
*/
function __CMTAT_init(
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_
IEngine.Engine memory engines
) internal onlyInitializing {
/* OpenZeppelin library */
// OZ init_unchained functions are called firstly due to inheritance
Expand All @@ -117,11 +109,11 @@ abstract contract CMTAT_BASE is
__SnapshotModuleBase_init_unchained();
__ERC20Snapshot_init_unchained();

__Validation_init_unchained(ruleEngine_);
__Validation_init_unchained(engines.ruleEngine);

/* Wrapper */
// AuthorizationModule_init_unchained is called firstly due to inheritance
__AuthorizationModule_init_unchained(admin, authorizationEngineIrrevocable);
__AuthorizationModule_init_unchained(admin, engines.authorizationEngine);
__ERC20BurnModule_init_unchained();
__ERC20MintModule_init_unchained();
// EnforcementModule_init_unchained is called before ValidationModule_init_unchained due to inheritance
Expand All @@ -136,10 +128,11 @@ abstract contract CMTAT_BASE is
Add this call in case you add the SnapshotModule
*/
__ERC20SnasphotModule_init_unchained();

__DocumentModule_init_unchained(engines.documentEngine);
__DebtModule_init_unchained(engines.debtEngine);

/* Other modules */
__Base_init_unchained(tokenId_, terms_, information_, flag_);
__Base_init_unchained(tokenId_, terms_, information_);

/* own function */
__CMTAT_init_unchained();
Expand Down
Loading

0 comments on commit a0c082b

Please sign in to comment.