forked from PolymathNetwork/polymath-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from PolymathNetwork/development-1.5.0
Development 1.5.0
- Loading branch information
Showing
83 changed files
with
4,720 additions
and
2,882 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
const duration = { | ||
seconds: function (val) { return val; }, | ||
minutes: function (val) { return val * this.seconds(60); }, | ||
hours: function (val) { return val * this.minutes(60); }, | ||
days: function (val) { return val * this.hours(24); }, | ||
weeks: function (val) { return val * this.days(7); }, | ||
years: function (val) { return val * this.days(365); }, | ||
}; | ||
var readlineSync = require('readline-sync'); | ||
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'); | ||
|
||
const OWNER_KEY = 'owner'; | ||
const REG_FEE_KEY = 'tickerRegFee'; | ||
const LAUNCH_FEE_KEY = 'stLaunchFee'; | ||
const EXPIRY_LIMIT_KEY = 'expiryLimit'; | ||
|
||
// App flow | ||
let currentContract = null; | ||
|
||
async function executeApp(remoteNetwork) { | ||
await global.initialize(remoteNetwork); | ||
|
||
common.logAsciiBull(); | ||
console.log("*********************************************"); | ||
console.log("Welcome to the Command-Line Contract Manager."); | ||
console.log("*********************************************"); | ||
console.log("Issuer Account: " + Issuer.address + "\n"); | ||
|
||
//await setup(); | ||
try { | ||
await selectContract(); | ||
} catch (err) { | ||
console.log(err); | ||
return; | ||
} | ||
}; | ||
|
||
async function selectContract() { | ||
console.log('\n\x1b[34m%s\x1b[0m',"Contract Manager - Contract selection"); | ||
let contractList = ['PolymathRegistry', 'FeatureRegistry', 'SecurityTokenRegistry', 'ModuleRegistry']; | ||
|
||
while (!currentContract) { | ||
let index = readlineSync.keyInSelect(contractList, `Select a contract: `); | ||
let selected = index == -1 ? 'CANCEL' : contractList[index]; | ||
switch (selected) { | ||
case 'PolymathRegistry': | ||
console.log(chalk.red(` | ||
********************************* | ||
This option is not yet available. | ||
*********************************`)); | ||
break; | ||
case 'FeatureRegistry': | ||
console.log(chalk.red(` | ||
********************************* | ||
This option is not yet available. | ||
*********************************`)); | ||
break; | ||
case 'SecurityTokenRegistry': | ||
let strAdress = await contracts.securityTokenRegistry(); | ||
let strABI = abis.securityTokenRegistry(); | ||
currentContract = new web3.eth.Contract(strABI, strAdress); | ||
await strActions(); | ||
break; | ||
case 'ModuleRegistry': | ||
console.log(chalk.red(` | ||
********************************* | ||
This option is not yet available. | ||
*********************************`)); | ||
break; | ||
case 'CANCEL': | ||
process.exit(0); | ||
} | ||
} | ||
} | ||
|
||
async function strActions() { | ||
console.log('\n\x1b[34m%s\x1b[0m',"Security Token Registry - Main menu"); | ||
let contractOwner = await currentContract.methods.getAddressValues(web3.utils.soliditySha3(OWNER_KEY)).call(); | ||
|
||
if (contractOwner != Issuer.address) { | ||
console.log(chalk.red(`You are not the owner of this contract. Current owner is ${contractOwner}`)); | ||
currentContract = null; | ||
} else { | ||
let actions = ['Modify Ticker', 'Remove Ticker', 'Modify SecurityToken', 'Change Expiry Limit', 'Change registration fee', 'Change ST launch fee']; | ||
let index = readlineSync.keyInSelect(actions, 'What do you want to do? '); | ||
let selected = index == -1 ? 'CANCEL' : actions[index]; | ||
switch (selected) { | ||
case 'Modify Ticker': | ||
let tickerToModify = readlineSync.question('Enter the token symbol that you want to add or modify: '); | ||
let tickerToModifyDetails = await currentContract.methods.getTickerDetails(tickerToModify).call(); | ||
if (tickerToModifyDetails[1] == 0) { | ||
console.log(chalk.yellow(`${ticker} is not registered.`)); | ||
} else { | ||
console.log(`\n-- Current Ticker details --`); | ||
console.log(` Owner: ${tickerToModifyDetails[0]}`); | ||
console.log(` Registration date: ${tickerToModifyDetails[1]}`); | ||
console.log(` Expiry date: ${tickerToModifyDetails[2]}`); | ||
console.log(` Token name: ${tickerToModifyDetails[3]}`); | ||
console.log(` Status: ${tickerToModifyDetails[4] ? 'Deployed' : 'Not deployed'}\n`); | ||
} | ||
let tickerOwner = readlineSync.question(`Enter the token owner: `, { | ||
limit: function(input) { | ||
return web3.utils.isAddress(input); | ||
}, | ||
limitMessage: "Must be a valid address" | ||
}); | ||
let tickerSTName = readlineSync.question(`Enter the token name: `); | ||
let tickerRegistrationDate = readlineSync.question(`Enter the Unix Epoch time on which ticker get registered: `); | ||
let tickerExpiryDate = readlineSync.question(`Enter the Unix Epoch time on wich the ticker will expire: `); | ||
let tickerStatus = readlineSync.keyInYNStrict(`Is the token deployed?`); | ||
let modifyTickerAction = currentContract.methods.modifyTicker(tickerOwner, tickerToModify, tickerSTName, tickerRegistrationDate, tickerExpiryDate, tickerStatus); | ||
await common.sendTransaction(Issuer, modifyTickerAction, defaultGasPrice, 0, 1.5); | ||
console.log(chalk.green(`Ticker has been updated successfuly`)); | ||
break; | ||
case 'Remove Ticker': | ||
let tickerToRemove = readlineSync.question('Enter the token symbol that you want to add or modify: '); | ||
let tickerToRemoveDetails = await currentContract.methods.getTickerDetails(tickerToRemove).call(); | ||
if (tickerToRemoveDetails[1] == 0) { | ||
console.log(chalk.yellow(`${ticker} does not exist.`)); | ||
} else { | ||
let removeTickerAction = currentContract.methods.removeTicker(tickerToRemove); | ||
await common.sendTransaction(Issuer, removeTickerAction, defaultGasPrice, 0, 3); | ||
console.log(chalk.green(`Ticker has been removed successfuly`)); | ||
} | ||
break; | ||
case 'Modify SecurityToken': | ||
let stAddress = readlineSync.question('Enter the security token address that you want to add or modify: ', { | ||
limit: function(input) { | ||
return web3.utils.isAddress(input); | ||
}, | ||
limitMessage: "Must be a valid address" | ||
}); | ||
let ticker; | ||
let stData = await currentContract.methods.getSecurityTokenData(stAddress).call(); | ||
if (stData[1] == '0x0000000000000000000000000000000000000000') { | ||
console.log(chalk.yellow(`Currently there are no security token registered at ${stAddress}`)); | ||
ticker = readlineSync.question('Enter the token symbol that you want to register: '); | ||
} else { | ||
ticker = stData[0]; | ||
console.log(`\n-- Current Security Token data --`); | ||
console.log(` Ticker: ${stData[0]}`); | ||
console.log(` Token details: ${stData[2]}`); | ||
console.log(` Deployed at: ${stData[3]}`); | ||
} | ||
let tickerDetails = await currentContract.methods.getTickerDetails(ticker).call(); | ||
if (tickerDetails[1] == 0) { | ||
console.log(chalk.yellow(`${ticker} is not registered.`)); | ||
} else { | ||
console.log(`-- Current Ticker details --`); | ||
console.log(` Owner: ${tickerDetails[0]}`); | ||
console.log(` Token name: ${tickerDetails[3]}\n`); | ||
} | ||
let name = readlineSync.question(`Enter the token name: `); | ||
let owner = readlineSync.question(`Enter the token owner: `, { | ||
limit: function(input) { | ||
return web3.utils.isAddress(input); | ||
}, | ||
limitMessage: "Must be a valid address" | ||
}); | ||
let tokenDetails = readlineSync.question(`Enter the token details: `); | ||
let deployedAt = readlineSync.questionInt(`Enter the Unix Epoch timestamp at which security token was deployed: `); | ||
let modifySTAction = currentContract.methods.modifySecurityToken(name, ticker, owner, stAddress, tokenDetails, deployedAt); | ||
await common.sendTransaction(Issuer, modifySTAction, defaultGasPrice, 0, 1.5); | ||
console.log(chalk.green(`Security Token has been updated successfuly`)); | ||
break; | ||
case 'Change Expiry Limit': | ||
let currentExpiryLimit = await currentContract.methods.getUintValues(web3.utils.soliditySha3(EXPIRY_LIMIT_KEY)).call(); | ||
console.log(chalk.yellow(`Current expiry limit is ${Math.floor(parseInt(currentExpiryLimit)/60/60/24)} days`)); | ||
let newExpiryLimit = duration.days(readlineSync.questionInt('Enter a new value in days for expiry limit: ')); | ||
let changeExpiryLimitAction = currentContract.methods.changeExpiryLimit(newExpiryLimit); | ||
let changeExpiryLimitReceipt = await common.sendTransaction(Issuer, changeExpiryLimitAction, defaultGasPrice); | ||
let changeExpiryLimitEvent = common.getEventFromLogs(currentContract._jsonInterface, changeExpiryLimitReceipt.logs, 'LogChangeExpiryLimit'); | ||
console.log(chalk.green(`Expiry limit was changed successfuly. New limit is ${Math.floor(parseInt(changeExpiryLimitEvent._newExpiry)/60/60/24)} days\n`)); | ||
break; | ||
case 'Change registration fee': | ||
let currentRegFee = web3.utils.fromWei(await currentContract.methods.getUintValues(web3.utils.soliditySha3(REG_FEE_KEY)).call()); | ||
console.log(chalk.yellow(`\nCurrent ticker registration fee is ${currentRegFee} POLY`)); | ||
let newRegFee = web3.utils.toWei(readlineSync.questionInt('Enter a new value in POLY for ticker registration fee: ').toString()); | ||
let changeRegFeeAction = currentContract.methods.changeTickerRegistrationFee(newRegFee); | ||
let changeRegFeeReceipt = await common.sendTransaction(Issuer, changeRegFeeAction, defaultGasPrice); | ||
let changeRegFeeEvent = common.getEventFromLogs(currentContract._jsonInterface, changeRegFeeReceipt.logs, 'LogChangeTickerRegistrationFee'); | ||
console.log(chalk.green(`Fee was changed successfuly. New fee is ${web3.utils.fromWei(changeRegFeeEvent._newFee)} POLY\n`)); | ||
break; | ||
case 'Change ST launch fee': | ||
let currentLaunchFee = web3.utils.fromWei(await currentContract.methods.getUintValues(web3.utils.soliditySha3(LAUNCH_FEE_KEY)).call()); | ||
console.log(chalk.yellow(`\nCurrent ST launch fee is ${currentLaunchFee} POLY`)); | ||
let newLaunchFee = web3.utils.toWei(readlineSync.questionInt('Enter a new value in POLY for ST launch fee: ').toString()); | ||
let changeLaunchFeeAction = currentContract.methods.changeSecurityLaunchFee(newLaunchFee); | ||
let changeLaunchFeeReceipt = await common.sendTransaction(Issuer, changeLaunchFeeAction, defaultGasPrice); | ||
let changeLaunchFeeEvent = common.getEventFromLogs(currentContract._jsonInterface, changeLaunchFeeReceipt.logs, 'LogChangeSecurityLaunchFee'); | ||
console.log(chalk.green(`Fee was changed successfuly. New fee is ${web3.utils.fromWei(changeLaunchFeeEvent._newFee)} POLY\n`)); | ||
break; | ||
case 'CANCEL': | ||
process.exit(0); | ||
} | ||
} | ||
currentContract = null; | ||
} | ||
|
||
module.exports = { | ||
executeApp: async function(remoteNetwork) { | ||
return executeApp(remoteNetwork); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.