|
1 | 1 | import { RedundantSubprovider, RPCSubprovider, Web3ProviderEngine } from '@0x/subproviders';
|
2 | 2 | import { GeneralTransferManagerEvents, BigNumber } from '@polymathnetwork/abi-wrappers';
|
3 | 3 | import { ApiConstructorParams, PolymathAPI } from '../src/PolymathAPI';
|
4 |
| -import { ModuleName } from '../src'; |
| 4 | +import { ModuleName, TransferType } from '../src'; |
5 | 5 |
|
6 | 6 | // This file acts as a valid sandbox for using a general transfer manager module on an unlocked node (like ganache)
|
7 | 7 |
|
@@ -52,11 +52,13 @@ window.addEventListener('load', async () => {
|
52 | 52 | });
|
53 | 53 |
|
54 | 54 | // Generate a security token
|
55 |
| - await polymathAPI.securityTokenRegistry.generateSecurityToken({ |
| 55 | + await polymathAPI.securityTokenRegistry.generateNewSecurityToken({ |
56 | 56 | name: tokenName!,
|
57 | 57 | ticker: ticker!,
|
58 |
| - details: 'http://', |
| 58 | + tokenDetails: 'http://', |
59 | 59 | divisible: false,
|
| 60 | + treasuryWallet: myAddress, |
| 61 | + protocolVersion: '0', |
60 | 62 | });
|
61 | 63 |
|
62 | 64 | // Create a Security Token Instance
|
@@ -87,57 +89,63 @@ window.addEventListener('load', async () => {
|
87 | 89 | },
|
88 | 90 | });
|
89 | 91 |
|
90 |
| - // Change allow all whitelist transfers: I_GeneralTransferManager.modifyTransferRequirementsMulti( |
91 |
| - // [0, 1, 2], |
92 |
| - // [false, false, false], |
93 |
| - // [false, false, false], |
94 |
| - // [false, false, false], |
95 |
| - // [false, false, false], |
96 |
| - // { from: token_owner } |
97 |
| -// await generalTM.changeAllowAllTransfers({ allowAllTransfers: true }); |
| 92 | + // Add owner address in the whitelist to allow mint tokens |
| 93 | + await generalTM.modifyKYCData({ |
| 94 | + investor: myAddress, |
| 95 | + canSendAfter: new Date(), |
| 96 | + canReceiveAfter: new Date(), |
| 97 | + expiryTime: new Date(2020, 0), |
| 98 | + txData: { |
| 99 | + from: await polymathAPI.getAccount(), |
| 100 | + }, |
| 101 | + }); |
| 102 | + |
98 | 103 | const randomBeneficiary1 = '0x3444444444444444444444444444444444444444';
|
99 | 104 | const randomBeneficiary2 = '0x5544444444444444444444444444444444444444';
|
100 | 105 |
|
101 |
| - // Mint yourself some tokens and transfer them around, check balances |
102 |
| - await tickerSecurityTokenInstance.issue({ investor: myAddress, value: new BigNumber(200), data: '' }); |
103 |
| - await tickerSecurityTokenInstance.transfer({ to: randomBeneficiary1, value: new BigNumber(50) }); |
104 |
| - console.log(await tickerSecurityTokenInstance.balanceOf({ owner: randomBeneficiary1 })); |
105 |
| - console.log(await tickerSecurityTokenInstance.balanceOf({ owner: myAddress })); |
106 |
| - |
107 |
| - // Disallow all transfers between token holders// |
108 |
| -// await generalTM.changeAllowAllTransfers({ allowAllTransfers: false }); |
109 |
| - |
110 |
| - // Add whitelist special users |
111 |
| - await generalTM.modifyKYCData({ |
112 |
| - investor: randomBeneficiary1, |
113 |
| - canReceiveAfter: new Date(2018, 1), |
114 |
| - canSendAfter: new Date(2018, 2), |
115 |
| - expiryTime: new Date(2035, 1), |
| 106 | + // Add beneficiaries in the whitelist with distant dates to send and receive |
| 107 | + await generalTM.modifyKYCDataMulti({ |
| 108 | + investors: [randomBeneficiary1, randomBeneficiary2], |
| 109 | + canSendAfter: [new Date(2020, 0), new Date(2020, 0)], |
| 110 | + canReceiveAfter: [new Date(2020, 0), new Date(2020, 0)], |
| 111 | + expiryTime: [new Date(2020, 0), new Date(2020, 0)], |
116 | 112 | });
|
117 | 113 |
|
118 |
| -// await generalTM.changeAllowAllWhitelistTransfers({ allowAllWhitelistTransfers: true }); |
| 114 | + // Mint yourself some tokens |
| 115 | + await tickerSecurityTokenInstance.issue({ investor: myAddress, value: new BigNumber(200), data: '0x00' }); |
119 | 116 |
|
120 |
| - // Verify we can make transfers |
| 117 | + // No one can receive tokens |
121 | 118 | console.log(
|
122 |
| - await tickerSecurityTokenInstance.canTransferFrom({ |
123 |
| - from: myAddress, |
| 119 | + await tickerSecurityTokenInstance.canTransfer({ |
124 | 120 | to: randomBeneficiary1,
|
125 | 121 | data: '0x00',
|
126 | 122 | value: new BigNumber(10),
|
127 | 123 | }),
|
128 | 124 | );
|
| 125 | + |
| 126 | + // Allow all transfers between token holders |
| 127 | + await generalTM.modifyTransferRequirementsMulti({ |
| 128 | + transferTypes: [TransferType.General, TransferType.Issuance, TransferType.Redemption], |
| 129 | + fromValidKYC: [false, false, false], |
| 130 | + toValidKYC: [false, false, false], |
| 131 | + fromRestricted: [false, false, false], |
| 132 | + toRestricted: [false, false, false], |
| 133 | + }); |
| 134 | + |
| 135 | + // Now we can transfer to all |
129 | 136 | console.log(
|
130 |
| - await tickerSecurityTokenInstance.canTransferFrom({ |
131 |
| - from: myAddress, |
132 |
| - to: randomBeneficiary2, |
| 137 | + await tickerSecurityTokenInstance.canTransfer({ |
| 138 | + to: randomBeneficiary1, |
133 | 139 | data: '0x00',
|
134 | 140 | value: new BigNumber(10),
|
135 | 141 | }),
|
136 | 142 | );
|
137 | 143 |
|
138 |
| - // Make the transfers |
139 |
| - await tickerSecurityTokenInstance.transfer({ to: randomBeneficiary1, value: new BigNumber(10) }); |
| 144 | + await tickerSecurityTokenInstance.transfer({ to: randomBeneficiary1, value: new BigNumber(50) }); |
140 | 145 | await tickerSecurityTokenInstance.transfer({ to: randomBeneficiary2, value: new BigNumber(10) });
|
| 146 | + console.log(await tickerSecurityTokenInstance.balanceOf({ owner: myAddress })); |
| 147 | + console.log(await tickerSecurityTokenInstance.balanceOf({ owner: randomBeneficiary1 })); |
| 148 | + console.log(await tickerSecurityTokenInstance.balanceOf({ owner: randomBeneficiary2 })); |
141 | 149 | console.log('Funds transferred');
|
142 | 150 |
|
143 | 151 | generalTM.unsubscribeAll();
|
|
0 commit comments