Skip to content

Commit 87252a3

Browse files
authored
Merge pull request #428 from PolymathNetwork/module-labeling
Module labeling
2 parents e4dc5f3 + 6e6b137 commit 87252a3

File tree

3 files changed

+56
-17
lines changed

3 files changed

+56
-17
lines changed

contracts/libraries/TokenLib.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ library TokenLib {
1616
uint8[] moduleTypes;
1717
uint256[] moduleIndexes;
1818
uint256 nameIndex;
19+
bytes32 label;
1920
}
2021

2122
// Structures to maintain checkpoints of balances for governance / dividends

contracts/tokens/SecurityToken.sol

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ contract SecurityToken is ERC20, ERC20Detailed, ReentrancyGuard, RegistryUpdater
9090
address _module,
9191
uint256 _moduleCost,
9292
uint256 _budget,
93+
bytes32 _label,
9394
uint256 _timestamp
9495
);
9596

@@ -213,21 +214,24 @@ contract SecurityToken is ERC20, ERC20Detailed, ReentrancyGuard, RegistryUpdater
213214
securityTokenVersion = SemanticVersion(2,0,0);
214215
}
215216

216-
/**
217-
* @notice Attachs a module to the SecurityToken
218-
* @dev E.G.: On deployment (through the STR) ST gets a TransferManager module attached to it
219-
* @dev to control restrictions on transfers.
220-
* @param _moduleFactory is the address of the module factory to be added
221-
* @param _data is data packed into bytes used to further configure the module (See STO usage)
222-
* @param _maxCost max amount of POLY willing to pay to the module.
223-
* @param _budget max amount of ongoing POLY willing to assign to the module.
224-
*/
225-
function addModule(
217+
// /**
218+
// * @notice Attachs a module to the SecurityToken
219+
// * @dev E.G.: On deployment (through the STR) ST gets a TransferManager module attached to it
220+
// * @dev to control restrictions on transfers.
221+
// * @param _moduleFactory is the address of the module factory to be added
222+
// * @param _data is data packed into bytes used to further configure the module (See STO usage)
223+
// * @param _maxCost max amount of POLY willing to pay to the module.
224+
// * @param _budget max amount of ongoing POLY willing to assign to the module.
225+
// * @param _label custom module label.
226+
// */
227+
228+
function addModuleWithLabel(
226229
address _moduleFactory,
227230
bytes _data,
228231
uint256 _maxCost,
229-
uint256 _budget
230-
) external onlyOwner nonReentrant {
232+
uint256 _budget,
233+
bytes32 _label
234+
) public onlyOwner nonReentrant {
231235
//Check that the module factory exists in the ModuleRegistry - will throw otherwise
232236
IModuleRegistry(moduleRegistry).useModule(_moduleFactory);
233237
IModuleFactory moduleFactory = IModuleFactory(_moduleFactory);
@@ -250,12 +254,24 @@ contract SecurityToken is ERC20, ERC20Detailed, ReentrancyGuard, RegistryUpdater
250254
modules[moduleTypes[i]].push(module);
251255
}
252256
modulesToData[module] = TokenLib.ModuleData(
253-
moduleName, module, _moduleFactory, false, moduleTypes, moduleIndexes, names[moduleName].length
257+
moduleName, module, _moduleFactory, false, moduleTypes, moduleIndexes, names[moduleName].length, _label
254258
);
255259
names[moduleName].push(module);
256260
//Emit log event
257261
/*solium-disable-next-line security/no-block-members*/
258-
emit ModuleAdded(moduleTypes, moduleName, _moduleFactory, module, moduleCost, _budget, now);
262+
emit ModuleAdded(moduleTypes, moduleName, _moduleFactory, module, moduleCost, _budget, _label, now);
263+
}
264+
265+
/**
266+
* @notice addModule function will call addModuleWithLabel() with an empty label for backward compatible
267+
*/
268+
function addModule(
269+
address _moduleFactory,
270+
bytes _data,
271+
uint256 _maxCost,
272+
uint256 _budget
273+
) external {
274+
addModuleWithLabel(_moduleFactory, _data, _maxCost, _budget, "");
259275
}
260276

261277
/**
@@ -330,12 +346,13 @@ contract SecurityToken is ERC20, ERC20Detailed, ReentrancyGuard, RegistryUpdater
330346
* @return bool module archived
331347
* @return uint8 module type
332348
*/
333-
function getModule(address _module) external view returns (bytes32, address, address, bool, uint8[]) {
349+
function getModule(address _module) external view returns (bytes32, address, address, bool, uint8[], bytes32) {
334350
return (modulesToData[_module].name,
335351
modulesToData[_module].module,
336352
modulesToData[_module].moduleFactory,
337353
modulesToData[_module].isArchived,
338-
modulesToData[_module].moduleTypes);
354+
modulesToData[_module].moduleTypes,
355+
modulesToData[_module].label);
339356
}
340357

341358
/**

test/o_security_token.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,27 @@ contract("SecurityToken", accounts => {
296296
);
297297
});
298298

299+
it("Should successfully add module with label", async () => {
300+
let snapId = await takeSnapshot();
301+
startTime = latestTime() + duration.seconds(5000);
302+
endTime = startTime + duration.days(30);
303+
let bytesSTO = encodeModuleCall(STOParameters, [startTime, endTime, cap, rate, fundRaiseType, account_fundsReceiver]);
304+
305+
await I_PolyToken.getTokens(cappedSTOSetupCost, token_owner);
306+
await I_PolyToken.transfer(I_SecurityToken.address, cappedSTOSetupCost, { from: token_owner });
307+
console.log("0");
308+
const tx = await I_SecurityToken.addModuleWithLabel(I_CappedSTOFactory.address, bytesSTO, maxCost, 0, 'stofactory', { from: token_owner });
309+
console.log("1");
310+
assert.equal(tx.logs[3].args._types[0], stoKey, "CappedSTO doesn't get deployed");
311+
assert.equal(web3.utils.toUtf8(tx.logs[3].args._name), "CappedSTO", "CappedSTOFactory module was not added");
312+
console.log("module label is .. "+ web3.utils.toAscii(tx.logs[3].args._label));
313+
assert(web3.utils.toAscii(tx.logs[3].args._label), "stofactory", "label doesnt match");
314+
I_CappedSTO = CappedSTO.at(tx.logs[3].args._module);
315+
await revertToSnapshot(snapId);
316+
});
317+
299318
it("Should successfully attach the STO factory with the security token", async () => {
319+
300320
startTime = latestTime() + duration.seconds(5000);
301321
endTime = startTime + duration.days(30);
302322
let bytesSTO = encodeModuleCall(STOParameters, [startTime, endTime, cap, rate, fundRaiseType, account_fundsReceiver]);
@@ -327,13 +347,14 @@ contract("SecurityToken", accounts => {
327347
});
328348

329349
describe("Module related functions", async () => {
330-
it("Should get the modules of the securityToken by index", async () => {
350+
it(" Should get the modules of the securityToken by name", async () => {
331351
let moduleData = await I_SecurityToken.getModule.call(I_CappedSTO.address);
332352
assert.equal(web3.utils.toAscii(moduleData[0]).replace(/\u0000/g, ""), "CappedSTO");
333353
assert.equal(moduleData[1], I_CappedSTO.address);
334354
assert.equal(moduleData[2], I_CappedSTOFactory.address);
335355
assert.equal(moduleData[3], false);
336356
assert.equal(moduleData[4][0], 3);
357+
assert.equal(moduleData[5], 0x0000000000000000000000000000000000000000);
337358
});
338359

339360
it("Should get the modules of the securityToken by index (not added into the security token yet)", async () => {

0 commit comments

Comments
 (0)