1
1
import { RedundantSubprovider , RPCSubprovider , Web3ProviderEngine } from '@0x/subproviders' ;
2
2
import { ERC20DividendCheckpointEvents , BigNumber } from '@polymathnetwork/abi-wrappers' ;
3
3
import { ApiConstructorParams , PolymathAPI } from '../src/PolymathAPI' ;
4
- import { bytes32ToString } from '../src/utils/convert' ;
5
4
import { ModuleName , ModuleType } from '../src' ;
6
5
import ModuleFactoryWrapper from '../src/contract_wrappers/modules/module_factory_wrapper' ;
7
6
8
- // This file acts as a valid sandbox for adding a etherDividend module on an unlocked node (like ganache)
7
+ // This file acts as a valid sandbox for adding a erc20Dividend module on an unlocked node (like ganache)
9
8
10
9
window . addEventListener ( 'load' , async ( ) => {
11
10
// Setup the redundant provider
@@ -21,30 +20,24 @@ window.addEventListener('load', async () => {
21
20
const polymathAPI = new PolymathAPI ( params ) ;
22
21
23
22
// Get some poly tokens in your account and the security token
24
- const myAddress = await polymathAPI . getAccount ( ) ;
25
- // Token faucet on test net only
23
+ const myAddress = ( await polymathAPI . getAccount ( ) ) . toLowerCase ( ) ;
26
24
await polymathAPI . getPolyTokens ( { amount : new BigNumber ( 1000000 ) , address : myAddress } ) ;
27
25
28
26
// Prompt to setup your ticker and token name
29
- const ticker = prompt ( 'Ticker' , '' ) ;
30
- const tokenName = prompt ( 'Token Name' , '' ) ;
31
-
32
- // Double check available
33
- await polymathAPI . securityTokenRegistry . isTickerAvailable ( {
34
- ticker : ticker ! ,
35
- } ) ;
27
+ const ticker = prompt ( 'ticker' , '' ) ;
28
+ const tokenName = prompt ( 'token name' , '' ) ;
36
29
37
30
// Get the ticker fee and approve the security token registry to spend
38
31
const tickerFee = await polymathAPI . securityTokenRegistry . getTickerRegistrationFee ( ) ;
39
32
await polymathAPI . polyToken . approve ( {
40
33
spender : await polymathAPI . securityTokenRegistry . address ( ) ,
41
34
value : tickerFee ,
42
35
} ) ;
43
-
44
36
// Register a ticker
45
- await polymathAPI . securityTokenRegistry . registerTicker ( {
37
+ console . log ( 'Ticker is:' + ticker ) ;
38
+ await polymathAPI . securityTokenRegistry . registerNewTicker ( {
39
+ owner : myAddress ,
46
40
ticker : ticker ! ,
47
- tokenName : tokenName ! ,
48
41
} ) ;
49
42
50
43
// Get the st launch fee and approve the security token registry to spend
@@ -55,13 +48,20 @@ window.addEventListener('load', async () => {
55
48
} ) ;
56
49
57
50
// Generate a security token
58
- await polymathAPI . securityTokenRegistry . generateSecurityToken ( {
51
+ await polymathAPI . securityTokenRegistry . generateNewSecurityToken ( {
59
52
name : tokenName ! ,
60
53
ticker : ticker ! ,
61
- details : 'http://' ,
62
- divisible : false ,
54
+ tokenDetails : 'details' ,
55
+ divisible : true ,
56
+ treasuryWallet : myAddress ,
57
+ protocolVersion : '0' ,
63
58
} ) ;
64
59
60
+ console . log ( 'Security token has been generated' ) ;
61
+
62
+ // Create a Security Token Instance
63
+ const tickerSecurityTokenInstance = await polymathAPI . tokenFactory . getSecurityTokenInstanceFromTicker ( ticker ! ) ;
64
+
65
65
const moduleStringName = 'ERC20DividendCheckpoint' ;
66
66
const moduleName = ModuleName . ERC20DividendCheckpoint ;
67
67
const modules = await polymathAPI . moduleRegistry . getModulesByType ( {
@@ -73,29 +73,17 @@ window.addEventListener('load', async () => {
73
73
instances . push ( polymathAPI . moduleFactory . getModuleFactory ( address ) ) ;
74
74
} ) ;
75
75
const resultInstances = await Promise . all ( instances ) ;
76
-
77
76
const names : Promise < string > [ ] = [ ] ;
78
77
resultInstances . map ( instanceFactory => {
79
78
names . push ( instanceFactory . name ( ) ) ;
80
79
} ) ;
81
80
const resultNames = await Promise . all ( names ) ;
82
-
83
- const finalNames = resultNames . map ( name => {
84
- return bytes32ToString ( name ) ;
85
- } ) ;
86
- const index = finalNames . indexOf ( moduleStringName ) ;
87
-
88
- // Create a Security Token Instance
89
- const tickerSecurityTokenInstance = await polymathAPI . tokenFactory . getSecurityTokenInstanceFromTicker ( ticker ! ) ;
81
+ const index = resultNames . indexOf ( moduleStringName ) ;
90
82
91
83
// Get setup cost
92
84
const factory = await polymathAPI . moduleFactory . getModuleFactory ( modules [ index ] ) ;
93
85
const setupCost = await factory . setupCostInPoly ( ) ;
94
86
95
- // Create 2 checkpoints
96
- await tickerSecurityTokenInstance . createCheckpoint ( { } ) ;
97
- await tickerSecurityTokenInstance . createCheckpoint ( { } ) ;
98
-
99
87
// Call to add etherdividend module
100
88
await tickerSecurityTokenInstance . addModule ( {
101
89
moduleName,
@@ -117,53 +105,99 @@ window.addEventListener('load', async () => {
117
105
name : ModuleName . ERC20DividendCheckpoint ,
118
106
address : erc20DividendAddress ,
119
107
} ) ;
120
- const erc20Dividend = ( await tickerSecurityTokenInstance . getModulesByName ( {
121
- moduleName : ModuleName . ERC20DividendCheckpoint ,
108
+
109
+ // Get General TM Address to whitelist transfers
110
+ const generalTMAddress = ( await tickerSecurityTokenInstance . getModulesByName ( {
111
+ moduleName : ModuleName . GeneralTransferManager ,
122
112
} ) ) [ 0 ] ;
113
+ const generalTM = await polymathAPI . moduleFactory . getModuleInstance ( {
114
+ name : ModuleName . GeneralTransferManager ,
115
+ address : generalTMAddress ,
116
+ } ) ;
117
+
118
+ // Add owner address in the whitelist to allow issue tokens
119
+ await generalTM . modifyKYCData ( {
120
+ investor : myAddress ,
121
+ canSendAfter : new Date ( ) ,
122
+ canReceiveAfter : new Date ( ) ,
123
+ expiryTime : new Date ( 2020 , 0 ) ,
124
+ txData : {
125
+ from : await polymathAPI . getAccount ( ) ,
126
+ } ,
127
+ } ) ;
128
+
129
+ // Mint yourself some tokens and make some transfers
130
+ await tickerSecurityTokenInstance . issue ( {
131
+ investor : myAddress ,
132
+ value : new BigNumber ( 50 ) ,
133
+ data : '0x00' ,
134
+ } ) ;
123
135
124
- await polymathAPI . polyToken . transfer ( { to : erc20Dividend , value : new BigNumber ( 5 ) } ) ;
125
136
await polymathAPI . polyToken . approve ( {
126
- spender : erc20Dividend ,
137
+ spender : erc20DividendAddress ,
127
138
value : new BigNumber ( 4 ) ,
128
139
} ) ;
129
140
141
+ const randomInvestors = [
142
+ '0x1111111111111111111111111111111111111111' ,
143
+ '0x2222222222222222222222222222222222222222' ,
144
+ '0x3333333333333333333333333333333333333333' ,
145
+ ] ;
146
+
147
+ // Add beneficiaries address to whitelist
148
+ await generalTM . modifyKYCDataMulti ( {
149
+ investors : randomInvestors ,
150
+ canSendAfter : [ new Date ( ) , new Date ( ) , new Date ( ) ] ,
151
+ canReceiveAfter : [ new Date ( ) , new Date ( ) , new Date ( ) ] ,
152
+ expiryTime : [ new Date ( 2020 , 0 ) , new Date ( 2020 , 0 ) , new Date ( 2020 , 0 ) ] ,
153
+ } ) ;
154
+
155
+ await tickerSecurityTokenInstance . transfer ( { to : randomInvestors [ 0 ] , value : new BigNumber ( 10 ) } ) ;
156
+ await tickerSecurityTokenInstance . transfer ( { to : randomInvestors [ 1 ] , value : new BigNumber ( 20 ) } ) ;
157
+ await tickerSecurityTokenInstance . transfer ( { to : randomInvestors [ 2 ] , value : new BigNumber ( 20 ) } ) ;
158
+
130
159
// Create Dividends
131
160
await erc20DividendCheckpoint . createDividendWithExclusions ( {
132
- name : 'MyDividend2 ' ,
161
+ name : 'MyDividend1 ' ,
133
162
amount : new BigNumber ( 1 ) ,
134
163
token : await polymathAPI . polyToken . address ( ) ,
135
164
expiry : new Date ( 2035 , 2 ) ,
136
165
maturity : new Date ( 2018 , 1 ) ,
137
- excluded : [ '0x1111111111111111111111111111111111111111' , '0x2222222222222222222222222222222222222222' ] ,
166
+ excluded : [ randomInvestors [ 1 ] , randomInvestors [ 2 ] ] ,
138
167
} ) ;
139
168
169
+ // Create a checkpoint
170
+ await tickerSecurityTokenInstance . createCheckpoint ( { } ) ;
171
+
140
172
await erc20DividendCheckpoint . createDividendWithCheckpointAndExclusions ( {
141
173
name : 'MyDividend2' ,
142
174
amount : new BigNumber ( 1 ) ,
143
175
token : await polymathAPI . polyToken . address ( ) ,
144
176
expiry : new Date ( 2035 , 2 ) ,
145
177
maturity : new Date ( 2018 , 1 ) ,
146
178
checkpointId : 1 ,
147
- excluded : [ '0x1111111111111111111111111111111111111111' , '0x2222222222222222222222222222222222222222' ] ,
179
+ excluded : [ randomInvestors [ 0 ] , randomInvestors [ 1 ] ] ,
148
180
} ) ;
149
181
150
182
await erc20DividendCheckpoint . createDividend ( {
151
- name : 'MyDividend ' ,
183
+ name : 'MyDividend3 ' ,
152
184
amount : new BigNumber ( 1 ) ,
153
185
token : await polymathAPI . polyToken . address ( ) ,
154
186
expiry : new Date ( 2035 , 2 ) ,
155
187
maturity : new Date ( 2018 , 1 ) ,
156
188
} ) ;
157
189
158
190
await erc20DividendCheckpoint . createDividendWithCheckpoint ( {
159
- name : 'MyDividend2 ' ,
191
+ name : 'MyDividend4 ' ,
160
192
amount : new BigNumber ( 1 ) ,
161
193
token : await polymathAPI . polyToken . address ( ) ,
162
194
expiry : new Date ( 2035 , 2 ) ,
163
195
maturity : new Date ( 2018 , 1 ) ,
164
- checkpointId : 0 ,
196
+ checkpointId : 1 ,
165
197
} ) ;
166
198
199
+ console . log ( '4 types of erc20 dividends created' ) ;
200
+
167
201
// Subscribe to event of update dividend dates
168
202
await erc20DividendCheckpoint . subscribeAsync ( {
169
203
eventName : ERC20DividendCheckpointEvents . UpdateDividendDates ,
@@ -179,10 +213,9 @@ window.addEventListener('load', async () => {
179
213
180
214
// Update dividend dates
181
215
await erc20DividendCheckpoint . updateDividendDates ( {
182
- dividendIndex : 0 ,
216
+ dividendIndex : 1 ,
183
217
expiry : new Date ( 2038 , 2 ) ,
184
218
maturity : new Date ( 2037 , 4 ) ,
185
219
} ) ;
186
-
187
220
erc20DividendCheckpoint . unsubscribeAll ( ) ;
188
221
} ) ;
0 commit comments