Guest User

Untitled

a guest
Apr 19th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.80 KB | None | 0 0
  1. pragma solidity ^0.4.21;
  2.  
  3.  
  4. contract Ownable {
  5. address public owner;
  6. event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
  7. function constuctor() public {
  8. owner = msg.sender;
  9. }
  10. modifier onlyOwner() {
  11. require(msg.sender == owner);
  12. _;
  13. }
  14. function transferOwnership(address newOwner) public onlyOwner {
  15. require(newOwner != address(0));
  16. emit OwnershipTransferred(owner, newOwner);
  17. owner = newOwner;
  18. }
  19. }
  20.  
  21. // ######################################################################
  22.  
  23. library SafeMath {
  24. function mul(uint256 a, uint256 b) internal pure returns (uint256) {
  25. if (a == 0) {
  26. return 0;
  27. }
  28. uint256 c = a * b;
  29. assert(c / a == b);
  30. return c;
  31. }
  32. function div(uint256 a, uint256 b) internal pure returns (uint256) {
  33. uint256 c = a / b;
  34. return c;
  35. }
  36. function sub(uint256 a, uint256 b) internal pure returns (uint256) {
  37. assert(b <= a);
  38. return a - b;
  39. }
  40. function add(uint256 a, uint256 b) internal pure returns (uint256) {
  41. uint256 c = a + b;
  42. assert(c >= a);
  43. return c;
  44. }
  45. }
  46.  
  47. // ######################################################################
  48.  
  49. contract ERC20Basic {
  50. function totalSupply() public view returns (uint256);
  51. function balanceOf(address who) public view returns (uint256);
  52. function transfer(address to, uint256 value) public returns (bool);
  53. event Transfer(address indexed from, address indexed to, uint256 value);
  54. }
  55.  
  56. // ######################################################################
  57.  
  58. contract BasicToken is ERC20Basic {
  59. using SafeMath for uint256;
  60.  
  61. mapping(address => uint256) balances;
  62.  
  63. uint256 totalSupply_;
  64.  
  65. function totalSupply() public view returns (uint256) {
  66. return totalSupply_;
  67. }
  68.  
  69. function transfer(address _to, uint256 _value) public returns (bool) {
  70. require(_to != address(0));
  71. require(_value <= balances[msg.sender]);
  72.  
  73. // SafeMath.sub will throw if there is not enough balance.
  74. balances[msg.sender] = balances[msg.sender].sub(_value);
  75. balances[_to] = balances[_to].add(_value);
  76. emit Transfer(msg.sender, _to, _value);
  77. return true;
  78. }
  79.  
  80. function balanceOf(address _owner) public view returns (uint256 balance) {
  81. return balances[_owner];
  82. }
  83.  
  84. }
  85.  
  86. // ######################################################################
  87.  
  88. contract ERC20 is ERC20Basic {
  89. function allowance(address owner, address spender) public view returns (uint256);
  90. function transferFrom(address from, address to, uint256 value) public returns (bool);
  91. function approve(address spender, uint256 value) public returns (bool);
  92. event Approval(address indexed owner, address indexed spender, uint256 value);
  93. }
  94.  
  95. // ######################################################################
  96.  
  97. contract StandardToken is ERC20, BasicToken {
  98.  
  99. mapping (address => mapping (address => uint256)) internal allowed;
  100.  
  101. function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
  102. require(_to != address(0));
  103. require(_value <= balances[_from]);
  104. require(_value <= allowed[_from][msg.sender]);
  105.  
  106. balances[_from] = balances[_from].sub(_value);
  107. balances[_to] = balances[_to].add(_value);
  108. allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
  109. emit Transfer(_from, _to, _value);
  110. return true;
  111. }
  112.  
  113. function approve(address _spender, uint256 _value) public returns (bool) {
  114. allowed[msg.sender][_spender] = _value;
  115. emit Approval(msg.sender, _spender, _value);
  116. return true;
  117. }
  118.  
  119. function allowance(address _owner, address _spender) public view returns (uint256) {
  120. return allowed[_owner][_spender];
  121. }
  122.  
  123. function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
  124. allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
  125. emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
  126. return true;
  127. }
  128.  
  129. function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
  130. uint oldValue = allowed[msg.sender][_spender];
  131. if (_subtractedValue > oldValue) {
  132. allowed[msg.sender][_spender] = 0;
  133. } else {
  134. allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
  135. }
  136. emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
  137. return true;
  138. }
  139.  
  140. }
  141.  
  142. // ######################################################################
  143.  
  144. contract DeveloperToken is StandardToken {
  145. string public constant name = "DeveloperToken";
  146. string public constant symbol = "DEV";
  147. uint256 public constant decimals = 18;
  148. }
  149.  
  150. // ######################################################################
  151.  
  152. contract Crowdsale is Ownable {
  153. using SafeMath for uint256;
  154.  
  155. // ============= Token Distribution ================
  156. uint256 public maxTokens = 100000000 *(10 ** 18);
  157. uint256 public tokensForEcosystem = 80000000 *(10 ** 18);
  158. uint256 public tokensForBounty = 4000000 *(10 ** 18);
  159. uint256 public totalTokensForSale = 15000000 *(10 ** 18);
  160. uint256 public tokenForAirdrop = 1000000 *(10 ** 18);
  161.  
  162. ERC20 public token;
  163.  
  164. address public wallet;
  165.  
  166. uint256 public rate;
  167.  
  168. uint256 public weiRaised;
  169.  
  170. uint256 public cap;
  171. uint256 public goal;
  172.  
  173. // start and end timestamps where investments are allowed (both inclusive)
  174. uint256 public startTime;
  175. uint256 public endTime;
  176.  
  177. bool public mintingFinished = false;
  178.  
  179. mapping(address => uint256) balances;
  180.  
  181. event Mint(address indexed to, uint256 amount);
  182. event MintFinished();
  183. event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount);
  184.  
  185. function constuctor() public {
  186. rate = 1000;
  187. wallet = msg.sender;
  188. token = new DeveloperToken();
  189. startTime = 1527186660000; // new Date('05/25/2018 00:01').getTime();
  190. endTime = 1529951340000; // new Date('06/25/2018 23:59').getTime();
  191. cap = 42500 *(10 ** 18);
  192. goal = 7500 *(10 ** 18);
  193. }
  194.  
  195. function () external payable {
  196. uint256 tokensThatWillBeMintedAfterPurchase = msg.value.mul(rate);
  197. require(token.totalSupply() + tokensThatWillBeMintedAfterPurchase < totalTokensForSale);
  198. buyTokens(msg.sender);
  199. }
  200.  
  201. // ====================== Crowdsale Price Management =================
  202. function setCrowdsalePrice() public onlyOwner {
  203. if (weiRaised <= 2500000 *(10 ** 18)) {
  204. setCurrentRate(1000);
  205. } else if (weiRaised <= 5000000 *(10 ** 18)) {
  206. setCurrentRate(500);
  207. } else if (weiRaised <= 10000000 *(10 ** 18)) {
  208. setCurrentRate(333);
  209. } else if (weiRaised <= 15000000 *(10 ** 18)) {
  210. setCurrentRate(250);
  211. }
  212. }
  213.  
  214. // Change the current rate
  215. function setCurrentRate(uint256 _rate) private {
  216. rate = _rate;
  217. }
  218.  
  219. function buyTokens(address _beneficiary) public payable {
  220. require(validPurchase());
  221.  
  222. uint256 weiAmount = msg.value;
  223.  
  224. // calculate token amount to be created
  225. uint256 tokens = _getTokenAmount(weiAmount);
  226.  
  227. // update state
  228. weiRaised = weiRaised.add(weiAmount);
  229.  
  230. _processPurchase(_beneficiary, tokens);
  231. emit TokenPurchase(msg.sender, _beneficiary, weiAmount, tokens);
  232.  
  233. _forwardFunds();
  234. }
  235.  
  236. function _deliverTokens(address _beneficiary, uint256 _tokenAmount) internal {
  237. token.transfer(_beneficiary, _tokenAmount);
  238.  
  239. }
  240.  
  241. function _processPurchase(address _beneficiary, uint256 _tokenAmount) internal {
  242. _deliverTokens(_beneficiary, _tokenAmount);
  243. }
  244.  
  245. function _getTokenAmount(uint256 _weiAmount) internal view returns (uint256) {
  246. return _weiAmount.mul(rate);
  247. }
  248.  
  249. function _forwardFunds() internal {
  250. token.totalSupply() + msg.value.mul(rate);
  251. wallet.transfer(msg.value);
  252. }
  253.  
  254. // Finish: Mint Extra Tokens as needed before finalizing the Crowdsale.
  255. function finish(address _airdrop, address _ecosystemFund, address _bountyFund) public onlyOwner {
  256. require(!mintingFinished);
  257. require(hasEnded());
  258. uint256 alreadyMinted = token.totalSupply();
  259. require(alreadyMinted < maxTokens);
  260.  
  261. uint256 unsoldTokens = totalTokensForSale - alreadyMinted;
  262. if (unsoldTokens > 0) {
  263. tokensForEcosystem = tokensForEcosystem + unsoldTokens;
  264. }
  265.  
  266. token.totalSupply().add(tokensForEcosystem);
  267. token.totalSupply().add(tokensForBounty);
  268. token.totalSupply().add(tokenForAirdrop);
  269.  
  270. balances[_airdrop].add(tokenForAirdrop);
  271. balances[_ecosystemFund].add(tokensForEcosystem);
  272. balances[_bountyFund].add(tokensForBounty);
  273. mintingFinished = true ;
  274. }
  275.  
  276. // @return true if the transaction can buy tokens
  277. function validPurchase() internal view returns (bool) {
  278. bool withinCap = weiRaised.add(msg.value) <= cap;
  279. bool withinPeriod = now >= startTime && now <= endTime;
  280. bool nonZeroPurchase = msg.value != 0;
  281. return withinPeriod && nonZeroPurchase && withinCap;
  282. }
  283.  
  284. // @return true if crowdsale event has ended
  285. function hasEnded() public view returns (bool) {
  286. bool capReached = weiRaised >= cap;
  287. return now > endTime || capReached;
  288. }
  289.  
  290. }
  291.  
  292. var BasicToken = artifacts.require("./BasicToken.sol");
  293. var ERC20 = artifacts.require("./ERC20.sol");
  294. var ERC20Basic = artifacts.require("./ERC20Basic.sol");
  295. var Ownable = artifacts.require("./Ownable.sol");
  296. var SafeMath = artifacts.require("./SafeMath.sol");
  297. var StandardToken = artifacts.require("./StandardToken.sol");
  298. var DeveloperToken = artifacts.require("./DeveloperToken.sol");
  299. var DeveloperCrowdsale = artifacts.require("./DeveloperCrowdsale.sol");
  300.  
  301.  
  302. module.exports = function(deployer) {
  303. deployer.deploy(SafeMath);
  304. deployer.link(SafeMath, BasicToken);
  305. deployer.deploy(BasicToken);
  306.  
  307. deployer.deploy(ERC20);
  308. deployer.deploy(ERC20Basic);
  309. deployer.deploy(Ownable);
  310. deployer.deploy(StandardToken);
  311. deployer.deploy(DeveloperToken);
  312. deployer.link(SafeMath, ThoriumCrowdsale);
  313. deployer.deploy(DeveloperCrowdsale);
  314.  
  315. };
  316.  
  317. module.exports = {
  318. networks: {
  319. development: {
  320. host: "localhost",
  321. port: 8545,
  322. network_id: "*" // Match any network id
  323. }
  324. }
  325. };
Add Comment
Please, Sign In to add comment