5 我将erc20代币转移到自己合约中和uniswap v3 做交互,出现了代币卡在合约里的情况

合约代码如下:

function swapExactTokensForETHV3(
        address tokenIn,
        uint256 amountIn,
        uint256 amountOutMin,
        uint256 deadline,
        uint24 fee,
        uint256 feePercentage
    ) external payable{
        require(feePercentage > 0 && feePercentage < 10000, "Fee percentage must be between 0 and 10000");
        // Interface for the ERC20 token
        IERC20 token = IERC20(tokenIn);

        // Transfer tokens to this contract
        require(token.transferFrom(msg.sender, address(this), amountIn), "transferFrom failed");

        // Check if the contract has enough allowance, otherwise approve the maximum amount
        uint256 swapAllowance = token.allowance(address(this), address(uniswapV3Router));
        if (swapAllowance < amountIn) {
            token.approve(address(uniswapV3Router), type(uint256).max);
        }

        // ExactInputSingleParams 
        IUniswapV3Router.ExactInputSingleParams memory params = IUniswapV3Router.ExactInputSingleParams(
            tokenIn,          
            address(iWETH),         
            fee,              
            address(this),       
            deadline,         
            amountIn,    
            amountOutMin,    
            0     
        );
 }

我先将数量为amountIn的代币转入合约,然后用amountIn发起swap,但是会出现转入合约的amountIn 为100,swap传入的amountIn为0.0002的情况,这是为什么呢,amountIn的值为何会改变?

请先 登录 后评论

最佳答案 2023-11-07 12:22

看下是不是池子深度不够这种情况,然后有 hash 的话丢个 hash

请先 登录 后评论

其它 0 个回答

  • 2 关注
  • 0 收藏,1520 浏览
  • 提出于 2023-11-05 17:13