added types
This commit is contained in:
parent
cfa2a90dae
commit
a7db900e51
@ -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 = {
|
||||
|
@ -136,7 +136,7 @@ export class SwapQuoter {
|
||||
makerAssetSwapAmount: BigNumber,
|
||||
options: Partial<SwapQuoteRequestOpts> = {},
|
||||
): Promise<SwapQuote> {
|
||||
const { shouldForceOrderRefresh, slippagePercentage } = _.merge(
|
||||
const { shouldForceOrderRefresh, slippagePercentage, operation } = _.merge(
|
||||
{},
|
||||
constants.DEFAULT_SWAP_QUOTE_REQUEST_OPTS,
|
||||
options,
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -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,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user