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

Commit e3d9242

Browse files
author
Victor Wiebe
committed
fix: examples sto, dividends review issues
1 parent 434e953 commit e3d9242

File tree

4 files changed

+33
-48
lines changed

4 files changed

+33
-48
lines changed

examples/cappedSTO.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { RedundantSubprovider, RPCSubprovider, Web3ProviderEngine } from '@0x/su
22
import { ModuleRegistryEvents, BigNumber, CappedSTOEvents } from '@polymathnetwork/abi-wrappers';
33
import ModuleFactoryWrapper from '../src/contract_wrappers/modules/module_factory_wrapper';
44
import { ApiConstructorParams, PolymathAPI } from '../src/PolymathAPI';
5-
import { FundRaiseType, ModuleName, ModuleType } from '../src';
5+
import { CappedSTOFundRaiseType, ModuleName, ModuleType } from '../src';
66

77
// This file acts as a valid sandbox.ts file in root directory for adding a cappedSTO module on an unlocked node (like ganache)
88

@@ -60,7 +60,6 @@ window.addEventListener('load', async () => {
6060

6161
console.log('Security Token Generated');
6262

63-
const moduleStringName = 'CappedSTO';
6463
const moduleName = ModuleName.CappedSTO;
6564

6665
const modules = await polymathAPI.moduleRegistry.getModulesByType({
@@ -79,7 +78,7 @@ window.addEventListener('load', async () => {
7978
});
8079
const resultNames = await Promise.all(names);
8180

82-
const index = resultNames.indexOf(moduleStringName);
81+
const index = resultNames.indexOf(moduleName);
8382

8483
// Create a Security Token Instance
8584
const tickerSecurityTokenInstance = await polymathAPI.tokenFactory.getSecurityTokenInstanceFromTicker(ticker!);
@@ -104,7 +103,7 @@ window.addEventListener('load', async () => {
104103
},
105104
});
106105

107-
// Get General TM Address to whitelist transfers
106+
// Get General Transfer Manager to whitelist an address to buy tokens
108107
const generalTMAddress = (await tickerSecurityTokenInstance.getModulesByName({
109108
moduleName: ModuleName.GeneralTransferManager,
110109
}))[0];
@@ -135,7 +134,7 @@ window.addEventListener('load', async () => {
135134
endTime: new Date(2031, 1),
136135
cap: new BigNumber(10),
137136
rate: new BigNumber(10),
138-
fundRaiseType: FundRaiseType.ETH.valueOf(),
137+
fundRaiseType: CappedSTOFundRaiseType.ETH,
139138
fundsReceiver: await polymathAPI.getAccount(),
140139
},
141140
});
@@ -155,7 +154,7 @@ window.addEventListener('load', async () => {
155154
};
156155
await sleep(10000);
157156

158-
// Subscribe to event of update dividend dates
157+
// Subscribe to event of token purchase
159158
await cappedSTO.subscribeAsync({
160159
eventName: CappedSTOEvents.TokenPurchase,
161160
indexFilterValues: {},

examples/erc20Dividend.ts

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ApiConstructorParams, PolymathAPI } from '../src/PolymathAPI';
44
import { ModuleName, ModuleType } from '../src';
55
import ModuleFactoryWrapper from '../src/contract_wrappers/modules/module_factory_wrapper';
66

7-
// This file acts as a valid sandbox for adding a erc20Dividend 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)
88

99
window.addEventListener('load', async () => {
1010
// Setup the redundant provider
@@ -62,7 +62,6 @@ window.addEventListener('load', async () => {
6262
// Create a Security Token Instance
6363
const tickerSecurityTokenInstance = await polymathAPI.tokenFactory.getSecurityTokenInstanceFromTicker(ticker!);
6464

65-
const moduleStringName = 'ERC20DividendCheckpoint';
6665
const moduleName = ModuleName.ERC20DividendCheckpoint;
6766
const modules = await polymathAPI.moduleRegistry.getModulesByType({
6867
moduleType: ModuleType.Dividends,
@@ -78,13 +77,13 @@ window.addEventListener('load', async () => {
7877
names.push(instanceFactory.name());
7978
});
8079
const resultNames = await Promise.all(names);
81-
const index = resultNames.indexOf(moduleStringName);
80+
const index = resultNames.indexOf(moduleName);
8281

8382
// Get setup cost
8483
const factory = await polymathAPI.moduleFactory.getModuleFactory(modules[index]);
8584
const setupCost = await factory.setupCostInPoly();
8685

87-
// Call to add etherdividend module
86+
// Call to add erc20 dividend module
8887
await tickerSecurityTokenInstance.addModule({
8988
moduleName,
9089
address: modules[index],
@@ -96,7 +95,7 @@ window.addEventListener('load', async () => {
9695
},
9796
});
9897

99-
// Get module for ether dividend checkpoint and address for module
98+
// Get module for erc20 dividend checkpoint and address for module
10099
const erc20DividendAddress = (await tickerSecurityTokenInstance.getModulesByName({
101100
moduleName: ModuleName.ERC20DividendCheckpoint,
102101
}))[0];
@@ -115,24 +114,6 @@ window.addEventListener('load', async () => {
115114
address: generalTMAddress,
116115
});
117116

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-
});
135-
136117
await polymathAPI.polyToken.approve({
137118
spender: erc20DividendAddress,
138119
value: new BigNumber(4),
@@ -152,11 +133,14 @@ window.addEventListener('load', async () => {
152133
expiryTime: [new Date(2020, 0), new Date(2020, 0), new Date(2020, 0)],
153134
});
154135

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) });
136+
// Mint yourself some tokens and make some transfers
137+
await tickerSecurityTokenInstance.issueMulti({
138+
investors: randomInvestors,
139+
values: [new BigNumber(10), new BigNumber(20), new BigNumber(20)],
140+
});
158141

159142
// Create Dividends
143+
// A checkpoint is created behind the scenes
160144
await erc20DividendCheckpoint.createDividendWithExclusions({
161145
name: 'MyDividend1',
162146
amount: new BigNumber(1),
@@ -166,9 +150,10 @@ window.addEventListener('load', async () => {
166150
excluded: [randomInvestors[1], randomInvestors[2]],
167151
});
168152

169-
// Create a checkpoint
153+
// Create another checkpoint
170154
await tickerSecurityTokenInstance.createCheckpoint({});
171155

156+
// Using the most recent checkpoint
172157
await erc20DividendCheckpoint.createDividendWithCheckpointAndExclusions({
173158
name: 'MyDividend2',
174159
amount: new BigNumber(1),
@@ -187,13 +172,14 @@ window.addEventListener('load', async () => {
187172
maturity: new Date(2018, 1),
188173
});
189174

175+
// Another checkpoint was created behind the scenes
190176
await erc20DividendCheckpoint.createDividendWithCheckpoint({
191177
name: 'MyDividend4',
192178
amount: new BigNumber(1),
193179
token: await polymathAPI.polyToken.address(),
194180
expiry: new Date(2035, 2),
195181
maturity: new Date(2018, 1),
196-
checkpointId: 1,
182+
checkpointId: 2,
197183
});
198184

199185
console.log('4 types of erc20 dividends created');

examples/etherDividend.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { RedundantSubprovider, RPCSubprovider, Web3ProviderEngine } from '@0x/subproviders';
22
import { EtherDividendCheckpointEvents, 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 etherDividend module on an unlocked node (like ganache)
98

109
window.addEventListener('load', async () => {
1110
// Setup the redundant provider
@@ -21,7 +20,7 @@ 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()).toLowerCase();
23+
const myAddress = await polymathAPI.getAccount();
2524
await polymathAPI.getPolyTokens({ amount: new BigNumber(1000000), address: myAddress });
2625
// Prompt to setup your ticker and token name
2726
const ticker = prompt('Ticker', '');
@@ -68,7 +67,6 @@ window.addEventListener('load', async () => {
6867
// Create a Security Token Instance
6968
const tickerSecurityTokenInstance = await polymathAPI.tokenFactory.getSecurityTokenInstanceFromTicker(ticker!);
7069

71-
const moduleStringName = 'EtherDividendCheckpoint';
7270
const moduleName = ModuleName.EtherDividendCheckpoint;
7371
const modules = await polymathAPI.moduleRegistry.getModulesByType({
7472
moduleType: ModuleType.Dividends,
@@ -85,7 +83,7 @@ window.addEventListener('load', async () => {
8583
names.push(instanceFactory.name());
8684
});
8785
const resultNames = await Promise.all(names);
88-
const index = resultNames.indexOf(moduleStringName);
86+
const index = resultNames.indexOf(moduleName);
8987

9088
// Get setup cost
9189
const factory = await polymathAPI.moduleFactory.getModuleFactory(modules[index]);
@@ -159,6 +157,7 @@ window.addEventListener('load', async () => {
159157
await tickerSecurityTokenInstance.transfer({ to: randomInvestors[2], value: new BigNumber(20) });
160158

161159
// Create Dividends
160+
// A checkpoint is created behind the scenes.
162161
await etherDividendCheckpoint.createDividendWithExclusions({
163162
name: 'MyDividend1',
164163
value: new BigNumber(1),
@@ -167,9 +166,10 @@ window.addEventListener('load', async () => {
167166
excluded: [randomInvestors[1], randomInvestors[2]],
168167
});
169168

170-
// Create a checkpoint
169+
// Create another checkpoint
171170
await tickerSecurityTokenInstance.createCheckpoint({});
172171

172+
// Using the most recent checkpoint
173173
await etherDividendCheckpoint.createDividendWithCheckpointAndExclusions({
174174
name: 'MyDividend2',
175175
value: new BigNumber(1),
@@ -186,12 +186,13 @@ window.addEventListener('load', async () => {
186186
maturity: new Date(2018, 1),
187187
});
188188

189+
// Another checkpoint was created behind the scenes.
189190
await etherDividendCheckpoint.createDividendWithCheckpoint({
190191
name: 'MyDividend4',
191192
value: new BigNumber(1),
192193
expiry: new Date(2035, 2),
193194
maturity: new Date(2018, 1),
194-
checkpointId: 1,
195+
checkpointId: 2,
195196
});
196197

197198
console.log('4 types of ether dividends created');

examples/usdTieredSTO.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ window.addEventListener('load', async () => {
5858
protocolVersion: '0',
5959
});
6060

61-
const moduleStringName = 'USDTieredSTO';
6261
const moduleName = ModuleName.UsdTieredSTO;
6362
const modules = await polymathAPI.moduleRegistry.getModulesByType({
6463
moduleType: ModuleType.STO,
@@ -76,7 +75,7 @@ window.addEventListener('load', async () => {
7675
});
7776
const resultNames = await Promise.all(names);
7877

79-
const index = resultNames.indexOf(moduleStringName);
78+
const index = resultNames.indexOf(moduleName);
8079

8180
// Create a Security Token Instance
8281
const tickerSecurityTokenInstance = await polymathAPI.tokenFactory.getSecurityTokenInstanceFromTicker(ticker!);
@@ -88,7 +87,7 @@ window.addEventListener('load', async () => {
8887
value: setupCost,
8988
});
9089

91-
// Get General TM Address to whitelist transfers
90+
// Get General Transfer Manager to whitelist an address to buy tokens
9291
const generalTMAddress = (await tickerSecurityTokenInstance.getModulesByName({
9392
moduleName: ModuleName.GeneralTransferManager,
9493
}))[0];
@@ -138,7 +137,7 @@ window.addEventListener('load', async () => {
138137
address: usdTieredAddress,
139138
});
140139

141-
// Subscribe to event of update dividend dates
140+
// Subscribe to event for setTiers
142141
await usdTiered.subscribeAsync({
143142
eventName: USDTieredSTOEvents.SetTiers,
144143
indexFilterValues: {},
@@ -151,7 +150,7 @@ window.addEventListener('load', async () => {
151150
},
152151
});
153152

154-
// Update dividend dates
153+
// Update USDTiered STO Tiers
155154
await usdTiered.modifyTiers({
156155
ratePerTier: [new BigNumber(5), new BigNumber(5)],
157156
ratePerTierDiscountPoly: [new BigNumber(4), new BigNumber(4)],
@@ -161,11 +160,11 @@ window.addEventListener('load', async () => {
161160

162161
const sleep = (milliseconds: number) => {
163162
console.log('Sleeping until the STO starts');
164-
return new Promise(resolve => setTimeout(resolve, milliseconds))
163+
return new Promise(resolve => setTimeout(resolve, milliseconds));
165164
};
166165
await sleep(10000);
167166

168-
// Subscribe to event of update dividend dates
167+
// Subscribe to event for token purchase
169168
await usdTiered.subscribeAsync({
170169
eventName: USDTieredSTOEvents.TokenPurchase,
171170
indexFilterValues: {},

0 commit comments

Comments
 (0)