Stop Burn once it reaches a certain supply

Hello,

I am new to solidity and open zeppelin. Overall it seems quite straightforward, but I am stuck on something that, I am sure, is pretty simple to fix.
My smart contract has a burn function that reduces the total supply for each transaction. I am trying to implement a simple check of the total supply against the minimum supply. Once the total supply is lower or equal to the minimum supply the burn and fee should stop applying. I have tried a bunch of ways and tested via remix but the statement doesn't seem to work regardless.
Any idea of what I am doing wrong? Cheers

Sample function

    function transfer(address recipient, uint256 amount) public override returns(bool) {
        
        if(ExcludedFromFee[msg.sender] == true || isPresale) {
            _transfer(_msgSender(), recipient, amount);
        }
        
         else if(TotalSupply >= _minimunSupply) {
            uint burntAmount = amount.mul(Burn_Fee) / basePercent;
            uint ownerAmount = amount.mul(Dev_Fee)/ basePercent;
            _burn(_msgSender(), burntAmount);
            _transfer(_msgSender(), owner(), ownerAmount);
            _transfer(_msgSender(), recipient, amount.sub(burntAmount).sub(ownerAmount));
            
            
        } 
         else if(TotalSupply <= _minimunSupply) {
            uint burntAmount = 0;
            uint ownerAmount = 0;
            _transfer(_msgSender(), recipient, amount.sub(burntAmount).sub(ownerAmount));
             
         }
            
        return true;
    }

Hello @Joshua_Tree

When overloading the transfer function, the added logic doesn't apply to the transferFrom mechanism.

IMO you should hook into the _transfer internal function. Something like this:

    function _transfer(
        address sender,
        address recipient,
        uint256 amount
    ) internal virtual override {
        if (sender == address(0) || recipient == address(0) || ExcludedFromFee[sender] || isPresale || totalSupply() <= _minimunSupply) {
            super._transfer(sender, to, amount);
        } else {
            uint burntAmount = amount.mul(Burn_Fee) / basePercent;
            uint ownerAmount = amount.mul(Dev_Fee) / basePercent;
            _burn(sender, burntAmount);
            super._transfer(sender, owner(), ownerAmount);
            super._transfer(sender, recipient, amount.sub(burntAmount).sub(ownerAmount));
        }
    }
1 Like

Thank you very much @Amxx . It works fine now. A bit counterintuitive though! if you hadn't told me I probably wouldn't have been able to figure it out.

Cheers
Yuri