From 666751a7d2e2589b4b801d05b336abe017769175 Mon Sep 17 00:00:00 2001 From: SilentHex Date: Wed, 31 Jul 2024 17:01:39 +0530 Subject: [PATCH] fix: omnichain-staking-contract --- contracts/interfaces/IOmnichainStaking.sol | 7 ++-- contracts/interfaces/IVotingPowerCombined.sol | 6 +++ .../locker/staking/OmnichainStakingBase.sol | 42 +++++-------------- contracts/voter/PoolVoter.sol | 4 +- 4 files changed, 24 insertions(+), 35 deletions(-) create mode 100644 contracts/interfaces/IVotingPowerCombined.sol diff --git a/contracts/interfaces/IOmnichainStaking.sol b/contracts/interfaces/IOmnichainStaking.sol index 038ad26..9b9ed4f 100644 --- a/contracts/interfaces/IOmnichainStaking.sol +++ b/contracts/interfaces/IOmnichainStaking.sol @@ -13,8 +13,6 @@ pragma solidity ^0.8.20; // Twitter: https://twitter.com/zerolendxyz import {IVotes} from "@openzeppelin/contracts/governance/utils/IVotes.sol"; -import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; - import {ILocker} from "./ILocker.sol"; interface IOmnichainStaking is IVotes { @@ -50,5 +48,8 @@ interface IOmnichainStaking is IVotes { event RewardsDurationUpdated(uint256 newDuration); event TokenLockerUpdated(address previousLocker, address _tokenLocker); event RewardsTokenUpdated(address previousToken, address _zeroToken); - event PoolVoterUpdated(address previousVoter, address _poolVoter); + event VotingPowerCombinedUpdated( + address previousVotingPowerCombined, + address _votingPowerCombined + ); } diff --git a/contracts/interfaces/IVotingPowerCombined.sol b/contracts/interfaces/IVotingPowerCombined.sol new file mode 100644 index 0000000..c3ce468 --- /dev/null +++ b/contracts/interfaces/IVotingPowerCombined.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.11; + +interface IVotingPowerCombined { + function reset(address _who) external; +} diff --git a/contracts/locker/staking/OmnichainStakingBase.sol b/contracts/locker/staking/OmnichainStakingBase.sol index 57bc3a4..2adfb38 100644 --- a/contracts/locker/staking/OmnichainStakingBase.sol +++ b/contracts/locker/staking/OmnichainStakingBase.sol @@ -15,10 +15,8 @@ pragma solidity ^0.8.20; import {ERC20VotesUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20VotesUpgradeable.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {ILocker} from "../../interfaces/ILocker.sol"; -import {ILPOracle} from "../../interfaces/ILPOracle.sol"; import {IOmnichainStaking} from "../../interfaces/IOmnichainStaking.sol"; -import {IPoolVoter} from "../../interfaces/IPoolVoter.sol"; -import {IPythAggregatorV3} from "../../interfaces/IPythAggregatorV3.sol"; +import {IVotingPowerCombined} from "../../interfaces/IVotingPowerCombined.sol"; import {IWETH} from "../../interfaces/IWETH.sol"; import {IZeroLend} from "../../interfaces/IZeroLend.sol"; import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; @@ -37,7 +35,7 @@ abstract contract OmnichainStakingBase is { ILocker public locker; ILocker public __; // unwanted variable to keep storage layout - IPoolVoter public poolVoter; + IVotingPowerCombined public votingPowerCombined; // staking reward variables IZeroLend public rewardsToken; @@ -75,7 +73,7 @@ abstract contract OmnichainStakingBase is string memory symbol, address _locker, address _zeroToken, - address _poolVoter, + address _votingPowerCombined, uint256 _rewardsDuration, address _distributor ) internal { @@ -85,7 +83,7 @@ abstract contract OmnichainStakingBase is __ERC20_init(name, symbol); locker = ILocker(_locker); - poolVoter = IPoolVoter(_poolVoter); + votingPowerCombined = IVotingPowerCombined(_votingPowerCombined); rewardsToken = IZeroLend(_zeroToken); rewardsDuration = _rewardsDuration; @@ -185,7 +183,7 @@ abstract contract OmnichainStakingBase is // reset and burn voting power _burn(msg.sender, tokenPower[tokenId]); tokenPower[tokenId] = 0; - poolVoter.reset(msg.sender); + votingPowerCombined.reset(msg.sender); locker.safeTransferFrom(address(this), msg.sender, tokenId); } @@ -210,7 +208,7 @@ abstract contract OmnichainStakingBase is _mint(msg.sender, tokenPower[tokenId]); // reset all the votes for the user - poolVoter.reset(msg.sender); + votingPowerCombined.reset(msg.sender); } /** @@ -238,7 +236,7 @@ abstract contract OmnichainStakingBase is _mint(msg.sender, tokenPower[tokenId]); // reset all the votes for the user - poolVoter.reset(msg.sender); + votingPowerCombined.reset(msg.sender); } /** @@ -352,13 +350,13 @@ abstract contract OmnichainStakingBase is } /** - * Admin only function to set the pool voter contract + * Admin only function to set the VotingPowerCombined contract address * * @param what The new address for the pool voter contract */ - function setPoolVoter(address what) external onlyOwner { - emit PoolVoterUpdated(address(poolVoter), what); - poolVoter = IPoolVoter(what); + function setVotingPowerCombined(address what) external onlyOwner { + emit VotingPowerCombinedUpdated(address(votingPowerCombined), what); + votingPowerCombined = IVotingPowerCombined(what); } /** @@ -410,24 +408,6 @@ abstract contract OmnichainStakingBase is } } - /** - * @dev Prevents transfers of voting power. - */ - function transfer(address, uint256) public pure override returns (bool) { - revert("transfer disabled"); - } - - /** - * @dev Prevents transfers of voting power. - */ - function transferFrom( - address, - address, - uint256 - ) public pure override returns (bool) { - revert("transferFrom disabled"); - } - /** * @dev Deletes an element from an array. * @param elements The array to delete from. diff --git a/contracts/voter/PoolVoter.sol b/contracts/voter/PoolVoter.sol index 91df86c..b82f833 100644 --- a/contracts/voter/PoolVoter.sol +++ b/contracts/voter/PoolVoter.sol @@ -34,6 +34,8 @@ contract PoolVoter is mapping(address => uint256) public supplyIndex; mapping(address => uint256) public claimable; + address public votingPowerCombined; + /** * @notice Initializes the PoolVoter contract with the specified staking and reward tokens. * @dev This function is called only once during deployment. @@ -74,7 +76,7 @@ contract PoolVoter is */ function reset(address _who) external override { require( - msg.sender == _who || msg.sender == address(staking), + msg.sender == _who || msg.sender == address(votingPowerCombined), "Invalid reset performed" ); _reset(_who);