-
Notifications
You must be signed in to change notification settings - Fork 897
/
FrontEndRewarder.sol
72 lines (58 loc) · 2.06 KB
/
FrontEndRewarder.sol
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
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.10;
import "../types/OlympusAccessControlled.sol";
import "../interfaces/IERC20.sol";
abstract contract FrontEndRewarder is OlympusAccessControlled {
/* ========= STATE VARIABLES ========== */
uint256 public daoReward; // % reward for dao (3 decimals: 100 = 1%)
uint256 public refReward; // % reward for referrer (3 decimals: 100 = 1%)
mapping(address => uint256) public rewards; // front end operator rewards
mapping(address => bool) public whitelisted; // whitelisted status for operators
IERC20 internal immutable ohm; // reward token
constructor(
IOlympusAuthority _authority,
IERC20 _ohm
) OlympusAccessControlled(_authority) {
ohm = _ohm;
}
/* ========= EXTERNAL FUNCTIONS ========== */
// pay reward to front end operator
function getReward() external {
uint256 reward = rewards[msg.sender];
rewards[msg.sender] = 0;
ohm.transfer(msg.sender, reward);
}
/* ========= INTERNAL ========== */
/**
* @notice add new market payout to user data
*/
function _giveRewards(
uint256 _payout,
address _referral
) internal returns (uint256) {
// first we calculate rewards paid to the DAO and to the front end operator (referrer)
uint256 toDAO = _payout * daoReward / 1e4;
uint256 toRef = _payout * refReward / 1e4;
// and store them in our rewards mapping
if (whitelisted[_referral]) {
rewards[_referral] += toRef;
rewards[authority.guardian()] += toDAO;
} else { // the DAO receives both rewards if referrer is not whitelisted
rewards[authority.guardian()] += toDAO + toRef;
}
return toDAO + toRef;
}
/**
* @notice set rewards for front end operators and DAO
*/
function setRewards(uint256 _toFrontEnd, uint256 _toDAO) external onlyGovernor {
refReward = _toFrontEnd;
daoReward = _toDAO;
}
/**
* @notice add or remove addresses from the reward whitelist
*/
function whitelist(address _operator) external onlyPolicy {
whitelisted[_operator] = !whitelisted[_operator];
}
}