aboutsummaryrefslogtreecommitdiffstats
path: root/packages/asset-buyer/src
diff options
context:
space:
mode:
authorSteve Klebanoff <steve.klebanoff@gmail.com>2018-12-14 07:16:51 +0800
committerSteve Klebanoff <steve.klebanoff@gmail.com>2018-12-15 07:34:45 +0800
commitc6c45095a8511814db6aa33e39794ae60debad8b (patch)
tree708189f5ec03707c2954725db150788026fc3b1f /packages/asset-buyer/src
parent6d45beccad44e86ddd692d0cf54c09c29c5d9daf (diff)
downloaddexon-sol-tools-c6c45095a8511814db6aa33e39794ae60debad8b.tar
dexon-sol-tools-c6c45095a8511814db6aa33e39794ae60debad8b.tar.gz
dexon-sol-tools-c6c45095a8511814db6aa33e39794ae60debad8b.tar.bz2
dexon-sol-tools-c6c45095a8511814db6aa33e39794ae60debad8b.tar.lz
dexon-sol-tools-c6c45095a8511814db6aa33e39794ae60debad8b.tar.xz
dexon-sol-tools-c6c45095a8511814db6aa33e39794ae60debad8b.tar.zst
dexon-sol-tools-c6c45095a8511814db6aa33e39794ae60debad8b.zip
feat(asset-buyer): Custom InsufficientAssetLiquidityError error
BREAKING CHANGE: A custom InsufficientAssetLiquidityError error is now raised when there is insufficient liquidity
Diffstat (limited to 'packages/asset-buyer/src')
-rw-r--r--packages/asset-buyer/src/types.ts10
-rw-r--r--packages/asset-buyer/src/utils/buy_quote_calculator.ts11
2 files changed, 19 insertions, 2 deletions
diff --git a/packages/asset-buyer/src/types.ts b/packages/asset-buyer/src/types.ts
index 3b573edca..dfa17a22d 100644
--- a/packages/asset-buyer/src/types.ts
+++ b/packages/asset-buyer/src/types.ts
@@ -117,6 +117,16 @@ export enum AssetBuyerError {
TransactionValueTooLow = 'TRANSACTION_VALUE_TOO_LOW',
}
+export class InsufficientAssetLiquidityError extends Error {
+ public numAssetsAvailable: BigNumber;
+ constructor(numAssetsAvailable: BigNumber) {
+ super(AssetBuyerError.InsufficientAssetLiquidity);
+ this.numAssetsAvailable = numAssetsAvailable;
+ // 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 b15b880c2..e52c9c5bf 100644
--- a/packages/asset-buyer/src/utils/buy_quote_calculator.ts
+++ b/packages/asset-buyer/src/utils/buy_quote_calculator.ts
@@ -3,7 +3,13 @@ import { BigNumber } from '@0x/utils';
import * as _ from 'lodash';
import { constants } from '../constants';
-import { AssetBuyerError, BuyQuote, BuyQuoteInfo, OrdersAndFillableAmounts } from '../types';
+import {
+ AssetBuyerError,
+ BuyQuote,
+ BuyQuoteInfo,
+ InsufficientAssetLiquidityError,
+ OrdersAndFillableAmounts,
+} from '../types';
import { orderUtils } from './order_utils';
@@ -33,7 +39,8 @@ export const buyQuoteCalculator = {
});
// if we do not have enough orders to cover the desired assetBuyAmount, throw
if (remainingFillAmount.gt(constants.ZERO_AMOUNT)) {
- throw new Error(AssetBuyerError.InsufficientAssetLiquidity);
+ const amountRemaining = assetBuyAmount.minus(remainingFillAmount);
+ throw new InsufficientAssetLiquidityError(amountRemaining);
}
// if we are not buying ZRX:
// given the orders calculated above, find the fee-orders that cover the desired assetBuyAmount (with slippage)