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

Commit da322d5

Browse files
author
Victor Wiebe
committed
fix: 🐛 mint token to investor
1 parent 3759ca2 commit da322d5

File tree

1 file changed

+63
-10
lines changed

1 file changed

+63
-10
lines changed

examples/mintTokenToInvestor.ts

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,73 @@ window.addEventListener('load', async () => {
1818
// Instantiate the API
1919
const polymathAPI = new PolymathAPI(params);
2020

21-
const ticker = 'TEST';
22-
const tokenAddress = await polymathAPI.securityTokenRegistry.getSecurityTokenAddress(ticker);
23-
const TEST = await polymathAPI.tokenFactory.getSecurityTokenInstanceFromAddress(tokenAddress);
24-
const investorAddress = '<investor address>'.toLowerCase();
25-
const generalTMAddress = (await TEST.getModulesByName({ moduleName: ModuleName.GeneralTransferManager }))[0];
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+
62+
const tokenAddress = await polymathAPI.securityTokenRegistry.getSecurityTokenAddress(ticker!);
63+
const tickerSecurityTokenInstance = await polymathAPI.tokenFactory.getSecurityTokenInstanceFromAddress(tokenAddress);
64+
65+
const investorAddress = '0x1111111111111111111111111111111111111111';
66+
const generalTMAddress = (await tickerSecurityTokenInstance.getModulesByName({
67+
moduleName: ModuleName.GeneralTransferManager,
68+
}))[0];
2669

2770
const generalTM = await polymathAPI.moduleFactory.getModuleInstance({
2871
name: ModuleName.GeneralTransferManager,
2972
address: generalTMAddress,
3073
});
3174

75+
await generalTM.modifyKYCData({
76+
investor: investorAddress,
77+
canReceiveAfter: new Date(),
78+
canSendAfter: new Date(),
79+
expiryTime: new Date(2035, 1),
80+
});
81+
3282
const listInvestors = await generalTM.getAllKYCData();
3383
const found = listInvestors.find(function(addr) {
3484
return addr.investor == investorAddress;
3585
});
3686

37-
await TEST.subscribeAsync({
87+
await tickerSecurityTokenInstance.subscribeAsync({
3888
eventName: SecurityTokenEvents.Issued,
3989
indexFilterValues: {},
4090
callback: async (error, log) => {
@@ -47,17 +97,20 @@ window.addEventListener('load', async () => {
4797
});
4898

4999
if (found) {
50-
await TEST.issue({
100+
await tickerSecurityTokenInstance.issue({
51101
investor: investorAddress,
52102
value: new BigNumber(100),
53-
data: '',
103+
data: '0x51',
54104
txData: {
55-
from: '<sto owner>'.toLowerCase(),
105+
from: myAddress.toLowerCase(),
56106
},
57107
});
108+
console.log('100 tokens issued');
58109
} else {
59110
console.log('Please make sure beneficiary address has been whitelisted');
60111
}
112+
console.log('Balance of investor:');
113+
console.log((await tickerSecurityTokenInstance.balanceOf({ owner: investorAddress })).toNumber());
61114

62-
TEST.unsubscribeAll();
115+
tickerSecurityTokenInstance.unsubscribeAll();
63116
});

0 commit comments

Comments
 (0)