Hello, I’m trying to create a token with a burn (2.5%) function but also a tax (2.5%) that would go to an ethereum address of our choice. This burn/tax function would act on each transfers (to and from).
Could you explain to me how to code both togeher on the following contract please ?
pragma solidity ^0.5.0;
import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
import "openzeppelin-solidity/contracts/token/ERC20/ERC20Detailed.sol";
contract MYTOKEN is ERC20, ERC20Detailed {
uint256 private _minimumSupply = 1000 * (10 ** 18);
/**
* @dev Constructor that gives msg.sender all of existing tokens.
*/
constructor () public ERC20Detailed("MYTOKEN", "MTK", 18) {
_mint(msg.sender, 15000 * (10 ** uint256(decimals())));
}
function transfer(address to, uint256 amount) public returns (bool) {
return super.transfer(to, _partialBurn(amount));
}
function transferFrom(address from, address to, uint256 amount) public returns (bool) {
return super.transferFrom(from, to, _partialBurn(amount));
}
function _partialBurn(uint256 amount) internal returns (uint256) {
uint256 burnAmount = _calculateBurnAmount(amount);
if (burnAmount > 0) {
_burn(msg.sender, burnAmount);
}
return amount.sub(burnAmount);
}
function _calculateBurnAmount(uint256 amount) internal view returns (uint256) {
uint256 burnAmount = 0;
// burn amount calculations
if (totalSupply() > _minimumSupply) {
burnAmount = amount.mul(2.5).div(100);
uint256 availableBurn = totalSupply().sub(_minimumSupply);
if (burnAmount > availableBurn) {
burnAmount = availableBurn;
}
}
return burnAmount;
}
}