return quote report
This commit is contained in:
@@ -3,6 +3,7 @@ import { SignedOrder } from '@0x/types';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
|
||||
import { GetMarketOrdersOpts, OptimizedMarketOrder } from './utils/market_operation_utils/types';
|
||||
import { QuoteReport } from './utils/quote_report_generator';
|
||||
import { LogFunction } from './utils/quote_requestor';
|
||||
|
||||
/**
|
||||
@@ -155,7 +156,7 @@ export interface SwapQuoteBase {
|
||||
bestCaseQuoteInfo: SwapQuoteInfo;
|
||||
worstCaseQuoteInfo: SwapQuoteInfo;
|
||||
sourceBreakdown: SwapQuoteOrdersBreakdown;
|
||||
quoteReport: string;
|
||||
quoteReport: QuoteReport;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -2,10 +2,13 @@ import { ContractAddresses } from '@0x/contract-addresses';
|
||||
import { RFQTIndicativeQuote } from '@0x/quote-server';
|
||||
import { SignedOrder } from '@0x/types';
|
||||
import { BigNumber, NULL_ADDRESS } from '@0x/utils';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { MarketOperation } from '../../types';
|
||||
import { QuoteRequestor } from '../quote_requestor';
|
||||
import { difference } from '../utils';
|
||||
|
||||
import { QuoteReportGenerator } from './../quote_report_generator';
|
||||
import { BUY_SOURCES, DEFAULT_GET_MARKET_ORDERS_OPTS, FEE_QUOTE_SOURCES, ONE_ETHER, SELL_SOURCES } from './constants';
|
||||
import { createFillPaths, getPathAdjustedRate, getPathAdjustedSlippage } from './fills';
|
||||
import {
|
||||
@@ -121,6 +124,7 @@ export class MarketOperationUtils {
|
||||
[orderFillableAmounts, liquidityProviderAddress, ethToMakerAssetRate, dexQuotes],
|
||||
rfqtIndicativeQuotes,
|
||||
] = await Promise.all([samplerPromise, rfqtPromise]);
|
||||
|
||||
return this._generateOptimizedOrders({
|
||||
orderFillableAmounts,
|
||||
nativeOrders,
|
||||
@@ -139,6 +143,7 @@ export class MarketOperationUtils {
|
||||
feeSchedule: _opts.feeSchedule,
|
||||
allowFallback: _opts.allowFallback,
|
||||
shouldBatchBridgeOrders: _opts.shouldBatchBridgeOrders,
|
||||
quoteRequestor: _opts.rfqt ? _opts.rfqt.quoteRequestor : undefined,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -225,6 +230,7 @@ export class MarketOperationUtils {
|
||||
feeSchedule: _opts.feeSchedule,
|
||||
allowFallback: _opts.allowFallback,
|
||||
shouldBatchBridgeOrders: _opts.shouldBatchBridgeOrders,
|
||||
quoteRequestor: _opts.rfqt ? _opts.rfqt.quoteRequestor : undefined,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -332,6 +338,7 @@ export class MarketOperationUtils {
|
||||
shouldBatchBridgeOrders?: boolean;
|
||||
liquidityProviderAddress?: string;
|
||||
multiBridgeAddress?: string;
|
||||
quoteRequestor?: QuoteRequestor;
|
||||
}): OptimizedOrdersAndQuoteReport {
|
||||
const { inputToken, outputToken, side, inputAmount } = opts;
|
||||
const maxFallbackSlippage = opts.maxFallbackSlippage || 0;
|
||||
@@ -396,7 +403,10 @@ export class MarketOperationUtils {
|
||||
multiBridgeAddress: opts.multiBridgeAddress,
|
||||
shouldBatchBridgeOrders: !!opts.shouldBatchBridgeOrders,
|
||||
});
|
||||
return { optimizedOrders, quoteReport: 'TODO' };
|
||||
|
||||
const collapsedPaths = _.flatten(optimizedOrders.map(o => o.fills));
|
||||
const quoteReport = new QuoteReportGenerator(opts.side, _.flatten(opts.dexQuotes), opts.nativeOrders, opts.orderFillableAmounts, collapsedPaths, opts.quoteRequestor).generateReport();
|
||||
return { optimizedOrders, quoteReport };
|
||||
}
|
||||
|
||||
private _optionalSources(): ERC20BridgeSource[] {
|
||||
|
@@ -3,6 +3,7 @@ import { BigNumber } from '@0x/utils';
|
||||
|
||||
import { RfqtRequestOpts, SignedOrderWithFillableAmounts } from '../../types';
|
||||
import { QuoteRequestor } from '../../utils/quote_requestor';
|
||||
import { QuoteReport } from '../quote_report_generator';
|
||||
|
||||
/**
|
||||
* Order domain keys: chainId and exchange
|
||||
@@ -221,5 +222,5 @@ export interface FakeBuyOpts {
|
||||
|
||||
export interface OptimizedOrdersAndQuoteReport {
|
||||
optimizedOrders: OptimizedMarketOrder[];
|
||||
quoteReport: string;
|
||||
quoteReport: QuoteReport;
|
||||
}
|
||||
|
@@ -44,7 +44,7 @@ export class QuoteReportGenerator {
|
||||
private readonly _collapsedFills: CollapsedFill[];
|
||||
private readonly _quoteRequestor?: QuoteRequestor;
|
||||
|
||||
constructor(marketOperation: MarketOperation, dexQuotes: DexSample[], nativeOrders: SignedOrder[], orderFillableAmounts: BigNumber[], collapsedFills: CollapsedFill[], quoteRequestor: QuoteRequestor) {
|
||||
constructor(marketOperation: MarketOperation, dexQuotes: DexSample[], nativeOrders: SignedOrder[], orderFillableAmounts: BigNumber[], collapsedFills: CollapsedFill[], quoteRequestor?: QuoteRequestor) {
|
||||
this._dexQuotes = dexQuotes;
|
||||
this._nativeOrders = nativeOrders;
|
||||
this._marketOperation = marketOperation;
|
||||
|
@@ -20,6 +20,7 @@ import { convertNativeOrderToFullyFillableOptimizedOrders } from './market_opera
|
||||
import { GetMarketOrdersOpts, OptimizedMarketOrder, OptimizedOrdersAndQuoteReport } from './market_operation_utils/types';
|
||||
import { isSupportedAssetDataInOrders } from './utils';
|
||||
|
||||
import { QuoteReport } from './quote_report_generator';
|
||||
import { QuoteFillResult, simulateBestCaseFill, simulateWorstCaseFill } from './quote_simulation';
|
||||
|
||||
// TODO(dave4506) How do we want to reintroduce InsufficientAssetLiquidityError?
|
||||
@@ -87,6 +88,7 @@ export class SwapQuoteCalculator {
|
||||
assetFillAmounts,
|
||||
opts,
|
||||
);
|
||||
const blankQuoteReport = { sourcesConsidered: [], sourcesDelivered: [] }; // TODO: better solution here
|
||||
const batchSwapQuotes = await Promise.all(
|
||||
batchSignedOrders.map(async (orders, i) => {
|
||||
if (orders) {
|
||||
@@ -94,11 +96,12 @@ export class SwapQuoteCalculator {
|
||||
return createSwapQuote(
|
||||
makerAssetData,
|
||||
takerAssetData,
|
||||
{ optimizedOrders: orders, quoteReport: 'TODO' },
|
||||
{ optimizedOrders: orders, quoteReport: blankQuoteReport },
|
||||
operation,
|
||||
assetFillAmounts[i],
|
||||
gasPrice,
|
||||
opts.gasSchedule,
|
||||
blankQuoteReport,
|
||||
);
|
||||
} else {
|
||||
return undefined;
|
||||
@@ -134,8 +137,9 @@ export class SwapQuoteCalculator {
|
||||
: { assetProxyId: '' };
|
||||
|
||||
if (firstOrderMakerAssetData.assetProxyId === AssetProxyId.ERC721) {
|
||||
const blankQuoteReport = { sourcesConsidered: [], sourcesDelivered: [] }; // TODO: better solution here
|
||||
// HACK: to conform ERC721 orders to the output of market operation utils, assumes complete fillable
|
||||
result = { optimizedOrders: prunedOrders.map(o => convertNativeOrderToFullyFillableOptimizedOrders(o)), quoteReport: 'TODO' };
|
||||
result = { optimizedOrders: prunedOrders.map(o => convertNativeOrderToFullyFillableOptimizedOrders(o)), quoteReport: blankQuoteReport };
|
||||
} else {
|
||||
if (operation === MarketOperation.Buy) {
|
||||
result = await this._marketOperationUtils.getMarketBuyOrdersAsync(
|
||||
@@ -163,6 +167,7 @@ export class SwapQuoteCalculator {
|
||||
assetFillAmount,
|
||||
gasPrice,
|
||||
opts.gasSchedule,
|
||||
result.quoteReport,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -175,6 +180,7 @@ function createSwapQuote(
|
||||
assetFillAmount: BigNumber,
|
||||
gasPrice: BigNumber,
|
||||
gasSchedule: { [source: string]: number },
|
||||
quoteReport: QuoteReport,
|
||||
): SwapQuote {
|
||||
const resultOrders = result.optimizedOrders;
|
||||
|
||||
@@ -202,6 +208,7 @@ function createSwapQuote(
|
||||
worstCaseQuoteInfo: fillResultsToQuoteInfo(worstCaseFillResult),
|
||||
sourceBreakdown: getSwapQuoteOrdersBreakdown(bestCaseFillResult.fillAmountBySource),
|
||||
orders: resultOrders,
|
||||
quoteReport,
|
||||
};
|
||||
|
||||
if (operation === MarketOperation.Buy) {
|
||||
|
Reference in New Issue
Block a user