Skip to content

Commit

Permalink
Merge pull request #297 from PolymathNetwork/fix_namespace_squatting_…
Browse files Browse the repository at this point in the history
…in_MR

Fix namespace squatting in MR
  • Loading branch information
satyamakgec authored Oct 2, 2018
2 parents d7fc06a + 8dfa7b3 commit e871913
Show file tree
Hide file tree
Showing 27 changed files with 532 additions and 541 deletions.
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
[__1.5.0__](https://www.npmjs.com/package/polymath-core?activeTab=readme) __15-08-18__

## Added
* Added `getTagsByType`, `getTagsByTypeAndToken`, `getModulesByType`, `getModulesByTypeAndToken` to MR
* Added `getTokensByOwner` to STR
* Added withholding tax to ether & erc20 dividends
* Generalised MakerDAO oracle to allow different instances referencing different currencies
Expand All @@ -24,10 +25,11 @@ All notable changes to this project will be documented in this file.
## Fixed
* Generalize the STO varaible names and added them in `ISTO.sol` to use the common standard in all STOs.
* Generalize the event when any new token get registered with the polymath ecosystem. `LogNewSecurityToken` should emit _ticker, _name, _securityTokenAddress, _owner, _addedAt, _registrant respectively. #230
## Removed

## Removed
* Remove `swarmHash` from the `registerTicker(), addCustomTicker(), generateSecurityToken(), addCustomSecurityToken()` functions of TickerRegistry.sol and SecurityTokenRegistry.sol. #230
* Remove `Log` prefix from all the event present in the ecosystem.
* Remove `Log` prefix from all the event present in the ecosystem.
* Removed `addTagByModuleType` & `removeTagsByModuleType` from MR.

======

Expand Down
95 changes: 56 additions & 39 deletions contracts/ModuleRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
// contains the list of verified modules
mapping (address => bool) public verified;
// Contains the list of the available tags corresponding to each module type
mapping (uint8 => bytes32[]) public availableTags;
*/

///////////
Expand Down Expand Up @@ -70,8 +68,8 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
* @notice Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPausedOrOwner() {
if (msg.sender == owner())
_;
if (msg.sender == owner())
_;
else {
require(!isPaused(), "Already paused");
_;
Expand Down Expand Up @@ -106,7 +104,7 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {

function initialize(address _polymathRegistry, address _owner) external payable {
require(!getBool(Encoder.getKey("initialised")));
require(_owner != address(0) && _polymathRegistry != address(0), "0x address is in-valid");
require(_owner != address(0) && _polymathRegistry != address(0), "0x address is invalid");
set(Encoder.getKey("polymathRegistry"), _polymathRegistry);
set(Encoder.getKey("owner"), _owner);
set(Encoder.getKey("initialised"), true);
Expand Down Expand Up @@ -135,7 +133,7 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
}
}

function _isCompatibleModule(address _moduleFactory, address _securityToken) internal returns(bool) {
function _isCompatibleModule(address _moduleFactory, address _securityToken) internal view returns(bool) {
uint8[] memory _latestVersion = ISecurityToken(_securityToken).getVersion();
uint8[] memory _lowerBound = IModuleFactory(_moduleFactory).getLowerSTVersionBounds();
uint8[] memory _upperBound = IModuleFactory(_moduleFactory).getUpperSTVersionBounds();
Expand All @@ -149,6 +147,12 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
* @param _moduleFactory is the address of the module factory to be registered
*/
function registerModule(address _moduleFactory) external whenNotPausedOrOwner {
if (IFeatureRegistry(getAddress(Encoder.getKey('featureRegistry'))).getFeatureStatus("customModulesAllowed")) {
require(msg.sender == IOwnable(_moduleFactory).owner() || msg.sender == getAddress(Encoder.getKey('owner')),
"msg.sender must be the Module Factory owner or registry curator");
} else {
require(msg.sender == getAddress(Encoder.getKey("owner")), "Only owner allowed to register modules");
}
require(getUint(Encoder.getKey('registry', _moduleFactory)) == 0, "Module factory should not be pre-registered");
IModuleFactory moduleFactory = IModuleFactory(_moduleFactory);
uint8 moduleType = moduleFactory.getType();
Expand Down Expand Up @@ -177,7 +181,7 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
// pop from array and re-order
if (index != last) {
// moduleList[moduleType][index] = temp;
setArrayIndexValue(Encoder.getKey('moduleList', moduleType), index, temp);
setArrayIndexValue(Encoder.getKey('moduleList', moduleType), index, temp);
set(Encoder.getKey('moduleListIndex', temp), index);
}
deleteArrayAddress(Encoder.getKey('moduleList', moduleType), last);
Expand All @@ -201,56 +205,69 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
* @param _moduleFactory is the address of the module factory to be verified
* @return bool
*/
function verifyModule(address _moduleFactory, bool _verified) external onlyOwner returns(bool) {
function verifyModule(address _moduleFactory, bool _verified) external onlyOwner {
require(getUint(Encoder.getKey('registry', _moduleFactory)) != uint256(0), "Module factory must be registered");
set(Encoder.getKey('verified', _moduleFactory), _verified);
emit ModuleVerified(_moduleFactory, _verified);
return true;
}

/**
* @notice Adds a list of tags for the specified Module Factory
* @dev This function is susceptible to hit the block gas limit if too many tags get added.
* @param _moduleType is the module type.
* @param _tag is the list of tags to add.
* @notice Returns all the tags related to the a module type which are valid for the given token
* @param _moduleType is the module type
* @param _securityToken is the token
* @return list of tags
* @return corresponding list of module factories
*/
function addTagByModuleType(uint8 _moduleType, bytes32[] _tag) external onlyOwner {
for (uint8 i = 0; i < _tag.length; i++) {
pushArray(Encoder.getKey('availableTags', uint256(_moduleType)), _tag[i]);
}
}
function getTagsByTypeAndToken(uint8 _moduleType, address _securityToken) external view returns(bytes32[], address[]) {
address[] memory modules = getModulesByTypeAndToken(_moduleType, _securityToken);
return _tagsByModules(modules);
}

/**
* @notice Removes the tag for specified Module Factory
* @dev This function is susceptible to hit the block gas limit if too many tags get removed.
* @param _moduleType is the module type.
* @param _removedTags is the list of tags to remove
* @notice Returns all the tags related to the a module type which are valid for the given token
* @param _moduleType is the module type
* @return list of tags
* @return corresponding list of module factories
*/
function removeTagByModuleType(uint8 _moduleType, bytes32[] _removedTags) external onlyOwner {
for (uint8 i = 0; i < getArrayBytes32(Encoder.getKey('availableTags', uint256(_moduleType))).length; i++) {
for (uint8 j = 0; j < _removedTags.length; j++) {
if (getArrayBytes32(Encoder.getKey('availableTags', uint256(_moduleType)))[i] == _removedTags[j]) {
deleteArrayBytes32(Encoder.getKey('availableTags', uint256(_moduleType)), uint256(i));
}
}
}
function getTagsByType(uint8 _moduleType) external view returns(bytes32[], address[]) {
address[] memory modules = getModulesByType(_moduleType);
return _tagsByModules(modules);
}

/**
* @notice Returns all the tags related to the functionality of the entered Module Factory.
* @param _moduleType is the module type
* @return bytes32 array
* @notice Returns all the tags related to the modules provided
* @param _modules modules to return tags for
* @return list of tags
* @return corresponding list of module factories
*/
function getTagByModuleType(uint8 _moduleType) public view returns(bytes32[]) {
return getArrayBytes32(Encoder.getKey('availableTags', uint256(_moduleType)));
function _tagsByModules(address[] _modules) internal view returns(bytes32[], address[]) {
uint256 counter = 0;
uint256 i;
uint256 j;
for (i = 0; i < _modules.length; i++) {
counter = counter + IModuleFactory(_modules[i]).getTags().length;
}
bytes32[] memory tags = new bytes32[](counter);
address[] memory modules = new address[](counter);
bytes32[] memory tempTags;
counter = 0;
for (i = 0; i < _modules.length; i++) {
tempTags = IModuleFactory(_modules[i]).getTags();
for (j = 0; j < tempTags.length; j++) {
tags[counter] = tempTags[j];
modules[counter] = _modules[i];
counter++;
}
}
return (tags, modules);
}

/**
* @notice Returns the reputation of the entered Module Factory
* @param _factoryAddress is the address of the module factory
* @return address array which contains the list of securityTokens that use that module factory
*/
function getReputationOfFactory(address _factoryAddress) external view returns(address[]) {
function getReputationByFactory(address _factoryAddress) external view returns(address[]) {
return getArrayAddress(Encoder.getKey('reputation', _factoryAddress));
}

Expand All @@ -259,7 +276,7 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
* @param _moduleType Type of Module
* @return address array that contains the list of addresses of module factory contracts.
*/
function getModuleListOfType(uint8 _moduleType) external view returns(address[]) {
function getModulesByType(uint8 _moduleType) public view returns(address[]) {
return getArrayAddress(Encoder.getKey('moduleList', uint256(_moduleType)));
}

Expand All @@ -269,7 +286,7 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
* @param _securityToken is the address of SecurityToken
* @return address array that contains the list of available addresses of module factory contracts.
*/
function getAvailableModulesOfType(uint8 _moduleType, address _securityToken) external view returns (address[]) {
function getModulesByTypeAndToken(uint8 _moduleType, address _securityToken) public view returns (address[]) {
uint256 _len = getArrayAddress(Encoder.getKey('moduleList', uint256(_moduleType))).length;
address[] memory _addressList = getArrayAddress(Encoder.getKey('moduleList', uint256(_moduleType)));
bool _isCustomModuleAllowed = IFeatureRegistry(getAddress(Encoder.getKey('featureRegistry'))).getFeatureStatus("customModulesAllowed");
Expand Down Expand Up @@ -353,7 +370,7 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {

/**
* @notice Check whether the contract operations is paused or not
* @return bool
* @return bool
*/
function isPaused() public view returns(bool) {
return getBool(Encoder.getKey("paused"));
Expand Down
54 changes: 25 additions & 29 deletions contracts/interfaces/IModuleRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,56 +23,52 @@ interface IModuleRegistry {
*/
function removeModule(address _moduleFactory) external;

/**
* @notice Use to get all the tags releated to the functionality of the Module Factory.
* @param _moduleType Type of module
*/
function getTagByModuleType(uint8 _moduleType) external view returns(bytes32[]);

/**
* @notice Called by Polymath to verify modules for SecurityToken to use.
* @notice A module can not be used by an ST unless first approved/verified by Polymath
* @notice (The only exception to this is that the author of the module is the owner of the ST)
* @param _moduleFactory is the address of the module factory to be registered
* @return bool
*/
function verifyModule(address _moduleFactory, bool _verified) external returns(bool);
function verifyModule(address _moduleFactory, bool _verified) external;

/**
* @notice Add the tag for specified Module Factory
* @param _moduleType Type of module.
* @param _tag List of tags
* @notice Used to get the reputation of a Module Factory
* @param _factoryAddress address of the Module Factory
* @return address array which has the list of securityToken's uses that module factory
*/
function addTagByModuleType(uint8 _moduleType, bytes32[] _tag) external;
function getReputationByFactory(address _factoryAddress) external view returns(address[]);

/**
* @notice remove a tag for a Module Factory
* @param _moduleType Type of module.
* @param _removedTags List of tags
*/
function removeTagByModuleType(uint8 _moduleType, bytes32[] _removedTags) external;
/**
* @notice Returns all the tags related to the a module type which are valid for the given token
* @param _moduleType is the module type
* @param _securityToken is the token
* @return list of tags
* @return corresponding list of module factories
*/
function getTagsByTypeAndToken(uint8 _moduleType, address _securityToken) external view returns(bytes32[], address[]);

/**
* @notice Used to get the reputation of a Module Factory
* @param _factoryAddress address of the Module Factory
* @return address array which has the list of securityToken's uses that module factory
* @notice Returns all the tags related to the a module type which are valid for the given token
* @param _moduleType is the module type
* @return list of tags
* @return corresponding list of module factories
*/
function getReputationOfFactory(address _factoryAddress) external view returns(address[]);
function getTagsByType(uint8 _moduleType) external view returns(bytes32[], address[]);

/**
* @notice Use to get the list of Module Factory addresses for a given module type
* @notice Returns the list of addresses of Module Factory of a particular type
* @param _moduleType Type of Module
* @return address array thal contains the list of addresses of module factory contracts.
* @return address array that contains the list of addresses of module factory contracts.
*/
function getModuleListOfType(uint8 _moduleType) external view returns(address[]);
function getModulesByType(uint8 _moduleType) external view returns(address[]);

/**
* @notice Use to get the list of available Module factory addresses for a particular type
* @param _moduleType Type of Module
* @param _securityToken Address of securityToken
* @notice Returns the list of available Module factory addresses of a particular type for a given token.
* @param _moduleType is the module type to look for
* @param _securityToken is the address of SecurityToken
* @return address array that contains the list of available addresses of module factory contracts.
*/
function getAvailableModulesOfType(uint8 _moduleType, address _securityToken) external view returns (address[]);
function getModulesByTypeAndToken(uint8 _moduleType, address _securityToken) external view returns (address[]);

/**
* @notice Use to get the latest contract address of the regstries
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/ISecurityTokenRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ interface ISecurityTokenRegistry {
/**
* @notice get Protocol version
*/
function getProtocolVersion() public view returns(uint8[]);
function getProtocolVersion() external view returns(uint8[]);

/**
* @notice Use to get the ticker list as per the owner
Expand Down
19 changes: 19 additions & 0 deletions contracts/mocks/MockModuleRegistry.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
pragma solidity ^0.4.24;

import "../ModuleRegistry.sol";

/**
* @title Registry contract for issuers to register their security tokens
*/
contract MockModuleRegistry is ModuleRegistry {

/// @notice It is dummy functionality
/// Alert! Alert! Do not use it for the mainnet release
function addMoreReputation(address _moduleFactory, address[] _tokens) public onlyOwner {
for (uint8 i = 0; i < _tokens.length; i++) {
pushArray(Encoder.getKey('reputation', _moduleFactory), _tokens[i]);
}
}


}
18 changes: 0 additions & 18 deletions contracts/mocks/ModuleRegistryMock.sol

This file was deleted.

Loading

0 comments on commit e871913

Please sign in to comment.