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

Minor optimizations #628

Merged
merged 24 commits into from
Apr 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
44 changes: 26 additions & 18 deletions contracts/ModuleRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {

*/

bytes32 constant INITIALIZE = 0x9ef7257c3339b099aacf96e55122ee78fb65a36bd2a6c19249882be9c98633bf; //keccak256("initialised")
bytes32 constant POLYTOKEN = 0xacf8fbd51bb4b83ba426cdb12f63be74db97c412515797993d2a385542e311d7; //keccak256("polyToken")
bytes32 constant PAUSED = 0xee35723ac350a69d2a92d3703f17439cbaadf2f093a21ba5bf5f1a53eb2a14d9; //keccak256("paused")
bytes32 constant OWNER = 0x02016836a56b71f0d02689e69e326f4f4c1b9057164ef592671cf0d37c8040c0; //keccak256("owner")
bytes32 constant POLYMATHREGISTRY = 0x90eeab7c36075577c7cc5ff366e389fefa8a18289b949bab3529ab4471139d4d; //keccak256("polymathRegistry")
bytes32 constant FEATURE_REGISTRY = 0xed9ca06607835ad25ecacbcb97f2bc414d4a51ecf391b5ae42f15991227ab146; //keccak256("featureRegistry")
bytes32 constant SECURITY_TOKEN_REGISTRY = 0x12ada4f7ee6c2b7b933330be61fefa007a1f497dc8df1b349b48071a958d7a81; //keccak256("securityTokenRegistry")

///////////
// Events
//////////
Expand Down Expand Up @@ -105,12 +113,12 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
}

function initialize(address _polymathRegistry, address _owner) external payable {
require(!getBoolValue(Encoder.getKey("initialised")), "already initialized");
require(!getBoolValue(INITIALIZE), "already initialized");
require(_owner != address(0) && _polymathRegistry != address(0), "0x address is invalid");
set(Encoder.getKey("polymathRegistry"), _polymathRegistry);
set(Encoder.getKey("owner"), _owner);
set(Encoder.getKey("paused"), false);
set(Encoder.getKey("initialised"), true);
set(POLYMATHREGISTRY, _polymathRegistry);
set(OWNER, _owner);
set(PAUSED, false);
set(INITIALIZE, true);
}

/**
Expand All @@ -122,7 +130,7 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
* @param _isUpgrade whether or not the function is being called as a result of an upgrade
*/
function useModule(address _moduleFactory, bool _isUpgrade) external {
if (IFeatureRegistry(getAddressValue(Encoder.getKey("featureRegistry"))).getFeatureStatus("customModulesAllowed")) {
if (IFeatureRegistry(getAddressValue(FEATURE_REGISTRY)).getFeatureStatus("customModulesAllowed")) {
require(
getBoolValue(Encoder.getKey("verified", _moduleFactory)) || IOwnable(_moduleFactory).owner() == IOwnable(msg.sender).owner(),
"ModuleFactory must be verified or SecurityToken owner must be ModuleFactory owner"
Expand All @@ -132,7 +140,7 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
}
// This if statement is required to be able to add modules from the STFactory contract during deployment
// before the token has been registered to the STR.
if (ISecurityTokenRegistry(getAddressValue(Encoder.getKey("securityTokenRegistry"))).isSecurityToken(msg.sender)) {
if (ISecurityTokenRegistry(getAddressValue(SECURITY_TOKEN_REGISTRY)).isSecurityToken(msg.sender)) {
require(isCompatibleModule(_moduleFactory, msg.sender), "Incompatible versions");
if (!_isUpgrade) {
pushArray(Encoder.getKey("reputation", _moduleFactory), msg.sender);
Expand Down Expand Up @@ -161,7 +169,7 @@ 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(getAddressValue(Encoder.getKey("featureRegistry"))).getFeatureStatus("customModulesAllowed")) {
if (IFeatureRegistry(getAddressValue(FEATURE_REGISTRY)).getFeatureStatus("customModulesAllowed")) {
require(
msg.sender == IOwnable(_moduleFactory).owner() || msg.sender == owner(),
"msg.sender must be the Module Factory owner or registry curator"
Expand Down Expand Up @@ -337,7 +345,7 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
function getModulesByTypeAndToken(uint8 _moduleType, address _securityToken) public view returns(address[] memory) {
address[] memory _addressList = getArrayAddress(Encoder.getKey("moduleList", uint256(_moduleType)));
uint256 _len = _addressList.length;
bool _isCustomModuleAllowed = IFeatureRegistry(getAddressValue(Encoder.getKey("featureRegistry"))).getFeatureStatus(
bool _isCustomModuleAllowed = IFeatureRegistry(getAddressValue(FEATURE_REGISTRY)).getFeatureStatus(
"customModulesAllowed"
);
uint256 counter = 0;
Expand Down Expand Up @@ -387,7 +395,7 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
* @notice Called by the owner to pause, triggers stopped state
*/
function pause() external whenNotPaused onlyOwner {
set(Encoder.getKey("paused"), true);
set(PAUSED, true);
/*solium-disable-next-line security/no-block-members*/
emit Pause(msg.sender);
}
Expand All @@ -396,7 +404,7 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
* @notice Called by the owner to unpause, returns to normal state
*/
function unpause() external whenPaused onlyOwner {
set(Encoder.getKey("paused"), false);
set(PAUSED, false);
/*solium-disable-next-line security/no-block-members*/
emit Unpause(msg.sender);
}
Expand All @@ -405,10 +413,10 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
* @notice Stores the contract addresses of other key contracts from the PolymathRegistry
*/
function updateFromRegistry() external onlyOwner {
address _polymathRegistry = getAddressValue(Encoder.getKey("polymathRegistry"));
set(Encoder.getKey("securityTokenRegistry"), IPolymathRegistry(_polymathRegistry).getAddress("SecurityTokenRegistry"));
set(Encoder.getKey("featureRegistry"), IPolymathRegistry(_polymathRegistry).getAddress("FeatureRegistry"));
set(Encoder.getKey("polyToken"), IPolymathRegistry(_polymathRegistry).getAddress("PolyToken"));
address _polymathRegistry = getAddressValue(POLYMATHREGISTRY);
set(SECURITY_TOKEN_REGISTRY, IPolymathRegistry(_polymathRegistry).getAddress("SecurityTokenRegistry"));
set(FEATURE_REGISTRY, IPolymathRegistry(_polymathRegistry).getAddress("FeatureRegistry"));
set(POLYTOKEN, IPolymathRegistry(_polymathRegistry).getAddress("PolyToken"));
}

/**
Expand All @@ -418,22 +426,22 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
function transferOwnership(address _newOwner) external onlyOwner {
require(_newOwner != address(0), "Invalid address");
emit OwnershipTransferred(owner(), _newOwner);
set(Encoder.getKey("owner"), _newOwner);
set(OWNER, _newOwner);
}

/**
* @notice Gets the owner of the contract
* @return address owner
*/
function owner() public view returns(address) {
return getAddressValue(Encoder.getKey("owner"));
return getAddressValue(OWNER);
}

/**
* @notice Checks whether the contract operations is paused or not
* @return bool
*/
function isPaused() public view returns(bool) {
return getBoolValue(Encoder.getKey("paused"));
return getBoolValue(PAUSED);
}
}
25 changes: 0 additions & 25 deletions contracts/RegistryUpdater.sol

This file was deleted.

34 changes: 17 additions & 17 deletions contracts/SecurityTokenRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,18 @@ contract SecurityTokenRegistry is EternalStorage, Proxy {

using SafeMath for uint256;

bytes32 constant INITIALIZE = 0x9ef7257c3339b099aacf96e55122ee78fb65a36bd2a6c19249882be9c98633bf;
bytes32 constant POLYTOKEN = 0xacf8fbd51bb4b83ba426cdb12f63be74db97c412515797993d2a385542e311d7;
bytes32 constant STLAUNCHFEE = 0xd677304bb45536bb7fdfa6b9e47a3c58fe413f9e8f01474b0a4b9c6e0275baf2;
bytes32 constant TICKERREGFEE = 0x2fcc69711628630fb5a42566c68bd1092bc4aa26826736293969fddcd11cb2d2;
bytes32 constant EXPIRYLIMIT = 0x604268e9a73dfd777dcecb8a614493dd65c638bad2f5e7d709d378bd2fb0baee;
bytes32 constant PAUSED = 0xee35723ac350a69d2a92d3703f17439cbaadf2f093a21ba5bf5f1a53eb2a14d9;
bytes32 constant OWNER = 0x02016836a56b71f0d02689e69e326f4f4c1b9057164ef592671cf0d37c8040c0;
bytes32 constant POLYMATHREGISTRY = 0x90eeab7c36075577c7cc5ff366e389fefa8a18289b949bab3529ab4471139d4d;
bytes32 constant STRGETTER = 0x982f24b3bd80807ec3cb227ba152e15c07d66855fa8ae6ca536e689205c0e2e9;
bytes32 constant INITIALIZE = 0x9ef7257c3339b099aacf96e55122ee78fb65a36bd2a6c19249882be9c98633bf; //keccak256("initialised")
bytes32 constant POLYTOKEN = 0xacf8fbd51bb4b83ba426cdb12f63be74db97c412515797993d2a385542e311d7; //keccak256("polyToken")
bytes32 constant STLAUNCHFEE = 0xd677304bb45536bb7fdfa6b9e47a3c58fe413f9e8f01474b0a4b9c6e0275baf2; //keccak256("stLaunchFee")
bytes32 constant TICKERREGFEE = 0x2fcc69711628630fb5a42566c68bd1092bc4aa26826736293969fddcd11cb2d2; //keccak256("tickerRegFee")
bytes32 constant EXPIRYLIMIT = 0x604268e9a73dfd777dcecb8a614493dd65c638bad2f5e7d709d378bd2fb0baee; //keccak256("expiryLimit")
bytes32 constant PAUSED = 0xee35723ac350a69d2a92d3703f17439cbaadf2f093a21ba5bf5f1a53eb2a14d9; //keccak256("paused")
bytes32 constant OWNER = 0x02016836a56b71f0d02689e69e326f4f4c1b9057164ef592671cf0d37c8040c0; //keccak256("owner")
bytes32 constant POLYMATHREGISTRY = 0x90eeab7c36075577c7cc5ff366e389fefa8a18289b949bab3529ab4471139d4d; //keccak256("polymathRegistry")
bytes32 constant STRGETTER = 0x982f24b3bd80807ec3cb227ba152e15c07d66855fa8ae6ca536e689205c0e2e9; //keccak256("STRGetter")
bytes32 constant IS_FEE_IN_POLY = 0x7152e5426955da44af11ecd67fec5e2a3ba747be974678842afa9394b9a075b6; //keccak256("IS_FEE_IN_POLY")
bytes32 constant ACTIVE_USERS = 0x425619ce6ba8e9f80f17c0ef298b6557e321d70d7aeff2e74dd157bd87177a9e; //keccak256("activeUsers")
bytes32 constant LATEST_VERSION = 0x4c63b69b9117452b9f11af62077d0cda875fb4e2dbe07ad6f31f728de6926230; //keccak256("latestVersion")

string constant POLY_ORACLE = "StablePolyUsdOracle";

Expand Down Expand Up @@ -196,7 +198,6 @@ contract SecurityTokenRegistry is EternalStorage, Proxy {
address _getterContract
)
public
payable
{
require(!getBoolValue(INITIALIZE),"Initialized");
require(
Expand Down Expand Up @@ -264,7 +265,7 @@ contract SecurityTokenRegistry is EternalStorage, Proxy {
}

function _implementation() internal view returns(address) {
return getAddressValue(Encoder.getKey("STRGetter"));
return getAddressValue(STRGETTER);
}

/////////////////////////////
Expand Down Expand Up @@ -422,7 +423,7 @@ contract SecurityTokenRegistry is EternalStorage, Proxy {
set(Encoder.getKey("tickerIndex", _ticker), length);
bytes32 seenKey = Encoder.getKey("seenUsers", _owner);
if (!getBoolValue(seenKey)) {
pushArray(Encoder.getKey("activeUsers"), _owner);
pushArray(ACTIVE_USERS, _owner);
set(seenKey, true);
}
}
Expand Down Expand Up @@ -528,7 +529,7 @@ contract SecurityTokenRegistry is EternalStorage, Proxy {
require(bytes(_name).length > 0 && bytes(_ticker).length > 0, "Bad ticker");
require(_treasuryWallet != address(0), "0x0 not allowed");
if (_protocolVersion == 0) {
protocolVersion = getUintValue(Encoder.getKey("latestVersion"));
protocolVersion = getUintValue(LATEST_VERSION);
}
require(protocolVersion != uint256(0), "Invalid version");
string memory ticker = Util.upper(_ticker);
Expand Down Expand Up @@ -572,7 +573,7 @@ contract SecurityTokenRegistry is EternalStorage, Proxy {
address stOwner = IOwnable(st).owner();
require(msg.sender == stOwner, "Unauthroized");
require(ISecurityToken(st).transfersFrozen(), "Transfers not frozen");
uint256 protocolVersion = getUintValue(Encoder.getKey("latestVersion"));
uint256 protocolVersion = getUintValue(LATEST_VERSION);
address newSecurityTokenAddress =
_deployToken(_name, ticker, _tokenDetails, stOwner, _divisible, _treasuryWallet, protocolVersion);
emit SecurityTokenRefreshed(
Expand Down Expand Up @@ -777,7 +778,6 @@ contract SecurityTokenRegistry is EternalStorage, Proxy {
function _setProtocolFactory(address _STFactoryAddress, uint8 _major, uint8 _minor, uint8 _patch) internal {
require(_STFactoryAddress != address(0), "Bad address");
uint24 _packedVersion = VersionUtils.pack(_major, _minor, _patch);
//set(Encoder.getKey("latestVersion"), uint256(_packedVersion));
set(Encoder.getKey("protocolVersionST", uint256(_packedVersion)), _STFactoryAddress);
emit ProtocolFactorySet(_STFactoryAddress, _major, _minor, _patch);
}
Expand All @@ -790,7 +790,7 @@ contract SecurityTokenRegistry is EternalStorage, Proxy {
*/
function removeProtocolFactory(uint8 _major, uint8 _minor, uint8 _patch) public onlyOwner {
uint24 _packedVersion = VersionUtils.pack(_major, _minor, _patch);
require(getUintValue(Encoder.getKey("latestVersion")) != _packedVersion, "Cannot remove latestVersion");
require(getUintValue(LATEST_VERSION) != _packedVersion, "Cannot remove latestVersion");
emit ProtocolFactoryRemoved(getAddressValue(Encoder.getKey("protocolVersionST", _packedVersion)), _major, _minor, _patch);
set(Encoder.getKey("protocolVersionST", uint256(_packedVersion)), address(0));
}
Expand All @@ -810,7 +810,7 @@ contract SecurityTokenRegistry is EternalStorage, Proxy {
function _setLatestVersion(uint8 _major, uint8 _minor, uint8 _patch) internal {
uint24 _packedVersion = VersionUtils.pack(_major, _minor, _patch);
require(getAddressValue(Encoder.getKey("protocolVersionST", _packedVersion)) != address(0), "No factory");
set(Encoder.getKey("latestVersion"), uint256(_packedVersion));
set(LATEST_VERSION, uint256(_packedVersion));
emit LatestVersionSet(_major, _minor, _patch);
}

Expand Down
Loading