Hi @Refresko,
If you create a fee on transfer or deflationary token (burn a percentage on transfer) this can cause issues when used with other contracts such as: https://medium.com/balancer-protocol/incident-with-non-standard-erc20-deflationary-tokens-95a0f6d46dea
From: Points to consider when creating a fungible token (ERC20, ERC777)
You were missing the keyword override that was introduced in Solidity 0.6, see: https://docs.soliditylang.org/en/v0.7.5/060-breaking-changes.html?highlight=override#how-to-update-your-code
The following code has not been tested nor audited. Deflationary tokens can cause issues. (see above)
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.2;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.1.0/contracts/token/ERC20/ERC20.sol";
contract MyToken is ERC20 {
uint256 private _minimumSupply = 2000 * (10 ** 18);
/**
* @dev Constructor that gives msg.sender all of existing tokens.
*/
constructor () public ERC20( "MyToken", "MTN") {
_mint(msg.sender, 10000 * (10 ** uint256(decimals())));
}
function transfer(address to, uint256 amount) public override returns (bool) {
return super.transfer(to, _partialBurn(amount));
}
function transferFrom(address from, address to, uint256 amount) public override 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.div(100);
uint256 availableBurn = totalSupply().sub(_minimumSupply);
if (burnAmount > availableBurn) {
burnAmount = availableBurn;
}
}
return burnAmount;
}
}