Skip to content

Commit

Permalink
fix: don't explore split routes with native&wrappedNative (#812)
Browse files Browse the repository at this point in the history
* fix: don't explore split routes with native&wrappedNative

* add unit tests

* package version

* update test values

* test updates
  • Loading branch information
xrsv authored Jan 31, 2025
1 parent 81df3cd commit 17da523
Show file tree
Hide file tree
Showing 4 changed files with 418 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@uniswap/smart-order-router",
"version": "4.17.5",
"version": "4.17.6",
"description": "Uniswap Smart Order Router",
"main": "build/main/index.js",
"typings": "build/main/index.d.ts",
Expand Down
51 changes: 50 additions & 1 deletion src/routers/alpha-router/functions/best-swap-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import Queue from 'mnemonist/queue';

import { IPortionProvider } from '../../../providers/portion-provider';
import { ProviderConfig } from '../../../providers/provider';
import { HAS_L1_FEE, V2_SUPPORTED, V4_SUPPORTED } from '../../../util';
import {
HAS_L1_FEE,
V2_SUPPORTED,
V4_SUPPORTED,
WRAPPED_NATIVE_CURRENCY,
} from '../../../util';
import { CurrencyAmount } from '../../../util/amounts';
import { log } from '../../../util/log';
import { metric, MetricLoggerUnit } from '../../../util/metric';
Expand Down Expand Up @@ -831,8 +836,52 @@ const findFirstRouteNotUsingUsedPools = (
continue;
}

// Note: Below is a temporary fix until we have this logic handled in the SDK level.
// If any previous route has Native token, don't allow Wrapped Native token routes and vice versa
const hasNativeInUsedRoutes = usedRoutes.some(
routeHasNativeTokenInputOrOutput
);
const hasWrappedNativeInUsedRoutes = usedRoutes.some(
routeHasWrappedNativeTokenInputOrOutput
);

if (
(hasNativeInUsedRoutes &&
routeHasWrappedNativeTokenInputOrOutput(routeQuote)) ||
(hasWrappedNativeInUsedRoutes &&
routeHasNativeTokenInputOrOutput(routeQuote))
) {
continue;
}

return routeQuote;
}

return null;
};

export const routeHasNativeTokenInputOrOutput = (
routeWithValidQuote: RouteWithValidQuote
): boolean => {
return (
routeWithValidQuote.route.input.isNative ||
routeWithValidQuote.route.output.isNative
);
};

export const routeHasWrappedNativeTokenInputOrOutput = (
routeWithValidQuote: RouteWithValidQuote
): boolean => {
const chainId = routeWithValidQuote.route.chainId;
const wrappedNativeToken =
WRAPPED_NATIVE_CURRENCY[chainId as keyof typeof WRAPPED_NATIVE_CURRENCY];
if (!wrappedNativeToken) {
return false;
}
return (
(routeWithValidQuote.route.input.isToken &&
routeWithValidQuote.route.input.wrapped.equals(wrappedNativeToken)) ||
(routeWithValidQuote.route.output.isToken &&
routeWithValidQuote.route.output.wrapped.equals(wrappedNativeToken))
);
};
Loading

0 comments on commit 17da523

Please sign in to comment.