编译器
0.8.10+commit.fc410830
文件 1 的 5:Context.sol
pragma solidity ^0.8.10;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgValue() internal view virtual returns (uint256) {
return msg.value;
}
function _msgData() internal view virtual returns (bytes memory) {
this;
return msg.data;
}
}
文件 2 的 5:IRewardsToken.sol
pragma solidity ^0.8.10;
interface IRewardsToken {
function balanceOf(address account) external view returns (uint256);
function isExcludedFromRewards(address wallet) external view returns (bool);
function getRewardsSupply() external view returns (uint256);
}
文件 3 的 5:Ownable.sol
pragma solidity ^0.8.10;
import "./Context.sol";
contract Ownable is Context {
address private _owner;
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
constructor() {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
function owner() public view returns (address) {
return _owner;
}
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
function renounceOwnership() external virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
function transferOwnership(address newOwner) external virtual onlyOwner {
require(
newOwner != address(0),
"Ownable: new owner is the zero address"
);
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
文件 4 的 5:RewardsTracker.sol
pragma solidity ^0.8.10;
import "./Ownable.sol";
import "./IRewardsToken.sol";
import "./SafeMath.sol";
contract RewardsTracker is Ownable {
using SafeMath for uint256;
struct TrackingData {
IRewardsToken rewardsToken;
string trackerName;
uint256 allocation;
bool enabled;
}
mapping(uint256 => TrackingData) private trackerData;
mapping(address => uint256) private walletNonce;
bool public withdrawAllowed = true;
uint256 public totalCollected = 0;
uint256 public totalWithdrawn = 0;
address public signer =
address(0xF83Ba7773Acc6F87Ea53Ff8B6B9C6a979fef63AD);
address payable private _devWalletAddress =
payable(0x4cCCC4DDde1D32f728Dca729475A75FE23159E38);
event TrackerAdded(uint trackerId);
event TrackerRemoved(uint trackerId);
event AllocationAdded(uint256 value);
event DevWalletUpdated(address newDevWallet);
event SignerUpdated(address signer);
event WithdrawStatusChanged(bool allowed);
event Withdrawn(address wallet, uint256 amount);
function addTracker(uint identifier, address rewardsTokenAddress, string memory name) external onlyOwner {
require (!trackerData[identifier].enabled, "Tracker already registered and enabled");
TrackingData memory data;
data.rewardsToken = IRewardsToken(rewardsTokenAddress);
data.trackerName = name;
data.enabled = true;
trackerData[identifier] = data;
emit TrackerAdded(identifier);
}
function removeTracker(uint identifier) external onlyOwner {
require (trackerData[identifier].enabled, "Tracker not yet registered or already disabled");
trackerData[identifier].enabled = false;
if (trackerData[identifier].allocation > 0) {
sendEthToWallet(_devWalletAddress, trackerData[identifier].allocation);
}
emit TrackerRemoved(identifier);
}
function getTracker(uint identifier) external view returns (TrackingData memory) {
return trackerData[identifier];
}
function getWalletNonce(address wallet) external view returns (uint256) {
return walletNonce[wallet];
}
function addAllocation(uint identifier) external payable {
require(_msgValue() > 0, "Allocation can't be 0");
TrackingData storage trackingData = trackerData[identifier];
require(trackingData.enabled, "Tracker isn't enabled");
totalCollected = totalCollected.add(_msgValue());
trackingData.allocation = trackingData.allocation.add(_msgValue());
emit AllocationAdded(_msgValue());
}
function withdraw(uint256 identifier, uint256 amount, uint256 nonce, bytes memory sig) external payable {
require(withdrawAllowed, "withdraw is disabled");
bytes32 message = keccak256(abi.encodePacked(identifier, amount, nonce, _msgSender()));
bool signatureMatch = recoverSigner(message, sig) == signer;
require(signatureMatch, "signature mismatch");
require(address(this).balance >= amount, "contract balance is not enough for withdrawal");
bool trackerHasBalance = trackerData[identifier].allocation >= amount;
require(trackerHasBalance, "tracker balance is not enough for withdrawal");
bool uniqueNonce = (nonce == walletNonce[_msgSender()] + 1);
require(uniqueNonce, "Duplicate nonce");
if (signatureMatch && trackerHasBalance && uniqueNonce) {
walletNonce[_msgSender()] = walletNonce[_msgSender()] + 1;
trackerData[identifier].allocation = trackerData[identifier].allocation.sub(amount);
totalWithdrawn = totalWithdrawn.add(_msgValue());
payable(_msgSender()).transfer(amount);
emit Withdrawn(_msgSender(), amount);
}
}
function setSigner(address newSigner) external onlyOwner {
signer = newSigner;
emit SignerUpdated(newSigner);
}
function setDevWallet(address payable newDevWallet) external onlyOwner {
_devWalletAddress = newDevWallet;
emit DevWalletUpdated(newDevWallet);
}
function setAllowWithdraw(bool allowed) external onlyOwner {
withdrawAllowed = allowed;
emit WithdrawStatusChanged(allowed);
}
function manualSend() external onlyOwner {
uint256 contractEthBalance = address(this).balance;
sendEthToWallet(_devWalletAddress, contractEthBalance);
}
function sendEthToWallet(address wallet, uint256 amount) private {
require (amount > 0, "Withdraw must be > 0");
require (address(this).balance >= amount, "Insufficient balance");
payable(wallet).transfer(amount);
}
function recoverSigner(bytes32 message, bytes memory sig)
internal
pure
returns (address)
{
uint8 v;
bytes32 r;
bytes32 s;
(v, r, s) = splitSignature(sig);
return ecrecover(message, v, r, s);
}
function splitSignature(bytes memory sig)
internal
pure
returns (uint8, bytes32, bytes32)
{
require(sig.length == 65);
bytes32 r;
bytes32 s;
uint8 v;
assembly {
r := mload(add(sig, 32))
s := mload(add(sig, 64))
v := byte(0, mload(add(sig, 96)))
}
return (v, r, s);
}
}
文件 5 的 5:SafeMath.sol
pragma solidity ^0.8.10;
library SafeMath {
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
return c;
}
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
}
{
"compilationTarget": {
"Rewards Tracker V2/RewardsTracker.sol": "RewardsTracker"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"AllocationAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newDevWallet","type":"address"}],"name":"DevWalletUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"signer","type":"address"}],"name":"SignerUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"trackerId","type":"uint256"}],"name":"TrackerAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"trackerId","type":"uint256"}],"name":"TrackerRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"allowed","type":"bool"}],"name":"WithdrawStatusChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"wallet","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Withdrawn","type":"event"},{"inputs":[{"internalType":"uint256","name":"identifier","type":"uint256"}],"name":"addAllocation","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"identifier","type":"uint256"},{"internalType":"address","name":"rewardsTokenAddress","type":"address"},{"internalType":"string","name":"name","type":"string"}],"name":"addTracker","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"identifier","type":"uint256"}],"name":"getTracker","outputs":[{"components":[{"internalType":"contract IRewardsToken","name":"rewardsToken","type":"address"},{"internalType":"string","name":"trackerName","type":"string"},{"internalType":"uint256","name":"allocation","type":"uint256"},{"internalType":"bool","name":"enabled","type":"bool"}],"internalType":"struct RewardsTracker.TrackingData","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"wallet","type":"address"}],"name":"getWalletNonce","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"manualSend","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"identifier","type":"uint256"}],"name":"removeTracker","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"allowed","type":"bool"}],"name":"setAllowWithdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"newDevWallet","type":"address"}],"name":"setDevWallet","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newSigner","type":"address"}],"name":"setSigner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"signer","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalCollected","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalWithdrawn","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"identifier","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"bytes","name":"sig","type":"bytes"}],"name":"withdraw","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"withdrawAllowed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"}]