使用uni v3进行单例交换(非多跳)出现错误

错误详情: 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);
    }
请先 登录 后评论

最佳答案 2023-09-19 11:20

昨天已经解决了

请先 登录 后评论

其它 2 个回答

Jeack
请先 登录 后评论
lalala
请先 登录 后评论
  • 2 关注
  • 0 收藏,1486 浏览
  • lalala 提出于 2023-09-18 16:08