Reflect Token Burn Function

Hi, I want to use the Reflect Token and want to use a burn mechanism within the contract until I reached a certain amount of total supply without effecting the users balance

I am using following function for that:

    function burn(uint amount) external {
        require(_tTotal > 3 * 10**8);
        _tTotal -= _tFeeTotal;
        _tTotal -= amount;
    }

If I check the totalSupply then it is reducing the totalSupply. Can someone agree that's the right way?
I want to add the funciton within each transaction which funciton is it? tranfer() or tranferFrom()?

Full Code:

contract REFLECT is Context, IERC20, Ownable {
    using SafeMath for uint256;
    using Address for address;

    mapping (address => uint256) private _rOwned;
    mapping (address => uint256) private _tOwned;
    mapping (address => mapping (address => uint256)) private _allowances;

    mapping (address => bool) private _isExcluded;
    address[] private _excluded;
   
    uint256 private constant MAX = ~uint256(0);
    //10 000 000 000 000
    uint256 _tTotal = 10 * 10**12;
    uint256 private _rTotal = (MAX - (MAX % _tTotal));
    uint256 private _tFeeTotal;

    string private _name = 'reflect.finance';
    string private _symbol = 'RFI';
    uint8 private _decimals = 18;

    constructor () public {
        _rOwned[_msgSender()] = _rTotal;
        emit Transfer(address(0), _msgSender(), _tTotal);
    }

    function burn(uint amount) external {
        require(_tTotal > 3 * 10**8);
        _tTotal -= _tFeeTotal;
        _tTotal -= amount;
    }
   function totalSupply() public view override returns (uint256) {
        return _tTotal;
    }
}


There are different types of burn in my opinion:

  1. reduce total supply
  2. reduce circulating supply

For the 2. you don't need any burn function. Just send tokens to dead wallet

Ok, would the code above not work?

You can reduce the gas cost significantly here:

You're currently doing:

  • 3 storage reads of _tTotal (each one consuming 2100 gas at the time of writing this answer)
  • 2 storage writes of _tTotal (each one consuming 5000 gas at the time of writing this answer)

You can reduce that to 1 read and 1 write:

uint256 total = _tTotal;
require(total > 3 * 10**8);
_tTotal = total - _tFeeTotal - amount;
1 Like