@@ -34,6 +34,7 @@ import {
34
34
Subscribe ,
35
35
SubscribeAsyncParams ,
36
36
TxParams ,
37
+ ErrorCode ,
37
38
} from '../../../types' ;
38
39
import {
39
40
bigNumberToDate ,
@@ -441,9 +442,14 @@ export default class USDTieredSTOWrapper extends STOWrapper {
441
442
} ;
442
443
443
444
public changeAllowBeneficialInvestments = async ( params : ChangeAllowBeneficialInvestmentsParams ) => {
444
- assert . assert ( await this . isCallerTheSecurityTokenOwner ( params . txData ) , 'The caller must be the ST owner' ) ;
445
+ assert . assert (
446
+ await this . isCallerTheSecurityTokenOwner ( params . txData ) ,
447
+ ErrorCode . Unauthorized ,
448
+ 'The caller must be the ST owner' ,
449
+ ) ;
445
450
assert . assert (
446
451
params . allowBeneficialInvestments !== ( await this . allowBeneficialInvestments ( ) ) ,
452
+ ErrorCode . PreconditionRequired ,
447
453
'The value must be different' ,
448
454
) ;
449
455
return ( await this . contract ) . changeAllowBeneficialInvestments . sendTransactionAsync (
@@ -597,7 +603,7 @@ export default class USDTieredSTOWrapper extends STOWrapper {
597
603
598
604
public getTokensSoldByTier = async ( params : TierIndexParams ) => {
599
605
const tiers = await this . getNumberOfTiers ( ) ;
600
- assert . assert ( params . tier < new BigNumber ( tiers ) . toNumber ( ) , 'Invalid tier' ) ;
606
+ assert . assert ( params . tier < new BigNumber ( tiers ) . toNumber ( ) , ErrorCode . InvalidData , 'Invalid tier' ) ;
601
607
return weiToValue (
602
608
await ( await this . contract ) . getTokensSoldByTier . callAsync ( numberToBigNumber ( params . tier ) ) ,
603
609
await ( await this . securityTokenContract ( ) ) . decimals . callAsync ( ) ,
@@ -711,7 +717,7 @@ export default class USDTieredSTOWrapper extends STOWrapper {
711
717
*/
712
718
public getTokensMintedByTier = async ( params : TierIndexParams ) => {
713
719
const decimals = await ( await this . securityTokenContract ( ) ) . decimals . callAsync ( ) ;
714
- assert . assert ( params . tier < ( await this . getNumberOfTiers ( ) ) . toNumber ( ) , 'Invalid tier' ) ;
720
+ assert . assert ( params . tier < ( await this . getNumberOfTiers ( ) ) . toNumber ( ) , ErrorCode . InvalidData , 'Invalid tier' ) ;
715
721
const result = await ( await this . contract ) . getTokensMintedByTier . callAsync ( numberToBigNumber ( params . tier ) ) ;
716
722
const typedResult : MintedByTier = {
717
723
mintedInETH : weiToValue ( result [ 0 ] , decimals ) ,
@@ -759,8 +765,12 @@ export default class USDTieredSTOWrapper extends STOWrapper {
759
765
* Reserve address must be whitelisted to successfully finalize
760
766
*/
761
767
public finalize = async ( params : TxParams ) => {
762
- assert . assert ( await this . isCallerTheSecurityTokenOwner ( params . txData ) , 'The caller must be the ST owner' ) ;
763
- assert . assert ( ! ( await this . isFinalized ( ) ) , 'STO is finalized' ) ;
768
+ assert . assert (
769
+ await this . isCallerTheSecurityTokenOwner ( params . txData ) ,
770
+ ErrorCode . Unauthorized ,
771
+ 'The caller must be the ST owner' ,
772
+ ) ;
773
+ assert . assert ( ! ( await this . isFinalized ( ) ) , ErrorCode . PreconditionRequired , 'STO is finalized' ) ;
764
774
// we can't execute mint to validate the method
765
775
return ( await this . contract ) . finalize . sendTransactionAsync ( params . txData , params . safetyFactor ) ;
766
776
} ;
@@ -769,9 +779,17 @@ export default class USDTieredSTOWrapper extends STOWrapper {
769
779
* Modifies the list of overrides for non-accredited limits in USD
770
780
*/
771
781
public changeNonAccreditedLimit = async ( params : ChangeNonAccreditedLimitParams ) => {
772
- assert . assert ( await this . isCallerTheSecurityTokenOwner ( params . txData ) , 'The caller must be the ST owner' ) ;
782
+ assert . assert (
783
+ await this . isCallerTheSecurityTokenOwner ( params . txData ) ,
784
+ ErrorCode . Unauthorized ,
785
+ 'The caller must be the ST owner' ,
786
+ ) ;
773
787
params . investors . forEach ( address => assert . isETHAddressHex ( 'investors' , address ) ) ;
774
- assert . assert ( params . investors . length === params . nonAccreditedLimit . length , 'Array length mismatch' ) ;
788
+ assert . assert (
789
+ params . investors . length === params . nonAccreditedLimit . length ,
790
+ ErrorCode . MismatchedArrayLength ,
791
+ 'Array length mismatch' ,
792
+ ) ;
775
793
return ( await this . contract ) . changeNonAccreditedLimit . sendTransactionAsync (
776
794
params . investors ,
777
795
valueArrayToWeiArray ( params . nonAccreditedLimit , FULL_DECIMALS ) ,
@@ -784,9 +802,13 @@ export default class USDTieredSTOWrapper extends STOWrapper {
784
802
* Modifies STO start and end times
785
803
*/
786
804
public modifyTimes = async ( params : ModifyTimesParams ) => {
787
- assert . assert ( await this . isCallerTheSecurityTokenOwner ( params . txData ) , 'The caller must be the ST owner' ) ;
805
+ assert . assert (
806
+ await this . isCallerTheSecurityTokenOwner ( params . txData ) ,
807
+ ErrorCode . Unauthorized ,
808
+ 'The caller must be the ST owner' ,
809
+ ) ;
788
810
assert . isFutureDate ( bigNumberToDate ( await this . startTime ( ) ) , 'STO already started' ) ;
789
- assert . assert ( params . endTime > params . startTime , 'Start date must be greater than end time' ) ;
811
+ assert . assert ( params . endTime > params . startTime , ErrorCode . TooEarly , 'Start date must be greater than end time' ) ;
790
812
assert . isFutureDate ( params . startTime , 'Start date must be in the future' ) ;
791
813
return ( await this . contract ) . modifyTimes . sendTransactionAsync (
792
814
dateToBigNumber ( params . startTime ) ,
@@ -800,9 +822,14 @@ export default class USDTieredSTOWrapper extends STOWrapper {
800
822
* Modifies oracle
801
823
*/
802
824
public modifyOracle = async ( params : ModifyOracleParams ) => {
803
- assert . assert ( await this . isCallerTheSecurityTokenOwner ( params . txData ) , 'The caller must be the ST owner' ) ;
825
+ assert . assert (
826
+ await this . isCallerTheSecurityTokenOwner ( params . txData ) ,
827
+ ErrorCode . Unauthorized ,
828
+ 'The caller must be the ST owner' ,
829
+ ) ;
804
830
assert . assert (
805
831
params . fundRaiseType === FundRaiseType . POLY || params . fundRaiseType === FundRaiseType . ETH ,
832
+ ErrorCode . InvalidData ,
806
833
'Invalid currency' ,
807
834
) ;
808
835
return ( await this . contract ) . modifyOracle . sendTransactionAsync (
@@ -817,7 +844,11 @@ export default class USDTieredSTOWrapper extends STOWrapper {
817
844
* Modifies max non accredited invets limit and overall minimum investment limit
818
845
*/
819
846
public modifyLimits = async ( params : ModifyLimitsParams ) => {
820
- assert . assert ( await this . isCallerTheSecurityTokenOwner ( params . txData ) , 'The caller must be the ST owner' ) ;
847
+ assert . assert (
848
+ await this . isCallerTheSecurityTokenOwner ( params . txData ) ,
849
+ ErrorCode . Unauthorized ,
850
+ 'The caller must be the ST owner' ,
851
+ ) ;
821
852
assert . isFutureDate ( bigNumberToDate ( await this . startTime ( ) ) , 'STO already started' ) ;
822
853
return ( await this . contract ) . modifyLimits . sendTransactionAsync (
823
854
valueToWei ( params . nonAccreditedLimitUSD , FULL_DECIMALS ) ,
@@ -831,7 +862,11 @@ export default class USDTieredSTOWrapper extends STOWrapper {
831
862
* Modifies fund raise types
832
863
*/
833
864
public modifyFunding = async ( params : ModifyFundingParams ) => {
834
- assert . assert ( await this . isCallerTheSecurityTokenOwner ( params . txData ) , 'The caller must be the ST owner' ) ;
865
+ assert . assert (
866
+ await this . isCallerTheSecurityTokenOwner ( params . txData ) ,
867
+ ErrorCode . Unauthorized ,
868
+ 'The caller must be the ST owner' ,
869
+ ) ;
835
870
assert . isFutureDate ( bigNumberToDate ( await this . startTime ( ) ) , 'STO already started' ) ;
836
871
return ( await this . contract ) . modifyFunding . sendTransactionAsync (
837
872
params . fundRaiseTypes ,
@@ -844,7 +879,11 @@ export default class USDTieredSTOWrapper extends STOWrapper {
844
879
* Modifies addresses used as wallet, reserve wallet and usd token
845
880
*/
846
881
public modifyAddresses = async ( params : ModifyAddressesParams ) => {
847
- assert . assert ( await this . isCallerTheSecurityTokenOwner ( params . txData ) , 'The caller must be the ST owner' ) ;
882
+ assert . assert (
883
+ await this . isCallerTheSecurityTokenOwner ( params . txData ) ,
884
+ ErrorCode . Unauthorized ,
885
+ 'The caller must be the ST owner' ,
886
+ ) ;
848
887
params . usdTokens . forEach ( address => assert . isETHAddressHex ( 'usdTokens' , address ) ) ;
849
888
assert . isNonZeroETHAddressHex ( 'wallet' , params . wallet ) ;
850
889
assert . isNonZeroETHAddressHex ( 'treasuryWallet' , params . treasuryWallet ) ;
@@ -861,23 +900,33 @@ export default class USDTieredSTOWrapper extends STOWrapper {
861
900
* Modifiers STO tiers. All tiers must be passed, can not edit specific tiers.
862
901
*/
863
902
public modifyTiers = async ( params : ModifyTiersParams ) => {
864
- assert . assert ( await this . isCallerTheSecurityTokenOwner ( params . txData ) , 'The caller must be the ST owner' ) ;
903
+ assert . assert (
904
+ await this . isCallerTheSecurityTokenOwner ( params . txData ) ,
905
+ ErrorCode . Unauthorized ,
906
+ 'The caller must be the ST owner' ,
907
+ ) ;
865
908
assert . isFutureDate ( bigNumberToDate ( await this . startTime ( ) ) , 'STO already started' ) ;
866
- assert . assert ( params . tokensPerTierTotal . length > 0 , 'No tiers provided' ) ;
909
+ assert . assert ( params . tokensPerTierTotal . length > 0 , ErrorCode . MismatchedArrayLength , 'No tiers provided' ) ;
867
910
assert . assert (
868
911
params . ratePerTier . length === params . tokensPerTierTotal . length &&
869
912
params . ratePerTierDiscountPoly . length === params . tokensPerTierTotal . length &&
870
913
params . tokensPerTierDiscountPoly . length === params . tokensPerTierTotal . length ,
914
+ ErrorCode . MismatchedArrayLength ,
871
915
'Tier data arrays length mismatch' ,
872
916
) ;
873
917
for ( let i = 0 ; i < params . tokensPerTierTotal . length ; i += 1 ) {
874
918
assert . isBigNumberGreaterThanZero ( params . ratePerTier [ i ] , 'Invalid rate' ) ;
875
919
assert . isBigNumberGreaterThanZero ( params . tokensPerTierTotal [ i ] , 'Invalid token amount' ) ;
876
920
assert . assert (
877
921
params . tokensPerTierDiscountPoly [ i ] . isLessThanOrEqualTo ( params . tokensPerTierTotal [ i ] ) ,
922
+ ErrorCode . InvalidDiscount ,
878
923
'Too many discounted tokens' ,
879
924
) ;
880
- assert . assert ( params . ratePerTierDiscountPoly [ i ] . isLessThanOrEqualTo ( params . ratePerTier [ i ] ) , 'Invalid discount' ) ;
925
+ assert . assert (
926
+ params . ratePerTierDiscountPoly [ i ] . isLessThanOrEqualTo ( params . ratePerTier [ i ] ) ,
927
+ ErrorCode . InvalidDiscount ,
928
+ 'Invalid discount' ,
929
+ ) ;
881
930
}
882
931
const decimals = await ( await this . securityTokenContract ( ) ) . decimals . callAsync ( ) ;
883
932
return ( await this . contract ) . modifyTiers . sendTransactionAsync (
@@ -956,45 +1005,55 @@ export default class USDTieredSTOWrapper extends STOWrapper {
956
1005
usdToken ?: string ,
957
1006
) => {
958
1007
assert . isETHAddressHex ( 'beneficiary' , beneficiary ) ;
959
- assert . assert ( ! ( await this . paused ( ) ) , 'Contract is Paused' ) ;
960
- assert . assert ( await this . isOpen ( ) , 'STO not open' ) ;
1008
+ assert . assert ( ! ( await this . paused ( ) ) , ErrorCode . PreconditionRequired , 'Contract is Paused' ) ;
1009
+ assert . assert ( await this . isOpen ( ) , ErrorCode . STOClosed , 'STO not open' ) ;
961
1010
assert . isBigNumberGreaterThanZero ( investmentValue , 'No funds were sent' ) ;
962
1011
const stoDetails = await this . getSTODetails ( ) ;
963
1012
switch ( fundRaiseType ) {
964
1013
case FundRaiseType . ETH : {
965
- assert . assert ( stoDetails . isRaisedInETH , 'ETH Not Allowed' ) ;
1014
+ assert . assert ( stoDetails . isRaisedInETH , ErrorCode . CoinNotAllowed , 'ETH Not Allowed' ) ;
966
1015
const weiBalance = await this . web3Wrapper . getBalanceInWeiAsync ( from ) ;
967
- assert . assert ( weiBalance . isGreaterThan ( investmentValue ) , 'Insufficient ETH funds' ) ;
1016
+ assert . assert (
1017
+ weiBalance . isGreaterThan ( investmentValue ) ,
1018
+ ErrorCode . InsufficientBalance ,
1019
+ 'Insufficient ETH funds' ,
1020
+ ) ;
968
1021
break ;
969
1022
}
970
1023
case FundRaiseType . POLY : {
971
- assert . assert ( stoDetails . isRaisedInPOLY , 'POLY Not Allowed' ) ;
1024
+ assert . assert ( stoDetails . isRaisedInPOLY , ErrorCode . CoinNotAllowed , 'POLY Not Allowed' ) ;
972
1025
const polyTokenBalance = await ( await this . polyTokenContract ( ) ) . balanceOf . callAsync ( from ) ;
973
1026
assert . assert (
974
1027
polyTokenBalance . isGreaterThanOrEqualTo ( investmentValue ) ,
1028
+ ErrorCode . InsufficientBalance ,
975
1029
'Budget less than amount unable to transfer fee' ,
976
1030
) ;
977
1031
break ;
978
1032
}
979
1033
case FundRaiseType . StableCoin : {
980
- assert . assert ( stoDetails . isRaisedInSC , 'USD Not Allowed' ) ;
981
- assert . assert ( usdToken !== null , 'USD Token Address must exist' ) ;
1034
+ assert . assert ( stoDetails . isRaisedInSC , ErrorCode . CoinNotAllowed , 'USD Not Allowed' ) ;
1035
+ assert . assert ( usdToken !== null , ErrorCode . InvalidAddress , 'USD Token Address must exist' ) ;
982
1036
if ( usdToken ) {
983
1037
const scTokenBalance = await ( await this . detailedERC20TokenContract ( usdToken ) ) . balanceOf . callAsync ( from ) ;
984
1038
assert . assert (
985
1039
scTokenBalance . isGreaterThanOrEqualTo ( investmentValue ) ,
1040
+ ErrorCode . InsufficientBalance ,
986
1041
'Budget less than amount unable to transfer fee' ,
987
1042
) ;
988
1043
}
989
1044
break ;
990
1045
}
991
1046
default : {
992
- assert . assert ( false , 'Missing fundraise type' ) ;
1047
+ assert . assert ( false , ErrorCode . InvalidData , 'Missing fundraise type' ) ;
993
1048
break ;
994
1049
}
995
1050
}
996
1051
if ( ! ( await this . allowBeneficialInvestments ( ) ) ) {
997
- assert . assert ( functionsUtils . checksumAddressComparision ( beneficiary , from ) , 'Beneficiary != funder' ) ;
1052
+ assert . assert (
1053
+ functionsUtils . checksumAddressComparision ( beneficiary , from ) ,
1054
+ ErrorCode . Unauthorized ,
1055
+ 'Beneficiary != funder' ,
1056
+ ) ;
998
1057
}
999
1058
const rate = await this . getRate ( {
1000
1059
fundRaiseType,
@@ -1004,7 +1063,11 @@ export default class USDTieredSTOWrapper extends STOWrapper {
1004
1063
investorAddress : beneficiary ,
1005
1064
} ) ;
1006
1065
const minimumInvestmentUSD = await this . minimumInvestmentUSD ( ) ;
1007
- assert . assert ( investedUSD . plus ( investorInvestedUSD ) . isGreaterThan ( minimumInvestmentUSD ) , 'Investment < min' ) ;
1066
+ assert . assert (
1067
+ investedUSD . plus ( investorInvestedUSD ) . isGreaterThan ( minimumInvestmentUSD ) ,
1068
+ ErrorCode . InsufficientBalance ,
1069
+ 'Investment < min' ,
1070
+ ) ;
1008
1071
1009
1072
const generalTMAddress = await ( await this . securityTokenContract ( ) ) . getModulesByName . callAsync (
1010
1073
stringToBytes32 ( ModuleName . GeneralTransferManager ) ,
@@ -1026,7 +1089,7 @@ export default class USDTieredSTOWrapper extends STOWrapper {
1026
1089
! nonAccreditedLimit || nonAccreditedLimit . isEqualTo ( BIG_NUMBER_ZERO )
1027
1090
? await this . nonAccreditedLimitUSD ( )
1028
1091
: nonAccreditedLimit ;
1029
- assert . assert ( investorInvestedUSD . isLessThan ( nonAccreditedLimitUSD ) , 'Over investor limit' ) ;
1092
+ assert . assert ( investorInvestedUSD . isLessThan ( nonAccreditedLimitUSD ) , ErrorCode . ErrorLimit , 'Over investor limit' ) ;
1030
1093
}
1031
1094
} ;
1032
1095
}
0 commit comments