MultiversX Tracker is Live!

Can someone check the code for my ERC-20 ! Trying to add 1% buy limit but not working

Etherum Reddit

More / Etherum Reddit 32 Views

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

}

}

submitted by /u/Some_Ad_1020
[link] [comments]
Get BONUS $200 for FREE!

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