From aee758eca26e52343f59b83d873be67b4a5b6c25 Mon Sep 17 00:00:00 2001 From: "F. Eugene Aumson" Date: Tue, 14 Apr 2020 11:59:57 -0400 Subject: [PATCH] Fix bug: Stop ignoring default SwapQuoteRequestOps SwapQuoter._getSwapQuoteAsync() was merging defaults into the options sent into SwapQuoteCalculator.calculateMarket{Buy,Sell}SwapQuoteAsync(), but it was using the unmerged options function parameter for the RFQ-T options and also for the gas price option. --- packages/asset-swapper/src/swap_quoter.ts | 24 +++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/asset-swapper/src/swap_quoter.ts b/packages/asset-swapper/src/swap_quoter.ts index c09c9c81bd..d4ded8d956 100644 --- a/packages/asset-swapper/src/swap_quoter.ts +++ b/packages/asset-swapper/src/swap_quoter.ts @@ -517,12 +517,12 @@ export class SwapQuoter { marketOperation: MarketOperation, options: Partial, ): Promise { - const calculateSwapQuoteOpts = _.merge({}, constants.DEFAULT_SWAP_QUOTE_REQUEST_OPTS, options); + const opts = _.merge({}, constants.DEFAULT_SWAP_QUOTE_REQUEST_OPTS, options); assert.isString('makerAssetData', makerAssetData); assert.isString('takerAssetData', takerAssetData); let gasPrice: BigNumber; - if (!!options.gasPrice) { - gasPrice = options.gasPrice; + if (!!opts.gasPrice) { + gasPrice = opts.gasPrice; assert.isBigNumber('gasPrice', gasPrice); } else { gasPrice = await this._protocolFeeUtils.getGasPriceEstimationOrThrowAsync(); @@ -531,12 +531,12 @@ export class SwapQuoter { const orderBatchPromises: Array> = []; orderBatchPromises.push(this._getSignedOrdersAsync(makerAssetData, takerAssetData)); // order book if ( - options.rfqt && - options.rfqt.intentOnFilling && - options.apiKey && - this._rfqtTakerApiKeyWhitelist.includes(options.apiKey) + opts.rfqt && + opts.rfqt.intentOnFilling && + opts.apiKey && + this._rfqtTakerApiKeyWhitelist.includes(opts.apiKey) ) { - if (!options.rfqt.takerAddress || options.rfqt.takerAddress === constants.NULL_ADDRESS) { + if (!opts.rfqt.takerAddress || opts.rfqt.takerAddress === constants.NULL_ADDRESS) { throw new Error('RFQ-T requests must specify a taker address'); } orderBatchPromises.push( @@ -545,8 +545,8 @@ export class SwapQuoter { takerAssetData, assetFillAmount, marketOperation, - options.apiKey, - options.rfqt.takerAddress, + opts.apiKey, + opts.rfqt.takerAddress, ), ); } @@ -571,14 +571,14 @@ export class SwapQuoter { orders, assetFillAmount, gasPrice, - calculateSwapQuoteOpts, + opts, ); } else { swapQuote = await this._swapQuoteCalculator.calculateMarketSellSwapQuoteAsync( orders, assetFillAmount, gasPrice, - calculateSwapQuoteOpts, + opts, ); }