-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOwnableUpgradeable.sol
76 lines (67 loc) · 2.14 KB
/
OwnableUpgradeable.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// SPDX-License-Identifier: MIT
pragma solidity 0.8.10;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
/**
* @title OwnableUpgradeable
* @dev The contract provides a basic access control mechanism, where there is
* an account (an owner) that can be granted exclusive access to specific
* functions.
*
* By default, the owner account will be the one that deploys the contract.
* This can later be changed through a two-step process:
* {transferOwnership, claimOwnership}
*
* The contract is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to functions to restrict their use to the
* owner.
*/
contract OwnableUpgradeable is Initializable {
address private _owner;
address private _pendingOwner;
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
/**
* @dev The contract constructor that sets the original `owner` of the
* contract to the sender account.
*/
function initialize() internal onlyInitializing {
_owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == _owner, "ce30");
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Returns the address of the pending owner.
*/
function pendingOwner() public view returns (address) {
return _pendingOwner;
}
/**
* @dev Allows the current owner to set the pendingOwner address.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) public onlyOwner {
_pendingOwner = newOwner;
}
/**
* @dev Allows the pendingOwner address to finalize the transfer.
*/
function claimOwnership() public {
require(msg.sender == _pendingOwner, "ce31");
_owner = _pendingOwner;
_pendingOwner = address(0);
emit OwnershipTransferred(_owner, _pendingOwner);
}
}