diff --git a/lib/handlers/quote/handler.ts b/lib/handlers/quote/handler.ts index 9137c17..0d14b34 100644 --- a/lib/handlers/quote/handler.ts +++ b/lib/handlers/quote/handler.ts @@ -4,6 +4,7 @@ import Logger from 'bunyan'; import Joi from 'joi'; import { Metric, QuoteRequest, QuoteResponse } from '../../entities'; +import { ProtocolVersion } from '../../providers'; import { Quoter } from '../../quoters'; import { NoQuotesAvailable } from '../../util/errors'; import { timestampInMstoSeconds } from '../../util/time'; @@ -107,6 +108,11 @@ export async function getBestQuote( break; } + // don't use X if less than 2 fillers show up in soft quote + if (responses.length < 2 && quoteRequest.protocol == ProtocolVersion.V2) { + return null; + } + // return the response with the highest amountOut value return responses.reduce((bestQuote: QuoteResponse | null, quote: QuoteResponse) => { log.info({ diff --git a/test/handlers/quote/handler.test.ts b/test/handlers/quote/handler.test.ts index 3d0bac0..372d844 100644 --- a/test/handlers/quote/handler.test.ts +++ b/test/handlers/quote/handler.test.ts @@ -144,6 +144,20 @@ describe('Quote handler', () => { ).toMatchObject({ ...quoteResponse, quoteId: expect.any(String) }); }); + it('Returns no soft quote in V2 if less than two fillers show up', async () => { + const quoters = [new MockQuoter(logger, 1, 1)]; + const request = getRequest('1', 'EXACT_INPUT', ProtocolVersion.V2); + const response = await getQuoteHandler(quoters).handler(getEvent(request), {} as unknown as Context); + expect(response.statusCode).toEqual(404); + const quoteResponse: PostQuoteResponse = JSON.parse(response.body); + expect(quoteResponse).toMatchObject( + expect.objectContaining({ + errorCode: 'QUOTE_ERROR', + detail: 'No quotes available', + }) + ); + }); + it('Pick the greater of two quotes - EXACT_IN', async () => { const quoters = [new MockQuoter(logger, 1, 1), new MockQuoter(logger, 2, 1)]; const amountIn = ethers.utils.parseEther('1');