generated from ZeframLou/foundry-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use BoringOwnable for VeRecipient
- Loading branch information
Showing
5 changed files
with
73 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule boringsolidity
deleted from
78f481
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
// Source: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol + Claimable.sol | ||
// Simplified by BoringCrypto | ||
|
||
contract BoringOwnableData { | ||
address public owner; | ||
address public pendingOwner; | ||
} | ||
|
||
contract BoringOwnable is BoringOwnableData { | ||
error BoringOwnable__ZeroAddress(); | ||
error BoringOwnable__NotPendingOwner(); | ||
error BoringOwnable__NotOwner(); | ||
|
||
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); | ||
|
||
constructor(address owner_) { | ||
owner = owner_; | ||
emit OwnershipTransferred(address(0), owner_); | ||
} | ||
|
||
/// @notice 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`. | ||
/// @param renounce Allows the `newOwner` to be `address(0)` if `direct` and `renounce` is True. Has no effect otherwise. | ||
function transferOwnership(address newOwner, bool direct, bool renounce) public onlyOwner { | ||
if (direct) { | ||
// Checks | ||
if (newOwner == address(0) && !renounce) revert BoringOwnable__ZeroAddress(); | ||
|
||
// Effects | ||
emit OwnershipTransferred(owner, newOwner); | ||
owner = newOwner; | ||
pendingOwner = address(0); | ||
} else { | ||
// Effects | ||
pendingOwner = newOwner; | ||
} | ||
} | ||
|
||
/// @notice Needs to be called by `pendingOwner` to claim ownership. | ||
function claimOwnership() public { | ||
address _pendingOwner = pendingOwner; | ||
|
||
// Checks | ||
if (msg.sender != _pendingOwner) revert BoringOwnable__NotPendingOwner(); | ||
|
||
// Effects | ||
emit OwnershipTransferred(owner, _pendingOwner); | ||
owner = _pendingOwner; | ||
pendingOwner = address(0); | ||
} | ||
|
||
/// @notice Only allows the `owner` to execute the function. | ||
modifier onlyOwner() { | ||
if (msg.sender != owner) revert BoringOwnable__NotOwner(); | ||
_; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters