How can we able a user to burn the token if the contract is still pause? also same issue if we go for upgradeable smart contracts

what we want is according to artical 23 of MICA user can still burn the token while contract is pause.but he can't transfer the token or mint it .we try to overide the burn function but still can't do this ?any help or guide about this

// SPDX-License-Identifier: MIT
// Compatible with OpenZeppelin Contracts ^5.0.0
pragma solidity ^0.8.22;

import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {ERC20Burnable} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import {ERC20Pausable} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Pausable.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";

contract MyToken is ERC20, ERC20Burnable, ERC20Pausable, Ownable {
    constructor(address initialOwner)
        ERC20("MyToken", "MTK")
        Ownable(initialOwner)
    {}

    function pause() public onlyOwner {
        _pause();
    }

    function unpause() public onlyOwner {
        _unpause();
    }

    function mint(address to, uint256 amount) public onlyOwner {
        _mint(to, amount);
    }

    // The following functions are overrides required by Solidity.

    function _update(address from, address to, uint256 value)
        internal
        override(ERC20, ERC20Pausable)
    {
        super._update(from, to, value);
    }
}

Hi, welcome to the community! :wave:

If you want to burn tokens when contract is paused, maybe you can override the _update function like following:

    function _update(address from, address to, uint256 value)
        internal
        override(ERC20, ERC20Pausable)    {
        // Allow burns (transfers to the zero address) even when paused
        if (to == address(0)) {
            ERC20._update(from, to, value); // Skip pausing check for burns
        } else {
            ERC20Pausable._update(from, to, value); // Enforce pausing check for other transfers
        }
    }
1 Like

i got it thanks for reply .

1 Like