From a7db900e518589d318210f5d22507b198c15d3b3 Mon Sep 17 00:00:00 2001 From: David Sun Date: Wed, 26 Jun 2019 14:48:37 -0700 Subject: [PATCH] added types --- packages/asset-buyer/src/constants.ts | 2 ++ packages/asset-buyer/src/swap_quoter.ts | 2 +- packages/asset-buyer/src/types.ts | 7 +++++++ packages/asset-buyer/src/utils/swap_quote_calculator.ts | 5 +++-- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/asset-buyer/src/constants.ts b/packages/asset-buyer/src/constants.ts index 10dd79b9d4..52b211e2b2 100644 --- a/packages/asset-buyer/src/constants.ts +++ b/packages/asset-buyer/src/constants.ts @@ -5,6 +5,7 @@ import { ForwarderSwapQuoteExecutionOpts, ForwarderSwapQuoteGetOutputOpts, OrdersAndFillableAmounts, + SwapQuoteOperation, SwapQuoteRequestOpts, SwapQuoterOpts, } from './types'; @@ -29,6 +30,7 @@ const DEFAULT_FORWARDER_SWAP_QUOTE_EXECUTE_OPTS: ForwarderSwapQuoteExecutionOpts const DEFAULT_SWAP_QUOTE_REQUEST_OPTS: SwapQuoteRequestOpts = { shouldForceOrderRefresh: false, slippagePercentage: 0.2, // 20% slippage protection, + operation: SwapQuoteOperation.MarketBuy, }; const EMPTY_ORDERS_AND_FILLABLE_AMOUNTS: OrdersAndFillableAmounts = { diff --git a/packages/asset-buyer/src/swap_quoter.ts b/packages/asset-buyer/src/swap_quoter.ts index 032f035324..e3ccfa78f1 100644 --- a/packages/asset-buyer/src/swap_quoter.ts +++ b/packages/asset-buyer/src/swap_quoter.ts @@ -136,7 +136,7 @@ export class SwapQuoter { makerAssetSwapAmount: BigNumber, options: Partial = {}, ): Promise { - const { shouldForceOrderRefresh, slippagePercentage } = _.merge( + const { shouldForceOrderRefresh, slippagePercentage, operation } = _.merge( {}, constants.DEFAULT_SWAP_QUOTE_REQUEST_OPTS, options, diff --git a/packages/asset-buyer/src/types.ts b/packages/asset-buyer/src/types.ts index 2ede85bd45..2ba18ebcf9 100644 --- a/packages/asset-buyer/src/types.ts +++ b/packages/asset-buyer/src/types.ts @@ -154,6 +154,11 @@ export interface ForwarderSwapQuoteGetOutputOpts extends SwapQuoteGetOutputOpts */ export interface ForwarderSwapQuoteExecutionOpts extends ForwarderSwapQuoteGetOutputOpts, SwapQuoteExecutionOpts {} +export enum SwapQuoteOperation { + MarketSell = 'MARKET_SELL', + MarketBuy = 'MARKET_BUY', +} + /** * takerAssetData: String that represents a specific taker asset (for more info: https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md). * makerAssetData: String that represents a specific maker asset (for more info: https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md). @@ -171,6 +176,7 @@ export interface SwapQuote { feeOrders: SignedOrder[]; bestCaseQuoteInfo: SwapQuoteInfo; worstCaseQuoteInfo: SwapQuoteInfo; + operation: SwapQuoteOperation; } export interface SwapQuoteWithAffiliateFee extends SwapQuote { @@ -195,6 +201,7 @@ export interface SwapQuoteInfo { export interface SwapQuoteRequestOpts { shouldForceOrderRefresh: boolean; slippagePercentage: number; + operation: SwapQuoteOperation; } /* diff --git a/packages/asset-buyer/src/utils/swap_quote_calculator.ts b/packages/asset-buyer/src/utils/swap_quote_calculator.ts index c60ad95d8d..6c174bd2e5 100644 --- a/packages/asset-buyer/src/utils/swap_quote_calculator.ts +++ b/packages/asset-buyer/src/utils/swap_quote_calculator.ts @@ -4,11 +4,11 @@ import * as _ from 'lodash'; import { constants } from '../constants'; import { InsufficientAssetLiquidityError } from '../errors'; -import { OrdersAndFillableAmounts, SwapQuote, SwapQuoteInfo, SwapQuoterError } from '../types'; +import { OrdersAndFillableAmounts, SwapQuote, SwapQuoteInfo, SwapQuoteOperation, SwapQuoterError } from '../types'; // Calculates a swap quote for orders export const swapQuoteCalculator = { - calculate( + calculateMarketBuySwapQuote( ordersAndFillableAmounts: OrdersAndFillableAmounts, feeOrdersAndFillableAmounts: OrdersAndFillableAmounts, makerAssetFillAmount: BigNumber, @@ -106,6 +106,7 @@ export const swapQuoteCalculator = { feeOrders: resultFeeOrders, bestCaseQuoteInfo, worstCaseQuoteInfo, + operation: SwapQuoteOperation.MarketBuy, }; }, };