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.
This commit is contained in:
F. Eugene Aumson 2020-04-14 11:59:57 -04:00
parent 47ef7fffce
commit aee758eca2
No known key found for this signature in database
GPG Key ID: 23E6737B1374A24A

View File

@ -517,12 +517,12 @@ export class SwapQuoter {
marketOperation: MarketOperation, marketOperation: MarketOperation,
options: Partial<SwapQuoteRequestOpts>, options: Partial<SwapQuoteRequestOpts>,
): Promise<SwapQuote> { ): Promise<SwapQuote> {
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('makerAssetData', makerAssetData);
assert.isString('takerAssetData', takerAssetData); assert.isString('takerAssetData', takerAssetData);
let gasPrice: BigNumber; let gasPrice: BigNumber;
if (!!options.gasPrice) { if (!!opts.gasPrice) {
gasPrice = options.gasPrice; gasPrice = opts.gasPrice;
assert.isBigNumber('gasPrice', gasPrice); assert.isBigNumber('gasPrice', gasPrice);
} else { } else {
gasPrice = await this._protocolFeeUtils.getGasPriceEstimationOrThrowAsync(); gasPrice = await this._protocolFeeUtils.getGasPriceEstimationOrThrowAsync();
@ -531,12 +531,12 @@ export class SwapQuoter {
const orderBatchPromises: Array<Promise<SignedOrder[]>> = []; const orderBatchPromises: Array<Promise<SignedOrder[]>> = [];
orderBatchPromises.push(this._getSignedOrdersAsync(makerAssetData, takerAssetData)); // order book orderBatchPromises.push(this._getSignedOrdersAsync(makerAssetData, takerAssetData)); // order book
if ( if (
options.rfqt && opts.rfqt &&
options.rfqt.intentOnFilling && opts.rfqt.intentOnFilling &&
options.apiKey && opts.apiKey &&
this._rfqtTakerApiKeyWhitelist.includes(options.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'); throw new Error('RFQ-T requests must specify a taker address');
} }
orderBatchPromises.push( orderBatchPromises.push(
@ -545,8 +545,8 @@ export class SwapQuoter {
takerAssetData, takerAssetData,
assetFillAmount, assetFillAmount,
marketOperation, marketOperation,
options.apiKey, opts.apiKey,
options.rfqt.takerAddress, opts.rfqt.takerAddress,
), ),
); );
} }
@ -571,14 +571,14 @@ export class SwapQuoter {
orders, orders,
assetFillAmount, assetFillAmount,
gasPrice, gasPrice,
calculateSwapQuoteOpts, opts,
); );
} else { } else {
swapQuote = await this._swapQuoteCalculator.calculateMarketSellSwapQuoteAsync( swapQuote = await this._swapQuoteCalculator.calculateMarketSellSwapQuoteAsync(
orders, orders,
assetFillAmount, assetFillAmount,
gasPrice, gasPrice,
calculateSwapQuoteOpts, opts,
); );
} }