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

update YetiVoter #151

Open
wants to merge 1 commit into
base: master
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
33 changes: 22 additions & 11 deletions contracts/strategies/yeti/YetiVoter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import "../../lib/Ownable.sol";
import "../../lib/ERC20.sol";

import "./interfaces/IYetiVoter.sol";
import "./interfaces/IVeYeti.sol";

/**
* @notice YetiVoter manages deposits for other strategies
Expand All @@ -18,7 +17,7 @@ contract YetiVoter is Ownable, IYetiVoter, ERC20 {
IERC20 private constant YETI = IERC20(0x77777777777d4554c39223C354A05825b2E8Faa3);

address public voterProxy;
address public currentYetiRewarder;
address public defaultYetiRewarder;
bool public override depositsEnabled = true;

modifier onlyProxy() {
Expand Down Expand Up @@ -58,12 +57,12 @@ contract YetiVoter is Ownable, IYetiVoter, ERC20 {
}

/**
* @notice Update Yeti rewarder for which this contract accumulates veYETI
* @notice Update Yeti rewarder for which this contract accumulates veYETI as default for user deposits
* @dev Restricted to owner
* @param _rewarder new address
*/
function updateYetiRewarder(address _rewarder) external onlyOwner {
currentYetiRewarder = _rewarder;
defaultYetiRewarder = _rewarder;
}

/**
Expand All @@ -73,24 +72,36 @@ contract YetiVoter is Ownable, IYetiVoter, ERC20 {
function deposit(uint256 _amount) external {
require(depositsEnabled == true, "YetiVoter::deposits disabled");
require(IERC20(YETI).transferFrom(msg.sender, address(this), _amount), "YetiVoter::transfer failed");
_deposit(_amount);
IVeYeti.RewarderUpdate[] memory rewarderUpdates = new IVeYeti.RewarderUpdate[](1);
rewarderUpdates[0] = IVeYeti.RewarderUpdate({rewarder: defaultYetiRewarder, amount: _amount, isIncrease: true});
_deposit(_amount, rewarderUpdates);
}

function depositFromBalance(uint256 _amount) external override onlyProxy {
function depositFromBalance(uint256 _amount, IVeYeti.RewarderUpdate[] memory _rewarderUpdates)
external
override
onlyProxy
{
require(depositsEnabled == true, "YetiVoter:deposits disabled");
_deposit(_amount);
_deposit(_amount, _rewarderUpdates);
}

function _deposit(uint256 _amount) internal {
function _deposit(uint256 _amount, IVeYeti.RewarderUpdate[] memory _rewarderUpdates) internal {
_mint(msg.sender, _amount);

YETI.approve(VeYETI, _amount);
IVeYeti.RewarderUpdate[] memory rewarderUpdates = new IVeYeti.RewarderUpdate[](1);
rewarderUpdates[0] = IVeYeti.RewarderUpdate({rewarder: currentYetiRewarder, amount: _amount, isIncrease: true});
IVeYeti(VeYETI).update(rewarderUpdates);
_updateVeYeti(_rewarderUpdates);
YETI.approve(VeYETI, 0);
}

function updateVeYeti(IVeYeti.RewarderUpdate[] memory _rewarderUpdates) external onlyProxy {
_updateVeYeti(_rewarderUpdates);
}

function _updateVeYeti(IVeYeti.RewarderUpdate[] memory _rewarderUpdates) internal {
IVeYeti(VeYETI).update(_rewarderUpdates);
}

/**
* @notice Open-ended execute function
* @dev Very sensitive, restricted to proxy
Expand Down
26 changes: 25 additions & 1 deletion contracts/strategies/yeti/YetiVoterProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,24 @@ contract YetiVoterProxy is IYetiVoterProxy {
boosterFeeReceiver = _boosterFeeReceiver;
}

/**
* @notice Move veYeti
* @dev Restricted to devAddr
* @param _from rewarder where to reduce
* @param _to rewarder where to add
* @param _amount to move
*/
function moveVeYeti(
address _from,
address _to,
uint256 _amount
) external onlyDev {
IVeYeti.RewarderUpdate[] memory rewarderUpdates = new IVeYeti.RewarderUpdate[](2);
rewarderUpdates[0] = IVeYeti.RewarderUpdate({rewarder: _from, amount: _amount, isIncrease: false});
rewarderUpdates[1] = IVeYeti.RewarderUpdate({rewarder: _to, amount: _amount, isIncrease: true});
voter.updateVeYeti(rewarderUpdates);
}

/**
* @notice Deposit function
* @dev Restricted to strategy with _pid
Expand Down Expand Up @@ -188,7 +206,13 @@ contract YetiVoterProxy is IYetiVoterProxy {
abi.encodeWithSignature("transfer(address,uint256)", msg.sender, reward)
);
if (boostFee > 0) {
voter.depositFromBalance(boostFee);
IVeYeti.RewarderUpdate[] memory rewarderUpdates = new IVeYeti.RewarderUpdate[](1);
rewarderUpdates[0] = IVeYeti.RewarderUpdate({
rewarder: _stakingContract,
amount: boostFee,
isIncrease: true
});
voter.depositFromBalance(boostFee, rewarderUpdates);
IERC20(address(voter)).safeTransfer(boosterFeeReceiver, boostFee);
}
}
Expand Down
6 changes: 5 additions & 1 deletion contracts/strategies/yeti/interfaces/IYetiVoter.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;

import "./IVeYeti.sol";

interface IYetiVoter {
function execute(
address to,
uint256 value,
bytes calldata data
) external returns (bool, bytes memory);

function depositFromBalance(uint256 _amount) external;
function depositFromBalance(uint256 _amount, IVeYeti.RewarderUpdate[] memory _rewarderUpdates) external;

function updateVeYeti(IVeYeti.RewarderUpdate[] memory _rewarderUpdates) external;

function depositsEnabled() external view returns (bool);
}