ERC20Burnable.sol 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity >=0.6.0 <0.8.0;
  3. import "../../GSN/Context.sol";
  4. import "./ERC20.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. using SafeMath for uint256;
  12. /**
  13. * @dev Destroys `amount` tokens from the caller.
  14. *
  15. * See {ERC20-_burn}.
  16. */
  17. function burn(uint256 amount) public virtual {
  18. _burn(_msgSender(), amount);
  19. }
  20. /**
  21. * @dev Destroys `amount` tokens from `account`, deducting from the caller's
  22. * allowance.
  23. *
  24. * See {ERC20-_burn} and {ERC20-allowance}.
  25. *
  26. * Requirements:
  27. *
  28. * - the caller must have allowance for ``accounts``'s tokens of at least
  29. * `amount`.
  30. */
  31. function burnFrom(address account, uint256 amount) public virtual {
  32. uint256 decreasedAllowance = allowance(account, _msgSender()).sub(amount, "ERC20: burn amount exceeds allowance");
  33. _approve(account, _msgSender(), decreasedAllowance);
  34. _burn(account, amount);
  35. }
  36. }