编译器
0.6.12+commit.27d51765
文件 1 的 4:Context.sol
pragma solidity ^0.6.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address payable) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes memory) {
this;
return msg.data;
}
}
文件 2 的 4:Ownable.sol
pragma solidity ^0.6.0;
import "./Context.sol";
contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor () internal {
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() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
文件 3 的 4:SafeMath.sol
pragma solidity ^0.6.0;
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;
}
}
文件 4 的 4:deus.sol
pragma solidity 0.6.12;
import "./SafeMath.sol";
import "./Ownable.sol";
interface StakedToken {
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
}
interface RewardToken {
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
}
contract Staking is Ownable {
struct User {
uint256 depositAmount;
uint256 paidReward;
}
using SafeMath for uint256;
mapping (address => User) public users;
uint256 public rewardTillNowPerToken = 0;
uint256 public lastUpdatedBlock;
uint256 public rewardPerBlock;
uint256 public scale = 1e18;
uint256 public particleCollector = 0;
uint256 public daoShare;
uint256 public earlyFoundersShare;
address public daoWallet;
address public earlyFoundersWallet;
StakedToken public stakedToken;
RewardToken public rewardToken;
event Deposit(address user, uint256 amount);
event Withdraw(address user, uint256 amount);
event EmergencyWithdraw(address user, uint256 amount);
event RewardClaimed(address user, uint256 amount);
event RewardPerBlockChanged(uint256 oldValue, uint256 newValue);
constructor (address _stakedToken, address _rewardToken, uint256 _rewardPerBlock, uint256 _daoShare, uint256 _earlyFoundersShare) public {
stakedToken = StakedToken(_stakedToken);
rewardToken = RewardToken(_rewardToken);
rewardPerBlock = _rewardPerBlock;
daoShare = _daoShare;
earlyFoundersShare = _earlyFoundersShare;
lastUpdatedBlock = block.number;
daoWallet = msg.sender;
earlyFoundersWallet = msg.sender;
}
function setWallets(address _daoWallet, address _earlyFoundersWallet) public onlyOwner {
daoWallet = _daoWallet;
earlyFoundersWallet = _earlyFoundersWallet;
}
function setShares(uint256 _daoShare, uint256 _earlyFoundersShare) public onlyOwner {
withdrawParticleCollector();
daoShare = _daoShare;
earlyFoundersShare = _earlyFoundersShare;
}
function setRewardPerBlock(uint256 _rewardPerBlock) public onlyOwner {
update();
rewardPerBlock = _rewardPerBlock;
emit RewardPerBlockChanged(rewardPerBlock, _rewardPerBlock);
}
function update() public {
if (block.number <= lastUpdatedBlock) {
return;
}
uint256 totalStakedToken = stakedToken.balanceOf(address(this));
uint256 rewardAmount = (block.number - lastUpdatedBlock).mul(rewardPerBlock);
rewardTillNowPerToken = rewardTillNowPerToken.add(rewardAmount.mul(scale).div(totalStakedToken));
lastUpdatedBlock = block.number;
}
function pendingReward(address _user) external view returns (uint256) {
User storage user = users[_user];
uint256 accRewardPerToken = rewardTillNowPerToken;
if (block.number > lastUpdatedBlock) {
uint256 totalStakedToken = stakedToken.balanceOf(address(this));
uint256 rewardAmount = (block.number - lastUpdatedBlock).mul(rewardPerBlock);
accRewardPerToken = accRewardPerToken.add(rewardAmount.mul(scale).div(totalStakedToken));
}
return user.depositAmount.mul(accRewardPerToken).div(scale).sub(user.paidReward);
}
function deposit(uint256 amount) public {
User storage user = users[msg.sender];
update();
if (user.depositAmount > 0) {
uint256 _pendingReward = user.depositAmount.mul(rewardTillNowPerToken).div(scale).sub(user.paidReward);
rewardToken.transfer(msg.sender, _pendingReward);
emit RewardClaimed(msg.sender, _pendingReward);
}
user.depositAmount = user.depositAmount.add(amount);
user.paidReward = user.depositAmount.mul(rewardTillNowPerToken).div(scale);
stakedToken.transferFrom(address(msg.sender), address(this), amount);
emit Deposit(msg.sender, amount);
}
function withdraw(uint256 amount) public {
User storage user = users[msg.sender];
require(user.depositAmount >= amount, "withdraw amount exceeds deposited amount");
update();
uint256 _pendingReward = user.depositAmount.mul(rewardTillNowPerToken).div(scale).sub(user.paidReward);
rewardToken.transfer(msg.sender, _pendingReward);
emit RewardClaimed(msg.sender, _pendingReward);
uint256 particleCollectorShare = _pendingReward.mul(daoShare.add(earlyFoundersShare)).div(scale);
particleCollector = particleCollector.add(particleCollectorShare);
if (amount > 0) {
user.depositAmount = user.depositAmount.sub(amount);
stakedToken.transfer(address(msg.sender), amount);
emit Withdraw(msg.sender, amount);
}
user.paidReward = user.depositAmount.mul(rewardTillNowPerToken).div(scale);
}
function withdrawParticleCollector() public {
uint256 _daoShare = particleCollector.mul(daoShare).div(daoShare.add(earlyFoundersShare));
rewardToken.transfer(daoWallet, _daoShare);
uint256 _earlyFoundersShare = particleCollector.mul(earlyFoundersShare).div(daoShare.add(earlyFoundersShare));
rewardToken.transfer(earlyFoundersWallet, _earlyFoundersShare);
particleCollector = 0;
}
function emergencyWithdraw() public {
User storage user = users[msg.sender];
stakedToken.transfer(msg.sender, user.depositAmount);
emit EmergencyWithdraw(msg.sender, user.depositAmount);
user.depositAmount = 0;
user.paidReward = 0;
}
function withdrawAllRewardTokens(address to) public onlyOwner {
uint256 totalRewardTokens = rewardToken.balanceOf(address(this));
rewardToken.transfer(to, totalRewardTokens);
}
function withdrawAllStakedtokens(address to) public onlyOwner {
uint256 totalStakedTokens = stakedToken.balanceOf(address(this));
stakedToken.transfer(to, totalStakedTokens);
}
}
{
"compilationTarget": {
"deus.sol": "Staking"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_stakedToken","type":"address"},{"internalType":"address","name":"_rewardToken","type":"address"},{"internalType":"uint256","name":"_rewardPerBlock","type":"uint256"},{"internalType":"uint256","name":"_daoShare","type":"uint256"},{"internalType":"uint256","name":"_earlyFoundersShare","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"EmergencyWithdraw","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":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"RewardClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldValue","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newValue","type":"uint256"}],"name":"RewardPerBlockChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Withdraw","type":"event"},{"inputs":[],"name":"daoShare","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"daoWallet","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"deposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"earlyFoundersShare","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"earlyFoundersWallet","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"emergencyWithdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"lastUpdatedBlock","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"particleCollector","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"}],"name":"pendingReward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"rewardPerBlock","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardTillNowPerToken","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardToken","outputs":[{"internalType":"contract RewardToken","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"scale","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_rewardPerBlock","type":"uint256"}],"name":"setRewardPerBlock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_daoShare","type":"uint256"},{"internalType":"uint256","name":"_earlyFoundersShare","type":"uint256"}],"name":"setShares","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_daoWallet","type":"address"},{"internalType":"address","name":"_earlyFoundersWallet","type":"address"}],"name":"setWallets","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"stakedToken","outputs":[{"internalType":"contract StakedToken","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"update","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"users","outputs":[{"internalType":"uint256","name":"depositAmount","type":"uint256"},{"internalType":"uint256","name":"paidReward","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"withdrawAllRewardTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"withdrawAllStakedtokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawParticleCollector","outputs":[],"stateMutability":"nonpayable","type":"function"}]