You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A common integration error is to pass in a non-zero sqrtPriceLimitX96 value and then not refund the user the unswapped tokens.
Highlighting this in the documentation, or even providing a more complex example in the documentation, will be extremely useful to developers wishing to integrate with Uniswap V3.
contractSomeContract {
// ...function swapExactInputSingle(uint256amountIn, uint160sqrtPriceLimitX96) externalreturns (uint256amountOut) {
// msg.sender must approve this contract// Transfer the specified amount of DAI to this contract.
TransferHelper.safeTransferFrom(DAI, msg.sender, address(this), amountIn);
// Approve the router to spend DAI.
TransferHelper.safeApprove(DAI, address(swapRouter), amountIn);
// Naively set amountOutMinimum to 0. In production, use an oracle or other data source to choose a safer value for amountOutMinimum.// We also set the sqrtPriceLimitx96 to be 0 to ensure we swap our exact input amount.
ISwapRouter.ExactInputSingleParams memory params =
ISwapRouter.ExactInputSingleParams({
tokenIn: DAI,
tokenOut: WETH9,
fee: poolFee,
recipient: msg.sender,
deadline: block.timestamp,
amountIn: amountIn,
amountOutMinimum: 0,
sqrtPriceLimitX96: sqrtPriceLimitX96
});
// The call to `exactInputSingle` executes the swap.
amountOut = swapRouter.exactInputSingle(params);
// ***ERROR***: Less than amountIn token may have been swapped. They need to be refunded to the user!
}
// ....
}
The text was updated successfully, but these errors were encountered:
A common integration error is to pass in a non-zero
sqrtPriceLimitX96
value and then not refund the user the unswapped tokens.Highlighting this in the documentation, or even providing a more complex example in the documentation, will be extremely useful to developers wishing to integrate with Uniswap V3.
The text was updated successfully, but these errors were encountered: