-
Notifications
You must be signed in to change notification settings - Fork 4
/
OwnableUDS.sol
55 lines (39 loc) · 1.35 KB
/
OwnableUDS.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {Initializable} from "../utils/Initializable.sol";
// ------------- storage
bytes32 constant DIAMOND_STORAGE_OWNABLE = keccak256("diamond.storage.ownable");
function s() pure returns (OwnableDS storage diamondStorage) {
bytes32 slot = DIAMOND_STORAGE_OWNABLE;
assembly {
diamondStorage.slot := slot
}
}
struct OwnableDS {
address owner;
}
// ------------- errors
error CallerNotOwner();
/// @title Ownable (Upgradeable Diamond Storage)
/// @author phaze (https://github.com/0xPhaze/UDS)
/// @dev Requires `__Ownable_init` to be called in proxy
abstract contract OwnableUDS is Initializable {
OwnableDS private __storageLayout; // storage layout for upgrade compatibility checks
event OwnerChanged(address oldOwner, address newOwner);
function __Ownable_init() internal initializer {
s().owner = msg.sender;
}
/* ------------- external ------------- */
function owner() public view returns (address) {
return s().owner;
}
function transferOwnership(address newOwner) external onlyOwner {
s().owner = newOwner;
emit OwnerChanged(msg.sender, newOwner);
}
/* ------------- modifier ------------- */
modifier onlyOwner() {
if (msg.sender != s().owner) revert CallerNotOwner();
_;
}
}