Defender PausableUpgradeable

I’m trying to implement the Pauseable functionality to my upgradeable contract to use with Defender.

I must do something wrong because Defender is not picking up the Pausable feature and shows;

Defender Admin could not determine whether this contract is pauseable. For a contract to be detected as pauseable by Defender, the provided ABI needs to specify a pause() function.

You can still add this contract to Defender Admin and run admin operations on it.

The doc mention using a Pausable() argument in the constructor. But what happens when we are using the initializer instead?

This is what I’m trying;

   // contracts/MyContract.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

// Imports from the OpenZeppelin Contracts library
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/utils/math/SafeMathUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";

contract MyContract is Initializable, PausableUpgradeable {

    using SafeMathUpgradeable for uint;
    
    uint256 private value;
    address private admin;

    /// @notice Events
    event ValueChanged(uint256 newValue);

    /// @notice initialize.
    /// @dev Upgradable Contract constructor
   
   function initialize(address _admin) public initializer {
        admin = _admin;
    }

    /// @notice store.
    /// @dev update the trading fees
    /// @param newValue uint

    function store(uint256 newValue)  public whenNotPaused{
      
        value = newValue;
        emit ValueChanged(newValue);
    }

    /// @notice retreive.
    /// @dev return value
   
    function retrieve() public view returns (uint256) {
        return value;
    }

    /// @notice pause
    /// @dev pause the contract
  function pause() public  whenNotPaused{
      _pause();
  }
    

}

Anyone know what I am missing?

1 Like

Hi @madeindreams,

You need to initialize the pause functionality calling __Pausable_init in your initialize function:

See the documentation: https://docs.openzeppelin.com/contracts/4.x/upgradeable#usage

3 Likes

A post was split to a new topic: whenNotPaused modifier throws a compilation error when applying to pure functions