Last active
September 29, 2021 10:24
-
-
Save korrio/41f86913d735dca4d45e6fe6c3145a1f to your computer and use it in GitHub Desktop.
HolderBonus.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pragma solidity ^0.6.12; | |
| pragma experimental ABIEncoderV2; | |
| // import './VonderToken.sol'; | |
| // import './MasterChef.sol'; | |
| abstract contract Context { | |
| function _msgSender() internal view virtual returns (address payable) { | |
| return msg.sender; | |
| } | |
| function _msgData() internal view virtual returns (bytes memory) { | |
| this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 | |
| return msg.data; | |
| } | |
| } | |
| /** | |
| * @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. | |
| */ | |
| abstract contract Ownable is Context { | |
| address private _owner; | |
| event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); | |
| /** | |
| * @dev Initializes the contract setting the deployer as the initial owner. | |
| */ | |
| constructor () internal { | |
| address msgSender = _msgSender(); | |
| _owner = msgSender; | |
| emit OwnershipTransferred(address(0), msgSender); | |
| } | |
| /** | |
| * @dev Returns the address of the current owner. | |
| */ | |
| function owner() public view returns (address) { | |
| return _owner; | |
| } | |
| /** | |
| * @dev Throws if called by any account other than the owner. | |
| */ | |
| modifier onlyOwner() { | |
| require(_owner == _msgSender(), "Ownable: caller is not the owner"); | |
| _; | |
| } | |
| /** | |
| * @dev Leaves the contract without owner. It will not be possible to call | |
| * `onlyOwner` functions anymore. Can only be called by the current owner. | |
| * | |
| * NOTE: Renouncing ownership will leave the contract without an owner, | |
| * thereby removing any functionality that is only available to the owner. | |
| */ | |
| function renounceOwnership() public virtual onlyOwner { | |
| emit OwnershipTransferred(_owner, address(0)); | |
| _owner = address(0); | |
| } | |
| /** | |
| * @dev Transfers ownership of the contract to a new account (`newOwner`). | |
| * Can only be called by the current owner. | |
| */ | |
| function transferOwnership(address newOwner) public virtual onlyOwner { | |
| require(newOwner != address(0), "Ownable: new owner is the zero address"); | |
| emit OwnershipTransferred(_owner, newOwner); | |
| _owner = newOwner; | |
| } | |
| } | |
| 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; | |
| } | |
| } | |
| 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); | |
| } | |
| interface IMasterChef { | |
| // using BoringERC20 for IERC20; | |
| struct UserInfo { | |
| uint256 amount; // How many LP tokens the user has provided. | |
| uint256 rewardDebt; // Reward debt. See explanation below. | |
| } | |
| // struct PoolInfo { | |
| // IERC20 lpToken; // Address of LP token contract. | |
| // uint256 allocPoint; // How many allocation points assigned to this pool. SUSHI to distribute per block. | |
| // uint256 lastRewardBlock; // Last block number that SUSHI distribution occurs. | |
| // uint256 accSushiPerShare; // Accumulated SUSHI per share, times 1e12. See below. | |
| // } | |
| function userInfo(uint256 pid, address userAddress) external view returns (IMasterChef.UserInfo memory); | |
| // function poolInfo(uint256 pid) external view returns (IMasterChef.PoolInfo memory); | |
| function totalAllocPoint() external view returns (uint256); | |
| function deposit(uint256 _pid, uint256 _amount) external; | |
| } | |
| 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; | |
| } | |
| } | |
| contract HolderBonus is Ownable,ReentrancyGuard { | |
| using SafeMath for uint256; | |
| // address myWalletAddress = 0x22f45E683b2574eFe3b2d82642E4176Fa1967c42; | |
| IMasterChef public immutable MASTER_CHEF; // 0x60326f6Ad05adeE2ffD42B0c05c68Ead535B104E | |
| IBEP20 public von; // 0x19dade57b0bbce7d5e859ba02846820f5c0c2b09 | |
| address public devaddress = 0x4D2f9077F357c4296dAB5fcd27DB793Ed6E0AEae; | |
| mapping(address => bool) public isClaimed; | |
| uint256 public totalVonBonus = 500000 ether; | |
| uint256 public startBonusBlock = 2490110; // will be claimable at 00.05 am | |
| // uint256 public startBonusBlock = 2485100; // for test claim | |
| uint256 public PRECISION_FACTOR; | |
| event Claimed(address wallet, uint256 claimAmount); | |
| // constructor (IMasterChef _masterChef, IBEP20 _von) public { | |
| constructor (IMasterChef _masterChef, IBEP20 _von) public { | |
| MASTER_CHEF = _masterChef; | |
| von = _von; | |
| // devaddress = _devaddress; | |
| uint256 decimalsRewardToken = uint256(von.decimals()); | |
| require(decimalsRewardToken < 30, "Must be inferior to 30"); | |
| PRECISION_FACTOR = uint256(10**(uint256(30).sub(decimalsRewardToken))); | |
| } | |
| function getMasterChefAddress() public view returns (address) { | |
| return address(MASTER_CHEF); | |
| } | |
| function getStakeAmount(address theAddress) public view returns (uint256) { | |
| return MASTER_CHEF.userInfo(0,theAddress).amount; | |
| } | |
| function getVonInMasterchef() public view returns (uint256) { | |
| return von.balanceOf(address(MASTER_CHEF)); | |
| } | |
| function getClaimableAmount(address theAddress) public view returns (uint256) { | |
| uint256 stakeAmount = getStakeAmount(theAddress); | |
| uint256 vonInMasterchef = getVonInMasterchef(); | |
| uint256 claimAmount = stakeAmount.mul(totalVonBonus).div(vonInMasterchef); | |
| return claimAmount; | |
| } | |
| function emergencyWithdraw() external onlyOwner { | |
| von.transfer(msg.sender, von.balanceOf(address(this))); | |
| } | |
| function isClaimable() external view returns (bool) { | |
| return !isClaimed[msg.sender] && block.number > startBonusBlock; | |
| } | |
| function getCurrentBlock() external view returns (uint) { | |
| return block.number; | |
| } | |
| function getCurrentBlockTimestamp() external view returns (uint) { | |
| return block.timestamp; | |
| } | |
| function claim() external nonReentrant { | |
| require(!isClaimed[msg.sender]); | |
| require(block.number > startBonusBlock); | |
| isClaimed[msg.sender] = true; | |
| uint256 claimAmount = getClaimableAmount(msg.sender); | |
| // von.transfer(msg.sender, claimAmount); | |
| von.transferFrom(devaddress,msg.sender,claimAmount); | |
| emit Claimed(msg.sender, claimAmount); | |
| } | |
| function claimFromDevAddress(uint256 amount) external onlyOwner nonReentrant { | |
| von.transferFrom(devaddress,msg.sender,amount); | |
| } | |
| function setStartBonusBlock(uint256 _blockNumber) external onlyOwner { | |
| startBonusBlock = _blockNumber; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment