From 7b46cef83dca0a743bd598a70076004983cbf294 Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Fri, 14 Sep 2018 16:18:16 +0200 Subject: Create initial AssetBuyer class --- .../utils/forwarder_helper_impl_config_utils.ts | 170 ++++++++++----------- 1 file changed, 85 insertions(+), 85 deletions(-) (limited to 'packages/asset-buyer/src/utils') diff --git a/packages/asset-buyer/src/utils/forwarder_helper_impl_config_utils.ts b/packages/asset-buyer/src/utils/forwarder_helper_impl_config_utils.ts index 253384f65..d3cbb651a 100644 --- a/packages/asset-buyer/src/utils/forwarder_helper_impl_config_utils.ts +++ b/packages/asset-buyer/src/utils/forwarder_helper_impl_config_utils.ts @@ -1,92 +1,92 @@ -import { sortingUtils } from '@0xproject/order-utils'; -import { SignedOrder } from '@0xproject/types'; -import { BigNumber } from '@0xproject/utils'; -import * as _ from 'lodash'; +// import { sortingUtils } from '@0xproject/order-utils'; +// import { SignedOrder } from '@0xproject/types'; +// import { BigNumber } from '@0xproject/utils'; +// import * as _ from 'lodash'; -import { ForwarderHelperImplConfig } from '../forwarder_helper_impl'; +// import { ForwarderHelperImplConfig } from '@0xproject/asset-buyer/src/asset_buyer'; -interface SignedOrderWithAmount extends SignedOrder { - remainingFillAmount: BigNumber; -} +// interface SignedOrderWithAmount extends SignedOrder { +// remainingFillAmount: BigNumber; +// } -export const forwarderHelperImplConfigUtils = { - sortedConfig(config: ForwarderHelperImplConfig): ForwarderHelperImplConfig { - const { orders, feeOrders, remainingFillableMakerAssetAmounts, remainingFillableFeeAmounts } = config; - // TODO: provide a feeRate to the sorting function to more accurately sort based on the current market for ZRX tokens - const orderSorter = (ordersToSort: SignedOrder[]) => { - return sortingUtils.sortOrdersByFeeAdjustedRate(ordersToSort); - }; - const sortOrdersResult = sortOrdersAndRemainingFillAmounts( - orderSorter, - orders, - remainingFillableMakerAssetAmounts, - ); - const feeOrderSorter = (ordersToSort: SignedOrder[]) => { - return sortingUtils.sortFeeOrdersByFeeAdjustedRate(ordersToSort); - }; - const sortFeeOrdersResult = sortOrdersAndRemainingFillAmounts( - feeOrderSorter, - feeOrders, - remainingFillableFeeAmounts, - ); - return { - orders: sortOrdersResult.orders, - feeOrders: sortFeeOrdersResult.orders, - remainingFillableMakerAssetAmounts: sortOrdersResult.remainingFillAmounts, - remainingFillableFeeAmounts: sortFeeOrdersResult.remainingFillAmounts, - }; - }, -}; +// export const forwarderHelperImplConfigUtils = { +// sortedConfig(config: ForwarderHelperImplConfig): ForwarderHelperImplConfig { +// const { orders, feeOrders, remainingFillableMakerAssetAmounts, remainingFillableFeeAmounts } = config; +// // TODO: provide a feeRate to the sorting function to more accurately sort based on the current market for ZRX tokens +// const orderSorter = (ordersToSort: SignedOrder[]) => { +// return sortingUtils.sortOrdersByFeeAdjustedRate(ordersToSort); +// }; +// const sortOrdersResult = sortOrdersAndRemainingFillAmounts( +// orderSorter, +// orders, +// remainingFillableMakerAssetAmounts, +// ); +// const feeOrderSorter = (ordersToSort: SignedOrder[]) => { +// return sortingUtils.sortFeeOrdersByFeeAdjustedRate(ordersToSort); +// }; +// const sortFeeOrdersResult = sortOrdersAndRemainingFillAmounts( +// feeOrderSorter, +// feeOrders, +// remainingFillableFeeAmounts, +// ); +// return { +// orders: sortOrdersResult.orders, +// feeOrders: sortFeeOrdersResult.orders, +// remainingFillableMakerAssetAmounts: sortOrdersResult.remainingFillAmounts, +// remainingFillableFeeAmounts: sortFeeOrdersResult.remainingFillAmounts, +// }; +// }, +// }; -type OrderSorter = (orders: SignedOrder[]) => SignedOrder[]; +// type OrderSorter = (orders: SignedOrder[]) => SignedOrder[]; -function sortOrdersAndRemainingFillAmounts( - orderSorter: OrderSorter, - orders: SignedOrder[], - remainingFillAmounts?: BigNumber[], -): { orders: SignedOrder[]; remainingFillAmounts?: BigNumber[] } { - if (!_.isUndefined(remainingFillAmounts)) { - // Bundle orders together with their remainingFillAmounts so that we can sort them together - const orderWithAmounts = bundleSignedOrderWithAmounts(orders, remainingFillAmounts); - // Sort - const sortedOrderWithAmounts = orderSorter(orderWithAmounts) as SignedOrderWithAmount[]; - // Unbundle after sorting - const unbundledSortedOrderWithAmounts = unbundleSignedOrderWithAmounts(sortedOrderWithAmounts); - return { - orders: unbundledSortedOrderWithAmounts.orders, - remainingFillAmounts: unbundledSortedOrderWithAmounts.amounts, - }; - } else { - const sortedOrders = orderSorter(orders); - return { - orders: sortedOrders, - }; - } -} +// function sortOrdersAndRemainingFillAmounts( +// orderSorter: OrderSorter, +// orders: SignedOrder[], +// remainingFillAmounts?: BigNumber[], +// ): { orders: SignedOrder[]; remainingFillAmounts?: BigNumber[] } { +// if (!_.isUndefined(remainingFillAmounts)) { +// // Bundle orders together with their remainingFillAmounts so that we can sort them together +// const orderWithAmounts = bundleSignedOrderWithAmounts(orders, remainingFillAmounts); +// // Sort +// const sortedOrderWithAmounts = orderSorter(orderWithAmounts) as SignedOrderWithAmount[]; +// // Unbundle after sorting +// const unbundledSortedOrderWithAmounts = unbundleSignedOrderWithAmounts(sortedOrderWithAmounts); +// return { +// orders: unbundledSortedOrderWithAmounts.orders, +// remainingFillAmounts: unbundledSortedOrderWithAmounts.amounts, +// }; +// } else { +// const sortedOrders = orderSorter(orders); +// return { +// orders: sortedOrders, +// }; +// } +// } -function bundleSignedOrderWithAmounts(orders: SignedOrder[], amounts: BigNumber[]): SignedOrderWithAmount[] { - const ordersAndAmounts = _.map(orders, (order, index) => { - return { - ...order, - remainingFillAmount: amounts[index], - }; - }); - return ordersAndAmounts; -} +// function bundleSignedOrderWithAmounts(orders: SignedOrder[], amounts: BigNumber[]): SignedOrderWithAmount[] { +// const ordersAndAmounts = _.map(orders, (order, index) => { +// return { +// ...order, +// remainingFillAmount: amounts[index], +// }; +// }); +// return ordersAndAmounts; +// } -function unbundleSignedOrderWithAmounts( - signedOrderWithAmounts: SignedOrderWithAmount[], -): { orders: SignedOrder[]; amounts: BigNumber[] } { - const orders = _.map(signedOrderWithAmounts, order => { - const { remainingFillAmount, ...rest } = order; - return rest; - }); - const amounts = _.map(signedOrderWithAmounts, order => { - const { remainingFillAmount } = order; - return remainingFillAmount; - }); - return { - orders, - amounts, - }; -} +// function unbundleSignedOrderWithAmounts( +// signedOrderWithAmounts: SignedOrderWithAmount[], +// ): { orders: SignedOrder[]; amounts: BigNumber[] } { +// const orders = _.map(signedOrderWithAmounts, order => { +// const { remainingFillAmount, ...rest } = order; +// return rest; +// }); +// const amounts = _.map(signedOrderWithAmounts, order => { +// const { remainingFillAmount } = order; +// return remainingFillAmount; +// }); +// return { +// orders, +// amounts, +// }; +// } -- cgit