From a5c7ddcff54fcb9e88adfda15167836b00db877d Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Wed, 22 Aug 2018 14:45:44 -0700 Subject: Add more comments --- packages/forwarder-helper/src/forwarder_helper_factory.ts | 6 ++++++ packages/forwarder-helper/src/forwarder_helper_impl.ts | 3 +++ 2 files changed, 9 insertions(+) diff --git a/packages/forwarder-helper/src/forwarder_helper_factory.ts b/packages/forwarder-helper/src/forwarder_helper_factory.ts index f08e3ff04..0fb02e3a6 100644 --- a/packages/forwarder-helper/src/forwarder_helper_factory.ts +++ b/packages/forwarder-helper/src/forwarder_helper_factory.ts @@ -4,6 +4,12 @@ import { ForwarderHelperImpl, ForwarderHelperImplConfig } from './forwarder_help import { ForwarderHelper } from './types'; export const forwarderHelperFactory = { + /** + * Given an array of orders and an array of feeOrders + * @param orders An array of objects conforming to SignedOrder. Each order should specify the same makerAssetData and takerAssetData + * @param orders An array of objects conforming to SignedOrder. Each order should specify ZRX as makerAssetData WETH as takerAssetData + * @return A ForwarderHelper, see type for definition + */ getForwarderHelperForOrders(orders: SignedOrder[], feeOrders: SignedOrder[] = []): ForwarderHelper { const config: ForwarderHelperImplConfig = { orders, diff --git a/packages/forwarder-helper/src/forwarder_helper_impl.ts b/packages/forwarder-helper/src/forwarder_helper_impl.ts index 123c925f1..f21fab9fd 100644 --- a/packages/forwarder-helper/src/forwarder_helper_impl.ts +++ b/packages/forwarder-helper/src/forwarder_helper_impl.ts @@ -52,15 +52,18 @@ export class ForwarderHelperImpl implements ForwarderHelper { } private static _sortConfig(opts: ForwarderHelperImplConfig): ForwarderHelperImplConfig { const { orders, feeOrders, remainingFillableMakerAssetAmounts, remainingFillableFeeAmounts } = opts; + // Bundle orders together with their remainingFillAmounts so that we can sort them together const orderWithAmounts = ForwarderHelperImpl._createSignedOrderWithAmounts( orders, remainingFillableMakerAssetAmounts, ); // TODO: provide a feeRate to the sorting function to more accurately sort based on the current market for ZRX tokens const sortedOrderWithAmounts = sortingUtils.sortOrdersByFeeAdjustedRate(orderWithAmounts); + // Unbundle after sorting const unbundledSortedOrderWithAmounts = ForwarderHelperImpl._unbundleSignedOrderWithAmounts( sortedOrderWithAmounts, ); + // Do the same bundling + unbundling for feeOrder sorting const feeOrderWithAmounts = ForwarderHelperImpl._createSignedOrderWithAmounts( feeOrders, remainingFillableFeeAmounts, -- cgit