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;
}