RushMars vs PantherSwap MasterChef Diff

/**
/**
*Submitted for verification at BscScan.com on 2021-04-23
*Submitted for verification at BscScan.com on 2021-06-03
*/
*/
// RushMars PROJECT, Farm Contract, https://rushmars.finance
// SPDX-License-Identifier: MIT
// SPDX-License-Identifier: MIT
// File: @uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol
// File: @uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol
pragma solidity >=0.5.0;
pragma solidity >=0.5.0;
interface IUniswapV2Factory {
interface IUniswapV2Factory {
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
function feeTo() external view returns (address);
function feeTo() external view returns (address);
function feeToSetter() external view returns (address);
function feeToSetter() external view returns (address);
function getPair(address tokenA, address tokenB) external view returns (address pair);
function getPair(address tokenA, address tokenB) external view returns (address pair);
function allPairs(uint) external view returns (address pair);
function allPairs(uint) external view returns (address pair);
function allPairsLength() external view returns (uint);
function allPairsLength() external view returns (uint);
function createPair(address tokenA, address tokenB) external returns (address pair);
function createPair(address tokenA, address tokenB) external returns (address pair);
function setFeeTo(address) external;
function setFeeTo(address) external;
function setFeeToSetter(address) external;
function setFeeToSetter(address) external;
}
}
// File: @uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol
// File: @uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol
pragma solidity >=0.5.0;
pragma solidity >=0.5.0;
interface IUniswapV2Pair {
interface IUniswapV2Pair {
event Approval(address indexed owner, address indexed spender, uint value);
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
event Transfer(address indexed from, address indexed to, uint value);
function name() external pure returns (string memory);
function name() external pure returns (string memory);
function symbol() external pure returns (string memory);
function symbol() external pure returns (string memory);
function decimals() external pure returns (uint8);
function decimals() external pure returns (uint8);
function totalSupply() external view returns (uint);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint value) external returns (bool);
function approve(address spender, uint value) external returns (bool);
function transfer(address to, uint value) external returns (bool);
function transfer(address to, uint value) external returns (bool);
function transferFrom(address from, address to, uint value) external returns (bool);
function transferFrom(address from, address to, uint value) external returns (bool);
function DOMAIN_SEPARATOR() external view returns (bytes32);
function DOMAIN_SEPARATOR() external view returns (bytes32);
function PERMIT_TYPEHASH() external pure returns (bytes32);
function PERMIT_TYPEHASH() external pure returns (bytes32);
function nonces(address owner) external view returns (uint);
function nonces(address owner) external view returns (uint);
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
event Mint(address indexed sender, uint amount0, uint amount1);
event Mint(address indexed sender, uint amount0, uint amount1);
event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
event Swap(
event Swap(
address indexed sender,
address indexed sender,
uint amount0In,
uint amount0In,
uint amount1In,
uint amount1In,
uint amount0Out,
uint amount0Out,
uint amount1Out,
uint amount1Out,
address indexed to
address indexed to
);
);
event Sync(uint112 reserve0, uint112 reserve1);
event Sync(uint112 reserve0, uint112 reserve1);
function MINIMUM_LIQUIDITY() external pure returns (uint);
function MINIMUM_LIQUIDITY() external pure returns (uint);
function factory() external view returns (address);
function factory() external view returns (address);
function token0() external view returns (address);
function token0() external view returns (address);
function token1() external view returns (address);
function token1() external view returns (address);
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
function price0CumulativeLast() external view returns (uint);
function price0CumulativeLast() external view returns (uint);
function price1CumulativeLast() external view returns (uint);
function price1CumulativeLast() external view returns (uint);
function kLast() external view returns (uint);
function kLast() external view returns (uint);
function mint(address to) external returns (uint liquidity);
function mint(address to) external returns (uint liquidity);
function burn(address to) external returns (uint amount0, uint amount1);
function burn(address to) external returns (uint amount0, uint amount1);
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
function skim(address to) external;
function skim(address to) external;
function sync() external;
function sync() external;
function initialize(address, address) external;
function initialize(address, address) external;
}
}
// File: @uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router01.sol
// File: @uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router01.sol
pragma solidity >=0.6.2;
pragma solidity >=0.6.2;
interface IUniswapV2Router01 {
interface IUniswapV2Router01 {
function factory() external pure returns (address);
function factory() external pure returns (address);
function WETH() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidity(
function addLiquidity(
address tokenA,
address tokenA,
address tokenB,
address tokenB,
uint amountADesired,
uint amountADesired,
uint amountBDesired,
uint amountBDesired,
uint amountAMin,
uint amountAMin,
uint amountBMin,
uint amountBMin,
address to,
address to,
uint deadline
uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
) external returns (uint amountA, uint amountB, uint liquidity);
function addLiquidityETH(
function addLiquidityETH(
address token,
address token,
uint amountTokenDesired,
uint amountTokenDesired,
uint amountTokenMin,
uint amountTokenMin,
uint amountETHMin,
uint amountETHMin,
address to,
address to,
uint deadline
uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
function removeLiquidity(
function removeLiquidity(
address tokenA,
address tokenA,
address tokenB,
address tokenB,
uint liquidity,
uint liquidity,
uint amountAMin,
uint amountAMin,
uint amountBMin,
uint amountBMin,
address to,
address to,
uint deadline
uint deadline
) external returns (uint amountA, uint amountB);
) external returns (uint amountA, uint amountB);
function removeLiquidityETH(
function removeLiquidityETH(
address token,
address token,
uint liquidity,
uint liquidity,
uint amountTokenMin,
uint amountTokenMin,
uint amountETHMin,
uint amountETHMin,
address to,
address to,
uint deadline
uint deadline
) external returns (uint amountToken, uint amountETH);
) external returns (uint amountToken, uint amountETH);
function removeLiquidityWithPermit(
function removeLiquidityWithPermit(
address tokenA,
address tokenA,
address tokenB,
address tokenB,
uint liquidity,
uint liquidity,
uint amountAMin,
uint amountAMin,
uint amountBMin,
uint amountBMin,
address to,
address to,
uint deadline,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountA, uint amountB);
) external returns (uint amountA, uint amountB);
function removeLiquidityETHWithPermit(
function removeLiquidityETHWithPermit(
address token,
address token,
uint liquidity,
uint liquidity,
uint amountTokenMin,
uint amountTokenMin,
uint amountETHMin,
uint amountETHMin,
address to,
address to,
uint deadline,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountToken, uint amountETH);
) external returns (uint amountToken, uint amountETH);
function swapExactTokensForTokens(
function swapExactTokensForTokens(
uint amountIn,
uint amountIn,
uint amountOutMin,
uint amountOutMin,
address[] calldata path,
address[] calldata path,
address to,
address to,
uint deadline
uint deadline
) external returns (uint[] memory amounts);
) external returns (uint[] memory amounts);
function swapTokensForExactTokens(
function swapTokensForExactTokens(
uint amountOut,
uint amountOut,
uint amountInMax,
uint amountInMax,
address[] calldata path,
address[] calldata path,
address to,
address to,
uint deadline
uint deadline
) external returns (uint[] memory amounts);
) external returns (uint[] memory amounts);
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
external
external
payable
payable
returns (uint[] memory amounts);
returns (uint[] memory amounts);
function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
external
external
returns (uint[] memory amounts);
returns (uint[] memory amounts);
function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
external
external
returns (uint[] memory amounts);
returns (uint[] memory amounts);
function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
external
external
payable
payable
returns (uint[] memory amounts);
returns (uint[] memory amounts);
function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
}
}
// File: @uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol
// File: @uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol
pragma solidity >=0.6.2;
pragma solidity >=0.6.2;
interface IUniswapV2Router02 is IUniswapV2Router01 {
interface IUniswapV2Router02 is IUniswapV2Router01 {
function removeLiquidityETHSupportingFeeOnTransferTokens(
function removeLiquidityETHSupportingFeeOnTransferTokens(
address token,
address token,
uint liquidity,
uint liquidity,
uint amountTokenMin,
uint amountTokenMin,
uint amountETHMin,
uint amountETHMin,
address to,
address to,
uint deadline
uint deadline
) external returns (uint amountETH);
) external returns (uint amountETH);
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
address token,
address token,
uint liquidity,
uint liquidity,
uint amountTokenMin,
uint amountTokenMin,
uint amountETHMin,
uint amountETHMin,
address to,
address to,
uint deadline,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountETH);
) external returns (uint amountETH);
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint amountIn,
uint amountIn,
uint amountOutMin,
uint amountOutMin,
address[] calldata path,
address[] calldata path,
address to,
address to,
uint deadline
uint deadline
) external;
) external;
function swapExactETHForTokensSupportingFeeOnTransferTokens(
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint amountOutMin,
uint amountOutMin,
address[] calldata path,
address[] calldata path,
address to,
address to,
uint deadline
uint deadline
) external payable;
) external payable;
function swapExactTokensForETHSupportingFeeOnTransferTokens(
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountIn,
uint amountOutMin,
uint amountOutMin,
address[] calldata path,
address[] calldata path,
address to,
address to,
uint deadline
uint deadline
) external;
) external;
}
}
// File: @openzeppelin/contracts/utils/ReentrancyGuard.sol
// File: @openzeppelin/contracts/utils/ReentrancyGuard.sol
pragma solidity >=0.6.0 <0.8.0;
pragma solidity >=0.6.0 <0.8.0;
/**
/**
* @dev Contract module that helps prevent reentrant calls to a function.
* @dev Contract module that helps prevent reentrant calls to a function.
*
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
* (reentrant) calls to them.
*
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* 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
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
* points to them.
*
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
*/
abstract contract ReentrancyGuard {
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private constant _ENTERED = 2;
uint256 private _status;
uint256 private _status;
constructor () internal {
constructor () internal {
_status = _NOT_ENTERED;
_status = _NOT_ENTERED;
}
}
/**
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and make it call a
* by making the `nonReentrant` function external, and make it call a
* `private` function that does the actual work.
* `private` function that does the actual work.
*/
*/
modifier nonReentrant() {
modifier nonReentrant() {
// On the first call to nonReentrant, _notEntered will be true
// On the first call to nonReentrant, _notEntered will be true
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
_status = _ENTERED;
_;
_;
// By storing the original value once again, a refund is triggered (see
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
_status = _NOT_ENTERED;
}
}
}
}
// File: @openzeppelin/contracts/utils/Context.sol
// File: @openzeppelin/contracts/utils/Context.sol
pragma solidity >=0.6.0 <0.8.0;
pragma solidity >=0.6.0 <0.8.0;
/*
/*
* @dev Provides information about the current execution context, including the
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* 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
* 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
* 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
* paying for execution may not be the actual sender (as far as an application
* is concerned).
* is concerned).
*
*
* This contract is only required for intermediate, library-like contracts.
* This contract is only required for intermediate, library-like contracts.
*/
*/
abstract contract Context {
abstract contract Context {
function _msgSender() internal view virtual returns (address payable) {
function _msgSender() internal view virtual returns (address payable) {
return msg.sender;
return msg.sender;
}
}
function _msgData() internal view virtual returns (bytes memory) {
function _msgData() internal view virtual returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
return msg.data;
}
}
}
}
// File: @openzeppelin/contracts/access/Ownable.sol
// File: @openzeppelin/contracts/access/Ownable.sol
pragma solidity >=0.6.0 <0.8.0;
pragma solidity >=0.6.0 <0.8.0;
/**
/**
* @dev Contract module which provides a basic access control mechanism, where
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
* specific functions.
*
*
* By default, the owner account will be the one that deploys the contract. This
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
* can later be changed with {transferOwnership}.
*
*
* This module is used through inheritance. It will make available the modifier
* 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
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
* the owner.
*/
*/
abstract contract Ownable is Context {
abstract contract Ownable is Context {
address private _owner;
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
/**
* @dev Initializes the contract setting the deployer as the initial owner.
* @dev Initializes the contract setting the deployer as the initial owner.
*/
*/
constructor () internal {
constructor () internal {
address msgSender = _msgSender();
address msgSender = _msgSender();
_owner = msgSender;
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
emit OwnershipTransferred(address(0), msgSender);
}
}
/**
/**
* @dev Returns the address of the current owner.
* @dev Returns the address of the current owner.
*/
*/
function owner() public view virtual returns (address) {
function owner() public view virtual returns (address) {
return _owner;
return _owner;
}
}
/**
/**
* @dev Throws if called by any account other than the owner.
* @dev Throws if called by any account other than the owner.
*/
*/
modifier onlyOwner() {
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
_;
}
}
/**
/**
* @dev Leaves the contract without owner. It will not be possible to call
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
* thereby removing any functionality that is only available to the owner.
*/
*/
function renounceOwnership() public virtual onlyOwner {
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
_owner = address(0);
}
}
/**
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
* Can only be called by the current owner.
*/
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
_owner = newOwner;
}
}
}
}
// File: contracts/libs/IPantherReferral.sol
// File: contracts/libs/IMarsReferral.sol
pragma solidity 0.6.12;
pragma solidity 0.6.12;
interface IPantherReferral {
interface IMarsReferral {
/**
/**
* @dev Record referral.
* @dev Record referral.
*/
*/
function recordReferral(address user, address referrer) external;
function recordReferral(address user, address referrer) external;
/**
/**
* @dev Record referral commission.
* @dev Record referral commission.
*/
*/
function recordReferralCommission(address referrer, uint256 commission) external;
function recordReferralCommission(address referrer, uint256 commission) external;
/**
/**
* @dev Get the referrer address that referred the user.
* @dev Get the referrer address that referred the user.
*/
*/
function getReferrer(address user) external view returns (address);
function getReferrer(address user) external view returns (address);
}
}
// File: @openzeppelin/contracts/utils/Address.sol
// File: @openzeppelin/contracts/utils/Address.sol
pragma solidity >=0.6.2 <0.8.0;
pragma solidity >=0.6.2 <0.8.0;
/**
/**
* @dev Collection of functions related to the address type
* @dev Collection of functions related to the address type
*/
*/
library Address {
library Address {
/**
/**
* @dev Returns true if `account` is a contract.
* @dev Returns true if `account` is a contract.
*
*
* [IMPORTANT]
* [IMPORTANT]
* ====
* ====
* It is unsafe to assume that an address for which this function returns
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
* false is an externally-owned account (EOA) and not a contract.
*
*
* Among others, `isContract` will return false for the following
* Among others, `isContract` will return false for the following
* types of addresses:
* types of addresses:
*
*
* - an externally-owned account
* - an externally-owned account
* - a contract in construction
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* - an address where a contract lived, but was destroyed
* ====
* ====
*/
*/
function isContract(address account) internal view returns (bool) {
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// construction, since the code is only stored at the end of the
// constructor execution.
// constructor execution.
uint256 size;
uint256 size;
// solhint-disable-next-line no-inline-assembly
// solhint-disable-next-line no-inline-assembly
assembly { size := extcodesize(account) }
assembly { size := extcodesize(account) }
return size > 0;
return size > 0;
}
}
/**
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
* `recipient`, forwarding all available gas and reverting on errors.
*
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
* `transfer`. {sendValue} removes this limitation.
*
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
* 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 {
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
require(success, "Address: unable to send value, recipient may have reverted");
}
}
/**
/**
* @dev Performs a Solidity function call using a low level `call`. A
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
* function instead.
*
*
* If `target` reverts with a revert reason, it is bubbled up by this
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
* function (like regular Solidity function calls).
*
*
* Returns the raw returned data. To convert to the expected return value,
* 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`].
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
*
* Requirements:
* Requirements:
*
*
* - `target` must be a contract.
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
* - calling `target` with `data` must not revert.
*
*
* _Available since v3.1._
* _Available since v3.1._
*/
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
return functionCall(target, data, "Address: low-level call failed");
}
}
/**
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
* `errorMessage` as a fallback revert reason when `target` reverts.
*
*
* _Available since v3.1._
* _Available since v3.1._
*/
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
return functionCallWithValue(target, data, 0, errorMessage);
}
}
/**
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
* but also transferring `value` wei to `target`.
*
*
* Requirements:
* Requirements:
*
*
* - the calling contract must have an ETH balance of at least `value`.
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
* - the called Solidity function must be `payable`.
*
*
* _Available since v3.1._
* _Available since v3.1._
*/
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
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");
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
}
/**
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
*
* _Available since v3.1._
* _Available since v3.1._
*/
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
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(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: value }(data);
(bool success, bytes memory returndata) = target.call{ value: value }(data);
return _verifyCallResult(success, returndata, errorMessage);
return _verifyCallResult(success, returndata, errorMessage);
}
}
/**
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
* but performing a static call.
*
*
* _Available since v3.3._
* _Available since v3.3._
*/
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
return functionStaticCall(target, data, "Address: low-level static call failed");
}
}
/**
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
* but performing a static call.
*
*
* _Available since v3.3._
* _Available since v3.3._
*/
*/
function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
require(isContract(target), "Address: static call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.staticcall(data);
(bool success, bytes memory returndata) = target.staticcall(data);
return _verifyCallResult(success, returndata, errorMessage);
return _verifyCallResult(success, returndata, errorMessage);
}
}
/**
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
* but performing a delegate call.
*
*
* _Available since v3.4._
* _Available since v3.4._
*/
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
}
/**
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
* but performing a delegate call.
*
*
* _Available since v3.4._
* _Available since v3.4._
*/
*/
function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
require(isContract(target), "Address: delegate call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.delegatecall(data);
(bool success, bytes memory returndata) = target.delegatecall(data);
return _verifyCallResult(success, returndata, errorMessage);
return _verifyCallResult(success, returndata, errorMessage);
}
}
function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
if (success) {
if (success) {
return returndata;
return returndata;
} else {
} else {
// Look for revert reason and bubble it up if present
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
// solhint-disable-next-line no-inline-assembly
assembly {
assembly {
let returndata_size := mload(returndata)
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
revert(add(32, returndata), returndata_size)
}
}
} else {
} else {
revert(errorMessage);
revert(errorMessage);
}
}
}
}
}
}
}
}
// File: contracts/libs/SafeBEP20.sol
// File: contracts/libs/SafeBEP20.sol
pragma solidity ^0.6.0;
pragma solidity ^0.6.0;
/**
/**
* @title SafeBEP20
* @title SafeBEP20
* @dev Wrappers around BEP20 operations that throw on failure (when the token
* @dev Wrappers around BEP20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* 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
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* successful.
* To use this library you can add a `using SafeBEP20 for IBEP20;` statement to your contract,
* To use this library you can add a `using SafeBEP20 for IBEP20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
*/
library SafeBEP20 {
library SafeBEP20 {
using SafeMath for uint256;
using SafeMath for uint256;
using Address for address;
using Address for address;
function safeTransfer(
function safeTransfer(
IBEP20 token,
IBEP20 token,
address to,
address to,
uint256 value
uint256 value
) internal {
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
}
function safeTransferFrom(
function safeTransferFrom(
IBEP20 token,
IBEP20 token,
address from,
address from,
address to,
address to,
uint256 value
uint256 value
) internal {
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
}
/**
/**
* @dev Deprecated. This function has issues similar to the ones found in
* @dev Deprecated. This function has issues similar to the ones found in
* {IBEP20-approve}, and its usage is discouraged.
* {IBEP20-approve}, and its usage is discouraged.
*
*
* Whenever possible, use {safeIncreaseAllowance} and
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
* {safeDecreaseAllowance} instead.
*/
*/
function safeApprove(
function safeApprove(
IBEP20 token,
IBEP20 token,
address spender,
address spender,
uint256 value
uint256 value
) internal {
) internal {
// safeApprove should only be called when setting an initial allowance,
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
// solhint-disable-next-line max-line-length
// solhint-disable-next-line max-line-length
require(
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeBEP20: approve from non-zero to non-zero allowance"
"SafeBEP20: approve from non-zero to non-zero allowance"
);
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
}
function safeIncreaseAllowance(
function safeIncreaseAllowance(
IBEP20 token,
IBEP20 token,
address spender,
address spender,
uint256 value
uint256 value
) internal {
) internal {
uint256 newAllowance = token.allowance(address(this), spender).add(value);
uint256 newAllowance = token.allowance(address(this), spender).add(value);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
function safeDecreaseAllowance(
function safeDecreaseAllowance(
IBEP20 token,
IBEP20 token,
address spender,
address spender,
uint256 value
uint256 value
) internal {
) internal {
uint256 newAllowance = token.allowance(address(this), spender).sub(
uint256 newAllowance = token.allowance(address(this), spender).su
value,
"SafeBEP20: decreas