15 地址转换错误?数组传参数问题 在研究自动swap相关功能,遇到如下问题: 1、接口的函数定义:

image.png

interface IBakerySwapRouter {
    function swapTokensForExactTokens(
    uint256 amountOut,
    uint256 amountInMax,
    address[] calldata path,
    address to,
    uint256 deadline
    ) external returns (uint256[] memory amounts);
}
function swapExactTokensForTokens() public onlyOwner returns (uint[] memory) {
        require(getPair() != address(0), "Cannot swapExactTokensForTokens, because the tokenPairAddress is zero");
        (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast) = getReserves();
        require(reserve0 > 0 && reserve1 > 0, "Cannot swapExactTokensForTokens, because the reserve0 or reserve1 is zero");

        uint amountIn = _totalWBNBBalance;
        uint amountOutMin = _totalWBNBBalance * bnbPrice / tokenPriceUpperLimit / (10 ** 14);
        address[] memory path = new address[](2);
        path[0] = address(wBnbTokenAddress);
        path[1] = address(buyTokenAddress);
        address to = msg.sender;
        uint deadline = now;
        uint[] memory swapResult = pancakeRouterContract.safeSwapExactTokensForTokens(amountIn, amountOutMin, path, to, deadline);
        return swapResult;
    }
请先 登录 后评论

最佳答案 6天前

你可以把接口修改为

interface IBakerySwapRouter {
function swapTokensForExactTokens(
uint256 amountOut,
uint256 amountInMax,
address[] memory path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
}
请先 登录 后评论

其它 1 个回答

Sunny
请先 登录 后评论