编译器
0.6.12+commit.27d51765
文件 1 的 6: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 的 6:IERC20.sol
pragma solidity ^0.6.0;
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
文件 3 的 6:IStaking.sol
pragma solidity ^0.6.0;
import "@openzeppelin/contracts/access/Ownable.sol";
interface IStaking {
function getEpochId(uint timestamp) external view returns (uint);
function getEpochUserBalance(address user, address token, uint128 epoch) external view returns(uint);
function getEpochPoolSize(address token, uint128 epoch) external view returns (uint);
function epoch1Start() external view returns (uint);
function epochDuration() external view returns (uint);
}
文件 4 的 6:Ownable.sol
pragma solidity ^0.6.0;
import "../GSN/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;
}
}
文件 5 的 6: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;
}
}
文件 6 的 6:YieldFarmGenericToken.sol
pragma solidity ^0.6.0;
import "@openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./interfaces/IStaking.sol";
contract YieldFarmGenericToken {
using SafeMath for uint;
using SafeMath for uint128;
uint public constant TOTAL_DISTRIBUTED_AMOUNT = 1_000_000;
uint public constant NR_OF_EPOCHS = 20;
uint128 public constant EPOCHS_DELAYED_FROM_STAKING_CONTRACT = 0;
address private _poolTokenAddress;
address private _communityVault;
IERC20 private _entr;
IStaking private _staking;
uint[] private epochs = new uint[](NR_OF_EPOCHS + 1);
uint private _totalAmountPerEpoch;
uint128 public lastInitializedEpoch;
mapping(address => uint128) private lastEpochIdHarvested;
uint public epochDuration;
uint public epochStart;
event MassHarvest(address indexed user, uint256 epochsHarvested, uint256 totalValue);
event Harvest(address indexed user, uint128 indexed epochId, uint256 amount);
constructor(address poolTokenAddress, address entrTokenAddress, address stakeContract, address communityVault) public {
_entr = IERC20(entrTokenAddress);
_poolTokenAddress = poolTokenAddress;
_staking = IStaking(stakeContract);
_communityVault = communityVault;
epochDuration = _staking.epochDuration();
epochStart = _staking.epoch1Start() + epochDuration.mul(EPOCHS_DELAYED_FROM_STAKING_CONTRACT);
_totalAmountPerEpoch = TOTAL_DISTRIBUTED_AMOUNT.mul(10**18).div(NR_OF_EPOCHS);
}
function massHarvest() external returns (uint){
uint totalDistributedValue;
uint epochId = _getEpochId().sub(1);
if (epochId > NR_OF_EPOCHS) {
epochId = NR_OF_EPOCHS;
}
for (uint128 i = lastEpochIdHarvested[msg.sender] + 1; i <= epochId; i++) {
totalDistributedValue += _harvest(i);
}
emit MassHarvest(msg.sender, epochId - lastEpochIdHarvested[msg.sender], totalDistributedValue);
if (totalDistributedValue > 0) {
_entr.transferFrom(_communityVault, msg.sender, totalDistributedValue);
}
return totalDistributedValue;
}
function harvest (uint128 epochId) external returns (uint){
require (_getEpochId() > epochId, "This epoch is in the future");
require(epochId <= NR_OF_EPOCHS, "Maximum number of epochs is 12");
require (lastEpochIdHarvested[msg.sender].add(1) == epochId, "Harvest in order");
uint userReward = _harvest(epochId);
if (userReward > 0) {
_entr.transferFrom(_communityVault, msg.sender, userReward);
}
emit Harvest(msg.sender, epochId, userReward);
return userReward;
}
function getPoolSize(uint128 epochId) external view returns (uint) {
return _getPoolSize(epochId);
}
function getCurrentEpoch() external view returns (uint) {
return _getEpochId();
}
function getEpochStake(address userAddress, uint128 epochId) external view returns (uint) {
return _getUserBalancePerEpoch(userAddress, epochId);
}
function userLastEpochIdHarvested() external view returns (uint){
return lastEpochIdHarvested[msg.sender];
}
function _initEpoch(uint128 epochId) internal {
require(lastInitializedEpoch.add(1) == epochId, "Epoch can be init only in order");
lastInitializedEpoch = epochId;
epochs[epochId] = _getPoolSize(epochId);
}
function _harvest (uint128 epochId) internal returns (uint) {
if (lastInitializedEpoch < epochId) {
_initEpoch(epochId);
}
lastEpochIdHarvested[msg.sender] = epochId;
if (epochs[epochId] == 0) {
return 0;
}
return _totalAmountPerEpoch
.mul(_getUserBalancePerEpoch(msg.sender, epochId))
.div(epochs[epochId]);
}
function _getPoolSize(uint128 epochId) internal view returns (uint) {
return _staking.getEpochPoolSize(_poolTokenAddress, _stakingEpochId(epochId));
}
function _getUserBalancePerEpoch(address userAddress, uint128 epochId) internal view returns (uint){
return _staking.getEpochUserBalance(userAddress, _poolTokenAddress, _stakingEpochId(epochId));
}
function _getEpochId() internal view returns (uint128 epochId) {
if (block.timestamp < epochStart) {
return 0;
}
epochId = uint128(block.timestamp.sub(epochStart).div(epochDuration).add(1));
}
function _stakingEpochId(uint128 epochId) pure internal returns (uint128) {
return epochId + EPOCHS_DELAYED_FROM_STAKING_CONTRACT;
}
}
{
"compilationTarget": {
"contracts/YieldFarmGenericToken.sol": "YieldFarmGenericToken"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 1000
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"poolTokenAddress","type":"address"},{"internalType":"address","name":"entrTokenAddress","type":"address"},{"internalType":"address","name":"stakeContract","type":"address"},{"internalType":"address","name":"communityVault","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"uint128","name":"epochId","type":"uint128"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Harvest","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"epochsHarvested","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"totalValue","type":"uint256"}],"name":"MassHarvest","type":"event"},{"inputs":[],"name":"EPOCHS_DELAYED_FROM_STAKING_CONTRACT","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"NR_OF_EPOCHS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TOTAL_DISTRIBUTED_AMOUNT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"epochDuration","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"epochStart","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCurrentEpoch","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"userAddress","type":"address"},{"internalType":"uint128","name":"epochId","type":"uint128"}],"name":"getEpochStake","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint128","name":"epochId","type":"uint128"}],"name":"getPoolSize","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint128","name":"epochId","type":"uint128"}],"name":"harvest","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"lastInitializedEpoch","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"massHarvest","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"userLastEpochIdHarvested","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]