From 5fae3d6dfd323d4491e7777a9cafc4c0d8186b3d Mon Sep 17 00:00:00 2001 From: midnight-commit <43814957+midnight-commit@users.noreply.github.com> Date: Fri, 26 Aug 2022 10:35:56 +0200 Subject: [PATCH] update YetiVoter --- contracts/strategies/yeti/YetiVoter.sol | 33 ++++++++++++------- contracts/strategies/yeti/YetiVoterProxy.sol | 26 ++++++++++++++- .../strategies/yeti/interfaces/IYetiVoter.sol | 6 +++- 3 files changed, 52 insertions(+), 13 deletions(-) diff --git a/contracts/strategies/yeti/YetiVoter.sol b/contracts/strategies/yeti/YetiVoter.sol index 05323e86..fb148116 100644 --- a/contracts/strategies/yeti/YetiVoter.sol +++ b/contracts/strategies/yeti/YetiVoter.sol @@ -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 @@ -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() { @@ -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; } /** @@ -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 diff --git a/contracts/strategies/yeti/YetiVoterProxy.sol b/contracts/strategies/yeti/YetiVoterProxy.sol index 7ce97fc9..428d345f 100644 --- a/contracts/strategies/yeti/YetiVoterProxy.sol +++ b/contracts/strategies/yeti/YetiVoterProxy.sol @@ -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 @@ -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); } } diff --git a/contracts/strategies/yeti/interfaces/IYetiVoter.sol b/contracts/strategies/yeti/interfaces/IYetiVoter.sol index c54fda05..7b221d41 100644 --- a/contracts/strategies/yeti/interfaces/IYetiVoter.sol +++ b/contracts/strategies/yeti/interfaces/IYetiVoter.sol @@ -1,6 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.13; +import "./IVeYeti.sol"; + interface IYetiVoter { function execute( address to, @@ -8,7 +10,9 @@ interface IYetiVoter { 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); }