Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: skip X v2 soft quote if less than 2 fillers show up #349

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading