diff options
author | Brandon Millman <brandon.millman@gmail.com> | 2018-08-10 06:54:17 +0800 |
---|---|---|
committer | Brandon Millman <brandon.millman@gmail.com> | 2018-08-10 07:12:42 +0800 |
commit | cbe639866ec9d6088cc7aa133033d2735524c5a0 (patch) | |
tree | 31dcd5fb2a73d4d6ce33f0c4d495625d53ef7e58 /packages/order-utils/src | |
parent | fcd57d2743e4b6a1363b8071696147a91d2afb00 (diff) | |
download | dexon-sol-tools-cbe639866ec9d6088cc7aa133033d2735524c5a0.tar dexon-sol-tools-cbe639866ec9d6088cc7aa133033d2735524c5a0.tar.gz dexon-sol-tools-cbe639866ec9d6088cc7aa133033d2735524c5a0.tar.bz2 dexon-sol-tools-cbe639866ec9d6088cc7aa133033d2735524c5a0.tar.lz dexon-sol-tools-cbe639866ec9d6088cc7aa133033d2735524c5a0.tar.xz dexon-sol-tools-cbe639866ec9d6088cc7aa133033d2735524c5a0.tar.zst dexon-sol-tools-cbe639866ec9d6088cc7aa133033d2735524c5a0.zip |
Make feeRate optional with a default of 0
Diffstat (limited to 'packages/order-utils/src')
-rw-r--r-- | packages/order-utils/src/rate_utils.ts | 9 | ||||
-rw-r--r-- | packages/order-utils/src/sorting_utils.ts | 6 |
2 files changed, 12 insertions, 3 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); |