From c0f363037dc0a3ea8c00ee9817dce4d206631d2c Mon Sep 17 00:00:00 2001 From: Adam Dossa Date: Wed, 26 Sep 2018 19:52:42 +0100 Subject: [PATCH 1/6] Add `getDefaultExcluded` --- contracts/modules/Checkpoint/DividendCheckpoint.sol | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/contracts/modules/Checkpoint/DividendCheckpoint.sol b/contracts/modules/Checkpoint/DividendCheckpoint.sol index e427509ab..67948ca02 100644 --- a/contracts/modules/Checkpoint/DividendCheckpoint.sol +++ b/contracts/modules/Checkpoint/DividendCheckpoint.sol @@ -61,6 +61,14 @@ contract DividendCheckpoint is ICheckpoint, Module { return bytes4(0); } + /** + * @notice Return the default excluded addresses + * @return List of excluded addresses + */ + function getDefaultExcluded() external view returns (address[]) { + return excluded; + } + /** * @notice Function to set withholding tax rates for investors * @param _investors addresses of investor @@ -157,7 +165,7 @@ contract DividendCheckpoint is ICheckpoint, Module { * @notice Calculate amount of dividends claimable * @param _dividendIndex Dividend to calculate * @param _payee Affected investor address - * @return unit256 + * @return claim, withheld amounts */ function calculateDividend(uint256 _dividendIndex, address _payee) public view returns(uint256, uint256) { require(_dividendIndex < dividends.length, "Incorrect dividend index"); From 45550bbb2a82906bd8cb433f4acf628ba3c5fcd4 Mon Sep 17 00:00:00 2001 From: Adam Dossa Date: Wed, 26 Sep 2018 22:05:20 +0100 Subject: [PATCH 2/6] Add events for withholding tax and change to setDefaultExcluded --- .../modules/Checkpoint/DividendCheckpoint.sol | 30 +++++++++++-------- test/e_erc20_dividends.js | 4 +-- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/contracts/modules/Checkpoint/DividendCheckpoint.sol b/contracts/modules/Checkpoint/DividendCheckpoint.sol index 67948ca02..d751e02fe 100644 --- a/contracts/modules/Checkpoint/DividendCheckpoint.sol +++ b/contracts/modules/Checkpoint/DividendCheckpoint.sol @@ -43,7 +43,9 @@ contract DividendCheckpoint is ICheckpoint, Module { // Total amount of ETH withheld per investor mapping (address => uint256) public investorWithheld; - event SetExcludedAddresses(address[] _excluded, uint256 _timestamp); + event SetDefaultExcludedAddresses(address[] _excluded, uint256 _timestamp); + event SetWithholding(address[] _investors, uint256[] _withholding, uint256 _timestamp); + event SetWithholdingFixed(address[] _investors, uint256 _withholding, uint256 _timestamp); modifier validDividendIndex(uint256 _dividendIndex) { require(_dividendIndex < dividends.length, "Incorrect dividend index"); @@ -69,6 +71,16 @@ contract DividendCheckpoint is ICheckpoint, Module { return excluded; } + /** + * @notice Function to clear and set list of excluded addresses used for future dividends + * @param _excluded addresses of investor + */ + function setDefaultExcluded(address[] _excluded) public onlyOwner { + require(_excluded.length <= EXCLUDED_ADDRESS_LIMIT, "Too many excluded addresses"); + excluded = _excluded; + emit SetDefaultExcludedAddresses(excluded, now); + } + /** * @notice Function to set withholding tax rates for investors * @param _investors addresses of investor @@ -76,29 +88,21 @@ contract DividendCheckpoint is ICheckpoint, Module { */ function setWithholding(address[] _investors, uint256[] _withholding) public onlyOwner { require(_investors.length == _withholding.length, "Mismatched input lengths"); + emit SetWithholding(_investors, _withholding, now); for (uint256 i = 0; i < _investors.length; i++) { - require(_withholding[i] <= 10**18); + require(_withholding[i] <= 10**18, "Incorrect withholding tax"); withholdingTax[_investors[i]] = _withholding[i]; } } - /** - * @notice Function to clear and set list of excluded addresses used for future dividends - * @param _excluded addresses of investor - */ - function setExcluded(address[] _excluded) public onlyOwner { - require(_excluded.length <= EXCLUDED_ADDRESS_LIMIT, "Too many excluded addresses"); - excluded = _excluded; - emit SetExcludedAddresses(excluded, now); - } - /** * @notice Function to set withholding tax rates for investors * @param _investors addresses of investor * @param _withholding withholding tax for all investors (multiplied by 10**16) */ function setWithholdingFixed(address[] _investors, uint256 _withholding) public onlyOwner { - require(_withholding <= 10**18); + require(_withholding <= 10**18, "Incorrect withholding tax"); + emit SetWithholdingFixed(_investors, _withholding, now); for (uint256 i = 0; i < _investors.length; i++) { withholdingTax[_investors[i]] = _withholding; } diff --git a/test/e_erc20_dividends.js b/test/e_erc20_dividends.js index 4e4812419..52570446a 100644 --- a/test/e_erc20_dividends.js +++ b/test/e_erc20_dividends.js @@ -583,7 +583,7 @@ contract('ERC20DividendCheckpoint', accounts => { }); it("Exclude account_temp using global exclusion list", async() => { - await I_ERC20DividendCheckpoint.setExcluded([account_temp], {from: token_owner}); + await I_ERC20DividendCheckpoint.setDefaultExcluded([account_temp], {from: token_owner}); }); it("Create another new dividend", async() => { @@ -657,7 +657,7 @@ contract('ERC20DividendCheckpoint', accounts => { it("Delete global exclusion list", async() => { - await I_ERC20DividendCheckpoint.setExcluded([], {from: token_owner}); + await I_ERC20DividendCheckpoint.setDefaultExcluded([], {from: token_owner}); }); From 8a0d25b51dd86a1aa461ceddb90d00783174b34e Mon Sep 17 00:00:00 2001 From: Victor Vicente Date: Wed, 26 Sep 2018 09:41:32 -0300 Subject: [PATCH 3/6] CLI: Switch over text menu options instead of indexes. --- CLI/commands/dividends_manager.js | 35 ++++++++++++------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/CLI/commands/dividends_manager.js b/CLI/commands/dividends_manager.js index 0c147545c..a84a15067 100644 --- a/CLI/commands/dividends_manager.js +++ b/CLI/commands/dividends_manager.js @@ -109,54 +109,46 @@ async function start_explorer(){ } let index = readlineSync.keyInSelect(options, 'What do you want to do?'); - console.log('Selected:', index != -1 ? options[index] : 'Cancel', '\n'); - switch (index) { - case 0: - // Mint tokens + let selected = index != -1 ? options[index] : 'Cancel'; + console.log('Selected:', selected, '\n'); + switch (selected) { + case 'Mint tokens': let _to = readlineSync.question('Enter beneficiary of minting: '); let _amount = readlineSync.question('Enter amount of tokens to mint: '); await mintTokens(_to,_amount); break; - case 1: - // Transfer tokens + case 'Transfer tokens': let _to2 = readlineSync.question('Enter beneficiary of tranfer: '); let _amount2 = readlineSync.question('Enter amount of tokens to transfer: '); await transferTokens(_to2,_amount2); break; - case 2: - // Create checkpoint + case 'Create checkpoint': let createCheckpointAction = securityToken.methods.createCheckpoint(); await common.sendTransaction(Issuer, createCheckpointAction, defaultGasPrice); break; - case 3: - // Create Dividends + case 'Create dividends': let dividend = readlineSync.question(`How much ${dividendsType} would you like to distribute to token holders?: `); await checkBalance(dividend); let checkpointId = currentCheckpoint == 0 ? 0 : await selectCheckpoint(true); // If there are no checkpoints, it must create a new one await createDividends(dividend, checkpointId); break; - case 4: - // Explore account at checkpoint + case 'Explore account at checkpoint': let _address = readlineSync.question('Enter address to explore: '); let _checkpoint = await selectCheckpoint(false); await exploreAddress(_address, _checkpoint); break; - case 5: - // Explore total supply at checkpoint + case 'Explore total supply at checkpoint': let _checkpoint2 = await selectCheckpoint(false); await exploreTotalSupply(_checkpoint2); break; - break; - case 6: - // Push dividends to account + case 'Push dividends to accounts': let _dividend = await selectDividend({valid: true, expired: false, reclaimed: false}); if (_dividend !== null) { let _addresses = readlineSync.question('Enter addresses to push dividends to (ex- add1,add2,add3,...): '); await pushDividends(_dividend, _addresses); } break; - case 7: - //explore balance + case `Explore ${dividendsType} balance`: let _address3 = readlineSync.question('Enter address to explore: '); let _dividend3 = await selectDividend(); if (_dividend3 !== null) { @@ -168,14 +160,13 @@ async function start_explorer(){ `); } break; - case 8: - // Reclaimed dividends after expiry + case 'Reclaim expired dividends': let _dividend4 = await selectDividend({expired: true, reclaimed: false}); if (_dividend4 !== null) { await reclaimedDividend(_dividend4); } break; - case -1: + case 'Cancel': process.exit(0); break; } From 6120339d13f51ee51df0fa1da0fcec168c6553d1 Mon Sep 17 00:00:00 2001 From: Victor Vicente Date: Thu, 27 Sep 2018 10:19:58 -0300 Subject: [PATCH 4/6] CLI: Support for tax withholding and exclusions from dividends. --- CLI/commands/dividends_manager.js | 141 +++++++++++++++++++++++--- CLI/data/dividendsExclusions_data.csv | 6 ++ 2 files changed, 135 insertions(+), 12 deletions(-) create mode 100644 CLI/data/dividendsExclusions_data.csv diff --git a/CLI/commands/dividends_manager.js b/CLI/commands/dividends_manager.js index a84a15067..609338839 100644 --- a/CLI/commands/dividends_manager.js +++ b/CLI/commands/dividends_manager.js @@ -96,7 +96,7 @@ async function start_explorer(){ let currentCheckpoint = await securityToken.methods.currentCheckpointId().call(); console.log(chalk.yellow(`\nToken is at checkpoint: ${currentCheckpoint}`)); - let options = ['Mint tokens', 'Transfer tokens', 'Create checkpoint', 'Create dividends'] + let options = ['Mint tokens', 'Transfer tokens', 'Create checkpoint', 'Set default exclusions for dividends', 'Tax holding settings', 'Create dividends'] if (currentCheckpoint > 0) { options.push('Explore account at checkpoint', 'Explore total supply at checkpoint') @@ -126,6 +126,12 @@ async function start_explorer(){ let createCheckpointAction = securityToken.methods.createCheckpoint(); await common.sendTransaction(Issuer, createCheckpointAction, defaultGasPrice); break; + case 'Set default exclusions for dividends': + await setDefaultExclusions(); + break; + case 'Tax holding settings': + await taxHoldingMenu(); + break; case 'Create dividends': let dividend = readlineSync.question(`How much ${dividendsType} would you like to distribute to token holders?: `); await checkBalance(dividend); @@ -142,7 +148,7 @@ async function start_explorer(){ await exploreTotalSupply(_checkpoint2); break; case 'Push dividends to accounts': - let _dividend = await selectDividend({valid: true, expired: false, reclaimed: false}); + let _dividend = await selectDividend({valid: true, expired: false, reclaimed: false, withRemaining: true}); if (_dividend !== null) { let _addresses = readlineSync.question('Enter addresses to push dividends to (ex- add1,add2,add3,...): '); await pushDividends(_dividend, _addresses); @@ -240,6 +246,69 @@ async function exploreTotalSupply(checkpoint){ console.log(`TotalSupply is: ${totalSupplyAt} (Using totalSupplyAt - checkpoint ${checkpoint})`); } +async function setDefaultExclusions() { + await addDividendsModule(); + + let excluded = await currentDividendsModule.methods.getDefaultExcluded().call(); + showExcluded(excluded); + + console.log(chalk.yellow(`Excluded addresses will be loaded from 'dividendsExclusions_data.csv'. Please check your data before continue.`)); + if (readlineSync.keyInYNStrict(`Do you want to continue?`)) { + let excluded = getExcludedFromDataFile(); + let setDefaultExclusionsActions = currentDividendsModule.methods.setDefaultExcluded(excluded); + let receipt = await common.sendTransaction(Issuer, setDefaultExclusionsActions, defaultGasPrice); + let event = common.getEventFromLogs(currentDividendsModule._jsonInterface, receipt.logs, 'SetDefaultExcludedAddresses'); + console.log(chalk.green(`Exclusions were successfuly set.`)); + showExcluded(event._excluded); + } +} + +async function taxHoldingMenu() { + await addDividendsModule(); + + let options = ['Set a % to withhold from dividends sent to an address', 'Withdraw withholding for dividend', 'Return to main menu']; + let index = readlineSync.keyInSelect(options, 'What do you want to do?', {cancel: false}); + let selected = options[index]; + console.log("Selected:", selected); + switch (selected) { + case 'Set a % to withhold from dividends sent to an address': + let address = readlineSync.question('Enter the address of the investor: ', { + limit: function(input) { + return web3.utils.isAddress(input); + }, + limitMessage: "Must be a valid address", + }); + let percentage = readlineSync.question('Enter the percentage of dividends to withhold (number between 0-100): ', { + limit: function(input) { + return (parseInt(input) >= 0 && parseInt(input) <= 100); + }, + limitMessage: "Must be a value between 0 and 100", + }); + let percentageWei = web3.utils.toWei((percentage / 100).toString()); + let setWithHoldingFixedAction = currentDividendsModule.methods.setWithholdingFixed([address], percentageWei); + let receipt = await common.sendTransaction(Issuer, setWithHoldingFixedAction, defaultGasPrice); + console.log(chalk.green(`Successfully set tax withholding of ${percentage}% for ${address}.`)); + break; + case 'Withdraw withholding for dividend': + let _dividend = await selectDividend({withRemainingWithheld: true}); + if (_dividend !== null) { + let withdrawWithholdingAction = currentDividendsModule.methods.withdrawWithholding(_dividend.index); + let receipt = await common.sendTransaction(Issuer, withdrawWithholdingAction, defaultGasPrice); + let eventName; + if (dividendsType == 'POLY') { + eventName = 'ERC20DividendWithholdingWithdrawn'; + } else if (dividendsType == 'ETH') { + eventName = 'EtherDividendWithholdingWithdrawn'; + } + let event = common.getEventFromLogs(currentDividendsModule._jsonInterface, receipt.logs, eventName); + console.log(chalk.green(`Successfully withdrew ${web3.utils.fromWei(event._withheldAmount)} ${dividendsType} from dividend ${_dividend.index} tax withholding.`)); + } + break; + case 'Return to main menu': + break; + } +} + async function createDividends(dividend, checkpointId) { await addDividendsModule(); @@ -247,26 +316,46 @@ async function createDividends(dividend, checkpointId) { let maturityTime = readlineSync.questionInt('Enter the dividend maturity time from which dividend can be paid (Unix Epoch time)\n(Now = ' + time + ' ): ', {defaultInput: time}); let defaultTime = time + duration.minutes(10); let expiryTime = readlineSync.questionInt('Enter the dividend expiry time (Unix Epoch time)\n(10 minutes from now = ' + defaultTime + ' ): ', {defaultInput: defaultTime}); + + let useDefaultExcluded = readlineSync.keyInYNStrict(`Do you want to use the default excluded addresses for this dividend? If not, data from 'dividendsExclusions_data.csv' will be used instead.`); let createDividendAction; if (dividendsType == 'POLY') { let approveAction = polyToken.methods.approve(currentDividendsModule._address, web3.utils.toWei(dividend)); await common.sendTransaction(Issuer, approveAction, defaultGasPrice); if (checkpointId > 0) { - createDividendAction = currentDividendsModule.methods.createDividendWithCheckpoint(maturityTime, expiryTime, polyToken._address, web3.utils.toWei(dividend), checkpointId); + if (useDefaultExcluded) { + createDividendAction = currentDividendsModule.methods.createDividendWithCheckpoint(maturityTime, expiryTime, polyToken._address, web3.utils.toWei(dividend), checkpointId); + } else { + let excluded = getExcludedFromDataFile(); + createDividendAction = currentDividendsModule.methods.createDividendWithCheckpointAndExclusions(maturityTime, expiryTime, polyToken._address, web3.utils.toWei(dividend), checkpointId, excluded); + } } else { - createDividendAction = currentDividendsModule.methods.createDividend(maturityTime, expiryTime, polyToken._address, web3.utils.toWei(dividend)); + if (useDefaultExcluded) { + createDividendAction = currentDividendsModule.methods.createDividend(maturityTime, expiryTime, polyToken._address, web3.utils.toWei(dividend)); + } else { + let excluded = getExcludedFromDataFile(); + createDividendAction = currentDividendsModule.methods.createDividendWithExclusions(maturityTime, expiryTime, polyToken._address, web3.utils.toWei(dividend), excluded); + } } let receipt = await common.sendTransaction(Issuer, createDividendAction, defaultGasPrice); let event = common.getEventFromLogs(currentDividendsModule._jsonInterface, receipt.logs, 'ERC20DividendDeposited'); - console.log(` - Dividend ${event._dividendIndex} deposited` - ); + console.log(chalk.green(`Dividend ${event._dividendIndex} deposited`)); } else if (dividendsType == 'ETH') { if (checkpointId > 0) { - createDividendAction = currentDividendsModule.methods.createDividendWithCheckpoint(maturityTime, expiryTime, checkpointId); + if (useDefaultExcluded) { + createDividendAction = currentDividendsModule.methods.createDividendWithCheckpoint(maturityTime, expiryTime, checkpointId); + } else { + let excluded = getExcludedFromDataFile(); + createDividendAction = currentDividendsModule.methods.createDividendWithCheckpointAndExclusions(maturityTime, expiryTime, checkpointId, excluded); + } } else { - createDividendAction = currentDividendsModule.methods.createDividend(maturityTime, expiryTime); + if (useDefaultExcluded) { + createDividendAction = currentDividendsModule.methods.createDividend(maturityTime, expiryTime); + } else { + let excluded = getExcludedFromDataFile(); + createDividendAction = currentDividendsModule.methods.createDividendWithExclusions(maturityTime, expiryTime, excluded); + } } let receipt = await common.sendTransaction(Issuer, createDividendAction, defaultGasPrice, web3.utils.toWei(dividend)); let event = common.getEventFromLogs(currentDividendsModule._jsonInterface, receipt.logs, 'EtherDividendDeposited'); @@ -299,7 +388,8 @@ async function pushDividends(dividend, account){ for (const event of successEvents) { console.log(` Claimed ${web3.utils.fromWei(event._amount)} ${dividendsType} - to account ${event._payee}` + to account ${event._payee} + ${web3.utils.fromWei(event._withheld)} ${dividendsType} of tax withheld` ); } } @@ -441,6 +531,12 @@ async function selectDividend(filter) { if (typeof filter.reclaimed !== 'undefined') { dividends = dividends.filter(d => filter.reclaimed == d.reclaimed); } + if (typeof filter.withRemainingWithheld !== 'undefined') { + dividends = dividends.filter(d => new web3.utils.BN(d.dividendWithheld).sub(new web3.utils.BN(d.dividendWithheldReclaimed)) > 0); + } + if (typeof filter.withRemaining !== 'undefined') { + dividends = dividends.filter(d => new web3.utils.BN(d.amount).sub(new web3.utils.BN(d.claimedAmount)) > 0); + } } if (dividends.length > 0) { @@ -448,9 +544,11 @@ async function selectDividend(filter) { return `Created: ${moment.unix(d.created).format('MMMM Do YYYY, HH:mm:ss')} Maturity: ${moment.unix(d.maturity).format('MMMM Do YYYY, HH:mm:ss')} Expiry: ${moment.unix(d.expiry).format('MMMM Do YYYY, HH:mm:ss')} + At checkpoint: ${d.checkpointId} Amount: ${web3.utils.fromWei(d.amount)} ${dividendsType} Claimed Amount: ${web3.utils.fromWei(d.claimedAmount)} ${dividendsType} - At checkpoint: ${d.checkpointId}` + Withheld: ${web3.utils.fromWei(d.dividendWithheld)} ${dividendsType} + Withheld claimed: ${web3.utils.fromWei(d.dividendWithheldReclaimed)} ${dividendsType}` }); let index = readlineSync.keyInSelect(options, 'Select a dividend:'); @@ -459,7 +557,8 @@ async function selectDividend(filter) { } } else { console.log(chalk.red(`No dividends were found meeting the requirements`)) - console.log(chalk.red(`Requirements: Valid: ${filter.valid} - Expired: ${filter.expired} - Reclaimed: ${filter.reclaimed}\n`)) + console.log(chalk.red(`Requirements: Valid: ${filter.valid} - Expired: ${filter.expired} - Reclaimed: ${filter.reclaimed} + WithRemainingWithheld: ${filter.withRemainingWithheld} - WithRemaining: ${filter.withRemaining}\n`)) } return result; @@ -481,6 +580,24 @@ async function getDividends() { return result; } +function getExcludedFromDataFile() { + let excludedFromFile = require('fs').readFileSync('./CLI/data/dividendsExclusions_data.csv').toString().split("\n"); + let excluded = excludedFromFile.filter(function (address) { + return web3.utils.isAddress(address); + }); + return excluded; +} + +function showExcluded(excluded) { + if (excluded.length > 0) { + console.log('Current default excluded addresses:') + excluded.map(function (address) { console.log(' ', address) }); + } else { + console.log('There are not default excluded addresses.') + } + console.log(); +} + module.exports = { executeApp: async function(type, remoteNetwork) { return executeApp(type, remoteNetwork); diff --git a/CLI/data/dividendsExclusions_data.csv b/CLI/data/dividendsExclusions_data.csv new file mode 100644 index 000000000..b418985eb --- /dev/null +++ b/CLI/data/dividendsExclusions_data.csv @@ -0,0 +1,6 @@ +0xa26cc0567e29fda3c77369791e926b4c46456fcb +0x97c09f763a699a51cb947f95e602c08f7bcba202 +0x308a3ea530e5b160f1f7115f2ddb30cb44d8b54d +0xbc1bfb5d90692854672febe76ca5379dea1015e4 +0x7442dcd2eb074ea6dbfaa8338300bc86238c2aae +0x0a519b4b6501f92e8f516230b97aca83257b0c01 \ No newline at end of file From 8a1d8f989a3c4390d86e4bdb86dcd38c3953db3b Mon Sep 17 00:00:00 2001 From: Victor Vicente Date: Fri, 28 Sep 2018 09:26:32 -0300 Subject: [PATCH 5/6] Event names modified --- CLI/commands/ST20Generator.js | 8 ++++---- CLI/commands/contract_manager.js | 6 +++--- CLI/commands/dividends_manager.js | 4 ++-- CLI/commands/strMigrator.js | 2 +- CLI/commands/transfer_manager.js | 4 ++-- CLI/commands/whitelist.js | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/CLI/commands/ST20Generator.js b/CLI/commands/ST20Generator.js index 1f15dc4c2..27ae398b2 100644 --- a/CLI/commands/ST20Generator.js +++ b/CLI/commands/ST20Generator.js @@ -144,7 +144,7 @@ async function step_ticker_reg(){ }); 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'); + 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); } @@ -187,7 +187,7 @@ 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); @@ -444,7 +444,7 @@ async function cappedSTO_launch() { 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; @@ -828,7 +828,7 @@ async function usdTieredSTO_launch() { 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; diff --git a/CLI/commands/contract_manager.js b/CLI/commands/contract_manager.js index 9f8cf6812..60af89396 100644 --- a/CLI/commands/contract_manager.js +++ b/CLI/commands/contract_manager.js @@ -173,7 +173,7 @@ async function strActions() { 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': @@ -182,7 +182,7 @@ async function strActions() { 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': @@ -191,7 +191,7 @@ async function strActions() { 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': diff --git a/CLI/commands/dividends_manager.js b/CLI/commands/dividends_manager.js index bc30dddf9..bd43d6661 100644 --- a/CLI/commands/dividends_manager.js +++ b/CLI/commands/dividends_manager.js @@ -475,7 +475,7 @@ async function addDividendsModule() { 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, 'LogModuleAdded'); + let event = common.getEventFromLogs(securityToken._jsonInterface, receipt.logs, 'ModuleAdded'); console.log(`Module deployed at address: ${event._module}`); currentDividendsModule = new web3.eth.Contract(dividendsModuleABI, event._module); currentDividendsModule.setProvider(web3.currentProvider); @@ -504,7 +504,7 @@ async function getCheckpoints() { } */ - let events = await securityToken.getPastEvents('LogCheckpointCreated', { fromBlock: 0}); + let events = await securityToken.getPastEvents('CheckpointCreated', { fromBlock: 0}); for (let event of events) { let checkpoint = {}; checkpoint.id = event.returnValues._checkpointId; diff --git a/CLI/commands/strMigrator.js b/CLI/commands/strMigrator.js index d0538dbad..a2ba4bdf0 100644 --- a/CLI/commands/strMigrator.js +++ b/CLI/commands/strMigrator.js @@ -80,7 +80,7 @@ function step_instance_toSTR(toStrAddress){ async function step_get_deployed_tokens(securityTokenRegistry) { let tokens = []; - let events = await securityTokenRegistry.getPastEvents('LogNewSecurityToken', { fromBlock: 0}); + let events = await securityTokenRegistry.getPastEvents('NewSecurityToken', { fromBlock: 0}); if (events.length == 0) { console.log("No security token events were emitted."); } else { diff --git a/CLI/commands/transfer_manager.js b/CLI/commands/transfer_manager.js index 9d9b46f29..0769f88aa 100644 --- a/CLI/commands/transfer_manager.js +++ b/CLI/commands/transfer_manager.js @@ -85,7 +85,7 @@ async function start_explorer() { }); let setControllerAction = securityToken.methods.setController(controllerAddress); let setControllerReceipt = await common.sendTransaction(Issuer, setControllerAction, defaultGasPrice); - let setControllerEvent = common.getEventFromLogs(securityToken._jsonInterface, setControllerReceipt.logs, 'LogSetController'); + let setControllerEvent = common.getEventFromLogs(securityToken._jsonInterface, setControllerReceipt.logs, 'SetController'); console.log(chalk.green(`New controller is ${setControllerEvent._newController}`)); break; case 'Force Transfer': @@ -114,7 +114,7 @@ async function start_explorer() { let data = readlineSync.question('Enter the data attached to the transfer by controller to emit in event: '); let forceTransferAction = securityToken.methods.forceTransfer(from, to, web3.utils.toWei(amount), web3.utils.asciiToHex(data)); let forceTransferReceipt = await common.sendTransaction(Issuer, forceTransferAction, defaultGasPrice, 0, 1.5); - let forceTransferEvent = common.getEventFromLogs(securityToken._jsonInterface, forceTransferReceipt.logs, 'LogForceTransfer'); + let forceTransferEvent = common.getEventFromLogs(securityToken._jsonInterface, forceTransferReceipt.logs, 'ForceTransfer'); console.log(chalk.green(` ${forceTransferEvent._controller} has successfully forced a transfer of ${web3.utils.fromWei(forceTransferEvent._amount)} ${tokenSymbol} from ${forceTransferEvent._from} to ${forceTransferEvent._to} Verified transfer: ${forceTransferEvent._verifyTransfer} diff --git a/CLI/commands/whitelist.js b/CLI/commands/whitelist.js index 26f4af32a..903ef40ec 100644 --- a/CLI/commands/whitelist.js +++ b/CLI/commands/whitelist.js @@ -185,7 +185,7 @@ async function setInvestors() { let investorData_Events = new Array(); let investorObjectLookup = {}; - let event_data = await generalTransferManager.getPastEvents('LogModifyWhitelist', { + let event_data = await generalTransferManager.getPastEvents('ModifyWhitelist', { fromBlock: 0, toBlock: 'latest' }, function (error, events) { From fe71172dd5abe161e7211d997b4ea10bd4d737b3 Mon Sep 17 00:00:00 2001 From: Victor Vicente Date: Fri, 28 Sep 2018 09:33:24 -0300 Subject: [PATCH 6/6] Fix for calculate dividend --- CLI/commands/dividends_manager.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CLI/commands/dividends_manager.js b/CLI/commands/dividends_manager.js index bd43d6661..59b0d748a 100644 --- a/CLI/commands/dividends_manager.js +++ b/CLI/commands/dividends_manager.js @@ -157,11 +157,14 @@ async function start_explorer(){ let _address3 = readlineSync.question('Enter address to explore: '); let _dividend3 = await selectDividend(); if (_dividend3 !== null) { - let divsBalance = await currentDividendsModule.methods.calculateDividend(_dividend3.index, _address3).call(); + let dividendAmounts = await currentDividendsModule.methods.calculateDividend(_dividend3.index, _address3).call(); + let dividendBalance = dividendAmounts[0]; + let dividendTax = dividendAmounts[1]; let balance = await getBalance(_address3); console.log(` ${dividendsType} Balance: ${web3.utils.fromWei(balance)} ${dividendsType} - Dividends owned: ${web3.utils.fromWei(divsBalance)} ${dividendsType} + Dividends owned: ${web3.utils.fromWei(dividendBalance)} ${dividendsType} + Tax withheld: ${web3.utils.fromWei(dividendTax)} ${dividendsType} `); } break;