Skip to content

Commit

Permalink
ignore casing when validating token addr
Browse files Browse the repository at this point in the history
  • Loading branch information
ConjunctiveNormalForm committed Jan 31, 2024
1 parent 74eb597 commit 68cd1ac
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/entities/QuoteResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { TradeType } from '@uniswap/sdk-core';
import { BigNumber } from 'ethers';
import { v4 as uuidv4 } from 'uuid';

import { QuoteRequestData } from '.';
import { PostQuoteResponse, RfqResponse, RfqResponseJoi } from '../handlers/quote/schema';
import { currentTimestampInMs, timestampInMstoSeconds } from '../util/time';
import { QuoteRequestData } from '.';

export interface QuoteResponseData
extends Omit<QuoteRequestData, 'tokenInChainId' | 'tokenOutChainId' | 'amount' | 'type' | 'numOutputs'> {
Expand Down Expand Up @@ -61,7 +61,10 @@ export class QuoteResponse implements QuoteResponseData {
};
}

if (request.tokenIn !== data.tokenIn || request.tokenOut !== data.tokenOut) {
if (
request.tokenIn.toLowerCase() !== data.tokenIn.toLowerCase() ||
request.tokenOut.toLowerCase() !== data.tokenOut.toLowerCase()
) {
validationError = {
message: `RFQ response token mismatch: request tokenIn: ${request.tokenIn} tokenOut: ${request.tokenOut} response tokenIn: ${data.tokenIn} tokenOut: ${data.tokenOut}`,
value: data,
Expand Down
17 changes: 17 additions & 0 deletions test/entities/QuoteResponse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,23 @@ describe('QuoteRequest', () => {
expect(response.validationError).toBe(undefined);
});

it('fromRFQ with valid response - allow checksumed', async () => {
const response = QuoteResponse.fromRFQ(
quoteRequest,
{
chainId: CHAIN_ID,
requestId: REQUEST_ID,
tokenIn: TOKEN_IN.toLowerCase(),
amountIn: parseEther('1').toString(),
tokenOut: TOKEN_OUT.toLowerCase(),
amountOut: parseEther('1').toString(),
quoteId: QUOTE_ID,
},
TradeType.EXACT_INPUT
);
expect(response.validationError).toBe(undefined);
});

it('fromRFQ with invalid response - wrong type amountIn', async () => {
const invalidResponse = {
chainId: CHAIN_ID,
Expand Down

0 comments on commit 68cd1ac

Please sign in to comment.