aboutsummaryrefslogtreecommitdiffstats
path: root/packages/asset-buyer/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/asset-buyer/src')
-rw-r--r--packages/asset-buyer/src/errors.ts16
-rw-r--r--packages/asset-buyer/src/index.ts2
-rw-r--r--packages/asset-buyer/src/types.ts12
-rw-r--r--packages/asset-buyer/src/utils/buy_quote_calculator.ts16
4 files changed, 25 insertions, 21 deletions
diff --git a/packages/asset-buyer/src/errors.ts b/packages/asset-buyer/src/errors.ts
new file mode 100644
index 000000000..ef05a5d0a
--- /dev/null
+++ b/packages/asset-buyer/src/errors.ts
@@ -0,0 +1,16 @@
+import { BigNumber } from '@0x/utils';
+
+import { AssetBuyerError } from './types';
+
+/**
+ * Error class representing insufficient asset liquidity
+ */
+export class InsufficientAssetLiquidityError extends Error {
+ public amountAvailableToFill?: BigNumber;
+ constructor(amountAvailableToFill?: BigNumber) {
+ super(AssetBuyerError.InsufficientAssetLiquidity);
+ this.amountAvailableToFill = amountAvailableToFill;
+ // Setting prototype so instanceof works. See https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work
+ Object.setPrototypeOf(this, InsufficientAssetLiquidityError.prototype);
+ }
+}
diff --git a/packages/asset-buyer/src/index.ts b/packages/asset-buyer/src/index.ts
index 59515e24f..a42d7e272 100644
--- a/packages/asset-buyer/src/index.ts
+++ b/packages/asset-buyer/src/index.ts
@@ -9,6 +9,7 @@ export { SignedOrder } from '@0x/types';
export { BigNumber } from '@0x/utils';
export { AssetBuyer } from './asset_buyer';
+export { InsufficientAssetLiquidityError } from './errors';
export { BasicOrderProvider } from './order_providers/basic_order_provider';
export { StandardRelayerAPIOrderProvider } from './order_providers/standard_relayer_api_order_provider';
export {
@@ -18,7 +19,6 @@ export {
BuyQuoteExecutionOpts,
BuyQuoteInfo,
BuyQuoteRequestOpts,
- InsufficientAssetLiquidityError,
OrderProvider,
OrderProviderRequest,
OrderProviderResponse,
diff --git a/packages/asset-buyer/src/types.ts b/packages/asset-buyer/src/types.ts
index d435f337e..d5d6be695 100644
--- a/packages/asset-buyer/src/types.ts
+++ b/packages/asset-buyer/src/types.ts
@@ -102,7 +102,7 @@ export interface AssetBuyerOpts {
}
/**
- * Possible errors thrown by an AssetBuyer instance or associated static methods.
+ * Possible error messages thrown by an AssetBuyer instance or associated static methods.
*/
export enum AssetBuyerError {
NoEtherTokenContractFound = 'NO_ETHER_TOKEN_CONTRACT_FOUND',
@@ -117,16 +117,6 @@ export enum AssetBuyerError {
TransactionValueTooLow = 'TRANSACTION_VALUE_TOO_LOW',
}
-export class InsufficientAssetLiquidityError extends Error {
- public amountAvailableToFill: BigNumber;
- constructor(amountAvailableToFill: BigNumber) {
- super(AssetBuyerError.InsufficientAssetLiquidity);
- this.amountAvailableToFill = amountAvailableToFill;
- // Setting prototype so instanceof works. See https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work
- Object.setPrototypeOf(this, InsufficientAssetLiquidityError.prototype);
- }
-}
-
export interface OrdersAndFillableAmounts {
orders: SignedOrder[];
remainingFillableMakerAssetAmounts: BigNumber[];
diff --git a/packages/asset-buyer/src/utils/buy_quote_calculator.ts b/packages/asset-buyer/src/utils/buy_quote_calculator.ts
index 23d3e9b24..59293d1b7 100644
--- a/packages/asset-buyer/src/utils/buy_quote_calculator.ts
+++ b/packages/asset-buyer/src/utils/buy_quote_calculator.ts
@@ -1,16 +1,10 @@
import { marketUtils, SignedOrder } from '@0x/order-utils';
import { BigNumber } from '@0x/utils';
-import { Web3Wrapper } from '@0x/web3-wrapper';
import * as _ from 'lodash';
import { constants } from '../constants';
-import {
- AssetBuyerError,
- BuyQuote,
- BuyQuoteInfo,
- InsufficientAssetLiquidityError,
- OrdersAndFillableAmounts,
-} from '../types';
+import { InsufficientAssetLiquidityError } from '../errors';
+import { AssetBuyerError, BuyQuote, BuyQuoteInfo, OrdersAndFillableAmounts } from '../types';
import { orderUtils } from './order_utils';
@@ -53,7 +47,11 @@ export const buyQuoteCalculator = {
.div(multiplerNeededWithSlippage)
.round(0, BigNumber.ROUND_DOWN);
- throw new InsufficientAssetLiquidityError(amountAvailableToFillConsideringSlippage);
+ throw new InsufficientAssetLiquidityError(
+ amountAvailableToFillConsideringSlippage.gt(constants.ZERO_AMOUNT)
+ ? amountAvailableToFillConsideringSlippage
+ : undefined,
+ );
}
// if we are not buying ZRX:
// given the orders calculated above, find the fee-orders that cover the desired assetBuyAmount (with slippage)