ERC20Burnable.sol 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.0;
  3. import "../ERC20.sol";
  4. import "../../../utils/Context.sol";
  5. /**
  6. * @dev Extension of {ERC20} that allows token holders to destroy both their own
  7. * tokens and those that they have an allowance for, in a way that can be
  8. * recognized off-chain (via event analysis).
  9. */
  10. abstract contract ERC20Burnable is Context, ERC20 {
  11. /**
  12. * @dev Destroys `amount` tokens from the caller.
  13. *
  14. * See {ERC20-_burn}.
  15. */
  16. function burn(uint256 amount) public virtual {
  17. _burn(_msgSender(), amount);
  18. }
  19. /**
  20. * @dev Destroys `amount` tokens from `account`, deducting from the caller's
  21. * allowance.
  22. *
  23. * See {ERC20-_burn} and {ERC20-allowance}.
  24. *
  25. * Requirements:
  26. *
  27. * - the caller must have allowance for ``accounts``'s tokens of at least
  28. * `amount`.
  29. */
  30. function burnFrom(address account, uint256 amount) public virtual {
  31. uint256 currentAllowance = allowance(account, _msgSender());
  32. require(currentAllowance >= amount, "ERC20: burn amount exceeds allowance");
  33. _approve(account, _msgSender(), currentAllowance - amount);
  34. _burn(account, amount);
  35. }
  36. }