From 43d06ee453b50753935547a806e153ce3646bea0 Mon Sep 17 00:00:00 2001 From: "Siyu Jiang (See-You John)" <91580504+jsy1218@users.noreply.github.com> Date: Fri, 7 Feb 2025 09:13:13 -0800 Subject: [PATCH] chore: bump sor to 4.17.10 - fix: add base mixed quoter v2 (#1002) works on my local now: - mockA -> ETH -> WETH -> USDC https://app.warp.dev/block/eRFwEjYZpAj60IkrTDmix5 - USDC -> WETH -> ETH -> mockA https://app.warp.dev/block/L2CgtuJZV8aeUdJa1kTioS --- lib/handlers/injector-sor.ts | 2 +- lib/handlers/quote/quote.ts | 8 ++++ package-lock.json | 78 ++++++++++++++++++------------------ package.json | 6 +-- test/mocha/e2e/quote.test.ts | 48 ++++++++++++++++++++++ 5 files changed, 99 insertions(+), 43 deletions(-) diff --git a/lib/handlers/injector-sor.ts b/lib/handlers/injector-sor.ts index fe0b35d406..322950198b 100644 --- a/lib/handlers/injector-sor.ts +++ b/lib/handlers/injector-sor.ts @@ -532,7 +532,7 @@ export abstract class InjectorSOR extends Injector< ChainId.MAINNET, ] - const mixedSupported = [ChainId.MAINNET, ChainId.SEPOLIA, ChainId.GOERLI] + const mixedSupported = [ChainId.MAINNET, ChainId.SEPOLIA, ChainId.GOERLI, ChainId.BASE] const cachedRoutesCacheInvalidationFixRolloutPercentage = NEW_CACHED_ROUTES_ROLLOUT_PERCENT[chainId] diff --git a/lib/handlers/quote/quote.ts b/lib/handlers/quote/quote.ts index 26952bbe32..4b7c439bc9 100644 --- a/lib/handlers/quote/quote.ts +++ b/lib/handlers/quote/quote.ts @@ -13,6 +13,7 @@ import { sortsBefore, SwapOptions, 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' @@ -543,6 +544,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/package-lock.json b/package-lock.json index f4411fb086..603e816072 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,11 +27,11 @@ "@types/stats-lite": "^2.2.0", "@uniswap/default-token-list": "^11.13.0", "@uniswap/permit2-sdk": "^1.3.0", - "@uniswap/router-sdk": "^1.21.0", + "@uniswap/router-sdk": "^1.22.1", "@uniswap/sdk-core": "^7.5.0", - "@uniswap/smart-order-router": "4.17.6", + "@uniswap/smart-order-router": "4.17.10", "@uniswap/token-lists": "^1.0.0-beta.33", - "@uniswap/universal-router-sdk": "^4.14.0", + "@uniswap/universal-router-sdk": "^4.17.0", "@uniswap/v2-sdk": "^4.13.0", "@uniswap/v3-periphery": "^1.4.4", "@uniswap/v3-sdk": "^3.24.0", @@ -4476,16 +4476,16 @@ } }, "node_modules/@uniswap/router-sdk": { - "version": "1.21.0", - "resolved": "https://registry.npmjs.org/@uniswap/router-sdk/-/router-sdk-1.21.0.tgz", - "integrity": "sha512-L7NixcJvcjkkX4WOa9mSyep1M2LMRp6gI0DKZGNuYsY+mjSJfxdlZyAKPXWHmVZGfVSE25IcbKZhA/i0KgVhKg==", + "version": "1.22.1", + "resolved": "https://registry.npmjs.org/@uniswap/router-sdk/-/router-sdk-1.22.1.tgz", + "integrity": "sha512-j7LzPaxdlA/6Rf3V9iHzi7GnLW6huJSpLTq+6KZRcD1jbmV7RRKcSq0tgqGv/fbJprM8LqgW/NetfPIAqxzdLw==", "dependencies": { "@ethersproject/abi": "^5.5.0", "@uniswap/sdk-core": "^7.5.0", "@uniswap/swap-router-contracts": "^1.3.0", "@uniswap/v2-sdk": "^4.13.0", "@uniswap/v3-sdk": "^3.24.0", - "@uniswap/v4-sdk": "^1.18.0" + "@uniswap/v4-sdk": "^1.18.1" } }, "node_modules/@uniswap/sdk-core": { @@ -4508,23 +4508,23 @@ } }, "node_modules/@uniswap/smart-order-router": { - "version": "4.17.6", - "resolved": "https://registry.npmjs.org/@uniswap/smart-order-router/-/smart-order-router-4.17.6.tgz", - "integrity": "sha512-GLvj2Qv8tEF99LghrAFs7r5DOjAM0CNYEMAanErIIBptyoIa8QjiN5n83Jqo1VWNiYnQO7tekxvYuHIwvts1iw==", + "version": "4.17.10", + "resolved": "https://registry.npmjs.org/@uniswap/smart-order-router/-/smart-order-router-4.17.10.tgz", + "integrity": "sha512-5X6r6lFGzjFFWuCBIBHTOv+qv9XnuWy4BEKuh/LSbPFj3OZkJ//6WbbqCjXyN30pF08UiqUcjClRGCA2RUtEiA==", "dependencies": { "@eth-optimism/sdk": "^3.2.2", "@types/brotli": "^1.3.4", "@uniswap/default-token-list": "^11.13.0", "@uniswap/permit2-sdk": "^1.3.0", - "@uniswap/router-sdk": "^1.21.0", + "@uniswap/router-sdk": "^1.22.1", "@uniswap/sdk-core": "^7.5.0", "@uniswap/swap-router-contracts": "^1.3.1", "@uniswap/token-lists": "^1.0.0-beta.31", "@uniswap/universal-router": "^1.6.0", - "@uniswap/universal-router-sdk": "^4.14.0", + "@uniswap/universal-router-sdk": "^4.17.0", "@uniswap/v2-sdk": "^4.13.0", "@uniswap/v3-sdk": "^3.24.0", - "@uniswap/v4-sdk": "^1.18.0", + "@uniswap/v4-sdk": "^1.18.1", "async-retry": "^1.3.1", "await-timeout": "^1.1.1", "axios": "^0.21.1", @@ -4605,20 +4605,20 @@ } }, "node_modules/@uniswap/universal-router-sdk": { - "version": "4.14.0", - "resolved": "https://registry.npmjs.org/@uniswap/universal-router-sdk/-/universal-router-sdk-4.14.0.tgz", - "integrity": "sha512-lM8o5olNxJSgaAXUotltSuobfjiDQhkS46XkRbJEDrFjmUDCqggUgegZjU4TFDC87d5LBF47TWYF9dAVQENjxg==", + "version": "4.17.0", + "resolved": "https://registry.npmjs.org/@uniswap/universal-router-sdk/-/universal-router-sdk-4.17.0.tgz", + "integrity": "sha512-LjdiBq1ab1Z2l8DQ7OuOmpJ+BbhlTU8xxIrTvRppVf4RtHCHaNNrwwXMbZF3bBDWD4h0WrMDJqwZ5LSfm2plbg==", "dependencies": { "@openzeppelin/contracts": "4.7.0", "@uniswap/permit2-sdk": "^1.3.0", - "@uniswap/router-sdk": "^1.21.0", + "@uniswap/router-sdk": "^1.22.1", "@uniswap/sdk-core": "^7.5.0", "@uniswap/universal-router": "2.0.0-beta.2", "@uniswap/v2-core": "^1.0.1", "@uniswap/v2-sdk": "^4.13.0", "@uniswap/v3-core": "1.0.0", "@uniswap/v3-sdk": "^3.24.0", - "@uniswap/v4-sdk": "^1.18.0", + "@uniswap/v4-sdk": "^1.19.2", "bignumber.js": "^9.0.2", "ethers": "^5.7.0" }, @@ -4733,9 +4733,9 @@ "integrity": "sha512-tAG9LWg8+M2CMu7hIsqHPaTyG4uDzjr6mhvH96LvOpLZZj6tgzTluBt+LsCf1/QaYrlis6pITvpIaIhE+iZB+Q==" }, "node_modules/@uniswap/v4-sdk": { - "version": "1.18.0", - "resolved": "https://registry.npmjs.org/@uniswap/v4-sdk/-/v4-sdk-1.18.0.tgz", - "integrity": "sha512-ZcVSwgozrggfotH6D5g63W1T84bndsU1VZ+x67KM0Z8csBNzyV4GkKsMQPE4jnPEf3O0JSnGyHL2qPlpTHvGOQ==", + "version": "1.19.2", + "resolved": "https://registry.npmjs.org/@uniswap/v4-sdk/-/v4-sdk-1.19.2.tgz", + "integrity": "sha512-WwebI+2rlCO44UIoqVIVrcDg6rD/GRY57rfZ43TEX/DYQIG7v/EvYxQ/TIDCeAw1b1Jy0bLuAIFis9fbdP7VRg==", "dependencies": { "@ethersproject/solidity": "^5.0.9", "@uniswap/sdk-core": "^7.5.0", @@ -27907,16 +27907,16 @@ } }, "@uniswap/router-sdk": { - "version": "1.21.0", - "resolved": "https://registry.npmjs.org/@uniswap/router-sdk/-/router-sdk-1.21.0.tgz", - "integrity": "sha512-L7NixcJvcjkkX4WOa9mSyep1M2LMRp6gI0DKZGNuYsY+mjSJfxdlZyAKPXWHmVZGfVSE25IcbKZhA/i0KgVhKg==", + "version": "1.22.1", + "resolved": "https://registry.npmjs.org/@uniswap/router-sdk/-/router-sdk-1.22.1.tgz", + "integrity": "sha512-j7LzPaxdlA/6Rf3V9iHzi7GnLW6huJSpLTq+6KZRcD1jbmV7RRKcSq0tgqGv/fbJprM8LqgW/NetfPIAqxzdLw==", "requires": { "@ethersproject/abi": "^5.5.0", "@uniswap/sdk-core": "^7.5.0", "@uniswap/swap-router-contracts": "^1.3.0", "@uniswap/v2-sdk": "^4.13.0", "@uniswap/v3-sdk": "^3.24.0", - "@uniswap/v4-sdk": "^1.18.0" + "@uniswap/v4-sdk": "^1.18.1" } }, "@uniswap/sdk-core": { @@ -27936,23 +27936,23 @@ } }, "@uniswap/smart-order-router": { - "version": "4.17.6", - "resolved": "https://registry.npmjs.org/@uniswap/smart-order-router/-/smart-order-router-4.17.6.tgz", - "integrity": "sha512-GLvj2Qv8tEF99LghrAFs7r5DOjAM0CNYEMAanErIIBptyoIa8QjiN5n83Jqo1VWNiYnQO7tekxvYuHIwvts1iw==", + "version": "4.17.10", + "resolved": "https://registry.npmjs.org/@uniswap/smart-order-router/-/smart-order-router-4.17.10.tgz", + "integrity": "sha512-5X6r6lFGzjFFWuCBIBHTOv+qv9XnuWy4BEKuh/LSbPFj3OZkJ//6WbbqCjXyN30pF08UiqUcjClRGCA2RUtEiA==", "requires": { "@eth-optimism/sdk": "^3.2.2", "@types/brotli": "^1.3.4", "@uniswap/default-token-list": "^11.13.0", "@uniswap/permit2-sdk": "^1.3.0", - "@uniswap/router-sdk": "^1.21.0", + "@uniswap/router-sdk": "^1.22.1", "@uniswap/sdk-core": "^7.5.0", "@uniswap/swap-router-contracts": "^1.3.1", "@uniswap/token-lists": "^1.0.0-beta.31", "@uniswap/universal-router": "^1.6.0", - "@uniswap/universal-router-sdk": "^4.14.0", + "@uniswap/universal-router-sdk": "^4.17.0", "@uniswap/v2-sdk": "^4.13.0", "@uniswap/v3-sdk": "^3.24.0", - "@uniswap/v4-sdk": "^1.18.0", + "@uniswap/v4-sdk": "^1.18.1", "async-retry": "^1.3.1", "await-timeout": "^1.1.1", "axios": "^0.21.1", @@ -28016,20 +28016,20 @@ } }, "@uniswap/universal-router-sdk": { - "version": "4.14.0", - "resolved": "https://registry.npmjs.org/@uniswap/universal-router-sdk/-/universal-router-sdk-4.14.0.tgz", - "integrity": "sha512-lM8o5olNxJSgaAXUotltSuobfjiDQhkS46XkRbJEDrFjmUDCqggUgegZjU4TFDC87d5LBF47TWYF9dAVQENjxg==", + "version": "4.17.0", + "resolved": "https://registry.npmjs.org/@uniswap/universal-router-sdk/-/universal-router-sdk-4.17.0.tgz", + "integrity": "sha512-LjdiBq1ab1Z2l8DQ7OuOmpJ+BbhlTU8xxIrTvRppVf4RtHCHaNNrwwXMbZF3bBDWD4h0WrMDJqwZ5LSfm2plbg==", "requires": { "@openzeppelin/contracts": "4.7.0", "@uniswap/permit2-sdk": "^1.3.0", - "@uniswap/router-sdk": "^1.21.0", + "@uniswap/router-sdk": "^1.22.1", "@uniswap/sdk-core": "^7.5.0", "@uniswap/universal-router": "2.0.0-beta.2", "@uniswap/v2-core": "^1.0.1", "@uniswap/v2-sdk": "^4.13.0", "@uniswap/v3-core": "1.0.0", "@uniswap/v3-sdk": "^3.24.0", - "@uniswap/v4-sdk": "^1.18.0", + "@uniswap/v4-sdk": "^1.19.2", "bignumber.js": "^9.0.2", "ethers": "^5.7.0" }, @@ -28127,9 +28127,9 @@ } }, "@uniswap/v4-sdk": { - "version": "1.18.0", - "resolved": "https://registry.npmjs.org/@uniswap/v4-sdk/-/v4-sdk-1.18.0.tgz", - "integrity": "sha512-ZcVSwgozrggfotH6D5g63W1T84bndsU1VZ+x67KM0Z8csBNzyV4GkKsMQPE4jnPEf3O0JSnGyHL2qPlpTHvGOQ==", + "version": "1.19.2", + "resolved": "https://registry.npmjs.org/@uniswap/v4-sdk/-/v4-sdk-1.19.2.tgz", + "integrity": "sha512-WwebI+2rlCO44UIoqVIVrcDg6rD/GRY57rfZ43TEX/DYQIG7v/EvYxQ/TIDCeAw1b1Jy0bLuAIFis9fbdP7VRg==", "requires": { "@ethersproject/solidity": "^5.0.9", "@uniswap/sdk-core": "^7.5.0", diff --git a/package.json b/package.json index 2468257b83..376e669d54 100644 --- a/package.json +++ b/package.json @@ -86,11 +86,11 @@ "@types/stats-lite": "^2.2.0", "@uniswap/default-token-list": "^11.13.0", "@uniswap/permit2-sdk": "^1.3.0", - "@uniswap/router-sdk": "^1.21.0", + "@uniswap/router-sdk": "^1.22.1", "@uniswap/sdk-core": "^7.5.0", - "@uniswap/smart-order-router": "4.17.6", + "@uniswap/smart-order-router": "4.17.10", "@uniswap/token-lists": "^1.0.0-beta.33", - "@uniswap/universal-router-sdk": "^4.14.0", + "@uniswap/universal-router-sdk": "^4.17.0", "@uniswap/v2-sdk": "^4.13.0", "@uniswap/v3-periphery": "^1.4.4", "@uniswap/v3-sdk": "^3.24.0", diff --git a/test/mocha/e2e/quote.test.ts b/test/mocha/e2e/quote.test.ts index a4968ff854..9e2953bf5a 100644 --- a/test/mocha/e2e/quote.test.ts +++ b/test/mocha/e2e/quote.test.ts @@ -13,6 +13,7 @@ import { parseAmount, SWAP_ROUTER_02_ADDRESSES, USDB_BLAST, + USDC_BASE, USDC_BNB, USDC_MAINNET, USDC_NATIVE_ARBITRUM, @@ -3417,6 +3418,53 @@ describe('quote', function () { fail(JSON.stringify(err.response.data)) } }) + + it(`USDC -> mockA only through mixed`, async () => { + if (chain !== ChainId.BASE) { + // Only Base has mockA + return + } + + if (type !== 'exactIn') { + // mixed route only supports exact in + return + } + + const tokenOut = new Token(ChainId.BASE, '0x878784f7ebf6e57d17c81d82ddf53f117a5e2988', 18, 'MOCKA') + const amount = type === 'exactIn' ? '0.00000000000001' : '0.000001' + + const quoteReq: QuoteQueryParams = { + tokenInAddress: USDC_BASE.address, + tokenInChainId: chain, + tokenOutAddress: tokenOut.address, + tokenOutChainId: chain, + amount: await getAmountFromToken(type, WNATIVE_ON(chain), tokenOut, amount), + type, + enableUniversalRouter: true, + forceMixedRoutes: true, + protocols: 'mixed', + } + + const headers = { + 'x-universal-router-version': '2.0', + } + + const queryParams = qs.stringify(quoteReq) + + try { + const response: AxiosResponse = await axios.get(`${API}?${queryParams}`, { + headers: headers, + }) + const { status, data } = response + + expect(status).to.equal(200, JSON.stringify(response.data)) + expect(data.route.filter((pools) => pools.filter((pool) => pool.type === 'v3-pool'))).to.not.be.undefined + expect(data.route.filter((pools) => pools.filter((pool) => pool.type === 'v4-pool'))).to.not.be.undefined + } catch (err: any) { + fail(JSON.stringify(err.response.data)) + } + }) + it(`has quoteGasAdjusted values`, async () => { if (chain === ChainId.SEPOLIA && !erc1.equals(V4_SEPOLIA_TEST_A)) { // Sepolia doesn't have sufficient liquidity on DAI pools yet