Skip to content

Commit fcc2fc6

Browse files
authored
Merge pull request #515 from PolymathNetwork/CLI-text-and-improvements
[CLI] Cli text and improvements
2 parents 013ac45 + 0973815 commit fcc2fc6

File tree

7 files changed

+311
-326
lines changed

7 files changed

+311
-326
lines changed

CLI/commands/ST20Generator.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,13 @@ async function selectTicker() {
187187

188188
async function approvePoly(spender, fee) {
189189
polyBalance = await polyToken.methods.balanceOf(Issuer.address).call();
190-
let requiredAmount = web3.utils.toWei(fee.toString(), "ether");
190+
let requiredAmount = web3.utils.toWei(fee.toString());
191191
if (parseInt(polyBalance) >= parseInt(requiredAmount)) {
192-
let allowance = await polyToken.methods.allowance(spender, Issuer.address).call();
193-
if (allowance == web3.utils.toWei(fee.toString(), "ether")) {
192+
let allowance = await polyToken.methods.allowance(Issuer.address, spender).call();
193+
if (parseInt(allowance) >= parseInt(requiredAmount)) {
194194
return true;
195195
} else {
196-
let approveAction = polyToken.methods.approve(spender, web3.utils.toWei(fee.toString(), "ether"));
196+
let approveAction = polyToken.methods.approve(spender, requiredAmount);
197197
await common.sendTransaction(approveAction);
198198
}
199199
} else {

CLI/commands/investor_portal.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,6 @@ async function showTokenInfo() {
152152

153153
// Show info
154154
async function showUserInfo(_user) {
155-
let listOfStableCoins = await currentSTO.methods.getUsdTokens().call();
156-
157155
console.log(`
158156
******************* User Information ********************
159157
- Address: ${_user}`);
@@ -164,6 +162,7 @@ async function showUserInfo(_user) {
164162
console.log(` - ETH balance:\t ${web3.utils.fromWei(await web3.eth.getBalance(_user))}`);
165163
}
166164
if (await currentSTO.methods.fundRaiseTypes(gbl.constants.FUND_RAISE_TYPES.STABLE).call()) {
165+
let listOfStableCoins = await currentSTO.methods.getUsdTokens().call();
167166
let stableSymbolsAndBalance = await processAddressWithBalance(listOfStableCoins);
168167
stableSymbolsAndBalance.forEach(stable => {
169168
console.log(` - ${stable.symbol} balance:\t ${web3.utils.fromWei(stable.balance)}`);
@@ -499,8 +498,8 @@ async function investCappedSTO(currency, amount) {
499498
if (raiseTypes[0] == 'POLY') {
500499
let userBalance = await polyBalance(User.address);
501500
if (parseInt(userBalance) >= parseInt(cost)) {
502-
let allowance = await polyToken.methods.allowance(STOAddress, User.address).call();
503-
if (allowance < costWei) {
501+
let allowance = await polyToken.methods.allowance(User.address, STOAddress).call();
502+
if (parseInt(allowance) < parseInt(costWei)) {
504503
let approveAction = polyToken.methods.approve(STOAddress, costWei);
505504
await common.sendTransaction(approveAction, { from: User });
506505
}
@@ -608,8 +607,8 @@ async function investUsdTieredSTO(currency, amount) {
608607
if (raiseType == POLY) {
609608
let userBalance = await polyBalance(User.address);
610609
if (parseInt(userBalance) >= parseInt(cost)) {
611-
let allowance = await polyToken.methods.allowance(STOAddress, User.address).call();
612-
if (allowance < costWei) {
610+
let allowance = await polyToken.methods.allowance(User.address, STOAddress).call();
611+
if (parseInt(allowance) < parseInt(costWei)) {
613612
let approveAction = polyToken.methods.approve(STOAddress, costWei);
614613
await common.sendTransaction(approveAction, { from: User });
615614
}
@@ -629,8 +628,8 @@ async function investUsdTieredSTO(currency, amount) {
629628

630629
if (parseInt(stableInfo.balance) >= parseInt(cost)) {
631630
let stableCoin = common.connect(abis.erc20(), stableInfo.address);
632-
let allowance = await stableCoin.methods.allowance(STOAddress, User.address).call();
633-
if (allowance < costWei) {
631+
let allowance = await stableCoin.methods.allowance(User.address, STOAddress).call();
632+
if (parseInt(allowance) < parseInt(costWei)) {
634633
let approveAction = stableCoin.methods.approve(STOAddress, costWei);
635634
await common.sendTransaction(approveAction, { from: User });
636635
}

CLI/commands/permission_manager.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ async function executeApp() {
3232
}
3333
};
3434

35-
async function setup(){
35+
async function setup() {
3636
try {
3737
let securityTokenRegistryAddress = await contracts.securityTokenRegistry();
3838
let securityTokenRegistryABI = abis.securityTokenRegistry();
3939
securityTokenRegistry = new web3.eth.Contract(securityTokenRegistryABI, securityTokenRegistryAddress);
4040
securityTokenRegistry.setProvider(web3.currentProvider);
4141
} catch (err) {
4242
console.log(err)
43-
console.log('\x1b[31m%s\x1b[0m',"There was a problem getting the contracts. Make sure they are deployed to the selected network.");
43+
console.log('\x1b[31m%s\x1b[0m', "There was a problem getting the contracts. Make sure they are deployed to the selected network.");
4444
process.exit(0);
4545
}
4646
}
@@ -56,7 +56,7 @@ async function selectST() {
5656
await selectST();
5757
} else {
5858
let securityTokenABI = abis.securityToken();
59-
securityToken = new web3.eth.Contract(securityTokenABI,result);
59+
securityToken = new web3.eth.Contract(securityTokenABI, result);
6060
}
6161
}
6262

@@ -85,13 +85,13 @@ async function addPermissionModule() {
8585
}
8686

8787
async function changePermissionStep() {
88-
console.log('\n\x1b[34m%s\x1b[0m',"Permission Manager - Change Permission");
88+
console.log('\n\x1b[34m%s\x1b[0m', "Permission Manager - Change Permission");
8989
let selectedDelegate = await selectDelegate();
9090
if (isNewDelegate) {
9191
isNewDelegate = false;
9292
changePermissionAction(selectedDelegate);
9393
} else {
94-
let selectFlow = readlineSync.keyInSelect(['Remove', 'Change permission'], 'Select an option:', {cancel: false});
94+
let selectFlow = readlineSync.keyInSelect(['Remove', 'Change permission'], 'Select an option:', { cancel: false });
9595
if (selectFlow == 0) {
9696
await deleteDelegate(selectedDelegate);
9797
console.log("Delegate successfully deleted.")
@@ -110,26 +110,26 @@ async function changePermissionAction(selectedDelegate) {
110110

111111
async function deleteDelegate(address) {
112112
let deleteDelegateAction = generalPermissionManager.methods.deleteDelegate(address);
113-
await common.sendTransaction(deleteDelegateAction, {factor: 2});
113+
await common.sendTransaction(deleteDelegateAction, { factor: 2 });
114114
}
115115

116116
// Helper functions
117117
async function selectDelegate() {
118118
let result;
119119
let delegates = await getDelegates();
120120
let permissions = await getDelegatesAndPermissions();
121-
121+
122122
let options = ['Add new delegate'];
123123

124-
options = options.concat(delegates.map(function(d) {
124+
options = options.concat(delegates.map(function (d) {
125125
let perm = renderTable(permissions, d.address);
126126

127127
return `Account: ${d.address}
128128
Details: ${d.details}
129129
Permisions: ${perm}`
130130
}));
131131

132-
let index = readlineSync.keyInSelect(options, 'Select a delegate:', {cancel: false});
132+
let index = readlineSync.keyInSelect(options, 'Select a delegate:', { cancel: false });
133133
if (index == 0) {
134134
let newDelegate = await addNewDelegate();
135135
result = newDelegate;
@@ -142,32 +142,32 @@ async function selectDelegate() {
142142

143143
async function selectModule() {
144144
let modules = await getModulesWithPermissions();
145-
let options = modules.map(function(m) {
145+
let options = modules.map(function (m) {
146146
return m.name;
147147
});
148-
let index = readlineSync.keyInSelect(options, 'Select a module:', {cancel: false});
148+
let index = readlineSync.keyInSelect(options, 'Select a module:', { cancel: false });
149149
return modules[index];
150150
}
151151

152152
async function selectPermission(permissions) {
153-
let options = permissions.map(function(p) {
153+
let options = permissions.map(function (p) {
154154
return p
155155
});
156-
let index = readlineSync.keyInSelect(options, 'Select a permission:', {cancel: false});
156+
let index = readlineSync.keyInSelect(options, 'Select a permission:', { cancel: false });
157157
return permissions[index];
158158
}
159159

160160
function isPermissionValid() {
161161
let options = ['Grant permission', 'Revoke permission'];
162-
let index = readlineSync.keyInSelect(options, 'What do you want to do?', {cancel: false});
162+
let index = readlineSync.keyInSelect(options, 'What do you want to do?', { cancel: false });
163163
return index == 0;
164164
}
165165

166166
async function changePermission(delegate, moduleAddress, permission, isValid) {
167167
let changePermissionAction = generalPermissionManager.methods.changePermission(delegate, moduleAddress, web3.utils.asciiToHex(permission), isValid);
168-
let receipt = await common.sendTransaction(changePermissionAction, {factor: 2});
168+
let receipt = await common.sendTransaction(changePermissionAction, { factor: 2 });
169169
common.getEventFromLogs(generalPermissionManager._jsonInterface, receipt.logs, 'ChangePermission');
170-
console.log(`Permission changed succesfully,`);
170+
console.log(`Permission changed successfully!`);
171171
}
172172

173173
async function getDelegates() {
@@ -199,7 +199,7 @@ async function addNewDelegate() {
199199
limitMessage: "Must be a valid address"
200200
});
201201
let details = readlineSync.question('Enter the delegate details (i.e `Belongs to financial firm`): ', {
202-
limit: function(input) {
202+
limit: function (input) {
203203
return input.length > 0;
204204
},
205205
limitMessage: "Must be a valid string"
@@ -208,22 +208,22 @@ async function addNewDelegate() {
208208
let addPermissionAction = generalPermissionManager.methods.addDelegate(newDelegate, web3.utils.asciiToHex(details));
209209
let receipt = await common.sendTransaction(addPermissionAction);
210210
let event = common.getEventFromLogs(generalPermissionManager._jsonInterface, receipt.logs, 'AddDelegate');
211-
console.log(`Delegate added succesfully: ${event._delegate} - ${web3.utils.hexToAscii(event._details)}`);
211+
console.log(`Delegate added successfully: ${event._delegate} - ${web3.utils.hexToAscii(event._details)}`);
212212
isNewDelegate = true;
213213
return event._delegate;
214214
}
215215

216216
async function getModulesWithPermissions() {
217217
let modules = [];
218218
let moduleABI = abis.moduleInterface();
219-
219+
220220
for (const type in gbl.constants.MODULES_TYPES) {
221221
let modulesAttached = await securityToken.methods.getModulesByType(gbl.constants.MODULES_TYPES[type]).call();
222222
for (const m of modulesAttached) {
223223
let contractTemp = new web3.eth.Contract(moduleABI, m);
224224
let permissions = await contractTemp.methods.getPermissions().call();
225225
if (permissions.length > 0) {
226-
modules.push({
226+
modules.push({
227227
name: web3.utils.hexToAscii((await securityToken.methods.getModule(m).call())[0]),
228228
address: m,
229229
permissions: permissions.map(function (p) { return web3.utils.hexToAscii(p) })
@@ -251,11 +251,11 @@ async function getDelegatesAndPermissions() {
251251
for (delegateAddr of allDelegates) {
252252
if (result[delegateAddr] == undefined) {
253253
result[delegateAddr] = []
254-
}
254+
}
255255
if (result[delegateAddr][moduleName + '-' + module] == undefined) {
256-
result[delegateAddr][moduleName + '-' + module] = [{permission: permissionName}]
256+
result[delegateAddr][moduleName + '-' + module] = [{ permission: permissionName }]
257257
} else {
258-
result[delegateAddr][moduleName + '-' + module].push({permission: permissionName})
258+
result[delegateAddr][moduleName + '-' + module].push({ permission: permissionName })
259259
}
260260
}
261261
}
@@ -283,7 +283,7 @@ function renderTable(permissions, address) {
283283
}
284284

285285
module.exports = {
286-
executeApp: async function() {
287-
return executeApp();
288-
}
286+
executeApp: async function () {
287+
return executeApp();
288+
}
289289
}

CLI/commands/sto_manager.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ let tokenSymbol;
2222
let securityTokenRegistry;
2323
let moduleRegistry;
2424
let polyToken;
25-
let usdToken;
2625
let securityToken;
2726

2827
async function executeApp() {
@@ -329,20 +328,15 @@ async function addressesConfigUSDTieredSTO(usdTokenRaise) {
329328
let listOfAddress;
330329

331330
if (usdTokenRaise) {
332-
addresses.usdToken = readlineSync.question('Enter the address (or multiple addresses separated by commas) of the USD stable coin(s) (' + usdToken.options.address + '): ', {
331+
addresses.usdToken = readlineSync.question('Enter the address (or multiple addresses separated by commas) of the USD stable coin(s): ', {
333332
limit: function (input) {
334333
listOfAddress = input.split(',');
335334
return listOfAddress.every((addr) => {
336335
return web3.utils.isAddress(addr)
337336
})
338337
},
339338
limitMessage: "Must be a valid address",
340-
defaultInput: usdToken.options.address
341339
});
342-
if (addresses.usdToken == "") {
343-
listOfAddress = [usdToken.options.address]
344-
addresses.usdToken = [usdToken.options.address];
345-
}
346340
} else {
347341
listOfAddress = []
348342
addresses.usdToken = [];
@@ -978,8 +972,6 @@ async function getBalance(from, type) {
978972
return await web3.eth.getBalance(from);
979973
case gbl.constants.FUND_RAISE_TYPES.POLY:
980974
return await polyToken.methods.balanceOf(from).call();
981-
case gbl.constants.FUND_RAISE_TYPES.STABLE:
982-
return await usdToken.methods.balanceOf(from).call();
983975
}
984976
}
985977

@@ -1055,11 +1047,6 @@ async function setup() {
10551047
let polytokenABI = abis.polyToken();
10561048
polyToken = new web3.eth.Contract(polytokenABI, polytokenAddress);
10571049
polyToken.setProvider(web3.currentProvider);
1058-
1059-
//TODO: Use proper DAI token here
1060-
let usdTokenAddress = await contracts.usdToken();
1061-
usdToken = new web3.eth.Contract(polytokenABI, usdTokenAddress);
1062-
usdToken.setProvider(web3.currentProvider);
10631050
} catch (err) {
10641051
console.log(err)
10651052
console.log('\x1b[31m%s\x1b[0m', "There was a problem getting the contracts. Make sure they are deployed to the selected network.");

CLI/commands/token_manager.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ async function mintTokens() {
297297
let fromTime = readlineSync.questionInt('Enter the time (Unix Epoch time) when the sale lockup period ends and the investor can freely sell his tokens: ');
298298
let toTime = readlineSync.questionInt('Enter the time (Unix Epoch time) when the purchase lockup period ends and the investor can freely purchase tokens from others: ');
299299
let expiryTime = readlineSync.questionInt('Enter the time till investors KYC will be validated (after that investor need to do re-KYC): ');
300-
let canBuyFromSTO = readlineSync.keyInYNStrict('Is the investor a restricted investor?');
300+
let canBuyFromSTO = readlineSync.keyInYNStrict('Can the investor buy from security token offerings?');
301301
await modifyWhitelist(investor, fromTime, toTime, expiryTime, canBuyFromSTO);
302302
break;
303303
case 'Mint tokens to a single address':
@@ -467,7 +467,7 @@ async function listModuleOptions() {
467467
// Modules a actions
468468
async function addModule() {
469469
let options = ['Permission Manager', 'Transfer Manager', 'Security Token Offering', 'Dividends', 'Burn'];
470-
let index = readlineSync.keyInSelect(options, 'What type of module whould you like to add?', { cancel: 'Return' });
470+
let index = readlineSync.keyInSelect(options, 'What type of module would you like to add?', { cancel: 'Return' });
471471
switch (options[index]) {
472472
case 'Permission Manager':
473473
console.log(chalk.red(`
@@ -498,13 +498,13 @@ async function addModule() {
498498

499499
async function pauseModule(modules) {
500500
let options = modules.map(m => `${m.name} (${m.address})`);
501-
let index = readlineSync.keyInSelect(options, 'Which module whould you like to pause?');
501+
let index = readlineSync.keyInSelect(options, 'Which module would you like to pause?');
502502
if (index != -1) {
503503
console.log("\nSelected:", options[index]);
504504
let moduleABI;
505505
if (modules[index].type == gbl.constants.MODULES_TYPES.STO) {
506506
moduleABI = abis.ISTO();
507-
} else if (modules[index].type == gbl.constants.MODULES_TYPES.STO) {
507+
} else if (modules[index].type == gbl.constants.MODULES_TYPES.TRANSFER) {
508508
moduleABI = abis.ITransferManager();
509509
} else {
510510
console.log(chalk.red(`Only STO and TM modules can be paused/unpaused`));
@@ -519,13 +519,13 @@ async function pauseModule(modules) {
519519

520520
async function unpauseModule(modules) {
521521
let options = modules.map(m => `${m.name} (${m.address})`);
522-
let index = readlineSync.keyInSelect(options, 'Which module whould you like to pause?');
522+
let index = readlineSync.keyInSelect(options, 'Which module would you like to pause?');
523523
if (index != -1) {
524524
console.log("\nSelected: ", options[index]);
525525
let moduleABI;
526526
if (modules[index].type == gbl.constants.MODULES_TYPES.STO) {
527527
moduleABI = abis.ISTO();
528-
} else if (modules[index].type == gbl.constants.MODULES_TYPES.STO) {
528+
} else if (modules[index].type == gbl.constants.MODULES_TYPES.TRANSFER) {
529529
moduleABI = abis.ITransferManager();
530530
} else {
531531
console.log(chalk.red(`Only STO and TM modules can be paused/unpaused`));
@@ -551,7 +551,7 @@ async function archiveModule(modules) {
551551

552552
async function unarchiveModule(modules) {
553553
let options = modules.map(m => `${m.name} (${m.address})`);
554-
let index = readlineSync.keyInSelect(options, 'Which module whould you like to unarchive?');
554+
let index = readlineSync.keyInSelect(options, 'Which module would you like to unarchive?');
555555
if (index != -1) {
556556
console.log("\nSelected: ", options[index]);
557557
let unarchiveModuleAction = securityToken.methods.unarchiveModule(modules[index].address);
@@ -562,7 +562,7 @@ async function unarchiveModule(modules) {
562562

563563
async function removeModule(modules) {
564564
let options = modules.map(m => `${m.name} (${m.address})`);
565-
let index = readlineSync.keyInSelect(options, 'Which module whould you like to remove?');
565+
let index = readlineSync.keyInSelect(options, 'Which module would you like to remove?');
566566
if (index != -1) {
567567
console.log("\nSelected: ", options[index]);
568568
let removeModuleAction = securityToken.methods.removeModule(modules[index].address);
@@ -571,9 +571,9 @@ async function removeModule(modules) {
571571
}
572572
}
573573

574-
async function changeBudget() {
574+
async function changeBudget(modules) {
575575
let options = modules.map(m => `${m.name} (${m.address})`);
576-
let index = readlineSync.keyInSelect(options, 'Which module whould you like to remove?');
576+
let index = readlineSync.keyInSelect(options, 'Which module would you like to change budget for?');
577577
if (index != -1) {
578578
console.log("\nSelected: ", options[index]);
579579
let increase = 0 == readlineSync.keyInSelect(['Increase', 'Decrease'], `Do you want to increase or decrease budget?`, { cancel: false });

0 commit comments

Comments
 (0)