diff --git a/contracts/CMTAT_STANDALONE.sol b/contracts/CMTAT_STANDALONE.sol deleted file mode 100644 index dfe10c6..0000000 --- a/contracts/CMTAT_STANDALONE.sol +++ /dev/null @@ -1,53 +0,0 @@ -//SPDX-License-Identifier: MPL-2.0 - -pragma solidity ^0.8.20; - -import "./modules/CMTAT_BASE.sol"; - -contract CMTAT_STANDALONE is CMTAT_BASE { - /** - * @notice Contract version for standalone deployment - * @param forwarderIrrevocable address of the forwarder, required for the gasless support - * @param admin address of the admin of contract (Access Control) - * @param authorizationEngineIrrevocable - * @param nameIrrevocable name of the token - * @param symbolIrrevocable name of the symbol - * @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_ - ) 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_ - ); - } - - // No storage gap because the contract is deployed in standalone mode -} diff --git a/contracts/deployment/CMTAT_BEACON_FACTORY.sol b/contracts/deployment/CMTAT_BEACON_FACTORY.sol deleted file mode 100644 index 7065535..0000000 --- a/contracts/deployment/CMTAT_BEACON_FACTORY.sol +++ /dev/null @@ -1,92 +0,0 @@ -// 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'; - -/** -* @notice Factory to deploy beacon proxy -* -*/ -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(); - } -} \ No newline at end of file diff --git a/contracts/deployment/CMTAT_TP_FACTORY.sol b/contracts/deployment/CMTAT_TP_FACTORY.sol deleted file mode 100644 index 1cf37ab..0000000 --- a/contracts/deployment/CMTAT_TP_FACTORY.sol +++ /dev/null @@ -1,78 +0,0 @@ -// 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'; -/** -* @notice Factory to deploy transparent proxy -* -*/ -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_]; - } -} \ No newline at end of file diff --git a/contracts/interfaces/ICCIPToken.sol b/contracts/interfaces/ICCIPToken.sol deleted file mode 100644 index 4ab3564..0000000 --- a/contracts/interfaces/ICCIPToken.sol +++ /dev/null @@ -1,20 +0,0 @@ -//SPDX-License-Identifier: MPL-2.0 - -pragma solidity ^0.8.0; - -interface ICCIPMintERC20 { - /// @notice Mints new tokens for a given address. - /// @param account The address to mint the new tokens to. - /// @param value The number of tokens to be minted. - /// @dev this function increases the total supply. - function mint(address account, uint256 value) external; -} - -interface ICCIPBurnFromERC20 { - /// @notice Burns tokens from a given address.. - /// @param account The address to burn tokens from. - /// @param value The number of tokens to be burned. - /// @dev this function decreases the total supply. - function burnFrom(address account, uint256 value) external; - -} \ No newline at end of file diff --git a/contracts/interfaces/engine/IAuthorizationEngine.sol b/contracts/interfaces/engine/IAuthorizationEngine.sol deleted file mode 100644 index fed67bc..0000000 --- a/contracts/interfaces/engine/IAuthorizationEngine.sol +++ /dev/null @@ -1,20 +0,0 @@ -// SPDX-License-Identifier: MPL-2.0 - -pragma solidity ^0.8.0; - -interface IAuthorizationEngine { - /** - * @dev Returns true if the operation is authorized, and false otherwise. - */ - function operateOnGrantRole( - bytes32 role, address account - ) external returns (bool isValid); - - /** - * @dev Returns true if the operation is authorized, and false otherwise. - */ - function operateOnRevokeRole( - bytes32 role, address account - ) external returns (bool isValid); - -} diff --git a/contracts/interfaces/engine/IRuleEngine.sol b/contracts/interfaces/engine/IRuleEngine.sol deleted file mode 100644 index 7c52321..0000000 --- a/contracts/interfaces/engine/IRuleEngine.sol +++ /dev/null @@ -1,17 +0,0 @@ -// SPDX-License-Identifier: MPL-2.0 - -pragma solidity ^0.8.0; - -import "../draft-IERC1404/draft-IERC1404Wrapper.sol"; - -interface IRuleEngine 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/libraries/Errors.sol b/contracts/libraries/Errors.sol deleted file mode 100644 index 28840db..0000000 --- a/contracts/libraries/Errors.sol +++ /dev/null @@ -1,66 +0,0 @@ -//SPDX-License-Identifier: MPL-2.0 - -pragma solidity ^0.8.20; - -library Errors { - // CMTAT - error CMTAT_InvalidTransfer(address from, address to, uint256 amount); - - // SnapshotModule - error CMTAT_SnapshotModule_SnapshotScheduledInThePast( - uint256 time, - uint256 timestamp - ); - error CMTAT_SnapshotModule_SnapshotTimestampBeforeLastSnapshot( - uint256 time, - uint256 lastSnapshotTimestamp - ); - error CMTAT_SnapshotModule_SnapshotTimestampAfterNextSnapshot( - uint256 time, - uint256 nextSnapshotTimestamp - ); - error CMTAT_SnapshotModule_SnapshotTimestampBeforePreviousSnapshot( - uint256 time, - uint256 previousSnapshotTimestamp - ); - error CMTAT_SnapshotModule_SnapshotAlreadyExists(); - error CMTAT_SnapshotModule_SnapshotAlreadyDone(); - error CMTAT_SnapshotModule_NoSnapshotScheduled(); - error CMTAT_SnapshotModule_SnapshotNotFound(); - - // ERC20BaseModule - error CMTAT_ERC20BaseModule_WrongAllowance( - address spender, - uint256 currentAllowance, - uint256 allowanceProvided - ); - - // BurnModule - error CMTAT_BurnModule_EmptyAccounts(); - error CMTAT_BurnModule_AccountsValueslengthMismatch(); - - // MintModule - error CMTAT_MintModule_EmptyAccounts(); - error CMTAT_MintModule_AccountsValueslengthMismatch(); - - // ERC20BaseModule - error CMTAT_ERC20BaseModule_EmptyTos(); - error CMTAT_ERC20BaseModule_TosValueslengthMismatch(); - - // DebtModule - error CMTAT_DebtModule_SameValue(); - - // BaseModule - error CMTAT_BaseModule_SameValue(); - - // ValidationModule - error CMTAT_ValidationModule_SameValue(); - - // AuthorizationModule - error CMTAT_AuthorizationModule_AddressZeroNotAllowed(); - error CMTAT_AuthorizationModule_InvalidAuthorization(); - error CMTAT_AuthorizationModule_AuthorizationEngineAlreadySet(); - - // PauseModule - error CMTAT_PauseModule_ContractIsDeactivated(); -} diff --git a/contracts/mocks/AuthorizationEngineMock.sol b/contracts/mocks/AuthorizationEngineMock.sol deleted file mode 100644 index e6dad25..0000000 --- a/contracts/mocks/AuthorizationEngineMock.sol +++ /dev/null @@ -1,60 +0,0 @@ -//SPDX-License-Identifier: MPL-2.0 - -pragma solidity ^0.8.20; - -import "../interfaces/engine/IAuthorizationEngine.sol"; - -/* -@title a mock for testing, not suitable for production -*/ -contract AuthorizationEngineMock is IAuthorizationEngine { - address nextAdmin; - bool revokeAdminRoleAuthorized; - constructor() { - revokeAdminRoleAuthorized = true; - } - - /* - * @dev - * Warning: if you want to use this mock, you have to restrict the access to this function through an an access control - */ - function authorizeAdminChange(address newAdmin) external { - nextAdmin = newAdmin; - } - - function setRevokeAdminRoleAuthorized(bool - newValue) external { - revokeAdminRoleAuthorized = newValue; - } - - /* - * @dev - * Warning: if you want to use this mock, you have to restrict the access to this function through an an access control - */ - function operateOnGrantRole( - bytes32 role, address account - ) external returns (bool isValid){ - if(role == 0x0 && account == nextAdmin && account != address(0x0)){ - // Reset to 0 - nextAdmin = address(0x0); - return true; - }else{ - return false; - } - } - - /* - * @dev - * Warning: if you want to use this mock, you have to restrict the access to this function through an an access control - */ - function operateOnRevokeRole( - bytes32 role, address /*account*/ - ) external view returns (bool isValid){ - if(role == 0x0){ - return revokeAdminRoleAuthorized; - } else{ - // the tests will fail if this branch is taken - return !revokeAdminRoleAuthorized; - } - } -} diff --git a/contracts/mocks/RuleEngine/RuleEngineMock.sol b/contracts/mocks/RuleEngine/RuleEngineMock.sol deleted file mode 100644 index 409b515..0000000 --- a/contracts/mocks/RuleEngine/RuleEngineMock.sol +++ /dev/null @@ -1,99 +0,0 @@ -//SPDX-License-Identifier: MPL-2.0 - -pragma solidity ^0.8.20; - -import "./interfaces/IRule.sol"; -import "./interfaces/IRuleEngineMock.sol"; -import "./RuleMock.sol"; -import "./CodeList.sol"; - -/* -@title a mock for testing, not suitable for production -*/ -contract RuleEngineMock is IRuleEngineMock { - IRule[] internal _rules; - - constructor() { - _rules.push(new RuleMock()); - } - - /* - * @dev - * Warning: if you want to use this mock, you have to restrict the access to this function through an an access control - */ - function setRules(IRule[] calldata rules_) external override { - _rules = rules_; - } - - function rulesCount() external view override returns (uint256) { - return _rules.length; - } - - function rule(uint256 ruleId) external view override returns (IRule) { - return _rules[ruleId]; - } - - function rules() external view override returns (IRule[] memory) { - return _rules; - } - - function detectTransferRestriction( - address _from, - address _to, - uint256 _amount - ) public view override returns (uint8) { - uint256 ruleArrayLength = _rules.length; - for (uint256 i; i < ruleArrayLength; ) { - uint8 restriction = _rules[i].detectTransferRestriction( - _from, - _to, - _amount - ); - if (restriction != uint8(REJECTED_CODE_BASE.TRANSFER_OK)) { - return restriction; - } - unchecked { - ++i; - } - } - return uint8(REJECTED_CODE_BASE.TRANSFER_OK); - } - - function validateTransfer( - address _from, - address _to, - uint256 _amount - ) public view override returns (bool) { - 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) view public override returns (bool){ - return validateTransfer(_from, _to, _amount); - } - - /** - * @dev - * For all the rules, each restriction code has to be unique. - */ - function messageForTransferRestriction( - uint8 _restrictionCode - ) public view override returns (string memory) { - uint256 ruleArrayLength = _rules.length; - for (uint256 i; i < ruleArrayLength; ) { - if (_rules[i].canReturnTransferRestrictionCode(_restrictionCode)) { - return - _rules[i].messageForTransferRestriction(_restrictionCode); - } - unchecked { - ++i; - } - } - return "Unknown restriction code"; - } -} diff --git a/contracts/mocks/RuleEngine/interfaces/IRuleEngineMock.sol b/contracts/mocks/RuleEngine/interfaces/IRuleEngineMock.sol deleted file mode 100644 index 0257418..0000000 --- a/contracts/mocks/RuleEngine/interfaces/IRuleEngineMock.sol +++ /dev/null @@ -1,28 +0,0 @@ -//SPDX-License-Identifier: MPL-2.0 - -pragma solidity ^0.8.0; - -import "./IRule.sol"; -import "../../../interfaces/engine/IRuleEngine.sol"; - -interface IRuleEngineMock is IRuleEngine { - /** - * @dev define the rules, the precedent rules will be overwritten - */ - function setRules(IRule[] calldata rules_) external; - - /** - * @dev return the number of rules - */ - function rulesCount() external view returns (uint256); - - /** - * @dev return the rule at the index specified by ruleId - */ - function rule(uint256 ruleId) external view returns (IRule); - - /** - * @dev return all the rules - */ - function rules() external view returns (IRule[] memory); -} diff --git a/contracts/modules/CMTAT_BASE.sol b/contracts/modules/CMTAT_BASE.sol deleted file mode 100644 index 8c0d1a0..0000000 --- a/contracts/modules/CMTAT_BASE.sol +++ /dev/null @@ -1,250 +0,0 @@ -//SPDX-License-Identifier: MPL-2.0 - -pragma solidity ^0.8.20; - -// required OZ imports here -import "../../openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol"; -import "../../openzeppelin-contracts-upgradeable/contracts/utils/ContextUpgradeable.sol"; - -import "./wrapper/core/BaseModule.sol"; -import "./wrapper/core/ERC20BurnModule.sol"; -import "./wrapper/core/ERC20MintModule.sol"; -import "./wrapper/core/EnforcementModule.sol"; -import "./wrapper/core/ERC20BaseModule.sol"; -import "./wrapper/core/PauseModule.sol"; -/* -SnapshotModule: -Add this import in case you add the SnapshotModule -*/ -import "./wrapper/extensions/ERC20SnapshotModule.sol"; - -import "./wrapper/controllers/ValidationModule.sol"; -import "./wrapper/extensions/MetaTxModule.sol"; -import "./wrapper/extensions/DebtModule/DebtBaseModule.sol"; -import "./wrapper/extensions/DebtModule/CreditEventsModule.sol"; -import "./security/AuthorizationModule.sol"; - -import "../libraries/Errors.sol"; - -abstract contract CMTAT_BASE is - Initializable, - ContextUpgradeable, - BaseModule, - PauseModule, - ERC20MintModule, - ERC20BurnModule, - EnforcementModule, - ValidationModule, - MetaTxModule, - ERC20BaseModule, - ERC20SnapshotModule, - DebtBaseModule, - CreditEventsModule -{ - /** - * @notice - * initialize the proxy contract - * The calls to this function will revert if the contract was deployed without a proxy - * @param admin address of the admin of contract (Access Control) - * @param nameIrrevocable name of the token - * @param symbolIrrevocable name of the symbol - * @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_ - ) public initializer { - __CMTAT_init( - admin, - authorizationEngineIrrevocable, - nameIrrevocable, - symbolIrrevocable, - decimalsIrrevocable, - tokenId_, - terms_, - ruleEngine_, - information_, - flag_ - ); - } - - /** - * @dev calls the different initialize functions from the different modules - */ - 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_ - ) internal onlyInitializing { - /* OpenZeppelin library */ - // OZ init_unchained functions are called firstly due to inheritance - __Context_init_unchained(); - __ERC20_init_unchained(nameIrrevocable, symbolIrrevocable); - // AccessControlUpgradeable inherits from ERC165Upgradeable - __ERC165_init_unchained(); - // AuthorizationModule inherits from AccessControlUpgradeable - __AccessControl_init_unchained(); - __Pausable_init_unchained(); - - /* Internal Modules */ - __Enforcement_init_unchained(); - /* - SnapshotModule: - Add these two calls in case you add the SnapshotModule - */ - __SnapshotModuleBase_init_unchained(); - __ERC20Snapshot_init_unchained(); - - __Validation_init_unchained(ruleEngine_); - - /* Wrapper */ - // AuthorizationModule_init_unchained is called firstly due to inheritance - __AuthorizationModule_init_unchained(admin, authorizationEngineIrrevocable); - __ERC20BurnModule_init_unchained(); - __ERC20MintModule_init_unchained(); - // EnforcementModule_init_unchained is called before ValidationModule_init_unchained due to inheritance - __EnforcementModule_init_unchained(); - __ERC20BaseModule_init_unchained(decimalsIrrevocable); - // PauseModule_init_unchained is called before ValidationModule_init_unchained due to inheritance - __PauseModule_init_unchained(); - __ValidationModule_init_unchained(); - - /* - SnapshotModule: - Add this call in case you add the SnapshotModule - */ - __ERC20SnasphotModule_init_unchained(); - - - /* Other modules */ - __DebtBaseModule_init_unchained(); - __CreditEvents_init_unchained(); - __Base_init_unchained(tokenId_, terms_, information_, flag_); - - /* own function */ - __CMTAT_init_unchained(); - } - - function __CMTAT_init_unchained() internal onlyInitializing { - // no variable to initialize - } - - /** - * @notice Returns the number of decimals used to get its user representation. - */ - function decimals() - public - view - virtual - override(ERC20Upgradeable, ERC20BaseModule) - returns (uint8) - { - return ERC20BaseModule.decimals(); - } - - function transferFrom( - address sender, - address recipient, - uint256 amount - ) - public - virtual - override(ERC20Upgradeable, ERC20BaseModule) - returns (bool) - { - return ERC20BaseModule.transferFrom(sender, recipient, amount); - } - - /** - * @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); - mint(to, amountToMint); - } - - /** - * @dev - * - */ - function _update( - address from, - address to, - uint256 amount - ) internal override(ERC20Upgradeable) { - if (!ValidationModule._operateOnTransfer(from, to, amount)) { - revert Errors.CMTAT_InvalidTransfer(from, to, amount); - } - /* - SnapshotModule: - Add this in case you add the SnapshotModule - We call the SnapshotModule only if the transfer is valid - */ - ERC20SnapshotModuleInternal._snapshotUpdate(from, to); - ERC20Upgradeable._update(from, to, amount); - } - - /************* MetaTx Module *************/ - /** - * @dev This surcharge is not necessary if you do not use the MetaTxModule - */ - function _msgSender() - internal - view - override(ERC2771ContextUpgradeable, ContextUpgradeable) - returns (address sender) - { - return ERC2771ContextUpgradeable._msgSender(); - } - - /** - * @dev This surcharge is not necessary if you do not use the MetaTxModule - */ - function _contextSuffixLength() internal view - override(ERC2771ContextUpgradeable, ContextUpgradeable) - returns (uint256) { - return ERC2771ContextUpgradeable._contextSuffixLength(); - } - - /** - * @dev This surcharge is not necessary if you do not use the MetaTxModule - */ - function _msgData() - internal - view - override(ERC2771ContextUpgradeable, ContextUpgradeable) - returns (bytes calldata) - { - return ERC2771ContextUpgradeable._msgData(); - } - - uint256[50] private __gap; -} diff --git a/contracts/modules/internal/ERC20SnapshotModuleInternal.sol b/contracts/modules/internal/ERC20SnapshotModuleInternal.sol deleted file mode 100644 index ad6c7b9..0000000 --- a/contracts/modules/internal/ERC20SnapshotModuleInternal.sol +++ /dev/null @@ -1,119 +0,0 @@ -//SPDX-License-Identifier: MPL-2.0 - -pragma solidity ^0.8.20; - -import "../../../openzeppelin-contracts-upgradeable/contracts/utils/ContextUpgradeable.sol"; -import "../../../openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol"; -import "../../../openzeppelin-contracts-upgradeable/contracts/token/ERC20/ERC20Upgradeable.sol"; -import {Arrays} from '@openzeppelin/contracts/utils/Arrays.sol'; - -import "../../libraries/Errors.sol"; -import "./base/SnapshotModuleBase.sol"; -/** - * @dev Snapshot module internal. - * - * Useful to take a snapshot of token holder balance and total supply at a specific time - * Inspired by Openzeppelin - ERC20Snapshot but use the time as Id instead of a counter. - * Contrary to OpenZeppelin, the function _getCurrentSnapshotId is not available - because overriding this function can break the contract. - */ - -abstract contract ERC20SnapshotModuleInternal is SnapshotModuleBase, ERC20Upgradeable { - using Arrays for uint256[]; - - - /** - * @dev - * list of scheduled snapshot (time) - * This list is sorted in ascending order - */ - uint256[] private _scheduledSnapshots; - - function __ERC20Snapshot_init_unchained() internal onlyInitializing { - // Nothing to do - // _currentSnapshotTime & _currentSnapshotIndex are initialized to zero - } - - - /** - * @dev Update balance and/or total supply snapshots before the values are modified. This is implemented - * in the _beforeTokenTransfer hook, which is executed for _mint, _burn, and _transfer operations. - */ - function _snapshotUpdate( - address from, - address to - ) internal virtual { - _setCurrentSnapshot(); - if (from != address(0)) { - // for both burn and transfer - _updateAccountSnapshot(from); - if (to != address(0)) { - // transfer - _updateAccountSnapshot(to); - } else { - // burn - _updateTotalSupplySnapshot(); - } - } else { - // mint - _updateAccountSnapshot(to); - _updateTotalSupplySnapshot(); - } - } - - - /** - * @dev See {OpenZeppelin - ERC20Snapshot} - */ - function _updateAccountSnapshot(address account) private { - _updateSnapshot(_accountBalanceSnapshots[account], balanceOf(account)); - } - - /** - * @dev See {OpenZeppelin - ERC20Snapshot} - */ - function _updateTotalSupplySnapshot() private { - _updateSnapshot(_totalSupplySnapshots, totalSupply()); - } - - /** - * @notice Return snapshotBalanceOf and snapshotTotalSupply to avoid multiple calls - * @return ownerBalance , totalSupply - see snapshotBalanceOf and snapshotTotalSupply - */ - function getSnapshotInfoBatch(uint256 time, address owner) public view returns (uint256 ownerBalance, uint256 totalSupply) { - ownerBalance = snapshotBalanceOf(time, owner); - totalSupply = snapshotTotalSupply(time); - } - - - /** - * @notice Return the number of tokens owned by the given owner at the time when the snapshot with the given time was created. - * @return value stored in the snapshot, or the actual balance if no snapshot - */ - function snapshotBalanceOf( - uint256 time, - address owner - ) public view returns (uint256) { - (bool snapshotted, uint256 value) = _valueAt( - time, - _accountBalanceSnapshots[owner] - ); - - return snapshotted ? value : balanceOf(owner); - } - - /** - * @dev See {OpenZeppelin - ERC20Snapshot} - * Retrieves the total supply at the specified time. - * @return value stored in the snapshot, or the actual totalSupply if no snapshot - */ - function snapshotTotalSupply(uint256 time) public view returns (uint256) { - (bool snapshotted, uint256 value) = _valueAt( - time, - _totalSupplySnapshots - ); - return snapshotted ? value : totalSupply(); - } - - uint256[50] private __gap; -} diff --git a/contracts/modules/internal/EnforcementModuleInternal.sol b/contracts/modules/internal/EnforcementModuleInternal.sol deleted file mode 100644 index 63230bf..0000000 --- a/contracts/modules/internal/EnforcementModuleInternal.sol +++ /dev/null @@ -1,88 +0,0 @@ -//SPDX-License-Identifier: MPL-2.0 - -pragma solidity ^0.8.20; - -import "../../../openzeppelin-contracts-upgradeable/contracts/utils/ContextUpgradeable.sol"; -import "../../../openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol"; -import "../../../openzeppelin-contracts-upgradeable/contracts/token/ERC20/ERC20Upgradeable.sol"; - -/** - * @dev Enforcement module. - * - * Allows the issuer to freeze transfers from a given address - */ -abstract contract EnforcementModuleInternal is - Initializable, - ContextUpgradeable -{ - /** - * @notice Emitted when an address is frozen. - */ - event Freeze( - address indexed enforcer, - address indexed owner, - string indexed reasonIndexed, - string reason - ); - - /** - * @notice Emitted when an address is unfrozen. - */ - event Unfreeze( - address indexed enforcer, - address indexed owner, - string indexed reasonIndexed, - string reason - ); - - mapping(address => bool) private _frozen; - - function __Enforcement_init_unchained() internal onlyInitializing { - // no variable to initialize - } - - /** - * @dev Returns true if the account is frozen, and false otherwise. - */ - function frozen(address account) public view virtual returns (bool) { - return _frozen[account]; - } - - /** - * @dev Freezes an address. - * @param account the account to freeze - * @param reason indicate why the account was frozen. - * - */ - function _freeze( - address account, - string calldata reason - ) internal virtual returns (bool) { - if (_frozen[account]) { - return false; - } - _frozen[account] = true; - emit Freeze(_msgSender(), account, reason, reason); - return true; - } - - /** - * @dev Unfreezes an address. - * @param account the account to unfreeze - * @param reason indicate why the account was unfrozen. - */ - function _unfreeze( - address account, - string calldata reason - ) internal virtual returns (bool) { - if (!_frozen[account]) { - return false; - } - _frozen[account] = false; - emit Unfreeze(_msgSender(), account, reason, reason); - - return true; - } - - uint256[50] private __gap; -} diff --git a/contracts/modules/internal/ValidationModuleInternal.sol b/contracts/modules/internal/ValidationModuleInternal.sol deleted file mode 100644 index d66fa00..0000000 --- a/contracts/modules/internal/ValidationModuleInternal.sol +++ /dev/null @@ -1,70 +0,0 @@ -//SPDX-License-Identifier: MPL-2.0 - -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/engine/IRuleEngine.sol"; -/** - * @dev Validation module. - * - * Useful for to restrict and validate transfers - */ -abstract contract ValidationModuleInternal is - Initializable, - ContextUpgradeable -{ - /** - * @dev Emitted when a rule engine is set. - */ - event RuleEngine(IRuleEngine indexed newRuleEngine); - - IRuleEngine public ruleEngine; - - function __Validation_init_unchained( - IRuleEngine ruleEngine_ - ) internal onlyInitializing { - if (address(ruleEngine_) != address(0)) { - ruleEngine = ruleEngine_; - emit RuleEngine(ruleEngine); - } - } - - /** - * @dev before making a call to this function, you have to check if a ruleEngine is set. - */ - function _validateTransfer( - address from, - address to, - uint256 amount - ) internal view returns (bool) { - return ruleEngine.validateTransfer(from, to, amount); - } - - /** - * @dev before making a call to this function, you have to check if a ruleEngine is set. - */ - function _messageForTransferRestriction( - uint8 restrictionCode - ) internal view returns (string memory) { - return ruleEngine.messageForTransferRestriction(restrictionCode); - } - - /** - * @dev before making a call to this function, you have to check if a ruleEngine is set. - */ - function _detectTransferRestriction( - address from, - address to, - uint256 amount - ) internal view returns (uint8) { - 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/internal/base/SnapshotModuleBase.sol b/contracts/modules/internal/base/SnapshotModuleBase.sol deleted file mode 100644 index 59da356..0000000 --- a/contracts/modules/internal/base/SnapshotModuleBase.sol +++ /dev/null @@ -1,410 +0,0 @@ -//SPDX-License-Identifier: MPL-2.0 - -pragma solidity ^0.8.20; - -import "../../../../openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol"; -import {Arrays} from '@openzeppelin/contracts/utils/Arrays.sol'; - -import "../../../libraries/Errors.sol"; - -/** - * @dev Base for the Snapshot module - * - * Useful to take a snapshot of token holder balance and total supply at a specific time - * Inspired by Openzeppelin - ERC20Snapshot but use the time as Id instead of a counter. - * Contrary to OpenZeppelin, the function _getCurrentSnapshotId is not available - because overriding this function can break the contract. - */ - -abstract contract SnapshotModuleBase is Initializable { - using Arrays for uint256[]; - - /** - @notice Emitted when the snapshot with the specified oldTime was scheduled or rescheduled at the specified newTime. - */ - event SnapshotSchedule(uint256 indexed oldTime, uint256 indexed newTime); - - /** - * @notice Emitted when the scheduled snapshot with the specified time was cancelled. - */ - event SnapshotUnschedule(uint256 indexed time); - - /** - * @dev See {OpenZeppelin - ERC20Snapshot} - * Snapshotted values have arrays of ids (time) and the value corresponding to that id. - * ids is expected to be sorted in ascending order, and to contain no repeated elements - * because we use findUpperBound in the function _valueAt - */ - struct Snapshots { - uint256[] ids; - uint256[] values; - } - - /** - * @dev See {OpenZeppelin - ERC20Snapshot} - */ - mapping(address => Snapshots) internal _accountBalanceSnapshots; - Snapshots internal _totalSupplySnapshots; - - /** - * @dev time instead of a counter for OpenZeppelin - */ - // Initialized to zero - uint256 private _currentSnapshotTime; - // Initialized to zero - uint256 private _currentSnapshotIndex; - - /** - * @dev - * list of scheduled snapshot (time) - * This list is sorted in ascending order - */ - uint256[] private _scheduledSnapshots; - - function __SnapshotModuleBase_init_unchained() internal onlyInitializing { - // Nothing to do - // _currentSnapshotTime & _currentSnapshotIndex are initialized to zero - } - - /** - * @dev schedule a snapshot at the specified time - * You can only add a snapshot after the last previous - */ - function _scheduleSnapshot(uint256 time) internal { - // Check the time firstly to avoid an useless read of storage - if (time <= block.timestamp) { - revert Errors.CMTAT_SnapshotModule_SnapshotScheduledInThePast( - time, - block.timestamp - ); - } - - if (_scheduledSnapshots.length > 0) { - // We check the last snapshot on the list - uint256 nextSnapshotTime = _scheduledSnapshots[ - _scheduledSnapshots.length - 1 - ]; - if (time < nextSnapshotTime) { - revert Errors - .CMTAT_SnapshotModule_SnapshotTimestampBeforeLastSnapshot( - time, - nextSnapshotTime - ); - } else if (time == nextSnapshotTime) { - revert Errors.CMTAT_SnapshotModule_SnapshotAlreadyExists(); - } - } - _scheduledSnapshots.push(time); - emit SnapshotSchedule(0, time); - } - - /** - * @dev schedule a snapshot at the specified time - */ - function _scheduleSnapshotNotOptimized(uint256 time) internal { - if (time <= block.timestamp) { - revert Errors.CMTAT_SnapshotModule_SnapshotScheduledInThePast( - time, - block.timestamp - ); - } - (bool isFound, uint256 index) = _findScheduledSnapshotIndex(time); - // Perfect match - if (isFound) { - revert Errors.CMTAT_SnapshotModule_SnapshotAlreadyExists(); - } - // if no upper bound match found, we push the snapshot at the end of the list - if (index == _scheduledSnapshots.length) { - _scheduledSnapshots.push(time); - } else { - _scheduledSnapshots.push( - _scheduledSnapshots[_scheduledSnapshots.length - 1] - ); - for (uint256 i = _scheduledSnapshots.length - 2; i > index; ) { - _scheduledSnapshots[i] = _scheduledSnapshots[i - 1]; - unchecked { - --i; - } - } - _scheduledSnapshots[index] = time; - } - emit SnapshotSchedule(0, time); - } - - /** - * @dev reschedule a scheduled snapshot at the specified newTime - */ - function _rescheduleSnapshot(uint256 oldTime, uint256 newTime) internal { - // Check the time firstly to avoid an useless read of storage - if (oldTime <= block.timestamp) { - revert Errors.CMTAT_SnapshotModule_SnapshotAlreadyDone(); - } - if (newTime <= block.timestamp) { - revert Errors.CMTAT_SnapshotModule_SnapshotScheduledInThePast( - newTime, - block.timestamp - ); - } - if (_scheduledSnapshots.length == 0) { - revert Errors.CMTAT_SnapshotModule_NoSnapshotScheduled(); - } - (bool foundOld, uint256 index) = _findScheduledSnapshotIndex(oldTime); - if (!foundOld) { - revert Errors.CMTAT_SnapshotModule_SnapshotNotFound(); - } - if (index + 1 < _scheduledSnapshots.length) { - uint256 nextSnapshotTime = _scheduledSnapshots[index + 1]; - if (newTime > nextSnapshotTime) { - revert Errors - .CMTAT_SnapshotModule_SnapshotTimestampAfterNextSnapshot( - newTime, - nextSnapshotTime - ); - } else if (newTime == nextSnapshotTime) { - revert Errors.CMTAT_SnapshotModule_SnapshotAlreadyExists(); - } - } - if (index > 0) { - if (newTime <= _scheduledSnapshots[index - 1]) - revert Errors - .CMTAT_SnapshotModule_SnapshotTimestampBeforePreviousSnapshot( - newTime, - _scheduledSnapshots[index - 1] - ); - } - _scheduledSnapshots[index] = newTime; - - emit SnapshotSchedule(oldTime, newTime); - } - - /** - * @dev unschedule the last scheduled snapshot - */ - function _unscheduleLastSnapshot(uint256 time) internal { - // Check the time firstly to avoid an useless read of storage - if (time <= block.timestamp) { - revert Errors.CMTAT_SnapshotModule_SnapshotAlreadyDone(); - } - if (_scheduledSnapshots.length == 0) { - revert Errors.CMTAT_SnapshotModule_NoSnapshotScheduled(); - } - // All snapshot time are unique, so we do not check the indice - if (time != _scheduledSnapshots[_scheduledSnapshots.length - 1]) { - revert Errors.CMTAT_SnapshotModule_SnapshotNotFound(); - } - _scheduledSnapshots.pop(); - emit SnapshotUnschedule(time); - } - - /** - * @dev unschedule (remove) a scheduled snapshot in three steps: - * - search the snapshot in the list - * - If found, move all next snapshots one position to the left - * - Reduce the array size by deleting the last snapshot - */ - function _unscheduleSnapshotNotOptimized(uint256 time) internal { - if (time <= block.timestamp) { - revert Errors.CMTAT_SnapshotModule_SnapshotAlreadyDone(); - } - (bool isFound, uint256 index) = _findScheduledSnapshotIndex(time); - if (!isFound) { - revert Errors.CMTAT_SnapshotModule_SnapshotNotFound(); - } - for (uint256 i = index; i + 1 < _scheduledSnapshots.length; ) { - _scheduledSnapshots[i] = _scheduledSnapshots[i + 1]; - unchecked { - ++i; - } - } - _scheduledSnapshots.pop(); - } - - /** - * @dev - * Get the next scheduled snapshots - */ - function getNextSnapshots() public view returns (uint256[] memory) { - uint256[] memory nextScheduledSnapshot = new uint256[](0); - // no snapshot were planned - if (_scheduledSnapshots.length > 0) { - ( - uint256 timeLowerBound, - uint256 indexLowerBound - ) = _findScheduledMostRecentPastSnapshot(); - // All snapshots are situated in the futur - if ((timeLowerBound == 0) && (_currentSnapshotTime == 0)) { - return _scheduledSnapshots; - } else { - // There are snapshots situated in the futur - if (indexLowerBound + 1 != _scheduledSnapshots.length) { - // All next snapshots are located after the snapshot specified by indexLowerBound - uint256 arraySize = _scheduledSnapshots.length - - indexLowerBound - - 1; - nextScheduledSnapshot = new uint256[](arraySize); - for (uint256 i; i < arraySize; ) { - nextScheduledSnapshot[i] = _scheduledSnapshots[ - indexLowerBound + 1 + i - ]; - unchecked { - ++i; - } - } - } - } - } - return nextScheduledSnapshot; - } - - /** - * - * @notice Get all snapshots - */ - function getAllSnapshots() public view returns (uint256[] memory) { - return _scheduledSnapshots; - } - - - /** - * @dev See {OpenZeppelin - ERC20Snapshot} - * @param time where we want a snapshot - * @param snapshots the struct where are stored the snapshots - * @return snapshotExist true if a snapshot is found, false otherwise - * value 0 if no snapshot, balance value if a snapshot exists - */ - function _valueAt( - uint256 time, - Snapshots storage snapshots - ) internal view returns (bool snapshotExist, uint256 value) { - // When a valid snapshot is queried, there are three possibilities: - // a) The queried value was not modified after the snapshot was taken. Therefore, a snapshot entry was never - // created for this id, and all stored snapshot ids are smaller than the requested one. The value that corresponds - // to this id is the current one. - // b) The queried value was modified after the snapshot was taken. Therefore, there will be an entry with the - // requested id, and its value is the one to return. - // c) More snapshots were created after the requested one, and the queried value was later modified. There will be - // no entry for the requested id: the value that corresponds to it is that of the smallest snapshot id that is - // larger than the requested one. - // - // In summary, we need to find an element in an array, returning the index of the smallest value that is larger if - // it is not found, unless said value doesn't exist (e.g. when all values are smaller). Arrays.findUpperBound does - // exactly this. - - uint256 index = snapshots.ids.findUpperBound(time); - - if (index == snapshots.ids.length) { - return (false, 0); - } else { - return (true, snapshots.values[index]); - } - } - - /** - * @dev - * Inside a struct Snapshots: - * - Update the array ids to the current Snapshot time if this one is greater than the snapshot times stored in ids. - * - Update the value to the corresponding value. - */ - function _updateSnapshot( - Snapshots storage snapshots, - uint256 currentValue - ) internal { - uint256 current = _currentSnapshotTime; - if (_lastSnapshot(snapshots.ids) < current) { - snapshots.ids.push(current); - snapshots.values.push(currentValue); - } - } - - /** - * @dev - * Set the currentSnapshotTime by retrieving the most recent snapshot - * if a snapshot exists, clear all past scheduled snapshot - */ - function _setCurrentSnapshot() internal { - ( - uint256 scheduleSnapshotTime, - uint256 scheduleSnapshotIndex - ) = _findScheduledMostRecentPastSnapshot(); - if (scheduleSnapshotTime > 0) { - _currentSnapshotTime = scheduleSnapshotTime; - _currentSnapshotIndex = scheduleSnapshotIndex; - } - } - - /** - * @return the last snapshot time inside a snapshot ids array - */ - function _lastSnapshot( - uint256[] storage ids - ) private view returns (uint256) { - if (ids.length == 0) { - return 0; - } else { - return ids[ids.length - 1]; - } - } - - /** - * @dev Find the snapshot index at the specified time - * @return (true, index) if the snapshot exists, (false, 0) otherwise - */ - function _findScheduledSnapshotIndex( - uint256 time - ) private view returns (bool, uint256) { - uint256 indexFound = _scheduledSnapshots.findUpperBound(time); - uint256 _scheduledSnapshotsLength = _scheduledSnapshots.length; - // Exact match - if ( - indexFound != _scheduledSnapshotsLength && - _scheduledSnapshots[indexFound] == time - ) { - return (true, indexFound); - } - // Upper bound match - else if (indexFound != _scheduledSnapshotsLength) { - return (false, indexFound); - } - // no match - else { - return (false, _scheduledSnapshotsLength); - } - } - - /** - * @dev find the most recent past snapshot - * The complexity of this function is O(N) because we go through the whole list - */ - function _findScheduledMostRecentPastSnapshot() - private - view - returns (uint256 time, uint256 index) - { - uint256 currentArraySize = _scheduledSnapshots.length; - // no snapshot or the current snapshot already points on the last snapshot - if ( - currentArraySize == 0 || - ((_currentSnapshotIndex + 1 == currentArraySize) && (time != 0)) - ) { - return (0, currentArraySize); - } - // mostRecent is initialized in the loop - uint256 mostRecent; - index = currentArraySize; - for (uint256 i = _currentSnapshotIndex; i < currentArraySize; ) { - if (_scheduledSnapshots[i] <= block.timestamp) { - mostRecent = _scheduledSnapshots[i]; - index = i; - } else { - // All snapshot are planned in the futur - break; - } - unchecked { - ++i; - } - } - return (mostRecent, index); - } - - uint256[50] private __gap; -} diff --git a/contracts/modules/security/AuthorizationModule.sol b/contracts/modules/security/AuthorizationModule.sol deleted file mode 100644 index a270a6a..0000000 --- a/contracts/modules/security/AuthorizationModule.sol +++ /dev/null @@ -1,104 +0,0 @@ -//SPDX-License-Identifier: MPL-2.0 - -pragma solidity ^0.8.20; - -import "../../../openzeppelin-contracts-upgradeable/contracts/access/AccessControlUpgradeable.sol"; -import "../../../openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol"; - -import "../../libraries/Errors.sol"; -import "../../interfaces/engine/IAuthorizationEngine.sol"; -abstract contract AuthorizationModule is AccessControlUpgradeable { - IAuthorizationEngine private authorizationEngine; - /** - * @dev Emitted when a rule engine is set. - */ - event AuthorizationEngine(IAuthorizationEngine indexed newAuthorizationEngine); - // BurnModule - bytes32 public constant BURNER_ROLE = keccak256("BURNER_ROLE"); - bytes32 public constant BURNER_FROM_ROLE = keccak256("BURNER_FROM_ROLE"); - // CreditEvents - bytes32 public constant DEBT_CREDIT_EVENT_ROLE = - keccak256("DEBT_CREDIT_EVENT_ROLE"); - // DebtModule - bytes32 public constant DEBT_ROLE = keccak256("DEBT_ROLE"); - // EnforcementModule - bytes32 public constant ENFORCER_ROLE = keccak256("ENFORCER_ROLE"); - // MintModule - bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE"); - // PauseModule - bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE"); - // SnapshotModule - bytes32 public constant SNAPSHOOTER_ROLE = keccak256("SNAPSHOOTER_ROLE"); - - /** - * @dev - * - * - The grant to the admin role is done by AccessControlDefaultAdminRules - * - The control of the zero address is done by AccessControlDefaultAdminRules - * - */ - function __AuthorizationModule_init_unchained(address admin, IAuthorizationEngine authorizationEngine_) - internal onlyInitializing { - if(admin == address(0)){ - revert Errors.CMTAT_AuthorizationModule_AddressZeroNotAllowed(); - } - _grantRole(DEFAULT_ADMIN_ROLE, admin); - if (address(authorizationEngine) != address (0)) { - authorizationEngine = authorizationEngine_; - } - - - } - - /* - * @notice set an authorizationEngine if not already set - * @dev once an AuthorizationEngine is set, it is not possible to unset it - */ - function setAuthorizationEngine( - IAuthorizationEngine authorizationEngine_ - ) external onlyRole(DEFAULT_ADMIN_ROLE) { - if (address(authorizationEngine) != address (0)){ - revert Errors.CMTAT_AuthorizationModule_AuthorizationEngineAlreadySet(); - } - authorizationEngine = authorizationEngine_; - emit AuthorizationEngine(authorizationEngine_); - } - - function grantRole(bytes32 role, address account) public override onlyRole(getRoleAdmin(role)) { - if (address(authorizationEngine) != address (0)) { - bool result = authorizationEngine.operateOnGrantRole(role, account); - if(!result) { - // Operation rejected by the authorizationEngine - revert Errors.CMTAT_AuthorizationModule_InvalidAuthorization(); - } - } - return AccessControlUpgradeable.grantRole(role, account); - } - - function revokeRole(bytes32 role, address account) public override onlyRole(getRoleAdmin(role)) { - if (address(authorizationEngine) != address (0)) { - bool result = authorizationEngine.operateOnRevokeRole(role, account); - if(!result) { - // Operation rejected by the authorizationEngine - revert Errors.CMTAT_AuthorizationModule_InvalidAuthorization(); - } - } - return AccessControlUpgradeable.revokeRole(role, account); - } - - /** - * @dev Returns `true` if `account` has been granted `role`. - */ - function hasRole( - bytes32 role, - address account - ) public view virtual override(AccessControlUpgradeable) returns (bool) { - // The Default Admin has all roles - if (AccessControlUpgradeable.hasRole(DEFAULT_ADMIN_ROLE, account)) { - return true; - } - return AccessControlUpgradeable.hasRole(role, account); - } - - uint256[50] private __gap; -} diff --git a/contracts/modules/wrapper/controllers/ValidationModule.sol b/contracts/modules/wrapper/controllers/ValidationModule.sol deleted file mode 100644 index ce3f68f..0000000 --- a/contracts/modules/wrapper/controllers/ValidationModule.sol +++ /dev/null @@ -1,138 +0,0 @@ -//SPDX-License-Identifier: MPL-2.0 - -pragma solidity ^0.8.20; - -import "../../../../openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol"; -import "../../security/AuthorizationModule.sol"; -import "../../internal/ValidationModuleInternal.sol"; -import "../core/PauseModule.sol"; -import "../core/EnforcementModule.sol"; - -import "../../../libraries/Errors.sol"; - -/** - * @dev Validation module. - * - * Useful for to restrict and validate transfers - */ -abstract contract ValidationModule is - ValidationModuleInternal, - PauseModule, - EnforcementModule, - IERC1404Wrapper -{ - string constant TEXT_TRANSFER_OK = "No restriction"; - string constant TEXT_UNKNOWN_CODE = "Unknown code"; - - function __ValidationModule_init_unchained() internal onlyInitializing { - // no variable to initialize - } - - /* - * @notice set a RuleEngine - * @param ruleEngine_ the call will be reverted if the new value of ruleEngine is the same as the current one - */ - function setRuleEngine( - IRuleEngine ruleEngine_ - ) external onlyRole(DEFAULT_ADMIN_ROLE) { - if (ruleEngine == ruleEngine_){ - revert Errors.CMTAT_ValidationModule_SameValue(); - } - ruleEngine = ruleEngine_; - emit RuleEngine(ruleEngine_); - } - - /** - * @dev ERC1404 check if _value token can be transferred from _from to _to - * @param from address The address which you want to send tokens from - * @param to address The address which you want to transfer to - * @param amount uint256 the amount of tokens to be transferred - * @return code of the rejection reason - */ - function detectTransferRestriction( - address from, - address to, - uint256 amount - ) public view override returns (uint8 code) { - if (paused()) { - return uint8(REJECTED_CODE_BASE.TRANSFER_REJECTED_PAUSED); - } else if (frozen(from)) { - return uint8(REJECTED_CODE_BASE.TRANSFER_REJECTED_FROM_FROZEN); - } else if (frozen(to)) { - return uint8(REJECTED_CODE_BASE.TRANSFER_REJECTED_TO_FROZEN); - } else if (address(ruleEngine) != address(0)) { - return _detectTransferRestriction(from, to, amount); - } else { - return uint8(REJECTED_CODE_BASE.TRANSFER_OK); - } - } - - /** - * @dev ERC1404 returns the human readable explaination corresponding to the error code returned by detectTransferRestriction - * @param restrictionCode The error code returned by detectTransferRestriction - * @return message The human readable explaination corresponding to the error code returned by detectTransferRestriction - */ - function messageForTransferRestriction( - uint8 restrictionCode - ) external view override returns (string memory message) { - if (restrictionCode == uint8(REJECTED_CODE_BASE.TRANSFER_OK)) { - return TEXT_TRANSFER_OK; - } else if ( - restrictionCode == - uint8(REJECTED_CODE_BASE.TRANSFER_REJECTED_PAUSED) - ) { - return TEXT_TRANSFER_REJECTED_PAUSED; - } else if ( - restrictionCode == - uint8(REJECTED_CODE_BASE.TRANSFER_REJECTED_FROM_FROZEN) - ) { - return TEXT_TRANSFER_REJECTED_FROM_FROZEN; - } else if ( - restrictionCode == - uint8(REJECTED_CODE_BASE.TRANSFER_REJECTED_TO_FROZEN) - ) { - return TEXT_TRANSFER_REJECTED_TO_FROZEN; - } else if (address(ruleEngine) != address(0)) { - return _messageForTransferRestriction(restrictionCode); - } else { - 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 (!validateTransferByModule(from, to, amount)) { - return false; - } - if (address(ruleEngine) != address(0)) { - return _validateTransfer(from, to, amount); - } - 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/modules/wrapper/core/BaseModule.sol b/contracts/modules/wrapper/core/BaseModule.sol deleted file mode 100644 index ff3f492..0000000 --- a/contracts/modules/wrapper/core/BaseModule.sol +++ /dev/null @@ -1,96 +0,0 @@ -//SPDX-License-Identifier: MPL-2.0 - -pragma solidity ^0.8.20; - -// required OZ imports here -import "../../../../openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol"; -import "../../security/AuthorizationModule.sol"; -import "../../../libraries/Errors.sol"; - -abstract contract BaseModule is AuthorizationModule { - /** - * @notice - * Get the current version of the smart contract - */ - string public constant VERSION = "2.4.0"; - /* Events */ - event Term(string indexed newTermIndexed, string newTerm); - event TokenId(string indexed newTokenIdIndexed, string newTokenId); - event Information( - string indexed newInformationIndexed, - string newInformation - ); - event Flag(uint256 indexed newFlag); - - /* Variables */ - string public tokenId; - string public terms; - string public information; - // additional attribute to store information as an uint256 - uint256 public flag; - - - - /* Initializers */ - /** - * @dev Sets the values for {name} and {symbol}. - * - * All two of these values are immutable: they can only be set once during - * construction. - */ - function __Base_init_unchained( - string memory tokenId_, - string memory terms_, - string memory information_, - uint256 flag_ - ) internal onlyInitializing { - tokenId = tokenId_; - terms = terms_; - information = information_; - flag = flag_; - } - - /* Methods */ - /** - * @notice the tokenId will be changed even if the new value is the same as the current one - */ - function setTokenId( - string calldata tokenId_ - ) public onlyRole(DEFAULT_ADMIN_ROLE) { - tokenId = tokenId_; - emit TokenId(tokenId_, tokenId_); - } - - /** - * @notice The terms will be changed even if the new value is the same as the current one - */ - function setTerms( - string calldata terms_ - ) public onlyRole(DEFAULT_ADMIN_ROLE) { - terms = terms_; - emit Term(terms_, terms_); - } - - /** - * @notice The information will be changed even if the new value is the same as the current one - */ - function setInformation( - string calldata information_ - ) public onlyRole(DEFAULT_ADMIN_ROLE) { - information = information_; - emit Information(information_, information_); - } - - /** - * @notice The call will be reverted if the new value of flag is the same as the current one - */ - function setFlag(uint256 flag_) public onlyRole(DEFAULT_ADMIN_ROLE) { - if (flag == flag_) { - revert Errors.CMTAT_BaseModule_SameValue(); - } - flag = flag_; - emit Flag(flag_); - } - - uint256[50] private __gap; -} diff --git a/contracts/modules/wrapper/core/ERC20BaseModule.sol b/contracts/modules/wrapper/core/ERC20BaseModule.sol deleted file mode 100644 index 0a2af91..0000000 --- a/contracts/modules/wrapper/core/ERC20BaseModule.sol +++ /dev/null @@ -1,105 +0,0 @@ -//SPDX-License-Identifier: MPL-2.0 - -pragma solidity ^0.8.20; - -// required OZ imports here -import "../../../../openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol"; -import "../../../../openzeppelin-contracts-upgradeable/contracts/token/ERC20/ERC20Upgradeable.sol"; -import "../../../libraries/Errors.sol"; - -abstract contract ERC20BaseModule is ERC20Upgradeable { - /* Events */ - /** - * @notice Emitted when the specified `spender` spends the specified `value` tokens owned by the specified `owner` reducing the corresponding allowance. - * @dev The allowance can be also "spend" with the function BurnFrom, but in this case, the emitted event is BurnFrom. - */ - event Spend(address indexed owner, address indexed spender, uint256 value); - - /* Variables */ - uint8 private _decimals; - - /* Initializers */ - - /** - * @dev Sets the values for decimals. - * - * this value is immutable: it can only be set once during - * construction/initialization. - */ - function __ERC20BaseModule_init_unchained( - uint8 decimals_ - ) internal onlyInitializing { - _decimals = decimals_; - } - - /* Methods */ - /** - * - * @notice Returns the number of decimals used to get its user representation. - * @inheritdoc ERC20Upgradeable - */ - function decimals() public view virtual override returns (uint8) { - return _decimals; - } - - /** - * @notice batch version of transfer - * @param tos can not be empty, must have the same length as values - * @param values can not be empty - * @dev See {OpenZeppelin ERC20-transfer & ERC1155-safeBatchTransferFrom}. - * - * - * Requirements: - * - `tos` and `values` must have the same length - * - `tos`cannot contain a zero address (check made by transfer) - * - the caller must have a balance cooresponding to the total values - */ - function transferBatch( - address[] calldata tos, - uint256[] calldata values - ) public returns (bool) { - if (tos.length == 0) { - revert Errors.CMTAT_ERC20BaseModule_EmptyTos(); - } - // We do not check that values is not empty since - // this require will throw an error in this case. - if (bool(tos.length != values.length)) { - revert Errors.CMTAT_ERC20BaseModule_TosValueslengthMismatch(); - } - - for (uint256 i = 0; i < tos.length; ) { - // We call directly the internal function transfer - // The reason is that the public function adds only the owner address recovery - ERC20Upgradeable._transfer(_msgSender(), tos[i], values[i]); - unchecked { - ++i; - } - } - // not really useful - // Here only to keep the same behaviour as transfer - return true; - } - - /** - * @notice Transfers `value` amount of tokens from address `from` to address `to` - * @custom:dev-cmtat - * Emits a {Spend} event indicating the spended allowance. - * @inheritdoc ERC20Upgradeable - * - */ - function transferFrom( - address from, - address to, - uint256 value - ) public virtual override returns (bool) { - bool result = ERC20Upgradeable.transferFrom(from, to, value); - // The result will be normally always true because OpenZeppelin will revert in case of an error - if (result) { - emit Spend(from, _msgSender(), value); - } - - return result; - } - - uint256[50] private __gap; -} diff --git a/contracts/modules/wrapper/core/ERC20BurnModule.sol b/contracts/modules/wrapper/core/ERC20BurnModule.sol deleted file mode 100644 index 0b3729f..0000000 --- a/contracts/modules/wrapper/core/ERC20BurnModule.sol +++ /dev/null @@ -1,116 +0,0 @@ -//SPDX-License-Identifier: MPL-2.0 - -pragma solidity ^0.8.20; - -import "../../../../openzeppelin-contracts-upgradeable/contracts/token/ERC20/ERC20Upgradeable.sol"; -import "../../../../openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol"; -import "../../security/AuthorizationModule.sol"; -import "../../../interfaces/ICCIPToken.sol"; -abstract contract ERC20BurnModule is ERC20Upgradeable, ICCIPBurnFromERC20, AuthorizationModule { - /** - * @notice Emitted when the specified `value` amount of tokens owned by `owner`are destroyed with the given `reason` - */ - event Burn(address indexed owner, uint256 value, string reason); - /** - * @notice Emitted when the specified `spender` burns the specified `value` tokens owned by the specified `owner` reducing the corresponding allowance. - */ - event BurnFrom(address indexed owner, address indexed spender, uint256 value); - function __ERC20BurnModule_init_unchained() internal onlyInitializing { - // no variable to initialize - } - - /** - * @notice Destroys a `value` amount of tokens from `account`, by transferring it to address(0). - * @dev - * See {ERC20-_burn} - * Emits a {Burn} event - * Emits a {Transfer} event with `to` set to the zero address (emits inside _burn). - * Requirements: - * - the caller must have the `BURNER_ROLE`. - */ - function burn( - address account, - uint256 value, - string calldata reason - ) public onlyRole(BURNER_ROLE) { - _burn(account, value); - emit Burn(account, value, reason); - } - - - /** - * - * @notice batch version of {burn}. - * @dev - * See {ERC20-_burn} and {OpenZeppelin ERC1155_burnBatch}. - * - * For each burn action: - * -Emits a {Burn} event - * -Emits a {Transfer} event with `to` set to the zero address (emits inside _burn). - * The burn `reason`is the same for all `accounts` which tokens are burnt. - * Requirements: - * - `accounts` and `values` must have the same length - * - the caller must have the `BURNER_ROLE`. - */ - function burnBatch( - address[] calldata accounts, - uint256[] calldata values, - string calldata reason - ) public onlyRole(BURNER_ROLE) { - if (accounts.length == 0) { - revert Errors.CMTAT_BurnModule_EmptyAccounts(); - } - // We do not check that values is not empty since - // this require will throw an error in this case. - if (bool(accounts.length != values.length)) { - revert Errors.CMTAT_BurnModule_AccountsValueslengthMismatch(); - } - - for (uint256 i = 0; i < accounts.length; ) { - _burn(accounts[i], values[i]); - emit Burn(accounts[i], values[i], reason); - unchecked { - ++i; - } - } - } - - /** - * @notice Destroys `amount` tokens from `account`, deducting from the caller's - * allowance. - * @dev - * Can be used to authorize a bridge (e.g. CCIP) to burn token owned by the bridge - * No string parameter reason to be compatible with Bridge, e.g. CCIP - * - * See {ERC20-_burn} and {ERC20-allowance}. - * - * Requirements: - * - * - the caller must have allowance for ``accounts``'s tokens of at least - * `value`. - */ - function burnFrom(address account, uint256 value) - public - onlyRole(BURNER_FROM_ROLE) - { - // Allowance check - address sender = _msgSender(); - uint256 currentAllowance = allowance(account, sender); - if(currentAllowance < value){ - // ERC-6093 - revert ERC20InsufficientAllowance(sender, currentAllowance, value); - } - // Update allowance - unchecked { - _approve(account, sender, currentAllowance - value); - } - // burn - _burn(account, value); - // We also emit a burn event since its a burn operation - emit Burn(account, value, "burnFrom"); - // Specific event for the operation - emit BurnFrom(account, sender, value); - } - - uint256[50] private __gap; -} diff --git a/contracts/modules/wrapper/core/ERC20MintModule.sol b/contracts/modules/wrapper/core/ERC20MintModule.sol deleted file mode 100644 index cb38022..0000000 --- a/contracts/modules/wrapper/core/ERC20MintModule.sol +++ /dev/null @@ -1,76 +0,0 @@ -//SPDX-License-Identifier: MPL-2.0 - -pragma solidity ^0.8.20; - -import "../../../../openzeppelin-contracts-upgradeable/contracts/token/ERC20/ERC20Upgradeable.sol"; -import "../../../../openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol"; -import "../../security/AuthorizationModule.sol"; -import "../../../interfaces/ICCIPToken.sol"; -abstract contract ERC20MintModule is ERC20Upgradeable, ICCIPMintERC20, AuthorizationModule { - /** - * @notice Emitted when the specified `value` amount of new tokens are created and - * allocated to the specified `account`. - */ - event Mint(address indexed account, uint256 value); - - function __ERC20MintModule_init_unchained() internal onlyInitializing { - // no variable to initialize - } - - /** - * @notice Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0) - * @param account token receiver - * @param value amount of tokens - * @dev - * See {OpenZeppelin ERC20-_mint}. - * Emits a {Mint} event. - * Emits a {Transfer} event with `from` set to the zero address (emits inside _mint). - * - * Requirements: - * - `account` cannot be the zero address (check made by _mint). - * - The caller must have the `MINTER_ROLE`. - */ - function mint(address account, uint256 value) public onlyRole(MINTER_ROLE) { - _mint(account, value); - emit Mint(account, value); - } - - /** - * - * @notice batch version of {mint} - * @dev - * See {OpenZeppelin ERC20-_mint} and {OpenZeppelin ERC1155_mintBatch}. - * - * For each mint action: - * - Emits a {Mint} event. - * - Emits a {Transfer} event with `from` set to the zero address (emits inside _mint). - * - * Requirements: - * - `accounts` and `values` must have the same length - * - `accounts` cannot contain a zero address (check made by _mint). - * - the caller must have the `MINTER_ROLE`. - */ - function mintBatch( - address[] calldata accounts, - uint256[] calldata values - ) public onlyRole(MINTER_ROLE) { - if (accounts.length == 0) { - revert Errors.CMTAT_MintModule_EmptyAccounts(); - } - // We do not check that values is not empty since - // this require will throw an error in this case. - if (bool(accounts.length != values.length)) { - revert Errors.CMTAT_MintModule_AccountsValueslengthMismatch(); - } - - for (uint256 i = 0; i < accounts.length; ) { - _mint(accounts[i], values[i]); - emit Mint(accounts[i], values[i]); - unchecked { - ++i; - } - } - } - - uint256[50] private __gap; -} diff --git a/contracts/modules/wrapper/core/EnforcementModule.sol b/contracts/modules/wrapper/core/EnforcementModule.sol deleted file mode 100644 index df1b3d6..0000000 --- a/contracts/modules/wrapper/core/EnforcementModule.sol +++ /dev/null @@ -1,54 +0,0 @@ -//SPDX-License-Identifier: MPL-2.0 - -pragma solidity ^0.8.20; - -import "../../security/AuthorizationModule.sol"; -import "../../internal/EnforcementModuleInternal.sol"; - -/** - * @dev Enforcement module. - * - * Allows the issuer to freeze transfers from a given address - */ -abstract contract EnforcementModule is - EnforcementModuleInternal, - AuthorizationModule -{ - string internal constant TEXT_TRANSFER_REJECTED_FROM_FROZEN = - "Address FROM is frozen"; - - string internal constant TEXT_TRANSFER_REJECTED_TO_FROZEN = - "Address TO is frozen"; - - function __EnforcementModule_init_unchained() internal onlyInitializing { - // no variable to initialize - } - - /** - * @notice Freezes an address. - * @param account the account to freeze - * @param reason indicate why the account was frozen. - */ - function freeze( - address account, - string calldata reason - ) public onlyRole(ENFORCER_ROLE) returns (bool) { - return _freeze(account, reason); - } - - /** - * @notice Unfreezes an address. - * @param account the account to unfreeze - * @param reason indicate why the account was unfrozen. - * - * - */ - function unfreeze( - address account, - string calldata reason - ) public onlyRole(ENFORCER_ROLE) returns (bool) { - return _unfreeze(account, reason); - } - - uint256[50] private __gap; -} diff --git a/contracts/modules/wrapper/extensions/DebtModule/DebtBaseModule.sol b/contracts/modules/wrapper/extensions/DebtModule/DebtBaseModule.sol deleted file mode 100644 index 9193531..0000000 --- a/contracts/modules/wrapper/extensions/DebtModule/DebtBaseModule.sol +++ /dev/null @@ -1,231 +0,0 @@ -//SPDX-License-Identifier: MPL-2.0 - -pragma solidity ^0.8.20; - -import "../../../../../openzeppelin-contracts-upgradeable/contracts/access/AccessControlUpgradeable.sol"; -import "../../../../../openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol"; -import "../../../../interfaces/IDebtGlobal.sol"; -import "../../../security/AuthorizationModule.sol"; - -import "../../../../libraries/Errors.sol"; - -abstract contract DebtBaseModule is - IDebtGlobal, - Initializable, - ContextUpgradeable, - AuthorizationModule -{ - DebtBase public debt; - - /* Events */ - event InterestRate(uint256 newInterestRate); - event ParValue(uint256 newParValue); - event Guarantor(string indexed newGuarantorIndexed, string newGuarantor); - event BondHolder(string indexed newBondHolderIndexed, string newBondHolder); - event MaturityDate( - string indexed newMaturityDateIndexed, - string newMaturityDate - ); - event InterestScheduleFormat( - string indexed newInterestScheduleFormatIndexed, - string newInterestScheduleFormat - ); - event InterestPaymentDate( - string indexed newInterestPaymentDateIndexed, - string newInterestPaymentDate - ); - event DayCountConvention( - string indexed newDayCountConventionIndexed, - string newDayCountConvention - ); - event BusinessDayConvention( - string indexed newBusinessDayConventionIndexed, - string newBusinessDayConvention - ); - event PublicHolidaysCalendar( - string indexed newPublicHolidaysCalendarIndexed, - string newPublicHolidaysCalendar - ); - event IssuanceDate( - string indexed newIssuanceDateIndexed, - string newIssuanceDate - ); - event CouponFrequency( - string indexed newCouponFrequencyIndexed, - string newCouponFrequency - ); - - function __DebtBaseModule_init_unchained() internal onlyInitializing { - // no variable to initialize - } - - /** - * @notice Set all attributes of debt - * The values of all attributes will be changed even if the new values are the same as the current ones - */ - function setDebt(DebtBase calldata debt_) public onlyRole(DEBT_ROLE) { - debt = debt_; - emit InterestRate(debt_.interestRate); - emit ParValue(debt_.parValue); - emit Guarantor(debt_.guarantor, debt_.guarantor); - emit BondHolder(debt_.bondHolder, debt_.bondHolder); - emit MaturityDate(debt_.maturityDate, debt_.maturityDate); - emit InterestScheduleFormat( - debt_.interestScheduleFormat, - debt_.interestScheduleFormat - ); - emit InterestPaymentDate( - debt_.interestPaymentDate, - debt_.interestPaymentDate - ); - emit DayCountConvention( - debt_.dayCountConvention, - debt_.dayCountConvention - ); - emit BusinessDayConvention( - debt_.businessDayConvention, - debt_.businessDayConvention - ); - emit PublicHolidaysCalendar( - debt_.publicHolidaysCalendar, - debt_.publicHolidaysCalendar - ); - - emit IssuanceDate(debt_.issuanceDate, debt_.issuanceDate); - - emit CouponFrequency(debt_.couponFrequency, debt_.couponFrequency); - } - - /** - * @notice The call will be reverted if the new value of interestRate is the same as the current one - */ - function setInterestRate(uint256 interestRate_) public onlyRole(DEBT_ROLE) { - if (interestRate_ == debt.interestRate) { - revert Errors.CMTAT_DebtModule_SameValue(); - } - debt.interestRate = interestRate_; - emit InterestRate(interestRate_); - } - - /** - * @notice The call will be reverted if the new value of parValue is the same as the current one - */ - function setParValue(uint256 parValue_) public onlyRole(DEBT_ROLE) { - if (parValue_ == debt.parValue) { - revert Errors.CMTAT_DebtModule_SameValue(); - } - debt.parValue = parValue_; - emit ParValue(parValue_); - } - - /** - * @notice The Guarantor will be changed even if the new value is the same as the current one - */ - function setGuarantor( - string calldata guarantor_ - ) public onlyRole(DEBT_ROLE) { - debt.guarantor = guarantor_; - emit Guarantor(guarantor_, guarantor_); - } - - /** - * @notice The bonHolder will be changed even if the new value is the same as the current one - */ - function setBondHolder( - string calldata bondHolder_ - ) public onlyRole(DEBT_ROLE) { - debt.bondHolder = bondHolder_; - emit BondHolder(bondHolder_, bondHolder_); - } - - /** - * @notice The maturityDate will be changed even if the new value is the same as the current one - */ - function setMaturityDate( - string calldata maturityDate_ - ) public onlyRole(DEBT_ROLE) { - debt.maturityDate = maturityDate_; - emit MaturityDate(maturityDate_, maturityDate_); - } - - /** - * @notice The interestScheduleFormat will be changed even if the new value is the same as the current one - */ - function setInterestScheduleFormat( - string calldata interestScheduleFormat_ - ) public onlyRole(DEBT_ROLE) { - debt.interestScheduleFormat = interestScheduleFormat_; - emit InterestScheduleFormat( - interestScheduleFormat_, - interestScheduleFormat_ - ); - } - - /** - * @notice The interestPaymentDate will be changed even if the new value is the same as the current one - */ - function setInterestPaymentDate( - string calldata interestPaymentDate_ - ) public onlyRole(DEBT_ROLE) { - debt.interestPaymentDate = interestPaymentDate_; - emit InterestPaymentDate(interestPaymentDate_, interestPaymentDate_); - } - - /** - * @notice The dayCountConvention will be changed even if the new value is the same as the current one - */ - function setDayCountConvention( - string calldata dayCountConvention_ - ) public onlyRole(DEBT_ROLE) { - debt.dayCountConvention = dayCountConvention_; - emit DayCountConvention(dayCountConvention_, dayCountConvention_); - } - - /** - * @notice The businessDayConvention will be changed even if the new value is the same as the current one - */ - function setBusinessDayConvention( - string calldata businessDayConvention_ - ) public onlyRole(DEBT_ROLE) { - debt.businessDayConvention = businessDayConvention_; - emit BusinessDayConvention( - businessDayConvention_, - businessDayConvention_ - ); - } - - /** - * @notice The publicHolidayCalendar will be changed even if the new value is the same as the current one - */ - function setPublicHolidaysCalendar( - string calldata publicHolidaysCalendar_ - ) public onlyRole(DEBT_ROLE) { - debt.publicHolidaysCalendar = publicHolidaysCalendar_; - emit PublicHolidaysCalendar( - publicHolidaysCalendar_, - publicHolidaysCalendar_ - ); - } - - /** - * @notice The issuanceDate will be changed even if the new value is the same as the current one - */ - function setIssuanceDate( - string calldata issuanceDate_ - ) public onlyRole(DEBT_ROLE) { - debt.issuanceDate = issuanceDate_; - emit IssuanceDate(issuanceDate_, issuanceDate_); - } - - /** - * @notice The couponFrequency will be changed even if the new value is the same as the current one - */ - function setCouponFrequency( - string calldata couponFrequency_ - ) public onlyRole(DEBT_ROLE) { - debt.couponFrequency = couponFrequency_; - emit CouponFrequency(couponFrequency_, couponFrequency_); - } - - uint256[50] private __gap; -} diff --git a/contracts/modules/wrapper/extensions/MetaTxModule.sol b/contracts/modules/wrapper/extensions/MetaTxModule.sol deleted file mode 100644 index 5908845..0000000 --- a/contracts/modules/wrapper/extensions/MetaTxModule.sol +++ /dev/null @@ -1,24 +0,0 @@ -//SPDX-License-Identifier: MPL-2.0 - -pragma solidity ^0.8.20; - -import "../../../../openzeppelin-contracts-upgradeable/contracts/metatx/ERC2771ContextUpgradeable.sol"; -import "../../../../openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol"; - -/** - * @dev Meta transaction (gasless) module. - * - * Useful for to provide UX where the user does not pay gas for token exchange - * To follow OpenZeppelin, this contract does not implement the functions init & init_unchained. - * () - */ -abstract contract MetaTxModule is ERC2771ContextUpgradeable { - /// @custom:oz-upgrades-unsafe-allow constructor - constructor( - address trustedForwarder - ) ERC2771ContextUpgradeable(trustedForwarder) { - // Nothing to do - } - - uint256[50] private __gap; -}