Skip to content

Commit

Permalink
Merge pull request #127 from rabbitholegg/mmackz-uniswap-fix
Browse files Browse the repository at this point in the history
fix(uniswap): fix casing issue with tokens on V3 swaps
  • Loading branch information
Quazia authored Dec 14, 2023
2 parents 1cea5b6 + afc1d1f commit e76a912
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/neat-teachers-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rabbitholegg/questdk-plugin-uniswap": patch
---

fix casing issue with token on V3 swaps
19 changes: 19 additions & 0 deletions packages/uniswap/src/Uniswap.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { GreaterThanOrEqual, apply } from '@rabbitholegg/questdk/filter'
import { describe, expect, test } from 'vitest'
import { getSupportedTokenAddresses, swap } from './Uniswap.js'
import { getAddress, type Address } from 'viem'
import {
CHAIN_ID_ARRAY,
EXECUTE_ABI_FRAGMENTS,
Expand Down Expand Up @@ -83,6 +84,24 @@ describe('Given the uniswap plugin', () => {
expect(apply(transaction, filter)).to.be.true
})
})

test('when tokenIn is checksummed', async () => {
const { transaction, params } = passingTestCases[1]
const filter = await swap({
...params,
tokenIn: getAddress(params.tokenIn as Address),
})
expect(apply(transaction, filter)).to.be.true
})

test('when tokenOut is checksummed', async () => {
const { transaction, params } = passingTestCases[0]
const filter = await swap({
...params,
tokenOut: getAddress(params.tokenOut as Address),
})
expect(apply(transaction, filter)).to.be.true
})
})

describe('should not pass filter with invalid transactions', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/uniswap/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ export const buildV3PathQuery = (tokenIn?: string, tokenOut?: string) => {
const conditions: FilterOperator[] = []

if (tokenIn) {
conditions.push({ $regex: `^${tokenIn}` })
conditions.push({ $regex: `^${tokenIn.toLowerCase()}` })
}

if (tokenOut) {
// Chop the 0x prefix before comparing
conditions.push({ $regex: `${tokenOut.slice(2)}$` })
conditions.push({ $regex: `${tokenOut.toLowerCase().slice(2)}$` })
}

return {
Expand Down

0 comments on commit e76a912

Please sign in to comment.