// SPDX-License-Identifier: BSD-3-Clausepragmasolidity ^0.8.15;import"./GovernorBravoInterfaces.sol";
contractGovernorBravoDelegatorisGovernorBravoDelegatorStorage, GovernorBravoEvents{
constructor(address timelock_,
address hifi_,
address admin_,
address implementation_,
uint256 votingPeriod_,
uint256 votingDelay_,
uint256 proposalThreshold_
) {
// Admin set to msg.sender for initialization
admin =msg.sender;
delegateTo(
implementation_,
abi.encodeWithSignature(
"initialize(address,address,uint256,uint256,uint256)",
timelock_,
hifi_,
votingPeriod_,
votingDelay_,
proposalThreshold_
)
);
_setImplementation(implementation_);
admin = admin_;
}
/**
* @notice Called by the admin to update the implementation of the delegator
* @param implementation_ The address of the new implementation for delegation
*/function_setImplementation(address implementation_) public{
require(msg.sender== admin, "GovernorBravoDelegator::_setImplementation: admin only");
require(
implementation_ !=address(0),
"GovernorBravoDelegator::_setImplementation: invalid implementation address"
);
address oldImplementation = implementation;
implementation = implementation_;
emit NewImplementation(oldImplementation, implementation);
}
/**
* @notice Internal method to delegate execution to another contract
* @dev It returns to the external caller whatever the implementation returns or forwards reverts
* @param callee The contract to delegatecall
* @param data The raw data to delegatecall
*/functiondelegateTo(address callee, bytesmemory data) internal{
(bool success, bytesmemory returnData) = callee.delegatecall(data);
assembly {
ifeq(success, 0) {
revert(add(returnData, 0x20), returndatasize())
}
}
}
/**
* @dev Delegates the current call to implementation.
*
* This function does not return to its internall call site, it will return directly to the external caller.
*/function_fallback() internal{
// delegate all other functions to current implementation
(bool success, ) = implementation.delegatecall(msg.data);
assembly {
let free_mem_ptr :=mload(0x40)
returndatacopy(free_mem_ptr, 0, returndatasize())
switch success
case0 {
revert(free_mem_ptr, returndatasize())
}
default {
return(free_mem_ptr, returndatasize())
}
}
}
/**
* @dev Delegates execution to an implementation contract.
* It returns to the external caller whatever the implementation returns or forwards reverts.
*/fallback() externalpayable{
_fallback();
}
/**
* @dev Fallback function that delegates calls to implementation. Will run if call data is empty.
*/receive() externalpayable{
_fallback();
}
}
Contract Source Code
File 2 of 2: GovernorBravoInterfaces.sol
// SPDX-License-Identifier: BSD-3-Clausepragmasolidity ^0.8.15;contractGovernorBravoEvents{
/// @notice An event emitted when a new proposal is createdeventProposalCreated(uint256 id,
address proposer,
address[] targets,
uint256[] values,
string[] signatures,
bytes[] calldatas,
uint256 startBlock,
uint256 endBlock,
string description
);
/// @notice An event emitted when a vote has been cast on a proposal/// @param voter The address which casted a vote/// @param proposalId The proposal id which was voted on/// @param support Support value for the vote. 0=against, 1=for, 2=abstain/// @param votes Number of votes which were cast by the voter/// @param reason The reason given for the vote by the votereventVoteCast(addressindexed voter, uint256 proposalId, uint8 support, uint256 votes, string reason);
/// @notice An event emitted when a proposal has been canceledeventProposalCanceled(uint256 id);
/// @notice An event emitted when a proposal has been queued in the TimelockeventProposalQueued(uint256 id, uint256 eta);
/// @notice An event emitted when a proposal has been executed in the TimelockeventProposalExecuted(uint256 id);
/// @notice An event emitted when the voting delay is seteventVotingDelaySet(uint256 oldVotingDelay, uint256 newVotingDelay);
/// @notice An event emitted when the voting period is seteventVotingPeriodSet(uint256 oldVotingPeriod, uint256 newVotingPeriod);
/// @notice Emitted when implementation is changedeventNewImplementation(address oldImplementation, address newImplementation);
/// @notice Emitted when proposal threshold is seteventProposalThresholdSet(uint256 oldProposalThreshold, uint256 newProposalThreshold);
/// @notice Emitted when pendingAdmin is changedeventNewPendingAdmin(address oldPendingAdmin, address newPendingAdmin);
/// @notice Emitted when pendingAdmin is accepted, which means admin is updatedeventNewAdmin(address oldAdmin, address newAdmin);
}
contractGovernorBravoDelegatorStorage{
/// @notice Administrator for this contractaddresspublic admin;
/// @notice Pending administrator for this contractaddresspublic pendingAdmin;
/// @notice Active brains of Governoraddresspublic implementation;
}
/**
* @title Storage for Governor Bravo Delegate
* @notice For future upgrades, do not change GovernorBravoDelegateStorageV1. Create a new
* contract which implements GovernorBravoDelegateStorageV1 and following the naming convention
* GovernorBravoDelegateStorageVX.
*/contractGovernorBravoDelegateStorageV1isGovernorBravoDelegatorStorage{
/// @notice The delay before voting on a proposal may take place, once proposed, in blocksuint256public votingDelay;
/// @notice The duration of voting on a proposal, in blocksuint256public votingPeriod;
/// @notice The number of votes required in order for a voter to become a proposeruint256public proposalThreshold;
/// @notice The total number of proposalsuint256public proposalCount;
/// @notice The address of the Hifi Protocol Timelock
TimelockInterface public timelock;
/// @notice The address of the Hifi governance token
HifiInterface public hifi;
/// @notice The official record of all proposals ever proposedmapping(uint256=> Proposal) public proposals;
/// @notice The latest proposal for each proposermapping(address=>uint256) public latestProposalIds;
structProposal {
/// @notice Unique id for looking up a proposaluint256 id;
/// @notice Creator of the proposaladdress proposer;
/// @notice The timestamp that the proposal will be available for execution, set once the vote succeedsuint256 eta;
/// @notice The ordered list of target addresses for calls to be madeaddress[] targets;
/// @notice The ordered list of values (i.e. msg.value) to be passed to the calls to be madeuint256[] values;
/// @notice The ordered list of function signatures to be calledstring[] signatures;
/// @notice The ordered list of calldata to be passed to each callbytes[] calldatas;
/// @notice The block at which voting begins: holders must delegate their votes prior to this blockuint256 startBlock;
/// @notice The block at which voting ends: votes must be cast prior to this blockuint256 endBlock;
/// @notice Current number of votes in favor of this proposaluint256 forVotes;
/// @notice Current number of votes in opposition to this proposaluint256 againstVotes;
/// @notice Current number of votes for abstaining for this proposaluint256 abstainVotes;
/// @notice Flag marking whether the proposal has been canceledbool canceled;
/// @notice Flag marking whether the proposal has been executedbool executed;
/// @notice Receipts of ballots for the entire set of votersmapping(address=> Receipt) receipts;
}
/// @notice Ballot receipt record for a voterstructReceipt {
/// @notice Whether or not a vote has been castbool hasVoted;
/// @notice Whether or not the voter supports the proposal or abstainsuint8 support;
/// @notice The number of votes the voter had, which were castuint96 votes;
}
/// @notice Possible states that a proposal may be inenumProposalState {
Pending,
Active,
Canceled,
Defeated,
Succeeded,
Queued,
Expired,
Executed
}
}
interfaceTimelockInterface{
functiondelay() externalviewreturns (uint256);
functionGRACE_PERIOD() externalviewreturns (uint256);
functionacceptAdmin() external;
functionqueuedTransactions(bytes32 hash) externalviewreturns (bool);
functionqueueTransaction(address target,
uint256 value,
stringcalldata signature,
bytescalldata data,
uint256 eta
) externalreturns (bytes32);
functioncancelTransaction(address target,
uint256 value,
stringcalldata signature,
bytescalldata data,
uint256 eta
) external;
functionexecuteTransaction(address target,
uint256 value,
stringcalldata signature,
bytescalldata data,
uint256 eta
) externalpayablereturns (bytesmemory);
}
interfaceHifiInterface{
functiongetPriorVotes(address account, uint256 blockNumber) externalviewreturns (uint96);
functiontotalSupply() externalviewreturns (uint256);
}