错误详情: Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? Returned error: {"jsonrpc":"2.0","error":"execution reverted","id":5115106837169996}
错误代码:
function doV3Swap(address token0,address token1,uint128 inputAmount,uint24 _fee)external{
//根据输入获得的最小输出值
address thisPool=getPoolAddress(token0,token1,_fee);
uint outMinAmount=getV3Data(thisPool,inputAmount);
//转移相应token到该合约进行交换
TransferHelper.safeApprove(token0, address(routerV3), inputAmount);
TransferHelper.safeTransferFrom(token0,msg.sender,address(this),inputAmount);
//进行交换
// uint receiveAmount=routerV3.exactInputSingle(
// ISwapRouter.ExactInputSingleParams({
// tokenIn: token0,
// tokenOut: token1,
// fee: _fee,
// recipient: address(this),
// deadline: block.timestamp,
// amountIn: inputAmount,
// amountOutMinimum: 0,
// sqrtPriceLimitX96: 0
// })
// );
ISwapRouter.ExactInputSingleParams memory params = ISwapRouter
.ExactInputSingleParams({
tokenIn: token0,
tokenOut: token1,
fee: _fee,
recipient: address(this),
deadline: block.timestamp,
amountIn: inputAmount,
amountOutMinimum: 0,
sqrtPriceLimitX96: 0
});
//通过uni的v3将token0转换成token1的数量
uint256 receiveAmount = routerV3.exactInputSingle(params);
emit tradeMes(msg.sender,outMinAmount,receiveAmount);
}