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

Commit 7f2c2f2

Browse files
committed
fix: 🐛 GTM example works again
1 parent 1d65417 commit 7f2c2f2

File tree

1 file changed

+43
-35
lines changed

1 file changed

+43
-35
lines changed

examples/generalTransferManager.ts

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { RedundantSubprovider, RPCSubprovider, Web3ProviderEngine } from '@0x/subproviders';
22
import { GeneralTransferManagerEvents, BigNumber } from '@polymathnetwork/abi-wrappers';
33
import { ApiConstructorParams, PolymathAPI } from '../src/PolymathAPI';
4-
import { ModuleName } from '../src';
4+
import { ModuleName, TransferType } from '../src';
55

66
// This file acts as a valid sandbox for using a general transfer manager module on an unlocked node (like ganache)
77

@@ -52,11 +52,13 @@ window.addEventListener('load', async () => {
5252
});
5353

5454
// Generate a security token
55-
await polymathAPI.securityTokenRegistry.generateSecurityToken({
55+
await polymathAPI.securityTokenRegistry.generateNewSecurityToken({
5656
name: tokenName!,
5757
ticker: ticker!,
58-
details: 'http://',
58+
tokenDetails: 'http://',
5959
divisible: false,
60+
treasuryWallet: myAddress,
61+
protocolVersion: '0',
6062
});
6163

6264
// Create a Security Token Instance
@@ -87,57 +89,63 @@ window.addEventListener('load', async () => {
8789
},
8890
});
8991

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+
98103
const randomBeneficiary1 = '0x3444444444444444444444444444444444444444';
99104
const randomBeneficiary2 = '0x5544444444444444444444444444444444444444';
100105

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)],
116112
});
117113

118-
// await generalTM.changeAllowAllWhitelistTransfers({ allowAllWhitelistTransfers: true });
114+
// Mint yourself some tokens
115+
await tickerSecurityTokenInstance.issue({ investor: myAddress, value: new BigNumber(200), data: '0x00' });
119116

120-
// Verify we can make transfers
117+
// No one can receive tokens
121118
console.log(
122-
await tickerSecurityTokenInstance.canTransferFrom({
123-
from: myAddress,
119+
await tickerSecurityTokenInstance.canTransfer({
124120
to: randomBeneficiary1,
125121
data: '0x00',
126122
value: new BigNumber(10),
127123
}),
128124
);
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
129136
console.log(
130-
await tickerSecurityTokenInstance.canTransferFrom({
131-
from: myAddress,
132-
to: randomBeneficiary2,
137+
await tickerSecurityTokenInstance.canTransfer({
138+
to: randomBeneficiary1,
133139
data: '0x00',
134140
value: new BigNumber(10),
135141
}),
136142
);
137143

138-
// Make the transfers
139-
await tickerSecurityTokenInstance.transfer({ to: randomBeneficiary1, value: new BigNumber(10) });
144+
await tickerSecurityTokenInstance.transfer({ to: randomBeneficiary1, value: new BigNumber(50) });
140145
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 }));
141149
console.log('Funds transferred');
142150

143151
generalTM.unsubscribeAll();

0 commit comments

Comments
 (0)