@@ -17,6 +17,7 @@ const PERCENTAGE_WHITELIST_DATA_CSV = './CLI/data/Transfer/PercentageTM/whitelis
17
17
let tokenSymbol ;
18
18
let securityToken ;
19
19
let securityTokenRegistry ;
20
+ let moduleRegistry ;
20
21
let currentTransferManager ;
21
22
22
23
async function executeApp ( ) {
@@ -48,23 +49,23 @@ async function executeApp() {
48
49
console . log ( 'Selected:' , optionSelected , '\n' ) ;
49
50
switch ( optionSelected ) {
50
51
case 'Verify transfer' :
52
+ let verifyTotalSupply = web3 . utils . fromWei ( await securityToken . methods . totalSupply ( ) . call ( ) ) ;
53
+ await logTotalInvestors ( ) ;
51
54
let verifyTransferFrom = readlineSync . question ( `Enter the sender account (${ Issuer . address } ): ` , {
52
55
limit : function ( input ) {
53
56
return web3 . utils . isAddress ( input ) ;
54
57
} ,
55
58
limitMessage : "Must be a valid address" ,
56
59
defaultInput : Issuer . address
57
60
} ) ;
58
- let verifyFromBalance = web3 . utils . fromWei ( await securityToken . methods . balanceOf ( verifyTransferFrom ) . call ( ) ) ;
59
- console . log ( chalk . yellow ( `Balance of ${ verifyTransferFrom } : ${ verifyFromBalance } ${ tokenSymbol } ` ) ) ;
61
+ await logBalance ( verifyTransferFrom , verifyTotalSupply ) ;
60
62
let verifyTransferTo = readlineSync . question ( 'Enter the receiver account: ' , {
61
63
limit : function ( input ) {
62
64
return web3 . utils . isAddress ( input ) ;
63
65
} ,
64
66
limitMessage : "Must be a valid address" ,
65
67
} ) ;
66
- let verifyToBalance = web3 . utils . fromWei ( await securityToken . methods . balanceOf ( verifyTransferTo ) . call ( ) ) ;
67
- console . log ( chalk . yellow ( `Balance of ${ verifyTransferTo } : ${ verifyToBalance } ${ tokenSymbol } ` ) ) ;
68
+ await logBalance ( verifyTransferTo , verifyTotalSupply ) ;
68
69
let verifyTransferAmount = readlineSync . question ( 'Enter amount of tokens to verify: ' ) ;
69
70
let isVerified = await securityToken . methods . verifyTransfer ( verifyTransferFrom , verifyTransferTo , web3 . utils . toWei ( verifyTransferAmount ) , web3 . utils . fromAscii ( "" ) ) . call ( ) ;
70
71
if ( isVerified ) {
@@ -74,25 +75,26 @@ async function executeApp() {
74
75
}
75
76
break ;
76
77
case 'Transfer' :
77
- let fromBalance = web3 . utils . fromWei ( await securityToken . methods . balanceOf ( Issuer . address ) . call ( ) ) ;
78
- console . log ( chalk . yellow ( `Balance of ${ Issuer . address } : ${ fromBalance } ${ tokenSymbol } ` ) ) ;
78
+ let totalSupply = web3 . utils . fromWei ( await securityToken . methods . totalSupply ( ) . call ( ) ) ;
79
+ await logTotalInvestors ( ) ;
80
+ await logBalance ( Issuer . address , totalSupply ) ;
79
81
let transferTo = readlineSync . question ( 'Enter beneficiary of tranfer: ' , {
80
82
limit : function ( input ) {
81
83
return web3 . utils . isAddress ( input ) ;
82
84
} ,
83
85
limitMessage : "Must be a valid address"
84
86
} ) ;
85
- let toBalance = web3 . utils . fromWei ( await securityToken . methods . balanceOf ( transferTo ) . call ( ) ) ;
86
- console . log ( chalk . yellow ( `Balance of ${ transferTo } : ${ toBalance } ${ tokenSymbol } ` ) ) ;
87
+ await logBalance ( transferTo , totalSupply ) ;
87
88
let transferAmount = readlineSync . question ( 'Enter amount of tokens to transfer: ' ) ;
88
89
let isTranferVerified = await securityToken . methods . verifyTransfer ( Issuer . address , transferTo , web3 . utils . toWei ( transferAmount ) , web3 . utils . fromAscii ( "" ) ) . call ( ) ;
89
90
if ( isTranferVerified ) {
90
91
let transferAction = securityToken . methods . transfer ( transferTo , web3 . utils . toWei ( transferAmount ) ) ;
91
92
let receipt = await common . sendTransaction ( transferAction ) ;
92
93
let event = common . getEventFromLogs ( securityToken . _jsonInterface , receipt . logs , 'Transfer' ) ;
93
94
console . log ( chalk . green ( `${ event . from } transferred ${ web3 . utils . fromWei ( event . value ) } ${ tokenSymbol } to ${ event . to } successfully!` ) ) ;
94
- console . log ( `Balance of ${ Issuer . address } after transfer: ${ web3 . utils . fromWei ( await securityToken . methods . balanceOf ( Issuer . address ) . call ( ) ) } ${ tokenSymbol } ` ) ;
95
- console . log ( `Balance of ${ transferTo } after transfer: ${ web3 . utils . fromWei ( await securityToken . methods . balanceOf ( transferTo ) . call ( ) ) } ${ tokenSymbol } ` ) ;
95
+ await logTotalInvestors ( ) ;
96
+ await logBalance ( Issuer . address , totalSupply ) ;
97
+ await logBalance ( transferTo , totalSupply ) ;
96
98
} else {
97
99
console . log ( chalk . red ( `Transfer failed at verification. Please review the transfer restrictions.` ) ) ;
98
100
}
@@ -231,14 +233,12 @@ async function configExistingModules(tmModules) {
231
233
}
232
234
233
235
async function addTransferManagerModule ( ) {
234
- let options = [
235
- 'GeneralTransferManager' ,
236
- 'ManualApprovalTransferManager' ,
237
- 'CountTransferManager' ,
238
- 'PercentageTransferManager' ,
239
- //'SingleTradeVolumeRestrictionTM',
240
- //'LookupVolumeRestrictionTM'*/
241
- ] ;
236
+ let availableModules = await moduleRegistry . methods . getModulesByTypeAndToken ( gbl . constants . MODULES_TYPES . TRANSFER , securityToken . options . address ) . call ( ) ;
237
+ let options = await Promise . all ( availableModules . map ( async function ( m ) {
238
+ let moduleFactoryABI = abis . moduleFactory ( ) ;
239
+ let moduleFactory = new web3 . eth . Contract ( moduleFactoryABI , m ) ;
240
+ return web3 . utils . hexToUtf8 ( await moduleFactory . methods . name ( ) . call ( ) ) ;
241
+ } ) ) ;
242
242
243
243
let index = readlineSync . keyInSelect ( options , 'Which Transfer Manager module do you want to add? ' , { cancel : 'Return' } ) ;
244
244
if ( index != - 1 && readlineSync . keyInYNStrict ( `Are you sure you want to add ${ options [ index ] } module?` ) ) {
@@ -1134,6 +1134,11 @@ async function setup() {
1134
1134
let securityTokenRegistryABI = abis . securityTokenRegistry ( ) ;
1135
1135
securityTokenRegistry = new web3 . eth . Contract ( securityTokenRegistryABI , securityTokenRegistryAddress ) ;
1136
1136
securityTokenRegistry . setProvider ( web3 . currentProvider ) ;
1137
+
1138
+ let moduleRegistryAddress = await contracts . moduleRegistry ( ) ;
1139
+ let moduleRegistryABI = abis . moduleRegistry ( ) ;
1140
+ moduleRegistry = new web3 . eth . Contract ( moduleRegistryABI , moduleRegistryAddress ) ;
1141
+ moduleRegistry . setProvider ( web3 . currentProvider ) ;
1137
1142
} catch ( err ) {
1138
1143
console . log ( err )
1139
1144
console . log ( '\x1b[31m%s\x1b[0m' , "There was a problem getting the contracts. Make sure they are deployed to the selected network." ) ;
@@ -1171,6 +1176,17 @@ async function selectToken() {
1171
1176
return result ;
1172
1177
}
1173
1178
1179
+ async function logTotalInvestors ( ) {
1180
+ let investorsCount = await securityToken . methods . getInvestorCount ( ) . call ( ) ;
1181
+ console . log ( chalk . yellow ( `Total investors at the moment: ${ investorsCount } ` ) ) ;
1182
+ }
1183
+
1184
+ async function logBalance ( from , totalSupply ) {
1185
+ let fromBalance = web3 . utils . fromWei ( await securityToken . methods . balanceOf ( from ) . call ( ) ) ;
1186
+ let percentage = totalSupply != '0' ? ` - ${ parseFloat ( fromBalance ) / parseFloat ( totalSupply ) * 100 } % of total supply` : '' ;
1187
+ console . log ( chalk . yellow ( `Balance of ${ from } : ${ fromBalance } ${ tokenSymbol } ${ percentage } ` ) ) ;
1188
+ }
1189
+
1174
1190
module . exports = {
1175
1191
executeApp : async function ( _tokenSymbol ) {
1176
1192
await initialize ( _tokenSymbol ) ;
0 commit comments