文件 1 的 10:Address.sol
pragma solidity ^0.7.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 的 10: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 的 10:DAOFarm.sol
pragma solidity =0.7.6;
pragma abicoder v2;
import "openzeppelin-contracts/math/SafeMath.sol";
import "openzeppelin-contracts/token/ERC20/SafeERC20.sol";
import "openzeppelin-contracts/token/ERC20/IERC20.sol";
import "openzeppelin-contracts/utils/EnumerableSet.sol";
import "openzeppelin-contracts/utils/ReentrancyGuard.sol";
import "openzeppelin-contracts/access/Ownable.sol";
import {IDAOFarmFactory} from "./DAOFarmFactory.sol";
contract DAOFarm is ReentrancyGuard, Ownable {
using EnumerableSet for EnumerableSet.UintSet;
using EnumerableSet for EnumerableSet.AddressSet;
using SafeERC20 for IERC20;
using SafeMath for uint256;
struct UserInfo {
uint256 totalDepositAmount;
uint256 rewardDebtToken1;
}
struct Settings {
uint256 startTime;
uint256 endTime;
}
struct RewardsToken {
IERC20 token;
uint256 amount;
uint256 remainingAmount;
uint256 accRewardsPerShare;
}
IDAOFarmFactory public factory;
uint256 public creationTime;
bool public emergencyClose;
IERC20 public depositToken;
RewardsToken public rewardsToken1;
uint256 public totalDepositAmount;
uint256 public lastRewardTime;
mapping(address => UserInfo) public userInfo;
Settings public settings;
constructor(address owner_, IERC20 depositToken_, IERC20 rewardsToken1_, Settings memory settings_) {
require(_currentBlockTimestamp() < settings_.startTime, "invalid startTime");
require(settings_.startTime < settings_.endTime, "invalid endTime");
factory = IDAOFarmFactory(msg.sender);
creationTime = _currentBlockTimestamp();
depositToken = depositToken_;
rewardsToken1.token = rewardsToken1_;
settings.startTime = settings_.startTime;
settings.endTime = settings_.endTime;
lastRewardTime = settings_.startTime;
Ownable.transferOwnership(owner_);
}
event ActivateEmergencyClose();
event AddRewardsToken1(uint256 amount, uint256 feeAmount);
event Deposit(address indexed userAddress, uint256 amount);
event Harvest(address indexed userAddress, IERC20 rewardsToken, uint256 pending);
event SetDateSettings(uint256 endTime);
event UpdatePool();
event Withdraw(address indexed userAddress, uint256 amount);
event EmergencyWithdraw(address indexed userAddress, uint256 amount);
event WithdrawRewardsToken1(uint256 amount, uint256 totalRewardsAmount);
function rewardsToken1PerSecond() public view returns (uint256) {
if (settings.endTime <= lastRewardTime) return 0;
return rewardsToken1.remainingAmount.div(settings.endTime.sub(lastRewardTime));
}
function pendingRewards(address account) external view returns (uint256 pending1) {
UserInfo memory user = userInfo[account];
uint256 accRewardsToken1PerShare_ = rewardsToken1.accRewardsPerShare;
if (lastRewardTime < _currentBlockTimestamp() && totalDepositAmount > 0) {
uint256 rewardsAmount = rewardsToken1PerSecond().mul(_currentBlockTimestamp().sub(lastRewardTime));
if (rewardsAmount > rewardsToken1.remainingAmount) rewardsAmount = rewardsToken1.remainingAmount;
accRewardsToken1PerShare_ = accRewardsToken1PerShare_.add(rewardsAmount.mul(1e18).div(totalDepositAmount));
}
pending1 = (user.totalDepositAmount.mul(accRewardsToken1PerShare_).div(1e18).sub(user.rewardDebtToken1));
}
function updatePool() external nonReentrant {
_updatePool();
}
function deposit(uint256 amount) external {
require((settings.endTime >= _currentBlockTimestamp()) && !emergencyClose, "not allowed");
uint256 balanceBefore = IERC20(depositToken).balanceOf(address(this));
IERC20(depositToken).transferFrom(msg.sender, address(this), amount);
_deposit(msg.sender, amount);
require(balanceBefore + amount >= IERC20(depositToken).balanceOf(address(this)), "Likely a fee on transfer error");
}
function withdraw(uint256 amount) external virtual nonReentrant {
_updatePool();
UserInfo storage user = userInfo[msg.sender];
require(user.totalDepositAmount >= amount, "Withdrawing too much");
_harvest(user, msg.sender);
user.totalDepositAmount = user.totalDepositAmount.sub(amount);
totalDepositAmount = totalDepositAmount.sub(amount);
_updateRewardDebt(user);
IERC20(depositToken).transfer(msg.sender, amount);
emit Withdraw(msg.sender, amount);
}
function emergencyWithdraw() external virtual nonReentrant {
UserInfo storage user = userInfo[msg.sender];
uint256 amount = user.totalDepositAmount;
user.totalDepositAmount = user.totalDepositAmount.sub(amount);
totalDepositAmount = totalDepositAmount.sub(amount);
_updateRewardDebt(user);
IERC20(depositToken).transfer(msg.sender, amount);
emit EmergencyWithdraw(msg.sender, amount);
}
function harvest() external nonReentrant {
_updatePool();
UserInfo storage user = userInfo[msg.sender];
_harvest(user, msg.sender);
_updateRewardDebt(user);
}
function transferOwnership(address newOwner) public override onlyOwner {
_setNitroPoolOwner(newOwner);
Ownable.transferOwnership(newOwner);
}
function renounceOwnership() public override onlyOwner {
_setNitroPoolOwner(address(0));
Ownable.renounceOwnership();
}
function addRewards(uint256 amountToken1) external nonReentrant {
require(_currentBlockTimestamp() < settings.endTime, "pool ended");
_updatePool();
uint256 feeShare = factory.getNitroPoolFee(address(this), owner());
address feeAddress = factory.feeAddress();
uint256 feeAmount;
if (amountToken1 > 0) {
feeAmount = amountToken1.mul(feeShare).div(10000);
amountToken1 =
_transferSupportingFeeOnTransfer(rewardsToken1.token, msg.sender, amountToken1.sub(feeAmount));
rewardsToken1.amount = rewardsToken1.amount.add(amountToken1);
rewardsToken1.remainingAmount = rewardsToken1.remainingAmount.add(amountToken1);
emit AddRewardsToken1(amountToken1, feeAmount);
if (feeAmount > 0) {
rewardsToken1.token.safeTransferFrom(msg.sender, feeAddress, feeAmount);
}
}
}
function withdrawRewards(uint256 amountToken1) external onlyOwner nonReentrant {
require(block.timestamp < settings.startTime);
if (amountToken1 > 0) {
rewardsToken1.amount = rewardsToken1.amount.sub(amountToken1, "too high");
rewardsToken1.remainingAmount = rewardsToken1.remainingAmount.sub(amountToken1, "too high");
emit WithdrawRewardsToken1(amountToken1, rewardsToken1.amount);
_safeRewardsTransfer(rewardsToken1.token, msg.sender, amountToken1);
}
}
function setDateSettings(uint256 endTime_) external nonReentrant onlyOwner {
require(settings.startTime < endTime_, "invalid endTime");
require(_currentBlockTimestamp() <= settings.endTime, "pool ended");
settings.endTime = endTime_;
emit SetDateSettings(endTime_);
}
function activateEmergencyClose() external nonReentrant onlyOwner {
address emergencyRecoveryAddress = factory.emergencyRecoveryAddress();
uint256 remainingToken1 = rewardsToken1.remainingAmount;
rewardsToken1.amount = rewardsToken1.amount.sub(remainingToken1);
rewardsToken1.remainingAmount = 0;
emergencyClose = true;
emit ActivateEmergencyClose();
_safeRewardsTransfer(rewardsToken1.token, emergencyRecoveryAddress, remainingToken1);
}
function _updatePool() internal {
uint256 currentBlockTimestamp = _currentBlockTimestamp();
if (currentBlockTimestamp <= lastRewardTime) return;
if (totalDepositAmount == 0) {
lastRewardTime = currentBlockTimestamp;
emit UpdatePool();
return;
}
uint256 rewardsAmount = rewardsToken1PerSecond().mul(currentBlockTimestamp.sub(lastRewardTime));
if (rewardsAmount > rewardsToken1.remainingAmount) rewardsAmount = rewardsToken1.remainingAmount;
rewardsToken1.remainingAmount = rewardsToken1.remainingAmount.sub(rewardsAmount);
rewardsToken1.accRewardsPerShare =
rewardsToken1.accRewardsPerShare.add(rewardsAmount.mul(1e18).div(totalDepositAmount));
lastRewardTime = currentBlockTimestamp;
emit UpdatePool();
}
function _deposit(address account, uint256 amount) internal {
_updatePool();
UserInfo storage user = userInfo[account];
_harvest(user, account);
user.totalDepositAmount = user.totalDepositAmount.add(amount);
totalDepositAmount = totalDepositAmount.add(amount);
_updateRewardDebt(user);
emit Deposit(account, amount);
}
function _harvest(UserInfo storage user, address to) internal {
uint256 pending =
user.totalDepositAmount.mul(rewardsToken1.accRewardsPerShare).div(1e18).sub(user.rewardDebtToken1);
_safeRewardsTransfer(rewardsToken1.token, to, pending);
emit Harvest(to, rewardsToken1.token, pending);
}
function _updateRewardDebt(UserInfo storage user) internal virtual {
(bool succeed, uint256 result) = user.totalDepositAmount.tryMul(rewardsToken1.accRewardsPerShare);
if (succeed) user.rewardDebtToken1 = result.div(1e18);
}
function _transferSupportingFeeOnTransfer(IERC20 token, address user, uint256 amount)
internal
returns (uint256 receivedAmount)
{
uint256 previousBalance = token.balanceOf(address(this));
token.safeTransferFrom(user, address(this), amount);
return token.balanceOf(address(this)).sub(previousBalance);
}
function _safeRewardsTransfer(IERC20 token, address to, uint256 amount) internal virtual {
if (amount == 0) return;
uint256 balance = token.balanceOf(address(this));
if (amount > balance) {
amount = balance;
}
token.safeTransfer(to, amount);
}
function _setNitroPoolOwner(address newOwner) internal {
factory.setNitroPoolOwner(owner(), newOwner);
}
function _currentBlockTimestamp() internal view virtual returns (uint256) {
return block.timestamp;
}
}
文件 4 的 10:DAOFarmFactory.sol
pragma solidity =0.7.6;
pragma abicoder v2;
import "openzeppelin-contracts/access/Ownable.sol";
import "openzeppelin-contracts/token/ERC20/IERC20.sol";
import "openzeppelin-contracts/utils/EnumerableSet.sol";
import "./DAOFarm.sol";
interface IDAOFarmFactory {
function emergencyRecoveryAddress() external view returns (address);
function feeAddress() external view returns (address);
function getNitroPoolFee(address nitroPoolAddress, address ownerAddress) external view returns (uint256);
function setNitroPoolOwner(address previousOwner, address newOwner) external;
}
contract DAOFarmFactory is Ownable, IDAOFarmFactory {
using EnumerableSet for EnumerableSet.AddressSet;
EnumerableSet.AddressSet internal _nitroPools;
mapping(address => EnumerableSet.AddressSet) internal _ownerNitroPools;
uint256 public constant MAX_DEFAULT_FEE = 500;
uint256 public defaultFee;
address public override feeAddress;
EnumerableSet.AddressSet internal _exemptedAddresses;
address public override emergencyRecoveryAddress;
constructor(address emergencyRecoveryAddress_, address feeAddress_) {
require(emergencyRecoveryAddress_ != address(0) && feeAddress_ != address(0), "invalid");
emergencyRecoveryAddress = emergencyRecoveryAddress_;
feeAddress = feeAddress_;
}
event CreateNitroPool(address nitroAddress);
event SetDefaultFee(uint256 fee);
event SetFeeAddress(address feeAddress);
event SetEmergencyRecoveryAddress(address emergencyRecoveryAddress);
event SetExemptedAddress(address exemptedAddress, bool isExempted);
event SetNitroPoolOwner(address previousOwner, address newOwner);
modifier nitroPoolExists(address nitroPoolAddress) {
require(_nitroPools.contains(nitroPoolAddress), "unknown nitroPool");
_;
}
function nitroPoolsLength() external view returns (uint256) {
return _nitroPools.length();
}
function getNitroPool(uint256 index) external view returns (address) {
return _nitroPools.at(index);
}
function ownerNitroPoolsLength(address userAddress) external view returns (uint256) {
return _ownerNitroPools[userAddress].length();
}
function getOwnerNitroPool(address userAddress, uint256 index) external view returns (address) {
return _ownerNitroPools[userAddress].at(index);
}
function exemptedAddressesLength() external view returns (uint256) {
return _exemptedAddresses.length();
}
function getExemptedAddress(uint256 index) external view returns (address) {
return _exemptedAddresses.at(index);
}
function isExemptedAddress(address checkedAddress) external view returns (bool) {
return _exemptedAddresses.contains(checkedAddress);
}
function getNitroPoolFee(address nitroPoolAddress, address ownerAddress) external view override returns (uint256) {
if (_exemptedAddresses.contains(nitroPoolAddress) || _exemptedAddresses.contains(ownerAddress)) {
return 0;
}
return defaultFee;
}
function createNitroPool(IERC20 depositToken, IERC20 rewardsToken1, DAOFarm.Settings calldata settings)
external
virtual
returns (address nitroPool)
{
nitroPool = address(new DAOFarm(msg.sender, depositToken, rewardsToken1, settings));
_nitroPools.add(nitroPool);
_ownerNitroPools[msg.sender].add(nitroPool);
emit CreateNitroPool(nitroPool);
}
function setNitroPoolOwner(address previousOwner, address newOwner) external override nitroPoolExists(msg.sender) {
require(_ownerNitroPools[previousOwner].remove(msg.sender), "invalid owner");
_ownerNitroPools[newOwner].add(msg.sender);
emit SetNitroPoolOwner(previousOwner, newOwner);
}
function setDefaultFee(uint256 newFee) external onlyOwner {
require(newFee <= MAX_DEFAULT_FEE, "invalid amount");
defaultFee = newFee;
emit SetDefaultFee(newFee);
}
function setFeeAddress(address feeAddress_) external onlyOwner {
require(feeAddress_ != address(0), "zero address");
feeAddress = feeAddress_;
emit SetFeeAddress(feeAddress_);
}
function setExemptedAddress(address exemptedAddress, bool isExempted) external onlyOwner {
require(exemptedAddress != address(0), "zero address");
if (isExempted) _exemptedAddresses.add(exemptedAddress);
else _exemptedAddresses.remove(exemptedAddress);
emit SetExemptedAddress(exemptedAddress, isExempted);
}
function setEmergencyRecoveryAddress(address emergencyRecoveryAddress_) external onlyOwner {
require(emergencyRecoveryAddress_ != address(0), "zero address");
emergencyRecoveryAddress = emergencyRecoveryAddress_;
emit SetEmergencyRecoveryAddress(emergencyRecoveryAddress_);
}
function _currentBlockTimestamp() internal view virtual returns (uint256) {
return block.timestamp;
}
}
文件 5 的 10:EnumerableSet.sol
pragma solidity ^0.7.0;
library EnumerableSet {
struct Set {
bytes32[] _values;
mapping (bytes32 => uint256) _indexes;
}
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
set._indexes[value] = set._values.length;
return true;
} else {
return false;
}
}
function _remove(Set storage set, bytes32 value) private returns (bool) {
uint256 valueIndex = set._indexes[value];
if (valueIndex != 0) {
uint256 toDeleteIndex = valueIndex - 1;
uint256 lastIndex = set._values.length - 1;
bytes32 lastvalue = set._values[lastIndex];
set._values[toDeleteIndex] = lastvalue;
set._indexes[lastvalue] = toDeleteIndex + 1;
set._values.pop();
delete set._indexes[value];
return true;
} else {
return false;
}
}
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._indexes[value] != 0;
}
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
function _at(Set storage set, uint256 index) private view returns (bytes32) {
require(set._values.length > index, "EnumerableSet: index out of bounds");
return set._values[index];
}
struct Bytes32Set {
Set _inner;
}
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
struct AddressSet {
Set _inner;
}
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
struct UintSet {
Set _inner;
}
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
}
文件 6 的 10:IERC20.sol
pragma solidity ^0.7.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);
}
文件 7 的 10:Ownable.sol
pragma solidity ^0.7.0;
import "../utils/Context.sol";
abstract 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 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;
}
}
文件 8 的 10:ReentrancyGuard.sol
pragma solidity ^0.7.0;
abstract contract ReentrancyGuard {
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor () {
_status = _NOT_ENTERED;
}
modifier nonReentrant() {
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
_status = _ENTERED;
_;
_status = _NOT_ENTERED;
}
}
文件 9 的 10:SafeERC20.sol
pragma solidity ^0.7.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");
}
}
}
文件 10 的 10:SafeMath.sol
pragma solidity ^0.7.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;
}
}
{
"compilationTarget": {
"src/DAOFarm.sol": "DAOFarm"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": [
":ds-test/=lib/forge-std/lib/ds-test/src/",
":forge-std/=lib/forge-std/src/",
":openzeppelin-contracts/=lib/openzeppelin-contracts/contracts/"
]
}
[{"inputs":[{"internalType":"address","name":"owner_","type":"address"},{"internalType":"contract IERC20","name":"depositToken_","type":"address"},{"internalType":"contract IERC20","name":"rewardsToken1_","type":"address"},{"components":[{"internalType":"uint256","name":"startTime","type":"uint256"},{"internalType":"uint256","name":"endTime","type":"uint256"}],"internalType":"struct DAOFarm.Settings","name":"settings_","type":"tuple"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[],"name":"ActivateEmergencyClose","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feeAmount","type":"uint256"}],"name":"AddRewardsToken1","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"userAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"userAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"EmergencyWithdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"userAddress","type":"address"},{"indexed":false,"internalType":"contract IERC20","name":"rewardsToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"pending","type":"uint256"}],"name":"Harvest","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":"uint256","name":"endTime","type":"uint256"}],"name":"SetDateSettings","type":"event"},{"anonymous":false,"inputs":[],"name":"UpdatePool","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"userAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Withdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"totalRewardsAmount","type":"uint256"}],"name":"WithdrawRewardsToken1","type":"event"},{"inputs":[],"name":"activateEmergencyClose","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountToken1","type":"uint256"}],"name":"addRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"creationTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"deposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"depositToken","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"emergencyClose","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"emergencyWithdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"contract IDAOFarmFactory","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"harvest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"lastRewardTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"pendingRewards","outputs":[{"internalType":"uint256","name":"pending1","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"rewardsToken1","outputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"remainingAmount","type":"uint256"},{"internalType":"uint256","name":"accRewardsPerShare","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardsToken1PerSecond","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"endTime_","type":"uint256"}],"name":"setDateSettings","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"settings","outputs":[{"internalType":"uint256","name":"startTime","type":"uint256"},{"internalType":"uint256","name":"endTime","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalDepositAmount","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":[],"name":"updatePool","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"userInfo","outputs":[{"internalType":"uint256","name":"totalDepositAmount","type":"uint256"},{"internalType":"uint256","name":"rewardDebtToken1","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountToken1","type":"uint256"}],"name":"withdrawRewards","outputs":[],"stateMutability":"nonpayable","type":"function"}]