@@ -73,6 +73,7 @@ import {
73
73
TxParams ,
74
74
CappedSTOFundRaiseType ,
75
75
TransferStatusCode ,
76
+ ErrorCode
76
77
} from '../../types' ;
77
78
import {
78
79
bigNumberToDate ,
@@ -1120,7 +1121,7 @@ export default class SecurityTokenWrapper extends ERC20TokenWrapper {
1120
1121
1121
1122
public changeName = async ( params : ChangeNameParams ) => {
1122
1123
await this . checkOnlyOwner ( params . txData ) ;
1123
- assert . assert ( params . name . length > 0 , 'Name required' ) ;
1124
+ assert . assert ( params . name . length > 0 , ErrorCode . InvalidData , 'Name required' ) ;
1124
1125
return ( await this . contract ) . changeName . sendTransactionAsync ( params . name , params . txData , params . safetyFactor ) ;
1125
1126
} ;
1126
1127
@@ -1177,13 +1178,13 @@ export default class SecurityTokenWrapper extends ERC20TokenWrapper {
1177
1178
1178
1179
public freezeTransfers = async ( params : TxParams ) => {
1179
1180
await this . checkOnlyOwner ( params . txData ) ;
1180
- assert . assert ( ! ( await this . transfersFrozen ( ) ) , 'Transfers already frozen' ) ;
1181
+ assert . assert ( ! ( await this . transfersFrozen ( ) ) , ErrorCode . PreconditionRequired , 'Transfers already frozen' ) ;
1181
1182
return ( await this . contract ) . freezeTransfers . sendTransactionAsync ( params . txData , params . safetyFactor ) ;
1182
1183
} ;
1183
1184
1184
1185
public unfreezeTransfers = async ( params : TxParams ) => {
1185
1186
await this . checkOnlyOwner ( params . txData ) ;
1186
- assert . assert ( await this . transfersFrozen ( ) , 'Transfers are not frozen' ) ;
1187
+ assert . assert ( await this . transfersFrozen ( ) , ErrorCode . PreconditionRequired , 'Transfers are not frozen' ) ;
1187
1188
return ( await this . contract ) . unfreezeTransfers . sendTransactionAsync ( params . txData , params . safetyFactor ) ;
1188
1189
} ;
1189
1190
@@ -1212,12 +1213,13 @@ export default class SecurityTokenWrapper extends ERC20TokenWrapper {
1212
1213
} ;
1213
1214
1214
1215
public freezeIssuance = async ( params : FreezeIssuanceParams ) => {
1215
- assert . assert ( await this . isIssuable ( ) , 'Issuance frozen' ) ;
1216
+ assert . assert ( await this . isIssuable ( ) , ErrorCode . PreconditionRequired , 'Issuance frozen' ) ;
1216
1217
assert . assert (
1217
1218
functionsUtils . checksumAddressComparision (
1218
1219
await this . owner ( ) ,
1219
1220
( await this . web3Wrapper . getAvailableAddressesAsync ( ) ) [ 0 ] ,
1220
1221
) ,
1222
+ ErrorCode . Unauthorized ,
1221
1223
'Msg sender must be owner' ,
1222
1224
) ;
1223
1225
return ( await this . contract ) . freezeIssuance . sendTransactionAsync (
@@ -1230,14 +1232,15 @@ export default class SecurityTokenWrapper extends ERC20TokenWrapper {
1230
1232
public issue = async ( params : IssueParams ) => {
1231
1233
assert . isNonZeroETHAddressHex ( 'investor' , params . investor ) ;
1232
1234
await this . checkOnlyOwner ( params . txData ) ;
1233
- assert . assert ( await this . isIssuable ( ) , 'Issuance frozen' ) ;
1235
+ assert . assert ( await this . isIssuable ( ) , ErrorCode . PreconditionRequired , 'Issuance frozen' ) ;
1234
1236
const canTransfer = await this . canTransfer ( {
1235
1237
to : params . investor ,
1236
1238
value : params . value ,
1237
1239
data : params . data || '0x00' ,
1238
1240
} ) ;
1239
1241
assert . assert (
1240
1242
canTransfer . statusCode !== TransferStatusCode . TransferFailure ,
1243
+ ErrorCode . InvalidTransfer ,
1241
1244
`Transfer Status: ${ canTransfer . statusCode } ` ,
1242
1245
) ;
1243
1246
return ( await this . contract ) . issue . sendTransactionAsync (
@@ -1252,7 +1255,7 @@ export default class SecurityTokenWrapper extends ERC20TokenWrapper {
1252
1255
public issueByPartition = async ( params : IssueByPartitionParams ) => {
1253
1256
assert . isNonZeroETHAddressHex ( 'investor' , params . investor ) ;
1254
1257
await this . checkOnlyOwner ( params . txData ) ;
1255
- assert . assert ( await this . isIssuable ( ) , 'Issuance frozen' ) ;
1258
+ assert . assert ( await this . isIssuable ( ) , ErrorCode . PreconditionRequired , 'Issuance frozen' ) ;
1256
1259
assert . isValidPartition ( params . partition ) ;
1257
1260
return ( await this . contract ) . issueByPartition . sendTransactionAsync (
1258
1261
params . partition ,
@@ -1268,9 +1271,10 @@ export default class SecurityTokenWrapper extends ERC20TokenWrapper {
1268
1271
params . investors . forEach ( address => assert . isNonZeroETHAddressHex ( 'investors' , address ) ) ;
1269
1272
assert . assert (
1270
1273
params . investors . length === params . values . length ,
1274
+ ErrorCode . MismatchedLength ,
1271
1275
'Number of investors passed in must be equivalent to number of values' ,
1272
1276
) ;
1273
- assert . assert ( await this . isIssuable ( ) , 'Issuance frozen' ) ;
1277
+ assert . assert ( await this . isIssuable ( ) , ErrorCode . PreconditionRequired , 'Issuance frozen' ) ;
1274
1278
await this . checkOnlyOwner ( params . txData ) ;
1275
1279
return ( await this . contract ) . issueMulti . sendTransactionAsync (
1276
1280
params . investors ,
@@ -1315,7 +1319,7 @@ export default class SecurityTokenWrapper extends ERC20TokenWrapper {
1315
1319
public operatorRedeemByPartition = async ( params : OperatorRedeemByPartitionParams ) => {
1316
1320
await this . checkBalanceFromGreaterThanValue ( ( await this . web3Wrapper . getAvailableAddressesAsync ( ) ) [ 0 ] , params . value ) ;
1317
1321
assert . isNonZeroETHAddressHex ( 'TokenHolder' , params . tokenHolder ) ;
1318
- assert . assert ( params . operatorData . length > 0 , 'Operator data cannot be 0' ) ;
1322
+ assert . assert ( params . operatorData . length > 0 , ErrorCode . InvalidData , 'Operator data cannot be 0' ) ;
1319
1323
assert . isValidPartition ( params . partition ) ;
1320
1324
return ( await this . contract ) . operatorRedeemByPartition . sendTransactionAsync (
1321
1325
params . partition ,
@@ -1335,6 +1339,7 @@ export default class SecurityTokenWrapper extends ERC20TokenWrapper {
1335
1339
owner : params . from ,
1336
1340
spender : ( await this . web3Wrapper . getAvailableAddressesAsync ( ) ) [ 0 ] ,
1337
1341
} ) ) . isGreaterThanOrEqualTo ( params . value ) ,
1342
+ ErrorCode . InsufficientAllowance ,
1338
1343
'Insufficient allowance for inputted burn value' ,
1339
1344
) ;
1340
1345
assert . isETHAddressHex ( 'from' , params . from ) ;
@@ -1351,6 +1356,7 @@ export default class SecurityTokenWrapper extends ERC20TokenWrapper {
1351
1356
await this . checkOnlyOwner ( params . txData ) ;
1352
1357
assert . assert (
1353
1358
( await this . currentCheckpointId ( ) ) . isLessThan ( MAX_CHECKPOINT_NUMBER ) ,
1359
+ ErrorCode . PreconditionRequired ,
1354
1360
'Reached maximum checkpoint number' ,
1355
1361
) ;
1356
1362
return ( await this . contract ) . createCheckpoint . sendTransactionAsync ( params . txData , params . safetyFactor ) ;
@@ -1365,6 +1371,7 @@ export default class SecurityTokenWrapper extends ERC20TokenWrapper {
1365
1371
public totalSupplyAt = async ( params : CheckpointIdParams ) => {
1366
1372
assert . assert (
1367
1373
( await this . currentCheckpointId ( ) ) . isGreaterThanOrEqualTo ( params . checkpointId ) ,
1374
+ ErrorCode . InvalidData ,
1368
1375
'Checkpoint id must be less than or equal to currentCheckpoint' ,
1369
1376
) ;
1370
1377
return weiToValue (
@@ -1377,6 +1384,7 @@ export default class SecurityTokenWrapper extends ERC20TokenWrapper {
1377
1384
assert . isETHAddressHex ( 'investor' , params . investor ) ;
1378
1385
assert . assert (
1379
1386
( await this . currentCheckpointId ( ) ) . isGreaterThanOrEqualTo ( params . checkpointId ) ,
1387
+ ErrorCode . InvalidData ,
1380
1388
'Checkpoint id must be less than or equal to currentCheckpoint' ,
1381
1389
) ;
1382
1390
return weiToValue (
@@ -1449,7 +1457,7 @@ export default class SecurityTokenWrapper extends ERC20TokenWrapper {
1449
1457
public operatorTransferByPartition = async ( params : OperatorTransferByPartitionParams ) => {
1450
1458
assert . isETHAddressHex ( 'To' , params . to ) ;
1451
1459
assert . isETHAddressHex ( 'From' , params . from ) ;
1452
- assert . assert ( params . operatorData . length > 0 , 'Operator data cannot be 0' ) ;
1460
+ assert . assert ( params . operatorData . length > 0 , ErrorCode . InvalidData , 'Operator data cannot be 0' ) ;
1453
1461
assert . isValidPartition ( params . partition ) ;
1454
1462
return ( await this . contract ) . operatorTransferByPartition . sendTransactionAsync (
1455
1463
stringToBytes32 ( params . partition ) ,
@@ -1701,8 +1709,8 @@ export default class SecurityTokenWrapper extends ERC20TokenWrapper {
1701
1709
} ;
1702
1710
1703
1711
public setDocument = async ( params : SetDocumentParams ) => {
1704
- assert . assert ( params . name . length > 0 , 'Bad name, cannot be empty' ) ;
1705
- assert . assert ( params . uri . length > 0 , 'Bad uri, cannot be empty' ) ;
1712
+ assert . assert ( params . name . length > 0 , ErrorCode . InvalidData , 'Bad name, cannot be empty' ) ;
1713
+ assert . assert ( params . uri . length > 0 , ErrorCode . InvalidData , 'Bad uri, cannot be empty' ) ;
1706
1714
await this . checkOnlyOwner ( params . txData ) ;
1707
1715
return ( await this . contract ) . setDocument . sendTransactionAsync (
1708
1716
stringToBytes32 ( params . name ) ,
@@ -1716,7 +1724,7 @@ export default class SecurityTokenWrapper extends ERC20TokenWrapper {
1716
1724
public removeDocument = async ( params : DocumentParams ) => {
1717
1725
await this . checkOnlyOwner ( params . txData ) ;
1718
1726
const document = await this . getDocument ( { name : params . name } ) ;
1719
- assert . assert ( document . documentUri . length !== 0 , 'Document does not exist' ) ;
1727
+ assert . assert ( document . documentUri . length !== 0 , ErrorCode . NotFound , 'Document does not exist' ) ;
1720
1728
return ( await this . contract ) . removeDocument . sendTransactionAsync (
1721
1729
stringToBytes32 ( params . name ) ,
1722
1730
params . txData ,
@@ -1781,15 +1789,15 @@ export default class SecurityTokenWrapper extends ERC20TokenWrapper {
1781
1789
} ;
1782
1790
1783
1791
private checkModuleExists = async ( moduleAddress : string ) => {
1784
- assert . assert ( ( await this . getModule ( { moduleAddress } ) ) . name !== '' , 'Module does not exist' ) ;
1792
+ assert . assert ( ( await this . getModule ( { moduleAddress } ) ) . name !== '' , ErrorCode . NotFound , 'Module does not exist' ) ;
1785
1793
} ;
1786
1794
1787
1795
private checkIsArchived = async ( moduleAddress : string ) => {
1788
- assert . assert ( ( await this . getModule ( { moduleAddress } ) ) . archived , 'Module is not yet archived' ) ;
1796
+ assert . assert ( ( await this . getModule ( { moduleAddress } ) ) . archived , ErrorCode . PreconditionRequired , 'Module is not yet archived' ) ;
1789
1797
} ;
1790
1798
1791
1799
private checkIsNotArchived = async ( moduleAddress : string ) => {
1792
- assert . assert ( ! ( await this . getModule ( { moduleAddress } ) ) . archived , 'Module is archived' ) ;
1800
+ assert . assert ( ! ( await this . getModule ( { moduleAddress } ) ) . archived , ErrorCode . PreconditionRequired , 'Module is archived' ) ;
1793
1801
} ;
1794
1802
1795
1803
private checkModuleStructAddressIsNotZero = async ( moduleAddress : string ) => {
@@ -1802,17 +1810,19 @@ export default class SecurityTokenWrapper extends ERC20TokenWrapper {
1802
1810
( await this . getModule ( { moduleAddress } ) ) . address ,
1803
1811
'0x0000000000000000000000000000000000000000' ,
1804
1812
) ,
1813
+ ErrorCode . AlreadyExists ,
1805
1814
'Module already exists at that address' ,
1806
1815
) ;
1807
1816
} ;
1808
1817
1809
1818
private checkIsControllable = async ( ) => {
1810
- assert . assert ( await this . isControllable ( ) , 'Controller currently disabled' ) ;
1819
+ assert . assert ( await this . isControllable ( ) , ErrorCode . PreconditionRequired , 'Controller currently disabled' ) ;
1811
1820
} ;
1812
1821
1813
1822
private checkBalanceFromGreaterThanValue = async ( from : string , value : BigNumber ) => {
1814
1823
assert . assert (
1815
1824
( await this . balanceOf ( { owner : from } ) ) . isGreaterThanOrEqualTo ( value ) ,
1825
+ ErrorCode . InsufficientBalance ,
1816
1826
'Insufficient balance for inputted value' ,
1817
1827
) ;
1818
1828
} ;
@@ -1821,25 +1831,29 @@ export default class SecurityTokenWrapper extends ERC20TokenWrapper {
1821
1831
const moduleCost = await ( await this . moduleFactoryContract ( moduleFactory ) ) . setupCostInPoly . callAsync ( ) ;
1822
1832
assert . assert (
1823
1833
maxCost . isGreaterThanOrEqualTo ( moduleCost ) ,
1834
+ ErrorCode . InsufficientBalance ,
1824
1835
'Insufficient max cost to cover module factory setup cost' ,
1825
1836
) ;
1826
1837
const polyTokenBalance = await ( await this . polyTokenContract ( ) ) . balanceOf . callAsync ( await this . address ( ) ) ;
1827
1838
assert . assert (
1828
1839
polyTokenBalance . isGreaterThanOrEqualTo ( moduleCost ) ,
1840
+ ErrorCode . InsufficientBalance ,
1829
1841
'Insufficient poly token balance for module cost' ,
1830
1842
) ;
1831
1843
} ;
1832
1844
1833
1845
private checkOnlyOwner = async ( txData : Partial < TxData > | undefined ) => {
1834
1846
assert . assert (
1835
1847
functionsUtils . checksumAddressComparision ( await this . owner ( ) , await this . getCallerAddress ( txData ) ) ,
1848
+ ErrorCode . Unauthorized ,
1836
1849
'Msg sender must be owner' ,
1837
1850
) ;
1838
1851
} ;
1839
1852
1840
1853
private checkMsgSenderIsController = async ( txData : Partial < TxData > | undefined ) => {
1841
1854
assert . assert (
1842
1855
( await this . isControllable ( ) ) && ( await this . controller ( ) ) === ( await this . getCallerAddress ( txData ) ) ,
1856
+ ErrorCode . Unauthorized ,
1843
1857
'Msg sender must be controller' ,
1844
1858
) ;
1845
1859
} ;
@@ -1849,12 +1863,13 @@ export default class SecurityTokenWrapper extends ERC20TokenWrapper {
1849
1863
const isOwner = ( await ( await this . moduleFactoryContract ( address ) ) . owner . callAsync ( ) ) === ( await this . owner ( ) ) ;
1850
1864
assert . assert (
1851
1865
( await this . checkForRegisteredModule ( address ) ) || isOwner ,
1866
+ ErrorCode . Unauthorized ,
1852
1867
'ModuleFactory must be verified or SecurityToken owner must be ModuleFactory owner' ,
1853
1868
) ;
1854
1869
} else {
1855
- assert . assert ( await this . checkForRegisteredModule ( address ) , 'ModuleFactory must be verified' ) ;
1870
+ assert . assert ( await this . checkForRegisteredModule ( address ) , ErrorCode . Unauthorized , 'ModuleFactory must be verified' ) ;
1856
1871
}
1857
- assert . assert ( await this . isCompatibleModule ( address ) , 'Version should within the compatible range of ST' ) ;
1872
+ assert . assert ( await this . isCompatibleModule ( address ) , ErrorCode . InvalidVersion , 'Version should within the compatible range of ST' ) ;
1858
1873
} ;
1859
1874
1860
1875
private checkForRegisteredModule = async ( moduleAddress : string ) => {
@@ -1899,14 +1914,14 @@ export default class SecurityTokenWrapper extends ERC20TokenWrapper {
1899
1914
assert . isBigNumberGreaterThanZero ( data . rate , 'Rate of token should be greater than 0' ) ;
1900
1915
assert . isNonZeroETHAddressHex ( 'Funds Receiver' , data . fundsReceiver ) ;
1901
1916
assert . isFutureDate ( data . startTime , 'Start time date not valid' ) ;
1902
- assert . assert ( data . endTime > data . startTime , 'End time not valid' ) ;
1917
+ assert . assert ( data . endTime > data . startTime , ErrorCode . TooEarly , 'End time not valid' ) ;
1903
1918
assert . isBigNumberGreaterThanZero ( data . cap , 'Cap should be greater than 0' ) ;
1904
1919
} ;
1905
1920
1906
1921
private usdTieredSTOAssertions = async ( data : USDTieredSTOData ) => {
1907
1922
assert . isFutureDate ( data . startTime , 'Start time date not valid' ) ;
1908
- assert . assert ( data . endTime > data . startTime , 'End time not valid' ) ;
1909
- assert . assert ( data . tokensPerTierTotal . length > 0 , 'No tiers provided' ) ;
1923
+ assert . assert ( data . endTime > data . startTime , ErrorCode . TooEarly , 'End time not valid' ) ;
1924
+ assert . assert ( data . tokensPerTierTotal . length > 0 , ErrorCode . InvalidData , 'No tiers provided' ) ;
1910
1925
assert . areValidArrayLengths (
1911
1926
[ data . ratePerTier , data . tokensPerTierTotal , data . ratePerTierDiscountPoly , data . tokensPerTierDiscountPoly ] ,
1912
1927
'Tier data length mismatch' ,
@@ -1916,11 +1931,12 @@ export default class SecurityTokenWrapper extends ERC20TokenWrapper {
1916
1931
assert . isBigNumberGreaterThanZero ( data . tokensPerTierTotal [ i ] , 'Invalid token amount' ) ;
1917
1932
assert . assert (
1918
1933
data . tokensPerTierDiscountPoly [ i ] . isLessThanOrEqualTo ( data . tokensPerTierTotal [ i ] ) ,
1934
+ ErrorCode . InvalidData ,
1919
1935
'Too many discounted tokens' ,
1920
1936
) ;
1921
- assert . assert ( data . ratePerTierDiscountPoly [ i ] . isLessThanOrEqualTo ( data . ratePerTier [ i ] ) , 'Invalid discount' ) ;
1937
+ assert . assert ( data . ratePerTierDiscountPoly [ i ] . isLessThanOrEqualTo ( data . ratePerTier [ i ] ) , ErrorCode . InvalidData , 'Invalid discount' ) ;
1922
1938
}
1923
- assert . assert ( data . fundRaiseTypes . length > 0 && data . fundRaiseTypes . length <= 3 , 'Raise type is not specified' ) ;
1939
+ assert . assert ( data . fundRaiseTypes . length > 0 && data . fundRaiseTypes . length <= 3 , ErrorCode . InvalidData , 'Raise type is not specified' ) ;
1924
1940
assert . isNonZeroETHAddressHex ( 'Wallet' , data . wallet ) ;
1925
1941
assert . isNonZeroETHAddressHex ( 'ReserveWallet' , data . treasuryWallet ) ;
1926
1942
} ;
0 commit comments