@@ -91,7 +91,7 @@ contract ProtocolStaking is AccessControlDefaultAdminRulesUpgradeable, ERC20Vote
9191 address manager ,
9292 uint48 initialUnstakeCooldownPeriod ,
9393 uint256 initialRewardRate
94- ) public initializer {
94+ ) public virtual initializer {
9595 __AccessControlDefaultAdminRules_init (0 , governor);
9696 _grantRole (MANAGER_ROLE, manager);
9797 _setRoleAdmin (ELIGIBLE_ACCOUNT_ROLE, MANAGER_ROLE);
@@ -106,7 +106,7 @@ contract ProtocolStaking is AccessControlDefaultAdminRulesUpgradeable, ERC20Vote
106106 * @dev Stake `amount` tokens from `msg.sender`.
107107 * @param amount The amount of tokens to stake.
108108 */
109- function stake (uint256 amount ) public {
109+ function stake (uint256 amount ) public virtual {
110110 _mint (msg .sender , amount);
111111 IERC20 (stakingToken ()).safeTransferFrom (msg .sender , address (this ), amount);
112112
@@ -124,7 +124,7 @@ contract ProtocolStaking is AccessControlDefaultAdminRulesUpgradeable, ERC20Vote
124124 * @param amount The amount of tokens to unstake.
125125 * @return releaseTime The timestamp when the unstaked tokens can be released.
126126 */
127- function unstake (uint256 amount ) public returns (uint48 ) {
127+ function unstake (uint256 amount ) public virtual returns (uint48 ) {
128128 _burn (msg .sender , amount);
129129
130130 ProtocolStakingStorage storage $ = _getProtocolStakingStorage ();
@@ -157,7 +157,7 @@ contract ProtocolStaking is AccessControlDefaultAdminRulesUpgradeable, ERC20Vote
157157 * @dev Claim staking rewards for `account`. Can be called by anyone.
158158 * @param account The account to claim rewards for.
159159 */
160- function claimRewards (address account ) public {
160+ function claimRewards (address account ) public virtual {
161161 uint256 rewards = earned (account);
162162 if (rewards > 0 ) {
163163 _getProtocolStakingStorage ()._paid[account] += SafeCast.toInt256 (rewards);
@@ -171,7 +171,7 @@ contract ProtocolStaking is AccessControlDefaultAdminRulesUpgradeable, ERC20Vote
171171 * @dev Sets the reward rate in tokens per second. Only callable by `MANAGER_ROLE` role.
172172 * @param rewardRate_ The new reward rate in tokens per second.
173173 */
174- function setRewardRate (uint256 rewardRate_ ) public onlyRole (MANAGER_ROLE) {
174+ function setRewardRate (uint256 rewardRate_ ) public virtual onlyRole (MANAGER_ROLE) {
175175 _setRewardRate (rewardRate_);
176176 }
177177
@@ -181,7 +181,7 @@ contract ProtocolStaking is AccessControlDefaultAdminRulesUpgradeable, ERC20Vote
181181 * `ELIGIBLE_ACCOUNT_ROLE`. By default this is `MANAGER_ROLE`.
182182 * @param account The account to grant the `ELIGIBLE_ACCOUNT_ROLE` role to.
183183 */
184- function addEligibleAccount (address account ) public {
184+ function addEligibleAccount (address account ) public virtual {
185185 grantRole (ELIGIBLE_ACCOUNT_ROLE, account);
186186 }
187187
@@ -191,7 +191,7 @@ contract ProtocolStaking is AccessControlDefaultAdminRulesUpgradeable, ERC20Vote
191191 * `ELIGIBLE_ACCOUNT_ROLE`. By default this is `MANAGER_ROLE`.
192192 * @param account The account to revoke the `ELIGIBLE_ACCOUNT_ROLE` role from.
193193 */
194- function removeEligibleAccount (address account ) public {
194+ function removeEligibleAccount (address account ) public virtual {
195195 revokeRole (ELIGIBLE_ACCOUNT_ROLE, account);
196196 }
197197
@@ -200,7 +200,7 @@ contract ProtocolStaking is AccessControlDefaultAdminRulesUpgradeable, ERC20Vote
200200 * by `MANAGER_ROLE` role. See {unstake} for important notes regarding the cooldown period.
201201 * @param unstakeCooldownPeriod_ The new unstake cooldown period.
202202 */
203- function setUnstakeCooldownPeriod (uint48 unstakeCooldownPeriod_ ) public onlyRole (MANAGER_ROLE) {
203+ function setUnstakeCooldownPeriod (uint48 unstakeCooldownPeriod_ ) public virtual onlyRole (MANAGER_ROLE) {
204204 _setUnstakeCooldownPeriod (unstakeCooldownPeriod_);
205205 }
206206
@@ -210,7 +210,7 @@ contract ProtocolStaking is AccessControlDefaultAdminRulesUpgradeable, ERC20Vote
210210 * @param recipient The recipient that will receive rewards on behalf of `msg.sender` for all future {claimRewards} calls.
211211 * A value of `address(0)` indicates that rewards should be sent to `msg.sender`.
212212 */
213- function setRewardsRecipient (address recipient ) public {
213+ function setRewardsRecipient (address recipient ) public virtual {
214214 _getProtocolStakingStorage ()._rewardsRecipient[msg .sender ] = recipient;
215215
216216 emit RewardsRecipientSet (msg .sender , recipient);
@@ -221,7 +221,7 @@ contract ProtocolStaking is AccessControlDefaultAdminRulesUpgradeable, ERC20Vote
221221 * @param account The account to check rewards for.
222222 * @return The earned amount.
223223 */
224- function earned (address account ) public view returns (uint256 ) {
224+ function earned (address account ) public view virtual returns (uint256 ) {
225225 ProtocolStakingStorage storage $ = _getProtocolStakingStorage ();
226226 uint256 stakedWeight = isEligibleAccount (account) ? weight (balanceOf (account)) : 0 ;
227227 // if stakedWeight == 0, there is a risk of totalStakedWeight == 0. To avoid div by 0 just return 0
@@ -231,7 +231,7 @@ contract ProtocolStaking is AccessControlDefaultAdminRulesUpgradeable, ERC20Vote
231231 }
232232
233233 /// @dev Returns the staking token which is used for staking and rewards.
234- function stakingToken () public view returns (address ) {
234+ function stakingToken () public view virtual returns (address ) {
235235 return _getProtocolStakingStorage ()._stakingToken;
236236 }
237237
@@ -240,17 +240,17 @@ contract ProtocolStaking is AccessControlDefaultAdminRulesUpgradeable, ERC20Vote
240240 * @param amount The amount being weighted.
241241 * @return The staking weight.
242242 */
243- function weight (uint256 amount ) public pure returns (uint256 ) {
243+ function weight (uint256 amount ) public pure virtual returns (uint256 ) {
244244 return Math.sqrt (amount);
245245 }
246246
247247 /// @dev Returns the current total staked weight.
248- function totalStakedWeight () public view returns (uint256 ) {
248+ function totalStakedWeight () public view virtual returns (uint256 ) {
249249 return _getProtocolStakingStorage ()._totalEligibleStakedWeight;
250250 }
251251
252252 /// @dev Returns the current unstake cooldown period in seconds.
253- function unstakeCooldownPeriod () public view returns (uint256 ) {
253+ function unstakeCooldownPeriod () public view virtual returns (uint256 ) {
254254 return _getProtocolStakingStorage ()._unstakeCooldownPeriod;
255255 }
256256
@@ -269,7 +269,7 @@ contract ProtocolStaking is AccessControlDefaultAdminRulesUpgradeable, ERC20Vote
269269 * @dev Gets the current protocol reward rate in tokens distributed per second.
270270 * @return The reward rate.
271271 */
272- function rewardRate () public view returns (uint256 ) {
272+ function rewardRate () public view virtual returns (uint256 ) {
273273 return _getProtocolStakingStorage ()._rewardRate;
274274 }
275275
@@ -278,7 +278,7 @@ contract ProtocolStaking is AccessControlDefaultAdminRulesUpgradeable, ERC20Vote
278278 * @param account The account that earned rewards.
279279 * @return The rewards recipient.
280280 */
281- function rewardsRecipient (address account ) public view returns (address ) {
281+ function rewardsRecipient (address account ) public view virtual returns (address ) {
282282 address storedRewardsRecipient = _getProtocolStakingStorage ()._rewardsRecipient[account];
283283 return storedRewardsRecipient == address (0 ) ? account : storedRewardsRecipient;
284284 }
@@ -288,11 +288,11 @@ contract ProtocolStaking is AccessControlDefaultAdminRulesUpgradeable, ERC20Vote
288288 * @param account The account being checked for eligibility.
289289 * @return True if eligible.
290290 */
291- function isEligibleAccount (address account ) public view returns (bool ) {
291+ function isEligibleAccount (address account ) public view virtual returns (bool ) {
292292 return hasRole (ELIGIBLE_ACCOUNT_ROLE, account);
293293 }
294294
295- function _grantRole (bytes32 role , address account ) internal override returns (bool ) {
295+ function _grantRole (bytes32 role , address account ) internal virtual override returns (bool ) {
296296 bool success = super ._grantRole (role, account);
297297 if (role == ELIGIBLE_ACCOUNT_ROLE && success) {
298298 require (account != address (0 ), InvalidEligibleAccount (account));
@@ -301,15 +301,15 @@ contract ProtocolStaking is AccessControlDefaultAdminRulesUpgradeable, ERC20Vote
301301 return success;
302302 }
303303
304- function _revokeRole (bytes32 role , address account ) internal override returns (bool ) {
304+ function _revokeRole (bytes32 role , address account ) internal virtual override returns (bool ) {
305305 bool success = super ._revokeRole (role, account);
306306 if (role == ELIGIBLE_ACCOUNT_ROLE && success) {
307307 _updateRewards (account, weight (balanceOf (account)), 0 );
308308 }
309309 return success;
310310 }
311311
312- function _setUnstakeCooldownPeriod (uint48 unstakeCooldownPeriod_ ) internal {
312+ function _setUnstakeCooldownPeriod (uint48 unstakeCooldownPeriod_ ) internal virtual {
313313 require (unstakeCooldownPeriod_ != 0 && unstakeCooldownPeriod_ <= 365 days, InvalidUnstakeCooldownPeriod ());
314314 _getProtocolStakingStorage ()._unstakeCooldownPeriod = unstakeCooldownPeriod_;
315315
@@ -320,7 +320,7 @@ contract ProtocolStaking is AccessControlDefaultAdminRulesUpgradeable, ERC20Vote
320320 * @dev Sets the reward rate in tokens per second.
321321 * @param rewardRate_ The new reward rate in tokens per second.
322322 */
323- function _setRewardRate (uint256 rewardRate_ ) internal {
323+ function _setRewardRate (uint256 rewardRate_ ) internal virtual {
324324 ProtocolStakingStorage storage $ = _getProtocolStakingStorage ();
325325 $._lastUpdateReward = _historicalReward ();
326326 $._lastUpdateTimestamp = Time.timestamp ();
@@ -329,7 +329,7 @@ contract ProtocolStaking is AccessControlDefaultAdminRulesUpgradeable, ERC20Vote
329329 emit RewardRateSet (rewardRate_);
330330 }
331331
332- function _updateRewards (address user , uint256 weightBefore , uint256 weightAfter ) internal {
332+ function _updateRewards (address user , uint256 weightBefore , uint256 weightAfter ) internal virtual {
333333 ProtocolStakingStorage storage $ = _getProtocolStakingStorage ();
334334 uint256 oldTotalWeight = $._totalEligibleStakedWeight;
335335 $._totalEligibleStakedWeight = oldTotalWeight - weightBefore + weightAfter;
@@ -351,7 +351,7 @@ contract ProtocolStaking is AccessControlDefaultAdminRulesUpgradeable, ERC20Vote
351351 }
352352 }
353353
354- function _update (address from , address to , uint256 value ) internal override {
354+ function _update (address from , address to , uint256 value ) internal virtual override {
355355 // Disable Transfers
356356 require (from == address (0 ) || to == address (0 ), TransferDisabled ());
357357 if (isEligibleAccount (from)) {
@@ -367,21 +367,21 @@ contract ProtocolStaking is AccessControlDefaultAdminRulesUpgradeable, ERC20Vote
367367 super ._update (from, to, value);
368368 }
369369
370- function _authorizeUpgrade (address newImplementation ) internal override onlyRole (DEFAULT_ADMIN_ROLE) {}
370+ function _authorizeUpgrade (address newImplementation ) internal virtual override onlyRole (DEFAULT_ADMIN_ROLE) {}
371371
372- function _historicalReward () internal view returns (uint256 ) {
372+ function _historicalReward () internal view virtual returns (uint256 ) {
373373 ProtocolStakingStorage storage $ = _getProtocolStakingStorage ();
374374 return $._lastUpdateReward + (Time.timestamp () - $._lastUpdateTimestamp) * $._rewardRate;
375375 }
376376
377- function _allocation (uint256 share , uint256 total ) private view returns (uint256 ) {
377+ function _allocation (uint256 share , uint256 total ) internal view virtual returns (uint256 ) {
378378 return
379379 SafeCast
380380 .toUint256 (SafeCast.toInt256 (_historicalReward ()) + _getProtocolStakingStorage ()._totalVirtualPaid)
381381 .mulDiv (share, total);
382382 }
383383
384- function _getProtocolStakingStorage () private pure returns (ProtocolStakingStorage storage $) {
384+ function _getProtocolStakingStorage () internal pure returns (ProtocolStakingStorage storage $) {
385385 assembly {
386386 $.slot := PROTOCOL_STAKING_STORAGE_LOCATION
387387 }
0 commit comments