Skip to content

Commit 9a80c01

Browse files
maxsam4adamdossa
authored andcommitted
Allow token name change (#600)
* Allow owner to change name * Reduce size * Update ST interface * Added update name event * Updated OZ * Updated storage verification test
1 parent 74d0940 commit 9a80c01

File tree

8 files changed

+58
-31
lines changed

8 files changed

+58
-31
lines changed

contracts/interfaces/ISecurityToken.sol

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,12 @@ interface ISecurityToken {
269269
*/
270270
function updateTokenDetails(string calldata _newTokenDetails) external;
271271

272+
/**
273+
* @notice Allows owner to change token name
274+
* @param _name new name of the token
275+
*/
276+
function changeName(string calldata _name) external;
277+
272278
/**
273279
* @notice Allows the owner to change token granularity
274280
* @param _granularity Granularity level of the token

contracts/tokens/OZStorage.sol

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ contract OZStorage {
88

99
uint256 private _totalSupply;
1010

11-
string private _name;
12-
string private _symbol;
13-
uint8 private _decimals;
14-
1511
address private _owner;
1612

1713
/// @dev counter to allow mutex lock with only one SSTORE operation
@@ -25,4 +21,4 @@ contract OZStorage {
2521
return _balances[_investor];
2622
}
2723

28-
}
24+
}

contracts/tokens/SecurityToken.sol

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import "../interfaces/ITransferManager.sol";
1616
import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
1717
import "openzeppelin-solidity/contracts/utils/ReentrancyGuard.sol";
1818
import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
19-
import "openzeppelin-solidity/contracts/token/ERC20/ERC20Detailed.sol";
2019

2120
/**
2221
* @title Security Token contract
@@ -28,7 +27,7 @@ import "openzeppelin-solidity/contracts/token/ERC20/ERC20Detailed.sol";
2827
* @notice - ST does not inherit from ISecurityToken due to:
2928
* @notice - https://github.com/ethereum/solidity/issues/4847
3029
*/
31-
contract SecurityToken is ERC20, ERC20Detailed, Ownable, ReentrancyGuard, SecurityTokenStorage, IERC1594, IERC1643, IERC1644, Proxy {
30+
contract SecurityToken is ERC20, Ownable, ReentrancyGuard, SecurityTokenStorage, IERC1594, IERC1643, IERC1644, Proxy {
3231

3332
using SafeMath for uint256;
3433

@@ -45,6 +44,8 @@ contract SecurityToken is ERC20, ERC20Detailed, Ownable, ReentrancyGuard, Securi
4544

4645
// Emit when the token details get updated
4746
event UpdateTokenDetails(string _oldDetails, string _newDetails);
47+
// Emit when the token name get updated
48+
event UpdateTokenName(string _oldName, string _newName);
4849
// Emit when the granularity get changed
4950
event GranularityChanged(uint256 _oldGranularity, uint256 _newGranularity);
5051
// Emit when is permanently frozen by the issuer
@@ -134,13 +135,15 @@ contract SecurityToken is ERC20, ERC20Detailed, Ownable, ReentrancyGuard, Securi
134135
address _delegate
135136
)
136137
public
137-
ERC20Detailed(_name, _symbol, _decimals)
138138
{
139139
_zeroAddressCheck(_polymathRegistry);
140140
_zeroAddressCheck(_delegate);
141141
polymathRegistry = _polymathRegistry;
142142
//When it is created, the owner is the STR
143143
updateFromRegistry();
144+
name = _name;
145+
symbol = _symbol;
146+
decimals = _decimals;
144147
delegate = _delegate;
145148
tokenDetails = _tokenDetails;
146149
granularity = _granularity;
@@ -289,6 +292,15 @@ contract SecurityToken is ERC20, ERC20Detailed, Ownable, ReentrancyGuard, Securi
289292
dataStore = _dataStore;
290293
}
291294

295+
/**
296+
* @notice Allows owner to change token name
297+
* @param _name new name of the token
298+
*/
299+
function changeName(string calldata _name) external onlyOwner {
300+
emit UpdateTokenName(name, _name);
301+
name = _name;
302+
}
303+
292304
/**
293305
* @notice Allows to change the treasury wallet address
294306
* @param _wallet Ethereum address of the treasury wallet

contracts/tokens/SecurityTokenStorage.sol

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ contract SecurityTokenStorage {
4646
uint256 value;
4747
}
4848

49+
// ERC20 Details
50+
string public name;
51+
string public symbol;
52+
uint8 public decimals;
53+
4954
// Address of the controller which is a delegated entity
5055
// set by the issuer/owner of the token
5156
address public controller;
@@ -108,5 +113,4 @@ contract SecurityTokenStorage {
108113
mapping(bytes32 => Document) internal _documents;
109114
// mapping to store the document name indexes
110115
mapping(bytes32 => uint256) internal _docIndexes;
111-
112116
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"fs": "0.0.2",
8282
"ganache-cli": "6.1.8",
8383
"mocha-junit-reporter": "^1.18.0",
84-
"openzeppelin-solidity": "2.1.2",
84+
"openzeppelin-solidity": "2.2.0",
8585
"prettier": "^1.15.3",
8686
"prompt": "^1.0.0",
8787
"request": "^2.88.0",

test/n_security_token_registry.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,8 +668,9 @@ contract("SecurityTokenRegistry", async (accounts) => {
668668
I_TokenLib = await TokenLib.new();
669669
await STFactoryV2.link(TokenLib);
670670
await SecurityTokenMock.link(TokenLib);
671+
console.log("ST linked");
671672
I_STFactory002 = await STFactoryV2.new(I_GeneralTransferManagerFactory.address, I_DataStoreFactory.address, I_STGetter.address, { from: account_polymath });
672-
673+
console.log("STF deployed");
673674
assert.notEqual(
674675
I_STFactory002.address.valueOf(),
675676
address_zero,

test/o_security_token.js

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,17 @@ contract("SecurityToken", async (accounts) => {
203203
assert.equal(web3.utils.toUtf8(log.args._name), "GeneralTransferManager");
204204
});
205205

206+
it("Should not allow unauthorized address to change name", async() => {
207+
await catchRevert(I_SecurityToken.changeName("new token name"));
208+
});
209+
210+
it("Should allow authorized address to change name", async() => {
211+
let snapId = await takeSnapshot();
212+
await I_SecurityToken.changeName("new token name", { from: token_owner });
213+
assert.equal((await I_SecurityToken.name()).replace(/\u0000/g, ""), "new token name");
214+
await revertToSnapshot(snapId);
215+
});
216+
206217
it("Should intialize the auto attached modules", async () => {
207218
let moduleData = (await stGetter.getModulesByType(transferManagerKey))[0];
208219
I_GeneralTransferManager = await GeneralTransferManager.at(moduleData);
@@ -1358,49 +1369,46 @@ contract("SecurityToken", async (accounts) => {
13581369
`);
13591370
assert.equal(
13601371
await I_SecurityToken.name.call(),
1361-
(web3.utils.toAscii(await readStorage(I_SecurityToken.address, 3)).replace(/\u0000/g, "")).replace(/\u0014/g, "")
1372+
(web3.utils.toAscii(await readStorage(I_SecurityToken.address, 5)).replace(/\u0000/g, "")).replace(/\u0014/g, "")
13621373
)
13631374
console.log(`
13641375
Name of the ST: ${await I_SecurityToken.name.call()}
1365-
Name of the ST from the storage: ${web3.utils.toUtf8(await readStorage(I_SecurityToken.address, 3))}
1376+
Name of the ST from the storage: ${web3.utils.toUtf8(await readStorage(I_SecurityToken.address, 5))}
13661377
`);
13671378
assert.equal(
13681379
await I_SecurityToken.symbol.call(),
1369-
(web3.utils.toUtf8(await readStorage(I_SecurityToken.address, 4)).replace(/\u0000/g, "")).replace(/\u0006/g, "")
1380+
(web3.utils.toUtf8(await readStorage(I_SecurityToken.address, 6)).replace(/\u0000/g, "")).replace(/\u0006/g, "")
13701381
);
13711382
console.log(`
13721383
Symbol of the ST: ${await I_SecurityToken.symbol.call()}
1373-
Symbol of the ST from the storage: ${web3.utils.toUtf8(await readStorage(I_SecurityToken.address, 4))}
1384+
Symbol of the ST from the storage: ${web3.utils.toUtf8(await readStorage(I_SecurityToken.address, 6))}
13741385
`);
13751386

13761387
console.log(`
13771388
Address of the owner: ${await I_SecurityToken.owner.call()}
1378-
Address of the owner from the storage: ${(await readStorage(I_SecurityToken.address, 5)).substring(0, 42)}
1389+
Address of the owner from the storage: ${(await readStorage(I_SecurityToken.address, 3)).substring(0, 42)}
13791390
`)
13801391
assert.equal(
13811392
await I_SecurityToken.owner.call(),
1382-
web3.utils.toChecksumAddress((await readStorage(I_SecurityToken.address, 5)).substring(0, 42))
1393+
web3.utils.toChecksumAddress((await readStorage(I_SecurityToken.address, 3)).substring(0, 42))
13831394
);
13841395

13851396
});
13861397

13871398
it("Verify the storage of the STStorage", async() => {
1388-
// for (let j = 7; j < 35; j++) {
1389-
// console.log(await readStorage(I_SecurityToken.address, j));
1390-
// }
13911399

13921400
console.log(`
1393-
Controller address from the contract: ${await stGetter.controller.call()}
1394-
Controller address from the storage: ${await readStorage(I_SecurityToken.address, 7)}
1401+
Controller address from the contract: ${await stGetter.controller.call()}
1402+
decimals from the contract: ${await stGetter.decimals.call()}
1403+
controller address from the storage + uint8 decimals: ${await readStorage(I_SecurityToken.address, 7)}
13951404
`)
1396-
// Different versions of web3 behave differently :/
1405+
1406+
// Controller address is packed with decimals so if controller address is 0x0, only decimals will be returned from read storage.
13971407
assert.oneOf(
13981408
await readStorage(I_SecurityToken.address, 7),
13991409
[
1400-
(await stGetter.controller.call()).toLowerCase(),
1401-
(await stGetter.controller.call()).substring(0, 4),
1402-
(await stGetter.controller.call()).substring(0, 3),
1403-
await stGetter.controller.call()
1410+
(await stGetter.controller.call()).toLowerCase() + "12",
1411+
"0x12" // When controller address = 0x0, web3 converts 0x00000..000012 to 0x12
14041412
]
14051413
);
14061414

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5148,10 +5148,10 @@ onetime@^2.0.0:
51485148
dependencies:
51495149
mimic-fn "^1.0.0"
51505150

5151-
openzeppelin-solidity@2.1.2:
5152-
version "2.1.2"
5153-
resolved "https://registry.yarnpkg.com/openzeppelin-solidity/-/openzeppelin-solidity-2.1.2.tgz#94e2bb92b60e91abb22c6fe27d983d92850fb324"
5154-
integrity sha512-1ggh+AZFpMAgGfgnVMQ8dwYawjD2QN4xuWkQS4FUbeUz1fnCKJpguUl2cyadyfDYjBq1XJ6MA6VkzYpTZtJMqw==
5151+
openzeppelin-solidity@^2.2.0:
5152+
version "2.2.0"
5153+
resolved "https://registry.yarnpkg.com/openzeppelin-solidity/-/openzeppelin-solidity-2.2.0.tgz#1f0e857f53bda29b77a8e72f9a629db81015fd34"
5154+
integrity sha512-HfQq0xyT+EPs/lTWEd5Odu4T7CYdYe+qwf54EH28FQZthp4Bs6IWvOlOumTdS2dvpwZoTXURAopHn2LN1pwAGQ==
51555155

51565156
optimist@^0.6.1:
51575157
version "0.6.1"

0 commit comments

Comments
 (0)