Guest User

Untitled

a guest
Dec 16th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.22 KB | None | 0 0
  1. pragma solidity ^0.4.18;
  2.  
  3. // File: node_modules/zeppelin-solidity/contracts/ownership/Ownable.sol
  4.  
  5. /**
  6. * @title Ownable
  7. * @dev The Ownable contract has an owner address, and provides basic authorization control
  8. * functions, this simplifies the implementation of "user permissions".
  9. */
  10. contract Ownable {
  11. address public owner;
  12.  
  13.  
  14. event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
  15.  
  16.  
  17. /**
  18. * @dev The Ownable constructor sets the original `owner` of the contract to the sender
  19. * account.
  20. */
  21. function Ownable() public {
  22. owner = msg.sender;
  23. }
  24.  
  25.  
  26. /**
  27. * @dev Throws if called by any account other than the owner.
  28. */
  29. modifier onlyOwner() {
  30. require(msg.sender == owner);
  31. _;
  32. }
  33.  
  34.  
  35. /**
  36. * @dev Allows the current owner to transfer control of the contract to a newOwner.
  37. * @param newOwner The address to transfer ownership to.
  38. */
  39. function transferOwnership(address newOwner) public onlyOwner {
  40. require(newOwner != address(0));
  41. OwnershipTransferred(owner, newOwner);
  42. owner = newOwner;
  43. }
  44.  
  45. }
  46.  
  47. // File: node_modules/zeppelin-solidity/contracts/lifecycle/Pausable.sol
  48.  
  49. /**
  50. * @title Pausable
  51. * @dev Base contract which allows children to implement an emergency stop mechanism.
  52. */
  53. contract Pausable is Ownable {
  54. event Pause();
  55. event Unpause();
  56.  
  57. bool public paused = false;
  58.  
  59.  
  60. /**
  61. * @dev Modifier to make a function callable only when the contract is not paused.
  62. */
  63. modifier whenNotPaused() {
  64. require(!paused);
  65. _;
  66. }
  67.  
  68. /**
  69. * @dev Modifier to make a function callable only when the contract is paused.
  70. */
  71. modifier whenPaused() {
  72. require(paused);
  73. _;
  74. }
  75.  
  76. /**
  77. * @dev called by the owner to pause, triggers stopped state
  78. */
  79. function pause() onlyOwner whenNotPaused public {
  80. paused = true;
  81. Pause();
  82. }
  83.  
  84. /**
  85. * @dev called by the owner to unpause, returns to normal state
  86. */
  87. function unpause() onlyOwner whenPaused public {
  88. paused = false;
  89. Unpause();
  90. }
  91. }
  92.  
  93. // File: node_modules/zeppelin-solidity/contracts/math/SafeMath.sol
  94.  
  95. /**
  96. * @title SafeMath
  97. * @dev Math operations with safety checks that throw on error
  98. */
  99. library SafeMath {
  100. function mul(uint256 a, uint256 b) internal pure returns (uint256) {
  101. if (a == 0) {
  102. return 0;
  103. }
  104. uint256 c = a * b;
  105. assert(c / a == b);
  106. return c;
  107. }
  108.  
  109. function div(uint256 a, uint256 b) internal pure returns (uint256) {
  110. // assert(b > 0); // Solidity automatically throws when dividing by 0
  111. uint256 c = a / b;
  112. // assert(a == b * c + a % b); // There is no case in which this doesn't hold
  113. return c;
  114. }
  115.  
  116. function sub(uint256 a, uint256 b) internal pure returns (uint256) {
  117. assert(b <= a);
  118. return a - b;
  119. }
  120.  
  121. function add(uint256 a, uint256 b) internal pure returns (uint256) {
  122. uint256 c = a + b;
  123. assert(c >= a);
  124. return c;
  125. }
  126. }
  127.  
  128. // File: contracts/PreICOComplexCrowdsale.sol
  129.  
  130. /**
  131. * @title PreICOComplexCrowdsale
  132. * @dev This crowdsale contract filters investments made according to:
  133. * - time
  134. * - amount invested (in Wei)
  135. * - eventually a whitelist of addresses?
  136. */
  137. contract PreICOComplexCrowdsale is Pausable {
  138. using SafeMath for uint256;
  139.  
  140. /*// The token being sold
  141. ComplexToken public token;*/
  142.  
  143. // start and end timestamps where investments are allowed (both inclusive)
  144. uint256 public startTime; // Donnerstag morgen
  145. uint256 public endTime; // Freitag abend
  146.  
  147. // address where funds are collected
  148. address public wallet; // TODO wallet
  149.  
  150. // how many token units a buyer gets per wei
  151. uint256 public rate;
  152.  
  153. // amount of raised money in wei
  154. uint256 public weiRaised;
  155.  
  156. uint256 public minWeiInvestment;
  157. uint256 public maxWeiInvestment;
  158.  
  159. uint256 public cap; //
  160.  
  161.  
  162. // TODO add / create the Rates Contract here?
  163. // RatesContract public ratesContract;
  164.  
  165. /**
  166. * event for token purchase logging
  167. * @param purchaser who paid for the tokens
  168. * @param beneficiary who got the tokens
  169. * @param value weis paid for purchase
  170. */
  171. event Investment(address indexed purchaser, address indexed beneficiary, uint256 value); //, uint256 amount); * @param amount amount of tokens purchased
  172.  
  173.  
  174. function PreICOComplexCrowdsale(uint256 _startTime, uint256 _endTime,
  175. uint256 _minWeiInvestment, uint256 _maxWeiInvestment,
  176. uint256 _cap, address _wallet) public {
  177. require(_startTime >= now);
  178. require(_endTime >= _startTime);
  179. require(_minWeiInvestment > 0);
  180. require(_maxWeiInvestment > _minWeiInvestment);
  181. require(_cap >= _maxWeiInvestment);
  182.  
  183. require(_wallet != address(0));
  184.  
  185. cap = _cap;
  186. /*token = createTokenContract();*/
  187.  
  188. /* rates = createRatesContract();*/
  189. startTime = _startTime;
  190. endTime = _endTime;
  191.  
  192. minWeiInvestment = _minWeiInvestment;
  193. maxWeiInvestment = _maxWeiInvestment;
  194. /*rate = _rate;*/
  195. wallet = _wallet;
  196. }
  197.  
  198.  
  199. // fallback function can be used to buy tokens
  200. function () external payable {
  201. buyTokens(msg.sender);
  202. }
  203.  
  204. // low level token purchase function
  205. function buyTokens(address beneficiary) whenNotPaused public payable {
  206. require(beneficiary != address(0));
  207. require(validPurchase());
  208.  
  209. uint256 weiAmount = msg.value;
  210.  
  211. // update state
  212. weiRaised = weiRaised.add(weiAmount);
  213.  
  214. Investment(msg.sender, beneficiary, weiAmount);
  215.  
  216. forwardFunds();
  217. }
  218.  
  219. // send ether to the fund collection wallet
  220. // override to create custom fund forwarding mechanisms
  221. function forwardFunds() internal {
  222. wallet.transfer(msg.value);
  223. // eventually here a refundable wallet
  224. }
  225.  
  226. // overriding Crowdsale#validPurchase to add extra cap logic
  227. // @return true if investors can buy at the moment
  228. function validPurchase() internal view returns (bool) {
  229. if (msg.value < minWeiInvestment || msg.value > maxWeiInvestment) {
  230. return false;
  231. }
  232. bool withinPeriod = now >= startTime && now <= endTime;
  233. bool nonZeroPurchase = msg.value != 0;
  234. bool withinCap = weiRaised.add(msg.value) <= cap;
  235. return withinPeriod && nonZeroPurchase && withinCap;
  236. }
  237.  
  238. // overriding Crowdsale#hasEnded to add cap logic
  239. // @return true if crowdsale event has ended
  240. function hasEnded() public view returns (bool) {
  241. bool capReached = weiRaised >= cap;
  242. return now > endTime || capReached;
  243. }
  244.  
  245. }
Add Comment
Please, Sign In to add comment