1
1
import { RedundantSubprovider , RPCSubprovider , Web3ProviderEngine } from '@0x/subproviders' ;
2
2
import ModuleFactoryWrapper from '../src/contract_wrappers/modules/module_factory_wrapper' ;
3
3
import { ApiConstructorParams , PolymathAPI } from '../src/PolymathAPI' ;
4
- import { bytes32ToString } from '../src/utils/convert' ;
5
4
import { ModuleName , ModuleType } from '../src' ;
6
- import { BigNumber } from '@polymathnetwork/abi-wrappers' ;
5
+ import { BigNumber , ModuleRegistryEvents , PercentageTransferManagerEvents } from '@polymathnetwork/abi-wrappers' ;
7
6
8
7
// This file acts as a valid sandbox for using a percentage restriction transfer manager module on an unlocked node (like ganache)
9
8
window . addEventListener ( 'load' , async ( ) => {
@@ -16,15 +15,52 @@ window.addEventListener('load', async () => {
16
15
polymathRegistryAddress : '<Deployed Polymath Registry address>' ,
17
16
} ;
18
17
19
- // Instantiate the API
18
+ // Instantiate the API
20
19
const polymathAPI = new PolymathAPI ( params ) ;
21
20
22
- const ticker = 'TEST' ;
23
- const tickerSecurityTokenInstance = await polymathAPI . tokenFactory . getSecurityTokenInstanceFromTicker ( ticker ) ;
24
- const moduleStringName = 'PercentageTransferManager' ;
21
+ // Get some poly tokens in your account and the security token
22
+ const myAddress = await polymathAPI . getAccount ( ) ;
23
+ await polymathAPI . getPolyTokens ( { amount : new BigNumber ( 1000000 ) , address : myAddress } ) ;
24
+
25
+ // Prompt to setup your ticker and token name
26
+ const ticker = prompt ( 'Ticker' , '' ) ;
27
+ const tokenName = prompt ( 'Token Name' , '' ) ;
28
+
29
+ // Double check available
30
+ await polymathAPI . securityTokenRegistry . isTickerAvailable ( {
31
+ ticker : ticker ! ,
32
+ } ) ;
33
+ // Get the ticker fee and approve the security token registry to spend
34
+ const tickerFee = await polymathAPI . securityTokenRegistry . getTickerRegistrationFee ( ) ;
35
+ await polymathAPI . polyToken . approve ( {
36
+ spender : await polymathAPI . securityTokenRegistry . address ( ) ,
37
+ value : tickerFee ,
38
+ } ) ;
39
+ // Register a ticker
40
+ await polymathAPI . securityTokenRegistry . registerTicker ( {
41
+ ticker : ticker ! ,
42
+ tokenName : tokenName ! ,
43
+ } ) ;
44
+ // Get the st launch fee and approve the security token registry to spend
45
+ const securityTokenLaunchFee = await polymathAPI . securityTokenRegistry . getSecurityTokenLaunchFee ( ) ;
46
+ await polymathAPI . polyToken . approve ( {
47
+ spender : await polymathAPI . securityTokenRegistry . address ( ) ,
48
+ value : securityTokenLaunchFee ,
49
+ } ) ;
50
+
51
+ await polymathAPI . securityTokenRegistry . generateNewSecurityToken ( {
52
+ name : tokenName ! ,
53
+ ticker : ticker ! ,
54
+ tokenDetails : 'details' ,
55
+ divisible : true ,
56
+ treasuryWallet : myAddress ,
57
+ protocolVersion : '0' ,
58
+ } ) ;
59
+
60
+ console . log ( 'Security Token Generated' ) ;
61
+
25
62
const moduleName = ModuleName . PercentageTransferManager ;
26
63
27
- // Get permission manager factory address
28
64
const modules = await polymathAPI . moduleRegistry . getModulesByType ( {
29
65
moduleType : ModuleType . TransferManager ,
30
66
} ) ;
@@ -41,19 +77,94 @@ window.addEventListener('load', async () => {
41
77
} ) ;
42
78
const resultNames = await Promise . all ( names ) ;
43
79
44
- const finalNames = resultNames . map ( name => {
45
- return bytes32ToString ( name ) ;
80
+ const index = resultNames . indexOf ( moduleName ) ;
81
+
82
+ // Create a Security Token Instance
83
+ const tickerSecurityTokenInstance = await polymathAPI . tokenFactory . getSecurityTokenInstanceFromTicker ( ticker ! ) ;
84
+ const factory = await polymathAPI . moduleFactory . getModuleFactory ( modules [ index ] ) ;
85
+ const setupCost = await factory . setupCostInPoly ( ) ;
86
+
87
+ await polymathAPI . moduleRegistry . subscribeAsync ( {
88
+ eventName : ModuleRegistryEvents . ModuleRegistered ,
89
+ indexFilterValues : { } ,
90
+ callback : async ( error , log ) => {
91
+ if ( error ) {
92
+ console . log ( error ) ;
93
+ } else {
94
+ console . log ( 'Module added!' , log ) ;
95
+ }
96
+ } ,
97
+ } ) ;
98
+
99
+ // Get General TM Address to whitelist transfers
100
+ const generalTMAddress = ( await tickerSecurityTokenInstance . getModulesByName ( {
101
+ moduleName : ModuleName . GeneralTransferManager ,
102
+ } ) ) [ 0 ] ;
103
+ const generalTM = await polymathAPI . moduleFactory . getModuleInstance ( {
104
+ name : ModuleName . GeneralTransferManager ,
105
+ address : generalTMAddress ,
106
+ } ) ;
107
+
108
+ await generalTM . modifyKYCData ( {
109
+ investor : myAddress ,
110
+ canSendAfter : new Date ( ) ,
111
+ canReceiveAfter : new Date ( ) ,
112
+ expiryTime : new Date ( 2020 , 0 ) ,
113
+ txData : {
114
+ from : await polymathAPI . getAccount ( ) ,
115
+ } ,
46
116
} ) ;
47
- const index = finalNames . indexOf ( moduleStringName ) ;
48
117
49
- // Call to add module
50
118
await tickerSecurityTokenInstance . addModule ( {
51
119
moduleName,
52
120
address : modules [ index ] ,
53
121
data : {
54
- maxHolderPercentage : new BigNumber ( 10 ) ,
122
+ maxHolderPercentage : new BigNumber ( 50 ) ,
55
123
allowPrimaryIssuance : true ,
56
124
} ,
57
125
archived : false ,
58
126
} ) ;
127
+
128
+ const percentageTMAddress = ( await tickerSecurityTokenInstance . getModulesByName ( {
129
+ moduleName : ModuleName . PercentageTransferManager ,
130
+ } ) ) [ 0 ] ;
131
+
132
+ const percentageTM = await polymathAPI . moduleFactory . getModuleInstance ( {
133
+ name : ModuleName . PercentageTransferManager ,
134
+ address : percentageTMAddress ,
135
+ } ) ;
136
+
137
+ // Subscribe to event of setAllowPrimaryIssuance
138
+ await percentageTM . subscribeAsync ( {
139
+ eventName : PercentageTransferManagerEvents . SetAllowPrimaryIssuance ,
140
+ indexFilterValues : { } ,
141
+ callback : async ( error , log ) => {
142
+ if ( error ) {
143
+ console . log ( error ) ;
144
+ } else {
145
+ console . log ( 'AllowPrimaryIssuance has been set' , log ) ;
146
+ }
147
+ } ,
148
+ } ) ;
149
+
150
+ const randomBeneficiary = '0x0123456789012345678901234567890123456789' ;
151
+
152
+ await generalTM . modifyKYCDataMulti ( {
153
+ investors : [ myAddress , randomBeneficiary ] ,
154
+ canReceiveAfter : [ new Date ( ) , new Date ( ) ] ,
155
+ canSendAfter : [ new Date ( ) , new Date ( ) ] ,
156
+ expiryTime : [ new Date ( 2035 , 1 ) , new Date ( 2035 , 1 ) ] ,
157
+ } ) ;
158
+
159
+ await tickerSecurityTokenInstance . issueMulti ( {
160
+ investors : [ myAddress , randomBeneficiary ] ,
161
+ values : [ new BigNumber ( 10 ) , new BigNumber ( 10 ) ] ,
162
+ } ) ;
163
+
164
+ await percentageTM . setAllowPrimaryIssuance ( { allowPrimaryIssuance : false } ) ;
165
+ console . log ( 'SetAllowPrimaryIssuance has been called' ) ;
166
+
167
+ // Issuing now invalid
168
+
169
+ tickerSecurityTokenInstance . unsubscribeAll ( ) ;
59
170
} ) ;
0 commit comments