Max wallet limit

Hi everyone,

I'm trying to setup a smart contract on BSC testnet that limits buys, sells and maxwallet. Everything seems to be working fine, apart from users cannot sell tokens (any amount!) When I set the maxWalletLimit to 100% everything works. My question is, can anyone see what is going wrong? Is the maxWalletLimit being applied to something that would throw an error? Could it be checking the contract balance and not transferring to it because it holds so many tokens?

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract BRO is ERC20, Ownable {
    uint256 private constant MAX_SUPPLY = 32_000_000 * 10**18;
    uint256 public maxTransferLimitPercent = 1; // Default to 1%, adjust as needed
    uint256 public maxWalletLimitPercent = 1; // Default to 1%, adjust as needed
    address public router = 0xD99D1c33F9fC3444f8101754aBC46c52416550D1; // Testnet router address

    event MaxTransferLimitChanged(uint256 newPercent);
    event MaxWalletLimitChanged(uint256 newPercent);

    constructor() ERC20("BRO", "BRO") Ownable() {
        _mint(msg.sender, MAX_SUPPLY);
    }

    modifier checkTransferLimits(address to, uint256 amount) {
        if (msg.sender != owner() && msg.sender != router) {
            uint256 toBalance = balanceOf(to);
            uint256 maxTransferLimit = (MAX_SUPPLY * maxTransferLimitPercent) / 100;
            uint256 maxWalletLimit = (MAX_SUPPLY * maxWalletLimitPercent) / 100;
            require(
                amount <= maxTransferLimit &&
                (toBalance + amount) <= maxWalletLimit,
                "Transfer amount exceeds max allowed for users"
            );
        }
        _;
    }

    function transfer(address recipient, uint256 amount) public virtual override checkTransferLimits(recipient, amount) returns (bool) {
        return super.transfer(recipient, amount);
    }

    function transferFrom(address sender, address recipient, uint256 amount) public virtual override checkTransferLimits(recipient, amount) returns (bool) {
        return super.transferFrom(sender, recipient, amount);
    }

    function setMaxTransferLimitPercent(uint256 newPercent) external onlyOwner {
        require(newPercent <= 10, "Limit Too High");
        maxTransferLimitPercent = newPercent;
        emit MaxTransferLimitChanged(newPercent);
    }

    function setMaxWalletLimitPercent(uint256 newPercent) external onlyOwner {
        require(newPercent <= 10, "Limit Too High");
        maxWalletLimitPercent = newPercent;
        emit MaxWalletLimitChanged(newPercent);
    }

    function setRouter(address _router) external onlyOwner {
        router = _router;
    }

    function renounceOwnership() public override onlyOwner {
        super.renounceOwnership();
    }
}

I found out through trial and error it was being limited by the pancakeswap factory pair.

If there an easy way to pull this into my contract or should I just specify it manually?

What do you mean with this? Pancake can't limit in any way.
You issue is that you are using maxWalelt for the pair too, so it can't have more than maxWallet tokens in the reserve. You should exclude the pair from this check.