From 44abb89abf05c471f65b2e959e85b30c175dfa68 Mon Sep 17 00:00:00 2001 From: jsy1218 <91580504+jsy1218@users.noreply.github.com> Date: Fri, 14 Feb 2025 10:06:57 -0800 Subject: [PATCH 1/6] fix: mixed route eth <-> weth need to remove fake pool --- lib/handlers/quote/quote.ts | 9 ++++++++- lib/util/enableMixedRouteEthWeth.ts | 2 +- test/mocha/e2e/quote.test.ts | 16 ++++++++++++---- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/handlers/quote/quote.ts b/lib/handlers/quote/quote.ts index a39507efae..150496d732 100644 --- a/lib/handlers/quote/quote.ts +++ b/lib/handlers/quote/quote.ts @@ -12,7 +12,7 @@ import { SimulationStatus, sortsBefore, SwapOptions, - SwapRoute, + SwapRoute, V4_ETH_WETH_FAKE_POOL } from '@uniswap/smart-order-router' import { Pool as V3Pool } from '@uniswap/v3-sdk' import { Pool as V4Pool } from '@uniswap/v4-sdk' @@ -552,6 +552,13 @@ export class QuoteHandler extends APIGLambdaHandler< } if (nextPool instanceof V4Pool) { + // We want to filter the fake v4 pool here, + // because in SOR, we intentionally retain the fake pool, when it returns the valid routes + // https://github.com/Uniswap/smart-order-router/pull/819/files#diff-0eeab2733d13572382be381aa273dddcb38e797adf48c864105fbab2dcf011ffR489 + if (nextPool.tickSpacing === V4_ETH_WETH_FAKE_POOL[chainId].tickSpacing) { + continue + } + curRoute.push({ type: 'v4-pool', address: v4PoolProvider.getPoolId( diff --git a/lib/util/enableMixedRouteEthWeth.ts b/lib/util/enableMixedRouteEthWeth.ts index 221278f880..e838ba453e 100644 --- a/lib/util/enableMixedRouteEthWeth.ts +++ b/lib/util/enableMixedRouteEthWeth.ts @@ -6,6 +6,6 @@ export function enableMixedRouteEthWeth(requestSourceHeader?: string): boolean { // TODO: enable once web, mobile, extension releases the FE bug fix for mixed route (https://uniswapteam.slack.com/archives/C07AD3507SQ/p1739296535359709?thread_ts=1739224900.129809&cid=C07AD3507SQ) // TODO: for mobile, we need to ensure backward compatibility with the old version, using app version (https://uniswapteam.slack.com/archives/C07AD3507SQ/p1739309767819639?thread_ts=1739224900.129809&cid=C07AD3507SQ) default: - return false + return true } } diff --git a/test/mocha/e2e/quote.test.ts b/test/mocha/e2e/quote.test.ts index 4978a8a59f..df23cf65e7 100644 --- a/test/mocha/e2e/quote.test.ts +++ b/test/mocha/e2e/quote.test.ts @@ -12,7 +12,7 @@ import { NATIVE_CURRENCY, parseAmount, SWAP_ROUTER_02_ADDRESSES, - USDB_BLAST, + USDB_BLAST, USDC_BASE, USDC_BNB, USDC_MAINNET, USDC_NATIVE_ARBITRUM, @@ -26,7 +26,7 @@ import { V4_SEPOLIA_TEST_B, V4_SUPPORTED, WBTC_MAINNET, - WLD_WORLDCHAIN, + WLD_WORLDCHAIN } from '@uniswap/smart-order-router' import { UNIVERSAL_ROUTER_ADDRESS as UNIVERSAL_ROUTER_ADDRESS_BY_CHAIN, @@ -1061,7 +1061,7 @@ describe('quote', function () { tokenOutAddress: 'USDC', tokenOutChainId: 1, // Reducing amount as v4 ETH/USDC pool with very low liquidity might be selected, and liquidity changes often - amount: await getAmount(1, type, 'ETH', 'USDC', type == 'exactIn' ? '0.00001' : '0.1'), + amount: await getAmount(1, type, 'ETH', 'USDC', type == 'exactIn' ? '0.001' : '0.1'), type, recipient: alice.address, slippageTolerance: LARGE_SLIPPAGE, @@ -1533,7 +1533,7 @@ describe('quote', function () { }, }) const { - data: { quoteDecimals, quoteGasAdjustedDecimals, methodParameters, routeString }, + data: { quoteDecimals, quoteGasAdjustedDecimals, methodParameters, route, routeString }, status, } = response @@ -1543,6 +1543,14 @@ describe('quote', function () { /// since we only get the routeString back, we can check if there's V3 + V2 expect(routeString.includes('[V2 + V3 + V4]')) + expect(route.length).to.equal(1) + expect(route[0].length).to.equal(2) + expect(route[0][0].type).to.equal('v3-pool') + expect(route[0][0].tokenIn.address).to.equal('0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913') + expect(route[0][0].tokenOut.address).to.equal(WETH9[ChainId.BASE]) + expect(route[0][1].type).to.equal('v4-pool') + expect(route[0][1].tokenIn.address).to.equal('0x0000000000000000000000000000000000000000') + expect(route[0][1].tokenOut.address).to.equal('0x878784F7eBF6e57d17C81D82DDF53F117a5E2988') }) it('USDC -> mockA forceMixedRoutes true for mixed protocol on Base no request source', async () => { From 9a577f2b8076e88293dba019a6a8c5ea79e5ec20 Mon Sep 17 00:00:00 2001 From: jsy1218 <91580504+jsy1218@users.noreply.github.com> Date: Fri, 14 Feb 2025 10:26:43 -0800 Subject: [PATCH 2/6] revert enable false --- lib/util/enableMixedRouteEthWeth.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/util/enableMixedRouteEthWeth.ts b/lib/util/enableMixedRouteEthWeth.ts index e838ba453e..221278f880 100644 --- a/lib/util/enableMixedRouteEthWeth.ts +++ b/lib/util/enableMixedRouteEthWeth.ts @@ -6,6 +6,6 @@ export function enableMixedRouteEthWeth(requestSourceHeader?: string): boolean { // TODO: enable once web, mobile, extension releases the FE bug fix for mixed route (https://uniswapteam.slack.com/archives/C07AD3507SQ/p1739296535359709?thread_ts=1739224900.129809&cid=C07AD3507SQ) // TODO: for mobile, we need to ensure backward compatibility with the old version, using app version (https://uniswapteam.slack.com/archives/C07AD3507SQ/p1739309767819639?thread_ts=1739224900.129809&cid=C07AD3507SQ) default: - return true + return false } } From ae593b13e186f56365a508a8cae5b6f05dfdfa1b Mon Sep 17 00:00:00 2001 From: jsy1218 <91580504+jsy1218@users.noreply.github.com> Date: Fri, 14 Feb 2025 10:28:05 -0800 Subject: [PATCH 3/6] revert v4 amount --- test/mocha/e2e/quote.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/mocha/e2e/quote.test.ts b/test/mocha/e2e/quote.test.ts index df23cf65e7..063c287278 100644 --- a/test/mocha/e2e/quote.test.ts +++ b/test/mocha/e2e/quote.test.ts @@ -1061,7 +1061,7 @@ describe('quote', function () { tokenOutAddress: 'USDC', tokenOutChainId: 1, // Reducing amount as v4 ETH/USDC pool with very low liquidity might be selected, and liquidity changes often - amount: await getAmount(1, type, 'ETH', 'USDC', type == 'exactIn' ? '0.001' : '0.1'), + amount: await getAmount(1, type, 'ETH', 'USDC', type == 'exactIn' ? '0.0.00001' : '0.1'), type, recipient: alice.address, slippageTolerance: LARGE_SLIPPAGE, From e8e01915b9ded4638661b524695e6a323ba5529b Mon Sep 17 00:00:00 2001 From: jsy1218 <91580504+jsy1218@users.noreply.github.com> Date: Fri, 14 Feb 2025 13:27:36 -0800 Subject: [PATCH 4/6] fix prettier --- lib/handlers/quote/quote.ts | 3 ++- test/mocha/e2e/quote.test.ts | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/handlers/quote/quote.ts b/lib/handlers/quote/quote.ts index 150496d732..f3ba8a7367 100644 --- a/lib/handlers/quote/quote.ts +++ b/lib/handlers/quote/quote.ts @@ -12,7 +12,8 @@ import { SimulationStatus, sortsBefore, SwapOptions, - SwapRoute, V4_ETH_WETH_FAKE_POOL + SwapRoute, + V4_ETH_WETH_FAKE_POOL, } from '@uniswap/smart-order-router' import { Pool as V3Pool } from '@uniswap/v3-sdk' import { Pool as V4Pool } from '@uniswap/v4-sdk' diff --git a/test/mocha/e2e/quote.test.ts b/test/mocha/e2e/quote.test.ts index 063c287278..8b91436ccd 100644 --- a/test/mocha/e2e/quote.test.ts +++ b/test/mocha/e2e/quote.test.ts @@ -12,7 +12,8 @@ import { NATIVE_CURRENCY, parseAmount, SWAP_ROUTER_02_ADDRESSES, - USDB_BLAST, USDC_BASE, + USDB_BLAST, + USDC_BASE, USDC_BNB, USDC_MAINNET, USDC_NATIVE_ARBITRUM, @@ -26,7 +27,7 @@ import { V4_SEPOLIA_TEST_B, V4_SUPPORTED, WBTC_MAINNET, - WLD_WORLDCHAIN + WLD_WORLDCHAIN, } from '@uniswap/smart-order-router' import { UNIVERSAL_ROUTER_ADDRESS as UNIVERSAL_ROUTER_ADDRESS_BY_CHAIN, From 84ce964ff78afd4e5ae641aef3394d0451b9134c Mon Sep 17 00:00:00 2001 From: jsy1218 <91580504+jsy1218@users.noreply.github.com> Date: Fri, 14 Feb 2025 13:29:52 -0800 Subject: [PATCH 5/6] fix prettier --- test/mocha/e2e/quote.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/test/mocha/e2e/quote.test.ts b/test/mocha/e2e/quote.test.ts index 8b91436ccd..7bdc66ff3d 100644 --- a/test/mocha/e2e/quote.test.ts +++ b/test/mocha/e2e/quote.test.ts @@ -13,7 +13,6 @@ import { parseAmount, SWAP_ROUTER_02_ADDRESSES, USDB_BLAST, - USDC_BASE, USDC_BNB, USDC_MAINNET, USDC_NATIVE_ARBITRUM, From f3371668b4f195172b3e434f67317f678d20db25 Mon Sep 17 00:00:00 2001 From: jsy1218 <91580504+jsy1218@users.noreply.github.com> Date: Fri, 14 Feb 2025 13:31:33 -0800 Subject: [PATCH 6/6] fix 0.0.00001 --- test/mocha/e2e/quote.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/mocha/e2e/quote.test.ts b/test/mocha/e2e/quote.test.ts index 7bdc66ff3d..fbe3a50085 100644 --- a/test/mocha/e2e/quote.test.ts +++ b/test/mocha/e2e/quote.test.ts @@ -1061,7 +1061,7 @@ describe('quote', function () { tokenOutAddress: 'USDC', tokenOutChainId: 1, // Reducing amount as v4 ETH/USDC pool with very low liquidity might be selected, and liquidity changes often - amount: await getAmount(1, type, 'ETH', 'USDC', type == 'exactIn' ? '0.0.00001' : '0.1'), + amount: await getAmount(1, type, 'ETH', 'USDC', type == 'exactIn' ? '0.00001' : '0.1'), type, recipient: alice.address, slippageTolerance: LARGE_SLIPPAGE,