Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.15 KB | None | 0 0
  1. pragma solidity ^0.4.2;
  2. contract owned {
  3. address public owner;
  4. function owned() {
  5. owner = msg.sender;
  6. }
  7. function changeOwner(address newOwner) onlyowner {
  8. owner = newOwner;
  9. }
  10. modifier onlyowner() {
  11. if (msg.sender==owner) _;
  12. }
  13. }
  14. contract tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData); }
  15. contract CSToken is owned {
  16. /* Public variables of the token */
  17. string public standard = 'Token 0.1';
  18. string public name;
  19. string public symbol;
  20. uint8 public decimals;
  21. uint256 public totalSupply;
  22. /* This creates an array with all balances */
  23. mapping (address => uint256) public balanceOf;
  24. mapping (address => mapping (address => uint256)) public allowance;
  25. /* This generates a public event on the blockchain that will notify clients */
  26. event Transfer(address indexed from, address indexed to, uint256 value);
  27. /* Initializes contract with initial supply tokens to the creator of the contract */
  28. function CSToken(
  29. uint256 initialSupply,
  30. string tokenName,
  31. uint8 decimalUnits,
  32. string tokenSymbol
  33. ) {
  34. owner = msg.sender;
  35. balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens
  36. totalSupply = initialSupply; // Update total supply
  37. name = tokenName; // Set the name for display purposes
  38. symbol = tokenSymbol; // Set the symbol for display purposes
  39. decimals = decimalUnits; // Amount of decimals for display purposes
  40. }
  41. /* Send coins */
  42. function transfer(address _to, uint256 _value) {
  43. if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
  44. if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
  45. balanceOf[msg.sender] -= _value; // Subtract from the sender
  46. balanceOf[_to] += _value; // Add the same to the recipient
  47. Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
  48. }
  49. function mintToken(address target, uint256 mintedAmount) onlyowner {
  50. balanceOf[target] += mintedAmount;
  51. totalSupply += mintedAmount;
  52. Transfer(0, owner, mintedAmount);
  53. Transfer(owner, target, mintedAmount);
  54. }
  55. /* Allow another contract to spend some tokens in your behalf */
  56. function approve(address _spender, uint256 _value)
  57. returns (bool success) {
  58. allowance[msg.sender][_spender] = _value;
  59. return true;
  60. }
  61. /* Approve and then comunicate the approved contract in a single tx */
  62. function approveAndCall(address _spender, uint256 _value, bytes _extraData)
  63. returns (bool success) {
  64. tokenRecipient spender = tokenRecipient(_spender);
  65. if (approve(_spender, _value)) {
  66. spender.receiveApproval(msg.sender, _value, this, _extraData);
  67. return true;
  68. }
  69. }
  70. /* A contract attempts to get the coins */
  71. function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
  72. if (balanceOf[_from] < _value) throw; // Check if the sender has enough
  73. if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
  74. if (_value > allowance[_from][msg.sender]) throw; // Check allowance
  75. balanceOf[_from] -= _value; // Subtract from the sender
  76. balanceOf[_to] += _value; // Add the same to the recipient
  77. allowance[_from][msg.sender] -= _value;
  78. Transfer(_from, _to, _value);
  79. return true;
  80. }
  81. /* This unnamed function is called whenever someone tries to send ether to it */
  82. function () {
  83. throw; // Prevents accidental sending of ether
  84. }
  85. }
  86. contract Crowdsale is owned{
  87. uint public start = 1498651200;
  88. uint public currentStage = 0;
  89. bool public crowdsaleStarted = false;
  90. uint public currentStageStart;
  91. uint[] public prices;
  92. uint[] public tresholds;
  93. address public bounties;
  94. uint public totalCollected;
  95. uint public deadline;
  96. uint public presaleDeadline;
  97. uint public tokensRaised;
  98.  
  99. uint constant presaleDuration = 19 days;
  100. uint constant saleDuration = 29 days;
  101. uint tokenMultiplier = 10;
  102.  
  103.  
  104. CSToken public tokenReward;
  105. mapping(address => uint256) public balanceOf;
  106. mapping(address => address) public presaleContracts;
  107. mapping(address => uint256) public presaleBalance;
  108. event GoalReached(address beneficiary, uint totalCollected);
  109. event FundTransfer(address backer, uint amount, bool isContribution);
  110. event NewStage (uint time, uint stage);
  111.  
  112.  
  113. modifier afterDeadline() { if (now < deadline) throw; _; }
  114. modifier beforeDeadline() { if (now >= deadline) throw; _; }
  115. modifier onPresale() { if (now >= presaleDeadline) throw; _; }
  116. modifier afterPresale() { if (now < presaleDeadline) throw; _; }
  117.  
  118. function Crowdsale(
  119. address _bounties,
  120. uint premine //Note that premine shouldn't ignore precision (1 will equal to 0.00000001)
  121. ) {
  122. tokenReward = new CSToken(0, 'MyBit Token', 8, 'MyB');
  123. tokenMultiplier = tokenMultiplier**tokenReward.decimals();
  124. tokenReward.mintToken(_bounties, premine);
  125. presaleDeadline = start + presaleDuration;
  126. deadline = start + presaleDuration + saleDuration;
  127. tresholds.push(1250000 * tokenMultiplier);
  128. tresholds.push(3000000 * tokenMultiplier);
  129. tresholds.push(2**256 - 1);
  130. prices.push(7500 szabo / tokenMultiplier);
  131. prices.push(10 finney / tokenMultiplier);
  132. prices.push(2**256 - 1);
  133.  
  134.  
  135. bounties = _bounties;
  136.  
  137. }
  138.  
  139.  
  140. function mint(uint amount, uint tokens, address sender) internal {
  141. balanceOf[sender] += amount;
  142. tokensRaised += tokens;
  143. totalCollected += amount;
  144. tokenReward.mintToken(sender, tokens);
  145. tokenReward.mintToken(owner, tokens * 1333333 / 10000000);
  146. tokenReward.mintToken(bounties, tokens * 1666667 / 10000000);
  147. FundTransfer(sender, amount, true);
  148. }
  149.  
  150. function processPayment(address from, uint amount) internal beforeDeadline
  151. {
  152. FundTransfer(from, amount, false);
  153. uint price = prices[currentStage];
  154. uint256 tokenAmount = amount / price;
  155. if (tokensRaised + tokenAmount > tresholds[currentStage])
  156. {
  157. uint256 currentTokens = tresholds[currentStage] - tokensRaised;
  158. uint256 currentAmount = currentTokens * price;
  159. mint(currentAmount, currentTokens, from);
  160. currentStage++;
  161. NewStage(now, currentStage);
  162. processPayment(from, amount - currentAmount);
  163. return;
  164. }
  165. mint(amount, tokenAmount, from);
  166. uint256 change = amount - tokenAmount * price;
  167. if(change > 0)
  168. {
  169. totalCollected -= change;
  170. balanceOf[from] -= change;
  171. if (!from.send(change)){
  172. throw;
  173. }
  174. }
  175. }
  176. function () payable beforeDeadline {
  177. if(now < start) throw;
  178. if(currentStage > 1) throw;
  179. if (crowdsaleStarted){
  180. processPayment(msg.sender, msg.value);
  181. } else {
  182. if (now > presaleDeadline)
  183. {
  184. crowdsaleStarted = true;
  185. } else {
  186. if (msg.value < 1 ether) throw;
  187. }
  188. processPayment(msg.sender, msg.value);
  189. }
  190. }
  191. function safeWithdrawal() afterDeadline {
  192. if (bounties == msg.sender) {
  193. if (!bounties.send(totalCollected)) {
  194. throw;
  195. }
  196. }
  197. }
  198. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement