Skip to content

Commit

Permalink
Merge pull request #5 from PolymathNetwork/development-1.5.0
Browse files Browse the repository at this point in the history
Development 1.5.0
  • Loading branch information
glitch003 authored Oct 4, 2018
2 parents 6421e09 + af9ae8c commit 3904fa9
Show file tree
Hide file tree
Showing 60 changed files with 2,902 additions and 2,392 deletions.
2 changes: 1 addition & 1 deletion .solcover.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
norpc: true,
port: 8545,
copyPackages: ['openzeppelin-solidity'],
testCommand: 'node ../node_modules/.bin/truffle test `find test/*.js ! -name a_poly_oracle.js` --network coverage',
testCommand: 'node ../node_modules/.bin/truffle test `find test/*.js ! -name a_poly_oracle.js -and ! -name s_v130_to_v140_upgrade.js` --network coverage',
deepSkip: true,
skipFiles: ['external', 'flat']
};
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ All notable changes to this project will be documented in this file.
[__1.5.0__](https://www.npmjs.com/package/polymath-core?activeTab=readme) __15-08-18__

## Added
* Added `name` field to dividends struct in DividendCheckpoint. #295
* Added `getTagsByType`, `getTagsByTypeAndToken`, `getModulesByType`, `getModulesByTypeAndToken` to MR
* Added `getTokensByOwner` to STR
* Added withholding tax to ether & erc20 dividends
* Generalised MakerDAO oracle to allow different instances referencing different currencies
Expand All @@ -24,10 +26,11 @@ All notable changes to this project will be documented in this file.
## Fixed
* Generalize the STO varaible names and added them in `ISTO.sol` to use the common standard in all STOs.
* Generalize the event when any new token get registered with the polymath ecosystem. `LogNewSecurityToken` should emit _ticker, _name, _securityTokenAddress, _owner, _addedAt, _registrant respectively. #230
## Removed

## Removed
* Remove `swarmHash` from the `registerTicker(), addCustomTicker(), generateSecurityToken(), addCustomSecurityToken()` functions of TickerRegistry.sol and SecurityTokenRegistry.sol. #230
* Remove `Log` prefix from all the event present in the ecosystem.
* Remove `Log` prefix from all the event present in the ecosystem.
* Removed `addTagByModuleType` & `removeTagsByModuleType` from MR.

======

Expand Down
68 changes: 32 additions & 36 deletions CLI/commands/ST20Generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@ var common = require('./common/common_functions');
var global = require('./common/global');

let securityTokenRegistryAddress;
let cappedSTOFactoryAddress;
let usdTieredSTOFactoryAddress;

///////////////////
// Crowdsale params
let tokenName;
let tokenSymbol;
let selectedSTO;

const STO_KEY = 3;
const REG_FEE_KEY = 'tickerRegFee';
const LAUNCH_FEE_KEY = 'stLaunchFee';
const MODULES_TYPES = {
PERMISSION: 1,
TRANSFER: 2,
STO: 3,
DIVIDENDS: 4
}

const cappedSTOFee = 20000;
const usdTieredSTOFee = 100000;
const tokenDetails = "";
Expand All @@ -37,8 +39,6 @@ let usdToken;
let securityToken;
let generalTransferManager;
let currentSTO;
let cappedSTOFactory;
let usdTieredSTOFactory;

// App flow
let _tokenConfig;
Expand Down Expand Up @@ -90,16 +90,6 @@ async function setup(){
let usdTokenAddress = await contracts.usdToken();
usdToken = new web3.eth.Contract(polytokenABI, usdTokenAddress);
usdToken.setProvider(web3.currentProvider);

cappedSTOFactoryAddress = await contracts.cappedSTOFactoryAddress();
let cappedSTOFactoryABI = abis.cappedSTOFactory();
cappedSTOFactory = new web3.eth.Contract(cappedSTOFactoryABI, cappedSTOFactoryAddress);
cappedSTOFactory.setProvider(web3.currentProvider);

usdTieredSTOFactoryAddress = await contracts.usdTieredSTOFactoryAddress();
let usdTieredSTOFactoryABI = abis.usdTieredSTOFactory();
usdTieredSTOFactory = new web3.eth.Contract(usdTieredSTOFactoryABI, usdTieredSTOFactoryAddress);
usdTieredSTOFactory.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 All @@ -111,7 +101,8 @@ async function step_ticker_reg(){
console.log('\n\x1b[34m%s\x1b[0m',"Token Creation - Symbol Registration");

let available = false;
let regFee = web3.utils.fromWei(await securityTokenRegistry.methods.getUintValues(web3.utils.soliditySha3(REG_FEE_KEY)).call());
let regFee = web3.utils.fromWei(await securityTokenRegistry.methods.getTickerRegistrationFee().call());
let isDeployed;

while (!available) {
console.log(chalk.green(`\nRegistering the new token symbol requires ${regFee} POLY & deducted from '${Issuer.address}', Current balance is ${(await currentBalance(Issuer.address))} POLY\n`));
Expand All @@ -123,6 +114,7 @@ async function step_ticker_reg(){
}

let details = await securityTokenRegistry.methods.getTickerDetails(tokenSymbol).call();
isDeployed = details[4];
if (new BigNumber(details[1]).toNumber() == 0) {
available = true;
await approvePoly(securityTokenRegistryAddress, regFee);
Expand All @@ -135,18 +127,20 @@ async function step_ticker_reg(){
}
}

if (typeof _tokenConfig === 'undefined' && readlineSync.keyInYNStrict(`Do you want to transfer the ownership of ${tokenSymbol} ticker?`)) {
let newOwner = readlineSync.question('Enter the address that will be the new owner: ', {
limit: function(input) {
return web3.utils.isAddress(input);
},
limitMessage: "Must be a valid address"
});
let transferTickerOwnershipAction = securityTokenRegistry.methods.transferTickerOwnership(newOwner, tokenSymbol);
let receipt = await common.sendTransaction(Issuer, transferTickerOwnershipAction, defaultGasPrice, 0, 1.5);
let event = common.getEventFromLogs(securityTokenRegistry._jsonInterface, receipt.logs, 'LogChangeTickerOwnership');
console.log(chalk.green(`Ownership trasferred successfully. The new owner is ${event._newOwner}`));
process.exit(0);
if (!isDeployed) {
if (typeof _tokenConfig === 'undefined' && readlineSync.keyInYNStrict(`Do you want to transfer the ownership of ${tokenSymbol} ticker?`)) {
let newOwner = readlineSync.question('Enter the address that will be the new owner: ', {
limit: function(input) {
return web3.utils.isAddress(input);
},
limitMessage: "Must be a valid address"
});
let transferTickerOwnershipAction = securityTokenRegistry.methods.transferTickerOwnership(newOwner, tokenSymbol);
let receipt = await common.sendTransaction(Issuer, transferTickerOwnershipAction, defaultGasPrice, 0, 1.5);
let event = common.getEventFromLogs(securityTokenRegistry._jsonInterface, receipt.logs, 'ChangeTickerOwnership');
console.log(chalk.green(`Ownership trasferred successfully. The new owner is ${event._newOwner}`));
process.exit(0);
}
}
}

Expand All @@ -160,7 +154,7 @@ async function step_token_deploy(){
} else {
console.log('\n\x1b[34m%s\x1b[0m',"Token Creation - Token Deployment");

let launchFee = web3.utils.fromWei(await securityTokenRegistry.methods.getUintValues(web3.utils.soliditySha3(LAUNCH_FEE_KEY)).call());
let launchFee = web3.utils.fromWei(await securityTokenRegistry.methods.getSecurityTokenLaunchFee().call());
console.log(chalk.green(`\nToken deployment requires ${launchFee} POLY & deducted from '${Issuer.address}', Current balance is ${(await currentBalance(Issuer.address))} POLY\n`));

if (typeof _tokenConfig !== 'undefined' && _tokenConfig.hasOwnProperty('name')) {
Expand All @@ -187,15 +181,15 @@ async function step_token_deploy(){
await approvePoly(securityTokenRegistryAddress, launchFee);
let generateSecurityTokenAction = securityTokenRegistry.methods.generateSecurityToken(tokenName, tokenSymbol, tokenDetails, divisibility);
let receipt = await common.sendTransaction(Issuer, generateSecurityTokenAction, defaultGasPrice);
let event = common.getEventFromLogs(securityTokenRegistry._jsonInterface, receipt.logs, 'LogNewSecurityToken');
let event = common.getEventFromLogs(securityTokenRegistry._jsonInterface, receipt.logs, 'NewSecurityToken');
console.log(`Deployed Token at address: ${event._securityTokenAddress}`);
let securityTokenABI = abis.securityToken();
securityToken = new web3.eth.Contract(securityTokenABI, event._securityTokenAddress);
}
}

async function step_Wallet_Issuance(){
let result = await securityToken.methods.getModulesByType(STO_KEY).call();
let result = await securityToken.methods.getModulesByType(MODULES_TYPES.STO).call();
if (result.length > 0) {
console.log('\x1b[32m%s\x1b[0m',"STO has already been created at address " + result[0] + ". Skipping initial minting");
} else {
Expand Down Expand Up @@ -275,7 +269,7 @@ async function step_STO_launch() {
console.log("\n");
console.log('\x1b[34m%s\x1b[0m',"Token Creation - STO Configuration");

let result = await securityToken.methods.getModulesByType(STO_KEY).call();
let result = await securityToken.methods.getModulesByType(MODULES_TYPES.STO).call();
if (result.length > 0) {
STO_Address = result[0];
let stoModuleData = await securityToken.methods.getModule(STO_Address).call();
Expand Down Expand Up @@ -442,9 +436,10 @@ async function cappedSTO_launch() {
]
}, [startTime, endTime, web3.utils.toWei(cap), rate, raiseType, wallet]);

let cappedSTOFactoryAddress = await contracts.getModuleFactoryAddressByName(securityToken.options.address, MODULES_TYPES.STO, "CappedSTO");
let addModuleAction = securityToken.methods.addModule(cappedSTOFactoryAddress, bytesSTO, new BigNumber(stoFee).times(new BigNumber(10).pow(18)), 0);
let receipt = await common.sendTransaction(Issuer, addModuleAction, defaultGasPrice);
let event = common.getEventFromLogs(securityToken._jsonInterface, receipt.logs, 'LogModuleAdded');
let event = common.getEventFromLogs(securityToken._jsonInterface, receipt.logs, 'ModuleAdded');
console.log(`STO deployed at address: ${event._module}`);

STO_Address = event._module;
Expand Down Expand Up @@ -826,9 +821,10 @@ async function usdTieredSTO_launch() {
addresses.usdToken
]);

let usdTieredSTOFactoryAddress = await contracts.getModuleFactoryAddressByName(securityToken.options.address, MODULES_TYPES.STO, 'USDTieredSTO');
let addModuleAction = securityToken.methods.addModule(usdTieredSTOFactoryAddress, bytesSTO, new BigNumber(stoFee).times(new BigNumber(10).pow(18)), 0);
let receipt = await common.sendTransaction(Issuer, addModuleAction, defaultGasPrice);
let event = common.getEventFromLogs(securityToken._jsonInterface, receipt.logs, 'LogModuleAdded');
let event = common.getEventFromLogs(securityToken._jsonInterface, receipt.logs, 'ModuleAdded');
console.log(`STO deployed at address: ${event._module}`);

STO_Address = event._module;
Expand Down
4 changes: 1 addition & 3 deletions CLI/commands/TickerRollForward.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ var abis = require('./helpers/contract_abis');
let remoteNetwork = process.argv.slice(2)[0]; //batch size

///////////////////////// GLOBAL VARS /////////////////////////
const REG_FEE_KEY = 'tickerRegFee';

let ticker_data = [];
let registered_tickers = [];
let failed_tickers = [];
Expand Down Expand Up @@ -80,7 +78,7 @@ async function readFile() {
async function registerTickers() {
// Poly approval for registration fees
let polyBalance = BigNumber(await polyToken.methods.balanceOf(Issuer.address).call());
let fee = web3.utils.fromWei(await securityTokenRegistry.methods.getUintValues(web3.utils.soliditySha3(REG_FEE_KEY)).call());
let fee = web3.utils.fromWei(await securityTokenRegistry.methods.getTickerRegistrationFee().call());
let totalFee = BigNumber(ticker_data.length).mul(fee);

if (totalFee.gt(polyBalance)) {
Expand Down
5 changes: 5 additions & 0 deletions CLI/commands/common/common_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ module.exports = {
sendTransaction: async function (from, action, gasPrice, value, factor) {
if (typeof factor === 'undefined') factor = 1.2;

let block = await web3.eth.getBlock("latest");
let networkGasLimit = block.gasLimit;

let gas = Math.round(factor * (await action.estimateGas({ from: from.address, value: value})));
if (gas > networkGasLimit) gas = networkGasLimit;

console.log(chalk.black.bgYellowBright(`---- Transaction executed: ${action._method.name} - Gas limit provided: ${gas} ----`));

let nonce = await web3.eth.getTransactionCount(from.address);
Expand Down
21 changes: 8 additions & 13 deletions CLI/commands/contract_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ 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;

Expand Down Expand Up @@ -79,7 +74,7 @@ async function selectContract() {

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();
let contractOwner = await currentContract.methods.owner().call();

if (contractOwner != Issuer.address) {
console.log(chalk.red(`You are not the owner of this contract. Current owner is ${contractOwner}`));
Expand Down Expand Up @@ -117,7 +112,7 @@ async function strActions() {
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 tickerToRemove = readlineSync.question('Enter the token symbol that you want to remove: ');
let tickerToRemoveDetails = await currentContract.methods.getTickerDetails(tickerToRemove).call();
if (tickerToRemoveDetails[1] == 0) {
console.log(chalk.yellow(`${ticker} does not exist.`));
Expand Down Expand Up @@ -168,30 +163,30 @@ async function strActions() {
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();
let currentExpiryLimit = await currentContract.methods.getExpiryLimit().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');
let changeExpiryLimitEvent = common.getEventFromLogs(currentContract._jsonInterface, changeExpiryLimitReceipt.logs, 'ChangeExpiryLimit');
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());
let currentRegFee = web3.utils.fromWei(await currentContract.methods.getTickerRegistrationFee().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');
let changeRegFeeEvent = common.getEventFromLogs(currentContract._jsonInterface, changeRegFeeReceipt.logs, 'ChangeTickerRegistrationFee');
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());
let currentLaunchFee = web3.utils.fromWei(await currentContract.methods.getSecurityTokenLaunchFee().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');
let changeLaunchFeeEvent = common.getEventFromLogs(currentContract._jsonInterface, changeLaunchFeeReceipt.logs, 'ChangeSecurityLaunchFee');
console.log(chalk.green(`Fee was changed successfuly. New fee is ${web3.utils.fromWei(changeLaunchFeeEvent._newFee)} POLY\n`));
break;
case 'CANCEL':
Expand Down
Loading

0 comments on commit 3904fa9

Please sign in to comment.