diff --git a/packages/asset-swapper/src/swap_quoter.ts b/packages/asset-swapper/src/swap_quoter.ts index 2690942f81..5817743e40 100644 --- a/packages/asset-swapper/src/swap_quoter.ts +++ b/packages/asset-swapper/src/swap_quoter.ts @@ -559,7 +559,11 @@ export class SwapQuoter { // If RFQT is enabled and `nativeExclusivelyRFQT` is set, then `ERC20BridgeSource.Native` should // never be excluded. - if ((opts.rfqt && opts.rfqt.nativeExclusivelyRFQT === true) && opts.excludedSources.includes(ERC20BridgeSource.Native)) { + if ( + opts.rfqt && + opts.rfqt.nativeExclusivelyRFQT === true && + opts.excludedSources.includes(ERC20BridgeSource.Native) + ) { throw new Error('Native liquidity cannot be excluded if "rfqt.nativeExclusivelyRFQT" is set'); } @@ -567,15 +571,16 @@ export class SwapQuoter { const orderBatchPromises: Array> = []; orderBatchPromises.push( // Don't fetch Open Orderbook orders from the DB if Native has been excluded, or if `nativeExclusivelyRFQT` has been set. - opts.excludedSources.includes(ERC20BridgeSource.Native) || (opts.rfqt && opts.rfqt.nativeExclusivelyRFQT === true) + opts.excludedSources.includes(ERC20BridgeSource.Native) || + (opts.rfqt && opts.rfqt.nativeExclusivelyRFQT === true) ? Promise.resolve([]) : this._getSignedOrdersAsync(makerAssetData, takerAssetData), ); if ( - opts.rfqt && // This is an RFQT-enabled API request - opts.rfqt.intentOnFilling && // The requestor is asking for a firm quote - !opts.excludedSources.includes(ERC20BridgeSource.Native) && // Native liquidity is not excluded - this._rfqtTakerApiKeyWhitelist.includes(opts.rfqt.apiKey) // A valid API key was provided + opts.rfqt && // This is an RFQT-enabled API request + opts.rfqt.intentOnFilling && // The requestor is asking for a firm quote + !opts.excludedSources.includes(ERC20BridgeSource.Native) && // Native liquidity is not excluded + this._rfqtTakerApiKeyWhitelist.includes(opts.rfqt.apiKey) // A valid API key was provided ) { if (!opts.rfqt.takerAddress || opts.rfqt.takerAddress === constants.NULL_ADDRESS) { throw new Error('RFQ-T requests must specify a taker address'); 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 f7f1d12eff..597dcb0fc1 100644 --- a/packages/asset-swapper/src/utils/market_operation_utils/index.ts +++ b/packages/asset-swapper/src/utils/market_operation_utils/index.ts @@ -26,6 +26,14 @@ import { OrderDomain, } from './types'; +/** + * Returns a indicative quotes or an empty array if RFQT is not enabled or requested + * @param makerAssetData the maker asset data + * @param takerAssetData the taker asset data + * @param marketOperation Buy or Sell + * @param assetFillAmount the amount to fill, in base units + * @param opts market request options + */ export async function getRfqtIndicativeQuotesAsync( makerAssetData: string, takerAssetData: string, diff --git a/packages/asset-swapper/test/market_operation_utils_test.ts b/packages/asset-swapper/test/market_operation_utils_test.ts index 6b52497666..7702aa7c9f 100644 --- a/packages/asset-swapper/test/market_operation_utils_test.ts +++ b/packages/asset-swapper/test/market_operation_utils_test.ts @@ -351,41 +351,45 @@ describe('MarketOperationUtils tests', () => { MarketOperation.Sell, new BigNumber('100e18'), { - rfqt: {quoteRequestor: requestor.object, ...partialRfqt}, + rfqt: { quoteRequestor: requestor.object, ...partialRfqt }, excludedSources: [ERC20BridgeSource.Native], }, ); expect(result.length).to.eql(0); requestor.verify( - r => r.requestRfqtIndicativeQuotesAsync( - TypeMoq.It.isAny(), - TypeMoq.It.isAny(), - TypeMoq.It.isAny(), - TypeMoq.It.isAny(), - TypeMoq.It.isAny(), - ), + r => + r.requestRfqtIndicativeQuotesAsync( + TypeMoq.It.isAny(), + TypeMoq.It.isAny(), + TypeMoq.It.isAny(), + TypeMoq.It.isAny(), + TypeMoq.It.isAny(), + ), TypeMoq.Times.never(), ); }); it('calls RFQT if Native source is not excluded', async () => { const requestor = TypeMoq.Mock.ofType(QuoteRequestor, TypeMoq.MockBehavior.Loose); - requestor.setup( - r => r.requestRfqtIndicativeQuotesAsync( - TypeMoq.It.isAny(), - TypeMoq.It.isAny(), - TypeMoq.It.isAny(), - TypeMoq.It.isAny(), - TypeMoq.It.isAny(), - ), - ).returns(() => Promise.resolve([])).verifiable(TypeMoq.Times.once()); + requestor + .setup(r => + r.requestRfqtIndicativeQuotesAsync( + TypeMoq.It.isAny(), + TypeMoq.It.isAny(), + TypeMoq.It.isAny(), + TypeMoq.It.isAny(), + TypeMoq.It.isAny(), + ), + ) + .returns(() => Promise.resolve([])) + .verifiable(TypeMoq.Times.once()); await getRfqtIndicativeQuotesAsync( MAKER_ASSET_DATA, TAKER_ASSET_DATA, MarketOperation.Sell, new BigNumber('100e18'), { - rfqt: {quoteRequestor: requestor.object, ...partialRfqt}, + rfqt: { quoteRequestor: requestor.object, ...partialRfqt }, excludedSources: [], }, );