aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeonid <logvinov.leon@gmail.com>2017-07-12 09:22:22 +0800
committerGitHub <noreply@github.com>2017-07-12 09:22:22 +0800
commit5fe128ccf6aa71494b71c6a8ecb07c3a6145140f (patch)
tree835a231e28ed0fff4d70e98b46940b5bfe3b4ffa
parent89236fff410563c0d290e0a8090864cf21bae62e (diff)
parent41f0be48f1360ca6241b399593212cdf767c2db0 (diff)
downloaddexon-sol-tools-5fe128ccf6aa71494b71c6a8ecb07c3a6145140f.tar
dexon-sol-tools-5fe128ccf6aa71494b71c6a8ecb07c3a6145140f.tar.gz
dexon-sol-tools-5fe128ccf6aa71494b71c6a8ecb07c3a6145140f.tar.bz2
dexon-sol-tools-5fe128ccf6aa71494b71c6a8ecb07c3a6145140f.tar.lz
dexon-sol-tools-5fe128ccf6aa71494b71c6a8ecb07c3a6145140f.tar.xz
dexon-sol-tools-5fe128ccf6aa71494b71c6a8ecb07c3a6145140f.tar.zst
dexon-sol-tools-5fe128ccf6aa71494b71c6a8ecb07c3a6145140f.zip
Merge pull request #104 from 0xProject/ts-2.4
Update to typescript@2.4
-rw-r--r--package.json2
-rw-r--r--src/0x.ts2
-rw-r--r--src/contract_wrappers/contract_wrapper.ts6
-rw-r--r--src/contract_wrappers/ether_token_wrapper.ts4
-rw-r--r--src/contract_wrappers/exchange_wrapper.ts61
-rw-r--r--src/contract_wrappers/token_wrapper.ts8
-rw-r--r--src/types.ts117
-rw-r--r--src/utils/assert.ts4
-rw-r--r--src/utils/decorators.ts4
-rw-r--r--src/utils/utils.ts24
-rw-r--r--test/ether_token_wrapper_test.ts4
-rw-r--r--test/exchange_wrapper_test.ts34
-rw-r--r--test/token_wrapper_test.ts14
-rw-r--r--test/utils/token_utils.ts2
-rw-r--r--yarn.lock2
15 files changed, 140 insertions, 148 deletions
diff --git a/package.json b/package.json
index d1d7b8c84..5673bd4ed 100644
--- a/package.json
+++ b/package.json
@@ -83,7 +83,7 @@
"tslint": "^5.3.2",
"tslint-config-0xproject": "^0.0.2",
"typedoc": "^0.7.1",
- "typescript": "^2.3.3",
+ "typescript": "^2.4.1",
"web3-provider-engine": "^13.0.1",
"web3-typescript-typings": "^0.0.11",
"webpack": "^3.1.0"
diff --git a/src/0x.ts b/src/0x.ts
index 3d1e8745f..eaaa67d59 100644
--- a/src/0x.ts
+++ b/src/0x.ts
@@ -242,6 +242,6 @@ export class ZeroEx {
}
}
- throw new Error(ZeroExError.INVALID_SIGNATURE);
+ throw new Error(ZeroExError.InvalidSignature);
}
}
diff --git a/src/contract_wrappers/contract_wrapper.ts b/src/contract_wrappers/contract_wrapper.ts
index f9c1bc1cf..1cce1b235 100644
--- a/src/contract_wrappers/contract_wrapper.ts
+++ b/src/contract_wrappers/contract_wrapper.ts
@@ -28,7 +28,7 @@ export class ContractWrapper {
if (!_.isUndefined(contractAddress)) {
const doesContractExist = await this._web3Wrapper.doesContractExistAtAddressAsync(contractAddress);
if (!doesContractExist) {
- throw new Error(ZeroExError.CONTRACT_DOES_NOT_EXIST);
+ throw new Error(ZeroExError.ContractDoesNotExist);
}
}
@@ -38,10 +38,10 @@ export class ContractWrapper {
} catch (err) {
const errMsg = `${err}`;
if (_.includes(errMsg, 'not been deployed to detected network')) {
- throw new Error(ZeroExError.CONTRACT_DOES_NOT_EXIST);
+ throw new Error(ZeroExError.ContractDoesNotExist);
} else {
utils.consoleLog(`Notice: Error encountered: ${err} ${err.stack}`);
- throw new Error(ZeroExError.UNHANDLED_ERROR);
+ throw new Error(ZeroExError.UnhandledError);
}
}
}
diff --git a/src/contract_wrappers/ether_token_wrapper.ts b/src/contract_wrappers/ether_token_wrapper.ts
index 03d714bd7..ee0ac2d8c 100644
--- a/src/contract_wrappers/ether_token_wrapper.ts
+++ b/src/contract_wrappers/ether_token_wrapper.ts
@@ -29,7 +29,7 @@ export class EtherTokenWrapper extends ContractWrapper {
await assert.isSenderAddressAsync('depositor', depositor, this._web3Wrapper);
const ethBalanceInWei = await this._web3Wrapper.getBalanceInWeiAsync(depositor);
- assert.assert(ethBalanceInWei.gte(amountInWei), ZeroExError.INSUFFICIENT_ETH_BALANCE_FOR_DEPOSIT);
+ assert.assert(ethBalanceInWei.gte(amountInWei), ZeroExError.InsufficientEthBalanceForDeposit);
const wethContract = await this._getEtherTokenContractAsync();
await wethContract.deposit({
@@ -49,7 +49,7 @@ export class EtherTokenWrapper extends ContractWrapper {
const wethContractAddress = await this.getContractAddressAsync();
const WETHBalanceInBaseUnits = await this._tokenWrapper.getBalanceAsync(wethContractAddress, withdrawer);
- assert.assert(WETHBalanceInBaseUnits.gte(amountInWei), ZeroExError.INSUFFICIENT_WETH_BALANCE_FOR_WITHDRAWAL);
+ assert.assert(WETHBalanceInBaseUnits.gte(amountInWei), ZeroExError.InsufficientWEthBalanceForWithdrawal);
const wethContract = await this._getEtherTokenContractAsync();
await wethContract.withdraw(amountInWei, {
diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts
index a6eab0fa2..9cc29e286 100644
--- a/src/contract_wrappers/exchange_wrapper.ts
+++ b/src/contract_wrappers/exchange_wrapper.ts
@@ -57,12 +57,12 @@ import * as ExchangeArtifacts from '../artifacts/Exchange.json';
*/
export class ExchangeWrapper extends ContractWrapper {
private _exchangeContractErrCodesToMsg = {
- [ExchangeContractErrCodes.ERROR_FILL_EXPIRED]: ExchangeContractErrs.ORDER_FILL_EXPIRED,
- [ExchangeContractErrCodes.ERROR_CANCEL_EXPIRED]: ExchangeContractErrs.ORDER_FILL_EXPIRED,
- [ExchangeContractErrCodes.ERROR_FILL_NO_VALUE]: ExchangeContractErrs.ORDER_REMAINING_FILL_AMOUNT_ZERO,
- [ExchangeContractErrCodes.ERROR_CANCEL_NO_VALUE]: ExchangeContractErrs.ORDER_REMAINING_FILL_AMOUNT_ZERO,
- [ExchangeContractErrCodes.ERROR_FILL_TRUNCATION]: ExchangeContractErrs.ORDER_FILL_ROUNDING_ERROR,
- [ExchangeContractErrCodes.ERROR_FILL_BALANCE_ALLOWANCE]: ExchangeContractErrs.FILL_BALANCE_ALLOWANCE_ERROR,
+ [ExchangeContractErrCodes.ERROR_FILL_EXPIRED]: ExchangeContractErrs.OrderFillExpired,
+ [ExchangeContractErrCodes.ERROR_CANCEL_EXPIRED]: ExchangeContractErrs.OrderFillExpired,
+ [ExchangeContractErrCodes.ERROR_FILL_NO_VALUE]: ExchangeContractErrs.OrderRemainingFillAmountZero,
+ [ExchangeContractErrCodes.ERROR_CANCEL_NO_VALUE]: ExchangeContractErrs.OrderRemainingFillAmountZero,
+ [ExchangeContractErrCodes.ERROR_FILL_TRUNCATION]: ExchangeContractErrs.OrderFillRoundingError,
+ [ExchangeContractErrCodes.ERROR_FILL_BALANCE_ALLOWANCE]: ExchangeContractErrs.FillBalanceAllowanceError,
};
private _exchangeContractIfExists?: ExchangeContract;
private _exchangeLogEventEmitters: ContractEventEmitter[];
@@ -220,7 +220,10 @@ export class ExchangeWrapper extends ContractWrapper {
assert.doesConformToSchema('signedOrders', signedOrders, signedOrdersSchema);
const takerTokenAddresses = _.map(signedOrders, signedOrder => signedOrder.takerTokenAddress);
assert.hasAtMostOneUniqueValue(takerTokenAddresses,
- ExchangeContractErrs.MULTIPLE_TAKER_TOKENS_IN_FILL_UP_TO_DISALLOWED);
+ ExchangeContractErrs.MultipleTakerTokensInFillUpToDisallowed);
+ const exchangeContractAddresses = _.map(signedOrders, signedOrder => signedOrder.exchangeContractAddress);
+ assert.hasAtMostOneUniqueValue(exchangeContractAddresses,
+ ExchangeContractErrs.BatchOrdersMustHaveSameExchangeAddress);
assert.isBigNumber('fillTakerTokenAmount', fillTakerTokenAmount);
assert.isBoolean('shouldThrowOnInsufficientBalanceOrAllowance', shouldThrowOnInsufficientBalanceOrAllowance);
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);
@@ -300,6 +303,12 @@ export class ExchangeWrapper extends ContractWrapper {
shouldThrowOnInsufficientBalanceOrAllowance: boolean,
takerAddress: string): Promise<void> {
assert.doesConformToSchema('orderFillRequests', orderFillRequests, orderFillRequestsSchema);
+ const exchangeContractAddresses = _.map(
+ orderFillRequests,
+ orderFillRequest => orderFillRequest.signedOrder.exchangeContractAddress,
+ );
+ assert.hasAtMostOneUniqueValue(exchangeContractAddresses,
+ ExchangeContractErrs.BatchOrdersMustHaveSameExchangeAddress);
assert.isBoolean('shouldThrowOnInsufficientBalanceOrAllowance', shouldThrowOnInsufficientBalanceOrAllowance);
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);
for (const orderFillRequest of orderFillRequests) {
@@ -416,7 +425,7 @@ export class ExchangeWrapper extends ContractWrapper {
orderFillOrKillRequest => orderFillOrKillRequest.signedOrder.exchangeContractAddress,
);
assert.hasAtMostOneUniqueValue(exchangeContractAddresses,
- ExchangeContractErrs.BATCH_ORDERS_MUST_HAVE_SAME_EXCHANGE_ADDRESS);
+ ExchangeContractErrs.BatchOrdersMustHaveSameExchangeAddress);
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);
if (_.isEmpty(orderFillOrKillRequests)) {
return; // no-op
@@ -520,9 +529,9 @@ export class ExchangeWrapper extends ContractWrapper {
orderCancellationRequest => orderCancellationRequest.order.exchangeContractAddress,
);
assert.hasAtMostOneUniqueValue(exchangeContractAddresses,
- ExchangeContractErrs.BATCH_ORDERS_MUST_HAVE_SAME_EXCHANGE_ADDRESS);
+ ExchangeContractErrs.BatchOrdersMustHaveSameExchangeAddress);
const makers = _.map(orderCancellationRequests, cancellationRequest => cancellationRequest.order.maker);
- assert.hasAtMostOneUniqueValue(makers, ExchangeContractErrs.MULTIPLE_MAKERS_IN_SINGLE_CANCEL_BATCH_DISALLOWED);
+ assert.hasAtMostOneUniqueValue(makers, ExchangeContractErrs.MultipleMakersInSingleCancelBatchDisallowed);
const maker = makers[0];
await assert.isSenderAddressAsync('maker', maker, this._web3Wrapper);
for (const cancellationRequest of orderCancellationRequests) {
@@ -648,14 +657,14 @@ export class ExchangeWrapper extends ContractWrapper {
fillTakerAmount: BigNumber.BigNumber,
senderAddress: string): Promise<void> {
if (fillTakerAmount.eq(0)) {
- throw new Error(ExchangeContractErrs.ORDER_REMAINING_FILL_AMOUNT_ZERO);
+ throw new Error(ExchangeContractErrs.OrderRemainingFillAmountZero);
}
if (signedOrder.taker !== constants.NULL_ADDRESS && signedOrder.taker !== senderAddress) {
- throw new Error(ExchangeContractErrs.TRANSACTION_SENDER_IS_NOT_FILL_ORDER_TAKER);
+ throw new Error(ExchangeContractErrs.TransactionSenderIsNotFillOrderTaker);
}
const currentUnixTimestampSec = utils.getCurrentUnixTimestamp();
if (signedOrder.expirationUnixTimestampSec.lessThan(currentUnixTimestampSec)) {
- throw new Error(ExchangeContractErrs.ORDER_FILL_EXPIRED);
+ throw new Error(ExchangeContractErrs.OrderFillExpired);
}
const zrxTokenAddress = await this._getZRXTokenAddressAsync(signedOrder.exchangeContractAddress);
await this._validateFillOrderBalancesAndAllowancesAndThrowIfInvalidAsync(signedOrder, fillTakerAmount,
@@ -665,22 +674,22 @@ export class ExchangeWrapper extends ContractWrapper {
signedOrder.takerTokenAmount, fillTakerAmount, signedOrder.makerTokenAmount,
);
if (wouldRoundingErrorOccur) {
- throw new Error(ExchangeContractErrs.ORDER_FILL_ROUNDING_ERROR);
+ throw new Error(ExchangeContractErrs.OrderFillRoundingError);
}
}
private async _validateCancelOrderAndThrowIfInvalidAsync(
order: Order, takerTokenCancelAmount: BigNumber.BigNumber): Promise<void> {
if (takerTokenCancelAmount.eq(0)) {
- throw new Error(ExchangeContractErrs.ORDER_CANCEL_AMOUNT_ZERO);
+ throw new Error(ExchangeContractErrs.OrderCancelAmountZero);
}
const orderHash = utils.getOrderHashHex(order);
const unavailableAmount = await this.getUnavailableTakerAmountAsync(orderHash);
if (order.takerTokenAmount.minus(unavailableAmount).eq(0)) {
- throw new Error(ExchangeContractErrs.ORDER_ALREADY_CANCELLED_OR_FILLED);
+ throw new Error(ExchangeContractErrs.OrderAlreadyCancelledOrFilled);
}
const currentUnixTimestampSec = utils.getCurrentUnixTimestamp();
if (order.expirationUnixTimestampSec.lessThan(currentUnixTimestampSec)) {
- throw new Error(ExchangeContractErrs.ORDER_CANCEL_EXPIRED);
+ throw new Error(ExchangeContractErrs.OrderCancelExpired);
}
}
private async _validateFillOrKillOrderAndThrowIfInvalidAsync(signedOrder: SignedOrder,
@@ -690,7 +699,7 @@ export class ExchangeWrapper extends ContractWrapper {
const unavailableTakerAmount = await this.getUnavailableTakerAmountAsync(orderHashHex);
const remainingTakerAmount = signedOrder.takerTokenAmount.minus(unavailableTakerAmount);
if (remainingTakerAmount < fillTakerAmount) {
- throw new Error(ExchangeContractErrs.INSUFFICIENT_REMAINING_FILL_AMOUNT);
+ throw new Error(ExchangeContractErrs.InsufficientRemainingFillAmount);
}
}
/**
@@ -721,16 +730,16 @@ export class ExchangeWrapper extends ContractWrapper {
const fillMakerAmountInBaseUnits = fillTakerAmount.div(exchangeRate);
if (fillTakerAmount.greaterThan(takerBalance)) {
- throw new Error(ExchangeContractErrs.INSUFFICIENT_TAKER_BALANCE);
+ throw new Error(ExchangeContractErrs.InsufficientTakerBalance);
}
if (fillTakerAmount.greaterThan(takerAllowance)) {
- throw new Error(ExchangeContractErrs.INSUFFICIENT_TAKER_ALLOWANCE);
+ throw new Error(ExchangeContractErrs.InsufficientTakerAllowance);
}
if (fillMakerAmountInBaseUnits.greaterThan(makerBalance)) {
- throw new Error(ExchangeContractErrs.INSUFFICIENT_MAKER_BALANCE);
+ throw new Error(ExchangeContractErrs.InsufficientMakerBalance);
}
if (fillMakerAmountInBaseUnits.greaterThan(makerAllowance)) {
- throw new Error(ExchangeContractErrs.INSUFFICIENT_MAKER_ALLOWANCE);
+ throw new Error(ExchangeContractErrs.InsufficientMakerAllowance);
}
const makerFeeBalance = await this._tokenWrapper.getBalanceAsync(zrxTokenAddress,
@@ -742,16 +751,16 @@ export class ExchangeWrapper extends ContractWrapper {
senderAddress);
if (signedOrder.takerFee.greaterThan(takerFeeBalance)) {
- throw new Error(ExchangeContractErrs.INSUFFICIENT_TAKER_FEE_BALANCE);
+ throw new Error(ExchangeContractErrs.InsufficientTakerFeeBalance);
}
if (signedOrder.takerFee.greaterThan(takerFeeAllowance)) {
- throw new Error(ExchangeContractErrs.INSUFFICIENT_TAKER_FEE_ALLOWANCE);
+ throw new Error(ExchangeContractErrs.InsufficientTakerFeeAllowance);
}
if (signedOrder.makerFee.greaterThan(makerFeeBalance)) {
- throw new Error(ExchangeContractErrs.INSUFFICIENT_MAKER_FEE_BALANCE);
+ throw new Error(ExchangeContractErrs.InsufficientMakerFeeBalance);
}
if (signedOrder.makerFee.greaterThan(makerFeeAllowance)) {
- throw new Error(ExchangeContractErrs.INSUFFICIENT_MAKER_FEE_ALLOWANCE);
+ throw new Error(ExchangeContractErrs.InsufficientMakerFeeAllowance);
}
}
private _throwErrorLogsAsErrors(logs: ContractEvent[]): void {
diff --git a/src/contract_wrappers/token_wrapper.ts b/src/contract_wrappers/token_wrapper.ts
index fdf711823..9c073f30b 100644
--- a/src/contract_wrappers/token_wrapper.ts
+++ b/src/contract_wrappers/token_wrapper.ts
@@ -146,7 +146,7 @@ export class TokenWrapper extends ContractWrapper {
const fromAddressBalance = await this.getBalanceAsync(tokenAddress, fromAddress);
if (fromAddressBalance.lessThan(amountInBaseUnits)) {
- throw new Error(ZeroExError.INSUFFICIENT_BALANCE_FOR_TRANSFER);
+ throw new Error(ZeroExError.InsufficientBalanceForTransfer);
}
await tokenContract.transfer(toAddress, amountInBaseUnits, {
@@ -178,12 +178,12 @@ export class TokenWrapper extends ContractWrapper {
const fromAddressAllowance = await this.getAllowanceAsync(tokenAddress, fromAddress, senderAddress);
if (fromAddressAllowance.lessThan(amountInBaseUnits)) {
- throw new Error(ZeroExError.INSUFFICIENT_ALLOWANCE_FOR_TRANSFER);
+ throw new Error(ZeroExError.InsufficientAllowanceForTransfer);
}
const fromAddressBalance = await this.getBalanceAsync(tokenAddress, fromAddress);
if (fromAddressBalance.lessThan(amountInBaseUnits)) {
- throw new Error(ZeroExError.INSUFFICIENT_BALANCE_FOR_TRANSFER);
+ throw new Error(ZeroExError.InsufficientBalanceForTransfer);
}
await tokenContract.transferFrom(fromAddress, toAddress, amountInBaseUnits, {
@@ -252,7 +252,7 @@ export class TokenWrapper extends ContractWrapper {
undefined :
(ProxyArtifacts as any).networks[networkIdIfExists];
if (_.isUndefined(proxyNetworkConfigsIfExists)) {
- throw new Error(ZeroExError.CONTRACT_NOT_DEPLOYED_ON_NETWORK);
+ throw new Error(ZeroExError.ContractNotDeployedOnNetwork);
}
const proxyAddress = proxyNetworkConfigsIfExists.address;
return proxyAddress;
diff --git a/src/types.ts b/src/types.ts
index 851627a09..974057fed 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -1,34 +1,21 @@
import * as _ from 'lodash';
import * as Web3 from 'web3';
-// Utility function to create a K:V from a list of strings
-// Adapted from: https://basarat.gitbooks.io/typescript/content/docs/types/literal-types.html
-export interface StringEnum {
- [key: string]: string;
-}
-function strEnum(values: string[]): StringEnum {
- return _.reduce(values, (result, key) => {
- result[key] = key;
- return result;
- }, Object.create(null));
-}
-
-export const ZeroExError = strEnum([
- 'CONTRACT_DOES_NOT_EXIST',
- 'EXCHANGE_CONTRACT_DOES_NOT_EXIST',
- 'UNHANDLED_ERROR',
- 'USER_HAS_NO_ASSOCIATED_ADDRESSES',
- 'INVALID_SIGNATURE',
- 'CONTRACT_NOT_DEPLOYED_ON_NETWORK',
- 'ZRX_NOT_IN_TOKEN_REGISTRY',
- 'INSUFFICIENT_ALLOWANCE_FOR_TRANSFER',
- 'INSUFFICIENT_BALANCE_FOR_TRANSFER',
- 'INSUFFICIENT_ETH_BALANCE_FOR_DEPOSIT',
- 'INSUFFICIENT_WETH_BALANCE_FOR_WITHDRAWAL',
- 'INVALID_JUMP',
- 'OUT_OF_GAS',
-]);
-export type ZeroExError = keyof typeof ZeroExError;
+export enum ZeroExError {
+ ContractDoesNotExist = 'CONTRACT_DOES_NOT_EXIST',
+ ExchangeContractDoesNotExist = 'EXCHANGE_CONTRACT_DOES_NOT_EXIST',
+ UnhandledError = 'UNHANDLED_ERROR',
+ UserHasNoAssociatedAddress = 'USER_HAS_NO_ASSOCIATED_ADDRESSES',
+ InvalidSignature = 'INVALID_SIGNATURE',
+ ContractNotDeployedOnNetwork = 'CONTRACT_NOT_DEPLOYED_ON_NETWORK',
+ ZrxNotInTokenRegistry = 'ZRX_NOT_IN_TOKEN_REGISTRY',
+ InsufficientAllowanceForTransfer = 'INSUFFICIENT_ALLOWANCE_FOR_TRANSFER',
+ InsufficientBalanceForTransfer = 'INSUFFICIENT_BALANCE_FOR_TRANSFER',
+ InsufficientEthBalanceForDeposit = 'INSUFFICIENT_ETH_BALANCE_FOR_DEPOSIT',
+ InsufficientWEthBalanceForWithdrawal = 'INSUFFICIENT_WETH_BALANCE_FOR_WITHDRAWAL',
+ InvalidJump = 'INVALID_JUMP',
+ OutOfGas = 'OUT_OF_GAS',
+}
/**
* Elliptic Curve signature
@@ -175,11 +162,10 @@ export interface ProxyContract extends ContractInstance {
};
}
-export const SolidityTypes = strEnum([
- 'address',
- 'uint256',
-]);
-export type SolidityTypes = keyof typeof SolidityTypes;
+export enum SolidityTypes {
+ Address = 'address',
+ Uint256 = 'uint256',
+}
export enum ExchangeContractErrCodes {
ERROR_FILL_EXPIRED, // Order has already expired
@@ -190,29 +176,28 @@ export enum ExchangeContractErrCodes {
ERROR_CANCEL_NO_VALUE, // Order has already been fully filled or cancelled
}
-export const ExchangeContractErrs = strEnum([
- 'ORDER_FILL_EXPIRED',
- 'ORDER_CANCEL_EXPIRED',
- 'ORDER_CANCEL_AMOUNT_ZERO',
- 'ORDER_ALREADY_CANCELLED_OR_FILLED',
- 'ORDER_REMAINING_FILL_AMOUNT_ZERO',
- 'ORDER_FILL_ROUNDING_ERROR',
- 'FILL_BALANCE_ALLOWANCE_ERROR',
- 'INSUFFICIENT_TAKER_BALANCE',
- 'INSUFFICIENT_TAKER_ALLOWANCE',
- 'INSUFFICIENT_MAKER_BALANCE',
- 'INSUFFICIENT_MAKER_ALLOWANCE',
- 'INSUFFICIENT_TAKER_FEE_BALANCE',
- 'INSUFFICIENT_TAKER_FEE_ALLOWANCE',
- 'INSUFFICIENT_MAKER_FEE_BALANCE',
- 'INSUFFICIENT_MAKER_FEE_ALLOWANCE',
- 'TRANSACTION_SENDER_IS_NOT_FILL_ORDER_TAKER',
- 'MULTIPLE_MAKERS_IN_SINGLE_CANCEL_BATCH_DISALLOWED',
- 'INSUFFICIENT_REMAINING_FILL_AMOUNT',
- 'MULTIPLE_TAKER_TOKENS_IN_FILL_UP_TO_DISALLOWED',
- 'BATCH_ORDERS_MUST_HAVE_SAME_EXCHANGE_ADDRESS',
-]);
-export type ExchangeContractErrs = keyof typeof ExchangeContractErrs;
+export enum ExchangeContractErrs {
+ OrderFillExpired = 'ORDER_FILL_EXPIRED',
+ OrderCancelExpired = 'ORDER_CANCEL_EXPIRED',
+ OrderCancelAmountZero = 'ORDER_CANCEL_AMOUNT_ZERO',
+ OrderAlreadyCancelledOrFilled = 'ORDER_ALREADY_CANCELLED_OR_FILLED',
+ OrderRemainingFillAmountZero = 'ORDER_REMAINING_FILL_AMOUNT_ZERO',
+ OrderFillRoundingError = 'ORDER_FILL_ROUNDING_ERROR',
+ FillBalanceAllowanceError = 'FILL_BALANCE_ALLOWANCE_ERROR',
+ InsufficientTakerBalance = 'INSUFFICIENT_TAKER_BALANCE',
+ InsufficientTakerAllowance = 'INSUFFICIENT_TAKER_ALLOWANCE',
+ InsufficientMakerBalance = 'INSUFFICIENT_MAKER_BALANCE',
+ InsufficientMakerAllowance = 'INSUFFICIENT_MAKER_ALLOWANCE',
+ InsufficientTakerFeeBalance = 'INSUFFICIENT_TAKER_FEE_BALANCE',
+ InsufficientTakerFeeAllowance = 'INSUFFICIENT_TAKER_FEE_ALLOWANCE',
+ InsufficientMakerFeeBalance = 'INSUFFICIENT_MAKER_FEE_BALANCE',
+ InsufficientMakerFeeAllowance = 'INSUFFICIENT_MAKER_FEE_ALLOWANCE',
+ TransactionSenderIsNotFillOrderTaker = 'TRANSACTION_SENDER_IS_NOT_FILL_ORDER_TAKER',
+ MultipleMakersInSingleCancelBatchDisallowed = 'MULTIPLE_MAKERS_IN_SINGLE_CANCEL_BATCH_DISALLOWED',
+ InsufficientRemainingFillAmount = 'INSUFFICIENT_REMAINING_FILL_AMOUNT',
+ MultipleTakerTokensInFillUpToDisallowed = 'MULTIPLE_TAKER_TOKENS_IN_FILL_UP_TO_DISALLOWED',
+ BatchOrdersMustHaveSameExchangeAddress = 'BATCH_ORDERS_MUST_HAVE_SAME_EXCHANGE_ADDRESS',
+}
export interface ContractResponse {
logs: ContractEvent[];
@@ -312,18 +297,16 @@ export interface TokenAddressBySymbol {
[symbol: string]: string;
}
-export const ExchangeEvents = strEnum([
- 'LogFill',
- 'LogCancel',
- 'LogError',
-]);
-export type ExchangeEvents = keyof typeof ExchangeEvents;
+export enum ExchangeEvents {
+ LogFill = 'LogFill',
+ LogCancel = 'LogCancel',
+ LogError = 'LogError',
+}
-export const TokenEvents = strEnum([
- 'Transfer',
- 'Approval',
-]);
-export type TokenEvents = keyof typeof TokenEvents;
+export enum TokenEvents {
+ Transfer = 'Transfer',
+ Approval = 'Approval',
+}
export interface IndexedFilterValues {
[index: string]: ContractEventArg;
diff --git a/src/utils/assert.ts b/src/utils/assert.ts
index bdd38721e..dab796c4e 100644
--- a/src/utils/assert.ts
+++ b/src/utils/assert.ts
@@ -4,7 +4,6 @@ import * as Web3 from 'web3';
import {Web3Wrapper} from '../web3_wrapper';
import {SchemaValidator} from './schema_validator';
import {utils} from './utils';
-import {StringEnum} from '../types';
const HEX_REGEX = /^0x[0-9A-F]*$/i;
@@ -27,7 +26,8 @@ export const assert = {
const web3 = new Web3();
this.assert(web3.isAddress(value), this.typeAssertionMessage(variableName, 'ETHAddressHex', value));
},
- doesBelongToStringEnum(variableName: string, value: string, stringEnum: StringEnum): void {
+ doesBelongToStringEnum(variableName: string, value: string,
+ stringEnum: any /* There is no base type for every string enum */): void {
const doesBelongToStringEnum = !_.isUndefined(stringEnum[value]);
const enumValues = _.keys(stringEnum);
const enumValuesAsStrings = _.map(enumValues, enumValue => `'${enumValue}'`);
diff --git a/src/utils/decorators.ts b/src/utils/decorators.ts
index a25f2cff5..ec750b891 100644
--- a/src/utils/decorators.ts
+++ b/src/utils/decorators.ts
@@ -21,10 +21,10 @@ export const decorators = {
return result;
} catch (error) {
if (_.includes(error.message, constants.INVALID_JUMP_PATTERN)) {
- throw new Error(ZeroExError.INVALID_JUMP);
+ throw new Error(ZeroExError.InvalidJump);
}
if (_.includes(error.message, constants.OUT_OF_GAS_PATTERN)) {
- throw new Error(ZeroExError.OUT_OF_GAS);
+ throw new Error(ZeroExError.OutOfGas);
}
throw error;
}
diff --git a/src/utils/utils.ts b/src/utils/utils.ts
index ecc171bfe..6702de218 100644
--- a/src/utils/utils.ts
+++ b/src/utils/utils.ts
@@ -30,18 +30,18 @@ export const utils = {
},
getOrderHashHex(order: Order|SignedOrder): string {
const orderParts = [
- {value: order.exchangeContractAddress, type: SolidityTypes.address},
- {value: order.maker, type: SolidityTypes.address},
- {value: order.taker, type: SolidityTypes.address},
- {value: order.makerTokenAddress, type: SolidityTypes.address},
- {value: order.takerTokenAddress, type: SolidityTypes.address},
- {value: order.feeRecipient, type: SolidityTypes.address},
- {value: utils.bigNumberToBN(order.makerTokenAmount), type: SolidityTypes.uint256},
- {value: utils.bigNumberToBN(order.takerTokenAmount), type: SolidityTypes.uint256},
- {value: utils.bigNumberToBN(order.makerFee), type: SolidityTypes.uint256},
- {value: utils.bigNumberToBN(order.takerFee), type: SolidityTypes.uint256},
- {value: utils.bigNumberToBN(order.expirationUnixTimestampSec), type: SolidityTypes.uint256},
- {value: utils.bigNumberToBN(order.salt), type: SolidityTypes.uint256},
+ {value: order.exchangeContractAddress, type: SolidityTypes.Address},
+ {value: order.maker, type: SolidityTypes.Address},
+ {value: order.taker, type: SolidityTypes.Address},
+ {value: order.makerTokenAddress, type: SolidityTypes.Address},
+ {value: order.takerTokenAddress, type: SolidityTypes.Address},
+ {value: order.feeRecipient, type: SolidityTypes.Address},
+ {value: utils.bigNumberToBN(order.makerTokenAmount), type: SolidityTypes.Uint256},
+ {value: utils.bigNumberToBN(order.takerTokenAmount), type: SolidityTypes.Uint256},
+ {value: utils.bigNumberToBN(order.makerFee), type: SolidityTypes.Uint256},
+ {value: utils.bigNumberToBN(order.takerFee), type: SolidityTypes.Uint256},
+ {value: utils.bigNumberToBN(order.expirationUnixTimestampSec), type: SolidityTypes.Uint256},
+ {value: utils.bigNumberToBN(order.salt), type: SolidityTypes.Uint256},
];
const types = _.map(orderParts, o => o.type);
const values = _.map(orderParts, o => o.value);
diff --git a/test/ether_token_wrapper_test.ts b/test/ether_token_wrapper_test.ts
index ebce81e97..5ed800fc7 100644
--- a/test/ether_token_wrapper_test.ts
+++ b/test/ether_token_wrapper_test.ts
@@ -66,7 +66,7 @@ describe('EtherTokenWrapper', () => {
return expect(
zeroEx.etherToken.depositAsync(overETHBalanceinWei, addressWithETH),
- ).to.be.rejectedWith(ZeroExError.INSUFFICIENT_ETH_BALANCE_FOR_DEPOSIT);
+ ).to.be.rejectedWith(ZeroExError.InsufficientEthBalanceForDeposit);
});
});
describe('#withdrawAsync', () => {
@@ -100,7 +100,7 @@ describe('EtherTokenWrapper', () => {
return expect(
zeroEx.etherToken.withdrawAsync(overWETHBalance, addressWithETH),
- ).to.be.rejectedWith(ZeroExError.INSUFFICIENT_WETH_BALANCE_FOR_WITHDRAWAL);
+ ).to.be.rejectedWith(ZeroExError.InsufficientWEthBalanceForWithdrawal);
});
});
});
diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts
index eb07b09ba..0dc67bb01 100644
--- a/test/exchange_wrapper_test.ts
+++ b/test/exchange_wrapper_test.ts
@@ -111,7 +111,7 @@ describe('ExchangeWrapper', () => {
return expect(zeroEx.exchange.fillOrKillOrderAsync(
signedOrder, tooLargeFillAmount, takerAddress,
- )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_REMAINING_FILL_AMOUNT);
+ )).to.be.rejectedWith(ExchangeContractErrs.InsufficientRemainingFillAmount);
});
});
describe('successful fills', () => {
@@ -183,7 +183,7 @@ describe('ExchangeWrapper', () => {
const zeroFillAmount = new BigNumber(0);
return expect(zeroEx.exchange.fillOrderAsync(
signedOrder, zeroFillAmount, shouldCheckTransfer, takerAddress,
- )).to.be.rejectedWith(ExchangeContractErrs.ORDER_REMAINING_FILL_AMOUNT_ZERO);
+ )).to.be.rejectedWith(ExchangeContractErrs.OrderRemainingFillAmountZero);
});
it('should throw when sender is not a taker', async () => {
const signedOrder = await fillScenarios.createFillableSignedOrderAsync(
@@ -192,7 +192,7 @@ describe('ExchangeWrapper', () => {
const nonTakerAddress = userAddresses[6];
return expect(zeroEx.exchange.fillOrderAsync(
signedOrder, fillTakerAmount, shouldCheckTransfer, nonTakerAddress,
- )).to.be.rejectedWith(ExchangeContractErrs.TRANSACTION_SENDER_IS_NOT_FILL_ORDER_TAKER);
+ )).to.be.rejectedWith(ExchangeContractErrs.TransactionSenderIsNotFillOrderTaker);
});
it('should throw when order is expired', async () => {
const expirationInPast = new BigNumber(1496826058); // 7th Jun 2017
@@ -202,7 +202,7 @@ describe('ExchangeWrapper', () => {
);
return expect(zeroEx.exchange.fillOrderAsync(
signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress,
- )).to.be.rejectedWith(ExchangeContractErrs.ORDER_FILL_EXPIRED);
+ )).to.be.rejectedWith(ExchangeContractErrs.OrderFillExpired);
});
describe('should throw when not enough balance or allowance to fulfill the order', () => {
const balanceToSubtractFromMaker = new BigNumber(3);
@@ -219,7 +219,7 @@ describe('ExchangeWrapper', () => {
);
return expect(zeroEx.exchange.fillOrderAsync(
signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress,
- )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_TAKER_BALANCE);
+ )).to.be.rejectedWith(ExchangeContractErrs.InsufficientTakerBalance);
});
it('should throw when taker allowance is less than fill amount', async () => {
const newAllowanceWhichIsLessThanFillAmount = fillTakerAmount.minus(lackingAllowance);
@@ -227,7 +227,7 @@ describe('ExchangeWrapper', () => {
newAllowanceWhichIsLessThanFillAmount);
return expect(zeroEx.exchange.fillOrderAsync(
signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress,
- )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_TAKER_ALLOWANCE);
+ )).to.be.rejectedWith(ExchangeContractErrs.InsufficientTakerAllowance);
});
it('should throw when maker balance is less than maker fill amount', async () => {
await zeroEx.token.transferAsync(
@@ -235,7 +235,7 @@ describe('ExchangeWrapper', () => {
);
return expect(zeroEx.exchange.fillOrderAsync(
signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress,
- )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_MAKER_BALANCE);
+ )).to.be.rejectedWith(ExchangeContractErrs.InsufficientMakerBalance);
});
it('should throw when maker allowance is less than maker fill amount', async () => {
const newAllowanceWhichIsLessThanFillAmount = fillTakerAmount.minus(lackingAllowance);
@@ -243,7 +243,7 @@ describe('ExchangeWrapper', () => {
newAllowanceWhichIsLessThanFillAmount);
return expect(zeroEx.exchange.fillOrderAsync(
signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress,
- )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_MAKER_ALLOWANCE);
+ )).to.be.rejectedWith(ExchangeContractErrs.InsufficientMakerAllowance);
});
});
it('should throw when there a rounding error would have occurred', async () => {
@@ -256,7 +256,7 @@ describe('ExchangeWrapper', () => {
const fillTakerAmountThatCausesRoundingError = new BigNumber(3);
return expect(zeroEx.exchange.fillOrderAsync(
signedOrder, fillTakerAmountThatCausesRoundingError, shouldCheckTransfer, takerAddress,
- )).to.be.rejectedWith(ExchangeContractErrs.ORDER_FILL_ROUNDING_ERROR);
+ )).to.be.rejectedWith(ExchangeContractErrs.OrderFillRoundingError);
});
describe('should throw when not enough balance or allowance to pay fees', () => {
const makerFee = new BigNumber(2);
@@ -275,7 +275,7 @@ describe('ExchangeWrapper', () => {
);
return expect(zeroEx.exchange.fillOrderAsync(
signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress,
- )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_MAKER_FEE_BALANCE);
+ )).to.be.rejectedWith(ExchangeContractErrs.InsufficientMakerFeeBalance);
});
it('should throw when maker doesn\'t have enough allowance to pay fees', async () => {
const newAllowanceWhichIsLessThanFees = makerFee.minus(1);
@@ -283,7 +283,7 @@ describe('ExchangeWrapper', () => {
newAllowanceWhichIsLessThanFees);
return expect(zeroEx.exchange.fillOrderAsync(
signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress,
- )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_MAKER_FEE_ALLOWANCE);
+ )).to.be.rejectedWith(ExchangeContractErrs.InsufficientMakerFeeAllowance);
});
it('should throw when taker doesn\'t have enough balance to pay fees', async () => {
const balanceToSubtractFromTaker = new BigNumber(1);
@@ -292,7 +292,7 @@ describe('ExchangeWrapper', () => {
);
return expect(zeroEx.exchange.fillOrderAsync(
signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress,
- )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_TAKER_FEE_BALANCE);
+ )).to.be.rejectedWith(ExchangeContractErrs.InsufficientTakerFeeBalance);
});
it('should throw when taker doesn\'t have enough allowance to pay fees', async () => {
const newAllowanceWhichIsLessThanFees = makerFee.minus(1);
@@ -300,7 +300,7 @@ describe('ExchangeWrapper', () => {
newAllowanceWhichIsLessThanFees);
return expect(zeroEx.exchange.fillOrderAsync(
signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress,
- )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_TAKER_FEE_ALLOWANCE);
+ )).to.be.rejectedWith(ExchangeContractErrs.InsufficientTakerFeeAllowance);
});
});
});
@@ -491,7 +491,7 @@ describe('ExchangeWrapper', () => {
it('should throw when cancel amount is zero', async () => {
const zeroCancelAmount = new BigNumber(0);
return expect(zeroEx.exchange.cancelOrderAsync(signedOrder, zeroCancelAmount))
- .to.be.rejectedWith(ExchangeContractErrs.ORDER_CANCEL_AMOUNT_ZERO);
+ .to.be.rejectedWith(ExchangeContractErrs.OrderCancelAmountZero);
});
it('should throw when order is expired', async () => {
const expirationInPast = new BigNumber(1496826058); // 7th Jun 2017
@@ -501,12 +501,12 @@ describe('ExchangeWrapper', () => {
);
orderHashHex = ZeroEx.getOrderHashHex(expiredSignedOrder);
return expect(zeroEx.exchange.cancelOrderAsync(expiredSignedOrder, cancelAmount))
- .to.be.rejectedWith(ExchangeContractErrs.ORDER_CANCEL_EXPIRED);
+ .to.be.rejectedWith(ExchangeContractErrs.OrderCancelExpired);
});
it('should throw when order is already cancelled or filled', async () => {
await zeroEx.exchange.cancelOrderAsync(signedOrder, fillableAmount);
return expect(zeroEx.exchange.cancelOrderAsync(signedOrder, fillableAmount))
- .to.be.rejectedWith(ExchangeContractErrs.ORDER_ALREADY_CANCELLED_OR_FILLED);
+ .to.be.rejectedWith(ExchangeContractErrs.OrderAlreadyCancelledOrFilled);
});
});
describe('successful cancels', () => {
@@ -552,7 +552,7 @@ describe('ExchangeWrapper', () => {
order: signedOrderWithDifferentMaker,
takerTokenCancelAmount: cancelAmount,
},
- ])).to.be.rejectedWith(ExchangeContractErrs.MULTIPLE_MAKERS_IN_SINGLE_CANCEL_BATCH);
+ ])).to.be.rejectedWith(ExchangeContractErrs.MultipleMakersInSingleCancelBatchDisallowed);
});
});
describe('successful batch cancels', () => {
diff --git a/test/token_wrapper_test.ts b/test/token_wrapper_test.ts
index 06e373bfa..52a2507bf 100644
--- a/test/token_wrapper_test.ts
+++ b/test/token_wrapper_test.ts
@@ -64,7 +64,7 @@ describe('TokenWrapper', () => {
const toAddress = coinbase;
return expect(zeroEx.token.transferAsync(
token.address, fromAddress, toAddress, transferAmount,
- )).to.be.rejectedWith(ZeroExError.INSUFFICIENT_BALANCE_FOR_TRANSFER);
+ )).to.be.rejectedWith(ZeroExError.InsufficientBalanceForTransfer);
});
it('should throw a CONTRACT_DOES_NOT_EXIST error for a non-existent token contract', async () => {
const nonExistentTokenAddress = '0x9dd402f14d67e001d8efbe6583e51bf9706aa065';
@@ -72,7 +72,7 @@ describe('TokenWrapper', () => {
const toAddress = coinbase;
return expect(zeroEx.token.transferAsync(
nonExistentTokenAddress, fromAddress, toAddress, transferAmount,
- )).to.be.rejectedWith(ZeroExError.CONTRACT_DOES_NOT_EXIST);
+ )).to.be.rejectedWith(ZeroExError.ContractDoesNotExist);
});
});
describe('#transferFromAsync', () => {
@@ -97,7 +97,7 @@ describe('TokenWrapper', () => {
return expect(zeroEx.token.transferFromAsync(
token.address, fromAddress, toAddress, senderAddress, transferAmount,
- )).to.be.rejectedWith(ZeroExError.INSUFFICIENT_ALLOWANCE_FOR_TRANSFER);
+ )).to.be.rejectedWith(ZeroExError.InsufficientAllowanceForTransfer);
});
it('[regression] should fail to transfer tokens if set allowance for toAddress instead of senderAddress',
async () => {
@@ -108,7 +108,7 @@ describe('TokenWrapper', () => {
return expect(zeroEx.token.transferFromAsync(
token.address, fromAddress, toAddress, senderAddress, transferAmount,
- )).to.be.rejectedWith(ZeroExError.INSUFFICIENT_ALLOWANCE_FOR_TRANSFER);
+ )).to.be.rejectedWith(ZeroExError.InsufficientAllowanceForTransfer);
});
it('should fail to transfer tokens if fromAddress has insufficient balance', async () => {
const fromAddress = addressWithoutFunds;
@@ -124,7 +124,7 @@ describe('TokenWrapper', () => {
return expect(zeroEx.token.transferFromAsync(
token.address, fromAddress, toAddress, senderAddress, transferAmount,
- )).to.be.rejectedWith(ZeroExError.INSUFFICIENT_BALANCE_FOR_TRANSFER);
+ )).to.be.rejectedWith(ZeroExError.InsufficientBalanceForTransfer);
});
it('should successfully transfer tokens', async () => {
const fromAddress = coinbase;
@@ -145,7 +145,7 @@ describe('TokenWrapper', () => {
const nonExistentTokenAddress = '0x9dd402f14d67e001d8efbe6583e51bf9706aa065';
return expect(zeroEx.token.transferFromAsync(
nonExistentTokenAddress, fromAddress, toAddress, senderAddress, new BigNumber(42),
- )).to.be.rejectedWith(ZeroExError.CONTRACT_DOES_NOT_EXIST);
+ )).to.be.rejectedWith(ZeroExError.ContractDoesNotExist);
});
});
describe('#getBalanceAsync', () => {
@@ -160,7 +160,7 @@ describe('TokenWrapper', () => {
const nonExistentTokenAddress = '0x9dd402f14d67e001d8efbe6583e51bf9706aa065';
const ownerAddress = coinbase;
return expect(zeroEx.token.getBalanceAsync(nonExistentTokenAddress, ownerAddress))
- .to.be.rejectedWith(ZeroExError.CONTRACT_DOES_NOT_EXIST);
+ .to.be.rejectedWith(ZeroExError.ContractDoesNotExist);
});
it('should return a balance of 0 for a non-existent owner address', async () => {
const token = tokens[0];
diff --git a/test/utils/token_utils.ts b/test/utils/token_utils.ts
index f4fa7ac31..60cf4527b 100644
--- a/test/utils/token_utils.ts
+++ b/test/utils/token_utils.ts
@@ -11,7 +11,7 @@ export class TokenUtils {
public getProtocolTokenOrThrow(): Token {
const zrxToken = _.find(this.tokens, {symbol: PROTOCOL_TOKEN_SYMBOL});
if (_.isUndefined(zrxToken)) {
- throw new Error(ZeroExError.ZRX_NOT_IN_TOKEN_REGISTRY);
+ throw new Error(ZeroExError.ZrxNotInTokenRegistry);
}
return zrxToken;
}
diff --git a/yarn.lock b/yarn.lock
index f96c2c29f..dcc8ace84 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -4840,7 +4840,7 @@ typescript@2.3.2:
version "2.3.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.3.2.tgz#f0f045e196f69a72f06b25fd3bd39d01c3ce9984"
-typescript@^2.3.3:
+typescript@^2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.4.1.tgz#c3ccb16ddaa0b2314de031e7e6fee89e5ba346bc"