Skip to content

Commit 7569a2f

Browse files
committed
include aggregate slippage check in swaps
1 parent 1ddfc5b commit 7569a2f

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

sdks/universal-router-sdk/src/entities/protocols/uniswap.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ function addV2Swap<TInput extends Currency, TOutput extends Currency>(
187187
// if native, we have to unwrap so keep in the router for now
188188
routerMustCustody ? ROUTER_AS_RECIPIENT : options.recipient,
189189
trade.maximumAmountIn(options.slippageTolerance).quotient.toString(),
190-
trade.minimumAmountOut(options.slippageTolerance).quotient.toString(),
190+
// if router will custody funds, we do aggregated slippage check from rotuer
191+
routerMustCustody ? 0 : trade.minimumAmountOut(options.slippageTolerance).quotient.toString(),
191192
route.path.map((token) => token.wrapped.address),
192193
payerIsUser,
193194
])
@@ -223,7 +224,7 @@ function addV3Swap<TInput extends Currency, TOutput extends Currency>(
223224
planner.addCommand(CommandType.V3_SWAP_EXACT_IN, [
224225
routerMustCustody ? ROUTER_AS_RECIPIENT : options.recipient,
225226
trade.maximumAmountIn(options.slippageTolerance).quotient.toString(),
226-
trade.minimumAmountOut(options.slippageTolerance).quotient.toString(),
227+
routerMustCustody ? 0 : trade.minimumAmountOut(options.slippageTolerance).quotient.toString(),
227228
path,
228229
payerIsUser,
229230
])
@@ -269,7 +270,7 @@ function addMixedSwap<TInput extends Currency, TOutput extends Currency>(
269270
})
270271

271272
const amountIn = trade.maximumAmountIn(options.slippageTolerance, inputAmount).quotient.toString()
272-
const amountOut = trade.minimumAmountOut(options.slippageTolerance, outputAmount).quotient.toString()
273+
const amountOut = routerMustCustody ? 0 : trade.minimumAmountOut(options.slippageTolerance, outputAmount).quotient.toString()
273274

274275
// logic from
275276
// https://github.com/Uniswap/router-sdk/blob/d8eed164e6c79519983844ca8b6a3fc24ebcb8f8/src/swapRouter.ts#L276

0 commit comments

Comments
 (0)