Skip to content

Commit 7112718

Browse files
authoredFeb 7, 2025··
Revert: chore: bump sor to 4.17.7 - fix: mixed route support ETH <-> WETH (#819) (#823)
- **What kind of change does this PR introduce?** (Bug fix, feature, docs update, ...) - **What is the current behavior?** (You can also link to an open issue here) - **What is the new behavior (if this is a feature change)?** - **Other information**:
1 parent 7a036e3 commit 7112718

File tree

10 files changed

+47
-442
lines changed

10 files changed

+47
-442
lines changed
 

‎package-lock.json

+29-29
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@uniswap/smart-order-router",
3-
"version": "4.17.11",
3+
"version": "4.17.12",
44
"description": "Uniswap Smart Order Router",
55
"main": "build/main/index.js",
66
"typings": "build/main/index.d.ts",
@@ -37,15 +37,15 @@
3737
"@types/brotli": "^1.3.4",
3838
"@uniswap/default-token-list": "^11.13.0",
3939
"@uniswap/permit2-sdk": "^1.3.0",
40-
"@uniswap/router-sdk": "^1.22.1",
40+
"@uniswap/router-sdk": "^1.21.0",
4141
"@uniswap/sdk-core": "^7.5.0",
4242
"@uniswap/swap-router-contracts": "^1.3.1",
4343
"@uniswap/token-lists": "^1.0.0-beta.31",
4444
"@uniswap/universal-router": "^1.6.0",
45-
"@uniswap/universal-router-sdk": "^4.17.0",
45+
"@uniswap/universal-router-sdk": "^4.14.0",
4646
"@uniswap/v2-sdk": "^4.13.0",
4747
"@uniswap/v3-sdk": "^3.24.0",
48-
"@uniswap/v4-sdk": "^1.18.1",
48+
"@uniswap/v4-sdk": "^1.18.0",
4949
"async-retry": "^1.3.1",
5050
"await-timeout": "^1.1.1",
5151
"axios": "^0.21.1",

‎src/providers/on-chain-quote-provider.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -483,10 +483,9 @@ export class OnChainQuoteProvider implements IOnChainQuoteProvider {
483483
// Hence in case of V2 or mixed, we explicitly encode into mixed routes.
484484
case Protocol.V2:
485485
case Protocol.MIXED:
486-
// we need to retain the fake pool data for the mixed route
487486
return encodeMixedRouteToPath(
488487
route instanceof V2Route
489-
? new MixedRouteSDK(route.pairs, route.input, route.output, true)
488+
? new MixedRouteSDK(route.pairs, route.input, route.output)
490489
: route
491490
) as TPath;
492491
default:

‎src/routers/alpha-router/functions/compute-all-routes.ts

+8-44
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { TPool } from '@uniswap/router-sdk/dist/utils/TPool';
2-
import { ChainId, Currency, Token } from '@uniswap/sdk-core';
2+
import { Currency, Token } from '@uniswap/sdk-core';
33
import { Pair } from '@uniswap/v2-sdk';
44
import { Pool as V3Pool } from '@uniswap/v3-sdk';
55
import { Pool as V4Pool } from '@uniswap/v4-sdk';
66

7-
import { getAddressLowerCase, nativeOnChain } from '../../../util';
7+
import { getAddressLowerCase } from '../../../util';
88
import { log } from '../../../util/log';
9-
import { V4_ETH_WETH_FAKE_POOL } from '../../../util/pool';
109
import { poolToString, routeToString } from '../../../util/routes';
1110
import {
1211
MixedRoute,
@@ -76,35 +75,17 @@ export function computeAllMixedRoutes(
7675
parts: TPool[],
7776
maxHops: number
7877
): MixedRoute[] {
79-
// only add fake v4 pool, if we see there's a native v4 pool in the candidate pool
80-
const containsV4NativePools =
81-
parts.filter(
82-
(pool) =>
83-
pool instanceof V4Pool &&
84-
pool.v4InvolvesToken(nativeOnChain(currencyIn.chainId))
85-
).length > 0;
86-
const amendedPools = containsV4NativePools
87-
? parts.concat(V4_ETH_WETH_FAKE_POOL[currencyIn.chainId as ChainId])
88-
: parts;
89-
// NOTE: we added a fake v4 pool, in order for mixed route to connect the v3 weth pool with v4 eth pool
9078
const routesRaw = computeAllRoutes<TPool, MixedRoute, Currency>(
9179
currencyIn,
9280
currencyOut,
9381
(route: TPool[], currencyIn: Currency, currencyOut: Currency) => {
94-
// we only retake the fake v4 pool if the route contains a native v4 pool
95-
return new MixedRoute(
96-
route,
97-
currencyIn,
98-
currencyOut,
99-
containsV4NativePools
100-
);
82+
return new MixedRoute(route, currencyIn, currencyOut);
10183
},
102-
(pool: TPool, currency: Currency) => {
103-
return currency.isNative
84+
(pool: TPool, currency: Currency) =>
85+
currency.isNative
10486
? (pool as V4Pool).involvesToken(currency)
105-
: pool.involvesToken(currency);
106-
},
107-
amendedPools,
87+
: pool.involvesToken(currency),
88+
parts,
10889
maxHops
10990
);
11091
/// filter out pure v4 and v3 and v2 routes
@@ -144,24 +125,7 @@ export function computeAllRoutes<
144125
tokensVisited: Set<string>,
145126
_previousTokenOut?: TCurrency
146127
) => {
147-
const currentRouteContainsFakeV4Pool =
148-
currentRoute.filter(
149-
(pool) =>
150-
pool instanceof V4Pool &&
151-
pool.tickSpacing ===
152-
V4_ETH_WETH_FAKE_POOL[tokenIn.chainId as ChainId].tickSpacing
153-
).length > 0;
154-
const amendedMaxHops = currentRouteContainsFakeV4Pool
155-
? maxHops + 1
156-
: maxHops;
157-
158-
// amendedMaxHops is the maxHops + 1 if the current route contains a fake v4 pool
159-
// b/c we want to allow the route to go through the fake v4 pool
160-
// also gas wise, if a route goes through the fake v4 pool, mixed quoter will add the wrap/unwrap gas cost:
161-
// https://github.com/Uniswap/mixed-quoter/pull/41/files#diff-a4d1289f264d1da22aac20cc55a9d01c8ba9cccd76ce1af8f952ec9034e7e1aaR189
162-
// and SOR will use the gas cost from the mixed quoter:
163-
// https://github.com/Uniswap/smart-order-router/blob/17da523f1af050e6430afb866d96681346c8fb8b/src/routers/alpha-router/gas-models/mixedRoute/mixed-route-heuristic-gas-model.ts#L222
164-
if (currentRoute.length > amendedMaxHops) {
128+
if (currentRoute.length > maxHops) {
165129
return;
166130
}
167131

‎src/routers/alpha-router/functions/get-candidate-pools.ts

+4-9
Original file line numberDiff line numberDiff line change
@@ -1926,7 +1926,6 @@ export async function getMixedRouteCandidatePools({
19261926
v4PoolProvider,
19271927
v3poolProvider,
19281928
v2poolProvider,
1929-
chainId,
19301929
}: MixedRouteGetCandidatePoolsParams): Promise<MixedCandidatePools> {
19311930
const beforeSubgraphPools = Date.now();
19321931
const [
@@ -2077,15 +2076,10 @@ export async function getMixedRouteCandidatePools({
20772076

20782077
const V4tokenPairsRaw = _.map<
20792078
V4SubgraphPool,
2080-
[Currency, Currency, number, number, string] | undefined
2079+
[Token, Token, number, number, string] | undefined
20812080
>(V4sortedPools, (subgraphPool) => {
2082-
// native currency is not erc20 token, therefore there's no way to retrieve native currency metadata as the erc20 token.
2083-
const tokenA = isNativeCurrency(subgraphPool.token0.id)
2084-
? nativeOnChain(chainId)
2085-
: tokenAccessor.getTokenByAddress(subgraphPool.token0.id);
2086-
const tokenB = isNativeCurrency(subgraphPool.token1.id)
2087-
? nativeOnChain(chainId)
2088-
: tokenAccessor.getTokenByAddress(subgraphPool.token1.id);
2081+
const tokenA = tokenAccessor.getTokenByAddress(subgraphPool.token0.id);
2082+
const tokenB = tokenAccessor.getTokenByAddress(subgraphPool.token1.id);
20892083
let fee: FeeAmount;
20902084
try {
20912085
fee = Number(subgraphPool.feeTier);
@@ -2096,6 +2090,7 @@ export async function getMixedRouteCandidatePools({
20962090
);
20972091
return undefined;
20982092
}
2093+
20992094
if (!tokenA || !tokenB) {
21002095
log.info(
21012096
`Dropping candidate pool for ${subgraphPool.token0.id}/${

‎src/util/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@ export * from './chains';
44
export * from './intent';
55
export * from './log';
66
export * from './metric';
7-
export * from './pool';
87
export * from './protocols';
98
export * from './routes';

‎src/util/methodParameters.ts

-2
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,6 @@ export function buildTrade<TTradeType extends TradeType>(
282282
quote.denominator
283283
);
284284

285-
// we cannot retain fake pools for mixed routes,
286-
// when we generate the ur swap calldata
287285
const routeRaw = new MixedRouteSDK(
288286
route.pools,
289287
amountCurrency.currency,

‎src/util/pool.ts

-300
This file was deleted.

‎src/util/routes.ts

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Protocol } from '@uniswap/router-sdk';
2-
import { ChainId, Currency, Percent } from '@uniswap/sdk-core';
2+
import { Currency, Percent } from '@uniswap/sdk-core';
33
import { Pair } from '@uniswap/v2-sdk';
44
import { Pool as V3Pool } from '@uniswap/v3-sdk';
55
import { Pool as V4Pool } from '@uniswap/v4-sdk';
@@ -16,7 +16,6 @@ import { V3_CORE_FACTORY_ADDRESSES } from './addresses';
1616
import { TPool } from '@uniswap/router-sdk/dist/utils/TPool';
1717
import { CurrencyAmount } from '.';
1818
import { CachedRoutes } from '../providers';
19-
import { V4_ETH_WETH_FAKE_POOL } from './pool';
2019

2120
export const routeToTokens = (route: SupportedRoutes): Currency[] => {
2221
switch (route.protocol) {
@@ -92,15 +91,6 @@ export const routeToString = (route: SupportedRoutes): string => {
9291
V3_CORE_FACTORY_ADDRESSES[pool.chainId]
9392
)}]`;
9493
} else if (pool instanceof V4Pool) {
95-
// Special case in the case of ETH/WETH fake pool
96-
// where we do not want to return the fake pool in the route string as it is not a real pool
97-
if (
98-
pool.tickSpacing ===
99-
V4_ETH_WETH_FAKE_POOL[pool.chainId as ChainId].tickSpacing
100-
) {
101-
return ' -- ';
102-
}
103-
10494
return ` -- ${pool.fee / 10000}% [${V4Pool.getPoolId(
10595
pool.token0,
10696
pool.token1,

‎test/unit/routers/alpha-router/functions/compute-all-routes.test.ts

-40
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { Pool as V4Pool } from '@uniswap/v4-sdk';
44
import {
55
CurrencyAmount,
66
DAI_MAINNET as DAI,
7-
nativeOnChain,
87
USDC_MAINNET as USDC,
98
USDT_MAINNET as USDT,
109
WBTC_MAINNET as WBTC,
@@ -40,7 +39,6 @@ import {
4039
} from '../../../../test-util/mock-data';
4140
import { ADDRESS_ZERO } from '@uniswap/router-sdk';
4241
import { ChainId, WETH9 } from '@uniswap/sdk-core';
43-
import { V4_ETH_WETH_FAKE_POOL } from '../../../../../src/util/pool';
4442

4543
describe('compute all v4 routes', () => {
4644
test('succeeds to compute all routes', async () => {
@@ -293,44 +291,6 @@ describe('compute all mixed routes', () => {
293291

294292
expect(routes).toHaveLength(1);
295293
});
296-
297-
test('handles ETH/WETH wrapping in mixed routes', async () => {
298-
const pools = [
299-
USDC_WETH_LOW, // V3 pool
300-
ETH_USDT_V4_LOW
301-
];
302-
const routes = computeAllMixedRoutes(USDC, USDT, pools, 2);
303-
expect(routes.length).toBeGreaterThan(0);
304-
// Routes should not include both ETH and WETH fake pools
305-
routes.forEach(route => {
306-
expect(route.pools).toEqual([USDC_WETH_LOW, V4_ETH_WETH_FAKE_POOL[ChainId.MAINNET], ETH_USDT_V4_LOW])
307-
expect(route.path).toEqual([USDC, nativeOnChain(ChainId.MAINNET).wrapped, nativeOnChain(ChainId.MAINNET), USDT])
308-
expect(route.input).toEqual(USDC)
309-
expect(route.output).toEqual(USDT)
310-
expect(route.pathInput).toEqual(USDC)
311-
expect(route.pathOutput).toEqual(USDT)
312-
expect(route.chainId).toEqual(1)
313-
});
314-
});
315-
316-
test('handles WETH/ETH unwrapping in mixed routes', async () => {
317-
const pools = [
318-
ETH_USDT_V4_LOW,
319-
USDC_WETH_LOW
320-
];
321-
const routes = computeAllMixedRoutes(USDT, USDC, pools, 2);
322-
expect(routes.length).toBeGreaterThan(0);
323-
// Routes should not include both ETH and WETH fake pools
324-
routes.forEach(route => {
325-
expect(route.pools).toEqual([ETH_USDT_V4_LOW, V4_ETH_WETH_FAKE_POOL[ChainId.MAINNET], USDC_WETH_LOW])
326-
expect(route.path).toEqual([USDT, nativeOnChain(ChainId.MAINNET), nativeOnChain(ChainId.MAINNET).wrapped, USDC])
327-
expect(route.input).toEqual(USDT)
328-
expect(route.output).toEqual(USDC)
329-
expect(route.pathInput).toEqual(USDT)
330-
expect(route.pathOutput).toEqual(USDC)
331-
expect(route.chainId).toEqual(1)
332-
});
333-
});
334294
});
335295

336296
describe('compute all v2 routes', () => {

0 commit comments

Comments
 (0)
Please sign in to comment.