aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
9 files changed, 111 insertions, 119 deletions
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);