Skip to content

Commit

Permalink
Merge branch 'development-1.5.0' into singleTradeVolumeRestriction
Browse files Browse the repository at this point in the history
  • Loading branch information
subramanianv authored Oct 2, 2018
2 parents 6b328dc + c06beaa commit 6457008
Show file tree
Hide file tree
Showing 43 changed files with 1,719 additions and 1,501 deletions.
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ 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 `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 +25,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
62 changes: 29 additions & 33 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, 'ChangeTickerOwnership');
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 Down Expand Up @@ -195,7 +189,7 @@ async function step_token_deploy(){
}

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,6 +436,7 @@ 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, 'ModuleAdded');
Expand Down Expand Up @@ -826,6 +821,7 @@ 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, 'ModuleAdded');
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
15 changes: 5 additions & 10 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,7 +163,7 @@ 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);
Expand All @@ -177,7 +172,7 @@ async function strActions() {
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);
Expand All @@ -186,7 +181,7 @@ async function strActions() {
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);
Expand Down
32 changes: 16 additions & 16 deletions CLI/commands/dividends_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ var global = require('./common/global');
var contracts = require('./helpers/contract_addresses');
var abis = require('./helpers/contract_abis');

const STO_KEY = 3;
const MODULES_TYPES = {
PERMISSION: 1,
TRANSFER: 2,
STO: 3,
DIVIDENDS: 4
}

// App flow
let tokenSymbol;
Expand Down Expand Up @@ -188,7 +193,7 @@ async function mintTokens(address, amount){
if (await securityToken.methods.mintingFrozen().call()) {
console.log(chalk.red("Minting is not possible - Minting has been permanently frozen by issuer"));
} else {
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(chalk.red("Minting is not possible - STO is attached to Security Token"));
} else {
Expand Down Expand Up @@ -466,16 +471,17 @@ async function isDividendsModuleAttached() {

async function addDividendsModule() {
if (!(await isDividendsModuleAttached())) {
let dividendsFactoryAddress;
let dividendsFactoryName;
let dividendsModuleABI;
if (dividendsType == 'POLY') {
dividendsFactoryAddress = await contracts.erc20DividendCheckpointFactoryAddress();
dividendsFactoryName = 'ERC20DividendCheckpoint';
dividendsModuleABI = abis.erc20DividendCheckpoint();
} else if (dividendsType == 'ETH') {
dividendsFactoryAddress = await contracts.etherDividendCheckpointFactoryAddress();
dividendsFactoryName = 'EtherDividendCheckpoint';
dividendsModuleABI = abis.etherDividendCheckpoint();
}

let dividendsFactoryAddress = await contracts.getModuleFactoryAddressByName(securityToken.options.address, MODULES_TYPES.DIVIDENDS, dividendsFactoryName);
let addModuleAction = securityToken.methods.addModule(dividendsFactoryAddress, web3.utils.fromAscii('', 16), 0, 0);
let receipt = await common.sendTransaction(Issuer, addModuleAction, defaultGasPrice);
let event = common.getEventFromLogs(securityToken._jsonInterface, receipt.logs, 'ModuleAdded');
Expand All @@ -500,18 +506,12 @@ async function selectCheckpoint(includeCreate) {

async function getCheckpoints() {
let result = [];
/*
let currentCheckpoint = await securityToken.methods.currentCheckpointId().call();
for (let index = 1; index <= currentCheckpoint; index++) {
result.push(checkpoint(index).call());
}
*/

let events = await securityToken.getPastEvents('CheckpointCreated', { fromBlock: 0});
for (let event of events) {

let checkPointsTimestamps = await securityToken.methods.getCheckpointTimes().call();
for (let index = 0; index < checkPointsTimestamps.length; index++) {
let checkpoint = {};
checkpoint.id = event.returnValues._checkpointId;
checkpoint.timestamp = moment.unix(event.returnValues._timestamp).format('MMMM Do YYYY, HH:mm:ss');
checkpoint.id = index + 1;
checkpoint.timestamp = moment.unix(checkPointsTimestamps[index]).format('MMMM Do YYYY, HH:mm:ss');
result.push(checkpoint);
}

Expand Down
16 changes: 13 additions & 3 deletions CLI/commands/helpers/contract_abis.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
let polymathRegistryABI;
let securityTokenRegistryABI;
let featureRegistryABI;
let moduleRegistryABI;
let securityTokenABI;
let stoInterfaceABI;
let cappedSTOABI;
Expand All @@ -11,12 +12,14 @@ let cappedSTOFactoryABI;
let usdTieredSTOFactoryABI;
let erc20DividendCheckpointABI;
let etherDividendCheckpointABI;
let ownable;
let ownableABI;
let moduleFactoryABI;

try {
polymathRegistryABI = JSON.parse(require('fs').readFileSync('./build/contracts/PolymathRegistry.json').toString()).abi;
securityTokenRegistryABI = JSON.parse(require('fs').readFileSync('./build/contracts/SecurityTokenRegistry.json').toString()).abi;
featureRegistryABI = JSON.parse(require('fs').readFileSync('./build/contracts/FeatureRegistry.json').toString()).abi;
moduleRegistryABI = JSON.parse(require('fs').readFileSync('./build/contracts/ModuleRegistry.json').toString()).abi;
securityTokenABI = JSON.parse(require('fs').readFileSync('./build/contracts/SecurityToken.json').toString()).abi;
stoInterfaceABI = JSON.parse(require('fs').readFileSync('./build/contracts/ISTO.json').toString()).abi;
cappedSTOABI = JSON.parse(require('fs').readFileSync('./build/contracts/CappedSTO.json').toString()).abi;
Expand All @@ -27,7 +30,8 @@ try {
usdTieredSTOFactoryABI = JSON.parse(require('fs').readFileSync('./build/contracts/USDTieredSTOFactory.json').toString()).abi;
erc20DividendCheckpointABI = JSON.parse(require('fs').readFileSync('./build/contracts/ERC20DividendCheckpoint.json').toString()).abi;
etherDividendCheckpointABI = JSON.parse(require('fs').readFileSync('./build/contracts/EtherDividendCheckpoint.json').toString()).abi;
ownable = JSON.parse(require('fs').readFileSync('./build/contracts/Ownable.json').toString()).abi;
ownableABI = JSON.parse(require('fs').readFileSync('./build/contracts/Ownable.json').toString()).abi;
moduleFactoryABI = JSON.parse(require('fs').readFileSync('./build/contracts/ModuleFactory.json').toString()).abi;
} catch (err) {
console.log('\x1b[31m%s\x1b[0m',"Couldn't find contracts' artifacts. Make sure you ran truffle compile first");
return;
Expand All @@ -43,6 +47,9 @@ module.exports = {
featureRegistry: function () {
return featureRegistryABI;
},
moduleRegistry: function () {
return moduleRegistryABI;
},
securityToken: function () {
return securityTokenABI;
},
Expand Down Expand Up @@ -74,6 +81,9 @@ module.exports = {
return etherDividendCheckpointABI;
},
ownable: function () {
return ownable;
return ownableABI;
},
moduleFactory: function () {
return moduleFactoryABI;
}
}
Loading

0 comments on commit 6457008

Please sign in to comment.