Skip to content
This repository was archived by the owner on Apr 3, 2019. It is now read-only.

Commit def6a27

Browse files
authored
Merge pull request #64 from PolymathNetwork/publish-fix
Move web3 wrapper from devDependencies to dependencies. Add Complianc…
2 parents 8b68e70 + 5607772 commit def6a27

File tree

10 files changed

+96
-88
lines changed

10 files changed

+96
-88
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
install:
2-
- yarn install
2+
- yarn prepack
33
env:
44
- CI="true"
55

src/contract_wrappers/Compliance.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import Web3 from 'web3';
55
import { Web3Wrapper } from '@0xproject/web3-wrapper';
66

77
import ContractWrapper from './ContractWrapper';
8-
import Customers from './Customers';
9-
import SecurityTokenRegistrar from './SecurityTokenRegistrar';
10-
8+
import Template from './Template';
119
import complianceArtifact from '../artifacts/Compliance.json';
1210
import type {
1311
BlockRange,
@@ -28,13 +26,9 @@ export default class Compliance extends ContractWrapper {
2826
*/
2927
constructor(
3028
web3Wrapper: Web3Wrapper,
31-
customers: Customers,
3229
deployedAddress?: string,
3330
) {
3431
super(web3Wrapper, complianceArtifact, deployedAddress);
35-
36-
this.customers = customers;
37-
this.securityTokenRegistrar = SecurityTokenRegistrar;
3832
}
3933

4034
/**
@@ -87,7 +81,7 @@ export default class Compliance extends ContractWrapper {
8781
* @param fee Amount of POLY to use the template (held in escrow until issuance)
8882
* @param quorum Minimum percent of shareholders which need to vote to freeze
8983
* @param vestingPeriod Length of time to vest funds
90-
* @return The address of the created template
84+
* @return The created template
9185
*/
9286
async createTemplate(
9387
legalDelegateAddress: string,
@@ -100,7 +94,7 @@ export default class Compliance extends ContractWrapper {
10094
fee: BigNumber,
10195
quorum: BigNumber,
10296
vestingPeriod: BigNumber,
103-
): Promise<string> {
97+
): Promise<Template> {
10498
const receipt = await this._contract.createTemplate(
10599
offeringType,
106100
Web3.prototype.fromAscii(issuerJurisdiction),
@@ -116,16 +110,30 @@ export default class Compliance extends ContractWrapper {
116110
gas: 4000000,
117111
},
118112
);
113+
const logs = receipt.logs.filter(log => log.event === 'LogTemplateCreated');
114+
115+
if (logs.length === 0) {
116+
throw new Error('createTemplate couldn\'t find an event log.');
117+
}
119118

120-
for (let i = 0; i < receipt.logs.length; i++) {
121-
const log = receipt.logs[i];
119+
const address = logs[0].args._template;
122120

123-
if (log.event === 'LogTemplateCreated') {
124-
return log.args._template;
125-
}
121+
if (!address) {
122+
throw new Error('createTemplate couldn\'t get template address.');
126123
}
127124

128-
throw new Error('createTemplate should have emitted LogTemplateCreated.');
125+
return this.getTemplateFromAddress(address);
126+
}
127+
128+
/**
129+
* Instantiates a template given its contract address.
130+
* @param address The address of the template contract
131+
* @return The template instance
132+
*/
133+
async getTemplateFromAddress(address: string): Promise<Template> {
134+
const template = new Template(this._web3Wrapper, address);
135+
await template.initialize();
136+
return template;
129137
}
130138

131139
/**

src/contract_wrappers/Customers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type LogCustomerVerifiedArgsUnprocessed = {
3030
* Wrapper for the Customers Solidity contract
3131
*/
3232
export default class Customers extends ContractWrapper {
33-
// polyToken: PolyToken;
33+
polyToken: PolyToken;
3434

3535
/**
3636
* @hideconstructor

src/contract_wrappers/SecurityToken.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,14 @@ export type LogNewWhitelistedAddress = {
3232
* Wrapper for the SecurityToken Solidity contract
3333
*/
3434
export default class SecurityToken extends ContractWrapper {
35-
polyToken: PolyToken;
36-
customers: Customers;
37-
compliance: Compliance;
38-
3935
/**
4036
* @hideconstructor
4137
*/
4238
constructor(
4339
web3Wrapper: Web3Wrapper,
44-
polyToken: PolyToken,
45-
customers: Customers,
46-
compliance: Compliance,
4740
deployedAddress: string,
4841
) {
4942
super(web3Wrapper, securityTokenArtifact, deployedAddress);
50-
51-
this.polyToken = polyToken;
52-
this.customers = customers;
53-
this.compliance = compliance;
5443
}
5544

5645
/**

src/contract_wrappers/SecurityTokenRegistrar.js

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
import { Web3Wrapper } from '@0xproject/web3-wrapper';
44
import { BigNumber } from 'bignumber.js';
5+
56
import ContractWrapper from './ContractWrapper';
6-
import securityTokenRegistrarArtifact from '../artifacts/SecurityTokenRegistrar.json';
77
import SecurityToken from './SecurityToken';
8-
import Compliance from './Compliance';
8+
import securityTokenRegistrarArtifact from '../artifacts/SecurityTokenRegistrar.json';
99
import type {
1010
BlockRange,
1111
SecurityTokenRegistrarEventArgs,
@@ -24,14 +24,9 @@ export default class SecurityTokenRegistrar extends ContractWrapper {
2424
*/
2525
constructor(
2626
web3Wrapper: Web3Wrapper,
27-
securityToken: SecurityToken,
28-
compliance: Compliance,
2927
deployedAddress?: string,
3028
) {
3129
super(web3Wrapper, securityTokenRegistrarArtifact, deployedAddress);
32-
33-
this.securityToken = securityToken;
34-
this.compliance = compliance;
3530
}
3631

3732
/**
@@ -65,7 +60,7 @@ export default class SecurityTokenRegistrar extends ContractWrapper {
6560
}
6661

6762
/**
68-
* Creates a security token and stores it in the security token registry. Returns a promise of true it the security token was successfully created. This is done by event watching for the event {@link LogNewSecurityToken()}.
63+
* Creates a security token and stores it in the security token registry.
6964
*
7065
* @param creator The address from which the token is created
7166
* @param name Name of the security token
@@ -79,6 +74,7 @@ export default class SecurityTokenRegistrar extends ContractWrapper {
7974
* @param type Type of security being tokenized (NEED TOKEN NUMBERS ie. security:1, somethingelse:2)
8075
* @param lockupPeriod Length of time (unix) raised POLY will be locked up for dispute
8176
* @param quorum Percent of initial investors required to freeze POLY raise
77+
* @return The security token created
8278
*/
8379
async createSecurityToken(
8480
creator: string,
@@ -93,8 +89,8 @@ export default class SecurityTokenRegistrar extends ContractWrapper {
9389
type: number,
9490
lockupPeriod: BigNumber,
9591
quorum: number,
96-
) {
97-
await this._contract.createSecurityToken(
92+
): Promise<SecurityToken> {
93+
const receipt = await this._contract.createSecurityToken(
9894
name,
9995
ticker,
10096
totalSupply,
@@ -111,6 +107,19 @@ export default class SecurityTokenRegistrar extends ContractWrapper {
111107
gas: 6700000,
112108
},
113109
);
110+
const logs = receipt.logs.filter(log => log.event === 'LogNewSecurityToken');
111+
112+
if (logs.length === 0) {
113+
throw new Error('createSecurityToken couldn\'t find an event log.');
114+
}
115+
116+
const address = logs[0].args.securityTokenAddress;
117+
118+
if (!address) {
119+
throw new Error('createSecurityToken couldn\'t get security token address.');
120+
}
121+
122+
return this.getSecurityTokenByAddress(address);
114123
}
115124

116125
/**
@@ -129,6 +138,17 @@ export default class SecurityTokenRegistrar extends ContractWrapper {
129138
return dataToNumber;
130139
}
131140

141+
/**
142+
* Instantiates a `SecurityToken` given its contract address.
143+
* @param address The address of the security tokens
144+
* @return The security token instance
145+
*/
146+
async getSecurityTokenByAddress(address: string): Promise<SecurityToken> {
147+
const securityToken = new SecurityToken(this._web3Wrapper, address);
148+
await securityToken.initialize();
149+
return securityToken;
150+
}
151+
132152
/**
133153
* Getter function for ST addresses by passing the ticker/symbol as the argument.
134154
* @param ticker The security token ticker

src/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { Web3Wrapper } from '@0xproject/web3-wrapper';
44

55
// import { ContractNotFoundError } from './types';
6-
import { Customers, PolyToken } from './contract_wrappers';
6+
import { Compliance, Customers, PolyToken, SecurityTokenRegistrar } from './contract_wrappers';
77
import type { Web3Provider } from './types';
88

99
export * from './contract_wrappers';
@@ -21,6 +21,8 @@ export class Polymath {
2121

2222
polyToken: PolyToken;
2323
customers: Customers;
24+
compliance: Compliance;
25+
securityTokenRegistrar: SecurityTokenRegistrar;
2426

2527
constructor(web3Provider: Web3Provider) {
2628
this._web3Wrapper = new Web3Wrapper(web3Provider);
@@ -33,6 +35,12 @@ export class Polymath {
3335
this.customers = new Customers(this._web3Wrapper, this.polyToken);
3436
initializePromises.push(this.customers.initialize());
3537

38+
this.compliance = new Compliance(this._web3Wrapper);
39+
initializePromises.push(this.compliance.initialize());
40+
41+
this.securityTokenRegistrar = new SecurityTokenRegistrar(this._web3Wrapper);
42+
initializePromises.push(this.securityTokenRegistrar.initialize());
43+
3644
this.initializedPromise = Promise.all(initializePromises);
3745
}
3846
}

test/Compliance_test.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ describe('Compliance wrapper', () => {
5454
polyToken,
5555
customers,
5656
compliance,
57-
securityToken,
5857
accounts[0],
5958
accounts[1],
6059
expiryTime,
@@ -87,12 +86,12 @@ describe('Compliance wrapper', () => {
8786
it('createTemplate', async () => {
8887
await makeKYCProvider(customers, accounts[1], expiryTime);
8988
await makeLegalDelegate(polyToken, customers, accounts[1], accounts[2], expiryTime);
90-
const templateAddress = await makeTemplate(
89+
const templateAddress = (await makeTemplate(
9190
compliance,
9291
accounts[1],
9392
accounts[2],
9493
expiryTime,
95-
);
94+
)).address;
9695

9796
assert.isAbove(templateAddress.length, 0);
9897
});
@@ -136,13 +135,12 @@ describe('Compliance wrapper', () => {
136135

137136
await makeKYCProvider(customers, accounts[1]);
138137
await makeLegalDelegate(polyToken, customers, accounts[1], accounts[2], expiryTime);
139-
const templateAddress = await makeTemplateWithFinalized(
138+
const templateAddress = (await makeTemplateWithFinalized(
140139
compliance,
141140
accounts[1],
142141
accounts[2],
143142
expiryTime,
144-
145-
);
143+
)).address;
146144

147145

148146
// Propose Template
@@ -236,12 +234,12 @@ describe('Compliance wrapper', () => {
236234
await makeKYCProvider(customers, kycProvider);
237235

238236
await makeLegalDelegate(polyToken, customers, accounts[1], accounts[2], expiryTime);
239-
const templateAddress = await makeTemplateWithFinalized(
237+
const templateAddress = (await makeTemplateWithFinalized(
240238
compliance,
241239
kycProvider,
242240
legalDelegate,
243241
expiryTime,
244-
);
242+
)).address;
245243

246244
await makeSelectedTemplateForSecurityToken(
247245
securityToken,
@@ -326,12 +324,12 @@ describe('Compliance wrapper', () => {
326324

327325
await makeKYCProvider(customers, accounts[1]);
328326
await makeLegalDelegate(polyToken, customers, accounts[1], accounts[2], expiryTime);
329-
const templateAddress = await makeTemplate(
327+
const templateAddress = (await makeTemplate(
330328
compliance,
331329
accounts[1],
332330
accounts[2],
333331
expiryTime,
334-
);
332+
)).address;
335333

336334
const logTemplateCreated = await logTemplateCreatedArgsPromise;
337335
assert.equal(logTemplateCreated._creator, accounts[2], 'legal delegate creator address wasnt found in event subscription'); //'offeringtype' from make_examples.js

test/SecurityTokenRegistrar_test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import BigNumber from 'bignumber.js';
22
import chai from 'chai';
33
import 'mocha';
4+
import Web3 from 'web3';
45

56
import {
67
makePolyToken,
@@ -49,7 +50,6 @@ describe('Registrar wrapper', () => {
4950
polyToken,
5051
customers,
5152
compliance,
52-
securityToken,
5353
accounts[0],
5454
);
5555

@@ -79,7 +79,7 @@ describe('Registrar wrapper', () => {
7979
const quorum = 75;
8080

8181
await polyToken.approve(owner, registrar.address, fee);
82-
await registrar.createSecurityToken(
82+
const securityToken = await registrar.createSecurityToken(
8383
creator,
8484
name,
8585
ticker,
@@ -94,6 +94,8 @@ describe('Registrar wrapper', () => {
9494
quorum,
9595
);
9696

97+
assert(Web3.prototype.isAddress(securityToken.address), 'Returned security token has valid address.');
98+
9799
const logs = await registrar.getLogs(
98100
'LogNewSecurityToken',
99101
{},

0 commit comments

Comments
 (0)