-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* build: util contracts * fix: name * feat: virtualize * fix: two step gov
- Loading branch information
1 parent
ed73d39
commit b1ed340
Showing
8 changed files
with
119 additions
and
33 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
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
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
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,40 @@ | ||
// SPDX-License-Identifier: AGPL-3.0 | ||
pragma solidity 0.8.18; | ||
|
||
contract Clonable { | ||
/// @notice Set to the address to auto clone from. | ||
address public original; | ||
|
||
/** | ||
* @notice Clone the contracts default `original` contract. | ||
* @return Address of the new Minimal Proxy clone. | ||
*/ | ||
function _clone() internal virtual returns (address) { | ||
return _clone(original); | ||
} | ||
|
||
/** | ||
* @notice Clone any `_original` contract. | ||
* @return _newContract Address of the new Minimal Proxy clone. | ||
*/ | ||
function _clone( | ||
address _original | ||
) internal virtual returns (address _newContract) { | ||
// Copied from https://github.com/optionality/clone-factory/blob/master/contracts/CloneFactory.sol | ||
bytes20 addressBytes = bytes20(_original); | ||
assembly { | ||
// EIP-1167 bytecode | ||
let clone_code := mload(0x40) | ||
mstore( | ||
clone_code, | ||
0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000 | ||
) | ||
mstore(add(clone_code, 0x14), addressBytes) | ||
mstore( | ||
add(clone_code, 0x28), | ||
0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000 | ||
) | ||
_newContract := create(0, clone_code, 0x37) | ||
} | ||
} | ||
} |
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,40 @@ | ||
// SPDX-License-Identifier: AGPL-3.0 | ||
pragma solidity 0.8.18; | ||
|
||
import {Governance} from "./Governance.sol"; | ||
|
||
contract Governance2Step is Governance { | ||
/// @notice Emitted when the pending governance address is set. | ||
event UpdatePendingGovernance(address indexed newPendingGovernance); | ||
|
||
/// @notice Address that is set to take over governance. | ||
address public pendingGovernance; | ||
|
||
constructor(address _governance) Governance(_governance) {} | ||
|
||
/** | ||
* @notice Sets a new address as the `pendingGovernance` of the contract. | ||
* @dev Throws if the caller is not current governance. | ||
* @param _newGovernance The new governance address. | ||
*/ | ||
function transferGovernance( | ||
address _newGovernance | ||
) external virtual override onlyGovernance { | ||
require(_newGovernance != address(0), "ZERO ADDRESS"); | ||
pendingGovernance = _newGovernance; | ||
|
||
emit UpdatePendingGovernance(_newGovernance); | ||
} | ||
|
||
/** | ||
* @notice Allows the `pendingGovernance` to accept the role. | ||
*/ | ||
function acceptGovernance() external virtual { | ||
require(msg.sender == pendingGovernance, "!pending governance"); | ||
|
||
emit GovernanceTransferred(governance, msg.sender); | ||
|
||
governance = msg.sender; | ||
pendingGovernance = address(0); | ||
} | ||
} |