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

Commit 6fad80c

Browse files
committed
fix: 🐛 manual merge
2 parents 6044442 + a3836d5 commit 6fad80c

22 files changed

+1424
-182
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ scripts/*
44
sandbox.ts
55
test_utils/*
66
examples/*
7+
webpack.*

examples/investInCappedSTO.ts

Lines changed: 0 additions & 73 deletions
This file was deleted.

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
});

examples/percentageTransferManager.ts

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

87
// This file acts as a valid sandbox for using a percentage restriction transfer manager module on an unlocked node (like ganache)
@@ -19,12 +18,49 @@ window.addEventListener('load', async () => {
1918
// 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
});
@@ -40,16 +76,109 @@ window.addEventListener('load', async () => {
4076
names.push(instanceFactory.name());
4177
});
4278
const resultNames = await Promise.all(names);
43-
const index = resultNames.indexOf(moduleStringName);
4479

45-
// Call to add module
80+
const index = resultNames.indexOf(moduleName);
81+
82+
// Create a Security Token Instance
83+
const tickerSecurityTokenInstance = await polymathAPI.tokenFactory.getSecurityTokenInstanceFromTicker(ticker!);
84+
85+
await polymathAPI.moduleRegistry.subscribeAsync({
86+
eventName: ModuleRegistryEvents.ModuleRegistered,
87+
indexFilterValues: {},
88+
callback: async (error, log) => {
89+
if (error) {
90+
console.log(error);
91+
} else {
92+
console.log('Module added!', log);
93+
}
94+
},
95+
});
96+
97+
// Get General TM Address to whitelist transfers
98+
const generalTMAddress = (await tickerSecurityTokenInstance.getModulesByName({
99+
moduleName: ModuleName.GeneralTransferManager,
100+
}))[0];
101+
const generalTM = await polymathAPI.moduleFactory.getModuleInstance({
102+
name: ModuleName.GeneralTransferManager,
103+
address: generalTMAddress,
104+
});
105+
106+
await generalTM.modifyKYCData({
107+
investor: myAddress,
108+
canSendAfter: new Date(),
109+
canReceiveAfter: new Date(),
110+
expiryTime: new Date(2020, 0),
111+
txData: {
112+
from: await polymathAPI.getAccount(),
113+
},
114+
});
115+
46116
await tickerSecurityTokenInstance.addModule({
47117
moduleName,
48118
address: modules[index],
49119
data: {
50-
maxHolderPercentage: new BigNumber(10),
120+
maxHolderPercentage: new BigNumber(25),
51121
allowPrimaryIssuance: true,
52122
},
53123
archived: false,
54124
});
125+
126+
const percentageTMAddress = (await tickerSecurityTokenInstance.getModulesByName({
127+
moduleName: ModuleName.PercentageTransferManager,
128+
}))[0];
129+
130+
const percentageTM = await polymathAPI.moduleFactory.getModuleInstance({
131+
name: ModuleName.PercentageTransferManager,
132+
address: percentageTMAddress,
133+
});
134+
135+
// Subscribe to event of setAllowPrimaryIssuance
136+
await percentageTM.subscribeAsync({
137+
eventName: PercentageTransferManagerEvents.SetAllowPrimaryIssuance,
138+
indexFilterValues: {},
139+
callback: async (error, log) => {
140+
if (error) {
141+
console.log(error);
142+
} else {
143+
console.log('AllowPrimaryIssuance has been set', log);
144+
}
145+
},
146+
});
147+
148+
const randomBeneficiary1 = '0x0123456789012345678901234567890123456789';
149+
const randomBeneficiary2 = '0x9123456789012345678901234567890123456789';
150+
151+
await generalTM.modifyKYCDataMulti({
152+
investors: [myAddress, randomBeneficiary1, randomBeneficiary2],
153+
canReceiveAfter: [new Date(), new Date(), new Date()],
154+
canSendAfter: [new Date(), new Date(), new Date()],
155+
expiryTime: [new Date(2035, 1), new Date(2035, 1), new Date(2035, 1)],
156+
});
157+
158+
await tickerSecurityTokenInstance.issueMulti({
159+
investors: [myAddress, randomBeneficiary1],
160+
values: [new BigNumber(10), new BigNumber(10)],
161+
});
162+
163+
await percentageTM.setAllowPrimaryIssuance({ allowPrimaryIssuance: false });
164+
console.log('SetAllowPrimaryIssuance has been called');
165+
166+
// Primary Issuance now invalid
167+
// Percentage transfer manager whitelist beneficiary 1 so they can receive more tokens
168+
await percentageTM.modifyWhitelist({ investor: randomBeneficiary1, valid: true });
169+
await tickerSecurityTokenInstance.transfer({ to: randomBeneficiary1, value: new BigNumber(1) });
170+
171+
// Try out transfer above 25% to beneficiary 2, should fail
172+
try {
173+
await tickerSecurityTokenInstance.transfer({ to: randomBeneficiary2, value: new BigNumber(6) });
174+
} catch (e) {
175+
console.log('Transfer above 25% to non-whitelisted address fails as expected');
176+
}
177+
178+
// Try out transfer below 25% to beneficiary 2, should pass
179+
await tickerSecurityTokenInstance.transfer({ to: randomBeneficiary2, value: new BigNumber(5) });
180+
181+
console.log('Tokens transferred to beneficiaries');
182+
183+
tickerSecurityTokenInstance.unsubscribeAll();
55184
});

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@polymathnetwork/contract-wrappers",
3-
"version": "2.0.0-beta.16",
3+
"version": "2.0.0-beta.23",
44
"description": "Smart TS wrappers for Polymath smart contracts",
55
"keywords": [
66
"polymath",
@@ -10,6 +10,7 @@
1010
"lib/**/*"
1111
],
1212
"main": "lib/index.js",
13+
"browser": "lib/index.browser.js",
1314
"types": "lib/index.d.ts",
1415
"scripts": {
1516
"start": "webpack-dev-server --config=webpack.config.dev.js",
@@ -83,12 +84,14 @@
8384
"@0x/subproviders": "^4.1.1",
8485
"@0x/types": "^2.4.0",
8586
"@0x/typescript-typings": "^4.2.3",
86-
"@polymathnetwork/abi-wrappers": "3.0.0-beta.4",
87+
"@polymathnetwork/abi-wrappers": "3.0.0-beta.6",
88+
"@types/semver": "^6.0.1",
8789
"ethereumjs-blockstream": "6.0.0",
8890
"ethereumjs-util": "^6.1.0",
8991
"js-sha3": "^0.8.0",
9092
"lodash": "^4.17.5",
9193
"moment": "^2.24.0",
94+
"semver": "^6.3.0",
9295
"uuid": "^3.3.2"
9396
},
9497
"publishConfig": {

0 commit comments

Comments
 (0)