daily pastebin goal
0%
SHARE
TWEET

Untitled

a guest Dec 21st, 2018 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. pragma solidity ^0.4.23; // solhint-disable-line
  2.  
  3.  
  4.  
  5. contract PotPotato{
  6.     address public ceoAddress;
  7.     address public hotPotatoHolder;
  8.     address public lastHotPotatoHolder;
  9.     uint256 public lastBidTime;
  10.     uint256 public contestStartTime;
  11.     uint256 public lastPot;
  12.  
  13.     Potato[] public potatoes;
  14.  
  15.     uint256 public BASE_TIME_TO_COOK=5 minutes;//60 seconds;
  16.     uint256 public TIME_MULTIPLIER=2 minutes;//5 seconds;//time per index of potato
  17.     uint256 public TIME_TO_COOK=BASE_TIME_TO_COOK; //this changes
  18.     uint256 public NUM_POTATOES=12;
  19.     uint256 public START_PRICE=100 trx;
  20.     uint256 public CONTEST_INTERVAL=5 minutes;//4 minutes;//1 week
  21.  
  22.     /*** DATATYPES ***/
  23.     struct Potato {
  24.         address owner;
  25.         uint256 price;
  26.     }
  27.  
  28.     /*** CONSTRUCTOR ***/
  29.     function PotPotato() public{
  30.         ceoAddress=msg.sender;
  31.         hotPotatoHolder=ceoAddress;
  32.         contestStartTime=now+90 minutes;//1520799754;//
  33.         for(uint i = 0; i<NUM_POTATOES; i++){
  34.             Potato memory newpotato=Potato({owner:address(this),price: START_PRICE});
  35.             potatoes.push(newpotato);
  36.         }
  37.     }
  38.  
  39.     /*** VIEW FUNCTIONS ***/
  40.     function getOwner(uint index) public view returns(address){
  41.       return potatoes[index].owner;
  42.     }
  43.     function getPrice(uint index) public view returns(uint256){
  44.       return potatoes[index].price;
  45.     }
  46.  
  47.     /*** PUBLIC FUNCTIONS ***/
  48.     function buyPotato(uint256 index) public payable{
  49.         require(block.timestamp>contestStartTime);
  50.         if(_endContestIfNeeded()){
  51.  
  52.         }
  53.         else{
  54.             Potato storage potato=potatoes[index];
  55.             require(msg.value >= potato.price);
  56.             //allow calling transfer() on these addresses without risking re-entrancy attacks
  57.             require(msg.sender != potato.owner);
  58.             //require(msg.sender != ceoAddress);
  59.             uint256 sellingPrice=potato.price;
  60.             uint256 purchaseExcess = SafeMath.sub(msg.value, sellingPrice);
  61.             uint256 payment = uint256(SafeMath.div(SafeMath.mul(sellingPrice, 74), 100));
  62.             uint256 devFee= uint256(SafeMath.div(SafeMath.mul(sellingPrice, 6), 100));
  63.             //20 percent remaining in the contract goes to the pot
  64.             //if the owner is the contract, this is the first purchase, and payment should go to the pot
  65.             if(potato.owner!=address(this)){
  66.                 potato.owner.send(payment);
  67.             }
  68.             ceoAddress.transfer(devFee);
  69.             potato.price= SafeMath.div(SafeMath.mul(sellingPrice, 150), 74);
  70.             potato.owner=msg.sender;//transfer ownership
  71.             hotPotatoHolder=msg.sender;//becomes holder with potential to win the pot
  72.             lastBidTime=block.timestamp;
  73.             TIME_TO_COOK=SafeMath.add(BASE_TIME_TO_COOK,SafeMath.mul(index,TIME_MULTIPLIER)); //pots have times to cook varying from 30-85 minutes
  74.             msg.sender.transfer(purchaseExcess);//returns excess eth
  75.         }
  76.     }
  77.  
  78.     function getBalance() public view returns(uint256){
  79.         return this.balance;
  80.     }
  81.     function timePassed() public view returns(uint256){
  82.         if(lastBidTime==0){
  83.             return 0;
  84.         }
  85.         return SafeMath.sub(block.timestamp,lastBidTime);
  86.     }
  87.     function timeLeftToContestStart() public view returns(uint256){
  88.         if(block.timestamp>contestStartTime){
  89.             return 0;
  90.         }
  91.         return SafeMath.sub(contestStartTime,block.timestamp);
  92.     }
  93.     function timeLeftToCook() public view returns(uint256){
  94.         return SafeMath.sub(TIME_TO_COOK,timePassed());
  95.     }
  96.     function contestOver() public view returns(bool){
  97.         return timePassed()>=TIME_TO_COOK;
  98.     }
  99.  
  100.     /*** PRIVATE FUNCTIONS ***/
  101.     function _endContestIfNeeded() private returns(bool){
  102.         if(timePassed()>=TIME_TO_COOK){
  103.             //contest over, refund anything paid
  104.             msg.sender.transfer(msg.value);
  105.             lastPot=this.balance;
  106.             lastHotPotatoHolder=hotPotatoHolder;
  107.             hotPotatoHolder.send(this.balance);
  108.             hotPotatoHolder=0;
  109.             lastBidTime=0;
  110.             _resetPotatoes();
  111.             _setNewStartTime();
  112.             return true;
  113.         }
  114.         return false;
  115.     }
  116.     function _resetPotatoes() private{
  117.         for(uint i = 0; i<NUM_POTATOES; i++){
  118.             Potato memory newpotato=Potato({owner:address(this),price: START_PRICE});
  119.             potatoes[i]=newpotato;
  120.         }
  121.     }
  122.     function _setNewStartTime() private{
  123.         contestStartTime=now+CONTEST_INTERVAL;
  124.     }
  125. }
  126. library SafeMath {
  127.  
  128.   /**
  129.   * @dev Multiplies two numbers, throws on overflow.
  130.   */
  131.   function mul(uint256 a, uint256 b) internal pure returns (uint256) {
  132.     if (a == 0) {
  133.       return 0;
  134.     }
  135.     uint256 c = a * b;
  136.     assert(c / a == b);
  137.     return c;
  138.   }
  139.  
  140.   /**
  141.   * @dev Integer division of two numbers, truncating the quotient.
  142.   */
  143.   function div(uint256 a, uint256 b) internal pure returns (uint256) {
  144.     // assert(b > 0); // Solidity automatically throws when dividing by 0
  145.     uint256 c = a / b;
  146.     // assert(a == b * c + a % b); // There is no case in which this doesn't hold
  147.     return c;
  148.   }
  149.  
  150.   /**
  151.   * @dev Substracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
  152.   */
  153.   function sub(uint256 a, uint256 b) internal pure returns (uint256) {
  154.     assert(b <= a);
  155.     return a - b;
  156.   }
  157.  
  158.   /**
  159.   * @dev Adds two numbers, throws on overflow.
  160.   */
  161.   function add(uint256 a, uint256 b) internal pure returns (uint256) {
  162.     uint256 c = a + b;
  163.     assert(c >= a);
  164.     return c;
  165.   }
  166. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top