ERC20BurnableUpgradeable.sol 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. }
  15. function __ERC20Burnable_init_unchained() internal onlyInitializing {
  16. }
  17. /**
  18. * @dev Destroys `amount` tokens from the caller.
  19. *
  20. * See {ERC20-_burn}.
  21. */
  22. function burn(uint256 amount) public virtual {
  23. _burn(_msgSender(), amount);
  24. }
  25. /**
  26. * @dev Destroys `amount` tokens from `account`, deducting from the caller's
  27. * allowance.
  28. *
  29. * See {ERC20-_burn} and {ERC20-allowance}.
  30. *
  31. * Requirements:
  32. *
  33. * - the caller must have allowance for ``accounts``'s tokens of at least
  34. * `amount`.
  35. */
  36. function burnFrom(address account, uint256 amount) public virtual {
  37. uint256 currentAllowance = allowance(account, _msgSender());
  38. require(currentAllowance >= amount, "ERC20: burn amount exceeds allowance");
  39. unchecked {
  40. _approve(account, _msgSender(), currentAllowance - amount);
  41. }
  42. _burn(account, amount);
  43. }
  44. /**
  45. * This empty reserved space is put in place to allow future versions to add new
  46. * variables without shifting down storage in the inheritance chain.
  47. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
  48. */
  49. uint256[50] private __gap;
  50. }