Skip to content

Commit

Permalink
Merge pull request #261 from Uniswap/fix-token-validation
Browse files Browse the repository at this point in the history
fix: ignore casing when validating token addr
  • Loading branch information
rileydcampbell authored Jan 31, 2024
2 parents 74eb597 + 4ead407 commit 38b7116
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 @@ -54,14 +54,17 @@ export class QuoteResponse implements QuoteResponseData {
stripUnknown: true,
});

if (responseValidation.error) {
if (responseValidation?.error) {
validationError = {
message: responseValidation.error?.message,
value: data,
};
}

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 38b7116

Please sign in to comment.