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

Upgradeable Module Registry #265

Merged
merged 26 commits into from
Sep 27, 2018
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0839c14
intial verrsion of MR
SatyamSB Sep 18, 2018
345b5d2
fix the migrations and adding the updater functionality in the MR
SatyamSB Sep 18, 2018
119a837
add getter
SatyamSB Sep 19, 2018
9b83be2
Merge branch 'development-1.5.0' into upgrade-mr
SatyamSB Sep 19, 2018
793eea2
add the versioning concept into the modules
SatyamSB Sep 21, 2018
87fd4eb
merge dev-1.5.0
SatyamSB Sep 21, 2018
05ae051
remove bug from the library
SatyamSB Sep 21, 2018
057ba09
small fix
SatyamSB Sep 21, 2018
f0846f6
remove the Log prefix from the name of the event
SatyamSB Sep 21, 2018
7a4e9f7
add proxy for the USDTiered deployment
SatyamSB Sep 21, 2018
6ce4db0
add restriction
SatyamSB Sep 21, 2018
55e47b4
typo fix
SatyamSB Sep 22, 2018
38f919b
test cases improvement related to upgradeable MR
SatyamSB Sep 26, 2018
a2f5f9c
resolve conflicts
SatyamSB Sep 26, 2018
16373dc
add test cases for the module registry proxy
SatyamSB Sep 26, 2018
f157b85
minor fix
SatyamSB Sep 26, 2018
38edf14
remove old mr contract to increase the coverage
SatyamSB Sep 26, 2018
a27e3fb
resolve merge conflicts
SatyamSB Sep 26, 2018
9a69957
Merge branch 'development-1.5.0' into upgrade-mr
adamdossa Sep 26, 2018
a3b7d25
comments cleanup
pabloruiz55 Sep 26, 2018
2ab4d8d
Merge branch 'upgrade-mr' of https://github.com/PolymathNetwork/polym…
pabloruiz55 Sep 26, 2018
5d76ff8
add IOwnable in mr
SatyamSB Sep 26, 2018
06caf7a
Merge branch 'upgrade-mr' of https://github.com/PolymathNetwork/polym…
SatyamSB Sep 26, 2018
fb70134
more comments fixing
pabloruiz55 Sep 26, 2018
5cbafb3
add setters for index value and add the getVersion() in ST
SatyamSB Sep 27, 2018
1274e92
minor fix
SatyamSB Sep 27, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ All notable changes to this project will be documented in this file.
* 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
* Remove `swarmHash` from the `registerTicker(), addCustomTicker(), generateSecurityToken(), addCustomSecurityToken()` functions of TickerRegistry.sol and SecurityTokenRegistry.sol. #230
* 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.

======

Expand Down
4 changes: 2 additions & 2 deletions contracts/FeatureRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ contract FeatureRegistry is IFeatureRegistry, ReclaimTokens {

mapping (bytes32 => bool) public featureStatus;

event LogChangeFeatureStatus(string _nameKey, bool _newStatus);
event ChangeFeatureStatus(string _nameKey, bool _newStatus);

/**
* @notice Get the status of a feature
Expand All @@ -31,7 +31,7 @@ contract FeatureRegistry is IFeatureRegistry, ReclaimTokens {
function setFeatureStatus(string _nameKey, bool _newStatus) public onlyOwner {
bytes32 key = keccak256(bytes(_nameKey));
require(featureStatus[key] != _newStatus, "Status unchanged");
emit LogChangeFeatureStatus(_nameKey, _newStatus);
emit ChangeFeatureStatus(_nameKey, _newStatus);
featureStatus[key] = _newStatus;
}

Expand Down
262 changes: 192 additions & 70 deletions contracts/ModuleRegistry.sol

Large diffs are not rendered by default.

200 changes: 200 additions & 0 deletions contracts/OldModuleRegistry.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
pragma solidity ^0.4.24;

import "./interfaces/IModuleRegistry.sol";
import "./interfaces/IModuleFactory.sol";
import "./interfaces/ISecurityTokenRegistry.sol";
import "./interfaces/IFeatureRegistry.sol";
import "./Pausable.sol";
import "./RegistryUpdater.sol";
import "./ReclaimTokens.sol";

/**
* @title Registry contract to store registered modules
* @notice Anyone can register modules, but only those "approved" by Polymath will be available for issuers to add
*/
contract OldModuleRegistry is IModuleRegistry, Pausable, RegistryUpdater, ReclaimTokens {

// Mapping used to hold the type of module factory corresponds to the address of the Module factory contract
mapping (address => uint8) public registry;
// Mapping used to hold the reputation of the factory
mapping (address => address[]) public reputation;
// Mapping contain the list of addresses of Module factory for a particular type
mapping (uint8 => address[]) public moduleList;
// Mapping to store the index of the moduleFactory in the moduleList
mapping(address => uint8) private moduleListIndex;
// contains the list of verified modules
mapping (address => bool) public verified;
// Contains the list of the available tags corresponds to the module type
mapping (uint8 => bytes32[]) public availableTags;

// Emit when Module been used by the securityToken
event LogModuleUsed(address indexed _moduleFactory, address indexed _securityToken);
// Emit when the Module Factory get registered with the ModuleRegistry contract
event LogModuleRegistered(address indexed _moduleFactory, address indexed _owner);
// Emit when the module get verified by the Polymath team
event LogModuleVerified(address indexed _moduleFactory, bool _verified);
// Emit when a moduleFactory is removed by Polymath or moduleFactory owner
event LogModuleRemoved(address indexed _moduleFactory, address indexed _decisionMaker);

constructor (address _polymathRegistry) public
RegistryUpdater(_polymathRegistry)
{
}

/**
* @notice Called by a security token to check if the ModuleFactory is verified or appropriate custom module
* @dev ModuleFactory reputation increases by one every time it is deployed
* @dev Any module can be added during token creation without being registered if it is defined in the token proxy deployment contract
* @dev The feature switch for custom modules is labelled "customModulesAllowed"
* @param _moduleFactory is the address of the relevant module factory
*/
function useModule(address _moduleFactory) external {
// This if statement is required to be able to add modules from the token proxy contract during deployment
if (ISecurityTokenRegistry(securityTokenRegistry).isSecurityToken(msg.sender)) {
if (IFeatureRegistry(featureRegistry).getFeatureStatus("customModulesAllowed")) {
require(verified[_moduleFactory]||(Ownable(_moduleFactory).owner() == Ownable(msg.sender).owner()),
"ModuleFactory must be verified or SecurityToken owner must be ModuleFactory owner");
} else {
require(verified[_moduleFactory], "ModuleFactory must be verified");
}
require(registry[_moduleFactory] != 0, "ModuleFactory type should not be 0");
reputation[_moduleFactory].push(msg.sender);
emit LogModuleUsed(_moduleFactory, msg.sender);
}
}

/**
* @notice Called by moduleFactory owner to register new modules for SecurityToken to use
* @param _moduleFactory is the address of the module factory to be registered
* @return bool
*/
function registerModule(address _moduleFactory) external whenNotPaused returns(bool) {
require(registry[_moduleFactory] == 0, "Module factory should not be pre-registered");
IModuleFactory moduleFactory = IModuleFactory(_moduleFactory);
uint8 moduleType = moduleFactory.getType();
require(moduleType != 0, "Factory moduleType should not equal to 0");
registry[_moduleFactory] = moduleType;
moduleListIndex[_moduleFactory] = uint8(moduleList[moduleType].length);
moduleList[moduleType].push(_moduleFactory);
reputation[_moduleFactory] = new address[](0);
emit LogModuleRegistered (_moduleFactory, Ownable(_moduleFactory).owner());
return true;
}

/**
* @notice Called by moduleFactory owner or registry curator to delete a moduleFactory
* @param _moduleFactory is the address of the module factory to be deleted
* @return bool
*/
function removeModule(address _moduleFactory) external whenNotPaused returns(bool) {
uint8 moduleType = registry[_moduleFactory];

require(moduleType != 0, "Module factory should be registered");
require(msg.sender == Ownable(_moduleFactory).owner() || msg.sender == owner,
"msg.sender must be moduleFactory owner or registry curator");

uint8 index = moduleListIndex[_moduleFactory];
uint8 last = uint8(moduleList[moduleType].length - 1);
address temp = moduleList[moduleType][last];

// pop from array and re-order
if (index != last) {
moduleList[moduleType][index] = temp;
moduleListIndex[temp] = index;
}
delete moduleList[moduleType][last];
moduleList[moduleType].length--;

delete registry[_moduleFactory];
delete reputation[_moduleFactory];
delete verified[_moduleFactory];
delete moduleListIndex[_moduleFactory];

emit LogModuleRemoved (_moduleFactory, msg.sender);
return true;
}

/**
* @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 onlyOwner returns(bool) {
//Must already have been registered
require(registry[_moduleFactory] != 0, "Module factory should have been already registered");
verified[_moduleFactory] = _verified;
emit LogModuleVerified(_moduleFactory, _verified);
return true;
}

/**
* @notice Add the tag for specified Module Factory
* @param _moduleType Type of module.
* @param _tag List of tags
*/
function addTagByModuleType(uint8 _moduleType, bytes32[] _tag) external onlyOwner {
for (uint8 i = 0; i < _tag.length; i++) {
availableTags[_moduleType].push(_tag[i]);
}
}

/**
* @notice remove the tag for specified Module Factory
* @param _moduleType Type of module.
* @param _removedTags List of tags
*/
function removeTagByModuleType(uint8 _moduleType, bytes32[] _removedTags) external onlyOwner {
for (uint8 i = 0; i < availableTags[_moduleType].length; i++) {
for (uint8 j = 0; j < _removedTags.length; j++) {
if (availableTags[_moduleType][i] == _removedTags[j]) {
delete availableTags[_moduleType][i];
}
}
}
}

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

/**
* @notice Use to get the reputation of the Module factory
* @param _factoryAddress Ethereum contract address of the module factory
* @return address array which have the list of securityToken's uses that module factory
*/
function getReputationOfFactory(address _factoryAddress) external view returns(address[]) {
return reputation[_factoryAddress];
}

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

/**
* @notice pause registration function
*/
function unpause() public onlyOwner {
_unpause();
}

/**
* @notice unpause registration function
*/
function pause() public onlyOwner {
_pause();
}


}
8 changes: 4 additions & 4 deletions contracts/PolymathRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ contract PolymathRegistry is ReclaimTokens {

mapping (bytes32 => address) public storedAddresses;

event LogChangeAddress(string _nameKey, address indexed _oldAddress, address indexed _newAddress);
event ChangeAddress(string _nameKey, address indexed _oldAddress, address indexed _newAddress);

/**
* @notice Get the contract address
* @param _nameKey is the key for the contract address mapping
* @return address
*/
function getAddress(string _nameKey) view public returns(address) {
function getAddress(string _nameKey) view external returns(address) {
bytes32 key = keccak256(bytes(_nameKey));
require(storedAddresses[key] != address(0), "Invalid address key");
return storedAddresses[key];
Expand All @@ -27,9 +27,9 @@ contract PolymathRegistry is ReclaimTokens {
* @param _nameKey is the key for the contract address mapping
* @param _newAddress is the new contract address
*/
function changeAddress(string _nameKey, address _newAddress) public onlyOwner {
function changeAddress(string _nameKey, address _newAddress) external onlyOwner {
bytes32 key = keccak256(bytes(_nameKey));
emit LogChangeAddress(_nameKey, storedAddresses[key], _newAddress);
emit ChangeAddress(_nameKey, storedAddresses[key], _newAddress);
storedAddresses[key] = _newAddress;
}

Expand Down
Loading