Skip to content

Commit

Permalink
Merge branch 'development-1.5.0' into singleTradeVolumeRestriction
Browse files Browse the repository at this point in the history
  • Loading branch information
subramanianv authored Sep 28, 2018
2 parents 0c010be + 4570480 commit 5b9c588
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 18 deletions.
16 changes: 14 additions & 2 deletions contracts/ModuleRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
/**
* @notice Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPausedOrOwner() {
if (msg.sender == getAddress(Encoder.getKey("owner")))
_;
else {
require(!getBool(Encoder.getKey("paused")), "Already paused");
_;
}
}

/**
* @notice Modifier to make a function callable only when the contract is not paused and ignore is msg.sender is owner.
*/
modifier whenNotPaused() {
require(!getBool(Encoder.getKey("paused")), "Already paused");
_;
Expand Down Expand Up @@ -131,7 +143,7 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
* @notice Called by the ModuleFactory owner to register new modules for SecurityTokens to use
* @param _moduleFactory is the address of the module factory to be registered
*/
function registerModule(address _moduleFactory) external whenNotPaused {
function registerModule(address _moduleFactory) external whenNotPausedOrOwner {
require(getUint(Encoder.getKey('registry', _moduleFactory)) == 0, "Module factory should not be pre-registered");
IModuleFactory moduleFactory = IModuleFactory(_moduleFactory);
uint8 moduleType = moduleFactory.getType();
Expand All @@ -146,7 +158,7 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
* @notice Called by the ModuleFactory owner or registry curator to delete a ModuleFactory from the registry
* @param _moduleFactory is the address of the module factory to be deleted from the registry
*/
function removeModule(address _moduleFactory) external whenNotPaused {
function removeModule(address _moduleFactory) external whenNotPausedOrOwner {
uint256 moduleType = getUint(Encoder.getKey('registry', _moduleFactory));

require(moduleType != 0, "Module factory should be registered");
Expand Down
37 changes: 25 additions & 12 deletions contracts/SecurityTokenRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,24 @@ contract SecurityTokenRegistry is ISecurityTokenRegistry, EternalStorage {
/**
* @notice Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPausedOrOwner() {
if (msg.sender == getAddress(Encoder.getKey("owner")))
_;
else {
require(!getBool(Encoder.getKey("paused")), "Already paused");
_;
}
}

/**
* @notice Modifier to make a function callable only when the contract is not paused and ignore is msg.sender is owner.
*/
modifier whenNotPaused() {
require(!getBool(Encoder.getKey("paused")), "Already paused");
_;
}


/**
* @notice Modifier to make a function callable only when the contract is paused.
*/
Expand Down Expand Up @@ -149,7 +162,7 @@ contract SecurityTokenRegistry is ISecurityTokenRegistry, EternalStorage {
*/
function initialize(address _polymathRegistry, address _STFactory, uint256 _stLaunchFee, uint256 _tickerRegFee, address _polyToken, address _owner) payable external {
require(!getBool(Encoder.getKey("initialised")));
require(_STFactory != address(0) && _polyToken != address(0) && _owner != address(0) && _polymathRegistry != address(0), "0x address is in-valid");
require(_STFactory != address(0) && _polyToken != address(0) && _owner != address(0) && _polymathRegistry != address(0), "In-valid address");
require(_stLaunchFee != 0 && _tickerRegFee != 0, "Fees should not be 0");
// address polyToken = _polyToken;
set(Encoder.getKey("polyToken"), _polyToken);
Expand All @@ -175,7 +188,7 @@ contract SecurityTokenRegistry is ISecurityTokenRegistry, EternalStorage {
* @param _ticker is unique token ticker
* @param _tokenName is the name of the token
*/
function registerTicker(address _owner, string _ticker, string _tokenName) external whenNotPaused {
function registerTicker(address _owner, string _ticker, string _tokenName) external whenNotPausedOrOwner {
require(_owner != address(0), "Owner should not be 0x");
require(bytes(_ticker).length > 0 && bytes(_ticker).length <= 10, "Ticker length range (0,10]");
// Attempt to charge the reg fee if it is > 0 POLY
Expand Down Expand Up @@ -205,7 +218,7 @@ contract SecurityTokenRegistry is ISecurityTokenRegistry, EternalStorage {
require(bytes(_ticker).length > 0 && bytes(_ticker).length <= 10, "Ticker length range (0,10]");
require(_expiryDate != 0 && _registrationDate != 0, "Dates should not be 0");
require(_registrationDate <= _expiryDate, "Registration date should < expiry date");
require(_owner != address(0), "Address should not be 0x");
require(_owner != address(0), "In-valid address");
string memory ticker = Util.upper(_ticker);
_modifyTicker(_owner, ticker, _tokenName, _registrationDate, _expiryDate, _status);
}
Expand Down Expand Up @@ -237,7 +250,7 @@ contract SecurityTokenRegistry is ISecurityTokenRegistry, EternalStorage {
function removeTicker(string _ticker) external onlyOwner {
string memory ticker = Util.upper(_ticker);
address owner = getAddress(Encoder.getKey("registeredTickers_owner", ticker));
require(owner != address(0), "Ticker does not exist");
require(owner != address(0), "Ticker doesn't exist");
_deleteTickerOwnership(owner, ticker);
set(Encoder.getKey("tickerToSecurityToken", ticker), address(0));
_storeTickerDetails(ticker, address(0), 0, 0, "", false);
Expand Down Expand Up @@ -304,9 +317,9 @@ contract SecurityTokenRegistry is ISecurityTokenRegistry, EternalStorage {
* @param _newOwner is the address of the new owner of the ticker
* @param _ticker is the ticker symbol
*/
function transferTickerOwnership(address _newOwner, string _ticker) external whenNotPaused {
function transferTickerOwnership(address _newOwner, string _ticker) external whenNotPausedOrOwner {
string memory ticker = Util.upper(_ticker);
require(_newOwner != address(0), "Address should not be 0x");
require(_newOwner != address(0), "In-valid address");
require(getAddress(Encoder.getKey("registeredTickers_owner", ticker)) == msg.sender, "Not authorised");
_transferTickerOwnership(msg.sender, _newOwner, ticker);
set(Encoder.getKey("registeredTickers_owner", ticker), _newOwner);
Expand All @@ -320,7 +333,7 @@ contract SecurityTokenRegistry is ISecurityTokenRegistry, EternalStorage {
*/
function _transferTickerOwnership(address _oldOwner, address _newOwner, string _ticker) internal {
if(getBool(Encoder.getKey("registeredTickers_status", _ticker)))
require(IOwnable(getAddress(Encoder.getKey("tickerToSecurityToken", _ticker))).owner() == _newOwner, "If the token exists, the ticker can only be transferred to its owner");
require(IOwnable(getAddress(Encoder.getKey("tickerToSecurityToken", _ticker))).owner() == _newOwner, "Ticker can only be transferred to its token owner");

_deleteTickerOwnership(_oldOwner, _ticker);
_setTickerOwner(_newOwner, _ticker);
Expand Down Expand Up @@ -448,18 +461,18 @@ contract SecurityTokenRegistry is ISecurityTokenRegistry, EternalStorage {
* @param _tokenDetails is the off-chain details of the token
* @param _divisible is whether or not the token is divisible
*/
function generateSecurityToken(string _name, string _ticker, string _tokenDetails, bool _divisible) external whenNotPaused {
function generateSecurityToken(string _name, string _ticker, string _tokenDetails, bool _divisible) external whenNotPausedOrOwner {
require(bytes(_name).length > 0 && bytes(_ticker).length > 0, "Ticker length > 0");
string memory ticker = Util.upper(_ticker);

require(getBool(Encoder.getKey("registeredTickers_status", ticker)) != true, "Ticker already deployed");
require(getAddress(Encoder.getKey("registeredTickers_owner", ticker)) == msg.sender, "Ticker and token should have same owner");
require(getUint(Encoder.getKey("registeredTickers_expiryDate", ticker)) >= now, "Ticker should not have expired");
require(getBool(Encoder.getKey("registeredTickers_status", ticker)) != true, "Already deployed");
require(getAddress(Encoder.getKey("registeredTickers_owner", ticker)) == msg.sender, "Not authorised");
require(getUint(Encoder.getKey("registeredTickers_expiryDate", ticker)) >= now, "Ticker gets expired");

set(Encoder.getKey("registeredTickers_status", ticker), true);

if (getUint(Encoder.getKey("stLaunchFee")) > 0)
require(IERC20(getAddress(Encoder.getKey("polyToken"))).transferFrom(msg.sender, address(this), getUint(Encoder.getKey("stLaunchFee"))), "Sufficent allowance is not provided");
require(IERC20(getAddress(Encoder.getKey("polyToken"))).transferFrom(msg.sender, address(this), getUint(Encoder.getKey("stLaunchFee"))), "Insufficient allowance");

address newSecurityTokenAddress = ISTFactory(getSTFactoryAddress()).deployToken(
_name,
Expand Down
5 changes: 2 additions & 3 deletions contracts/mocks/SecurityTokenRegistryMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ contract SecurityTokenRegistryMock is SecurityTokenRegistry {

/// @notice It is dummy functionality
/// Alert! Alert! Do not use it for the mainnet release
function changeTheDeployedAddress(string _ticker, address _newSecurityTokenAddress) public onlyOwner {
string memory __ticker = Util.upper(_ticker);
set(Encoder.getKey("tickerToSecurityToken", __ticker), _newSecurityTokenAddress);
function changeTheDeployedAddress(string _ticker, address _newSecurityTokenAddress) public {
set(Encoder.getKey("tickerToSecurityToken", _ticker), _newSecurityTokenAddress);
}

}
2 changes: 1 addition & 1 deletion test/k_module_registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ contract('ModuleRegistry', accounts => {
await I_MRProxied.pause({from: account_polymath});
let errorThrown = false;
try {
let tx = await I_MRProxied.registerModule(I_GeneralTransferManagerFactory.address, {from: account_polymath});
let tx = await I_MRProxied.registerModule(I_GeneralTransferManagerFactory.address, {from: account_delegate});
} catch(error) {
console.log(` tx -> revert because already registered modules are not allowed`);
errorThrown = true;
Expand Down

0 comments on commit 5b9c588

Please sign in to comment.