用REMIX部署uniswap v3合约,这个编译错误如何修改?

1726104735386.png

function _v2Swap(address[] calldata path, address recipient, address pair) private { unchecked { if (path.length < 2) revert V2InvalidPath();

        // cached to save on duplicate operations
        (address token0,) = UniswapV2Library.sortTokens(path[0], path[1]);
        uint256 finalPairIndex = path.length - 1;
        uint256 penultimatePairIndex = finalPairIndex - 1;
        for (uint256 i; i &lt; finalPairIndex; i++) {
            (address input, address output) = (path[i], path[i + 1]);
            (uint256 reserve0, uint256 reserve1,) = IUniswapV2Pair(pair).getReserves();
            (uint256 reserveInput, uint256 reserveOutput) =
                input == token0 ? (reserve0, reserve1) : (reserve1, reserve0);
            uint256 amountInput = ERC20(input).balanceOf(pair) - reserveInput;
            uint256 amountOutput = UniswapV2Library.getAmountOut(amountInput, reserveInput, reserveOutput);
            (uint256 amount0Out, uint256 amount1Out) =
                input == token0 ? (uint256(0), amountOutput) : (amountOutput, uint256(0));
            address nextPair;
            if (i &lt; penultimatePairIndex){
                 (nextPair, token0) = UniswapV2Library.pairAndToken0For(
                    UNISWAP_V2_FACTORY, UNISWAP_V2_PAIR_INIT_CODE_HASH, output, path[i + 2]
                );
            }else{
                (nextPair, token0) = (recipient, address(0));
            }
            //(nextPair, token0) = i &lt; penultimatePairIndex
            //    ? UniswapV2Library.pairAndToken0For(
            //        UNISWAP_V2_FACTORY, UNISWAP_V2_PAIR_INIT_CODE_HASH, output, path[i + 2]
            //    )
            //    : (recipient, address(0));

            IUniswapV2Pair(pair).swap(amount0Out, amount1Out, nextPair, new bytes(0));
            pair = nextPair;
        }
    }
}
请先 登录 后评论

3 个回答

张文阁
请先 登录 后评论
Alan
请先 登录 后评论
Leo
请先 登录 后评论
  • 3 关注
  • 0 收藏,579 浏览
  • 张文阁 提出于 2024-09-12 09:33