diff --git a/sdks/universal-router-sdk/package.json b/sdks/universal-router-sdk/package.json index e90393c8d..1f063f0d2 100644 --- a/sdks/universal-router-sdk/package.json +++ b/sdks/universal-router-sdk/package.json @@ -31,11 +31,12 @@ }, "dependencies": { "@uniswap/permit2-sdk": "^1.3.0", - "@uniswap/router-sdk": "^1.9.3", + "@uniswap/router-sdk": "^1.10.0", "@uniswap/sdk-core": "^5.3.1", "@uniswap/universal-router": "1.6.0", "@uniswap/v2-sdk": "^4.4.1", "@uniswap/v3-sdk": "^3.13.1", + "@uniswap/v4-sdk": "^1.0.0", "bignumber.js": "^9.0.2", "ethers": "^5.7.0" }, diff --git a/sdks/universal-router-sdk/src/entities/protocols/uniswap.ts b/sdks/universal-router-sdk/src/entities/protocols/uniswap.ts index 41638895d..e1835f10d 100644 --- a/sdks/universal-router-sdk/src/entities/protocols/uniswap.ts +++ b/sdks/universal-router-sdk/src/entities/protocols/uniswap.ts @@ -1,6 +1,7 @@ import { RoutePlanner, CommandType } from '../../utils/routerCommands' import { Trade as V2Trade, Pair } from '@uniswap/v2-sdk' -import { Trade as V3Trade, Pool, encodeRouteToPath } from '@uniswap/v3-sdk' +import { Trade as V3Trade, Pool as V3Pool, encodeRouteToPath } from '@uniswap/v3-sdk' +import { Pool as V4Pool } from '@uniswap/v4-sdk' import { Trade as RouterTrade, MixedRouteTrade, @@ -41,7 +42,7 @@ export type SwapOptions = Omit & { const REFUND_ETH_PRICE_IMPACT_THRESHOLD = new Percent(50, 100) interface Swap { - route: IRoute + route: IRoute inputAmount: CurrencyAmount outputAmount: CurrencyAmount } @@ -187,7 +188,7 @@ function addV2Swap( routerMustCustody ? ROUTER_AS_RECIPIENT : options.recipient, trade.maximumAmountIn(options.slippageTolerance).quotient.toString(), trade.minimumAmountOut(options.slippageTolerance).quotient.toString(), - route.path.map((pool) => pool.address), + route.path.map((token) => token.wrapped.address), payerIsUser, ]) } else if (tradeType == TradeType.EXACT_OUTPUT) { @@ -195,7 +196,7 @@ function addV2Swap( routerMustCustody ? ROUTER_AS_RECIPIENT : options.recipient, trade.minimumAmountOut(options.slippageTolerance).quotient.toString(), trade.maximumAmountIn(options.slippageTolerance).quotient.toString(), - route.path.map((pool) => pool.address), + route.path.map((token) => token.wrapped.address), payerIsUser, ]) } @@ -251,7 +252,7 @@ function addMixedSwap( // single hop, so it can be reduced to plain v2 or v3 swap logic if (route.pools.length === 1) { - if (route.pools[0] instanceof Pool) { + if (route.pools[0] instanceof V3Pool) { return addV3Swap(planner, swap, tradeType, options, payerIsUser, routerMustCustody) } else if (route.pools[0] instanceof Pair) { return addV2Swap(planner, swap, tradeType, options, payerIsUser, routerMustCustody) @@ -293,10 +294,10 @@ function addMixedSwap( const newRoute = new MixedRoute(newRouteOriginal) /// Previous output is now input - inputToken = outputToken + inputToken = outputToken.wrapped const mixedRouteIsAllV3 = (route: MixedRouteSDK) => { - return route.pools.every((pool) => pool instanceof Pool) + return route.pools.every((pool) => pool instanceof V3Pool) } if (mixedRouteIsAllV3(newRoute)) { @@ -316,7 +317,7 @@ function addMixedSwap( isLastSectionInRoute(i) ? tradeRecipient : ROUTER_AS_RECIPIENT, // recipient i === 0 ? amountIn : CONTRACT_BALANCE, // amountIn !isLastSectionInRoute(i) ? 0 : amountOut, // amountOutMin - newRoute.path.map((pool) => pool.address), // path + newRoute.path.map((token) => token.wrapped.address), // path payerIsUser && i === 0, ]) } diff --git a/sdks/universal-router-sdk/src/utils/routerTradeAdapter.ts b/sdks/universal-router-sdk/src/utils/routerTradeAdapter.ts index a6aacfff9..0bd128edf 100644 --- a/sdks/universal-router-sdk/src/utils/routerTradeAdapter.ts +++ b/sdks/universal-router-sdk/src/utils/routerTradeAdapter.ts @@ -143,6 +143,8 @@ export class RouterTradeAdapter { inputAmount: route.inputAmount, outputAmount: route.outputAmount, })), + // TODO: ROUTE-219 - Support v4 trade in universal-router sdk + v4Routes: [], mixedRoutes: typedRoutes .filter((route) => route.mixedRoute) .map((route) => ({ diff --git a/sdks/universal-router-sdk/test/utils/uniswapData.ts b/sdks/universal-router-sdk/test/utils/uniswapData.ts index 4483846c5..b0dcf0910 100644 --- a/sdks/universal-router-sdk/test/utils/uniswapData.ts +++ b/sdks/universal-router-sdk/test/utils/uniswapData.ts @@ -1,5 +1,5 @@ import JSBI from 'jsbi' -import { BigNumber, ethers } from 'ethers' +import { ethers } from 'ethers' import { MixedRouteTrade, MixedRouteSDK, Trade as RouterTrade } from '@uniswap/router-sdk' import { Trade as V2Trade, Pair, Route as RouteV2, computePairAddress } from '@uniswap/v2-sdk' import { @@ -151,6 +151,8 @@ export function buildTrade( inputAmount: trade.inputAmount, outputAmount: trade.outputAmount, })), + // TODO: ROUTE-219 - Support v4 trade in universal-router sdk + v4Routes: [], mixedRoutes: trades .filter((trade) => trade instanceof MixedRouteTrade) .map((trade) => ({ diff --git a/yarn.lock b/yarn.lock index 9d596e4b0..2cf285935 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4602,16 +4602,17 @@ __metadata: languageName: unknown linkType: soft -"@uniswap/router-sdk@npm:^1.9.3": - version: 1.9.3 - resolution: "@uniswap/router-sdk@npm:1.9.3" +"@uniswap/router-sdk@npm:^1.10.0": + version: 1.10.0 + resolution: "@uniswap/router-sdk@npm:1.10.0" dependencies: "@ethersproject/abi": ^5.5.0 "@uniswap/sdk-core": ^5.3.1 "@uniswap/swap-router-contracts": ^1.3.0 "@uniswap/v2-sdk": ^4.3.2 "@uniswap/v3-sdk": ^3.11.2 - checksum: 92922d43432908b9159e0f9cd1c9bb9658ceb89fb1e8e5ef4fc0350b4309cbd3767586135887333bb8d586c5ed304d2c2910b86bf276485421d2be025101485f + "@uniswap/v4-sdk": ^1.0.0 + checksum: df468dfd4c60ad311e51ce6414b67e3ee1fb07fde69979c468f478d84b6754a9a7e23c7d20b0bac53a9092c04b17fae2da365e8e084f953c39c4204e62c2268c languageName: node linkType: hard @@ -4721,11 +4722,12 @@ __metadata: "@types/node": ^18.7.16 "@types/node-fetch": ^2.6.2 "@uniswap/permit2-sdk": ^1.3.0 - "@uniswap/router-sdk": ^1.9.3 + "@uniswap/router-sdk": ^1.10.0 "@uniswap/sdk-core": ^5.3.1 "@uniswap/universal-router": 1.6.0 "@uniswap/v2-sdk": ^4.4.1 "@uniswap/v3-sdk": ^3.13.1 + "@uniswap/v4-sdk": ^1.0.0 bignumber.js: ^9.0.2 chai: ^4.3.6 dotenv: ^16.0.3