-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathWine.sol
More file actions
114 lines (90 loc) · 3.86 KB
/
Wine.sol
File metadata and controls
114 lines (90 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// SPDX-License-Identifier: MIT
pragma solidity 0.6.12;
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Burnable.sol";
import "./owner/Operator.sol";
contract Wine is ERC20Burnable, Operator {
using SafeMath for uint256;
// TOTAL MAX SUPPLY = 50,000 WINE
uint256 public constant FARMING_POOL_REWARD_ALLOCATION = 41000 ether;
uint256 public constant COMMUNITY_FUND_POOL_ALLOCATION = 4500 ether;
uint256 public constant DEV_FUND_POOL_ALLOCATION = 4500 ether;
uint256 public constant VESTING_DURATION = 300 days;
uint256 public startTime;
uint256 public endTime;
uint256 public communityFundRewardRate;
uint256 public devFundRewardRate;
address public communityFund;
address public devFund;
uint256 public communityFundLastClaimed;
uint256 public devFundLastClaimed;
bool public rewardPoolDistributed = false;
constructor(uint256 _startTime, address _communityFund, address _devFund) public ERC20("Wine Shares", "WINE") {
_mint(msg.sender, 1 ether); // mint 1 GRAPE Share for initial pools deployment
startTime = _startTime;
endTime = startTime + VESTING_DURATION;
communityFundLastClaimed = startTime;
devFundLastClaimed = startTime;
communityFundRewardRate = COMMUNITY_FUND_POOL_ALLOCATION.div(VESTING_DURATION);
devFundRewardRate = DEV_FUND_POOL_ALLOCATION.div(VESTING_DURATION);
require(_devFund != address(0), "Address cannot be 0");
devFund = _devFund;
require(_communityFund != address(0), "Address cannot be 0");
communityFund = _communityFund;
}
function setTreasuryFund(address _communityFund) external {
require(msg.sender == devFund, "!dev");
communityFund = _communityFund;
}
function setDevFund(address _devFund) external {
require(msg.sender == devFund, "!dev");
require(_devFund != address(0), "zero");
devFund = _devFund;
}
function unclaimedTreasuryFund() public view returns (uint256 _pending) {
uint256 _now = block.timestamp;
if (_now > endTime) _now = endTime;
if (communityFundLastClaimed >= _now) return 0;
_pending = _now.sub(communityFundLastClaimed).mul(communityFundRewardRate);
}
function unclaimedDevFund() public view returns (uint256 _pending) {
uint256 _now = block.timestamp;
if (_now > endTime) _now = endTime;
if (devFundLastClaimed >= _now) return 0;
_pending = _now.sub(devFundLastClaimed).mul(devFundRewardRate);
}
/**
* @dev Claim pending rewards to community and dev fund
*/
function claimRewards() external {
uint256 _pending = unclaimedTreasuryFund();
if (_pending > 0 && communityFund != address(0)) {
_mint(communityFund, _pending);
communityFundLastClaimed = block.timestamp;
}
_pending = unclaimedDevFund();
if (_pending > 0 && devFund != address(0)) {
_mint(devFund, _pending);
devFundLastClaimed = block.timestamp;
}
}
/**
* @notice distribute to reward pool (only once)
*/
function distributeReward(address _farmingIncentiveFund) external onlyOperator {
require(!rewardPoolDistributed, "only can distribute once");
require(_farmingIncentiveFund != address(0), "!_farmingIncentiveFund");
rewardPoolDistributed = true;
_mint(_farmingIncentiveFund, FARMING_POOL_REWARD_ALLOCATION);
}
function burn(uint256 amount) public override {
super.burn(amount);
}
function governanceRecoverUnsupported(
IERC20 _token,
uint256 _amount,
address _to
) external onlyOperator {
_token.transfer(_to, _amount);
}
}