Last active
August 29, 2021 06:24
-
-
Save minemintteam/0a09c69f949c84835856c7a4df1d91d3 to your computer and use it in GitHub Desktop.
This file contains 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
// SPDX-License-Identifier: MIT | |
//Copyright 2021 MineMintTeam | Samuel Rivera | |
//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 SOFTWARE. | |
//MineMintFaucet - v1.3 | |
pragma solidity ^0.6.2; | |
//IERC20 thanks to OpenZeppelin | |
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.0.0/contracts/token/ERC20/IERC20.sol"; | |
//Faucet Contract | |
contract faucet { | |
//set contract owner for balance Returns | |
address _owner = 0xYOURWALLETADDRESS; //please replace with your personal wallet, the owner | |
//Initialize the token contract | |
address _token = 0xYOURTOKENCONTRACT; //please replace with your token contract address | |
IERC20 private token = IERC20(_token); | |
//Initialize cotract wallet | |
address _wallet = address(this); | |
//Initialize varibles for mini game | |
mapping(address => uint) private users; | |
mapping(address => uint) private levels; | |
mapping(address => uint) private counts; | |
mapping(address => uint) private times; | |
mapping(address => uint) private ammounts; | |
//accept any token as payable | |
receive() external payable {} | |
//buy a level up | |
function buyLevel() payable public returns (bool) { | |
if(msg.value >= 100) { | |
require(msg.value >= 100); | |
_setLevel(); | |
if(levels[msg.sender] == 1) { | |
_resetDripCount(); | |
_setTime(60 minutes); | |
_setTokenAllowance(1000000000000); | |
} | |
if(levels[msg.sender] == 2) { | |
_resetDripCount(); | |
_setTime(59 minutes); | |
_setTokenAllowance(1100000000000); | |
} | |
if(levels[msg.sender] == 3) { | |
_resetDripCount(); | |
_setTime(58 minutes); | |
_setTokenAllowance(1200000000000); | |
} | |
if(levels[msg.sender] == 4) { | |
_resetDripCount(); | |
_setTime(57 minutes); | |
_setTokenAllowance(1300000000000); | |
} | |
if(levels[msg.sender] == 5) { | |
_resetDripCount(); | |
_setTime(56 minutes); | |
_setTokenAllowance(1400000000000); | |
} | |
if(levels[msg.sender] == 6) { | |
_resetDripCount(); | |
_setTime(55 minutes); | |
_setTokenAllowance(1500000000000); | |
} | |
if(levels[msg.sender] == 7) { | |
_resetDripCount(); | |
_setTime(54 minutes); | |
_setTokenAllowance(1600000000000); | |
} | |
if(levels[msg.sender] == 8) { | |
_resetDripCount(); | |
_setTime(53 minutes); | |
_setTokenAllowance(1700000000000); | |
} | |
if(levels[msg.sender] == 9) { | |
_resetDripCount(); | |
_setTime(52 minutes); | |
_setTokenAllowance(1800000000000); | |
} | |
if(levels[msg.sender] == 10) { | |
_resetDripCount(); | |
_setTime(51 minutes); | |
_setTokenAllowance(1900000000000); | |
} | |
if(levels[msg.sender] == 11) { | |
_resetDripCount(); | |
_setTime(50 minutes); | |
_setTokenAllowance(2000000000000); | |
} | |
if(levels[msg.sender] == 12) { | |
_resetDripCount(); | |
_setTime(49 minutes); | |
_setTokenAllowance(2100000000000); | |
} | |
if(levels[msg.sender] == 13) { | |
_resetDripCount(); | |
_setTime(48 minutes); | |
_setTokenAllowance(2200000000000); | |
} | |
if(levels[msg.sender] == 14) { | |
_resetDripCount(); | |
_setTime(47 minutes); | |
_setTokenAllowance(2300000000000); | |
} | |
if(levels[msg.sender] == 15) { | |
_resetDripCount(); | |
_setTime(46 minutes); | |
_setTokenAllowance(2400000000000); | |
} | |
if(levels[msg.sender] == 16) { | |
_resetDripCount(); | |
_setTime(45 minutes); | |
_setTokenAllowance(2500000000000); | |
} | |
return true; | |
} else { | |
return false; | |
} | |
} | |
//Sets user level | |
function _setLevel() private { | |
levels[msg.sender]++; | |
} | |
//Returns user level | |
function getLevel() public view returns (uint) { | |
return levels[msg.sender]; | |
} | |
//Sets user takes | |
function _upDripCount() private { | |
counts[msg.sender]++; | |
} | |
//Reset user takes | |
function _resetDripCount() private { | |
counts[msg.sender] = 0; | |
} | |
//Returns user take | |
function getDripCount() public view returns (uint) { | |
return counts[msg.sender]; | |
} | |
//Returns user take | |
function getTimeInterval() public view returns (uint256) { | |
return times[msg.sender]; | |
} | |
//set new times | |
function _setTime(uint256 time) private { | |
times[msg.sender] = time; | |
} | |
//Returns token allowance | |
function getTokenAllowance() public view returns (uint256) { | |
return ammounts[msg.sender]; | |
} | |
//set token allowance | |
function _setTokenAllowance(uint256 amount) private { | |
ammounts[msg.sender] = amount; | |
} | |
//Function to verify if enough time has past to collect | |
function _checkTime() private returns (bool) { | |
//checks to see if 60-45 minutes has passed, and if is true, it updates last time collected | |
if (now - users[msg.sender] < times[msg.sender]) { | |
return false; | |
} else { | |
users[msg.sender] = now; | |
return true; | |
} | |
} | |
//Returns user last time | |
function isFaucetReady() public view returns (bool ready) { | |
return (now - users[msg.sender] > times[msg.sender]); | |
} | |
//Returns faucet balance | |
function getFaucetBalance() public view returns (uint) { | |
return token.balanceOf(address(this)); | |
} | |
//Allows for safe transfer of funds | |
function _safeTransferFrom(address recipient, uint amount) private { | |
bool sent = token.transfer(recipient, amount); | |
require(sent, "Token transfer failed"); | |
} | |
//returns the token balance in the contract to the owner wallet | |
function returnTokenBalance() public returns (bool) { | |
if(msg.sender == _owner) { | |
_safeTransferFrom(msg.sender, token.balanceOf(address(this))); | |
return true; | |
} else { | |
return false; | |
} | |
} | |
//returns the token balance in the contract to the owner wallet | |
function returnMintBalance() public returns (bool) { | |
if(msg.sender == _owner) { | |
msg.sender.transfer(address(this).balance); | |
return true; | |
} else { | |
return false; | |
} | |
} | |
//Public access to funds, drip checks all requierments and level\ | |
function faucetDrip() public returns (bool success) { | |
// Only allow to drip every 60-45 minutes per user to limit abuse | |
if(_checkTime()) { | |
//initialiazes variable for new users | |
if(levels[msg.sender] == 0) { | |
_setLevel(); | |
_setTime(60 minutes); | |
_setTokenAllowance(1000000000000); | |
} | |
//level up logic | |
if(counts[msg.sender] >= 10 && levels[msg.sender] == 1) { | |
_resetDripCount(); | |
_setLevel(); | |
_setTime(59 minutes); | |
_setTokenAllowance(1100000000000); | |
} | |
if(counts[msg.sender] >= 24 && levels[msg.sender] == 2) { | |
_resetDripCount(); | |
_setLevel(); | |
_setTime(58 minutes); | |
_setTokenAllowance(1200000000000); | |
} | |
if(counts[msg.sender] >= 48 && levels[msg.sender] == 3) { | |
_resetDripCount(); | |
_setLevel(); | |
_setTime(57 minutes); | |
_setTokenAllowance(1300000000000); | |
} | |
if(counts[msg.sender] >= 72 && levels[msg.sender] == 4) { | |
_resetDripCount(); | |
_setLevel(); | |
_setTime(56 minutes); | |
_setTokenAllowance(1400000000000); | |
} | |
if(counts[msg.sender] >= 96 && levels[msg.sender] == 5) { | |
_resetDripCount(); | |
_setLevel(); | |
_setTime(55 minutes); | |
_setTokenAllowance(1500000000000); | |
} | |
if(counts[msg.sender] >= 120 && levels[msg.sender] == 6) { | |
_resetDripCount(); | |
_setLevel(); | |
_setTime(54 minutes); | |
_setTokenAllowance(1600000000000); | |
} | |
if(counts[msg.sender] >= 144 && levels[msg.sender] == 7) { | |
_resetDripCount(); | |
_setLevel(); | |
_setTime(53 minutes); | |
_setTokenAllowance(1700000000000); | |
} | |
if(counts[msg.sender] >= 168 && levels[msg.sender] == 8) { | |
_resetDripCount(); | |
_setLevel(); | |
_setTime(52 minutes); | |
_setTokenAllowance(1800000000000); | |
} | |
if(counts[msg.sender] >= 192 && levels[msg.sender] == 9) { | |
_resetDripCount(); | |
_setLevel(); | |
_setTime(51 minutes); | |
_setTokenAllowance(1900000000000); | |
} | |
if(counts[msg.sender] >= 216 && levels[msg.sender] == 10) { | |
_resetDripCount(); | |
_setLevel(); | |
_setTime(50 minutes); | |
_setTokenAllowance(2000000000000); | |
} | |
if(counts[msg.sender] >= 240 && levels[msg.sender] == 11) { | |
_resetDripCount(); | |
_setLevel(); | |
_setTime(49 minutes); | |
_setTokenAllowance(2100000000000); | |
} | |
if(counts[msg.sender] >= 264 && levels[msg.sender] == 12) { | |
_resetDripCount(); | |
_setLevel(); | |
_setTime(48 minutes); | |
_setTokenAllowance(2200000000000); | |
} | |
if(counts[msg.sender] >= 288 && levels[msg.sender] == 13) { | |
_resetDripCount(); | |
_setLevel(); | |
_setTime(47 minutes); | |
_setTokenAllowance(2300000000000); | |
} | |
if(counts[msg.sender] >= 312 && levels[msg.sender] == 14) { | |
_resetDripCount(); | |
_setLevel(); | |
_setTime(46 minutes); | |
_setTokenAllowance(2400000000000); | |
} | |
if(counts[msg.sender] >= 336 && levels[msg.sender] == 15) { | |
_resetDripCount(); | |
_setLevel(); | |
_setTime(45 minutes); | |
_setTokenAllowance(2500000000000); | |
} | |
//attemp to send the coin | |
if(token.balanceOf(_wallet) > ammounts[msg.sender]) { | |
//up the take count | |
_upDripCount(); | |
_safeTransferFrom(msg.sender, ammounts[msg.sender]); | |
return true; | |
} else { | |
return false; | |
} | |
} else { | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment