Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate Truffle test + Manage documents #269

Merged
merged 13 commits into from
Aug 7, 2024
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ Here is the list of the different version available for each CMTAT version.

| Name | RuleEngine |
| ----------------------- | ------------------------------------------------------------ |
| CMTAT 2.4.0 (unaudited) | Still in development |
| CMTAT 2.4.0 (unaudited) | RuleEngine >=v2.0.0<br />Last version: [v2.0.2](https://github.com/CMTA/RuleEngine/releases/tag/v2.0.2)(unaudited) |
| CMTAT 2.3.0 | [RuleEngine v1.0.2](https://github.com/CMTA/RuleEngine/releases/tag/v1.0.2) |
| CMTAT 2.0 (unaudited) | [RuleEngine 1.0](https://github.com/CMTA/RuleEngine/releases/tag/1.0) (unaudited) |
| CMTAT 1.0 | No ruleEngine available |
Expand Down Expand Up @@ -252,7 +252,16 @@ CMTA providers further documentation describing the CMTAT framework in a platfor
- [CMTA Token (CMTAT)](https://cmta.ch/standards/cmta-token-cmtat)
- [Standard for the tokenization of shares of Swiss corporations using the distributed ledger technology](https://cmta.ch/standards/standard-for-the-tokenization-of-shares-of-swiss-corporations-using-the-distributed-ledger-technology)

## Further reading
- [CMTA - A comparison of different security token standards](https://cmta.ch/news-articles/a-comparison-of-different-security-token-standards)
- [Taurus - Security Token Standards: A Closer Look at CMTAT](https://www.taurushq.com/blog/security-token-standards-a-closer-look-at-cmtat/)
- [Taurus - Equity Tokenization: How to Pay Dividend On-Chain Using CMTAT](https://www.taurushq.com/blog/equity-tokenization-how-to-pay-dividend-on-chain-using-cmtat/)
- [Taurus - Token Transfer Management: How to Apply Restrictions with CMTAT and ERC-1404](https://www.taurushq.com/blog/token-transfer-management-how-to-apply-restrictions-with-cmtat-and-erc-1404/)$

## Others implementations
Two versions are available for the blockchain [Tezos](https://tezos.com)
- [CMTAT FA2](https://github.com/CMTA/CMTAT-Tezos-FA2) Official version written in SmartPy
- [@ligo/cmtat](https://github.com/ligolang/CMTAT-Ligo/) Unofficial version written in Ligo

## Contract size

Expand Down
2 changes: 0 additions & 2 deletions contracts/CMTAT_PROXY.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,4 @@ contract CMTAT_PROXY is CMTAT_BASE {
// Disable the possibility to initialize the implementation
_disableInitializers();
}

uint256[50] private __gap;
}
54 changes: 54 additions & 0 deletions contracts/CMTAT_PROXY_UUPS.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//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";
import "./interfaces/engine/IEngine.sol";
contract CMTAT_PROXY_UUPS is CMTAT_BASE, UUPSUpgradeable {
bytes32 public constant PROXY_UPGRADE_ROLE = keccak256("PROXY_UPGRADE_ROLE");
/**
* @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 information_ additional information to describe the token
* @param engines list of engines
*/
function initialize( address admin,
string memory nameIrrevocable,
string memory symbolIrrevocable,
uint8 decimalsIrrevocable,
string memory tokenId_,
string memory terms_,
string memory information_,
IEngine.Engine memory engines) public override initializer {
CMTAT_BASE.initialize( admin,
nameIrrevocable,
symbolIrrevocable,
decimalsIrrevocable,
tokenId_,
terms_,
information_,
engines);
__UUPSUpgradeable_init_unchained();
}

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

// No storage gap because the contract is deployed in standalone mode
}
13 changes: 5 additions & 8 deletions contracts/deployment/CMTAT_BEACON_FACTORY.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import "../CMTAT_PROXY.sol";
import "../modules/CMTAT_BASE.sol";
import "../libraries/FactoryErrors.sol";
import '@openzeppelin/contracts/access/AccessControl.sol';
import "../interfaces/engine/IEngine.sol";

/**
* @notice Factory to deploy beacon proxy
Expand Down Expand Up @@ -51,30 +52,26 @@ contract CMTAT_BEACON_FACTORY is AccessControl {
function deployCMTAT(
// CMTAT function initialize
address admin,
IAuthorizationEngine authorizationEngineIrrevocable,
string memory nameIrrevocable,
string memory symbolIrrevocable,
uint8 decimalsIrrevocable,
string memory tokenId_,
string memory terms_,
IRuleEngine ruleEngine_,
string memory information_,
uint256 flag_
IEngine.Engine memory engines
) public onlyRole(CMTAT_DEPLOYER_ROLE) returns(BeaconProxy cmtat) {
cmtat = new BeaconProxy(
address(beacon),
abi.encodeWithSelector(
CMTAT_PROXY(address(0)).initialize.selector,
admin,
authorizationEngineIrrevocable,
nameIrrevocable,
symbolIrrevocable,
decimalsIrrevocable,
tokenId_,
terms_,
ruleEngine_,
information_,
flag_
information_,
engines
)
);
cmtats[cmtatCounterId] = address(cmtat);
Expand All @@ -88,7 +85,7 @@ contract CMTAT_BEACON_FACTORY is AccessControl {
* @notice get CMTAT proxy address
*
*/
function getAddress(uint256 cmtatID_) external view returns (address) {
function getCMTATAddress(uint256 cmtatID_) external view returns (address) {
return cmtats[cmtatID_];
}

Expand Down
21 changes: 7 additions & 14 deletions contracts/deployment/CMTAT_TP_FACTORY.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "../CMTAT_PROXY.sol";
import "../libraries/FactoryErrors.sol";
import '@openzeppelin/contracts/utils/Create2.sol';
import '@openzeppelin/contracts/access/AccessControl.sol';
import "../interfaces/engine/IEngine.sol";

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

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

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


function _encodeImplementationArgument( address admin,
IAuthorizationEngine authorizationEngineIrrevocable,
string memory nameIrrevocable,
string memory symbolIrrevocable,
uint8 decimalsIrrevocable,
string memory tokenId_,
string memory terms_,
IRuleEngine ruleEngine_,
string memory information_,
uint256 flag_) internal pure returns(bytes memory){
IEngine.Engine memory engines) internal pure returns(bytes memory){
return abi.encodeWithSelector(
CMTAT_PROXY(address(0)).initialize.selector,
admin,
authorizationEngineIrrevocable,
nameIrrevocable,
symbolIrrevocable,
decimalsIrrevocable,
tokenId_,
terms_,
ruleEngine_,
information_,
flag_
information_,
engines
);
}
}
16 changes: 16 additions & 0 deletions contracts/interfaces/engine/IDebtEngine.sol
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 view returns(IDebtGlobal.DebtBase memory);
/**
* @dev Returns true if the operation is authorized, and false otherwise.
*/
function creditEvents() external view returns(IDebtGlobal.CreditEvents memory);

}
21 changes: 21 additions & 0 deletions contracts/interfaces/engine/IEngine.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//SPDX-License-Identifier: MPL-2.0
import "./IDebtEngine.sol";
import "./IRuleEngine.sol";
import "./IAuthorizationEngine.sol";
import "./draft-IERC1643.sol";

pragma solidity ^0.8.20;

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


}
11 changes: 11 additions & 0 deletions contracts/interfaces/engine/draft-IERC1643.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//SPDX-License-Identifier: MPL-2.0

pragma solidity ^0.8.20;

/// @title IERC1643 Document Management
/// (part of the ERC1400 Security Token Standards)
interface IERC1643 {
// Document Management
function getDocument(bytes32 _name) external view returns (string memory , bytes32, uint256);
function getAllDocuments() external view returns (bytes32[] memory);
}
3 changes: 3 additions & 0 deletions contracts/libraries/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ library Errors {
error CMTAT_AuthorizationModule_InvalidAuthorization();
error CMTAT_AuthorizationModule_AuthorizationEngineAlreadySet();

// DocumentModule
error CMTAT_DocumentModule_SameValue();

// PauseModule
error CMTAT_PauseModule_ContractIsDeactivated();
}
31 changes: 31 additions & 0 deletions contracts/mocks/DebtEngineMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

// SPDX-License-Identifier: MPL-2.0
pragma solidity ^0.8.20;
import "../interfaces/IDebtGlobal.sol";
interface IDebtEngine is IDebtGlobal {
function debt() external view returns (DebtBase memory);
function creditEvents() external view returns (CreditEvents memory);
function setDebt(DebtBase calldata debt_) external;
function setCreditEvents(CreditEvents calldata creditEvents) external;
}

contract DebtEngineMock is IDebtEngine {
DebtBase private _debt;
CreditEvents private _creditEvents;

function debt() external view override returns (DebtBase memory) {
return _debt;
}

function creditEvents() external view override returns (CreditEvents memory) {
return _creditEvents;
}

function setDebt(DebtBase calldata debt_) external override {
_debt = debt_;
}

function setCreditEvents(CreditEvents calldata creditEvents_) external override {
_creditEvents = creditEvents_;
}
}
Loading
Loading