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

Commit 9379d20

Browse files
committed
fix: 🐛 implement ErrorCode class on VRT
1 parent a54056c commit 9379d20

File tree

1 file changed

+120
-24
lines changed

1 file changed

+120
-24
lines changed

src/contract_wrappers/modules/transfer_manager/volume_restriction_transfer_manager_wrapper.ts

Lines changed: 120 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import {
4545
Perm,
4646
RestrictionType,
4747
PERCENTAGE_DECIMALS,
48+
ErrorCode,
4849
} from '../../../types';
4950

5051
interface ChangedExemptWalletListSubscribeAsyncParams extends SubscribeAsyncParams {
@@ -354,8 +355,12 @@ export default class VolumeRestrictionTransferManagerWrapper extends ModuleWrapp
354355
}
355356

356357
public unpause = async (params: TxParams) => {
357-
assert.assert(await this.paused(), 'Controller not currently paused');
358-
assert.assert(await this.isCallerTheSecurityTokenOwner(params.txData), 'Sender is not owner');
358+
assert.assert(await this.paused(), ErrorCode.PreconditionRequired, 'Controller not currently paused');
359+
assert.assert(
360+
await this.isCallerTheSecurityTokenOwner(params.txData),
361+
ErrorCode.Unauthorized,
362+
'Sender is not owner',
363+
);
359364
return (await this.contract).unpause.sendTransactionAsync(params.txData, params.safetyFactor);
360365
};
361366

@@ -364,8 +369,12 @@ export default class VolumeRestrictionTransferManagerWrapper extends ModuleWrapp
364369
};
365370

366371
public pause = async (params: TxParams) => {
367-
assert.assert(!(await this.paused()), 'Controller currently paused');
368-
assert.assert(await this.isCallerTheSecurityTokenOwner(params.txData), 'Sender is not owner');
372+
assert.assert(!(await this.paused()), ErrorCode.ContractPaused, 'Controller currently paused');
373+
assert.assert(
374+
await this.isCallerTheSecurityTokenOwner(params.txData),
375+
ErrorCode.Unauthorized,
376+
'Sender is not owner',
377+
);
369378
return (await this.contract).pause.sendTransactionAsync(params.txData, params.safetyFactor);
370379
};
371380

@@ -454,6 +463,7 @@ export default class VolumeRestrictionTransferManagerWrapper extends ModuleWrapp
454463
assert.isNonZeroETHAddressHex('wallet', params.wallet);
455464
assert.assert(
456465
!(await this.getExemptAddress()).includes(params.wallet) === params.change,
466+
ErrorCode.PreconditionRequired,
457467
'There will be no change to exempt list',
458468
);
459469
return (await this.contract).changeExemptWalletList.sendTransactionAsync(
@@ -465,9 +475,17 @@ export default class VolumeRestrictionTransferManagerWrapper extends ModuleWrapp
465475
};
466476

467477
public addIndividualRestriction = async (params: IndividualRestrictionParams) => {
468-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
478+
assert.assert(
479+
await this.isCallerAllowed(params.txData, Perm.Admin),
480+
ErrorCode.Unauthorized,
481+
'Caller is not allowed',
482+
);
469483
assert.isNonZeroETHAddressHex('holder', params.holder);
470-
assert.assert(!(await this.getExemptAddress()).includes(params.holder), 'Holder is exempt from restriction');
484+
assert.assert(
485+
!(await this.getExemptAddress()).includes(params.holder),
486+
ErrorCode.PreconditionRequired,
487+
'Holder is exempt from restriction',
488+
);
471489
this.checkRestrictionInputParams(
472490
params.startTime,
473491
params.endTime,
@@ -489,7 +507,11 @@ export default class VolumeRestrictionTransferManagerWrapper extends ModuleWrapp
489507
};
490508

491509
public addIndividualDailyRestriction = async (params: IndividualRestrictionParams) => {
492-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
510+
assert.assert(
511+
await this.isCallerAllowed(params.txData, Perm.Admin),
512+
ErrorCode.Unauthorized,
513+
'Caller is not allowed',
514+
);
493515
assert.isNonZeroETHAddressHex('holder', params.holder);
494516
this.checkRestrictionInputParams(params.startTime, params.endTime, params.allowedTokens, params.restrictionType, 1);
495517
const decimals = await this.decimalsByRestrictionType(params.restrictionType);
@@ -505,13 +527,18 @@ export default class VolumeRestrictionTransferManagerWrapper extends ModuleWrapp
505527
};
506528

507529
public addIndividualDailyRestrictionMulti = async (params: IndividualDailyRestrictionMultiParams) => {
508-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
530+
assert.assert(
531+
await this.isCallerAllowed(params.txData, Perm.Admin),
532+
ErrorCode.Unauthorized,
533+
'Caller is not allowed',
534+
);
509535
params.holders.forEach(address => assert.isNonZeroETHAddressHex('holders', address));
510536
assert.assert(
511537
params.startTimes.length === params.allowedTokens.length &&
512538
params.startTimes.length === params.restrictionTypes.length &&
513539
params.startTimes.length === params.holders.length &&
514540
params.startTimes.length === params.endTimes.length,
541+
ErrorCode.MismatchedArrayLength,
515542
'Array lengths missmatch',
516543
);
517544
let restrictions = [];
@@ -542,11 +569,16 @@ export default class VolumeRestrictionTransferManagerWrapper extends ModuleWrapp
542569
};
543570

544571
public addIndividualRestrictionMulti = async (params: IndividualRestrictionMultiParams) => {
545-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
572+
assert.assert(
573+
await this.isCallerAllowed(params.txData, Perm.Admin),
574+
ErrorCode.Unauthorized,
575+
'Caller is not allowed',
576+
);
546577
params.holders.forEach(address => assert.isNonZeroETHAddressHex('holders', address));
547578
const exemptAddress = await this.getExemptAddress();
548579
assert.assert(
549580
!exemptAddress.some(address => params.holders.includes(address)),
581+
ErrorCode.PreconditionRequired,
550582
'Holder is exempt from restriction',
551583
);
552584
assert.assert(
@@ -555,6 +587,7 @@ export default class VolumeRestrictionTransferManagerWrapper extends ModuleWrapp
555587
params.startTimes.length === params.rollingPeriodInDays.length &&
556588
params.startTimes.length === params.holders.length &&
557589
params.startTimes.length === params.endTimes.length,
590+
ErrorCode.MismatchedArrayLength,
558591
'Array lengths missmatch',
559592
);
560593
let restrictions = [];
@@ -586,7 +619,11 @@ export default class VolumeRestrictionTransferManagerWrapper extends ModuleWrapp
586619
};
587620

588621
public addDefaultRestriction = async (params: RestrictionParams) => {
589-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
622+
assert.assert(
623+
await this.isCallerAllowed(params.txData, Perm.Admin),
624+
ErrorCode.Unauthorized,
625+
'Caller is not allowed',
626+
);
590627
this.checkRestrictionInputParams(
591628
params.startTime,
592629
params.endTime,
@@ -607,7 +644,11 @@ export default class VolumeRestrictionTransferManagerWrapper extends ModuleWrapp
607644
};
608645

609646
public addDefaultDailyRestriction = async (params: DailyRestrictionParams) => {
610-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
647+
assert.assert(
648+
await this.isCallerAllowed(params.txData, Perm.Admin),
649+
ErrorCode.Unauthorized,
650+
'Caller is not allowed',
651+
);
611652
this.checkRestrictionInputParams(params.startTime, params.endTime, params.allowedTokens, params.restrictionType, 1);
612653
const decimals = await this.decimalsByRestrictionType(params.restrictionType);
613654
return (await this.contract).addDefaultDailyRestriction.sendTransactionAsync(
@@ -621,7 +662,11 @@ export default class VolumeRestrictionTransferManagerWrapper extends ModuleWrapp
621662
};
622663

623664
public removeIndividualRestriction = async (params: HolderIndividualRestrictionParams) => {
624-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
665+
assert.assert(
666+
await this.isCallerAllowed(params.txData, Perm.Admin),
667+
ErrorCode.Unauthorized,
668+
'Caller is not allowed',
669+
);
625670
assert.isNotDateZero(
626671
(await this.getIndividualRestriction({ investor: params.investor })).endTime,
627672
'Individual Restriction not set with end time',
@@ -635,7 +680,11 @@ export default class VolumeRestrictionTransferManagerWrapper extends ModuleWrapp
635680
};
636681

637682
public removeIndividualRestrictionMulti = async (params: RemoveIndividualRestrictionMultiParams) => {
638-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
683+
assert.assert(
684+
await this.isCallerAllowed(params.txData, Perm.Admin),
685+
ErrorCode.Unauthorized,
686+
'Caller is not allowed',
687+
);
639688
params.holders.forEach(address => assert.isNonZeroETHAddressHex('holders', address));
640689
await Promise.all(
641690
params.holders.map(async holder =>
@@ -653,7 +702,11 @@ export default class VolumeRestrictionTransferManagerWrapper extends ModuleWrapp
653702
};
654703

655704
public removeIndividualDailyRestriction = async (params: HolderIndividualRestrictionParams) => {
656-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
705+
assert.assert(
706+
await this.isCallerAllowed(params.txData, Perm.Admin),
707+
ErrorCode.Unauthorized,
708+
'Caller is not allowed',
709+
);
657710
assert.isNotDateZero(
658711
(await this.getIndividualDailyRestriction({ investor: params.investor })).endTime,
659712
'Individual Daily Restriction not set with end time',
@@ -667,7 +720,11 @@ export default class VolumeRestrictionTransferManagerWrapper extends ModuleWrapp
667720
};
668721

669722
public removeIndividualDailyRestrictionMulti = async (params: RemoveIndividualRestrictionMultiParams) => {
670-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
723+
assert.assert(
724+
await this.isCallerAllowed(params.txData, Perm.Admin),
725+
ErrorCode.Unauthorized,
726+
'Caller is not allowed',
727+
);
671728
await Promise.all(
672729
params.holders.map(async holder =>
673730
assert.isNotDateZero(
@@ -685,13 +742,21 @@ export default class VolumeRestrictionTransferManagerWrapper extends ModuleWrapp
685742
};
686743

687744
public removeDefaultRestriction = async (params: TxParams) => {
688-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
745+
assert.assert(
746+
await this.isCallerAllowed(params.txData, Perm.Admin),
747+
ErrorCode.Unauthorized,
748+
'Caller is not allowed',
749+
);
689750
assert.isNotDateZero((await this.getDefaultRestriction()).endTime, 'Individual Restriction not set with end time');
690751
return (await this.contract).removeDefaultRestriction.sendTransactionAsync(params.txData, params.safetyFactor);
691752
};
692753

693754
public removeDefaultDailyRestriction = async (params: TxParams) => {
694-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
755+
assert.assert(
756+
await this.isCallerAllowed(params.txData, Perm.Admin),
757+
ErrorCode.Unauthorized,
758+
'Caller is not allowed',
759+
);
695760
assert.isNotDateZero(
696761
(await this.getDefaultDailyRestriction()).endTime,
697762
'Individual Restriction not set with end time',
@@ -700,7 +765,11 @@ export default class VolumeRestrictionTransferManagerWrapper extends ModuleWrapp
700765
};
701766

702767
public modifyIndividualRestriction = async (params: IndividualRestrictionParams) => {
703-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
768+
assert.assert(
769+
await this.isCallerAllowed(params.txData, Perm.Admin),
770+
ErrorCode.Unauthorized,
771+
'Caller is not allowed',
772+
);
704773
assert.isNonZeroETHAddressHex('holder', params.holder);
705774
this.checkRestrictionInputParams(
706775
params.startTime,
@@ -723,7 +792,11 @@ export default class VolumeRestrictionTransferManagerWrapper extends ModuleWrapp
723792
};
724793

725794
public modifyIndividualDailyRestriction = async (params: IndividualDailyRestrictionParams) => {
726-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
795+
assert.assert(
796+
await this.isCallerAllowed(params.txData, Perm.Admin),
797+
ErrorCode.Unauthorized,
798+
'Caller is not allowed',
799+
);
727800
assert.isNonZeroETHAddressHex('holder', params.holder);
728801
this.checkRestrictionInputParams(params.startTime, params.endTime, params.allowedTokens, params.restrictionType, 1);
729802
const decimals = await this.decimalsByRestrictionType(params.restrictionType);
@@ -739,13 +812,18 @@ export default class VolumeRestrictionTransferManagerWrapper extends ModuleWrapp
739812
};
740813

741814
public modifyIndividualDailyRestrictionMulti = async (params: IndividualDailyRestrictionMultiParams) => {
742-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
815+
assert.assert(
816+
await this.isCallerAllowed(params.txData, Perm.Admin),
817+
ErrorCode.Unauthorized,
818+
'Caller is not allowed',
819+
);
743820
params.holders.forEach(address => assert.isNonZeroETHAddressHex('holders', address));
744821
assert.assert(
745822
params.startTimes.length === params.allowedTokens.length &&
746823
params.startTimes.length === params.restrictionTypes.length &&
747824
params.startTimes.length === params.holders.length &&
748825
params.startTimes.length === params.endTimes.length,
826+
ErrorCode.MismatchedArrayLength,
749827
'Array lengths missmatch',
750828
);
751829
let restrictions = [];
@@ -776,14 +854,19 @@ export default class VolumeRestrictionTransferManagerWrapper extends ModuleWrapp
776854
};
777855

778856
public modifyIndividualRestrictionMulti = async (params: IndividualRestrictionMultiParams) => {
779-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
857+
assert.assert(
858+
await this.isCallerAllowed(params.txData, Perm.Admin),
859+
ErrorCode.Unauthorized,
860+
'Caller is not allowed',
861+
);
780862
params.holders.forEach(address => assert.isNonZeroETHAddressHex('holders', address));
781863
assert.assert(
782864
params.startTimes.length === params.allowedTokens.length &&
783865
params.startTimes.length === params.restrictionTypes.length &&
784866
params.startTimes.length === params.rollingPeriodInDays.length &&
785867
params.startTimes.length === params.holders.length &&
786868
params.startTimes.length === params.endTimes.length,
869+
ErrorCode.MismatchedArrayLength,
787870
'Array lengths missmatch',
788871
);
789872
let restrictions = [];
@@ -815,7 +898,11 @@ export default class VolumeRestrictionTransferManagerWrapper extends ModuleWrapp
815898
};
816899

817900
public modifyDefaultRestriction = async (params: RestrictionParams) => {
818-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
901+
assert.assert(
902+
await this.isCallerAllowed(params.txData, Perm.Admin),
903+
ErrorCode.Unauthorized,
904+
'Caller is not allowed',
905+
);
819906
this.checkRestrictionInputParams(
820907
params.startTime,
821908
params.endTime,
@@ -836,7 +923,11 @@ export default class VolumeRestrictionTransferManagerWrapper extends ModuleWrapp
836923
};
837924

838925
public modifyDefaultDailyRestriction = async (params: DailyRestrictionParams) => {
839-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
926+
assert.assert(
927+
await this.isCallerAllowed(params.txData, Perm.Admin),
928+
ErrorCode.Unauthorized,
929+
'Caller is not allowed',
930+
);
840931
this.checkRestrictionInputParams(params.startTime, params.endTime, params.allowedTokens, params.restrictionType, 1);
841932
const decimals = await this.decimalsByRestrictionType(params.restrictionType);
842933
return (await this.contract).modifyDefaultDailyRestriction.sendTransactionAsync(
@@ -963,10 +1054,15 @@ export default class VolumeRestrictionTransferManagerWrapper extends ModuleWrapp
9631054
if (restrictionType === RestrictionType.Percentage) {
9641055
assert.isPercentage('allowed tokens', allowedTokens);
9651056
}
966-
assert.assert(rollingPeriodInDays <= 365 && rollingPeriodInDays >= 1, 'Invalid number of days in rolling period');
1057+
assert.assert(
1058+
rollingPeriodInDays <= 365 && rollingPeriodInDays >= 1,
1059+
ErrorCode.InvalidData,
1060+
'Invalid number of days in rolling period',
1061+
);
9671062
const diffDays = Math.ceil(Math.abs(endTime.getTime() - startTime.getTime()) / (1000 * 3600 * 24));
9681063
assert.assert(
9691064
new BigNumber(diffDays).isGreaterThanOrEqualTo(rollingPeriodInDays),
1065+
ErrorCode.InvalidData,
9701066
'Invalid times, rollingPeriodInDays must have less days than the duration',
9711067
);
9721068
};

0 commit comments

Comments
 (0)