diff --git a/contracts/CMTAT_STANDALONE.sol b/contracts/CMTAT_STANDALONE.sol index 29fbed43..ad52c01a 100644 --- a/contracts/CMTAT_STANDALONE.sol +++ b/contracts/CMTAT_STANDALONE.sol @@ -28,7 +28,7 @@ contract CMTAT_STANDALONE is CMTAT_BASE { uint8 decimalsIrrevocable, string memory tokenId_, string memory terms_, - IERC1404Wrapper ruleEngine_, + IRuleEngineCMTAT ruleEngine_, string memory information_, uint256 flag_ ) MetaTxModule(forwarderIrrevocable) { diff --git a/contracts/interfaces/draft-IERC1404/IRuleEngineCMTAT.sol b/contracts/interfaces/draft-IERC1404/IRuleEngineCMTAT.sol new file mode 100644 index 00000000..40e34023 --- /dev/null +++ b/contracts/interfaces/draft-IERC1404/IRuleEngineCMTAT.sol @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: MPL-2.0 + +pragma solidity ^0.8.0; + +import "./draft-IERC1404Wrapper.sol"; + +interface IRuleEngineCMTAT is IERC1404Wrapper { + /** + * @dev Returns true if the operation is a success, and false otherwise. + */ + function operateOnTransfer( + address _from, + address _to, + uint256 _amount + ) external returns (bool isValid); + +} diff --git a/contracts/mocks/RuleEngine/RuleEngineMock.sol b/contracts/mocks/RuleEngine/RuleEngineMock.sol index 46473108..5bd94774 100644 --- a/contracts/mocks/RuleEngine/RuleEngineMock.sol +++ b/contracts/mocks/RuleEngine/RuleEngineMock.sol @@ -67,6 +67,16 @@ contract RuleEngineMock is IRuleEngine { return detectTransferRestriction(_from, _to, _amount) == 0; } + /* + @dev + Warning: if you want to use this mock, you have to restrict the access to this function through an an access control + */ + function operateOnTransfer( address _from, + address _to, + uint256 _amount) public override returns (bool){ + return validateTransfer(_from, _to, _amount); + } + /** @dev For all the rules, each restriction code has to be unique. diff --git a/contracts/mocks/RuleEngine/interfaces/IRuleEngine.sol b/contracts/mocks/RuleEngine/interfaces/IRuleEngine.sol index 44720657..f7a5b4bc 100644 --- a/contracts/mocks/RuleEngine/interfaces/IRuleEngine.sol +++ b/contracts/mocks/RuleEngine/interfaces/IRuleEngine.sol @@ -3,9 +3,9 @@ pragma solidity ^0.8.0; import "./IRule.sol"; -import "../../../interfaces/draft-IERC1404/draft-IERC1404Wrapper.sol"; +import "../../../interfaces/draft-IERC1404/IRuleEngineCMTAT.sol"; -interface IRuleEngine is IERC1404Wrapper { +interface IRuleEngine is IRuleEngineCMTAT { /** * @dev define the rules, the precedent rules will be overwritten */ diff --git a/contracts/modules/CMTAT_BASE.sol b/contracts/modules/CMTAT_BASE.sol index 395a17f6..59da035a 100644 --- a/contracts/modules/CMTAT_BASE.sol +++ b/contracts/modules/CMTAT_BASE.sol @@ -62,8 +62,8 @@ abstract contract CMTAT_BASE is uint8 decimalsIrrevocable, string memory tokenId_, string memory terms_, - IERC1404Wrapper ruleEngine_, - string memory information_, + IRuleEngineCMTAT ruleEngine_, + string memory information_, uint256 flag_ ) public initializer { __CMTAT_init( @@ -91,7 +91,7 @@ abstract contract CMTAT_BASE is uint8 decimalsIrrevocable, string memory tokenId_, string memory terms_, - IERC1404Wrapper ruleEngine_, + IRuleEngineCMTAT ruleEngine_, string memory information_, uint256 flag_ ) internal onlyInitializing { @@ -183,7 +183,7 @@ abstract contract CMTAT_BASE is address to, uint256 amount ) internal override(ERC20Upgradeable) { - if (!ValidationModule.validateTransfer(from, to, amount)) { + if (!ValidationModule._operateOnTransfer(from, to, amount)) { revert Errors.CMTAT_InvalidTransfer(from, to, amount); } /* diff --git a/contracts/modules/internal/ERC20SnapshotModuleInternal.sol b/contracts/modules/internal/ERC20SnapshotModuleInternal.sol index 83c1a91d..f80ec992 100644 --- a/contracts/modules/internal/ERC20SnapshotModuleInternal.sol +++ b/contracts/modules/internal/ERC20SnapshotModuleInternal.sol @@ -29,19 +29,6 @@ abstract contract ERC20SnapshotModuleInternal is SnapshotModuleBase, ERC20Upgrad */ uint256[] private _scheduledSnapshots; - /** - * @dev Initializes the contract - */ - function __ERC20Snapshot_init( - string memory name_, - string memory symbol_ - ) internal onlyInitializing { - __Context_init_unchained(); - __ERC20_init(name_, symbol_); - __SnapshotModuleBase_init_unchained(); - __ERC20Snapshot_init_unchained(); - } - function __ERC20Snapshot_init_unchained() internal onlyInitializing { // Nothing to do // _currentSnapshotTime & _currentSnapshotIndex are initialized to zero diff --git a/contracts/modules/internal/EnforcementModuleInternal.sol b/contracts/modules/internal/EnforcementModuleInternal.sol index 173db731..63230bfb 100644 --- a/contracts/modules/internal/EnforcementModuleInternal.sol +++ b/contracts/modules/internal/EnforcementModuleInternal.sol @@ -37,14 +37,6 @@ abstract contract EnforcementModuleInternal is mapping(address => bool) private _frozen; - /** - * @dev Initializes the contract - */ - function __Enforcement_init() internal onlyInitializing { - __Context_init_unchained(); - __Enforcement_init_unchained(); - } - function __Enforcement_init_unchained() internal onlyInitializing { // no variable to initialize } diff --git a/contracts/modules/internal/ValidationModuleInternal.sol b/contracts/modules/internal/ValidationModuleInternal.sol index 12c03c3e..f780fef5 100644 --- a/contracts/modules/internal/ValidationModuleInternal.sol +++ b/contracts/modules/internal/ValidationModuleInternal.sol @@ -5,7 +5,7 @@ pragma solidity ^0.8.20; import "../../../openzeppelin-contracts-upgradeable/contracts/utils/ContextUpgradeable.sol"; import "../../../openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol"; import "../../interfaces/draft-IERC1404/draft-IERC1404Wrapper.sol"; - +import "../../interfaces/draft-IERC1404/IRuleEngineCMTAT.sol"; /** * @dev Validation module. * @@ -18,22 +18,12 @@ abstract contract ValidationModuleInternal is /** * @dev Emitted when a rule engine is set. */ - event RuleEngine(IERC1404Wrapper indexed newRuleEngine); - - IERC1404Wrapper public ruleEngine; + event RuleEngine(IRuleEngineCMTAT indexed newRuleEngine); - /** - * @dev Initializes the contract with rule engine. - */ - function __Validation_init( - IERC1404Wrapper ruleEngine_ - ) internal onlyInitializing { - __Context_init_unchained(); - __Validation_init_unchained(ruleEngine_); - } + IRuleEngineCMTAT public ruleEngine; function __Validation_init_unchained( - IERC1404Wrapper ruleEngine_ + IRuleEngineCMTAT ruleEngine_ ) internal onlyInitializing { if (address(ruleEngine_) != address(0)) { ruleEngine = ruleEngine_; @@ -72,5 +62,9 @@ abstract contract ValidationModuleInternal is return ruleEngine.detectTransferRestriction(from, to, amount); } + function _operateOnTransfer(address from, address to, uint256 amount) virtual internal returns (bool) { + return ruleEngine.operateOnTransfer(from, to, amount); + } + uint256[50] private __gap; } diff --git a/contracts/modules/security/AuthorizationModule.sol b/contracts/modules/security/AuthorizationModule.sol index 43dbf630..2df2a049 100644 --- a/contracts/modules/security/AuthorizationModule.sol +++ b/contracts/modules/security/AuthorizationModule.sol @@ -24,23 +24,6 @@ abstract contract AuthorizationModule is AccessControlDefaultAdminRulesUpgradeab // SnapshotModule bytes32 public constant SNAPSHOOTER_ROLE = keccak256("SNAPSHOOTER_ROLE"); - - - function __AuthorizationModule_init( - address admin, - uint48 initialDelay - ) internal onlyInitializing { - /* OpenZeppelin */ - __Context_init_unchained(); - // AccessControlUpgradeable inherits from ERC165Upgradeable - __ERC165_init_unchained(); - __AccessControl_init_unchained(); - __AccessControlDefaultAdminRules_init_unchained(initialDelay, admin); - - /* own function */ - __AuthorizationModule_init_unchained(); - } - /** * @dev * diff --git a/contracts/modules/wrapper/controllers/ValidationModule.sol b/contracts/modules/wrapper/controllers/ValidationModule.sol index d7b0ed86..ef699c20 100644 --- a/contracts/modules/wrapper/controllers/ValidationModule.sol +++ b/contracts/modules/wrapper/controllers/ValidationModule.sol @@ -33,7 +33,7 @@ abstract contract ValidationModule is @param ruleEngine_ the call will be reverted if the new value of ruleEngine is the same as the current one */ function setRuleEngine( - IERC1404Wrapper ruleEngine_ + IRuleEngineCMTAT ruleEngine_ ) external onlyRole(DEFAULT_ADMIN_ROLE) { if (ruleEngine == ruleEngine_) revert Errors.CMTAT_ValidationModule_SameValue(); @@ -97,13 +97,24 @@ abstract contract ValidationModule is return TEXT_UNKNOWN_CODE; } } + + function validateTransferByModule( + address from, + address to, + uint256 /*amount*/ + ) internal view returns (bool) { + if (paused() || frozen(from) || frozen(to)) { + return false; + } + return true; + } function validateTransfer( address from, address to, uint256 amount ) public view override returns (bool) { - if (paused() || frozen(from) || frozen(to)) { + if (!validateTransferByModule(from, to, amount)) { return false; } if (address(ruleEngine) != address(0)) { @@ -112,5 +123,15 @@ abstract contract ValidationModule is return true; } + function _operateOnTransfer(address from, address to, uint256 amount) override internal returns (bool){ + if (!validateTransferByModule(from, to, amount)){ + return false; + } + if (address(ruleEngine) != address(0)) { + return ValidationModuleInternal._operateOnTransfer(from, to, amount); + } + return true; + } + uint256[50] private __gap; } diff --git a/contracts/test/CMTATSnapshot/CMTATSnapshotStandaloneTest.sol b/contracts/test/CMTATSnapshot/CMTATSnapshotStandaloneTest.sol index 654c6b5d..d372faac 100644 --- a/contracts/test/CMTATSnapshot/CMTATSnapshotStandaloneTest.sol +++ b/contracts/test/CMTATSnapshot/CMTATSnapshotStandaloneTest.sol @@ -27,7 +27,7 @@ contract CMTATSnapshotStandaloneTest is CMTAT_BASE_SnapshotTest { uint8 decimalsIrrevocable, string memory tokenId_, string memory terms_, - IERC1404Wrapper ruleEngine_, + IRuleEngineCMTAT ruleEngine_, string memory information_, uint256 flag_ ) MetaTxModule(forwarderIrrevocable) { diff --git a/contracts/test/CMTATSnapshot/CMTAT_BASE_SnapshotTest.sol b/contracts/test/CMTATSnapshot/CMTAT_BASE_SnapshotTest.sol index a86567b7..2b051940 100644 --- a/contracts/test/CMTATSnapshot/CMTAT_BASE_SnapshotTest.sol +++ b/contracts/test/CMTATSnapshot/CMTAT_BASE_SnapshotTest.sol @@ -53,7 +53,7 @@ abstract contract CMTAT_BASE_SnapshotTest is uint8 decimalsIrrevocable, string memory tokenId_, string memory terms_, - IERC1404Wrapper ruleEngine_, + IRuleEngineCMTAT ruleEngine_, string memory information_, uint256 flag_ ) public initializer { @@ -82,7 +82,7 @@ abstract contract CMTAT_BASE_SnapshotTest is uint8 decimalsIrrevocable, string memory tokenId_, string memory terms_, - IERC1404Wrapper ruleEngine_, + IRuleEngineCMTAT ruleEngine_, string memory information_, uint256 flag_ ) internal onlyInitializing { @@ -177,8 +177,7 @@ abstract contract CMTAT_BASE_SnapshotTest is address to, uint256 amount ) internal override(ERC20Upgradeable) { - - if (!ValidationModule.validateTransfer(from, to, amount)){ + if (!ValidationModule._operateOnTransfer(from, to, amount)){ revert Errors.CMTAT_InvalidTransfer(from, to, amount); } /*