Skip to content

Commit

Permalink
chore: bump SOR to 4.7.2 - fix: add v4 related split routes metrics a…
Browse files Browse the repository at this point in the history
…nd routeToString (#750)

* fix: add v4 related split routes metrics

* 4.7.2

* also fix routeToString

* also fix routeToString

* also fix routeToString
  • Loading branch information
jsy1218 authored Oct 16, 2024
1 parent f7d78d5 commit cb279d8
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 28 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.7.1",
"version": "4.7.2",
"description": "Uniswap Smart Order Router",
"main": "build/main/index.js",
"typings": "build/main/index.d.ts",
Expand Down
80 changes: 61 additions & 19 deletions src/routers/alpha-router/alpha-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2455,7 +2455,12 @@ export class AlphaRouter
);

if (bestSwapRoute) {
this.emitPoolSelectionMetrics(bestSwapRoute, allCandidatePools);
this.emitPoolSelectionMetrics(
bestSwapRoute,
allCandidatePools,
currencyIn,
currencyOut
);
}

return bestSwapRoute;
Expand Down Expand Up @@ -2722,7 +2727,9 @@ export class AlphaRouter
routes: RouteWithValidQuote[];
estimatedGasUsed: BigNumber;
},
allPoolsBySelection: CandidatePoolsBySelectionCriteria[]
allPoolsBySelection: CandidatePoolsBySelectionCriteria[],
currencyIn: Currency,
currencyOut: Currency
) {
const poolAddressesUsed = new Set<string>();
const { routes: routeAmounts } = swapRouteRaw;
Expand Down Expand Up @@ -2753,10 +2760,14 @@ export class AlphaRouter
);
}

let hasV4Route = false;
let hasV3Route = false;
let hasV2Route = false;
let hasMixedRoute = false;
for (const routeAmount of routeAmounts) {
if (routeAmount.protocol === Protocol.V4) {
hasV4Route = true;
}
if (routeAmount.protocol === Protocol.V3) {
hasV3Route = true;
}
Expand All @@ -2768,40 +2779,62 @@ export class AlphaRouter
}
}

if (hasMixedRoute && (hasV3Route || hasV2Route)) {
if (hasV3Route && hasV2Route) {
if (hasMixedRoute && (hasV4Route || hasV3Route || hasV2Route)) {
let metricsPrefix = 'Mixed';

if (hasV4Route) {
metricsPrefix += 'AndV4';
}

if (hasV3Route) {
metricsPrefix += 'AndV3';
}

if (hasV2Route) {
metricsPrefix += 'AndV2';
}

metric.putMetric(`${metricsPrefix}SplitRoute`, 1, MetricLoggerUnit.Count);
metric.putMetric(
`${metricsPrefix}SplitRouteForChain${this.chainId}`,
1,
MetricLoggerUnit.Count
);

if (hasV4Route && (currencyIn.isNative || currencyOut.isNative)) {
// Keep track of this edge case https://linear.app/uniswap/issue/ROUTE-303/tech-debt-split-route-can-have-different-ethweth-input-or-output#comment-bba53758
metric.putMetric(
`MixedAndV3AndV2SplitRoute`,
`${metricsPrefix}SplitRouteWithNativeToken`,
1,
MetricLoggerUnit.Count
);
metric.putMetric(
`MixedAndV3AndV2SplitRouteForChain${this.chainId}`,
`${metricsPrefix}SplitRouteWithNativeTokenForChain${this.chainId}`,
1,
MetricLoggerUnit.Count
);
} else if (hasV3Route) {
metric.putMetric(`MixedAndV3SplitRoute`, 1, MetricLoggerUnit.Count);
}
} else if (hasV4Route && hasV3Route && hasV2Route) {
metric.putMetric(`V4AndV3AndV2SplitRoute`, 1, MetricLoggerUnit.Count);
metric.putMetric(
`V4AndV3AndV2SplitRouteForChain${this.chainId}`,
1,
MetricLoggerUnit.Count
);

if (currencyIn.isNative || currencyOut.isNative) {
// Keep track of this edge case https://linear.app/uniswap/issue/ROUTE-303/tech-debt-split-route-can-have-different-ethweth-input-or-output#comment-bba53758
metric.putMetric(
`MixedAndV3SplitRouteForChain${this.chainId}`,
`V4AndV3AndV2SplitRouteWithNativeToken`,
1,
MetricLoggerUnit.Count
);
} else if (hasV2Route) {
metric.putMetric(`MixedAndV2SplitRoute`, 1, MetricLoggerUnit.Count);
metric.putMetric(
`MixedAndV2SplitRouteForChain${this.chainId}`,
`V4AndV3AndV2SplitRouteWithNativeTokenForChain${this.chainId}`,
1,
MetricLoggerUnit.Count
);
}
} else if (hasV3Route && hasV2Route) {
metric.putMetric(`V3AndV2SplitRoute`, 1, MetricLoggerUnit.Count);
metric.putMetric(
`V3AndV2SplitRouteForChain${this.chainId}`,
1,
MetricLoggerUnit.Count
);
} else if (hasMixedRoute) {
if (routeAmounts.length > 1) {
metric.putMetric(`MixedSplitRoute`, 1, MetricLoggerUnit.Count);
Expand All @@ -2818,6 +2851,15 @@ export class AlphaRouter
MetricLoggerUnit.Count
);
}
} else if (hasV4Route) {
if (routeAmounts.length > 1) {
metric.putMetric(`V4SplitRoute`, 1, MetricLoggerUnit.Count);
metric.putMetric(
`V4SplitRouteForChain${this.chainId}`,
1,
MetricLoggerUnit.Count
);
}
} else if (hasV3Route) {
if (routeAmounts.length > 1) {
metric.putMetric(`V3SplitRoute`, 1, MetricLoggerUnit.Count);
Expand Down
12 changes: 6 additions & 6 deletions src/util/routes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ADDRESS_ZERO, Protocol } from '@uniswap/router-sdk';
import { Protocol } from '@uniswap/router-sdk';
import { Currency, Percent } from '@uniswap/sdk-core';
import { Pair } from '@uniswap/v2-sdk';
import { Pool as V3Pool } from '@uniswap/v3-sdk';
Expand Down Expand Up @@ -50,8 +50,8 @@ export const poolToString = (pool: TPool): string => {
pool.token0,
pool.token1,
pool.fee,
0,
ADDRESS_ZERO
pool.tickSpacing,
pool.hooks
)}]`;
} else if (pool instanceof V3Pool) {
return ` -- ${pool.fee / 10000}% [${V3Pool.getAddress(
Expand Down Expand Up @@ -95,8 +95,8 @@ export const routeToString = (route: SupportedRoutes): string => {
pool.token0,
pool.token1,
pool.fee,
0,
ADDRESS_ZERO
pool.tickSpacing,
pool.hooks
)}]`;
} else {
throw new Error(`Unsupported pool ${JSON.stringify(pool)}`);
Expand Down Expand Up @@ -131,7 +131,7 @@ export const routeAmountsToString = (
const percent = new Percent(portion.numerator, portion.denominator);
/// @dev special case for MIXED routes we want to show user friendly V2+V3 instead
return `[${
protocol == Protocol.MIXED ? 'V2 + V3' : protocol
protocol == Protocol.MIXED ? 'V2 + V3 + V4' : protocol
}] ${percent.toFixed(2)}% = ${routeToString(route)}`;
});

Expand Down

0 comments on commit cb279d8

Please sign in to comment.