From 0500b3d81a03f261f6e55a69232d89441b260aa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Volpe?= Date: Wed, 25 Sep 2024 11:49:51 +0200 Subject: [PATCH] Removed duplicated code election.sol --- .../contracts/governance/Election.sol | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/packages/protocol/contracts/governance/Election.sol b/packages/protocol/contracts/governance/Election.sol index 653348dbeb3..5e1c15c4684 100644 --- a/packages/protocol/contracts/governance/Election.sol +++ b/packages/protocol/contracts/governance/Election.sol @@ -637,10 +637,7 @@ contract Election is */ function hasActivatablePendingVotes(address account, address group) external view returns (bool) { PendingVote storage pendingVote = votes.pending.forGroup[group].byAccount[account]; - if (isL2()) { - return pendingVote.epoch < getEpochManager().getCurrentEpochNumber() && pendingVote.value > 0; - } - return pendingVote.epoch < getEpochNumber() && pendingVote.value > 0; + return pendingVote.epoch < _getEpochNumber() && pendingVote.value > 0; } /** @@ -1010,14 +1007,9 @@ contract Election is function _activate(address group, address account) internal onlyWhenNotBlocked returns (bool) { PendingVote storage pendingVote = votes.pending.forGroup[group].byAccount[account]; - if (isL2()) { - require( - pendingVote.epoch < getEpochManager().getCurrentEpochNumber(), - "Pending vote epoch not passed" - ); - } else { - require(pendingVote.epoch < getEpochNumber(), "Pending vote epoch not passed"); - } + + require(pendingVote.epoch < _getEpochNumber(), "Pending vote epoch not passed"); + uint256 value = pendingVote.value; require(value > 0, "Vote value cannot be zero"); decrementPendingVotes(group, account, value); @@ -1165,11 +1157,7 @@ contract Election is PendingVote storage pendingVote = groupPending.byAccount[account]; pendingVote.value = pendingVote.value.add(value); - if (isL2()) { - pendingVote.epoch = getEpochManager().getCurrentEpochNumber(); - } else { - pendingVote.epoch = getEpochNumber(); - } + pendingVote.epoch = _getEpochNumber(); } /** @@ -1290,4 +1278,17 @@ contract Election is value.mul(votes.active.forGroup[group].total).div(votes.active.forGroup[group].totalUnits); } } + + /** + * @notice Returns the epoch number. + * @return Current epoch number. + */ + function _getEpochNumber() private view returns (uint256) { + // TODO remove this after L2 is fully implemented + if (isL2()) { + return getEpochManager().getCurrentEpochNumber(); + } else { + return getEpochNumber(); + } + } }