Skip to content

Commit

Permalink
Add ERC20 decimals as an argument of the initialize function
Browse files Browse the repository at this point in the history
  • Loading branch information
rya-sge committed Aug 2, 2023
1 parent 9baf8aa commit 583202a
Show file tree
Hide file tree
Showing 40 changed files with 224 additions and 238 deletions.
4 changes: 2 additions & 2 deletions contracts/CMTAT_PROXY.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import "./modules/CMTAT_BASE.sol";

contract CMTAT_PROXY is CMTAT_BASE {
/**
@notice Contract version for the deployment with a proxy
@param forwarderIrrevocable address of the forwarder, required for the gasless support
* @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(
Expand Down
23 changes: 13 additions & 10 deletions contracts/CMTAT_STANDALONE.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,25 @@ 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 nameIrrevocable name of the token
@param symbolIrrevocable name of the symbol
@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)
* @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 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,
string memory nameIrrevocable,
string memory symbolIrrevocable,
uint8 decimalsIrrevocable,
string memory tokenId_,
string memory terms_,
IEIP1404Wrapper ruleEngine_,
Expand All @@ -35,6 +37,7 @@ contract CMTAT_STANDALONE is CMTAT_BASE {
admin,
nameIrrevocable,
symbolIrrevocable,
decimalsIrrevocable,
tokenId_,
terms_,
ruleEngine_,
Expand Down
40 changes: 26 additions & 14 deletions contracts/modules/CMTAT_BASE.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,24 @@ abstract contract CMTAT_BASE is
CreditEventsModule
{
/**
@notice
initialize the proxy contract
The calls to this function will revert if the contract was deployed without a proxy
* @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 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)
*/
function initialize(
address admin,
string memory nameIrrevocable,
string memory symbolIrrevocable,
uint8 decimalsIrrevocable,
string memory tokenId_,
string memory terms_,
IEIP1404Wrapper ruleEngine_,
Expand All @@ -58,6 +68,7 @@ abstract contract CMTAT_BASE is
admin,
nameIrrevocable,
symbolIrrevocable,
decimalsIrrevocable,
tokenId_,
terms_,
ruleEngine_,
Expand All @@ -67,12 +78,13 @@ abstract contract CMTAT_BASE is
}

/**
@dev calls the different initialize functions from the different modules
* @dev calls the different initialize functions from the different modules
*/
function __CMTAT_init(
address admin,
string memory nameIrrevocable,
string memory symbolIrrevocable,
uint8 decimalsIrrevocable,
string memory tokenId_,
string memory terms_,
IEIP1404Wrapper ruleEngine_,
Expand Down Expand Up @@ -105,7 +117,7 @@ abstract contract CMTAT_BASE is
__MintModule_init_unchained();
// EnforcementModule_init_unchained is called before ValidationModule_init_unchained due to inheritance
__EnforcementModule_init_unchained();
__ERC20Module_init_unchained(0);
__ERC20Module_init_unchained(decimalsIrrevocable);
// PauseModule_init_unchained is called before ValidationModule_init_unchained due to inheritance
__PauseModule_init_unchained();
__ValidationModule_init_unchained();
Expand All @@ -130,7 +142,7 @@ abstract contract CMTAT_BASE is
}

/**
@notice Returns the number of decimals used to get its user representation.
* @notice Returns the number of decimals used to get its user representation.
*/
function decimals()
public
Expand All @@ -155,12 +167,12 @@ abstract contract CMTAT_BASE is
return ERC20BaseModule.transferFrom(sender, recipient, amount);
}

/*
@dev
SnapshotModule:
- override SnapshotModuleInternal if you add the SnapshotModule
e.g. override(SnapshotModuleInternal, ERC20Upgradeable)
- remove the keyword view
/**
* @dev
* SnapshotModule:
* - override SnapshotModuleInternal if you add the SnapshotModule
* e.g. override(SnapshotModuleInternal, ERC20Upgradeable)
* - remove the keyword view
*/
function _beforeTokenTransfer(
address from,
Expand All @@ -180,7 +192,7 @@ abstract contract CMTAT_BASE is
}

/**
@dev This surcharge is not necessary if you do not use the MetaTxModule
* @dev This surcharge is not necessary if you do not use the MetaTxModule
*/
function _msgSender()
internal
Expand All @@ -192,7 +204,7 @@ abstract contract CMTAT_BASE is
}

/**
@dev This surcharge is not necessary if you do not use the MetaTxModule
* @dev This surcharge is not necessary if you do not use the MetaTxModule
*/
function _msgData()
internal
Expand Down
24 changes: 13 additions & 11 deletions contracts/test/CMTATSnapshot/CMTATSnapshotStandaloneTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pragma solidity ^0.8.17;
import "./CMTAT_BASE_SnapshotTest.sol";

contract CMTATSnapshotStandaloneTest is CMTAT_BASE_SnapshotTest {
/**
/**
@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)
Expand All @@ -23,23 +23,25 @@ contract CMTATSnapshotStandaloneTest is CMTAT_BASE_SnapshotTest {
address admin,
string memory nameIrrevocable,
string memory symbolIrrevocable,
string memory tokenId,
string memory terms,
IEIP1404Wrapper ruleEngine,
string memory information,
uint256 flag
uint8 decimalsIrrevocable,
string memory tokenId_,
string memory terms_,
IEIP1404Wrapper ruleEngine_,
string memory information_,
uint256 flag_
) MetaTxModule(forwarderIrrevocable) {
// Initialize the contract to avoid front-running
// Warning : do not initialize the proxy
initialize(
admin,
nameIrrevocable,
symbolIrrevocable,
tokenId,
terms,
ruleEngine,
information,
flag
decimalsIrrevocable,
tokenId_,
terms_,
ruleEngine_,
information_,
flag_
);
}

Expand Down
46 changes: 24 additions & 22 deletions contracts/test/CMTATSnapshot/CMTAT_BASE_SnapshotTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ abstract contract CMTAT_BASE_SnapshotTest is
DebtBaseModule,
CreditEventsModule
{
/**
/**
@notice
initialize the proxy contract
The calls to this function will revert if the contract was deployed without a proxy
Expand All @@ -48,37 +48,39 @@ abstract contract CMTAT_BASE_SnapshotTest is
address admin,
string memory nameIrrevocable,
string memory symbolIrrevocable,
string memory tokenId,
string memory terms,
IEIP1404Wrapper ruleEngine,
string memory information,
uint256 flag
uint8 decimalsIrrevocable,
string memory tokenId_,
string memory terms_,
IEIP1404Wrapper ruleEngine_,
string memory information_,
uint256 flag_
) public initializer {
__CMTAT_init(
admin,
nameIrrevocable,
symbolIrrevocable,
tokenId,
terms,
ruleEngine,
information,
flag
decimalsIrrevocable,
tokenId_,
terms_,
ruleEngine_,
information_,
flag_
);
}

/**
@dev calls the different initialize functions from the different modules
@param admin the address has to be different from 0, check made in AuthorizationModule
*/
function __CMTAT_init(
address admin,
string memory nameIrrevocable,
string memory symbolIrrevocable,
string memory tokenId,
string memory terms,
IEIP1404Wrapper ruleEngine,
string memory information,
uint256 flag
uint8 decimalsIrrevocable,
string memory tokenId_,
string memory terms_,
IEIP1404Wrapper ruleEngine_,
string memory information_,
uint256 flag_
) internal onlyInitializing {
/* OpenZeppelin library */
// OZ init_unchained functions are called firstly due to inheritance
Expand All @@ -95,10 +97,9 @@ abstract contract CMTAT_BASE_SnapshotTest is
/*
SnapshotModule:
Add this call in case you add the SnapshotModule
*/
__Snapshot_init_unchained();

__Validation_init_unchained(ruleEngine);
*/
__Validation_init_unchained(ruleEngine_);

/* Wrapper */
// AuthorizationModule_init_unchained is called firstly due to inheritance
Expand All @@ -107,7 +108,7 @@ abstract contract CMTAT_BASE_SnapshotTest is
__MintModule_init_unchained();
// EnforcementModule_init_unchained is called before ValidationModule_init_unchained due to inheritance
__EnforcementModule_init_unchained();
__ERC20Module_init_unchained(0);
__ERC20Module_init_unchained(decimalsIrrevocable);
// PauseModule_init_unchained is called before ValidationModule_init_unchained due to inheritance
__PauseModule_init_unchained();
__ValidationModule_init_unchained();
Expand All @@ -117,11 +118,12 @@ abstract contract CMTAT_BASE_SnapshotTest is
Add this call in case you add the SnapshotModule
*/
__SnasphotModule_init_unchained();


/* Other modules */
__DebtBaseModule_init_unchained();
__CreditEvents_init_unchained();
__Base_init_unchained(tokenId, terms, information, flag);
__Base_init_unchained(tokenId_, terms_, information_, flag_);

/* own function */
__CMTAT_init_unchained();
Expand Down
39 changes: 21 additions & 18 deletions contracts/test/killTest/CMTATKillTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,23 @@ contract CMTAT_KILL_TEST is
address admin,
string memory nameIrrevocable,
string memory symbolIrrevocable,
string memory tokenId,
string memory terms,
IEIP1404Wrapper ruleEngine,
string memory information,
uint256 flag
uint8 decimalsIrrevocable,
string memory tokenId_,
string memory terms_,
IEIP1404Wrapper ruleEngine_,
string memory information_,
uint256 flag_
) public initializer {
__CMTAT_init(
admin,
nameIrrevocable,
symbolIrrevocable,
tokenId,
terms,
ruleEngine,
information,
flag
decimalsIrrevocable,
tokenId_,
terms_,
ruleEngine_,
information_,
flag_
);
}

Expand All @@ -89,11 +91,12 @@ contract CMTAT_KILL_TEST is
address admin,
string memory nameIrrevocable,
string memory symbolIrrevocable,
string memory tokenId,
string memory terms,
IEIP1404Wrapper ruleEngine,
string memory information,
uint256 flag
uint8 decimalsIrrevocable,
string memory tokenId_,
string memory terms_,
IEIP1404Wrapper ruleEngine_,
string memory information_,
uint256 flag_
) internal onlyInitializing {
/* OpenZeppelin library */
// OZ init_unchained functions are called firstly due to inheritance
Expand All @@ -112,7 +115,7 @@ contract CMTAT_KILL_TEST is
Add this call in case you add the SnapshotModule
__Snapshot_init_unchained();
*/
__Validation_init_unchained(ruleEngine);
__Validation_init_unchained(ruleEngine_);

/* Wrapper */
// AuthorizationModule_init_unchained is called firstly due to inheritance
Expand All @@ -121,7 +124,7 @@ contract CMTAT_KILL_TEST is
__MintModule_init_unchained();
// EnforcementModule_init_unchained is called before ValidationModule_init_unchained due to inheritance
__EnforcementModule_init_unchained();
__ERC20Module_init_unchained(0);
__ERC20Module_init_unchained(decimalsIrrevocable);
// PauseModule_init_unchained is called before ValidationModule_init_unchained due to inheritance
__PauseModule_init_unchained();
__ValidationModule_init_unchained();
Expand All @@ -135,7 +138,7 @@ contract CMTAT_KILL_TEST is
/* Other modules */
__DebtBaseModule_init_unchained();
__CreditEvents_init_unchained();
__Base_init_unchained(tokenId, terms, information, flag);
__Base_init_unchained(tokenId_, terms_, information_, flag_);

/* own function */
__CMTAT_init_unchained();
Expand Down
1 change: 1 addition & 0 deletions migrations/1_deploy_contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = async function (deployer, _network, account) {
admin,
"Test CMTA Token",
"TCMTAT",
0,
"TCMTAT_ISIN",
"https://cmta.ch",
ZERO_ADDRESS,
Expand Down
Loading

0 comments on commit 583202a

Please sign in to comment.