I'm using functionCallWithValue() to call UniswapV3's swap function. I have confirmed that the params are correct because calling the function directly works. But when I try to do so through functionCallWithValue, it errors out with 'Address: low level call with value failed'.
I thought the problem was with my use of the functionCallWithValue() function because in the docs it lists 3 arguments instead of the 2 I use here, but when I try putting 3 arguments in, it says
Member "functionCall" not found or not visible after argument-dependent lookup in address.
despite the fact that I'm importing
import { Address } from "@openzeppelin/contracts/utils/Address.sol";
and
using Address for address;
Code to reproduce
IV3SwapRouter swapRouter02 = IV3SwapRouter(uniswapRouter);
IV3SwapRouter.ExactInputSingleParams memory params = IV3SwapRouter
.ExactInputSingleParams({
tokenIn: _sellComponent,
tokenOut: _buyComponent,
fee: 3000,
recipient: address(this),
amountIn: 10**16,
amountOutMinimum: 1,
sqrtPriceLimitX96: 0
});
//this is working
//amountOut = swapRouter02.exactInputSingle(params);
bytes memory callData = abi.encodeWithSignature(
SWAP_EXACT_INPUT,
params
);
//this is not working
bytes memory _return = uniswapRouter.functionCallWithValue(callData, 0);
Environment
Hardhat. Can provide the javascript testing snippet I'm using if necessary