Skip to content

Commit

Permalink
Protocol upgrade fixes (#728)
Browse files Browse the repository at this point in the history
* Make useModule backwards compatible

* Make deployToken backwards compatible (#726)

* Make deployToken backwards compatible

* Small fix for scheduledCheckpoint
  • Loading branch information
adamdossa authored Jun 20, 2019
1 parent d388c13 commit 6f6ed85
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 16 deletions.
14 changes: 13 additions & 1 deletion contracts/ModuleRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
return IFeatureRegistry(getAddressValue(FEATURE_REGISTRY)).getFeatureStatus("customModulesAllowed");
}


/**
* @notice Called by a SecurityToken (2.x) to check if the ModuleFactory is verified or appropriate custom module
* @dev ModuleFactory reputation increases by one every time it is deployed(used) by a ST.
* @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 {
useModule(_moduleFactory, false);
}

/**
* @notice Called by a SecurityToken to check if the ModuleFactory is verified or appropriate custom module
* @dev ModuleFactory reputation increases by one every time it is deployed(used) by a ST.
Expand All @@ -126,7 +138,7 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
* @param _moduleFactory is the address of the relevant module factory
* @param _isUpgrade whether or not the function is being called as a result of an upgrade
*/
function useModule(address _moduleFactory, bool _isUpgrade) external nonReentrant {
function useModule(address _moduleFactory, bool _isUpgrade) public nonReentrant {
if (_customModules()) {
require(
getBoolValue(Encoder.getKey("verified", _moduleFactory)) || getAddressValue(Encoder.getKey("factoryOwner", _moduleFactory))
Expand Down
26 changes: 19 additions & 7 deletions contracts/SecurityTokenRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ contract SecurityTokenRegistry is EternalStorage, Proxy {
// Emit when ownership of the ticker gets changed
event ChangeTickerOwnership(string _ticker, address indexed _oldOwner, address indexed _newOwner);
// Emit at the time of launching a new security token of version 3.0+
event NewSecurityTokenCreated(
event NewSecurityToken(
string _ticker,
string _name,
address indexed _securityTokenAddress,
Expand Down Expand Up @@ -173,10 +173,14 @@ contract SecurityTokenRegistry is EternalStorage, Proxy {
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner(), "Only owner");
_onlyOwner();
_;
}

function _onlyOwner() internal view {
require(msg.sender == owner(), "Only owner");
}

modifier onlyOwnerOrSelf() {
require(msg.sender == owner() || msg.sender == address(this), "Only owner or self");
_;
Expand Down Expand Up @@ -639,7 +643,7 @@ contract SecurityTokenRegistry is EternalStorage, Proxy {
_ticker, _name, newSecurityTokenAddress, issuer, now, issuer, false, _polyFee
);
} else {
emit NewSecurityTokenCreated(
emit NewSecurityToken(
_ticker, _name, newSecurityTokenAddress, issuer, now, issuer, false, _usdFee, _polyFee, _protocolVersion
);
}
Expand Down Expand Up @@ -691,15 +695,24 @@ contract SecurityTokenRegistry is EternalStorage, Proxy {
internal
returns(address newSecurityTokenAddress)
{
// In v2.x of STFactory, the final argument to deployToken is the PolymathRegistry.
// In v3.x of STFactory, the final argument to deployToken is the Treasury wallet.
uint8[] memory upperLimit = new uint8[](3);
upperLimit[0] = 2;
upperLimit[1] = 99;
upperLimit[2] = 99;
if (VersionUtils.lessThanOrEqual(VersionUtils.unpack(uint24(_protocolVersion)), upperLimit)) {
_wallet = getAddressValue(POLYMATHREGISTRY);
}

newSecurityTokenAddress = ISTFactory(getAddressValue(Encoder.getKey("protocolVersionST", _protocolVersion))).deployToken(
_name,
_ticker,
18,
_tokenDetails,
_issuer,
_divisible,
_wallet,
getAddressValue(POLYMATHREGISTRY)
_wallet
);

/*solium-disable-next-line security/no-block-members*/
Expand Down Expand Up @@ -739,7 +752,7 @@ contract SecurityTokenRegistry is EternalStorage, Proxy {
set(Encoder.getKey("tickerToSecurityToken", ticker), _securityToken);
_modifyTicker(_owner, ticker, registrationTime, expiryTime, true);
_storeSecurityTokenData(_securityToken, ticker, _tokenDetails, _deployedAt);
emit NewSecurityTokenCreated(
emit NewSecurityToken(
ticker, ISecurityToken(_securityToken).name(), _securityToken, _owner, _deployedAt, msg.sender, true, uint256(0), uint256(0), 0
);
}
Expand Down Expand Up @@ -951,5 +964,4 @@ contract SecurityTokenRegistry is EternalStorage, Proxy {
function owner() public view returns(address) {
return getAddressValue(OWNER);
}

}
6 changes: 6 additions & 0 deletions contracts/interfaces/IModuleRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ interface IModuleRegistry {
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);


/**
* @notice Called by a security token (2.x) to notify the registry it is using a module
* @param _moduleFactory is the address of the relevant module factory
*/
function useModule(address _moduleFactory) external;

/**
* @notice Called by a security token to notify the registry it is using a module
* @param _moduleFactory is the address of the relevant module factory
Expand Down
8 changes: 3 additions & 5 deletions contracts/interfaces/ISTFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ interface ISTFactory {
* @param _issuer is the owner of the Security Token
* @param _divisible whether the token is divisible or not
* @param _treasuryWallet Ethereum address which will holds the STs.
* @param _polymathRegistry is the address of the Polymath Registry contract
*/
function deployToken(
string calldata _name,
Expand All @@ -32,10 +31,9 @@ interface ISTFactory {
string calldata _tokenDetails,
address _issuer,
bool _divisible,
address _treasuryWallet,
address _polymathRegistry
)
external
address _treasuryWallet //In v2.x this is the Polymath Registry
)
external
returns(address tokenAddress);

/**
Expand Down
2 changes: 2 additions & 0 deletions contracts/modules/Experimental/Mixed/ScheduledCheckpoint.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ contract ScheduledCheckpoint is ICheckpoint, TransferManager {
*/
function addSchedule(bytes32 _name, uint256 _startTime, uint256 _interval, TimeUnit _timeUnit) external {
_onlySecurityTokenOwner();
require(_name != bytes32(""), "Empty name");
require(_startTime > now, "Start time must be in the future");
require(schedules[_name].name == bytes32(0), "Name already in use");
schedules[_name].name = _name;
Expand All @@ -75,6 +76,7 @@ contract ScheduledCheckpoint is ICheckpoint, TransferManager {
*/
function removeSchedule(bytes32 _name) external {
_onlySecurityTokenOwner();
require(_name != bytes32(""), "Empty name");
require(schedules[_name].name == _name, "Name does not exist");
uint256 index = schedules[_name].index;
names[index] = names[names.length - 1];
Expand Down
3 changes: 1 addition & 2 deletions contracts/tokens/STFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ contract STFactory is ISTFactory, Ownable {
string calldata _tokenDetails,
address _issuer,
bool _divisible,
address _treasuryWallet,
address /* _polymathRegistry */
address _treasuryWallet
)
external
returns(address)
Expand Down
1 change: 0 additions & 1 deletion test/k_module_registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,6 @@ contract("ModuleRegistry", async (accounts) => {
assert.equal(tx.logs[1].args._ticker, newSymbol.toUpperCase());
I_SecurityToken2 = await SecurityToken.at(tx.logs[1].args._securityTokenAddress);
stGetter = await STGetter.at(I_SecurityToken2.address);
assert.equal(await stGetter.getTreasuryWallet.call(), account_issuer, "Incorrect wallet set")
let bytesData = encodeModuleCall(
["uint256", "uint256", "uint256", "string"],
[await latestTime(), currentTime.add(new BN(duration.days(1))), cap, "Test STO"]
Expand Down

0 comments on commit 6f6ed85

Please sign in to comment.