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 all 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
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ 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
* Remove `swarmHash` from the `registerTicker(), addCustomTicker(), generateSecurityToken(), addCustomSecurityToken()` functions of TickerRegistry.sol and SecurityTokenRegistry.sol. #230

## 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.

======

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
328 changes: 225 additions & 103 deletions contracts/ModuleRegistry.sol

Large diffs are not rendered by default.

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
78 changes: 51 additions & 27 deletions contracts/SecurityTokenRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import "./interfaces/ISecurityTokenRegistry.sol";
import "./storage/EternalStorage.sol";
import "./libraries/Util.sol";
import "./libraries/Encoder.sol";
import "./libraries/VersionUtils.sol";

/**
* @title Registry contract for issuers to register their tickers and security tokens
Expand All @@ -21,6 +22,7 @@ contract SecurityTokenRegistry is ISecurityTokenRegistry, EternalStorage {
uint256 public stLaunchFee;
uint256 public tickerRegFee;
uint256 public expiryLimit;
uint256 public latestProtocolVersion;
bool public paused;
address public owner;
address public polymathRegistry;
Expand All @@ -34,6 +36,13 @@ contract SecurityTokenRegistry is ISecurityTokenRegistry, EternalStorage {
mapping(string => TickerDetails) registeredTickers;
mapping(address => SecurityTokenData) securityTokens;
mapping(bytes32 => address) protocolVersionST;
mapping(uint256 => ProtocolVersion) versionData;

struct ProtocolVersion {
uint8 major;
uint8 minor;
uint8 patch;
}

struct TickerDetails {
address owner;
Expand All @@ -58,21 +67,21 @@ contract SecurityTokenRegistry is ISecurityTokenRegistry, EternalStorage {
// Emit when network becomes unpaused
event Unpause(uint256 _timestamp);
// Emit when the ticker is removed from the registry
event LogTickerRemoved(string _ticker, uint256 _removedAt, address _removedBy);
event TickerRemoved(string _ticker, uint256 _removedAt, address _removedBy);
// Emit when the token ticker expiry is changed
event LogChangeExpiryLimit(uint256 _oldExpiry, uint256 _newExpiry);
event ChangeExpiryLimit(uint256 _oldExpiry, uint256 _newExpiry);
// Emit when changeSecurityLaunchFee is called
event LogChangeSecurityLaunchFee(uint256 _oldFee, uint256 _newFee);
event ChangeSecurityLaunchFee(uint256 _oldFee, uint256 _newFee);
// Emit when changeTickerRegistrationFee is called
event LogChangeTickerRegistrationFee(uint256 _oldFee, uint256 _newFee);
event ChangeTickerRegistrationFee(uint256 _oldFee, uint256 _newFee);
// Emit when ownership gets transferred
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
// Emit when ownership of the ticker gets changed
event LogChangeTickerOwnership(string _ticker, address indexed _oldOwner, address indexed _newOwner);
event ChangeTickerOwnership(string _ticker, address indexed _oldOwner, address indexed _newOwner);
// Emit when a ticker details is modified
event LogModifyTickerDetails(address _owner, string _ticker, string _name, uint256 _registrationDate, uint256 _expiryDate, bool _status);
event ModifyTickerDetails(address _owner, string _ticker, string _name, uint256 _registrationDate, uint256 _expiryDate, bool _status);
// Emit at the time of launching a new security token
event LogNewSecurityToken(
event NewSecurityToken(
string _ticker,
string _name,
address indexed _securityTokenAddress,
Expand All @@ -82,7 +91,7 @@ contract SecurityTokenRegistry is ISecurityTokenRegistry, EternalStorage {
bool _fromAdmin
);
// Emit after ticker registration
event LogRegisterTicker(
event RegisterTicker(
address indexed _owner,
string _ticker,
string _name,
Expand Down Expand Up @@ -146,11 +155,11 @@ contract SecurityTokenRegistry is ISecurityTokenRegistry, EternalStorage {
set(Encoder.getKey("polyToken"), _polyToken);
set(Encoder.getKey("stLaunchFee"), _stLaunchFee);
set(Encoder.getKey("tickerRegFee"), _tickerRegFee);
set(Encoder.getKey("expiryLimit"), uint256(15 * 1 days));
set(Encoder.getKey("expiryLimit"), uint256(60 * 1 days));
set(Encoder.getKey("paused"), false);
set(Encoder.getKey("owner"), _owner);
set(Encoder.getKey("polymathRegistry"), _polymathRegistry);
_setProtocolVersion(_STFactory, "0.0.1");
_setProtocolVersion(_STFactory, uint8(0), uint8(0), uint8(2));
set(Encoder.getKey("initialised"), true);
}

Expand Down Expand Up @@ -218,7 +227,7 @@ contract SecurityTokenRegistry is ISecurityTokenRegistry, EternalStorage {
set(Encoder.getKey("tickerToSecurityToken", _ticker), address(0));
}
_storeTickerDetails(_ticker, _owner, _registrationDate, _expiryDate, _tokenName, _status);
emit LogRegisterTicker(_owner, _ticker, _tokenName, _registrationDate, _expiryDate, true);
emit RegisterTicker(_owner, _ticker, _tokenName, _registrationDate, _expiryDate, true);
}

/**
Expand All @@ -232,7 +241,7 @@ contract SecurityTokenRegistry is ISecurityTokenRegistry, EternalStorage {
_deleteTickerOwnership(owner, ticker);
set(Encoder.getKey("tickerToSecurityToken", ticker), address(0));
_storeTickerDetails(ticker, address(0), 0, 0, "", false);
emit LogTickerRemoved(_ticker, now, msg.sender);
emit TickerRemoved(_ticker, now, msg.sender);
}

/**
Expand All @@ -256,7 +265,7 @@ contract SecurityTokenRegistry is ISecurityTokenRegistry, EternalStorage {
function _addTicker(address _owner, string _ticker, string _tokenName, uint256 _registrationDate, uint256 _expiryDate, bool _status, bool _fromAdmin) internal {
_setTickerOwner(_owner, _ticker);
_storeTickerDetails(_ticker, _owner, _registrationDate, _expiryDate, _tokenName, _status);
emit LogRegisterTicker(_owner, _ticker, _tokenName, _registrationDate, _expiryDate, _fromAdmin);
emit RegisterTicker(_owner, _ticker, _tokenName, _registrationDate, _expiryDate, _fromAdmin);
}

/**
Expand Down Expand Up @@ -312,7 +321,7 @@ contract SecurityTokenRegistry is ISecurityTokenRegistry, EternalStorage {
function _transferTickerOwnership(address _oldOwner, address _newOwner, string _ticker) internal {
_deleteTickerOwnership(_oldOwner, _ticker);
_setTickerOwner(_newOwner, _ticker);
emit LogChangeTickerOwnership(_ticker, _oldOwner, _newOwner);
emit ChangeTickerOwnership(_ticker, _oldOwner, _newOwner);
}

/**
Expand All @@ -336,7 +345,7 @@ contract SecurityTokenRegistry is ISecurityTokenRegistry, EternalStorage {
*/
function changeExpiryLimit(uint256 _newExpiry) external onlyOwner {
require(_newExpiry >= 1 days, "Expiry should >= 1 day");
emit LogChangeExpiryLimit(getUint(Encoder.getKey('expiryLimit')), _newExpiry);
emit ChangeExpiryLimit(getUint(Encoder.getKey('expiryLimit')), _newExpiry);
set(Encoder.getKey('expiryLimit'), _newExpiry);
}

Expand Down Expand Up @@ -444,7 +453,7 @@ contract SecurityTokenRegistry is ISecurityTokenRegistry, EternalStorage {
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");

set(Encoder.getKey("registeredTickers_status", _ticker), true);
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");
Expand All @@ -461,7 +470,7 @@ contract SecurityTokenRegistry is ISecurityTokenRegistry, EternalStorage {

_storeSecurityTokenData(newSecurityTokenAddress, ticker, _tokenDetails, now);
set(Encoder.getKey("tickerToSecurityToken", ticker), newSecurityTokenAddress);
emit LogNewSecurityToken(ticker, _name, newSecurityTokenAddress, msg.sender, now, msg.sender, false);
emit NewSecurityToken(ticker, _name, newSecurityTokenAddress, msg.sender, now, msg.sender, false);
}

/**
Expand All @@ -483,7 +492,7 @@ contract SecurityTokenRegistry is ISecurityTokenRegistry, EternalStorage {
_modifyTicker(_owner, ticker, _name, getUint(Encoder.getKey("registeredTickers_registrationDate", ticker)), getUint(Encoder.getKey("registeredTickers_expiryDate", ticker)), true);
set(Encoder.getKey("tickerToSecurityToken", ticker), _securityToken);
_storeSecurityTokenData(_securityToken, ticker, _tokenDetails, _deployedAt);
emit LogNewSecurityToken(ticker, _name, _securityToken, _owner, _deployedAt, msg.sender, true);
emit NewSecurityToken(ticker, _name, _securityToken, _owner, _deployedAt, msg.sender, true);
}

/**
Expand Down Expand Up @@ -567,7 +576,7 @@ contract SecurityTokenRegistry is ISecurityTokenRegistry, EternalStorage {
*/
function changeTickerRegistrationFee(uint256 _tickerRegFee) external onlyOwner {
require(getUint(Encoder.getKey('tickerRegFee')) != _tickerRegFee);
emit LogChangeTickerRegistrationFee(getUint(Encoder.getKey('tickerRegFee')), _tickerRegFee);
emit ChangeTickerRegistrationFee(getUint(Encoder.getKey('tickerRegFee')), _tickerRegFee);
set(Encoder.getKey('tickerRegFee'), _tickerRegFee);
}

Expand All @@ -577,7 +586,7 @@ contract SecurityTokenRegistry is ISecurityTokenRegistry, EternalStorage {
*/
function changeSecurityLaunchFee(uint256 _stLaunchFee) external onlyOwner {
require(getUint(Encoder.getKey("stLaunchFee")) != _stLaunchFee);
emit LogChangeSecurityLaunchFee(getUint(Encoder.getKey("stLaunchFee")), _stLaunchFee);
emit ChangeSecurityLaunchFee(getUint(Encoder.getKey("stLaunchFee")), _stLaunchFee);
set(Encoder.getKey("stLaunchFee"), _stLaunchFee);
}

Expand All @@ -597,25 +606,40 @@ contract SecurityTokenRegistry is ISecurityTokenRegistry, EternalStorage {
* @notice Used only by Polymath to upgrade the SecurityToken contract and add more functionalities to future versions
* @notice Changing versions does not affect existing tokens.
* @param _STFactoryAddress is the address of the proxy.
* @param _version is the new version of the proxy which is used to deploy the security token.
* @param _major Major version of the proxy.
* @param _minor Minor version of the proxy.
* @param _patch Patch version of the proxy
*/
function setProtocolVersion(address _STFactoryAddress, bytes32 _version) external onlyOwner {
_setProtocolVersion(_STFactoryAddress, _version);
function setProtocolVersion(address _STFactoryAddress, uint8 _major, uint8 _minor, uint8 _patch) external onlyOwner {
_setProtocolVersion(_STFactoryAddress, _major, _minor, _patch);
}

/**
* @notice Internal - Changes the protocol version and the SecurityToken contract
*/
function _setProtocolVersion(address _STFactoryAddress, bytes32 _version) internal {
set(Encoder.getKey("protocolVersion"), _version);
set(Encoder.getKey("protocolVersionST", getBytes32(Encoder.getKey("protocolVersion"))), _STFactoryAddress);
function _setProtocolVersion(address _STFactoryAddress, uint8 _major, uint8 _minor, uint8 _patch) internal {
uint8[] memory _version = new uint8[](3);
_version[0] = _major;
_version[1] = _minor;
_version[2] = _patch;
uint24 _packedVersion = VersionUtils.pack(_major, _minor, _patch);
require(VersionUtils.isValidVersion(getProtocolVersion(), _version),"In-valid version");
set(Encoder.getKey("latestVersion"), uint256(_packedVersion));
set(Encoder.getKey("protocolVersionST", getUint(Encoder.getKey("latestVersion"))), _STFactoryAddress);
}

/**
* @notice Returns the current STFactory Address
*/
function getSTFactoryAddress() public view returns(address) {
return getAddress(Encoder.getKey("protocolVersionST", getBytes32(Encoder.getKey("protocolVersion"))));
return getAddress(Encoder.getKey("protocolVersionST", getUint(Encoder.getKey("latestVersion"))));
}

/**
* @notice get Protocol version
*/
function getProtocolVersion() public view returns(uint8[]) {
return VersionUtils.unpack(uint24(getUint(Encoder.getKey("latestVersion"))));
}

/**
Expand Down
28 changes: 24 additions & 4 deletions contracts/interfaces/IModuleFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ pragma solidity ^0.4.24;
*/
interface IModuleFactory {

event LogChangeFactorySetupFee(uint256 _oldSetupCost, uint256 _newSetupCost, address _moduleFactory);
event LogChangeFactoryUsageFee(uint256 _oldUsageCost, uint256 _newUsageCost, address _moduleFactory);
event LogChangeFactorySubscriptionFee(uint256 _oldSubscriptionCost, uint256 _newMonthlySubscriptionCost, address _moduleFactory);
event LogGenerateModuleFromFactory(
event ChangeFactorySetupFee(uint256 _oldSetupCost, uint256 _newSetupCost, address _moduleFactory);
event ChangeFactoryUsageFee(uint256 _oldUsageCost, uint256 _newUsageCost, address _moduleFactory);
event ChangeFactorySubscriptionFee(uint256 _oldSubscriptionCost, uint256 _newMonthlySubscriptionCost, address _moduleFactory);
event GenerateModuleFromFactory(
address _module,
bytes32 indexed _moduleName,
address indexed _moduleFactory,
address _creator,
uint256 _setupCost,
uint256 _timestamp
);
event ChangeSTVersionBound(string _boundType, uint8 _major, uint8 _minor, uint8 _patch);

//Should create an instance of the Module, or throw
function deploy(bytes _data) external returns(address);
Expand Down Expand Up @@ -73,9 +74,28 @@ interface IModuleFactory {
*/
function changeFactorySubscriptionFee(uint256 _newSubscriptionCost) external;

/**
* @notice Function use to change the lower and upper bound of the compatible version st
* @param _boundType Type of bound
* @param _newVersion new version array
*/
function changeSTVersionBounds(string _boundType, uint8[] _newVersion) external;

/**
* @notice Get the setup cost of the module
*/
function getSetupCost() external view returns (uint256);

/**
* @notice use to get the lower bound
* @return lower bound
*/
function getLowerSTVersionBounds() external view returns(uint8[]);

/**
* @notice use to get the upper bound
* @return upper bound
*/
function getUpperSTVersionBounds() external view returns(uint8[]);

}
18 changes: 15 additions & 3 deletions contracts/interfaces/IModuleRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ interface IModuleRegistry {
* @notice Called by the ModuleFactory owner to register new modules for SecurityToken to use
* @param _moduleFactory is the address of the module factory to be registered
*/
function registerModule(address _moduleFactory) external returns(bool);
function registerModule(address _moduleFactory) external;

/**
* @notice Called by the 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 returns(bool);
function removeModule(address _moduleFactory) external;

/**
* @notice Use to get all the tags releated to the functionality of the Module Factory.
Expand Down Expand Up @@ -67,4 +66,17 @@ interface IModuleRegistry {
*/
function getModuleListOfType(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
* @return address array that contains the list of available addresses of module factory contracts.
*/
function getAvailableModulesOfType(uint8 _moduleType, address _securityToken) external view returns (address[]);

/**
* @notice Use to get the latest contract address of the regstries
*/
function updateFromRegistry() external;

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


interface IPolymathRegistry {

/**
* @notice Get the contract address
* @param _nameKey is the key for the contract address mapping
* @return address
*/
function getAddress(string _nameKey) view external returns(address);

}

5 changes: 5 additions & 0 deletions contracts/interfaces/ISecurityToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,9 @@ interface ISecurityToken {
* @dev enabled via feature switch "disableControllerAllowed"
*/
function disableController() external;

/**
* @notice Use to get the version of the securityToken
*/
function getVersion() external view returns(uint8[]);
}
Loading