From 354e52c03c3d9f3301eb918906f07b313afd72f9 Mon Sep 17 00:00:00 2001 From: Keating Date: Mon, 23 Sep 2024 10:31:44 -0400 Subject: [PATCH] Changes based on feedback --- script/interfaces/GovernorBravoInterfaces.sol | 114 ------------------ test/GovernanceStaker.t.sol | 18 +-- test/README.md | 4 +- test/helpers/GovernanceStaker.handler.sol | 44 +++---- 4 files changed, 33 insertions(+), 147 deletions(-) delete mode 100644 script/interfaces/GovernorBravoInterfaces.sol diff --git a/script/interfaces/GovernorBravoInterfaces.sol b/script/interfaces/GovernorBravoInterfaces.sol deleted file mode 100644 index fe1ed1d..0000000 --- a/script/interfaces/GovernorBravoInterfaces.sol +++ /dev/null @@ -1,114 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only -pragma solidity ^0.8.23; - -// This interface was created using cast interface. The contract can be found at -// https://etherscan.io/address/0x53a328f4086d7c0f1fa19e594c9b842125263026#code#F2#L182 - -interface GovernorBravoDelegate { - type ProposalState is uint8; - - struct Receipt { - bool hasVoted; - uint8 support; - uint96 votes; - } - - event NewAdmin(address oldAdmin, address newAdmin); - event NewImplementation(address oldImplementation, address newImplementation); - event NewPendingAdmin(address oldPendingAdmin, address newPendingAdmin); - event ProposalCanceled(uint256 id); - event ProposalCreated( - uint256 id, - address proposer, - address[] targets, - uint256[] values, - string[] signatures, - bytes[] calldatas, - uint256 startBlock, - uint256 endBlock, - string description - ); - event ProposalExecuted(uint256 id); - event ProposalQueued(uint256 id, uint256 eta); - event ProposalThresholdSet(uint256 oldProposalThreshold, uint256 newProposalThreshold); - event VoteCast( - address indexed voter, uint256 proposalId, uint8 support, uint256 votes, string reason - ); - event VotingDelaySet(uint256 oldVotingDelay, uint256 newVotingDelay); - event VotingPeriodSet(uint256 oldVotingPeriod, uint256 newVotingPeriod); - - function BALLOT_TYPEHASH() external view returns (bytes32); - function DOMAIN_TYPEHASH() external view returns (bytes32); - function MAX_PROPOSAL_THRESHOLD() external view returns (uint256); - function MAX_VOTING_DELAY() external view returns (uint256); - function MAX_VOTING_PERIOD() external view returns (uint256); - function MIN_PROPOSAL_THRESHOLD() external view returns (uint256); - function MIN_VOTING_DELAY() external view returns (uint256); - function MIN_VOTING_PERIOD() external view returns (uint256); - function _acceptAdmin() external; - function _initiate(uint256 proposalCount) external; - function _setPendingAdmin(address newPendingAdmin) external; - function _setProposalThreshold(uint256 newProposalThreshold) external; - function _setVotingDelay(uint256 newVotingDelay) external; - function _setVotingPeriod(uint256 newVotingPeriod) external; - function admin() external view returns (address); - function cancel(uint256 proposalId) external; - function castVote(uint256 proposalId, uint8 support) external; - function castVoteBySig(uint256 proposalId, uint8 support, uint8 v, bytes32 r, bytes32 s) external; - function castVoteWithReason(uint256 proposalId, uint8 support, string memory reason) external; - function execute(uint256 proposalId) external payable; - function getActions(uint256 proposalId) - external - view - returns ( - address[] memory targets, - uint256[] memory values, - string[] memory signatures, - bytes[] memory calldatas - ); - function getReceipt(uint256 proposalId, address voter) external view returns (Receipt memory); - function implementation() external view returns (address); - function initialProposalId() external view returns (uint256); - function initialize( - address timelock_, - address uni_, - uint256 votingPeriod_, - uint256 votingDelay_, - uint256 proposalThreshold_ - ) external; - function latestProposalIds(address) external view returns (uint256); - function name() external view returns (string memory); - function pendingAdmin() external view returns (address); - function proposalCount() external view returns (uint256); - function proposalMaxOperations() external view returns (uint256); - function proposalThreshold() external view returns (uint256); - function proposals(uint256) - external - view - returns ( - uint256 id, - address proposer, - uint256 eta, - uint256 startBlock, - uint256 endBlock, - uint256 forVotes, - uint256 againstVotes, - uint256 abstainVotes, - bool canceled, - bool executed - ); - function propose( - address[] memory targets, - uint256[] memory values, - string[] memory signatures, - bytes[] memory calldatas, - string memory description - ) external returns (uint256); - function queue(uint256 proposalId) external; - function quorumVotes() external view returns (uint256); - function state(uint256 proposalId) external view returns (ProposalState); - function timelock() external view returns (address); - function uni() external view returns (address); - function votingDelay() external view returns (uint256); - function votingPeriod() external view returns (uint256); -} diff --git a/test/GovernanceStaker.t.sol b/test/GovernanceStaker.t.sol index 1ea3d71..fae86e3 100644 --- a/test/GovernanceStaker.t.sol +++ b/test/GovernanceStaker.t.sol @@ -3140,7 +3140,7 @@ contract InvalidateNonce is GovernanceStakerTest { } } -contract UniStakerRewardsTest is GovernanceStakerTest { +contract GovernanceStakerRewardsTest is GovernanceStakerTest { // Helper methods for dumping contract state related to rewards calculation for debugging function __dumpDebugGlobalRewards() public view { console2.log("reward balance"); @@ -3220,7 +3220,7 @@ contract UniStakerRewardsTest is GovernanceStakerTest { } } -contract NotifyRewardAmount is UniStakerRewardsTest { +contract NotifyRewardAmount is GovernanceStakerRewardsTest { function testFuzz_UpdatesTheRewardRate(uint256 _amount) public { _amount = _boundToRealisticReward(_amount); _mintTransferAndNotifyReward(_amount); @@ -3389,7 +3389,7 @@ contract NotifyRewardAmount is UniStakerRewardsTest { } } -contract LastTimeRewardDistributed is UniStakerRewardsTest { +contract LastTimeRewardDistributed is GovernanceStakerRewardsTest { function test_ReturnsZeroBeforeARewardNotificationHasOccurred() public view { assertEq(govStaker.lastTimeRewardDistributed(), 0); } @@ -3470,7 +3470,7 @@ contract LastTimeRewardDistributed is UniStakerRewardsTest { } } -contract RewardPerTokenAccumulated is UniStakerRewardsTest { +contract RewardPerTokenAccumulated is GovernanceStakerRewardsTest { function testFuzz_ReturnsZeroIfThereHasNeverBeenAReward( address _depositor1, address _depositor2, @@ -3877,7 +3877,7 @@ contract RewardPerTokenAccumulated is UniStakerRewardsTest { } } -contract UnclaimedReward is UniStakerRewardsTest { +contract UnclaimedReward is GovernanceStakerRewardsTest { function testFuzz_CalculatesCorrectEarningsForASingleDepositorThatStakesForFullDuration( address _depositor, address _delegatee, @@ -5003,7 +5003,7 @@ contract UnclaimedReward is UniStakerRewardsTest { } } -contract ClaimReward is UniStakerRewardsTest { +contract ClaimReward is GovernanceStakerRewardsTest { function testFuzz_SendsRewardsEarnedToTheUser( address _depositor, address _delegatee, @@ -5108,7 +5108,7 @@ contract ClaimReward is UniStakerRewardsTest { } } -contract ClaimRewardOnBehalf is UniStakerRewardsTest { +contract ClaimRewardOnBehalf is GovernanceStakerRewardsTest { using stdStorage for StdStorage; function testFuzz_ClaimRewardOnBehalfOfBeneficiary( @@ -5354,7 +5354,7 @@ contract ClaimRewardOnBehalf is UniStakerRewardsTest { } } -contract _FetchOrDeploySurrogate is UniStakerRewardsTest { +contract _FetchOrDeploySurrogate is GovernanceStakerRewardsTest { function testFuzz_EmitsAnEventWhenASurrogateIsDeployed(address _delegatee) public { vm.assume(_delegatee != address(0)); vm.recordLogs(); @@ -5369,7 +5369,7 @@ contract _FetchOrDeploySurrogate is UniStakerRewardsTest { } } -contract Multicall is UniStakerRewardsTest { +contract Multicall is GovernanceStakerRewardsTest { function _encodeStake(address _delegatee, uint96 _stakeAmount) internal pure diff --git a/test/README.md b/test/README.md index 24daad7..87e3172 100644 --- a/test/README.md +++ b/test/README.md @@ -52,8 +52,8 @@ These actions are typical user actions that can be taken on the system. They are These are actions that are outside the normal use of the system. They are used to test the system's behavior under abnormal conditions. -- [ ] directly transfer in some amount of STAKE_TOKEN to UniStaker -- [ ] directly transfer some amount of REWARD_TOKEN to UniStaker +- [ ] directly transfer in some amount of STAKE_TOKEN to GovernanceStaker +- [ ] directly transfer some amount of REWARD_TOKEN to GovernanceStaker - [ ] transfer stake directly to surrogate - [ ] reentrancy attempts - [ ] SELFDESTRUCT to this contract diff --git a/test/helpers/GovernanceStaker.handler.sol b/test/helpers/GovernanceStaker.handler.sol index bb2efb2..99bdcbe 100644 --- a/test/helpers/GovernanceStaker.handler.sol +++ b/test/helpers/GovernanceStaker.handler.sol @@ -13,7 +13,7 @@ contract GovernanceStakerHandler is CommonBase, StdCheats, StdUtils { using LibAddressSet for AddressSet; // system setup - GovernanceStaker public uniStaker; + GovernanceStaker public govStaker; IERC20 public stakeToken; IERC20 public rewardToken; address public admin; @@ -46,11 +46,11 @@ contract GovernanceStakerHandler is CommonBase, StdCheats, StdUtils { _; } - constructor(GovernanceStaker _uniStaker) { - uniStaker = _uniStaker; - stakeToken = IERC20(address(_uniStaker.STAKE_TOKEN())); - rewardToken = IERC20(address(_uniStaker.REWARD_TOKEN())); - admin = uniStaker.admin(); + constructor(GovernanceStaker _govStaker) { + govStaker = _govStaker; + stakeToken = IERC20(address(_govStaker.STAKE_TOKEN())); + rewardToken = IERC20(address(_govStaker.REWARD_TOKEN())); + admin = govStaker.admin(); } function _mintStakeToken(address _to, uint256 _amount) internal { @@ -68,10 +68,10 @@ contract GovernanceStakerHandler is CommonBase, StdCheats, StdUtils { countCall("enableRewardNotifier") doCheckpoints { - vm.assume(_notifier != address(0) && _notifier != address(uniStaker)); + vm.assume(_notifier != address(0) && _notifier != address(govStaker)); _rewardNotifiers.add(_notifier); vm.prank(admin); - uniStaker.setRewardNotifier(_notifier, true); + govStaker.setRewardNotifier(_notifier, true); } function notifyRewardAmount(uint256 _amount, uint256 _actorSeed) @@ -82,11 +82,11 @@ contract GovernanceStakerHandler is CommonBase, StdCheats, StdUtils { _useActor(_rewardNotifiers, _actorSeed); vm.assume(_currentActor != address(0)); _amount = _bound(_amount, 0, 100_000_000e18); - ghost_prevRewardPerTokenAccumulatedCheckpoint = uniStaker.rewardPerTokenAccumulatedCheckpoint(); + ghost_prevRewardPerTokenAccumulatedCheckpoint = govStaker.rewardPerTokenAccumulatedCheckpoint(); _mintRewardToken(_currentActor, _amount); vm.startPrank(_currentActor); - rewardToken.transfer(address(uniStaker), _amount); - uniStaker.notifyRewardAmount(_amount); + rewardToken.transfer(address(govStaker), _amount); + govStaker.notifyRewardAmount(_amount); vm.stopPrank(); ghost_rewardsNotified += _amount; } @@ -106,14 +106,14 @@ contract GovernanceStakerHandler is CommonBase, StdCheats, StdUtils { _mintStakeToken(_currentActor, _amount); vm.startPrank(_currentActor); - stakeToken.approve(address(uniStaker), _amount); - uniStaker.stake(_amount, _delegatee, _beneficiary); + stakeToken.approve(address(govStaker), _amount); + govStaker.stake(_amount, _delegatee, _beneficiary); vm.stopPrank(); // update handler state _depositIds[_currentActor].push(ghost_depositCount); ghost_depositCount++; - _surrogates.add(address(uniStaker.surrogates(_delegatee))); + _surrogates.add(address(govStaker.surrogates(_delegatee))); ghost_stakeSum += _amount; } @@ -127,11 +127,11 @@ contract GovernanceStakerHandler is CommonBase, StdCheats, StdUtils { vm.assume(_depositIds[_currentActor].length > 0); GovernanceStaker.DepositIdentifier _depositId = GovernanceStaker.DepositIdentifier.wrap(_getActorRandDepositId(_actorDepositSeed)); - (uint96 _balance,,,) = uniStaker.deposits(_depositId); + (uint96 _balance,,,) = govStaker.deposits(_depositId); _amount = uint96(_bound(_amount, 0, _balance)); vm.startPrank(_currentActor); - stakeToken.approve(address(uniStaker), _amount); - uniStaker.stakeMore(_depositId, _amount); + stakeToken.approve(address(govStaker), _amount); + govStaker.stakeMore(_depositId, _amount); vm.stopPrank(); ghost_stakeSum += _amount; } @@ -146,10 +146,10 @@ contract GovernanceStakerHandler is CommonBase, StdCheats, StdUtils { vm.assume(_depositIds[_currentActor].length > 0); GovernanceStaker.DepositIdentifier _depositId = GovernanceStaker.DepositIdentifier.wrap(_getActorRandDepositId(_actorDepositSeed)); - (uint96 _balance,,,) = uniStaker.deposits(_depositId); + (uint96 _balance,,,) = govStaker.deposits(_depositId); _amount = uint96(_bound(_amount, 0, _balance)); vm.startPrank(_currentActor); - uniStaker.withdraw(_depositId, _amount); + govStaker.withdraw(_depositId, _amount); vm.stopPrank(); ghost_stakeWithdrawn += _amount; } @@ -157,13 +157,13 @@ contract GovernanceStakerHandler is CommonBase, StdCheats, StdUtils { function claimReward(uint256 _actorSeed) public countCall("claimReward") doCheckpoints { _useActor(_beneficiaries, _actorSeed); vm.startPrank(_currentActor); - uint256 rewardsClaimed = uniStaker.claimReward(); + uint256 rewardsClaimed = govStaker.claimReward(); vm.stopPrank(); ghost_rewardsClaimed += rewardsClaimed; } function warpAhead(uint256 _seconds) public countCall("warpAhead") doCheckpoints { - _seconds = _bound(_seconds, 0, uniStaker.REWARD_DURATION() * 2); + _seconds = _bound(_seconds, 0, govStaker.REWARD_DURATION() * 2); skip(_seconds); } @@ -204,7 +204,7 @@ contract GovernanceStakerHandler is CommonBase, StdCheats, StdUtils { } function _checkpoint_ghost_prevRewardPerTokenAccumulatedCheckpoint() internal { - ghost_prevRewardPerTokenAccumulatedCheckpoint = uniStaker.rewardPerTokenAccumulatedCheckpoint(); + ghost_prevRewardPerTokenAccumulatedCheckpoint = govStaker.rewardPerTokenAccumulatedCheckpoint(); } function callSummary() external view {