Skip to content

Commit

Permalink
refactor: add shortcircuit improvement (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
sogipec authored Nov 10, 2023
1 parent fc88d1c commit 20fdcea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
5 changes: 3 additions & 2 deletions contracts/AngleGovernor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,10 @@ contract AngleGovernor is
}

// Allow early execution when overwhelming majority
if (_shortCircuitFor(proposalId)) {
(bool isShortCircuitFor, bool isShortCircuitAgainst) = _shortCircuit(proposalId);
if (isShortCircuitFor) {
return ProposalState.Succeeded;
} else if (_shortCircuitAgainst(proposalId)) {
} else if (isShortCircuitAgainst) {
return ProposalState.Defeated;
}

Expand Down
21 changes: 8 additions & 13 deletions contracts/external/GovernorShortCircuit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,19 @@ abstract contract GovernorShortCircuit is GovernorVotes, GovernorCountingFractio
INTERNALS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

/// @notice Called by state() to check for early proposal success
/// @notice Called by state() to check for early proposal success or failure
/// @param proposalId Proposal ID
/// @return isShortCircuitFor Represents if short circuit threshold for votes were reached or not
function _shortCircuitFor(uint256 proposalId) internal view returns (bool isShortCircuitFor) {
(, uint256 forVoteWeight, ) = proposalVotes(proposalId);

uint256 proposalVoteStart = proposalSnapshot(proposalId);
isShortCircuitFor = forVoteWeight > shortCircuitThreshold(proposalVoteStart);
}

/// @notice Called by state() to check for early proposal failure
/// @param proposalId Proposal ID
/// @return isShortCircuitAgainst Represents if short circuit threshold against votes were reached or not
function _shortCircuitAgainst(uint256 proposalId) internal view returns (bool isShortCircuitAgainst) {
(uint256 againstVoteWeight, , ) = proposalVotes(proposalId);
function _shortCircuit(
uint256 proposalId
) internal view returns (bool isShortCircuitFor, bool isShortCircuitAgainst) {
(uint256 againstVoteWeight, uint256 forVoteWeight, ) = proposalVotes(proposalId);

uint256 proposalVoteStart = proposalSnapshot(proposalId);
isShortCircuitAgainst = againstVoteWeight > shortCircuitThreshold(proposalVoteStart);
uint256 shortCircuitThresholdValue = shortCircuitThreshold(proposalVoteStart);
isShortCircuitFor = forVoteWeight > shortCircuitThresholdValue;
isShortCircuitAgainst = againstVoteWeight > shortCircuitThresholdValue;
}

/// @notice Called by governance to change the short circuit numerator
Expand Down

0 comments on commit 20fdcea

Please sign in to comment.