forked from 3v3rt0n/DextroFinance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUraniumBonusAggregator.sol
56 lines (43 loc) · 2.04 KB
/
UraniumBonusAggregator.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
pragma solidity 0.6.12;
import "@pancakeswap/pancake-swap-lib/contracts/math/SafeMath.sol";
import "@pancakeswap/pancake-swap-lib/contracts/access/Ownable.sol";
import "./interfaces/IMasterBonus.sol";
import "./interfaces/IBonusAggregator.sol";
/*
The purpose of this contract is to allow us adding bonus to user's reward by adding NFT contracts for example
without updating the masterChef
The owner of this contract will be transferred to a timelock
*/
contract UraniumBonusAggregator is Ownable, IBonusAggregator{
using SafeMath for uint256;
IMasterBonus master;
// pid => address => bonus percent
mapping(uint256 => mapping(address => uint256)) public userBonusOnFarms;
mapping (address => bool) public contractBonusSource;
/**
* @dev Throws if called by any account other than the verified contracts.
* Can be an NFT contract for example
*/
modifier onlyVerifiedContract() {
require(contractBonusSource[msg.sender], "caller is not in contract list");
_;
}
function setupMaster(IMasterBonus _master) external onlyOwner{
master = _master;
}
function addOrRemoveContractBonusSource(address _contract, bool _add) external onlyOwner{
contractBonusSource[_contract] = _add;
}
function addUserBonusOnFarm(address _user, uint256 _percent, uint256 _pid) external onlyVerifiedContract{
userBonusOnFarms[_pid][_user] = userBonusOnFarms[_pid][_user].add(_percent);
require(userBonusOnFarms[_pid][_user] < 10000, "Invalid percent");
master.updateUserBonus(_user, _pid, userBonusOnFarms[_pid][_user]);
}
function removeUserBonusOnFarm(address _user, uint256 _percent, uint256 _pid) external onlyVerifiedContract{
userBonusOnFarms[_pid][_user] = userBonusOnFarms[_pid][_user].sub(_percent);
master.updateUserBonus(_user, _pid, userBonusOnFarms[_pid][_user]);
}
function getBonusOnFarmsForUser(address _user, uint256 _pid) external virtual override view returns (uint256){
return userBonusOnFarms[_pid][_user];
}
}