Guest User

Untitled

a guest
Aug 18th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. function Ownable() {
  2. owner = msg.sender;
  3. }
  4.  
  5. modifier onlyOwner {
  6. if (msg.sender != owner) throw;
  7. _;
  8. }
  9.  
  10. function transferOwnership(address newOwner) onlyOwner {
  11. if (newOwner != address(0)) {
  12. owner = newOwner;
  13. }
  14. }
  15.  
  16. if (payment == 0) {
  17. throw;
  18. }
  19.  
  20. if (this.balance < payment) {
  21. throw;
  22. }
  23.  
  24. payments[payee] = 0;
  25.  
  26. if (!payee.send(payment)) {
  27. throw;
  28. }
  29. LogRefundETH(payee,payment);
  30.  
  31. using SafeMath for uint;
  32.  
  33. struct Backer {
  34. uint weiReceived; // Amount of Ether given
  35. uint manusSent;
  36. }
  37.  
  38. /*
  39. * Constants
  40. */
  41. /* Minimum number of manus to sell */
  42. uint public constant MIN_CAP = 2000000000000000000000000;
  43. /* Maximum number of manus to sell */
  44. uint public constant MAX_CAP =4000000000000000000000000 ;
  45.  
  46.  
  47. /*
  48. * Variables
  49. */
  50. /* Manus contract reference */
  51. Manus public manus;
  52. /* Multisig contract that will receive the Ether */
  53. address public multisigEther;
  54. /* Number of Ether received */
  55. uint public etherReceived;
  56. /* Number of manus sent to Ether contributors */
  57. uint public manusSentToEther;
  58.  
  59. /* Backers Ether indexed by their Ethereum address */
  60. mapping(address => Backer) public backers;
  61.  
  62.  
  63. /*
  64. * Modifiers
  65. */
  66. modifier minCapNotReached() {
  67. if (manusSentToEther >= MIN_CAP ) throw;
  68. _;
  69. }
  70.  
  71. /*
  72. * Event
  73. */
  74. event LogReceivedETH(address addr, uint value);
  75. event LogManusEmited(address indexed from, uint amount);
  76.  
  77. /*
  78. * Constructor
  79. */
  80. function Crowdsale(address _manusAddress, address _to) {
  81. manus = Manus(_manusAddress);
  82. multisigEther = _to;
  83. }
  84.  
  85. /*
  86.  
  87.  
  88. /*
  89. * Receives a donation in Ether
  90. */
  91. function receiveETH(address beneficiary) internal {
  92.  
  93. uint manusToSend = bonus(msg.value.div(1 ether));
  94. Backer backer = backers[beneficiary];
  95. manus.transfer(beneficiary, manusToSend); // Transfer ManusToken right now
  96.  
  97. backer.manusSent = backer.manusSent.add(manusToSend);
  98. backer.weiReceived = backer.weiReceived.add(msg.value); // Update the total wei collected during the crowdfunding for this backer
  99.  
  100. etherReceived = etherReceived.add(msg.value); // Update the total wei collected during the crowdfunding
  101. manusSentToEther = manusSentToEther.add(manusToSend);
  102.  
  103. // Send events
  104. LogManusEmited(msg.sender ,manusToSend);
  105. LogReceivedETH(beneficiary, etherReceived);
  106. }
  107.  
  108.  
  109. /*
  110. *Compute the manus bonus according to the investment period
  111. */
  112. function bonus(uint amount) internal constant returns (uint) {
  113. return amount.add(amount.div(5)); // bonus 20%
  114. return amount;
  115. }
  116.  
  117. /*
  118. * Finalize the crowdsale, should be called after the refund period
  119. */
  120.  
  121. /*
  122. * Failsafe drain
  123. */
  124. function drain() onlyOwner {
  125. if (!owner.send(this.balance)) throw;
  126. }
  127.  
  128. /**
  129. * Allow to change the team multisig address in the case of emergency.
  130. */
  131. function setMultisig(address addr) onlyOwner public {
  132. if (addr == address(0)) throw;
  133. multisigEther = addr;
  134. }
  135.  
  136. /**
  137. * Manually back manus owner address.
  138. */
  139. function backManusOwner() onlyOwner public {
  140. manus.transferOwnership(owner);
  141. }
  142.  
  143. /*
  144. * When MIN_CAP is not reach:
  145. * 1) backer call the "approve" function of the manus token contract with the amount of all manus they got in order to be refund
  146. * 2) backer call the "refund" function of the Crowdsale contract with the same amount of manus
  147. * 3) backer call the "withdrawPayments" function of the Crowdsale contract to get a refund in ETH
  148. */
  149. function refund(uint _value) minCapNotReached public {
  150.  
  151. if (_value != backers[msg.sender].manusSent) throw; // compare value from backer balance
  152.  
  153. manus.transferFrom(msg.sender, address(this), _value); // get the token back to the crowdsale contract
  154.  
  155. if (!manus.burn(_value)) throw ; // token sent for refund are burnt
  156.  
  157. uint ETHToSend = backers[msg.sender].weiReceived;
  158. backers[msg.sender].weiReceived=0;
  159.  
  160. if (ETHToSend > 0) {
  161. asyncSend(msg.sender, ETHToSend); // pull payment to get refund in ETH
  162. }
  163. }
Add Comment
Please, Sign In to add comment