WIP: add quoteReport response
This commit is contained in:
		@@ -155,6 +155,7 @@ export interface SwapQuoteBase {
 | 
			
		||||
    bestCaseQuoteInfo: SwapQuoteInfo;
 | 
			
		||||
    worstCaseQuoteInfo: SwapQuoteInfo;
 | 
			
		||||
    sourceBreakdown: SwapQuoteOrdersBreakdown;
 | 
			
		||||
    quoteReport: string;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 
 | 
			
		||||
@@ -22,6 +22,7 @@ import {
 | 
			
		||||
    ERC20BridgeSource,
 | 
			
		||||
    GetMarketOrdersOpts,
 | 
			
		||||
    OptimizedMarketOrder,
 | 
			
		||||
    OptimizedOrdersAndQuoteReport,
 | 
			
		||||
    OrderDomain,
 | 
			
		||||
} from './types';
 | 
			
		||||
 | 
			
		||||
@@ -71,7 +72,7 @@ export class MarketOperationUtils {
 | 
			
		||||
        nativeOrders: SignedOrder[],
 | 
			
		||||
        takerAmount: BigNumber,
 | 
			
		||||
        opts?: Partial<GetMarketOrdersOpts>,
 | 
			
		||||
    ): Promise<OptimizedMarketOrder[]> {
 | 
			
		||||
    ): Promise<OptimizedOrdersAndQuoteReport> {
 | 
			
		||||
        if (nativeOrders.length === 0) {
 | 
			
		||||
            throw new Error(AggregationError.EmptyOrders);
 | 
			
		||||
        }
 | 
			
		||||
@@ -153,7 +154,7 @@ export class MarketOperationUtils {
 | 
			
		||||
        nativeOrders: SignedOrder[],
 | 
			
		||||
        makerAmount: BigNumber,
 | 
			
		||||
        opts?: Partial<GetMarketOrdersOpts>,
 | 
			
		||||
    ): Promise<OptimizedMarketOrder[]> {
 | 
			
		||||
    ): Promise<OptimizedOrdersAndQuoteReport> {
 | 
			
		||||
        if (nativeOrders.length === 0) {
 | 
			
		||||
            throw new Error(AggregationError.EmptyOrders);
 | 
			
		||||
        }
 | 
			
		||||
@@ -238,6 +239,7 @@ export class MarketOperationUtils {
 | 
			
		||||
     * @param opts Options object.
 | 
			
		||||
     * @return orders.
 | 
			
		||||
     */
 | 
			
		||||
    // TODO: can we delete?
 | 
			
		||||
    public async getBatchMarketBuyOrdersAsync(
 | 
			
		||||
        batchNativeOrders: SignedOrder[][],
 | 
			
		||||
        makerAmounts: BigNumber[],
 | 
			
		||||
@@ -302,7 +304,7 @@ export class MarketOperationUtils {
 | 
			
		||||
                    feeSchedule: _opts.feeSchedule,
 | 
			
		||||
                    allowFallback: _opts.allowFallback,
 | 
			
		||||
                    shouldBatchBridgeOrders: _opts.shouldBatchBridgeOrders,
 | 
			
		||||
                });
 | 
			
		||||
                }).optimizedOrders;
 | 
			
		||||
            } catch (e) {
 | 
			
		||||
                // It's possible for one of the pairs to have no path
 | 
			
		||||
                // rather than throw NO_OPTIMAL_PATH we return undefined
 | 
			
		||||
@@ -330,7 +332,7 @@ export class MarketOperationUtils {
 | 
			
		||||
        shouldBatchBridgeOrders?: boolean;
 | 
			
		||||
        liquidityProviderAddress?: string;
 | 
			
		||||
        multiBridgeAddress?: string;
 | 
			
		||||
    }): OptimizedMarketOrder[] {
 | 
			
		||||
    }): OptimizedOrdersAndQuoteReport {
 | 
			
		||||
        const { inputToken, outputToken, side, inputAmount } = opts;
 | 
			
		||||
        const maxFallbackSlippage = opts.maxFallbackSlippage || 0;
 | 
			
		||||
        // Convert native orders and dex quotes into fill paths.
 | 
			
		||||
@@ -383,7 +385,7 @@ export class MarketOperationUtils {
 | 
			
		||||
                optimalPath = [...nativeSubPath.filter(f => f !== lastNativeFillIfExists), ...nonNativeOptimalPath];
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return createOrdersFromPath(optimalPath, {
 | 
			
		||||
        const optimizedOrders = createOrdersFromPath(optimalPath, {
 | 
			
		||||
            side,
 | 
			
		||||
            inputToken,
 | 
			
		||||
            outputToken,
 | 
			
		||||
@@ -394,6 +396,7 @@ export class MarketOperationUtils {
 | 
			
		||||
            multiBridgeAddress: opts.multiBridgeAddress,
 | 
			
		||||
            shouldBatchBridgeOrders: !!opts.shouldBatchBridgeOrders,
 | 
			
		||||
        });
 | 
			
		||||
        return { optimizedOrders, quoteReport: 'TODO' };
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private _optionalSources(): ERC20BridgeSource[] {
 | 
			
		||||
 
 | 
			
		||||
@@ -218,3 +218,8 @@ export interface FakeBuyOpts {
 | 
			
		||||
    targetSlippageBps: BigNumber;
 | 
			
		||||
    maxIterations: BigNumber;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface OptimizedOrdersAndQuoteReport {
 | 
			
		||||
    optimizedOrders: OptimizedMarketOrder[];
 | 
			
		||||
    quoteReport: string;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -17,7 +17,7 @@ import {
 | 
			
		||||
 | 
			
		||||
import { MarketOperationUtils } from './market_operation_utils';
 | 
			
		||||
import { convertNativeOrderToFullyFillableOptimizedOrders } from './market_operation_utils/orders';
 | 
			
		||||
import { GetMarketOrdersOpts, OptimizedMarketOrder } from './market_operation_utils/types';
 | 
			
		||||
import { GetMarketOrdersOpts, OptimizedMarketOrder, OptimizedOrdersAndQuoteReport } from './market_operation_utils/types';
 | 
			
		||||
import { isSupportedAssetDataInOrders } from './utils';
 | 
			
		||||
 | 
			
		||||
import { QuoteFillResult, simulateBestCaseFill, simulateWorstCaseFill } from './quote_simulation';
 | 
			
		||||
@@ -94,7 +94,7 @@ export class SwapQuoteCalculator {
 | 
			
		||||
                    return createSwapQuote(
 | 
			
		||||
                        makerAssetData,
 | 
			
		||||
                        takerAssetData,
 | 
			
		||||
                        orders,
 | 
			
		||||
                        { optimizedOrders: orders, quoteReport: 'TODO' },
 | 
			
		||||
                        operation,
 | 
			
		||||
                        assetFillAmounts[i],
 | 
			
		||||
                        gasPrice,
 | 
			
		||||
@@ -120,7 +120,7 @@ export class SwapQuoteCalculator {
 | 
			
		||||
        }
 | 
			
		||||
        // since prunedOrders do not have fillState, we will add a buffer of fillable orders to consider that some native are orders are partially filled
 | 
			
		||||
 | 
			
		||||
        let resultOrders: OptimizedMarketOrder[] = [];
 | 
			
		||||
        let result: OptimizedOrdersAndQuoteReport | undefined;
 | 
			
		||||
 | 
			
		||||
        {
 | 
			
		||||
            // Scale fees by gas price.
 | 
			
		||||
@@ -135,16 +135,16 @@ export class SwapQuoteCalculator {
 | 
			
		||||
 | 
			
		||||
            if (firstOrderMakerAssetData.assetProxyId === AssetProxyId.ERC721) {
 | 
			
		||||
                // HACK: to conform ERC721 orders to the output of market operation utils, assumes complete fillable
 | 
			
		||||
                resultOrders = prunedOrders.map(o => convertNativeOrderToFullyFillableOptimizedOrders(o));
 | 
			
		||||
                result = { optimizedOrders: prunedOrders.map(o => convertNativeOrderToFullyFillableOptimizedOrders(o)), quoteReport: 'TODO' };
 | 
			
		||||
            } else {
 | 
			
		||||
                if (operation === MarketOperation.Buy) {
 | 
			
		||||
                    resultOrders = await this._marketOperationUtils.getMarketBuyOrdersAsync(
 | 
			
		||||
                    result = await this._marketOperationUtils.getMarketBuyOrdersAsync(
 | 
			
		||||
                        prunedOrders,
 | 
			
		||||
                        assetFillAmount,
 | 
			
		||||
                        _opts,
 | 
			
		||||
                    );
 | 
			
		||||
                } else {
 | 
			
		||||
                    resultOrders = await this._marketOperationUtils.getMarketSellOrdersAsync(
 | 
			
		||||
                    result = await this._marketOperationUtils.getMarketSellOrdersAsync(
 | 
			
		||||
                        prunedOrders,
 | 
			
		||||
                        assetFillAmount,
 | 
			
		||||
                        _opts,
 | 
			
		||||
@@ -158,7 +158,7 @@ export class SwapQuoteCalculator {
 | 
			
		||||
        return createSwapQuote(
 | 
			
		||||
            makerAssetData,
 | 
			
		||||
            takerAssetData,
 | 
			
		||||
            resultOrders,
 | 
			
		||||
            result,
 | 
			
		||||
            operation,
 | 
			
		||||
            assetFillAmount,
 | 
			
		||||
            gasPrice,
 | 
			
		||||
@@ -170,12 +170,14 @@ export class SwapQuoteCalculator {
 | 
			
		||||
function createSwapQuote(
 | 
			
		||||
    makerAssetData: string,
 | 
			
		||||
    takerAssetData: string,
 | 
			
		||||
    resultOrders: OptimizedMarketOrder[],
 | 
			
		||||
    result: OptimizedOrdersAndQuoteReport,
 | 
			
		||||
    operation: MarketOperation,
 | 
			
		||||
    assetFillAmount: BigNumber,
 | 
			
		||||
    gasPrice: BigNumber,
 | 
			
		||||
    gasSchedule: { [source: string]: number },
 | 
			
		||||
): SwapQuote {
 | 
			
		||||
    const resultOrders = result.optimizedOrders;
 | 
			
		||||
 | 
			
		||||
    const bestCaseFillResult = simulateBestCaseFill({
 | 
			
		||||
        gasPrice,
 | 
			
		||||
        orders: resultOrders,
 | 
			
		||||
@@ -192,7 +194,7 @@ function createSwapQuote(
 | 
			
		||||
        opts: { gasSchedule },
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    const quoteBase: SwapQuoteBase = {
 | 
			
		||||
    const quoteBase = {
 | 
			
		||||
        takerAssetData,
 | 
			
		||||
        makerAssetData,
 | 
			
		||||
        gasPrice,
 | 
			
		||||
@@ -207,12 +209,14 @@ function createSwapQuote(
 | 
			
		||||
            ...quoteBase,
 | 
			
		||||
            type: MarketOperation.Buy,
 | 
			
		||||
            makerAssetFillAmount: assetFillAmount,
 | 
			
		||||
            quoteReport: result.quoteReport,
 | 
			
		||||
        };
 | 
			
		||||
    } else {
 | 
			
		||||
        return {
 | 
			
		||||
            ...quoteBase,
 | 
			
		||||
            type: MarketOperation.Sell,
 | 
			
		||||
            takerAssetFillAmount: assetFillAmount,
 | 
			
		||||
            quoteReport: result.quoteReport,
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user