aboutsummaryrefslogtreecommitdiffstats
path: root/packages/order-utils
diff options
context:
space:
mode:
Diffstat (limited to 'packages/order-utils')
-rw-r--r--packages/order-utils/src/rate_utils.ts9
-rw-r--r--packages/order-utils/src/sorting_utils.ts6
-rw-r--r--packages/order-utils/test/rate_utils_test.ts8
3 files changed, 13 insertions, 10 deletions
diff --git a/packages/order-utils/src/rate_utils.ts b/packages/order-utils/src/rate_utils.ts
index 212431e0c..72d11584a 100644
--- a/packages/order-utils/src/rate_utils.ts
+++ b/packages/order-utils/src/rate_utils.ts
@@ -1,6 +1,7 @@
import { schemas } from '@0xproject/json-schemas';
import { SignedOrder } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
+import * as _ from 'lodash';
import { assert } from './assert';
import { constants } from './constants';
@@ -12,12 +13,16 @@ export const rateUtils = {
* @param signedOrder An object that conforms to the signedOrder interface
* @param feeRate The market rate of ZRX denominated in takerAssetAmount
* (ex. feeRate is 0.1 takerAsset/ZRX if it takes 1 unit of takerAsset to buy 10 ZRX)
+ * Defaults to 0
* @return The rate (takerAsset/makerAsset) of the order adjusted for fees
*/
- getFeeAdjustedRateOfOrder(signedOrder: SignedOrder, feeRate: BigNumber): BigNumber {
+ getFeeAdjustedRateOfOrder(signedOrder: SignedOrder, feeRate: BigNumber = constants.ZERO_AMOUNT): BigNumber {
assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema);
assert.isBigNumber('feeRate', feeRate);
- assert.assert(feeRate.greaterThan(constants.ZERO_AMOUNT), `Expected feeRate: ${feeRate} to be greater than 0`);
+ assert.assert(
+ feeRate.gte(constants.ZERO_AMOUNT),
+ `Expected feeRate: ${feeRate} to be greater than or equal to 0`,
+ );
const takerAssetAmountNeededToPayForFees = signedOrder.takerFee.mul(feeRate);
const totalTakerAssetAmount = takerAssetAmountNeededToPayForFees.plus(signedOrder.takerAssetAmount);
const rate = totalTakerAssetAmount.div(signedOrder.makerAssetAmount);
diff --git a/packages/order-utils/src/sorting_utils.ts b/packages/order-utils/src/sorting_utils.ts
index 2acd8180f..8424060fc 100644
--- a/packages/order-utils/src/sorting_utils.ts
+++ b/packages/order-utils/src/sorting_utils.ts
@@ -15,9 +15,13 @@ export const sortingUtils = {
* the makerAsset and WETH as the takerAsset.
* @param feeRate The market rate of ZRX denominated in takerAssetAmount
* (ex. feeRate is 0.1 takerAsset/ZRX if it takes 1 unit of takerAsset to buy 10 ZRX)
+ * Defaults to 0
* @return The input orders sorted by rate in ascending order
*/
- sortOrdersByFeeAdjustedRate(signedOrders: SignedOrder[], feeRate: BigNumber): SignedOrder[] {
+ sortOrdersByFeeAdjustedRate(
+ signedOrders: SignedOrder[],
+ feeRate: BigNumber = constants.ZERO_AMOUNT,
+ ): SignedOrder[] {
assert.doesConformToSchema('signedOrders', signedOrders, schemas.signedOrdersSchema);
assert.isBigNumber('feeRate', feeRate);
const rateCalculator = (signedOrder: SignedOrder) => rateUtils.getFeeAdjustedRateOfOrder(signedOrder, feeRate);
diff --git a/packages/order-utils/test/rate_utils_test.ts b/packages/order-utils/test/rate_utils_test.ts
index 2f321a7db..167a40465 100644
--- a/packages/order-utils/test/rate_utils_test.ts
+++ b/packages/order-utils/test/rate_utils_test.ts
@@ -17,16 +17,10 @@ describe('rateUtils', () => {
takerFee: new BigNumber(20),
});
describe('#getFeeAdjustedRateOfOrder', () => {
- it('throws when feeRate is zero', async () => {
- const feeRate = constants.ZERO_AMOUNT;
- expect(() => rateUtils.getFeeAdjustedRateOfOrder(testOrder, feeRate)).to.throw(
- 'Expected feeRate: 0 to be greater than 0',
- );
- });
it('throws when feeRate is less than zero', async () => {
const feeRate = new BigNumber(-1);
expect(() => rateUtils.getFeeAdjustedRateOfOrder(testOrder, feeRate)).to.throw(
- 'Expected feeRate: -1 to be greater than 0',
+ 'Expected feeRate: -1 to be greater than or equal to 0',
);
});
it('correctly calculates fee adjusted rate', async () => {