-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Naohiro Yoshida <[email protected]>
- Loading branch information
Naohiro Yoshida
committed
Sep 6, 2023
1 parent
2554144
commit 71fcf7c
Showing
3 changed files
with
89 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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,86 @@ | ||
pragma solidity 0.6.4; | ||
|
||
import "./System.sol"; | ||
import "./lib/Memory.sol"; | ||
import "./interface/IParamSubscriber.sol"; | ||
import "./interface/ISystemReward.sol"; | ||
|
||
contract SystemReward is System, IParamSubscriber, ISystemReward { | ||
uint256 public constant MAX_REWARDS = 1e18; | ||
|
||
uint 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() { | ||
// start mod | ||
// require(operators[msg.sender],"only operator is allowed to call the method"); | ||
// end mod | ||
_; | ||
} | ||
|
||
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) onlyGov external override { | ||
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); | ||
} | ||
} |