|
|
|
|
|
|
|
|
|
pragma solidity ^0.8.0;
|
|
|
|
abstract contract Initializable {
|
|
|
|
|
|
|
|
bool private _initialized;
|
|
|
|
|
|
|
|
|
|
bool private _initializing;
|
|
|
|
|
|
|
|
|
|
modifier initializer() {
|
|
require(
|
|
_initializing || !_initialized,
|
|
"Initializable: contract is already initialized"
|
|
);
|
|
|
|
bool isTopLevelCall = !_initializing;
|
|
if (isTopLevelCall) {
|
|
_initializing = true;
|
|
_initialized = true;
|
|
}
|
|
|
|
_;
|
|
|
|
if (isTopLevelCall) {
|
|
_initializing = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
library SafeMathUpgradeable {
|
|
|
|
|
|
|
|
|
|
|
|
function tryAdd(uint256 a, uint256 b)
|
|
internal
|
|
pure
|
|
returns (bool, uint256)
|
|
{
|
|
unchecked {
|
|
uint256 c = a + b;
|
|
if (c < a) return (false, 0);
|
|
return (true, c);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function trySub(uint256 a, uint256 b)
|
|
internal
|
|
pure
|
|
returns (bool, uint256)
|
|
{
|
|
unchecked {
|
|
if (b > a) return (false, 0);
|
|
return (true, a - b);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function tryMul(uint256 a, uint256 b)
|
|
internal
|
|
pure
|
|
returns (bool, uint256)
|
|
{
|
|
unchecked {
|
|
|
|
|
|
|
|
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)
|
|
{
|
|
unchecked {
|
|
if (b == 0) return (false, 0);
|
|
return (true, a / b);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function tryMod(uint256 a, uint256 b)
|
|
internal
|
|
pure
|
|
returns (bool, uint256)
|
|
{
|
|
unchecked {
|
|
if (b == 0) return (false, 0);
|
|
return (true, a % b);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function add(uint256 a, uint256 b) internal pure returns (uint256) {
|
|
return a + b;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
|
|
return a - b;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
|
|
return a * b;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function div(uint256 a, uint256 b) internal pure returns (uint256) {
|
|
return a / b;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
|
|
return a % b;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function sub(
|
|
uint256 a,
|
|
uint256 b,
|
|
string memory errorMessage
|
|
) internal pure returns (uint256) {
|
|
unchecked {
|
|
require(b <= a, errorMessage);
|
|
return a - b;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function div(
|
|
uint256 a,
|
|
uint256 b,
|
|
string memory errorMessage
|
|
) internal pure returns (uint256) {
|
|
unchecked {
|
|
require(b > 0, errorMessage);
|
|
return a / b;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function mod(
|
|
uint256 a,
|
|
uint256 b,
|
|
string memory errorMessage
|
|
) internal pure returns (uint256) {
|
|
unchecked {
|
|
require(b > 0, errorMessage);
|
|
return a % b;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
pragma solidity >=0.6.4;
|
|
|
|
interface IBEP20Upgradeable {
|
|
|
|
|
|
|
|
function totalSupply() external view returns (uint256);
|
|
|
|
|
|
|
|
|
|
function decimals() external view returns (uint8);
|
|
|
|
|
|
|
|
|
|
function symbol() external view returns (string memory);
|
|
|
|
|
|
|
|
|
|
function name() external view returns (string memory);
|
|
|
|
|
|
|
|
|
|
function getOwner() external view returns (address);
|
|
|
|
|
|
|
|
|
|
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
|
|
);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library AddressUpgradeable {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 verifyCallResult(
|
|
bool success,
|
|
bytes memory returndata,
|
|
string memory errorMessage
|
|
) internal 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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
library SafeBEP20Upgradeable {
|
|
using SafeMathUpgradeable for uint256;
|
|
using AddressUpgradeable for address;
|
|
|
|
function safeTransfer(
|
|
IBEP20Upgradeable token,
|
|
address to,
|
|
uint256 value
|
|
) internal {
|
|
_callOptionalReturn(
|
|
token,
|
|
abi.encodeWithSelector(token.transfer.selector, to, value)
|
|
);
|
|
}
|
|
|
|
function safeTransferFrom(
|
|
IBEP20Upgradeable token,
|
|
address from,
|
|
address to,
|
|
uint256 value
|
|
) internal {
|
|
_callOptionalReturn(
|
|
token,
|
|
abi.encodeWithSelector(token.transferFrom.selector, from, to, value)
|
|
);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function safeApprove(
|
|
IBEP20Upgradeable token,
|
|
address spender,
|
|
uint256 value
|
|
) internal {
|
|
|
|
|
|
|
|
|
|
require(
|
|
(value == 0) || (token.allowance(address(this), spender) == 0),
|
|
"SafeBEP20: approve from non-zero to non-zero allowance"
|
|
);
|
|
_callOptionalReturn(
|
|
token,
|
|
abi.encodeWithSelector(token.approve.selector, spender, value)
|
|
);
|
|
}
|
|
|
|
function safeIncreaseAllowance(
|
|
IBEP20Upgradeable 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(
|
|
IBEP20Upgradeable token,
|
|
address spender,
|
|
uint256 value
|
|
) internal {
|
|
uint256 newAllowance = token.allowance(address(this), spender).sub(
|
|
value,
|
|
"SafeBEP20: decreased allowance below zero"
|
|
);
|
|
_callOptionalReturn(
|
|
token,
|
|
abi.encodeWithSelector(
|
|
token.approve.selector,
|
|
spender,
|
|
newAllowance
|
|
)
|
|
);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _callOptionalReturn(IBEP20Upgradeable token, bytes memory data)
|
|
private
|
|
{
|
|
|
|
|
|
|
|
|
|
bytes memory returndata = address(token).functionCall(
|
|
data,
|
|
"SafeBEP20: low-level call failed"
|
|
);
|
|
if (returndata.length > 0) {
|
|
|
|
|
|
require(
|
|
abi.decode(returndata, (bool)),
|
|
"SafeBEP20: BEP20 operation did not succeed"
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
abstract contract ContextUpgradeable is Initializable {
|
|
function __Context_init() internal initializer {
|
|
__Context_init_unchained();
|
|
}
|
|
|
|
function __Context_init_unchained() internal initializer {}
|
|
|
|
function _msgSender() internal view virtual returns (address) {
|
|
return msg.sender;
|
|
}
|
|
|
|
function _msgData() internal view virtual returns (bytes calldata) {
|
|
return msg.data;
|
|
}
|
|
|
|
uint256[50] private __gap;
|
|
}
|
|
|
|
|
|
|
|
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
|
|
address private _owner;
|
|
|
|
event OwnershipTransferred(
|
|
address indexed previousOwner,
|
|
address indexed newOwner
|
|
);
|
|
|
|
|
|
|
|
|
|
function __Ownable_init() internal initializer {
|
|
__Context_init_unchained();
|
|
__Ownable_init_unchained();
|
|
}
|
|
|
|
function __Ownable_init_unchained() internal initializer {
|
|
_transferOwnership(_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 {
|
|
_transferOwnership(address(0));
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function transferOwnership(address newOwner) public virtual onlyOwner {
|
|
require(
|
|
newOwner != address(0),
|
|
"Ownable: new owner is the zero address"
|
|
);
|
|
_transferOwnership(newOwner);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function _transferOwnership(address newOwner) internal virtual {
|
|
address oldOwner = _owner;
|
|
_owner = newOwner;
|
|
emit OwnershipTransferred(oldOwner, newOwner);
|
|
}
|
|
|
|
uint256[49] private __gap;
|
|
}
|
|
|
|
contract BEP20Upgradeable is
|
|
ContextUpgradeable,
|
|
IBEP20Upgradeable,
|
|
OwnableUpgradeable
|
|
{
|
|
using SafeMathUpgradeable for uint256;
|
|
|
|
mapping(address => uint256) private _balances;
|
|
|
|
mapping(address => mapping(address => uint256)) private _allowances;
|
|
|
|
uint256 private _totalSupply;
|
|
|
|
string private _name;
|
|
string private _symbol;
|
|
uint8 private _decimals;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constructor(string memory name, string memory symbol) public {
|
|
_name = name;
|
|
_symbol = symbol;
|
|
_decimals = 18;
|
|
}
|
|
|
|
|
|
|
|
|
|
function getOwner() external view override returns (address) {
|
|
return owner();
|
|
}
|
|
|
|
|
|
|
|
|
|
function name() public view override returns (string memory) {
|
|
return _name;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function symbol() public view override returns (string memory) {
|
|
return _symbol;
|
|
}
|
|
|
|
|
|
|
|
|
|
function decimals() public view override returns (uint8) {
|
|
return _decimals;
|
|
}
|
|
|
|
|
|
|
|
|
|
function totalSupply() public view override returns (uint256) {
|
|
return _totalSupply;
|
|
}
|
|
|
|
|
|
|
|
|
|
function balanceOf(address account) public view override returns (uint256) {
|
|
return _balances[account];
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function transfer(address recipient, uint256 amount)
|
|
public
|
|
override
|
|
returns (bool)
|
|
{
|
|
_transfer(_msgSender(), recipient, amount);
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
|
|
function allowance(address owner, address spender)
|
|
public
|
|
view
|
|
override
|
|
returns (uint256)
|
|
{
|
|
return _allowances[owner][spender];
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function approve(address spender, uint256 amount)
|
|
public
|
|
override
|
|
returns (bool)
|
|
{
|
|
_approve(_msgSender(), spender, amount);
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function transferFrom(
|
|
address sender,
|
|
address recipient,
|
|
uint256 amount
|
|
) public override returns (bool) {
|
|
_transfer(sender, recipient, amount);
|
|
_approve(
|
|
sender,
|
|
_msgSender(),
|
|
_allowances[sender][_msgSender()].sub(
|
|
amount,
|
|
"BEP20: transfer amount exceeds allowance"
|
|
)
|
|
);
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function increaseAllowance(address spender, uint256 addedValue)
|
|
public
|
|
returns (bool)
|
|
{
|
|
_approve(
|
|
_msgSender(),
|
|
spender,
|
|
_allowances[_msgSender()][spender].add(addedValue)
|
|
);
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function decreaseAllowance(address spender, uint256 subtractedValue)
|
|
public
|
|
returns (bool)
|
|
{
|
|
_approve(
|
|
_msgSender(),
|
|
spender,
|
|
_allowances[_msgSender()][spender].sub(
|
|
subtractedValue,
|
|
"BEP20: decreased allowance below zero"
|
|
)
|
|
);
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function mint(uint256 amount) public onlyOwner returns (bool) {
|
|
_mint(_msgSender(), amount);
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _transfer(
|
|
address sender,
|
|
address recipient,
|
|
uint256 amount
|
|
) internal {
|
|
require(sender != address(0), "BEP20: transfer from the zero address");
|
|
require(recipient != address(0), "BEP20: transfer to the zero address");
|
|
|
|
_balances[sender] = _balances[sender].sub(
|
|
amount,
|
|
"BEP20: transfer amount exceeds balance"
|
|
);
|
|
_balances[recipient] = _balances[recipient].add(amount);
|
|
emit Transfer(sender, recipient, amount);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _mint(address account, uint256 amount) internal {
|
|
require(account != address(0), "BEP20: mint to the zero address");
|
|
|
|
_totalSupply = _totalSupply.add(amount);
|
|
_balances[account] = _balances[account].add(amount);
|
|
emit Transfer(address(0), account, amount);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _burn(address account, uint256 amount) internal {
|
|
require(account != address(0), "BEP20: burn from the zero address");
|
|
|
|
_balances[account] = _balances[account].sub(
|
|
amount,
|
|
"BEP20: burn amount exceeds balance"
|
|
);
|
|
_totalSupply = _totalSupply.sub(amount);
|
|
emit Transfer(account, address(0), amount);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _approve(
|
|
address owner,
|
|
address spender,
|
|
uint256 amount
|
|
) internal {
|
|
require(owner != address(0), "BEP20: approve from the zero address");
|
|
require(spender != address(0), "BEP20: approve to the zero address");
|
|
|
|
_allowances[owner][spender] = amount;
|
|
emit Approval(owner, spender, amount);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _burnFrom(address account, uint256 amount) internal {
|
|
_burn(account, amount);
|
|
_approve(
|
|
account,
|
|
_msgSender(),
|
|
_allowances[account][_msgSender()].sub(
|
|
amount,
|
|
"BEP20: burn amount exceeds allowance"
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
contract Masterchef is Initializable, OwnableUpgradeable {
|
|
using SafeMathUpgradeable for uint256;
|
|
using SafeBEP20Upgradeable for IBEP20Upgradeable;
|
|
struct UserInfo {
|
|
uint256 amount;
|
|
uint256 rewardDebt;
|
|
uint256 lastRewardTimestamp;
|
|
}
|
|
|
|
|
|
struct PoolInfo {
|
|
IBEP20Upgradeable lpToken;
|
|
uint16 depositFeeBP;
|
|
uint256 apy;
|
|
}
|
|
|
|
|
|
BEP20Upgradeable public one80;
|
|
|
|
uint256 public constant BONUS_MULTIPLIER = 1;
|
|
|
|
address public feeAddress;
|
|
|
|
uint256 public perDaysecond;
|
|
|
|
|
|
PoolInfo[] public poolInfo;
|
|
|
|
mapping(uint256 => mapping(address => UserInfo)) public userInfo;
|
|
|
|
uint256 public startBlock;
|
|
|
|
event Deposit(address indexed user, uint256 indexed pid, uint256 amount);
|
|
event Withdraw(address indexed user, uint256 indexed pid, uint256 amount);
|
|
event EmergencyWithdraw(
|
|
address indexed user,
|
|
uint256 indexed pid,
|
|
uint256 amount
|
|
);
|
|
|
|
constructor(
|
|
|
|
) public {
|
|
|
|
}
|
|
|
|
function initialize(
|
|
BEP20Upgradeable _one80,
|
|
address _feeAddress,
|
|
uint256 _perDaysecond,
|
|
uint256 _startBlock
|
|
) public initializer {
|
|
__Ownable_init();
|
|
one80 = _one80;
|
|
feeAddress = _feeAddress;
|
|
perDaysecond = _perDaysecond;
|
|
startBlock = _startBlock;
|
|
}
|
|
|
|
function poolLength() external view returns (uint256) {
|
|
return poolInfo.length;
|
|
}
|
|
|
|
function add(
|
|
IBEP20Upgradeable _lpToken,
|
|
uint16 _depositFeeBP,
|
|
uint256 _apy
|
|
) public onlyOwner {
|
|
require(
|
|
_depositFeeBP <= 10000,
|
|
"add: invalid deposit fee basis points"
|
|
);
|
|
require(_apy >= 0, "add: invalid apy");
|
|
poolInfo.push(
|
|
PoolInfo({
|
|
lpToken: _lpToken,
|
|
depositFeeBP: _depositFeeBP,
|
|
apy: _apy
|
|
})
|
|
);
|
|
}
|
|
|
|
function set(
|
|
uint256 _pid,
|
|
uint16 _depositFeeBP,
|
|
uint256 _apy
|
|
) public onlyOwner {
|
|
require(
|
|
_depositFeeBP <= 10000,
|
|
"set: invalid deposit fee basis points"
|
|
);
|
|
require(_apy >= 0, "add: invalid apy");
|
|
poolInfo[_pid].depositFeeBP = _depositFeeBP;
|
|
poolInfo[_pid].apy = _apy;
|
|
}
|
|
|
|
|
|
function getMultiplier(uint256 _from, uint256 _to)
|
|
internal
|
|
pure
|
|
returns (uint256)
|
|
{
|
|
return _to.sub(_from).mul(BONUS_MULTIPLIER);
|
|
}
|
|
|
|
function pendingOne80(uint256 _pid, address _user)
|
|
external
|
|
view
|
|
returns (uint256)
|
|
{
|
|
PoolInfo storage pool = poolInfo[_pid];
|
|
UserInfo storage user = userInfo[_pid][_user];
|
|
uint256 one80Reward = 0;
|
|
if (block.timestamp > user.lastRewardTimestamp && user.amount > 0) {
|
|
uint256 multiplier = getMultiplier(
|
|
user.lastRewardTimestamp,
|
|
block.timestamp
|
|
);
|
|
uint256 perYear = perDaysecond.mul(365);
|
|
uint256 mpadPerSecond = pool.apy.mul(1e14).div(perYear);
|
|
one80Reward = multiplier.mul(mpadPerSecond);
|
|
} else {
|
|
one80Reward = 0;
|
|
}
|
|
return user.amount.mul(one80Reward).div(1e18);
|
|
}
|
|
|
|
|
|
function _harvest(uint256 _pid) internal {
|
|
PoolInfo storage pool = poolInfo[_pid];
|
|
UserInfo storage user = userInfo[_pid][msg.sender];
|
|
if (block.timestamp > user.lastRewardTimestamp && user.amount > 0) {
|
|
uint256 multiplier = getMultiplier(
|
|
user.lastRewardTimestamp,
|
|
block.timestamp
|
|
);
|
|
uint256 perYear = perDaysecond.mul(365);
|
|
uint256 mpadPerSecond = pool.apy.mul(1e14).div(perYear);
|
|
uint256 one80Reward = multiplier.mul(mpadPerSecond);
|
|
uint256 pending = user.amount.mul(one80Reward).div(1e18);
|
|
if (pending > 0) {
|
|
safeOne80Transfer(msg.sender, pending);
|
|
}
|
|
}
|
|
user.lastRewardTimestamp = block.timestamp;
|
|
}
|
|
|
|
function deposit(uint256 _pid, uint256 _amount) public {
|
|
PoolInfo storage pool = poolInfo[_pid];
|
|
UserInfo storage user = userInfo[_pid][msg.sender];
|
|
_harvest(_pid);
|
|
if (_amount > 0) {
|
|
pool.lpToken.safeTransferFrom(
|
|
address(msg.sender),
|
|
address(this),
|
|
_amount
|
|
);
|
|
if (pool.depositFeeBP > 0) {
|
|
uint256 depositFee = _amount.mul(pool.depositFeeBP).div(10000);
|
|
pool.lpToken.safeTransfer(feeAddress, depositFee);
|
|
user.amount = user.amount.add(_amount).sub(depositFee);
|
|
} else {
|
|
user.amount = user.amount.add(_amount);
|
|
}
|
|
}
|
|
emit Deposit(msg.sender, _pid, _amount);
|
|
}
|
|
|
|
|
|
function withdraw(uint256 _pid, uint256 _amount) public {
|
|
PoolInfo storage pool = poolInfo[_pid];
|
|
UserInfo storage user = userInfo[_pid][msg.sender];
|
|
require(user.amount >= _amount, "withdraw: not good");
|
|
_harvest(_pid);
|
|
if (_amount > 0) {
|
|
user.amount = user.amount.sub(_amount);
|
|
pool.lpToken.safeTransfer(address(msg.sender), _amount);
|
|
}
|
|
emit Withdraw(msg.sender, _pid, _amount);
|
|
}
|
|
|
|
|
|
function emergencyWithdraw(uint256 _pid) public {
|
|
PoolInfo storage pool = poolInfo[_pid];
|
|
UserInfo storage user = userInfo[_pid][msg.sender];
|
|
uint256 amount = user.amount;
|
|
user.amount = 0;
|
|
user.rewardDebt = 0;
|
|
pool.lpToken.safeTransfer(address(msg.sender), amount);
|
|
emit EmergencyWithdraw(msg.sender, _pid, amount);
|
|
}
|
|
|
|
|
|
function safeOne80Transfer(address _to, uint256 _amount) internal {
|
|
uint256 one80Bal = one80.balanceOf(address(this));
|
|
if (_amount > one80Bal) {
|
|
one80.transfer(_to, one80Bal);
|
|
} else {
|
|
one80.transfer(_to, _amount);
|
|
}
|
|
}
|
|
|
|
function safeOne80Withdraw(address _addr, uint256 _amount)
|
|
public
|
|
onlyOwner
|
|
{
|
|
uint256 one80Bal = one80.balanceOf(address(this));
|
|
if (_amount > one80Bal) {
|
|
one80.transfer(_addr, one80Bal);
|
|
} else {
|
|
one80.transfer(_addr, _amount);
|
|
}
|
|
}
|
|
|
|
function setFeeAddress(address _feeAddress) public {
|
|
require(msg.sender == feeAddress, "setFeeAddress: FORBIDDEN");
|
|
feeAddress = _feeAddress;
|
|
}
|
|
|
|
function updateStartBlock(uint256 _startBlock) public onlyOwner {
|
|
startBlock = _startBlock;
|
|
}
|
|
} |