Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for a rewards delegate #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions vesper-pools/contracts/interfaces/vesper/IPoolRewards.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ interface IPoolRewards {
event RewardPaid(address indexed user, address indexed rewardToken, uint256 reward);
/// Emitted after adding new rewards token into rewardTokens array
event RewardTokenAdded(address indexed rewardToken, address[] existingRewardTokens);
/// Emitted after setting the reward delegate for a user
event RewardsDelegateSet(address indexed user, address indexed delegate);

function claimReward(address) external;

Expand Down
16 changes: 15 additions & 1 deletion vesper-pools/contracts/pool/PoolRewards.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ abstract contract PoolRewardsStorage is IPoolRewards {

/// RewardToken => User => Rewards earned till last reward update
mapping(address => mapping(address => uint256)) public rewards;

// User => Address rewards are delegated to
mapping(address => address) public rewardsDelegate;
}

/// @title Distribute rewards based on vesper pool balance and supply
Expand Down Expand Up @@ -178,7 +181,11 @@ contract PoolRewards is Initializable, ReentrancyGuard, PoolRewardsStorage {
// Mark reward as claimed
rewards[rewardToken_][account_] = 0;
// Transfer reward
IERC20(rewardToken_).safeTransfer(account_, reward_);
if (rewardsDelegate[account_] != address(0)) {
IERC20(rewardToken_).safeTransfer(rewardsDelegate[account_], reward_);
} else {
IERC20(rewardToken_).safeTransfer(account_, reward_);
}
}

// There are scenarios when extending contract will override external methods and
Expand Down Expand Up @@ -287,4 +294,11 @@ contract PoolRewards is Initializable, ReentrancyGuard, PoolRewardsStorage {
) external virtual override onlyAuthorized {
_notifyRewardAmount(rewardToken_, rewardAmount_, rewardDuration_, IERC20(pool).totalSupply());
}

function setRewardsDelegate(address user_, address delegate_) external onlyAuthorized {
require(user_ != delegate_, "rewards-delegate-is-user");
require(rewardsDelegate[user_] != delegate_, "rewards-delegate-already-set");
emit RewardsDelegateSet(user_, delegate_);
rewardsDelegate[user_] = delegate_;
}
}