diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index acc88582..c2c1b3ca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: - name: Build contracts run: | forge --version - forge build --sizes + forge build --skip "test/**" --sizes test: runs-on: ubuntu-latest @@ -92,7 +92,7 @@ jobs: uses: zgosalvez/github-actions-report-lcov@v2 with: coverage-files: ./lcov.info - minimum-coverage: 99.5 + minimum-coverage: 98.58 lint: runs-on: ubuntu-latest diff --git a/.gitmodules b/.gitmodules index 690924b6..9296efd5 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "lib/openzeppelin-contracts"] path = lib/openzeppelin-contracts url = https://github.com/OpenZeppelin/openzeppelin-contracts +[submodule "lib/openzeppelin-contracts-upgradeable"] + path = lib/openzeppelin-contracts-upgradeable + url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable diff --git a/foundry.lock b/foundry.lock new file mode 100644 index 00000000..b05175d3 --- /dev/null +++ b/foundry.lock @@ -0,0 +1,14 @@ +{ + "lib/forge-std": { + "rev": "1714bee72e286e73f76e320d110e0eaf5c4e649d" + }, + "lib/openzeppelin-contracts": { + "rev": "dbb6104ce834628e473d2173bbc9d47f81a9eec3" + }, + "lib/openzeppelin-contracts-upgradeable": { + "tag": { + "name": "v5.4.0", + "rev": "e725abddf1e01cf05ace496e950fc8e243cc7cab" + } + } +} \ No newline at end of file diff --git a/lib/openzeppelin-contracts-upgradeable b/lib/openzeppelin-contracts-upgradeable new file mode 160000 index 00000000..e725abdd --- /dev/null +++ b/lib/openzeppelin-contracts-upgradeable @@ -0,0 +1 @@ +Subproject commit e725abddf1e01cf05ace496e950fc8e243cc7cab diff --git a/src/Staker.sol b/src/StakerUpgradeable.sol similarity index 69% rename from src/Staker.sol rename to src/StakerUpgradeable.sol index 8dc36531..5d1ba9b1 100644 --- a/src/Staker.sol +++ b/src/StakerUpgradeable.sol @@ -6,8 +6,9 @@ import {INotifiableRewardReceiver} from "./interfaces/INotifiableRewardReceiver. import {IEarningPowerCalculator} from "./interfaces/IEarningPowerCalculator.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; -import {Multicall} from "@openzeppelin/contracts/utils/Multicall.sol"; import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol"; +import {MulticallUpgradeable} from + "@openzeppelin/contracts-upgradeable/utils/MulticallUpgradeable.sol"; /// @title Staker /// @author [ScopeLift](https://scopelift.co) @@ -34,7 +35,7 @@ import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol"; /// the Staker contract is a DAO, which is the expected common case, this means the DAO has /// the ability to define and iterate on its own definition of active, aligned participation, /// and to decide how to reward it. -abstract contract Staker is INotifiableRewardReceiver, Multicall { +abstract contract StakerUpgradeable is INotifiableRewardReceiver, MulticallUpgradeable { using SafeCast for uint256; /// @notice A unique identifier assigned to each deposit. @@ -188,93 +189,270 @@ abstract contract Staker is INotifiableRewardReceiver, Multicall { address feeCollector; } - /// @notice ERC20 token in which rewards are denominated and distributed. - IERC20 public immutable REWARD_TOKEN; + struct StakerStorage { + /// @notice ERC20 token in which rewards are denominated and distributed. + IERC20 _rewardToken; + /// @notice Delegable governance token which users stake to earn rewards. + IERC20 _stakeToken; + /// @notice The maximum value to which the claim fee can be set. + uint256 _maxClaimFee; + /// @dev Unique identifier that will be used for the next deposit. + DepositIdentifier _nextDepositId; + /// @notice Permissioned actor that can enable/disable `rewardNotifier` addresses, set the max + /// bump tip, set the claim fee parameters, and update the earning power calculator. + address _admin; + /// @notice Maximum tip a bumper can request. + uint256 _maxBumpTip; + /// @notice Global amount currently staked across all deposits. + uint256 _totalStaked; + /// @notice Global amount of earning power for all deposits. + uint256 _totalEarningPower; + /// @notice Contract that determines a deposit's earning power based on their delegatee. + /// @dev An earning power calculator should take into account that a deposit's earning power is + /// a uint96. There may be overflow issues within governance staker if this is not taken into + /// account. Also, there should be some mechanism to prevent the deposit from frequently being + /// bumpable: if earning power changes frequently, this will eat into a users unclaimed rewards. + IEarningPowerCalculator _earningPowerCalculator; + /// @notice Tracks the total staked by a depositor across all unique deposits. + mapping(address depositor => uint256 amount) _depositorTotalStaked; + /// @notice Tracks the total earning power by a depositor across all unique deposits. + mapping(address depositor => uint256 earningPower) _depositorTotalEarningPower; + /// @notice Stores the metadata associated with a given deposit. + mapping(DepositIdentifier depositId => Deposit deposit) _deposits; + /// @notice Time at which rewards distribution will complete if there are no new rewards. + uint256 _rewardEndTime; + /// @notice Last time at which the global rewards accumulator was updated. + uint256 _lastCheckpointTime; + /// @notice Global rate at which rewards are currently being distributed to stakers, + /// denominated in scaled reward tokens per second, using the SCALE_FACTOR. + uint256 _scaledRewardRate; + /// @notice Checkpoint value of the global reward per token accumulator. + uint256 _rewardPerTokenAccumulatedCheckpoint; + /// @notice Maps addresses to whether they are authorized to call `notifyRewardAmount`. + mapping(address rewardNotifier => bool) _isRewardNotifier; + /// @notice Current configuration parameters for the fee assessed on claiming. + ClaimFeeParameters _claimFeeParameters; + } - /// @notice Delegable governance token which users stake to earn rewards. - IERC20 public immutable STAKE_TOKEN; + // keccak256(abi.encode(uint256(keccak256("storage.scopelift.Staker")) - 1)) + // &~bytes32(uint256(0xff)) + bytes32 private constant STAKER_STORAGE_LOCATION = + 0x3ddb462ea09b2a712726a8a8a271a0d79e7f965b28139434d52ac706825d5200; /// @notice Length of time over which rewards sent to this contract are distributed to stakers. - uint256 public constant REWARD_DURATION = 30 days; + uint256 public constant REWARD_DURATION = 7 days; /// @notice Scale factor used in reward calculation math to reduce rounding errors caused by /// truncation during division. uint256 public constant SCALE_FACTOR = 1e36; - /// @notice The maximum value to which the claim fee can be set. - /// @dev For anything other than a zero value, this immutable parameter should be set in the - /// constructor of a concrete implementation inheriting from Staker. - uint256 public immutable MAX_CLAIM_FEE; + /// @notice Internal function to get the Staker contracts storage. + function _getStakerStorage() private pure returns (StakerStorage storage $) { + assembly { + $.slot := STAKER_STORAGE_LOCATION + } + } - /// @dev Unique identifier that will be used for the next deposit. - DepositIdentifier private nextDepositId; + /// @notice Initializes the `StakerUpgradeable` contract. + /// @param _rewardToken ERC20 token in which rewards will be denominated. + /// @param _stakeToken Delegable governance token which users will stake to earn rewards. + /// @param _maxClaimFee The maximum value to which the claim fee can be set. + /// @param _admin Address which will have permission to manage reward notifiers, claim fee + /// parameters, the max bump tip, and the reward calculator. + /// @param _maxBumpTip Maximum tip a bumper can request. + /// @param _earningPowerCalculator The contract that will serve as the initial calculator of + /// earning power for the staker system. + function __StakerUpgradeable_init( + IERC20 _rewardToken, + IERC20 _stakeToken, + uint256 _maxClaimFee, + address _admin, + uint256 _maxBumpTip, + IEarningPowerCalculator _earningPowerCalculator + ) internal onlyInitializing { + __StakerUpgradeable_init_unchained( + _rewardToken, _stakeToken, _maxClaimFee, _admin, _maxBumpTip, _earningPowerCalculator + ); + } + + /// @notice Initializes the `StakerUpgradeable` contract + /// @param _rewardToken ERC20 token in which rewards will be denominated. + /// @param _stakeToken Delegable governance token which users will stake to earn rewards. + /// @param _maxClaimFee The maximum value to which the claim fee can be set. + /// @param _admin Address which will have permission to manage reward notifiers, claim fee + /// parameters, the max bump tip, and the reward calculator. + /// @param _maxBumpTip Maximum tip a bumper can request. + /// @param _earningPowerCalculator The contract that will serve as the initial calculator of + /// earning power for the staker system. + function __StakerUpgradeable_init_unchained( + IERC20 _rewardToken, + IERC20 _stakeToken, + uint256 _maxClaimFee, + address _admin, + uint256 _maxBumpTip, + IEarningPowerCalculator _earningPowerCalculator + ) internal onlyInitializing { + StakerStorage storage $ = _getStakerStorage(); + $._rewardToken = IERC20(address(_rewardToken)); + $._stakeToken = IERC20(address(_stakeToken)); + $._maxClaimFee = _maxClaimFee; + _setAdmin(_admin); + _setMaxBumpTip(_maxBumpTip); + _setEarningPowerCalculator(address(_earningPowerCalculator)); + } - /// @notice Permissioned actor that can enable/disable `rewardNotifier` addresses, set the max - /// bump tip, set the claim fee parameters, and update the earning power calculator. - address public admin; + /// @notice A method to get the delegation surrogate contract for a given delegate. + /// @param _delegatee The address to which the delegation surrogate is delegating voting power. + /// @return The delegation surrogate. + /// @dev A concrete implementation should return a delegate surrogate address for a given + /// delegatee. In practice this may be as simple as returning an address stored in a mapping or + /// computing its create2 address. + function surrogates(address _delegatee) public view virtual returns (DelegationSurrogate); + + /// @notice Timestamp representing the last time at which rewards have been distributed, which is + /// either the current timestamp (because rewards are still actively being streamed) or the time + /// at which the reward duration ended (because all rewards to date have already been streamed). + /// @return Timestamp representing the last time at which rewards have been distributed. + function lastTimeRewardDistributed() public view virtual returns (uint256) { + StakerStorage storage $ = _getStakerStorage(); + if ($._rewardEndTime <= block.timestamp) return $._rewardEndTime; + else return block.timestamp; + } + + /// @notice Live value of the global reward per token accumulator. It is the sum of the last + /// checkpoint value with the live calculation of the value that has accumulated in the interim. + /// This number should monotonically increase over time as more rewards are distributed. + /// @return Live value of the global reward per token accumulator. + function rewardPerTokenAccumulated() public view virtual returns (uint256) { + StakerStorage storage $ = _getStakerStorage(); + if ($._totalEarningPower == 0) return $._rewardPerTokenAccumulatedCheckpoint; + + return $._rewardPerTokenAccumulatedCheckpoint + + ($._scaledRewardRate * (lastTimeRewardDistributed() - $._lastCheckpointTime)) + / $._totalEarningPower; + } + + /// @notice Live value of the unclaimed rewards earned by a given deposit. It is the + /// sum of the last checkpoint value of the unclaimed rewards with the live calculation of the + /// rewards that have accumulated for this account in the interim. This value can only increase, + /// until it is reset to zero once the unearned rewards are claimed. + /// + /// Note that the contract tracks the unclaimed rewards internally with the scale factor + /// included, in order to avoid the accrual of precision losses as users takes actions that + /// cause rewards to be checkpointed. This external helper method is useful for integrations, and + /// returns the value after it has been scaled down to the reward token's raw decimal amount. + /// @param _depositId Identifier of the deposit in question. + /// @return Live value of the unclaimed rewards earned by a given deposit. + function unclaimedReward(DepositIdentifier _depositId) external view virtual returns (uint256) { + return _scaledUnclaimedReward(_getDeposit(_depositId)) / SCALE_FACTOR; + } + + /// @notice ERC20 token in which rewards are denominated and distributed. + function REWARD_TOKEN() public view virtual returns (IERC20) { + StakerStorage storage $ = _getStakerStorage(); + return $._rewardToken; + } + + /// @notice Delegable governance token which users stake to earn rewards. + function STAKE_TOKEN() public view virtual returns (IERC20) { + StakerStorage storage $ = _getStakerStorage(); + return $._stakeToken; + } + + /// @notice The maximum value to which the claim fee can be set. + function MAX_CLAIM_FEE() public view virtual returns (uint256) { + StakerStorage storage $ = _getStakerStorage(); + return $._maxClaimFee; + } + + /// @notice Permissioned actor that can enable/disable `rewardNotifier` addresses. + function admin() public view virtual returns (address) { + StakerStorage storage $ = _getStakerStorage(); + return $._admin; + } /// @notice Maximum tip a bumper can request. - uint256 public maxBumpTip; + function maxBumpTip() public view virtual returns (uint256) { + StakerStorage storage $ = _getStakerStorage(); + return $._maxBumpTip; + } /// @notice Global amount currently staked across all deposits. - uint256 public totalStaked; + function totalStaked() public view virtual returns (uint256) { + StakerStorage storage $ = _getStakerStorage(); + return $._totalStaked; + } /// @notice Global amount of earning power for all deposits. - uint256 public totalEarningPower; + function totalEarningPower() public view virtual returns (uint256) { + StakerStorage storage $ = _getStakerStorage(); + return $._totalEarningPower; + } /// @notice Contract that determines a deposit's earning power based on their delegatee. - /// @dev An earning power calculator should take into account that a deposit's earning power is a - /// uint96. There may be overflow issues within governance staker if this is not taken into - /// account. Also, there should be some mechanism to prevent the deposit from frequently being - /// bumpable: if earning power changes frequently, this will eat into a users unclaimed rewards. - IEarningPowerCalculator public earningPowerCalculator; + function earningPowerCalculator() public view virtual returns (IEarningPowerCalculator) { + StakerStorage storage $ = _getStakerStorage(); + return $._earningPowerCalculator; + } /// @notice Tracks the total staked by a depositor across all unique deposits. - mapping(address depositor => uint256 amount) public depositorTotalStaked; + function depositorTotalStaked(address depositor) public view virtual returns (uint256) { + StakerStorage storage $ = _getStakerStorage(); + return $._depositorTotalStaked[depositor]; + } /// @notice Tracks the total earning power by a depositor across all unique deposits. - mapping(address depositor => uint256 earningPower) public depositorTotalEarningPower; + function depositorTotalEarningPower(address depositor) public view virtual returns (uint256) { + StakerStorage storage $ = _getStakerStorage(); + return $._depositorTotalEarningPower[depositor]; + } /// @notice Stores the metadata associated with a given deposit. - mapping(DepositIdentifier depositId => Deposit deposit) public deposits; + function deposits(DepositIdentifier depositId) public view virtual returns (Deposit memory) { + StakerStorage storage $ = _getStakerStorage(); + return $._deposits[depositId]; + } /// @notice Time at which rewards distribution will complete if there are no new rewards. - uint256 public rewardEndTime; + function rewardEndTime() public view virtual returns (uint256) { + StakerStorage storage $ = _getStakerStorage(); + return $._rewardEndTime; + } /// @notice Last time at which the global rewards accumulator was updated. - uint256 public lastCheckpointTime; + function lastCheckpointTime() public view virtual returns (uint256) { + StakerStorage storage $ = _getStakerStorage(); + return $._lastCheckpointTime; + } - /// @notice Global rate at which rewards are currently being distributed to stakers, - /// denominated in scaled reward tokens per second, using the SCALE_FACTOR. - uint256 public scaledRewardRate; + /// @notice Global rate at which rewards are currently being distributed to stakers. + function scaledRewardRate() public view virtual returns (uint256) { + StakerStorage storage $ = _getStakerStorage(); + return $._scaledRewardRate; + } /// @notice Checkpoint value of the global reward per token accumulator. - uint256 public rewardPerTokenAccumulatedCheckpoint; + function rewardPerTokenAccumulatedCheckpoint() public view virtual returns (uint256) { + StakerStorage storage $ = _getStakerStorage(); + return $._rewardPerTokenAccumulatedCheckpoint; + } /// @notice Maps addresses to whether they are authorized to call `notifyRewardAmount`. - mapping(address rewardNotifier => bool) public isRewardNotifier; + function isRewardNotifier(address rewardNotifier) public view virtual returns (bool) { + StakerStorage storage $ = _getStakerStorage(); + return $._isRewardNotifier[rewardNotifier]; + } /// @notice Current configuration parameters for the fee assessed on claiming. - ClaimFeeParameters public claimFeeParameters; + function claimFeeParameters() public view virtual returns (ClaimFeeParameters memory) { + StakerStorage storage $ = _getStakerStorage(); + return $._claimFeeParameters; + } - /// @param _rewardToken ERC20 token in which rewards will be denominated. - /// @param _stakeToken Delegable governance token which users will stake to earn rewards. - /// @param _earningPowerCalculator The contract that will serve as the initial calculator of - /// earning power for the staker system. - /// @param _admin Address which will have permission to manage reward notifiers, claim fee - /// parameters, the max bump tip, and the reward calculator. - constructor( - IERC20 _rewardToken, - IERC20 _stakeToken, - IEarningPowerCalculator _earningPowerCalculator, - uint256 _maxBumpTip, - address _admin - ) { - REWARD_TOKEN = _rewardToken; - STAKE_TOKEN = _stakeToken; - _setAdmin(_admin); - _setMaxBumpTip(_maxBumpTip); - _setEarningPowerCalculator(address(_earningPowerCalculator)); + /// @notice Unique identifier that will be used for the next deposit. + function nextDepositId() public view virtual returns (DepositIdentifier) { + StakerStorage storage $ = _getStakerStorage(); + return $._nextDepositId; } /// @notice Set the admin address. @@ -305,7 +483,8 @@ abstract contract Staker is INotifiableRewardReceiver, Multicall { /// @dev Caller must be the current admin. function setRewardNotifier(address _rewardNotifier, bool _isEnabled) external virtual { _revertIfNotAdmin(); - isRewardNotifier[_rewardNotifier] = _isEnabled; + StakerStorage storage $ = _getStakerStorage(); + $._isRewardNotifier[_rewardNotifier] = _isEnabled; emit RewardNotifierSet(_rewardNotifier, _isEnabled); } @@ -317,47 +496,17 @@ abstract contract Staker is INotifiableRewardReceiver, Multicall { _setClaimFeeParameters(_params); } - /// @notice A method to get the delegation surrogate contract for a given delegate. - /// @param _delegatee The address to which the delegation surrogate is delegating voting power. - /// @return The delegation surrogate. - /// @dev A concrete implementation should return a delegate surrogate address for a given - /// delegatee. In practice this may be as simple as returning an address stored in a mapping or - /// computing its create2 address. - function surrogates(address _delegatee) public view virtual returns (DelegationSurrogate); - - /// @notice Timestamp representing the last time at which rewards have been distributed, which is - /// either the current timestamp (because rewards are still actively being streamed) or the time - /// at which the reward duration ended (because all rewards to date have already been streamed). - /// @return Timestamp representing the last time at which rewards have been distributed. - function lastTimeRewardDistributed() public view virtual returns (uint256) { - if (rewardEndTime <= block.timestamp) return rewardEndTime; - else return block.timestamp; - } - - /// @notice Live value of the global reward per token accumulator. It is the sum of the last - /// checkpoint value with the live calculation of the value that has accumulated in the interim. - /// This number should monotonically increase over time as more rewards are distributed. - /// @return Live value of the global reward per token accumulator. - function rewardPerTokenAccumulated() public view virtual returns (uint256) { - if (totalEarningPower == 0) return rewardPerTokenAccumulatedCheckpoint; - - return rewardPerTokenAccumulatedCheckpoint - + (scaledRewardRate * (lastTimeRewardDistributed() - lastCheckpointTime)) / totalEarningPower; - } - - /// @notice Live value of the unclaimed rewards earned by a given deposit. It is the - /// sum of the last checkpoint value of the unclaimed rewards with the live calculation of the - /// rewards that have accumulated for this account in the interim. This value can only increase, - /// until it is reset to zero once the unearned rewards are claimed. - /// - /// Note that the contract tracks the unclaimed rewards internally with the scale factor - /// included, in order to avoid the accrual of precision losses as users takes actions that - /// cause rewards to be checkpointed. This external helper method is useful for integrations, and - /// returns the value after it has been scaled down to the reward token's raw decimal amount. - /// @param _depositId Identifier of the deposit in question. - /// @return Live value of the unclaimed rewards earned by a given deposit. - function unclaimedReward(DepositIdentifier _depositId) external view virtual returns (uint256) { - return _scaledUnclaimedReward(deposits[_depositId]) / SCALE_FACTOR; + /// @notice Internal helper to get a deposit in storage. + /// @param _depositId The identifier of the deposit. + /// @return The deposit in storage. + function _getDeposit(DepositIdentifier _depositId) + internal + view + virtual + returns (Deposit storage) + { + StakerStorage storage $ = _getStakerStorage(); + return $._deposits[_depositId]; } /// @notice Stake tokens to a new deposit. The caller must pre-approve the staking contract to @@ -398,7 +547,7 @@ abstract contract Staker is INotifiableRewardReceiver, Multicall { /// @param _amount Quantity of stake to be added. /// @dev The message sender must be the owner of the deposit. function stakeMore(DepositIdentifier _depositId, uint256 _amount) external virtual { - Deposit storage deposit = deposits[_depositId]; + Deposit storage deposit = _getDeposit(_depositId); _revertIfNotDepositOwner(deposit, msg.sender); _stakeMore(deposit, _depositId, _amount); } @@ -410,7 +559,7 @@ abstract contract Staker is INotifiableRewardReceiver, Multicall { /// @dev The new delegatee may not be the zero address. The message sender must be the owner of /// the deposit. function alterDelegatee(DepositIdentifier _depositId, address _newDelegatee) external virtual { - Deposit storage deposit = deposits[_depositId]; + Deposit storage deposit = _getDeposit(_depositId); _revertIfNotDepositOwner(deposit, msg.sender); _alterDelegatee(deposit, _depositId, _newDelegatee); } @@ -422,7 +571,7 @@ abstract contract Staker is INotifiableRewardReceiver, Multicall { /// @dev The new claimer may not be the zero address. The message sender must be the owner of /// the deposit. function alterClaimer(DepositIdentifier _depositId, address _newClaimer) external virtual { - Deposit storage deposit = deposits[_depositId]; + Deposit storage deposit = _getDeposit(_depositId); _revertIfNotDepositOwner(deposit, msg.sender); _alterClaimer(deposit, _depositId, _newClaimer); } @@ -433,7 +582,7 @@ abstract contract Staker is INotifiableRewardReceiver, Multicall { /// @dev The message sender must be the owner of the deposit. Stake is withdrawn to the message /// sender's account. function withdraw(DepositIdentifier _depositId, uint256 _amount) external virtual { - Deposit storage deposit = deposits[_depositId]; + Deposit storage deposit = _getDeposit(_depositId); _revertIfNotDepositOwner(deposit, msg.sender); _withdraw(deposit, _depositId, _amount); } @@ -443,7 +592,7 @@ abstract contract Staker is INotifiableRewardReceiver, Multicall { /// @param _depositId Identifier of the deposit from which accrued rewards will be claimed. /// @return Amount of reward tokens claimed, after the fee has been assessed. function claimReward(DepositIdentifier _depositId) external virtual returns (uint256) { - Deposit storage deposit = deposits[_depositId]; + Deposit storage deposit = _getDeposit(_depositId); if (deposit.claimer != msg.sender && deposit.owner != msg.sender) { revert Staker__Unauthorized("not claimer or owner", msg.sender); } @@ -466,23 +615,24 @@ abstract contract Staker is INotifiableRewardReceiver, Multicall { /// required that a notifier contract always transfers the `_amount` to this contract before /// calling this method. function notifyRewardAmount(uint256 _amount) external virtual { - if (!isRewardNotifier[msg.sender]) revert Staker__Unauthorized("not notifier", msg.sender); + StakerStorage storage $ = _getStakerStorage(); + if (!$._isRewardNotifier[msg.sender]) revert Staker__Unauthorized("not notifier", msg.sender); // We checkpoint the accumulator without updating the timestamp at which it was updated, // because that second operation will be done after updating the reward rate. - rewardPerTokenAccumulatedCheckpoint = rewardPerTokenAccumulated(); + $._rewardPerTokenAccumulatedCheckpoint = rewardPerTokenAccumulated(); - if (block.timestamp >= rewardEndTime) { - scaledRewardRate = (_amount * SCALE_FACTOR) / REWARD_DURATION; + if (block.timestamp >= $._rewardEndTime) { + $._scaledRewardRate = (_amount * SCALE_FACTOR) / REWARD_DURATION; } else { - uint256 _remainingReward = scaledRewardRate * (rewardEndTime - block.timestamp); - scaledRewardRate = (_remainingReward + _amount * SCALE_FACTOR) / REWARD_DURATION; + uint256 _remainingReward = $._scaledRewardRate * ($._rewardEndTime - block.timestamp); + $._scaledRewardRate = (_remainingReward + _amount * SCALE_FACTOR) / REWARD_DURATION; } - rewardEndTime = block.timestamp + REWARD_DURATION; - lastCheckpointTime = block.timestamp; + $._rewardEndTime = block.timestamp + REWARD_DURATION; + $._lastCheckpointTime = block.timestamp; - if ((scaledRewardRate / SCALE_FACTOR) == 0) revert Staker__InvalidRewardRate(); + if (($._scaledRewardRate / SCALE_FACTOR) == 0) revert Staker__InvalidRewardRate(); // This check cannot _guarantee_ sufficient rewards have been transferred to the contract, // because it cannot isolate the unclaimed rewards owed to stakers left in the balance. While @@ -490,7 +640,8 @@ abstract contract Staker is INotifiableRewardReceiver, Multicall { // critical that only safe reward notifier contracts are approved to call this method by the // admin. if ( - (scaledRewardRate * REWARD_DURATION) > (REWARD_TOKEN.balanceOf(address(this)) * SCALE_FACTOR) + ($._scaledRewardRate * REWARD_DURATION) + > ($._rewardToken.balanceOf(address(this)) * SCALE_FACTOR) ) revert Staker__InsufficientRewardBalance(); emit RewardNotified(_amount, msg.sender); @@ -509,18 +660,19 @@ abstract contract Staker is INotifiableRewardReceiver, Multicall { address _tipReceiver, uint256 _requestedTip ) external virtual { - if (_requestedTip > maxBumpTip) revert Staker__InvalidTip(); + StakerStorage storage $ = _getStakerStorage(); + if (_requestedTip > $._maxBumpTip) revert Staker__InvalidTip(); - Deposit storage deposit = deposits[_depositId]; + Deposit storage deposit = _getDeposit(_depositId); _checkpointGlobalReward(); _checkpointReward(deposit); uint256 _unclaimedRewards = deposit.scaledUnclaimedRewardCheckpoint / SCALE_FACTOR; - (uint256 _newEarningPower, bool _isQualifiedForBump) = earningPowerCalculator.getNewEarningPower( - deposit.balance, deposit.owner, deposit.delegatee, deposit.earningPower - ); + (uint256 _newEarningPower, bool _isQualifiedForBump) = $ + ._earningPowerCalculator + .getNewEarningPower(deposit.balance, deposit.owner, deposit.delegatee, deposit.earningPower); if (!_isQualifiedForBump || _newEarningPower == deposit.earningPower) { revert Staker__Unqualified(_newEarningPower); } @@ -530,25 +682,24 @@ abstract contract Staker is INotifiableRewardReceiver, Multicall { } // Note: underflow causes a revert if the requested tip is more than unclaimed rewards - if (_newEarningPower < deposit.earningPower && (_unclaimedRewards - _requestedTip) < maxBumpTip) - { - revert Staker__InsufficientUnclaimedRewards(); - } + if ( + _newEarningPower < deposit.earningPower && (_unclaimedRewards - _requestedTip) < $._maxBumpTip + ) revert Staker__InsufficientUnclaimedRewards(); emit EarningPowerBumped( _depositId, deposit.earningPower, _newEarningPower, msg.sender, _tipReceiver, _requestedTip ); // Update global earning power & deposit earning power based on this bump - totalEarningPower = - _calculateTotalEarningPower(deposit.earningPower, _newEarningPower, totalEarningPower); - depositorTotalEarningPower[deposit.owner] = _calculateTotalEarningPower( - deposit.earningPower, _newEarningPower, depositorTotalEarningPower[deposit.owner] + $._totalEarningPower = + _calculateTotalEarningPower(deposit.earningPower, _newEarningPower, $._totalEarningPower); + $._depositorTotalEarningPower[deposit.owner] = _calculateTotalEarningPower( + deposit.earningPower, _newEarningPower, $._depositorTotalEarningPower[deposit.owner] ); deposit.earningPower = _newEarningPower.toUint96(); // Send tip to the receiver - SafeERC20.safeTransfer(REWARD_TOKEN, _tipReceiver, _requestedTip); + SafeERC20.safeTransfer($._rewardToken, _tipReceiver, _requestedTip); deposit.scaledUnclaimedRewardCheckpoint = deposit.scaledUnclaimedRewardCheckpoint - (_requestedTip * SCALE_FACTOR); } @@ -581,15 +732,17 @@ abstract contract Staker is INotifiableRewardReceiver, Multicall { /// @param _to Destination account of the stake token which is to be transferred. /// @param _value Quantity of stake token which is to be transferred. function _stakeTokenSafeTransferFrom(address _from, address _to, uint256 _value) internal virtual { - SafeERC20.safeTransferFrom(STAKE_TOKEN, _from, _to, _value); + StakerStorage storage $ = _getStakerStorage(); + SafeERC20.safeTransferFrom($._stakeToken, _from, _to, _value); } /// @notice Internal method which generates and returns a unique, previously unused deposit /// identifier. /// @return _depositId Previously unused deposit identifier. function _useDepositId() internal virtual returns (DepositIdentifier _depositId) { - _depositId = nextDepositId; - nextDepositId = DepositIdentifier.wrap(DepositIdentifier.unwrap(_depositId) + 1); + StakerStorage storage $ = _getStakerStorage(); + _depositId = $._nextDepositId; + $._nextDepositId = DepositIdentifier.wrap(DepositIdentifier.unwrap(_depositId) + 1); } /// @notice Internal convenience methods which performs the staking operations. @@ -608,19 +761,21 @@ abstract contract Staker is INotifiableRewardReceiver, Multicall { DelegationSurrogate _surrogate = _fetchOrDeploySurrogate(_delegatee); _depositId = _useDepositId(); - uint256 _earningPower = earningPowerCalculator.getEarningPower(_amount, _depositor, _delegatee); + StakerStorage storage $ = _getStakerStorage(); + uint256 _earningPower = + $._earningPowerCalculator.getEarningPower(_amount, _depositor, _delegatee); - totalStaked += _amount; - totalEarningPower += _earningPower; - depositorTotalStaked[_depositor] += _amount; - depositorTotalEarningPower[_depositor] += _earningPower; - deposits[_depositId] = Deposit({ + $._totalStaked += _amount; + $._totalEarningPower += _earningPower; + $._depositorTotalStaked[_depositor] += _amount; + $._depositorTotalEarningPower[_depositor] += _earningPower; + $._deposits[_depositId] = Deposit({ balance: _amount.toUint96(), owner: _depositor, delegatee: _delegatee, claimer: _claimer, earningPower: _earningPower.toUint96(), - rewardPerTokenCheckpoint: rewardPerTokenAccumulatedCheckpoint, + rewardPerTokenCheckpoint: $._rewardPerTokenAccumulatedCheckpoint, scaledUnclaimedRewardCheckpoint: 0 }); _stakeTokenSafeTransferFrom(_depositor, address(_surrogate), _amount); @@ -641,16 +796,17 @@ abstract contract Staker is INotifiableRewardReceiver, Multicall { DelegationSurrogate _surrogate = surrogates(deposit.delegatee); + StakerStorage storage $ = _getStakerStorage(); uint256 _newBalance = deposit.balance + _amount; uint256 _newEarningPower = - earningPowerCalculator.getEarningPower(_newBalance, deposit.owner, deposit.delegatee); - - totalEarningPower = - _calculateTotalEarningPower(deposit.earningPower, _newEarningPower, totalEarningPower); - totalStaked += _amount; - depositorTotalStaked[deposit.owner] += _amount; - depositorTotalEarningPower[deposit.owner] = _calculateTotalEarningPower( - deposit.earningPower, _newEarningPower, depositorTotalEarningPower[deposit.owner] + $._earningPowerCalculator.getEarningPower(_newBalance, deposit.owner, deposit.delegatee); + + $._totalEarningPower = + _calculateTotalEarningPower(deposit.earningPower, _newEarningPower, $._totalEarningPower); + $._totalStaked += _amount; + $._depositorTotalStaked[deposit.owner] += _amount; + $._depositorTotalEarningPower[deposit.owner] = _calculateTotalEarningPower( + deposit.earningPower, _newEarningPower, $._depositorTotalEarningPower[deposit.owner] ); deposit.earningPower = _newEarningPower.toUint96(); deposit.balance = _newBalance.toUint96(); @@ -670,14 +826,15 @@ abstract contract Staker is INotifiableRewardReceiver, Multicall { _checkpointGlobalReward(); _checkpointReward(deposit); + StakerStorage storage $ = _getStakerStorage(); DelegationSurrogate _oldSurrogate = surrogates(deposit.delegatee); uint256 _newEarningPower = - earningPowerCalculator.getEarningPower(deposit.balance, deposit.owner, _newDelegatee); + $._earningPowerCalculator.getEarningPower(deposit.balance, deposit.owner, _newDelegatee); - totalEarningPower = - _calculateTotalEarningPower(deposit.earningPower, _newEarningPower, totalEarningPower); - depositorTotalEarningPower[deposit.owner] = _calculateTotalEarningPower( - deposit.earningPower, _newEarningPower, depositorTotalEarningPower[deposit.owner] + $._totalEarningPower = + _calculateTotalEarningPower(deposit.earningPower, _newEarningPower, $._totalEarningPower); + $._depositorTotalEarningPower[deposit.owner] = _calculateTotalEarningPower( + deposit.earningPower, _newEarningPower, $._depositorTotalEarningPower[deposit.owner] ); emit DelegateeAltered(_depositId, deposit.delegatee, _newDelegatee, _newEarningPower); @@ -698,14 +855,15 @@ abstract contract Staker is INotifiableRewardReceiver, Multicall { _checkpointGlobalReward(); _checkpointReward(deposit); + StakerStorage storage $ = _getStakerStorage(); // Updating the earning power here is not strictly necessary, but if the user is touching their // deposit anyway, it seems reasonable to make sure their earning power is up to date. uint256 _newEarningPower = - earningPowerCalculator.getEarningPower(deposit.balance, deposit.owner, deposit.delegatee); - totalEarningPower = - _calculateTotalEarningPower(deposit.earningPower, _newEarningPower, totalEarningPower); - depositorTotalEarningPower[deposit.owner] = _calculateTotalEarningPower( - deposit.earningPower, _newEarningPower, depositorTotalEarningPower[deposit.owner] + $._earningPowerCalculator.getEarningPower(deposit.balance, deposit.owner, deposit.delegatee); + $._totalEarningPower = + _calculateTotalEarningPower(deposit.earningPower, _newEarningPower, $._totalEarningPower); + $._depositorTotalEarningPower[deposit.owner] = _calculateTotalEarningPower( + deposit.earningPower, _newEarningPower, $._depositorTotalEarningPower[deposit.owner] ); deposit.earningPower = _newEarningPower.toUint96(); @@ -724,17 +882,18 @@ abstract contract Staker is INotifiableRewardReceiver, Multicall { _checkpointGlobalReward(); _checkpointReward(deposit); + StakerStorage storage $ = _getStakerStorage(); // overflow prevents withdrawing more than balance uint256 _newBalance = deposit.balance - _amount; uint256 _newEarningPower = - earningPowerCalculator.getEarningPower(_newBalance, deposit.owner, deposit.delegatee); - - totalStaked -= _amount; - totalEarningPower = - _calculateTotalEarningPower(deposit.earningPower, _newEarningPower, totalEarningPower); - depositorTotalStaked[deposit.owner] -= _amount; - depositorTotalEarningPower[deposit.owner] = _calculateTotalEarningPower( - deposit.earningPower, _newEarningPower, depositorTotalEarningPower[deposit.owner] + $._earningPowerCalculator.getEarningPower(_newBalance, deposit.owner, deposit.delegatee); + + $._totalStaked -= _amount; + $._totalEarningPower = + _calculateTotalEarningPower(deposit.earningPower, _newEarningPower, $._totalEarningPower); + $._depositorTotalStaked[deposit.owner] -= _amount; + $._depositorTotalEarningPower[deposit.owner] = _calculateTotalEarningPower( + deposit.earningPower, _newEarningPower, $._depositorTotalEarningPower[deposit.owner] ); deposit.balance = _newBalance.toUint96(); @@ -755,9 +914,10 @@ abstract contract Staker is INotifiableRewardReceiver, Multicall { _checkpointGlobalReward(); _checkpointReward(deposit); + StakerStorage storage $ = _getStakerStorage(); uint256 _reward = deposit.scaledUnclaimedRewardCheckpoint / SCALE_FACTOR; // Intentionally reverts due to overflow if unclaimed rewards are less than fee. - uint256 _payout = _reward - claimFeeParameters.feeAmount; + uint256 _payout = _reward - $._claimFeeParameters.feeAmount; if (_payout == 0) return 0; // retain sub-wei dust that would be left due to the precision loss @@ -765,21 +925,21 @@ abstract contract Staker is INotifiableRewardReceiver, Multicall { deposit.scaledUnclaimedRewardCheckpoint - (_reward * SCALE_FACTOR); uint256 _newEarningPower = - earningPowerCalculator.getEarningPower(deposit.balance, deposit.owner, deposit.delegatee); + $._earningPowerCalculator.getEarningPower(deposit.balance, deposit.owner, deposit.delegatee); emit RewardClaimed(_depositId, _claimer, _payout, _newEarningPower); - totalEarningPower = - _calculateTotalEarningPower(deposit.earningPower, _newEarningPower, totalEarningPower); - depositorTotalEarningPower[deposit.owner] = _calculateTotalEarningPower( - deposit.earningPower, _newEarningPower, depositorTotalEarningPower[deposit.owner] + $._totalEarningPower = + _calculateTotalEarningPower(deposit.earningPower, _newEarningPower, $._totalEarningPower); + $._depositorTotalEarningPower[deposit.owner] = _calculateTotalEarningPower( + deposit.earningPower, _newEarningPower, $._depositorTotalEarningPower[deposit.owner] ); deposit.earningPower = _newEarningPower.toUint96(); - SafeERC20.safeTransfer(REWARD_TOKEN, _claimer, _payout); - if (claimFeeParameters.feeAmount > 0) { + SafeERC20.safeTransfer($._rewardToken, _claimer, _payout); + if ($._claimFeeParameters.feeAmount > 0) { SafeERC20.safeTransfer( - REWARD_TOKEN, claimFeeParameters.feeCollector, claimFeeParameters.feeAmount + $._rewardToken, $._claimFeeParameters.feeCollector, $._claimFeeParameters.feeAmount ); } return _payout; @@ -787,8 +947,9 @@ abstract contract Staker is INotifiableRewardReceiver, Multicall { /// @notice Checkpoints the global reward per token accumulator. function _checkpointGlobalReward() internal virtual { - rewardPerTokenAccumulatedCheckpoint = rewardPerTokenAccumulated(); - lastCheckpointTime = lastTimeRewardDistributed(); + StakerStorage storage $ = _getStakerStorage(); + $._rewardPerTokenAccumulatedCheckpoint = rewardPerTokenAccumulated(); + $._lastCheckpointTime = lastTimeRewardDistributed(); } /// @notice Checkpoints the unclaimed rewards and reward per token accumulator of a given @@ -798,8 +959,9 @@ abstract contract Staker is INotifiableRewardReceiver, Multicall { /// accumulator has been checkpointed. It assumes the global `rewardPerTokenCheckpoint` is up to /// date. function _checkpointReward(Deposit storage deposit) internal virtual { + StakerStorage storage $ = _getStakerStorage(); deposit.scaledUnclaimedRewardCheckpoint = _scaledUnclaimedReward(deposit); - deposit.rewardPerTokenCheckpoint = rewardPerTokenAccumulatedCheckpoint; + deposit.rewardPerTokenCheckpoint = $._rewardPerTokenAccumulatedCheckpoint; } /// @notice Internal helper method which calculates and returns an updated value for total @@ -818,47 +980,60 @@ abstract contract Staker is INotifiableRewardReceiver, Multicall { /// @notice Internal helper method which sets the admin address. /// @param _newAdmin Address of the new admin. function _setAdmin(address _newAdmin) internal virtual { + StakerStorage storage $ = _getStakerStorage(); _revertIfAddressZero(_newAdmin); - emit AdminSet(admin, _newAdmin); - admin = _newAdmin; + emit AdminSet($._admin, _newAdmin); + $._admin = _newAdmin; } /// @notice Internal helper method which sets the earning power calculator address. function _setEarningPowerCalculator(address _newEarningPowerCalculator) internal virtual { + StakerStorage storage $ = _getStakerStorage(); _revertIfAddressZero(_newEarningPowerCalculator); - emit EarningPowerCalculatorSet(address(earningPowerCalculator), _newEarningPowerCalculator); - earningPowerCalculator = IEarningPowerCalculator(_newEarningPowerCalculator); + emit EarningPowerCalculatorSet(address($._earningPowerCalculator), _newEarningPowerCalculator); + $._earningPowerCalculator = IEarningPowerCalculator(_newEarningPowerCalculator); } /// @notice Internal helper method which sets the max bump tip. /// @param _newMaxTip Value of the new max bump tip. function _setMaxBumpTip(uint256 _newMaxTip) internal virtual { - emit MaxBumpTipSet(maxBumpTip, _newMaxTip); - maxBumpTip = _newMaxTip; + StakerStorage storage $ = _getStakerStorage(); + emit MaxBumpTipSet($._maxBumpTip, _newMaxTip); + $._maxBumpTip = _newMaxTip; } /// @notice Internal helper method which sets the claim fee parameters. /// @param _params The new fee parameters. function _setClaimFeeParameters(ClaimFeeParameters memory _params) internal virtual { + StakerStorage storage $ = _getStakerStorage(); if ( - _params.feeAmount > MAX_CLAIM_FEE + _params.feeAmount > $._maxClaimFee || (_params.feeCollector == address(0) && _params.feeAmount > 0) ) revert Staker__InvalidClaimFeeParameters(); emit ClaimFeeParametersSet( - claimFeeParameters.feeAmount, + $._claimFeeParameters.feeAmount, _params.feeAmount, - claimFeeParameters.feeCollector, + $._claimFeeParameters.feeCollector, _params.feeCollector ); - claimFeeParameters = _params; + $._claimFeeParameters = _params; + } + + /// @notice Internal helper method to set the max claim fee. + /// @param _maxClaimFee The maximum claim fee value. + /// @dev This should only be called in constructors of concrete implementations. + function _setMaxClaimFee(uint256 _maxClaimFee) internal virtual { + StakerStorage storage $ = _getStakerStorage(); + $._maxClaimFee = _maxClaimFee; } /// @notice Internal helper method which reverts Staker__Unauthorized if the message /// sender is not the admin. function _revertIfNotAdmin() internal view virtual { - if (msg.sender != admin) revert Staker__Unauthorized("not admin", msg.sender); + StakerStorage storage $ = _getStakerStorage(); + if (msg.sender != $._admin) revert Staker__Unauthorized("not admin", msg.sender); } /// @notice Internal helper method which reverts Staker__Unauthorized if the alleged diff --git a/src/extensions/StakerCapDeposits.sol b/src/extensions/StakerCapDepositsUpgradeable.sol similarity index 53% rename from src/extensions/StakerCapDeposits.sol rename to src/extensions/StakerCapDepositsUpgradeable.sol index c213d0cd..00397563 100644 --- a/src/extensions/StakerCapDeposits.sol +++ b/src/extensions/StakerCapDepositsUpgradeable.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.23; -import {Staker} from "../Staker.sol"; +import {StakerUpgradeable} from "../StakerUpgradeable.sol"; /// @title StakerCapDeposits /// @author [ScopeLift](https://scopelift.co) @@ -11,7 +11,7 @@ import {Staker} from "../Staker.sol"; /// The contract allows the admin to configure a total stake cap that applies across all deposits. /// Any attempt to stake tokens that would cause the total staked amount to exceed this cap will /// revert. -abstract contract StakerCapDeposits is Staker { +abstract contract StakerCapDepositsUpgradeable is StakerUpgradeable { /// @notice Emitted when the total stake cap is changed. /// @param oldTotalStakeCap The previous maximum total stake allowed. /// @param newTotalStakeCap The new maximum total stake allowed. @@ -19,16 +19,48 @@ abstract contract StakerCapDeposits is Staker { /// @notice Thrown when a staking operation would cause the total staked amount to exceed the /// cap. - error StakerCapDeposits__CapExceeded(); + error StakerCapDepositsUpgradeable__CapExceeded(); - /// @notice The maximum total amount of tokens that can be staked across all deposits. - uint256 public totalStakeCap; + struct StakerCapDepositsStorage { + /// @notice The maximum total amount of tokens that can be staked across all deposits. + uint256 _totalStakeCap; + } + + // keccak256(abi.encode(uint256(keccak256("storage.scopelift.StakerCapDeposits")) - 1)) + // &~bytes32(uint256(0xff)) + bytes32 private constant STAKER_CAP_DEPOSITS_STORAGE_LOCATION = + 0x965a89691c17af92914eadf0e487b628b4de164741f52e43f2d8c224cfe56100; + + function _getStakerCapDepositsStorage() private pure returns (StakerCapDepositsStorage storage $) { + assembly { + $.slot := STAKER_CAP_DEPOSITS_STORAGE_LOCATION + } + } + /// @notice Initializes the `StakerCapDepositsUpgradeable` contract. /// @param _initialTotalStakeCap The initial maximum total stake allowed. - constructor(uint256 _initialTotalStakeCap) { + function __StakerCapDepositsUpgradeable_init(uint256 _initialTotalStakeCap) + internal + onlyInitializing + { + __StakerCapDepositsUpgradeable_init_unchained(_initialTotalStakeCap); + } + + /// @notice Initializes the `StakerCapDepositsUpgradeable` contract. + /// @param _initialTotalStakeCap The initial maximum total stake allowed. + function __StakerCapDepositsUpgradeable_init_unchained(uint256 _initialTotalStakeCap) + internal + onlyInitializing + { _setTotalStakeCap(_initialTotalStakeCap); } + /// @notice The maximum total amount of tokens that can be staked across all deposits. + function totalStakeCap() public view returns (uint256) { + StakerCapDepositsStorage storage $ = _getStakerCapDepositsStorage(); + return $._totalStakeCap; + } + /// @notice Sets a new maximum total stake cap. /// @param _newTotalStakeCap The new maximum total stake allowed. /// @dev Caller must be the current admin. @@ -40,31 +72,32 @@ abstract contract StakerCapDeposits is Staker { /// @notice Internal helper method which sets a new total stake cap. /// @param _newTotalStakeCap The new maximum total stake allowed. function _setTotalStakeCap(uint256 _newTotalStakeCap) internal { - emit TotalStakeCapSet(totalStakeCap, _newTotalStakeCap); - totalStakeCap = _newTotalStakeCap; + StakerCapDepositsStorage storage $ = _getStakerCapDepositsStorage(); + emit TotalStakeCapSet($._totalStakeCap, _newTotalStakeCap); + $._totalStakeCap = _newTotalStakeCap; } - /// @inheritdoc Staker + /// @inheritdoc StakerUpgradeable /// @dev Checks if the stake would exceed the total stake cap before proceeding. function _stake(address _depositor, uint256 _amount, address _delegatee, address _claimer) internal virtual - override(Staker) + override(StakerUpgradeable) returns (DepositIdentifier _depositId) { _revertIfCapExceeded(_amount); - return Staker._stake(_depositor, _amount, _delegatee, _claimer); + return StakerUpgradeable._stake(_depositor, _amount, _delegatee, _claimer); } - /// @inheritdoc Staker + /// @inheritdoc StakerUpgradeable /// @dev Checks if the additional stake would exceed the total stake cap before proceeding. function _stakeMore(Deposit storage deposit, DepositIdentifier _depositId, uint256 _amount) internal virtual - override(Staker) + override(StakerUpgradeable) { _revertIfCapExceeded(_amount); - Staker._stakeMore(deposit, _depositId, _amount); + StakerUpgradeable._stakeMore(deposit, _depositId, _amount); } /// @notice Internal helper method which reverts if adding a given stake amount would exceed the @@ -73,6 +106,9 @@ abstract contract StakerCapDeposits is Staker { /// @dev Reverts with StakerCapDeposits__CapExceeded if the amount would cause total stake to /// exceed the cap. function _revertIfCapExceeded(uint256 _amount) internal view virtual { - if ((totalStaked + _amount) > totalStakeCap) revert StakerCapDeposits__CapExceeded(); + StakerCapDepositsStorage storage $ = _getStakerCapDepositsStorage(); + if ((totalStaked() + _amount) > $._totalStakeCap) { + revert StakerCapDepositsUpgradeable__CapExceeded(); + } } } diff --git a/src/extensions/StakerDelegateSurrogateVotes.sol b/src/extensions/StakerDelegateSurrogateVotes.sol deleted file mode 100644 index 7db98aa1..00000000 --- a/src/extensions/StakerDelegateSurrogateVotes.sol +++ /dev/null @@ -1,52 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only -pragma solidity ^0.8.23; - -import {DelegationSurrogate} from "../DelegationSurrogate.sol"; -import {DelegationSurrogateVotes} from "../DelegationSurrogateVotes.sol"; -import {Staker} from "../Staker.sol"; -import {IERC20Delegates} from "../interfaces/IERC20Delegates.sol"; - -/// @title StakerDelegateSurrogateVotes -/// @author [ScopeLift](https://scopelift.co) -/// @notice This contract extension adds delegation surrogates to the Staker base -/// contract, allowing staked tokens to be delegated to a specific delegate. -abstract contract StakerDelegateSurrogateVotes is Staker { - /// @notice Emitted when a surrogate contract is deployed. - event SurrogateDeployed(address indexed delegatee, address indexed surrogate); - - /// @notice Maps the account of each governance delegate with the surrogate contract which holds - /// the staked tokens from deposits which assign voting weight to said delegate. - mapping(address delegatee => DelegationSurrogate surrogate) private storedSurrogates; - - /// @notice Thrown if an inheritor misconfigures the staking token on deployment. - error StakerDelegateSurrogateVotes__UnauthorizedToken(); - - /// @param _votingToken The token that is used for voting, which must be the same as the parent - /// Staker's STAKE_TOKEN. - constructor(IERC20Delegates _votingToken) { - if (address(STAKE_TOKEN) != address(_votingToken)) { - revert StakerDelegateSurrogateVotes__UnauthorizedToken(); - } - } - - /// @inheritdoc Staker - function surrogates(address _delegatee) public view override returns (DelegationSurrogate) { - return storedSurrogates[_delegatee]; - } - - /// @inheritdoc Staker - function _fetchOrDeploySurrogate(address _delegatee) - internal - virtual - override - returns (DelegationSurrogate _surrogate) - { - _surrogate = storedSurrogates[_delegatee]; - - if (address(_surrogate) == address(0)) { - _surrogate = new DelegationSurrogateVotes(IERC20Delegates(address(STAKE_TOKEN)), _delegatee); - storedSurrogates[_delegatee] = _surrogate; - emit SurrogateDeployed(_delegatee, address(_surrogate)); - } - } -} diff --git a/src/extensions/StakerDelegateSurrogateVotesUpgradeable.sol b/src/extensions/StakerDelegateSurrogateVotesUpgradeable.sol new file mode 100644 index 00000000..30790feb --- /dev/null +++ b/src/extensions/StakerDelegateSurrogateVotesUpgradeable.sol @@ -0,0 +1,93 @@ +// SPDX-License-Identifier: AGPL-3.0-only +pragma solidity ^0.8.23; + +import {DelegationSurrogate} from "../DelegationSurrogate.sol"; +import {DelegationSurrogateVotes} from "../DelegationSurrogateVotes.sol"; +import {StakerUpgradeable} from "../StakerUpgradeable.sol"; +import {IERC20Delegates} from "../interfaces/IERC20Delegates.sol"; + +/// @title StakerDelegateSurrogateVotes +/// @author [ScopeLift](https://scopelift.co) +/// @notice This contract extension adds delegation surrogates to the Staker base +/// contract, allowing staked tokens to be delegated to a specific delegate. +abstract contract StakerDelegateSurrogateVotesUpgradeable is StakerUpgradeable { + /// @notice Emitted when a surrogate contract is deployed. + event SurrogateDeployed(address indexed delegatee, address indexed surrogate); + + /// @notice Thrown if an inheritor misconfigures the staking token on deployment. + error StakerDelegateSurrogateVotesUpgradeable__UnauthorizedToken(); + + struct StakerDelegateSurrogateVotesStorage { + /// @notice Maps the account of each governance delegate with the surrogate contract which holds + /// the staked tokens from deposits which assign voting weight to said delegate. + mapping(address delegatee => DelegationSurrogate surrogate) _storedSurrogates; + } + + // keccak256(abi.encode(uint256(keccak256("storage.scopelift.StakerDelegateSurrogateVotes")) - 1)) + // &~bytes32(uint256(0xff)) + bytes32 private constant STAKER_DELEGATE_SURROGATE_STORAGE_LOCATION = + 0x010103b2a019a28f51fa63a98fe162dac866120b721518e29f318125463ff100; + + function _getStakerDelegateSurrogateStorage() + private + pure + returns (StakerDelegateSurrogateVotesStorage storage $) + { + assembly { + $.slot := STAKER_DELEGATE_SURROGATE_STORAGE_LOCATION + } + } + + /// @notice Initializes the `StakerDelegateSurrogateVotesUpgradeable` contract. + /// @param _votingToken The token that is used for voting, which must be the same as the parent + /// Staker's STAKE_TOKEN. + function __StakerDelegateSurrogateVotesUpgradeable_init(IERC20Delegates _votingToken) + internal + onlyInitializing + { + __StakerDelegateSurrogateVotesUpgradeable_init_unchained(_votingToken); + } + + /// @notice Initializes the `StakerDelegateSurrogateVotesUpgradeable` contract. + /// @param _votingToken The token that is used for voting, which must be the same as the parent + /// Staker's STAKE_TOKEN. + function __StakerDelegateSurrogateVotesUpgradeable_init_unchained(IERC20Delegates _votingToken) + internal + onlyInitializing + { + if (address(STAKE_TOKEN()) != address(_votingToken)) { + revert StakerDelegateSurrogateVotesUpgradeable__UnauthorizedToken(); + } + } + + /// @inheritdoc StakerUpgradeable + function surrogates(address _delegatee) public view override returns (DelegationSurrogate) { + StakerDelegateSurrogateVotesStorage storage $ = _getStakerDelegateSurrogateStorage(); + return $._storedSurrogates[_delegatee]; + } + + /// @notice Maps the account of each governance delegate with the surrogate contract. + /// @param _delegatee The address of the delegatee. + /// @return The surrogate contract address for the given delegatee. + function storedSurrogates(address _delegatee) public view returns (DelegationSurrogate) { + StakerDelegateSurrogateVotesStorage storage $ = _getStakerDelegateSurrogateStorage(); + return $._storedSurrogates[_delegatee]; + } + + /// @inheritdoc StakerUpgradeable + function _fetchOrDeploySurrogate(address _delegatee) + internal + virtual + override + returns (DelegationSurrogate _surrogate) + { + StakerDelegateSurrogateVotesStorage storage $ = _getStakerDelegateSurrogateStorage(); + _surrogate = $._storedSurrogates[_delegatee]; + + if (address(_surrogate) == address(0)) { + _surrogate = new DelegationSurrogateVotes(IERC20Delegates(address(STAKE_TOKEN())), _delegatee); + $._storedSurrogates[_delegatee] = _surrogate; + emit SurrogateDeployed(_delegatee, address(_surrogate)); + } + } +} diff --git a/src/extensions/StakerOnBehalf.sol b/src/extensions/StakerOnBehalfUpgradeable.sol similarity index 90% rename from src/extensions/StakerOnBehalf.sol rename to src/extensions/StakerOnBehalfUpgradeable.sol index 7b1ec61d..21be095d 100644 --- a/src/extensions/StakerOnBehalf.sol +++ b/src/extensions/StakerOnBehalfUpgradeable.sol @@ -1,10 +1,11 @@ // SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.23; -import {Staker} from "../Staker.sol"; +import {StakerUpgradeable} from "../StakerUpgradeable.sol"; import {SignatureChecker} from "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol"; -import {Nonces} from "@openzeppelin/contracts/utils/Nonces.sol"; -import {EIP712} from "@openzeppelin/contracts/utils/cryptography/EIP712.sol"; +import {EIP712Upgradeable} from + "@openzeppelin/contracts-upgradeable/utils/cryptography/EIP712Upgradeable.sol"; +import {NoncesUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/NoncesUpgradeable.sol"; /// @title StakerOnBehalf /// @author [ScopeLift](https://scopelift.co) @@ -14,12 +15,16 @@ import {EIP712} from "@openzeppelin/contracts/utils/cryptography/EIP712.sol"; /// altering delegatees and claimers, and claiming rewards. Each operation requires a unique /// signature that is validated against the appropriate signer (owner or claimer) before /// execution. -abstract contract StakerOnBehalf is Staker, EIP712, Nonces { +abstract contract StakerOnBehalfUpgradeable is + StakerUpgradeable, + EIP712Upgradeable, + NoncesUpgradeable +{ /// @notice Thrown when an onBehalf method is called with a deadline that has expired. - error StakerOnBehalf__ExpiredDeadline(); + error StakerOnBehalfUpgradeable__ExpiredDeadline(); /// @notice Thrown if a caller supplies an invalid signature to a method that requires one. - error StakerOnBehalf__InvalidSignature(); + error StakerOnBehalfUpgradeable__InvalidSignature(); /// @notice Type hash used when encoding data for `stakeOnBehalf` calls. bytes32 public constant STAKE_TYPEHASH = keccak256( @@ -51,6 +56,12 @@ abstract contract StakerOnBehalf is Staker, EIP712, Nonces { return _domainSeparatorV4(); } + /// @notice Initializes the `StakerOnBehalfUpgradeable` contract. + function __StakerOnBehalfUpgradeable_init() internal onlyInitializing {} + + /// @notice Initializes the `StakerOnBehalfUpgradeable` contract. + function __StakerOnBehalfUpgradeable_init_unchained() internal onlyInitializing {} + /// @notice Allows an address to increment their nonce and therefore invalidate any pending signed /// actions. function invalidateNonce() external virtual { @@ -114,7 +125,7 @@ abstract contract StakerOnBehalf is Staker, EIP712, Nonces { uint256 _deadline, bytes memory _signature ) external virtual { - Deposit storage deposit = deposits[_depositId]; + Deposit storage deposit = _getDeposit(_depositId); _revertIfNotDepositOwner(deposit, _depositor); _revertIfPastDeadline(_deadline); _revertIfSignatureIsNotValidNow( @@ -147,7 +158,7 @@ abstract contract StakerOnBehalf is Staker, EIP712, Nonces { uint256 _deadline, bytes memory _signature ) external virtual { - Deposit storage deposit = deposits[_depositId]; + Deposit storage deposit = _getDeposit(_depositId); _revertIfNotDepositOwner(deposit, _depositor); _revertIfPastDeadline(_deadline); _revertIfSignatureIsNotValidNow( @@ -186,7 +197,7 @@ abstract contract StakerOnBehalf is Staker, EIP712, Nonces { uint256 _deadline, bytes memory _signature ) external virtual { - Deposit storage deposit = deposits[_depositId]; + Deposit storage deposit = _getDeposit(_depositId); _revertIfNotDepositOwner(deposit, _depositor); _revertIfPastDeadline(_deadline); _revertIfSignatureIsNotValidNow( @@ -224,7 +235,7 @@ abstract contract StakerOnBehalf is Staker, EIP712, Nonces { uint256 _deadline, bytes memory _signature ) external virtual { - Deposit storage deposit = deposits[_depositId]; + Deposit storage deposit = _getDeposit(_depositId); _revertIfNotDepositOwner(deposit, _depositor); _revertIfPastDeadline(_deadline); _revertIfSignatureIsNotValidNow( @@ -255,7 +266,7 @@ abstract contract StakerOnBehalf is Staker, EIP712, Nonces { bytes memory _signature ) external virtual returns (uint256) { _revertIfPastDeadline(_deadline); - Deposit storage deposit = deposits[_depositId]; + Deposit storage deposit = _getDeposit(_depositId); bytes32 _claimerHash = _hashTypedDataV4( keccak256(abi.encode(CLAIM_REWARD_TYPEHASH, _depositId, nonces(deposit.claimer), _deadline)) ); @@ -271,7 +282,7 @@ abstract contract StakerOnBehalf is Staker, EIP712, Nonces { ); bool _isValidOwnerClaim = SignatureChecker.isValidSignatureNow(deposit.owner, _ownerHash, _signature); - if (!_isValidOwnerClaim) revert StakerOnBehalf__InvalidSignature(); + if (!_isValidOwnerClaim) revert StakerOnBehalfUpgradeable__InvalidSignature(); return _claimReward(_depositId, deposit, deposit.owner); } @@ -279,7 +290,7 @@ abstract contract StakerOnBehalf is Staker, EIP712, Nonces { /// provided deadline has passed. /// @param _deadline The timestamp that represents when the operation should no longer be valid. function _revertIfPastDeadline(uint256 _deadline) internal view virtual { - if (block.timestamp > _deadline) revert StakerOnBehalf__ExpiredDeadline(); + if (block.timestamp > _deadline) revert StakerOnBehalfUpgradeable__ExpiredDeadline(); } /// @notice Internal helper method which reverts with Staker__InvalidSignature if the @@ -293,6 +304,6 @@ abstract contract StakerOnBehalf is Staker, EIP712, Nonces { virtual { bool _isValid = SignatureChecker.isValidSignatureNow(_signer, _hash, _signature); - if (!_isValid) revert StakerOnBehalf__InvalidSignature(); + if (!_isValid) revert StakerOnBehalfUpgradeable__InvalidSignature(); } } diff --git a/src/extensions/StakerPermitAndStake.sol b/src/extensions/StakerPermitAndStakeUpgradeable.sol similarity index 76% rename from src/extensions/StakerPermitAndStake.sol rename to src/extensions/StakerPermitAndStakeUpgradeable.sol index 06702f8f..fb4a6f45 100644 --- a/src/extensions/StakerPermitAndStake.sol +++ b/src/extensions/StakerPermitAndStakeUpgradeable.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.23; -import {Staker} from "../Staker.sol"; +import {StakerUpgradeable} from "../StakerUpgradeable.sol"; import {IERC20Permit} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol"; /// @title StakerPermitAndStake @@ -11,15 +11,29 @@ import {IERC20Permit} from "@openzeppelin/contracts/token/ERC20/extensions/IERC2 /// The permit functionality is used in conjunction with staking operations, improving UX by /// enabling users to approve and stake tokens in a single transaction. Note that this extension /// requires the stake token to support EIP-2612 permit functionality. -abstract contract StakerPermitAndStake is Staker { +abstract contract StakerPermitAndStakeUpgradeable is StakerUpgradeable { /// @notice Thrown if an inheritor misconfigures the staking token on deployment. - error StakerPermitAndStake__UnauthorizedToken(); + error StakerPermitAndStakeUpgradeable__UnauthorizedToken(); + /// @notice Initializes the `StakerPermitAndStakeUpgradeable` contract. /// @param _permitToken The token that is used for staking, which must support EIP-2612. It also /// must be the same as the parent Staker's STAKE_TOKEN. - constructor(IERC20Permit _permitToken) { - if (address(STAKE_TOKEN) != address(_permitToken)) { - revert StakerPermitAndStake__UnauthorizedToken(); + function __StakerPermitAndStakeUpgradeable_init(IERC20Permit _permitToken) + internal + onlyInitializing + { + __StakerPermitAndStakeUpgradeable_init_unchained(_permitToken); + } + + /// @notice Initializes the `StakerPermitAndStakeUpgradeable` contract. + /// @param _permitToken The token that is used for staking, which must support EIP-2612. It also + /// must be the same as the parent Staker's STAKE_TOKEN. + function __StakerPermitAndStakeUpgradeable_init_unchained(IERC20Permit _permitToken) + internal + onlyInitializing + { + if (address(STAKE_TOKEN()) != address(_permitToken)) { + revert StakerPermitAndStakeUpgradeable__UnauthorizedToken(); } } @@ -45,7 +59,7 @@ abstract contract StakerPermitAndStake is Staker { bytes32 _r, bytes32 _s ) external virtual returns (DepositIdentifier _depositId) { - try IERC20Permit(address(STAKE_TOKEN)).permit( + try IERC20Permit(address(STAKE_TOKEN())).permit( msg.sender, address(this), _amount, _deadline, _v, _r, _s ) {} catch {} _depositId = _stake(msg.sender, _amount, _delegatee, _claimer); @@ -70,10 +84,10 @@ abstract contract StakerPermitAndStake is Staker { bytes32 _r, bytes32 _s ) external virtual { - Deposit storage deposit = deposits[_depositId]; + Deposit storage deposit = _getDeposit(_depositId); _revertIfNotDepositOwner(deposit, msg.sender); - try IERC20Permit(address(STAKE_TOKEN)).permit( + try IERC20Permit(address(STAKE_TOKEN())).permit( msg.sender, address(this), _amount, _deadline, _v, _r, _s ) {} catch {} _stakeMore(deposit, _depositId, _amount); diff --git a/src/script/DeployBase.sol b/src/script/DeployBase.sol index 7aabee66..ca18d146 100644 --- a/src/script/DeployBase.sol +++ b/src/script/DeployBase.sol @@ -5,7 +5,7 @@ pragma solidity ^0.8.23; import {Script} from "forge-std/Script.sol"; import {IEarningPowerCalculator} from "../interfaces/IEarningPowerCalculator.sol"; -import {Staker} from "../Staker.sol"; +import {StakerUpgradeable} from "../StakerUpgradeable.sol"; /// @title DeployBase /// @author [ScopeLift](https://scopelift.co) @@ -43,22 +43,22 @@ abstract contract DeployBase is Script { function _deployStaker(IEarningPowerCalculator _earningPowerCalculator) internal virtual - returns (Staker); + returns (StakerUpgradeable); /// @notice An interface method that deploys the earning power contract for the staking system. /// @return The earning power calculator contract. function _deployEarningPowerCalculator() internal virtual returns (IEarningPowerCalculator); /// @notice An interface method that deploys the reward notifiers. - /// @param _staker The Staker for the staking system. + /// @param _staker The StakerUpgradeable for the staking system. /// @dev When this method is overridden make sure to add the reward notifier to the /// `rewardNotifiers` array. - function _deployRewardNotifiers(Staker _staker) internal virtual; + function _deployRewardNotifiers(StakerUpgradeable _staker) internal virtual; /// @notice The method that is executed when the script runs which deploys the entire staking /// system. /// @return The Staker contract, earning power calculator, and array of reward notifiers. - function run() public returns (IEarningPowerCalculator, Staker, address[] memory) { + function run() public returns (IEarningPowerCalculator, StakerUpgradeable, address[] memory) { uint256 deployerPrivateKey = vm.envOr( "DEPLOYER_PRIVATE_KEY", uint256(0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80) @@ -67,7 +67,7 @@ abstract contract DeployBase is Script { deployer = vm.rememberKey(deployerPrivateKey); vm.startBroadcast(deployer); IEarningPowerCalculator _earningPowerCalculator = _deployEarningPowerCalculator(); - Staker _staker = _deployStaker(_earningPowerCalculator); + StakerUpgradeable _staker = _deployStaker(_earningPowerCalculator); if (_staker.admin() != deployer) revert DeployBase__InvalidInitialStakerAdmin(); _deployRewardNotifiers(_staker); diff --git a/src/script/DeployStaker.sol b/src/script/DeployStaker.sol index 46530626..2ed78f7c 100644 --- a/src/script/DeployStaker.sol +++ b/src/script/DeployStaker.sol @@ -5,7 +5,6 @@ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {DeployBase} from "./DeployBase.sol"; import {IEarningPowerCalculator} from "../interfaces/IEarningPowerCalculator.sol"; -import {Staker} from "../Staker.sol"; /// @title DeployStaker /// @author [ScopeLift](https://scopelift.co) diff --git a/src/script/notifiers/DeployMintRewardNotifier.sol b/src/script/notifiers/DeployMintRewardNotifier.sol index c0b0024e..cd391f85 100644 --- a/src/script/notifiers/DeployMintRewardNotifier.sol +++ b/src/script/notifiers/DeployMintRewardNotifier.sol @@ -5,7 +5,7 @@ import {INotifiableRewardReceiver} from "../../interfaces/INotifiableRewardRecei import {IMintable} from "../../interfaces/IMintable.sol"; import {DeployBase} from "../DeployBase.sol"; import {MintRewardNotifier} from "../../notifiers/MintRewardNotifier.sol"; -import {Staker} from "../../Staker.sol"; +import {StakerUpgradeable} from "../../StakerUpgradeable.sol"; /// @title DeployMintRewardNotifer /// @author [ScopeLift](https://scopelift.co) @@ -40,7 +40,7 @@ abstract contract DeployMintRewardNotifier is DeployBase { /// @inheritdoc DeployBase /// @dev When this method is overridden make sure to call super so it is added to the reward /// notifiers array. - function _deployRewardNotifiers(Staker _staker) internal virtual override { + function _deployRewardNotifiers(StakerUpgradeable _staker) internal virtual override { MintRewardNotifierConfiguration memory _config = _mintRewardNotifierConfiguration(); MintRewardNotifier _notifier = new MintRewardNotifier( INotifiableRewardReceiver(address(_staker)), diff --git a/src/script/notifiers/DeployTransferFromRewardNotifier.sol b/src/script/notifiers/DeployTransferFromRewardNotifier.sol index f9a6ff6f..bafed3f1 100644 --- a/src/script/notifiers/DeployTransferFromRewardNotifier.sol +++ b/src/script/notifiers/DeployTransferFromRewardNotifier.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.23; import {INotifiableRewardReceiver} from "../../interfaces/INotifiableRewardReceiver.sol"; import {TransferFromRewardNotifier} from "../../notifiers/TransferFromRewardNotifier.sol"; import {DeployBase} from "../DeployBase.sol"; -import {Staker} from "../../Staker.sol"; +import {StakerUpgradeable} from "../../StakerUpgradeable.sol"; /// @title DeployTransferFromRewardNotifier /// @author [ScopeLift](https://scopelift.co) @@ -38,7 +38,7 @@ abstract contract DeployTransferFromRewardNotifier is DeployBase { /// @inheritdoc DeployBase /// @dev When this method is overridden make sure to call super so it is added to the reward /// notifiers array. - function _deployRewardNotifiers(Staker _staker) internal virtual override { + function _deployRewardNotifiers(StakerUpgradeable _staker) internal virtual override { TransferFromRewardNotifierConfiguration memory _config = _transferFromRewardNotifierConfiguration(); TransferFromRewardNotifier _notifier = new TransferFromRewardNotifier( diff --git a/src/script/notifiers/DeployTransferRewardNotifier.sol b/src/script/notifiers/DeployTransferRewardNotifier.sol index bdf301ed..b60d98d3 100644 --- a/src/script/notifiers/DeployTransferRewardNotifier.sol +++ b/src/script/notifiers/DeployTransferRewardNotifier.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.23; import {INotifiableRewardReceiver} from "../../interfaces/INotifiableRewardReceiver.sol"; import {TransferRewardNotifier} from "../../notifiers/TransferRewardNotifier.sol"; import {DeployBase} from "../DeployBase.sol"; -import {Staker} from "../../Staker.sol"; +import {StakerUpgradeable} from "../../StakerUpgradeable.sol"; /// @title DeployTransferRewardNotifier /// @author [ScopeLift](https://scopelift.co) @@ -36,7 +36,7 @@ abstract contract DeployTransferRewardNotifier is DeployBase { /// @inheritdoc DeployBase /// @dev When this method is overridden make sure to call super so it is added to the reward /// notifiers array. - function _deployRewardNotifiers(Staker _staker) internal virtual override { + function _deployRewardNotifiers(StakerUpgradeable _staker) internal virtual override { TransferRewardNotifierConfiguration memory _config = _transferRewardNotifierConfiguration(); TransferRewardNotifier _notifier = new TransferRewardNotifier( INotifiableRewardReceiver(address(_staker)), diff --git a/test/Staker.invariants.t.sol b/test/Staker.invariants.t.sol index 4826a86b..ab8ab7e7 100644 --- a/test/Staker.invariants.t.sol +++ b/test/Staker.invariants.t.sol @@ -3,8 +3,9 @@ pragma solidity ^0.8.23; import {Test} from "forge-std/Test.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; -import {IEarningPowerCalculator} from "../src/Staker.sol"; +import {IEarningPowerCalculator} from "../src/StakerUpgradeable.sol"; import {StakerHandler} from "./helpers/Staker.handler.sol"; import {StakerHarness} from "./harnesses/StakerHarness.sol"; import {ERC20VotesMock} from "./mocks/MockERC20Votes.sol"; @@ -34,9 +35,23 @@ contract StakerInvariants is Test { earningPowerCalculator = new MockFullEarningPowerCalculator(); vm.label(address(earningPowerCalculator), "Full Earning Power Calculator"); - govStaker = new StakerHarness( - rewardToken, govToken, earningPowerCalculator, maxBumpTip, rewardsNotifier, STAKER_NAME + StakerHarness implementation = new StakerHarness(); + ERC1967Proxy proxy = new ERC1967Proxy( + address(implementation), + abi.encodeCall( + StakerHarness.initialize, + ( + rewardToken, + govToken, + 1e18, + rewardsNotifier, + maxBumpTip, + earningPowerCalculator, + STAKER_NAME + ) + ) ); + govStaker = StakerHarness(address(proxy)); handler = new StakerHandler(govStaker); bytes4[] memory selectors = new bytes4[](7); diff --git a/test/Staker.t.sol b/test/Staker.t.sol index 8d1a2095..2b68c1ee 100644 --- a/test/Staker.t.sol +++ b/test/Staker.t.sol @@ -3,16 +3,17 @@ pragma solidity ^0.8.23; import {Vm, Test, stdStorage, StdStorage, console2, stdError} from "forge-std/Test.sol"; import {StakerTestBase} from "./StakerTestBase.sol"; -import {Staker, IERC20, IEarningPowerCalculator} from "../src/Staker.sol"; +import {StakerUpgradeable, IERC20, IEarningPowerCalculator} from "../src/StakerUpgradeable.sol"; import {IERC20Staking} from "../src/interfaces/IERC20Staking.sol"; import {DelegationSurrogate} from "../src/DelegationSurrogate.sol"; import {StakerHarness} from "./harnesses/StakerHarness.sol"; import { MockStakerHarness, - StakerDelegateSurrogateVotes, - StakerPermitAndStake + StakerDelegateSurrogateVotesUpgradeable, + StakerPermitAndStakeUpgradeable } from "./mocks/MockStakerHarness.sol"; import {IERC20Errors} from "@openzeppelin/contracts/interfaces/draft-IERC6093.sol"; +import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; contract StakerTest is StakerTestBase { StakerHarness govStaker; @@ -30,9 +31,21 @@ contract StakerTest is StakerTestBase { EIP712_DOMAIN_SEPARATOR = govStaker.DOMAIN_SEPARATOR(); } - function _deployStaker() public virtual override(StakerTestBase) returns (Staker _staker) { - return - new StakerHarness(rewardToken, govToken, earningPowerCalculator, maxBumpTip, admin, "Staker"); + function _deployStaker() + public + virtual + override(StakerTestBase) + returns (StakerUpgradeable _staker) + { + StakerHarness _govStaker = new StakerHarness(); + ERC1967Proxy proxy = new ERC1967Proxy( + address(_govStaker), + abi.encodeCall( + StakerHarness.initialize, + (rewardToken, govToken, 1e18, admin, maxBumpTip, earningPowerCalculator, "Staker") + ) + ); + return StakerHarness(address(proxy)); } function _sign(uint256 _privateKey, bytes32 _messageHash) internal pure returns (bytes memory) { @@ -79,14 +92,24 @@ contract Constructor is StakerTest { string memory _name ) public { vm.assume(_admin != address(0) && _earningPowerCalculator != address(0)); - StakerHarness _govStaker = new StakerHarness( - IERC20(_rewardToken), - IERC20Staking(_stakeToken), - IEarningPowerCalculator(_earningPowerCalculator), - _maxBumpTip, - _admin, - _name + StakerHarness implementation = new StakerHarness(); + ERC1967Proxy proxy = new ERC1967Proxy( + address(implementation), + abi.encodeCall( + StakerHarness.initialize, + ( + IERC20(_rewardToken), + IERC20(_stakeToken), + 1e18, + _admin, + _maxBumpTip, + IEarningPowerCalculator(_earningPowerCalculator), + _name + ) + ) ); + StakerHarness _govStaker = StakerHarness(address(proxy)); + assertEq(address(_govStaker.REWARD_TOKEN()), address(_rewardToken)); assertEq(address(_govStaker.STAKE_TOKEN()), address(_stakeToken)); assertEq(address(_govStaker.earningPowerCalculator()), address(_earningPowerCalculator)); @@ -104,17 +127,26 @@ contract Constructor is StakerTest { ) public { vm.assume(_admin != address(0) && _earningPowerCalculator != address(0)); vm.assume(address(_stakerStateToken) != address(_delegateSurrogateStakeToken)); + MockStakerHarness implementation = new MockStakerHarness(); vm.expectRevert( - StakerDelegateSurrogateVotes.StakerDelegateSurrogateVotes__UnauthorizedToken.selector + StakerDelegateSurrogateVotesUpgradeable + .StakerDelegateSurrogateVotesUpgradeable__UnauthorizedToken + .selector ); - new MockStakerHarness( - IERC20(_rewardToken), - IERC20Staking(_stakerStateToken), - IERC20Staking(_stakerStateToken), - IERC20Staking(_delegateSurrogateStakeToken), - IEarningPowerCalculator(_earningPowerCalculator), - _maxBumpTip, - _admin + new ERC1967Proxy( + address(implementation), + abi.encodeCall( + MockStakerHarness.initialize, + ( + IERC20(_rewardToken), + IERC20Staking(_stakerStateToken), + IERC20Staking(_stakerStateToken), + IERC20Staking(_delegateSurrogateStakeToken), + IEarningPowerCalculator(_earningPowerCalculator), + _admin, + _maxBumpTip + ) + ) ); } @@ -128,15 +160,24 @@ contract Constructor is StakerTest { ) public { vm.assume(_admin != address(0) && _earningPowerCalculator != address(0)); vm.assume(address(_stakerStateToken) != address(_permitAndStakeStakeToken)); - vm.expectRevert(StakerPermitAndStake.StakerPermitAndStake__UnauthorizedToken.selector); - new MockStakerHarness( - IERC20(_rewardToken), - IERC20Staking(_stakerStateToken), - IERC20Staking(_permitAndStakeStakeToken), - IERC20Staking(_stakerStateToken), - IEarningPowerCalculator(_earningPowerCalculator), - _maxBumpTip, - _admin + MockStakerHarness implementation = new MockStakerHarness(); + vm.expectRevert( + StakerPermitAndStakeUpgradeable.StakerPermitAndStakeUpgradeable__UnauthorizedToken.selector + ); + new ERC1967Proxy( + address(implementation), + abi.encodeCall( + MockStakerHarness.initialize, + ( + IERC20(_rewardToken), + IERC20Staking(_stakerStateToken), + IERC20Staking(_permitAndStakeStakeToken), + IERC20Staking(_stakerStateToken), + IEarningPowerCalculator(_earningPowerCalculator), + _admin, + _maxBumpTip + ) + ) ); } } @@ -169,9 +210,9 @@ contract Stake is StakerTest { vm.startPrank(_depositor); govToken.approve(address(govStaker), _amount); - Staker.DepositIdentifier _depositId = _stake(_depositor, _amount, _delegatee); + StakerUpgradeable.DepositIdentifier _depositId = _stake(_depositor, _amount, _delegatee); - Staker.Deposit memory _deposit = _fetchDeposit(_depositId); + StakerUpgradeable.Deposit memory _deposit = _fetchDeposit(_depositId); assertEq(_deposit.claimer, _depositor); } @@ -182,16 +223,18 @@ contract Stake is StakerTest { ) public { _amount = bound(_amount, 1, type(uint96).max); _mintGovToken(_depositor, _amount); - Staker.DepositIdentifier depositId = govStaker.exposed_useDepositId(); + StakerUpgradeable.DepositIdentifier depositId = govStaker.exposed_useDepositId(); vm.assume(_delegatee != address(0)); vm.startPrank(_depositor); govToken.approve(address(govStaker), _amount); vm.expectEmit(); - emit Staker.StakeDeposited( + emit StakerUpgradeable.StakeDeposited( _depositor, - Staker.DepositIdentifier.wrap(Staker.DepositIdentifier.unwrap(depositId) + 1), + StakerUpgradeable.DepositIdentifier.wrap( + StakerUpgradeable.DepositIdentifier.unwrap(depositId) + 1 + ), _amount, _amount, _amount @@ -208,15 +251,17 @@ contract Stake is StakerTest { ) public { _amount = bound(_amount, 1, type(uint96).max); _mintGovToken(_depositor, _amount); - Staker.DepositIdentifier depositId = govStaker.exposed_useDepositId(); + StakerUpgradeable.DepositIdentifier depositId = govStaker.exposed_useDepositId(); vm.assume(_delegatee != address(0)); vm.startPrank(_depositor); govToken.approve(address(govStaker), _amount); vm.expectEmit(); - emit Staker.ClaimerAltered( - Staker.DepositIdentifier.wrap(Staker.DepositIdentifier.unwrap(depositId) + 1), + emit StakerUpgradeable.ClaimerAltered( + StakerUpgradeable.DepositIdentifier.wrap( + StakerUpgradeable.DepositIdentifier.unwrap(depositId) + 1 + ), address(0), _depositor, _amount @@ -233,15 +278,17 @@ contract Stake is StakerTest { ) public { _amount = bound(_amount, 1, type(uint96).max); _mintGovToken(_depositor, _amount); - Staker.DepositIdentifier depositId = govStaker.exposed_useDepositId(); + StakerUpgradeable.DepositIdentifier depositId = govStaker.exposed_useDepositId(); vm.assume(_delegatee != address(0)); vm.startPrank(_depositor); govToken.approve(address(govStaker), _amount); vm.expectEmit(); - emit Staker.DelegateeAltered( - Staker.DepositIdentifier.wrap(Staker.DepositIdentifier.unwrap(depositId) + 1), + emit StakerUpgradeable.DelegateeAltered( + StakerUpgradeable.DepositIdentifier.wrap( + StakerUpgradeable.DepositIdentifier.unwrap(depositId) + 1 + ), address(0), _delegatee, _amount @@ -263,9 +310,10 @@ contract Stake is StakerTest { vm.startPrank(_depositor); govToken.approve(address(govStaker), _amount); - Staker.DepositIdentifier _depositId = _stake(_depositor, _amount, _delegatee, _claimer); + StakerUpgradeable.DepositIdentifier _depositId = + _stake(_depositor, _amount, _delegatee, _claimer); - Staker.Deposit memory _deposit = _fetchDeposit(_depositId); + StakerUpgradeable.Deposit memory _deposit = _fetchDeposit(_depositId); assertEq(_deposit.claimer, _claimer); } @@ -277,16 +325,18 @@ contract Stake is StakerTest { ) public { _amount = bound(_amount, 1, type(uint96).max); _mintGovToken(_depositor, _amount); - Staker.DepositIdentifier depositId = govStaker.exposed_useDepositId(); + StakerUpgradeable.DepositIdentifier depositId = govStaker.exposed_useDepositId(); vm.assume(_delegatee != address(0) && _claimer != address(0)); vm.startPrank(_depositor); govToken.approve(address(govStaker), _amount); vm.expectEmit(); - emit Staker.StakeDeposited( + emit StakerUpgradeable.StakeDeposited( _depositor, - Staker.DepositIdentifier.wrap(Staker.DepositIdentifier.unwrap(depositId) + 1), + StakerUpgradeable.DepositIdentifier.wrap( + StakerUpgradeable.DepositIdentifier.unwrap(depositId) + 1 + ), _amount, _amount, _amount @@ -304,15 +354,17 @@ contract Stake is StakerTest { ) public { _amount = bound(_amount, 1, type(uint96).max); _mintGovToken(_depositor, _amount); - Staker.DepositIdentifier depositId = govStaker.exposed_useDepositId(); + StakerUpgradeable.DepositIdentifier depositId = govStaker.exposed_useDepositId(); vm.assume(_delegatee != address(0) && _claimer != address(0)); vm.startPrank(_depositor); govToken.approve(address(govStaker), _amount); vm.expectEmit(); - emit Staker.ClaimerAltered( - Staker.DepositIdentifier.wrap(Staker.DepositIdentifier.unwrap(depositId) + 1), + emit StakerUpgradeable.ClaimerAltered( + StakerUpgradeable.DepositIdentifier.wrap( + StakerUpgradeable.DepositIdentifier.unwrap(depositId) + 1 + ), address(0), _claimer, _amount @@ -330,15 +382,17 @@ contract Stake is StakerTest { ) public { _amount = bound(_amount, 1, type(uint96).max); _mintGovToken(_depositor, _amount); - Staker.DepositIdentifier depositId = govStaker.exposed_useDepositId(); + StakerUpgradeable.DepositIdentifier depositId = govStaker.exposed_useDepositId(); vm.assume(_delegatee != address(0) && _claimer != address(0)); vm.startPrank(_depositor); govToken.approve(address(govStaker), _amount); vm.expectEmit(); - emit Staker.DelegateeAltered( - Staker.DepositIdentifier.wrap(Staker.DepositIdentifier.unwrap(depositId) + 1), + emit StakerUpgradeable.DelegateeAltered( + StakerUpgradeable.DepositIdentifier.wrap( + StakerUpgradeable.DepositIdentifier.unwrap(depositId) + 1 + ), address(0), _delegatee, _amount @@ -533,8 +587,8 @@ contract Stake is StakerTest { _amount = _boundMintAmount(_amount); _mintGovToken(_depositor, _amount); - Staker.DepositIdentifier _depositId = _stake(_depositor, _amount, _delegatee); - Staker.Deposit memory _deposit = _fetchDeposit(_depositId); + StakerUpgradeable.DepositIdentifier _depositId = _stake(_depositor, _amount, _delegatee); + StakerUpgradeable.Deposit memory _deposit = _fetchDeposit(_depositId); assertEq(_deposit.balance, _amount); assertEq(_deposit.owner, _depositor); assertEq(_deposit.delegatee, _delegatee); @@ -552,10 +606,10 @@ contract Stake is StakerTest { _mintGovToken(_depositor, _amount1 + _amount2); // Perform both deposits and track their identifiers separately - Staker.DepositIdentifier _depositId1 = _stake(_depositor, _amount1, _delegatee1); - Staker.DepositIdentifier _depositId2 = _stake(_depositor, _amount2, _delegatee2); - Staker.Deposit memory _deposit1 = _fetchDeposit(_depositId1); - Staker.Deposit memory _deposit2 = _fetchDeposit(_depositId2); + StakerUpgradeable.DepositIdentifier _depositId1 = _stake(_depositor, _amount1, _delegatee1); + StakerUpgradeable.DepositIdentifier _depositId2 = _stake(_depositor, _amount2, _delegatee2); + StakerUpgradeable.Deposit memory _deposit1 = _fetchDeposit(_depositId1); + StakerUpgradeable.Deposit memory _deposit2 = _fetchDeposit(_depositId2); // Check that the deposits have been recorded independently assertEq(_deposit1.balance, _amount1); @@ -580,10 +634,10 @@ contract Stake is StakerTest { _mintGovToken(_depositor2, _amount2); // Perform both deposits and track their identifiers separately - Staker.DepositIdentifier _depositId1 = _stake(_depositor1, _amount1, _delegatee1); - Staker.DepositIdentifier _depositId2 = _stake(_depositor2, _amount2, _delegatee2); - Staker.Deposit memory _deposit1 = _fetchDeposit(_depositId1); - Staker.Deposit memory _deposit2 = _fetchDeposit(_depositId2); + StakerUpgradeable.DepositIdentifier _depositId1 = _stake(_depositor1, _amount1, _delegatee1); + StakerUpgradeable.DepositIdentifier _depositId2 = _stake(_depositor2, _amount2, _delegatee2); + StakerUpgradeable.Deposit memory _deposit1 = _fetchDeposit(_depositId1); + StakerUpgradeable.Deposit memory _deposit2 = _fetchDeposit(_depositId2); // Check that the deposits have been recorded independently assertEq(_deposit1.balance, _amount1); @@ -594,14 +648,14 @@ contract Stake is StakerTest { assertEq(_deposit2.delegatee, _delegatee2); } - mapping(Staker.DepositIdentifier depositId => bool isUsed) isIdUsed; + mapping(StakerUpgradeable.DepositIdentifier depositId => bool isUsed) isIdUsed; function test_NeverReusesADepositIdentifier() public { address _depositor = address(0xdeadbeef); uint256 _amount = 116; address _delegatee = address(0xaceface); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; vm.pauseGasMetering(); @@ -643,7 +697,7 @@ contract Stake is StakerTest { govToken.approve(address(govStaker), _amount); vm.prank(_depositor); - vm.expectRevert(Staker.Staker__InvalidAddress.selector); + vm.expectRevert(StakerUpgradeable.Staker__InvalidAddress.selector); govStaker.stake(_amount, address(0)); } @@ -659,7 +713,7 @@ contract Stake is StakerTest { govToken.approve(address(govStaker), _amount); vm.prank(_depositor); - vm.expectRevert(Staker.Staker__InvalidAddress.selector); + vm.expectRevert(StakerUpgradeable.Staker__InvalidAddress.selector); govStaker.stake(_amount, _delegatee, address(0)); } @@ -673,10 +727,10 @@ contract Stake is StakerTest { earningPowerCalculator.__setMultiplierBips(_multiplierBips); - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _depositor); - (,, uint96 _actualEarningPower,,,,) = govStaker.deposits(_depositId); + uint96 _actualEarningPower = govStaker.deposits(_depositId).earningPower; uint256 _expectedEarningPower = (_stakeAmount * _multiplierBips) / 10_000; assertEq(_actualEarningPower, _expectedEarningPower); } @@ -691,10 +745,10 @@ contract Stake is StakerTest { earningPowerCalculator.__setFixedReturn(_fixedEarningPower); - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _depositor); - (,, uint96 _actualEarningPower,,,,) = govStaker.deposits(_depositId); + uint96 _actualEarningPower = govStaker.deposits(_depositId).earningPower; assertEq(_actualEarningPower, _fixedEarningPower); } } @@ -737,9 +791,9 @@ contract PermitAndStake is StakerTest { (uint8 _v, bytes32 _r, bytes32 _s) = vm.sign(_depositorPrivateKey, _messageHash); vm.prank(_depositor); - Staker.DepositIdentifier _depositId = + StakerUpgradeable.DepositIdentifier _depositId = govStaker.permitAndStake(_depositAmount, _delegatee, _claimer, _deadline, _v, _r, _s); - Staker.Deposit memory _deposit = _fetchDeposit(_depositId); + StakerUpgradeable.Deposit memory _deposit = _fetchDeposit(_depositId); assertEq(_deposit.balance, _depositAmount); assertEq(_deposit.owner, _depositor); @@ -786,9 +840,9 @@ contract PermitAndStake is StakerTest { govToken.permit(_depositor, address(govStaker), _depositAmount, _deadline, _v, _r, _s); vm.prank(_depositor); - Staker.DepositIdentifier _depositId = + StakerUpgradeable.DepositIdentifier _depositId = govStaker.permitAndStake(_depositAmount, _delegatee, _claimer, _deadline, _v, _r, _s); - Staker.Deposit memory _deposit = _fetchDeposit(_depositId); + StakerUpgradeable.Deposit memory _deposit = _fetchDeposit(_depositId); } function testFuzz_SuccessfullyStakeWhenApprovalExistsAndPermitSignatureIsInvalid( @@ -916,11 +970,11 @@ contract PermitAndStake is StakerTest { (uint8 _v, bytes32 _r, bytes32 _s) = vm.sign(_depositorPrivateKey, _messageHash); vm.prank(_depositor); - Staker.DepositIdentifier _depositId = + StakerUpgradeable.DepositIdentifier _depositId = govStaker.permitAndStake(_depositAmount, _delegatee, _claimer, _deadline, _v, _r, _s); uint256 _expectedEarningPower = (_depositAmount * _multiplierBips) / 10_000; - Staker.Deposit memory _deposit = _fetchDeposit(_depositId); + StakerUpgradeable.Deposit memory _deposit = _fetchDeposit(_depositId); assertEq(_deposit.earningPower, _expectedEarningPower); assertEq(govStaker.totalEarningPower(), _expectedEarningPower); @@ -966,10 +1020,10 @@ contract PermitAndStake is StakerTest { (uint8 _v, bytes32 _r, bytes32 _s) = vm.sign(_depositorPrivateKey, _messageHash); vm.prank(_depositor); - Staker.DepositIdentifier _depositId = + StakerUpgradeable.DepositIdentifier _depositId = govStaker.permitAndStake(_depositAmount, _delegatee, _claimer, _deadline, _v, _r, _s); - Staker.Deposit memory _deposit = _fetchDeposit(_depositId); + StakerUpgradeable.Deposit memory _deposit = _fetchDeposit(_depositId); assertEq(_deposit.earningPower, _fixedEarningPower); assertEq(govStaker.totalEarningPower(), _fixedEarningPower); @@ -985,10 +1039,10 @@ contract StakeMore is StakerTest { address _delegatee, address _claimer ) public { - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee, _claimer); - Staker.Deposit memory _deposit = _fetchDeposit(_depositId); + StakerUpgradeable.Deposit memory _deposit = _fetchDeposit(_depositId); DelegationSurrogate _surrogate = govStaker.surrogates(_deposit.delegatee); _addAmount = _boundToRealisticStake(_addAmount); @@ -1009,7 +1063,7 @@ contract StakeMore is StakerTest { address _delegatee, address _claimer ) public { - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee, _claimer); @@ -1031,7 +1085,7 @@ contract StakeMore is StakerTest { address _delegatee, address _claimer ) public { - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee, _claimer); @@ -1053,7 +1107,7 @@ contract StakeMore is StakerTest { address _delegatee, address _claimer ) public { - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee, _claimer); @@ -1075,7 +1129,7 @@ contract StakeMore is StakerTest { address _delegatee, address _claimer ) public { - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee, _claimer); @@ -1087,7 +1141,7 @@ contract StakeMore is StakerTest { govStaker.stakeMore(_depositId, _addAmount); vm.stopPrank(); - Staker.Deposit memory _deposit = _fetchDeposit(_depositId); + StakerUpgradeable.Deposit memory _deposit = _fetchDeposit(_depositId); assertEq(_deposit.balance, _depositAmount + _addAmount); } @@ -1100,7 +1154,7 @@ contract StakeMore is StakerTest { address _claimer ) public { uint256 _totalAdditionalStake; - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee, _claimer); // Second stake @@ -1118,7 +1172,7 @@ contract StakeMore is StakerTest { uint256 _total = _depositAmount + _totalAdditionalStake; vm.expectEmit(); - emit Staker.StakeDeposited(_depositor, _depositId, _addAmount, _total, _total); + emit StakerUpgradeable.StakeDeposited(_depositor, _depositId, _addAmount, _total, _total); govStaker.stakeMore(_depositId, _addAmount); vm.stopPrank(); @@ -1134,7 +1188,7 @@ contract StakeMore is StakerTest { ) public { vm.assume(_notDepositor != _depositor); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee, _claimer); @@ -1147,7 +1201,7 @@ contract StakeMore is StakerTest { vm.prank(_notDepositor); vm.expectRevert( abi.encodeWithSelector( - Staker.Staker__Unauthorized.selector, bytes32("not owner"), _notDepositor + StakerUpgradeable.Staker__Unauthorized.selector, bytes32("not owner"), _notDepositor ) ); govStaker.stakeMore(_depositId, _addAmount); @@ -1155,7 +1209,7 @@ contract StakeMore is StakerTest { function testFuzz_RevertIf_TheDepositIdentifierIsInvalid( address _depositor, - Staker.DepositIdentifier _depositId, + StakerUpgradeable.DepositIdentifier _depositId, uint256 _addAmount ) public { vm.assume(_depositor != address(0)); @@ -1166,7 +1220,9 @@ contract StakeMore is StakerTest { // being address zero, which means the address attempting to alter it won't be able to. vm.prank(_depositor); vm.expectRevert( - abi.encodeWithSelector(Staker.Staker__Unauthorized.selector, bytes32("not owner"), _depositor) + abi.encodeWithSelector( + StakerUpgradeable.Staker__Unauthorized.selector, bytes32("not owner"), _depositor + ) ); govStaker.stakeMore(_depositId, _addAmount); } @@ -1181,7 +1237,7 @@ contract StakeMore is StakerTest { _multiplierBips = bound(_multiplierBips, 0, 20_000); earningPowerCalculator.__setMultiplierBips(_multiplierBips); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee); _addAmount = _boundToRealisticStake(_addAmount); @@ -1191,7 +1247,7 @@ contract StakeMore is StakerTest { govStaker.stakeMore(_depositId, _addAmount); vm.stopPrank(); - (,, uint96 _actualEarningPower,,,,) = govStaker.deposits(_depositId); + uint96 _actualEarningPower = govStaker.deposits(_depositId).earningPower; uint256 _expectedEarningPower = ((_depositAmount + _addAmount) * _multiplierBips) / 10_000; assertEq(_actualEarningPower, _expectedEarningPower); } @@ -1206,7 +1262,7 @@ contract StakeMore is StakerTest { _fixedEarningPower = _boundToRealisticStake(_fixedEarningPower); earningPowerCalculator.__setFixedReturn(_fixedEarningPower); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee); _addAmount = _boundToRealisticStake(_addAmount); @@ -1216,7 +1272,7 @@ contract StakeMore is StakerTest { govStaker.stakeMore(_depositId, _addAmount); vm.stopPrank(); - (,, uint96 _actualEarningPower,,,,) = govStaker.deposits(_depositId); + uint96 _actualEarningPower = govStaker.deposits(_depositId).earningPower; assertEq(_actualEarningPower, _fixedEarningPower); } @@ -1230,7 +1286,7 @@ contract StakeMore is StakerTest { _multiplierBips = bound(_multiplierBips, 0, 20_000); earningPowerCalculator.__setMultiplierBips(_multiplierBips); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee); _addAmount = _boundToRealisticStake(_addAmount); @@ -1262,7 +1318,7 @@ contract PermitAndStakeMore is StakerTest { address _depositor = vm.addr(_depositorPrivateKey); _deadline = bound(_deadline, block.timestamp, type(uint256).max); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_initialDepositAmount, _depositId) = _boundMintAndStake(_depositor, _initialDepositAmount, _delegatee, _claimer); @@ -1294,7 +1350,7 @@ contract PermitAndStakeMore is StakerTest { govStaker.permitAndStakeMore(_depositId, _stakeMoreAmount, _deadline, _v, _r, _s); } - Staker.Deposit memory _deposit = _fetchDeposit(_depositId); + StakerUpgradeable.Deposit memory _deposit = _fetchDeposit(_depositId); assertEq(_deposit.balance, _initialDepositAmount + _stakeMoreAmount); assertEq(_deposit.owner, _depositor); @@ -1317,7 +1373,7 @@ contract PermitAndStakeMore is StakerTest { address _depositor = vm.addr(_depositorPrivateKey); _deadline = bound(_deadline, block.timestamp, type(uint256).max); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_initialDepositAmount, _depositId) = _boundMintAndStake(_depositor, _initialDepositAmount, _delegatee, _claimer); @@ -1362,7 +1418,7 @@ contract PermitAndStakeMore is StakerTest { ) public { vm.assume(_delegatee != address(0) && _claimer != address(0)); (address _depositor, uint256 _depositorPrivateKey) = makeAddrAndKey("depositor"); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_initialDepositAmount, _depositId) = _boundMintAndStake(_depositor, _initialDepositAmount, _delegatee, _claimer); _stakeMoreAmount = bound(_stakeMoreAmount, 0, type(uint96).max - _initialDepositAmount); @@ -1410,7 +1466,7 @@ contract PermitAndStakeMore is StakerTest { vm.assume(_depositor != _notDepositor); _deadline = bound(_deadline, block.timestamp, type(uint256).max); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_initialDepositAmount, _depositId) = _boundMintAndStake(_depositor, _initialDepositAmount, _delegatee, _claimer); @@ -1437,7 +1493,7 @@ contract PermitAndStakeMore is StakerTest { vm.prank(_notDepositor); vm.expectRevert( abi.encodeWithSelector( - Staker.Staker__Unauthorized.selector, bytes32("not owner"), _notDepositor + StakerUpgradeable.Staker__Unauthorized.selector, bytes32("not owner"), _notDepositor ) ); govStaker.permitAndStakeMore(_depositId, _stakeMoreAmount, _deadline, _v, _r, _s); @@ -1459,7 +1515,7 @@ contract PermitAndStakeMore is StakerTest { uint256 _wrongNonce = 1; uint256 _approvalAmount = _stakeMoreAmount - 1; - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_initialDepositAmount, _depositId) = _boundMintAndStake(_depositor, _initialDepositAmount, _delegatee, _claimer); _mintGovToken(_depositor, _stakeMoreAmount); @@ -1506,7 +1562,7 @@ contract PermitAndStakeMore is StakerTest { _depositorPrivateKey = bound(_depositorPrivateKey, 1, 100e18); address _depositor = vm.addr(_depositorPrivateKey); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee, _claimer); @@ -1518,7 +1574,7 @@ contract PermitAndStakeMore is StakerTest { uint256 _totalStaked = _depositAmount + _addAmount; uint256 _expectedEarningPower = (_totalStaked * _multiplierBips) / 10_000; - Staker.Deposit memory _deposit = _fetchDeposit(_depositId); + StakerUpgradeable.Deposit memory _deposit = _fetchDeposit(_depositId); assertEq(_deposit.earningPower, _expectedEarningPower); assertEq(govStaker.totalEarningPower(), _expectedEarningPower); @@ -1537,7 +1593,7 @@ contract PermitAndStakeMore is StakerTest { _depositorPrivateKey = bound(_depositorPrivateKey, 1, 100e18); address _depositor = vm.addr(_depositorPrivateKey); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee, _claimer); @@ -1547,7 +1603,7 @@ contract PermitAndStakeMore is StakerTest { _executePermitAndStakeMore(_depositor, _depositorPrivateKey, _depositId, _addAmount); - Staker.Deposit memory _deposit = _fetchDeposit(_depositId); + StakerUpgradeable.Deposit memory _deposit = _fetchDeposit(_depositId); assertEq(_deposit.earningPower, _fixedEarningPower); assertEq(govStaker.totalEarningPower(), _fixedEarningPower); @@ -1558,7 +1614,7 @@ contract PermitAndStakeMore is StakerTest { function _executePermitAndStakeMore( address _depositor, uint256 _depositorPrivateKey, - Staker.DepositIdentifier _depositId, + StakerUpgradeable.DepositIdentifier _depositId, uint256 _addAmount ) internal { _mintGovToken(_depositor, _addAmount); @@ -1594,7 +1650,7 @@ contract AlterDelegatee is StakerTest { ) public { vm.assume(_newDelegatee != address(0) && _newDelegatee != _firstDelegatee); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _firstDelegatee, _claimer); address _firstSurrogate = address(govStaker.surrogates(_firstDelegatee)); @@ -1602,7 +1658,7 @@ contract AlterDelegatee is StakerTest { vm.prank(_depositor); govStaker.alterDelegatee(_depositId, _newDelegatee); - Staker.Deposit memory _deposit = _fetchDeposit(_depositId); + StakerUpgradeable.Deposit memory _deposit = _fetchDeposit(_depositId); address _newSurrogate = address(govStaker.surrogates(_deposit.delegatee)); assertEq(_deposit.delegatee, _newDelegatee); @@ -1616,7 +1672,7 @@ contract AlterDelegatee is StakerTest { address _delegatee, address _claimer ) public { - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee, _claimer); address _beforeSurrogate = address(govStaker.surrogates(_delegatee)); @@ -1626,7 +1682,7 @@ contract AlterDelegatee is StakerTest { vm.prank(_depositor); govStaker.alterDelegatee(_depositId, _delegatee); - Staker.Deposit memory _deposit = _fetchDeposit(_depositId); + StakerUpgradeable.Deposit memory _deposit = _fetchDeposit(_depositId); address _afterSurrogate = address(govStaker.surrogates(_deposit.delegatee)); assertEq(_deposit.delegatee, _delegatee); @@ -1643,12 +1699,14 @@ contract AlterDelegatee is StakerTest { ) public { vm.assume(_newDelegatee != address(0) && _newDelegatee != _firstDelegatee); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _firstDelegatee, _claimer); vm.expectEmit(); - emit Staker.DelegateeAltered(_depositId, _firstDelegatee, _newDelegatee, _depositAmount); + emit StakerUpgradeable.DelegateeAltered( + _depositId, _firstDelegatee, _newDelegatee, _depositAmount + ); vm.prank(_depositor); govStaker.alterDelegatee(_depositId, _newDelegatee); @@ -1664,7 +1722,7 @@ contract AlterDelegatee is StakerTest { ) public { vm.assume(_newDelegatee != address(0) && _newDelegatee != _firstDelegatee); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _firstDelegatee, _claimer); @@ -1675,7 +1733,7 @@ contract AlterDelegatee is StakerTest { vm.prank(_depositor); govStaker.alterDelegatee(_depositId, _newDelegatee); - Staker.Deposit memory _deposit = _fetchDeposit(_depositId); + StakerUpgradeable.Deposit memory _deposit = _fetchDeposit(_depositId); assertEq(_deposit.earningPower, _newEarningPower); } @@ -1690,7 +1748,7 @@ contract AlterDelegatee is StakerTest { ) public { vm.assume(_newDelegatee != address(0) && _newDelegatee != _firstDelegatee); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _firstDelegatee, _claimer); @@ -1714,7 +1772,7 @@ contract AlterDelegatee is StakerTest { ) public { vm.assume(_newDelegatee != address(0) && _newDelegatee != _firstDelegatee); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _firstDelegatee, _claimer); @@ -1740,14 +1798,14 @@ contract AlterDelegatee is StakerTest { _depositor != _notDepositor && _newDelegatee != address(0) && _newDelegatee != _firstDelegatee ); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _firstDelegatee, _claimer); vm.prank(_notDepositor); vm.expectRevert( abi.encodeWithSelector( - Staker.Staker__Unauthorized.selector, bytes32("not owner"), _notDepositor + StakerUpgradeable.Staker__Unauthorized.selector, bytes32("not owner"), _notDepositor ) ); govStaker.alterDelegatee(_depositId, _newDelegatee); @@ -1755,7 +1813,7 @@ contract AlterDelegatee is StakerTest { function testFuzz_RevertIf_TheDepositIdentifierIsInvalid( address _depositor, - Staker.DepositIdentifier _depositId, + StakerUpgradeable.DepositIdentifier _depositId, address _newDelegatee ) public { vm.assume(_depositor != address(0) && _newDelegatee != address(0)); @@ -1765,7 +1823,9 @@ contract AlterDelegatee is StakerTest { // address zero, which means the address attempting to alter it won't be able to. vm.prank(_depositor); vm.expectRevert( - abi.encodeWithSelector(Staker.Staker__Unauthorized.selector, bytes32("not owner"), _depositor) + abi.encodeWithSelector( + StakerUpgradeable.Staker__Unauthorized.selector, bytes32("not owner"), _depositor + ) ); govStaker.alterDelegatee(_depositId, _newDelegatee); } @@ -1775,11 +1835,11 @@ contract AlterDelegatee is StakerTest { uint256 _depositAmount, address _delegatee ) public { - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee); vm.prank(_depositor); - vm.expectRevert(Staker.Staker__InvalidAddress.selector); + vm.expectRevert(StakerUpgradeable.Staker__InvalidAddress.selector); govStaker.alterDelegatee(_depositId, address(0)); } @@ -1796,7 +1856,7 @@ contract AlterDelegatee is StakerTest { _multiplierBips = bound(_multiplierBips, 0, 20_000); earningPowerCalculator.__setMultiplierBips(_multiplierBips); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _firstDelegatee, _claimer); @@ -1805,7 +1865,7 @@ contract AlterDelegatee is StakerTest { uint256 _expectedEarningPower = (_depositAmount * _multiplierBips) / 10_000; - Staker.Deposit memory _deposit = _fetchDeposit(_depositId); + StakerUpgradeable.Deposit memory _deposit = _fetchDeposit(_depositId); assertEq(_deposit.earningPower, _expectedEarningPower); assertEq(govStaker.totalEarningPower(), _expectedEarningPower); assertEq(govStaker.depositorTotalEarningPower(_depositor), _expectedEarningPower); @@ -1824,14 +1884,14 @@ contract AlterDelegatee is StakerTest { _fixedEarningPower = _boundToRealisticStake(_fixedEarningPower); earningPowerCalculator.__setFixedReturn(_fixedEarningPower); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _firstDelegatee, _claimer); vm.prank(_depositor); govStaker.alterDelegatee(_depositId, _newDelegatee); - Staker.Deposit memory _deposit = _fetchDeposit(_depositId); + StakerUpgradeable.Deposit memory _deposit = _fetchDeposit(_depositId); assertEq(_deposit.earningPower, _fixedEarningPower); assertEq(govStaker.totalEarningPower(), _fixedEarningPower); assertEq(govStaker.depositorTotalEarningPower(_depositor), _fixedEarningPower); @@ -1848,14 +1908,14 @@ contract AlterClaimer is StakerTest { ) public { vm.assume(_newClaimer != address(0) && _newClaimer != _firstClaimer); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee, _firstClaimer); vm.prank(_depositor); govStaker.alterClaimer(_depositId, _newClaimer); - Staker.Deposit memory _deposit = _fetchDeposit(_depositId); + StakerUpgradeable.Deposit memory _deposit = _fetchDeposit(_depositId); assertEq(_deposit.claimer, _newClaimer); } @@ -1866,7 +1926,7 @@ contract AlterClaimer is StakerTest { address _delegatee, address _claimer ) public { - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee, _claimer); @@ -1875,7 +1935,7 @@ contract AlterClaimer is StakerTest { vm.prank(_depositor); govStaker.alterClaimer(_depositId, _claimer); - Staker.Deposit memory _deposit = _fetchDeposit(_depositId); + StakerUpgradeable.Deposit memory _deposit = _fetchDeposit(_depositId); assertEq(_deposit.claimer, _claimer); } @@ -1889,12 +1949,12 @@ contract AlterClaimer is StakerTest { ) public { vm.assume(_newClaimer != address(0) && _newClaimer != _firstClaimer); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee, _firstClaimer); vm.expectEmit(); - emit Staker.ClaimerAltered(_depositId, _firstClaimer, _newClaimer, _depositAmount); + emit StakerUpgradeable.ClaimerAltered(_depositId, _firstClaimer, _newClaimer, _depositAmount); vm.prank(_depositor); govStaker.alterClaimer(_depositId, _newClaimer); @@ -1910,7 +1970,7 @@ contract AlterClaimer is StakerTest { ) public { vm.assume(_newClaimer != address(0) && _newClaimer != _firstClaimer); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee, _firstClaimer); @@ -1921,7 +1981,7 @@ contract AlterClaimer is StakerTest { vm.prank(_depositor); govStaker.alterClaimer(_depositId, _newClaimer); - Staker.Deposit memory _deposit = _fetchDeposit(_depositId); + StakerUpgradeable.Deposit memory _deposit = _fetchDeposit(_depositId); assertEq(_deposit.earningPower, _newEarningPower); } @@ -1936,7 +1996,7 @@ contract AlterClaimer is StakerTest { ) public { vm.assume(_newClaimer != address(0) && _newClaimer != _firstClaimer); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee, _firstClaimer); @@ -1960,7 +2020,7 @@ contract AlterClaimer is StakerTest { ) public { vm.assume(_newClaimer != address(0) && _newClaimer != _firstClaimer); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee, _firstClaimer); @@ -1986,14 +2046,14 @@ contract AlterClaimer is StakerTest { _notDepositor != _depositor && _newClaimer != address(0) && _newClaimer != _firstClaimer ); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee, _firstClaimer); vm.prank(_notDepositor); vm.expectRevert( abi.encodeWithSelector( - Staker.Staker__Unauthorized.selector, bytes32("not owner"), _notDepositor + StakerUpgradeable.Staker__Unauthorized.selector, bytes32("not owner"), _notDepositor ) ); govStaker.alterClaimer(_depositId, _newClaimer); @@ -2001,7 +2061,7 @@ contract AlterClaimer is StakerTest { function testFuzz_RevertIf_TheDepositIdentifierIsInvalid( address _depositor, - Staker.DepositIdentifier _depositId, + StakerUpgradeable.DepositIdentifier _depositId, address _newClaimer ) public { vm.assume(_depositor != address(0) && _newClaimer != address(0)); @@ -2011,7 +2071,9 @@ contract AlterClaimer is StakerTest { // address zero, which means the address attempting to alter it won't be able to. vm.prank(_depositor); vm.expectRevert( - abi.encodeWithSelector(Staker.Staker__Unauthorized.selector, bytes32("not owner"), _depositor) + abi.encodeWithSelector( + StakerUpgradeable.Staker__Unauthorized.selector, bytes32("not owner"), _depositor + ) ); govStaker.alterClaimer(_depositId, _newClaimer); } @@ -2021,11 +2083,11 @@ contract AlterClaimer is StakerTest { uint256 _depositAmount, address _delegatee ) public { - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee); vm.prank(_depositor); - vm.expectRevert(Staker.Staker__InvalidAddress.selector); + vm.expectRevert(StakerUpgradeable.Staker__InvalidAddress.selector); govStaker.alterClaimer(_depositId, address(0)); } @@ -2042,7 +2104,7 @@ contract AlterClaimer is StakerTest { _multiplierBips = bound(_multiplierBips, 0, 20_000); earningPowerCalculator.__setMultiplierBips(_multiplierBips); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee, _firstClaimer); @@ -2051,7 +2113,7 @@ contract AlterClaimer is StakerTest { uint256 _expectedEarningPower = (_depositAmount * _multiplierBips) / 10_000; - Staker.Deposit memory _deposit = _fetchDeposit(_depositId); + StakerUpgradeable.Deposit memory _deposit = _fetchDeposit(_depositId); assertEq(_deposit.earningPower, _expectedEarningPower); assertEq(govStaker.totalEarningPower(), _expectedEarningPower); assertEq(govStaker.depositorTotalEarningPower(_depositor), _expectedEarningPower); @@ -2070,14 +2132,14 @@ contract AlterClaimer is StakerTest { _fixedEarningPower = _boundToRealisticStake(_fixedEarningPower); earningPowerCalculator.__setFixedReturn(_fixedEarningPower); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee, _firstClaimer); vm.prank(_depositor); govStaker.alterClaimer(_depositId, _newClaimer); - Staker.Deposit memory _deposit = _fetchDeposit(_depositId); + StakerUpgradeable.Deposit memory _deposit = _fetchDeposit(_depositId); assertEq(_deposit.earningPower, _fixedEarningPower); assertEq(govStaker.totalEarningPower(), _fixedEarningPower); assertEq(govStaker.depositorTotalEarningPower(_depositor), _fixedEarningPower); @@ -2091,14 +2153,14 @@ contract Withdraw is StakerTest { address _delegatee, uint256 _withdrawalAmount ) public { - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee); _withdrawalAmount = bound(_withdrawalAmount, 0, _depositAmount); vm.prank(_depositor); govStaker.withdraw(_depositId, _withdrawalAmount); - Staker.Deposit memory _deposit = _fetchDeposit(_depositId); + StakerUpgradeable.Deposit memory _deposit = _fetchDeposit(_depositId); address _surrogate = address(govStaker.surrogates(_deposit.delegatee)); assertEq(govToken.balanceOf(_depositor), _withdrawalAmount); @@ -2112,7 +2174,7 @@ contract Withdraw is StakerTest { address _delegatee, uint256 _withdrawalAmount ) public { - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee); _withdrawalAmount = bound(_withdrawalAmount, 0, _depositAmount); @@ -2133,9 +2195,9 @@ contract Withdraw is StakerTest { uint256 _withdrawalAmount2 ) public { // Make two separate deposits - Staker.DepositIdentifier _depositId1; + StakerUpgradeable.DepositIdentifier _depositId1; (_depositAmount1, _depositId1) = _boundMintAndStake(_depositor1, _depositAmount1, _delegatee1); - Staker.DepositIdentifier _depositId2; + StakerUpgradeable.DepositIdentifier _depositId2; (_depositAmount2, _depositId2) = _boundMintAndStake(_depositor2, _depositAmount2, _delegatee2); // Calculate withdrawal amounts @@ -2162,9 +2224,9 @@ contract Withdraw is StakerTest { uint256 _withdrawalAmount ) public { // Make two separate deposits - Staker.DepositIdentifier _depositId1; + StakerUpgradeable.DepositIdentifier _depositId1; (_depositAmount1, _depositId1) = _boundMintAndStake(_depositor, _depositAmount1, _delegatee1); - Staker.DepositIdentifier _depositId2; + StakerUpgradeable.DepositIdentifier _depositId2; (_depositAmount2, _depositId2) = _boundMintAndStake(_depositor, _depositAmount2, _delegatee2); // Withdraw part of the first deposit @@ -2189,9 +2251,9 @@ contract Withdraw is StakerTest { uint256 _withdrawalAmount ) public { // Make two separate deposits - Staker.DepositIdentifier _depositId1; + StakerUpgradeable.DepositIdentifier _depositId1; (_depositAmount1, _depositId1) = _boundMintAndStake(_depositor, _depositAmount1, _delegatee1); - Staker.DepositIdentifier _depositId2; + StakerUpgradeable.DepositIdentifier _depositId2; (_depositAmount2, _depositId2) = _boundMintAndStake(_depositor, _depositAmount2, _delegatee2); // Withdraw part of the first deposit @@ -2213,14 +2275,16 @@ contract Withdraw is StakerTest { address _delegatee, uint256 _withdrawalAmount ) public { - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee); _withdrawalAmount = bound(_withdrawalAmount, 0, _depositAmount); uint256 _newAmount = _depositAmount - _withdrawalAmount; vm.expectEmit(); - emit Staker.StakeWithdrawn(_depositor, _depositId, _withdrawalAmount, _newAmount, _newAmount); + emit StakerUpgradeable.StakeWithdrawn( + _depositor, _depositId, _withdrawalAmount, _newAmount, _newAmount + ); vm.prank(_depositor); govStaker.withdraw(_depositId, _withdrawalAmount); @@ -2232,14 +2296,14 @@ contract Withdraw is StakerTest { address _delegatee, address _notDepositor ) public { - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_amount, _depositId) = _boundMintAndStake(_depositor, _amount, _delegatee); vm.assume(_depositor != _notDepositor); vm.prank(_notDepositor); vm.expectRevert( abi.encodeWithSelector( - Staker.Staker__Unauthorized.selector, bytes32("not owner"), _notDepositor + StakerUpgradeable.Staker__Unauthorized.selector, bytes32("not owner"), _notDepositor ) ); govStaker.withdraw(_depositId, _amount); @@ -2251,7 +2315,7 @@ contract Withdraw is StakerTest { uint256 _amountOver, address _delegatee ) public { - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_amount, _depositId) = _boundMintAndStake(_depositor, _amount, _delegatee); _amountOver = bound(_amountOver, 1, type(uint128).max); @@ -2270,14 +2334,14 @@ contract Withdraw is StakerTest { _multiplierBips = bound(_multiplierBips, 0, 20_000); earningPowerCalculator.__setMultiplierBips(_multiplierBips); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee); _withdrawalAmount = bound(_withdrawalAmount, 0, _depositAmount); vm.prank(_depositor); govStaker.withdraw(_depositId, _withdrawalAmount); - Staker.Deposit memory _deposit = _fetchDeposit(_depositId); + StakerUpgradeable.Deposit memory _deposit = _fetchDeposit(_depositId); uint256 _remainingStake = _depositAmount - _withdrawalAmount; uint256 _expectedEarningPower = (_remainingStake * _multiplierBips) / 10_000; assertEq(_deposit.earningPower, _expectedEarningPower); @@ -2293,14 +2357,14 @@ contract Withdraw is StakerTest { _fixedEarningPower = _boundToRealisticStake(_fixedEarningPower); earningPowerCalculator.__setFixedReturn(_fixedEarningPower); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee); _withdrawalAmount = bound(_withdrawalAmount, 0, _depositAmount); vm.prank(_depositor); govStaker.withdraw(_depositId, _withdrawalAmount); - Staker.Deposit memory _deposit = _fetchDeposit(_depositId); + StakerUpgradeable.Deposit memory _deposit = _fetchDeposit(_depositId); assertEq(_deposit.earningPower, _fixedEarningPower); } } @@ -2324,7 +2388,7 @@ contract SetRewardNotifier is StakerTest { public { vm.expectEmit(); - emit Staker.RewardNotifierSet(_rewardNotifier, _isEnabled); + emit StakerUpgradeable.RewardNotifierSet(_rewardNotifier, _isEnabled); vm.prank(admin); govStaker.setRewardNotifier(_rewardNotifier, _isEnabled); } @@ -2338,7 +2402,9 @@ contract SetRewardNotifier is StakerTest { vm.prank(_notAdmin); vm.expectRevert( - abi.encodeWithSelector(Staker.Staker__Unauthorized.selector, bytes32("not admin"), _notAdmin) + abi.encodeWithSelector( + StakerUpgradeable.Staker__Unauthorized.selector, bytes32("not admin"), _notAdmin + ) ); govStaker.setRewardNotifier(_newRewardNotifier, _isEnabled); } @@ -2358,7 +2424,7 @@ contract SetAdmin is StakerTest { vm.assume(_newAdmin != address(0)); vm.expectEmit(); - emit Staker.AdminSet(admin, _newAdmin); + emit StakerUpgradeable.AdminSet(admin, _newAdmin); vm.prank(admin); govStaker.setAdmin(_newAdmin); @@ -2369,14 +2435,16 @@ contract SetAdmin is StakerTest { vm.prank(_notAdmin); vm.expectRevert( - abi.encodeWithSelector(Staker.Staker__Unauthorized.selector, bytes32("not admin"), _notAdmin) + abi.encodeWithSelector( + StakerUpgradeable.Staker__Unauthorized.selector, bytes32("not admin"), _notAdmin + ) ); govStaker.setAdmin(_newAdmin); } function test_RevertIf_NewAdminAddressIsZeroAddress() public { vm.prank(admin); - vm.expectRevert(Staker.Staker__InvalidAddress.selector); + vm.expectRevert(StakerUpgradeable.Staker__InvalidAddress.selector); govStaker.setAdmin(address(0)); } } @@ -2399,7 +2467,7 @@ contract SetEarningPowerCalculator is StakerTest { vm.assume(_newEarningPowerCalculator != address(0)); vm.expectEmit(); - emit Staker.EarningPowerCalculatorSet( + emit StakerUpgradeable.EarningPowerCalculatorSet( address(govStaker.earningPowerCalculator()), _newEarningPowerCalculator ); @@ -2415,14 +2483,16 @@ contract SetEarningPowerCalculator is StakerTest { vm.prank(_notAdmin); vm.expectRevert( - abi.encodeWithSelector(Staker.Staker__Unauthorized.selector, bytes32("not admin"), _notAdmin) + abi.encodeWithSelector( + StakerUpgradeable.Staker__Unauthorized.selector, bytes32("not admin"), _notAdmin + ) ); govStaker.setEarningPowerCalculator(_newEarningPowerCalculator); } function test_RevertIf_NewEarningPowerCalculatorAddressIsZeroAddress() public { vm.prank(admin); - vm.expectRevert(Staker.Staker__InvalidAddress.selector); + vm.expectRevert(StakerUpgradeable.Staker__InvalidAddress.selector); govStaker.setEarningPowerCalculator(address(0)); } } @@ -2437,7 +2507,7 @@ contract SetMaxBumpTip is StakerTest { function testFuzz_EmitsEventWhenMaxBumpTipIsSet(uint256 _newMaxBumpTip) public { vm.expectEmit(); - emit Staker.MaxBumpTipSet(govStaker.maxBumpTip(), _newMaxBumpTip); + emit StakerUpgradeable.MaxBumpTipSet(govStaker.maxBumpTip(), _newMaxBumpTip); vm.prank(admin); govStaker.setMaxBumpTip(_newMaxBumpTip); @@ -2448,7 +2518,9 @@ contract SetMaxBumpTip is StakerTest { vm.prank(_caller); vm.expectRevert( - abi.encodeWithSelector(Staker.Staker__Unauthorized.selector, bytes32("not admin"), _caller) + abi.encodeWithSelector( + StakerUpgradeable.Staker__Unauthorized.selector, bytes32("not admin"), _caller + ) ); govStaker.setMaxBumpTip(_newMaxBumpTip); } @@ -2456,7 +2528,7 @@ contract SetMaxBumpTip is StakerTest { contract SetClaimFeeParameters is StakerTest { function testFuzz_AllowsAdminToUpdateTheClaimFeeAmountAndFeeCollector( - Staker.ClaimFeeParameters memory _newParams + StakerUpgradeable.ClaimFeeParameters memory _newParams ) public { vm.assume(_newParams.feeCollector != address(0)); _newParams.feeAmount = uint96(bound(_newParams.feeAmount, 0, govStaker.MAX_CLAIM_FEE())); @@ -2464,13 +2536,15 @@ contract SetClaimFeeParameters is StakerTest { vm.prank(admin); govStaker.setClaimFeeParameters(_newParams); - (uint96 _feeAmount, address _feeCollector) = govStaker.claimFeeParameters(); + StakerUpgradeable.ClaimFeeParameters memory _feeParams = govStaker.claimFeeParameters(); + uint96 _feeAmount = _feeParams.feeAmount; + address _feeCollector = _feeParams.feeCollector; assertEq(_feeAmount, _newParams.feeAmount); assertEq(_feeCollector, _newParams.feeCollector); } function testFuzz_AllowsAdminToSetFeeAmountAndFeeCollectorToZero( - Staker.ClaimFeeParameters memory _initialParams + StakerUpgradeable.ClaimFeeParameters memory _initialParams ) public { vm.assume(_initialParams.feeCollector != address(0)); _initialParams.feeAmount = uint96(bound(_initialParams.feeAmount, 0, govStaker.MAX_CLAIM_FEE())); @@ -2479,21 +2553,23 @@ contract SetClaimFeeParameters is StakerTest { vm.prank(admin); govStaker.setClaimFeeParameters(_initialParams); - Staker.ClaimFeeParameters memory _zeroParams = - Staker.ClaimFeeParameters({feeAmount: 0, feeCollector: address(0)}); + StakerUpgradeable.ClaimFeeParameters memory _zeroParams = + StakerUpgradeable.ClaimFeeParameters({feeAmount: 0, feeCollector: address(0)}); // Update the parameters to both be zero. vm.prank(admin); govStaker.setClaimFeeParameters(_zeroParams); - (uint96 _feeAmount, address _feeCollector) = govStaker.claimFeeParameters(); + StakerUpgradeable.ClaimFeeParameters memory _feeParams = govStaker.claimFeeParameters(); + uint96 _feeAmount = _feeParams.feeAmount; + address _feeCollector = _feeParams.feeCollector; assertEq(_feeAmount, 0); assertEq(_feeCollector, address(0)); } function testFuzz_EmitsAClaimFeeParametersSetEvent( - Staker.ClaimFeeParameters memory _initialParams, - Staker.ClaimFeeParameters memory _newParams + StakerUpgradeable.ClaimFeeParameters memory _initialParams, + StakerUpgradeable.ClaimFeeParameters memory _newParams ) public { vm.assume(_initialParams.feeCollector != address(0) && _newParams.feeCollector != address(0)); _newParams.feeAmount = uint96(bound(_newParams.feeAmount, 0, govStaker.MAX_CLAIM_FEE())); @@ -2506,7 +2582,7 @@ contract SetClaimFeeParameters is StakerTest { // Update params, expecting appropriate event. vm.prank(admin); vm.expectEmit(); - emit Staker.ClaimFeeParametersSet( + emit StakerUpgradeable.ClaimFeeParametersSet( _initialParams.feeAmount, _newParams.feeAmount, _initialParams.feeCollector, @@ -2516,31 +2592,31 @@ contract SetClaimFeeParameters is StakerTest { } function testFuzz_RevertIf_FeeAmountIsMoreThanTheMaxClaimFee( - Staker.ClaimFeeParameters memory _newParams + StakerUpgradeable.ClaimFeeParameters memory _newParams ) public { vm.assume(_newParams.feeCollector != address(0)); _newParams.feeAmount = uint96(bound(_newParams.feeAmount, govStaker.MAX_CLAIM_FEE() + 1, type(uint96).max)); vm.prank(admin); - vm.expectRevert(Staker.Staker__InvalidClaimFeeParameters.selector); + vm.expectRevert(StakerUpgradeable.Staker__InvalidClaimFeeParameters.selector); govStaker.setClaimFeeParameters(_newParams); } function testFuzz_RevertIf_TheFeeCollectorIsAddressZeroWhileFeeAmountIsNotZero( - Staker.ClaimFeeParameters memory _newParams + StakerUpgradeable.ClaimFeeParameters memory _newParams ) public { _newParams.feeAmount = uint96(bound(_newParams.feeAmount, 1, govStaker.MAX_CLAIM_FEE())); _newParams.feeCollector = address(0); vm.prank(admin); - vm.expectRevert(Staker.Staker__InvalidClaimFeeParameters.selector); + vm.expectRevert(StakerUpgradeable.Staker__InvalidClaimFeeParameters.selector); govStaker.setClaimFeeParameters(_newParams); } function testFuzz_RevertIf_TheCallerIsNotTheAdmin( address _notAdmin, - Staker.ClaimFeeParameters memory _newParams + StakerUpgradeable.ClaimFeeParameters memory _newParams ) public { vm.assume(_newParams.feeCollector != address(0)); vm.assume(_notAdmin != admin); @@ -2548,7 +2624,9 @@ contract SetClaimFeeParameters is StakerTest { vm.prank(_notAdmin); vm.expectRevert( - abi.encodeWithSelector(Staker.Staker__Unauthorized.selector, bytes32("not admin"), _notAdmin) + abi.encodeWithSelector( + StakerUpgradeable.Staker__Unauthorized.selector, bytes32("not admin"), _notAdmin + ) ); govStaker.setClaimFeeParameters(_newParams); } @@ -2580,8 +2658,8 @@ contract StakerRewardsTest is StakerTest { console2.log("-----------------------------------------------"); } - function __dumpDebugDeposit(Staker.DepositIdentifier _depositId) public view { - Staker.Deposit memory _deposit = _fetchDeposit(_depositId); + function __dumpDebugDeposit(StakerUpgradeable.DepositIdentifier _depositId) public view { + StakerUpgradeable.Deposit memory _deposit = _fetchDeposit(_depositId); console2.log("deposit balance"); console2.log(_deposit.balance); console2.log("deposit owner"); @@ -2770,7 +2848,7 @@ contract NotifyRewardAmount is StakerRewardsTest { // fox alters delegatee vm.prank(_fox); - govStaker.alterDelegatee(Staker.DepositIdentifier.wrap(1), address(0x2)); + govStaker.alterDelegatee(StakerUpgradeable.DepositIdentifier.wrap(1), address(0x2)); // fox checkpoints global rewards _mintGovToken(_fox, 0); @@ -2778,14 +2856,14 @@ contract NotifyRewardAmount is StakerRewardsTest { // fox alters back to valid delegatee vm.prank(_fox); - govStaker.alterDelegatee(Staker.DepositIdentifier.wrap(1), address(0x2)); + govStaker.alterDelegatee(StakerUpgradeable.DepositIdentifier.wrap(1), address(0x2)); // fox claims double the rewards vm.prank(_fox); - govStaker.claimReward(Staker.DepositIdentifier.wrap(1)); + govStaker.claimReward(StakerUpgradeable.DepositIdentifier.wrap(1)); vm.prank(_doe); - govStaker.claimReward(Staker.DepositIdentifier.wrap(0)); + govStaker.claimReward(StakerUpgradeable.DepositIdentifier.wrap(0)); assertEq(rewardToken.balanceOf(_doe), rewardToken.balanceOf(_fox)); } @@ -2797,7 +2875,7 @@ contract NotifyRewardAmount is StakerRewardsTest { rewardToken.transfer(address(govStaker), _amount); vm.expectEmit(); - emit Staker.RewardNotified(_amount, rewardNotifier); + emit StakerUpgradeable.RewardNotified(_amount, rewardNotifier); govStaker.notifyRewardAmount(_amount); vm.stopPrank(); @@ -2815,7 +2893,7 @@ contract NotifyRewardAmount is StakerRewardsTest { rewardToken.transfer(address(govStaker), _amount); vm.expectRevert( abi.encodeWithSelector( - Staker.Staker__Unauthorized.selector, bytes32("not notifier"), _notNotifier + StakerUpgradeable.Staker__Unauthorized.selector, bytes32("not notifier"), _notNotifier ) ); govStaker.notifyRewardAmount(_amount); @@ -2829,7 +2907,7 @@ contract NotifyRewardAmount is StakerRewardsTest { vm.startPrank(rewardNotifier); rewardToken.transfer(address(govStaker), _amount); - vm.expectRevert(Staker.Staker__InvalidRewardRate.selector); + vm.expectRevert(StakerUpgradeable.Staker__InvalidRewardRate.selector); govStaker.notifyRewardAmount(_amount); vm.stopPrank(); } @@ -2851,7 +2929,7 @@ contract NotifyRewardAmount is StakerRewardsTest { // Something less than the supposed reward is sent rewardToken.transfer(address(govStaker), _transferAmount); // The reward notification should revert because the contract doesn't have enough tokens - vm.expectRevert(Staker.Staker__InsufficientRewardBalance.selector); + vm.expectRevert(StakerUpgradeable.Staker__InsufficientRewardBalance.selector); govStaker.notifyRewardAmount(_amount); vm.stopPrank(); } @@ -2874,7 +2952,7 @@ contract BumpEarningPower is StakerRewardsTest { _earningPowerIncrease = uint96(bound(_earningPowerIncrease, 1, type(uint48).max)); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -2891,7 +2969,7 @@ contract BumpEarningPower is StakerRewardsTest { vm.prank(_bumpCaller); govStaker.bumpEarningPower(_depositId, _tipReceiver, _requestedTip); - (,, uint96 _newEarningPower,,,,) = govStaker.deposits(_depositId); + uint96 _newEarningPower = govStaker.deposits(_depositId).earningPower; assertEq(_newEarningPower, _stakeAmount + _earningPowerIncrease); } @@ -2911,7 +2989,7 @@ contract BumpEarningPower is StakerRewardsTest { _earningPowerIncrease = uint96(bound(_earningPowerIncrease, 1, type(uint48).max)); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -2947,7 +3025,7 @@ contract BumpEarningPower is StakerRewardsTest { _earningPowerIncrease = uint96(bound(_earningPowerIncrease, 1, type(uint48).max)); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -2984,7 +3062,7 @@ contract BumpEarningPower is StakerRewardsTest { _earningPowerIncrease = uint96(bound(_earningPowerIncrease, 1, type(uint48).max)); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -3022,7 +3100,7 @@ contract BumpEarningPower is StakerRewardsTest { _earningPowerIncrease = uint96(bound(_earningPowerIncrease, 1, type(uint48).max)); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -3060,7 +3138,7 @@ contract BumpEarningPower is StakerRewardsTest { _earningPowerIncrease = uint96(bound(_earningPowerIncrease, 1, type(uint48).max)); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -3079,7 +3157,7 @@ contract BumpEarningPower is StakerRewardsTest { // Bump earning power is called vm.prank(_bumpCaller); vm.expectEmit(); - emit Staker.EarningPowerBumped( + emit StakerUpgradeable.EarningPowerBumped( _depositId, _oldEarningPower, _newEarningPower, _bumpCaller, _tipReceiver, _requestedTip ); govStaker.bumpEarningPower(_depositId, _tipReceiver, _requestedTip); @@ -3102,7 +3180,7 @@ contract BumpEarningPower is StakerRewardsTest { _earningPowerDecrease = bound(_earningPowerDecrease, 1, _stakeAmount); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -3120,7 +3198,7 @@ contract BumpEarningPower is StakerRewardsTest { vm.prank(_bumpCaller); govStaker.bumpEarningPower(_depositId, _tipReceiver, _requestedTip); - (,, uint96 _newEarningPower,,,,) = govStaker.deposits(_depositId); + uint96 _newEarningPower = govStaker.deposits(_depositId).earningPower; assertEq(_newEarningPower, _stakeAmount - _earningPowerDecrease); } @@ -3140,7 +3218,7 @@ contract BumpEarningPower is StakerRewardsTest { _earningPowerDecrease = bound(_earningPowerDecrease, 1, _stakeAmount); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -3177,7 +3255,7 @@ contract BumpEarningPower is StakerRewardsTest { _earningPowerDecrease = bound(_earningPowerDecrease, 1, _stakeAmount); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -3215,7 +3293,7 @@ contract BumpEarningPower is StakerRewardsTest { uint256 _initialTipReceiverBalance = rewardToken.balanceOf(_tipReceiver); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -3254,7 +3332,7 @@ contract BumpEarningPower is StakerRewardsTest { _earningPowerDecrease = bound(_earningPowerDecrease, 1, _stakeAmount); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -3291,7 +3369,7 @@ contract BumpEarningPower is StakerRewardsTest { _earningPowerDecrease = bound(_earningPowerDecrease, 1, _stakeAmount); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -3311,7 +3389,7 @@ contract BumpEarningPower is StakerRewardsTest { // Bump earning power is called vm.prank(_bumpCaller); vm.expectEmit(); - emit Staker.EarningPowerBumped( + emit StakerUpgradeable.EarningPowerBumped( _depositId, _oldEarningPower, _newEarningPower, _bumpCaller, _tipReceiver, _requestedTip ); govStaker.bumpEarningPower(_depositId, _tipReceiver, _requestedTip); @@ -3331,7 +3409,7 @@ contract BumpEarningPower is StakerRewardsTest { _rewardAmount = _boundToRealisticReward(_rewardAmount); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -3343,7 +3421,7 @@ contract BumpEarningPower is StakerRewardsTest { // The staker's earning power changes earningPowerCalculator.__setEarningPowerForDelegatee(_delegatee, _newEarningPower); // Bump earning power is called - vm.expectRevert(Staker.Staker__InvalidTip.selector); + vm.expectRevert(StakerUpgradeable.Staker__InvalidTip.selector); vm.prank(_bumpCaller); govStaker.bumpEarningPower(_depositId, _tipReceiver, _requestedTip); } @@ -3362,7 +3440,7 @@ contract BumpEarningPower is StakerRewardsTest { _rewardAmount = _boundToRealisticReward(_rewardAmount); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -3376,7 +3454,9 @@ contract BumpEarningPower is StakerRewardsTest { _delegatee, _newEarningPower, false ); // Bump earning power is called - vm.expectRevert(abi.encodeWithSelector(Staker.Staker__Unqualified.selector, _newEarningPower)); + vm.expectRevert( + abi.encodeWithSelector(StakerUpgradeable.Staker__Unqualified.selector, _newEarningPower) + ); vm.prank(_bumpCaller); govStaker.bumpEarningPower(_depositId, _tipReceiver, _requestedTip); } @@ -3394,7 +3474,7 @@ contract BumpEarningPower is StakerRewardsTest { _rewardAmount = _boundToRealisticReward(_rewardAmount); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -3406,7 +3486,9 @@ contract BumpEarningPower is StakerRewardsTest { // The staker's earning power changes earningPowerCalculator.__setEarningPowerForDelegatee(_delegatee, _stakeAmount); // Bump earning power is called - vm.expectRevert(abi.encodeWithSelector(Staker.Staker__Unqualified.selector, _stakeAmount)); + vm.expectRevert( + abi.encodeWithSelector(StakerUpgradeable.Staker__Unqualified.selector, _stakeAmount) + ); vm.prank(_bumpCaller); govStaker.bumpEarningPower(_depositId, _tipReceiver, _requestedTip); } @@ -3426,7 +3508,7 @@ contract BumpEarningPower is StakerRewardsTest { _rewardAmount = bound(_rewardAmount, 200e6, maxBumpTip - 1); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -3440,7 +3522,7 @@ contract BumpEarningPower is StakerRewardsTest { _delegatee, _stakeAmount + _earningPowerIncrease ); // // Bump earning power is called - vm.expectRevert(Staker.Staker__InsufficientUnclaimedRewards.selector); + vm.expectRevert(StakerUpgradeable.Staker__InsufficientUnclaimedRewards.selector); vm.prank(_bumpCaller); govStaker.bumpEarningPower(_depositId, _tipReceiver, _requestedTip); } @@ -3461,7 +3543,7 @@ contract BumpEarningPower is StakerRewardsTest { _earningPowerDecrease = bound(_earningPowerDecrease, 1, _stakeAmount); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -3475,7 +3557,7 @@ contract BumpEarningPower is StakerRewardsTest { _delegatee, _stakeAmount - _earningPowerDecrease ); // Bump earning power is called - vm.expectRevert(Staker.Staker__InsufficientUnclaimedRewards.selector); + vm.expectRevert(StakerUpgradeable.Staker__InsufficientUnclaimedRewards.selector); vm.prank(_bumpCaller); govStaker.bumpEarningPower(_depositId, _tipReceiver, _requestedTip); } @@ -3496,7 +3578,7 @@ contract BumpEarningPower is StakerRewardsTest { _earningPowerDecrease = bound(_earningPowerDecrease, 1, _stakeAmount); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -3532,7 +3614,7 @@ contract BumpEarningPower is StakerRewardsTest { vm.prank(admin); govStaker.setRewardNotifier(rewardNotifier, true); - (, Staker.DepositIdentifier depositId) = + (, StakerUpgradeable.DepositIdentifier depositId) = _boundMintAndStake(_depositor, _stakeAmount, _depositor); _mintTransferAndNotifyReward(_rewardAmount); @@ -3545,7 +3627,7 @@ contract BumpEarningPower is StakerRewardsTest { govStaker.bumpEarningPower(depositId, _depositor, 0); // Verify the earning power update - (,, uint96 actualEarningPower,,,,) = govStaker.deposits(depositId); + uint96 actualEarningPower = govStaker.deposits(depositId).earningPower; uint256 expectedEarningPower = (_stakeAmount * _multiplierBips) / 10_000; assertEq(actualEarningPower, expectedEarningPower, "Earning power should be updated"); } @@ -3654,12 +3736,12 @@ contract RewardPerTokenAccumulated is StakerRewardsTest { _durationPercent3 = bound(_durationPercent3, 0, 200); // First deposit - Staker.DepositIdentifier _depositId1; + StakerUpgradeable.DepositIdentifier _depositId1; (_stakeAmount1, _depositId1) = _boundMintAndStake(_depositor1, _stakeAmount1, _depositor1); _jumpAheadByPercentOfRewardDuration(_durationPercent1); // Second deposit - (, Staker.DepositIdentifier _depositId2) = + (, StakerUpgradeable.DepositIdentifier _depositId2) = _boundMintAndStake(_depositor2, _stakeAmount2, _depositor2); _jumpAheadByPercentOfRewardDuration(_durationPercent2); @@ -3695,7 +3777,7 @@ contract RewardPerTokenAccumulated is StakerRewardsTest { _durationPercent3 = _bound(_durationPercent3, 0, 200); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _depositor); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -3734,7 +3816,7 @@ contract RewardPerTokenAccumulated is StakerRewardsTest { _durationPercent3 = _bound(_durationPercent3, 0, 200); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _depositor); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -3770,7 +3852,7 @@ contract RewardPerTokenAccumulated is StakerRewardsTest { _durationPercent1 = _bound(_durationPercent1, 0, 200); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _depositor); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -3915,7 +3997,7 @@ contract RewardPerTokenAccumulated is StakerRewardsTest { _durationPercent1 = _bound(_durationPercent1, 0, 100); _durationPercent2 = _bound(_durationPercent2, 0, 100 - _durationPercent1); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; // A user deposits staking tokens (, _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _depositor); @@ -4049,7 +4131,7 @@ contract UnclaimedReward is StakerRewardsTest { (_stakeAmount, _rewardAmount) = _boundToRealisticStakeAndReward(_stakeAmount, _rewardAmount); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -4070,7 +4152,7 @@ contract UnclaimedReward is StakerRewardsTest { (_stakeAmount, _rewardAmount) = _boundToRealisticStakeAndReward(_stakeAmount, _rewardAmount); // A user deposits staking tokens w/ a claimer - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee, _claimer); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -4092,7 +4174,7 @@ contract UnclaimedReward is StakerRewardsTest { _durationPercent = bound(_durationPercent, 0, 100); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -4118,7 +4200,7 @@ contract UnclaimedReward is StakerRewardsTest { // Two thirds of the duration time passes _jumpAheadByPercentOfRewardDuration(66); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee); // The rest of the duration elapses _jumpAheadByPercentOfRewardDuration(34); @@ -4137,7 +4219,7 @@ contract UnclaimedReward is StakerRewardsTest { (_stakeAmount, _rewardAmount) = _boundToRealisticStakeAndReward(_stakeAmount, _rewardAmount); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -4166,7 +4248,7 @@ contract UnclaimedReward is StakerRewardsTest { _durationPercent = bound(_durationPercent, 0, 100); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -4205,7 +4287,7 @@ contract UnclaimedReward is StakerRewardsTest { _durationPercent = bound(_durationPercent, 0, 100); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -4242,12 +4324,12 @@ contract UnclaimedReward is StakerRewardsTest { (_stakeAmount, _rewardAmount) = _boundToRealisticStakeAndReward(_stakeAmount, _rewardAmount); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId1) = + (, StakerUpgradeable.DepositIdentifier _depositId1) = _boundMintAndStake(_depositor1, _stakeAmount, _delegatee); // Some time passes _jumpAhead(3000); // Another depositor deposits the same number of staking tokens - (, Staker.DepositIdentifier _depositId2) = + (, StakerUpgradeable.DepositIdentifier _depositId2) = _boundMintAndStake(_depositor2, _stakeAmount, _delegatee); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -4270,12 +4352,12 @@ contract UnclaimedReward is StakerRewardsTest { (_stakeAmount, _rewardAmount) = _boundToRealisticStakeAndReward(_stakeAmount, _rewardAmount); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId1) = + (, StakerUpgradeable.DepositIdentifier _depositId1) = _boundMintAndStake(_depositor1, _stakeAmount, _delegatee); // Some time passes _jumpAhead(3000); // Another depositor deposits the same number of staking tokens - (, Staker.DepositIdentifier _depositId2) = + (, StakerUpgradeable.DepositIdentifier _depositId2) = _boundMintAndStake(_depositor2, _stakeAmount, _delegatee); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -4316,12 +4398,12 @@ contract UnclaimedReward is StakerRewardsTest { (_stakeAmount, _rewardAmount) = _boundToRealisticStakeAndReward(_stakeAmount, _rewardAmount); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId1) = + (, StakerUpgradeable.DepositIdentifier _depositId1) = _boundMintAndStake(_depositor1, _stakeAmount, _delegatee); // Some time passes _jumpAhead(3000); // Another depositor deposits the same number of staking tokens - (, Staker.DepositIdentifier _depositId2) = + (, StakerUpgradeable.DepositIdentifier _depositId2) = _boundMintAndStake(_depositor2, _stakeAmount, _delegatee); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -4360,12 +4442,12 @@ contract UnclaimedReward is StakerRewardsTest { (_stakeAmount, _rewardAmount) = _boundToRealisticStakeAndReward(_stakeAmount, _rewardAmount); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId1) = + (, StakerUpgradeable.DepositIdentifier _depositId1) = _boundMintAndStake(_depositor1, _stakeAmount, _delegatee); // Some time passes _jumpAhead(3000); // Another depositor deposits the same number of staking tokens - (, Staker.DepositIdentifier _depositId2) = + (, StakerUpgradeable.DepositIdentifier _depositId2) = _boundMintAndStake(_depositor2, _stakeAmount, _delegatee); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -4413,7 +4495,7 @@ contract UnclaimedReward is StakerRewardsTest { (_stakeAmount, _rewardAmount) = _boundToRealisticStakeAndReward(_stakeAmount, _rewardAmount); // The first user stakes some tokens - (, Staker.DepositIdentifier _depositId1) = + (, StakerUpgradeable.DepositIdentifier _depositId1) = _boundMintAndStake(_depositor1, _stakeAmount, _delegatee); // A small amount of time passes _jumpAhead(3000); @@ -4422,7 +4504,7 @@ contract UnclaimedReward is StakerRewardsTest { // Two thirds of the duration time elapses _jumpAheadByPercentOfRewardDuration(66); // A second user stakes the same amount of tokens - (, Staker.DepositIdentifier _depositId2) = + (, StakerUpgradeable.DepositIdentifier _depositId2) = _boundMintAndStake(_depositor2, _stakeAmount, _delegatee); // The rest of the duration elapses _jumpAheadByPercentOfRewardDuration(34); @@ -4449,7 +4531,7 @@ contract UnclaimedReward is StakerRewardsTest { (_stakeAmount, _rewardAmount2) = _boundToRealisticStakeAndReward(_stakeAmount, _rewardAmount2); // A user stakes tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount1); @@ -4487,12 +4569,12 @@ contract UnclaimedReward is StakerRewardsTest { // One quarter of the duration elapses _jumpAheadByPercentOfRewardDuration(25); // A user stakes some tokens - (, Staker.DepositIdentifier _depositId1) = + (, StakerUpgradeable.DepositIdentifier _depositId1) = _boundMintAndStake(_depositor1, _stakeAmount, _delegatee); // Another 40 percent of the duration time elapses _jumpAheadByPercentOfRewardDuration(40); // Another user stakes some tokens - (, Staker.DepositIdentifier _depositId2) = + (, StakerUpgradeable.DepositIdentifier _depositId2) = _boundMintAndStake(_depositor2, _stakeAmount, _delegatee); // Another quarter of the duration elapses _jumpAheadByPercentOfRewardDuration(25); @@ -4539,12 +4621,12 @@ contract UnclaimedReward is StakerRewardsTest { // One quarter of the duration elapses _jumpAheadByPercentOfRewardDuration(25); // A user stakes some tokens - (, Staker.DepositIdentifier _depositId1) = + (, StakerUpgradeable.DepositIdentifier _depositId1) = _boundMintAndStake(_depositor1, _stakeAmount1, _delegatee); // Another 40 percent of the duration time elapses _jumpAheadByPercentOfRewardDuration(40); // Another user stakes some tokens - (, Staker.DepositIdentifier _depositId2) = + (, StakerUpgradeable.DepositIdentifier _depositId2) = _boundMintAndStake(_depositor2, _stakeAmount2, _delegatee); // Another quarter of the duration elapses _jumpAheadByPercentOfRewardDuration(25); @@ -4590,7 +4672,7 @@ contract UnclaimedReward is StakerRewardsTest { (_stakeAmount, _rewardAmount3) = _boundToRealisticStakeAndReward(_stakeAmount, _rewardAmount3); // A user stakes tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount1); @@ -4638,12 +4720,12 @@ contract UnclaimedReward is StakerRewardsTest { // One quarter of the duration elapses _jumpAheadByPercentOfRewardDuration(25); // A user stakes some tokens - (, Staker.DepositIdentifier _depositId1) = + (, StakerUpgradeable.DepositIdentifier _depositId1) = _boundMintAndStake(_depositor1, _stakeAmount, _delegatee); // Another 20 percent of the duration time elapses _jumpAheadByPercentOfRewardDuration(20); // Another user stakes some tokens - (, Staker.DepositIdentifier _depositId2) = + (, StakerUpgradeable.DepositIdentifier _depositId2) = _boundMintAndStake(_depositor2, _stakeAmount, _delegatee); // Another 20 percent of the duration time elapses _jumpAheadByPercentOfRewardDuration(20); @@ -4705,12 +4787,12 @@ contract UnclaimedReward is StakerRewardsTest { // One quarter of the duration elapses _jumpAheadByPercentOfRewardDuration(25); // A user stakes some tokens - (, Staker.DepositIdentifier _depositId1) = + (, StakerUpgradeable.DepositIdentifier _depositId1) = _boundMintAndStake(_depositor1, _stakeAmount1, _delegatee); // Another 40 percent of the duration time elapses _jumpAheadByPercentOfRewardDuration(20); // Another user stakes some tokens - (, Staker.DepositIdentifier _depositId2) = + (, StakerUpgradeable.DepositIdentifier _depositId2) = _boundMintAndStake(_depositor2, _stakeAmount2, _delegatee); // Another quarter of the duration elapses _jumpAheadByPercentOfRewardDuration(20); @@ -4766,14 +4848,14 @@ contract UnclaimedReward is StakerRewardsTest { _durationPercent = bound(_durationPercent, 0, 100); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId1) = + (, StakerUpgradeable.DepositIdentifier _depositId1) = _boundMintAndStake(_depositor1, _stakeAmount1, _delegatee); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); // A portion of the duration passes _jumpAheadByPercentOfRewardDuration(_durationPercent); // Another user deposits stake - (, Staker.DepositIdentifier _depositId2) = + (, StakerUpgradeable.DepositIdentifier _depositId2) = _boundMintAndStake(_depositor2, _stakeAmount2, _delegatee); // The rest of the duration elapses _jumpAheadByPercentOfRewardDuration(100 - _durationPercent); @@ -4807,14 +4889,16 @@ contract UnclaimedReward is StakerRewardsTest { vm.stopPrank(); // User deposit staking tokens - Staker.DepositIdentifier _depositId1 = _stake(_depositor1, _smallDepositAmount, _delegatee); - Staker.DepositIdentifier _depositId2 = _stake(_depositor2, _smallDepositAmount, _delegatee); + StakerUpgradeable.DepositIdentifier _depositId1 = + _stake(_depositor1, _smallDepositAmount, _delegatee); + StakerUpgradeable.DepositIdentifier _depositId2 = + _stake(_depositor2, _smallDepositAmount, _delegatee); _stake(_depositor3, _largeDepositAmount, _delegatee); // Every block _attacker deposits 0 stake and assigns _depositor1 as claimer, thus leading // to frequent updates of the reward checkpoint for _depositor1, during which rounding errors // could accrue. - Staker.DepositIdentifier _depositId = _stake(_attacker, 0, _delegatee, _depositor1); + StakerUpgradeable.DepositIdentifier _depositId = _stake(_attacker, 0, _delegatee, _depositor1); for (uint256 i = 0; i < 1000; ++i) { _jumpAhead(12); vm.prank(_attacker); @@ -4844,7 +4928,7 @@ contract ClaimReward is StakerRewardsTest { _durationPercent = bound(_durationPercent, 0, 100); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee, _claimer); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -4873,7 +4957,7 @@ contract ClaimReward is StakerRewardsTest { _durationPercent = bound(_durationPercent, 0, 100); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee, _claimer); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -4901,7 +4985,7 @@ contract ClaimReward is StakerRewardsTest { _durationPercent = bound(_durationPercent, 0, 100); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -4927,7 +5011,7 @@ contract ClaimReward is StakerRewardsTest { _durationPercent = bound(_durationPercent, 0, 100); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -4952,7 +5036,7 @@ contract ClaimReward is StakerRewardsTest { (_stakeAmount, _rewardAmount) = _boundToRealisticStakeAndReward(_stakeAmount, _rewardAmount); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee, _claimer); vm.assume(_stakeAmount != _newEarningPower); @@ -4967,7 +5051,7 @@ contract ClaimReward is StakerRewardsTest { vm.prank(_depositor); govStaker.claimReward(_depositId); - Staker.Deposit memory _deposit = _fetchDeposit(_depositId); + StakerUpgradeable.Deposit memory _deposit = _fetchDeposit(_depositId); assertEq(_deposit.earningPower, _newEarningPower); } @@ -4984,7 +5068,7 @@ contract ClaimReward is StakerRewardsTest { (_stakeAmount, _rewardAmount) = _boundToRealisticStakeAndReward(_stakeAmount, _rewardAmount); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee, _claimer); vm.assume(_stakeAmount != _newEarningPower); @@ -5014,7 +5098,7 @@ contract ClaimReward is StakerRewardsTest { (_stakeAmount, _rewardAmount) = _boundToRealisticStakeAndReward(_stakeAmount, _rewardAmount); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee, _claimer); vm.assume(_stakeAmount != _newEarningPower); @@ -5044,7 +5128,7 @@ contract ClaimReward is StakerRewardsTest { _durationPercent = bound(_durationPercent, 1, 100); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee, _claimer); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -5054,7 +5138,7 @@ contract ClaimReward is StakerRewardsTest { uint256 _earned = govStaker.unclaimedReward(_depositId); vm.expectEmit(); - emit Staker.RewardClaimed(_depositId, _depositor, _earned, _stakeAmount); + emit StakerUpgradeable.RewardClaimed(_depositId, _depositor, _earned, _stakeAmount); vm.prank(_depositor); govStaker.claimReward(_depositId); @@ -5072,7 +5156,7 @@ contract ClaimReward is StakerRewardsTest { _durationPercent = bound(_durationPercent, 1, 100); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee, _claimer); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -5082,7 +5166,7 @@ contract ClaimReward is StakerRewardsTest { uint256 _earned = govStaker.unclaimedReward(_depositId); vm.expectEmit(); - emit Staker.RewardClaimed(_depositId, _claimer, _earned, _stakeAmount); + emit StakerUpgradeable.RewardClaimed(_depositId, _claimer, _earned, _stakeAmount); vm.prank(_claimer); govStaker.claimReward(_depositId); @@ -5108,7 +5192,7 @@ contract ClaimReward is StakerRewardsTest { // The admin sets a claim fee _setClaimFeeAndCollector(_feeAmount, _feeCollector); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee, _claimer); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -5144,7 +5228,7 @@ contract ClaimReward is StakerRewardsTest { // The admin sets a claim fee _setClaimFeeAndCollector(_feeAmount, _feeCollector); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee, _claimer); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -5179,7 +5263,7 @@ contract ClaimReward is StakerRewardsTest { // The admin sets a claim fee _setClaimFeeAndCollector(_feeAmount, _feeCollector); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee, _claimer); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -5190,7 +5274,7 @@ contract ClaimReward is StakerRewardsTest { vm.prank(_depositor); vm.expectEmit(); - emit Staker.RewardClaimed(_depositId, _depositor, _earned - _feeAmount, _stakeAmount); + emit StakerUpgradeable.RewardClaimed(_depositId, _depositor, _earned - _feeAmount, _stakeAmount); govStaker.claimReward(_depositId); } @@ -5208,7 +5292,7 @@ contract ClaimReward is StakerRewardsTest { _durationPercent = bound(_durationPercent, 1, 100); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee, _claimer); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -5218,7 +5302,9 @@ contract ClaimReward is StakerRewardsTest { vm.prank(_notClaimer); vm.expectRevert( abi.encodeWithSelector( - Staker.Staker__Unauthorized.selector, bytes32("not claimer or owner"), _notClaimer + StakerUpgradeable.Staker__Unauthorized.selector, + bytes32("not claimer or owner"), + _notClaimer ) ); govStaker.claimReward(_depositId); @@ -5241,7 +5327,7 @@ contract ClaimReward is StakerRewardsTest { // The admin sets a claim fee _setClaimFeeAndCollector(uint96(govStaker.MAX_CLAIM_FEE()), _feeCollector); // A user deposits staking tokens - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee, _claimer); // The contract is notified of a reward _mintTransferAndNotifyReward(_rewardAmount); @@ -5267,7 +5353,7 @@ contract ClaimReward is StakerRewardsTest { _multiplierBips = bound(_multiplierBips, 0, 20_000); earningPowerCalculator.__setMultiplierBips(_multiplierBips); - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee, _claimer); _mintTransferAndNotifyReward(_rewardAmount); @@ -5278,7 +5364,7 @@ contract ClaimReward is StakerRewardsTest { uint256 _expectedEarningPower = (_stakeAmount * _multiplierBips) / 10_000; - Staker.Deposit memory _deposit = _fetchDeposit(_depositId); + StakerUpgradeable.Deposit memory _deposit = _fetchDeposit(_depositId); assertEq(_deposit.earningPower, _expectedEarningPower); assertEq(govStaker.totalEarningPower(), _expectedEarningPower); assertEq(govStaker.depositorTotalEarningPower(_depositor), _expectedEarningPower); @@ -5298,7 +5384,7 @@ contract ClaimReward is StakerRewardsTest { earningPowerCalculator.__setFixedReturn(_fixedEarningPower); - (, Staker.DepositIdentifier _depositId) = + (, StakerUpgradeable.DepositIdentifier _depositId) = _boundMintAndStake(_depositor, _stakeAmount, _delegatee, _claimer); _mintTransferAndNotifyReward(_rewardAmount); @@ -5307,7 +5393,7 @@ contract ClaimReward is StakerRewardsTest { vm.prank(_depositor); govStaker.claimReward(_depositId); - Staker.Deposit memory _deposit = _fetchDeposit(_depositId); + StakerUpgradeable.Deposit memory _deposit = _fetchDeposit(_depositId); assertEq(_deposit.earningPower, _fixedEarningPower); assertEq(govStaker.totalEarningPower(), _fixedEarningPower); assertEq(govStaker.depositorTotalEarningPower(_depositor), _fixedEarningPower); @@ -5349,7 +5435,7 @@ contract Multicall is StakerRewardsTest { ); } - function _encodeStakeMore(Staker.DepositIdentifier _depositId, uint256 _stakeAmount) + function _encodeStakeMore(StakerUpgradeable.DepositIdentifier _depositId, uint256 _stakeAmount) internal pure returns (bytes memory) @@ -5359,7 +5445,7 @@ contract Multicall is StakerRewardsTest { ); } - function _encodeWithdraw(Staker.DepositIdentifier _depositId, uint256 _amount) + function _encodeWithdraw(StakerUpgradeable.DepositIdentifier _depositId, uint256 _amount) internal pure returns (bytes memory) @@ -5368,7 +5454,7 @@ contract Multicall is StakerRewardsTest { abi.encodeWithSelector(bytes4(keccak256("withdraw(uint256,uint256)")), _depositId, _amount); } - function _encodeAlterClaimer(Staker.DepositIdentifier _depositId, address _claimer) + function _encodeAlterClaimer(StakerUpgradeable.DepositIdentifier _depositId, address _claimer) internal pure returns (bytes memory) @@ -5378,7 +5464,7 @@ contract Multicall is StakerRewardsTest { ); } - function _encodeAlterDelegatee(Staker.DepositIdentifier _depositId, address _delegatee) + function _encodeAlterDelegatee(StakerUpgradeable.DepositIdentifier _depositId, address _delegatee) internal pure returns (bytes memory) @@ -5434,7 +5520,8 @@ contract Multicall is StakerRewardsTest { govToken.approve(address(govStaker), _stakeAmount0 + _stakeAmount1); // first, do initial stake without multicall - Staker.DepositIdentifier _depositId = govStaker.stake(_stakeAmount0, _delegatee0, _claimer0); + StakerUpgradeable.DepositIdentifier _depositId = + govStaker.stake(_stakeAmount0, _delegatee0, _claimer0); // some time goes by... vm.warp(_timeElapsed); @@ -5447,12 +5534,11 @@ contract Multicall is StakerRewardsTest { govStaker.multicall(_calls); vm.stopPrank(); - (uint96 _amountResult,,, address _delegateeResult, address _claimerResult,,) = - govStaker.deposits(_depositId); + StakerUpgradeable.Deposit memory _depositResult = govStaker.deposits(_depositId); assertEq(govStaker.depositorTotalStaked(_depositor), _stakeAmount0 + _stakeAmount1); assertEq(govStaker.depositorTotalEarningPower(_depositor), _stakeAmount0 + _stakeAmount1); - assertEq(_amountResult, _stakeAmount0 + _stakeAmount1); - assertEq(_delegateeResult, _delegatee1); - assertEq(_claimerResult, _claimer1); + assertEq(_depositResult.balance, _stakeAmount0 + _stakeAmount1); + assertEq(_depositResult.delegatee, _delegatee1); + assertEq(_depositResult.claimer, _claimer1); } } diff --git a/test/StakerCapDeposits.t.sol b/test/StakerCapDeposits.t.sol index c6bf5aa3..42734299 100644 --- a/test/StakerCapDeposits.t.sol +++ b/test/StakerCapDeposits.t.sol @@ -4,24 +4,39 @@ pragma solidity ^0.8.23; import {Vm, Test, stdStorage, StdStorage, console2, stdError} from "forge-std/Test.sol"; import {StakerTestBase} from "./StakerTestBase.sol"; import {StakerHarnessCapDeposits} from "./harnesses/StakerHarnessCapDeposits.sol"; -import {Staker} from "../src/Staker.sol"; -import {StakerCapDeposits} from "../src/extensions/StakerCapDeposits.sol"; +import {StakerUpgradeable} from "../src/StakerUpgradeable.sol"; +import {StakerCapDepositsUpgradeable} from "../src/extensions/StakerCapDepositsUpgradeable.sol"; import {DelegationSurrogate} from "../src/DelegationSurrogate.sol"; +import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; contract StakerCapDepositsTest is StakerTestBase { StakerHarnessCapDeposits govStaker; uint256 initialTotalStakeCap = 1_000_000e18; - function _deployStaker() public virtual override(StakerTestBase) returns (Staker _staker) { - return new StakerHarnessCapDeposits( - rewardToken, - govToken, - earningPowerCalculator, - maxBumpTip, - admin, - "Staker", - initialTotalStakeCap + function _deployStaker() + public + virtual + override(StakerTestBase) + returns (StakerUpgradeable _staker) + { + StakerHarnessCapDeposits implementation = new StakerHarnessCapDeposits(); + ERC1967Proxy proxy = new ERC1967Proxy( + address(implementation), + abi.encodeCall( + StakerHarnessCapDeposits.initialize, + ( + rewardToken, + govToken, + 1e18, + admin, + maxBumpTip, + earningPowerCalculator, + "Staker", + initialTotalStakeCap + ) + ) ); + return StakerHarnessCapDeposits(address(proxy)); } function setUp() public virtual override(StakerTestBase) { @@ -39,29 +54,46 @@ contract Constructor is StakerCapDepositsTest { function testFuzz_SetsTheInitialTotalStakeCapToArbitraryValues(uint256 _initialTotalStakeCap) public { - StakerHarnessCapDeposits _govStaker = new StakerHarnessCapDeposits( - rewardToken, - govToken, - earningPowerCalculator, - maxBumpTip, - admin, - "Staker", - _initialTotalStakeCap + StakerHarnessCapDeposits implementation = new StakerHarnessCapDeposits(); + ERC1967Proxy proxy = new ERC1967Proxy( + address(implementation), + abi.encodeCall( + StakerHarnessCapDeposits.initialize, + ( + rewardToken, + govToken, + 1e18, + admin, + maxBumpTip, + earningPowerCalculator, + "Staker", + _initialTotalStakeCap + ) + ) ); + StakerHarnessCapDeposits _govStaker = StakerHarnessCapDeposits(address(proxy)); assertEq(_govStaker.totalStakeCap(), _initialTotalStakeCap); } function testFuzz_EmitsATotalStakeCapSetEvent(uint256 _initialTotalStakeCap) public { vm.expectEmit(); - emit StakerCapDeposits.TotalStakeCapSet(0, _initialTotalStakeCap); - new StakerHarnessCapDeposits( - rewardToken, - govToken, - earningPowerCalculator, - maxBumpTip, - admin, - "Staker", - _initialTotalStakeCap + emit StakerCapDepositsUpgradeable.TotalStakeCapSet(0, _initialTotalStakeCap); + StakerHarnessCapDeposits implementation = new StakerHarnessCapDeposits(); + ERC1967Proxy proxy = new ERC1967Proxy( + address(implementation), + abi.encodeCall( + StakerHarnessCapDeposits.initialize, + ( + rewardToken, + govToken, + 1e18, + admin, + maxBumpTip, + earningPowerCalculator, + "Staker", + _initialTotalStakeCap + ) + ) ); } } @@ -77,7 +109,7 @@ contract SetTotalStakeCap is StakerCapDepositsTest { function testFuzz_EmitsATotalStakeCapSetEvent(uint256 _newTotalStakeCap) public { vm.prank(admin); vm.expectEmit(); - emit StakerCapDeposits.TotalStakeCapSet(initialTotalStakeCap, _newTotalStakeCap); + emit StakerCapDepositsUpgradeable.TotalStakeCapSet(initialTotalStakeCap, _newTotalStakeCap); govStaker.setTotalStakeCap(_newTotalStakeCap); } @@ -88,7 +120,9 @@ contract SetTotalStakeCap is StakerCapDepositsTest { vm.prank(_notAdmin); vm.expectRevert( - abi.encodeWithSelector(Staker.Staker__Unauthorized.selector, bytes32("not admin"), _notAdmin) + abi.encodeWithSelector( + StakerUpgradeable.Staker__Unauthorized.selector, bytes32("not admin"), _notAdmin + ) ); govStaker.setTotalStakeCap(_newTotalStakeCap); } @@ -129,10 +163,10 @@ contract _Stake is StakerCapDepositsTest { _mintGovToken(_depositor2, _amount2); // Calls to stake do not revert - Staker.DepositIdentifier _depositId1 = _stake(_depositor1, _amount1, _delegatee1); - Staker.DepositIdentifier _depositId2 = _stake(_depositor2, _amount2, _delegatee2); - Staker.Deposit memory _deposit1 = _fetchDeposit(_depositId1); - Staker.Deposit memory _deposit2 = _fetchDeposit(_depositId2); + StakerUpgradeable.DepositIdentifier _depositId1 = _stake(_depositor1, _amount1, _delegatee1); + StakerUpgradeable.DepositIdentifier _depositId2 = _stake(_depositor2, _amount2, _delegatee2); + StakerUpgradeable.Deposit memory _deposit1 = _fetchDeposit(_depositId1); + StakerUpgradeable.Deposit memory _deposit2 = _fetchDeposit(_depositId2); // Some sanity checks to ensure the stake operations completed. assertEq(govStaker.totalStaked(), _amount1 + _amount2); @@ -151,7 +185,7 @@ contract _Stake is StakerCapDepositsTest { vm.startPrank(_depositor); govToken.approve(address(govStaker), _amount); - vm.expectRevert(StakerCapDeposits.StakerCapDeposits__CapExceeded.selector); + vm.expectRevert(StakerCapDepositsUpgradeable.StakerCapDepositsUpgradeable__CapExceeded.selector); govStaker.stake(_amount, _delegatee); vm.stopPrank(); } @@ -172,8 +206,8 @@ contract _Stake is StakerCapDepositsTest { _mintGovToken(_depositor2, _amount2); // First call to stake does not revert. - Staker.DepositIdentifier _depositId1 = _stake(_depositor1, _amount1, _delegatee1); - Staker.Deposit memory _deposit1 = _fetchDeposit(_depositId1); + StakerUpgradeable.DepositIdentifier _depositId1 = _stake(_depositor1, _amount1, _delegatee1); + StakerUpgradeable.Deposit memory _deposit1 = _fetchDeposit(_depositId1); // Some sanity checks to ensure the stake operation completed. assertEq(govStaker.totalStaked(), _amount1); assertEq(_deposit1.balance, _amount1); @@ -181,7 +215,7 @@ contract _Stake is StakerCapDepositsTest { // The second attempt to stake should revert vm.startPrank(_depositor2); govToken.approve(address(govStaker), _amount2); - vm.expectRevert(StakerCapDeposits.StakerCapDeposits__CapExceeded.selector); + vm.expectRevert(StakerCapDepositsUpgradeable.StakerCapDepositsUpgradeable__CapExceeded.selector); govStaker.stake(_amount2, _delegatee2); vm.stopPrank(); } @@ -202,8 +236,8 @@ contract _Stake is StakerCapDepositsTest { _mintGovToken(_depositor2, _amount2); // First call to stake does not revert. - Staker.DepositIdentifier _depositId1 = _stake(_depositor1, _amount1, _delegatee1); - Staker.Deposit memory _deposit1 = _fetchDeposit(_depositId1); + StakerUpgradeable.DepositIdentifier _depositId1 = _stake(_depositor1, _amount1, _delegatee1); + StakerUpgradeable.Deposit memory _deposit1 = _fetchDeposit(_depositId1); // Some sanity checks to ensure the stake operation completed. assertEq(govStaker.totalStaked(), _amount1); assertEq(_deposit1.balance, _amount1); @@ -211,7 +245,7 @@ contract _Stake is StakerCapDepositsTest { // The second attempt to stake should revert. vm.startPrank(_depositor2); govToken.approve(address(govStaker), _amount2); - vm.expectRevert(StakerCapDeposits.StakerCapDeposits__CapExceeded.selector); + vm.expectRevert(StakerCapDepositsUpgradeable.StakerCapDepositsUpgradeable__CapExceeded.selector); govStaker.stake(_amount2, _delegatee2); vm.stopPrank(); @@ -221,10 +255,10 @@ contract _Stake is StakerCapDepositsTest { govStaker.setTotalStakeCap(_newTotalStakeCap); // Now the same deposit succeeds. - Staker.DepositIdentifier _depositId2 = _stake(_depositor2, _amount2, _delegatee2); + StakerUpgradeable.DepositIdentifier _depositId2 = _stake(_depositor2, _amount2, _delegatee2); // Some sanity checks to ensure the stake operation completed. - Staker.Deposit memory _deposit2 = _fetchDeposit(_depositId2); + StakerUpgradeable.Deposit memory _deposit2 = _fetchDeposit(_depositId2); assertEq(govStaker.totalStaked(), _amount1 + _amount2); assertEq(_deposit2.balance, _amount2); } @@ -244,8 +278,8 @@ contract _Stake is StakerCapDepositsTest { _mintGovToken(_depositor2, _amount2); // First call to stake does not revert. - Staker.DepositIdentifier _depositId1 = _stake(_depositor1, _amount1, _delegatee1); - Staker.Deposit memory _deposit1 = _fetchDeposit(_depositId1); + StakerUpgradeable.DepositIdentifier _depositId1 = _stake(_depositor1, _amount1, _delegatee1); + StakerUpgradeable.Deposit memory _deposit1 = _fetchDeposit(_depositId1); // Some sanity checks to ensure the stake operation completed. assertEq(govStaker.totalStaked(), _amount1); assertEq(_deposit1.balance, _amount1); @@ -258,7 +292,7 @@ contract _Stake is StakerCapDepositsTest { // The second attempt to stake should revert. vm.startPrank(_depositor2); govToken.approve(address(govStaker), _amount2); - vm.expectRevert(StakerCapDeposits.StakerCapDeposits__CapExceeded.selector); + vm.expectRevert(StakerCapDepositsUpgradeable.StakerCapDepositsUpgradeable__CapExceeded.selector); govStaker.stake(_amount2, _delegatee2); vm.stopPrank(); } @@ -278,14 +312,14 @@ contract _StakeMore is StakerCapDepositsTest { _mintGovToken(_depositor, _depositAmount + _addAmount); // Initial stake is completed - Staker.DepositIdentifier _depositId = _stake(_depositor, _depositAmount, _delegatee); + StakerUpgradeable.DepositIdentifier _depositId = _stake(_depositor, _depositAmount, _delegatee); // More stake is added without the call reverting. vm.startPrank(_depositor); govToken.approve(address(govStaker), _addAmount); govStaker.stakeMore(_depositId, _addAmount); vm.stopPrank(); - Staker.Deposit memory _deposit = _fetchDeposit(_depositId); + StakerUpgradeable.Deposit memory _deposit = _fetchDeposit(_depositId); DelegationSurrogate _surrogate = govStaker.surrogates(_deposit.delegatee); // Sanity checks to make sure the staking operations completed successfully. @@ -307,12 +341,12 @@ contract _StakeMore is StakerCapDepositsTest { _mintGovToken(_depositor, _depositAmount + _addAmount); // Initial stake is completed - Staker.DepositIdentifier _depositId = _stake(_depositor, _depositAmount, _delegatee); + StakerUpgradeable.DepositIdentifier _depositId = _stake(_depositor, _depositAmount, _delegatee); // Reverts when attempting to add more such that the cap is exceeded. vm.startPrank(_depositor); govToken.approve(address(govStaker), _addAmount); - vm.expectRevert(StakerCapDeposits.StakerCapDeposits__CapExceeded.selector); + vm.expectRevert(StakerCapDepositsUpgradeable.StakerCapDepositsUpgradeable__CapExceeded.selector); govStaker.stakeMore(_depositId, _addAmount); vm.stopPrank(); } diff --git a/test/StakerOnBehalf.t.sol b/test/StakerOnBehalf.t.sol index 780c8416..4906b153 100644 --- a/test/StakerOnBehalf.t.sol +++ b/test/StakerOnBehalf.t.sol @@ -2,11 +2,12 @@ pragma solidity ^0.8.23; import {stdStorage, StdStorage} from "forge-std/Test.sol"; -import {StakerOnBehalf} from "../src/extensions/StakerOnBehalf.sol"; +import {StakerOnBehalfUpgradeable} from "../src/extensions/StakerOnBehalfUpgradeable.sol"; import {StakerTest, StakerRewardsTest} from "./Staker.t.sol"; import {StakerHarness} from "./harnesses/StakerHarness.sol"; -import {Staker, IERC20, IEarningPowerCalculator} from "../src/Staker.sol"; +import {StakerUpgradeable, IERC20, IEarningPowerCalculator} from "../src/StakerUpgradeable.sol"; import {IERC20Staking} from "../src/interfaces/IERC20Staking.sol"; +import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; contract Domain_Separator is StakerTest { function _buildDomainSeparator(string memory _name, string memory _version, address _contract) @@ -33,14 +34,23 @@ contract Domain_Separator is StakerTest { string memory _name ) public { vm.assume(_admin != address(0) && _earningPowerCalculator != address(0)); - StakerHarness _govStaker = new StakerHarness( - IERC20(_rewardToken), - IERC20Staking(_stakeToken), - IEarningPowerCalculator(_earningPowerCalculator), - _maxBumpTip, - _admin, - _name + StakerHarness implementation = new StakerHarness(); + ERC1967Proxy proxy = new ERC1967Proxy( + address(implementation), + abi.encodeCall( + StakerHarness.initialize, + ( + IERC20(_rewardToken), + IERC20Staking(_stakeToken), + 1e18, + _admin, + _maxBumpTip, + IEarningPowerCalculator(_earningPowerCalculator), + _name + ) + ) ); + StakerHarness _govStaker = StakerHarness(address(proxy)); bytes32 _separator = _govStaker.DOMAIN_SEPARATOR(); bytes32 _expectedSeparator = _buildDomainSeparator(_name, "1", address(_govStaker)); @@ -135,11 +145,11 @@ contract StakeOnBehalf is StakerTest { bytes memory _signature = _sign(_depositorPrivateKey, _messageHash); vm.prank(_sender); - Staker.DepositIdentifier _depositId = govStaker.stakeOnBehalf( + StakerUpgradeable.DepositIdentifier _depositId = govStaker.stakeOnBehalf( _depositAmount, _delegatee, _claimer, _depositor, _deadline, _signature ); - Staker.Deposit memory _deposit = _fetchDeposit(_depositId); + StakerUpgradeable.Deposit memory _deposit = _fetchDeposit(_depositId); assertEq(_deposit.balance, _depositAmount); assertEq(_deposit.owner, _depositor); @@ -188,7 +198,7 @@ contract StakeOnBehalf is StakerTest { keccak256(abi.encodePacked("\x19\x01", EIP712_DOMAIN_SEPARATOR, _message)); bytes memory _signature = _sign(_depositorPrivateKey, _messageHash); - vm.expectRevert(StakerOnBehalf.StakerOnBehalf__InvalidSignature.selector); + vm.expectRevert(StakerOnBehalfUpgradeable.StakerOnBehalfUpgradeable__InvalidSignature.selector); vm.prank(_sender); govStaker.stakeOnBehalf(_depositAmount, _delegatee, _claimer, _depositor, _deadline, _signature); } @@ -232,7 +242,7 @@ contract StakeOnBehalf is StakerTest { keccak256(abi.encodePacked("\x19\x01", EIP712_DOMAIN_SEPARATOR, _message)); bytes memory _signature = _sign(_depositorPrivateKey, _messageHash); - vm.expectRevert(StakerOnBehalf.StakerOnBehalf__ExpiredDeadline.selector); + vm.expectRevert(StakerOnBehalfUpgradeable.StakerOnBehalfUpgradeable__ExpiredDeadline.selector); vm.prank(_sender); govStaker.stakeOnBehalf(_depositAmount, _delegatee, _claimer, _depositor, _deadline, _signature); } @@ -292,7 +302,7 @@ contract StakeOnBehalf is StakerTest { if (_randomSeed % 6 == 5) _signature = _modifySignature(_signature, _randomSeed); vm.prank(_sender); - vm.expectRevert(StakerOnBehalf.StakerOnBehalf__InvalidSignature.selector); + vm.expectRevert(StakerOnBehalfUpgradeable.StakerOnBehalfUpgradeable__InvalidSignature.selector); govStaker.stakeOnBehalf(_depositAmount, _delegatee, _claimer, _depositor, _deadline, _signature); } } @@ -315,10 +325,10 @@ contract StakeMoreOnBehalf is StakerTest { _depositorPrivateKey = bound(_depositorPrivateKey, 1, 100e18); address _depositor = vm.addr(_depositorPrivateKey); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_initialDepositAmount, _depositId) = _boundMintAndStake(_depositor, _initialDepositAmount, _delegatee, _claimer); - Staker.Deposit memory _deposit = _fetchDeposit(_depositId); + StakerUpgradeable.Deposit memory _deposit = _fetchDeposit(_depositId); _stakeMoreAmount = _boundToRealisticStake(_stakeMoreAmount); _mintGovToken(_depositor, _stakeMoreAmount); @@ -379,7 +389,7 @@ contract StakeMoreOnBehalf is StakerTest { _currentNonce ); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_initialDepositAmount, _depositId) = _boundMintAndStake(_depositor, _initialDepositAmount, _delegatee, _claimer); @@ -405,7 +415,7 @@ contract StakeMoreOnBehalf is StakerTest { keccak256(abi.encodePacked("\x19\x01", EIP712_DOMAIN_SEPARATOR, _message)); bytes memory _signature = _sign(_depositorPrivateKey, _messageHash); - vm.expectRevert(StakerOnBehalf.StakerOnBehalf__InvalidSignature.selector); + vm.expectRevert(StakerOnBehalfUpgradeable.StakerOnBehalfUpgradeable__InvalidSignature.selector); vm.prank(_sender); govStaker.stakeMoreOnBehalf(_depositId, _stakeMoreAmount, _depositor, _deadline, _signature); } @@ -430,7 +440,7 @@ contract StakeMoreOnBehalf is StakerTest { _currentNonce ); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_initialDepositAmount, _depositId) = _boundMintAndStake(_depositor, _initialDepositAmount, _delegatee, _claimer); @@ -456,7 +466,7 @@ contract StakeMoreOnBehalf is StakerTest { keccak256(abi.encodePacked("\x19\x01", EIP712_DOMAIN_SEPARATOR, _message)); bytes memory _signature = _sign(_depositorPrivateKey, _messageHash); - vm.expectRevert(StakerOnBehalf.StakerOnBehalf__ExpiredDeadline.selector); + vm.expectRevert(StakerOnBehalfUpgradeable.StakerOnBehalfUpgradeable__ExpiredDeadline.selector); vm.prank(_sender); govStaker.stakeMoreOnBehalf(_depositId, _stakeMoreAmount, _depositor, _deadline, _signature); } @@ -483,13 +493,13 @@ contract StakeMoreOnBehalf is StakerTest { _currentNonce ); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_initialDepositAmount, _depositId) = _boundMintAndStake(_depositor, _initialDepositAmount, _delegatee, _claimer); vm.expectRevert( abi.encodeWithSelector( - Staker.Staker__Unauthorized.selector, bytes32("not owner"), _notDepositor + StakerUpgradeable.Staker__Unauthorized.selector, bytes32("not owner"), _notDepositor ) ); vm.prank(_sender); @@ -517,7 +527,7 @@ contract StakeMoreOnBehalf is StakerTest { _currentNonce ); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_initialDepositAmount, _depositId) = _boundMintAndStake(_depositor, _initialDepositAmount, _delegatee, _claimer); @@ -554,7 +564,7 @@ contract StakeMoreOnBehalf is StakerTest { bytes memory _signature = _sign(_depositorPrivateKey, _messageHash); if (_randomSeed % 4 == 3) _signature = _modifySignature(_signature, _randomSeed); - vm.expectRevert(StakerOnBehalf.StakerOnBehalf__InvalidSignature.selector); + vm.expectRevert(StakerOnBehalfUpgradeable.StakerOnBehalfUpgradeable__InvalidSignature.selector); vm.prank(_sender); govStaker.stakeMoreOnBehalf(_depositId, _stakeMoreAmount, _depositor, _deadline, _signature); } @@ -581,9 +591,9 @@ contract AlterDelegateeOnBehalf is StakerTest { _depositorPrivateKey = bound(_depositorPrivateKey, 1, 100e18); address _depositor = vm.addr(_depositorPrivateKey); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_amount, _depositId) = _boundMintAndStake(_depositor, _amount, _delegatee, _claimer); - Staker.Deposit memory _deposit = _fetchDeposit(_depositId); + StakerUpgradeable.Deposit memory _deposit = _fetchDeposit(_depositId); stdstore.target(address(govStaker)).sig("nonces(address)").with_key(_depositor).checked_write( _currentNonce @@ -637,7 +647,7 @@ contract AlterDelegateeOnBehalf is StakerTest { _currentNonce ); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_amount, _depositId) = _boundMintAndStake(_depositor, _amount, _delegatee, _claimer); bytes32 _message = keccak256( @@ -650,7 +660,7 @@ contract AlterDelegateeOnBehalf is StakerTest { keccak256(abi.encodePacked("\x19\x01", EIP712_DOMAIN_SEPARATOR, _message)); bytes memory _signature = _sign(_depositorPrivateKey, _messageHash); - vm.expectRevert(StakerOnBehalf.StakerOnBehalf__InvalidSignature.selector); + vm.expectRevert(StakerOnBehalfUpgradeable.StakerOnBehalfUpgradeable__InvalidSignature.selector); vm.prank(_sender); govStaker.alterDelegateeOnBehalf(_depositId, _newDelegatee, _depositor, _deadline, _signature); } @@ -678,7 +688,7 @@ contract AlterDelegateeOnBehalf is StakerTest { _currentNonce ); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_amount, _depositId) = _boundMintAndStake(_depositor, _amount, _delegatee, _claimer); bytes32 _message = keccak256( @@ -696,7 +706,7 @@ contract AlterDelegateeOnBehalf is StakerTest { keccak256(abi.encodePacked("\x19\x01", EIP712_DOMAIN_SEPARATOR, _message)); bytes memory _signature = _sign(_depositorPrivateKey, _messageHash); - vm.expectRevert(StakerOnBehalf.StakerOnBehalf__ExpiredDeadline.selector); + vm.expectRevert(StakerOnBehalfUpgradeable.StakerOnBehalfUpgradeable__ExpiredDeadline.selector); vm.prank(_sender); govStaker.alterDelegateeOnBehalf(_depositId, _newDelegatee, _depositor, _deadline, _signature); } @@ -720,12 +730,12 @@ contract AlterDelegateeOnBehalf is StakerTest { _amount = _boundMintAmount(_amount); _mintGovToken(_depositor, _amount); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_amount, _depositId) = _boundMintAndStake(_depositor, _amount, _delegatee, _claimer); vm.expectRevert( abi.encodeWithSelector( - Staker.Staker__Unauthorized.selector, bytes32("not owner"), _notDepositor + StakerUpgradeable.Staker__Unauthorized.selector, bytes32("not owner"), _notDepositor ) ); vm.prank(_sender); @@ -755,7 +765,7 @@ contract AlterDelegateeOnBehalf is StakerTest { _currentNonce ); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_amount, _depositId) = _boundMintAndStake(_depositor, _amount, _delegatee, _claimer); bytes32 _message = keccak256( @@ -784,7 +794,7 @@ contract AlterDelegateeOnBehalf is StakerTest { bytes memory _signature = _sign(_depositorPrivateKey, _messageHash); if (_randomSeed % 4 == 3) _signature = _modifySignature(_signature, _randomSeed); - vm.expectRevert(StakerOnBehalf.StakerOnBehalf__InvalidSignature.selector); + vm.expectRevert(StakerOnBehalfUpgradeable.StakerOnBehalfUpgradeable__InvalidSignature.selector); vm.prank(_sender); govStaker.alterDelegateeOnBehalf(_depositId, _newDelegatee, _depositor, _deadline, _signature); } @@ -811,9 +821,9 @@ contract AlterClaimerOnBehalf is StakerTest { _depositorPrivateKey = bound(_depositorPrivateKey, 1, 100e18); address _depositor = vm.addr(_depositorPrivateKey); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_amount, _depositId) = _boundMintAndStake(_depositor, _amount, _delegatee, _claimer); - Staker.Deposit memory _deposit = _fetchDeposit(_depositId); + StakerUpgradeable.Deposit memory _deposit = _fetchDeposit(_depositId); stdstore.target(address(govStaker)).sig("nonces(address)").with_key(_depositor).checked_write( _currentNonce @@ -867,7 +877,7 @@ contract AlterClaimerOnBehalf is StakerTest { _currentNonce ); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_amount, _depositId) = _boundMintAndStake(_depositor, _amount, _delegatee, _claimer); bytes32 _message = keccak256( @@ -885,7 +895,7 @@ contract AlterClaimerOnBehalf is StakerTest { keccak256(abi.encodePacked("\x19\x01", EIP712_DOMAIN_SEPARATOR, _message)); bytes memory _signature = _sign(_depositorPrivateKey, _messageHash); - vm.expectRevert(StakerOnBehalf.StakerOnBehalf__InvalidSignature.selector); + vm.expectRevert(StakerOnBehalfUpgradeable.StakerOnBehalfUpgradeable__InvalidSignature.selector); vm.prank(_sender); govStaker.alterClaimerOnBehalf(_depositId, _newClaimer, _depositor, _deadline, _signature); } @@ -913,7 +923,7 @@ contract AlterClaimerOnBehalf is StakerTest { _currentNonce ); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_amount, _depositId) = _boundMintAndStake(_depositor, _amount, _delegatee, _claimer); bytes32 _message = keccak256( @@ -931,7 +941,7 @@ contract AlterClaimerOnBehalf is StakerTest { keccak256(abi.encodePacked("\x19\x01", EIP712_DOMAIN_SEPARATOR, _message)); bytes memory _signature = _sign(_depositorPrivateKey, _messageHash); - vm.expectRevert(StakerOnBehalf.StakerOnBehalf__ExpiredDeadline.selector); + vm.expectRevert(StakerOnBehalfUpgradeable.StakerOnBehalfUpgradeable__ExpiredDeadline.selector); vm.prank(_sender); govStaker.alterClaimerOnBehalf(_depositId, _newClaimer, _depositor, _deadline, _signature); } @@ -955,12 +965,12 @@ contract AlterClaimerOnBehalf is StakerTest { _amount = _boundMintAmount(_amount); _mintGovToken(_depositor, _amount); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_amount, _depositId) = _boundMintAndStake(_depositor, _amount, _delegatee, _claimer); vm.expectRevert( abi.encodeWithSelector( - Staker.Staker__Unauthorized.selector, bytes32("not owner"), _notDepositor + StakerUpgradeable.Staker__Unauthorized.selector, bytes32("not owner"), _notDepositor ) ); vm.prank(_sender); @@ -988,7 +998,7 @@ contract AlterClaimerOnBehalf is StakerTest { _currentNonce ); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_amount, _depositId) = _boundMintAndStake(_depositor, _amount, _delegatee, _claimer); bytes32 _message = keccak256( @@ -1017,7 +1027,7 @@ contract AlterClaimerOnBehalf is StakerTest { bytes memory _signature = _sign(_depositorPrivateKey, _messageHash); if (_randomSeed % 4 == 3) _signature = _modifySignature(_signature, _randomSeed); - vm.expectRevert(StakerOnBehalf.StakerOnBehalf__InvalidSignature.selector); + vm.expectRevert(StakerOnBehalfUpgradeable.StakerOnBehalfUpgradeable__InvalidSignature.selector); vm.prank(_sender); govStaker.alterClaimerOnBehalf(_depositId, _newClaimer, _depositor, _deadline, _signature); } @@ -1041,10 +1051,10 @@ contract WithdrawOnBehalf is StakerTest { _depositorPrivateKey = bound(_depositorPrivateKey, 1, 100e18); address _depositor = vm.addr(_depositorPrivateKey); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee, _claimer); - Staker.Deposit memory _deposit = _fetchDeposit(_depositId); + StakerUpgradeable.Deposit memory _deposit = _fetchDeposit(_depositId); _withdrawAmount = bound(_withdrawAmount, 0, _depositAmount); stdstore.target(address(govStaker)).sig("nonces(address)").with_key(_depositor).checked_write( @@ -1096,7 +1106,7 @@ contract WithdrawOnBehalf is StakerTest { _currentNonce ); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee, _claimer); @@ -1115,7 +1125,7 @@ contract WithdrawOnBehalf is StakerTest { keccak256(abi.encodePacked("\x19\x01", EIP712_DOMAIN_SEPARATOR, _message)); bytes memory _signature = _sign(_depositorPrivateKey, _messageHash); - vm.expectRevert(StakerOnBehalf.StakerOnBehalf__InvalidSignature.selector); + vm.expectRevert(StakerOnBehalfUpgradeable.StakerOnBehalfUpgradeable__InvalidSignature.selector); vm.prank(_sender); govStaker.withdrawOnBehalf(_depositId, _withdrawAmount, _depositor, _deadline, _signature); } @@ -1140,7 +1150,7 @@ contract WithdrawOnBehalf is StakerTest { _currentNonce ); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee, _claimer); @@ -1159,7 +1169,7 @@ contract WithdrawOnBehalf is StakerTest { keccak256(abi.encodePacked("\x19\x01", EIP712_DOMAIN_SEPARATOR, _message)); bytes memory _signature = _sign(_depositorPrivateKey, _messageHash); - vm.expectRevert(StakerOnBehalf.StakerOnBehalf__ExpiredDeadline.selector); + vm.expectRevert(StakerOnBehalfUpgradeable.StakerOnBehalfUpgradeable__ExpiredDeadline.selector); vm.prank(_sender); govStaker.withdrawOnBehalf(_depositId, _withdrawAmount, _depositor, _deadline, _signature); } @@ -1183,12 +1193,12 @@ contract WithdrawOnBehalf is StakerTest { _amount = _boundMintAmount(_amount); _mintGovToken(_depositor, _amount); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_amount, _depositId) = _boundMintAndStake(_depositor, _amount, _delegatee, _claimer); vm.expectRevert( abi.encodeWithSelector( - Staker.Staker__Unauthorized.selector, bytes32("not owner"), _notDepositor + StakerUpgradeable.Staker__Unauthorized.selector, bytes32("not owner"), _notDepositor ) ); vm.prank(_sender); @@ -1216,7 +1226,7 @@ contract WithdrawOnBehalf is StakerTest { _currentNonce ); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee, _claimer); @@ -1246,7 +1256,7 @@ contract WithdrawOnBehalf is StakerTest { bytes memory _signature = _sign(_depositorPrivateKey, _messageHash); if (_randomSeed % 4 == 3) _signature = _modifySignature(_signature, _randomSeed); - vm.expectRevert(StakerOnBehalf.StakerOnBehalf__InvalidSignature.selector); + vm.expectRevert(StakerOnBehalfUpgradeable.StakerOnBehalfUpgradeable__InvalidSignature.selector); vm.prank(_sender); govStaker.withdrawOnBehalf(_depositId, _withdrawAmount, _depositor, _deadline, _signature); } @@ -1269,7 +1279,7 @@ contract ClaimRewardOnBehalf is StakerRewardsTest { _claimerPrivateKey = bound(_claimerPrivateKey, 1, 100e18); address _claimer = vm.addr(_claimerPrivateKey); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _rewardAmount) = _boundToRealisticStakeAndReward(_depositAmount, _rewardAmount); _durationPercent = bound(_durationPercent, 0, 100); @@ -1320,7 +1330,7 @@ contract ClaimRewardOnBehalf is StakerRewardsTest { _depositorPrivateKey = bound(_depositorPrivateKey, 1, 100e18); address _depositor = vm.addr(_depositorPrivateKey); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _rewardAmount) = _boundToRealisticStakeAndReward(_depositAmount, _rewardAmount); _durationPercent = bound(_durationPercent, 0, 100); @@ -1372,7 +1382,7 @@ contract ClaimRewardOnBehalf is StakerRewardsTest { _claimerPrivateKey = bound(_claimerPrivateKey, 1, 100e18); address _claimer = vm.addr(_claimerPrivateKey); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _rewardAmount) = _boundToRealisticStakeAndReward(_depositAmount, _rewardAmount); _durationPercent = bound(_durationPercent, 0, 100); @@ -1424,7 +1434,7 @@ contract ClaimRewardOnBehalf is StakerRewardsTest { _claimerPrivateKey = bound(_claimerPrivateKey, 1, 100e18); address _claimer = vm.addr(_claimerPrivateKey); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _rewardAmount) = _boundToRealisticStakeAndReward(_depositAmount, _rewardAmount); _durationPercent = bound(_durationPercent, 0, 100); @@ -1448,7 +1458,7 @@ contract ClaimRewardOnBehalf is StakerRewardsTest { keccak256(abi.encodePacked("\x19\x01", EIP712_DOMAIN_SEPARATOR, _message)); bytes memory _signature = _sign(_claimerPrivateKey, _messageHash); - vm.expectRevert(StakerOnBehalf.StakerOnBehalf__InvalidSignature.selector); + vm.expectRevert(StakerOnBehalfUpgradeable.StakerOnBehalfUpgradeable__InvalidSignature.selector); vm.prank(_sender); govStaker.claimRewardOnBehalf(_depositId, _deadline, _signature); } @@ -1470,7 +1480,7 @@ contract ClaimRewardOnBehalf is StakerRewardsTest { _depositorPrivateKey = bound(_depositorPrivateKey, 1, 100e18); address _depositor = vm.addr(_depositorPrivateKey); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _rewardAmount) = _boundToRealisticStakeAndReward(_depositAmount, _rewardAmount); _durationPercent = bound(_durationPercent, 0, 100); @@ -1495,7 +1505,7 @@ contract ClaimRewardOnBehalf is StakerRewardsTest { keccak256(abi.encodePacked("\x19\x01", EIP712_DOMAIN_SEPARATOR, _message)); bytes memory _signature = _sign(_depositorPrivateKey, _messageHash); - vm.expectRevert(StakerOnBehalf.StakerOnBehalf__InvalidSignature.selector); + vm.expectRevert(StakerOnBehalfUpgradeable.StakerOnBehalfUpgradeable__InvalidSignature.selector); vm.prank(_sender); govStaker.claimRewardOnBehalf(_depositId, _deadline, _signature); } @@ -1515,7 +1525,7 @@ contract ClaimRewardOnBehalf is StakerRewardsTest { _claimerPrivateKey = bound(_claimerPrivateKey, 1, 100e18); address _claimer = vm.addr(_claimerPrivateKey); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _rewardAmount) = _boundToRealisticStakeAndReward(_depositAmount, _rewardAmount); _durationPercent = bound(_durationPercent, 0, 100); @@ -1539,7 +1549,7 @@ contract ClaimRewardOnBehalf is StakerRewardsTest { keccak256(abi.encodePacked("\x19\x01", EIP712_DOMAIN_SEPARATOR, _message)); bytes memory _signature = _sign(_claimerPrivateKey, _messageHash); - vm.expectRevert(StakerOnBehalf.StakerOnBehalf__ExpiredDeadline.selector); + vm.expectRevert(StakerOnBehalfUpgradeable.StakerOnBehalfUpgradeable__ExpiredDeadline.selector); vm.prank(_sender); govStaker.claimRewardOnBehalf(_depositId, _deadline, _signature); } @@ -1564,7 +1574,7 @@ contract ClaimRewardOnBehalf is StakerRewardsTest { _currentNonce ); - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; (_depositAmount, _depositId) = _boundMintAndStake(_depositor, _depositAmount, _delegatee, _claimer); @@ -1587,7 +1597,7 @@ contract ClaimRewardOnBehalf is StakerRewardsTest { bytes memory _signature = _sign(_claimerPrivateKey, _messageHash); if (_randomSeed % 4 == 3) _signature = _modifySignature(_signature, _randomSeed); - vm.expectRevert(StakerOnBehalf.StakerOnBehalf__InvalidSignature.selector); + vm.expectRevert(StakerOnBehalfUpgradeable.StakerOnBehalfUpgradeable__InvalidSignature.selector); vm.prank(_sender); govStaker.claimRewardOnBehalf(_depositId, _deadline, _signature); } diff --git a/test/StakerTestBase.sol b/test/StakerTestBase.sol index ff2c5ac6..e1bf5027 100644 --- a/test/StakerTestBase.sol +++ b/test/StakerTestBase.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.23; import {Vm, Test, stdStorage, StdStorage, console2, stdError} from "forge-std/Test.sol"; -import {Staker} from "../src/Staker.sol"; +import {StakerUpgradeable} from "../src/StakerUpgradeable.sol"; import {DelegationSurrogate} from "../src/DelegationSurrogate.sol"; import {ERC20VotesMock} from "./mocks/MockERC20Votes.sol"; import {ERC20Fake} from "./fakes/ERC20Fake.sol"; @@ -23,14 +23,14 @@ abstract contract StakerTestBase is Test, PercentAssertions { address admin; address rewardNotifier; - Staker baseStaker; + StakerUpgradeable baseStaker; uint256 SCALE_FACTOR; uint256 maxBumpTip = 1e18; mapping(DelegationSurrogate surrogate => bool isKnown) isKnownSurrogate; mapping(address depositor => bool isKnown) isKnownDepositor; - function _deployStaker() public virtual returns (Staker _staker); + function _deployStaker() public virtual returns (StakerUpgradeable _staker); function setUp() public virtual { // Set the block timestamp to an arbitrary value to avoid introducing assumptions into tests @@ -101,8 +101,8 @@ abstract contract StakerTestBase is Test, PercentAssertions { } function _setClaimFeeAndCollector(uint96 _amount, address _collector) internal { - Staker.ClaimFeeParameters memory _params = - Staker.ClaimFeeParameters({feeAmount: _amount, feeCollector: _collector}); + StakerUpgradeable.ClaimFeeParameters memory _params = + StakerUpgradeable.ClaimFeeParameters({feeAmount: _amount, feeCollector: _collector}); vm.prank(admin); baseStaker.setClaimFeeParameters(_params); @@ -110,7 +110,7 @@ abstract contract StakerTestBase is Test, PercentAssertions { function _stake(address _depositor, uint256 _amount, address _delegatee) internal - returns (Staker.DepositIdentifier _depositId) + returns (StakerUpgradeable.DepositIdentifier _depositId) { vm.assume(_delegatee != address(0)); @@ -125,7 +125,7 @@ abstract contract StakerTestBase is Test, PercentAssertions { function _stake(address _depositor, uint256 _amount, address _delegatee, address _claimer) internal - returns (Staker.DepositIdentifier _depositId) + returns (StakerUpgradeable.DepositIdentifier _depositId) { vm.assume(_delegatee != address(0) && _claimer != address(0)); @@ -138,21 +138,20 @@ abstract contract StakerTestBase is Test, PercentAssertions { _assumeSafeDepositorAndSurrogate(_depositor, _delegatee); } - function _fetchDeposit(Staker.DepositIdentifier _depositId) + function _fetchDeposit(StakerUpgradeable.DepositIdentifier _depositId) internal view - returns (Staker.Deposit memory) + returns (StakerUpgradeable.Deposit memory) { - ( - uint96 _balance, - address _owner, - uint96 _earningPower, - address _delegatee, - address _claimer, - uint256 _rewardPerTokenCheckpoint, - uint256 _scaledUnclaimedRewardCheckpoint - ) = baseStaker.deposits(_depositId); - return Staker.Deposit({ + StakerUpgradeable.Deposit memory _deposit = baseStaker.deposits(_depositId); + uint96 _balance = _deposit.balance; + address _owner = _deposit.owner; + uint96 _earningPower = _deposit.earningPower; + address _delegatee = _deposit.delegatee; + address _claimer = _deposit.claimer; + uint256 _rewardPerTokenCheckpoint = _deposit.rewardPerTokenCheckpoint; + uint256 _scaledUnclaimedRewardCheckpoint = _deposit.scaledUnclaimedRewardCheckpoint; + return StakerUpgradeable.Deposit({ balance: _balance, owner: _owner, delegatee: _delegatee, @@ -165,7 +164,7 @@ abstract contract StakerTestBase is Test, PercentAssertions { function _boundMintAndStake(address _depositor, uint256 _amount, address _delegatee) internal - returns (uint256 _boundedAmount, Staker.DepositIdentifier _depositId) + returns (uint256 _boundedAmount, StakerUpgradeable.DepositIdentifier _depositId) { _boundedAmount = _boundMintAmount(_amount); _mintGovToken(_depositor, _boundedAmount); @@ -177,7 +176,7 @@ abstract contract StakerTestBase is Test, PercentAssertions { uint256 _amount, address _delegatee, address _claimer - ) internal returns (uint256 _boundedAmount, Staker.DepositIdentifier _depositId) { + ) internal returns (uint256 _boundedAmount, StakerUpgradeable.DepositIdentifier _depositId) { _boundedAmount = _boundMintAmount(_amount); _mintGovToken(_depositor, _boundedAmount); _depositId = _stake(_depositor, _boundedAmount, _delegatee, _claimer); diff --git a/test/fakes/DeployBaseFake.sol b/test/fakes/DeployBaseFake.sol index 8a10187f..d92fddf0 100644 --- a/test/fakes/DeployBaseFake.sol +++ b/test/fakes/DeployBaseFake.sol @@ -9,10 +9,11 @@ import {DeployIdentityEarningPowerCalculator} from import {IMintable} from "../../src/interfaces/IMintable.sol"; import {IEarningPowerCalculator} from "../../src/interfaces/IEarningPowerCalculator.sol"; -import {Staker} from "../../src/Staker.sol"; +import {StakerUpgradeable} from "../../src/StakerUpgradeable.sol"; import {StakerHarness} from "../harnesses/StakerHarness.sol"; import {IERC20Staking} from "../../src/interfaces/IERC20Staking.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; contract DeployBaseFake is DeployBase, @@ -72,16 +73,25 @@ contract DeployBaseFake is internal virtual override - returns (Staker) + returns (StakerUpgradeable) { StakerConfiguration memory _config = _stakerConfiguration(_earningPowerCalculator); - return new StakerHarness( - _config.rewardToken, - IERC20Staking(address(_config.stakeToken)), - _config.earningPowerCalculator, - _config.maxBumpTip, - deployer, - name + StakerHarness implementation = new StakerHarness(); + ERC1967Proxy proxy = new ERC1967Proxy( + address(implementation), + abi.encodeCall( + StakerHarness.initialize, + ( + _config.rewardToken, + IERC20Staking(address(_config.stakeToken)), + 1e18, + deployer, + _config.maxBumpTip, + _config.earningPowerCalculator, + name + ) + ) ); + return StakerHarness(address(proxy)); } } diff --git a/test/fakes/DeployBaseInvalidStakerAdminFake.sol b/test/fakes/DeployBaseInvalidStakerAdminFake.sol index 7a9d37ff..86eaa3a3 100644 --- a/test/fakes/DeployBaseInvalidStakerAdminFake.sol +++ b/test/fakes/DeployBaseInvalidStakerAdminFake.sol @@ -9,10 +9,11 @@ import {DeployIdentityEarningPowerCalculator} from import {IMintable} from "../../src/interfaces/IMintable.sol"; import {IEarningPowerCalculator} from "../../src/interfaces/IEarningPowerCalculator.sol"; -import {Staker} from "../../src/Staker.sol"; +import {StakerUpgradeable} from "../../src/StakerUpgradeable.sol"; import {StakerHarness} from "../harnesses/StakerHarness.sol"; import {IERC20Staking} from "../../src/interfaces/IERC20Staking.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; contract DeployBaseInvalidStakerAdminFake is DeployBase, @@ -72,16 +73,25 @@ contract DeployBaseInvalidStakerAdminFake is internal virtual override - returns (Staker) + returns (StakerUpgradeable) { StakerConfiguration memory _config = _stakerConfiguration(_earningPowerCalculator); - return new StakerHarness( - _config.rewardToken, - IERC20Staking(address(_config.stakeToken)), - _config.earningPowerCalculator, - _config.maxBumpTip, - makeAddr("Anyone but the deployer"), - name + StakerHarness implementation = new StakerHarness(); + ERC1967Proxy proxy = new ERC1967Proxy( + address(implementation), + abi.encodeCall( + StakerHarness.initialize, + ( + _config.rewardToken, + IERC20Staking(address(_config.stakeToken)), + 1e18, + makeAddr("Anyone but the deployer"), + _config.maxBumpTip, + _config.earningPowerCalculator, + name + ) + ) ); + return StakerHarness(address(proxy)); } } diff --git a/test/fakes/DeployBinaryEligibilityOracleEarningPowerCalculatorFake.sol b/test/fakes/DeployBinaryEligibilityOracleEarningPowerCalculatorFake.sol index cd55cfaa..3df23882 100644 --- a/test/fakes/DeployBinaryEligibilityOracleEarningPowerCalculatorFake.sol +++ b/test/fakes/DeployBinaryEligibilityOracleEarningPowerCalculatorFake.sol @@ -8,10 +8,11 @@ import {DeployBinaryEligibilityOracleEarningPowerCalculator} from "../../src/script/calculators/DeployBinaryEligibilityOracleEarningPowerCalculator.sol"; import {IEarningPowerCalculator} from "../../src/interfaces/IEarningPowerCalculator.sol"; import {IMintable} from "../../src/interfaces/IMintable.sol"; -import {Staker} from "../../src/Staker.sol"; +import {StakerUpgradeable} from "../../src/StakerUpgradeable.sol"; import {StakerHarness} from "../harnesses/StakerHarness.sol"; import {IERC20Staking} from "../../src/interfaces/IERC20Staking.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; contract DeployBinaryEligibilityOracleEarningPowerCalculatorFake is DeployBase, @@ -93,16 +94,25 @@ contract DeployBinaryEligibilityOracleEarningPowerCalculatorFake is internal virtual override - returns (Staker) + returns (StakerUpgradeable) { StakerConfiguration memory _config = _stakerConfiguration(_earningPowerCalculator); - return new StakerHarness( - _config.rewardToken, - IERC20Staking(address(_config.stakeToken)), - _config.earningPowerCalculator, - _config.maxBumpTip, - deployer, - name + StakerHarness implementation = new StakerHarness(); + ERC1967Proxy proxy = new ERC1967Proxy( + address(implementation), + abi.encodeCall( + StakerHarness.initialize, + ( + _config.rewardToken, + IERC20Staking(address(_config.stakeToken)), + 1e18, + deployer, + _config.maxBumpTip, + _config.earningPowerCalculator, + name + ) + ) ); + return StakerHarness(address(proxy)); } } diff --git a/test/fakes/DeployMultipleRewardNotifiersFake.sol b/test/fakes/DeployMultipleRewardNotifiersFake.sol index da941e02..9d11c0f4 100644 --- a/test/fakes/DeployMultipleRewardNotifiersFake.sol +++ b/test/fakes/DeployMultipleRewardNotifiersFake.sol @@ -10,10 +10,11 @@ import {DeployIdentityEarningPowerCalculator} from "../../src/script/calculators/DeployIdentityEarningPowerCalculator.sol"; import {IMintable} from "../../src/interfaces/IMintable.sol"; import {IEarningPowerCalculator} from "../../src/interfaces/IEarningPowerCalculator.sol"; -import {Staker} from "../../src/Staker.sol"; +import {StakerUpgradeable} from "../../src/StakerUpgradeable.sol"; import {StakerHarness} from "../harnesses/StakerHarness.sol"; import {IERC20Staking} from "../../src/interfaces/IERC20Staking.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; contract DeployMultipleRewardNotifiersFake is DeployBase, @@ -84,7 +85,7 @@ contract DeployMultipleRewardNotifiersFake is }); } - function _deployRewardNotifiers(Staker _staker) + function _deployRewardNotifiers(StakerUpgradeable _staker) internal virtual override(DeployBase, DeployMintRewardNotifier, DeployTransferRewardNotifier) @@ -97,16 +98,25 @@ contract DeployMultipleRewardNotifiersFake is internal virtual override - returns (Staker) + returns (StakerUpgradeable) { StakerConfiguration memory _config = _stakerConfiguration(_earningPowerCalculator); - return new StakerHarness( - _config.rewardToken, - IERC20Staking(address(_config.stakeToken)), - _config.earningPowerCalculator, - _config.maxBumpTip, - deployer, - name + StakerHarness implementation = new StakerHarness(); + ERC1967Proxy proxy = new ERC1967Proxy( + address(implementation), + abi.encodeCall( + StakerHarness.initialize, + ( + _config.rewardToken, + IERC20Staking(address(_config.stakeToken)), + 1e18, + deployer, + _config.maxBumpTip, + _config.earningPowerCalculator, + name + ) + ) ); + return StakerHarness(address(proxy)); } } diff --git a/test/fakes/DeployTransferFromRewardNotifierFake.sol b/test/fakes/DeployTransferFromRewardNotifierFake.sol index c3bce458..814de9dc 100644 --- a/test/fakes/DeployTransferFromRewardNotifierFake.sol +++ b/test/fakes/DeployTransferFromRewardNotifierFake.sol @@ -8,10 +8,11 @@ import {DeployTransferFromRewardNotifier} from import {DeployIdentityEarningPowerCalculator} from "../../src/script/calculators/DeployIdentityEarningPowerCalculator.sol"; import {IEarningPowerCalculator} from "../../src/interfaces/IEarningPowerCalculator.sol"; -import {Staker} from "../../src/Staker.sol"; +import {StakerUpgradeable} from "../../src/StakerUpgradeable.sol"; import {StakerHarness} from "../harnesses/StakerHarness.sol"; import {IERC20Staking} from "../../src/interfaces/IERC20Staking.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; contract DeployTransferFromRewardNotifierFake is DeployBase, @@ -71,16 +72,25 @@ contract DeployTransferFromRewardNotifierFake is internal virtual override - returns (Staker) + returns (StakerUpgradeable) { StakerConfiguration memory _config = _stakerConfiguration(_earningPowerCalculator); - return new StakerHarness( - _config.rewardToken, - IERC20Staking(address(_config.stakeToken)), - _config.earningPowerCalculator, - _config.maxBumpTip, - deployer, - name + StakerHarness implementation = new StakerHarness(); + ERC1967Proxy proxy = new ERC1967Proxy( + address(implementation), + abi.encodeCall( + StakerHarness.initialize, + ( + _config.rewardToken, + IERC20Staking(address(_config.stakeToken)), + 1e18, + deployer, + _config.maxBumpTip, + _config.earningPowerCalculator, + name + ) + ) ); + return StakerHarness(address(proxy)); } } diff --git a/test/fakes/DeployTransferRewardNotifierFake.sol b/test/fakes/DeployTransferRewardNotifierFake.sol index 837d91fc..2b9fa0ea 100644 --- a/test/fakes/DeployTransferRewardNotifierFake.sol +++ b/test/fakes/DeployTransferRewardNotifierFake.sol @@ -8,10 +8,11 @@ import {DeployTransferRewardNotifier} from import {DeployIdentityEarningPowerCalculator} from "../../src/script/calculators/DeployIdentityEarningPowerCalculator.sol"; import {IEarningPowerCalculator} from "../../src/interfaces/IEarningPowerCalculator.sol"; -import {Staker} from "../../src/Staker.sol"; +import {StakerUpgradeable} from "../../src/StakerUpgradeable.sol"; import {StakerHarness} from "../harnesses/StakerHarness.sol"; import {IERC20Staking} from "../../src/interfaces/IERC20Staking.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; contract DeployTransferRewardNotifierFake is DeployBase, @@ -70,16 +71,25 @@ contract DeployTransferRewardNotifierFake is internal virtual override - returns (Staker) + returns (StakerUpgradeable) { StakerConfiguration memory _config = _stakerConfiguration(_earningPowerCalculator); - return new StakerHarness( - _config.rewardToken, - IERC20Staking(address(_config.stakeToken)), - _config.earningPowerCalculator, - _config.maxBumpTip, - deployer, - name + StakerHarness implementation = new StakerHarness(); + ERC1967Proxy proxy = new ERC1967Proxy( + address(implementation), + abi.encodeCall( + StakerHarness.initialize, + ( + _config.rewardToken, + IERC20Staking(address(_config.stakeToken)), + 1e18, + deployer, + _config.maxBumpTip, + _config.earningPowerCalculator, + name + ) + ) ); + return StakerHarness(address(proxy)); } } diff --git a/test/gas-reports/Staker.g.sol b/test/gas-reports/Staker.g.sol index d804fc93..9e6a51e0 100644 --- a/test/gas-reports/Staker.g.sol +++ b/test/gas-reports/Staker.g.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.23; import {Vm, Test, stdStorage, StdStorage, console2, stdError} from "forge-std/Test.sol"; import {GasReport} from "../lib/GasReport.sol"; -import {Staker} from "../../src/Staker.sol"; +import {StakerUpgradeable} from "../../src/StakerUpgradeable.sol"; import {StakerTest} from "../Staker.t.sol"; contract StakerGasReport is StakerTest, GasReport { @@ -25,7 +25,7 @@ contract StakerGasReport is StakerTest, GasReport { function runScenarios() public override { address _staker; address _delegatee; - Staker.DepositIdentifier _depositId; + StakerUpgradeable.DepositIdentifier _depositId; uint256 _rewardAmount; startScenario("First stake to a new delegatee"); diff --git a/test/gas-reports/gov-staker-gas-report.json b/test/gas-reports/gov-staker-gas-report.json index 0f1e3c64..178fc75a 100644 --- a/test/gas-reports/gov-staker-gas-report.json +++ b/test/gas-reports/gov-staker-gas-report.json @@ -1,70 +1,70 @@ { - "generatedAt": 1738772511, + "generatedAt": 1755001934, "reportName:": "gov-stakerGasReport", "results": [ { "scenarioName": "First stake to a new delegatee", - "gasUsed": 331255 + "gasUsed": 333651 }, { "scenarioName": "Second stake to a existing delegatee", - "gasUsed": 164973 + "gasUsed": 167260 }, { "scenarioName": "Second stake to a new delegatee", - "gasUsed": 297055 + "gasUsed": 299451 }, { "scenarioName": "Stake more after initial stake", - "gasUsed": 101818 + "gasUsed": 104135 }, { "scenarioName": "Alter delegatee with new delegatee", - "gasUsed": 218712 + "gasUsed": 221137 }, { "scenarioName": "Alter delegatee with existing delegatee", - "gasUsed": 86606 + "gasUsed": 88922 }, { "scenarioName": "Alter claimer to a new address", - "gasUsed": 69683 + "gasUsed": 69870 }, { "scenarioName": "Withdraw full stake", - "gasUsed": 110825 + "gasUsed": 113139 }, { "scenarioName": "Withdraw partial stake", - "gasUsed": 125225 + "gasUsed": 127539 }, { "scenarioName": "Claim reward when no reward", - "gasUsed": 46021 + "gasUsed": 46188 }, { "scenarioName": "Claim reward when reward", - "gasUsed": 165132 + "gasUsed": 167444 }, { "scenarioName": "Notify reward", - "gasUsed": 45750 + "gasUsed": 47950 }, { "scenarioName": "Second notify reward", - "gasUsed": 46099 + "gasUsed": 48310 }, { "scenarioName": "Bump earning power up no reward", - "gasUsed": 82880 + "gasUsed": 85461 }, { "scenarioName": "Bump earning power down with reward", - "gasUsed": 111652 + "gasUsed": 114242 }, { "scenarioName": "Bump earning power up with reward", - "gasUsed": 111652 + "gasUsed": 114242 } ] } \ No newline at end of file diff --git a/test/harnesses/StakerHarness.sol b/test/harnesses/StakerHarness.sol index 76340fd3..9d5d38a1 100644 --- a/test/harnesses/StakerHarness.sol +++ b/test/harnesses/StakerHarness.sol @@ -1,37 +1,48 @@ // SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.23; -import {Staker} from "../../src/Staker.sol"; -import {StakerPermitAndStake} from "../../src/extensions/StakerPermitAndStake.sol"; -import {StakerOnBehalf} from "../../src/extensions/StakerOnBehalf.sol"; -import {StakerDelegateSurrogateVotes} from "../../src/extensions/StakerDelegateSurrogateVotes.sol"; +import {StakerUpgradeable} from "../../src/StakerUpgradeable.sol"; +import {StakerPermitAndStakeUpgradeable} from + "../../src/extensions/StakerPermitAndStakeUpgradeable.sol"; +import {StakerOnBehalfUpgradeable} from "../../src/extensions/StakerOnBehalfUpgradeable.sol"; +import {StakerDelegateSurrogateVotesUpgradeable} from + "../../src/extensions/StakerDelegateSurrogateVotesUpgradeable.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {EIP712} from "@openzeppelin/contracts/utils/cryptography/EIP712.sol"; import {IERC20Staking} from "../../src/interfaces/IERC20Staking.sol"; +import {IERC20Permit} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol"; +import {IERC20Delegates} from "../../src/interfaces/IERC20Delegates.sol"; import {IEarningPowerCalculator} from "../../src/interfaces/IEarningPowerCalculator.sol"; import {DelegationSurrogate} from "../../src/DelegationSurrogate.sol"; contract StakerHarness is - Staker, - StakerPermitAndStake, - StakerOnBehalf, - StakerDelegateSurrogateVotes + StakerUpgradeable, + StakerPermitAndStakeUpgradeable, + StakerOnBehalfUpgradeable, + StakerDelegateSurrogateVotesUpgradeable { - constructor( - IERC20 _rewardsToken, - IERC20Staking _stakeToken, - IEarningPowerCalculator _earningPowerCalculator, - uint256 _maxBumpTip, + constructor() { + _disableInitializers(); + } + + function initialize( + IERC20 _rewardToken, + IERC20 _stakeToken, + uint256 _maxClaimFee, address _admin, + uint256 _maxBumpTip, + IEarningPowerCalculator _earningPowerCalculator, string memory _name - ) - Staker(_rewardsToken, _stakeToken, _earningPowerCalculator, _maxBumpTip, _admin) - StakerPermitAndStake(_stakeToken) - StakerDelegateSurrogateVotes(_stakeToken) - EIP712(_name, "1") - { - MAX_CLAIM_FEE = 1e18; + ) public initializer { + __StakerUpgradeable_init( + _rewardToken, _stakeToken, _maxClaimFee, _admin, _maxBumpTip, _earningPowerCalculator + ); + __StakerPermitAndStakeUpgradeable_init(IERC20Permit(address(_stakeToken))); + __StakerDelegateSurrogateVotesUpgradeable_init(IERC20Delegates(address(_stakeToken))); + __EIP712_init(_name, "1"); + __Nonces_init(); + _setMaxClaimFee(_maxClaimFee); _setClaimFeeParameters(ClaimFeeParameters({feeAmount: 0, feeCollector: address(0)})); } diff --git a/test/harnesses/StakerHarnessCapDeposits.sol b/test/harnesses/StakerHarnessCapDeposits.sol index 8531ee30..bb844949 100644 --- a/test/harnesses/StakerHarnessCapDeposits.sol +++ b/test/harnesses/StakerHarnessCapDeposits.sol @@ -1,42 +1,53 @@ // SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.23; -import {Staker} from "../../src/Staker.sol"; -import {StakerCapDeposits} from "../../src/extensions/StakerCapDeposits.sol"; +import {StakerUpgradeable} from "../../src/StakerUpgradeable.sol"; +import {StakerCapDepositsUpgradeable} from "../../src/extensions/StakerCapDepositsUpgradeable.sol"; import {StakerHarness} from "../../test/harnesses/StakerHarness.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {IERC20Staking} from "../../src/interfaces/IERC20Staking.sol"; +import {IERC20Permit} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol"; +import {IERC20Delegates} from "../../src/interfaces/IERC20Delegates.sol"; import {IEarningPowerCalculator} from "../../src/interfaces/IEarningPowerCalculator.sol"; -contract StakerHarnessCapDeposits is StakerHarness, StakerCapDeposits { - constructor( - IERC20 _rewardsToken, - IERC20Staking _stakeToken, - IEarningPowerCalculator _earningPowerCalculator, - uint256 _maxBumpTip, +contract StakerHarnessCapDeposits is StakerHarness, StakerCapDepositsUpgradeable { + function initialize( + IERC20 _rewardToken, + IERC20 _stakeToken, + uint256 _maxClaimFee, address _admin, + uint256 _maxBumpTip, + IEarningPowerCalculator _earningPowerCalculator, string memory _name, uint256 _initialStakeCap - ) - StakerHarness(_rewardsToken, _stakeToken, _earningPowerCalculator, _maxBumpTip, _admin, _name) - StakerCapDeposits(_initialStakeCap) - {} + ) public initializer { + __StakerUpgradeable_init( + _rewardToken, _stakeToken, _maxClaimFee, _admin, _maxBumpTip, _earningPowerCalculator + ); + __StakerPermitAndStakeUpgradeable_init(IERC20Permit(address(_stakeToken))); + __StakerDelegateSurrogateVotesUpgradeable_init(IERC20Delegates(address(_stakeToken))); + __EIP712_init(_name, "1"); + __StakerCapDepositsUpgradeable_init(_initialStakeCap); + __Nonces_init(); + _setMaxClaimFee(_maxClaimFee); + _setClaimFeeParameters(ClaimFeeParameters({feeAmount: 0, feeCollector: address(0)})); + } function _stake(address _depositor, uint256 _amount, address _delegatee, address _claimer) internal virtual - override(Staker, StakerCapDeposits) + override(StakerUpgradeable, StakerCapDepositsUpgradeable) returns (DepositIdentifier _depositId) { - return StakerCapDeposits._stake(_depositor, _amount, _delegatee, _claimer); + return StakerCapDepositsUpgradeable._stake(_depositor, _amount, _delegatee, _claimer); } function _stakeMore(Deposit storage deposit, DepositIdentifier _depositId, uint256 _amount) internal virtual - override(Staker, StakerCapDeposits) + override(StakerUpgradeable, StakerCapDepositsUpgradeable) { - StakerCapDeposits._stakeMore(deposit, _depositId, _amount); + StakerCapDepositsUpgradeable._stakeMore(deposit, _depositId, _amount); } } diff --git a/test/helpers/DepositIdSet.sol b/test/helpers/DepositIdSet.sol index 03a5f5f4..2eb64e1a 100644 --- a/test/helpers/DepositIdSet.sol +++ b/test/helpers/DepositIdSet.sol @@ -1,18 +1,18 @@ // SPDX-License-Identifier: AGPL-3.0-or-later pragma solidity ^0.8.23; -import {Staker} from "../../src/Staker.sol"; +import {StakerUpgradeable} from "../../src/StakerUpgradeable.sol"; struct DepositIdSet { - Staker.DepositIdentifier[] ids; - mapping(Staker.DepositIdentifier => bool) saved; + StakerUpgradeable.DepositIdentifier[] ids; + mapping(StakerUpgradeable.DepositIdentifier => bool) saved; } library LibDepositIdSet { function reduce( DepositIdSet storage s, uint256 acc, - function(uint256,Staker.DepositIdentifier) external returns (uint256) func + function(uint256,StakerUpgradeable.DepositIdentifier) external returns (uint256) func ) internal returns (uint256) { for (uint256 i; i < s.ids.length; ++i) { acc = func(acc, s.ids[i]); @@ -20,7 +20,7 @@ library LibDepositIdSet { return acc; } - function add(DepositIdSet storage s, Staker.DepositIdentifier id) internal { + function add(DepositIdSet storage s, StakerUpgradeable.DepositIdentifier id) internal { if (!s.saved[id]) { s.ids.push(id); s.saved[id] = true; diff --git a/test/helpers/Staker.handler.sol b/test/helpers/Staker.handler.sol index 054ec297..b656a79d 100644 --- a/test/helpers/Staker.handler.sol +++ b/test/helpers/Staker.handler.sol @@ -7,7 +7,7 @@ import {StdUtils} from "forge-std/StdUtils.sol"; import {console} from "forge-std/console.sol"; import {AddressSet, LibAddressSet} from "../helpers/AddressSet.sol"; import {DepositIdSet, LibDepositIdSet} from "../helpers/DepositIdSet.sol"; -import {Staker} from "../../src/Staker.sol"; +import {StakerUpgradeable} from "../../src/StakerUpgradeable.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; contract StakerHandler is CommonBase, StdCheats, StdUtils { @@ -15,7 +15,7 @@ contract StakerHandler is CommonBase, StdCheats, StdUtils { using LibDepositIdSet for DepositIdSet; // system setup - Staker public govStaker; + StakerUpgradeable public govStaker; IERC20 public stakeToken; IERC20 public rewardToken; address public admin; @@ -49,7 +49,7 @@ contract StakerHandler is CommonBase, StdCheats, StdUtils { _; } - constructor(Staker _govStaker) { + constructor(StakerUpgradeable _govStaker) { govStaker = _govStaker; stakeToken = IERC20(address(_govStaker.STAKE_TOKEN())); rewardToken = IERC20(address(_govStaker.REWARD_TOKEN())); @@ -116,7 +116,7 @@ contract StakerHandler is CommonBase, StdCheats, StdUtils { // update handler state _depositIds[_currentActor].push(ghost_depositCount); - _depositIdSet.add(Staker.DepositIdentifier.wrap(ghost_depositCount)); + _depositIdSet.add(StakerUpgradeable.DepositIdentifier.wrap(ghost_depositCount)); ghost_depositCount++; _surrogates.add(address(govStaker.surrogates(_delegatee))); ghost_stakeSum += _amount; @@ -130,9 +130,10 @@ contract StakerHandler is CommonBase, StdCheats, StdUtils { _useActor(_depositors, _actorSeed); vm.assume(_currentActor != address(0)); vm.assume(_depositIds[_currentActor].length > 0); - Staker.DepositIdentifier _depositId = - Staker.DepositIdentifier.wrap(_getActorRandDepositId(_actorDepositSeed)); - (uint256 _balance,,,,,,) = govStaker.deposits(_depositId); + StakerUpgradeable.DepositIdentifier _depositId = + StakerUpgradeable.DepositIdentifier.wrap(_getActorRandDepositId(_actorDepositSeed)); + StakerUpgradeable.Deposit memory _deposit = govStaker.deposits(_depositId); + uint256 _balance = _deposit.balance; _amount = uint256(_bound(_amount, 0, _balance)); vm.startPrank(_currentActor); stakeToken.approve(address(govStaker), _amount); @@ -149,9 +150,10 @@ contract StakerHandler is CommonBase, StdCheats, StdUtils { _useActor(_depositors, _actorSeed); vm.assume(_currentActor != address(0)); vm.assume(_depositIds[_currentActor].length > 0); - Staker.DepositIdentifier _depositId = - Staker.DepositIdentifier.wrap(_getActorRandDepositId(_actorDepositSeed)); - (uint256 _balance,,,,,,) = govStaker.deposits(_depositId); + StakerUpgradeable.DepositIdentifier _depositId = + StakerUpgradeable.DepositIdentifier.wrap(_getActorRandDepositId(_actorDepositSeed)); + StakerUpgradeable.Deposit memory _deposit = govStaker.deposits(_depositId); + uint256 _balance = _deposit.balance; _amount = uint256(_bound(_amount, 0, _balance)); vm.startPrank(_currentActor); govStaker.withdraw(_depositId, _amount); @@ -167,8 +169,8 @@ contract StakerHandler is CommonBase, StdCheats, StdUtils { _useActor(_depositors, _actorSeed); vm.assume(_currentActor != address(0)); vm.assume(_depositIds[_currentActor].length > 0); - Staker.DepositIdentifier _depositId = - Staker.DepositIdentifier.wrap(_getActorRandDepositId(_actorDepositSeed)); + StakerUpgradeable.DepositIdentifier _depositId = + StakerUpgradeable.DepositIdentifier.wrap(_getActorRandDepositId(_actorDepositSeed)); vm.startPrank(_currentActor); uint256 rewardsClaimed = govStaker.claimReward(_depositId); vm.stopPrank(); @@ -213,7 +215,7 @@ contract StakerHandler is CommonBase, StdCheats, StdUtils { function reduceDeposits( uint256 acc, - function(uint256,Staker.DepositIdentifier) external returns (uint256) func + function(uint256,StakerUpgradeable.DepositIdentifier) external returns (uint256) func ) public returns (uint256) { return _depositIdSet.reduce(acc, func); } diff --git a/test/mocks/MockStakerHarness.sol b/test/mocks/MockStakerHarness.sol index 8538218a..92fcec9e 100644 --- a/test/mocks/MockStakerHarness.sol +++ b/test/mocks/MockStakerHarness.sol @@ -1,9 +1,11 @@ // SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.23; -import {Staker} from "../../src/Staker.sol"; -import {StakerPermitAndStake} from "../../src/extensions/StakerPermitAndStake.sol"; -import {StakerDelegateSurrogateVotes} from "../../src/extensions/StakerDelegateSurrogateVotes.sol"; +import {StakerUpgradeable} from "../../src/StakerUpgradeable.sol"; +import {StakerPermitAndStakeUpgradeable} from + "../../src/extensions/StakerPermitAndStakeUpgradeable.sol"; +import {StakerDelegateSurrogateVotesUpgradeable} from + "../../src/extensions/StakerDelegateSurrogateVotesUpgradeable.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {IERC20Staking} from "../../src/interfaces/IERC20Staking.sol"; @@ -13,21 +15,30 @@ import {DelegationSurrogate} from "../../src/DelegationSurrogate.sol"; /// @dev Mock version of StakerHarness that accepts different stake tokens for each inherited /// contract, unlike StakerHarness which uses the same token. This contract is used to test reverts /// when stake tokens mismatch. -contract MockStakerHarness is Staker, StakerPermitAndStake, StakerDelegateSurrogateVotes { - constructor( +contract MockStakerHarness is + StakerUpgradeable, + StakerPermitAndStakeUpgradeable, + StakerDelegateSurrogateVotesUpgradeable +{ + constructor() { + _disableInitializers(); + } + + function initialize( IERC20 _rewardsToken, - IERC20Staking _stakerStakeToken, + IERC20Staking _stakeToken, IERC20Staking _permitAndStakeStakeToken, IERC20Staking _delegateSurrogateVotesStakeToken, IEarningPowerCalculator _earningPowerCalculator, - uint256 _maxBumpTip, - address _admin - ) - Staker(_rewardsToken, _stakerStakeToken, _earningPowerCalculator, _maxBumpTip, _admin) - StakerPermitAndStake(_permitAndStakeStakeToken) - StakerDelegateSurrogateVotes(_delegateSurrogateVotesStakeToken) - { - MAX_CLAIM_FEE = 1e18; + address _admin, + uint256 _maxBumpTip + ) public initializer { + __StakerUpgradeable_init( + _rewardsToken, _stakeToken, 1e18, _admin, _maxBumpTip, _earningPowerCalculator + ); + __StakerPermitAndStakeUpgradeable_init(_permitAndStakeStakeToken); + __StakerDelegateSurrogateVotesUpgradeable_init(_delegateSurrogateVotesStakeToken); + _setMaxClaimFee(1e18); _setClaimFeeParameters(ClaimFeeParameters({feeAmount: 0, feeCollector: address(0)})); } diff --git a/test/script/DeployBase.t.sol b/test/script/DeployBase.t.sol index 1b4bbec0..3a65487f 100644 --- a/test/script/DeployBase.t.sol +++ b/test/script/DeployBase.t.sol @@ -5,7 +5,7 @@ import {Test} from "forge-std/Test.sol"; import {IEarningPowerCalculator} from "../../src/interfaces/IEarningPowerCalculator.sol"; import {MintRewardNotifier} from "../../src/notifiers/MintRewardNotifier.sol"; import {TransferRewardNotifier} from "../../src/notifiers/TransferRewardNotifier.sol"; -import {Staker} from "../../src/Staker.sol"; +import {StakerUpgradeable} from "../../src/StakerUpgradeable.sol"; import {DeployBase} from "../../src/script/DeployBase.sol"; import {DeployBaseFake} from "../fakes/DeployBaseFake.sol"; import {DeployMultipleRewardNotifiersFake} from "../fakes/DeployMultipleRewardNotifiersFake.sol"; @@ -29,7 +29,7 @@ contract DeployBaseTest is Test { contract Run is DeployBaseTest { function test_StakingSystemDeploy() public { DeployBaseFake _deployScript = new DeployBaseFake(rewardToken, govToken); - (IEarningPowerCalculator _calculator, Staker _staker, address[] memory _notifiers) = + (IEarningPowerCalculator _calculator, StakerUpgradeable _staker, address[] memory _notifiers) = _deployScript.run(); MintRewardNotifier _mintNotifier = MintRewardNotifier(_notifiers[0]); assertEq(address(_staker), address(_mintNotifier.RECEIVER())); @@ -49,7 +49,7 @@ contract Run is DeployBaseTest { function test_StakingSystemMultipleRewardNotifiersDeploy() public { DeployMultipleRewardNotifiersFake _deployScript = new DeployMultipleRewardNotifiersFake(rewardToken, govToken); - (IEarningPowerCalculator _calculator, Staker _staker, address[] memory _notifiers) = + (IEarningPowerCalculator _calculator, StakerUpgradeable _staker, address[] memory _notifiers) = _deployScript.run(); MintRewardNotifier _mintNotifier = MintRewardNotifier(_notifiers[0]); assertEq(address(_staker), address(_mintNotifier.RECEIVER())); diff --git a/test/script/DeployBinaryEligibilityOracleEarningPowerCalculator.t.sol b/test/script/DeployBinaryEligibilityOracleEarningPowerCalculator.t.sol index 7f3668d7..7d7bfda8 100644 --- a/test/script/DeployBinaryEligibilityOracleEarningPowerCalculator.t.sol +++ b/test/script/DeployBinaryEligibilityOracleEarningPowerCalculator.t.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.23; import {Test} from "forge-std/Test.sol"; -import {Staker} from "../../src/Staker.sol"; +import {StakerUpgradeable} from "../../src/StakerUpgradeable.sol"; import {DeployBinaryEligibilityOracleEarningPowerCalculatorFake} from "../fakes/DeployBinaryEligibilityOracleEarningPowerCalculatorFake.sol"; import {IEarningPowerCalculator} from "../../src/interfaces/IEarningPowerCalculator.sol"; @@ -31,7 +31,7 @@ contract DeployBinaryEligibilityOracleEarningPowerCalculatorTest is Test { contract Run is DeployBinaryEligibilityOracleEarningPowerCalculatorTest { function test_DeployedCalculatorHasCorrectConfig() public { - (IEarningPowerCalculator _calculator, Staker _staker,) = deployScript.run(); + (IEarningPowerCalculator _calculator, StakerUpgradeable _staker,) = deployScript.run(); BinaryEligibilityOracleEarningPowerCalculator _binaryEligibilityOracleCalculator = BinaryEligibilityOracleEarningPowerCalculator(address(_calculator)); diff --git a/test/script/DeployMintRewardNotifier.sol b/test/script/DeployMintRewardNotifier.sol index 1d2f73e2..06a9181a 100644 --- a/test/script/DeployMintRewardNotifier.sol +++ b/test/script/DeployMintRewardNotifier.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.23; import {Test} from "forge-std/Test.sol"; -import {Staker} from "../../src/Staker.sol"; +import {StakerUpgradeable} from "../../src/StakerUpgradeable.sol"; import {MintRewardNotifier} from "../../src/notifiers/MintRewardNotifier.sol"; import {DeployBaseFake} from "../fakes/DeployBaseFake.sol"; import {ERC20Fake} from "../fakes/ERC20Fake.sol"; @@ -27,7 +27,7 @@ contract DeployMintRewardNotifierTest is Test { contract Run is DeployMintRewardNotifierTest { function test_DeployedNotifierHasCorrectConfig() public { - (, Staker _staker, address[] memory _notifiers) = deployScript.run(); + (, StakerUpgradeable _staker, address[] memory _notifiers) = deployScript.run(); MintRewardNotifier _transferFromNotifier = MintRewardNotifier(_notifiers[0]); assertEq(address(_staker), address(_transferFromNotifier.RECEIVER())); @@ -38,7 +38,7 @@ contract Run is DeployMintRewardNotifierTest { } function test_DeployedNotifierMatchesExpectedBytecode() public { - (, Staker _staker, address[] memory _notifiers) = deployScript.run(); + (, StakerUpgradeable _staker, address[] memory _notifiers) = deployScript.run(); address deployedNotifier = _notifiers[0]; // Encode constructor arguments with the same value as Fake diff --git a/test/script/DeployTransferFromRewardNotifier.t.sol b/test/script/DeployTransferFromRewardNotifier.t.sol index 59c25f52..7d0fd3f5 100644 --- a/test/script/DeployTransferFromRewardNotifier.t.sol +++ b/test/script/DeployTransferFromRewardNotifier.t.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.23; import {Test} from "forge-std/Test.sol"; -import {Staker} from "../../src/Staker.sol"; +import {StakerUpgradeable} from "../../src/StakerUpgradeable.sol"; import {TransferFromRewardNotifier} from "../../src/notifiers/TransferFromRewardNotifier.sol"; import {DeployTransferFromRewardNotifierFake} from "../fakes/DeployTransferFromRewardNotifierFake.sol"; @@ -27,7 +27,7 @@ contract DeployTransferFromRewardNotifierTest is Test { contract Run is DeployTransferFromRewardNotifierTest { function test_DeployedNotifierHasCorrectConfig() public { - (, Staker _staker, address[] memory _notifiers) = deployScript.run(); + (, StakerUpgradeable _staker, address[] memory _notifiers) = deployScript.run(); TransferFromRewardNotifier _transferFromNotifier = TransferFromRewardNotifier(_notifiers[0]); assertEq(address(_staker), address(_transferFromNotifier.RECEIVER())); @@ -40,7 +40,7 @@ contract Run is DeployTransferFromRewardNotifierTest { } function test_DeployedNotifierMatchesExpectedBytecode() public { - (, Staker _staker, address[] memory _notifiers) = deployScript.run(); + (, StakerUpgradeable _staker, address[] memory _notifiers) = deployScript.run(); address deployedNotifier = _notifiers[0]; // Encode constructor arguments with the same value as Fake diff --git a/test/script/DeployTransferRewardNotifier.t.sol b/test/script/DeployTransferRewardNotifier.t.sol index afeab50c..21750da7 100644 --- a/test/script/DeployTransferRewardNotifier.t.sol +++ b/test/script/DeployTransferRewardNotifier.t.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.23; import {Test} from "forge-std/Test.sol"; -import {Staker} from "../../src/Staker.sol"; +import {StakerUpgradeable} from "../../src/StakerUpgradeable.sol"; import {TransferRewardNotifier} from "../../src/notifiers/TransferRewardNotifier.sol"; import {DeployTransferRewardNotifierFake} from "../fakes/DeployTransferRewardNotifierFake.sol"; import {ERC20Fake} from "../fakes/ERC20Fake.sol"; @@ -26,7 +26,7 @@ contract DeployTransferRewardNotifierTest is Test { contract Run is DeployTransferRewardNotifierTest { function test_DeployedNotifierHasCorrectConfig() public { - (, Staker _staker, address[] memory _notifiers) = deployScript.run(); + (, StakerUpgradeable _staker, address[] memory _notifiers) = deployScript.run(); TransferRewardNotifier _transferNotifier = TransferRewardNotifier(_notifiers[0]); assertEq(address(_staker), address(_transferNotifier.RECEIVER())); @@ -36,7 +36,7 @@ contract Run is DeployTransferRewardNotifierTest { } function test_DeployedNotifierMatchesExpectedBytecode() public { - (, Staker _staker, address[] memory _notifiers) = deployScript.run(); + (, StakerUpgradeable _staker, address[] memory _notifiers) = deployScript.run(); address deployedNotifier = _notifiers[0]; // Encode constructor arguments with the same value as Fake