ERC-20 Pausable

ERC20 token with pausable token transfers, minting, and burning.

Useful for scenarios such as preventing trades until the end of an evaluation period, or having an emergency switch for freezing all token transfers in the event of a large bug.

Usage

In order to make your ERC20 token pausable, you need to use the Pausable contract and apply its mechanisms to ERC20 token functions as follows:

use openzeppelin_stylus::{
    token::erc20::Erc20,
    utils::Pausable,
};

sol_storage! {
    #[entrypoint]
    struct Erc20Example {
        #[borrow]
        Erc20 erc20;
        #[borrow]
        Pausable pausable;
    }
}

#[external]
#[inherit(Erc20, Pausable)]
impl Erc20Example {
    pub fn burn(&mut self, value: U256) -> Result<(), Vec<u8>> {
        // ...
        self.pausable.when_not_paused()?;
        // ...
        self.erc20.burn(value).map_err(|e| e.into())
    }

    pub fn burn_from(
        &mut self,
        account: Address,
        value: U256,
    ) -> Result<(), Vec<u8>> {
        // ...
        self.pausable.when_not_paused()?;
        // ...
        self.erc20.burn_from(account, value).map_err(|e| e.into())
    }

    pub fn mint(
        &mut self,
        account: Address,
        value: U256,
    ) -> Result<(), Vec<u8>> {
        // ...
        self.pausable.when_not_paused()?;
        // ...
        self.erc20._mint(account, value)?;
        Ok(())
    }


    pub fn transfer(
        &mut self,
        to: Address,
        value: U256,
    ) -> Result<bool, Vec<u8>> {
        // ...
        self.pausable.when_not_paused()?;
        // ...
        self.erc20.transfer(to, value).map_err(|e| e.into())
    }

    pub fn transfer_from(
        &mut self,
        from: Address,
        to: Address,
        value: U256,
    ) -> Result<bool, Vec<u8>> {
        // ...
        self.pausable.when_not_paused()?;
        // ...
        self.erc20.transfer_from(from, to, value).map_err(|e| e.into())
    }

}

Additionally, you need to ensure proper initialization during contract deployment. Make sure to include the following code in your Solidity Constructor:

contract Erc20Example {
    bool private _paused;

    constructor() {
        _paused = false;
    }
}