Skip to content

Commit

Permalink
Changes based on feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkeating committed Sep 23, 2024
1 parent ca7001f commit 354e52c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 147 deletions.
114 changes: 0 additions & 114 deletions script/interfaces/GovernorBravoInterfaces.sol

This file was deleted.

18 changes: 9 additions & 9 deletions test/GovernanceStaker.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -3470,7 +3470,7 @@ contract LastTimeRewardDistributed is UniStakerRewardsTest {
}
}

contract RewardPerTokenAccumulated is UniStakerRewardsTest {
contract RewardPerTokenAccumulated is GovernanceStakerRewardsTest {
function testFuzz_ReturnsZeroIfThereHasNeverBeenAReward(
address _depositor1,
address _depositor2,
Expand Down Expand Up @@ -3877,7 +3877,7 @@ contract RewardPerTokenAccumulated is UniStakerRewardsTest {
}
}

contract UnclaimedReward is UniStakerRewardsTest {
contract UnclaimedReward is GovernanceStakerRewardsTest {
function testFuzz_CalculatesCorrectEarningsForASingleDepositorThatStakesForFullDuration(
address _depositor,
address _delegatee,
Expand Down Expand Up @@ -5003,7 +5003,7 @@ contract UnclaimedReward is UniStakerRewardsTest {
}
}

contract ClaimReward is UniStakerRewardsTest {
contract ClaimReward is GovernanceStakerRewardsTest {
function testFuzz_SendsRewardsEarnedToTheUser(
address _depositor,
address _delegatee,
Expand Down Expand Up @@ -5108,7 +5108,7 @@ contract ClaimReward is UniStakerRewardsTest {
}
}

contract ClaimRewardOnBehalf is UniStakerRewardsTest {
contract ClaimRewardOnBehalf is GovernanceStakerRewardsTest {
using stdStorage for StdStorage;

function testFuzz_ClaimRewardOnBehalfOfBeneficiary(
Expand Down Expand Up @@ -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();
Expand All @@ -5369,7 +5369,7 @@ contract _FetchOrDeploySurrogate is UniStakerRewardsTest {
}
}

contract Multicall is UniStakerRewardsTest {
contract Multicall is GovernanceStakerRewardsTest {
function _encodeStake(address _delegatee, uint96 _stakeAmount)
internal
pure
Expand Down
4 changes: 2 additions & 2 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 22 additions & 22 deletions test/helpers/GovernanceStaker.handler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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;
}
Expand All @@ -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;
}

Expand All @@ -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;
}
Expand All @@ -146,24 +146,24 @@ 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;
}

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);
}

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 354e52c

Please sign in to comment.