Skip to content

Commit

Permalink
feat: use AccessControl
Browse files Browse the repository at this point in the history
  • Loading branch information
the-emerald committed Jan 10, 2025
1 parent 7303dfd commit 238a905
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/WanderStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import {SafeERC20, IERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeE

import {PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {AccessControlUpgradeable} from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";

contract WanderStaking is Initializable, PausableUpgradeable, OwnableUpgradeable, UUPSUpgradeable {
contract WanderStaking is Initializable, PausableUpgradeable, AccessControlUpgradeable, UUPSUpgradeable {
using SafeERC20 for IERC20;

bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
bytes32 public constant UPGRADER_ROLE = keccak256("UPGRADER_ROLE");

event Stake(address indexed user, uint256 amount);
event Unstake(address indexed user, uint256 amount);
event SpendFromStake(address indexed user, address indexed to, uint256 amount);
Expand All @@ -27,23 +30,27 @@ contract WanderStaking is Initializable, PausableUpgradeable, OwnableUpgradeable
_disableInitializers();
}

function initialize(address initialOwner, IERC20 _token) public initializer {
function initialize(address admin, IERC20 _token) public initializer {
__Pausable_init();
__Ownable_init(initialOwner);
__AccessControl_init();
__UUPSUpgradeable_init();

_grantRole(DEFAULT_ADMIN_ROLE, admin);
_grantRole(PAUSER_ROLE, admin);
_grantRole(UPGRADER_ROLE, admin);

token = _token;
}

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

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

function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}
function _authorizeUpgrade(address newImplementation) internal override onlyRole(UPGRADER_ROLE) {}

function stake(uint256 amount) external whenNotPaused {
if (amount == 0) {
Expand Down

0 comments on commit 238a905

Please sign in to comment.