-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVetoProposal.sol
69 lines (60 loc) · 2.51 KB
/
VetoProposal.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
59
60
61
62
63
64
65
66
67
68
69
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.17;
import "../party/Party.sol";
/// @notice A contract that allows members of a party that has this contract as
/// a host to vote to veto a proposal.
contract VetoProposal {
error NotPartyHostError();
error ProposalNotActiveError(uint256 proposalId);
/// @notice Mapping from party to proposal ID to votes to veto the proposal.
mapping(Party => mapping(uint256 => uint96)) public vetoVotes;
/// @notice Vote to veto a proposal.
/// @param party The party to vote on.
/// @param proposalId The ID of the proposal to veto.
/// @param snapIndex The index of the snapshot to use for voting power.
function voteToVeto(Party party, uint256 proposalId, uint256 snapIndex) external {
uint96 votes = vetoVotes[party][proposalId];
// No need to perform following check more than once for party
if (votes == 0) {
// Check if this contract is a host of the party
if (!party.isHost(address(this))) revert NotPartyHostError();
}
// Check that proposal is active
(
PartyGovernance.ProposalStatus proposalStatus,
PartyGovernance.ProposalStateValues memory proposalValues
) = party.getProposalStateInfo(proposalId);
if (proposalStatus != PartyGovernance.ProposalStatus.Voting)
revert ProposalNotActiveError(proposalId);
// Increase the veto vote count
uint96 votingPower = party.getVotingPowerAt(
msg.sender,
proposalValues.proposedTime - 1,
snapIndex
);
uint96 newVotes = votes + votingPower;
// Check if the vote to veto is passing
PartyGovernance.GovernanceValues memory governanceValues = party.getGovernanceValues();
if (
_areVotesPassing(
newVotes,
governanceValues.totalVotingPower,
governanceValues.passThresholdBps
)
) {
// If so, veto the proposal and clear the vote count
party.veto(proposalId);
delete vetoVotes[party][proposalId];
} else {
// If not, update the vote count
vetoVotes[party][proposalId] = newVotes;
}
}
function _areVotesPassing(
uint96 voteCount,
uint96 totalVotingPower,
uint16 passThresholdBps
) private pure returns (bool) {
return (uint256(voteCount) * 1e4) / uint256(totalVotingPower) >= uint256(passThresholdBps);
}
}