generated from ScopeLift/foundry-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
L1VotePool.sol
58 lines (45 loc) · 1.91 KB
/
L1VotePool.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IGovernor} from "openzeppelin/governance/Governor.sol";
import {ERC20Votes} from "openzeppelin/token/ERC20/extensions/ERC20Votes.sol";
import {IFractionalGovernor} from "flexible-voting/src/interfaces/IFractionalGovernor.sol";
abstract contract L1VotePool {
/// @notice The address of the L1 Governor contract.
IGovernor public immutable GOVERNOR;
// This param is ignored by the governor when voting with fractional
// weights. It makes no difference what vote type this is.
uint8 constant UNUSED_SUPPORT_PARAM = uint8(1);
event VoteCast(
address indexed voter,
uint256 proposalId,
uint256 voteAgainst,
uint256 voteFor,
uint256 voteAbstain
);
/// @dev Thrown when proposal does not exist.
error MissingProposal();
/// @dev Thrown when a proposal vote is invalid.
error InvalidProposalVote();
/// @dev Contains the distribution of a proposal vote.
struct ProposalVote {
uint128 againstVotes;
uint128 forVotes;
uint128 abstainVotes;
}
/// @notice A mapping of proposal id to the proposal vote distribution.
mapping(uint256 => ProposalVote) public proposalVotes;
/// @param _governor The address of the L1 Governor contract.
constructor(address _governor) {
GOVERNOR = IGovernor(_governor);
ERC20Votes(IFractionalGovernor(address(GOVERNOR)).token()).delegate(address(this));
}
/// @notice Casts vote to the L1 Governor.
/// @param proposalId The id of the proposal being cast.
function _castVote(uint256 proposalId, ProposalVote memory vote) internal {
bytes memory votes = abi.encodePacked(vote.againstVotes, vote.forVotes, vote.abstainVotes);
GOVERNOR.castVoteWithReasonAndParams(
proposalId, UNUSED_SUPPORT_PARAM, "rolled-up vote from governance L2 token holders", votes
);
emit VoteCast(msg.sender, proposalId, vote.againstVotes, vote.forVotes, vote.abstainVotes);
}
}