Skip to content
This repository was archived by the owner on Jul 6, 2022. It is now read-only.

Commit 759b9a1

Browse files
author
Victor Wiebe
committed
fix: erc20Dividend example conform to new wrappers
1 parent 85668f2 commit 759b9a1

File tree

1 file changed

+75
-42
lines changed

1 file changed

+75
-42
lines changed

examples/erc20Dividend.ts

Lines changed: 75 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { RedundantSubprovider, RPCSubprovider, Web3ProviderEngine } from '@0x/subproviders';
22
import { ERC20DividendCheckpointEvents, BigNumber } from '@polymathnetwork/abi-wrappers';
33
import { ApiConstructorParams, PolymathAPI } from '../src/PolymathAPI';
4-
import { bytes32ToString } from '../src/utils/convert';
54
import { ModuleName, ModuleType } from '../src';
65
import ModuleFactoryWrapper from '../src/contract_wrappers/modules/module_factory_wrapper';
76

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)
98

109
window.addEventListener('load', async () => {
1110
// Setup the redundant provider
@@ -21,30 +20,24 @@ window.addEventListener('load', async () => {
2120
const polymathAPI = new PolymathAPI(params);
2221

2322
// 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();
2624
await polymathAPI.getPolyTokens({ amount: new BigNumber(1000000), address: myAddress });
2725

2826
// 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', '');
3629

3730
// Get the ticker fee and approve the security token registry to spend
3831
const tickerFee = await polymathAPI.securityTokenRegistry.getTickerRegistrationFee();
3932
await polymathAPI.polyToken.approve({
4033
spender: await polymathAPI.securityTokenRegistry.address(),
4134
value: tickerFee,
4235
});
43-
4436
// Register a ticker
45-
await polymathAPI.securityTokenRegistry.registerTicker({
37+
console.log('Ticker is:' + ticker);
38+
await polymathAPI.securityTokenRegistry.registerNewTicker({
39+
owner: myAddress,
4640
ticker: ticker!,
47-
tokenName: tokenName!,
4841
});
4942

5043
// Get the st launch fee and approve the security token registry to spend
@@ -55,13 +48,20 @@ window.addEventListener('load', async () => {
5548
});
5649

5750
// Generate a security token
58-
await polymathAPI.securityTokenRegistry.generateSecurityToken({
51+
await polymathAPI.securityTokenRegistry.generateNewSecurityToken({
5952
name: tokenName!,
6053
ticker: ticker!,
61-
details: 'http://',
62-
divisible: false,
54+
tokenDetails: 'details',
55+
divisible: true,
56+
treasuryWallet: myAddress,
57+
protocolVersion: '0',
6358
});
6459

60+
console.log('Security token has been generated');
61+
62+
// Create a Security Token Instance
63+
const tickerSecurityTokenInstance = await polymathAPI.tokenFactory.getSecurityTokenInstanceFromTicker(ticker!);
64+
6565
const moduleStringName = 'ERC20DividendCheckpoint';
6666
const moduleName = ModuleName.ERC20DividendCheckpoint;
6767
const modules = await polymathAPI.moduleRegistry.getModulesByType({
@@ -73,29 +73,17 @@ window.addEventListener('load', async () => {
7373
instances.push(polymathAPI.moduleFactory.getModuleFactory(address));
7474
});
7575
const resultInstances = await Promise.all(instances);
76-
7776
const names: Promise<string>[] = [];
7877
resultInstances.map(instanceFactory => {
7978
names.push(instanceFactory.name());
8079
});
8180
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);
9082

9183
// Get setup cost
9284
const factory = await polymathAPI.moduleFactory.getModuleFactory(modules[index]);
9385
const setupCost = await factory.setupCostInPoly();
9486

95-
// Create 2 checkpoints
96-
await tickerSecurityTokenInstance.createCheckpoint({});
97-
await tickerSecurityTokenInstance.createCheckpoint({});
98-
9987
// Call to add etherdividend module
10088
await tickerSecurityTokenInstance.addModule({
10189
moduleName,
@@ -117,53 +105,99 @@ window.addEventListener('load', async () => {
117105
name: ModuleName.ERC20DividendCheckpoint,
118106
address: erc20DividendAddress,
119107
});
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,
122112
}))[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+
});
123135

124-
await polymathAPI.polyToken.transfer({ to: erc20Dividend, value: new BigNumber(5) });
125136
await polymathAPI.polyToken.approve({
126-
spender: erc20Dividend,
137+
spender: erc20DividendAddress,
127138
value: new BigNumber(4),
128139
});
129140

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+
130159
// Create Dividends
131160
await erc20DividendCheckpoint.createDividendWithExclusions({
132-
name: 'MyDividend2',
161+
name: 'MyDividend1',
133162
amount: new BigNumber(1),
134163
token: await polymathAPI.polyToken.address(),
135164
expiry: new Date(2035, 2),
136165
maturity: new Date(2018, 1),
137-
excluded: ['0x1111111111111111111111111111111111111111', '0x2222222222222222222222222222222222222222'],
166+
excluded: [randomInvestors[1], randomInvestors[2]],
138167
});
139168

169+
// Create a checkpoint
170+
await tickerSecurityTokenInstance.createCheckpoint({});
171+
140172
await erc20DividendCheckpoint.createDividendWithCheckpointAndExclusions({
141173
name: 'MyDividend2',
142174
amount: new BigNumber(1),
143175
token: await polymathAPI.polyToken.address(),
144176
expiry: new Date(2035, 2),
145177
maturity: new Date(2018, 1),
146178
checkpointId: 1,
147-
excluded: ['0x1111111111111111111111111111111111111111', '0x2222222222222222222222222222222222222222'],
179+
excluded: [randomInvestors[0], randomInvestors[1]],
148180
});
149181

150182
await erc20DividendCheckpoint.createDividend({
151-
name: 'MyDividend',
183+
name: 'MyDividend3',
152184
amount: new BigNumber(1),
153185
token: await polymathAPI.polyToken.address(),
154186
expiry: new Date(2035, 2),
155187
maturity: new Date(2018, 1),
156188
});
157189

158190
await erc20DividendCheckpoint.createDividendWithCheckpoint({
159-
name: 'MyDividend2',
191+
name: 'MyDividend4',
160192
amount: new BigNumber(1),
161193
token: await polymathAPI.polyToken.address(),
162194
expiry: new Date(2035, 2),
163195
maturity: new Date(2018, 1),
164-
checkpointId: 0,
196+
checkpointId: 1,
165197
});
166198

199+
console.log('4 types of erc20 dividends created');
200+
167201
// Subscribe to event of update dividend dates
168202
await erc20DividendCheckpoint.subscribeAsync({
169203
eventName: ERC20DividendCheckpointEvents.UpdateDividendDates,
@@ -179,10 +213,9 @@ window.addEventListener('load', async () => {
179213

180214
// Update dividend dates
181215
await erc20DividendCheckpoint.updateDividendDates({
182-
dividendIndex: 0,
216+
dividendIndex: 1,
183217
expiry: new Date(2038, 2),
184218
maturity: new Date(2037, 4),
185219
});
186-
187220
erc20DividendCheckpoint.unsubscribeAll();
188221
});

0 commit comments

Comments
 (0)