Revolutionize Your Business with Xamer's Smart Audit Services
On-chain smart contract security monitoring
PancakeHunny aims to provide users the easiest way to join the bandwagon of the DeFi world, built on top of PancakeSwap, giving you the tastiest CAKEs topped with HUNNY.
Audits
Onboarded Date
07/Dec/2022
Contracts
0x565...46d69
Website
We talked about a project on linkedin.
Create new project Buildng product
Adding a new event with attachments
added a new member to velzon dashboard
These customers can rest assured their order has been placed.
They all have something to say beyond the words on the page. They can come across as casual or neutral, exotic or graphic.
2 days left notification to submit the monthly sales report. Reports Builder
User Erica245 submitted a ticket.
Team Leader & HR
Projects
Tasks
Full Stack Developer
Project Manager
UI/UX Designer
Team Leader & Web Developer
Backend Developer
Front-End Developer
Web Designer
Wed Developer
Showing 1 to 10 of 12 entries
All Findings
Acknowledge
Partially
Resolved
0x565b72163f...46d69
Token Standard
Functions
Verified Contract
/** *Submitted for verification at BscScan.com on 2021-06-01*/// Dependency file: @pancakeswap/pancake-swap-lib/contracts/math/SafeMath.sol// SPDX-License-Identifier: MIT// pragma solidity >=0.4.0;/** * @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; } function min(uint256 x, uint256 y) internal pure returns (uint256 z) { z = x < y ? x : y; } // babylonian method (https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method) function sqrt(uint256 y) internal pure returns (uint256 z) { if (y > 3) { z = y; uint256 x = y / 2 + 1; while (x < z) { z = x; x = (y / x + x) / 2; } } else if (y != 0) { z = 1; } }}// Dependency file: @pancakeswap/pancake-swap-lib/contracts/GSN/Context.sol// pragma solidity >=0.4.0;/* * @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. */contract Context { // Empty internal constructor, to prevent people from mistakenly deploying // an instance of this contract, which should be used via inheritance. constructor() internal {} function _msgSender() internal view returns (address payable) { return msg.sender; } function _msgData() internal view returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; }}// Dependency file: @pancakeswap/pancake-swap-lib/contracts/access/Ownable.sol// pragma solidity >=0.4.0;/** * @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 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 onlyOwner { _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). */ function _transferOwnership(address newOwner) internal { require(newOwner != address(0), 'Ownable: new owner is the zero address'); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; }}// Dependency file: @pancakeswap/pancake-swap-lib/contracts/token/BEP20/IBEP20.sol// pragma solidity >=0.4.0;interface IBEP20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the token decimals. */ function decimals() external view returns (uint8); /** * @dev Returns the token symbol. */ function symbol() external view returns (string memory); /** * @dev Returns the token name. */ function name() external view returns (string memory); /** * @dev Returns the bep token owner. */ function getOwner() external view returns (address); /** * @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);}// Dependency file: @pancakeswap/pancake-swap-lib/contracts/utils/Address.sol// pragma solidity ^0.6.2;/** * @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); } } }}// Dependency file: @pancakeswap/pancake-swap-lib/contracts/token/BEP20/SafeBEP20.sol// pragma solidity ^0.6.0;/** * @title SafeBEP20 * @dev Wrappers around BEP20 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 SafeBEP20 for IBEP20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */library SafeBEP20 { using SafeMath for uint256; using Address for address; function safeTransfer( IBEP20 token, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom( IBEP20 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 * {IBEP20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove( IBEP20 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), 'SafeBEP20: approve from non-zero to non-zero allowance' ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance( IBEP20 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( IBEP20 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)); } /** * @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(IBEP20 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, 'SafeBEP20: low-level call failed'); if (returndata.length > 0) { // Return data is optional // solhint-disable-next-line max-line-length require(abi.decode(returndata, (bool)), 'SafeBEP20: BEP20 operation did not succeed'); } }}// Dependency file: contracts/library/bep20/BEP20Virtual.sol// pragma solidity >=0.4.0;// import "@pancakeswap/pancake-swap-lib/contracts/access/Ownable.sol";// import "@pancakeswap/pancake-swap-lib/contracts/GSN/Context.sol";// import "@pancakeswap/pancake-swap-lib/contracts/token/BEP20/IBEP20.sol";// import "@pancakeswap/pancake-swap-lib/contracts/math/SafeMath.sol";// import "@pancakeswap/pancake-swap-lib/contracts/utils/Address.sol";/** * @dev Implementation of the {IBEP20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {BEP20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-BEP20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of BEP20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IBEP20-approve}. */contract BEP20Virtual is Context, IBEP20, Ownable { using SafeMath for uint256; using Address for address; mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor(string memory name, string memory symbol) public { _name = name; _symbol = symbol; _decimals = 18; } /** * @dev Returns the bep token owner. */ function getOwner() external override view returns (address) { return owner(); } /** * @dev Returns the token name. */ function name() public override view returns (string memory) { return _name; } /** * @dev Returns the token decimals. */ function decimals() public override view returns (uint8) { return _decimals; } /** * @dev Returns the token symbol. */ function symbol() public override view returns (string memory) { return _symbol; } /** * @dev See {BEP20-totalSupply}. */ function totalSupply() public override view returns (uint256) { return _totalSupply; } /** * @dev See {BEP20-balanceOf}. */ function balanceOf(address account) public override view returns (uint256) { return _balances[account]; } /** * @dev See {BEP20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {BEP20-allowance}. */ function allowance(address owner, address spender) public override view returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {BEP20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {BEP20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {BEP20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for `sender`'s tokens of at least * `amount`. */ 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; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {BEP20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {BEP20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) { _approve( _msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, 'BEP20: decreased allowance below zero') ); return true; } /** * @dev Creates `amount` tokens and assigns them to `msg.sender`, increasing * the total supply. * * Requirements * * - `msg.sender` must be the token owner */ function mint(uint256 amount) public onlyOwner returns (bool) { _mint(_msgSender(), amount); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer( address sender, address recipient, uint256 amount ) internal virtual { 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); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ 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); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ 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); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ 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); } /** * @dev Destroys `amount` tokens from `account`.`amount` is then deducted * from the caller's allowance. * * See {_burn} and {_approve}. */ function _burnFrom(address account, uint256 amount) internal { _burn(account, amount); _approve( account, _msgSender(), _allowances[account][_msgSender()].sub(amount, 'BEP20: burn amount exceeds allowance') ); }}// Dependency file: contracts/hunny/HunnyToken.sol// pragma solidity ^0.6.12;/*** MIT License* ===========** Copyright (c) 2020 HUNNYFinance** Permission is hereby granted, free of charge, to any person obtaining a copy* of this software and associated documentation files (the "Software"), to deal* in the Software without restriction, including without limitation the rights* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell* copies of the Software, and to permit persons to whom the Software is* furnished to do so, subject to the following conditions:** The above copyright notice and this permission notice shall be included in all* copies or substantial portions of the Software.** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE*/// import "contracts/library/bep20/BEP20Virtual.sol";// HunnyToken with Governance.contract HunnyToken is BEP20Virtual('Hunny Token', 'HUNNY') { uint16 public maxTransferAmountRate = 10000; // 100% address public constant BURN_ADDRESS = 0x000000000000000000000000000000000000dEaD; mapping(address => bool) private _excludedFromAntiWhale; address private _operator; event OperatorTransferred(address indexed previousOperator, address indexed newOperator); event MaxTransferAmountRateUpdated(address indexed operator, uint256 previousRate, uint256 newRate); modifier onlyOperator() { require(_operator == msg.sender, "operator: caller is not the operator"); _; } modifier antiWhale(address sender, address recipient, uint256 amount) { if (maxTransferAmount() > 0) { if ( _excludedFromAntiWhale[sender] == false && _excludedFromAntiWhale[recipient] == false ) { require(amount <= maxTransferAmount(), "HUNNY::antiWhale: Transfer amount exceeds the maxTransferAmount"); } } _; } constructor() public { _operator = msg.sender; _excludedFromAntiWhale[msg.sender] = true; _excludedFromAntiWhale[address(0)] = true; _excludedFromAntiWhale[address(this)] = true; _excludedFromAntiWhale[BURN_ADDRESS] = true; } function _transfer(address sender, address recipient, uint256 amount) internal override antiWhale(sender, recipient, amount) { super._transfer(sender, recipient, amount); } function maxTransferAmount() public view returns (uint256) { return totalSupply().mul(maxTransferAmountRate).div(10000); } function isExcludedFromAntiWhale(address _account) public view returns (bool) { return _excludedFromAntiWhale[_account]; } function updateMaxTransferAmountRate(uint16 _maxTransferAmountRate) public onlyOperator { require(_maxTransferAmountRate <= 10000, "HUNNY::updateMaxTransferAmountRate: Max transfer amount rate must not exceed the maximum rate."); emit MaxTransferAmountRateUpdated(msg.sender, maxTransferAmountRate, _maxTransferAmountRate); maxTransferAmountRate = _maxTransferAmountRate; } function setExcludedFromAntiWhale(address _account, bool _excluded) public onlyOperator { _excludedFromAntiWhale[_account] = _excluded; } function transferOperator(address newOperator) public onlyOperator { require(newOperator != address(0), "HUNNY::transferOperator: new operator is the zero address"); emit OperatorTransferred(_operator, newOperator); _operator = newOperator; _excludedFromAntiWhale[newOperator] = true; } // @dev Creates `_amount` token to `_to`. Must only be called by the owner (MasterChef). function mint(address _to, uint256 _amount) public onlyOwner { _mint(_to, _amount); _moveDelegates(address(0), _delegates[_to], _amount); } // Copied and modified from YAM code: // https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernanceStorage.sol // https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernance.sol // Which is copied and modified from COMPOUND: // https://github.com/compound-finance/compound-protocol/blob/master/contracts/Governance/Comp.sol // @dev A record of each accounts delegate mapping (address => address) internal _delegates; // @dev A checkpoint for marking number of votes from a given block struct Checkpoint { uint32 fromBlock; uint256 votes; } // @dev A record of votes checkpoints for each account, by index mapping (address => mapping (uint32 => Checkpoint)) public checkpoints; // @dev The number of checkpoints for each account mapping (address => uint32) public numCheckpoints; // @dev The EIP-712 typehash for the contract's domain bytes32 public constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)"); // @dev The EIP-712 typehash for the delegation struct used by the contract bytes32 public constant DELEGATION_TYPEHASH = keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)"); // @dev A record of states for signing / validating signatures mapping (address => uint) public nonces; // @dev An event thats emitted when an account changes its delegate event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate); // @dev An event thats emitted when a delegate account's vote balance changes event DelegateVotesChanged(address indexed delegate, uint previousBalance, uint newBalance); /** * @dev Delegate votes from `msg.sender` to `delegatee` * @param delegator The address to get delegatee for */ function delegates(address delegator) external view returns (address) { return _delegates[delegator]; } /** * @dev Delegate votes from `msg.sender` to `delegatee` * @param delegatee The address to delegate votes to */ function delegate(address delegatee) external { return _delegate(msg.sender, delegatee); } /** * @dev Delegates votes from signatory to `delegatee` * @param delegatee The address to delegate votes to * @param nonce The contract state required to match the signature * @param expiry The time at which to expire the signature * @param v The recovery byte of the signature * @param r Half of the ECDSA signature pair * @param s Half of the ECDSA signature pair */ function delegateBySig( address delegatee, uint nonce, uint expiry, uint8 v, bytes32 r, bytes32 s ) external { bytes32 domainSeparator = keccak256( abi.encode( DOMAIN_TYPEHASH, keccak256(bytes(name())), getChainId(), address(this) ) ); bytes32 structHash = keccak256( abi.encode( DELEGATION_TYPEHASH, delegatee, nonce, expiry ) ); bytes32 digest = keccak256( abi.encodePacked( "\x19\x01", domainSeparator, structHash ) ); address signatory = ecrecover(digest, v, r, s); require(signatory != address(0), "HUNNY::delegateBySig: invalid signature"); require(nonce == nonces[signatory]++, "HUNNY::delegateBySig: invalid nonce"); require(now <= expiry, "HUNNY::delegateBySig: signature expired"); return _delegate(signatory, delegatee); } /** * @dev Gets the current votes balance for `account` * @param account The address to get votes balance * @return The number of current votes for `account` */ function getCurrentVotes(address account) external view returns (uint256) { uint32 nCheckpoints = numCheckpoints[account]; return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0; } /** * @dev Determine the prior number of votes for an account as of a block number * @dev Block number must be a finalized block or else this function will revert to prevent misinformation. * @param account The address of the account to check * @param blockNumber The block number to get the vote balance at * @return The number of votes the account had as of the given block */ function getPriorVotes(address account, uint blockNumber) external view returns (uint256) { require(blockNumber < block.number, "HUNNY::getPriorVotes: not yet determined"); uint32 nCheckpoints = numCheckpoints[account]; if (nCheckpoints == 0) { return 0; } // First check most recent balance if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) { return checkpoints[account][nCheckpoints - 1].votes; } // Next check implicit zero balance if (checkpoints[account][0].fromBlock > blockNumber) { return 0; } uint32 lower = 0; uint32 upper = nCheckpoints - 1; while (upper > lower) { uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow Checkpoint memory cp = checkpoints[account][center]; if (cp.fromBlock == blockNumber) { return cp.votes; } else if (cp.fromBlock < blockNumber) { lower = center; } else { upper = center - 1; } } return checkpoints[account][lower].votes; } function _delegate(address delegator, address delegatee) internal { address currentDelegate = _delegates[delegator]; uint256 delegatorBalance = balanceOf(delegator); // balance of underlying HUNNYs (not scaled); _delegates[delegator] = delegatee; emit DelegateChanged(delegator, currentDelegate, delegatee); _moveDelegates(currentDelegate, delegatee, delegatorBalance); } function _moveDelegates(address srcRep, address dstRep, uint256 amount) internal { if (srcRep != dstRep && amount > 0) { if (srcRep != address(0)) { // decrease old representative uint32 srcRepNum = numCheckpoints[srcRep]; uint256 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0; uint256 srcRepNew = srcRepOld.sub(amount); _writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew); } if (dstRep != address(0)) { // increase new representative uint32 dstRepNum = numCheckpoints[dstRep]; uint256 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0; uint256 dstRepNew = dstRepOld.add(amount); _writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew); } } } function _writeCheckpoint( address delegatee, uint32 nCheckpoints, uint256 oldVotes, uint256 newVotes ) internal { uint32 blockNumber = safe32(block.number, "HUNNY::_writeCheckpoint: block number exceeds 32 bits"); if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) { checkpoints[delegatee][nCheckpoints - 1].votes = newVotes; } else { checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes); numCheckpoints[delegatee] = nCheckpoints + 1; } emit DelegateVotesChanged(delegatee, oldVotes, newVotes); } function safe32(uint n, string memory errorMessage) internal pure returns (uint32) { require(n < 2**32, errorMessage); return uint32(n); } function getChainId() internal pure returns (uint) { uint256 chainId; assembly { chainId := chainid() } return chainId; }}// Dependency file: @uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol// pragma solidity >=0.5.0;interface IUniswapV2Factory { event PairCreated(address indexed token0, address indexed token1, address pair, uint); function feeTo() external view returns (address); function feeToSetter() external view returns (address); function getPair(address tokenA, address tokenB) external view returns (address pair); function allPairs(uint) external view returns (address pair); function allPairsLength() external view returns (uint); function createPair(address tokenA, address tokenB) external returns (address pair); function setFeeTo(address) external; function setFeeToSetter(address) external;}// Dependency file: @uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol// pragma solidity >=0.5.0;interface IUniswapV2Pair { event Approval(address indexed owner, address indexed spender, uint value); event Transfer(address indexed from, address indexed to, uint value); function name() external pure returns (string memory); function symbol() external pure returns (string memory); function decimals() external pure returns (uint8); function totalSupply() external view returns (uint); function balanceOf(address owner) external view returns (uint); function allowance(address owner, address spender) external view returns (uint); function approve(address spender, 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 DOMAIN_SEPARATOR() external view returns (bytes32); function PERMIT_TYPEHASH() external pure returns (bytes32); 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; event Mint(address indexed sender, uint amount0, uint amount1); event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); event Swap( address indexed sender, uint amount0In, uint amount1In, uint amount0Out, uint amount1Out, address indexed to ); event Sync(uint112 reserve0, uint112 reserve1); function MINIMUM_LIQUIDITY() external pure returns (uint); function factory() external view returns (address); function token0() external view returns (address); function token1() external view returns (address); function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); function price0CumulativeLast() external view returns (uint); function price1CumulativeLast() external view returns (uint); function kLast() external view returns (uint); function mint(address to) external returns (uint liquidity); function burn(address to) external returns (uint amount0, uint amount1); function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; function skim(address to) external; function sync() external; function initialize(address, address) external;}// Dependency file: contracts/Constants.sol// pragma solidity 0.6.12;library Constants { // pancake address constant PANCAKE_ROUTER = address(0x10ED43C718714eb63d5aA57B78B54704E256024E); // v2 address constant PANCAKE_FACTORY = address(0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73); address constant PANCAKE_CHEF = address(0x73feaa1eE314F8c655E354234017bE2193C9E24E);// uint constant PANCAKE_CAKE_BNB_PID = 3; uint constant PANCAKE_CAKE_BNB_PID = 251; // mainnet uint constant PANCAKE_BUSD_BNB_PID = 252; // mainnet// uint constant PANCAKE_BUSD_BNB_PID = 4; uint constant PANCAKE_BUSD_USDT_PID = 264; // mainnet// uint constant PANCAKE_BUSD_USDT_PID = 0; // tokens address constant WBNB = address(0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c); address constant CAKE = address(0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82); address constant BUSD = address(0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56); // external addresses address constant HUNNY_DEPLOYER = address(0xe5F7E3DD9A5612EcCb228392F47b7Ddba8cE4F1a); address constant HUNNY_LOTTERY = address(0); // update later address constant HUNNY_KEEPER = address(0xe5F7E3DD9A5612EcCb228392F47b7Ddba8cE4F1a); // minter uint256 constant HUNNY_PER_BLOCK_LOTTERY = 12e18; // 12 HUNNY per block for lottery pool uint256 constant HUNNY_PER_PROFIT_BNB = 3200e18; // 1 BNB earned, mint 3200 HUNNY uint256 constant HUNNY_PER_HUNNY_BNB_FLIP = 150e18; // 1 HUNNY-BNB, earn 150 HUNNY / 365 days}// Dependency file: contracts/library/Whitelist.sol// pragma solidity ^0.6.12;/*** MIT License* ===========** Copyright (c) 2020 HunnyFinance** Permission is hereby granted, free of charge, to any person obtaining a copy* of this software and associated documentation files (the "Software"), to deal* in the Software without restriction, including without limitation the rights* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell* copies of the Software, and to permit persons to whom the Software is* furnished to do so, subject to the following conditions:** The above copyright notice and this permission notice shall be included in all* copies or substantial portions of the Software.** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE*/// import "@pancakeswap/pancake-swap-lib/contracts/access/Ownable.sol";contract Whitelist is Ownable { mapping(address => bool) private _whitelist; bool private _disable; // default - false means whitelist feature is working on. if true no more use of whitelist event Whitelisted(address indexed _address, bool whitelist); event EnableWhitelist(); event DisableWhitelist(); modifier onlyWhitelisted { require(_disable || _whitelist[msg.sender], "Whitelist: caller is not on the whitelist"); _; } function isWhitelist(address _address) public view returns (bool) { return _whitelist[_address]; } function setWhitelist(address _address, bool _on) public onlyOwner { _whitelist[_address] = _on; emit Whitelisted(_address, _on); } function disableWhitelist(bool disable) public onlyOwner { _disable = disable; if (disable) { emit DisableWhitelist(); } else { emit EnableWhitelist(); } }}// Dependency file: contracts/library/uniswap/FullMath.sol// pragma solidity ^0.6.12;// taken from https://medium.com/coinmonks/math-in-solidity-part-3-percents-and-proportions-4db014e080b1// license is CC-BY-4.0library FullMath { function fullMul(uint256 x, uint256 y) internal pure returns (uint256 l, uint256 h) { uint256 mm = mulmod(x, y, uint256(-1)); l = x * y; h = mm - l; if (mm < l) h -= 1; } function fullDiv( uint256 l, uint256 h, uint256 d ) private pure returns (uint256) { uint256 pow2 = d & -d; d /= pow2; l /= pow2; l += h * ((-pow2) / pow2 + 1); uint256 r = 1; r *= 2 - d * r; r *= 2 - d * r; r *= 2 - d * r; r *= 2 - d * r; r *= 2 - d * r; r *= 2 - d * r; r *= 2 - d * r; r *= 2 - d * r; return l * r; } function mulDiv( uint256 x, uint256 y, uint256 d ) internal pure returns (uint256) { (uint256 l, uint256 h) = fullMul(x, y); uint256 mm = mulmod(x, y, d); if (mm > l) h -= 1; l -= mm; if (h == 0) return l / d; require(h < d, 'FullMath: FULLDIV_OVERFLOW'); return fullDiv(l, h, d); }}// Dependency file: contracts/library/uniswap/Babylonian.sol// pragma solidity ^0.6.12;// computes square roots using the babylonian method// https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_methodlibrary Babylonian { // credit for this implementation goes to // https://github.com/abdk-consulting/abdk-libraries-solidity/blob/master/ABDKMath64x64.sol#L687 function sqrt(uint256 x) internal pure returns (uint256) { if (x == 0) return 0; // this block is equivalent to r = uint256(1) << (BitMath.mostSignificantBit(x) / 2); // however that code costs significantly more gas uint256 xx = x; uint256 r = 1; if (xx >= 0x100000000000000000000000000000000) { xx >>= 128; r <<= 64; } if (xx >= 0x10000000000000000) { xx >>= 64; r <<= 32; } if (xx >= 0x100000000) { xx >>= 32; r <<= 16; } if (xx >= 0x10000) { xx >>= 16; r <<= 8; } if (xx >= 0x100) { xx >>= 8; r <<= 4; } if (xx >= 0x10) { xx >>= 4; r <<= 2; } if (xx >= 0x8) { r <<= 1; } r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; // Seven iterations should be enough uint256 r1 = x / r; return (r < r1 ? r : r1); }}// Dependency file: contracts/library/uniswap/BitMath.sol// pragma solidity ^0.6.12;library BitMath { // returns the 0 indexed position of the most significant bit of the input x // s.t. x >= 2**msb and x < 2**(msb+1) function mostSignificantBit(uint256 x) internal pure returns (uint8 r) { require(x > 0, 'BitMath::mostSignificantBit: zero'); if (x >= 0x100000000000000000000000000000000) { x >>= 128; r += 128; } if (x >= 0x10000000000000000) { x >>= 64; r += 64; } if (x >= 0x100000000) { x >>= 32; r += 32; } if (x >= 0x10000) { x >>= 16; r += 16; } if (x >= 0x100) { x >>= 8; r += 8; } if (x >= 0x10) { x >>= 4; r += 4; } if (x >= 0x4) { x >>= 2; r += 2; } if (x >= 0x2) r += 1; } // returns the 0 indexed position of the least significant bit of the input x // s.t. (x & 2**lsb) != 0 and (x & (2**(lsb) - 1)) == 0) // i.e. the bit at the index is set and the mask of all lower bits is 0 function leastSignificantBit(uint256 x) internal pure returns (uint8 r) { require(x > 0, 'BitMath::leastSignificantBit: zero'); r = 255; if (x & uint128(-1) > 0) { r -= 128; } else { x >>= 128; } if (x & uint64(-1) > 0) { r -= 64; } else { x >>= 64; } if (x & uint32(-1) > 0) { r -= 32; } else { x >>= 32; } if (x & uint16(-1) > 0) { r -= 16; } else { x >>= 16; } if (x & uint8(-1) > 0) { r -= 8; } else { x >>= 8; } if (x & 0xf > 0) { r -= 4; } else { x >>= 4; } if (x & 0x3 > 0) { r -= 2; } else { x >>= 2; } if (x & 0x1 > 0) r -= 1; }}// Dependency file: contracts/library/uniswap/FixedPoint.sol// pragma solidity ^0.6.12;// import 'contracts/library/uniswap/FullMath.sol';// import 'contracts/library/uniswap/Babylonian.sol';// import 'contracts/library/uniswap/BitMath.sol';// a library for handling binary fixed point numbers (https://en.wikipedia.org/wiki/Q_(number_format))library FixedPoint { // range: [0, 2**112 - 1] // resolution: 1 / 2**112 struct uq112x112 { uint224 _x; } // range: [0, 2**144 - 1] // resolution: 1 / 2**112 struct uq144x112 { uint256 _x; } uint8 public constant RESOLUTION = 112; uint256 public constant Q112 = 0x10000000000000000000000000000; // 2**112 uint256 private constant Q224 = 0x100000000000000000000000000000000000000000000000000000000; // 2**224 uint256 private constant LOWER_MASK = 0xffffffffffffffffffffffffffff; // decimal of UQ*x112 (lower 112 bits) // encode a uint112 as a UQ112x112 function encode(uint112 x) internal pure returns (uq112x112 memory) { return uq112x112(uint224(x) << RESOLUTION); } // encodes a uint144 as a UQ144x112 function encode144(uint144 x) internal pure returns (uq144x112 memory) { return uq144x112(uint256(x) << RESOLUTION); } // decode a UQ112x112 into a uint112 by truncating after the radix point function decode(uq112x112 memory self) internal pure returns (uint112) { return uint112(self._x >> RESOLUTION); } // decode a UQ144x112 into a uint144 by truncating after the radix point function decode144(uq144x112 memory self) internal pure returns (uint144) { return uint144(self._x >> RESOLUTION); } // multiply a UQ112x112 by a uint, returning a UQ144x112 // reverts on overflow function mul(uq112x112 memory self, uint256 y) internal pure returns (uq144x112 memory) { uint256 z = 0; require(y == 0 || (z = self._x * y) / y == self._x, 'FixedPoint::mul: overflow'); return uq144x112(z); } // multiply a UQ112x112 by an int and decode, returning an int // reverts on overflow function muli(uq112x112 memory self, int256 y) internal pure returns (int256) { uint256 z = FullMath.mulDiv(self._x, uint256(y < 0 ? -y : y), Q112); require(z < 2**255, 'FixedPoint::muli: overflow'); return y < 0 ? -int256(z) : int256(z); } // multiply a UQ112x112 by a UQ112x112, returning a UQ112x112 // lossy function muluq(uq112x112 memory self, uq112x112 memory other) internal pure returns (uq112x112 memory) { if (self._x == 0 || other._x == 0) { return uq112x112(0); } uint112 upper_self = uint112(self._x >> RESOLUTION); // * 2^0 uint112 lower_self = uint112(self._x & LOWER_MASK); // * 2^-112 uint112 upper_other = uint112(other._x >> RESOLUTION); // * 2^0 uint112 lower_other = uint112(other._x & LOWER_MASK); // * 2^-112 // partial products uint224 upper = uint224(upper_self) * upper_other; // * 2^0 uint224 lower = uint224(lower_self) * lower_other; // * 2^-224 uint224 uppers_lowero = uint224(upper_self) * lower_other; // * 2^-112 uint224 uppero_lowers = uint224(upper_other) * lower_self; // * 2^-112 // so the bit shift does not overflow require(upper <= uint112(-1), 'FixedPoint::muluq: upper overflow'); // this cannot exceed 256 bits, all values are 224 bits uint256 sum = uint256(upper << RESOLUTION) + uppers_lowero + uppero_lowers + (lower >> RESOLUTION); // so the cast does not overflow require(sum <= uint224(-1), 'FixedPoint::muluq: sum overflow'); return uq112x112(uint224(sum)); } // divide a UQ112x112 by a UQ112x112, returning a UQ112x112 function divuq(uq112x112 memory self, uq112x112 memory other) internal pure returns (uq112x112 memory) { require(other._x > 0, 'FixedPoint::divuq: division by zero'); if (self._x == other._x) { return uq112x112(uint224(Q112)); } if (self._x <= uint144(-1)) { uint256 value = (uint256(self._x) << RESOLUTION) / other._x; require(value <= uint224(-1), 'FixedPoint::divuq: overflow'); return uq112x112(uint224(value)); } uint256 result = FullMath.mulDiv(Q112, self._x, other._x); require(result <= uint224(-1), 'FixedPoint::divuq: overflow'); return uq112x112(uint224(result)); } // returns a UQ112x112 which represents the ratio of the numerator to the denominator // can be lossy function fraction(uint256 numerator, uint256 denominator) internal pure returns (uq112x112 memory) { require(denominator > 0, 'FixedPoint::fraction: division by zero'); if (numerator == 0) return FixedPoint.uq112x112(0); if (numerator <= uint144(-1)) { uint256 result = (numerator << RESOLUTION) / denominator; require(result <= uint224(-1), 'FixedPoint::fraction: overflow'); return uq112x112(uint224(result)); } else { uint256 result = FullMath.mulDiv(numerator, Q112, denominator); require(result <= uint224(-1), 'FixedPoint::fraction: overflow'); return uq112x112(uint224(result)); } } // take the reciprocal of a UQ112x112 // reverts on overflow // lossy function reciprocal(uq112x112 memory self) internal pure returns (uq112x112 memory) { require(self._x != 0, 'FixedPoint::reciprocal: reciprocal of zero'); require(self._x != 1, 'FixedPoint::reciprocal: overflow'); return uq112x112(uint224(Q224 / self._x)); } // square root of a UQ112x112 // lossy between 0/1 and 40 bits function sqrt(uq112x112 memory self) internal pure returns (uq112x112 memory) { if (self._x <= uint144(-1)) { return uq112x112(uint224(Babylonian.sqrt(uint256(self._x) << 112))); } uint8 safeShiftBits = 255 - BitMath.mostSignificantBit(self._x); safeShiftBits -= safeShiftBits % 2; return uq112x112(uint224(Babylonian.sqrt(uint256(self._x) << safeShiftBits) << ((112 - safeShiftBits) / 2))); }}// Dependency file: contracts/library/uniswap/UniswapV2Library.sol// pragma solidity ^0.6.12;// import "@pancakeswap/pancake-swap-lib/contracts/math/SafeMath.sol";// import "@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol";library UniswapV2Library { using SafeMath for uint; // returns sorted token addresses, used to handle return values from pairs sorted in this order function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) { require(tokenA != tokenB, 'UniswapV2Library: IDENTICAL_ADDRESSES'); (token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA); require(token0 != address(0), 'UniswapV2Library: ZERO_ADDRESS'); } // calculates the CREATE2 address for a pair without making any external calls function pairFor(address factory, address tokenA, address tokenB) internal pure returns (address pair) { (address token0, address token1) = sortTokens(tokenA, tokenB); pair = address(uint(keccak256(abi.encodePacked( hex'ff', factory, keccak256(abi.encodePacked(token0, token1)), hex'96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f' // init code hash )))); } // fetches and sorts the reserves for a pair function getReserves(address factory, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) { (address token0,) = sortTokens(tokenA, tokenB); (uint reserve0, uint reserve1,) = IUniswapV2Pair(pairFor(factory, tokenA, tokenB)).getReserves(); (reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0); } // given some amount of an asset and pair reserves, returns an equivalent amount of the other asset function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) { require(amountA > 0, 'UniswapV2Library: INSUFFICIENT_AMOUNT'); require(reserveA > 0 && reserveB > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY'); amountB = amountA.mul(reserveB) / reserveA; } // given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) { require(amountIn > 0, 'UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT'); require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY'); uint amountInWithFee = amountIn.mul(997); uint numerator = amountInWithFee.mul(reserveOut); uint denominator = reserveIn.mul(1000).add(amountInWithFee); amountOut = numerator / denominator; } // given an output amount of an asset and pair reserves, returns a required input amount of the other asset function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn) { require(amountOut > 0, 'UniswapV2Library: INSUFFICIENT_OUTPUT_AMOUNT'); require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY'); uint numerator = reserveIn.mul(amountOut).mul(1000); uint denominator = reserveOut.sub(amountOut).mul(997); amountIn = (numerator / denominator).add(1); } // performs chained getAmountOut calculations on any number of pairs function getAmountsOut(address factory, uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) { require(path.length >= 2, 'UniswapV2Library: INVALID_PATH'); amounts = new uint[](path.length); amounts[0] = amountIn; for (uint i; i < path.length - 1; i++) { (uint reserveIn, uint reserveOut) = getReserves(factory, path[i], path[i + 1]); amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut); } } // performs chained getAmountIn calculations on any number of pairs function getAmountsIn(address factory, uint amountOut, address[] memory path) internal view returns (uint[] memory amounts) { require(path.length >= 2, 'UniswapV2Library: INVALID_PATH'); amounts = new uint[](path.length); amounts[amounts.length - 1] = amountOut; for (uint i = path.length - 1; i > 0; i--) { (uint reserveIn, uint reserveOut) = getReserves(factory, path[i - 1], path[i]); amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut); } }}// Dependency file: contracts/library/uniswap/UniswapV2OracleLibrary.sol// pragma solidity ^0.6.12;// import 'contracts/library/uniswap/FixedPoint.sol';// library with helper methods for oracles that are concerned with computing average priceslibrary UniswapV2OracleLibrary { using FixedPoint for *; // helper function that returns the current block timestamp within the range of uint32, i.e. [0, 2**32 - 1] function currentBlockTimestamp() internal view returns (uint32) { return uint32(block.timestamp % 2 ** 32); } // produces the cumulative price using counterfactuals to save gas and avoid a call to sync. function currentCumulativePrices( address pair ) internal view returns (uint price0Cumulative, uint price1Cumulative, uint32 blockTimestamp) { blockTimestamp = currentBlockTimestamp(); price0Cumulative = IUniswapV2Pair(pair).price0CumulativeLast(); price1Cumulative = IUniswapV2Pair(pair).price1CumulativeLast(); // if time has elapsed since the last update on the pair, mock the accumulated price values (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast) = IUniswapV2Pair(pair).getReserves(); if (blockTimestampLast != blockTimestamp) { // subtraction overflow is desired uint32 timeElapsed = blockTimestamp - blockTimestampLast; // addition overflow is desired // counterfactual price0Cumulative += uint(FixedPoint.fraction(reserve1, reserve0)._x) * timeElapsed; // counterfactual price1Cumulative += uint(FixedPoint.fraction(reserve0, reserve1)._x) * timeElapsed; } }}// Dependency file: contracts/hunny/HunnyOracle.sol// pragma solidity ^0.6.12;// import "@pancakeswap/pancake-swap-lib/contracts/access/Ownable.sol";// import "@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol";// import "@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol";// import "contracts/Constants.sol";// import "contracts/library/Whitelist.sol";// import "contracts/library/uniswap/FixedPoint.sol";// import "contracts/library/uniswap/UniswapV2Library.sol";// import "contracts/library/uniswap/UniswapV2OracleLibrary.sol";// fixed window oracle that recomputes the average price for the entire period once every period// note that the price average is only guaranteed to be over at least 1 period, but may be over a longer periodcontract HunnyOracle is Whitelist { using FixedPoint for *; uint public constant PERIOD = 10 minutes; uint112 public constant BOOTSTRAP_HUNNY_PRICE = 250000000000000; // 1 BNB = 4000 HUNNY bool public initialized; address public hunnyToken; IUniswapV2Pair pair; address public token0; address public token1; uint public price0CumulativeLast; uint public price1CumulativeLast; uint32 public blockTimestampLast; FixedPoint.uq112x112 public price0Average; FixedPoint.uq112x112 public price1Average; constructor(address hunny) public { hunnyToken = hunny; setWhitelist(msg.sender, true); } function initialize() internal { IUniswapV2Pair _pair = IUniswapV2Pair(IUniswapV2Factory(Constants.PANCAKE_FACTORY).getPair(hunnyToken, Constants.WBNB)); pair = _pair; token0 = _pair.token0(); token1 = _pair.token1(); price0CumulativeLast = _pair.price0CumulativeLast(); // fetch the current accumulated price value (1 / 0) price1CumulativeLast = _pair.price1CumulativeLast(); // fetch the current accumulated price value (0 / 1) // get the blockTimestampLast (,, blockTimestampLast) = _pair.getReserves(); _update(); initialized = true; } function update() public onlyWhitelisted { if (!initialized) { initialize(); } (, , uint32 blockTimestamp) = UniswapV2OracleLibrary.currentCumulativePrices(address(pair)); uint32 timeElapsed = blockTimestamp - blockTimestampLast; // overflow is desired // ensure that at least one full period has passed since the last update if (timeElapsed >= PERIOD) { _update(); } } function _update() internal { (uint price0Cumulative, uint price1Cumulative, uint32 blockTimestamp) = UniswapV2OracleLibrary.currentCumulativePrices(address(pair)); uint32 timeElapsed = blockTimestamp - blockTimestampLast; // overflow is desired // overflow is desired, casting never truncates // cumulative price is in (uq112x112 price * seconds) units so we simply wrap it after division by time elapsed price0Average = FixedPoint.uq112x112(uint224((price0Cumulative - price0CumulativeLast) / timeElapsed)); price1Average = FixedPoint.uq112x112(uint224((price1Cumulative - price1CumulativeLast) / timeElapsed)); price0CumulativeLast = price0Cumulative; price1CumulativeLast = price1Cumulative; blockTimestampLast = blockTimestamp; } // note this will always return 0 before update has been called successfully for the first time. function consult(address token, uint amountIn) public view returns (uint amountOut) { if (token == token0) { amountOut = price0Average.mul(amountIn).decode144(); } else { require(token == token1, 'HunnyOracle: INVALID_TOKEN'); amountOut = price1Average.mul(amountIn).decode144(); } } function capture() public view returns(uint) { uint consultAmount = consult(hunnyToken, 1e18); if (consultAmount == 0) { return BOOTSTRAP_HUNNY_PRICE; } else { return consultAmount; } }}// Dependency file: @pancakeswap/pancake-swap-lib/contracts/token/BEP20/BEP20.sol// pragma solidity >=0.4.0;/** * @dev Implementation of the {IBEP20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {BEP20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-BEP20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of BEP20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IBEP20-approve}. */contract BEP20 is Context, IBEP20, Ownable { using SafeMath for uint256; using Address for address; mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor(string memory name, string memory symbol) public { _name = name; _symbol = symbol; _decimals = 18; } /** * @dev Returns the bep token owner. */ function getOwner() external override view returns (address) { return owner(); } /** * @dev Returns the token name. */ function name() public override view returns (string memory) { return _name; } /** * @dev Returns the token decimals. */ function decimals() public override view returns (uint8) { return _decimals; } /** * @dev Returns the token symbol. */ function symbol() public override view returns (string memory) { return _symbol; } /** * @dev See {BEP20-totalSupply}. */ function totalSupply() public override view returns (uint256) { return _totalSupply; } /** * @dev See {BEP20-balanceOf}. */ function balanceOf(address account) public override view returns (uint256) { return _balances[account]; } /** * @dev See {BEP20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {BEP20-allowance}. */ function allowance(address owner, address spender) public override view returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {BEP20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {BEP20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {BEP20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for `sender`'s tokens of at least * `amount`. */ 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; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {BEP20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {BEP20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) { _approve( _msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, 'BEP20: decreased allowance below zero') ); return true; } /** * @dev Creates `amount` tokens and assigns them to `msg.sender`, increasing * the total supply. * * Requirements * * - `msg.sender` must be the token owner */ function mint(uint256 amount) public onlyOwner returns (bool) { _mint(_msgSender(), amount); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ 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); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ 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); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ 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); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ 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); } /** * @dev Destroys `amount` tokens from `account`.`amount` is then deducted * from the caller's allowance. * * See {_burn} and {_approve}. */ function _burnFrom(address account, uint256 amount) internal { _burn(account, amount); _approve( account, _msgSender(), _allowances[account][_msgSender()].sub(amount, 'BEP20: burn amount exceeds allowance') ); }}// Dependency file: contracts/interfaces/IPancakeRouter01.sol// pragma solidity >=0.6.2;interface IPancakeRouter01 { function factory() external pure returns (address); function WETH() external pure returns (address); function addLiquidity( address tokenA, address tokenB, uint amountADesired, uint amountBDesired, uint amountAMin, uint amountBMin, address to, uint deadline ) external returns (uint amountA, uint amountB, uint liquidity); function addLiquidityETH( address token, uint amountTokenDesired, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external payable returns (uint amountToken, uint amountETH, uint liquidity); function removeLiquidity( address tokenA, address tokenB, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline ) external returns (uint amountA, uint amountB); function removeLiquidityETH( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external returns (uint amountToken, uint amountETH); function removeLiquidityWithPermit( address tokenA, address tokenB, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountA, uint amountB); function removeLiquidityETHWithPermit( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountToken, uint amountETH); function swapExactTokensForTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external returns (uint[] memory amounts); function swapTokensForExactTokens( uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline ) external returns (uint[] memory amounts); function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts); function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts); function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts); function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts); 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 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 getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);}// Dependency file: contracts/interfaces/IPancakeRouter02.sol// pragma solidity >=0.6.2;// import 'contracts/interfaces/IPancakeRouter01.sol';interface IPancakeRouter02 is IPancakeRouter01 { function removeLiquidityETHSupportingFeeOnTransferTokens( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external returns (uint amountETH); function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountETH); function swapExactTokensForTokensSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external; function swapExactETHForTokensSupportingFeeOnTransferTokens( uint amountOutMin, address[] calldata path, address to, uint deadline ) external payable; function swapExactTokensForETHSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external;}// Dependency file: contracts/interfaces/IPancakePair.sol// pragma solidity >=0.6.2;interface IPancakePair { event Approval(address indexed owner, address indexed spender, uint value); event Transfer(address indexed from, address indexed to, uint value); function name() external pure returns (string memory); function symbol() external pure returns (string memory); function decimals() external pure returns (uint8); function totalSupply() external view returns (uint); function balanceOf(address owner) external view returns (uint); function allowance(address owner, address spender) external view returns (uint); function approve(address spender, 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 DOMAIN_SEPARATOR() external view returns (bytes32); function PERMIT_TYPEHASH() external pure returns (bytes32); 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; event Mint(address indexed sender, uint amount0, uint amount1); event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); event Swap( address indexed sender, uint amount0In, uint amount1In, uint amount0Out, uint amount1Out, address indexed to ); event Sync(uint112 reserve0, uint112 reserve1); function MINIMUM_LIQUIDITY() external pure returns (uint); function factory() external view returns (address); function token0() external view returns (address); function token1() external view returns (address); function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); function price0CumulativeLast() external view returns (uint); function price1CumulativeLast() external view returns (uint); function kLast() external view returns (uint); function mint(address to) external returns (uint liquidity); function burn(address to) external returns (uint amount0, uint amount1); function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; function skim(address to) external; function sync() external; function initialize(address, address) external;}// Dependency file: contracts/interfaces/IPancakeFactory.sol// pragma solidity ^0.6.12;interface IPancakeFactory { event PairCreated(address indexed token0, address indexed token1, address pair, uint); function feeTo() external view returns (address); function feeToSetter() external view returns (address); function getPair(address tokenA, address tokenB) external view returns (address pair); function allPairs(uint) external view returns (address pair); function allPairsLength() external view returns (uint); function createPair(address tokenA, address tokenB) external returns (address pair); function setFeeTo(address) external; function setFeeToSetter(address) external;}// Dependency file: contracts/hunny/legacy/PancakeSwap.sol// pragma solidity ^0.6.12;// import "@pancakeswap/pancake-swap-lib/contracts/math/SafeMath.sol";// import "@pancakeswap/pancake-swap-lib/contracts/token/BEP20/IBEP20.sol";// import "@pancakeswap/pancake-swap-lib/contracts/token/BEP20/SafeBEP20.sol";// import "contracts/Constants.sol";// import "contracts/interfaces/IPancakeRouter02.sol";// import "contracts/interfaces/IPancakePair.sol";// import "contracts/interfaces/IPancakeFactory.sol";contract PancakeSwap { using SafeMath for uint; using SafeBEP20 for IBEP20; IPancakeRouter02 private ROUTER = IPancakeRouter02(Constants.PANCAKE_ROUTER); IPancakeFactory private factory = IPancakeFactory(Constants.PANCAKE_FACTORY); address internal cake = Constants.CAKE; address private _hunny; address private _wbnb = Constants.WBNB; constructor(address _hunnyAddress) public { _hunny = _hunnyAddress; } function hunnyBNBFlipToken() internal view returns(address) { return factory.getPair(_hunny, _wbnb); } function tokenToHunnyBNB(address token, uint amount) internal returns(uint flipAmount) { if (token == cake) { flipAmount = _cakeToHunnyBNBFlip(amount); } else { // flip flipAmount = _flipToHunnyBNBFlip(token, amount); } } function _cakeToHunnyBNBFlip(uint amount) private returns(uint flipAmount) { swapToken(cake, amount.div(2), _hunny); swapToken(cake, amount.sub(amount.div(2)), _wbnb); flipAmount = generateFlipToken(); } function _flipToHunnyBNBFlip(address token, uint amount) private returns(uint flipAmount) { IPancakePair pair = IPancakePair(token); address _token0 = pair.token0(); address _token1 = pair.token1(); IBEP20(token).safeApprove(address(ROUTER), 0); IBEP20(token).safeApprove(address(ROUTER), amount); ROUTER.removeLiquidity(_token0, _token1, amount, 0, 0, address(this), block.timestamp); if (_token0 == _wbnb) { swapToken(_token1, IBEP20(_token1).balanceOf(address(this)), _hunny); flipAmount = generateFlipToken(); } else if (_token1 == _wbnb) { swapToken(_token0, IBEP20(_token0).balanceOf(address(this)), _hunny); flipAmount = generateFlipToken(); } else { swapToken(_token0, IBEP20(_token0).balanceOf(address(this)), _hunny); swapToken(_token1, IBEP20(_token1).balanceOf(address(this)), _wbnb); flipAmount = generateFlipToken(); } } function swapToken(address _from, uint _amount, address _to) private { if (_from == _to) return; address[] memory path; if (_from == _wbnb || _to == _wbnb) { path = new address[](2); path[0] = _from; path[1] = _to; } else { path = new address[](3); path[0] = _from; path[1] = _wbnb; path[2] = _to; } IBEP20(_from).safeApprove(address(ROUTER), 0); IBEP20(_from).safeApprove(address(ROUTER), _amount); ROUTER.swapExactTokensForTokens(_amount, 0, path, address(this), block.timestamp); } function generateFlipToken() private returns(uint liquidity) { uint amountADesired = IBEP20(_hunny).balanceOf(address(this)); uint amountBDesired = IBEP20(_wbnb).balanceOf(address(this)); IBEP20(_hunny).safeApprove(address(ROUTER), 0); IBEP20(_hunny).safeApprove(address(ROUTER), amountADesired); IBEP20(_wbnb).safeApprove(address(ROUTER), 0); IBEP20(_wbnb).safeApprove(address(ROUTER), amountBDesired); (,,liquidity) = ROUTER.addLiquidity(_hunny, _wbnb, amountADesired, amountBDesired, 0, 0, address(this), block.timestamp); // send dust IBEP20(_hunny).transfer(msg.sender, IBEP20(_hunny).balanceOf(address(this))); IBEP20(_wbnb).transfer(msg.sender, IBEP20(_wbnb).balanceOf(address(this))); }}// Dependency file: contracts/interfaces/IHunnyMinter.sol// pragma solidity ^0.6.12;interface IHunnyMinter { function isMinter(address) view external returns(bool); function amountHunnyToMint(uint bnbProfit) view external returns(uint); function amountHunnyToMintForHunnyBNB(uint amount, uint duration) view external returns(uint); function withdrawalFee(uint amount, uint depositedAt) view external returns(uint); function performanceFee(uint profit) view external returns(uint); function mintFor(address flip, uint _withdrawalFee, uint _performanceFee, address to, uint depositedAt) external; function mintForHunnyBNB(uint amount, uint duration, address to) external; function hunnyPerProfitBNB() view external returns(uint); function hunnyPerBlockLottery() view external returns(uint); function WITHDRAWAL_FEE_FREE_PERIOD() view external returns(uint); function WITHDRAWAL_FEE() view external returns(uint); function setMinter(address minter, bool canMint) external;}// Dependency file: contracts/interfaces/IHunnyOracle.sol// pragma solidity ^0.6.12;interface IHunnyOracle { function price0CumulativeLast() external view returns(uint); function price1CumulativeLast() external view returns(uint); function blockTimestampLast() external view returns(uint); function capture() external view returns(uint224); function update() external;}// Dependency file: contracts/interfaces/legacy/IStakingRewards.sol// pragma solidity ^0.6.12;interface IStakingRewards { function stakeTo(uint256 amount, address _to) external; function notifyRewardAmount(uint256 reward) external;}// Dependency file: contracts/interfaces/legacy/IStrategyHelper.sol// pragma solidity ^0.6.12;/*** MIT License* ===========** Copyright (c) 2020 HunnyFinance** Permission is hereby granted, free of charge, to any person obtaining a copy* of this software and associated documentation files (the "Software"), to deal* in the Software without restriction, including without limitation the rights* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell* copies of the Software, and to permit persons to whom the Software is* furnished to do so, subject to the following conditions:** The above copyright notice and this permission notice shall be included in all* copies or substantial portions of the Software.** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE*/// import "contracts/interfaces/IHunnyMinter.sol";interface IStrategyHelper { function tokenPriceInBNB(address _token) view external returns(uint); function cakePriceInBNB() view external returns(uint); function bnbPriceInUSD() view external returns(uint); function flipPriceInBNB(address _flip) view external returns(uint); function flipPriceInUSD(address _flip) view external returns(uint); function profitOf(IHunnyMinter minter, address _flip, uint amount) external view returns (uint _usd, uint _hunny, uint _bnb); function tvl(address _flip, uint amount) external view returns (uint); // in USD function tvlInBNB(address _flip, uint amount) external view returns (uint); // in BNB function apy(IHunnyMinter minter, uint pid) external view returns(uint _usd, uint _hunny, uint _bnb); function compoundingAPY(uint pid, uint compoundUnit) view external returns(uint);}// Dependency file: contracts/hunny/legacy/HunnyMinter.sol// pragma solidity ^0.6.12;// import "@pancakeswap/pancake-swap-lib/contracts/token/BEP20/BEP20.sol";// import "@pancakeswap/pancake-swap-lib/contracts/token/BEP20/SafeBEP20.sol";// import "@pancakeswap/pancake-swap-lib/contracts/math/SafeMath.sol";// import "@pancakeswap/pancake-swap-lib/contracts/access/Ownable.sol";// import "contracts/hunny/legacy/PancakeSwap.sol";// import "contracts/Constants.sol";// import "contracts/interfaces/IHunnyMinter.sol";// import "contracts/interfaces/IHunnyOracle.sol";// import "contracts/interfaces/legacy/IStakingRewards.sol";// import "contracts/interfaces/legacy/IStrategyHelper.sol";contract HunnyMinter is IHunnyMinter, Ownable, PancakeSwap { using SafeMath for uint; using SafeBEP20 for IBEP20; BEP20 private hunny; address public dev = Constants.HUNNY_DEPLOYER; IBEP20 private WBNB = IBEP20(Constants.WBNB); uint public override WITHDRAWAL_FEE_FREE_PERIOD = 2 days; uint public override WITHDRAWAL_FEE = 50; uint public constant FEE_MAX = 10000; uint public PERFORMANCE_FEE = 3000; // 30% uint public override hunnyPerProfitBNB; uint public override hunnyPerBlockLottery; uint public lastLotteryMintBlock; uint public hunnyPerHunnyBNBFlip; address public hunnyPool; address public lotteryPool; IHunnyOracle public oracle; IStrategyHelper public helper; mapping (address => bool) private _minters; modifier onlyMinter { require(isMinter(msg.sender) == true, "not minter"); _; } constructor(address _hunny, address _hunnyPool, address _lotteryPool, address _oracle, address _helper) PancakeSwap(_hunny) public { hunny = BEP20(_hunny); hunnyPool = _hunnyPool; lotteryPool = _lotteryPool; oracle = IHunnyOracle(_oracle); helper = IStrategyHelper(_helper); hunnyPerProfitBNB = Constants.HUNNY_PER_PROFIT_BNB; hunnyPerBlockLottery = Constants.HUNNY_PER_BLOCK_LOTTERY; lastLotteryMintBlock = block.number; hunnyPerHunnyBNBFlip = Constants.HUNNY_PER_HUNNY_BNB_FLIP; hunny.approve(hunnyPool, uint(~0)); } function transferHunnyOwner(address _owner) external onlyOwner { Ownable(address(hunny)).transferOwnership(_owner); } function setWithdrawalFee(uint _fee) external onlyOwner { require(_fee < 500, "wrong fee"); // less 5% WITHDRAWAL_FEE = _fee; } function setPerformanceFee(uint _fee) external onlyOwner { require(_fee < 5000, "wrong fee"); PERFORMANCE_FEE = _fee; } function setWithdrawalFeeFreePeriod(uint _period) external onlyOwner { WITHDRAWAL_FEE_FREE_PERIOD = _period; } function setMinter(address minter, bool canMint) external override onlyOwner { if (canMint) { _minters[minter] = canMint; } else { delete _minters[minter]; } } function setHunnyPerProfitBNB(uint _ratio) external onlyOwner { hunnyPerProfitBNB = _ratio; } function setHunnyPerHunnyBNBFlip(uint _hunnyPerHunnyBNBFlip) external onlyOwner { hunnyPerHunnyBNBFlip = _hunnyPerHunnyBNBFlip; } function setHunnyPerBlockLottery(uint _hunnyPerBlockLottery) external onlyOwner { hunnyPerBlockLottery = _hunnyPerBlockLottery; } function setHelper(IStrategyHelper _helper) external onlyOwner { require(address(_helper) != address(0), "zero address"); helper = _helper; } function setOracle(IHunnyOracle _oracle) external onlyOwner { require(address(_oracle) != address(0), "zero address"); oracle = _oracle; } function isMinter(address account) override view public returns(bool) { if (hunny.getOwner() != address(this)) { return false; } if (block.timestamp < 1605585600) { // 12:00 SGT 17th November 2020 return false; } return _minters[account]; } function amountHunnyToMint(uint bnbProfit) override view public returns(uint) { return bnbProfit.mul(hunnyPerProfitBNB).div(1e18); } function amountHunnyToMintForHunnyBNB(uint amount, uint duration) override view public returns(uint) { return amount.mul(hunnyPerHunnyBNBFlip).mul(duration).div(365 days).div(1e18); } function withdrawalFee(uint amount, uint depositedAt) override view external returns(uint) { if (depositedAt.add(WITHDRAWAL_FEE_FREE_PERIOD) > block.timestamp) { return amount.mul(WITHDRAWAL_FEE).div(FEE_MAX); } return 0; } function performanceFee(uint profit) override view public returns(uint) { return profit.mul(PERFORMANCE_FEE).div(FEE_MAX); } function mintFor(address flip, uint _withdrawalFee, uint _performanceFee, address to, uint) override external onlyMinter { uint feeSum = _performanceFee.add(_withdrawalFee); IBEP20(flip).safeTransferFrom(msg.sender, address(this), feeSum); uint hunnyBNBAmount = tokenToHunnyBNB(flip, IBEP20(flip).balanceOf(address(this))); address flipToken = hunnyBNBFlipToken(); IBEP20(flipToken).safeTransfer(hunnyPool, hunnyBNBAmount); IStakingRewards(hunnyPool).notifyRewardAmount(hunnyBNBAmount); uint contribution = helper.tvlInBNB(flipToken, hunnyBNBAmount).mul(_performanceFee).div(feeSum); uint mintHunny = amountHunnyToMint(contribution); mint(mintHunny, to); // addition step // update oracle price oracle.update(); } function mintForHunnyBNB(uint amount, uint duration, address to) override external onlyMinter { uint mintHunny = amountHunnyToMintForHunnyBNB(amount, duration); if (mintHunny == 0) return; mint(mintHunny, to); } function mint(uint amount, address to) private { hunny.mint(amount); hunny.transfer(to, amount); uint hunnyForDev = amount.mul(15).div(100); hunny.mint(hunnyForDev); IStakingRewards(hunnyPool).stakeTo(hunnyForDev, dev); // mint for lottery pool mintForLottery(); } // only after when lottery pool address was set // token calculated from the block when dev set lottery pool address only function mintForLottery() private { if (lotteryPool != address(0)) { uint amountHunny = block.number.sub(lastLotteryMintBlock).mul(hunnyPerBlockLottery); hunny.mint(amountHunny); hunny.transfer(lotteryPool, amountHunny); } lastLotteryMintBlock = block.number; }}// Dependency file: contracts/library/HomoraMath.sol// pragma solidity 0.6.12;// import "@pancakeswap/pancake-swap-lib/contracts/math/SafeMath.sol";library HomoraMath { using SafeMath for uint; function divCeil(uint lhs, uint rhs) internal pure returns (uint) { return lhs.add(rhs).sub(1) / rhs; } function fmul(uint lhs, uint rhs) internal pure returns (uint) { return lhs.mul(rhs) / (2**112); } function fdiv(uint lhs, uint rhs) internal pure returns (uint) { return lhs.mul(2**112) / rhs; } // implementation from https://github.com/Uniswap/uniswap-lib/commit/99f3f28770640ba1bb1ff460ac7c5292fb8291a0 // original implementation: https://github.com/abdk-consulting/abdk-libraries-solidity/blob/master/ABDKMath64x64.sol#L687 function sqrt(uint x) internal pure returns (uint) { if (x == 0) return 0; uint xx = x; uint r = 1; if (xx >= 0x100000000000000000000000000000000) { xx >>= 128; r <<= 64; } if (xx >= 0x10000000000000000) { xx >>= 64; r <<= 32; } if (xx >= 0x100000000) { xx >>= 32; r <<= 16; } if (xx >= 0x10000) { xx >>= 16; r <<= 8; } if (xx >= 0x100) { xx >>= 8; r <<= 4; } if (xx >= 0x10) { xx >>= 4; r <<= 2; } if (xx >= 0x8) { r <<= 1; } r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; // Seven iterations should be enough uint r1 = x / r; return (r < r1 ? r : r1); }}// Dependency file: contracts/interfaces/IMasterChef.sol// pragma solidity ^0.6.12;interface IMasterChef { function cakePerBlock() view external returns(uint); function totalAllocPoint() view external returns(uint); function poolInfo(uint _pid) view external returns(address lpToken, uint allocPoint, uint lastRewardBlock, uint accCakePerShare); function userInfo(uint _pid, address _account) view external returns(uint amount, uint rewardDebt); function poolLength() view external returns(uint); function deposit(uint256 _pid, uint256 _amount) external; function withdraw(uint256 _pid, uint256 _amount) external; function emergencyWithdraw(uint256 _pid) external; function enterStaking(uint256 _amount) external; function leaveStaking(uint256 _amount) external;}// Dependency file: contracts/interfaces/AggregatorV3Interface.sol// pragma solidity >=0.6.0;interface AggregatorV3Interface { function decimals() external view returns (uint8); function description() external view returns (string memory); function version() external view returns (uint256); // getRoundData and latestRoundData should both raise "No data present" // if they do not have data to report, instead of returning unset values // which could be misinterpreted as actual reported values. function getRoundData(uint80 _roundId) external view returns ( uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound ); function latestRoundData() external view returns ( uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound );}// Dependency file: contracts/vaults/legacy/StrategyHelperV1.sol// pragma solidity ^0.6.12;// import "@pancakeswap/pancake-swap-lib/contracts/access/Ownable.sol";// import "@pancakeswap/pancake-swap-lib/contracts/token/BEP20/BEP20.sol";// import "@pancakeswap/pancake-swap-lib/contracts/token/BEP20/IBEP20.sol";// import "contracts/Constants.sol";// import "contracts/library/HomoraMath.sol";// import "contracts/interfaces/IPancakeFactory.sol";// import "contracts/interfaces/IPancakePair.sol";// import "contracts/interfaces/IMasterChef.sol";// import "contracts/interfaces/IHunnyMinter.sol";// import "contracts/interfaces/IHunnyOracle.sol";// import "contracts/interfaces/AggregatorV3Interface.sol";// no storage// There are only calculations for apy, tvl, etc.contract StrategyHelperV1 is Ownable { using SafeMath for uint; IBEP20 private WBNB = IBEP20(Constants.WBNB); IBEP20 private CAKE = IBEP20(Constants.CAKE); IBEP20 private BUSD = IBEP20(Constants.BUSD); IBEP20 public hunny; IHunnyOracle public oracle; IMasterChef private master = IMasterChef(Constants.PANCAKE_CHEF); IPancakeFactory private factory = IPancakeFactory(Constants.PANCAKE_FACTORY); mapping(address => address) private tokenFeeds; constructor(address _hunny) public { hunny = IBEP20(_hunny); } // get hunny price to in BNB function tokenPriceInBNB(address _token) public view returns(uint) { if (_token == address(CAKE)) { return cakePriceInBNB(); } else if (_token == address(hunny)) { return oracle.capture(); } else { return unsafeTokenPriceInBNB(_token); } } function unsafeTokenPriceInBNB(address _token) private view returns(uint) { address pair = factory.getPair(_token, address(WBNB)); uint decimal = uint(BEP20(_token).decimals()); (uint reserve0, uint reserve1, ) = IPancakePair(pair).getReserves(); if (IPancakePair(pair).token0() == _token) { return reserve1.mul(10**decimal).div(reserve0); } else if (IPancakePair(pair).token1() == _token) { return reserve0.mul(10**decimal).div(reserve1); } else { return 0; } } function cakePriceInUSD() view public returns(uint) { (, int price, , ,) = AggregatorV3Interface(tokenFeeds[address(CAKE)]).latestRoundData(); return uint(price).mul(1e10); } function cakePriceInBNB() view public returns(uint) { return cakePriceInUSD().mul(1e18).div(bnbPriceInUSD()); } function bnbPriceInUSD() view public returns(uint) { (, int price, , ,) = AggregatorV3Interface(tokenFeeds[address(WBNB)]).latestRoundData(); return uint(price).mul(1e10); } function cakePerYearOfPool(uint pid) view public returns(uint) { (, uint allocPoint,,) = master.poolInfo(pid); return master.cakePerBlock().mul(blockPerYear()).mul(allocPoint).div(master.totalAllocPoint()); } function blockPerYear() pure public returns(uint) { // 86400 / 3 * 365 return 10512000; } function profitOf(address minter, address flip, uint amount) external view returns (uint _usd, uint _hunny, uint _bnb) { _usd = tvl(flip, amount); if (address(minter) == address(0)) { _hunny = 0; } else { uint performanceFee = IHunnyMinter(minter).performanceFee(_usd); _usd = _usd.sub(performanceFee); uint bnbAmount = performanceFee.mul(1e18).div(bnbPriceInUSD()); _hunny = IHunnyMinter(minter).amountHunnyToMint(bnbAmount); } _bnb = 0; } // apy() = cakePrice * (cakePerBlock * blockPerYear * weight) / PoolValue(=WBNB*2) function _apy(uint pid) view private returns(uint) { (address token,,,) = master.poolInfo(pid); uint poolSize = tvl(token, IBEP20(token).balanceOf(address(master))).mul(1e18).div(bnbPriceInUSD()); return cakePriceInBNB().mul(cakePerYearOfPool(pid)).div(poolSize); } function apy(address, uint pid) view public returns(uint _usd, uint _hunny, uint _bnb) { _usd = compoundingAPY(pid, 1 days); _hunny = 0; _bnb = 0; } function tvl(address _flip, uint amount) public view returns (uint) { if (_flip == address(CAKE)) { return cakePriceInBNB().mul(bnbPriceInUSD()).mul(amount).div(1e36); } address _token0 = IPancakePair(_flip).token0(); address _token1 = IPancakePair(_flip).token1(); // using hunny price from the oracle if (_token0 == address(hunny) || _token1 == address(hunny)) { uint hunnyBalance = hunny.balanceOf(address(_flip)).mul(amount).div(IBEP20(_flip).totalSupply()); uint priceInBNB = tokenPriceInBNB(address(hunny)); uint price = priceInBNB.mul(bnbPriceInUSD()).div(1e18); return hunnyBalance.mul(price).div(1e18).mul(2); } if (_token0 == address(WBNB) || _token1 == address(WBNB)) { uint bnb = WBNB.balanceOf(address(_flip)).mul(amount).div(IBEP20(_flip).totalSupply()); uint price = bnbPriceInUSD(); return bnb.mul(price).div(1e18).mul(2); } uint balanceToken0 = IBEP20(_token0).balanceOf(_flip); uint price = tokenPriceInBNB(_token0); return balanceToken0.mul(price).div(1e18).mul(bnbPriceInUSD()).div(1e18).mul(2); } function tvlInBNB(address _flip, uint amount) public view returns (uint) { if (_flip == address(CAKE)) { return cakePriceInBNB().mul(amount).div(1e18); } address _token0 = IPancakePair(_flip).token0(); address _token1 = IPancakePair(_flip).token1(); // using hunny price from the oracle if (_token0 == address(hunny) || _token1 == address(hunny)) { uint hunnyBalance = hunny.balanceOf(address(_flip)).mul(amount).div(IBEP20(_flip).totalSupply()); uint priceInBNB = tokenPriceInBNB(address(hunny)); return hunnyBalance.mul(priceInBNB).div(1e18).mul(2); } if (_token0 == address(WBNB) || _token1 == address(WBNB)) { uint bnb = WBNB.balanceOf(address(_flip)).mul(amount).div(IBEP20(_flip).totalSupply()); return bnb.mul(2); } uint balanceToken0 = IBEP20(_token0).balanceOf(_flip); uint price = tokenPriceInBNB(_token0); return balanceToken0.mul(price).div(1e18).mul(2); } function compoundingAPY(uint pid, uint compoundUnit) view public returns(uint) { uint __apy = _apy(pid); uint compoundTimes = 365 days / compoundUnit; uint unitAPY = 1e18 + (__apy / compoundTimes); uint result = 1e18; for(uint i=0; i<compoundTimes; i++) { result = (result * unitAPY) / 1e18; } return result - 1e18; } function setOracle(address oracleAddress) public onlyOwner { oracle = IHunnyOracle(oracleAddress); } function setTokenFeed(address asset, address feed) public onlyOwner { tokenFeeds[asset] = feed; }}// Dependency file: @openzeppelin/contracts/math/Math.sol// pragma solidity >=0.6.0 <0.8.0;/** * @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); }}// Dependency file: @openzeppelin/contracts/utils/ReentrancyGuard.sol// pragma solidity >=0.6.0 <0.8.0;/** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied 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. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */abstract contract ReentrancyGuard { // 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 // 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 // pointer aliasing, and it cannot be disabled. // 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 // 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 // increase the likelihood of the full refund coming into effect. uint256 private constant _NOT_ENTERED = 1; uint256 private constant _ENTERED = 2; uint256 private _status; constructor () internal { _status = _NOT_ENTERED; } /** * @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() { // On the first call to nonReentrant, _notEntered will be true require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; }}// Dependency file: contracts/library/legacy/RewardsDistributionRecipient.sol/* ____ __ __ __ _ / __/__ __ ___ / /_ / / ___ / /_ (_)__ __ _\ \ / // // _ \/ __// _ \/ -_)/ __// / \ \ //___/ \_, //_//_/\__//_//_/\__/ \__//_/ /_\_\ /___/* Docs: https://docs.synthetix.io/*** MIT License* ===========** Copyright (c) 2020 Synthetix** Permission is hereby granted, free of charge, to any person obtaining a copy* of this software and associated documentation files (the "Software"), to deal* in the Software without restriction, including without limitation the rights* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell* copies of the Software, and to permit persons to whom the Software is* furnished to do so, subject to the following conditions:** The above copyright notice and this permission notice shall be included in all* copies or substantial portions of the Software.** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE*/// pragma solidity ^0.6.2;// import "@pancakeswap/pancake-swap-lib/contracts/access/Ownable.sol";abstract contract RewardsDistributionRecipient is Ownable { address public rewardsDistribution; modifier onlyRewardsDistribution() { require(msg.sender == rewardsDistribution, "onlyRewardsDistribution"); _; } function notifyRewardAmount(uint256 reward) virtual external; function setRewardsDistribution(address _rewardsDistribution) external onlyOwner { rewardsDistribution = _rewardsDistribution; }}// Dependency file: contracts/library/legacy/Pausable.sol/* ____ __ __ __ _ / __/__ __ ___ / /_ / / ___ / /_ (_)__ __ _\ \ / // // _ \/ __// _ \/ -_)/ __// / \ \ //___/ \_, //_//_/\__//_//_/\__/ \__//_/ /_\_\ /___/* Docs: https://docs.synthetix.io/*** MIT License* ===========** Copyright (c) 2020 Synthetix** Permission is hereby granted, free of charge, to any person obtaining a copy* of this software and associated documentation files (the "Software"), to deal* in the Software without restriction, including without limitation the rights* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell* copies of the Software, and to permit persons to whom the Software is* furnished to do so, subject to the following conditions:** The above copyright notice and this permission notice shall be included in all* copies or substantial portions of the Software.** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE*/// pragma solidity ^0.6.2;// import "@pancakeswap/pancake-swap-lib/contracts/access/Ownable.sol";abstract contract Pausable is Ownable { uint public lastPauseTime; bool public paused; event PauseChanged(bool isPaused); modifier notPaused { require(!paused, "This action cannot be performed while the contract is paused"); _; } constructor() internal { require(owner() != address(0), "Owner must be set"); } function setPaused(bool _paused) external onlyOwner { if (_paused == paused) { return; } paused = _paused; if (paused) { lastPauseTime = now; } emit PauseChanged(paused); }}// Dependency file: contracts/interfaces/legacy/IStrategyLegacy.sol// pragma solidity ^0.6.12;pragma experimental ABIEncoderV2;/*** MIT License* ===========** Copyright (c) 2020 HunnyFinance** Permission is hereby granted, free of charge, to any person obtaining a copy* of this software and associated documentation files (the "Software"), to deal* in the Software without restriction, including without limitation the rights* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell* copies of the Software, and to permit persons to whom the Software is* furnished to do so, subject to the following conditions:** The above copyright notice and this permission notice shall be included in all* copies or substantial portions of the Software.** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE*/interface IStrategyLegacy { struct Profit { uint usd; uint hunny; uint bnb; } struct APY { uint usd; uint hunny; uint bnb; } struct UserInfo { uint balance; uint principal; uint available; Profit profit; uint poolTVL; APY poolAPY; } function deposit(uint _amount) external; function depositAll() external; function withdraw(uint256 _amount) external; // HUNNY STAKING POOL ONLY function withdrawAll() external; function getReward() external; // HUNNY STAKING POOL ONLY function harvest() external; function balance() external view returns (uint); function balanceOf(address account) external view returns (uint); function principalOf(address account) external view returns (uint); function withdrawableBalanceOf(address account) external view returns (uint); // HUNNY STAKING POOL ONLY function profitOf(address account) external view returns (uint _usd, uint _hunny, uint _bnb);// function earned(address account) external view returns (uint); function tvl() external view returns (uint); // in USD function apy() external view returns (uint _usd, uint _hunny, uint _bnb); /* ========== Strategy Information ========== */// function pid() external view returns (uint);// function poolType() external view returns (PoolTypes);// function isMinter() external view returns (bool, address);// function getDepositedAt(address account) external view returns (uint);// function getRewardsToken() external view returns (address); function info(address account) external view returns (UserInfo memory);}// Dependency file: contracts/vaults/legacy/HunnyPool.sol// pragma solidity ^0.6.12;// import "@openzeppelin/contracts/math/Math.sol";// import "@pancakeswap/pancake-swap-lib/contracts/math/SafeMath.sol";// import "@pancakeswap/pancake-swap-lib/contracts/token/BEP20/SafeBEP20.sol";// import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";// import "contracts/Constants.sol";// import "contracts/library/legacy/RewardsDistributionRecipient.sol";// import "contracts/library/legacy/Pausable.sol";// import "contracts/interfaces/legacy/IStrategyHelper.sol";// import "contracts/interfaces/IPancakeRouter02.sol";// import "contracts/interfaces/legacy/IStrategyLegacy.sol";interface IPresale { function endTime() view external returns(uint256); function totalBalance() view external returns(uint); function flipToken() view external returns(address);}contract HunnyPool is IStrategyLegacy, RewardsDistributionRecipient, ReentrancyGuard, Pausable { using SafeMath for uint256; using SafeBEP20 for IBEP20; /* ========== STATE VARIABLES ========== */ IBEP20 public rewardsToken; // hunny/bnb flip IBEP20 public stakingToken; uint256 public periodFinish = 0; uint256 public rewardRate = 0; uint256 public rewardsDuration = 90 days; uint256 public lastUpdateTime; uint256 public rewardPerTokenStored; mapping(address => uint256) public userRewardPerTokenPaid; mapping(address => uint256) public rewards; uint256 private _totalSupply; mapping(address => uint256) private _balances; mapping(address => bool) private _stakePermission; /* ========== PRESALE ============== */ address private presaleContract; address private constant deadAddress = 0x000000000000000000000000000000000000dEaD; mapping(address => uint256) private _presaleBalance; uint256 public TIMESTAMP_2_HOURS_AFTER_PRESALE; uint256 public TIMESTAMP_90_DAYS_AFTER_PRESALE; /* ========== HUNNY HELPER ========= */ IStrategyHelper public helper; IPancakeRouter02 private ROUTER = IPancakeRouter02(Constants.PANCAKE_ROUTER); /* ========== CONSTRUCTOR ========== */ constructor(address _hunny, address _presale, address _helper) public { stakingToken = IBEP20(_hunny); // hunny presaleContract = _presale; helper = IStrategyHelper(_helper); rewardsDistribution = msg.sender; _stakePermission[msg.sender] = true; _stakePermission[presaleContract] = true; stakingToken.safeApprove(address(ROUTER), uint(~0)); TIMESTAMP_2_HOURS_AFTER_PRESALE = IPresale(_presale).endTime() + 2 hours; TIMESTAMP_90_DAYS_AFTER_PRESALE = IPresale(_presale).endTime() + 90 days; } /* ========== VIEWS ========== */ function totalSupply() external view returns (uint256) { return _totalSupply; } function balance() override external view returns (uint) { return _totalSupply; } function balanceOf(address account) override external view returns (uint256) { return _balances[account]; } function presaleBalanceOf(address account) external view returns(uint256) { return _presaleBalance[account]; } function principalOf(address account) override external view returns (uint256) { return _balances[account]; } function withdrawableBalanceOf(address account) override public view returns (uint) { if (block.timestamp > TIMESTAMP_90_DAYS_AFTER_PRESALE) { // unlock all presale hunny after 90 days of presale return _balances[account]; } else if (block.timestamp < TIMESTAMP_2_HOURS_AFTER_PRESALE) { return _balances[account].sub(_presaleBalance[account]); } else { uint soldInPresale = IPresale(presaleContract).totalBalance().div(2).mul(3); // mint 150% of presale for making flip token uint hunnySupply = stakingToken.totalSupply().sub(stakingToken.balanceOf(deadAddress)); if (soldInPresale >= hunnySupply) { return _balances[account].sub(_presaleBalance[account]); } uint hunnyNewMint = hunnySupply.sub(soldInPresale); if (hunnyNewMint >= soldInPresale) { return _balances[account]; } uint lockedRatio = (soldInPresale.sub(hunnyNewMint)).mul(1e18).div(soldInPresale); uint lockedBalance = _presaleBalance[account].mul(lockedRatio).div(1e18); return _balances[account].sub(lockedBalance); } } function profitOf(address account) override public view returns (uint _usd, uint _hunny, uint _bnb) { _usd = 0; _hunny = 0; _bnb = helper.tvlInBNB(address(rewardsToken), earned(account)); } function tvl() override public view returns (uint) { uint price = helper.tokenPriceInBNB(address(stakingToken)); return _totalSupply.mul(price).div(1e18); } function apy() override public view returns(uint _usd, uint _hunny, uint _bnb) { uint tokenDecimals = 1e18; uint __totalSupply = _totalSupply; if (__totalSupply == 0) { __totalSupply = tokenDecimals; } uint rewardPerTokenPerSecond = rewardRate.mul(tokenDecimals).div(__totalSupply); uint hunnyPrice = helper.tokenPriceInBNB(address(stakingToken)); uint flipPrice = helper.tvlInBNB(address(rewardsToken), 1e18); _usd = 0; _hunny = 0; _bnb = rewardPerTokenPerSecond.mul(365 days).mul(flipPrice).div(hunnyPrice); } 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 _balances[account].mul(rewardPerToken().sub(userRewardPerTokenPaid[account])).div(1e18).add(rewards[account]); } function getRewardForDuration() external view returns (uint256) { return rewardRate.mul(rewardsDuration); } /* ========== MUTATIVE FUNCTIONS ========== */ function _deposit(uint256 amount, address _to) private nonReentrant notPaused updateReward(_to) { require(amount > 0, "amount"); _totalSupply = _totalSupply.add(amount); _balances[_to] = _balances[_to].add(amount); stakingToken.safeTransferFrom(msg.sender, address(this), amount); emit Staked(_to, amount); } function deposit(uint256 amount) override public { _deposit(amount, msg.sender); } function depositAll() override external { deposit(stakingToken.balanceOf(msg.sender)); } function withdraw(uint256 amount) override public nonReentrant updateReward(msg.sender) { require(amount > 0, "amount"); require(amount <= withdrawableBalanceOf(msg.sender), "locked"); _totalSupply = _totalSupply.sub(amount); _balances[msg.sender] = _balances[msg.sender].sub(amount); stakingToken.safeTransfer(msg.sender, amount); emit Withdrawn(msg.sender, amount); } function withdrawAll() override external { uint _withdraw = withdrawableBalanceOf(msg.sender); if (_withdraw > 0) { withdraw(_withdraw); } getReward(); } function getReward() override public nonReentrant updateReward(msg.sender) { uint256 reward = rewards[msg.sender]; if (reward > 0) { rewards[msg.sender] = 0; reward = _flipToWBNB(reward); IBEP20(ROUTER.WETH()).safeTransfer(msg.sender, reward); emit RewardPaid(msg.sender, reward); } } function _flipToWBNB(uint amount) private returns(uint reward) { address wbnb = ROUTER.WETH(); (uint rewardHunny,) = ROUTER.removeLiquidity( address(stakingToken), wbnb, amount, 0, 0, address(this), block.timestamp); address[] memory path = new address[](2); path[0] = address(stakingToken); path[1] = wbnb; ROUTER.swapExactTokensForTokens(rewardHunny, 0, path, address(this), block.timestamp); reward = IBEP20(wbnb).balanceOf(address(this)); } function harvest() override external {} function info(address account) override external view returns(UserInfo memory) { UserInfo memory userInfo; userInfo.balance = _balances[account]; userInfo.principal = _balances[account]; userInfo.available = withdrawableBalanceOf(account); Profit memory profit; (uint usd, uint hunny, uint bnb) = profitOf(account); profit.usd = usd; profit.hunny = hunny; profit.bnb = bnb; userInfo.profit = profit; userInfo.poolTVL = tvl(); APY memory poolAPY; (usd, hunny, bnb) = apy(); poolAPY.usd = usd; poolAPY.hunny = hunny; poolAPY.bnb = bnb; userInfo.poolAPY = poolAPY; return userInfo; } /* ========== RESTRICTED FUNCTIONS ========== */ function setRewardsToken(address _rewardsToken) external onlyOwner { require(address(rewardsToken) == address(0), "set rewards token already"); rewardsToken = IBEP20(_rewardsToken); // safe approve IBEP20(_rewardsToken).safeApprove(address(ROUTER), 0); IBEP20(_rewardsToken).safeApprove(address(ROUTER), uint(~0)); } function setHelper(IStrategyHelper _helper) external onlyOwner { require(address(_helper) != address(0), "zero address"); helper = _helper; } function setStakePermission(address _address, bool permission) external onlyOwner { _stakePermission[_address] = permission; } function stakeTo(uint256 amount, address _to) external canStakeTo { _deposit(amount, _to); if (msg.sender == presaleContract) { _presaleBalance[_to] = _presaleBalance[_to].add(amount); } } function notifyRewardAmount(uint256 reward) override external onlyRewardsDistribution updateReward(address(0)) { 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), "reward"); lastUpdateTime = block.timestamp; periodFinish = block.timestamp.add(rewardsDuration); emit RewardAdded(reward); } function recoverBEP20(address tokenAddress, uint256 tokenAmount) external onlyOwner { require(tokenAddress != address(stakingToken) && tokenAddress != address(rewardsToken), "tokenAddress"); IBEP20(tokenAddress).safeTransfer(owner(), tokenAmount); emit Recovered(tokenAddress, tokenAmount); } function setRewardsDuration(uint256 _rewardsDuration) external onlyOwner { require(periodFinish == 0 || block.timestamp > periodFinish, "period"); rewardsDuration = _rewardsDuration; emit RewardsDurationUpdated(rewardsDuration); } /* ========== MODIFIERS ========== */ modifier updateReward(address account) { rewardPerTokenStored = rewardPerToken(); lastUpdateTime = lastTimeRewardApplicable(); if (account != address(0)) { rewards[account] = earned(account); userRewardPerTokenPaid[account] = rewardPerTokenStored; } _; } modifier canStakeTo() { require(_stakePermission[msg.sender], 'auth'); _; } /* ========== EVENTS ========== */ event RewardAdded(uint256 reward); event Staked(address indexed user, uint256 amount); event Withdrawn(address indexed user, uint256 amount); event RewardPaid(address indexed user, uint256 reward); event RewardsDurationUpdated(uint256 newDuration); event Recovered(address token, uint256 amount);}// Dependency file: contracts/vaults/legacy/HunnyBNBPool.sol// pragma solidity ^0.6.12;/*** MIT License* ===========** Copyright (c) 2020 HunnyFinance** Permission is hereby granted, free of charge, to any person obtaining a copy* of this software and associated documentation files (the "Software"), to deal* in the Software without restriction, including without limitation the rights* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell* copies of the Software, and to permit persons to whom the Software is* furnished to do so, subject to the following conditions:** The above copyright notice and this permission notice shall be included in all* copies or substantial portions of the Software.** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE*/// import "@pancakeswap/pancake-swap-lib/contracts/token/BEP20/SafeBEP20.sol";// import "@pancakeswap/pancake-swap-lib/contracts/access/Ownable.sol";// import "contracts/Constants.sol";// import "contracts/interfaces/IMasterChef.sol";// import "contracts/interfaces/IHunnyMinter.sol";// import "contracts/interfaces/legacy/IStrategyHelper.sol";// import "contracts/interfaces/legacy/IStrategyLegacy.sol";contract HunnyBNBPool is IStrategyLegacy, Ownable { using SafeBEP20 for IBEP20; using SafeMath for uint256; IBEP20 private HUNNY; IBEP20 private CAKE = IBEP20(Constants.CAKE); IBEP20 private WBNB = IBEP20(Constants.WBNB); IBEP20 public token; address public presale; uint public totalShares; mapping (address => uint) private _shares; mapping (address => uint) public depositedAt; IHunnyMinter public minter; IStrategyHelper public helper; constructor(address _hunny, address _presale, address _helper) public { HUNNY = IBEP20(_hunny); presale = _presale; helper = IStrategyHelper(_helper); } function setFlipToken(address _token) public onlyOwner { require(address(token) == address(0), 'flip token set already'); token = IBEP20(_token); } function setMinter(IHunnyMinter _minter) external onlyOwner { minter = _minter; if (address(_minter) != address(0)) { token.safeApprove(address(_minter), 0); token.safeApprove(address(_minter), uint(~0)); } } function setHelper(IStrategyHelper _helper) external onlyOwner { require(address(_helper) != address(0), "zero address"); helper = _helper; } function balance() override public view returns (uint) { return token.balanceOf(address(this)); } function balanceOf(address account) override public view returns(uint) { return _shares[account]; } function withdrawableBalanceOf(address account) override public view returns (uint) { return _shares[account]; } function sharesOf(address account) public view returns (uint) { return _shares[account]; } function principalOf(address account) override public view returns (uint) { return _shares[account]; } function profitOf(address account) override public view returns (uint _usd, uint _hunny, uint _bnb) { if (address(minter) == address(0) || !minter.isMinter(address(this))) { return (0, 0, 0); } return (0, minter.amountHunnyToMintForHunnyBNB(balanceOf(account), block.timestamp.sub(depositedAt[account])), 0); } function tvl() override public view returns (uint) { return helper.tvl(address(token), balance()); } function apy() override public view returns(uint _usd, uint _hunny, uint _bnb) { if (address(minter) == address(0) || !minter.isMinter(address(this))) { return (0, 0, 0); } uint amount = 1e18; uint hunny = minter.amountHunnyToMintForHunnyBNB(amount, 365 days); uint _tvl = helper.tvlInBNB(address(token), amount); uint hunnyPrice = helper.tokenPriceInBNB(address(HUNNY)); return (hunny.mul(hunnyPrice).div(_tvl), 0, 0); } function info(address account) override external view returns(UserInfo memory) { UserInfo memory userInfo; userInfo.balance = balanceOf(account); userInfo.principal = principalOf(account); userInfo.available = withdrawableBalanceOf(account); Profit memory profit; (uint usd, uint hunny, uint bnb) = profitOf(account); profit.usd = usd; profit.hunny = hunny; profit.bnb = bnb; userInfo.profit = profit; userInfo.poolTVL = tvl(); APY memory poolAPY; (usd, hunny, bnb) = apy(); poolAPY.usd = usd; poolAPY.hunny = hunny; poolAPY.bnb = bnb; userInfo.poolAPY = poolAPY; return userInfo; } function priceShare() public view returns(uint) { return balance().mul(1e18).div(totalShares); } function depositTo(uint256, uint256 _amount, address _to) external { require(msg.sender == presale || msg.sender == owner(), "not presale contract"); _depositTo(_amount, _to); } function _depositTo(uint _amount, address _to) private { token.safeTransferFrom(msg.sender, address(this), _amount); uint amount = _shares[_to]; if (amount != 0 && depositedAt[_to] != 0) { uint duration = block.timestamp.sub(depositedAt[_to]); mintHunny(amount, duration); } totalShares = totalShares.add(_amount); _shares[_to] = _shares[_to].add(_amount); depositedAt[_to] = block.timestamp; } function deposit(uint _amount) override public { _depositTo(_amount, msg.sender); } function depositAll() override external { deposit(token.balanceOf(msg.sender)); } function withdrawAll() override external { uint _withdraw = balanceOf(msg.sender); totalShares = totalShares.sub(_shares[msg.sender]); delete _shares[msg.sender]; uint depositTimestamp = depositedAt[msg.sender]; delete depositedAt[msg.sender]; mintHunny(_withdraw, block.timestamp.sub(depositTimestamp)); token.safeTransfer(msg.sender, _withdraw); } function mintHunny(uint amount, uint duration) private { if (address(minter) == address(0) || !minter.isMinter(address(this))) { return; } minter.mintForHunnyBNB(amount, duration, msg.sender); } function harvest() override external { } function withdraw(uint256) override external { revert("Use withdrawAll"); } function getReward() override external { revert("Use withdrawAll"); }}// Dependency file: contracts/vaults/legacy/CakeVault.sol// pragma solidity ^0.6.12;/*** MIT License* ===========** Copyright (c) 2020 HunnyFinance** Permission is hereby granted, free of charge, to any person obtaining a copy* of this software and associated documentation files (the "Software"), to deal* in the Software without restriction, including without limitation the rights* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell* copies of the Software, and to permit persons to whom the Software is* furnished to do so, subject to the following conditions:** The above copyright notice and this permission notice shall be included in all* copies or substantial portions of the Software.** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE*/// import "@pancakeswap/pancake-swap-lib/contracts/token/BEP20/BEP20.sol";// import "@pancakeswap/pancake-swap-lib/contracts/token/BEP20/SafeBEP20.sol";// import "@pancakeswap/pancake-swap-lib/contracts/access/Ownable.sol";// import "contracts/Constants.sol";// import "contracts/interfaces/IMasterChef.sol";// import "contracts/interfaces/IHunnyMinter.sol";// import "contracts/interfaces/legacy/IStrategyHelper.sol";// import "contracts/interfaces/legacy/IStrategyLegacy.sol";contract CakeVault is IStrategyLegacy, Ownable { using SafeBEP20 for IBEP20; using SafeMath for uint256; IBEP20 private CAKE; IMasterChef private CAKE_MASTER_CHEF; address public keeper = Constants.HUNNY_KEEPER; uint public poolId = 0; uint public totalShares; mapping (address => uint) private _shares; IStrategyHelper public helper; mapping (address => bool) private _whitelist; constructor(address cake, address cakeMasterChef) public { CAKE = IBEP20(cake); CAKE_MASTER_CHEF = IMasterChef(cakeMasterChef); CAKE.safeApprove(address(CAKE_MASTER_CHEF), uint(~0)); } function setKeeper(address _keeper) external { require(msg.sender == _keeper || msg.sender == owner(), 'auth'); require(_keeper != address(0), 'zero address'); keeper = _keeper; } function setHelper(IStrategyHelper _helper) external { require(msg.sender == address(_helper) || msg.sender == owner(), 'auth'); require(address(_helper) != address(0), "zero address"); helper = _helper; } function setWhitelist(address _address, bool _on) external onlyOwner { _whitelist[_address] = _on; } function balance() override public view returns (uint) { (uint amount,) = CAKE_MASTER_CHEF.userInfo(poolId, address(this)); return CAKE.balanceOf(address(this)).add(amount); } // @returns cake amount function balanceOf(address account) override public view returns(uint) { if (totalShares == 0) return 0; return balance().mul(sharesOf(account)).div(totalShares); } function withdrawableBalanceOf(address account) override public view returns (uint) { return balanceOf(account); } function sharesOf(address account) public view returns (uint) { return _shares[account]; } function principalOf(address account) override public view returns (uint) { return balanceOf(account); } function profitOf(address) override public view returns (uint _usd, uint _hunny, uint _bnb) { // Not available return (0, 0, 0); } function tvl() override public view returns (uint) { return helper.tvl(address(CAKE), balance()); } function apy() override public view returns(uint _usd, uint _hunny, uint _bnb) { return helper.apy(IHunnyMinter(address (0)), poolId); } function info(address account) override external view returns(UserInfo memory) { UserInfo memory userInfo; userInfo.balance = balanceOf(account); userInfo.principal = principalOf(account); userInfo.available = withdrawableBalanceOf(account); Profit memory profit; (uint usd, uint hunny, uint bnb) = profitOf(account); profit.usd = usd; profit.hunny = hunny; profit.bnb = bnb; userInfo.profit = profit; userInfo.poolTVL = tvl(); APY memory poolAPY; (usd, hunny, bnb) = apy(); poolAPY.usd = usd; poolAPY.hunny = hunny; poolAPY.bnb = bnb; userInfo.poolAPY = poolAPY; return userInfo; } function priceShare() public view returns(uint) { if (totalShares == 0) return 0; return balance().mul(1e18).div(totalShares); } function _depositTo(uint _amount, address _to) private { require(_whitelist[msg.sender], "not whitelist"); uint _pool = balance(); CAKE.safeTransferFrom(msg.sender, address(this), _amount); uint shares = 0; if (totalShares == 0) { shares = _amount; } else { shares = (_amount.mul(totalShares)).div(_pool); } totalShares = totalShares.add(shares); _shares[_to] = _shares[_to].add(shares); CAKE_MASTER_CHEF.leaveStaking(0); uint balanceOfCake = CAKE.balanceOf(address(this)); CAKE_MASTER_CHEF.enterStaking(balanceOfCake); } function deposit(uint _amount) override public { _depositTo(_amount, msg.sender); } function depositAll() override external { deposit(CAKE.balanceOf(msg.sender)); } function withdrawAll() override external { uint amount = sharesOf(msg.sender); withdraw(amount); } function harvest() override external { CAKE_MASTER_CHEF.leaveStaking(0); uint cakeAmount = CAKE.balanceOf(address(this)); CAKE_MASTER_CHEF.enterStaking(cakeAmount); } // salvage purpose only function withdrawToken(address token, uint amount) external { require(msg.sender == keeper || msg.sender == owner(), 'auth'); require(token != address(CAKE)); IBEP20(token).safeTransfer(msg.sender, amount); } function withdraw(uint256 _amount) override public { uint _withdraw = balance().mul(_amount).div(totalShares); totalShares = totalShares.sub(_amount); _shares[msg.sender] = _shares[msg.sender].sub(_amount); CAKE_MASTER_CHEF.leaveStaking(_withdraw.sub(CAKE.balanceOf(address(this)))); CAKE.safeTransfer(msg.sender, _withdraw); CAKE_MASTER_CHEF.enterStaking(CAKE.balanceOf(address(this))); } function getReward() override external { revert("N/A"); }}// Dependency file: contracts/interfaces/legacy/ICakeVault.sol// pragma solidity ^0.6.12;interface ICakeVault { function priceShare() external view returns(uint); function balanceOf(address account) external view returns(uint); function sharesOf(address account) external view returns(uint); function deposit(uint _amount) external; function withdraw(uint256 _amount) external;}// Dependency file: contracts/vaults/legacy/CakeFlipVault.sol// pragma solidity ^0.6.12;// import "@openzeppelin/contracts/math/Math.sol";// import "@pancakeswap/pancake-swap-lib/contracts/math/SafeMath.sol";// import "@pancakeswap/pancake-swap-lib/contracts/token/BEP20/SafeBEP20.sol";// import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";// import "contracts/Constants.sol";// import "contracts/library/legacy/RewardsDistributionRecipient.sol";// import "contracts/library/legacy/Pausable.sol";// import "contracts/interfaces/legacy/IStrategyHelper.sol";// import "contracts/interfaces/IMasterChef.sol";// import "contracts/interfaces/legacy/ICakeVault.sol";// import "contracts/interfaces/IHunnyMinter.sol";// import "contracts/interfaces/legacy/IStrategyLegacy.sol";contract CakeFlipVault is IStrategyLegacy, RewardsDistributionRecipient, ReentrancyGuard, Pausable { using SafeMath for uint256; using SafeBEP20 for IBEP20; /* ========== STATE VARIABLES ========== */ ICakeVault public rewardsToken; IBEP20 public stakingToken; uint256 public periodFinish = 0; uint256 public rewardRate = 0; uint256 public rewardsDuration = 24 hours; uint256 public lastUpdateTime; uint256 public rewardPerTokenStored; mapping(address => uint256) public userRewardPerTokenPaid; mapping(address => uint256) public rewards; uint256 private _totalSupply; mapping(address => uint256) private _balances; /* ========== CAKE ============= */ address private CAKE = Constants.CAKE; IMasterChef private CAKE_MASTER_CHEF; uint public poolId; address public keeper = Constants.HUNNY_KEEPER; mapping (address => uint) public depositedAt; /* ========== HUNNY HELPER / MINTER ========= */ IStrategyHelper public helper; IHunnyMinter public minter; /* ========== CONSTRUCTOR ========== */ constructor(uint _pid, address cake, address cakeMasterChef, address cakeVault, address hunnyMinter) public { CAKE = cake; CAKE_MASTER_CHEF = IMasterChef(cakeMasterChef); (address _token,,,) = CAKE_MASTER_CHEF.poolInfo(_pid); stakingToken = IBEP20(_token); stakingToken.safeApprove(address(CAKE_MASTER_CHEF), uint(~0)); poolId = _pid; rewardsDistribution = msg.sender; setMinter(IHunnyMinter(hunnyMinter)); setRewardsToken(cakeVault); // cake vault address } /* ========== VIEWS ========== */ function totalSupply() external view returns (uint256) { return _totalSupply; } function balance() override external view returns (uint) { return _totalSupply; } function balanceOf(address account) override external view returns (uint256) { return _balances[account]; } function principalOf(address account) override external view returns (uint256) { return _balances[account]; } function withdrawableBalanceOf(address account) override public view returns (uint) { return _balances[account]; } // return cakeAmount, hunnyAmount, 0 function profitOf(address account) override public view returns (uint _usd, uint _hunny, uint _bnb) { uint cakeVaultPrice = rewardsToken.priceShare(); uint _earned = earned(account); uint amount = _earned.mul(cakeVaultPrice).div(1e18); if (address(minter) != address(0) && minter.isMinter(address(this))) { uint performanceFee = minter.performanceFee(amount); // cake amount _usd = amount.sub(performanceFee); uint bnbValue = helper.tvlInBNB(CAKE, performanceFee); // hunny amount _hunny = minter.amountHunnyToMint(bnbValue); } else { _usd = amount; _hunny = 0; } _bnb = 0; } function tvl() override public view returns (uint) { uint stakingTVL = helper.tvl(address(stakingToken), _totalSupply); uint price = rewardsToken.priceShare(); uint earned = rewardsToken.balanceOf(address(this)).mul(price).div(1e18); uint rewardTVL = helper.tvl(CAKE, earned); return stakingTVL.add(rewardTVL); } function tvlStaking() external view returns (uint) { return helper.tvl(address(stakingToken), _totalSupply); } function tvlReward() external view returns (uint) { uint price = rewardsToken.priceShare(); uint earned = rewardsToken.balanceOf(address(this)).mul(price).div(1e18); return helper.tvl(CAKE, earned); } function apy() override public view returns(uint _usd, uint _hunny, uint _bnb) { uint dailyAPY = helper.compoundingAPY(poolId, 365 days).div(365); uint cakeAPY = helper.compoundingAPY(0, 1 days); uint cakeDailyAPY = helper.compoundingAPY(0, 365 days).div(365); // let x = 0.5% (daily flip apr) // let y = 0.87% (daily cake apr) // sum of yield of the year = x*(1+y)^365 + x*(1+y)^364 + x*(1+y)^363 + ... + x // ref: https://en.wikipedia.org/wiki/Geometric_series // = x * (1-(1+y)^365) / (1-(1+y)) // = x * ((1+y)^365 - 1) / (y) _usd = dailyAPY.mul(cakeAPY).div(cakeDailyAPY); _hunny = 0; _bnb = 0; } 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 _balances[account].mul(rewardPerToken().sub(userRewardPerTokenPaid[account])).div(1e18).add(rewards[account]); } function getRewardForDuration() external view returns (uint256) { return rewardRate.mul(rewardsDuration); } /* ========== MUTATIVE FUNCTIONS ========== */ function _deposit(uint256 amount, address _to) private nonReentrant notPaused updateReward(_to) { require(amount > 0, "amount"); _totalSupply = _totalSupply.add(amount); _balances[_to] = _balances[_to].add(amount); depositedAt[_to] = block.timestamp; stakingToken.safeTransferFrom(msg.sender, address(this), amount); CAKE_MASTER_CHEF.deposit(poolId, amount); emit Staked(_to, amount); _harvest(); } function deposit(uint256 amount) override public { _deposit(amount, msg.sender); } function depositAll() override external { deposit(stakingToken.balanceOf(msg.sender)); } function withdraw(uint256 amount) override public nonReentrant updateReward(msg.sender) { require(amount > 0, "amount"); _totalSupply = _totalSupply.sub(amount); _balances[msg.sender] = _balances[msg.sender].sub(amount); CAKE_MASTER_CHEF.withdraw(poolId, amount); if (address(minter) != address(0) && minter.isMinter(address(this))) { uint _depositedAt = depositedAt[msg.sender]; uint withdrawalFee = minter.withdrawalFee(amount, _depositedAt); if (withdrawalFee > 0) { uint performanceFee = withdrawalFee.div(100); minter.mintFor(address(stakingToken), withdrawalFee.sub(performanceFee), performanceFee, msg.sender, _depositedAt); amount = amount.sub(withdrawalFee); } } stakingToken.safeTransfer(msg.sender, amount); emit Withdrawn(msg.sender, amount); _harvest(); } function withdrawAll() override external { uint _withdraw = withdrawableBalanceOf(msg.sender); if (_withdraw > 0) { withdraw(_withdraw); } getReward(); } function getReward() override public nonReentrant updateReward(msg.sender) { uint256 reward = rewards[msg.sender]; if (reward > 0) { rewards[msg.sender] = 0; rewardsToken.withdraw(reward); uint cakeBalance = IBEP20(CAKE).balanceOf(address(this)); if (address(minter) != address(0) && minter.isMinter(address(this))) { uint performanceFee = minter.performanceFee(cakeBalance); minter.mintFor(CAKE, 0, performanceFee, msg.sender, depositedAt[msg.sender]); cakeBalance = cakeBalance.sub(performanceFee); } IBEP20(CAKE).safeTransfer(msg.sender, cakeBalance); emit RewardPaid(msg.sender, cakeBalance); } } function harvest() override public { CAKE_MASTER_CHEF.withdraw(poolId, 0); _harvest(); } function _harvest() private { uint cakeAmount = IBEP20(CAKE).balanceOf(address(this)); uint _before = rewardsToken.sharesOf(address(this)); rewardsToken.deposit(cakeAmount); uint amount = rewardsToken.sharesOf(address(this)).sub(_before); if (amount > 0) { _notifyRewardAmount(amount); } } function info(address account) override external view returns(UserInfo memory) { UserInfo memory userInfo; userInfo.balance = _balances[account]; userInfo.principal = _balances[account]; userInfo.available = withdrawableBalanceOf(account); Profit memory profit; (uint usd, uint hunny, uint bnb) = profitOf(account); profit.usd = usd; profit.hunny = hunny; profit.bnb = bnb; userInfo.profit = profit; userInfo.poolTVL = tvl(); APY memory poolAPY; (usd, hunny, bnb) = apy(); poolAPY.usd = usd; poolAPY.hunny = hunny; poolAPY.bnb = bnb; userInfo.poolAPY = poolAPY; return userInfo; } /* ========== RESTRICTED FUNCTIONS ========== */ function setKeeper(address _keeper) external { require(msg.sender == _keeper || msg.sender == owner(), 'auth'); require(_keeper != address(0), 'zero address'); keeper = _keeper; } function setMinter(IHunnyMinter _minter) public onlyOwner { // can zero minter = _minter; if (address(_minter) != address(0)) { IBEP20(CAKE).safeApprove(address(_minter), 0); IBEP20(CAKE).safeApprove(address(_minter), uint(~0)); stakingToken.safeApprove(address(_minter), 0); stakingToken.safeApprove(address(_minter), uint(~0)); } } function setRewardsToken(address _rewardsToken) private onlyOwner { require(address(rewardsToken) == address(0), "set rewards token already"); rewardsToken = ICakeVault(_rewardsToken); IBEP20(CAKE).safeApprove(_rewardsToken, 0); IBEP20(CAKE).safeApprove(_rewardsToken, uint(~0)); } function setHelper(IStrategyHelper _helper) external onlyOwner { require(address(_helper) != address(0), "zero address"); helper = _helper; } function notifyRewardAmount(uint256 reward) override public onlyRewardsDistribution { _notifyRewardAmount(reward); } function _notifyRewardAmount(uint256 reward) private updateReward(address(0)) { 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.sharesOf(address(this)); require(rewardRate <= _balance.div(rewardsDuration), "reward"); lastUpdateTime = block.timestamp; periodFinish = block.timestamp.add(rewardsDuration); emit RewardAdded(reward); } function recoverBEP20(address tokenAddress, uint256 tokenAmount) external onlyOwner { require(tokenAddress != address(stakingToken) && tokenAddress != address(rewardsToken), "tokenAddress"); IBEP20(tokenAddress).safeTransfer(owner(), tokenAmount); emit Recovered(tokenAddress, tokenAmount); } function setRewardsDuration(uint256 _rewardsDuration) external onlyOwner { require(periodFinish == 0 || block.timestamp > periodFinish, "period"); rewardsDuration = _rewardsDuration; emit RewardsDurationUpdated(rewardsDuration); } /* ========== 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 Staked(address indexed user, uint256 amount); event Withdrawn(address indexed user, uint256 amount); event RewardPaid(address indexed user, uint256 reward); event RewardsDurationUpdated(uint256 newDuration); event Recovered(address token, uint256 amount);}// Root file: contracts/hunny/HunnyDeployer.solpragma solidity ^0.6.12;// import "@pancakeswap/pancake-swap-lib/contracts/math/SafeMath.sol";// import "@pancakeswap/pancake-swap-lib/contracts/access/Ownable.sol";// import "@pancakeswap/pancake-swap-lib/contracts/token/BEP20/SafeBEP20.sol";// import "contracts/hunny/HunnyToken.sol";// import "contracts/hunny/HunnyOracle.sol";// import "contracts/hunny/legacy/HunnyMinter.sol";// import "contracts/Constants.sol";// import "contracts/vaults/legacy/StrategyHelperV1.sol";// import "contracts/vaults/legacy/HunnyPool.sol";// import "contracts/vaults/legacy/HunnyBNBPool.sol";// import "contracts/vaults/legacy/CakeVault.sol";// import "contracts/vaults/legacy/CakeFlipVault.sol";// import "contracts/interfaces/IPancakeRouter02.sol";interface Presale { function totalBalance() external view returns(uint); function flipToken() external view returns(address); function initialize(address _token, address _masterChef, address _rewardToken) external; function distributeTokens(uint _pid, uint _fromIndex, uint _toIndex) external; function distributeTokensWhiteList(uint _pid) external; function finalize() external;}// assume that the presale contract has been deployed// deploy following contract only when the presale ended// ready for add liquidity and open legacy poolscontract Deployer1 is Ownable { HunnyToken public hunny; HunnyOracle public hunnyOracle; StrategyHelperV1 public helper; HunnyPool public hunnyPool; HunnyBNBPool public hunnyBNBPool; HunnyMinter public hunnyMinter; constructor(address presaleAddress) public { // deploy hunny token hunny = new HunnyToken(); hunnyOracle = new HunnyOracle(address(hunny)); helper = new StrategyHelperV1(address(hunny)); // deploy HUNNY Pool hunnyPool = new HunnyPool( address(hunny), address(presaleAddress), address(helper) ); // deploy HUNNY BNB pool hunnyBNBPool = new HunnyBNBPool( address(hunny), address(presaleAddress), address(helper) ); // deploy hunny minter hunnyMinter = new HunnyMinter( address(hunny), address(hunnyPool), address(Constants.HUNNY_LOTTERY), address(hunnyOracle), address(helper) ); } function transferContractOwner(address deployer2) public onlyOwner { hunny.transferOwnership(deployer2); hunny.transferOperator(deployer2); hunnyOracle.transferOwnership(deployer2); helper.transferOwnership(deployer2); hunnyPool.transferOwnership(deployer2); hunnyBNBPool.transferOwnership(deployer2); hunnyMinter.transferOwnership(deployer2); }}contract Deployer2 is Ownable { using SafeMath for uint256; using SafeBEP20 for IBEP20; Deployer1 public deployer1; Presale public presale; constructor(address deployer1Address, address payable presaleAddress) public { deployer1 = Deployer1(deployer1Address); presale = Presale(presaleAddress); } // allow deployer2 receive BNB from presale contract receive() external payable{} function step1_presaleInitialize() public onlyOwner { // mint token for presale contract deployer1.hunny().mint(address(presale), presale.totalBalance()); // this part used to add liquidity and distribute to HUNNY pool as reward deployer1.hunny().mint(address(this), presale.totalBalance().div(2)); // initialize presale presale.initialize( address(deployer1.hunny()), address(deployer1.hunnyBNBPool()), address(deployer1.hunnyPool()) ); // set flip token deployer1.hunnyBNBPool().setFlipToken(presale.flipToken()); // set rewards token deployer1.hunnyPool().setRewardsToken(presale.flipToken()); // update anti-whale max value // anti bots deployer1.hunny().updateMaxTransferAmountRate(4); } function step2_1_presaleDistributeTokens(uint fromIndex, uint toIndex) public onlyOwner { deployer1.hunny().updateMaxTransferAmountRate(10000); presale.distributeTokens(0, fromIndex, toIndex); deployer1.hunny().updateMaxTransferAmountRate(4); } function step2_2_presaleDistributeTokensWhiteList() public onlyOwner { deployer1.hunny().updateMaxTransferAmountRate(10000); presale.distributeTokensWhiteList(0); deployer1.hunny().updateMaxTransferAmountRate(4); } function step3_presaleFinalize() public onlyOwner { // transfer remain fund to this address presale.finalize(); // transfer HUNNY token ownership deployer1.hunny().transferOwnership(address(deployer1.hunnyMinter())); // set minter role for HUNNY-BNB Hive Pool deployer1.hunnyMinter().setMinter(address(deployer1.hunnyBNBPool()), true); // set minter address in HUNNY-BNB Hive Pool deployer1.hunnyBNBPool().setMinter(IHunnyMinter(address(deployer1.hunnyMinter()))); // set stake permission for Hunny Minter from HUNNY Hive Pool deployer1.hunnyPool().setStakePermission(address(deployer1.hunnyMinter()), true); // transfer hunny oracle owner to hunny minter deployer1.hunnyOracle().transferOwnership(address(deployer1.hunnyMinter())); } function step4_setupLiquidityReward(uint256 bnbAmount) public onlyOwner { deployer1.hunny().updateMaxTransferAmountRate(10000); IPancakeRouter02 router = IPancakeRouter02(Constants.PANCAKE_ROUTER); address token = address(deployer1.hunny()); uint256 tokenAmount = bnbAmount.mul(deployer1.hunny().balanceOf(address(this))).div(address(this).balance); IBEP20(token).safeApprove(address(router), 0); IBEP20(token).safeApprove(address(router), tokenAmount); router.addLiquidityETH{value: bnbAmount}(token, tokenAmount, 0, 0, address(this), block.timestamp); payable(owner()).transfer(address(this).balance); deployer1.hunny().transfer(owner(), deployer1.hunny().balanceOf(address(this))); // set reward distribution on this address deployer1.hunnyPool().setRewardsDistribution(address(this)); // transfer reward to HUNNY Hive Pool uint256 rewardAmount = IBEP20(presale.flipToken()).balanceOf(address(this)); IBEP20(presale.flipToken()).transfer(address(deployer1.hunnyPool()), rewardAmount); deployer1.hunnyPool().notifyRewardAmount(rewardAmount); // set reward distribution on HUNNY Hive Pool deployer1.hunnyPool().setRewardsDistribution(address(deployer1.hunnyMinter())); deployer1.hunny().updateMaxTransferAmountRate(4); } function transferContractOwner(address newOwner) public onlyOwner { Ownable(address(presale)).transferOwnership(newOwner); deployer1.hunny().transferOperator(newOwner); deployer1.helper().transferOwnership(newOwner); deployer1.hunnyPool().transferOwnership(newOwner); deployer1.hunnyBNBPool().transferOwnership(newOwner); deployer1.hunnyMinter().transferOwnership(newOwner); } // in the emergency situation, transfer remain fund to dev // dev will init liquidity and distribute reward function emergencyTransfer() public payable onlyOwner { payable(owner()).transfer(address(this).balance); deployer1.hunny().transfer(owner(), deployer1.hunny().balanceOf(address(this))); }}
/**
*Submitted for verification at BscScan.com on 2021-06-01
*/
// Dependency file: @pancakeswap/pancake-swap-lib/contracts/math/SafeMath.sol
// SPDX-License-Identifier: MIT
// pragma solidity >=0.4.0;
* @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.
* - 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
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
* @dev Returns the multiplication of two unsigned integers, reverting on
* Counterpart to Solidity's `*` operator.
* - 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');
* @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).
* - 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
function div(
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
* @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).
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, 'SafeMath: modulo by zero');
* Reverts with custom message when dividing by zero.
function mod(
require(b != 0, errorMessage);
return a % b;
function min(uint256 x, uint256 y) internal pure returns (uint256 z) {
z = x < y ? x : y;
// babylonian method (https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method)
function sqrt(uint256 y) internal pure returns (uint256 z) {
if (y > 3) {
z = y;
uint256 x = y / 2 + 1;
while (x < z) {
z = x;
x = (y / x + x) / 2;
} else if (y != 0) {
z = 1;
// Dependency file: @pancakeswap/pancake-swap-lib/contracts/GSN/Context.sol
/*
* @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.
contract Context {
// Empty internal constructor, to prevent people from mistakenly deploying
// an instance of this contract, which should be used via inheritance.
constructor() internal {}
function _msgSender() internal view returns (address payable) {
return msg.sender;
function _msgData() internal view returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
// Dependency file: @pancakeswap/pancake-swap-lib/contracts/access/Ownable.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 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 onlyOwner {
_transferOwnership(newOwner);
function _transferOwnership(address newOwner) internal {
require(newOwner != address(0), 'Ownable: new owner is the zero address');
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
// Dependency file: @pancakeswap/pancake-swap-lib/contracts/token/BEP20/IBEP20.sol
interface IBEP20 {
* @dev Returns the amount of tokens in existence.
function totalSupply() external view returns (uint256);
* @dev Returns the token decimals.
function decimals() external view returns (uint8);
* @dev Returns the token symbol.
function symbol() external view returns (string memory);
* @dev Returns the token name.
function name() external view returns (string memory);
* @dev Returns the bep token owner.
function getOwner() external view returns (address);
* @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.
* 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.
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);
// Dependency file: @pancakeswap/pancake-swap-lib/contracts/utils/Address.sol
// pragma solidity ^0.6.2;
* @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`].
* - `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.
function functionCall(
address target,
bytes memory data,
) 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`.
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
function functionCallWithValue(
uint256 value
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.
uint256 value,
require(address(this).balance >= value, 'Address: insufficient balance for call');
return _functionCallWithValue(target, data, value, errorMessage);
function _functionCallWithValue(
uint256 weiValue,
) 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
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
revert(errorMessage);
// Dependency file: @pancakeswap/pancake-swap-lib/contracts/token/BEP20/SafeBEP20.sol
// pragma solidity ^0.6.0;
* @title SafeBEP20
* @dev Wrappers around BEP20 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 SafeBEP20 for IBEP20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
library SafeBEP20 {
using SafeMath for uint256;
using Address for address;
function safeTransfer(
IBEP20 token,
address to,
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
function safeTransferFrom(
address from,
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
* @dev Deprecated. This function has issues similar to the ones found in
* {IBEP20-approve}, and its usage is discouraged.
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
function safeApprove(
address spender,
// 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),
'SafeBEP20: approve from non-zero to non-zero allowance'
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
function safeIncreaseAllowance(
uint256 newAllowance = token.allowance(address(this), spender).add(value);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
function safeDecreaseAllowance(
uint256 newAllowance = token.allowance(address(this), spender).sub(
value,
'SafeBEP20: decreased allowance below zero'
* @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(IBEP20 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, 'SafeBEP20: low-level call failed');
// Return data is optional
require(abi.decode(returndata, (bool)), 'SafeBEP20: BEP20 operation did not succeed');
// Dependency file: contracts/library/bep20/BEP20Virtual.sol
// import "@pancakeswap/pancake-swap-lib/contracts/access/Ownable.sol";
// import "@pancakeswap/pancake-swap-lib/contracts/GSN/Context.sol";
// import "@pancakeswap/pancake-swap-lib/contracts/token/BEP20/IBEP20.sol";
// import "@pancakeswap/pancake-swap-lib/contracts/math/SafeMath.sol";
// import "@pancakeswap/pancake-swap-lib/contracts/utils/Address.sol";
* @dev Implementation of the {IBEP20} interface.
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {BEP20PresetMinterPauser}.
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-BEP20-supply-mechanisms/226[How
* to implement supply mechanisms].
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of BEP20 applications.
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IBEP20-approve}.
contract BEP20Virtual is Context, IBEP20, Ownable {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
uint8 private _decimals;
* @dev Sets the values for {name} and {symbol}, initializes {decimals} with
* a default value of 18.
* To select a different value for {decimals}, use {_setupDecimals}.
* All three of these values are immutable: they can only be set once during
* construction.
constructor(string memory name, string memory symbol) public {
_name = name;
_symbol = symbol;
_decimals = 18;
function getOwner() external override view returns (address) {
return owner();
function name() public override view returns (string memory) {
return _name;
function decimals() public override view returns (uint8) {
return _decimals;
function symbol() public override view returns (string memory) {
return _symbol;
* @dev See {BEP20-totalSupply}.
function totalSupply() public override view returns (uint256) {
return _totalSupply;
* @dev See {BEP20-balanceOf}.
function balanceOf(address account) public override view returns (uint256) {
return _balances[account];
* @dev See {BEP20-transfer}.
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
function transfer(address recipient, uint256 amount) public override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
* @dev See {BEP20-allowance}.
function allowance(address owner, address spender) public override view returns (uint256) {
return _allowances[owner][spender];
* @dev See {BEP20-approve}.
* - `spender` cannot be the zero address.
function approve(address spender, uint256 amount) public override returns (bool) {
_approve(_msgSender(), spender, amount);
* @dev See {BEP20-transferFrom}.
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {BEP20};
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for `sender`'s tokens of at least
* `amount`.
) public override returns (bool) {
_transfer(sender, recipient, amount);
_approve(
sender,
_msgSender(),
_allowances[sender][_msgSender()].sub(amount, 'BEP20: transfer amount exceeds allowance')
* @dev Atomically increases the allowance granted to `spender` by the caller.
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {BEP20-approve}.
* Emits an {Approval} event indicating the updated allowance.
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
* @dev Atomically decreases the allowance granted to `spender` by the caller.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
spender,
_allowances[_msgSender()][spender].sub(subtractedValue, 'BEP20: decreased allowance below zero')
* @dev Creates `amount` tokens and assigns them to `msg.sender`, increasing
* the total supply.
* Requirements
* - `msg.sender` must be the token owner
function mint(uint256 amount) public onlyOwner returns (bool) {
_mint(_msgSender(), amount);
* @dev Moves tokens `amount` from `sender` to `recipient`.
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
* - `sender` cannot be the zero address.
function _transfer(
) internal virtual {
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);
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* Emits a {Transfer} event with `from` set to the zero address.
* - `to` cannot be the zero address.
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);
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
* Emits a {Transfer} event with `to` set to the zero address.
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
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);
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
* - `owner` cannot be the zero address.
function _approve(
address owner,
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);
* @dev Destroys `amount` tokens from `account`.`amount` is then deducted
* from the caller's allowance.
* See {_burn} and {_approve}.
function _burnFrom(address account, uint256 amount) internal {
_burn(account, amount);
account,
_allowances[account][_msgSender()].sub(amount, 'BEP20: burn amount exceeds allowance')
// Dependency file: contracts/hunny/HunnyToken.sol
// pragma solidity ^0.6.12;
* MIT License
* ===========
* Copyright (c) 2020 HUNNYFinance
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// import "contracts/library/bep20/BEP20Virtual.sol";
// HunnyToken with Governance.
contract HunnyToken is BEP20Virtual('Hunny Token', 'HUNNY') {
uint16 public maxTransferAmountRate = 10000; // 100%
address public constant BURN_ADDRESS = 0x000000000000000000000000000000000000dEaD;
mapping(address => bool) private _excludedFromAntiWhale;
address private _operator;
event OperatorTransferred(address indexed previousOperator, address indexed newOperator);
event MaxTransferAmountRateUpdated(address indexed operator, uint256 previousRate, uint256 newRate);
modifier onlyOperator() {
require(_operator == msg.sender, "operator: caller is not the operator");
modifier antiWhale(address sender, address recipient, uint256 amount) {
if (maxTransferAmount() > 0) {
if (
_excludedFromAntiWhale[sender] == false
&& _excludedFromAntiWhale[recipient] == false
) {
require(amount <= maxTransferAmount(), "HUNNY::antiWhale: Transfer amount exceeds the maxTransferAmount");
constructor() public {
_operator = msg.sender;
_excludedFromAntiWhale[msg.sender] = true;
_excludedFromAntiWhale[address(0)] = true;
_excludedFromAntiWhale[address(this)] = true;
_excludedFromAntiWhale[BURN_ADDRESS] = true;
function _transfer(address sender, address recipient, uint256 amount) internal override antiWhale(sender, recipient, amount) {
super._transfer(sender, recipient, amount);
function maxTransferAmount() public view returns (uint256) {
return totalSupply().mul(maxTransferAmountRate).div(10000);
function isExcludedFromAntiWhale(address _account) public view returns (bool) {
return _excludedFromAntiWhale[_account];
function updateMaxTransferAmountRate(uint16 _maxTransferAmountRate) public onlyOperator {
require(_maxTransferAmountRate <= 10000, "HUNNY::updateMaxTransferAmountRate: Max transfer amount rate must not exceed the maximum rate.");
emit MaxTransferAmountRateUpdated(msg.sender, maxTransferAmountRate, _maxTransferAmountRate);
maxTransferAmountRate = _maxTransferAmountRate;
function setExcludedFromAntiWhale(address _account, bool _excluded) public onlyOperator {
_excludedFromAntiWhale[_account] = _excluded;
function transferOperator(address newOperator) public onlyOperator {
require(newOperator != address(0), "HUNNY::transferOperator: new operator is the zero address");
emit OperatorTransferred(_operator, newOperator);
_operator = newOperator;
_excludedFromAntiWhale[newOperator] = true;
// @dev Creates `_amount` token to `_to`. Must only be called by the owner (MasterChef).
function mint(address _to, uint256 _amount) public onlyOwner {
_mint(_to, _amount);
_moveDelegates(address(0), _delegates[_to], _amount);
// Copied and modified from YAM code:
// https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernanceStorage.sol
// https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernance.sol
// Which is copied and modified from COMPOUND:
// https://github.com/compound-finance/compound-protocol/blob/master/contracts/Governance/Comp.sol
// @dev A record of each accounts delegate
mapping (address => address) internal _delegates;
// @dev A checkpoint for marking number of votes from a given block
struct Checkpoint {
uint32 fromBlock;
uint256 votes;
// @dev A record of votes checkpoints for each account, by index
mapping (address => mapping (uint32 => Checkpoint)) public checkpoints;
// @dev The number of checkpoints for each account
mapping (address => uint32) public numCheckpoints;
// @dev The EIP-712 typehash for the contract's domain
bytes32 public constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");
// @dev The EIP-712 typehash for the delegation struct used by the contract
bytes32 public constant DELEGATION_TYPEHASH = keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
// @dev A record of states for signing / validating signatures
mapping (address => uint) public nonces;
// @dev An event thats emitted when an account changes its delegate
event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);
// @dev An event thats emitted when a delegate account's vote balance changes
event DelegateVotesChanged(address indexed delegate, uint previousBalance, uint newBalance);
* @dev Delegate votes from `msg.sender` to `delegatee`
* @param delegator The address to get delegatee for
function delegates(address delegator)
external
view
returns (address)
{
return _delegates[delegator];
* @param delegatee The address to delegate votes to
function delegate(address delegatee) external {
return _delegate(msg.sender, delegatee);
* @dev Delegates votes from signatory to `delegatee`
* @param nonce The contract state required to match the signature
* @param expiry The time at which to expire the signature
* @param v The recovery byte of the signature
* @param r Half of the ECDSA signature pair
* @param s Half of the ECDSA signature pair
function delegateBySig(
address delegatee,
uint nonce,
uint expiry,
uint8 v,
bytes32 r,
bytes32 s
)
bytes32 domainSeparator = keccak256(
abi.encode(
DOMAIN_TYPEHASH,
keccak256(bytes(name())),
getChainId(),
address(this)
bytes32 structHash = keccak256(
DELEGATION_TYPEHASH,
delegatee,
nonce,
expiry
bytes32 digest = keccak256(
abi.encodePacked(
"\x19\x01",
domainSeparator,
structHash
address signatory = ecrecover(digest, v, r, s);
require(signatory != address(0), "HUNNY::delegateBySig: invalid signature");
require(nonce == nonces[signatory]++, "HUNNY::delegateBySig: invalid nonce");
require(now <= expiry, "HUNNY::delegateBySig: signature expired");
return _delegate(signatory, delegatee);
* @dev Gets the current votes balance for `account`
* @param account The address to get votes balance
* @return The number of current votes for `account`
function getCurrentVotes(address account)
returns (uint256)
uint32 nCheckpoints = numCheckpoints[account];
return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0;
* @dev Determine the prior number of votes for an account as of a block number
* @dev Block number must be a finalized block or else this function will revert to prevent misinformation.
* @param account The address of the account to check
* @param blockNumber The block number to get the vote balance at
* @return The number of votes the account had as of the given block
function getPriorVotes(address account, uint blockNumber)
require(blockNumber < block.number, "HUNNY::getPriorVotes: not yet determined");
if (nCheckpoints == 0) {
// First check most recent balance
if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) {
return checkpoints[account][nCheckpoints - 1].votes;
// Next check implicit zero balance
if (checkpoints[account][0].fromBlock > blockNumber) {
uint32 lower = 0;
uint32 upper = nCheckpoints - 1;
while (upper > lower) {
uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow
Checkpoint memory cp = checkpoints[account][center];
if (cp.fromBlock == blockNumber) {
return cp.votes;
} else if (cp.fromBlock < blockNumber) {
lower = center;
upper = center - 1;
return checkpoints[account][lower].votes;
function _delegate(address delegator, address delegatee)
internal
address currentDelegate = _delegates[delegator];
uint256 delegatorBalance = balanceOf(delegator); // balance of underlying HUNNYs (not scaled);
_delegates[delegator] = delegatee;
emit DelegateChanged(delegator, currentDelegate, delegatee);
_moveDelegates(currentDelegate, delegatee, delegatorBalance);
function _moveDelegates(address srcRep, address dstRep, uint256 amount) internal {
if (srcRep != dstRep && amount > 0) {
if (srcRep != address(0)) {
// decrease old representative
uint32 srcRepNum = numCheckpoints[srcRep];
uint256 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0;
uint256 srcRepNew = srcRepOld.sub(amount);
_writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew);
if (dstRep != address(0)) {
// increase new representative
uint32 dstRepNum = numCheckpoints[dstRep];
uint256 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0;
uint256 dstRepNew = dstRepOld.add(amount);
_writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew);
function _writeCheckpoint(
uint32 nCheckpoints,
uint256 oldVotes,
uint256 newVotes
uint32 blockNumber = safe32(block.number, "HUNNY::_writeCheckpoint: block number exceeds 32 bits");
if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) {
checkpoints[delegatee][nCheckpoints - 1].votes = newVotes;
checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes);
numCheckpoints[delegatee] = nCheckpoints + 1;
emit DelegateVotesChanged(delegatee, oldVotes, newVotes);
function safe32(uint n, string memory errorMessage) internal pure returns (uint32) {
require(n < 2**32, errorMessage);
return uint32(n);
function getChainId() internal pure returns (uint) {
uint256 chainId;
assembly { chainId := chainid() }
return chainId;
// Dependency file: @uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol
// pragma solidity >=0.5.0;
interface IUniswapV2Factory {
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
function feeTo() external view returns (address);
function feeToSetter() external view returns (address);
function getPair(address tokenA, address tokenB) external view returns (address pair);
function allPairs(uint) external view returns (address pair);
function allPairsLength() external view returns (uint);
function createPair(address tokenA, address tokenB) external returns (address pair);
function setFeeTo(address) external;
function setFeeToSetter(address) external;
// Dependency file: @uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol
interface IUniswapV2Pair {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
function name() external pure returns (string memory);
function symbol() external pure returns (string memory);
function decimals() external pure returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, 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 DOMAIN_SEPARATOR() external view returns (bytes32);
function PERMIT_TYPEHASH() external pure returns (bytes32);
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;
event Mint(address indexed sender, uint amount0, uint amount1);
event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
event Swap(
address indexed sender,
uint amount0In,
uint amount1In,
uint amount0Out,
uint amount1Out,
address indexed to
event Sync(uint112 reserve0, uint112 reserve1);
function MINIMUM_LIQUIDITY() external pure returns (uint);
function factory() external view returns (address);
function token0() external view returns (address);
function token1() external view returns (address);
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
function price0CumulativeLast() external view returns (uint);
function price1CumulativeLast() external view returns (uint);
function kLast() external view returns (uint);
function mint(address to) external returns (uint liquidity);
function burn(address to) external returns (uint amount0, uint amount1);
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
function skim(address to) external;
function sync() external;
function initialize(address, address) external;
// Dependency file: contracts/Constants.sol
// pragma solidity 0.6.12;
library Constants {
// pancake
address constant PANCAKE_ROUTER = address(0x10ED43C718714eb63d5aA57B78B54704E256024E); // v2
address constant PANCAKE_FACTORY = address(0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73);
address constant PANCAKE_CHEF = address(0x73feaa1eE314F8c655E354234017bE2193C9E24E);
// uint constant PANCAKE_CAKE_BNB_PID = 3;
uint constant PANCAKE_CAKE_BNB_PID = 251; // mainnet
uint constant PANCAKE_BUSD_BNB_PID = 252; // mainnet
// uint constant PANCAKE_BUSD_BNB_PID = 4;
uint constant PANCAKE_BUSD_USDT_PID = 264; // mainnet
// uint constant PANCAKE_BUSD_USDT_PID = 0;
// tokens
address constant WBNB = address(0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c);
address constant CAKE = address(0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82);
address constant BUSD = address(0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56);
// external addresses
address constant HUNNY_DEPLOYER = address(0xe5F7E3DD9A5612EcCb228392F47b7Ddba8cE4F1a);
address constant HUNNY_LOTTERY = address(0); // update later
address constant HUNNY_KEEPER = address(0xe5F7E3DD9A5612EcCb228392F47b7Ddba8cE4F1a);
// minter
uint256 constant HUNNY_PER_BLOCK_LOTTERY = 12e18; // 12 HUNNY per block for lottery pool
uint256 constant HUNNY_PER_PROFIT_BNB = 3200e18; // 1 BNB earned, mint 3200 HUNNY
uint256 constant HUNNY_PER_HUNNY_BNB_FLIP = 150e18; // 1 HUNNY-BNB, earn 150 HUNNY / 365 days
// Dependency file: contracts/library/Whitelist.sol
* Copyright (c) 2020 HunnyFinance
contract Whitelist is Ownable {
mapping(address => bool) private _whitelist;
bool private _disable; // default - false means whitelist feature is working on. if true no more use of whitelist
event Whitelisted(address indexed _address, bool whitelist);
event EnableWhitelist();
event DisableWhitelist();
modifier onlyWhitelisted {
require(_disable || _whitelist[msg.sender], "Whitelist: caller is not on the whitelist");
function isWhitelist(address _address) public view returns (bool) {
return _whitelist[_address];
function setWhitelist(address _address, bool _on) public onlyOwner {
_whitelist[_address] = _on;
emit Whitelisted(_address, _on);
function disableWhitelist(bool disable) public onlyOwner {
_disable = disable;
if (disable) {
emit DisableWhitelist();
emit EnableWhitelist();
// Dependency file: contracts/library/uniswap/FullMath.sol
// taken from https://medium.com/coinmonks/math-in-solidity-part-3-percents-and-proportions-4db014e080b1
// license is CC-BY-4.0
library FullMath {
function fullMul(uint256 x, uint256 y) internal pure returns (uint256 l, uint256 h) {
uint256 mm = mulmod(x, y, uint256(-1));
l = x * y;
h = mm - l;
if (mm < l) h -= 1;
function fullDiv(
uint256 l,
uint256 h,
uint256 d
) private pure returns (uint256) {
uint256 pow2 = d & -d;
d /= pow2;
l /= pow2;
l += h * ((-pow2) / pow2 + 1);
uint256 r = 1;
r *= 2 - d * r;
return l * r;
function mulDiv(
uint256 x,
uint256 y,
(uint256 l, uint256 h) = fullMul(x, y);
uint256 mm = mulmod(x, y, d);
if (mm > l) h -= 1;
l -= mm;
if (h == 0) return l / d;
require(h < d, 'FullMath: FULLDIV_OVERFLOW');
return fullDiv(l, h, d);
// Dependency file: contracts/library/uniswap/Babylonian.sol
// computes square roots using the babylonian method
// https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method
library Babylonian {
// credit for this implementation goes to
// https://github.com/abdk-consulting/abdk-libraries-solidity/blob/master/ABDKMath64x64.sol#L687
function sqrt(uint256 x) internal pure returns (uint256) {
if (x == 0) return 0;
// this block is equivalent to r = uint256(1) << (BitMath.mostSignificantBit(x) / 2);
// however that code costs significantly more gas
uint256 xx = x;
if (xx >= 0x100000000000000000000000000000000) {
xx >>= 128;
r <<= 64;
if (xx >= 0x10000000000000000) {
xx >>= 64;
r <<= 32;
if (xx >= 0x100000000) {
xx >>= 32;
r <<= 16;
if (xx >= 0x10000) {
xx >>= 16;
r <<= 8;
if (xx >= 0x100) {
xx >>= 8;
r <<= 4;
if (xx >= 0x10) {
xx >>= 4;
r <<= 2;
if (xx >= 0x8) {
r <<= 1;
r = (r + x / r) >> 1;
r = (r + x / r) >> 1; // Seven iterations should be enough
uint256 r1 = x / r;
return (r < r1 ? r : r1);
// Dependency file: contracts/library/uniswap/BitMath.sol
library BitMath {
// returns the 0 indexed position of the most significant bit of the input x
// s.t. x >= 2**msb and x < 2**(msb+1)
function mostSignificantBit(uint256 x) internal pure returns (uint8 r) {
require(x > 0, 'BitMath::mostSignificantBit: zero');
if (x >= 0x100000000000000000000000000000000) {
x >>= 128;
r += 128;
if (x >= 0x10000000000000000) {
x >>= 64;
r += 64;
if (x >= 0x100000000) {
x >>= 32;
r += 32;
if (x >= 0x10000) {
x >>= 16;
r += 16;
if (x >= 0x100) {
x >>= 8;
r += 8;
if (x >= 0x10) {
x >>= 4;
r += 4;
if (x >= 0x4) {
x >>= 2;
r += 2;
if (x >= 0x2) r += 1;
// returns the 0 indexed position of the least significant bit of the input x
// s.t. (x & 2**lsb) != 0 and (x & (2**(lsb) - 1)) == 0)
// i.e. the bit at the index is set and the mask of all lower bits is 0
function leastSignificantBit(uint256 x) internal pure returns (uint8 r) {
require(x > 0, 'BitMath::leastSignificantBit: zero');
r = 255;
if (x & uint128(-1) > 0) {
r -= 128;
if (x & uint64(-1) > 0) {
r -= 64;
if (x & uint32(-1) > 0) {
r -= 32;
if (x & uint16(-1) > 0) {
r -= 16;
if (x & uint8(-1) > 0) {
r -= 8;
if (x & 0xf > 0) {
r -= 4;
if (x & 0x3 > 0) {
r -= 2;
if (x & 0x1 > 0) r -= 1;
// Dependency file: contracts/library/uniswap/FixedPoint.sol
// import 'contracts/library/uniswap/FullMath.sol';
// import 'contracts/library/uniswap/Babylonian.sol';
// import 'contracts/library/uniswap/BitMath.sol';
// a library for handling binary fixed point numbers (https://en.wikipedia.org/wiki/Q_(number_format))
library FixedPoint {
// range: [0, 2**112 - 1]
// resolution: 1 / 2**112
struct uq112x112 {
uint224 _x;
// range: [0, 2**144 - 1]
struct uq144x112 {
uint256 _x;
uint8 public constant RESOLUTION = 112;
uint256 public constant Q112 = 0x10000000000000000000000000000; // 2**112
uint256 private constant Q224 = 0x100000000000000000000000000000000000000000000000000000000; // 2**224
uint256 private constant LOWER_MASK = 0xffffffffffffffffffffffffffff; // decimal of UQ*x112 (lower 112 bits)
// encode a uint112 as a UQ112x112
function encode(uint112 x) internal pure returns (uq112x112 memory) {
return uq112x112(uint224(x) << RESOLUTION);
// encodes a uint144 as a UQ144x112
function encode144(uint144 x) internal pure returns (uq144x112 memory) {
return uq144x112(uint256(x) << RESOLUTION);
// decode a UQ112x112 into a uint112 by truncating after the radix point
function decode(uq112x112 memory self) internal pure returns (uint112) {
return uint112(self._x >> RESOLUTION);
// decode a UQ144x112 into a uint144 by truncating after the radix point
function decode144(uq144x112 memory self) internal pure returns (uint144) {
return uint144(self._x >> RESOLUTION);
// multiply a UQ112x112 by a uint, returning a UQ144x112
// reverts on overflow
function mul(uq112x112 memory self, uint256 y) internal pure returns (uq144x112 memory) {
uint256 z = 0;
require(y == 0 || (z = self._x * y) / y == self._x, 'FixedPoint::mul: overflow');
return uq144x112(z);
// multiply a UQ112x112 by an int and decode, returning an int
function muli(uq112x112 memory self, int256 y) internal pure returns (int256) {
uint256 z = FullMath.mulDiv(self._x, uint256(y < 0 ? -y : y), Q112);
require(z < 2**255, 'FixedPoint::muli: overflow');
return y < 0 ? -int256(z) : int256(z);
// multiply a UQ112x112 by a UQ112x112, returning a UQ112x112
// lossy
function muluq(uq112x112 memory self, uq112x112 memory other) internal pure returns (uq112x112 memory) {
if (self._x == 0 || other._x == 0) {
return uq112x112(0);
uint112 upper_self = uint112(self._x >> RESOLUTION); // * 2^0
uint112 lower_self = uint112(self._x & LOWER_MASK); // * 2^-112
uint112 upper_other = uint112(other._x >> RESOLUTION); // * 2^0
uint112 lower_other = uint112(other._x & LOWER_MASK); // * 2^-112
// partial products
uint224 upper = uint224(upper_self) * upper_other; // * 2^0
uint224 lower = uint224(lower_self) * lower_other; // * 2^-224
uint224 uppers_lowero = uint224(upper_self) * lower_other; // * 2^-112
uint224 uppero_lowers = uint224(upper_other) * lower_self; // * 2^-112
// so the bit shift does not overflow
require(upper <= uint112(-1), 'FixedPoint::muluq: upper overflow');
// this cannot exceed 256 bits, all values are 224 bits
uint256 sum = uint256(upper << RESOLUTION) + uppers_lowero + uppero_lowers + (lower >> RESOLUTION);
// so the cast does not overflow
require(sum <= uint224(-1), 'FixedPoint::muluq: sum overflow');
return uq112x112(uint224(sum));
// divide a UQ112x112 by a UQ112x112, returning a UQ112x112
function divuq(uq112x112 memory self, uq112x112 memory other) internal pure returns (uq112x112 memory) {
require(other._x > 0, 'FixedPoint::divuq: division by zero');
if (self._x == other._x) {
return uq112x112(uint224(Q112));
if (self._x <= uint144(-1)) {
uint256 value = (uint256(self._x) << RESOLUTION) / other._x;
require(value <= uint224(-1), 'FixedPoint::divuq: overflow');
return uq112x112(uint224(value));
uint256 result = FullMath.mulDiv(Q112, self._x, other._x);
require(result <= uint224(-1), 'FixedPoint::divuq: overflow');
return uq112x112(uint224(result));
// returns a UQ112x112 which represents the ratio of the numerator to the denominator
// can be lossy
function fraction(uint256 numerator, uint256 denominator) internal pure returns (uq112x112 memory) {
require(denominator > 0, 'FixedPoint::fraction: division by zero');
if (numerator == 0) return FixedPoint.uq112x112(0);
if (numerator <= uint144(-1)) {
uint256 result = (numerator << RESOLUTION) / denominator;
require(result <= uint224(-1), 'FixedPoint::fraction: overflow');
uint256 result = FullMath.mulDiv(numerator, Q112, denominator);
// take the reciprocal of a UQ112x112
function reciprocal(uq112x112 memory self) internal pure returns (uq112x112 memory) {
require(self._x != 0, 'FixedPoint::reciprocal: reciprocal of zero');
require(self._x != 1, 'FixedPoint::reciprocal: overflow');
return uq112x112(uint224(Q224 / self._x));
// square root of a UQ112x112
// lossy between 0/1 and 40 bits
function sqrt(uq112x112 memory self) internal pure returns (uq112x112 memory) {
return uq112x112(uint224(Babylonian.sqrt(uint256(self._x) << 112)));
uint8 safeShiftBits = 255 - BitMath.mostSignificantBit(self._x);
safeShiftBits -= safeShiftBits % 2;
return uq112x112(uint224(Babylonian.sqrt(uint256(self._x) << safeShiftBits) << ((112 - safeShiftBits) / 2)));
// Dependency file: contracts/library/uniswap/UniswapV2Library.sol
// import "@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol";
library UniswapV2Library {
using SafeMath for uint;
// returns sorted token addresses, used to handle return values from pairs sorted in this order
function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) {
require(tokenA != tokenB, 'UniswapV2Library: IDENTICAL_ADDRESSES');
(token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
require(token0 != address(0), 'UniswapV2Library: ZERO_ADDRESS');
// calculates the CREATE2 address for a pair without making any external calls
function pairFor(address factory, address tokenA, address tokenB) internal pure returns (address pair) {
(address token0, address token1) = sortTokens(tokenA, tokenB);
pair = address(uint(keccak256(abi.encodePacked(
hex'ff',
factory,
keccak256(abi.encodePacked(token0, token1)),
hex'96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f' // init code hash
))));
// fetches and sorts the reserves for a pair
function getReserves(address factory, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) {
(address token0,) = sortTokens(tokenA, tokenB);
(uint reserve0, uint reserve1,) = IUniswapV2Pair(pairFor(factory, tokenA, tokenB)).getReserves();
(reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0);
// given some amount of an asset and pair reserves, returns an equivalent amount of the other asset
function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) {
require(amountA > 0, 'UniswapV2Library: INSUFFICIENT_AMOUNT');
require(reserveA > 0 && reserveB > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
amountB = amountA.mul(reserveB) / reserveA;
// given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) {
require(amountIn > 0, 'UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT');
require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
uint amountInWithFee = amountIn.mul(997);
uint numerator = amountInWithFee.mul(reserveOut);
uint denominator = reserveIn.mul(1000).add(amountInWithFee);
amountOut = numerator / denominator;
// given an output amount of an asset and pair reserves, returns a required input amount of the other asset
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn) {
require(amountOut > 0, 'UniswapV2Library: INSUFFICIENT_OUTPUT_AMOUNT');
uint numerator = reserveIn.mul(amountOut).mul(1000);
uint denominator = reserveOut.sub(amountOut).mul(997);
amountIn = (numerator / denominator).add(1);
// performs chained getAmountOut calculations on any number of pairs
function getAmountsOut(address factory, uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) {
require(path.length >= 2, 'UniswapV2Library: INVALID_PATH');
amounts = new uint[](path.length);
amounts[0] = amountIn;
for (uint i; i < path.length - 1; i++) {
(uint reserveIn, uint reserveOut) = getReserves(factory, path[i], path[i + 1]);
amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut);
// performs chained getAmountIn calculations on any number of pairs
function getAmountsIn(address factory, uint amountOut, address[] memory path) internal view returns (uint[] memory amounts) {
amounts[amounts.length - 1] = amountOut;
for (uint i = path.length - 1; i > 0; i--) {
(uint reserveIn, uint reserveOut) = getReserves(factory, path[i - 1], path[i]);
amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut);
// Dependency file: contracts/library/uniswap/UniswapV2OracleLibrary.sol
// import 'contracts/library/uniswap/FixedPoint.sol';
// library with helper methods for oracles that are concerned with computing average prices
library UniswapV2OracleLibrary {
using FixedPoint for *;
// helper function that returns the current block timestamp within the range of uint32, i.e. [0, 2**32 - 1]
function currentBlockTimestamp() internal view returns (uint32) {
return uint32(block.timestamp % 2 ** 32);
// produces the cumulative price using counterfactuals to save gas and avoid a call to sync.
function currentCumulativePrices(
address pair
) internal view returns (uint price0Cumulative, uint price1Cumulative, uint32 blockTimestamp) {
blockTimestamp = currentBlockTimestamp();
price0Cumulative = IUniswapV2Pair(pair).price0CumulativeLast();
price1Cumulative = IUniswapV2Pair(pair).price1CumulativeLast();
// if time has elapsed since the last update on the pair, mock the accumulated price values
(uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast) = IUniswapV2Pair(pair).getReserves();
if (blockTimestampLast != blockTimestamp) {
// subtraction overflow is desired
uint32 timeElapsed = blockTimestamp - blockTimestampLast;
// addition overflow is desired
// counterfactual
price0Cumulative += uint(FixedPoint.fraction(reserve1, reserve0)._x) * timeElapsed;
price1Cumulative += uint(FixedPoint.fraction(reserve0, reserve1)._x) * timeElapsed;
// Dependency file: contracts/hunny/HunnyOracle.sol
// import "@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol";
// import "contracts/Constants.sol";
// import "contracts/library/Whitelist.sol";
// import "contracts/library/uniswap/FixedPoint.sol";
// import "contracts/library/uniswap/UniswapV2Library.sol";
// import "contracts/library/uniswap/UniswapV2OracleLibrary.sol";
// fixed window oracle that recomputes the average price for the entire period once every period
// note that the price average is only guaranteed to be over at least 1 period, but may be over a longer period
contract HunnyOracle is Whitelist {
uint public constant PERIOD = 10 minutes;
uint112 public constant BOOTSTRAP_HUNNY_PRICE = 250000000000000; // 1 BNB = 4000 HUNNY
bool public initialized;
address public hunnyToken;
IUniswapV2Pair pair;
address public token0;
address public token1;
uint public price0CumulativeLast;
uint public price1CumulativeLast;
uint32 public blockTimestampLast;
FixedPoint.uq112x112 public price0Average;
FixedPoint.uq112x112 public price1Average;
constructor(address hunny) public {
hunnyToken = hunny;
setWhitelist(msg.sender, true);
function initialize() internal {
IUniswapV2Pair _pair = IUniswapV2Pair(IUniswapV2Factory(Constants.PANCAKE_FACTORY).getPair(hunnyToken, Constants.WBNB));
pair = _pair;
token0 = _pair.token0();
token1 = _pair.token1();
price0CumulativeLast = _pair.price0CumulativeLast(); // fetch the current accumulated price value (1 / 0)
price1CumulativeLast = _pair.price1CumulativeLast(); // fetch the current accumulated price value (0 / 1)
// get the blockTimestampLast
(,, blockTimestampLast) = _pair.getReserves();
_update();
initialized = true;
function update() public onlyWhitelisted {
if (!initialized) {
initialize();
(, , uint32 blockTimestamp) =
UniswapV2OracleLibrary.currentCumulativePrices(address(pair));
uint32 timeElapsed = blockTimestamp - blockTimestampLast; // overflow is desired
// ensure that at least one full period has passed since the last update
if (timeElapsed >= PERIOD) {
function _update() internal {
(uint price0Cumulative, uint price1Cumulative, uint32 blockTimestamp) =
// overflow is desired, casting never truncates
// cumulative price is in (uq112x112 price * seconds) units so we simply wrap it after division by time elapsed
price0Average = FixedPoint.uq112x112(uint224((price0Cumulative - price0CumulativeLast) / timeElapsed));
price1Average = FixedPoint.uq112x112(uint224((price1Cumulative - price1CumulativeLast) / timeElapsed));
price0CumulativeLast = price0Cumulative;
price1CumulativeLast = price1Cumulative;
blockTimestampLast = blockTimestamp;
// note this will always return 0 before update has been called successfully for the first time.
function consult(address token, uint amountIn) public view returns (uint amountOut) {
if (token == token0) {
amountOut = price0Average.mul(amountIn).decode144();
require(token == token1, 'HunnyOracle: INVALID_TOKEN');
amountOut = price1Average.mul(amountIn).decode144();
function capture() public view returns(uint) {
uint consultAmount = consult(hunnyToken, 1e18);
if (consultAmount == 0) {
return BOOTSTRAP_HUNNY_PRICE;
return consultAmount;
// Dependency file: @pancakeswap/pancake-swap-lib/contracts/token/BEP20/BEP20.sol
contract BEP20 is Context, IBEP20, Ownable {
// Dependency file: contracts/interfaces/IPancakeRouter01.sol
// pragma solidity >=0.6.2;
interface IPancakeRouter01 {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin,
uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
function removeLiquidity(
uint liquidity,
) external returns (uint amountA, uint amountB);
function removeLiquidityETH(
) external returns (uint amountToken, uint amountETH);
function removeLiquidityWithPermit(
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
function removeLiquidityETHWithPermit(
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
) external returns (uint[] memory amounts);
function swapTokensForExactTokens(
uint amountOut,
uint amountInMax,
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
payable
returns (uint[] memory amounts);
function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
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 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 getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
// Dependency file: contracts/interfaces/IPancakeRouter02.sol
// import 'contracts/interfaces/IPancakeRouter01.sol';
interface IPancakeRouter02 is IPancakeRouter01 {
function removeLiquidityETHSupportingFeeOnTransferTokens(
) external returns (uint amountETH);
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
) external;
function swapExactETHForTokensSupportingFeeOnTransferTokens(
) external payable;
function swapExactTokensForETHSupportingFeeOnTransferTokens(
// Dependency file: contracts/interfaces/IPancakePair.sol
interface IPancakePair {
// Dependency file: contracts/interfaces/IPancakeFactory.sol
interface IPancakeFactory {
// Dependency file: contracts/hunny/legacy/PancakeSwap.sol
// import "@pancakeswap/pancake-swap-lib/contracts/token/BEP20/SafeBEP20.sol";
// import "contracts/interfaces/IPancakeRouter02.sol";
// import "contracts/interfaces/IPancakePair.sol";
// import "contracts/interfaces/IPancakeFactory.sol";
contract PancakeSwap {
using SafeBEP20 for IBEP20;
IPancakeRouter02 private ROUTER = IPancakeRouter02(Constants.PANCAKE_ROUTER);
IPancakeFactory private factory = IPancakeFactory(Constants.PANCAKE_FACTORY);
address internal cake = Constants.CAKE;
address private _hunny;
address private _wbnb = Constants.WBNB;
constructor(address _hunnyAddress) public {
_hunny = _hunnyAddress;
function hunnyBNBFlipToken() internal view returns(address) {
return factory.getPair(_hunny, _wbnb);
function tokenToHunnyBNB(address token, uint amount) internal returns(uint flipAmount) {
if (token == cake) {
flipAmount = _cakeToHunnyBNBFlip(amount);
// flip
flipAmount = _flipToHunnyBNBFlip(token, amount);
function _cakeToHunnyBNBFlip(uint amount) private returns(uint flipAmount) {
swapToken(cake, amount.div(2), _hunny);
swapToken(cake, amount.sub(amount.div(2)), _wbnb);
flipAmount = generateFlipToken();
function _flipToHunnyBNBFlip(address token, uint amount) private returns(uint flipAmount) {
IPancakePair pair = IPancakePair(token);
address _token0 = pair.token0();
address _token1 = pair.token1();
IBEP20(token).safeApprove(address(ROUTER), 0);
IBEP20(token).safeApprove(address(ROUTER), amount);
ROUTER.removeLiquidity(_token0, _token1, amount, 0, 0, address(this), block.timestamp);
if (_token0 == _wbnb) {
swapToken(_token1, IBEP20(_token1).balanceOf(address(this)), _hunny);
} else if (_token1 == _wbnb) {
swapToken(_token0, IBEP20(_token0).balanceOf(address(this)), _hunny);
swapToken(_token1, IBEP20(_token1).balanceOf(address(this)), _wbnb);
function swapToken(address _from, uint _amount, address _to) private {
if (_from == _to) return;
address[] memory path;
if (_from == _wbnb || _to == _wbnb) {
path = new address[](2);
path[0] = _from;
path[1] = _to;
path = new address[](3);
path[1] = _wbnb;
path[2] = _to;
IBEP20(_from).safeApprove(address(ROUTER), 0);
IBEP20(_from).safeApprove(address(ROUTER), _amount);
ROUTER.swapExactTokensForTokens(_amount, 0, path, address(this), block.timestamp);
function generateFlipToken() private returns(uint liquidity) {
uint amountADesired = IBEP20(_hunny).balanceOf(address(this));
uint amountBDesired = IBEP20(_wbnb).balanceOf(address(this));
IBEP20(_hunny).safeApprove(address(ROUTER), 0);
IBEP20(_hunny).safeApprove(address(ROUTER), amountADesired);
IBEP20(_wbnb).safeApprove(address(ROUTER), 0);
IBEP20(_wbnb).safeApprove(address(ROUTER), amountBDesired);
(,,liquidity) = ROUTER.addLiquidity(_hunny, _wbnb, amountADesired, amountBDesired, 0, 0, address(this), block.timestamp);
// send dust
IBEP20(_hunny).transfer(msg.sender, IBEP20(_hunny).balanceOf(address(this)));
IBEP20(_wbnb).transfer(msg.sender, IBEP20(_wbnb).balanceOf(address(this)));
// Dependency file: contracts/interfaces/IHunnyMinter.sol
interface IHunnyMinter {
function isMinter(address) view external returns(bool);
function amountHunnyToMint(uint bnbProfit) view external returns(uint);
function amountHunnyToMintForHunnyBNB(uint amount, uint duration) view external returns(uint);
function withdrawalFee(uint amount, uint depositedAt) view external returns(uint);
function performanceFee(uint profit) view external returns(uint);
function mintFor(address flip, uint _withdrawalFee, uint _performanceFee, address to, uint depositedAt) external;
function mintForHunnyBNB(uint amount, uint duration, address to) external;
function hunnyPerProfitBNB() view external returns(uint);
function hunnyPerBlockLottery() view external returns(uint);
function WITHDRAWAL_FEE_FREE_PERIOD() view external returns(uint);
function WITHDRAWAL_FEE() view external returns(uint);
function setMinter(address minter, bool canMint) external;
// Dependency file: contracts/interfaces/IHunnyOracle.sol
interface IHunnyOracle {
function price0CumulativeLast() external view returns(uint);
function price1CumulativeLast() external view returns(uint);
function blockTimestampLast() external view returns(uint);
function capture() external view returns(uint224);
function update() external;
// Dependency file: contracts/interfaces/legacy/IStakingRewards.sol
interface IStakingRewards {
function stakeTo(uint256 amount, address _to) external;
function notifyRewardAmount(uint256 reward) external;
// Dependency file: contracts/interfaces/legacy/IStrategyHelper.sol
// import "contracts/interfaces/IHunnyMinter.sol";
interface IStrategyHelper {
function tokenPriceInBNB(address _token) view external returns(uint);
function cakePriceInBNB() view external returns(uint);
function bnbPriceInUSD() view external returns(uint);
function flipPriceInBNB(address _flip) view external returns(uint);
function flipPriceInUSD(address _flip) view external returns(uint);
function profitOf(IHunnyMinter minter, address _flip, uint amount) external view returns (uint _usd, uint _hunny, uint _bnb);
function tvl(address _flip, uint amount) external view returns (uint); // in USD
function tvlInBNB(address _flip, uint amount) external view returns (uint); // in BNB
function apy(IHunnyMinter minter, uint pid) external view returns(uint _usd, uint _hunny, uint _bnb);
function compoundingAPY(uint pid, uint compoundUnit) view external returns(uint);
// Dependency file: contracts/hunny/legacy/HunnyMinter.sol
// import "@pancakeswap/pancake-swap-lib/contracts/token/BEP20/BEP20.sol";
// import "contracts/hunny/legacy/PancakeSwap.sol";
// import "contracts/interfaces/IHunnyOracle.sol";
// import "contracts/interfaces/legacy/IStakingRewards.sol";
// import "contracts/interfaces/legacy/IStrategyHelper.sol";
contract HunnyMinter is IHunnyMinter, Ownable, PancakeSwap {
BEP20 private hunny;
address public dev = Constants.HUNNY_DEPLOYER;
IBEP20 private WBNB = IBEP20(Constants.WBNB);
uint public override WITHDRAWAL_FEE_FREE_PERIOD = 2 days;
uint public override WITHDRAWAL_FEE = 50;
uint public constant FEE_MAX = 10000;
uint public PERFORMANCE_FEE = 3000; // 30%
uint public override hunnyPerProfitBNB;
uint public override hunnyPerBlockLottery;
uint public lastLotteryMintBlock;
uint public hunnyPerHunnyBNBFlip;
address public hunnyPool;
address public lotteryPool;
IHunnyOracle public oracle;
IStrategyHelper public helper;
mapping (address => bool) private _minters;
modifier onlyMinter {
require(isMinter(msg.sender) == true, "not minter");
constructor(address _hunny, address _hunnyPool, address _lotteryPool, address _oracle, address _helper) PancakeSwap(_hunny) public {
hunny = BEP20(_hunny);
hunnyPool = _hunnyPool;
lotteryPool = _lotteryPool;
oracle = IHunnyOracle(_oracle);
helper = IStrategyHelper(_helper);
hunnyPerProfitBNB = Constants.HUNNY_PER_PROFIT_BNB;
hunnyPerBlockLottery = Constants.HUNNY_PER_BLOCK_LOTTERY;
lastLotteryMintBlock = block.number;
hunnyPerHunnyBNBFlip = Constants.HUNNY_PER_HUNNY_BNB_FLIP;
hunny.approve(hunnyPool, uint(~0));
function transferHunnyOwner(address _owner) external onlyOwner {
Ownable(address(hunny)).transferOwnership(_owner);
function setWithdrawalFee(uint _fee) external onlyOwner {
require(_fee < 500, "wrong fee"); // less 5%
WITHDRAWAL_FEE = _fee;
function setPerformanceFee(uint _fee) external onlyOwner {
require(_fee < 5000, "wrong fee");
PERFORMANCE_FEE = _fee;
function setWithdrawalFeeFreePeriod(uint _period) external onlyOwner {
WITHDRAWAL_FEE_FREE_PERIOD = _period;
function setMinter(address minter, bool canMint) external override onlyOwner {
if (canMint) {
_minters[minter] = canMint;
delete _minters[minter];
function setHunnyPerProfitBNB(uint _ratio) external onlyOwner {
hunnyPerProfitBNB = _ratio;
function setHunnyPerHunnyBNBFlip(uint _hunnyPerHunnyBNBFlip) external onlyOwner {
hunnyPerHunnyBNBFlip = _hunnyPerHunnyBNBFlip;
function setHunnyPerBlockLottery(uint _hunnyPerBlockLottery) external onlyOwner {
hunnyPerBlockLottery = _hunnyPerBlockLottery;
function setHelper(IStrategyHelper _helper) external onlyOwner {
require(address(_helper) != address(0), "zero address");
helper = _helper;
function setOracle(IHunnyOracle _oracle) external onlyOwner {
require(address(_oracle) != address(0), "zero address");
oracle = _oracle;
function isMinter(address account) override view public returns(bool) {
if (hunny.getOwner() != address(this)) {
return false;
if (block.timestamp < 1605585600) { // 12:00 SGT 17th November 2020
return _minters[account];
function amountHunnyToMint(uint bnbProfit) override view public returns(uint) {
return bnbProfit.mul(hunnyPerProfitBNB).div(1e18);
function amountHunnyToMintForHunnyBNB(uint amount, uint duration) override view public returns(uint) {
return amount.mul(hunnyPerHunnyBNBFlip).mul(duration).div(365 days).div(1e18);
function withdrawalFee(uint amount, uint depositedAt) override view external returns(uint) {
if (depositedAt.add(WITHDRAWAL_FEE_FREE_PERIOD) > block.timestamp) {
return amount.mul(WITHDRAWAL_FEE).div(FEE_MAX);
function performanceFee(uint profit) override view public returns(uint) {
return profit.mul(PERFORMANCE_FEE).div(FEE_MAX);
function mintFor(address flip, uint _withdrawalFee, uint _performanceFee, address to, uint) override external onlyMinter {
uint feeSum = _performanceFee.add(_withdrawalFee);
IBEP20(flip).safeTransferFrom(msg.sender, address(this), feeSum);
uint hunnyBNBAmount = tokenToHunnyBNB(flip, IBEP20(flip).balanceOf(address(this)));
address flipToken = hunnyBNBFlipToken();
IBEP20(flipToken).safeTransfer(hunnyPool, hunnyBNBAmount);
IStakingRewards(hunnyPool).notifyRewardAmount(hunnyBNBAmount);
uint contribution = helper.tvlInBNB(flipToken, hunnyBNBAmount).mul(_performanceFee).div(feeSum);
uint mintHunny = amountHunnyToMint(contribution);
mint(mintHunny, to);
// addition step
// update oracle price
oracle.update();
function mintForHunnyBNB(uint amount, uint duration, address to) override external onlyMinter {
uint mintHunny = amountHunnyToMintForHunnyBNB(amount, duration);
if (mintHunny == 0) return;
function mint(uint amount, address to) private {
hunny.mint(amount);
hunny.transfer(to, amount);
uint hunnyForDev = amount.mul(15).div(100);
hunny.mint(hunnyForDev);
IStakingRewards(hunnyPool).stakeTo(hunnyForDev, dev);
// mint for lottery pool
mintForLottery();
// only after when lottery pool address was set
// token calculated from the block when dev set lottery pool address only
function mintForLottery() private {
if (lotteryPool != address(0)) {
uint amountHunny = block.number.sub(lastLotteryMintBlock).mul(hunnyPerBlockLottery);
hunny.mint(amountHunny);
hunny.transfer(lotteryPool, amountHunny);
// Dependency file: contracts/library/HomoraMath.sol
library HomoraMath {
function divCeil(uint lhs, uint rhs) internal pure returns (uint) {
return lhs.add(rhs).sub(1) / rhs;
function fmul(uint lhs, uint rhs) internal pure returns (uint) {
return lhs.mul(rhs) / (2**112);
function fdiv(uint lhs, uint rhs) internal pure returns (uint) {
return lhs.mul(2**112) / rhs;
// implementation from https://github.com/Uniswap/uniswap-lib/commit/99f3f28770640ba1bb1ff460ac7c5292fb8291a0
// original implementation: https://github.com/abdk-consulting/abdk-libraries-solidity/blob/master/ABDKMath64x64.sol#L687
function sqrt(uint x) internal pure returns (uint) {
uint xx = x;
uint r = 1;
uint r1 = x / r;
// Dependency file: contracts/interfaces/IMasterChef.sol
interface IMasterChef {
function cakePerBlock() view external returns(uint);
function totalAllocPoint() view external returns(uint);
function poolInfo(uint _pid) view external returns(address lpToken, uint allocPoint, uint lastRewardBlock, uint accCakePerShare);
function userInfo(uint _pid, address _account) view external returns(uint amount, uint rewardDebt);
function poolLength() view external returns(uint);
function deposit(uint256 _pid, uint256 _amount) external;
function withdraw(uint256 _pid, uint256 _amount) external;
function emergencyWithdraw(uint256 _pid) external;
function enterStaking(uint256 _amount) external;
function leaveStaking(uint256 _amount) external;
// Dependency file: contracts/interfaces/AggregatorV3Interface.sol
// pragma solidity >=0.6.0;
interface AggregatorV3Interface {
function description() external view returns (string memory);
function version() external view returns (uint256);
// getRoundData and latestRoundData should both raise "No data present"
// if they do not have data to report, instead of returning unset values
// which could be misinterpreted as actual reported values.
function getRoundData(uint80 _roundId)
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
function latestRoundData()
// Dependency file: contracts/vaults/legacy/StrategyHelperV1.sol
// import "contracts/library/HomoraMath.sol";
// import "contracts/interfaces/IMasterChef.sol";
// import "contracts/interfaces/AggregatorV3Interface.sol";
// no storage
// There are only calculations for apy, tvl, etc.
contract StrategyHelperV1 is Ownable {
IBEP20 private CAKE = IBEP20(Constants.CAKE);
IBEP20 private BUSD = IBEP20(Constants.BUSD);
IBEP20 public hunny;
IMasterChef private master = IMasterChef(Constants.PANCAKE_CHEF);
mapping(address => address) private tokenFeeds;
constructor(address _hunny) public {
hunny = IBEP20(_hunny);
// get hunny price to in BNB
function tokenPriceInBNB(address _token) public view returns(uint) {
if (_token == address(CAKE)) {
return cakePriceInBNB();
} else if (_token == address(hunny)) {
return oracle.capture();
return unsafeTokenPriceInBNB(_token);
function unsafeTokenPriceInBNB(address _token) private view returns(uint) {
address pair = factory.getPair(_token, address(WBNB));
uint decimal = uint(BEP20(_token).decimals());
(uint reserve0, uint reserve1, ) = IPancakePair(pair).getReserves();
if (IPancakePair(pair).token0() == _token) {
return reserve1.mul(10**decimal).div(reserve0);
} else if (IPancakePair(pair).token1() == _token) {
return reserve0.mul(10**decimal).div(reserve1);
function cakePriceInUSD() view public returns(uint) {
(, int price, , ,) = AggregatorV3Interface(tokenFeeds[address(CAKE)]).latestRoundData();
return uint(price).mul(1e10);
function cakePriceInBNB() view public returns(uint) {
return cakePriceInUSD().mul(1e18).div(bnbPriceInUSD());
function bnbPriceInUSD() view public returns(uint) {
(, int price, , ,) = AggregatorV3Interface(tokenFeeds[address(WBNB)]).latestRoundData();
function cakePerYearOfPool(uint pid) view public returns(uint) {
(, uint allocPoint,,) = master.poolInfo(pid);
return master.cakePerBlock().mul(blockPerYear()).mul(allocPoint).div(master.totalAllocPoint());
function blockPerYear() pure public returns(uint) {
// 86400 / 3 * 365
return 10512000;
function profitOf(address minter, address flip, uint amount) external view returns (uint _usd, uint _hunny, uint _bnb) {
_usd = tvl(flip, amount);
if (address(minter) == address(0)) {
_hunny = 0;
uint performanceFee = IHunnyMinter(minter).performanceFee(_usd);
_usd = _usd.sub(performanceFee);
uint bnbAmount = performanceFee.mul(1e18).div(bnbPriceInUSD());
_hunny = IHunnyMinter(minter).amountHunnyToMint(bnbAmount);
_bnb = 0;
// apy() = cakePrice * (cakePerBlock * blockPerYear * weight) / PoolValue(=WBNB*2)
function _apy(uint pid) view private returns(uint) {
(address token,,,) = master.poolInfo(pid);
uint poolSize = tvl(token, IBEP20(token).balanceOf(address(master))).mul(1e18).div(bnbPriceInUSD());
return cakePriceInBNB().mul(cakePerYearOfPool(pid)).div(poolSize);
function apy(address, uint pid) view public returns(uint _usd, uint _hunny, uint _bnb) {
_usd = compoundingAPY(pid, 1 days);
function tvl(address _flip, uint amount) public view returns (uint) {
if (_flip == address(CAKE)) {
return cakePriceInBNB().mul(bnbPriceInUSD()).mul(amount).div(1e36);
address _token0 = IPancakePair(_flip).token0();
address _token1 = IPancakePair(_flip).token1();
// using hunny price from the oracle
if (_token0 == address(hunny) || _token1 == address(hunny)) {
uint hunnyBalance = hunny.balanceOf(address(_flip)).mul(amount).div(IBEP20(_flip).totalSupply());
uint priceInBNB = tokenPriceInBNB(address(hunny));
uint price = priceInBNB.mul(bnbPriceInUSD()).div(1e18);
return hunnyBalance.mul(price).div(1e18).mul(2);
if (_token0 == address(WBNB) || _token1 == address(WBNB)) {
uint bnb = WBNB.balanceOf(address(_flip)).mul(amount).div(IBEP20(_flip).totalSupply());
uint price = bnbPriceInUSD();
return bnb.mul(price).div(1e18).mul(2);
uint balanceToken0 = IBEP20(_token0).balanceOf(_flip);
uint price = tokenPriceInBNB(_token0);
return balanceToken0.mul(price).div(1e18).mul(bnbPriceInUSD()).div(1e18).mul(2);
function tvlInBNB(address _flip, uint amount) public view returns (uint) {
return cakePriceInBNB().mul(amount).div(1e18);
return hunnyBalance.mul(priceInBNB).div(1e18).mul(2);
return bnb.mul(2);
return balanceToken0.mul(price).div(1e18).mul(2);
function compoundingAPY(uint pid, uint compoundUnit) view public returns(uint) {
uint __apy = _apy(pid);
uint compoundTimes = 365 days / compoundUnit;
uint unitAPY = 1e18 + (__apy / compoundTimes);
uint result = 1e18;
for(uint i=0; i<compoundTimes; i++) {
result = (result * unitAPY) / 1e18;
return result - 1e18;
function setOracle(address oracleAddress) public onlyOwner {
oracle = IHunnyOracle(oracleAddress);
function setTokenFeed(address asset, address feed) public onlyOwner {
tokenFeeds[asset] = feed;
// Dependency file: @openzeppelin/contracts/math/Math.sol
// pragma solidity >=0.6.0 <0.8.0;
* @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);
// Dependency file: @openzeppelin/contracts/utils/ReentrancyGuard.sol
* @dev Contract module that helps prevent reentrant calls to a function.
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied 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.
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
abstract contract ReentrancyGuard {
// 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
// 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
// pointer aliasing, and it cannot be disabled.
// 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
// 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
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor () internal {
_status = _NOT_ENTERED;
* @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() {
// On the first call to nonReentrant, _notEntered will be true
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
// Dependency file: contracts/library/legacy/RewardsDistributionRecipient.sol
____ __ __ __ _
/ __/__ __ ___ / /_ / / ___ / /_ (_)__ __
_\ \ / // // _ \/ __// _ \/ -_)/ __// / \ \ /
/___/ \_, //_//_/\__//_//_/\__/ \__//_/ /_\_\
/___/
* Docs: https://docs.synthetix.io/
* Copyright (c) 2020 Synthetix
abstract contract RewardsDistributionRecipient is Ownable {
address public rewardsDistribution;
modifier onlyRewardsDistribution() {
require(msg.sender == rewardsDistribution, "onlyRewardsDistribution");
function notifyRewardAmount(uint256 reward) virtual external;
function setRewardsDistribution(address _rewardsDistribution) external onlyOwner {
rewardsDistribution = _rewardsDistribution;
// Dependency file: contracts/library/legacy/Pausable.sol
abstract contract Pausable is Ownable {
uint public lastPauseTime;
bool public paused;
event PauseChanged(bool isPaused);
modifier notPaused {
require(!paused, "This action cannot be performed while the contract is paused");
require(owner() != address(0), "Owner must be set");
function setPaused(bool _paused) external onlyOwner {
if (_paused == paused) {
return;
paused = _paused;
if (paused) {
lastPauseTime = now;
emit PauseChanged(paused);
// Dependency file: contracts/interfaces/legacy/IStrategyLegacy.sol
pragma experimental ABIEncoderV2;
interface IStrategyLegacy {
struct Profit {
uint usd;
uint hunny;
uint bnb;
struct APY {
struct UserInfo {
uint balance;
uint principal;
uint available;
Profit profit;
uint poolTVL;
APY poolAPY;
function deposit(uint _amount) external;
function depositAll() external;
function withdraw(uint256 _amount) external; // HUNNY STAKING POOL ONLY
function withdrawAll() external;
function getReward() external; // HUNNY STAKING POOL ONLY
function harvest() external;
function balance() external view returns (uint);
function balanceOf(address account) external view returns (uint);
function principalOf(address account) external view returns (uint);
function withdrawableBalanceOf(address account) external view returns (uint); // HUNNY STAKING POOL ONLY
function profitOf(address account) external view returns (uint _usd, uint _hunny, uint _bnb);
// function earned(address account) external view returns (uint);
function tvl() external view returns (uint); // in USD
function apy() external view returns (uint _usd, uint _hunny, uint _bnb);
/* ========== Strategy Information ========== */
// function pid() external view returns (uint);
// function poolType() external view returns (PoolTypes);
// function isMinter() external view returns (bool, address);
// function getDepositedAt(address account) external view returns (uint);
// function getRewardsToken() external view returns (address);
function info(address account) external view returns (UserInfo memory);
// Dependency file: contracts/vaults/legacy/HunnyPool.sol
// import "@openzeppelin/contracts/math/Math.sol";
// import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
// import "contracts/library/legacy/RewardsDistributionRecipient.sol";
// import "contracts/library/legacy/Pausable.sol";
// import "contracts/interfaces/legacy/IStrategyLegacy.sol";
interface IPresale {
function endTime() view external returns(uint256);
function totalBalance() view external returns(uint);
function flipToken() view external returns(address);
contract HunnyPool is IStrategyLegacy, RewardsDistributionRecipient, ReentrancyGuard, Pausable {
/* ========== STATE VARIABLES ========== */
IBEP20 public rewardsToken; // hunny/bnb flip
IBEP20 public stakingToken;
uint256 public periodFinish = 0;
uint256 public rewardRate = 0;
uint256 public rewardsDuration = 90 days;
uint256 public lastUpdateTime;
uint256 public rewardPerTokenStored;
mapping(address => uint256) public userRewardPerTokenPaid;
mapping(address => uint256) public rewards;
mapping(address => bool) private _stakePermission;
/* ========== PRESALE ============== */
address private presaleContract;
address private constant deadAddress = 0x000000000000000000000000000000000000dEaD;
mapping(address => uint256) private _presaleBalance;
uint256 public TIMESTAMP_2_HOURS_AFTER_PRESALE;
uint256 public TIMESTAMP_90_DAYS_AFTER_PRESALE;
/* ========== HUNNY HELPER ========= */
/* ========== CONSTRUCTOR ========== */
constructor(address _hunny, address _presale, address _helper) public {
stakingToken = IBEP20(_hunny); // hunny
presaleContract = _presale;
rewardsDistribution = msg.sender;
_stakePermission[msg.sender] = true;
_stakePermission[presaleContract] = true;
stakingToken.safeApprove(address(ROUTER), uint(~0));
TIMESTAMP_2_HOURS_AFTER_PRESALE = IPresale(_presale).endTime() + 2 hours;
TIMESTAMP_90_DAYS_AFTER_PRESALE = IPresale(_presale).endTime() + 90 days;
/* ========== VIEWS ========== */
function totalSupply() external view returns (uint256) {
function balance() override external view returns (uint) {
function balanceOf(address account) override external view returns (uint256) {
function presaleBalanceOf(address account) external view returns(uint256) {
return _presaleBalance[account];
function principalOf(address account) override external view returns (uint256) {
function withdrawableBalanceOf(address account) override public view returns (uint) {
if (block.timestamp > TIMESTAMP_90_DAYS_AFTER_PRESALE) {
// unlock all presale hunny after 90 days of presale
} else if (block.timestamp < TIMESTAMP_2_HOURS_AFTER_PRESALE) {
return _balances[account].sub(_presaleBalance[account]);
uint soldInPresale = IPresale(presaleContract).totalBalance().div(2).mul(3); // mint 150% of presale for making flip token
uint hunnySupply = stakingToken.totalSupply().sub(stakingToken.balanceOf(deadAddress));
if (soldInPresale >= hunnySupply) {
uint hunnyNewMint = hunnySupply.sub(soldInPresale);
if (hunnyNewMint >= soldInPresale) {
uint lockedRatio = (soldInPresale.sub(hunnyNewMint)).mul(1e18).div(soldInPresale);
uint lockedBalance = _presaleBalance[account].mul(lockedRatio).div(1e18);
return _balances[account].sub(lockedBalance);
function profitOf(address account) override public view returns (uint _usd, uint _hunny, uint _bnb) {
_usd = 0;
_bnb = helper.tvlInBNB(address(rewardsToken), earned(account));
function tvl() override public view returns (uint) {
uint price = helper.tokenPriceInBNB(address(stakingToken));
return _totalSupply.mul(price).div(1e18);
function apy() override public view returns(uint _usd, uint _hunny, uint _bnb) {
uint tokenDecimals = 1e18;
uint __totalSupply = _totalSupply;
if (__totalSupply == 0) {
__totalSupply = tokenDecimals;
uint rewardPerTokenPerSecond = rewardRate.mul(tokenDecimals).div(__totalSupply);
uint hunnyPrice = helper.tokenPriceInBNB(address(stakingToken));
uint flipPrice = helper.tvlInBNB(address(rewardsToken), 1e18);
_bnb = rewardPerTokenPerSecond.mul(365 days).mul(flipPrice).div(hunnyPrice);
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 _balances[account].mul(rewardPerToken().sub(userRewardPerTokenPaid[account])).div(1e18).add(rewards[account]);
function getRewardForDuration() external view returns (uint256) {
return rewardRate.mul(rewardsDuration);
/* ========== MUTATIVE FUNCTIONS ========== */
function _deposit(uint256 amount, address _to) private nonReentrant notPaused updateReward(_to) {
require(amount > 0, "amount");
_balances[_to] = _balances[_to].add(amount);
stakingToken.safeTransferFrom(msg.sender, address(this), amount);
emit Staked(_to, amount);
function deposit(uint256 amount) override public {
_deposit(amount, msg.sender);
function depositAll() override external {
deposit(stakingToken.balanceOf(msg.sender));
function withdraw(uint256 amount) override public nonReentrant updateReward(msg.sender) {
require(amount <= withdrawableBalanceOf(msg.sender), "locked");
_balances[msg.sender] = _balances[msg.sender].sub(amount);
stakingToken.safeTransfer(msg.sender, amount);
emit Withdrawn(msg.sender, amount);
function withdrawAll() override external {
uint _withdraw = withdrawableBalanceOf(msg.sender);
if (_withdraw > 0) {
withdraw(_withdraw);
getReward();
function getReward() override public nonReentrant updateReward(msg.sender) {
uint256 reward = rewards[msg.sender];
if (reward > 0) {
rewards[msg.sender] = 0;
reward = _flipToWBNB(reward);
IBEP20(ROUTER.WETH()).safeTransfer(msg.sender, reward);
emit RewardPaid(msg.sender, reward);
function _flipToWBNB(uint amount) private returns(uint reward) {
address wbnb = ROUTER.WETH();
(uint rewardHunny,) = ROUTER.removeLiquidity(
address(stakingToken), wbnb,
amount, 0, 0, address(this), block.timestamp);
address[] memory path = new address[](2);
path[0] = address(stakingToken);
path[1] = wbnb;
ROUTER.swapExactTokensForTokens(rewardHunny, 0, path, address(this), block.timestamp);
reward = IBEP20(wbnb).balanceOf(address(this));
function harvest() override external {}
function info(address account) override external view returns(UserInfo memory) {
UserInfo memory userInfo;
userInfo.balance = _balances[account];
userInfo.principal = _balances[account];
userInfo.available = withdrawableBalanceOf(account);
Profit memory profit;
(uint usd, uint hunny, uint bnb) = profitOf(account);
profit.usd = usd;
profit.hunny = hunny;
profit.bnb = bnb;
userInfo.profit = profit;
userInfo.poolTVL = tvl();
APY memory poolAPY;
(usd, hunny, bnb) = apy();
poolAPY.usd = usd;
poolAPY.hunny = hunny;
poolAPY.bnb = bnb;
userInfo.poolAPY = poolAPY;
return userInfo;
/* ========== RESTRICTED FUNCTIONS ========== */
function setRewardsToken(address _rewardsToken) external onlyOwner {
require(address(rewardsToken) == address(0), "set rewards token already");
rewardsToken = IBEP20(_rewardsToken);
// safe approve
IBEP20(_rewardsToken).safeApprove(address(ROUTER), 0);
IBEP20(_rewardsToken).safeApprove(address(ROUTER), uint(~0));
function setStakePermission(address _address, bool permission) external onlyOwner {
_stakePermission[_address] = permission;
function stakeTo(uint256 amount, address _to) external canStakeTo {
_deposit(amount, _to);
if (msg.sender == presaleContract) {
_presaleBalance[_to] = _presaleBalance[_to].add(amount);
function notifyRewardAmount(uint256 reward) override external onlyRewardsDistribution updateReward(address(0)) {
if (block.timestamp >= periodFinish) {
rewardRate = reward.div(rewardsDuration);
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), "reward");
lastUpdateTime = block.timestamp;
periodFinish = block.timestamp.add(rewardsDuration);
emit RewardAdded(reward);
function recoverBEP20(address tokenAddress, uint256 tokenAmount) external onlyOwner {
require(tokenAddress != address(stakingToken) && tokenAddress != address(rewardsToken), "tokenAddress");
IBEP20(tokenAddress).safeTransfer(owner(), tokenAmount);
emit Recovered(tokenAddress, tokenAmount);
function setRewardsDuration(uint256 _rewardsDuration) external onlyOwner {
require(periodFinish == 0 || block.timestamp > periodFinish, "period");
rewardsDuration = _rewardsDuration;
emit RewardsDurationUpdated(rewardsDuration);
/* ========== MODIFIERS ========== */
modifier updateReward(address account) {
rewardPerTokenStored = rewardPerToken();
lastUpdateTime = lastTimeRewardApplicable();
if (account != address(0)) {
rewards[account] = earned(account);
userRewardPerTokenPaid[account] = rewardPerTokenStored;
modifier canStakeTo() {
require(_stakePermission[msg.sender], 'auth');
/* ========== EVENTS ========== */
event RewardAdded(uint256 reward);
event Staked(address indexed user, uint256 amount);
event Withdrawn(address indexed user, uint256 amount);
event RewardPaid(address indexed user, uint256 reward);
event RewardsDurationUpdated(uint256 newDuration);
event Recovered(address token, uint256 amount);
// Dependency file: contracts/vaults/legacy/HunnyBNBPool.sol
contract HunnyBNBPool is IStrategyLegacy, Ownable {
IBEP20 private HUNNY;
IBEP20 public token;
address public presale;
uint public totalShares;
mapping (address => uint) private _shares;
mapping (address => uint) public depositedAt;
IHunnyMinter public minter;
HUNNY = IBEP20(_hunny);
presale = _presale;
function setFlipToken(address _token) public onlyOwner {
require(address(token) == address(0), 'flip token set already');
token = IBEP20(_token);
function setMinter(IHunnyMinter _minter) external onlyOwner {
minter = _minter;
if (address(_minter) != address(0)) {
token.safeApprove(address(_minter), 0);
token.safeApprove(address(_minter), uint(~0));
function balance() override public view returns (uint) {
return token.balanceOf(address(this));
function balanceOf(address account) override public view returns(uint) {
return _shares[account];
function sharesOf(address account) public view returns (uint) {
function principalOf(address account) override public view returns (uint) {
if (address(minter) == address(0) || !minter.isMinter(address(this))) {
return (0, 0, 0);
return (0, minter.amountHunnyToMintForHunnyBNB(balanceOf(account), block.timestamp.sub(depositedAt[account])), 0);
return helper.tvl(address(token), balance());
uint amount = 1e18;
uint hunny = minter.amountHunnyToMintForHunnyBNB(amount, 365 days);
uint _tvl = helper.tvlInBNB(address(token), amount);
uint hunnyPrice = helper.tokenPriceInBNB(address(HUNNY));
return (hunny.mul(hunnyPrice).div(_tvl), 0, 0);
userInfo.balance = balanceOf(account);
userInfo.principal = principalOf(account);
function priceShare() public view returns(uint) {
return balance().mul(1e18).div(totalShares);
function depositTo(uint256, uint256 _amount, address _to) external {
require(msg.sender == presale || msg.sender == owner(), "not presale contract");
_depositTo(_amount, _to);
function _depositTo(uint _amount, address _to) private {
token.safeTransferFrom(msg.sender, address(this), _amount);
uint amount = _shares[_to];
if (amount != 0 && depositedAt[_to] != 0) {
uint duration = block.timestamp.sub(depositedAt[_to]);
mintHunny(amount, duration);
totalShares = totalShares.add(_amount);
_shares[_to] = _shares[_to].add(_amount);
depositedAt[_to] = block.timestamp;
function deposit(uint _amount) override public {
_depositTo(_amount, msg.sender);
deposit(token.balanceOf(msg.sender));
uint _withdraw = balanceOf(msg.sender);
totalShares = totalShares.sub(_shares[msg.sender]);
delete _shares[msg.sender];
uint depositTimestamp = depositedAt[msg.sender];
delete depositedAt[msg.sender];
mintHunny(_withdraw, block.timestamp.sub(depositTimestamp));
token.safeTransfer(msg.sender, _withdraw);
function mintHunny(uint amount, uint duration) private {
minter.mintForHunnyBNB(amount, duration, msg.sender);
function harvest() override external {
function withdraw(uint256) override external {
revert("Use withdrawAll");
function getReward() override external {
// Dependency file: contracts/vaults/legacy/CakeVault.sol
contract CakeVault is IStrategyLegacy, Ownable {
IBEP20 private CAKE;
IMasterChef private CAKE_MASTER_CHEF;
address public keeper = Constants.HUNNY_KEEPER;
uint public poolId = 0;
mapping (address => bool) private _whitelist;
constructor(address cake, address cakeMasterChef) public {
CAKE = IBEP20(cake);
CAKE_MASTER_CHEF = IMasterChef(cakeMasterChef);
CAKE.safeApprove(address(CAKE_MASTER_CHEF), uint(~0));
function setKeeper(address _keeper) external {
require(msg.sender == _keeper || msg.sender == owner(), 'auth');
require(_keeper != address(0), 'zero address');
keeper = _keeper;
function setHelper(IStrategyHelper _helper) external {
require(msg.sender == address(_helper) || msg.sender == owner(), 'auth');
function setWhitelist(address _address, bool _on) external onlyOwner {
(uint amount,) = CAKE_MASTER_CHEF.userInfo(poolId, address(this));
return CAKE.balanceOf(address(this)).add(amount);
// @returns cake amount
if (totalShares == 0) return 0;
return balance().mul(sharesOf(account)).div(totalShares);
return balanceOf(account);
function profitOf(address) override public view returns (uint _usd, uint _hunny, uint _bnb) {
// Not available
return helper.tvl(address(CAKE), balance());
return helper.apy(IHunnyMinter(address (0)), poolId);
require(_whitelist[msg.sender], "not whitelist");
uint _pool = balance();
CAKE.safeTransferFrom(msg.sender, address(this), _amount);
uint shares = 0;
if (totalShares == 0) {
shares = _amount;
shares = (_amount.mul(totalShares)).div(_pool);
totalShares = totalShares.add(shares);
_shares[_to] = _shares[_to].add(shares);
CAKE_MASTER_CHEF.leaveStaking(0);
uint balanceOfCake = CAKE.balanceOf(address(this));
CAKE_MASTER_CHEF.enterStaking(balanceOfCake);
deposit(CAKE.balanceOf(msg.sender));
uint amount = sharesOf(msg.sender);
withdraw(amount);
uint cakeAmount = CAKE.balanceOf(address(this));
CAKE_MASTER_CHEF.enterStaking(cakeAmount);
// salvage purpose only
function withdrawToken(address token, uint amount) external {
require(msg.sender == keeper || msg.sender == owner(), 'auth');
require(token != address(CAKE));
IBEP20(token).safeTransfer(msg.sender, amount);
function withdraw(uint256 _amount) override public {
uint _withdraw = balance().mul(_amount).div(totalShares);
totalShares = totalShares.sub(_amount);
_shares[msg.sender] = _shares[msg.sender].sub(_amount);
CAKE_MASTER_CHEF.leaveStaking(_withdraw.sub(CAKE.balanceOf(address(this))));
CAKE.safeTransfer(msg.sender, _withdraw);
CAKE_MASTER_CHEF.enterStaking(CAKE.balanceOf(address(this)));
revert("N/A");
// Dependency file: contracts/interfaces/legacy/ICakeVault.sol
interface ICakeVault {
function priceShare() external view returns(uint);
function balanceOf(address account) external view returns(uint);
function sharesOf(address account) external view returns(uint);
function withdraw(uint256 _amount) external;
// Dependency file: contracts/vaults/legacy/CakeFlipVault.sol
// import "contracts/interfaces/legacy/ICakeVault.sol";
contract CakeFlipVault is IStrategyLegacy, RewardsDistributionRecipient, ReentrancyGuard, Pausable {
ICakeVault public rewardsToken;
uint256 public rewardsDuration = 24 hours;
/* ========== CAKE ============= */
address private CAKE = Constants.CAKE;
uint public poolId;
/* ========== HUNNY HELPER / MINTER ========= */
constructor(uint _pid, address cake, address cakeMasterChef, address cakeVault, address hunnyMinter) public {
CAKE = cake;
(address _token,,,) = CAKE_MASTER_CHEF.poolInfo(_pid);
stakingToken = IBEP20(_token);
stakingToken.safeApprove(address(CAKE_MASTER_CHEF), uint(~0));
poolId = _pid;
setMinter(IHunnyMinter(hunnyMinter));
setRewardsToken(cakeVault); // cake vault address
// return cakeAmount, hunnyAmount, 0
uint cakeVaultPrice = rewardsToken.priceShare();
uint _earned = earned(account);
uint amount = _earned.mul(cakeVaultPrice).div(1e18);
if (address(minter) != address(0) && minter.isMinter(address(this))) {
uint performanceFee = minter.performanceFee(amount);
// cake amount
_usd = amount.sub(performanceFee);
uint bnbValue = helper.tvlInBNB(CAKE, performanceFee);
// hunny amount
_hunny = minter.amountHunnyToMint(bnbValue);
_usd = amount;
uint stakingTVL = helper.tvl(address(stakingToken), _totalSupply);
uint price = rewardsToken.priceShare();
uint earned = rewardsToken.balanceOf(address(this)).mul(price).div(1e18);
uint rewardTVL = helper.tvl(CAKE, earned);
return stakingTVL.add(rewardTVL);
function tvlStaking() external view returns (uint) {
return helper.tvl(address(stakingToken), _totalSupply);
function tvlReward() external view returns (uint) {
return helper.tvl(CAKE, earned);
uint dailyAPY = helper.compoundingAPY(poolId, 365 days).div(365);
uint cakeAPY = helper.compoundingAPY(0, 1 days);
uint cakeDailyAPY = helper.compoundingAPY(0, 365 days).div(365);
// let x = 0.5% (daily flip apr)
// let y = 0.87% (daily cake apr)
// sum of yield of the year = x*(1+y)^365 + x*(1+y)^364 + x*(1+y)^363 + ... + x
// ref: https://en.wikipedia.org/wiki/Geometric_series
// = x * (1-(1+y)^365) / (1-(1+y))
// = x * ((1+y)^365 - 1) / (y)
_usd = dailyAPY.mul(cakeAPY).div(cakeDailyAPY);
CAKE_MASTER_CHEF.deposit(poolId, amount);
_harvest();
CAKE_MASTER_CHEF.withdraw(poolId, amount);
uint _depositedAt = depositedAt[msg.sender];
uint withdrawalFee = minter.withdrawalFee(amount, _depositedAt);
if (withdrawalFee > 0) {
uint performanceFee = withdrawalFee.div(100);
minter.mintFor(address(stakingToken), withdrawalFee.sub(performanceFee), performanceFee, msg.sender, _depositedAt);
amount = amount.sub(withdrawalFee);
rewardsToken.withdraw(reward);
uint cakeBalance = IBEP20(CAKE).balanceOf(address(this));
uint performanceFee = minter.performanceFee(cakeBalance);
minter.mintFor(CAKE, 0, performanceFee, msg.sender, depositedAt[msg.sender]);
cakeBalance = cakeBalance.sub(performanceFee);
IBEP20(CAKE).safeTransfer(msg.sender, cakeBalance);
emit RewardPaid(msg.sender, cakeBalance);
function harvest() override public {
CAKE_MASTER_CHEF.withdraw(poolId, 0);
function _harvest() private {
uint cakeAmount = IBEP20(CAKE).balanceOf(address(this));
uint _before = rewardsToken.sharesOf(address(this));
rewardsToken.deposit(cakeAmount);
uint amount = rewardsToken.sharesOf(address(this)).sub(_before);
if (amount > 0) {
_notifyRewardAmount(amount);
function setMinter(IHunnyMinter _minter) public onlyOwner {
// can zero
IBEP20(CAKE).safeApprove(address(_minter), 0);
IBEP20(CAKE).safeApprove(address(_minter), uint(~0));
stakingToken.safeApprove(address(_minter), 0);
stakingToken.safeApprove(address(_minter), uint(~0));
function setRewardsToken(address _rewardsToken) private onlyOwner {
rewardsToken = ICakeVault(_rewardsToken);
IBEP20(CAKE).safeApprove(_rewardsToken, 0);
IBEP20(CAKE).safeApprove(_rewardsToken, uint(~0));
function notifyRewardAmount(uint256 reward) override public onlyRewardsDistribution {
_notifyRewardAmount(reward);
function _notifyRewardAmount(uint256 reward) private updateReward(address(0)) {
uint _balance = rewardsToken.sharesOf(address(this));
// Root file: contracts/hunny/HunnyDeployer.sol
pragma solidity ^0.6.12;
// import "contracts/hunny/HunnyToken.sol";
// import "contracts/hunny/HunnyOracle.sol";
// import "contracts/hunny/legacy/HunnyMinter.sol";
// import "contracts/vaults/legacy/StrategyHelperV1.sol";
// import "contracts/vaults/legacy/HunnyPool.sol";
// import "contracts/vaults/legacy/HunnyBNBPool.sol";
// import "contracts/vaults/legacy/CakeVault.sol";
// import "contracts/vaults/legacy/CakeFlipVault.sol";
interface Presale {
function totalBalance() external view returns(uint);
function flipToken() external view returns(address);
function initialize(address _token, address _masterChef, address _rewardToken) external;
function distributeTokens(uint _pid, uint _fromIndex, uint _toIndex) external;
function distributeTokensWhiteList(uint _pid) external;
function finalize() external;
// assume that the presale contract has been deployed
// deploy following contract only when the presale ended
// ready for add liquidity and open legacy pools
contract Deployer1 is Ownable {
HunnyToken public hunny;
HunnyOracle public hunnyOracle;
StrategyHelperV1 public helper;
HunnyPool public hunnyPool;
HunnyBNBPool public hunnyBNBPool;
HunnyMinter public hunnyMinter;
constructor(address presaleAddress) public {
// deploy hunny token
hunny = new HunnyToken();
hunnyOracle = new HunnyOracle(address(hunny));
helper = new StrategyHelperV1(address(hunny));
// deploy HUNNY Pool
hunnyPool = new HunnyPool(
address(hunny),
address(presaleAddress),
address(helper)
// deploy HUNNY BNB pool
hunnyBNBPool = new HunnyBNBPool(
// deploy hunny minter
hunnyMinter = new HunnyMinter(
address(hunnyPool),
address(Constants.HUNNY_LOTTERY),
address(hunnyOracle),
function transferContractOwner(address deployer2) public onlyOwner {
hunny.transferOwnership(deployer2);
hunny.transferOperator(deployer2);
hunnyOracle.transferOwnership(deployer2);
helper.transferOwnership(deployer2);
hunnyPool.transferOwnership(deployer2);
hunnyBNBPool.transferOwnership(deployer2);
hunnyMinter.transferOwnership(deployer2);
contract Deployer2 is Ownable {
Deployer1 public deployer1;
Presale public presale;
constructor(address deployer1Address, address payable presaleAddress) public {
deployer1 = Deployer1(deployer1Address);
presale = Presale(presaleAddress);
// allow deployer2 receive BNB from presale contract
receive() external payable{}
function step1_presaleInitialize() public onlyOwner {
// mint token for presale contract
deployer1.hunny().mint(address(presale), presale.totalBalance());
// this part used to add liquidity and distribute to HUNNY pool as reward
deployer1.hunny().mint(address(this), presale.totalBalance().div(2));
// initialize presale
presale.initialize(
address(deployer1.hunny()),
address(deployer1.hunnyBNBPool()),
address(deployer1.hunnyPool())
// set flip token
deployer1.hunnyBNBPool().setFlipToken(presale.flipToken());
// set rewards token
deployer1.hunnyPool().setRewardsToken(presale.flipToken());
// update anti-whale max value
// anti bots
deployer1.hunny().updateMaxTransferAmountRate(4);
function step2_1_presaleDistributeTokens(uint fromIndex, uint toIndex) public onlyOwner {
deployer1.hunny().updateMaxTransferAmountRate(10000);
presale.distributeTokens(0, fromIndex, toIndex);
function step2_2_presaleDistributeTokensWhiteList() public onlyOwner {
presale.distributeTokensWhiteList(0);
function step3_presaleFinalize() public onlyOwner {
// transfer remain fund to this address
presale.finalize();
// transfer HUNNY token ownership
deployer1.hunny().transferOwnership(address(deployer1.hunnyMinter()));
// set minter role for HUNNY-BNB Hive Pool
deployer1.hunnyMinter().setMinter(address(deployer1.hunnyBNBPool()), true);
// set minter address in HUNNY-BNB Hive Pool
deployer1.hunnyBNBPool().setMinter(IHunnyMinter(address(deployer1.hunnyMinter())));
// set stake permission for Hunny Minter from HUNNY Hive Pool
deployer1.hunnyPool().setStakePermission(address(deployer1.hunnyMinter()), true);
// transfer hunny oracle owner to hunny minter
deployer1.hunnyOracle().transferOwnership(address(deployer1.hunnyMinter()));
function step4_setupLiquidityReward(uint256 bnbAmount) public onlyOwner {
IPancakeRouter02 router = IPancakeRouter02(Constants.PANCAKE_ROUTER);
address token = address(deployer1.hunny());
uint256 tokenAmount = bnbAmount.mul(deployer1.hunny().balanceOf(address(this))).div(address(this).balance);
IBEP20(token).safeApprove(address(router), 0);
IBEP20(token).safeApprove(address(router), tokenAmount);
router.addLiquidityETH{value: bnbAmount}(token, tokenAmount, 0, 0, address(this), block.timestamp);
payable(owner()).transfer(address(this).balance);
deployer1.hunny().transfer(owner(), deployer1.hunny().balanceOf(address(this)));
// set reward distribution on this address
deployer1.hunnyPool().setRewardsDistribution(address(this));
// transfer reward to HUNNY Hive Pool
uint256 rewardAmount = IBEP20(presale.flipToken()).balanceOf(address(this));
IBEP20(presale.flipToken()).transfer(address(deployer1.hunnyPool()), rewardAmount);
deployer1.hunnyPool().notifyRewardAmount(rewardAmount);
// set reward distribution on HUNNY Hive Pool
deployer1.hunnyPool().setRewardsDistribution(address(deployer1.hunnyMinter()));
function transferContractOwner(address newOwner) public onlyOwner {
Ownable(address(presale)).transferOwnership(newOwner);
deployer1.hunny().transferOperator(newOwner);
deployer1.helper().transferOwnership(newOwner);
deployer1.hunnyPool().transferOwnership(newOwner);
deployer1.hunnyBNBPool().transferOwnership(newOwner);
deployer1.hunnyMinter().transferOwnership(newOwner);
// in the emergency situation, transfer remain fund to dev
// dev will init liquidity and distribute reward
function emergencyTransfer() public payable onlyOwner {
ba163b03ae858daed1ba5af227adc536067c4a6e
8067c15e36c7deea9a646f7cc4060ae070a9b3e6
e4ecf986e1f6dc4c16c8a234c6463cded42890a2
16d1856bbb045cc46b1e04b84befd189a4ce7192
The provided code comprises smart contracts that are integral to a DeFi project. These contracts manage liquidity, token staking, and yield farming. The `CakeVault` and `CakeFlipVault` contracts handle token deposits, withdrawals, and reward harvesting. The `Presale` interface outlines functions for managing a token presale. The `Deployer1` and `Deployer2` contracts are used for deploying and initializing various project contracts, setting up ownership transfers, and finalizing the project's initial state.
The entire ecosystem is designed to facilitate token liquidity, yield generation, and presale distribution, but a comprehensive understanding of the entire project is necessary for proper utilization and security.
The provided code contains several contracts, each with its own set of privileged roles:
CakeVault:
CakeFlipVault:
Presale:
Deployer1 and Deployer2:
HunnyMinter:
HunnyPool and HunnyBNBPool:
HunnyOracle:
Please note that while these privileged roles are outlined in the code, their actual responsibilities and roles may vary depending on the project's specific requirements and implementation. Privileged roles are an important aspect of DeFi projects to ensure proper governance, security, and functionality.
function setMinter(address minter, bool canMint) external override onlyOwner { if (canMint) { _minters[minter] = canMint; } else { delete _minters[minter]; } }
Location in code: In the setMinter functionLine number: 5082-5094Description: The setMinter function is used to set the minter role, which controls minting of tokens. However, it is not properly restricted to only the owner's access. Any address can call this function and potentially take control of minting. This poses a severe security risk, as unauthorized minting can lead to financial losses. Proper access control should be implemented to restrict access to this function.
function emergencyTransfer() public payable onlyOwner { payable(owner()).transfer(address(this).balance); deployer1.hunny().transfer(owner(), deployer1.hunny().balanceOf(address(this))); }
Location in Code: function emergencyTransfer() public payable onlyOwner {Line in code: 8553-8559Description: The emergencyTransfer function allows the owner to transfer all remaining funds to the owner address. This poses a security risk, as it gives the owner full control over the contract's funds, which can lead to unauthorized fund transfers or misuse of the contract's balance.
function step4_setupLiquidityReward(uint256 bnbAmount) public onlyOwner { deployer1.hunny().updateMaxTransferAmountRate(10000); IPancakeRouter02 router = IPancakeRouter02(Constants.PANCAKE_ROUTER); address token = address(deployer1.hunny()); uint256 tokenAmount = bnbAmount.mul(deployer1.hunny().balanceOf(address(this))).div(address(this).balance); IBEP20(token).safeApprove(address(router), 0); IBEP20(token).safeApprove(address(router), tokenAmount); router.addLiquidityETH{value: bnbAmount}(token, tokenAmount, 0, 0, address(this), block.timestamp); payable(owner()).transfer(address(this).balance); deployer1.hunny().transfer(owner(), deployer1.hunny().balanceOf(address(this))); // set reward distribution on this address deployer1.hunnyPool().setRewardsDistribution(address(this)); // transfer reward to HUNNY Hive Pool uint256 rewardAmount = IBEP20(presale.flipToken()).balanceOf(address(this)); IBEP20(presale.flipToken()).transfer(address(deployer1.hunnyPool()), rewardAmount); deployer1.hunnyPool().notifyRewardAmount(rewardAmount); // set reward distribution on HUNNY Hive Pool deployer1.hunnyPool().setRewardsDistribution(address(deployer1.hunnyMinter())); deployer1.hunny().updateMaxTransferAmountRate(4); }
Line in code: 8482-8527Location in Code: function step4_setupLiquidityReward(uint256 bnbAmount) public onlyOwner {Description: The deployment of the liquidity pool in the step4_setupLiquidityReward function doesn't include proper checks and safeguards, which could lead to potential issues with the liquidity pool's configuration.
function step1_presaleInitialize() public onlyOwner { deployer1.hunny().mint(address(presale), presale.totalBalance()); deployer1.hunny().mint(address(this), presale.totalBalance().div(2)); presale.initialize( address(deployer1.hunny()), address(deployer1.hunnyBNBPool()), address(deployer1.hunnyPool()) ); deployer1.hunnyBNBPool().setFlipToken(presale.flipToken()); deployer1.hunnyPool().setRewardsToken(presale.flipToken()); deployer1.hunny().updateMaxTransferAmountRate(4); }
Line in code: 8382-8409Location in Code: function step1_presaleInitialize() public onlyOwner {Description: The step1_presaleInitialize function initializes the presale contract and transfers tokens to it without checking for potential issues or errors during the process.
Our industry-leading audit methodology and tooling includes a review of your code’s logic, with a mathematical approach to ensure your program works as intended.