aboutsummaryrefslogtreecommitdiffstats
path: root/packages/order-utils/src
diff options
context:
space:
mode:
authorBrandon Millman <brandon.millman@gmail.com>2018-08-03 04:22:04 +0800
committerBrandon Millman <brandon.millman@gmail.com>2018-08-06 06:33:52 +0800
commit09c0fc94fc91134acfdee1017d7a50e2047b019b (patch)
tree4ba69cf8e4777fd4411ffbfe96545883a358c662 /packages/order-utils/src
parente5d65b585a2b0a159f50320eaf5bfec05a869478 (diff)
downloaddexon-sol-tools-09c0fc94fc91134acfdee1017d7a50e2047b019b.tar
dexon-sol-tools-09c0fc94fc91134acfdee1017d7a50e2047b019b.tar.gz
dexon-sol-tools-09c0fc94fc91134acfdee1017d7a50e2047b019b.tar.bz2
dexon-sol-tools-09c0fc94fc91134acfdee1017d7a50e2047b019b.tar.lz
dexon-sol-tools-09c0fc94fc91134acfdee1017d7a50e2047b019b.tar.xz
dexon-sol-tools-09c0fc94fc91134acfdee1017d7a50e2047b019b.tar.zst
dexon-sol-tools-09c0fc94fc91134acfdee1017d7a50e2047b019b.zip
Implement first round of tests for findOrdersThatCoverMakerAssetFillAmount
Diffstat (limited to 'packages/order-utils/src')
-rw-r--r--packages/order-utils/src/constants.ts1
-rw-r--r--packages/order-utils/src/index.ts1
-rw-r--r--packages/order-utils/src/market_utils.ts23
3 files changed, 13 insertions, 12 deletions
diff --git a/packages/order-utils/src/constants.ts b/packages/order-utils/src/constants.ts
index b18546a6c..5137ff499 100644
--- a/packages/order-utils/src/constants.ts
+++ b/packages/order-utils/src/constants.ts
@@ -2,6 +2,7 @@ import { BigNumber } from '@0xproject/utils';
export const constants = {
NULL_ADDRESS: '0x0000000000000000000000000000000000000000',
+ NULL_BYTES: '0x',
// tslint:disable-next-line:custom-no-magic-numbers
UNLIMITED_ALLOWANCE_IN_BASE_UNITS: new BigNumber(2).pow(256).minus(1),
TESTRPC_NETWORK_ID: 50,
diff --git a/packages/order-utils/src/index.ts b/packages/order-utils/src/index.ts
index 129eb0a3d..858f500c6 100644
--- a/packages/order-utils/src/index.ts
+++ b/packages/order-utils/src/index.ts
@@ -32,3 +32,4 @@ export { assetDataUtils } from './asset_data_utils';
export { EIP712Utils } from './eip712_utils';
export { OrderValidationUtils } from './order_validation_utils';
export { ExchangeTransferSimulator } from './exchange_transfer_simulator';
+export { marketUtils } from './market_utils';
diff --git a/packages/order-utils/src/market_utils.ts b/packages/order-utils/src/market_utils.ts
index 4ddcc6ec8..710eddf8a 100644
--- a/packages/order-utils/src/market_utils.ts
+++ b/packages/order-utils/src/market_utils.ts
@@ -39,10 +39,17 @@ export const marketUtils = {
return { resultOrders, remainingFillAmount: constants.ZERO_AMOUNT };
} else {
const orderState = orderStates[index];
- const makerAssetAmountAvailable = getMakerAssetAmountAvailable(orderState);
+ const makerAssetAmountAvailable = orderState.remainingFillableMakerAssetAmount;
+ // if there is no makerAssetAmountAvailable do not append order to resultOrders
+ // if we have exceeded the total amount we want to fill set remainingFillAmount to 0
return {
- resultOrders: _.concat(resultOrders, order),
- remainingFillAmount: remainingFillAmount.minus(makerAssetAmountAvailable),
+ resultOrders: makerAssetAmountAvailable.gt(constants.ZERO_AMOUNT)
+ ? _.concat(resultOrders, order)
+ : resultOrders,
+ remainingFillAmount: BigNumber.max(
+ constants.ZERO_AMOUNT,
+ remainingFillAmount.minus(makerAssetAmountAvailable),
+ ),
};
}
},
@@ -83,7 +90,7 @@ export const marketUtils = {
signedOrders,
(accFees, order, index) => {
const orderState = orderStates[index];
- const makerAssetAmountAvailable = getMakerAssetAmountAvailable(orderState);
+ const makerAssetAmountAvailable = orderState.remainingFillableMakerAssetAmount;
const feeToFillMakerAssetAmountAvailable = makerAssetAmountAvailable
.div(order.makerAssetAmount)
.mul(order.takerFee);
@@ -99,11 +106,3 @@ export const marketUtils = {
);
},
};
-
-const getMakerAssetAmountAvailable = (orderState: OrderRelevantState) => {
- return BigNumber.min(
- orderState.makerBalance,
- orderState.remainingFillableMakerAssetAmount,
- orderState.makerProxyAllowance,
- );
-};