aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorBrandon Millman <brandon.millman@gmail.com>2018-09-13 20:39:06 +0800
committerBrandon Millman <brandon.millman@gmail.com>2018-09-15 20:14:48 +0800
commit8d6132736bfd57d08448cbde538c13072df80256 (patch)
treee36786a8c8d756eef05e2ce75eca8ce9c85dadc8 /packages
parent8687b9533c67a551df928b28a776bfdbe6e3e84f (diff)
downloaddexon-sol-tools-8d6132736bfd57d08448cbde538c13072df80256.tar
dexon-sol-tools-8d6132736bfd57d08448cbde538c13072df80256.tar.gz
dexon-sol-tools-8d6132736bfd57d08448cbde538c13072df80256.tar.bz2
dexon-sol-tools-8d6132736bfd57d08448cbde538c13072df80256.tar.lz
dexon-sol-tools-8d6132736bfd57d08448cbde538c13072df80256.tar.xz
dexon-sol-tools-8d6132736bfd57d08448cbde538c13072df80256.tar.zst
dexon-sol-tools-8d6132736bfd57d08448cbde538c13072df80256.zip
Remove taker address as param and filter out non-open orders
Diffstat (limited to 'packages')
-rw-r--r--packages/forwarder-helper/src/constants.ts1
-rw-r--r--packages/forwarder-helper/src/forwarder_helper_factory.ts20
-rw-r--r--packages/forwarder-helper/src/utils/order_utils.ts5
3 files changed, 18 insertions, 8 deletions
diff --git a/packages/forwarder-helper/src/constants.ts b/packages/forwarder-helper/src/constants.ts
index 0ad30e4c0..c0a1b090e 100644
--- a/packages/forwarder-helper/src/constants.ts
+++ b/packages/forwarder-helper/src/constants.ts
@@ -2,4 +2,5 @@ import { BigNumber } from '@0xproject/utils';
export const constants = {
ZERO_AMOUNT: new BigNumber(0),
+ NULL_ADDRESS: '0x0000000000000000000000000000000000000000',
};
diff --git a/packages/forwarder-helper/src/forwarder_helper_factory.ts b/packages/forwarder-helper/src/forwarder_helper_factory.ts
index e3ef59388..ab8eaeeaf 100644
--- a/packages/forwarder-helper/src/forwarder_helper_factory.ts
+++ b/packages/forwarder-helper/src/forwarder_helper_factory.ts
@@ -1,5 +1,5 @@
import { assert } from '@0xproject/assert';
-import { APIOrder, HttpClient } from '@0xproject/connect';
+import { APIOrder, HttpClient, OrderbookResponse } from '@0xproject/connect';
import { ContractWrappers, OrderAndTraderInfo, OrderStatus } from '@0xproject/contract-wrappers';
import { schemas } from '@0xproject/json-schemas';
import { assetDataUtils } from '@0xproject/order-utils';
@@ -41,13 +41,11 @@ export const forwarderHelperFactory = {
*/
async getForwarderHelperForMakerAssetDataAsync(
makerAssetData: string,
- takerAddress: string,
sraUrl: string,
rpcUrl?: string,
networkId: number = 1,
): Promise<ForwarderHelper> {
assert.isHexString('makerAssetData', makerAssetData);
- assert.isETHAddressHex('takerAddress', takerAddress);
assert.isWebUri('sraUrl', sraUrl);
if (!_.isUndefined(rpcUrl)) {
assert.isWebUri('rpcUrl', rpcUrl);
@@ -90,12 +88,12 @@ export const forwarderHelperFactory = {
let feeOrdersAndRemainingFillableMakerAssetAmounts: OrdersAndRemainingFillableMakerAssetAmounts;
if (!_.isUndefined(rpcUrl)) {
// if we do have an rpc url, get on-chain orders and traders info via the OrderValidatorWrapper
- const ordersFromSra = _.map(makerAssetOrderbook.asks.records, apiOrder => apiOrder.order);
- const feeOrdersFromSra = _.map(zrxOrderbook.asks.records, apiOrder => apiOrder.order);
+ const ordersFromSra = getOpenAsksFromOrderbook(makerAssetOrderbook);
+ const feeOrdersFromSra = getOpenAsksFromOrderbook(zrxOrderbook);
// TODO: try catch these requests and throw a more domain specific error
const [makerAssetOrdersAndTradersInfo, feeOrdersAndTradersInfo] = await Promise.all(
_.map([ordersFromSra, feeOrdersFromSra], ordersToBeValidated => {
- const takerAddresses = _.map(ordersToBeValidated, () => takerAddress);
+ const takerAddresses = _.map(ordersToBeValidated, () => constants.NULL_ADDRESS);
return contractWrappers.orderValidator.getOrdersAndTradersInfoAsync(
ordersToBeValidated,
takerAddresses,
@@ -161,8 +159,8 @@ function getValidOrdersAndRemainingFillableMakerAssetAmountsFromApi(
const { orders, remainingFillableMakerAssetAmounts } = acc;
// get order and metadata
const { order, metaData } = apiOrder;
- // if the order is expired, move on
- if (orderUtils.isOrderExpired(order)) {
+ // if the order is expired or not open, move on
+ if (orderUtils.isOrderExpired(order) || !orderUtils.isOpenOrder(order)) {
return acc;
}
// calculate remainingFillableMakerAssetAmount from api metadata
@@ -248,3 +246,9 @@ function getValidOrdersAndRemainingFillableMakerAssetAmountsFromOnChain(
);
return result;
}
+
+function getOpenAsksFromOrderbook(orderbookResponse: OrderbookResponse): SignedOrder[] {
+ const asks = _.map(orderbookResponse.asks.records, apiOrder => apiOrder.order);
+ const result = _.filter(asks, ask => orderUtils.isOpenOrder(ask));
+ return result;
+}
diff --git a/packages/forwarder-helper/src/utils/order_utils.ts b/packages/forwarder-helper/src/utils/order_utils.ts
index d14c6a6d7..482006bf1 100644
--- a/packages/forwarder-helper/src/utils/order_utils.ts
+++ b/packages/forwarder-helper/src/utils/order_utils.ts
@@ -1,6 +1,8 @@
import { SignedOrder } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
+import { constants } from '../constants';
+
export const orderUtils = {
isOrderExpired(order: SignedOrder): boolean {
const millisecondsInSecond = 1000;
@@ -13,4 +15,7 @@ export const orderUtils = {
: remainingTakerAssetAmount.times(order.makerAssetAmount).dividedToIntegerBy(order.takerAssetAmount);
return result;
},
+ isOpenOrder(order: SignedOrder): boolean {
+ return order.takerAddress === constants.NULL_ADDRESS;
+ },
};