// SPDX-License-Identifier: MIT pragma solidity 0.8.6; abstract contract OwnableData { address public owner; address public pendingOwner; } abstract contract Ownable is OwnableData { event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev `owner` defaults to msg.sender on construction. */ constructor() { _setOwner(msg.sender); } /** * @dev Transfers ownership to `newOwner`. Either directly or claimable by the new pending owner. * Can only be invoked by the current `owner`. * @param _newOwner Address of the new owner. * @param _direct True if `newOwner` should be set immediately. False if `newOwner` needs to use `claimOwnership`. */ function transferOwnership(address _newOwner, bool _direct) external onlyOwner { if (_direct) { require(_newOwner != address(0), "zero address"); emit OwnershipTransferred(owner, _newOwner); owner = _newOwner; pendingOwner = address(0); } else { pendingOwner = _newOwner; } } /** * @dev Needs to be called by `pendingOwner` to claim ownership. */ function claimOwnership() external { address _pendingOwner = pendingOwner; require(msg.sender == _pendingOwner, "caller != pending owner"); emit OwnershipTransferred(owner, _pendingOwner); owner = _pendingOwner; pendingOwner = address(0); } /** * @dev Throws if called by any account other than the Owner. */ modifier onlyOwner() { require(msg.sender == owner, "caller is not the owner"); _; } function _setOwner(address newOwner) internal { address oldOwner = owner; owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } }