Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Last active May 13, 2021 20:33
Show Gist options
  • Save percybolmer/15fe85ecd84dec89c2ae6067f9443907 to your computer and use it in GitHub Desktop.
Save percybolmer/15fe85ecd84dec89c2ae6067f9443907 to your computer and use it in GitHub Desktop.
Crypto-BEP20-BurnAndMintv2
/**
* @notice _mint will create tokens on the address inputted and then increase the total supply
*
* It will also emit an Transfer event, with sender set to zero address (adress(0))
*
* Requires that the address that is recieveing the tokens is not zero address
*/
function _mint(address account, uint256 amount) internal {
require(account != address(0), "DevToken: cannot mint to zero address");
// Increase total supply
_totalSupply = _totalSupply + (amount);
// Add amount to the account balance using the balance mapping
_balances[account] = _balances[account] + amount;
// Emit our event to log the action
emit Transfer(address(0), account, amount);
}
/**
* @notice _burn will destroy tokens from an address inputted and then decrease total supply
* An Transfer event will emit with receiever set to zero address
*
* Requires
* - Account cannot be zero
* - Account balance has to be bigger or equal to amount
*/
function _burn(address account, uint256 amount) internal {
require(account != address(0), "DevToken: cannot burn from zero address");
require(_balances[account] >= amount, "DevToken: Cannot burn more than the account owns");
// Remove the amount from the account balance
_balances[account] = _balances[account] - amount;
// Decrease totalSupply
_totalSupply = _totalSupply - amount;
// Emit event, use zero address as reciever
emit Transfer(account, address(0), amount);
}
/**
* @notice burn is used to destroy tokens on an address
*
* See {_burn}
* Requires
* - msg.sender must be the token owner
*
*/
function burn(address account, uint256 amount) public returns(bool) {
_burn(account, amount);
return true;
}
/**
* @notice mint is used to create tokens and assign them to msg.sender
*
* See {_mint}
* Requires
* - msg.sender must be the token owner
*
*/
function mint(address account, uint256 amount) public returns(bool){
_mint(account, amount);
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment