-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add debtEngine, documentEngine and UUPS proxy
- Loading branch information
Showing
10 changed files
with
204 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
//SPDX-License-Identifier: MPL-2.0 | ||
|
||
pragma solidity ^0.8.20; | ||
import "../openzeppelin-contracts-upgradeable/contracts/proxy/utils/UUPSUpgradeable.sol"; | ||
import "./modules/CMTAT_BASE.sol"; | ||
|
||
contract CMTAT_PROXY_UUPS is CMTAT_BASE, UUPSUpgradeable { | ||
/** | ||
* @notice Contract version for the deployment with a proxy | ||
* @param forwarderIrrevocable address of the forwarder, required for the gasless support | ||
*/ | ||
/// @custom:oz-upgrades-unsafe-allow constructor | ||
constructor( | ||
address forwarderIrrevocable | ||
) MetaTxModule(forwarderIrrevocable) { | ||
// Disable the possibility to initialize the implementation | ||
_disableInitializers(); | ||
} | ||
|
||
/** | ||
* @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 override initializer { | ||
CMTAT_BASE.initialize( admin, | ||
authorizationEngineIrrevocable, | ||
nameIrrevocable, | ||
symbolIrrevocable, | ||
decimalsIrrevocable, | ||
tokenId_, | ||
terms_, | ||
ruleEngine_, | ||
information_, | ||
flag_); | ||
__UUPSUpgradeable_init_unchained(); | ||
} | ||
|
||
function _authorizeUpgrade(address) internal override onlyRole("DEFAULT_ADMIN_ROLE") {} | ||
|
||
uint256[50] private __gap; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
pragma solidity ^0.8.20; | ||
import "../IDebtGlobal.sol"; | ||
|
||
interface IDebtEngine is IDebtGlobal { | ||
/** | ||
* @dev Returns true if the operation is authorized, and false otherwise. | ||
*/ | ||
function debt() external returns(IDebtGlobal.DebtBase memory); | ||
/** | ||
* @dev Returns true if the operation is authorized, and false otherwise. | ||
*/ | ||
function creditEvents() external returns(IDebtGlobal.CreditEvents memory); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
//SPDX-License-Identifier: MPL-2.0 | ||
|
||
pragma solidity ^0.8.20; | ||
|
||
import "../../security/AuthorizationModule.sol"; | ||
import "../../../libraries/Errors.sol"; | ||
import "../../../interfaces/engine/IDebtEngine.sol"; | ||
|
||
abstract contract DebtModule is AuthorizationModule, IDebtEngine { | ||
bytes32 public constant DEBT_ROLE = keccak256("DEBT_ROLE"); | ||
IDebtEngine public debtEngine; | ||
/** | ||
* @dev Emitted when a rule engine is set. | ||
*/ | ||
event DebtEngine(IDebtEngine indexed newDebtEngine); | ||
/** | ||
* @dev | ||
* | ||
* - The grant to the admin role is done by AccessControlDefaultAdminRules | ||
* - The control of the zero address is done by AccessControlDefaultAdminRules | ||
* | ||
*/ | ||
function __DebtModule_init_unchained(IDebtEngine debtEngine_) | ||
internal onlyInitializing { | ||
if (address(debtEngine_) != address (0)) { | ||
debtEngine = debtEngine_; | ||
emit DebtEngine(debtEngine_); | ||
} | ||
|
||
|
||
} | ||
|
||
/* | ||
* @notice set an authorizationEngine if not already set | ||
* | ||
*/ | ||
function setDebtEngine( | ||
IDebtEngine debtEngine_ | ||
) external onlyRole(DEBT_ROLE) { | ||
debtEngine = debtEngine_; | ||
emit DebtEngine(debtEngine_); | ||
} | ||
|
||
function debt() external returns(DebtBase memory debtBaseResult){ | ||
if(address(debtEngine) != address(0)){ | ||
debtBaseResult = debtEngine.debt(); | ||
} | ||
} | ||
|
||
function creditEvents() external returns(CreditEvents memory creditEventsResult){ | ||
if(address(debtEngine) != address(0)){ | ||
creditEventsResult = debtEngine.creditEvents(); | ||
} | ||
} | ||
|
||
uint256[50] private __gap; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
//SPDX-License-Identifier: MPL-2.0 | ||
|
||
pragma solidity ^0.8.20; | ||
|
||
import "../../security/AuthorizationModule.sol"; | ||
import "../../../libraries/Errors.sol"; | ||
import "../../../interfaces/draft-IERC1643.sol"; | ||
abstract contract DocumentModule is AuthorizationModule, IERC1643 { | ||
bytes32 public constant DOCUMENT_ROLE = keccak256("DOCUMENT_ROLE"); | ||
IERC1643 public documentEngine; | ||
/** | ||
* @dev Emitted when a rule engine is set. | ||
*/ | ||
event DocumentEngine(IERC1643 indexed newDocumentEngine); | ||
/** | ||
* @dev | ||
* | ||
* - The grant to the admin role is done by AccessControlDefaultAdminRules | ||
* - The control of the zero address is done by AccessControlDefaultAdminRules | ||
* | ||
*/ | ||
function __DocumentModule_init_unchained(IERC1643 documentEngine_) | ||
internal onlyInitializing { | ||
if (address(documentEngine_) != address (0)) { | ||
documentEngine = documentEngine_; | ||
emit DocumentEngine(documentEngine_); | ||
} | ||
} | ||
|
||
/* | ||
* @notice set an authorizationEngine if not already set | ||
* | ||
*/ | ||
function setDocumentEngine( | ||
IERC1643 documentEngine_ | ||
) external onlyRole(DOCUMENT_ROLE) { | ||
documentEngine = documentEngine_; | ||
emit DocumentEngine(documentEngine_); | ||
} | ||
|
||
|
||
function getDocument(bytes32 _name) public view returns (string memory, bytes32, uint256){ | ||
if(address(documentEngine) != address(0)){ | ||
return documentEngine.getDocument( _name); | ||
} else{ | ||
return ("",0x0, 0); | ||
} | ||
} | ||
|
||
function getAllDocuments() public view returns (bytes32[] memory documents){ | ||
if(address(documentEngine) != address(0)){ | ||
documents = documentEngine.getAllDocuments(); | ||
} | ||
} | ||
|
||
|
||
uint256[50] private __gap; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters