From a5e7ce9e1acb2f8fdfcef629789dd315e3adcbdc Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Fri, 11 Jan 2019 09:28:51 -0800 Subject: Move calculateLiquidity to helper function --- packages/asset-buyer/src/asset_buyer.ts | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) (limited to 'packages/asset-buyer/src/asset_buyer.ts') diff --git a/packages/asset-buyer/src/asset_buyer.ts b/packages/asset-buyer/src/asset_buyer.ts index 43b60f928..cd60f0eff 100644 --- a/packages/asset-buyer/src/asset_buyer.ts +++ b/packages/asset-buyer/src/asset_buyer.ts @@ -19,50 +19,20 @@ import { LiquidityForAssetData, LiquidityRequestOpts, OrderProvider, - OrderProviderResponse, OrdersAndFillableAmounts, } from './types'; import { assert } from './utils/assert'; import { assetDataUtils } from './utils/asset_data_utils'; import { buyQuoteCalculator } from './utils/buy_quote_calculator'; +import { calculateLiquidity } from './utils/calculate_liquidity'; import { orderProviderResponseProcessor } from './utils/order_provider_response_processor'; -import { orderUtils } from './utils/order_utils'; interface OrdersEntry { ordersAndFillableAmounts: OrdersAndFillableAmounts; lastRefreshTime: number; } -const calculateLiquidity = (ordersAndFillableAmounts: OrdersAndFillableAmounts): LiquidityForAssetData => { - const { orders, remainingFillableMakerAssetAmounts } = ordersAndFillableAmounts; - const liquidityInBigNumbers = orders.reduce( - (acc, order, curIndex) => { - const availableMakerAssetAmount = remainingFillableMakerAssetAmounts[curIndex]; - if (availableMakerAssetAmount === undefined) { - throw new Error(`No corresponding fillableMakerAssetAmounts at index ${curIndex}`); - } - - const tokensAvailableForCurrentOrder = availableMakerAssetAmount; - const ethValueAvailableForCurrentOrder = orderUtils.getTakerFillAmount(order, availableMakerAssetAmount); - return { - tokensAvailableInBaseUnits: acc.tokensAvailableInBaseUnits.plus(tokensAvailableForCurrentOrder), - ethValueAvailableInWei: acc.ethValueAvailableInWei.plus(ethValueAvailableForCurrentOrder), - }; - }, - { - tokensAvailableInBaseUnits: new BigNumber(0), - ethValueAvailableInWei: new BigNumber(0), - }, - ); - - // Turn into regular numbers - return { - tokensAvailableInBaseUnits: liquidityInBigNumbers.tokensAvailableInBaseUnits.toNumber(), - ethValueAvailableInWei: liquidityInBigNumbers.ethValueAvailableInWei.toNumber(), - }; -}; - export class AssetBuyer { public readonly provider: Provider; public readonly orderProvider: OrderProvider; -- cgit