1
1
import { RedundantSubprovider , RPCSubprovider , Web3ProviderEngine } from '@0x/subproviders' ;
2
- import { ModuleRegistryEvents , BigNumber } from '@polymathnetwork/abi-wrappers' ;
2
+ import { ModuleRegistryEvents , BigNumber , CappedSTOEvents } from '@polymathnetwork/abi-wrappers' ;
3
3
import ModuleFactoryWrapper from '../src/contract_wrappers/modules/module_factory_wrapper' ;
4
4
import { ApiConstructorParams , PolymathAPI } from '../src/PolymathAPI' ;
5
- import { bytes32ToString } from '../src/utils/convert' ;
6
5
import { FundRaiseType , ModuleName , ModuleType } from '../src' ;
7
6
8
7
// This file acts as a valid sandbox.ts file in root directory for adding a cappedSTO module on an unlocked node (like ganache)
@@ -20,9 +19,46 @@ window.addEventListener('load', async () => {
20
19
// Instantiate the API
21
20
const polymathAPI = new PolymathAPI ( params ) ;
22
21
23
- const ticker = 'TEST' ;
24
- const tokenAddress = await polymathAPI . securityTokenRegistry . getSecurityTokenAddress ( ticker ) ;
25
- const TEST = await polymathAPI . tokenFactory . getSecurityTokenInstanceFromAddress ( tokenAddress ) ;
22
+ // Get some poly tokens in your account and the security token
23
+ const myAddress = await polymathAPI . getAccount ( ) ;
24
+ await polymathAPI . getPolyTokens ( { amount : new BigNumber ( 1000000 ) , address : myAddress } ) ;
25
+
26
+ // Prompt to setup your ticker and token name
27
+ const ticker = prompt ( 'Ticker' , '' ) ;
28
+ const tokenName = prompt ( 'Token Name' , '' ) ;
29
+
30
+ // Double check available
31
+ await polymathAPI . securityTokenRegistry . isTickerAvailable ( {
32
+ ticker : ticker ! ,
33
+ } ) ;
34
+ // Get the ticker fee and approve the security token registry to spend
35
+ const tickerFee = await polymathAPI . securityTokenRegistry . getTickerRegistrationFee ( ) ;
36
+ await polymathAPI . polyToken . approve ( {
37
+ spender : await polymathAPI . securityTokenRegistry . address ( ) ,
38
+ value : tickerFee ,
39
+ } ) ;
40
+ // Register a ticker
41
+ await polymathAPI . securityTokenRegistry . registerTicker ( {
42
+ ticker : ticker ! ,
43
+ tokenName : tokenName ! ,
44
+ } ) ;
45
+ // Get the st launch fee and approve the security token registry to spend
46
+ const securityTokenLaunchFee = await polymathAPI . securityTokenRegistry . getSecurityTokenLaunchFee ( ) ;
47
+ await polymathAPI . polyToken . approve ( {
48
+ spender : await polymathAPI . securityTokenRegistry . address ( ) ,
49
+ value : securityTokenLaunchFee ,
50
+ } ) ;
51
+
52
+ await polymathAPI . securityTokenRegistry . generateNewSecurityToken ( {
53
+ name : tokenName ! ,
54
+ ticker : ticker ! ,
55
+ tokenDetails : 'details' ,
56
+ divisible : true ,
57
+ treasuryWallet : myAddress ,
58
+ protocolVersion : '0' ,
59
+ } ) ;
60
+
61
+ console . log ( 'Security Token Generated' ) ;
26
62
27
63
const moduleStringName = 'CappedSTO' ;
28
64
const moduleName = ModuleName . CappedSTO ;
@@ -43,17 +79,16 @@ window.addEventListener('load', async () => {
43
79
} ) ;
44
80
const resultNames = await Promise . all ( names ) ;
45
81
46
- const finalNames = resultNames . map ( name => {
47
- return bytes32ToString ( name ) ;
48
- } ) ;
49
- const index = finalNames . indexOf ( moduleStringName ) ;
82
+ const index = resultNames . indexOf ( moduleStringName ) ;
50
83
84
+ // Create a Security Token Instance
85
+ const tickerSecurityTokenInstance = await polymathAPI . tokenFactory . getSecurityTokenInstanceFromTicker ( ticker ! ) ;
51
86
const factory = await polymathAPI . moduleFactory . getModuleFactory ( modules [ index ] ) ;
52
87
const setupCost = await factory . setupCostInPoly ( ) ;
53
88
54
89
// Get some poly tokens on the security token instance
55
90
await polymathAPI . polyToken . transfer ( {
56
- to : await TEST . address ( ) ,
91
+ to : await tickerSecurityTokenInstance . address ( ) ,
57
92
value : setupCost ,
58
93
} ) ;
59
94
@@ -69,21 +104,72 @@ window.addEventListener('load', async () => {
69
104
} ,
70
105
} ) ;
71
106
72
- await TEST . addModule ( {
107
+ // Get General TM Address to whitelist transfers
108
+ const generalTMAddress = ( await tickerSecurityTokenInstance . getModulesByName ( {
109
+ moduleName : ModuleName . GeneralTransferManager ,
110
+ } ) ) [ 0 ] ;
111
+ const generalTM = await polymathAPI . moduleFactory . getModuleInstance ( {
112
+ name : ModuleName . GeneralTransferManager ,
113
+ address : generalTMAddress ,
114
+ } ) ;
115
+
116
+ await generalTM . modifyKYCData ( {
117
+ investor : myAddress ,
118
+ canSendAfter : new Date ( ) ,
119
+ canReceiveAfter : new Date ( ) ,
120
+ expiryTime : new Date ( 2020 , 0 ) ,
121
+ txData : {
122
+ from : await polymathAPI . getAccount ( ) ,
123
+ } ,
124
+ } ) ;
125
+
126
+ const startTime = new Date ( Date . now ( ) + 10000 ) ;
127
+ await tickerSecurityTokenInstance . addModule ( {
73
128
moduleName,
74
129
address : modules [ index ] ,
75
130
maxCost : setupCost ,
76
131
budget : setupCost ,
77
132
archived : false ,
78
133
data : {
79
- startTime : new Date ( ) ,
80
- endTime : new Date ( 2025 , 8 ) ,
134
+ startTime,
135
+ endTime : new Date ( 2031 , 1 ) ,
81
136
cap : new BigNumber ( 10 ) ,
82
137
rate : new BigNumber ( 10 ) ,
83
138
fundRaiseType : FundRaiseType . ETH . valueOf ( ) ,
84
139
fundsReceiver : await polymathAPI . getAccount ( ) ,
85
140
} ,
86
141
} ) ;
87
142
88
- TEST . unsubscribeAll ( ) ;
143
+ const cappedSTOAddress = ( await tickerSecurityTokenInstance . getModulesByName ( {
144
+ moduleName : ModuleName . CappedSTO ,
145
+ } ) ) [ 0 ] ;
146
+
147
+ const cappedSTO = await polymathAPI . moduleFactory . getModuleInstance ( {
148
+ name : ModuleName . CappedSTO ,
149
+ address : cappedSTOAddress ,
150
+ } ) ;
151
+
152
+ const sleep = ( milliseconds : number ) => {
153
+ console . log ( 'Sleeping until the STO starts' ) ;
154
+ return new Promise ( resolve => setTimeout ( resolve , milliseconds ) ) ;
155
+ } ;
156
+ await sleep ( 10000 ) ;
157
+
158
+ // Subscribe to event of update dividend dates
159
+ await cappedSTO . subscribeAsync ( {
160
+ eventName : CappedSTOEvents . TokenPurchase ,
161
+ indexFilterValues : { } ,
162
+ callback : async ( error , log ) => {
163
+ if ( error ) {
164
+ console . log ( error ) ;
165
+ } else {
166
+ console . log ( 'Token Purchased!' , log ) ;
167
+ }
168
+ } ,
169
+ } ) ;
170
+
171
+ await cappedSTO . buyTokens ( { beneficiary : await polymathAPI . getAccount ( ) , value : new BigNumber ( 1 ) } ) ;
172
+ console . log ( 'Buy Tokens has been called' ) ;
173
+
174
+ tickerSecurityTokenInstance . unsubscribeAll ( ) ;
89
175
} ) ;
0 commit comments