-
Notifications
You must be signed in to change notification settings - Fork 3
/
UpgradeableContract.sol
56 lines (44 loc) · 1.96 KB
/
UpgradeableContract.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// SPDX-License-Identifier: CC0-1.0
/// @title Upgradeable Contract with Access Control
/**
* ><< ><<<<< ><< ><< ><<
* > ><< ><< ><< ><<
* >< ><< ><< ><< ><<
* ><< ><< ><< ><< ><<
* ><<<< >< ><< ><< ><< ><<
* ><< ><< ><<<< ><<<<
*/
pragma solidity ^0.8.17;
import "openzeppelin-upgradeable/proxy/utils/Initializable.sol";
import "openzeppelin-upgradeable/access/AccessControlUpgradeable.sol";
import "openzeppelin-upgradeable/access/OwnableUpgradeable.sol";
import "openzeppelin-upgradeable/proxy/utils/UUPSUpgradeable.sol";
contract UpgradeableContract is Initializable, AccessControlUpgradeable, OwnableUpgradeable, UUPSUpgradeable {
bytes32 public constant UPGRADER_ROLE = keccak256("UPGRADER_ROLE");
bytes32 public constant WITHDRAW_ROLE = keccak256("WITHDRAW_ROLE");
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}
function initialize(address admin) public initializer {
__AccessControl_init();
__UUPSUpgradeable_init();
_grantRole(DEFAULT_ADMIN_ROLE, admin);
_grantRole(UPGRADER_ROLE, admin);
_grantRole(WITHDRAW_ROLE, admin);
_transferOwnership(admin);
}
function transferOwnership(address newOwner) public virtual override onlyRole(DEFAULT_ADMIN_ROLE) {
_transferOwnership(newOwner);
}
function _authorizeUpgrade(address newImplementation) internal override onlyRole(UPGRADER_ROLE) {}
function withdraw() external onlyRole(WITHDRAW_ROLE) {
payable(msg.sender).transfer(address(this).balance);
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
}