Hi, I'm new so please forgive this if it's a newbie question...
I have deployed this code to BNB TestNet and the initial Burn works on creation. However, when I create a liquidity pool and I use other wallets to swap from Pancakeswap, I do not see any Burn taking place. Is there something wrong with the code? Do Buy and Sell Burns work differently? Am I just completely wrong?
Here is the code:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract OneLoveBurn is ERC20, ERC20Burnable {
uint256 private constant TOTAL_SUPPLY = 420420000000 * 10**18; // Including 18 decimals
uint256 private constant INITIAL_BURN = 420000000 * 10**18; // Including 18 decimals
uint256 private constant MAX_HOLD_LIMIT_PERCENTAGE = 420; // 4.20% expressed as 420 / 10000
uint256 private constant BURN_PERCENTAGE = 420; // 4.20% expressed as 420 / 10000
uint256 private constant MINIMUM_CIRCULATING_SUPPLY = 420000000 * 10**18; // Minimum circulating supply
address public constant BURN_ADDRESS = 0x000000000000000000000000000000000000dEaD;
address public owner;
mapping(address => bool) public liquidityPools;
constructor() ERC20("41Love Burn - The best burn ever", "41LoveBURN") {
owner = msg.sender;
// Mint the total supply to the owner
_mint(owner, TOTAL_SUPPLY);
// Perform the initial burn
_transfer(owner, BURN_ADDRESS, INITIAL_BURN);
}
modifier onlyOwner() {
require(msg.sender == owner, "Caller is not the owner");
_;
}
function setLiquidityPool(address pool, bool isPool) external onlyOwner {
liquidityPools[pool] = isPool;
}
function transfer(address recipient, uint256 amount) public override returns (bool) {
_validateMaxHoldLimit(msg.sender, recipient, amount);
return super.transfer(recipient, amount);
}
function transferFrom(
address sender,
address recipient,
uint256 amount
) public override returns (bool) {
if (_isBuyOrSell(sender, recipient)) {
uint256 burnAmount = _calculateBurnAmount(amount);
if (burnAmount > 0) {
_transfer(sender, BURN_ADDRESS, burnAmount);
amount -= burnAmount;
}
}
_validateMaxHoldLimit(sender, recipient, amount);
return super.transferFrom(sender, recipient, amount);
}
function _calculateBurnAmount(uint256 amount) internal view returns (uint256) {
uint256 circulatingSupply = totalSupply() - balanceOf(BURN_ADDRESS);
if (circulatingSupply <= MINIMUM_CIRCULATING_SUPPLY) {
return 0; // Stop burning if circulating supply has reached the minimum
}
uint256 burnAmount = (amount * BURN_PERCENTAGE) / 10000;
// Ensure burn doesn't reduce circulating supply below the minimum
if (circulatingSupply - burnAmount < MINIMUM_CIRCULATING_SUPPLY) {
burnAmount = circulatingSupply - MINIMUM_CIRCULATING_SUPPLY;
}
return burnAmount;
}
function _isBuyOrSell(address sender, address recipient) internal view returns (bool) {
return liquidityPools[sender] || liquidityPools[recipient];
}
function _validateMaxHoldLimit(
address,
address recipient,
uint256 amount
) internal view {
uint256 maxLimit = (totalSupply() * MAX_HOLD_LIMIT_PERCENTAGE) / 10000;
require(amount <= maxLimit, "Transfer exceeds the maximum allowed percentage of total supply");
// Ensure recipient does not exceed the limit after receiving tokens
uint256 recipientBalance = balanceOf(recipient) + amount;
require(recipientBalance <= maxLimit, "Recipient balance exceeds the maximum allowed percentage");
}
function burn(uint256 amount) public override {
uint256 circulatingSupply = totalSupply() - balanceOf(BURN_ADDRESS);
require(circulatingSupply - amount >= MINIMUM_CIRCULATING_SUPPLY, "Cannot burn below the minimum circulating supply");
_transfer(msg.sender, BURN_ADDRESS, amount);
}
function burnFrom(address account, uint256 amount) public override {
uint256 circulatingSupply = totalSupply() - balanceOf(BURN_ADDRESS);
require(circulatingSupply - amount >= MINIMUM_CIRCULATING_SUPPLY, "Cannot burn below the minimum circulating supply");
uint256 currentAllowance = allowance(account, msg.sender);
require(currentAllowance >= amount, "ERC20: burn amount exceeds allowance");
_approve(account, msg.sender, currentAllowance - amount);
_transfer(account, BURN_ADDRESS, amount);
}
}