Skip to content

Commit 6f6ed85

Browse files
authored
Protocol upgrade fixes (#728)
* Make useModule backwards compatible * Make deployToken backwards compatible (#726) * Make deployToken backwards compatible * Small fix for scheduledCheckpoint
1 parent d388c13 commit 6f6ed85

File tree

7 files changed

+44
-16
lines changed

7 files changed

+44
-16
lines changed

contracts/ModuleRegistry.sol

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,18 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
118118
return IFeatureRegistry(getAddressValue(FEATURE_REGISTRY)).getFeatureStatus("customModulesAllowed");
119119
}
120120

121+
122+
/**
123+
* @notice Called by a SecurityToken (2.x) to check if the ModuleFactory is verified or appropriate custom module
124+
* @dev ModuleFactory reputation increases by one every time it is deployed(used) by a ST.
125+
* @dev Any module can be added during token creation without being registered if it is defined in the token proxy deployment contract
126+
* @dev The feature switch for custom modules is labelled "customModulesAllowed"
127+
* @param _moduleFactory is the address of the relevant module factory
128+
*/
129+
function useModule(address _moduleFactory) external {
130+
useModule(_moduleFactory, false);
131+
}
132+
121133
/**
122134
* @notice Called by a SecurityToken to check if the ModuleFactory is verified or appropriate custom module
123135
* @dev ModuleFactory reputation increases by one every time it is deployed(used) by a ST.
@@ -126,7 +138,7 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
126138
* @param _moduleFactory is the address of the relevant module factory
127139
* @param _isUpgrade whether or not the function is being called as a result of an upgrade
128140
*/
129-
function useModule(address _moduleFactory, bool _isUpgrade) external nonReentrant {
141+
function useModule(address _moduleFactory, bool _isUpgrade) public nonReentrant {
130142
if (_customModules()) {
131143
require(
132144
getBoolValue(Encoder.getKey("verified", _moduleFactory)) || getAddressValue(Encoder.getKey("factoryOwner", _moduleFactory))

contracts/SecurityTokenRegistry.sol

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ contract SecurityTokenRegistry is EternalStorage, Proxy {
108108
// Emit when ownership of the ticker gets changed
109109
event ChangeTickerOwnership(string _ticker, address indexed _oldOwner, address indexed _newOwner);
110110
// Emit at the time of launching a new security token of version 3.0+
111-
event NewSecurityTokenCreated(
111+
event NewSecurityToken(
112112
string _ticker,
113113
string _name,
114114
address indexed _securityTokenAddress,
@@ -173,10 +173,14 @@ contract SecurityTokenRegistry is EternalStorage, Proxy {
173173
* @dev Throws if called by any account other than the owner.
174174
*/
175175
modifier onlyOwner() {
176-
require(msg.sender == owner(), "Only owner");
176+
_onlyOwner();
177177
_;
178178
}
179179

180+
function _onlyOwner() internal view {
181+
require(msg.sender == owner(), "Only owner");
182+
}
183+
180184
modifier onlyOwnerOrSelf() {
181185
require(msg.sender == owner() || msg.sender == address(this), "Only owner or self");
182186
_;
@@ -639,7 +643,7 @@ contract SecurityTokenRegistry is EternalStorage, Proxy {
639643
_ticker, _name, newSecurityTokenAddress, issuer, now, issuer, false, _polyFee
640644
);
641645
} else {
642-
emit NewSecurityTokenCreated(
646+
emit NewSecurityToken(
643647
_ticker, _name, newSecurityTokenAddress, issuer, now, issuer, false, _usdFee, _polyFee, _protocolVersion
644648
);
645649
}
@@ -691,15 +695,24 @@ contract SecurityTokenRegistry is EternalStorage, Proxy {
691695
internal
692696
returns(address newSecurityTokenAddress)
693697
{
698+
// In v2.x of STFactory, the final argument to deployToken is the PolymathRegistry.
699+
// In v3.x of STFactory, the final argument to deployToken is the Treasury wallet.
700+
uint8[] memory upperLimit = new uint8[](3);
701+
upperLimit[0] = 2;
702+
upperLimit[1] = 99;
703+
upperLimit[2] = 99;
704+
if (VersionUtils.lessThanOrEqual(VersionUtils.unpack(uint24(_protocolVersion)), upperLimit)) {
705+
_wallet = getAddressValue(POLYMATHREGISTRY);
706+
}
707+
694708
newSecurityTokenAddress = ISTFactory(getAddressValue(Encoder.getKey("protocolVersionST", _protocolVersion))).deployToken(
695709
_name,
696710
_ticker,
697711
18,
698712
_tokenDetails,
699713
_issuer,
700714
_divisible,
701-
_wallet,
702-
getAddressValue(POLYMATHREGISTRY)
715+
_wallet
703716
);
704717

705718
/*solium-disable-next-line security/no-block-members*/
@@ -739,7 +752,7 @@ contract SecurityTokenRegistry is EternalStorage, Proxy {
739752
set(Encoder.getKey("tickerToSecurityToken", ticker), _securityToken);
740753
_modifyTicker(_owner, ticker, registrationTime, expiryTime, true);
741754
_storeSecurityTokenData(_securityToken, ticker, _tokenDetails, _deployedAt);
742-
emit NewSecurityTokenCreated(
755+
emit NewSecurityToken(
743756
ticker, ISecurityToken(_securityToken).name(), _securityToken, _owner, _deployedAt, msg.sender, true, uint256(0), uint256(0), 0
744757
);
745758
}
@@ -951,5 +964,4 @@ contract SecurityTokenRegistry is EternalStorage, Proxy {
951964
function owner() public view returns(address) {
952965
return getAddressValue(OWNER);
953966
}
954-
955967
}

contracts/interfaces/IModuleRegistry.sol

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ interface IModuleRegistry {
2727
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
2828

2929

30+
/**
31+
* @notice Called by a security token (2.x) to notify the registry it is using a module
32+
* @param _moduleFactory is the address of the relevant module factory
33+
*/
34+
function useModule(address _moduleFactory) external;
35+
3036
/**
3137
* @notice Called by a security token to notify the registry it is using a module
3238
* @param _moduleFactory is the address of the relevant module factory

contracts/interfaces/ISTFactory.sol

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ interface ISTFactory {
2323
* @param _issuer is the owner of the Security Token
2424
* @param _divisible whether the token is divisible or not
2525
* @param _treasuryWallet Ethereum address which will holds the STs.
26-
* @param _polymathRegistry is the address of the Polymath Registry contract
2726
*/
2827
function deployToken(
2928
string calldata _name,
@@ -32,10 +31,9 @@ interface ISTFactory {
3231
string calldata _tokenDetails,
3332
address _issuer,
3433
bool _divisible,
35-
address _treasuryWallet,
36-
address _polymathRegistry
37-
)
38-
external
34+
address _treasuryWallet //In v2.x this is the Polymath Registry
35+
)
36+
external
3937
returns(address tokenAddress);
4038

4139
/**

contracts/modules/Experimental/Mixed/ScheduledCheckpoint.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ contract ScheduledCheckpoint is ICheckpoint, TransferManager {
5757
*/
5858
function addSchedule(bytes32 _name, uint256 _startTime, uint256 _interval, TimeUnit _timeUnit) external {
5959
_onlySecurityTokenOwner();
60+
require(_name != bytes32(""), "Empty name");
6061
require(_startTime > now, "Start time must be in the future");
6162
require(schedules[_name].name == bytes32(0), "Name already in use");
6263
schedules[_name].name = _name;
@@ -75,6 +76,7 @@ contract ScheduledCheckpoint is ICheckpoint, TransferManager {
7576
*/
7677
function removeSchedule(bytes32 _name) external {
7778
_onlySecurityTokenOwner();
79+
require(_name != bytes32(""), "Empty name");
7880
require(schedules[_name].name == _name, "Name does not exist");
7981
uint256 index = schedules[_name].index;
8082
names[index] = names[names.length - 1];

contracts/tokens/STFactory.sol

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ contract STFactory is ISTFactory, Ownable {
8080
string calldata _tokenDetails,
8181
address _issuer,
8282
bool _divisible,
83-
address _treasuryWallet,
84-
address /* _polymathRegistry */
83+
address _treasuryWallet
8584
)
8685
external
8786
returns(address)

test/k_module_registry.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,6 @@ contract("ModuleRegistry", async (accounts) => {
421421
assert.equal(tx.logs[1].args._ticker, newSymbol.toUpperCase());
422422
I_SecurityToken2 = await SecurityToken.at(tx.logs[1].args._securityTokenAddress);
423423
stGetter = await STGetter.at(I_SecurityToken2.address);
424-
assert.equal(await stGetter.getTreasuryWallet.call(), account_issuer, "Incorrect wallet set")
425424
let bytesData = encodeModuleCall(
426425
["uint256", "uint256", "uint256", "string"],
427426
[await latestTime(), currentTime.add(new BN(duration.days(1))), cap, "Test STO"]

0 commit comments

Comments
 (0)