ERC20Burnable.sol 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts v4.4.0 (token/ERC20/extensions/ERC20Burnable.sol)
  3. pragma solidity ^0.8.0;
  4. import "../ERC20.sol";
  5. import "../../../utils/Context.sol";
  6. /**
  7. * @dev Extension of {ERC20} that allows token holders to destroy both their own
  8. * tokens and those that they have an allowance for, in a way that can be
  9. * recognized off-chain (via event analysis).
  10. */
  11. abstract contract ERC20Burnable is Context, ERC20 {
  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 currentAllowance = allowance(account, _msgSender());
  33. require(currentAllowance >= amount, "ERC20: burn amount exceeds allowance");
  34. unchecked {
  35. _approve(account, _msgSender(), currentAllowance - amount);
  36. }
  37. _burn(account, amount);
  38. }
  39. }