From 838bf2ddd0d437eafc108057ef71ac725ad8a53c Mon Sep 17 00:00:00 2001 From: Schlagonia Date: Fri, 20 Sep 2024 13:21:53 -0600 Subject: [PATCH] build: init gov --- src/utils/InitGov.sol | 76 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/utils/InitGov.sol diff --git a/src/utils/InitGov.sol b/src/utils/InitGov.sol new file mode 100644 index 0000000..8015eb8 --- /dev/null +++ b/src/utils/InitGov.sol @@ -0,0 +1,76 @@ +// SPDX-License-Identifier: AGPL-3.0 +pragma solidity ^0.8.18; + +import {Governance} from "./Governance.sol"; + +/// @notice Multi chain contract to be the initial governance for contracts on deployment. +contract InitGov { + address public constant SAFE = 0x33333333D5eFb92f19a5F94a43456b3cec2797AE; + + address public constant SIGNER_ONE = + 0xD7392bcc3D3611adF1793fDdaAAB4770772AC35A; + address public constant SIGNER_TWO = + 0xa05c4256ff0dd38697e63D48dF146e6e2FE7fe4A; + address public constant SIGNER_THREE = + 0x305af52AC31d3F9Daa1EC6231bA7b36Bb40f42f4; + address public constant SIGNER_FOUR = + 0x80f751EdcB3012d5AF5530AFE97d5dC6EE176Bc0; + address public constant SIGNER_FIVE = + 0x6d2b80BA79871281Be7F70b079996a052B8D62F4; + address public constant SIGNER_SIX = + 0x623d4A04e19328244924D1dee48252987C02fC0a; + + uint256 public constant THRESHOLD = 3; + + mapping(address => bool) public isSigner; + + mapping(bytes32 => uint256) public numberSigned; + + mapping(address => mapping(bytes32 => bool)) public signed; + + constructor() { + isSigner[SIGNER_ONE] = true; + isSigner[SIGNER_TWO] = true; + isSigner[SIGNER_THREE] = true; + isSigner[SIGNER_FOUR] = true; + isSigner[SIGNER_FIVE] = true; + isSigner[SIGNER_SIX] = true; + } + + /// @notice To sign a txn from an eoa. + function signTxn(address _contract, address _newGovernance) external { + require(isSigner[msg.sender], "!signer"); + bytes32 id = getTxnId(_contract, _newGovernance); + require(!signed[msg.sender][id], "already signer"); + + signed[msg.sender][id] = true; + numberSigned[id] += 1; + + // Execute if we have reached the threshold. + if (numberSigned[id] == THRESHOLD) + _transferGovernance(_contract, _newGovernance); + } + + /// @notice Can only be called by safe + function transferGovernance( + address _contract, + address _newGovernance + ) external { + require(msg.sender == SAFE, "!safe"); + _transferGovernance(_contract, _newGovernance); + } + + function _transferGovernance( + address _contract, + address _newGovernance + ) internal { + Governance(_contract).transferGovernance(_newGovernance); + } + + function getTxnId( + address _contract, + address _newGovernance + ) public pure returns (bytes32) { + return keccak256(abi.encodePacked(_contract, _newGovernance)); + } +}