@@ -123,14 +123,16 @@ async function configExistingModules(dividendModules) {
123123async function dividendsManager ( ) {
124124 console . log ( chalk . blue ( `Dividends module at ${ currentDividendsModule . options . address } ` ) , '\n' ) ;
125125
126+ let wallet = await currentDividendsModule . methods . wallet ( ) . call ( ) ;
126127 let currentDividends = await getDividends ( ) ;
127128 let defaultExcluded = await currentDividendsModule . methods . getDefaultExcluded ( ) . call ( ) ;
128129 let currentCheckpointId = await securityToken . methods . currentCheckpointId ( ) . call ( ) ;
129130
131+ console . log ( `- Wallet: ${ wallet } ` ) ;
130132 console . log ( `- Current dividends: ${ currentDividends . length } ` ) ;
131133 console . log ( `- Default exclusions: ${ defaultExcluded . length } ` ) ;
132134
133- let options = [ 'Create checkpoint' ] ;
135+ let options = [ 'Change wallet' , ' Create checkpoint'] ;
134136 if ( currentCheckpointId > 0 ) {
135137 options . push ( 'Explore checkpoint' ) ;
136138 }
@@ -150,6 +152,9 @@ async function dividendsManager() {
150152 let selected = index != - 1 ? options [ index ] : 'RETURN' ;
151153 console . log ( 'Selected:' , selected , '\n' ) ;
152154 switch ( selected ) {
155+ case 'Change wallet' :
156+ await changeWallet ( ) ;
157+ break ;
153158 case 'Create checkpoint' :
154159 await createCheckpointFromDividendModule ( ) ;
155160 break ;
@@ -180,6 +185,19 @@ async function dividendsManager() {
180185 await dividendsManager ( ) ;
181186}
182187
188+ async function changeWallet ( ) {
189+ let newWallet = readlineSync . question ( 'Enter the new account address to receive reclaimed dividends and tax: ' , {
190+ limit : function ( input ) {
191+ return web3 . utils . isAddress ( input ) ;
192+ } ,
193+ limitMessage : "Must be a valid address" ,
194+ } ) ;
195+ let action = currentDividendsModule . methods . changeWallet ( newWallet ) ;
196+ let receipt = await common . sendTransaction ( action ) ;
197+ let event = common . getEventFromLogs ( currentDividendsModule . _jsonInterface , receipt . logs , 'SetWallet' ) ;
198+ console . log ( chalk . green ( `The wallet has been changed successfully!` ) ) ;
199+ }
200+
183201async function createCheckpointFromDividendModule ( ) {
184202 let createCheckpointAction = securityToken . methods . createCheckpoint ( ) ;
185203 await common . sendTransaction ( createCheckpointAction ) ;
@@ -230,8 +248,19 @@ async function manageExistingDividend(dividendIndex) {
230248 let claimedArray = progress [ 1 ] ;
231249 let excludedArray = progress [ 2 ] ;
232250 let withheldArray = progress [ 3 ] ;
233- let balanceArray = progress [ 4 ] ;
234- let amountArray = progress [ 5 ] ;
251+ let amountArray = progress [ 4 ] ;
252+ let balanceArray = progress [ 5 ] ;
253+
254+ // function for adding two numbers. Easy!
255+ const add = ( a , b ) => {
256+ const bnA = new web3 . utils . BN ( a ) ;
257+ const bnB = new web3 . utils . BN ( b ) ;
258+ return bnA . add ( bnB ) . toString ( ) ;
259+ } ;
260+ // use reduce to sum our array
261+ let taxesToWithHeld = withheldArray . reduce ( add , 0 ) ;
262+ let claimedInvestors = claimedArray . filter ( c => c ) . length ;
263+ let excludedInvestors = excludedArray . filter ( e => e ) . length ;
235264
236265 console . log ( `- Name: ${ web3 . utils . hexToUtf8 ( dividend . name ) } ` ) ;
237266 console . log ( `- Created: ${ moment . unix ( dividend . created ) . format ( 'MMMM Do YYYY, HH:mm:ss' ) } ` ) ;
@@ -240,11 +269,13 @@ async function manageExistingDividend(dividendIndex) {
240269 console . log ( `- At checkpoint: ${ dividend . checkpointId } ` ) ;
241270 console . log ( `- Amount: ${ web3 . utils . fromWei ( dividend . amount ) } ${ dividendTokenSymbol } ` ) ;
242271 console . log ( `- Claimed amount: ${ web3 . utils . fromWei ( dividend . claimedAmount ) } ${ dividendTokenSymbol } ` ) ;
243- console . log ( `- Withheld: ${ web3 . utils . fromWei ( dividend . totalWithheld ) } ${ dividendTokenSymbol } ` ) ;
244- console . log ( `- Withheld claimed: ${ web3 . utils . fromWei ( dividend . totalWithheldWithdrawn ) } ${ dividendTokenSymbol } ` ) ;
272+ console . log ( `- Taxes:` ) ;
273+ console . log ( ` To withhold: ${ web3 . utils . fromWei ( taxesToWithHeld ) } ${ dividendTokenSymbol } ` ) ;
274+ console . log ( ` Withheld to-date: ${ web3 . utils . fromWei ( dividend . totalWithheld ) } ${ dividendTokenSymbol } ` ) ;
275+ console . log ( ` Withdrawn to-date: ${ web3 . utils . fromWei ( dividend . totalWithheldWithdrawn ) } ${ dividendTokenSymbol } ` ) ;
245276 console . log ( `- Total investors: ${ investorArray . length } ` ) ;
246- console . log ( ` Have already claimed: ${ claimedArray . filter ( c => c ) . length } ` ) ;
247- console . log ( ` Excluded: ${ excludedArray . filter ( e => e ) . length } ` ) ;
277+ console . log ( ` Have already claimed: ${ claimedInvestors } ( ${ investorArray . length - excludedInvestors !== 0 ? claimedInvestors / ( investorArray . length - excludedInvestors ) * 100 : 0 } %) ` ) ;
278+ console . log ( ` Excluded: ${ excludedInvestors } ` ) ;
248279 // ------------------
249280
250281
@@ -454,10 +485,10 @@ function showReport(_name, _tokenSymbol, _amount, _witthheld, _claimed, _investo
454485 let investor = _investorArray [ i ] ;
455486 let excluded = _excludedArray [ i ] ;
456487 let withdrawn = _claimedArray [ i ] ? 'YES' : 'NO' ;
457- let amount = ! excluded ? web3 . utils . fromWei ( _amountArray [ i ] ) : 0 ;
458- let withheld = ( ! excluded && _claimedArray [ i ] ) ? web3 . utils . fromWei ( _withheldArray [ i ] ) : 'NA' ;
459- let withheldPercentage = ( ! excluded && _claimedArray [ i ] ) ? ( withheld !== '0' ? parseFloat ( withheld ) / parseFloat ( amount ) * 100 : 0 ) : 'NA' ;
460- let received = ( ! excluded && _claimedArray [ i ] ) ? web3 . utils . fromWei ( web3 . utils . toBN ( _amountArray [ i ] ) . sub ( web3 . utils . toBN ( _withheldArray [ i ] ) ) ) : 0 ;
488+ let amount = ! excluded ? web3 . utils . fromWei ( web3 . utils . toBN ( _amountArray [ i ] ) . add ( web3 . utils . toBN ( _withheldArray [ i ] ) ) ) : 0 ;
489+ let withheld = ! excluded ? web3 . utils . fromWei ( _withheldArray [ i ] ) : 'NA' ;
490+ let withheldPercentage = ( ! excluded ) ? ( withheld !== '0' ? parseFloat ( withheld ) / parseFloat ( amount ) * 100 : 0 ) : 'NA' ;
491+ let received = ! excluded ? web3 . utils . fromWei ( _amountArray [ i ] ) : 0 ;
461492 dataTable . push ( [
462493 investor ,
463494 amount ,
@@ -476,6 +507,8 @@ function showReport(_name, _tokenSymbol, _amount, _witthheld, _claimed, _investo
476507 console . log ( `- Total amount of investors: ${ _investorArray . length } ` ) ;
477508 console . log ( ) ;
478509 console . log ( table ( dataTable ) ) ;
510+ console . log ( ) ;
511+ console . log ( chalk . yellow ( `NOTE: If investor has not claimed the dividend yet, TAX and AMOUNT are calculated with the current values set and they might change.` ) ) ;
479512 console . log ( chalk . yellow ( `-----------------------------------------------------------------------------------------------------------------------------------------------------------` ) ) ;
480513 console . log ( ) ;
481514}
@@ -561,7 +594,14 @@ async function addDividendsModule() {
561594
562595 let index = readlineSync . keyInSelect ( options , 'Which dividends module do you want to add? ' , { cancel : 'Return' } ) ;
563596 if ( index != - 1 && readlineSync . keyInYNStrict ( `Are you sure you want to add ${ options [ index ] } module? ` ) ) {
564- let bytes = web3 . utils . fromAscii ( '' , 16 ) ;
597+ let wallet = readlineSync . question ( 'Enter the account address to receive reclaimed dividends and tax: ' , {
598+ limit : function ( input ) {
599+ return web3 . utils . isAddress ( input ) ;
600+ } ,
601+ limitMessage : "Must be a valid address" ,
602+ } ) ;
603+ let configureFunction = abis . erc20DividendCheckpoint ( ) . find ( o => o . name === 'configure' && o . type === 'function' ) ;
604+ let bytes = web3 . eth . abi . encodeFunctionCall ( configureFunction , [ wallet ] ) ;
565605
566606 let selectedDividendFactoryAddress = await contracts . getModuleFactoryAddressByName ( securityToken . options . address , gbl . constants . MODULES_TYPES . DIVIDENDS , options [ index ] ) ;
567607 let addModuleAction = securityToken . methods . addModule ( selectedDividendFactoryAddress , bytes , 0 , 0 ) ;
@@ -655,11 +695,11 @@ async function selectDividend(dividends) {
655695 let result = null ;
656696 let options = dividends . map ( function ( d ) {
657697 return `${ d . name }
658- Amount: ${ web3 . utils . fromWei ( d . amount ) } ${ dividendsType }
659- Status: ${ isExpiredDividend ( d ) ? 'Expired' : hasRemaining ( d ) ? 'In progress' : 'Completed' }
660- Token: ${ d . tokenSymbol }
661- Created: ${ moment . unix ( d . created ) . format ( 'MMMM Do YYYY, HH:mm:ss' ) }
662- Expiry: ${ moment . unix ( d . expiry ) . format ( 'MMMM Do YYYY, HH:mm:ss' ) } `
698+ Amount: ${ web3 . utils . fromWei ( d . amount ) } ${ d . tokenSymbol }
699+ Status: ${ isExpiredDividend ( d ) ? 'Expired' : hasRemaining ( d ) ? 'In progress' : 'Completed' }
700+ Token: ${ d . tokenSymbol }
701+ Created: ${ moment . unix ( d . created ) . format ( 'MMMM Do YYYY, HH:mm:ss' ) }
702+ Expiry: ${ moment . unix ( d . expiry ) . format ( 'MMMM Do YYYY, HH:mm:ss' ) } `
663703 } ) ;
664704
665705 let index = readlineSync . keyInSelect ( options , 'Select a dividend:' , { cancel : 'RETURN' } ) ;
0 commit comments