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

Commit 651c588

Browse files
committed
fix: 🐛 CTM example now works!
1 parent ce9525b commit 651c588

File tree

1 file changed

+60
-25
lines changed

1 file changed

+60
-25
lines changed

examples/countTransferManager.ts

Lines changed: 60 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ window.addEventListener('load', async () => {
4141
});
4242

4343
// Register a ticker
44-
await polymathAPI.securityTokenRegistry.registerTicker({
44+
await polymathAPI.securityTokenRegistry.registerNewTicker({
45+
owner: myAddress,
4546
ticker: ticker!,
46-
tokenName: tokenName!,
4747
});
4848

4949
// Get the st launch fee and approve the security token registry to spend
@@ -54,11 +54,13 @@ window.addEventListener('load', async () => {
5454
});
5555

5656
// Generate a security token
57-
await polymathAPI.securityTokenRegistry.generateSecurityToken({
57+
await polymathAPI.securityTokenRegistry.generateNewSecurityToken({
5858
name: tokenName!,
5959
ticker: ticker!,
60-
details: 'http://',
61-
divisible: false,
60+
tokenDetails: 'http://',
61+
divisible: true,
62+
treasuryWallet: myAddress,
63+
protocolVersion: '0',
6264
});
6365

6466
// Create a Security Token Instance
@@ -82,16 +84,17 @@ window.addEventListener('load', async () => {
8284
names.push(instanceFactory.name());
8385
});
8486
const resultNames = await Promise.all(names);
85-
86-
const finalNames = resultNames.map(name => {
87-
return bytes32ToString(name);
88-
});
89-
const index = finalNames.indexOf(moduleStringName);
87+
const index = resultNames.indexOf(moduleStringName);
9088

9189
// Get setup cost
9290
const factory = await polymathAPI.moduleFactory.getModuleFactory(modules[index]);
9391
const setupCost = await factory.setupCostInPoly();
9492

93+
const randomBeneficiaries = [
94+
'0x3444444444444444444444444444444444444444',
95+
'0x5544444444444444444444444444444444444444',
96+
];
97+
9598
// Call to add count transfer manager module with max 3 holders
9699
await tickerSecurityTokenInstance.addModule({
97100
moduleName,
@@ -100,15 +103,14 @@ window.addEventListener('load', async () => {
100103
budget: setupCost,
101104
archived: false,
102105
data: {
103-
maxHolderCount: 3,
106+
maxHolderCount: randomBeneficiaries.length + 1,
104107
},
105108
});
106109

107110
// Get Count TM address and create count transfer manager
108111
const countTMAddress = (await tickerSecurityTokenInstance.getModulesByName({
109112
moduleName: ModuleName.CountTransferManager,
110113
}))[0];
111-
console.log(countTMAddress);
112114
const countTM = await polymathAPI.moduleFactory.getModuleInstance({
113115
name: ModuleName.CountTransferManager,
114116
address: countTMAddress,
@@ -122,18 +124,36 @@ window.addEventListener('load', async () => {
122124
name: ModuleName.GeneralTransferManager,
123125
address: generalTMAddress,
124126
});
125-
// await generalTM.changeAllowAllTransfers({ allowAllTransfers: true });
126127

127-
const randomBeneficiary1 = '0x3444444444444444444444444444444444444444';
128-
const randomBeneficiary2 = '0x5544444444444444444444444444444444444444';
129-
const randomBeneficiary3 = '0x6644444444444444444444444444444444444444';
128+
// Add owner address in the whitelist to allow mint tokens
129+
await generalTM.modifyKYCData({
130+
investor: myAddress,
131+
canSendAfter: new Date(),
132+
canReceiveAfter: new Date(),
133+
expiryTime: new Date(2020, 0),
134+
txData: {
135+
from: await polymathAPI.getAccount(),
136+
},
137+
});
130138

131139
// Mint yourself some tokens and make some transfers
132-
await tickerSecurityTokenInstance.issue({ investor: myAddress, value: new BigNumber(200), data: '' });
133-
await tickerSecurityTokenInstance.transfer({ to: randomBeneficiary1, value: new BigNumber(10) });
134-
await tickerSecurityTokenInstance.transfer({ to: randomBeneficiary2, value: new BigNumber(20) });
140+
await tickerSecurityTokenInstance.issue({
141+
investor: myAddress,
142+
value: new BigNumber(200),
143+
data: '0x00',
144+
});
145+
146+
// Add beneficiaries address to whitelist
147+
await generalTM.modifyKYCDataMulti({
148+
investors: randomBeneficiaries,
149+
canSendAfter: [new Date(), new Date()],
150+
canReceiveAfter: [new Date(), new Date()],
151+
expiryTime: [new Date(2020, 0), new Date(2020, 0)],
152+
});
153+
154+
await tickerSecurityTokenInstance.transfer({ to: randomBeneficiaries[0], value: new BigNumber(10) });
155+
await tickerSecurityTokenInstance.transfer({ to: randomBeneficiaries[1], value: new BigNumber(20) });
135156

136-
// We need to increase max holder account to get another transfer through (We are currently at max)
137157
// Subscribe to event of modify holder count
138158
await countTM.subscribeAsync({
139159
eventName: CountTransferManagerEvents.ModifyHolderCount,
@@ -146,13 +166,28 @@ window.addEventListener('load', async () => {
146166
}
147167
},
148168
});
149-
await countTM.changeHolderCount({ maxHolderCount: 4 });
150-
await tickerSecurityTokenInstance.transfer({ to: randomBeneficiary3, value: new BigNumber(30) });
169+
170+
// We need to increase max holder account to get another transfer through (We are currently at max)
171+
randomBeneficiaries.push('0x6644444444444444444444444444444444444444');
172+
await countTM.changeHolderCount({ maxHolderCount: randomBeneficiaries.length + 1 });
173+
174+
// And adding to our whitelist
175+
await generalTM.modifyKYCData({
176+
investor: randomBeneficiaries[2],
177+
canSendAfter: new Date(),
178+
canReceiveAfter: new Date(),
179+
expiryTime: new Date(2020, 0),
180+
txData: {
181+
from: await polymathAPI.getAccount(),
182+
},
183+
});
184+
185+
await tickerSecurityTokenInstance.transfer({ to: randomBeneficiaries[2], value: new BigNumber(30) });
151186

152187
// Show the balances of our token holders
153-
console.log(await tickerSecurityTokenInstance.balanceOf({ owner: randomBeneficiary1 }));
154-
console.log(await tickerSecurityTokenInstance.balanceOf({ owner: randomBeneficiary2 }));
155-
console.log(await tickerSecurityTokenInstance.balanceOf({ owner: randomBeneficiary3 }));
188+
console.log(await tickerSecurityTokenInstance.balanceOf({ owner: randomBeneficiaries[0] }));
189+
console.log(await tickerSecurityTokenInstance.balanceOf({ owner: randomBeneficiaries[1] }));
190+
console.log(await tickerSecurityTokenInstance.balanceOf({ owner: randomBeneficiaries[2] }));
156191
console.log(await tickerSecurityTokenInstance.balanceOf({ owner: myAddress }));
157192

158193
console.log('Funds transferred');

0 commit comments

Comments
 (0)