diff --git a/packages/asset-swapper/CHANGELOG.json b/packages/asset-swapper/CHANGELOG.json index 88326fead8..80b3461a44 100644 --- a/packages/asset-swapper/CHANGELOG.json +++ b/packages/asset-swapper/CHANGELOG.json @@ -77,6 +77,10 @@ { "note": "Re-worked `Kyber` quotes supporting multiple reserves", "pr": 2683 + }, + { + "note": "Enable Quote Report to be generated with an option `shouldGenerateQuoteReport`. Default is `false`", + "pr": 2687 } ] }, diff --git a/packages/asset-swapper/src/utils/market_operation_utils/constants.ts b/packages/asset-swapper/src/utils/market_operation_utils/constants.ts index aef4844709..9cbeefeb70 100644 --- a/packages/asset-swapper/src/utils/market_operation_utils/constants.ts +++ b/packages/asset-swapper/src/utils/market_operation_utils/constants.ts @@ -46,6 +46,7 @@ export const DEFAULT_GET_MARKET_ORDERS_OPTS: GetMarketOrdersOpts = { gasSchedule: {}, allowFallback: true, shouldBatchBridgeOrders: true, + shouldGenerateQuoteReport: false, }; /** diff --git a/packages/asset-swapper/src/utils/market_operation_utils/index.ts b/packages/asset-swapper/src/utils/market_operation_utils/index.ts index d6a26477b4..3c30f00861 100644 --- a/packages/asset-swapper/src/utils/market_operation_utils/index.ts +++ b/packages/asset-swapper/src/utils/market_operation_utils/index.ts @@ -342,6 +342,7 @@ export class MarketOperationUtils { allowFallback: _opts.allowFallback, shouldBatchBridgeOrders: _opts.shouldBatchBridgeOrders, quoteRequestor: _opts.rfqt ? _opts.rfqt.quoteRequestor : undefined, + shouldGenerateQuoteReport: _opts.shouldGenerateQuoteReport, }); } @@ -368,6 +369,7 @@ export class MarketOperationUtils { allowFallback: _opts.allowFallback, shouldBatchBridgeOrders: _opts.shouldBatchBridgeOrders, quoteRequestor: _opts.rfqt ? _opts.rfqt.quoteRequestor : undefined, + shouldGenerateQuoteReport: _opts.shouldGenerateQuoteReport, }); } @@ -455,6 +457,7 @@ export class MarketOperationUtils { feeSchedule: _opts.feeSchedule, allowFallback: _opts.allowFallback, shouldBatchBridgeOrders: _opts.shouldBatchBridgeOrders, + shouldGenerateQuoteReport: false, }, ); return optimizedOrders; @@ -478,6 +481,7 @@ export class MarketOperationUtils { allowFallback?: boolean; shouldBatchBridgeOrders?: boolean; quoteRequestor?: QuoteRequestor; + shouldGenerateQuoteReport?: boolean; }, ): Promise { const { @@ -534,15 +538,17 @@ export class MarketOperationUtils { ); if (bestTwoHopQuote && bestTwoHopRate.isGreaterThan(optimalPathRate)) { const twoHopOrders = createOrdersFromTwoHopSample(bestTwoHopQuote, orderOpts); - const twoHopQuoteReport = generateQuoteReport( - side, - _.flatten(dexQuotes), - twoHopQuotes, - nativeOrders, - orderFillableAmounts, - bestTwoHopQuote, - opts.quoteRequestor, - ); + const twoHopQuoteReport = opts.shouldGenerateQuoteReport + ? generateQuoteReport( + side, + _.flatten(dexQuotes), + twoHopQuotes, + nativeOrders, + orderFillableAmounts, + bestTwoHopQuote, + opts.quoteRequestor, + ) + : undefined; return { optimizedOrders: twoHopOrders, quoteReport: twoHopQuoteReport, isTwoHop: true }; } @@ -574,15 +580,17 @@ export class MarketOperationUtils { } } const optimizedOrders = createOrdersFromPath(optimalPath, orderOpts); - const quoteReport = generateQuoteReport( - side, - _.flatten(dexQuotes), - twoHopQuotes, - nativeOrders, - orderFillableAmounts, - _.flatten(optimizedOrders.map(order => order.fills)), - opts.quoteRequestor, - ); + const quoteReport = opts.shouldGenerateQuoteReport + ? generateQuoteReport( + side, + _.flatten(dexQuotes), + twoHopQuotes, + nativeOrders, + orderFillableAmounts, + _.flatten(optimizedOrders.map(order => order.fills)), + opts.quoteRequestor, + ) + : undefined; return { optimizedOrders, quoteReport, isTwoHop: false }; } diff --git a/packages/asset-swapper/src/utils/market_operation_utils/types.ts b/packages/asset-swapper/src/utils/market_operation_utils/types.ts index f59932d8b7..4269f87850 100644 --- a/packages/asset-swapper/src/utils/market_operation_utils/types.ts +++ b/packages/asset-swapper/src/utils/market_operation_utils/types.ts @@ -275,6 +275,10 @@ export interface GetMarketOrdersOpts { * order. Defaults to `true`. */ shouldBatchBridgeOrders: boolean; + /** + * Whether to generate a quote report + */ + shouldGenerateQuoteReport: boolean; } /** @@ -294,7 +298,7 @@ export interface SourceQuoteOperation export interface OptimizerResult { optimizedOrders: OptimizedMarketOrder[]; isTwoHop: boolean; - quoteReport: QuoteReport; + quoteReport?: QuoteReport; } export type MarketDepthSide = Array>>;