Skip to content

Commit a6eebac

Browse files
authored
fix: address tmnt 155 (#16536)
Please read [contributing guidelines](CONTRIBUTING.md) and remove this line. For audit-related pull requests, please use the [audit PR template](?expand=1&template=audit.md).
2 parents eea4750 + 884cd9b commit a6eebac

File tree

8 files changed

+37
-29
lines changed

8 files changed

+37
-29
lines changed

l1-contracts/src/governance/Governance.sol

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,17 @@ contract Governance is IGovernance {
508508

509509
/**
510510
* @notice Get the power of an address at a given timestamp.
511-
* @dev If the timestamp is the current block timestamp, we return the powerNow.
512-
* Otherwise, we return the powerAt the timestamp.
511+
*
512+
* @param _owner The address to get the power of.
513+
* @param _ts The timestamp to get the power at.
514+
* @return The power of the address at the given timestamp.
515+
*/
516+
function powerAt(address _owner, Timestamp _ts) external view override(IGovernance) returns (uint256) {
517+
return users[_owner].valueAt(_ts);
518+
}
519+
520+
/**
521+
* @notice Get the power of an address at the current block timestamp.
513522
*
514523
* Note that `powerNow` with the current block timestamp is NOT STABLE.
515524
*
@@ -522,35 +531,32 @@ contract Governance is IGovernance {
522531
* The powerNow at 4 will be different from the powerNow at 2.
523532
*
524533
* @param _owner The address to get the power of.
525-
* @param _ts The timestamp to get the power at.
526-
* @return The power of the address at the given timestamp.
534+
* @return The power of the address at the current block timestamp.
527535
*/
528-
function powerAt(address _owner, Timestamp _ts) external view override(IGovernance) returns (uint256) {
529-
if (_ts == Timestamp.wrap(block.timestamp)) {
530-
return users[_owner].valueNow();
531-
}
532-
return users[_owner].valueAt(_ts);
536+
function powerNow(address _owner) external view override(IGovernance) returns (uint256) {
537+
return users[_owner].valueNow();
533538
}
534539

535540
/**
536541
* @notice Get the total power in Governance at a given timestamp.
537-
* @dev If the timestamp is the current block timestamp, we return the powerNow.
538-
* Otherwise, we return the powerAt the timestamp.
539-
*
540-
* Note that `powerNow` with the current block timestamp is NOT STABLE.
541-
*
542-
* See `powerAt` for more details.
543542
*
544543
* @param _ts The timestamp to get the power at.
545544
* @return The total power at the given timestamp.
546545
*/
547546
function totalPowerAt(Timestamp _ts) external view override(IGovernance) returns (uint256) {
548-
if (_ts == Timestamp.wrap(block.timestamp)) {
549-
return total.valueNow();
550-
}
551547
return total.valueAt(_ts);
552548
}
553549

550+
/**
551+
* @notice Get the total power in Governance at the current block timestamp.
552+
* Note that `powerNow` with the current block timestamp is NOT STABLE.
553+
*
554+
* @return The total power at the current block timestamp.
555+
*/
556+
function totalPowerNow() external view override(IGovernance) returns (uint256) {
557+
return total.valueNow();
558+
}
559+
554560
/**
555561
* @notice Check if an address is permitted to hold power in Governance.
556562
*

l1-contracts/src/governance/interfaces/IGovernance.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ interface IGovernance {
8888
function isAllBeneficiariesAllowed() external view returns (bool);
8989

9090
function powerAt(address _owner, Timestamp _ts) external view returns (uint256);
91+
function powerNow(address _owner) external view returns (uint256);
9192
function totalPowerAt(Timestamp _ts) external view returns (uint256);
93+
function totalPowerNow() external view returns (uint256);
9294
function getProposalState(uint256 _proposalId) external view returns (ProposalState);
9395
function getConfiguration() external view returns (Configuration memory);
9496
function getProposal(uint256 _proposalId) external view returns (Proposal memory);

l1-contracts/test/delegation/minimal.t.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ contract MinimalDelegationTest is GSEBase {
115115

116116
vm.warp(ts.ts6);
117117

118-
assertEq(governance.totalPowerAt(Timestamp.wrap(ts.ts6)), activationThreshold * 3);
118+
assertEq(governance.totalPowerNow(), activationThreshold * 3);
119119

120120
if (_overwriteDelay) {
121121
stdstore.enable_packed_slots().target(address(ROLLUP)).sig("getExitDelay()").checked_write(5);
@@ -124,7 +124,7 @@ contract MinimalDelegationTest is GSEBase {
124124
vm.prank(WITHDRAWER);
125125
ROLLUP.initiateWithdraw(ATTESTER2, WITHDRAWER);
126126

127-
assertEq(governance.totalPowerAt(Timestamp.wrap(ts.ts6)), activationThreshold * 2);
127+
assertEq(governance.totalPowerNow(), activationThreshold * 2);
128128

129129
vm.warp(ts.ts7);
130130

@@ -224,7 +224,7 @@ contract MinimalDelegationTest is GSEBase {
224224
}
225225
ROLLUP.finalizeWithdraw(ATTESTER2);
226226

227-
assertEq(governance.totalPowerAt(Timestamp.wrap(block.timestamp)), activationThreshold * 2);
227+
assertEq(governance.totalPowerNow(), activationThreshold * 2);
228228
assertEq(stakingAsset.balanceOf(WITHDRAWER), activationThreshold);
229229

230230
assertEq(governance.getProposal(proposalId).summedBallot.yea, activationThreshold * 3, "yeas");

l1-contracts/test/governance/governance/deposit.t.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ contract DepositTest is GovernanceBase {
6565
governance.deposit(onBehalfOf, amount);
6666

6767
assertEq(governance.powerAt(onBehalfOf, Timestamp.wrap(block.timestamp - 1)), sums[onBehalfOf] - amount);
68-
assertEq(governance.powerAt(onBehalfOf, Timestamp.wrap(block.timestamp)), sums[onBehalfOf]);
68+
assertEq(governance.powerNow(onBehalfOf), sums[onBehalfOf]);
6969
assertEq(governance.totalPowerAt(Timestamp.wrap(block.timestamp - 1)), sum - amount);
70-
assertEq(governance.totalPowerAt(Timestamp.wrap(block.timestamp)), sum);
70+
assertEq(governance.totalPowerNow(), sum);
7171

7272
assertEq(token.balanceOf(address(this)), 0);
7373
assertEq(token.allowance(address(this), address(governance)), 0);

l1-contracts/test/governance/governance/getProposalState.t.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ contract GetProposalStateTest is GovernanceBase {
127127
// it return Rejected
128128
_stateRejected("empty");
129129

130-
uint256 totalPower = governance.totalPowerAt(Timestamp.wrap(block.timestamp));
130+
uint256 totalPower = governance.totalPowerNow();
131131
(VoteTabulationReturn vtr,) = proposal.voteTabulation(totalPower);
132132
assertEq(vtr, VoteTabulationReturn.Rejected, "invalid return value");
133133
assertEq(governance.getProposalState(proposalId), ProposalState.Rejected);
@@ -151,7 +151,7 @@ contract GetProposalStateTest is GovernanceBase {
151151
);
152152
assertEq(governance.getProposal(proposalId).config.quorum, 0);
153153

154-
uint256 totalPower = governance.totalPowerAt(Timestamp.wrap(block.timestamp));
154+
uint256 totalPower = governance.totalPowerNow();
155155

156156
proposal = governance.getProposal(proposalId);
157157
(VoteTabulationReturn vtr,) = proposal.voteTabulation(totalPower);

l1-contracts/test/governance/governance/initiateWithdraw.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ contract InitiateWithdrawTest is GovernanceBase {
103103
assertEq(withdrawal.unlocksAt, Timestamp.wrap(block.timestamp) + config.withdrawalDelay(), "Invalid timestamp");
104104
assertEq(withdrawal.recipient, recipient, "invalid recipient");
105105
assertFalse(withdrawal.claimed, "already claimed");
106-
assertEq(governance.totalPowerAt(Timestamp.wrap(block.timestamp)), sum);
106+
assertEq(governance.totalPowerNow(), sum);
107107

108108
withdrawalId++;
109109

l1-contracts/test/governance/governance/limitedDeposit.t.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ contract LimitedDepositTest is TestBase {
6363
vm.prank(_caller);
6464
governance.deposit(_depositor, 1000);
6565

66-
assertEq(governance.powerAt(_depositor, Timestamp.wrap(block.timestamp)), 1000);
66+
assertEq(governance.powerNow(_depositor), 1000);
6767
}
6868

6969
function test_WhenFloodgatesAreOpen(address _caller, address _depositor) external {
@@ -82,6 +82,6 @@ contract LimitedDepositTest is TestBase {
8282
vm.prank(_caller);
8383
governance.deposit(_depositor, 1000);
8484

85-
assertEq(governance.powerAt(_depositor, Timestamp.wrap(block.timestamp)), 1000);
85+
assertEq(governance.powerNow(_depositor), 1000);
8686
}
8787
}

l1-contracts/test/governance/governance/vote.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ contract VoteTest is GovernanceBase {
106106
vm.stopPrank();
107107

108108
assertEq(token.balanceOf(address(governance)), depositPower);
109-
assertEq(governance.powerAt(_voter, Timestamp.wrap(block.timestamp)), depositPower);
109+
assertEq(governance.powerNow(_voter), depositPower);
110110

111111
_stateActive("empty");
112112

0 commit comments

Comments
 (0)