Skip to content

Commit

Permalink
skip X v2 soft quote if less than 2 fillers show up
Browse files Browse the repository at this point in the history
  • Loading branch information
ConjunctiveNormalForm committed Jul 8, 2024
1 parent 0404755 commit 5d8e0e0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/handlers/quote/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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({
Expand Down
14 changes: 14 additions & 0 deletions test/handlers/quote/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 5d8e0e0

Please sign in to comment.