-
Notifications
You must be signed in to change notification settings - Fork 0
add PoolRewardDistributor #8
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
Open
mul53
wants to merge
3
commits into
master
Choose a base branch
from
feat/farm-reward-distributor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| pragma solidity 0.6.12; | ||
| pragma experimental ABIEncoderV2; | ||
|
|
||
| import "@openzeppelin/contracts/math/SafeMath.sol"; | ||
| import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; | ||
| import './uniswap/interfaces/IWETH.sol'; | ||
| import './interfaces/IMasterChef.sol'; | ||
| import "./boringcrypto/BoringOwnable.sol"; | ||
|
|
||
| /** | ||
| * @title PoolRewardDistributor | ||
| * @notice Distribute rewards to pools | ||
| */ | ||
| contract PoolRewardDistributor is BoringOwnable { | ||
| using SafeMath for uint256; | ||
| using SafeERC20 for IERC20; | ||
|
|
||
|
|
||
| struct Pool { | ||
| uint256 pid; // id of pool | ||
| uint256 rewardAmount; // amount of rewards to distribue | ||
| } | ||
|
|
||
| address public immutable masterChef; | ||
| address public immutable WETH; | ||
|
|
||
| uint256 public totalRewardAmount; | ||
| Pool[] public pools; | ||
|
|
||
| constructor(address _masterChef, address _WETH) public { | ||
| masterChef = _masterChef; | ||
| WETH = _WETH; | ||
| } | ||
|
|
||
| function recoverFuse() public onlyOwner { | ||
| uint256 fuseBalance = address(this).balance; | ||
| (bool sent,) = payable(owner).call{value: fuseBalance}(""); | ||
| require(sent); | ||
| } | ||
|
|
||
| function recoverToken(address token) public onlyOwner { | ||
| uint256 tokenBalance = IERC20(token).balanceOf(address(this)); | ||
| IERC20(token).transfer(owner, tokenBalance); | ||
| } | ||
|
|
||
| function addPools(Pool[] memory _pools) external onlyOwner { | ||
| for (uint256 i = 0; i < _pools.length; i++) { | ||
| _addPool(_pools[i]); | ||
| } | ||
| } | ||
|
|
||
| function addPool(Pool memory _pool) external onlyOwner { | ||
| _addPool(_pool); | ||
| } | ||
|
|
||
| function removePool(uint256 _pid) external onlyOwner { | ||
| _removePool(_pid); | ||
| } | ||
|
|
||
| function distributeRewards() external payable onlyOwner { | ||
| IWETH(WETH).deposit{value: msg.value}(); | ||
|
|
||
| for (uint256 i = 0; i < pools.length; i++) { | ||
| Pool memory pool = pools[i]; | ||
| IMasterChef.PoolInfo memory poolInfo = IMasterChef(masterChef).poolInfo(pool.pid); | ||
|
|
||
| if (address(poolInfo.rewarder) != address(0)) { | ||
| IWETH(WETH).transfer(address(poolInfo.rewarder), pool.rewardAmount); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| function _addPool(Pool memory _pool) internal { | ||
| pools.push(_pool); | ||
| totalRewardAmount = totalRewardAmount.add(_pool.rewardAmount); | ||
| } | ||
|
|
||
| function _removePool(uint256 _pid) internal { | ||
| uint256 index = _poolIndex(_pid); | ||
|
|
||
| Pool memory pool = pools[index]; | ||
| totalRewardAmount = totalRewardAmount.sub(pool.rewardAmount); | ||
|
|
||
| Pool[] storage poolsStorage = pools; | ||
|
|
||
| for (uint256 i = index; i < poolsStorage.length - 1; i++) { | ||
| poolsStorage[i] = poolsStorage[i + 1]; | ||
| } | ||
|
|
||
| poolsStorage.pop(); | ||
| } | ||
|
|
||
| function _poolIndex(uint256 _pid) internal view returns (uint256) { | ||
| for (uint256 i = 0; i < pools.length; i++) { | ||
| if (pools[i].pid == _pid) { | ||
| return i; | ||
| } | ||
| } | ||
|
|
||
| revert('pool not found'); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it payable?