Skip to content

Commit

Permalink
Merge pull request #46 from SilentHex/fix/omnichain-staking-contract
Browse files Browse the repository at this point in the history
Omnichain-Staking-Contract Fix
  • Loading branch information
deadshotryker authored Jul 31, 2024
2 parents 083d144 + 666751a commit a20868f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 35 deletions.
7 changes: 4 additions & 3 deletions contracts/interfaces/IOmnichainStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
);
}
6 changes: 6 additions & 0 deletions contracts/interfaces/IVotingPowerCombined.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.11;

interface IVotingPowerCombined {
function reset(address _who) external;
}
42 changes: 11 additions & 31 deletions contracts/locker/staking/OmnichainStakingBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -75,7 +73,7 @@ abstract contract OmnichainStakingBase is
string memory symbol,
address _locker,
address _zeroToken,
address _poolVoter,
address _votingPowerCombined,
uint256 _rewardsDuration,
address _distributor
) internal {
Expand All @@ -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;

Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion contracts/voter/PoolVoter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit a20868f

Please sign in to comment.