Skip to content

Commit

Permalink
include aggregate slippage check in swaps
Browse files Browse the repository at this point in the history
  • Loading branch information
ewilz committed Sep 10, 2024
1 parent 1ddfc5b commit 87cf40d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
7 changes: 4 additions & 3 deletions sdks/universal-router-sdk/src/entities/protocols/uniswap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ function addV2Swap<TInput extends Currency, TOutput extends Currency>(
// if native, we have to unwrap so keep in the router for now
routerMustCustody ? ROUTER_AS_RECIPIENT : options.recipient,
trade.maximumAmountIn(options.slippageTolerance).quotient.toString(),
trade.minimumAmountOut(options.slippageTolerance).quotient.toString(),
// if router will custody funds, we do aggregated slippage check from rotuer
routerMustCustody ? 0 : trade.minimumAmountOut(options.slippageTolerance).quotient.toString(),
route.path.map((token) => token.wrapped.address),
payerIsUser,
])
Expand Down Expand Up @@ -223,7 +224,7 @@ function addV3Swap<TInput extends Currency, TOutput extends Currency>(
planner.addCommand(CommandType.V3_SWAP_EXACT_IN, [
routerMustCustody ? ROUTER_AS_RECIPIENT : options.recipient,
trade.maximumAmountIn(options.slippageTolerance).quotient.toString(),
trade.minimumAmountOut(options.slippageTolerance).quotient.toString(),
routerMustCustody ? 0 : trade.minimumAmountOut(options.slippageTolerance).quotient.toString(),
path,
payerIsUser,
])
Expand Down Expand Up @@ -269,7 +270,7 @@ function addMixedSwap<TInput extends Currency, TOutput extends Currency>(
})

const amountIn = trade.maximumAmountIn(options.slippageTolerance, inputAmount).quotient.toString()
const amountOut = trade.minimumAmountOut(options.slippageTolerance, outputAmount).quotient.toString()
const amountOut = routerMustCustody ? 0 : trade.minimumAmountOut(options.slippageTolerance, outputAmount).quotient.toString()

// logic from
// https://github.com/Uniswap/router-sdk/blob/d8eed164e6c79519983844ca8b6a3fc24ebcb8f8/src/swapRouter.ts#L276
Expand Down
Loading

0 comments on commit 87cf40d

Please sign in to comment.