Contract Address Details

0xcC253026d4582f321C5F49c6517C28533EBF7B55

BonusFarmFactory Last Balance Update: Block #701479
Created by 0xf8bd27–2e5ab8 at 0x7f2534–26d8d1

Balance

0 Ether

Fetching tokens...

This contract has been verified via Sourcify. View contract in Sourcify repository
Contract name:
BonusFarmFactory




Optimization enabled
true
Compiler version
v0.6.12+commit.27d51765




Optimization runs
200
EVM Version
istanbul




Verified at
2021-12-21 08:39:43.016282Z

Contract source code

// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.6.12;
import "../common/Ownable.sol";
import "../interfaces/IOolongFarm.sol";
import "./BonusFarm.sol";
contract BonusFarmFactory is Ownable {
/* ======== STATE VARIABLS ======== */
IOolongFarm public parentFarm;
mapping(uint => address) public pidToFarm;
address[] public allFarms;
/* ======== EVENTS ======== */
event NewFarm(address _bonusFarm, address indexed _rewardsToken, uint _rewardsDuration, uint _pid, address _creator);
/* ======== CONSTRUCTOR ======== */
constructor(IOolongFarm _parentFarm) public {
parentFarm = _parentFarm;
}
/* ======== VIEWS ======== */
function allFarmsLength() external view returns (uint) {
return allFarms.length;
}
/* ======== MUTATIVES ======== */
function createBonusFarm(
address _rewardsToken,
uint _rewardsDuration,
uint _pid
)
external
returns (address)
{
BonusFarm bonusFarm = new BonusFarm(_rewardsToken, _rewardsDuration, parentFarm, _pid, owner());
_addBonusFarm(_pid, address(bonusFarm));
emit NewFarm(address(bonusFarm), _rewardsToken, _rewardsDuration, _pid, msg.sender);
return address(bonusFarm);
}
function _addBonusFarm(uint _pid, address _bonusFarm) internal {
require(pidToFarm[_pid] == address(0), "bonus farm already created");
pidToFarm[_pid] = _bonusFarm;
allFarms.push(_bonusFarm);
}
/* ======== ADMIN FUNCTIONS ======== */
function addBonusFarm(uint _pid, address _bonusFarm) external onlyOwner {
_addBonusFarm(_pid, _bonusFarm);
}
function removeBonusFarm(uint _pid) external onlyOwner {
require(pidToFarm[_pid] != address(0), "farm does not exist");
// find the index
uint indexToDelete = 0;
bool found = false;
for (uint i = 0; i < allFarms.length; i++) {
if (allFarms[i] == pidToFarm[_pid]) {
indexToDelete = i;
found = true;
break;
}
}
// remove element from list
require(found == true, "farm not found in list");
allFarms[indexToDelete] = allFarms[allFarms.length - 1];
allFarms.pop();
// clear from map
pidToFarm[_pid] = address(0);
}
}

BonusFarm.sol

// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.6.12;
import "../common/Math.sol";
import "../common/SafeMath.sol";
import "../common/IERC20.sol";
import "../common/SafeERC20.sol";
import "../common/ReentrancyGuard.sol";
import "../interfaces/IOolongFarm.sol";
import "../interfaces/IBonusFarm.sol";
// Modified from Uniswap staking reward contract at https://etherscan.io/address/0x7FBa4B8Dc5E7616e59622806932DBea72537A56b#code
// with the following changes:
// - Made abstract
// - Remove stake and withdraw
// - getReward use input address instead of msg.sender
// - Read staking balance from parent farm
// - notifyRewardAmount updated to transferFrom msg.sender instead of using permissioned distributor
abstract contract BaseReward is ReentrancyGuard {
using SafeMath for uint256;
using SafeERC20 for IERC20;
/* ========== STATE VARIABLES ========== */
IERC20 public rewardsToken;
uint256 public periodFinish = 0;
uint256 public rewardRate = 0;
uint256 public rewardsDuration;
uint256 public lastUpdateTime;
uint256 public rewardPerTokenStored;
mapping(address => uint256) public userRewardPerTokenPaid;
mapping(address => uint256) public rewards;
/* ========== CONSTRUCTOR ========== */
constructor(
address _rewardsToken,
uint _rewardsDuration
) public {
rewardsToken = IERC20(_rewardsToken);
rewardsDuration = _rewardsDuration;
}
/* ========== VIRTUAL FUNCTIONS ========== */
function totalSupply() public virtual view returns (uint256);
function balanceOf(address _account) public virtual view returns (uint256);
/* ========== VIEWS ========== */
function lastTimeRewardApplicable() public view returns (uint256) {
return Math.min(block.timestamp, periodFinish);
}
function rewardPerToken() public view returns (uint256) {
if (totalSupply() == 0) {
return rewardPerTokenStored;
}
return
rewardPerTokenStored.add(
lastTimeRewardApplicable().sub(lastUpdateTime).mul(rewardRate).mul(1e18).div(totalSupply())
);
}
function earned(address _account) public view returns (uint256) {
return balanceOf(_account).mul(rewardPerToken().sub(userRewardPerTokenPaid[_account])).div(1e18).add(rewards[_account]);
}
function getRewardForDuration() external view returns (uint256) {
return rewardRate.mul(rewardsDuration);
}
/* ========== MUTATIVE FUNCTIONS ========== */
function notifyRewardAmount(uint256 _reward) external updateReward(address(0)) {
require(_reward > 0, "Cannot provide 0 reward");
rewardsToken.safeTransferFrom(msg.sender, address(this), _reward);
if (block.timestamp >= periodFinish) {
rewardRate = _reward.div(rewardsDuration);
} else {
uint256 remaining = periodFinish.sub(block.timestamp);
uint256 leftover = remaining.mul(rewardRate);
rewardRate = _reward.add(leftover).div(rewardsDuration);
}
// Ensure the provided reward amount is not more than the balance in the contract.
// This keeps the reward rate in the right range, preventing overflows due to
// very high values of rewardRate in the earned and rewardsPerToken functions;
// Reward + leftover must be less than 2^256 / 10^18 to avoid overflow.
uint balance = rewardsToken.balanceOf(address(this));
require(rewardRate <= balance.div(rewardsDuration), "Provided reward too high");
lastUpdateTime = block.timestamp;
periodFinish = block.timestamp.add(rewardsDuration);
emit RewardAdded(_reward);
}
/* ========== INTERNAL FUNCTIONS ========== */
function getRewardFor(address _account) internal nonReentrant updateReward(_account) {
uint256 reward = rewards[_account];
if (reward > 0) {
rewards[_account] = 0;
rewardsToken.safeTransfer(_account, reward);
emit RewardPaid(_account, reward);
}
}
/* ========== MODIFIERS ========== */
modifier updateReward(address _account) {
rewardPerTokenStored = rewardPerToken();
lastUpdateTime = lastTimeRewardApplicable();
if (_account != address(0)) {
rewards[_account] = earned(_account);
userRewardPerTokenPaid[_account] = rewardPerTokenStored;
}
_;
}
/* ========== EVENTS ========== */
event RewardAdded(uint256 _reward);
event RewardPaid(address indexed _user, uint256 _reward);
}
// A farm contract to distribute rewards based on user balance of parent farm.
contract BonusFarm is IBonusFarm, BaseReward {
/* ========== STATES ========== */
address public governance;
IOolongFarm private parentFarm;
uint private parentPoolId;
IERC20 private parentStakingToken;
/* ========== CONSTRUCTOR ========== */
constructor(
address _rewardsToken,
uint _rewardsDuration,
IOolongFarm _parentFarm,
uint _parentPoolId,
address _governance
)
public
BaseReward(_rewardsToken, _rewardsDuration)
{
parentFarm = _parentFarm;
parentPoolId = _parentPoolId;
(address lpToken_, , , , ) = _parentFarm.poolInfo(_parentPoolId);
parentStakingToken = IERC20(lpToken_);
governance = _governance;
}
/* ========== VIEWS ========== */
function getParentFarm() external override view returns(address) {
return address(parentFarm);
}
function getParentPoolId() external override view returns(uint) {
return parentPoolId;
}
function getParentStakingToken() external override view returns(address) {
return address(parentStakingToken);
}
function totalSupply() public override view returns (uint) {
return parentStakingToken.balanceOf(address(parentFarm));
}
function balanceOf(address _account) public override view returns (uint) {
(uint balance, ) = parentFarm.userInfo(parentPoolId, _account);
return balance;
}
/* ========== MUTATIVE FUNCTIONS ========== */
// Called by parent farm during reward claim
function onParentReward(address _account) external override onlyParentFarm {
getRewardFor(_account);
}
/* ========== RESTRICTED FUNCTIONS ========== */
// Allow governance to rescue unclaimed reward after the bonus farm has been retired
function rescue(address _token) external onlyGov {
if (_token == address(rewardsToken)) {
// If parents BonusFarm reference is no longer address(this)
// It should mean this farm has been retired, and is safe to rescue
( , , , , address _bonusFarm) = parentFarm.poolInfo(parentPoolId);
require(_bonusFarm != address(this), "!retired");
}
uint _balance = IERC20(_token).balanceOf(address(this));
IERC20(_token).safeTransfer(governance, _balance);
}
function setGovernance(address _governance)
external
onlyGov
{
governance = _governance;
}
/* ========== MODIFIERS ========== */
modifier onlyParentFarm() {
require(msg.sender == address(parentFarm), "!parent");
_;
}
modifier onlyGov() {
require(msg.sender == governance, "!governance");
_;
}
}

IOolongFarm.sol

// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.6.12;
interface IOolongFarm {
function poolInfo(uint _poolId) external view returns (address _lpToken, uint _allocPoint, uint _lastRewardTimestamp, uint _accOolongPerShare, address _bonusFarm);
function userInfo(uint _poolId, address _user) external view returns (uint _balance, uint _rewardDebt);
function deposit(uint256 _pid, uint256 _amount) external;
function withdraw(uint256 _pid, uint256 _amount) external;
function pendingOolong(uint256 _pid, address _user) external view returns (uint256);
}

IBonusFarm.sol

// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.6.12;
interface IBonusFarm {
function onParentReward(address _account) external;
function getParentFarm() external view returns(address);
function getParentPoolId() external view returns(uint);
function getParentStakingToken() external view returns(address);
}

SafeMath.sol

// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.6.12;
/**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
}

SafeERC20.sol

// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.6.12;
import "./IERC20.sol";
import "./SafeMath.sol";
import "./Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
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));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(IERC20 token, address spender, uint256 value) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
// solhint-disable-next-line max-line-length
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));
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) { // Return data is optional
// solhint-disable-next-line max-line-length
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}

ReentrancyGuard.sol

// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.6.12;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the `nonReentrant` modifier
* available, which can be aplied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*/
contract ReentrancyGuard {
/// @dev counter to allow mutex lock with only one SSTORE operation
uint256 private _guardCounter;
constructor () internal {
// The counter starts at one to prevent changing it from zero to a non-zero
// value, which is a more expensive operation.
_guardCounter = 1;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and make it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_guardCounter += 1;
uint256 localCounter = _guardCounter;
_;
require(localCounter == _guardCounter, "ReentrancyGuard: reentrant call");
}
}

Ownable.sol

// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.6.12;
import "./Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}

Math.sol

// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.6.12;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a >= b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow, so we distribute
return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2);
}
}

IERC20.sol

// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.6.12;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}

Context.sol

// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.6.12;
/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with GSN meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address payable) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}

Address.sol

// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.6.12;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
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");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
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");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}

Contract ABI

[{"type":"constructor","stateMutability":"nonpayable","inputs":[{"type":"address","name":"_parentFarm","internalType":"contract IOolongFarm"}]},{"type":"event","name":"NewFarm","inputs":[{"type":"address","name":"_bonusFarm","internalType":"address","indexed":false},{"type":"address","name":"_rewardsToken","internalType":"address","indexed":true},{"type":"uint256","name":"_rewardsDuration","internalType":"uint256","indexed":false},{"type":"uint256","name":"_pid","internalType":"uint256","indexed":false},{"type":"address","name":"_creator","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"OwnershipTransferred","inputs":[{"type":"address","name":"previousOwner","internalType":"address","indexed":true},{"type":"address","name":"newOwner","internalType":"address","indexed":true}],"anonymous":false},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"addBonusFarm","inputs":[{"type":"uint256","name":"_pid","internalType":"uint256"},{"type":"address","name":"_bonusFarm","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"allFarms","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"allFarmsLength","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"createBonusFarm","inputs":[{"type":"address","name":"_rewardsToken","internalType":"address"},{"type":"uint256","name":"_rewardsDuration","internalType":"uint256"},{"type":"uint256","name":"_pid","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract IOolongFarm"}],"name":"parentFarm","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"pidToFarm","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"removeBonusFarm","inputs":[{"type":"uint256","name":"_pid","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceOwnership","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"newOwner","internalType":"address"}]}]
            

Deployed ByteCode

0x608060405234801561001057600080fd5b506004361061009e5760003560e01c80638651984411610066578063865198441461013a5780638da5cb5b14610157578063e3174ddd1461015f578063e870bb0c1461018b578063f2fde38b146101a85761009e565b80632a7b7754146100a357806343acb9a9146100c757806345e46227146100e4578063715018a6146101165780637bc6d44314610120575b600080fd5b6100ab6101ce565b604080516001600160a01b039092168252519081900360200190f35b6100ab600480360360208110156100dd57600080fd5b50356101dd565b6100ab600480360360608110156100fa57600080fd5b506001600160a01b038135169060208101359060400135610204565b61011e6102f4565b005b610128610396565b60408051918252519081900360200190f35b61011e6004803603602081101561015057600080fd5b503561039c565b6100ab6105be565b61011e6004803603604081101561017557600080fd5b50803590602001356001600160a01b03166105cd565b6100ab600480360360208110156101a157600080fd5b5035610633565b61011e600480360360208110156101be57600080fd5b50356001600160a01b031661064e565b6001546001600160a01b031681565b600381815481106101ea57fe5b6000918252602090912001546001600160a01b0316905081565b6001546000908190859085906001600160a01b0316856102226105be565b60405161022e9061081c565b80866001600160a01b03168152602001858152602001846001600160a01b03168152602001838152602001826001600160a01b0316815260200195505050505050604051809103906000f08015801561028b573d6000803e3d6000fd5b5090506102988382610746565b604080516001600160a01b038381168252602082018790528183018690523360608301529151918716917f514d6879f1aec4aa5e638300f55dc37cf0148ecb71f405adf94921a094a22e299181900360800190a2949350505050565b6102fc610818565b6000546001600160a01b0390811691161461034c576040805162461bcd60e51b81526020600482018190526024820152600080516020611b42833981519152604482015290519081900360640190fd5b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b60035490565b6103a4610818565b6000546001600160a01b039081169116146103f4576040805162461bcd60e51b81526020600482018190526024820152600080516020611b42833981519152604482015290519081900360640190fd5b6000818152600260205260409020546001600160a01b0316610453576040805162461bcd60e51b815260206004820152601360248201527219985c9b48191bd95cc81b9bdd08195e1a5cdd606a1b604482015290519081900360640190fd5b60008060005b6003548110156104bb57600084815260026020526040902054600380546001600160a01b03909216918390811061048c57fe5b6000918252602090912001546001600160a01b031614156104b357809250600191506104bb565b600101610459565b5060018115151461050c576040805162461bcd60e51b815260206004820152601660248201527519985c9b481b9bdd08199bdd5b99081a5b881b1a5cdd60521b604482015290519081900360640190fd5b60038054600019810190811061051e57fe5b600091825260209091200154600380546001600160a01b03909216918490811061054457fe5b9060005260206000200160006101000a8154816001600160a01b0302191690836001600160a01b03160217905550600380548061057d57fe5b60008281526020808220830160001990810180546001600160a01b031990811690915593019093559485526002909152604090932080549093169092555050565b6000546001600160a01b031690565b6105d5610818565b6000546001600160a01b03908116911614610625576040805162461bcd60e51b81526020600482018190526024820152600080516020611b42833981519152604482015290519081900360640190fd5b61062f8282610746565b5050565b6002602052600090815260409020546001600160a01b031681565b610656610818565b6000546001600160a01b039081169116146106a6576040805162461bcd60e51b81526020600482018190526024820152600080516020611b42833981519152604482015290519081900360640190fd5b6001600160a01b0381166106eb5760405162461bcd60e51b8152600401808060200182810382526026815260200180611b1c6026913960400191505060405180910390fd5b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b6000828152600260205260409020546001600160a01b0316156107b0576040805162461bcd60e51b815260206004820152601a60248201527f626f6e7573206661726d20616c72656164792063726561746564000000000000604482015290519081900360640190fd5b600091825260026020526040822080546001600160a01b039092166001600160a01b031992831681179091556003805460018101825593527fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b90920180549091169091179055565b3390565b6112f28061082a8339019056fe60806040526000600255600060035534801561001a57600080fd5b506040516112f23803806112f2833981810160405260a081101561003d57600080fd5b508051602082015160408084015160608501516080909501516001600081815581546001600160a01b038089166001600160a01b0319928316179093556004878155600a8054948716949092168417909155600b8990558551631526fe2760e01b815290810189905294519697959693959492939092631526fe279160248083019260a0929190829003018186803b1580156100d857600080fd5b505afa1580156100ec573d6000803e3d6000fd5b505050506040513d60a081101561010257600080fd5b5051600c80546001600160a01b039283166001600160a01b031991821617909155600980549490921693169290921790915550505050506111aa806101486000396000f3fe608060405234801561001057600080fd5b50600436106101415760003560e01c806380faa57d116100b8578063ab033ea91161007c578063ab033ea9146102bf578063c8f33c91146102e5578063cd3daf9d146102ed578063d1af0c7d146102f5578063df136d65146102fd578063ebe2b12b1461030557610141565b806380faa57d1461023d578063839006f2146102455780638b8763471461026b5780638d0e39401461029157806395a216271461029957610141565b80632263b0a11161010a5780632263b0a1146101bc578063386a9525146101e05780633c6b16ab146101e85780635aa6e6751461020757806370a082311461020f5780637b0a47ee1461023557610141565b80628cc262146101465780630700037d1461017e578063170bc338146101a457806318160ddd146101ac5780631c1f78eb146101b4575b600080fd5b61016c6004803603602081101561015c57600080fd5b50356001600160a01b031661030d565b60408051918252519081900360200190f35b61016c6004803603602081101561019457600080fd5b50356001600160a01b031661037b565b61016c61038d565b61016c610394565b61016c610419565b6101c4610437565b604080516001600160a01b039092168252519081900360200190f35b61016c610446565b610205600480360360208110156101fe57600080fd5b503561044c565b005b6101c46106a3565b61016c6004803603602081101561022557600080fd5b50356001600160a01b03166106b2565b61016c61073c565b61016c610742565b6102056004803603602081101561025b57600080fd5b50356001600160a01b0316610750565b61016c6004803603602081101561028157600080fd5b50356001600160a01b031661091a565b6101c461092c565b610205600480360360208110156102af57600080fd5b50356001600160a01b031661093b565b610205600480360360208110156102d557600080fd5b50356001600160a01b0316610990565b61016c6109ff565b61016c610a05565b6101c4610a53565b61016c610a62565b61016c610a68565b6001600160a01b0381166000908152600860209081526040808320546007909252822054610375919061036f90670de0b6b3a7640000906103699061035a90610354610a05565b90610a6e565b610363886106b2565b90610ab7565b90610b10565b90610b52565b92915050565b60086020526000908152604090205481565b600b545b90565b600c54600a54604080516370a0823160e01b81526001600160a01b039283166004820152905160009392909216916370a0823191602480820192602092909190829003018186803b1580156103e857600080fd5b505afa1580156103fc573d6000803e3d6000fd5b505050506040513d602081101561041257600080fd5b5051905090565b6000610432600454600354610ab790919063ffffffff16565b905090565b600a546001600160a01b031690565b60045481565b6000610456610a05565b600655610461610742565b6005556001600160a01b038116156104a85761047c8161030d565b6001600160a01b0382166000908152600860209081526040808320939093556006546007909152919020555b600082116104fd576040805162461bcd60e51b815260206004820152601760248201527f43616e6e6f742070726f76696465203020726577617264000000000000000000604482015290519081900360640190fd5b600154610515906001600160a01b0316333085610bac565b60025442106105345760045461052c908390610b10565b600355610577565b6002546000906105449042610a6e565b9050600061055d60035483610ab790919063ffffffff16565b600454909150610571906103698684610b52565b60035550505b600154604080516370a0823160e01b815230600482015290516000926001600160a01b0316916370a08231916024808301926020929190829003018186803b1580156105c257600080fd5b505afa1580156105d6573d6000803e3d6000fd5b505050506040513d60208110156105ec57600080fd5b50516004549091506105ff908290610b10565b6003541115610655576040805162461bcd60e51b815260206004820152601860248201527f50726f76696465642072657761726420746f6f20686967680000000000000000604482015290519081900360640190fd5b4260058190556004546106689190610b52565b6002556040805184815290517fde88a922e0d3b88b24e9623efeb464919c6bf9f66857a65e2bfcf2ce87a9433d9181900360200190a1505050565b6009546001600160a01b031681565b600a54600b54604080516393f1a40b60e01b815260048101929092526001600160a01b038481166024840152815160009485949216926393f1a40b9260448082019391829003018186803b15801561070957600080fd5b505afa15801561071d573d6000803e3d6000fd5b505050506040513d604081101561073357600080fd5b50519392505050565b60035481565b600061043242600254610c0c565b6009546001600160a01b0316331461079d576040805162461bcd60e51b815260206004820152600b60248201526a21676f7665726e616e636560a81b604482015290519081900360640190fd5b6001546001600160a01b038281169116141561087e57600a54600b5460408051631526fe2760e01b81526004810192909252516000926001600160a01b031691631526fe279160248083019260a0929190829003018186803b15801561080257600080fd5b505afa158015610816573d6000803e3d6000fd5b505050506040513d60a081101561082c57600080fd5b506080015190506001600160a01b03811630141561087c576040805162461bcd60e51b8152602060048201526008602482015267085c995d1a5c995960c21b604482015290519081900360640190fd5b505b6000816001600160a01b03166370a08231306040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b1580156108cd57600080fd5b505afa1580156108e1573d6000803e3d6000fd5b505050506040513d60208110156108f757600080fd5b5051600954909150610916906001600160a01b03848116911683610c22565b5050565b60076020526000908152604090205481565b600c546001600160a01b031690565b600a546001600160a01b03163314610984576040805162461bcd60e51b8152602060048201526007602482015266085c185c995b9d60ca1b604482015290519081900360640190fd5b61098d81610c79565b50565b6009546001600160a01b031633146109dd576040805162461bcd60e51b815260206004820152600b60248201526a21676f7665726e616e636560a81b604482015290519081900360640190fd5b600980546001600160a01b0319166001600160a01b0392909216919091179055565b60055481565b6000610a0f610394565b610a1c5750600654610391565b610432610a4a610a2a610394565b610369670de0b6b3a7640000610363600354610363600554610354610742565b60065490610b52565b6001546001600160a01b031681565b60065481565b60025481565b6000610ab083836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250610dbf565b9392505050565b600082610ac657506000610375565b82820282848281610ad357fe5b0414610ab05760405162461bcd60e51b815260040180806020018281038252602181526020018061112a6021913960400191505060405180910390fd5b6000610ab083836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250610e56565b600082820183811015610ab0576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b604080516001600160a01b0380861660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b179052610c06908590610ebb565b50505050565b6000818310610c1b5781610ab0565b5090919050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b179052610c74908490610ebb565b505050565b600080546001019081905581610c8d610a05565b600655610c98610742565b6005556001600160a01b03811615610cdf57610cb38161030d565b6001600160a01b0382166000908152600860209081526040808320939093556006546007909152919020555b6001600160a01b0383166000908152600860205260409020548015610d67576001600160a01b03808516600090815260086020526040812055600154610d2791168583610c22565b6040805182815290516001600160a01b038616917fe2403640ba68fed3a2f88b7557551d1993f84b99bb10ff833f0cf8db0c5e0486919081900360200190a25b50506000548114610916576040805162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b60008184841115610e4e5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015610e13578181015183820152602001610dfb565b50505050905090810190601f168015610e405780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b60008183610ea55760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315610e13578181015183820152602001610dfb565b506000838581610eb157fe5b0495945050505050565b6060610f10826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316610f6c9092919063ffffffff16565b805190915015610c7457808060200190516020811015610f2f57600080fd5b5051610c745760405162461bcd60e51b815260040180806020018281038252602a81526020018061114b602a913960400191505060405180910390fd5b6060610f7b8484600085610f83565b949350505050565b6060610f8e856110f0565b610fdf576040805162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b60006060866001600160a01b031685876040518082805190602001908083835b6020831061101e5780518252601f199092019160209182019101610fff565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114611080576040519150601f19603f3d011682016040523d82523d6000602084013e611085565b606091505b50915091508115611099579150610f7b9050565b8051156110a95780518082602001fd5b60405162461bcd60e51b8152602060048201818152865160248401528651879391928392604401919085019080838360008315610e13578181015183820152602001610dfb565b6000813f7fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470818114801590610f7b57505015159291505056fe536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f775361666545524332303a204552433230206f7065726174696f6e20646964206e6f742073756363656564a2646970667358221220fe3382d22aafedb450483f814734538e9197e6779676fa1c24f298752cfccea564736f6c634300060c00334f776e61626c653a206e6577206f776e657220697320746865207a65726f20616464726573734f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572a2646970667358221220fdac9cdbdb5cb963dccf55c46f8595c1cd73032a91a12218b2c0bd4b5ffe799164736f6c634300060c0033