Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions CLI/commands/ST20Generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ var readlineSync = require('readline-sync');
var BigNumber = require('bignumber.js');
var moment = require('moment');
var chalk = require('chalk');
const shell = require('shelljs');
var contracts = require('./helpers/contract_addresses');
var abis = require('./helpers/contract_abis');
var common = require('./common/common_functions');
var gbl = require('./common/global');
var whitelist = require('./whitelist');
var multi_mint = require('./multi_mint');
var accredit = require('./accredit');
var changeNonAccreditedLimit = require('./changeNonAccreditedLimit');

let securityTokenRegistryAddress;

Expand Down Expand Up @@ -241,12 +244,11 @@ async function step_Wallet_Issuance(){
}

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

shell.exec(`${__dirname}/scripts//script.sh Multimint ${tokenSymbol} 75 ${remoteNetwork}`);
await multi_mint.executeApp(tokenSymbol, 75);
console.log(chalk.green(`\nHurray!! Tokens get successfully Minted and transferred to token holders`));
}

Expand Down Expand Up @@ -1003,7 +1005,7 @@ async function usdTieredSTO_configure() {
await common.sendTransaction(changeAccreditedAction);
break;
case 2:
shell.exec(`${__dirname}/scripts/script.sh Accredit ${tokenSymbol} 75 ${remoteNetwork}`);
await accredit.executeApp(tokenSymbol, 75);
break;
case 3:
let account = readlineSync.question('Enter the address to change non accredited limit: ');
Expand All @@ -1015,7 +1017,7 @@ async function usdTieredSTO_configure() {
await common.sendTransaction(changeNonAccreditedLimitAction);
break;
case 4:
shell.exec(`${__dirname}/scripts/script.sh NonAccreditedLimit ${tokenSymbol} 75 ${remoteNetwork}`);
await changeNonAccreditedLimit.executeApp(tokenSymbol, 75);
break;
case 5:
await modfifyTimes();
Expand Down
177 changes: 61 additions & 116 deletions CLI/commands/accredit.js
Original file line number Diff line number Diff line change
@@ -1,149 +1,94 @@
var fs = require('fs');
var csv = require('fast-csv');
var BigNumber = require('bignumber.js');
var chalk = require('chalk');
var common = require('./common/common_functions');
var global = require('./common/global');
var contracts = require('./helpers/contract_addresses');
var abis = require('./helpers/contract_abis')

/////////////////////////////ARTIFACTS//////////////////////////////////////////
let securityTokenRegistry;
let securityToken;
let usdTieredSTO;

////////////////////////////USER INPUTS//////////////////////////////////////////
let tokenSymbol = process.argv.slice(2)[0]; //token symbol
let BATCH_SIZE = process.argv.slice(2)[1]; //batch size
if (!BATCH_SIZE) BATCH_SIZE = 75;
let remoteNetwork = process.argv.slice(2)[2];
var csv_shared = require('./common/csv_shared');
var abis = require('./helpers/contract_abis');
var BigNumber = require('bignumber.js');

/////////////////////////GLOBAL VARS//////////////////////////////////////////
//distribData is an array of batches. i.e. if there are 200 entries, with batch sizes of 75, we get [[75],[75],[50]]
let distribData = new Array();
//allocData is a temporary array that stores up to the batch size,
//then gets push into distribData, then gets set to 0 to start another batch
let allocData = new Array();
//full file data is a single array that contains all arrays. i.e. if there are 200 entries we get [[200]]
let fullFileData = new Array();
//baa data is an array that contains invalid entries
let badData = new Array();

//////////////////////////////////////////ENTRY INTO SCRIPT//////////////////////////////////////////
startScript();

async function startScript() {
if (remoteNetwork == 'undefined') remoteNetwork = undefined;
await global.initialize(remoteNetwork);

try {
let securityTokenRegistryAddress = await contracts.securityTokenRegistry();
let securityTokenRegistryABI = abis.securityTokenRegistry();
securityTokenRegistry = new web3.eth.Contract(securityTokenRegistryABI, securityTokenRegistryAddress);
securityTokenRegistry.setProvider(web3.currentProvider);
console.log("Processing investor CSV upload. Batch size is " + BATCH_SIZE + " accounts per transaction");
readFile();
} 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.");
return;
}
}
let securityToken;

///////////////////////////FUNCTION READING THE CSV FILE
function readFile() {
var stream = fs.createReadStream("./CLI/data/accredited_data.csv");
async function startScript(tokenSymbol, batchSize) {
securityToken = await csv_shared.start(tokenSymbol, batchSize);

let index = 0;
console.log(`
--------------------------------------------
----------- Parsing the csv file -----------
--------------------------------------------
`);
let result_processing = await csv_shared.read('./CLI/data/accredited_data.csv', accredit_processing);
distribData = result_processing.distribData;
fullFileData = result_processing.fullFileData;
badData = result_processing.badData;

await saveInBlockchain();
};

var csvStream = csv()
.on("data", function (data) {
let isAddress = web3.utils.isAddress(data[0]);
let isAccredited = (typeof JSON.parse(data[1].toLowerCase())) == "boolean" ? JSON.parse(data[1].toLowerCase()) : "not-valid";
function accredit_processing(csv_line) {
let isAddress = web3.utils.isAddress(csv_line[0]);
let isAccredited = (typeof JSON.parse(csv_line[1].toLowerCase())) == "boolean" ? JSON.parse(csv_line[1].toLowerCase()) : "not-valid";

if (isAddress && (isAccredited != "not-valid") ) {
let userArray = new Array()
let checksummedAddress = web3.utils.toChecksumAddress(data[0]);
if (isAddress &&
(isAccredited != "not-valid")) {
return [true, new Array(web3.utils.toChecksumAddress(csv_line[0]), isAccredited)]
} else {
return [false, new Array(csv_line[0], isAccredited)]
}
}

userArray.push(checksummedAddress)
userArray.push(isAccredited)
async function saveInBlockchain() {
let gtmModules;
try {
gtmModules = await securityToken.methods.getModulesByName(web3.utils.toHex('USDTieredSTO')).call();
} catch (e) {
console.log("Please attach USDTieredSTO module before launch this action.", e)
process.exit(0)
}

allocData.push(userArray);
fullFileData.push(userArray);

index++;
if (index >= BATCH_SIZE) {
distribData.push(allocData);
allocData = [];
index = 0;
}
} else {
let userArray = new Array()
userArray.push(data[0])
userArray.push(isAccredited);
if (!gtmModules.length) {
console.log("Please attach USDTieredSTO module before launch this action.")
process.exit(0)
}

badData.push(userArray);
fullFileData.push(userArray)
}
})
.on("end", function () {
//Add last remainder batch
distribData.push(allocData);
allocData = [];
let usdTieredSTO = new web3.eth.Contract(abis.usdTieredSTO(), gtmModules[0]);

changeAccredited();
});
console.log(`
--------------------------------------------------------
----- Sending accreditation changes to blockchain -----
--------------------------------------------------------
`);

stream.pipe(csvStream);
}
for (let i = 0; i < distribData.length; i++) {
try {

// MAIN FUNCTION COMMUNICATING TO BLOCKCHAIN
async function changeAccredited() {
// Let's check if token has already been deployed, if it has, skip to STO
let tokenDeployedAddress = await securityTokenRegistry.methods.getSecurityTokenAddress(tokenSymbol).call();
if (tokenDeployedAddress != "0x0000000000000000000000000000000000000000") {
let securityTokenABI = abis.securityToken();
securityToken = new web3.eth.Contract(securityTokenABI, tokenDeployedAddress);
let result = await securityToken.methods.getModulesByName(web3.utils.toHex('USDTieredSTO')).call();
if (result.length > 0) {
let usdTieredSTOABI = abis.usdTieredSTO();
usdTieredSTO = new web3.eth.Contract(usdTieredSTOABI, result[0]);
console.log(`
-------------------------------------------------------
----- Sending accreditation changes to blockchain -----
-------------------------------------------------------
`);
//this for loop will do the batches, so it should run 75, 75, 50 with 200
// Splitting the user arrays to be organized by input
for (let i = 0; i < distribData.length; i++) {
try {
let investorArray = [];
let isAccreditedArray = [];
let investorArray = [], isAccreditedArray = [];

//splitting the user arrays to be organized by input
for (let j = 0; j < distribData[i].length; j++) {
investorArray.push(distribData[i][j][0])
isAccreditedArray.push(distribData[i][j][1])
}

let changeAccreditedAction = usdTieredSTO.methods.changeAccredited(investorArray, isAccreditedArray);
let r = await common.sendTransaction(changeAccreditedAction);
let changeAccreditedAction = await usdTieredSTO.methods.changeAccredited(investorArray, isAccreditedArray);
let tx = await common.sendTransaction(changeAccreditedAction);
console.log(`Batch ${i} - Attempting to change accredited accounts:\n\n`, investorArray, "\n\n");
console.log("---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------");
console.log("Change accredited transaction was successful.", r.gasUsed, "gas used. Spent:", web3.utils.fromWei(BigNumber(r.gasUsed * defaultGasPrice).toString(), "ether"), "Ether");
console.log("Change accredited transaction was successful.", tx.gasUsed, "gas used. Spent:", web3.utils.fromWei(BigNumber(tx.gasUsed * defaultGasPrice).toString(), "ether"), "Ether");
console.log("---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------\n\n");
} catch (err) {
console.log("ERROR:", err);
}
}
} else {
console.log(chalk.red(`There is no USDTieredSTO module attached to the ${tokenSymbol.toUpperCase()} Token. No further actions can be taken.`));
}
} else {
console.log(chalk.red(`Token symbol provided is not a registered Security Token.`));

} catch (err) {
console.log("ERROR", err)
process.exit(0)
}
}

return;
}

module.exports = {
executeApp: async (tokenSymbol, batchSize) => {
return startScript(tokenSymbol, batchSize);
}
}
Loading