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

Commit d3e3ce1

Browse files
committed
fix: 🐛 implement ErrorCode type for CTM and GTM wrapper
1 parent 5aad2dc commit d3e3ce1

File tree

2 files changed

+75
-17
lines changed

2 files changed

+75
-17
lines changed

src/contract_wrappers/modules/transfer_manager/count_transfer_manager_wrapper.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
Subscribe,
2222
GetLogs,
2323
Perm,
24+
ErrorCode,
2425
} from '../../../types';
2526
import { numberToBigNumber, parseTransferResult, valueToWei } from '../../../utils/convert';
2627

@@ -98,8 +99,12 @@ export default class CountTransferManagerWrapper extends ModuleWrapper {
9899
}
99100

100101
public unpause = async (params: TxParams) => {
101-
assert.assert(await this.paused(), 'Controller not currently paused');
102-
assert.assert(await this.isCallerTheSecurityTokenOwner(params.txData), 'Sender is not owner');
102+
assert.assert(await this.paused(), ErrorCode.PreconditionRequired, 'Controller not currently paused');
103+
assert.assert(
104+
await this.isCallerTheSecurityTokenOwner(params.txData),
105+
ErrorCode.Unauthorized,
106+
'Sender is not owner',
107+
);
103108
return (await this.contract).unpause.sendTransactionAsync(params.txData, params.safetyFactor);
104109
};
105110

@@ -108,8 +113,12 @@ export default class CountTransferManagerWrapper extends ModuleWrapper {
108113
};
109114

110115
public pause = async (params: TxParams) => {
111-
assert.assert(!(await this.paused()), 'Controller currently paused');
112-
assert.assert(await this.isCallerTheSecurityTokenOwner(params.txData), 'Sender is not owner');
116+
assert.assert(!(await this.paused()), ErrorCode.ContractPaused, 'Controller currently paused');
117+
assert.assert(
118+
await this.isCallerTheSecurityTokenOwner(params.txData),
119+
ErrorCode.Unauthorized,
120+
'Sender is not owner',
121+
);
113122
return (await this.contract).pause.sendTransactionAsync(params.txData, params.safetyFactor);
114123
};
115124

@@ -135,7 +144,11 @@ export default class CountTransferManagerWrapper extends ModuleWrapper {
135144
};
136145

137146
public changeHolderCount = async (params: ChangeHolderCountParams) => {
138-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
147+
assert.assert(
148+
await this.isCallerAllowed(params.txData, Perm.Admin),
149+
ErrorCode.Unauthorized,
150+
'Caller is not allowed',
151+
);
139152
return (await this.contract).changeHolderCount.sendTransactionAsync(
140153
numberToBigNumber(params.maxHolderCount),
141154
params.txData,

src/contract_wrappers/modules/transfer_manager/general_transfer_manager_wrapper.ts

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
Perm,
3838
TransferType,
3939
Partition,
40+
ErrorCode,
4041
} from '../../../types';
4142

4243
const ONE_HUNDRED = new BigNumber(100);
@@ -340,8 +341,12 @@ export default class GeneralTransferManagerWrapper extends ModuleWrapper {
340341
}
341342

342343
public unpause = async (params: TxParams) => {
343-
assert.assert(await this.paused(), 'Controller not currently paused');
344-
assert.assert(await this.isCallerTheSecurityTokenOwner(params.txData), 'Sender is not owner');
344+
assert.assert(await this.paused(), ErrorCode.PreconditionRequired, 'Controller not currently paused');
345+
assert.assert(
346+
await this.isCallerTheSecurityTokenOwner(params.txData),
347+
ErrorCode.Unauthorized,
348+
'Sender is not owner',
349+
);
345350
return (await this.contract).unpause.sendTransactionAsync(params.txData, params.safetyFactor);
346351
};
347352

@@ -350,8 +355,12 @@ export default class GeneralTransferManagerWrapper extends ModuleWrapper {
350355
};
351356

352357
public pause = async (params: TxParams) => {
353-
assert.assert(!(await this.paused()), 'Controller currently paused');
354-
assert.assert(await this.isCallerTheSecurityTokenOwner(params.txData), 'Sender is not owner');
358+
assert.assert(!(await this.paused()), ErrorCode.ContractPaused, 'Controller currently paused');
359+
assert.assert(
360+
await this.isCallerTheSecurityTokenOwner(params.txData),
361+
ErrorCode.Unauthorized,
362+
'Sender is not owner',
363+
);
355364
return (await this.contract).pause.sendTransactionAsync(params.txData, params.safetyFactor);
356365
};
357366

@@ -374,7 +383,11 @@ export default class GeneralTransferManagerWrapper extends ModuleWrapper {
374383
};
375384

376385
public changeDefaults = async (params: ChangeDefaultsParams) => {
377-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
386+
assert.assert(
387+
await this.isCallerAllowed(params.txData, Perm.Admin),
388+
ErrorCode.Unauthorized,
389+
'Caller is not allowed',
390+
);
378391
return (await this.contract).changeDefaults.sendTransactionAsync(
379392
dateToBigNumber(params.defaultFromTime),
380393
dateToBigNumber(params.defaultToTime),
@@ -385,7 +398,11 @@ export default class GeneralTransferManagerWrapper extends ModuleWrapper {
385398

386399
public changeIssuanceAddress = async (params: ChangeIssuanceAddressParams) => {
387400
assert.isETHAddressHex('issuanceAddress', params.issuanceAddress);
388-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
401+
assert.assert(
402+
await this.isCallerAllowed(params.txData, Perm.Admin),
403+
ErrorCode.Unauthorized,
404+
'Caller is not allowed',
405+
);
389406
return (await this.contract).changeIssuanceAddress.sendTransactionAsync(
390407
params.issuanceAddress,
391408
params.txData,
@@ -395,7 +412,11 @@ export default class GeneralTransferManagerWrapper extends ModuleWrapper {
395412

396413
public modifyKYCData = async (params: ModifyKYCDataParams) => {
397414
assert.isNonZeroETHAddressHex('investor', params.investor);
398-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
415+
assert.assert(
416+
await this.isCallerAllowed(params.txData, Perm.Admin),
417+
ErrorCode.Unauthorized,
418+
'Caller is not allowed',
419+
);
399420
assert.isLessThanMax64BytesDate('canSendAfter', params.canSendAfter);
400421
assert.isLessThanMax64BytesDate('canReceiveAfter', params.canReceiveAfter);
401422
assert.isLessThanMax64BytesDate('expiryTime', params.expiryTime);
@@ -522,14 +543,19 @@ export default class GeneralTransferManagerWrapper extends ModuleWrapper {
522543

523544
public modifyKYCDataSigned = async (params: ModifyKYCDataSignedParams) => {
524545
assert.isNonZeroETHAddressHex('investor', params.investor);
525-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
546+
assert.assert(
547+
await this.isCallerAllowed(params.txData, Perm.Admin),
548+
ErrorCode.Unauthorized,
549+
'Caller is not allowed',
550+
);
526551
assert.isLessThanMax64BytesDate('canSendAfter', params.canSendAfter);
527552
assert.isLessThanMax64BytesDate('canReceiveAfter', params.canReceiveAfter);
528553
assert.isLessThanMax64BytesDate('expiryTime', params.expiryTime);
529554
assert.isPastDate(params.validFrom, 'ValidFrom date must be in the past');
530555
assert.isFutureDate(params.validTo, 'ValidTo date must be in the future');
531556
assert.assert(
532557
!(await this.nonceMap({ address: params.investor, nonce: params.nonce })),
558+
ErrorCode.AlreadyAdded,
533559
'Already used signature of investor address and nonce',
534560
);
535561
return (await this.contract).modifyKYCDataSigned.sendTransactionAsync(
@@ -550,7 +576,11 @@ export default class GeneralTransferManagerWrapper extends ModuleWrapper {
550576
* Used to modify investor Flag.
551577
*/
552578
public modifyInvestorFlag = async (params: ModifyInvestorFlag) => {
553-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
579+
assert.assert(
580+
await this.isCallerAllowed(params.txData, Perm.Admin),
581+
ErrorCode.Unauthorized,
582+
'Caller is not allowed',
583+
);
554584
assert.isNonZeroETHAddressHex('investor', params.investor);
555585
return (await this.contract).modifyInvestorFlag.sendTransactionAsync(
556586
params.investor,
@@ -565,9 +595,14 @@ export default class GeneralTransferManagerWrapper extends ModuleWrapper {
565595
* Used to modify investor data.
566596
*/
567597
public modifyInvestorFlagMulti = async (params: ModifyInvestorFlagMulti) => {
568-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
598+
assert.assert(
599+
await this.isCallerAllowed(params.txData, Perm.Admin),
600+
ErrorCode.Unauthorized,
601+
'Caller is not allowed',
602+
);
569603
assert.assert(
570604
params.investors.length === params.flag.length && params.flag.length === params.value.length,
605+
ErrorCode.MismatchedArrayLength,
571606
'Mismatched input lengths',
572607
);
573608
return (await this.contract).modifyInvestorFlagMulti.sendTransactionAsync(
@@ -631,12 +666,17 @@ export default class GeneralTransferManagerWrapper extends ModuleWrapper {
631666
* Modifies the successful checks required for transfers.
632667
*/
633668
public modifyTransferRequirementsMulti = async (params: ModifyTransferRequirementsMulti) => {
634-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
669+
assert.assert(
670+
await this.isCallerAllowed(params.txData, Perm.Admin),
671+
ErrorCode.Unauthorized,
672+
'Caller is not allowed',
673+
);
635674
assert.assert(
636675
params.transferTypes.length === params.fromValidKYC.length &&
637676
params.fromValidKYC.length === params.toValidKYC.length &&
638677
params.toValidKYC.length === params.fromRestricted.length &&
639678
params.fromRestricted.length === params.toRestricted.length,
679+
ErrorCode.MismatchedArrayLength,
640680
'Mismatched input lengths',
641681
);
642682
return (await this.contract).modifyTransferRequirementsMulti.sendTransactionAsync(
@@ -654,11 +694,16 @@ export default class GeneralTransferManagerWrapper extends ModuleWrapper {
654694
* Add or remove KYC info of an investor.
655695
*/
656696
public modifyKYCDataMulti = async (params: ModifyKYCDataMulti) => {
657-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
697+
assert.assert(
698+
await this.isCallerAllowed(params.txData, Perm.Admin),
699+
ErrorCode.Unauthorized,
700+
'Caller is not allowed',
701+
);
658702
assert.assert(
659703
params.investors.length === params.canSendAfter.length &&
660704
params.canSendAfter.length === params.canReceiveAfter.length &&
661705
params.canReceiveAfter.length === params.expiryTime.length,
706+
ErrorCode.MismatchedArrayLength,
662707
'Mismatched input lengths',
663708
);
664709

0 commit comments

Comments
 (0)