ERC20Burnable.sol 1.1 KB

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