@@ -123,14 +123,16 @@ async function configExistingModules(dividendModules) {
123
123
async function dividendsManager ( ) {
124
124
console . log ( chalk . blue ( `Dividends module at ${ currentDividendsModule . options . address } ` ) , '\n' ) ;
125
125
126
+ let wallet = await currentDividendsModule . methods . wallet ( ) . call ( ) ;
126
127
let currentDividends = await getDividends ( ) ;
127
128
let defaultExcluded = await currentDividendsModule . methods . getDefaultExcluded ( ) . call ( ) ;
128
129
let currentCheckpointId = await securityToken . methods . currentCheckpointId ( ) . call ( ) ;
129
130
131
+ console . log ( `- Wallet: ${ wallet } ` ) ;
130
132
console . log ( `- Current dividends: ${ currentDividends . length } ` ) ;
131
133
console . log ( `- Default exclusions: ${ defaultExcluded . length } ` ) ;
132
134
133
- let options = [ 'Create checkpoint' ] ;
135
+ let options = [ 'Change wallet' , ' Create checkpoint'] ;
134
136
if ( currentCheckpointId > 0 ) {
135
137
options . push ( 'Explore checkpoint' ) ;
136
138
}
@@ -150,6 +152,9 @@ async function dividendsManager() {
150
152
let selected = index != - 1 ? options [ index ] : 'RETURN' ;
151
153
console . log ( 'Selected:' , selected , '\n' ) ;
152
154
switch ( selected ) {
155
+ case 'Change wallet' :
156
+ await changeWallet ( ) ;
157
+ break ;
153
158
case 'Create checkpoint' :
154
159
await createCheckpointFromDividendModule ( ) ;
155
160
break ;
@@ -180,6 +185,19 @@ async function dividendsManager() {
180
185
await dividendsManager ( ) ;
181
186
}
182
187
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
+
183
201
async function createCheckpointFromDividendModule ( ) {
184
202
let createCheckpointAction = securityToken . methods . createCheckpoint ( ) ;
185
203
await common . sendTransaction ( createCheckpointAction ) ;
@@ -230,8 +248,19 @@ async function manageExistingDividend(dividendIndex) {
230
248
let claimedArray = progress [ 1 ] ;
231
249
let excludedArray = progress [ 2 ] ;
232
250
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 ;
235
264
236
265
console . log ( `- Name: ${ web3 . utils . hexToUtf8 ( dividend . name ) } ` ) ;
237
266
console . log ( `- Created: ${ moment . unix ( dividend . created ) . format ( 'MMMM Do YYYY, HH:mm:ss' ) } ` ) ;
@@ -240,11 +269,13 @@ async function manageExistingDividend(dividendIndex) {
240
269
console . log ( `- At checkpoint: ${ dividend . checkpointId } ` ) ;
241
270
console . log ( `- Amount: ${ web3 . utils . fromWei ( dividend . amount ) } ${ dividendTokenSymbol } ` ) ;
242
271
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 } ` ) ;
245
276
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 } ` ) ;
248
279
// ------------------
249
280
250
281
@@ -454,10 +485,10 @@ function showReport(_name, _tokenSymbol, _amount, _witthheld, _claimed, _investo
454
485
let investor = _investorArray [ i ] ;
455
486
let excluded = _excludedArray [ i ] ;
456
487
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 ;
461
492
dataTable . push ( [
462
493
investor ,
463
494
amount ,
@@ -476,6 +507,8 @@ function showReport(_name, _tokenSymbol, _amount, _witthheld, _claimed, _investo
476
507
console . log ( `- Total amount of investors: ${ _investorArray . length } ` ) ;
477
508
console . log ( ) ;
478
509
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.` ) ) ;
479
512
console . log ( chalk . yellow ( `-----------------------------------------------------------------------------------------------------------------------------------------------------------` ) ) ;
480
513
console . log ( ) ;
481
514
}
@@ -561,7 +594,14 @@ async function addDividendsModule() {
561
594
562
595
let index = readlineSync . keyInSelect ( options , 'Which dividends module do you want to add? ' , { cancel : 'Return' } ) ;
563
596
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 ] ) ;
565
605
566
606
let selectedDividendFactoryAddress = await contracts . getModuleFactoryAddressByName ( securityToken . options . address , gbl . constants . MODULES_TYPES . DIVIDENDS , options [ index ] ) ;
567
607
let addModuleAction = securityToken . methods . addModule ( selectedDividendFactoryAddress , bytes , 0 , 0 ) ;
@@ -655,11 +695,11 @@ async function selectDividend(dividends) {
655
695
let result = null ;
656
696
let options = dividends . map ( function ( d ) {
657
697
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' ) } `
663
703
} ) ;
664
704
665
705
let index = readlineSync . keyInSelect ( options , 'Select a dividend:' , { cancel : 'RETURN' } ) ;
0 commit comments