Skip to content

Commit

Permalink
Merge pull request #515 from PolymathNetwork/CLI-text-and-improvements
Browse files Browse the repository at this point in the history
[CLI] Cli text and improvements
  • Loading branch information
CPSTL authored Feb 7, 2019
2 parents 013ac45 + 0973815 commit fcc2fc6
Show file tree
Hide file tree
Showing 7 changed files with 311 additions and 326 deletions.
8 changes: 4 additions & 4 deletions CLI/commands/ST20Generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,13 @@ async function selectTicker() {

async function approvePoly(spender, fee) {
polyBalance = await polyToken.methods.balanceOf(Issuer.address).call();
let requiredAmount = web3.utils.toWei(fee.toString(), "ether");
let requiredAmount = web3.utils.toWei(fee.toString());
if (parseInt(polyBalance) >= parseInt(requiredAmount)) {
let allowance = await polyToken.methods.allowance(spender, Issuer.address).call();
if (allowance == web3.utils.toWei(fee.toString(), "ether")) {
let allowance = await polyToken.methods.allowance(Issuer.address, spender).call();
if (parseInt(allowance) >= parseInt(requiredAmount)) {
return true;
} else {
let approveAction = polyToken.methods.approve(spender, web3.utils.toWei(fee.toString(), "ether"));
let approveAction = polyToken.methods.approve(spender, requiredAmount);
await common.sendTransaction(approveAction);
}
} else {
Expand Down
15 changes: 7 additions & 8 deletions CLI/commands/investor_portal.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ async function showTokenInfo() {

// Show info
async function showUserInfo(_user) {
let listOfStableCoins = await currentSTO.methods.getUsdTokens().call();

console.log(`
******************* User Information ********************
- Address: ${_user}`);
Expand All @@ -164,6 +162,7 @@ async function showUserInfo(_user) {
console.log(` - ETH balance:\t ${web3.utils.fromWei(await web3.eth.getBalance(_user))}`);
}
if (await currentSTO.methods.fundRaiseTypes(gbl.constants.FUND_RAISE_TYPES.STABLE).call()) {
let listOfStableCoins = await currentSTO.methods.getUsdTokens().call();
let stableSymbolsAndBalance = await processAddressWithBalance(listOfStableCoins);
stableSymbolsAndBalance.forEach(stable => {
console.log(` - ${stable.symbol} balance:\t ${web3.utils.fromWei(stable.balance)}`);
Expand Down Expand Up @@ -499,8 +498,8 @@ async function investCappedSTO(currency, amount) {
if (raiseTypes[0] == 'POLY') {
let userBalance = await polyBalance(User.address);
if (parseInt(userBalance) >= parseInt(cost)) {
let allowance = await polyToken.methods.allowance(STOAddress, User.address).call();
if (allowance < costWei) {
let allowance = await polyToken.methods.allowance(User.address, STOAddress).call();
if (parseInt(allowance) < parseInt(costWei)) {
let approveAction = polyToken.methods.approve(STOAddress, costWei);
await common.sendTransaction(approveAction, { from: User });
}
Expand Down Expand Up @@ -608,8 +607,8 @@ async function investUsdTieredSTO(currency, amount) {
if (raiseType == POLY) {
let userBalance = await polyBalance(User.address);
if (parseInt(userBalance) >= parseInt(cost)) {
let allowance = await polyToken.methods.allowance(STOAddress, User.address).call();
if (allowance < costWei) {
let allowance = await polyToken.methods.allowance(User.address, STOAddress).call();
if (parseInt(allowance) < parseInt(costWei)) {
let approveAction = polyToken.methods.approve(STOAddress, costWei);
await common.sendTransaction(approveAction, { from: User });
}
Expand All @@ -629,8 +628,8 @@ async function investUsdTieredSTO(currency, amount) {

if (parseInt(stableInfo.balance) >= parseInt(cost)) {
let stableCoin = common.connect(abis.erc20(), stableInfo.address);
let allowance = await stableCoin.methods.allowance(STOAddress, User.address).call();
if (allowance < costWei) {
let allowance = await stableCoin.methods.allowance(User.address, STOAddress).call();
if (parseInt(allowance) < parseInt(costWei)) {
let approveAction = stableCoin.methods.approve(STOAddress, costWei);
await common.sendTransaction(approveAction, { from: User });
}
Expand Down
52 changes: 26 additions & 26 deletions CLI/commands/permission_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ async function executeApp() {
}
};

async function setup(){
async function setup() {
try {
let securityTokenRegistryAddress = await contracts.securityTokenRegistry();
let securityTokenRegistryABI = abis.securityTokenRegistry();
securityTokenRegistry = new web3.eth.Contract(securityTokenRegistryABI, securityTokenRegistryAddress);
securityTokenRegistry.setProvider(web3.currentProvider);
} catch (err) {
console.log(err)
console.log('\x1b[31m%s\x1b[0m',"There was a problem getting the contracts. Make sure they are deployed to the selected network.");
console.log('\x1b[31m%s\x1b[0m', "There was a problem getting the contracts. Make sure they are deployed to the selected network.");
process.exit(0);
}
}
Expand All @@ -56,7 +56,7 @@ async function selectST() {
await selectST();
} else {
let securityTokenABI = abis.securityToken();
securityToken = new web3.eth.Contract(securityTokenABI,result);
securityToken = new web3.eth.Contract(securityTokenABI, result);
}
}

Expand Down Expand Up @@ -85,13 +85,13 @@ async function addPermissionModule() {
}

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

async function deleteDelegate(address) {
let deleteDelegateAction = generalPermissionManager.methods.deleteDelegate(address);
await common.sendTransaction(deleteDelegateAction, {factor: 2});
await common.sendTransaction(deleteDelegateAction, { factor: 2 });
}

// Helper functions
async function selectDelegate() {
let result;
let delegates = await getDelegates();
let permissions = await getDelegatesAndPermissions();

let options = ['Add new delegate'];

options = options.concat(delegates.map(function(d) {
options = options.concat(delegates.map(function (d) {
let perm = renderTable(permissions, d.address);

return `Account: ${d.address}
Details: ${d.details}
Permisions: ${perm}`
}));

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

async function selectModule() {
let modules = await getModulesWithPermissions();
let options = modules.map(function(m) {
let options = modules.map(function (m) {
return m.name;
});
let index = readlineSync.keyInSelect(options, 'Select a module:', {cancel: false});
let index = readlineSync.keyInSelect(options, 'Select a module:', { cancel: false });
return modules[index];
}

async function selectPermission(permissions) {
let options = permissions.map(function(p) {
let options = permissions.map(function (p) {
return p
});
let index = readlineSync.keyInSelect(options, 'Select a permission:', {cancel: false});
let index = readlineSync.keyInSelect(options, 'Select a permission:', { cancel: false });
return permissions[index];
}

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

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

async function getDelegates() {
Expand Down Expand Up @@ -199,7 +199,7 @@ async function addNewDelegate() {
limitMessage: "Must be a valid address"
});
let details = readlineSync.question('Enter the delegate details (i.e `Belongs to financial firm`): ', {
limit: function(input) {
limit: function (input) {
return input.length > 0;
},
limitMessage: "Must be a valid string"
Expand All @@ -208,22 +208,22 @@ async function addNewDelegate() {
let addPermissionAction = generalPermissionManager.methods.addDelegate(newDelegate, web3.utils.asciiToHex(details));
let receipt = await common.sendTransaction(addPermissionAction);
let event = common.getEventFromLogs(generalPermissionManager._jsonInterface, receipt.logs, 'AddDelegate');
console.log(`Delegate added succesfully: ${event._delegate} - ${web3.utils.hexToAscii(event._details)}`);
console.log(`Delegate added successfully: ${event._delegate} - ${web3.utils.hexToAscii(event._details)}`);
isNewDelegate = true;
return event._delegate;
}

async function getModulesWithPermissions() {
let modules = [];
let moduleABI = abis.moduleInterface();

for (const type in gbl.constants.MODULES_TYPES) {
let modulesAttached = await securityToken.methods.getModulesByType(gbl.constants.MODULES_TYPES[type]).call();
for (const m of modulesAttached) {
let contractTemp = new web3.eth.Contract(moduleABI, m);
let permissions = await contractTemp.methods.getPermissions().call();
if (permissions.length > 0) {
modules.push({
modules.push({
name: web3.utils.hexToAscii((await securityToken.methods.getModule(m).call())[0]),
address: m,
permissions: permissions.map(function (p) { return web3.utils.hexToAscii(p) })
Expand Down Expand Up @@ -251,11 +251,11 @@ async function getDelegatesAndPermissions() {
for (delegateAddr of allDelegates) {
if (result[delegateAddr] == undefined) {
result[delegateAddr] = []
}
}
if (result[delegateAddr][moduleName + '-' + module] == undefined) {
result[delegateAddr][moduleName + '-' + module] = [{permission: permissionName}]
result[delegateAddr][moduleName + '-' + module] = [{ permission: permissionName }]
} else {
result[delegateAddr][moduleName + '-' + module].push({permission: permissionName})
result[delegateAddr][moduleName + '-' + module].push({ permission: permissionName })
}
}
}
Expand Down Expand Up @@ -283,7 +283,7 @@ function renderTable(permissions, address) {
}

module.exports = {
executeApp: async function() {
return executeApp();
}
executeApp: async function () {
return executeApp();
}
}
15 changes: 1 addition & 14 deletions CLI/commands/sto_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ let tokenSymbol;
let securityTokenRegistry;
let moduleRegistry;
let polyToken;
let usdToken;
let securityToken;

async function executeApp() {
Expand Down Expand Up @@ -329,20 +328,15 @@ async function addressesConfigUSDTieredSTO(usdTokenRaise) {
let listOfAddress;

if (usdTokenRaise) {
addresses.usdToken = readlineSync.question('Enter the address (or multiple addresses separated by commas) of the USD stable coin(s) (' + usdToken.options.address + '): ', {
addresses.usdToken = readlineSync.question('Enter the address (or multiple addresses separated by commas) of the USD stable coin(s): ', {
limit: function (input) {
listOfAddress = input.split(',');
return listOfAddress.every((addr) => {
return web3.utils.isAddress(addr)
})
},
limitMessage: "Must be a valid address",
defaultInput: usdToken.options.address
});
if (addresses.usdToken == "") {
listOfAddress = [usdToken.options.address]
addresses.usdToken = [usdToken.options.address];
}
} else {
listOfAddress = []
addresses.usdToken = [];
Expand Down Expand Up @@ -978,8 +972,6 @@ async function getBalance(from, type) {
return await web3.eth.getBalance(from);
case gbl.constants.FUND_RAISE_TYPES.POLY:
return await polyToken.methods.balanceOf(from).call();
case gbl.constants.FUND_RAISE_TYPES.STABLE:
return await usdToken.methods.balanceOf(from).call();
}
}

Expand Down Expand Up @@ -1055,11 +1047,6 @@ async function setup() {
let polytokenABI = abis.polyToken();
polyToken = new web3.eth.Contract(polytokenABI, polytokenAddress);
polyToken.setProvider(web3.currentProvider);

//TODO: Use proper DAI token here
let usdTokenAddress = await contracts.usdToken();
usdToken = new web3.eth.Contract(polytokenABI, usdTokenAddress);
usdToken.setProvider(web3.currentProvider);
} catch (err) {
console.log(err)
console.log('\x1b[31m%s\x1b[0m', "There was a problem getting the contracts. Make sure they are deployed to the selected network.");
Expand Down
20 changes: 10 additions & 10 deletions CLI/commands/token_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ async function mintTokens() {
let fromTime = readlineSync.questionInt('Enter the time (Unix Epoch time) when the sale lockup period ends and the investor can freely sell his tokens: ');
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: ');
let expiryTime = readlineSync.questionInt('Enter the time till investors KYC will be validated (after that investor need to do re-KYC): ');
let canBuyFromSTO = readlineSync.keyInYNStrict('Is the investor a restricted investor?');
let canBuyFromSTO = readlineSync.keyInYNStrict('Can the investor buy from security token offerings?');
await modifyWhitelist(investor, fromTime, toTime, expiryTime, canBuyFromSTO);
break;
case 'Mint tokens to a single address':
Expand Down Expand Up @@ -467,7 +467,7 @@ async function listModuleOptions() {
// Modules a actions
async function addModule() {
let options = ['Permission Manager', 'Transfer Manager', 'Security Token Offering', 'Dividends', 'Burn'];
let index = readlineSync.keyInSelect(options, 'What type of module whould you like to add?', { cancel: 'Return' });
let index = readlineSync.keyInSelect(options, 'What type of module would you like to add?', { cancel: 'Return' });
switch (options[index]) {
case 'Permission Manager':
console.log(chalk.red(`
Expand Down Expand Up @@ -498,13 +498,13 @@ async function addModule() {

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

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

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

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

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

0 comments on commit fcc2fc6

Please sign in to comment.