Skip to content

Make deployToken backwards compatible #726

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

Merged
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
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);
}

}
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