ERC20BurnableUpgradeable.sol 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/ERC20Burnable.sol)
  3. pragma solidity ^0.8.0;
  4. import "../ERC20Upgradeable.sol";
  5. import "../../../utils/ContextUpgradeable.sol";
  6. import "../../../proxy/utils/Initializable.sol";
  7. /**
  8. * @dev Extension of {ERC20} that allows token holders to destroy both their own
  9. * tokens and those that they have an allowance for, in a way that can be
  10. * recognized off-chain (via event analysis).
  11. */
  12. abstract contract ERC20BurnableUpgradeable is Initializable, ContextUpgradeable, ERC20Upgradeable {
  13. function __ERC20Burnable_init() internal onlyInitializing {
  14. __Context_init_unchained();
  15. __ERC20Burnable_init_unchained();
  16. }
  17. function __ERC20Burnable_init_unchained() internal onlyInitializing {
  18. }
  19. /**
  20. * @dev Destroys `amount` tokens from the caller.
  21. *
  22. * See {ERC20-_burn}.
  23. */
  24. function burn(uint256 amount) public virtual {
  25. _burn(_msgSender(), amount);
  26. }
  27. /**
  28. * @dev Destroys `amount` tokens from `account`, deducting from the caller's
  29. * allowance.
  30. *
  31. * See {ERC20-_burn} and {ERC20-allowance}.
  32. *
  33. * Requirements:
  34. *
  35. * - the caller must have allowance for ``accounts``'s tokens of at least
  36. * `amount`.
  37. */
  38. function burnFrom(address account, uint256 amount) public virtual {
  39. uint256 currentAllowance = allowance(account, _msgSender());
  40. require(currentAllowance >= amount, "ERC20: burn amount exceeds allowance");
  41. unchecked {
  42. _approve(account, _msgSender(), currentAllowance - amount);
  43. }
  44. _burn(account, amount);
  45. }
  46. uint256[50] private __gap;
  47. }