|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +pragma solidity ^0.8.20; |
| 3 | + |
| 4 | +import {OwnableLib} from "@diamond/libraries/OwnableLib.sol"; |
| 5 | + |
| 6 | +/// @title OwnableRolesFacet |
| 7 | +/// @notice Simple single owner and multiroles authorization mixin. |
| 8 | +/// @author David Dada |
| 9 | +/// @author Modified from Solady (https://github.com/vectorized/solady/blob/main/src/auth/OwnableRoles.sol) |
| 10 | +/// |
| 11 | +/// @dev Note: |
| 12 | +/// This implementation does NOT auto-initialize the owner to `msg.sender`. |
| 13 | +/// You MUST call the `_initializeOwner` in the constructor / initializer. |
| 14 | +/// |
| 15 | +/// While the ownable portion follows |
| 16 | +/// [EIP-173](https://eips.ethereum.org/EIPS/eip-173) for compatibility, |
| 17 | +/// the nomenclature for the 2-step ownership handover may be unique to this codebase. |
| 18 | +contract OwnableFacet { |
| 19 | + /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ |
| 20 | + /* PUBLIC UPDATE FUNCTIONS */ |
| 21 | + /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ |
| 22 | + |
| 23 | + /// @dev Allows the owner to transfer the ownership to `newOwner`. |
| 24 | + function transferOwnership(address _newOwner) public onlyOwner { |
| 25 | + OwnableLib.transferOwnership(_newOwner); |
| 26 | + } |
| 27 | + |
| 28 | + /// @dev Allows the owner to renounce their ownership. |
| 29 | + function renounceOwnership() public onlyOwner { |
| 30 | + OwnableLib.renounceOwnership(); |
| 31 | + } |
| 32 | + |
| 33 | + /// @dev Request a two-step ownership handover to the caller. |
| 34 | + /// The request will automatically expire in 48 hours (172800 seconds) by default. |
| 35 | + function requestOwnershipHandover() public { |
| 36 | + OwnableLib.requestOwnershipHandover(); |
| 37 | + } |
| 38 | + |
| 39 | + /// @dev Cancels the two-step ownership handover to the caller, if any. |
| 40 | + function cancelOwnershipHandover() public { |
| 41 | + OwnableLib.cancelOwnershipHandover(); |
| 42 | + } |
| 43 | + |
| 44 | + /// @dev Allows the owner to complete the two-step ownership handover to `pendingOwner`. |
| 45 | + /// Reverts if there is no existing ownership handover requested by `pendingOwner`. |
| 46 | + function completeOwnershipHandover(address _pendingOwner) public onlyOwner { |
| 47 | + OwnableLib.completeOwnershipHandover(_pendingOwner); |
| 48 | + } |
| 49 | + |
| 50 | + /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ |
| 51 | + /* PUBLIC READ FUNCTIONS */ |
| 52 | + /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ |
| 53 | + |
| 54 | + /// @dev Returns the owner of the contract. |
| 55 | + function owner() public view returns (address) { |
| 56 | + return OwnableLib.owner(); |
| 57 | + } |
| 58 | + |
| 59 | + /// @dev Returns the expiry timestamp for the two-step ownership handover to `pendingOwner`. |
| 60 | + function ownershipHandoverExpiresAt(address _pendingOwner) public view returns (uint256) { |
| 61 | + return OwnableLib.ownershipHandoverExpiresAt(_pendingOwner); |
| 62 | + } |
| 63 | + |
| 64 | + /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ |
| 65 | + /* MODIFIERS */ |
| 66 | + /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ |
| 67 | + |
| 68 | + /// @dev Marks a function as only callable by the owner. |
| 69 | + modifier onlyOwner() { |
| 70 | + OwnableLib.checkOwner(); |
| 71 | + _; |
| 72 | + } |
| 73 | +} |
0 commit comments