Skip to content

Commit

Permalink
Revert: chore: bump sor to 4.17.7 - fix: mixed route support ETH <-> …
Browse files Browse the repository at this point in the history
…WETH (#819)
  • Loading branch information
jsy1218 committed Feb 7, 2025
1 parent 7a036e3 commit f451675
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 439 deletions.
54 changes: 27 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@
"@types/brotli": "^1.3.4",
"@uniswap/default-token-list": "^11.13.0",
"@uniswap/permit2-sdk": "^1.3.0",
"@uniswap/router-sdk": "^1.22.1",
"@uniswap/router-sdk": "^1.21.0",
"@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.17.0",
"@uniswap/universal-router-sdk": "^4.14.0",
"@uniswap/v2-sdk": "^4.13.0",
"@uniswap/v3-sdk": "^3.24.0",
"@uniswap/v4-sdk": "^1.18.1",
"@uniswap/v4-sdk": "^1.18.0",
"async-retry": "^1.3.1",
"await-timeout": "^1.1.1",
"axios": "^0.21.1",
Expand Down
3 changes: 1 addition & 2 deletions src/providers/on-chain-quote-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,10 +483,9 @@ export class OnChainQuoteProvider implements IOnChainQuoteProvider {
// Hence in case of V2 or mixed, we explicitly encode into mixed routes.
case Protocol.V2:
case Protocol.MIXED:
// we need to retain the fake pool data for the mixed route
return encodeMixedRouteToPath(
route instanceof V2Route
? new MixedRouteSDK(route.pairs, route.input, route.output, true)
? new MixedRouteSDK(route.pairs, route.input, route.output)
: route
) as TPath;
default:
Expand Down
52 changes: 8 additions & 44 deletions src/routers/alpha-router/functions/compute-all-routes.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { TPool } from '@uniswap/router-sdk/dist/utils/TPool';
import { ChainId, Currency, Token } from '@uniswap/sdk-core';
import { Currency, Token } from '@uniswap/sdk-core';
import { Pair } from '@uniswap/v2-sdk';
import { Pool as V3Pool } from '@uniswap/v3-sdk';
import { Pool as V4Pool } from '@uniswap/v4-sdk';

import { getAddressLowerCase, nativeOnChain } from '../../../util';
import { getAddressLowerCase } from '../../../util';
import { log } from '../../../util/log';
import { V4_ETH_WETH_FAKE_POOL } from '../../../util/pool';
import { poolToString, routeToString } from '../../../util/routes';
import {
MixedRoute,
Expand Down Expand Up @@ -76,35 +75,17 @@ export function computeAllMixedRoutes(
parts: TPool[],
maxHops: number
): MixedRoute[] {
// only add fake v4 pool, if we see there's a native v4 pool in the candidate pool
const containsV4NativePools =
parts.filter(
(pool) =>
pool instanceof V4Pool &&
pool.v4InvolvesToken(nativeOnChain(currencyIn.chainId))
).length > 0;
const amendedPools = containsV4NativePools
? parts.concat(V4_ETH_WETH_FAKE_POOL[currencyIn.chainId as ChainId])
: parts;
// NOTE: we added a fake v4 pool, in order for mixed route to connect the v3 weth pool with v4 eth pool
const routesRaw = computeAllRoutes<TPool, MixedRoute, Currency>(
currencyIn,
currencyOut,
(route: TPool[], currencyIn: Currency, currencyOut: Currency) => {
// we only retake the fake v4 pool if the route contains a native v4 pool
return new MixedRoute(
route,
currencyIn,
currencyOut,
containsV4NativePools
);
return new MixedRoute(route, currencyIn, currencyOut);
},
(pool: TPool, currency: Currency) => {
return currency.isNative
(pool: TPool, currency: Currency) =>
currency.isNative
? (pool as V4Pool).involvesToken(currency)
: pool.involvesToken(currency);
},
amendedPools,
: pool.involvesToken(currency),
parts,
maxHops
);
/// filter out pure v4 and v3 and v2 routes
Expand Down Expand Up @@ -144,24 +125,7 @@ export function computeAllRoutes<
tokensVisited: Set<string>,
_previousTokenOut?: TCurrency
) => {
const currentRouteContainsFakeV4Pool =
currentRoute.filter(
(pool) =>
pool instanceof V4Pool &&
pool.tickSpacing ===
V4_ETH_WETH_FAKE_POOL[tokenIn.chainId as ChainId].tickSpacing
).length > 0;
const amendedMaxHops = currentRouteContainsFakeV4Pool
? maxHops + 1
: maxHops;

// amendedMaxHops is the maxHops + 1 if the current route contains a fake v4 pool
// b/c we want to allow the route to go through the fake v4 pool
// also gas wise, if a route goes through the fake v4 pool, mixed quoter will add the wrap/unwrap gas cost:
// https://github.com/Uniswap/mixed-quoter/pull/41/files#diff-a4d1289f264d1da22aac20cc55a9d01c8ba9cccd76ce1af8f952ec9034e7e1aaR189
// and SOR will use the gas cost from the mixed quoter:
// https://github.com/Uniswap/smart-order-router/blob/17da523f1af050e6430afb866d96681346c8fb8b/src/routers/alpha-router/gas-models/mixedRoute/mixed-route-heuristic-gas-model.ts#L222
if (currentRoute.length > amendedMaxHops) {
if (currentRoute.length > maxHops) {
return;
}

Expand Down
13 changes: 4 additions & 9 deletions src/routers/alpha-router/functions/get-candidate-pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1926,7 +1926,6 @@ export async function getMixedRouteCandidatePools({
v4PoolProvider,
v3poolProvider,
v2poolProvider,
chainId,
}: MixedRouteGetCandidatePoolsParams): Promise<MixedCandidatePools> {
const beforeSubgraphPools = Date.now();
const [
Expand Down Expand Up @@ -2077,15 +2076,10 @@ export async function getMixedRouteCandidatePools({

const V4tokenPairsRaw = _.map<
V4SubgraphPool,
[Currency, Currency, number, number, string] | undefined
[Token, Token, number, number, string] | undefined
>(V4sortedPools, (subgraphPool) => {
// native currency is not erc20 token, therefore there's no way to retrieve native currency metadata as the erc20 token.
const tokenA = isNativeCurrency(subgraphPool.token0.id)
? nativeOnChain(chainId)
: tokenAccessor.getTokenByAddress(subgraphPool.token0.id);
const tokenB = isNativeCurrency(subgraphPool.token1.id)
? nativeOnChain(chainId)
: tokenAccessor.getTokenByAddress(subgraphPool.token1.id);
const tokenA = tokenAccessor.getTokenByAddress(subgraphPool.token0.id);
const tokenB = tokenAccessor.getTokenByAddress(subgraphPool.token1.id);
let fee: FeeAmount;
try {
fee = Number(subgraphPool.feeTier);
Expand All @@ -2096,6 +2090,7 @@ export async function getMixedRouteCandidatePools({
);
return undefined;
}

if (!tokenA || !tokenB) {
log.info(
`Dropping candidate pool for ${subgraphPool.token0.id}/${
Expand Down
1 change: 0 additions & 1 deletion src/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ export * from './chains';
export * from './intent';
export * from './log';
export * from './metric';
export * from './pool';
export * from './protocols';
export * from './routes';
2 changes: 0 additions & 2 deletions src/util/methodParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,6 @@ export function buildTrade<TTradeType extends TradeType>(
quote.denominator
);

// we cannot retain fake pools for mixed routes,
// when we generate the ur swap calldata
const routeRaw = new MixedRouteSDK(
route.pools,
amountCurrency.currency,
Expand Down
Loading

0 comments on commit f451675

Please sign in to comment.