-
Notifications
You must be signed in to change notification settings - Fork 746
/
SystemReward.sol
87 lines (77 loc) · 2.82 KB
/
SystemReward.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
pragma solidity 0.6.4;
import "./System.sol";
import "./lib/0.6.x/Memory.sol";
import "./interface/0.6.x/IParamSubscriber.sol";
import "./interface/0.6.x/ISystemReward.sol";
contract SystemReward is System, IParamSubscriber, ISystemReward {
uint256 public constant MAX_REWARDS = 5e18;
uint256 public numOperator;
mapping(address => bool) operators;
modifier doInit() {
if (!alreadyInit) {
operators[LIGHT_CLIENT_ADDR] = true;
operators[INCENTIVIZE_ADDR] = true;
numOperator = 2;
alreadyInit = true;
}
_;
}
modifier onlyOperator() {
require(operators[msg.sender], "only operator is allowed to call the method");
_;
}
event rewardTo(address indexed to, uint256 amount);
event rewardEmpty();
event receiveDeposit(address indexed from, uint256 amount);
event addOperator(address indexed operator);
event deleteOperator(address indexed operator);
event paramChange(string key, bytes value);
receive() external payable {
if (msg.value > 0) {
emit receiveDeposit(msg.sender, msg.value);
}
}
function claimRewards(
address payable to,
uint256 amount
) external override(ISystemReward) doInit onlyOperator returns (uint256) {
uint256 actualAmount = amount < address(this).balance ? amount : address(this).balance;
if (actualAmount > MAX_REWARDS) {
actualAmount = MAX_REWARDS;
}
if (actualAmount != 0) {
to.transfer(actualAmount);
emit rewardTo(to, actualAmount);
} else {
emit rewardEmpty();
}
return actualAmount;
}
function isOperator(address addr) external view returns (bool) {
return operators[addr];
}
function updateParam(string calldata key, bytes calldata value) external override onlyGov {
if (Memory.compareStrings(key, "addOperator")) {
bytes memory valueLocal = value;
require(valueLocal.length == 20, "length of value for addOperator should be 20");
address operatorAddr;
assembly {
operatorAddr := mload(add(valueLocal, 20))
}
operators[operatorAddr] = true;
emit addOperator(operatorAddr);
} else if (Memory.compareStrings(key, "deleteOperator")) {
bytes memory valueLocal = value;
require(valueLocal.length == 20, "length of value for deleteOperator should be 20");
address operatorAddr;
assembly {
operatorAddr := mload(add(valueLocal, 20))
}
delete operators[operatorAddr];
emit deleteOperator(operatorAddr);
} else {
require(false, "unknown param");
}
emit paramChange(key, value);
}
}