Skip to content

Commit 43689cc

Browse files
VictorVicentepabloruiz55
authored andcommitted
Cli minor updates (#331)
* CLI fix for whitelist command * Fix for POLY transfer out of gas error * CLI fix for scripts on remote nodes * CLI: Allow any combination of raise types for USDTieredSTO * Remove CLI restriction to mint tokens if STO is attached * KYC expiry verification
1 parent 9dc1fc9 commit 43689cc

File tree

10 files changed

+86
-59
lines changed

10 files changed

+86
-59
lines changed

CLI/commands/ST20Generator.js

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,14 @@ let _tokenConfig;
4545
let _mintingConfig;
4646
let _stoConfig;
4747

48+
let network;
49+
4850
async function executeApp(tokenConfig, mintingConfig, stoConfig, remoteNetwork) {
4951
_tokenConfig = tokenConfig;
5052
_mintingConfig = mintingConfig;
5153
_stoConfig = stoConfig;
5254

55+
network = remoteNetwork;
5356
await global.initialize(remoteNetwork);
5457

5558
common.logAsciiBull();
@@ -257,11 +260,11 @@ async function step_Wallet_Issuance(){
257260

258261
async function multi_mint_tokens() {
259262
//await whitelist.startWhitelisting(tokenSymbol);
260-
shell.exec(`${__dirname}/scripts/script.sh Whitelist ${tokenSymbol} 75`);
263+
shell.exec(`${__dirname}/scripts/script.sh Whitelist ${tokenSymbol} 75 ${network}`);
261264
console.log(chalk.green(`\nCongrats! All the affiliates get succssfully whitelisted, Now its time to Mint the tokens\n`));
262265
console.log(chalk.red(`WARNING: `) + `Please make sure all the addresses that get whitelisted are only eligible to hold or get Security token\n`);
263266

264-
shell.exec(`${__dirname}/scripts//script.sh Multimint ${tokenSymbol} 75`);
267+
shell.exec(`${__dirname}/scripts//script.sh Multimint ${tokenSymbol} 75 ${network}`);
265268
console.log(chalk.green(`\nHurray!! Tokens get successfully Minted and transfered to token holders`));
266269
}
267270

@@ -350,7 +353,7 @@ async function cappedSTO_launch() {
350353
process.exit(0);
351354
} else {
352355
let transferAction = polyToken.methods.transfer(securityToken._address, new BigNumber(transferAmount));
353-
let receipt = await common.sendTransaction(Issuer, transferAction, defaultGasPrice, 0, 1.5);
356+
let receipt = await common.sendTransaction(Issuer, transferAction, defaultGasPrice, 0, 2);
354357
let event = common.getEventFromLogs(polyToken._jsonInterface, receipt.logs, 'Transfer');
355358
console.log(`Number of POLY sent: ${web3.utils.fromWei(new web3.utils.BN(event._value))}`)
356359
}
@@ -518,19 +521,20 @@ function fundingConfigUSDTieredSTO() {
518521
if (typeof _stoConfig !== 'undefined' && _stoConfig.hasOwnProperty('fundingType')) {
519522
selectedFunding = _stoConfig.fundingType;
520523
} else {
521-
selectedFunding = readlineSync.question('Enter' + chalk.green(` P `) + 'for POLY raise,' + chalk.green(` D `) + 'for DAI raise,' + chalk.green(` E `) + 'for Ether raise or' + chalk.green(` A `) + 'for all (A): ').toUpperCase();
524+
selectedFunding = readlineSync.question('Enter' + chalk.green(` P `) + 'for POLY raise,' + chalk.green(` D `) + 'for DAI raise,' + chalk.green(` E `) + 'for Ether raise or any combination of them (i.e.'+ chalk.green(` PED `) + 'for all): ').toUpperCase();
522525
}
523526

524-
if (selectedFunding == 'E') {
525-
funding.raiseType = [FUND_RAISE_TYPES.ETH];
527+
funding.raiseType = [];
528+
if (selectedFunding.includes('E')) {
529+
funding.raiseType.push(FUND_RAISE_TYPES.ETH);
526530
}
527-
else if (selectedFunding == 'P') {
528-
funding.raiseType = [FUND_RAISE_TYPES.POLY];
531+
if (selectedFunding.includes('P')) {
532+
funding.raiseType.push(FUND_RAISE_TYPES.POLY);
529533
}
530-
else if (selectedFunding == 'D') {
531-
funding.raiseType = [FUND_RAISE_TYPES.DAI];
534+
if (selectedFunding.includes('D')) {
535+
funding.raiseType.push(FUND_RAISE_TYPES.DAI);
532536
}
533-
else {
537+
if (funding.raiseType.length == 0) {
534538
funding.raiseType = [FUND_RAISE_TYPES.ETH, FUND_RAISE_TYPES.POLY, FUND_RAISE_TYPES.DAI];
535539
}
536540

@@ -744,17 +748,17 @@ async function usdTieredSTO_launch() {
744748
let stoFee = usdTieredSTOFee;
745749
let contractBalance = await polyToken.methods.balanceOf(securityToken._address).call();
746750
let requiredAmount = web3.utils.toWei(stoFee.toString(), "ether");
747-
if (parseInt(contractBalance) < parseInt(requiredAmount)) {
748-
let transferAmount = parseInt(requiredAmount) - parseInt(contractBalance);
749-
let ownerBalance = await polyToken.methods.balanceOf(Issuer.address).call();
750-
if(parseInt(ownerBalance) < transferAmount) {
751+
if (new web3.utils.BN(contractBalance).lt(new web3.utils.BN(requiredAmount))) {
752+
let transferAmount = (new web3.utils.BN(requiredAmount)).sub(new web3.utils.BN(contractBalance));
753+
let ownerBalance = new web3.utils.BN(await polyToken.methods.balanceOf(Issuer.address).call());
754+
if (ownerBalance.lt(transferAmount)) {
751755
console.log(chalk.red(`\n**************************************************************************************************************************************************`));
752-
console.log(chalk.red(`Not enough balance to pay the ${selectedSTO} fee, Requires ${(new BigNumber(transferAmount).dividedBy(new BigNumber(10).pow(18))).toNumber()} POLY but have ${(new BigNumber(ownerBalance).dividedBy(new BigNumber(10).pow(18))).toNumber()} POLY. Access POLY faucet to get the POLY to complete this txn`));
756+
console.log(chalk.red(`Not enough balance to pay the ${selectedSTO} fee, Requires ${web3.utils.fromWei(transferAmount)} POLY but have ${web3.utils.fromWei(ownerBalance)} POLY. Access POLY faucet to get the POLY to complete this txn`));
753757
console.log(chalk.red(`**************************************************************************************************************************************************\n`));
754758
process.exit(0);
755759
} else {
756-
let transferAction = polyToken.methods.transfer(securityToken._address, new BigNumber(transferAmount));
757-
let receipt = await common.sendTransaction(Issuer, transferAction, defaultGasPrice, 0, 1.5);
760+
let transferAction = polyToken.methods.transfer(securityToken._address, transferAmount);
761+
let receipt = await common.sendTransaction(Issuer, transferAction, defaultGasPrice, 0, 2);
758762
let event = common.getEventFromLogs(polyToken._jsonInterface, receipt.logs, 'Transfer');
759763
console.log(`Number of POLY sent: ${web3.utils.fromWei(new web3.utils.BN(event._value))}`)
760764
}
@@ -1017,7 +1021,7 @@ async function usdTieredSTO_configure() {
10171021
await common.sendTransaction(Issuer, changeAccreditedAction, defaultGasPrice);
10181022
break;
10191023
case 2:
1020-
shell.exec(`${__dirname}/scripts/script.sh Accredit ${tokenSymbol} 75`);
1024+
shell.exec(`${__dirname}/scripts/script.sh Accredit ${tokenSymbol} 75 ${network}`);
10211025
break;
10221026
case 3:
10231027
let account = readlineSync.question('Enter the address to change non accredited limit: ');
@@ -1029,7 +1033,7 @@ async function usdTieredSTO_configure() {
10291033
await common.sendTransaction(Issuer, changeNonAccreditedLimitAction, defaultGasPrice);
10301034
break;
10311035
case 4:
1032-
shell.exec(`${__dirname}/scripts/script.sh NonAccreditedLimit ${tokenSymbol} 75`);
1036+
shell.exec(`${__dirname}/scripts/script.sh NonAccreditedLimit ${tokenSymbol} 75 ${network}`);
10331037
break;
10341038
case 5:
10351039
await modfifyTimes();

CLI/commands/accredit.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ let badData = new Array();
3333
startScript();
3434

3535
async function startScript() {
36+
if (remoteNetwork == 'undefined') remoteNetwork = undefined;
3637
await global.initialize(remoteNetwork);
3738
try {
3839
let securityTokenRegistryAddress = await contracts.securityTokenRegistry();

CLI/commands/changeNonAccreditedLimit.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ let badData = new Array();
3333
startScript();
3434

3535
async function startScript() {
36+
if (remoteNetwork == 'undefined') remoteNetwork = undefined;
3637
await global.initialize(remoteNetwork);
3738
try {
3839
let securityTokenRegistryAddress = await contracts.securityTokenRegistry();

CLI/commands/dividends_manager.js

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -194,24 +194,19 @@ async function mintTokens(address, amount){
194194
if (await securityToken.methods.mintingFrozen().call()) {
195195
console.log(chalk.red("Minting is not possible - Minting has been permanently frozen by issuer"));
196196
} else {
197-
let result = await securityToken.methods.getModulesByType(MODULES_TYPES.STO).call();
198-
if (result.length > 0) {
199-
console.log(chalk.red("Minting is not possible - STO is attached to Security Token"));
200-
} else {
201-
await whitelistAddress(address);
197+
await whitelistAddress(address);
202198

203-
try {
204-
let mintAction = securityToken.methods.mint(address,web3.utils.toWei(amount));
205-
let receipt = await common.sendTransaction(Issuer, mintAction, defaultGasPrice);
206-
let event = common.getEventFromLogs(securityToken._jsonInterface, receipt.logs, 'Transfer');
207-
console.log(`
199+
try {
200+
let mintAction = securityToken.methods.mint(address,web3.utils.toWei(amount));
201+
let receipt = await common.sendTransaction(Issuer, mintAction, defaultGasPrice);
202+
let event = common.getEventFromLogs(securityToken._jsonInterface, receipt.logs, 'Transfer');
203+
console.log(`
208204
Minted ${web3.utils.fromWei(event.value)} tokens
209205
to account ${event.to}`
210-
);
211-
} catch (err) {
212-
console.log(err);
213-
console.log(chalk.red("There was an error processing the transfer transaction. \n The most probable cause for this error is one of the involved accounts not being in the whitelist or under a lockup period."));
214-
}
206+
);
207+
} catch (err) {
208+
console.log(err);
209+
console.log(chalk.red("There was an error processing the transfer transaction. \n The most probable cause for this error is one of the involved accounts not being in the whitelist or under a lockup period."));
215210
}
216211
}
217212
}

CLI/commands/investor_portal.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ let STOAddress;
3636

3737
// Global display variables
3838
let displayCanBuy;
39+
let displayValidKYC;
3940

4041
// Start Script
4142
async function executeApp(investorAddress, investorPrivKey, symbol, currency, amount, remoteNetwork) {
@@ -192,14 +193,15 @@ async function showCappedSTOInfo() {
192193
}
193194
}
194195

196+
let now = Math.floor(Date.now()/1000);
197+
195198
await generalTransferManager.methods.whitelist(User.address).call({}, function(error, result){
196199
displayCanBuy = result.canBuyFromSTO;
200+
displayValidKYC = parseInt(result.expiryTime) > now;
197201
});
198202

199-
let now = Math.floor(Date.now()/1000);
200203
let timeTitle;
201204
let timeRemaining;
202-
203205
if(now < displayStartTime){
204206
timeTitle = "STO starts in: ";
205207
timeRemaining = displayStartTime - now;
@@ -229,6 +231,9 @@ async function showCappedSTOInfo() {
229231
if(!displayCanBuy) {
230232
console.log(chalk.red(`Your address is not approved to participate in this token sale.\n`));
231233
process.exit(0);
234+
} else if (!displayValidKYC) {
235+
console.log(chalk.red(`Your KYC is expired.\n`));
236+
process.exit(0);
232237
} else if (now < displayStartTime) {
233238
console.log(chalk.red(`The token sale has not yet started.\n`));
234239
process.exit(0);
@@ -252,8 +257,10 @@ async function showUserInfoForUSDTieredSTO()
252257

253258
await generalTransferManager.methods.whitelist(User.address).call({}, function(error, result){
254259
displayCanBuy = result.canBuyFromSTO;
260+
displayValidKYC = parseInt(result.expiryTime) > Math.floor(Date.now()/1000);
255261
});
256-
console.log(` - Whitelisted: ${(displayCanBuy)? 'YES' : 'NO'}`)
262+
console.log(` - Whitelisted: ${(displayCanBuy)? 'YES' : 'NO'}`);
263+
console.log(` - Valid KYC: ${(displayValidKYC)? 'YES' : 'NO'}`);
257264

258265
let displayIsUserAccredited = await currentSTO.methods.accredited(User.address).call();
259266
console.log(` - Accredited: ${(displayIsUserAccredited)? "YES" : "NO"}`)
@@ -382,6 +389,9 @@ async function showUSDTieredSTOInfo() {
382389
if (!displayCanBuy) {
383390
console.log(chalk.red(`Your address is not approved to participate in this token sale.\n`));
384391
process.exit(0);
392+
} else if (!displayValidKYC) {
393+
console.log(chalk.red(`Your KYC is expired.\n`));
394+
process.exit(0);
385395
} else if (now < displayStartTime) {
386396
console.log(chalk.red(`The token sale has not yet started.\n`));
387397
process.exit(0);

CLI/commands/module_manager.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -385,11 +385,6 @@ async function mintTokens() {
385385
console.log(chalk.red("Minting is not possible - Minting has been permanently frozen by issuer"));
386386
return;
387387
}
388-
let stoModules = await securityToken.methods.getModulesByType(STO_KEY).call();
389-
if (stoModules.length > 0) {
390-
console.log(chalk.red("Minting is not possible - STO is attached to Security Token"));
391-
return;
392-
}
393388

394389
let _investor = readlineSync.question(chalk.yellow(`Enter the address to receive the tokens: `));
395390
let _amount = readlineSync.question(chalk.yellow(`Enter the amount of tokens to mint: `));

CLI/commands/multi_mint.js

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ let badData = new Array();
3535
startScript();
3636

3737
async function startScript() {
38+
if (remoteNetwork == 'undefined') remoteNetwork = undefined;
3839
await global.initialize(remoteNetwork);
3940

4041
try {
@@ -133,6 +134,7 @@ function readFile() {
133134
`);
134135

135136
let affiliatesFailedArray = [];
137+
let affiliatesKYCInvalidArray = [];
136138
//this for loop will do the batches, so it should run 75, 75, 50 with 200
137139
for (let i = 0; i < distribData.length; i++) {
138140
try {
@@ -142,12 +144,20 @@ function readFile() {
142144
for (let j = 0; j < distribData[i].length; j++) {
143145
let investorAccount = distribData[i][j][0];
144146
let tokenAmount = web3.utils.toWei((distribData[i][j][1]).toString(),"ether");
145-
let verifiedTransaction = await securityToken.methods.verifyTransfer("0x0000000000000000000000000000000000000000", investorAccount, tokenAmount, web3.utils.fromAscii("")).call();
147+
let verifiedTransaction = await securityToken.methods.verifyTransfer("0x0000000000000000000000000000000000000000", investorAccount, tokenAmount, web3.utils.fromAscii('')).call();
146148
if (verifiedTransaction) {
147149
affiliatesVerifiedArray.push(investorAccount);
148150
tokensVerifiedArray.push(tokenAmount);
149151
} else {
150-
affiliatesFailedArray.push(investorAccount);
152+
let gtmModule = await securityToken.methods.getModulesByName(web3.utils.toHex('GeneralTransferManager')).call();
153+
let generalTransferManagerABI = abis.generalTransferManager();
154+
let generalTransferManager = new web3.eth.Contract(generalTransferManagerABI, gtmModule[0]);
155+
let validKYC = (await generalTransferManager.methods.whitelist(Issuer.address).call()).expiryTime > Math.floor(Date.now()/1000);
156+
if (validKYC) {
157+
affiliatesFailedArray.push(investorAccount);
158+
} else {
159+
affiliatesKYCInvalidArray.push(investorAccount);
160+
}
151161
}
152162
}
153163
let mintMultiAction = securityToken.methods.mintMulti(affiliatesVerifiedArray, tokensVerifiedArray);
@@ -213,9 +223,10 @@ function readFile() {
213223

214224
console.log(`******************** EVENT LOGS ANALYSIS COMPLETE ********************\n`);
215225
console.log(`A total of ${totalInvestors} affiliated investors get the token\n`);
216-
console.log(`This script in total sent ${fullFileData.length - badData.length - affiliatesFailedArray.length} new investors and updated investors to the blockchain.\n`);
226+
console.log(`This script in total sent ${fullFileData.length - badData.length - affiliatesFailedArray.length - affiliatesKYCInvalidArray.length} new investors and updated investors to the blockchain.\n`);
217227
console.log(`There were ${badData.length} bad entries that didnt get sent to the blockchain in the script.\n`);
218-
console.log(`There were ${affiliatesFailedArray.length} accounts that didnt get sent to the blockchain as they would fail.\n`);
228+
console.log(`There were ${affiliatesKYCInvalidArray.length} accounts with invalid KYC.\n`);
229+
console.log(`There were ${affiliatesFailedArray.length} accounts that didn't get sent to the blockchain as they would fail.\n`);
219230

220231
console.log("************************************************************************************************");
221232
console.log("OBJECT WITH EVERY USER AND THEIR MINTED TOKEN: \n\n", investorObjectLookup)
@@ -224,27 +235,36 @@ function readFile() {
224235

225236
let missingDistribs = [];
226237
let failedVerificationDistribs = [];
238+
let invalidKYCDistribs = [];
227239
for (let l = 0; l < fullFileData.length; l++) {
228-
if (affiliatesFailedArray.includes(fullFileData[l][0])) {
240+
if (affiliatesKYCInvalidArray.includes(fullFileData[l][0])) {
241+
invalidKYCDistribs.push(fullFileData[l]);
242+
} else if (affiliatesFailedArray.includes(fullFileData[l][0])) {
229243
failedVerificationDistribs.push(fullFileData[l]);
230244
} else if (!investorObjectLookup.hasOwnProperty(fullFileData[l][0])) {
231245
missingDistribs.push(fullFileData[l]);
232246
}
233247
}
234248

249+
if (invalidKYCDistribs.length > 0) {
250+
console.log("**************************************************************************************************************************");
251+
console.log("The following data arrays have an invalid KYC. Please review if these accounts are whitelisted and their KYC is not expired\n");
252+
console.log(invalidKYCDistribs);
253+
console.log("**************************************************************************************************************************");
254+
}
235255
if (failedVerificationDistribs.length > 0) {
236-
console.log("************************************************************************************************");
256+
console.log("*********************************************************************************************************");
237257
console.log("-- The following data arrays failed at verifyTransfer. Please review if these accounts are whitelisted --\n");
238258
console.log(failedVerificationDistribs);
239-
console.log("************************************************************************************************");
259+
console.log("*********************************************************************************************************");
240260
}
241261
if (missingDistribs.length > 0) {
242-
console.log("************************************************************************************************");
243-
console.log("-- No Minted event was found for the following data arrays. Please review them manually --");
262+
console.log("******************************************************************************************");
263+
console.log("-- No Minted event was found for the following data arrays. Please review them manually --\n");
244264
console.log(missingDistribs);
245-
console.log("************************************************************************************************");
265+
console.log("******************************************************************************************");
246266
}
247-
if (missingDistribs.length == 0 && failedVerificationDistribs.length == 0) {
267+
if (missingDistribs.length == 0 && failedVerificationDistribs.length == 0 && invalidKYCDistribs.length == 0) {
248268
console.log("\n**************************************************************************************************************************");
249269
console.log("All accounts passed through from the CSV were successfully get the tokens, because we were able to read them all from events");
250270
console.log("****************************************************************************************************************************");

CLI/commands/scripts/script.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
if [ $1 = "Whitelist" ];
44
then
55
echo "Running the $1 script";
6-
node $PWD/CLI/commands/whitelist.js $2 $3
6+
node $PWD/CLI/commands/whitelist.js $2 $3 $4
77
elif [ $1 = "Multimint" ];
88
then
99
echo "Running the $1 script";
10-
node $PWD/CLI/commands/multi_mint.js $2 $3
10+
node $PWD/CLI/commands/multi_mint.js $2 $3 $4
1111
elif [ $1 = "Accredit" ];
1212
then
1313
echo "Running the $1 script";
14-
node $PWD/CLI/commands/accredit.js $2 $3
14+
node $PWD/CLI/commands/accredit.js $2 $3 $4
1515
elif [ $1 = "NonAccreditedLimit" ];
1616
then
1717
echo "Running the $1 script";
18-
node $PWD/CLI/commands/changeNonAccreditedLimit.js $2 $3
18+
node $PWD/CLI/commands/changeNonAccreditedLimit.js $2 $3 $4
1919
fi

CLI/commands/whitelist.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
3232
startScript();
3333

3434
async function startScript() {
35+
if (remoteNetwork == 'undefined') remoteNetwork = undefined;
3536
await global.initialize(remoteNetwork);
3637

3738
try {

CLI/polymath-cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ program
9191
.alias('w')
9292
.description('Mass-update a whitelist of allowed/known investors')
9393
.action(async function(tokenSymbol, batchSize) {
94-
shell.exec(`${__dirname}/commands/scripts/script.sh Whitelist ${tokenSymbol} ${batchSize} ${remoteNetwork} ${program.remoteNode}`);
94+
shell.exec(`${__dirname}/commands/scripts/script.sh Whitelist ${tokenSymbol} ${batchSize} ${program.remoteNode}`);
9595
});
9696

9797
program

0 commit comments

Comments
 (0)