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

Commit 4515e6d

Browse files
author
Victor Wiebe
committed
fix: percentageTransferManager fixes example
1 parent da322d5 commit 4515e6d

File tree

1 file changed

+123
-12
lines changed

1 file changed

+123
-12
lines changed

examples/percentageTransferManager.ts

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

87
// This file acts as a valid sandbox for using a percentage restriction transfer manager module on an unlocked node (like ganache)
98
window.addEventListener('load', async () => {
@@ -16,15 +15,52 @@ window.addEventListener('load', async () => {
1615
polymathRegistryAddress: '<Deployed Polymath Registry address>',
1716
};
1817

19-
// Instantiate the API
18+
// Instantiate the API
2019
const polymathAPI = new PolymathAPI(params);
2120

22-
const ticker = 'TEST';
23-
const tickerSecurityTokenInstance = await polymathAPI.tokenFactory.getSecurityTokenInstanceFromTicker(ticker);
24-
const moduleStringName = 'PercentageTransferManager';
21+
// Get some poly tokens in your account and the security token
22+
const myAddress = await polymathAPI.getAccount();
23+
await polymathAPI.getPolyTokens({ amount: new BigNumber(1000000), address: myAddress });
24+
25+
// Prompt to setup your ticker and token name
26+
const ticker = prompt('Ticker', '');
27+
const tokenName = prompt('Token Name', '');
28+
29+
// Double check available
30+
await polymathAPI.securityTokenRegistry.isTickerAvailable({
31+
ticker: ticker!,
32+
});
33+
// Get the ticker fee and approve the security token registry to spend
34+
const tickerFee = await polymathAPI.securityTokenRegistry.getTickerRegistrationFee();
35+
await polymathAPI.polyToken.approve({
36+
spender: await polymathAPI.securityTokenRegistry.address(),
37+
value: tickerFee,
38+
});
39+
// Register a ticker
40+
await polymathAPI.securityTokenRegistry.registerTicker({
41+
ticker: ticker!,
42+
tokenName: tokenName!,
43+
});
44+
// Get the st launch fee and approve the security token registry to spend
45+
const securityTokenLaunchFee = await polymathAPI.securityTokenRegistry.getSecurityTokenLaunchFee();
46+
await polymathAPI.polyToken.approve({
47+
spender: await polymathAPI.securityTokenRegistry.address(),
48+
value: securityTokenLaunchFee,
49+
});
50+
51+
await polymathAPI.securityTokenRegistry.generateNewSecurityToken({
52+
name: tokenName!,
53+
ticker: ticker!,
54+
tokenDetails: 'details',
55+
divisible: true,
56+
treasuryWallet: myAddress,
57+
protocolVersion: '0',
58+
});
59+
60+
console.log('Security Token Generated');
61+
2562
const moduleName = ModuleName.PercentageTransferManager;
2663

27-
// Get permission manager factory address
2864
const modules = await polymathAPI.moduleRegistry.getModulesByType({
2965
moduleType: ModuleType.TransferManager,
3066
});
@@ -41,19 +77,94 @@ window.addEventListener('load', async () => {
4177
});
4278
const resultNames = await Promise.all(names);
4379

44-
const finalNames = resultNames.map(name => {
45-
return bytes32ToString(name);
80+
const index = resultNames.indexOf(moduleName);
81+
82+
// Create a Security Token Instance
83+
const tickerSecurityTokenInstance = await polymathAPI.tokenFactory.getSecurityTokenInstanceFromTicker(ticker!);
84+
const factory = await polymathAPI.moduleFactory.getModuleFactory(modules[index]);
85+
const setupCost = await factory.setupCostInPoly();
86+
87+
await polymathAPI.moduleRegistry.subscribeAsync({
88+
eventName: ModuleRegistryEvents.ModuleRegistered,
89+
indexFilterValues: {},
90+
callback: async (error, log) => {
91+
if (error) {
92+
console.log(error);
93+
} else {
94+
console.log('Module added!', log);
95+
}
96+
},
97+
});
98+
99+
// Get General TM Address to whitelist transfers
100+
const generalTMAddress = (await tickerSecurityTokenInstance.getModulesByName({
101+
moduleName: ModuleName.GeneralTransferManager,
102+
}))[0];
103+
const generalTM = await polymathAPI.moduleFactory.getModuleInstance({
104+
name: ModuleName.GeneralTransferManager,
105+
address: generalTMAddress,
106+
});
107+
108+
await generalTM.modifyKYCData({
109+
investor: myAddress,
110+
canSendAfter: new Date(),
111+
canReceiveAfter: new Date(),
112+
expiryTime: new Date(2020, 0),
113+
txData: {
114+
from: await polymathAPI.getAccount(),
115+
},
46116
});
47-
const index = finalNames.indexOf(moduleStringName);
48117

49-
// Call to add module
50118
await tickerSecurityTokenInstance.addModule({
51119
moduleName,
52120
address: modules[index],
53121
data: {
54-
maxHolderPercentage: new BigNumber(10),
122+
maxHolderPercentage: new BigNumber(50),
55123
allowPrimaryIssuance: true,
56124
},
57125
archived: false,
58126
});
127+
128+
const percentageTMAddress = (await tickerSecurityTokenInstance.getModulesByName({
129+
moduleName: ModuleName.PercentageTransferManager,
130+
}))[0];
131+
132+
const percentageTM = await polymathAPI.moduleFactory.getModuleInstance({
133+
name: ModuleName.PercentageTransferManager,
134+
address: percentageTMAddress,
135+
});
136+
137+
// Subscribe to event of setAllowPrimaryIssuance
138+
await percentageTM.subscribeAsync({
139+
eventName: PercentageTransferManagerEvents.SetAllowPrimaryIssuance,
140+
indexFilterValues: {},
141+
callback: async (error, log) => {
142+
if (error) {
143+
console.log(error);
144+
} else {
145+
console.log('AllowPrimaryIssuance has been set', log);
146+
}
147+
},
148+
});
149+
150+
const randomBeneficiary = '0x0123456789012345678901234567890123456789';
151+
152+
await generalTM.modifyKYCDataMulti({
153+
investors: [myAddress, randomBeneficiary],
154+
canReceiveAfter: [new Date(), new Date()],
155+
canSendAfter: [new Date(), new Date()],
156+
expiryTime: [new Date(2035, 1), new Date(2035, 1)],
157+
});
158+
159+
await tickerSecurityTokenInstance.issueMulti({
160+
investors: [myAddress, randomBeneficiary],
161+
values: [new BigNumber(10), new BigNumber(10)],
162+
});
163+
164+
await percentageTM.setAllowPrimaryIssuance({ allowPrimaryIssuance: false });
165+
console.log('SetAllowPrimaryIssuance has been called');
166+
167+
// Issuing now invalid
168+
169+
tickerSecurityTokenInstance.unsubscribeAll();
59170
});

0 commit comments

Comments
 (0)