Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: bump sor to 4.17.5 - fix: mixed route support v4 ETH pool to v2/v3 WETH pool new way #814

Merged
merged 8 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.21.0",
"@uniswap/router-sdk": "^1.21.4",
"@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.15.1",
"@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",
Expand Down
16 changes: 13 additions & 3 deletions src/routers/alpha-router/entities/route-with-valid-quote.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { BigNumber } from '@ethersproject/bignumber';
import { Protocol } from '@uniswap/router-sdk';
import { Currency, Token, TradeType } 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 _ from 'lodash';

import { Pair } from '@uniswap/v2-sdk';
import { IV4PoolProvider } from '../../../providers';
import { IV2PoolProvider } from '../../../providers/v2/pool-provider';
import { IV3PoolProvider } from '../../../providers/v3/pool-provider';
import { CurrencyAmount } from '../../../util/amounts';
import { FAKE_TICK_SPACING } from '../../../util/pools';
import { routeToString } from '../../../util/routes';
import {
MixedRoute,
Expand Down Expand Up @@ -430,14 +431,23 @@ export class MixedRouteWithValidQuote implements IMixedRouteWithValidQuote {
v3PoolProvider,
v2PoolProvider,
}: MixedRouteWithValidQuoteParams) {
const poolsWithoutFakePool = route.pools.filter(
(p) => !(p instanceof V4Pool && p.tickSpacing === FAKE_TICK_SPACING)
);
const routeWithoutEthWethFakePool = new MixedRoute(
poolsWithoutFakePool,
route.input,
route.output
);

this.amount = amount;
this.rawQuote = rawQuote;
this.sqrtPriceX96AfterList = sqrtPriceX96AfterList;
this.initializedTicksCrossedList = initializedTicksCrossedList;
this.quoterGasEstimate = quoterGasEstimate;
this.quote = CurrencyAmount.fromRawAmount(quoteToken, rawQuote.toString());
this.percent = percent;
this.route = route;
this.route = routeWithoutEthWethFakePool;
this.gasModel = mixedRouteGasModel;
this.quoteToken = quoteToken;
this.tradeType = tradeType;
Expand All @@ -459,7 +469,7 @@ export class MixedRouteWithValidQuote implements IMixedRouteWithValidQuote {
this.quoteAdjustedForGas = quoteGasAdjusted;
}

this.poolIdentifiers = _.map(route.pools, (p) => {
this.poolIdentifiers = _.map(routeWithoutEthWethFakePool.pools, (p) => {
jsy1218 marked this conversation as resolved.
Show resolved Hide resolved
if (p instanceof V4Pool) {
return v4PoolProvider.getPoolId(
p.token0,
Expand Down
26 changes: 23 additions & 3 deletions src/routers/alpha-router/functions/compute-all-routes.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { TPool } from '@uniswap/router-sdk/dist/utils/TPool';
import { Currency, Token } from '@uniswap/sdk-core';
import { ChainId, 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 } from '../../../util';
import { log } from '../../../util/log';
import { FAKE_TICK_SPACING, V4_ETH_WETH_FAKE_POOL } from '../../../util/pools';
import { poolToString, routeToString } from '../../../util/routes';
import {
MixedRoute,
Expand Down Expand Up @@ -75,6 +76,10 @@ export function computeAllMixedRoutes(
parts: TPool[],
maxHops: number
): MixedRoute[] {
// NOTE: we added a fake v4 pool, in order for mixed route to connect the v3 weth pool with v4 eth pool
jsy1218 marked this conversation as resolved.
Show resolved Hide resolved
const amendedPools = parts.concat(
V4_ETH_WETH_FAKE_POOL[currencyIn.chainId as ChainId]
);
const routesRaw = computeAllRoutes<TPool, MixedRoute, Currency>(
currencyIn,
currencyOut,
Expand All @@ -85,7 +90,7 @@ export function computeAllMixedRoutes(
currency.isNative
? (pool as V4Pool).involvesToken(currency)
: pool.involvesToken(currency),
parts,
amendedPools,
maxHops
);
/// filter out pure v4 and v3 and v2 routes
Expand Down Expand Up @@ -125,7 +130,22 @@ export function computeAllRoutes<
tokensVisited: Set<string>,
_previousTokenOut?: TCurrency
) => {
if (currentRoute.length > maxHops) {
const currentRouteContainsFakeV4Pool =
currentRoute.filter(
(pool) =>
pool instanceof V4Pool && pool.tickSpacing === FAKE_TICK_SPACING
).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) {
return;
}

Expand Down
Loading
Loading