pragma solidity ^0.4.25; /* ................&..,&&&&&&.......%&&&%..........&.................... ................#&&&&&...&&&&&&&&&&&&&&&&&&&&&....................... ..............&&&&&..&&&&&&&&&&&&&&&&&&&&&&&&&&&&&................... ..........%.&&&&&.&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&................ ..........&&&&&.&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.............. .........&&&&.&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&............ ........&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.......... .......&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&......... ......&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&........ .....&&&&&&&&&&&&&&&&&&&&(&&&&&&&&&&&&&&&&&/&&&&&&&&&&&&&&&&&&....... ....#&&&&&&&&&&&&&&,&&&&&&&.&&&&&&&&&&&&&.&&&&&&&(.&&&&&&&&&&&&...... ....&&&&&&&&&&&&&&&&&.&&&&&&&..&&&&&&&..&&&&&&&*...&&&&&&&&&&&&&..... ....&&&&&&&&&&&&&&&&&&&/#&&&&&&&..&..&&&&&&&&......&&&&&&&&&&&&&..... ....&&&&&&&&&&&&&&.&&&&&&&.&&&&&&&.&&&&&&&%.......&&&&&&&&&&&&&&&.... ...*&&&&&&&&&&&&&&&&.%&&&&&&.(&&&&&&&&&&........&&&&&&&&&&&&&&&&&.... ....&&&&&&&&&&&&&&&&&&.*&&&&&&&.&&&&&%.......,&&&&&&&&&&&&&&&&&&&.... ....&&&&&&&&&&&&&&&&&&&&..&&&&&&&.(........#&&&&&&&&&&&&&&&&&&&&&.... ....&&&&&&&&&&&&&&&&&&&&&&../&&&&&/......&&&&&&&&&&&&&&&&&&&&&&&&.... ....&&&&&&&&&&&&&&&&&&&&&&&&(.,&&&/....&&&&&&&&&&&&&&&&&&&&&&&&&&.... .....&&&&&&&&&&&&&&&&&&&&&&&&,,&&&/....&&&&&&&&&&&&&&&&&&&&&&&&&%.... ......&&&&&&&&&&&&&&&&&&&&&&&*,&&&/....&&&&&&&&&&&&&&&&&&&&&&&&&..... .......&&&&&&&&&&&&&&&&&&&&&&%,&&&*....&&&&&&&&&&&&&&&&&&&&&&&&*..... ....,...&&&&&&&&&&&&&&&&&&&&&&,&&&*....&&&&&&&&&&&&&&&&&&&&&&&&...... .........&&&&&&&&&&&&&&&&&&&&&,&&&*...,&&&&&&&&&&&&&&&&&&&&&&&....... ..........&&&&&&&&&&&&&&&&&&&&,&&&*.../&&&&&&&&&&&&&&&&&,&&&&........ ............&&&&&&&&&&&&&&&&&&,&&&*...&&&&&&&&&&&&&&&&(&&&&%......... ..............&&&&&&&&&&&&&&&&&&&&*...&&&&&&&&&&&&&&(&&&&&........... ...........&....&&&&&&&&&&&&&&&&&&*...&&&&&&&&&&&&.&&&&&............. ...................%&&&&&&&&&&&&&&*..%&&&&&&&&&..&&&&&............... ................&(......&&&&&&&&&&/&&&&&&&(...&&&&................. */ interface tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) external; } contract Cyle { /***************************************************************************************/ /***************************************************************************************/ /********************************* VARIABLES START *************************************/ /***************************************************************************************/ /***************************************************************************************/ string name; string symbol; uint8 decimals = 18; uint256 totalSupply; uint256 cyleGenesisBlock; uint256 lastBlock; uint256 miningReward; uint256 publicMineSupply; uint256 masternodeSupply; uint256 smallReward = 0; uint256 bigReward = 0; uint256 masternodeRateNumerator; uint256 masternodeRateDenominator; uint256 staticFinney = 1 finney; uint256 requiredAmountForMasternode = 100* 10 ** uint256(decimals); uint256 public maxAmountForMasternode = 10000* 10 ** uint256(decimals); uint256 blocksBetweenReward; address owner; address cyle = 0x0bAFb154b0E48BC9C483B92A0Cf00Cfb3d132EC7; uint256 blacklistedAmountOfBlocks = 5760; /***************************************************************************************/ /***************************************************************************************/ /********************************** VARIABLES END **************************************/ /***************************************************************************************/ /***************************************************************************************/ /***************************************************************************************/ /***************************************************************************************/ /********************************** MAPPINGS START *************************************/ /***************************************************************************************/ /***************************************************************************************/ mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; mapping (uint256 => bool) public blockHasBeenMined; mapping (address => bool) public masternodeCheck; mapping (address => uint256) public registeredAtBlock; mapping (address => uint256) public lastTimeRewarded; mapping (address => bool) public addressHasParkedToken; mapping (address => uint256) public lockedAmount; mapping (address => uint256) public blacklistedTillBlock; /***************************************************************************************/ /***************************************************************************************/ /********************************** MAPPINGS END ***************************************/ /***************************************************************************************/ /***************************************************************************************/ event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); event Burn(address indexed from, uint256 value); event ValueCheck(uint256 value); /***************************************************************************************/ /***************************************************************************************/ /********************************** MODIFIERS START ************************************/ /************************ Routines that can be extended by methods *********************/ /***************************************************************************************/ /***************************************************************************************/ /* Checks if the sender of a transaction is the owner of the contract */ modifier onlyOwner { require(msg.sender == owner); _; } /* Checks if the sender of a transaction is a registered masternode*/ modifier onlyMasterNode { require(masternodeCheck[msg.sender]); _; } /* Checks if the remaining supply for claiming a masternode interest is high enough */ modifier remainingNodeSupplyChecky{ require(masternodeSupply > 0); _; } /* Checks if the remaining supply for a public mining process is high enough */ modifier remainingMineSupplyCheck{ require(publicMineSupply > miningReward); _; } /* Crosschecks if the sender is NOT a masternode and if the balance is high enough for becoming a masternode */ modifier nodePotentialCheck{ require(!masternodeCheck[msg.sender]); require(balanceOf[msg.sender] > requiredAmountForMasternode); _; } /*Checks if the message sender is blacklisted for the minign process*/ modifier checkForMiningBlacklisting{ require(getCurrentCyleBlock() > blacklistedTillBlock[msg.sender]); _; } /***************************************************************************************/ /***************************************************************************************/ /*********************************** MODIFIERS END *************************************/ /***************************************************************************************/ /***************************************************************************************/ /***************************************************************************************/ /***************************************************************************************/ /********************************* CONSTRUCTOR START ***********************************/ /***************************************************************************************/ /***************************************************************************************/ constructor() public { totalSupply = 450000000 * 10 ** uint256(decimals); // Update total supply with the decimal amount balanceOf[this] = totalSupply; // Give the creator all initial tokens name = "Cyle"; // Set the name for display purposes symbol = "CYLE"; // Set the symbol for display purposes cyleGenesisBlock = block.number; lastBlock = block.number; publicMineSupply = SafeMath.div(totalSupply,2); masternodeSupply = SafeMath.sub(totalSupply, publicMineSupply); owner = msg.sender; masternodeRateNumerator = 6081; masternodeRateDenominator = 500000; miningReward = 50 * 10 ** uint256(decimals); blocksBetweenReward = 40320; } /***************************************************************************************/ /***************************************************************************************/ /*********************************** CONSTRUCTOR END ***********************************/ /***************************************************************************************/ /***************************************************************************************/ /* Getter for the static finney variable. Used to convert integers to ETH currency */ function getStaticFinney() public view returns (uint){ return staticFinney; } /***************************************************************************************/ /***************************************************************************************/ /************************************ MINING START *************************************/ /***************************************************************************************/ /***************************************************************************************/ /*Calculates the small mining reward, aka the CYLE fee for each mining process - currently 70%*/ /*SAFEMATH FUNCTIONS CAN BE FOUND AT THE END OF TEH CONTRACT*/ function calcSmallReward(uint256 _miningReward) private pure returns(uint256 _reward){ _reward=SafeMath.div(SafeMath.mul(_miningReward, 20),100); return _reward; } /*Calculates the mining reward for the user - currently 80%*/ function calcBigReward(uint256 _miningReward) private pure returns(uint256 _reward){ _reward=SafeMath.div(SafeMath.mul(_miningReward, 80),100); return _reward; } /*Public mining that rewards the caller with token / makes use of teh modifier remainingMineSupplyCheck*/ function publicMine() public payable remainingMineSupplyCheck checkForMiningBlacklisting{ /*Make sure that the current block has not been mined. If so revert the trasnaction*/ require(!blockHasBeenMined[getCurrentCyleBlock()]); /*get the current rewards for this transaction*/ miningReward = getCurrentMiningReward(); smallReward = calcSmallReward(miningReward); bigReward = calcBigReward(miningReward); /*transfer the bigreward (80%) from this contract to the message sender. 20% to the specified cyle address*/ this.transfer(msg.sender, bigReward); this.transfer(cyle, smallReward); /*adjust the remaining supply that can be claimed by mining*/ publicMineSupply = SafeMath.sub(publicMineSupply,miningReward); /*mark the block as mined, so no other transaction can go through on this block*/ blockHasBeenMined[getCurrentCyleBlock()] = true; blacklistedTillBlock[msg.sender] = SafeMath.add(getCurrentCyleBlock(), blacklistedAmountOfBlocks); } /*Getter for the remainingMiningsupply*/ function getRemainingPublicMineSupply() public view returns (uint256 _amount){ return publicMineSupply; } /*Getter for the remaining Masternode Supply*/ function getRemainingMasternodeSupply() public view returns (uint256 _amount){ return masternodeSupply; } function getBlacklistblockForUser() public view returns(uint256){ return blacklistedTillBlock[msg.sender]; } /***************************************************************************************/ /***************************************************************************************/ /************************************ MINING START *************************************/ /***************************************************************************************/ /***************************************************************************************/ /***************************************************************************************/ /***************************************************************************************/ /********************************** MASTERNODE START ***********************************/ /***************************************************************************************/ /***************************************************************************************/ /*Function for registering a masternode which makes use of the midifier nodePotentialCheck*/ function registerMasternode() public nodePotentialCheck{ /*Check if sender is not already a masternode. If he is, then revert the trasnaction*/ require(!masternodeCheck[msg.sender]); /*Get the current block of the Cyle contract*/ uint256 currentCyleBlock = getCurrentCyleBlock(); /*Mark the message sender as a masternode (true), save the block the node has been registered, and save the last time the address has claimed the interest (lastTimeRewarded)*/ masternodeCheck[msg.sender] = true; registeredAtBlock[msg.sender] = currentCyleBlock; lastTimeRewarded[msg.sender] = currentCyleBlock; } /*Enables the Masternode owner to lock a given amount for his masternode he will get interest for.*/ function lockAmountForMasternode(uint256 _amount) public onlyMasterNode{ /*Check if balance of the message sender is greater or same as the amount he wants to lock*/ require(SafeMath.sub(balanceOf[msg.sender], lockedAmount[msg.sender]) >= _amount); require(_amount <= maxAmountForMasternode && SafeMath.add(lockedAmount[msg.sender],_amount)<= maxAmountForMasternode); /*Mark the address, that there have been token parked/locked and what amount has been locked*/ addressHasParkedToken[msg.sender] = true; if(lockedAmount[msg.sender] == 0){ lastTimeRewarded[msg.sender] = getCurrentCyleBlock(); } lockedAmount[msg.sender] = SafeMath.add(lockedAmount[msg.sender],_amount); } /*Unlock the whole locked amount of the senders address*/ function unlockAmountFromMasterNode() public onlyMasterNode returns(bool){ /*Remove the address of the sender from the mapping of masternodes with parked supply and adjust the locked amount of token*/ addressHasParkedToken[msg.sender] = false; lockedAmount[msg.sender] = 0; return true; } /*Function for claiming the interest for a master node with modifiers onlyMasterNode and remainingNodeSupplyChecky*/ function claimMasternodeReward() public onlyMasterNode remainingNodeSupplyChecky{ // Check if the message sender has parked tokens he can get interest for. require(addressHasParkedToken[msg.sender]); // calculate interest uint256 interest = interestToClaim(msg.sender); /*transfer the bigreward (80%) from this contract to the message sender. 20% to the specified cyle address*/ this.transfer(msg.sender, calcBigReward(interest)); this.transfer(cyle, calcSmallReward(interest)); // set the last time the message sender got his interest to the current block lastTimeRewarded[msg.sender] = getCurrentCyleBlock(); // adjust the remaining supply which can be claimed by masternodes masternodeSupply = SafeMath.sub(masternodeSupply, interest); } // Gives back the interest a given address can claim function interestToClaim(address _owner) public view returns(uint256 _amountToClaim){ // Calculate the amount of blocks the message sender must get interest for uint256 blockstopay = SafeMath.div(SafeMath.sub(getCurrentCyleBlock(),lastTimeRewarded[_owner]), blocksBetweenReward); // Calculate the interest for the masternode and return it _amountToClaim = SafeMath.mul((SafeMath.div(SafeMath.mul(getCurrentMasternodeNumerator(), lockedAmount[_owner]), getCurrentMasternodeDenominator())), blockstopay); return _amountToClaim; } // Calculate the current value of a masternode consisting of locked amount and possible interest function getCurrentPossibleAmountOfAddress(address _owner) public view returns(uint256 _amount){ if(!addressHasParkedToken[_owner]){ _amount = 0; } else { _amount = SafeMath.add(lockedAmount[_owner], interestToClaim(_owner)); return _amount; } } // Get the last time an address has been rewarded its interest function getLastTimeRewarded(address _owner) public view returns (uint256 _block){ return lastTimeRewarded[_owner]; } // return the state of a given address and checks if it is a masternode (yes = true) function checkForMasterNode(address _owner) public view returns (bool _state){ _state = masternodeCheck[_owner]; return _state; } // Allows the owner of the contract to adjust the Cyle blocks between possible mining trys function adjustBlocksBetweenReward(uint256 _newBlocksBetweenReward) public onlyOwner { blocksBetweenReward = _newBlocksBetweenReward; } /***************************************************************************************/ /***************************************************************************************/ /********************************** MASTERNODE END *************************************/ /***************************************************************************************/ /***************************************************************************************/ /** * Internal transfer, only can be called by this contract */ function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != 0x0); // Check if the sender has enough require(balanceOf[_from] >= _value); // Check for overflows require(balanceOf[_to] + _value >= balanceOf[_to]); // Save this for an assertion in the future uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; emit Transfer(_from, _to, _value); // Asserts are used to use static analysis to find bugs in your code. They should never fail assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } /** * Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */ function transfer(address _to, uint256 _value) public returns (bool success) { if(masternodeCheck[msg.sender]){ uint256 remain = SafeMath.sub(balanceOf[msg.sender], _value); require(remain > lockedAmount[msg.sender]); if(remain < requiredAmountForMasternode){ masternodeCheck[msg.sender] = false; } } _transfer(msg.sender, _to, _value); return true; } /** * Transfer tokens from other address * * Send `_value` tokens to `_to` on behalf of `_from` * * @param _from The address of the sender * @param _to The address of the recipient * @param _value the amount to send */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { require(_value <= allowance[_from][msg.sender]); // Check allowance allowance[_from][msg.sender] -= _value; _transfer(_from, _to, _value); return true; } /** * Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens on your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */ function approve(address _spender, uint256 _value) public returns (bool success) { allowance[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } /** * Set allowance for other address and notify * * Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it * * @param _spender The address authorized to spend * @param _value the max amount they can spend * @param _extraData some extra information to send to the approved contract */ function approveAndCall(address _spender, uint256 _value, bytes _extraData) public returns (bool success) { tokenRecipient spender = tokenRecipient(_spender); if (approve(_spender, _value)) { spender.receiveApproval(msg.sender, _value, this, _extraData); return true; } } /** * Destroy tokens * * Remove `_value` tokens from the system irreversibly * * @param _value the amount of money to burn */ function burn(uint256 _value) public returns (bool success) { require(balanceOf[msg.sender] >= _value); // Check if the sender has enough balanceOf[msg.sender] -= _value; // Subtract from the sender totalSupply -= _value; // Updates totalSupply emit Burn(msg.sender, _value); return true; } /** * Destroy tokens from other account * * Remove `_value` tokens from the system irreversibly on behalf of `_from`. * * @param _from the address of the sender * @param _value the amount of money to burn */ function burnFrom(address _from, uint256 _value) public returns (bool success) { require(balanceOf[_from] >= _value); // Check if the targeted balance is enough require(_value <= allowance[_from][msg.sender]); // Check allowance balanceOf[_from] -= _value; // Subtract from the targeted balance allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance totalSupply -= _value; // Update totalSupply emit Burn(_from, _value); return true; } //Get the current block of teh ether mainnet chain function getCurrentEthBlock() private view returns (uint256 blockAmount){ return block.number; } // calculate the current Cyle Block function getCurrentCyleBlock() public view returns (uint256){ uint256 eth = getCurrentEthBlock(); uint256 cyleBlock = SafeMath.sub(eth, cyleGenesisBlock); return cyleBlock; } // get the current reward for a mining function call function getCurrentMiningReward() public view returns(uint256 _miningReward){ return miningReward; } // get the current reward for a masternode function getCurrentMasterNodeReward() public view returns(uint256 _miningReward){ return SafeMath.mul(SafeMath.div(masternodeRateNumerator,masternodeRateDenominator),100); } // get the current Numerator for calculating the masternode reward function getCurrentMasternodeNumerator() public view returns(uint256 _numerator){ return masternodeRateNumerator; } // get the current Denominator for calculating the masternode reward function getCurrentMasternodeDenominator() public view returns(uint256 _denominator){ return masternodeRateDenominator; } // gets back the total supply function getTotalSupply() public view returns (uint256 _totalSupply){ return totalSupply; } function getCurrentLockedAmount() public view returns (uint256 _amount){ return lockedAmount[msg.sender]; } // gets back the available balance that is not locked for the user function getCurrentUnlockedAmount() public view returns (uint256 _unlockedAmount){ return SafeMath.sub(balanceOf[msg.sender], lockedAmount[msg.sender]); } function getMasternodeRequiredAmount() public view returns(uint256 _reqAmount){ return requiredAmountForMasternode; } // Function for the owner of the contract to adjust the rewards according to the current block of cyle function adjustMiningRewards() public onlyOwner{ uint256 _remainingMiningSupply = getRemainingPublicMineSupply(); if(_remainingMiningSupply < 175000000000000000000000000 && _remainingMiningSupply > 131250000000000000000000000){ miningReward = 25000000000000000000; } if(_remainingMiningSupply < 131250000000000000000000000 && _remainingMiningSupply > 93750000000000000000000000){ miningReward = 12500000000000000000; } if(_remainingMiningSupply < 93750000000000000000000000 && _remainingMiningSupply > 62500000000000000000000000){ miningReward = 6250000000000000000; } if(_remainingMiningSupply < 62500000000000000000000000 && _remainingMiningSupply > 37500000000000000000000000){ miningReward = 3125000000000000000; } if(_remainingMiningSupply < 37500000000000000000000000 && _remainingMiningSupply > 18750000000000000000000000){ miningReward = 1562500000000000000; } if(_remainingMiningSupply < 18750000000000000000000000 && _remainingMiningSupply > 12500000000000000000000000){ miningReward = 800000000000000000; } if(_remainingMiningSupply < 12500000000000000000000000 && _remainingMiningSupply > 6250000000000000000000000){ miningReward = 400000000000000000; } if(_remainingMiningSupply < 6250000000000000000000000){ miningReward = 200000000000000000; } } function adjustMasternodeRewards() public onlyOwner{ uint256 _remainingStakeSupply = getRemainingMasternodeSupply(); if(_remainingStakeSupply < 218750000000000000000000000 && _remainingStakeSupply > 206250000000000000000000000){ masternodeRateNumerator=5410; masternodeRateDenominator=500000; } if(_remainingStakeSupply < 206250000000000000000000000 && _remainingStakeSupply > 187500000000000000000000000){ masternodeRateNumerator=469; masternodeRateDenominator=50000; } if(_remainingStakeSupply < 187500000000000000000000000 && _remainingStakeSupply > 162500000000000000000000000){ masternodeRateNumerator=783; masternodeRateDenominator=100000; } if(_remainingStakeSupply < 162500000000000000000000000 && _remainingStakeSupply > 131250000000000000000000000){ masternodeRateNumerator=307; masternodeRateDenominator=50000; } if(_remainingStakeSupply < 131250000000000000000000000 && _remainingStakeSupply > 93750000000000000000000000){ masternodeRateNumerator=43; masternodeRateDenominator=10000; } if(_remainingStakeSupply < 93750000000000000000000000 && _remainingStakeSupply > 50000000000000000000000000){ masternodeRateNumerator=269; masternodeRateDenominator=100000; } if(_remainingStakeSupply < 50000000000000000000000000){ masternodeRateNumerator=183; masternodeRateDenominator=100000; } } } /*********************************/ /*********** CALC LIB ************/ /*********************************/ library SafeMath { function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0; } uint256 c = a * b; assert(c / a == b); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { // assert(b > 0); // Solidity automatically throws when dividing by 0 uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; assert(c >= a); return c; } }
0.4.18