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

Commit 774b270

Browse files
author
Victor Wiebe
committed
fix: usdTieredSTO example overhaul and working
1 parent 5620da9 commit 774b270

File tree

1 file changed

+50
-18
lines changed

1 file changed

+50
-18
lines changed

examples/usdTieredSTO.ts

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

@@ -38,26 +37,25 @@ window.addEventListener('load', async () => {
3837
spender: await polymathAPI.securityTokenRegistry.address(),
3938
value: tickerFee,
4039
});
41-
4240
// Register a ticker
4341
await polymathAPI.securityTokenRegistry.registerTicker({
4442
ticker: ticker!,
4543
tokenName: tokenName!,
4644
});
47-
4845
// Get the st launch fee and approve the security token registry to spend
4946
const securityTokenLaunchFee = await polymathAPI.securityTokenRegistry.getSecurityTokenLaunchFee();
5047
await polymathAPI.polyToken.approve({
5148
spender: await polymathAPI.securityTokenRegistry.address(),
5249
value: securityTokenLaunchFee,
5350
});
5451

55-
// Generate a security token
56-
await polymathAPI.securityTokenRegistry.generateSecurityToken({
52+
await polymathAPI.securityTokenRegistry.generateNewSecurityToken({
5753
name: tokenName!,
5854
ticker: ticker!,
59-
details: 'http://',
60-
divisible: false,
55+
tokenDetails: 'details',
56+
divisible: true,
57+
treasuryWallet: myAddress,
58+
protocolVersion: '0',
6159
});
6260

6361
const moduleStringName = 'USDTieredSTO';
@@ -78,14 +76,10 @@ window.addEventListener('load', async () => {
7876
});
7977
const resultNames = await Promise.all(names);
8078

81-
const finalNames = resultNames.map(name => {
82-
return bytes32ToString(name);
83-
});
84-
const index = finalNames.indexOf(moduleStringName);
79+
const index = resultNames.indexOf(moduleStringName);
8580

8681
// Create a Security Token Instance
8782
const tickerSecurityTokenInstance = await polymathAPI.tokenFactory.getSecurityTokenInstanceFromTicker(ticker!);
88-
8983
const factory = await polymathAPI.moduleFactory.getModuleFactory(modules[index]);
9084
const setupCost = await factory.setupCostInPoly();
9185

@@ -94,15 +88,34 @@ window.addEventListener('load', async () => {
9488
value: setupCost,
9589
});
9690

97-
// Call to add module
91+
// Get General TM Address to whitelist transfers
92+
const generalTMAddress = (await tickerSecurityTokenInstance.getModulesByName({
93+
moduleName: ModuleName.GeneralTransferManager,
94+
}))[0];
95+
const generalTM = await polymathAPI.moduleFactory.getModuleInstance({
96+
name: ModuleName.GeneralTransferManager,
97+
address: generalTMAddress,
98+
});
99+
await generalTM.modifyKYCData({
100+
investor: myAddress,
101+
canSendAfter: new Date(),
102+
canReceiveAfter: new Date(),
103+
expiryTime: new Date(2020, 0),
104+
txData: {
105+
from: await polymathAPI.getAccount(),
106+
},
107+
});
108+
109+
// Call to add usd tiered sto module
110+
const startTime = new Date(Date.now() + 10000);
98111
const usdTieredResult = await tickerSecurityTokenInstance.addModule({
99112
moduleName,
100113
address: modules[index],
101114
maxCost: setupCost,
102115
budget: setupCost,
103116
archived: false,
104117
data: {
105-
startTime: new Date(2030, 1),
118+
startTime,
106119
endTime: new Date(2031, 1),
107120
ratePerTier: [new BigNumber(10), new BigNumber(10)],
108121
ratePerTierDiscountPoly: [new BigNumber(8), new BigNumber(9)],
@@ -117,16 +130,13 @@ window.addEventListener('load', async () => {
117130
},
118131
});
119132
console.log(usdTieredResult);
120-
121133
const usdTieredAddress = (await tickerSecurityTokenInstance.getModulesByName({
122134
moduleName: ModuleName.UsdTieredSTO,
123135
}))[0];
124136
const usdTiered = await polymathAPI.moduleFactory.getModuleInstance({
125137
name: ModuleName.UsdTieredSTO,
126138
address: usdTieredAddress,
127139
});
128-
const buyWithETH = await usdTiered.buyWithETH({ value: new BigNumber(1), beneficiary: myAddress });
129-
console.log(buyWithETH);
130140

131141
// Subscribe to event of update dividend dates
132142
await usdTiered.subscribeAsync({
@@ -136,7 +146,7 @@ window.addEventListener('load', async () => {
136146
if (error) {
137147
console.log(error);
138148
} else {
139-
console.log('Dividend Date Updated!', log);
149+
console.log('STO Tiers updated', log);
140150
}
141151
},
142152
});
@@ -149,5 +159,27 @@ window.addEventListener('load', async () => {
149159
tokensPerTierDiscountPoly: [new BigNumber(4), new BigNumber(4)],
150160
});
151161

162+
const sleep = (milliseconds: number) => {
163+
console.log('Sleeping until the STO starts');
164+
return new Promise(resolve => setTimeout(resolve, milliseconds))
165+
};
166+
await sleep(10000);
167+
168+
// Subscribe to event of update dividend dates
169+
await usdTiered.subscribeAsync({
170+
eventName: USDTieredSTOEvents.TokenPurchase,
171+
indexFilterValues: {},
172+
callback: async (error, log) => {
173+
if (error) {
174+
console.log(error);
175+
} else {
176+
console.log('Token Purchased!', log);
177+
}
178+
},
179+
});
180+
181+
await usdTiered.buyWithETH({ value: new BigNumber(1), beneficiary: myAddress });
182+
console.log('BuyWithETH complete');
183+
152184
usdTiered.unsubscribeAll();
153185
});

0 commit comments

Comments
 (0)