Hello,
Im trying to create a token with 1% buy/sell limit and 1% maximum Hold but be able to switch it off later but when I test the code I still able to buy more than 1% . Not sure where is the mistake
I released a token on BNB for test (for cheap gas fees) but was able to buy from another wallet more than 1%
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract TEST is ERC20, Ownable {
uint256 public buyLimitPercent = 1; // 1% buy limit
uint256 public sellLimitPercent = 1; // 1% sell limit
bool public limitHoldingEnabled = true; // Enable/disable the holding limit
constructor(address initialOwner)
ERC20("TEST", "TEST") // Updated token name and symbol to TEST
Ownable(initialOwner)
{
_mint(msg.sender, 1000000000000 * 10 ** decimals());
}
// Function to set buy limit
function setBuyLimit(uint256 newLimitPercent) external onlyOwner {
require(newLimitPercent <= 100, "Invalid limit"); // Ensure the limit is not greater than 100%
buyLimitPercent = newLimitPercent;
}
// Function to set sell limit
function setSellLimit(uint256 newLimitPercent) external onlyOwner {
require(newLimitPercent <= 100, "Invalid limit"); // Ensure the limit is not greater than 100%
sellLimitPercent = newLimitPercent;
}
// Function to enable or disable holding limit
function setLimitHoldingEnabled(bool isEnabled) external onlyOwner {
limitHoldingEnabled = isEnabled;
}
// Function to remove buy/sell limit
function removeLimits() external onlyOwner {
buyLimitPercent = 0;
sellLimitPercent = 0;
}
// Function to transfer with limits
function transferWithLimits(address recipient, uint256 amount) external {
require(recipient != address(0), "Transfer to the zero address");
require(amount > 0, "Transfer amount must be greater than zero");
if (buyLimitPercent > 0 && limitHoldingEnabled) {
// Check buy limit
uint256 buyLimit = (totalSupply() * buyLimitPercent) / 100;
require(balanceOf(msg.sender) + amount <= buyLimit, "Buy amount exceeds limit");
}
if (sellLimitPercent > 0 && limitHoldingEnabled) {
// Check sell limit
uint256 sellLimit = (totalSupply() * sellLimitPercent) / 100;
require(balanceOf(recipient) + amount <= sellLimit, "Sell amount exceeds limit");
}
_transfer(msg.sender, recipient, amount);
}
}
[link] [comments]
You can get bonuses upto $100 FREE BONUS when you:
π° Install these recommended apps:
π² SocialGood - 100% Crypto Back on Everyday Shopping
π² xPortal - The DeFi For The Next Billion
π² CryptoTab Browser - Lightweight, fast, and ready to mine!
π° Register on these recommended exchanges:
π‘ Binanceπ‘ Bitfinexπ‘ Bitmartπ‘ Bittrexπ‘ Bitget
π‘ CoinExπ‘ Crypto.comπ‘ Gate.ioπ‘ Huobiπ‘ Kucoin.
Comments