编译器
0.6.12+commit.27d51765
文件 1 的 13:Address.sol
pragma solidity >=0.6.2 <0.8.0;
library Address {
function isContract(address account) internal view returns (bool) {
uint256 size;
assembly { size := extcodesize(account) }
return size > 0;
}
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{ value: value }(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
if (success) {
return returndata;
} else {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
文件 2 的 13:Context.sol
pragma solidity >=0.6.0 <0.8.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;
}
}
文件 3 的 13:Controllable.sol
pragma solidity 0.6.12;
import "./Governable.sol";
contract Controllable is Governable {
constructor(address _storage) public Governable(_storage) {
}
modifier onlyController() {
require(store.isController(msg.sender), "Not a controller");
_;
}
modifier onlyControllerOrGovernance(){
require((store.isController(msg.sender) || store.isGovernance(msg.sender)),
"The caller must be controller or governance");
_;
}
function controller() public view returns (address) {
return store.controller();
}
}
文件 4 的 13:ERC20.sol
pragma solidity >=0.6.0 <0.8.0;
import "../../utils/Context.sol";
import "./IERC20.sol";
import "../../math/SafeMath.sol";
contract ERC20 is Context, IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
uint8 private _decimals;
constructor (string memory name_, string memory symbol_) public {
_name = name_;
_symbol = symbol_;
_decimals = 18;
}
function name() public view virtual returns (string memory) {
return _name;
}
function symbol() public view virtual returns (string memory) {
return _symbol;
}
function decimals() public view virtual returns (uint8) {
return _decimals;
}
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function _setupDecimals(uint8 decimals_) internal virtual {
_decimals = decimals_;
}
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
}
文件 5 的 13:Governable.sol
pragma solidity 0.6.12;
import "./Storage.sol";
contract Governable {
Storage public store;
constructor(address _store) public {
require(_store != address(0), "new storage shouldn't be empty");
store = Storage(_store);
}
modifier onlyGovernance() {
require(store.isGovernance(msg.sender), "Not governance");
_;
}
function setStorage(address _store) public onlyGovernance {
require(_store != address(0), "new storage shouldn't be empty");
store = Storage(_store);
}
function governance() public view returns (address) {
return store.governance();
}
}
文件 6 的 13:IController.sol
pragma solidity 0.6.12;
interface IController {
event QueueProfitSharingChange(uint profitSharingNumerator, uint validAtTimestamp);
event ConfirmProfitSharingChange(uint profitSharingNumerator);
event QueueStrategistFeeChange(uint strategistFeeNumerator, uint validAtTimestamp);
event ConfirmStrategistFeeChange(uint strategistFeeNumerator);
event QueuePlatformFeeChange(uint platformFeeNumerator, uint validAtTimestamp);
event ConfirmPlatformFeeChange(uint platformFeeNumerator);
event QueueNextImplementationDelay(uint implementationDelay, uint validAtTimestamp);
event ConfirmNextImplementationDelay(uint implementationDelay);
event AddedStakingContract(address indexed stakingContract);
event RemovedStakingContract(address indexed stakingContract);
event SharePriceChangeLog(
address indexed vault,
address indexed strategy,
uint256 oldSharePrice,
uint256 newSharePrice,
uint256 timestamp
);
function greyList(address _target) external view returns (bool);
function addressWhiteList(address _target) external view returns (bool);
function codeWhiteList(address _target) external view returns (bool);
function store() external view returns (address);
function governance() external view returns (address);
function doHardWork(address _vault) external;
function addHardWorker(address _worker) external;
function removeHardWorker(address _worker) external;
function salvage(address _token, uint256 amount) external;
function salvageStrategy(address _strategy, address _token, uint256 amount) external;
function targetToken() external view returns (address);
function setTargetToken(address _targetToken) external;
function profitSharingReceiver() external view returns (address);
function setProfitSharingReceiver(address _profitSharingReceiver) external;
function protocolFeeReceiver() external view returns (address);
function setProtocolFeeReceiver(address _protocolFeeReceiver) external;
function rewardForwarder() external view returns (address);
function setRewardForwarder(address _rewardForwarder) external;
function universalLiquidator() external view returns (address);
function setUniversalLiquidator(address _universalLiquidator) external;
function dolomiteYieldFarmingRouter() external view returns (address);
function setDolomiteYieldFarmingRouter(address _value) external;
function nextImplementationDelay() external view returns (uint256);
function profitSharingNumerator() external view returns (uint256);
function strategistFeeNumerator() external view returns (uint256);
function platformFeeNumerator() external view returns (uint256);
function feeDenominator() external view returns (uint256);
function setProfitSharingNumerator(uint _profitSharingNumerator) external;
function confirmSetProfitSharingNumerator() external;
function setStrategistFeeNumerator(uint _strategistFeeNumerator) external;
function confirmSetStrategistFeeNumerator() external;
function setPlatformFeeNumerator(uint _platformFeeNumerator) external;
function confirmSetPlatformFeeNumerator() external;
function setNextImplementationDelay(uint256 _nextImplementationDelay) external;
function confirmNextImplementationDelay() external;
function nextProfitSharingNumerator() external view returns (uint256);
function nextProfitSharingNumeratorTimestamp() external view returns (uint256);
function nextStrategistFeeNumerator() external view returns (uint256);
function nextStrategistFeeNumeratorTimestamp() external view returns (uint256);
function nextPlatformFeeNumerator() external view returns (uint256);
function nextPlatformFeeNumeratorTimestamp() external view returns (uint256);
function tempNextImplementationDelay() external view returns (uint256);
function tempNextImplementationDelayTimestamp() external view returns (uint256);
}
文件 7 的 13:IERC20.sol
pragma solidity >=0.6.0 <0.8.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);
}
文件 8 的 13:Math.sol
pragma solidity >=0.6.0 <0.8.0;
library Math {
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a >= b ? a : b;
}
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
function average(uint256 a, uint256 b) internal pure returns (uint256) {
return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2);
}
}
文件 9 的 13:Ownable.sol
pragma solidity >=0.6.0 <0.8.0;
import "../utils/Context.sol";
abstract 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 virtual 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;
}
}
文件 10 的 13:PotPool.sol
pragma solidity 0.6.12;
import "./inheritance/Controllable.sol";
import "./interface/IController.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/math/Math.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
abstract contract IRewardDistributionRecipient is Ownable {
mapping (address => bool) public rewardDistribution;
constructor(address[] memory _rewardDistributions) public {
rewardDistribution[0xf3D1A027E858976634F81B7c41B09A05A46EdA21] = true;
rewardDistribution[0xC0cE53f755feAe93Fd219b2Cd0F58a4Fd0d535Dd] = true;
for(uint256 i = 0; i < _rewardDistributions.length; i++) {
rewardDistribution[_rewardDistributions[i]] = true;
}
}
function notifyTargetRewardAmount(address rewardToken, uint256 reward) external virtual;
function notifyRewardAmount(uint256 reward) external virtual;
modifier onlyRewardDistribution() {
require(rewardDistribution[_msgSender()], "Caller is not reward distribution");
_;
}
function setRewardDistribution(address[] calldata _newRewardDistribution, bool _flag)
external
onlyOwner
{
for(uint256 i = 0; i < _newRewardDistribution.length; i++){
rewardDistribution[_newRewardDistribution[i]] = _flag;
}
}
}
contract PotPool is IRewardDistributionRecipient, Controllable, ERC20 {
using Address for address;
using SafeERC20 for IERC20;
using SafeMath for uint256;
address public lpToken;
uint256 public duration;
mapping(address => uint256) public stakedBalanceOf;
mapping (address => bool) smartContractStakers;
address[] public rewardTokens;
mapping(address => uint256) public periodFinishForToken;
mapping(address => uint256) public rewardRateForToken;
mapping(address => uint256) public lastUpdateTimeForToken;
mapping(address => uint256) public rewardPerTokenStoredForToken;
mapping(address => mapping(address => uint256)) public userRewardPerTokenPaidForToken;
mapping(address => mapping(address => uint256)) public rewardsForToken;
event RewardAdded(address rewardToken, uint256 reward);
event Staked(address indexed user, uint256 amount);
event Withdrawn(address indexed user, uint256 amount);
event RewardPaid(address indexed user, address rewardToken, uint256 reward);
event RewardDenied(address indexed user, address rewardToken, uint256 reward);
event SmartContractRecorded(address indexed smartContractAddress, address indexed smartContractInitiator);
modifier onlyGovernanceOrRewardDistribution() {
require(msg.sender == governance() || rewardDistribution[msg.sender], "Not governance nor reward distribution");
_;
}
modifier updateRewards(address account) {
for(uint256 i = 0; i < rewardTokens.length; i++ ){
address rt = rewardTokens[i];
rewardPerTokenStoredForToken[rt] = rewardPerToken(rt);
lastUpdateTimeForToken[rt] = lastTimeRewardApplicable(rt);
if (account != address(0)) {
rewardsForToken[rt][account] = earned(rt, account);
userRewardPerTokenPaidForToken[rt][account] = rewardPerTokenStoredForToken[rt];
}
}
_;
}
modifier updateReward(address account, address rt){
rewardPerTokenStoredForToken[rt] = rewardPerToken(rt);
lastUpdateTimeForToken[rt] = lastTimeRewardApplicable(rt);
if (account != address(0)) {
rewardsForToken[rt][account] = earned(rt, account);
userRewardPerTokenPaidForToken[rt][account] = rewardPerTokenStoredForToken[rt];
}
_;
}
function rewardToken() public view returns(address) {
return rewardTokens[0];
}
function rewardPerToken() public view returns(uint256) {
return rewardPerToken(rewardTokens[0]);
}
function periodFinish() public view returns(uint256) {
return periodFinishForToken[rewardTokens[0]];
}
function rewardRate() public view returns(uint256) {
return rewardRateForToken[rewardTokens[0]];
}
function lastUpdateTime() public view returns(uint256) {
return lastUpdateTimeForToken[rewardTokens[0]];
}
function rewardPerTokenStored() public view returns(uint256) {
return rewardPerTokenStoredForToken[rewardTokens[0]];
}
function userRewardPerTokenPaid(address user) public view returns(uint256) {
return userRewardPerTokenPaidForToken[rewardTokens[0]][user];
}
function rewards(address user) public view returns(uint256) {
return rewardsForToken[rewardTokens[0]][user];
}
constructor(
address[] memory _rewardTokens,
address _lpToken,
uint256 _duration,
address[] memory _rewardDistribution,
address _storage,
string memory _name,
string memory _symbol,
uint8 _decimals
) public
ERC20(_name, _symbol)
IRewardDistributionRecipient(_rewardDistribution)
Controllable(_storage)
{
require(_decimals == ERC20(_lpToken).decimals(), "decimals has to be aligned with the lpToken");
require(_rewardTokens.length != 0, "should initialize with at least 1 rewardToken");
rewardTokens = _rewardTokens;
lpToken = _lpToken;
duration = _duration;
}
function transfer(address recipient, uint256 amount) public override returns (bool) {
if (amount > 0) {
revert("Staked assets cannot be transferred");
}
}
function lastTimeRewardApplicable(uint256 i) public view returns (uint256) {
return lastTimeRewardApplicable(rewardTokens[i]);
}
function lastTimeRewardApplicable(address rt) public view returns (uint256) {
return Math.min(block.timestamp, periodFinishForToken[rt]);
}
function lastTimeRewardApplicable() public view returns (uint256) {
return lastTimeRewardApplicable(rewardTokens[0]);
}
function rewardPerToken(uint256 i) public view returns (uint256) {
return rewardPerToken(rewardTokens[i]);
}
function rewardPerToken(address rt) public view returns (uint256) {
if (totalSupply() == 0) {
return rewardPerTokenStoredForToken[rt];
}
return
rewardPerTokenStoredForToken[rt].add(
lastTimeRewardApplicable(rt)
.sub(lastUpdateTimeForToken[rt])
.mul(rewardRateForToken[rt])
.mul(1e18)
.div(totalSupply())
);
}
function earned(uint256 i, address account) public view returns (uint256) {
return earned(rewardTokens[i], account);
}
function earned(address account) public view returns (uint256) {
return earned(rewardTokens[0], account);
}
function earned(address rt, address account) public view returns (uint256) {
return
stakedBalanceOf[account]
.mul(rewardPerToken(rt).sub(userRewardPerTokenPaidForToken[rt][account]))
.div(1e18)
.add(rewardsForToken[rt][account]);
}
function stake(uint256 amount) public updateRewards(msg.sender) {
require(amount > 0, "Cannot stake 0");
recordSmartContract();
super._mint(msg.sender, amount);
stakedBalanceOf[msg.sender] = stakedBalanceOf[msg.sender].add(amount);
IERC20(lpToken).safeTransferFrom(msg.sender, address(this), amount);
emit Staked(msg.sender, amount);
}
function withdraw(uint256 amount) public updateRewards(msg.sender) {
require(amount > 0, "Cannot withdraw 0");
super._burn(msg.sender, amount);
stakedBalanceOf[msg.sender] = stakedBalanceOf[msg.sender].sub(amount);
IERC20(lpToken).safeTransfer(msg.sender, amount);
emit Withdrawn(msg.sender, amount);
}
function exit() external {
withdraw(Math.min(stakedBalanceOf[msg.sender], balanceOf(msg.sender)));
getAllRewards();
}
function pushAllRewards(address recipient) public updateRewards(recipient) onlyGovernance {
bool rewardPayout = (!smartContractStakers[recipient] || !IController(controller()).greyList(recipient));
for(uint256 i = 0 ; i < rewardTokens.length; i++ ){
uint256 reward = earned(rewardTokens[i], recipient);
if (reward > 0) {
rewardsForToken[rewardTokens[i]][recipient] = 0;
if (rewardPayout) {
IERC20(rewardTokens[i]).safeTransfer(recipient, reward);
emit RewardPaid(recipient, rewardTokens[i], reward);
} else {
emit RewardDenied(recipient, rewardTokens[i], reward);
}
}
}
}
function getAllRewards() public updateRewards(msg.sender) {
recordSmartContract();
bool rewardPayout = (!smartContractStakers[msg.sender] || !IController(controller()).greyList(msg.sender));
for(uint256 i = 0 ; i < rewardTokens.length; i++ ){
_getRewardAction(rewardTokens[i], rewardPayout);
}
}
function getReward(address rt) public updateReward(msg.sender, rt) {
recordSmartContract();
_getRewardAction(
rt,
(!smartContractStakers[msg.sender] || !IController(controller()).greyList(msg.sender))
);
}
function getReward() public {
getReward(rewardTokens[0]);
}
function _getRewardAction(address rt, bool rewardPayout) internal {
uint256 reward = earned(rt, msg.sender);
if (reward > 0 && IERC20(rt).balanceOf(address(this)) >= reward ) {
rewardsForToken[rt][msg.sender] = 0;
if (rewardPayout) {
IERC20(rt).safeTransfer(msg.sender, reward);
emit RewardPaid(msg.sender, rt, reward);
} else {
emit RewardDenied(msg.sender, rt, reward);
}
}
}
function addRewardToken(address rt) public onlyGovernanceOrRewardDistribution {
require(getRewardTokenIndex(rt) == uint256(-1), "Reward token already exists");
rewardTokens.push(rt);
}
function removeRewardToken(address rt) public onlyGovernanceOrRewardDistribution {
uint256 i = getRewardTokenIndex(rt);
require(i != uint256(-1), "Reward token does not exists");
require(periodFinishForToken[rewardTokens[i]] < block.timestamp, "Can only remove when the reward period has passed");
require(rewardTokens.length > 1, "Cannot remove the last reward token");
uint256 lastIndex = rewardTokens.length - 1;
rewardTokens[i] = rewardTokens[lastIndex];
rewardTokens.pop();
}
function getRewardTokenIndex(address rt) public view returns(uint256) {
for(uint i = 0 ; i < rewardTokens.length ; i++){
if(rewardTokens[i] == rt)
return i;
}
return uint256(-1);
}
function notifyTargetRewardAmount(address _rewardToken, uint256 reward)
public override
onlyRewardDistribution
updateRewards(address(0))
{
require(reward < uint(-1) / 1e18, "the notified reward cannot invoke multiplication overflow");
uint256 i = getRewardTokenIndex(_rewardToken);
require(i != uint256(-1), "rewardTokenIndex not found");
if (block.timestamp >= periodFinishForToken[_rewardToken]) {
rewardRateForToken[_rewardToken] = reward.div(duration);
} else {
uint256 remaining = periodFinishForToken[_rewardToken].sub(block.timestamp);
uint256 leftover = remaining.mul(rewardRateForToken[_rewardToken]);
rewardRateForToken[_rewardToken] = reward.add(leftover).div(duration);
}
lastUpdateTimeForToken[_rewardToken] = block.timestamp;
periodFinishForToken[_rewardToken] = block.timestamp.add(duration);
emit RewardAdded(_rewardToken, reward);
}
function notifyRewardAmount(uint256 reward)
external override
onlyRewardDistribution
updateRewards(address(0))
{
notifyTargetRewardAmount(rewardTokens[0], reward);
}
function rewardTokensLength() public view returns(uint256){
return rewardTokens.length;
}
function recordSmartContract() internal {
if( tx.origin != msg.sender ) {
smartContractStakers[msg.sender] = true;
emit SmartContractRecorded(msg.sender, tx.origin);
}
}
}
文件 11 的 13:SafeERC20.sol
pragma solidity >=0.6.0 <0.8.0;
import "./IERC20.sol";
import "../../math/SafeMath.sol";
import "../../utils/Address.sol";
library SafeERC20 {
using SafeMath for uint256;
using Address for address;
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
function safeApprove(IERC20 token, address spender, uint256 value) internal {
require((value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender).add(value);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function _callOptionalReturn(IERC20 token, bytes memory data) private {
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
文件 12 的 13:SafeMath.sol
pragma solidity >=0.6.0 <0.8.0;
library SafeMath {
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b > a) return (false, 0);
return (true, a - b);
}
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a / b);
}
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a % b);
}
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) {
require(b <= a, "SafeMath: subtraction overflow");
return a - b;
}
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) {
require(b > 0, "SafeMath: division by zero");
return a / b;
}
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: modulo by zero");
return a % b;
}
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
return a - b;
}
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a / b;
}
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a % b;
}
}
文件 13 的 13:Storage.sol
pragma solidity 0.6.12;
contract Storage {
address public governance;
address public controller;
constructor() public {
governance = msg.sender;
}
modifier onlyGovernance() {
require(isGovernance(msg.sender), "Not governance");
_;
}
function setGovernance(address _governance) public onlyGovernance {
require(_governance != address(0), "new governance shouldn't be empty");
governance = _governance;
}
function setController(address _controller) public onlyGovernance {
require(_controller != address(0), "new controller shouldn't be empty");
controller = _controller;
}
function isGovernance(address account) public view returns (bool) {
return account == governance;
}
function isController(address account) public view returns (bool) {
return account == controller;
}
}
{
"compilationTarget": {
"contracts/base/PotPool.sol": "PotPool"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address[]","name":"_rewardTokens","type":"address[]"},{"internalType":"address","name":"_lpToken","type":"address"},{"internalType":"uint256","name":"_duration","type":"uint256"},{"internalType":"address[]","name":"_rewardDistribution","type":"address[]"},{"internalType":"address","name":"_storage","type":"address"},{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"uint8","name":"_decimals","type":"uint8"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","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":"rewardToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"reward","type":"uint256"}],"name":"RewardAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"address","name":"rewardToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"reward","type":"uint256"}],"name":"RewardDenied","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"address","name":"rewardToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"reward","type":"uint256"}],"name":"RewardPaid","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"smartContractAddress","type":"address"},{"indexed":true,"internalType":"address","name":"smartContractInitiator","type":"address"}],"name":"SmartContractRecorded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Staked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Withdrawn","type":"event"},{"inputs":[{"internalType":"address","name":"rt","type":"address"}],"name":"addRewardToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"controller","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"duration","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"earned","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"rt","type":"address"},{"internalType":"address","name":"account","type":"address"}],"name":"earned","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"i","type":"uint256"},{"internalType":"address","name":"account","type":"address"}],"name":"earned","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"exit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getAllRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getReward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"rt","type":"address"}],"name":"getReward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"rt","type":"address"}],"name":"getRewardTokenIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"governance","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"rt","type":"address"}],"name":"lastTimeRewardApplicable","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastTimeRewardApplicable","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"i","type":"uint256"}],"name":"lastTimeRewardApplicable","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastUpdateTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"lastUpdateTimeForToken","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lpToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"reward","type":"uint256"}],"name":"notifyRewardAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_rewardToken","type":"address"},{"internalType":"uint256","name":"reward","type":"uint256"}],"name":"notifyTargetRewardAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"periodFinish","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"periodFinishForToken","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"}],"name":"pushAllRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"rt","type":"address"}],"name":"removeRewardToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"rewardDistribution","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"i","type":"uint256"}],"name":"rewardPerToken","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardPerToken","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"rt","type":"address"}],"name":"rewardPerToken","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardPerTokenStored","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"rewardPerTokenStoredForToken","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"rewardRateForToken","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"rewardTokens","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardTokensLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"rewards","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"rewardsForToken","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"_newRewardDistribution","type":"address[]"},{"internalType":"bool","name":"_flag","type":"bool"}],"name":"setRewardDistribution","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_store","type":"address"}],"name":"setStorage","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"stake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"stakedBalanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"store","outputs":[{"internalType":"contract Storage","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"userRewardPerTokenPaid","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"userRewardPerTokenPaidForToken","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"}]