Deployed on Polygon Mumbai. Code compiles fine on REMIX and is meant to perform multihop swaps on Polygon Mumbai, but it returns error after function is called.
Deployed Contract always funded with USDC to initiate swaps.
Need quickfix.
// SPDX-License-Identifier: MIT
pragma solidity >0.7.6;
pragma abicoder v2;
import '@uniswap/v3-periphery/contracts/libraries/TransferHelper.sol';
import '@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol';
contract SwapExamples {
address private owner;
address public constant WETH = 0xA6FA4fB5f76172d178d61B04b0ecd319C5d1C0aa;
address public constant WETH9 = 0x9c3C9283D3e44854697Cd22D3Faa240Cfb032889;
address public constant USDC = 0x0FA8781a83E46826621b3BC094Ea2A0212e71B23;
ISwapRouter public immutable swapRouter = ISwapRouter(0xE592427A0AEce92De3Edee1F18E0157C05861564);
// For this example, we will set the pool fee to 0.3%.
uint24 public constant poolFee = 3000;
constructor() {
owner = payable(msg.sender);
}
modifier onlyOwner() {
require(msg.sender == owner, "Not the owner");
_;
}
function swapExactInputMultihop(uint256 amountIn) external returns (uint256 amountOut) {
TransferHelper.safeTransferFrom(WETH, msg.sender, address(this), amountIn);
TransferHelper.safeApprove(WETH, address(swapRouter), amountIn);
TransferHelper.safeApprove(USDC, address(swapRouter), amountIn);
ISwapRouter.ExactInputParams memory params =
ISwapRouter.ExactInputParams({
path: abi.encodePacked(USDC, poolFee, WETH9, poolFee, WETH),
recipient: msg.sender,
deadline: block.timestamp,
amountIn: amountIn,
amountOutMinimum: 0
});
// Executes the swap.
amountOut = swapRouter.exactInput(params);
}