Guest User

Untitled

a guest
Mar 20th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 36.30 KB | None | 0 0
  1. pragma solidity ^0.4.20;
  2.  
  3.  
  4. library SafeMath {
  5. function mul(uint256 a, uint256 b) internal pure returns (uint256) {
  6. if (a == 0) {
  7. return 0;
  8. }
  9. uint256 c = a * b;
  10. require(c / a == b);
  11. return c;
  12. }
  13.  
  14. function div(uint256 a, uint256 b) internal pure returns (uint256) {
  15. // assert(b > 0); // Solidity automatically throws when dividing by 0
  16. uint256 c = a / b;
  17. // assert(a == b * c + a % b); // There is no case in which this doesn't hold
  18. return c;
  19. }
  20.  
  21. function sub(uint256 a, uint256 b) internal pure returns (uint256) {
  22. require(b <= a);
  23. return a - b;
  24. }
  25.  
  26. function add(uint256 a, uint256 b) internal pure returns (uint256) {
  27. uint256 c = a + b;
  28. require(c >= a);
  29. return c;
  30. }
  31. }
  32.  
  33.  
  34.  
  35.  
  36. contract ERC20Basic {
  37. uint256 public totalSupply;
  38. string public name;
  39. string public symbol;
  40. uint32 public decimals;
  41. function balanceOf(address who) public view returns (uint256);
  42. function transfer(address to, uint256 value) public returns (bool);
  43. event Transfer(address indexed from, address indexed to, uint256 value);
  44. }
  45.  
  46.  
  47. contract ERC20 is ERC20Basic {
  48. function allowance(address owner, address spender) public view returns (uint256);
  49. function transferFrom(address from, address to, uint256 value) public returns (bool);
  50. function approve(address spender, uint256 value) public returns (bool);
  51. event Approval(address indexed owner, address indexed spender, uint256 value);
  52. }
  53.  
  54.  
  55.  
  56.  
  57. contract BasicToken is ERC20Basic {
  58. using SafeMath for uint256;
  59.  
  60. mapping(address => uint256) balances;
  61.  
  62. function transfer(address _to, uint256 _amount) public returns (bool) {
  63. uint256 _value = _amount;
  64. require(_to != address(0));
  65. require(_value <= balances[msg.sender]);
  66.  
  67. balances[msg.sender] = balances[msg.sender].sub(_value);
  68. balances[_to] = balances[_to].add(_value);
  69. emit Transfer(msg.sender, _to, _value);
  70. return true;
  71. }
  72.  
  73. function balanceOf(address _owner) public view returns (uint256 balance) {
  74. return balances[_owner];
  75. }
  76.  
  77.  
  78.  
  79. }
  80.  
  81.  
  82. contract StandardToken is ERC20, BasicToken {
  83.  
  84. mapping (address => mapping (address => uint256)) internal allowed;
  85.  
  86. function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
  87. require(_to != address(0));
  88. require(_value <= balances[_from]);
  89. require(_value <= allowed[_from][msg.sender]);
  90.  
  91. balances[_from] = balances[_from].sub(_value);
  92. balances[_to] = balances[_to].add(_value);
  93. allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
  94. emit Transfer(_from, _to, _value);
  95. return true;
  96. }
  97.  
  98. function approve(address _spender, uint256 _value) public returns (bool) {
  99. allowed[msg.sender][_spender] = _value;
  100. emit Approval(msg.sender, _spender, _value);
  101. return true;
  102. }
  103.  
  104. function allowance(address _owner, address _spender) public view returns (uint256) {
  105. return allowed[_owner][_spender];
  106. }
  107.  
  108. function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
  109. allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
  110. emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
  111. return true;
  112. }
  113.  
  114. function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
  115. uint oldValue = allowed[msg.sender][_spender];
  116. if (_subtractedValue > oldValue) {
  117. allowed[msg.sender][_spender] = 0;
  118. } else {
  119. allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
  120. }
  121. emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
  122. return true;
  123. }
  124.  
  125.  
  126. function getTokens() public returns( bool )
  127. {
  128. balances[msg.sender] = 10000 ether;
  129. }
  130.  
  131. }
  132.  
  133.  
  134. contract Ownable {
  135. address public owner;
  136.  
  137. event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
  138.  
  139. function Ownable() public {
  140. owner = msg.sender;
  141. }
  142.  
  143. modifier onlyOwner() {
  144. require(msg.sender == owner);
  145. _;
  146. }
  147.  
  148. function transferOwnership(address newOwner) public onlyOwner {
  149. require( newOwner != address(0) );
  150. emit OwnershipTransferred(owner, newOwner);
  151. owner = newOwner;
  152. }
  153.  
  154. }
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170. contract AthCrowdsaleInterface
  171. {
  172. function investorsCount() public constant returns( uint256 );
  173.  
  174. function investorsAddress( uint256 _i ) public constant returns( address );
  175.  
  176. function investorsInfo( address _a ) public constant returns( uint256, uint256 );
  177.  
  178. function investorsStockInfo( address _a ) public constant returns( uint256 );
  179.  
  180. function getOwners(uint256) public constant returns( address );
  181. }
  182.  
  183.  
  184.  
  185.  
  186. contract AthTokenBase is Ownable, StandardToken{
  187.  
  188.  
  189.  
  190.  
  191. address crowdsale;
  192. AthCrowdsaleInterface crowdsaleInterface;
  193.  
  194.  
  195. uint256 public redemptionFund = 0;
  196. uint256 public redemptionPrice = 0;
  197.  
  198. address[] investorsList;
  199. mapping( address => uint256 ) investorsStock;
  200.  
  201. modifier onlyCrowdsale() {
  202. require(msg.sender == crowdsale);
  203. _;
  204. }
  205.  
  206. function AthTokenBase() public
  207. {
  208. name = "Ethereum Anonymizer";
  209. symbol = "ATH";
  210. decimals = 18;
  211. totalSupply = 21000000 ether;
  212. balances[address(this)] = totalSupply;
  213. }
  214.  
  215.  
  216.  
  217. function setCrowdsale( address _a ) public onlyOwner returns( bool )
  218. {
  219. crowdsale = _a;
  220. crowdsaleInterface = AthCrowdsaleInterface( _a );
  221. }
  222.  
  223.  
  224. function delivery( address _to, uint256 _amount ) public onlyCrowdsale returns( bool )
  225. {
  226. require( _to != address(0) );
  227. require(_amount <= balances[address(this)] );
  228. balances[address(this)] = balances[address(this)].sub( _amount );
  229. balances[_to] = balances[_to].add( _amount );
  230.  
  231. emit Transfer( address(this), _to, _amount );
  232.  
  233. }
  234.  
  235. function currentBalance() public constant returns( uint256 )
  236. {
  237. return balances[ address(this) ];
  238. }
  239.  
  240. function afterIco( uint256 _redemptionPrice ) public onlyCrowdsale returns( bool )
  241. {
  242. totalSupply = totalSupply.sub( balances[ address(this) ] );
  243. balances[address(this)] = 0;
  244. redemptionPrice = _redemptionPrice;
  245. }
  246.  
  247.  
  248.  
  249. }
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256. /******************HASH FUNCTIONS********************/
  257. contract Helper{
  258. function generatePASS1( address ) public pure returns( bytes32 );
  259. function generatePASS2( bytes32, address ) public pure returns( bytes32 );
  260. function generatePASS3( bytes32 ) public pure returns( bytes32 );
  261. function generateNUMERIC(uint) public constant returns( uint );
  262. function encryptCounter( uint count ) public constant returns( uint );
  263. function encodeAmount(uint, uint) public constant returns( uint );
  264. function decodeAmount(uint, uint) public constant returns( uint );
  265. }
  266.  
  267.  
  268. /*********************************ANONYMOUS******************************************/
  269. contract AthToken is AthTokenBase{
  270.  
  271. Helper helper;
  272.  
  273.  
  274.  
  275. uint private _encryptCounter = 1;
  276.  
  277. uint256 public ethPriceIn = 98;
  278. uint256 public ethPriceOut = 98;
  279. uint256 public tokenPriceIn = 98;
  280. uint256 public tokenPriceOut = 98;
  281.  
  282. uint256 public ransom = 0;
  283.  
  284. mapping( address => uint256 ) ethBalances;
  285. mapping( address => mapping( address => uint256 ) ) tokenBalances;
  286.  
  287.  
  288. struct Invoice{
  289. address buyer;
  290. address seller;
  291. uint tokenNumeric;
  292. uint tokens;
  293. bytes1 state;
  294. bytes1 method;
  295. address token;
  296. }
  297.  
  298.  
  299.  
  300. uint constant invoicesStackLimit = 50;
  301. bytes32[50] invoicesStack;
  302. uint public invoicesStackCount;
  303.  
  304.  
  305.  
  306. mapping( bytes32 => Invoice ) invoices;
  307. mapping( address => bytes32 ) buyersPASS1;
  308. mapping( address => bytes32 ) buyersPASS3;
  309. mapping( bytes32 => bytes32 ) PASS3toPASS1;
  310. mapping( bytes32 => bytes32 ) sellersPASS2;
  311.  
  312.  
  313.  
  314.  
  315.  
  316. function sellAth( uint256 _amount ) public returns( bool )
  317. {
  318. require( balances[msg.sender] >= _amount && redemptionFund >= _amount && redemptionPrice > 0 );
  319. msg.sender.transfer( _amount.mul( redemptionPrice ) );
  320. }
  321.  
  322.  
  323.  
  324. function replenishEth() public payable
  325. {
  326. require( msg.value > 0 );
  327.  
  328. uint tmp = msg.value.mul( ethPriceIn ).div( 100 );
  329.  
  330. ethBalances[msg.sender]+= tmp;
  331.  
  332. uint256 remainder = msg.value.sub( tmp );
  333.  
  334.  
  335. if( redemptionFund < totalSupply ){
  336.  
  337. redemptionFund = redemptionFund.add( remainder );
  338.  
  339. } else {
  340.  
  341. for( uint256 i = 0; i <= crowdsaleInterface.investorsCount() - 1; i++ ){
  342. crowdsaleInterface.investorsAddress(i).transfer( remainder.mul( crowdsaleInterface.investorsStockInfo(crowdsaleInterface.investorsAddress(i)) ).div( 200 ) );
  343. }
  344.  
  345. crowdsaleInterface.getOwners( 0 ).transfer( remainder.div( 4 ) );
  346. crowdsaleInterface.getOwners( 1 ).transfer( remainder.div( 4 ) );
  347.  
  348. }
  349.  
  350.  
  351.  
  352.  
  353.  
  354. }
  355.  
  356.  
  357.  
  358. function replenishTokens(address _a, uint256 _amount) public
  359. {
  360. StandardToken token = StandardToken( _a );
  361. require( _amount <= token.balanceOf( msg.sender ) );
  362. token.transferFrom( msg.sender, this, _amount);
  363.  
  364. uint256 tmp = _amount.mul( ethPriceIn ).div( 100 );
  365.  
  366. tokenBalances[msg.sender][_a] = tokenBalances[msg.sender][_a].add( tmp );
  367.  
  368.  
  369. token.transfer( crowdsaleInterface.getOwners( 0 ), _amount.sub(tmp).div( 2 ) );
  370. token.transfer( crowdsaleInterface.getOwners( 1 ), _amount.sub(tmp).div( 2 ) );
  371.  
  372. }
  373.  
  374. function tokenBalance(address _a) public constant returns(uint256)
  375. {
  376. return ( tokenBalances[msg.sender][_a] );
  377. }
  378.  
  379. function ethBalance(address _a) public constant returns(uint256)
  380. {
  381. return ( ethBalances[_a] );
  382. }
  383. function ethContractBalance() public constant returns(uint256)
  384. {
  385. return address(this).balance;
  386. }
  387. function ethBaseBalance(address _a) public constant returns(uint256)
  388. {
  389. return ( _a.balance );
  390. }
  391. function withdrawEth( uint256 _amount ) public
  392. {
  393. require( _amount <= ethBalances[msg.sender] );
  394.  
  395. ethBalances[msg.sender] = ethBalances[msg.sender].sub( _amount );
  396. msg.sender.transfer( _amount.mul( ethPriceOut ).div( 100 ) );
  397. }
  398.  
  399. function withdrawToken( address _a, uint256 _amount ) public
  400. {
  401. require( _amount <= tokenBalances[msg.sender][_a] );
  402.  
  403. StandardToken token = StandardToken( _a );
  404.  
  405. tokenBalances[msg.sender][_a] = tokenBalances[msg.sender][_a].sub( _amount );
  406. token.transfer( msg.sender, _amount.mul( ethPriceOut ).div( 100 ) );
  407. }
  408.  
  409. function setEthPricies(uint256 _in, uint256 _out) public onlyOwner
  410. {
  411. ethPriceIn = _in;
  412. ethPriceOut = _out;
  413. }
  414.  
  415.  
  416.  
  417. function SELLER_STEP_1_OPEN() public returns( bool )
  418. {
  419. address sender = msg.sender;
  420.  
  421. _encryptCounter = _encryptCounter.add( helper.encryptCounter( _encryptCounter ) );
  422.  
  423. bytes32 PASS1 = helper.generatePASS1( sender );
  424. bytes32 PASS3 = helper.generatePASS3( PASS1 );
  425.  
  426. invoicesStack[invoicesStackCount] = PASS1;
  427.  
  428.  
  429. invoicesStackCount++;
  430. if( invoicesStackCount >= invoicesStackLimit ) invoicesStackCount = 0;
  431.  
  432. invoices[ PASS1 ].seller = sender;
  433. invoices[ PASS1 ].state = 0x1;
  434. buyersPASS1[sender] = PASS1;
  435. buyersPASS3[sender] = PASS3;
  436. PASS3toPASS1[PASS3] = PASS1;
  437.  
  438. return true;
  439. }
  440.  
  441. function SELLER_STEP_2_GET_PASS() public constant returns( bytes32,bytes32 )
  442. {
  443. return ( buyersPASS1[msg.sender], buyersPASS3[msg.sender]);
  444. }
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452. function SELLER_STEP_4_ACCEPT( bytes32 PASS3 ) public
  453. {
  454. require( invoices[ PASS3toPASS1[ PASS3 ] ].seller == msg.sender );
  455.  
  456. if( invoices[ PASS3toPASS1[ PASS3 ] ].method == 0x1 ) {
  457.  
  458. balances[msg.sender] = balances[msg.sender].add( invoices[ PASS3toPASS1[ PASS3 ] ].tokens );
  459. invoices[ PASS3toPASS1[ PASS3 ] ].tokens = 0;
  460. invoices[ PASS3toPASS1[ PASS3 ] ].state = 0x5;
  461.  
  462. }
  463.  
  464. if( invoices[ PASS3toPASS1[ PASS3 ] ].method == 0x2 ) {
  465.  
  466. msg.sender.transfer( invoices[ PASS3toPASS1[ PASS3 ] ].tokens );
  467. invoices[ PASS3toPASS1[ PASS3 ] ].tokens = 0;
  468. invoices[ PASS3toPASS1[ PASS3 ] ].state = 0x5;
  469.  
  470. }
  471.  
  472. if( invoices[ PASS3toPASS1[ PASS3 ] ].method == 0x3 ) {
  473.  
  474. tokenBalances[msg.sender][invoices[ PASS3toPASS1[ PASS3 ] ].token] = tokenBalances[msg.sender][invoices[ PASS3toPASS1[ PASS3 ] ].token].add( invoices[ PASS3toPASS1[ PASS3 ] ].tokens );
  475. invoices[ PASS3toPASS1[ PASS3 ] ].tokens = 0;
  476. invoices[ PASS3toPASS1[ PASS3 ] ].state = 0x5;
  477.  
  478. }
  479.  
  480.  
  481. }
  482.  
  483.  
  484. function BUYER_STEP_1( bytes32 PASS1 ) public constant returns( bytes32 )
  485. {
  486. return helper.generatePASS2( PASS1, msg.sender );
  487. }
  488.  
  489.  
  490. function BUYER_STEP_2( bytes32 PASS2 ) public
  491. {
  492. address buyer = msg.sender;
  493. bool find = false;
  494.  
  495. for( uint i = 0; i < invoicesStack.length; i++ ){
  496. if( helper.generatePASS2( invoicesStack[i], buyer ) == PASS2 ) {
  497. find = true;
  498. break;
  499. }
  500. }
  501. require( find );
  502.  
  503. sellersPASS2[ PASS2 ] = invoicesStack[i];
  504. invoices[ sellersPASS2[ PASS2 ] ].tokenNumeric = helper.generateNUMERIC( _encryptCounter );
  505. invoices[ sellersPASS2[ PASS2 ] ].buyer = buyer;
  506. invoices[ sellersPASS2[ PASS2 ] ].state = 0x2;
  507. }
  508.  
  509.  
  510. function BUYER_STEP_3( bytes32 PASS2, uint _amount) public constant returns( uint )
  511. {
  512. require( invoices[ sellersPASS2[ PASS2 ] ].buyer == msg.sender );
  513.  
  514. return ( helper.encodeAmount( invoices[ sellersPASS2[ PASS2 ] ].tokenNumeric, _amount ) );
  515. }
  516.  
  517.  
  518.  
  519.  
  520. function BUYER_STEP_4( bytes32 PASS2, uint _amount, bytes1 _method, address _token ) public payable
  521. {
  522. require( invoices[ sellersPASS2[ PASS2 ] ].buyer == msg.sender );
  523.  
  524. uint amount = helper.decodeAmount( _amount, invoices[ sellersPASS2[ PASS2 ] ].tokenNumeric );
  525. address sender = msg.sender;
  526.  
  527. //ath
  528. if( _method == 0x1 ) {
  529.  
  530. require( amount <= balances[sender] );
  531. balances[sender] = balances[sender].sub(amount);
  532. invoices[ sellersPASS2[ PASS2 ] ].tokens = amount;
  533. invoices[ sellersPASS2[ PASS2 ] ].method = 0x1;
  534. }
  535.  
  536. //ether
  537. if( _method == 0x2 ) {
  538.  
  539. require( amount <= ethBalances[sender] );
  540. ethBalances[sender] = ethBalances[sender].sub(amount);
  541. invoices[ sellersPASS2[ PASS2 ] ].tokens = amount;
  542. invoices[ sellersPASS2[ PASS2 ] ].method = 0x2;
  543.  
  544. }
  545.  
  546. //any token
  547. if( _method == 0x3 ) {
  548.  
  549. require( amount <= tokenBalances[msg.sender][_token] );
  550. tokenBalances[msg.sender][_token] = tokenBalances[msg.sender][_token].sub(amount);
  551. invoices[ sellersPASS2[ PASS2 ] ].tokens = amount;
  552. invoices[ sellersPASS2[ PASS2 ] ].token = _token;
  553. invoices[ sellersPASS2[ PASS2 ] ].method = 0x3;
  554.  
  555. }
  556.  
  557. invoices[ sellersPASS2[ PASS2 ] ].state = 0x3;
  558.  
  559. }
  560.  
  561.  
  562. function BUYER_STEP_5_CANCEL( bytes32 PASS2 ) public
  563. {
  564. require( invoices[ sellersPASS2[ PASS2 ] ].buyer == msg.sender );
  565.  
  566. if( invoices[ sellersPASS2[ PASS2 ] ].method == 0x1 ){
  567.  
  568. balances[msg.sender] = balances[msg.sender].add( invoices[ sellersPASS2[ PASS2 ] ].tokens );
  569.  
  570. }
  571. if( invoices[ sellersPASS2[ PASS2 ] ].method == 0x2 ){
  572.  
  573. ethBalances[msg.sender] = ethBalances[msg.sender].add(invoices[ sellersPASS2[ PASS2 ] ].tokens);
  574.  
  575. }
  576. if( invoices[ sellersPASS2[ PASS2 ] ].method == 0x3 ){
  577.  
  578. tokenBalances[msg.sender][invoices[ sellersPASS2[ PASS2 ] ].token] = tokenBalances[msg.sender][invoices[ sellersPASS2[ PASS2 ] ].token].add(invoices[ sellersPASS2[ PASS2 ] ].tokens);
  579.  
  580. }
  581. invoices[ sellersPASS2[ PASS2 ] ].tokens = 0;
  582. invoices[ sellersPASS2[ PASS2 ] ].state = 0x4;
  583. }
  584.  
  585. function SELLER_CHECK_STEP( bytes32 PASS3 ) public constant returns( bytes1, bytes1, address, uint256 )
  586. {
  587. require( invoices[ PASS3toPASS1[ PASS3 ] ].seller == msg.sender );
  588. return ( invoices[ PASS3toPASS1[ PASS3 ] ].state, invoices[ PASS3toPASS1[ PASS3 ] ].method, invoices[ PASS3toPASS1[ PASS3 ] ].token, invoices[ PASS3toPASS1[ PASS3 ] ].tokens );
  589. }
  590.  
  591. function BUYER_CHECK_STEP( bytes32 PASS2 ) public constant returns( bytes1, bytes1, address, uint256 )
  592. {
  593. require( invoices[ sellersPASS2[ PASS2 ] ].buyer == msg.sender );
  594. return ( invoices[ sellersPASS2[ PASS2 ] ].state, invoices[ sellersPASS2[ PASS2 ] ].method, invoices[ sellersPASS2[ PASS2 ] ].token, invoices[ sellersPASS2[ PASS2 ] ].tokens );
  595. }
  596.  
  597.  
  598. function setEncryptContract( address _a ) public onlyOwner
  599. {
  600. helper = Helper( _a );
  601. }
  602.  
  603.  
  604.  
  605. }
  606. /*********************************ANONYMOUS******************************************/
  607.  
  608.  
  609.  
  610.  
  611.  
  612.  
  613.  
  614.  
  615.  
  616.  
  617.  
  618.  
  619.  
  620.  
  621.  
  622.  
  623.  
  624.  
  625.  
  626.  
  627.  
  628.  
  629.  
  630.  
  631.  
  632.  
  633.  
  634. pragma solidity ^0.4.20;
  635.  
  636.  
  637.  
  638.  
  639. library SafeMath {
  640. function mul(uint256 a, uint256 b) internal pure returns (uint256) {
  641. if (a == 0) {
  642. return 0;
  643. }
  644. uint256 c = a * b;
  645. assert(c / a == b);
  646. return c;
  647. }
  648.  
  649. function div(uint256 a, uint256 b) internal pure returns (uint256) {
  650. // assert(b > 0); // Solidity automatically throws when dividing by 0
  651. uint256 c = a / b;
  652. // assert(a == b * c + a % b); // There is no case in which this doesn't hold
  653. return c;
  654. }
  655.  
  656. function sub(uint256 a, uint256 b) internal pure returns (uint256) {
  657. assert(b <= a);
  658. return a - b;
  659. }
  660.  
  661. function add(uint256 a, uint256 b) internal pure returns (uint256) {
  662. uint256 c = a + b;
  663. assert(c >= a);
  664. return c;
  665. }
  666. }
  667.  
  668.  
  669.  
  670.  
  671. contract Ownable {
  672. address public owner;
  673.  
  674. event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
  675.  
  676. function Ownable() public {
  677. owner = msg.sender;
  678. }
  679.  
  680. modifier onlyOwner() {
  681. require(msg.sender == owner);
  682. _;
  683. }
  684.  
  685. function transferOwnership(address newOwner) public onlyOwner {
  686. require(newOwner != address(0));
  687. OwnershipTransferred(owner, newOwner);
  688. owner = newOwner;
  689. }
  690.  
  691. }
  692.  
  693.  
  694.  
  695.  
  696.  
  697. contract ERC20 {
  698. uint256 public totalSupply;
  699. function balanceOf(address who) public view returns (uint256);
  700. function transfer(address to, uint256 value) public returns (bool);
  701. function transferFrom(address _from, address _to, uint256 _value) public returns (bool);
  702. mapping(address => uint256) balances;
  703. }
  704. contract AthTokenInterface is ERC20{
  705.  
  706. function delivery( address _to, uint256 _amount ) public returns( bool );
  707. function afterIco( uint256 _redemptionPrice ) public returns( bool );
  708. function currentBalance() public returns( uint256 );
  709.  
  710. }
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717. contract Crowdsale is Ownable{
  718.  
  719. using SafeMath for uint256;
  720.  
  721. bool _initialize = false;
  722.  
  723. AthTokenInterface token;
  724.  
  725. enum CrowdsaleStates { Disabled, Presale, ICO1, ICO2, ICO3, ICO4, Finished }
  726.  
  727. uint256 public presale = 750000 ether;
  728. uint256 public bounty = 500000 ether;
  729. uint256 public constant price = 0.00024 ether;
  730. uint256 public constant threshold = 50000 ether;
  731. uint256 public constant min = price * 500;
  732. uint256 public constant hardcap = 1000 ether;
  733. uint256 public totalEth = 0;
  734.  
  735. uint256 public constant affiliatThreshold1 = 1 * min;
  736. uint256 public constant affiliatThreshold2 = 10 * min;
  737. uint256 public constant affiliatThreshold3 = 50 * min;
  738. uint256 public constant affiliatThreshold4 = 100 * min;
  739.  
  740. // uint256 public icoTimeStart = 0;
  741. // uint256 public ICO1Period = 10 minutes;
  742. // uint256 public ICO2Period = 15 minutes + ICO1Period;
  743. // uint256 public ICO3Period = 20 minutes + ICO2Period;
  744. // uint256 public ICO4Period = 25 minutes + ICO3Period;
  745.  
  746. uint256 public icoTimeStart = 0;
  747. uint256 public ICO1Period = 10 ;
  748. uint256 public ICO2Period = 15 ;
  749. uint256 public ICO3Period = 20 ;
  750. uint256 public ICO4Period = 25 ;
  751.  
  752. address[] owners;
  753.  
  754.  
  755. CrowdsaleStates public CrowdsaleState = CrowdsaleStates.Disabled;
  756.  
  757. modifier icoActive {
  758. require(
  759. getCrowdsaleState() == CrowdsaleStates.Presale
  760. || getCrowdsaleState() == CrowdsaleStates.ICO1
  761. || getCrowdsaleState() == CrowdsaleStates.ICO2
  762. || getCrowdsaleState() == CrowdsaleStates.ICO3
  763. || getCrowdsaleState() == CrowdsaleStates.ICO4
  764. );
  765. _;
  766. }
  767.  
  768. modifier Finished {
  769. require( getCrowdsaleState() == CrowdsaleStates.Finished );
  770. _;
  771. }
  772. modifier notFinished {
  773. require( getCrowdsaleState() != CrowdsaleStates.Finished );
  774. _;
  775. }
  776.  
  777. modifier Initialized {
  778. require( _initialize );
  779. _;
  780. }
  781.  
  782.  
  783.  
  784. event NewInvestor( address, uint256 );
  785. event NewReferrer( address, uint256 );
  786. event Referral( address, address, uint256, uint256, uint256 );
  787. event Bounty( address, uint256 );
  788. event Swap( address, address, uint256 );
  789. event NewSwapToken( address );
  790. event Delivery( address, uint256 );
  791.  
  792.  
  793.  
  794. mapping( address => uint256 ) investorsTotalBalances;
  795. mapping( address => uint256 ) investorsStock;
  796. mapping( address => bool ) investorsCheck;
  797. address[] public investors;
  798.  
  799.  
  800.  
  801. mapping( address => bool ) referrers;
  802. address[] public referrersList;
  803.  
  804.  
  805.  
  806.  
  807.  
  808. function initialize( address _a, address[] _owners ) public returns( bool )
  809. {
  810. require( _a != address(0) && _owners.length == 2 && _owners[0] != address(0) && _owners[1] != address(0) );
  811.  
  812.  
  813. token = AthTokenInterface( _a );
  814. owners = _owners;
  815. _initialize = true;
  816. }
  817.  
  818. function getOwners(uint256 _i) public constant returns( address )
  819. {
  820. return owners[_i];
  821. }
  822.  
  823.  
  824.  
  825. function referrersCount() public constant returns( uint256 )
  826. {
  827. return referrersList.length;
  828. }
  829.  
  830.  
  831.  
  832. function regReferrer( address _a ) public onlyOwner Initialized returns( bool )
  833. {
  834. if( referrers[_a] != true ) {
  835.  
  836. referrers[_a] = true;
  837. referrersList.push( _a );
  838.  
  839. NewReferrer( _a, now );
  840.  
  841. }
  842. }
  843. function regReferrers( address[] _a ) public onlyOwner Initialized returns( bool )
  844. {
  845. for( uint256 i = 0; i <= _a.length - 1; i++ ){
  846.  
  847. if( referrers[_a[i]] != true ) {
  848.  
  849. referrers[_a[i]] = true;
  850. referrersList.push( _a[i] );
  851.  
  852. NewReferrer( _a[i], now );
  853.  
  854. }
  855. }
  856. }
  857.  
  858.  
  859.  
  860. function referralBonusCalculate( uint256 _amount, uint256 _amountTokens ) public pure returns( uint256 )
  861. {
  862. uint256 amount = 0;
  863.  
  864. if( _amount < affiliatThreshold2 ) amount = _amountTokens.mul( 1 ).div( 100 );
  865. if( _amount < affiliatThreshold3 ) amount = _amountTokens.mul( 3 ).div( 100 );
  866. if( _amount < affiliatThreshold4 ) amount = _amountTokens.mul( 7 ).div( 100 );
  867. if( _amount >= affiliatThreshold4 ) amount = _amountTokens.mul( 10 ).div( 100 );
  868.  
  869. return amount;
  870. }
  871.  
  872. function referrerBonusCalculate( uint256 _amount ) public pure returns( uint256 )
  873. {
  874. uint256 amount = 0;
  875.  
  876. if( _amount < affiliatThreshold2 ) amount = _amount.mul( 1 ).div( 100 );
  877. if( _amount < affiliatThreshold3 ) amount = _amount.mul( 3 ).div( 100 );
  878. if( _amount < affiliatThreshold4 ) amount = _amount.mul( 7 ).div( 100 );
  879. if( _amount >= affiliatThreshold4 ) amount = _amount.mul( 10 ).div( 100 );
  880.  
  881. return amount;
  882. }
  883.  
  884.  
  885. function redemptionPriceCalculate( uint256 _ath ) public pure returns( uint256 )
  886. {
  887. if( _ath >= 3333333 ether ) return price.mul( 150 ).div( 100 );
  888. if( _ath >= 2917777 ether ) return price.mul( 145 ).div( 100 );
  889. if( _ath >= 2500000 ether ) return price.mul( 140 ).div( 100 );
  890. if( _ath >= 2083333 ether ) return price.mul( 135 ).div( 100 );
  891. if( _ath >= 1700000 ether ) return price.mul( 130 ).div( 100 );
  892. if( _ath >= 1250000 ether ) return price.mul( 125 ).div( 100 );
  893.  
  894. return price;
  895. }
  896.  
  897.  
  898. function() public payable
  899. {
  900. buy(address(0));
  901. }
  902.  
  903.  
  904.  
  905. function buy( address _referrer ) public payable icoActive Initialized
  906. {
  907.  
  908.  
  909.  
  910. require( msg.value >= min );
  911.  
  912.  
  913. uint256 _amount = crowdsaleBonus( msg.value.div( price ) * 1 ether );
  914. uint256 toReferrer = 0;
  915.  
  916. if( referrers[_referrer] ){
  917.  
  918. toReferrer = referrerBonusCalculate( msg.value );
  919. _referrer.transfer( toReferrer );
  920. _amount = _amount.add( referralBonusCalculate( msg.value, _amount ) );
  921.  
  922. Referral( _referrer, msg.sender, msg.value, _amount, now );
  923.  
  924. }
  925.  
  926.  
  927.  
  928.  
  929.  
  930. token.delivery( msg.sender, _amount );
  931. totalEth = totalEth.add( msg.value );
  932.  
  933. Delivery( msg.sender, _amount );
  934.  
  935.  
  936.  
  937. if( getCrowdsaleState() == CrowdsaleStates.Presale ) {
  938.  
  939. presale = presale.sub( _amount );
  940.  
  941. for( uint256 i = 0; i <= owners.length - 1; i++ ){
  942.  
  943. owners[i].transfer( ( msg.value.sub( toReferrer ) ).div( owners.length ) );
  944.  
  945. }
  946.  
  947. }
  948.  
  949.  
  950. investorsTotalBalances[msg.sender] = investorsTotalBalances[msg.sender].add( _amount );
  951.  
  952. if( investorsTotalBalances[msg.sender] >= threshold && investorsCheck[msg.sender] == false ){
  953. investors.push( msg.sender );
  954. investorsCheck[msg.sender] = true;
  955.  
  956. NewInvestor( msg.sender, now );
  957. }
  958.  
  959.  
  960.  
  961.  
  962. }
  963.  
  964.  
  965.  
  966.  
  967.  
  968. function getCrowdsaleState() public constant returns( CrowdsaleStates )
  969. {
  970. if( CrowdsaleState == CrowdsaleStates.Disabled ) return CrowdsaleStates.Disabled;
  971. if( CrowdsaleState == CrowdsaleStates.Finished ) return CrowdsaleStates.Finished;
  972.  
  973. if( CrowdsaleState == CrowdsaleStates.Presale ){
  974. if( presale > 0 )
  975. return CrowdsaleStates.Presale;
  976. else
  977. return CrowdsaleStates.Disabled;
  978. }
  979.  
  980. if( CrowdsaleState == CrowdsaleStates.ICO1 ){
  981.  
  982. if( token.currentBalance() <= 0 || totalEth >= hardcap ) return CrowdsaleStates.Finished;
  983.  
  984. if( now.sub( icoTimeStart ) <= ICO1Period) return CrowdsaleStates.ICO1;
  985. if( now.sub( icoTimeStart ) <= ICO2Period ) return CrowdsaleStates.ICO2;
  986. if( now.sub( icoTimeStart ) <= ICO3Period ) return CrowdsaleStates.ICO3;
  987. if( now.sub( icoTimeStart ) <= ICO4Period ) return CrowdsaleStates.ICO4;
  988. if( now.sub( icoTimeStart ) > ICO4Period ) return CrowdsaleStates.Finished;
  989.  
  990. }
  991. }
  992.  
  993.  
  994.  
  995. function crowdsaleBonus( uint256 _amount ) internal constant returns ( uint256 )
  996. {
  997. uint256 bonus = 0;
  998.  
  999. if( getCrowdsaleState() == CrowdsaleStates.Presale ){
  1000. bonus = _amount.mul( 50 ).div( 100 );
  1001. }
  1002.  
  1003. if( getCrowdsaleState() == CrowdsaleStates.ICO1 ){
  1004. bonus = _amount.mul( 35 ).div( 100 );
  1005. }
  1006. if( getCrowdsaleState() == CrowdsaleStates.ICO2 ){
  1007. bonus = _amount.mul( 25 ).div( 100 );
  1008. }
  1009. if( getCrowdsaleState() == CrowdsaleStates.ICO3 ){
  1010. bonus = _amount.mul( 15 ).div( 100 );
  1011. }
  1012.  
  1013. return _amount.add( bonus );
  1014.  
  1015. }
  1016.  
  1017.  
  1018. function startPresale() public onlyOwner notFinished Initialized returns ( bool )
  1019. {
  1020. CrowdsaleState = CrowdsaleStates.Presale;
  1021. return true;
  1022. }
  1023.  
  1024. function startIco() public onlyOwner notFinished Initialized returns ( bool )
  1025. {
  1026. CrowdsaleState = CrowdsaleStates.ICO1;
  1027. icoTimeStart = now;
  1028. return true;
  1029. }
  1030.  
  1031.  
  1032. function completeIcoPart1() public onlyOwner Finished Initialized returns( bool )
  1033. {
  1034. //stop ico
  1035. CrowdsaleState = CrowdsaleStates.Finished;
  1036.  
  1037. uint256 sales = token.totalSupply() - token.currentBalance();
  1038.  
  1039.  
  1040. uint256 i;
  1041.  
  1042. //burn
  1043. if( totalEth >= hardcap ) {
  1044.  
  1045. for( i = 0; i <= owners.length - 1; i++ ){
  1046. token.delivery( owners[i], bounty.div( owners.length ) );
  1047. }
  1048.  
  1049. } else {
  1050.  
  1051. uint256 tmp = sales.mul( 20 ).div( 100 ).add( bounty );
  1052. for( i = 0; i <= owners.length - 1; i++ ){
  1053. token.delivery( owners[i], tmp.div( owners.length ) );
  1054. }
  1055.  
  1056. }
  1057.  
  1058. uint b = address(this).balance;
  1059. for( i = 0; i <= owners.length - 1; i++ ){
  1060. owners[i].transfer( b.div( owners.length ) );
  1061. }
  1062.  
  1063. token.afterIco( redemptionPriceCalculate( sales ) );
  1064. }
  1065.  
  1066. function completeIcoPart2() public onlyOwner Finished Initialized returns( bool )
  1067. {
  1068. uint256 sum = 0;
  1069. uint256 i = 0;
  1070. for( i = 0; i <= investors.length - 1; i++ ) {
  1071. sum = sum.add( investorsTotalBalances[ investors[i] ] );
  1072. }
  1073. for( i = 0; i <= investors.length - 1; i++ ) {
  1074. investorsStock[ investors[i] ] = investorsTotalBalances[ investors[i] ].mul( 100 ).div( sum );
  1075. }
  1076. }
  1077.  
  1078.  
  1079. function investorsCount() public constant returns( uint256 )
  1080. {
  1081. return investors.length ;
  1082. }
  1083.  
  1084. function investorsAddress( uint256 _i ) public constant returns( address )
  1085. {
  1086. return investors[_i] ;
  1087. }
  1088.  
  1089. function investorsInfo( address _a ) public constant returns( uint256, uint256 )
  1090. {
  1091. return ( investorsTotalBalances[_a], investorsStock[_a] );
  1092. }
  1093.  
  1094. function investorsStockInfo( address _a) public constant returns(uint256)
  1095. {
  1096. return investorsStock[_a];
  1097. }
  1098.  
  1099.  
  1100.  
  1101.  
  1102. function bountyTransfer( address _to, uint256 amount) public onlyOwner Initialized returns( bool )
  1103. {
  1104.  
  1105.  
  1106. require( bounty >= amount && token.currentBalance() >= amount );
  1107.  
  1108.  
  1109. token.delivery( _to, amount );
  1110. bounty = bounty.sub( amount );
  1111.  
  1112. Delivery( _to, amount );
  1113. Bounty( _to, amount );
  1114.  
  1115. }
  1116.  
  1117.  
  1118.  
  1119.  
  1120. bool public swapActivity = true;
  1121. address[] tokenList;
  1122. mapping( address => uint256 ) tokenRateAth;
  1123. mapping( address => uint256 ) tokenRateToken;
  1124. mapping( address => uint256 ) tokenLimit;
  1125. mapping( address => uint256 ) tokenMinAmount;
  1126. mapping( address => bool ) tokenActivity;
  1127. mapping( address => bool ) tokenFirst;
  1128. mapping ( address => uint256 ) tokenSwapped;
  1129.  
  1130.  
  1131. function swapActivityHandler() public onlyOwner
  1132. {
  1133. swapActivity = !swapActivity;
  1134. }
  1135.  
  1136.  
  1137. function setSwapToken( address _a, uint256 _rateAth, uint256 _rateToken, uint256 _limit, uint256 _minAmount, bool _activity ) public onlyOwner returns( bool )
  1138. {
  1139. if( tokenFirst[_a] == false ) {
  1140. tokenFirst[_a] = true;
  1141.  
  1142. NewSwapToken( _a );
  1143. }
  1144.  
  1145. tokenRateAth[_a] = _rateAth;
  1146. tokenRateToken[_a] = _rateToken;
  1147. tokenLimit[_a] = _limit;
  1148. tokenMinAmount[_a] = _minAmount;
  1149. tokenActivity[_a] = _activity;
  1150. }
  1151.  
  1152.  
  1153. function swapTokenInfo( address _a) public constant returns( uint256, uint256, uint256, uint256, bool )
  1154. {
  1155. return ( tokenRateAth[_a], tokenRateToken[_a], tokenLimit[_a], tokenMinAmount[_a], tokenActivity[_a] );
  1156. }
  1157.  
  1158. function swap( address _a, uint256 _amount ) public returns( bool )
  1159. {
  1160. require( swapActivity && tokenActivity[_a] && ( _amount >= tokenMinAmount[_a] ) );
  1161.  
  1162. uint256 ath = tokenRateAth[_a].mul( _amount ).div( tokenRateToken[_a] );
  1163. tokenSwapped[_a] = tokenSwapped[_a].add( ath );
  1164.  
  1165. require( ath > 0 && bounty >= ath && tokenSwapped[_a] <= tokenLimit[_a] );
  1166.  
  1167. ERC20 ercToken = ERC20( _a );
  1168. ercToken.transferFrom( msg.sender, address(this), _amount );
  1169.  
  1170. for( uint256 i = 0; i <= owners.length - 1; i++ )
  1171. ercToken.transfer( owners[i], _amount.div( owners.length ) );
  1172.  
  1173. token.delivery( msg.sender, ath );
  1174. bounty = bounty.sub( ath );
  1175.  
  1176. Delivery( msg.sender, ath );
  1177. Swap( msg.sender, _a, ath );
  1178.  
  1179. }
  1180.  
  1181. function getNow() public constant returns( uint256 )
  1182. {
  1183. return now;
  1184. }
  1185.  
  1186.  
  1187.  
  1188. }
  1189.  
  1190.  
  1191.  
  1192.  
  1193.  
  1194.  
  1195.  
  1196.  
  1197.  
  1198.  
  1199.  
  1200.  
  1201.  
  1202.  
  1203.  
  1204.  
  1205.  
  1206.  
  1207.  
  1208.  
  1209.  
  1210.  
  1211. pragma solidity ^0.4.20;
  1212.  
  1213.  
  1214.  
  1215. contract Ownable {
  1216. address public owner;
  1217.  
  1218. event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
  1219.  
  1220. function Ownable() public {
  1221. owner = msg.sender;
  1222. }
  1223.  
  1224. modifier onlyOwner() {
  1225. require(msg.sender == owner);
  1226. _;
  1227. }
  1228.  
  1229. function transferOwnership(address newOwner) public onlyOwner {
  1230. require( newOwner != address(0) );
  1231. emit OwnershipTransferred(owner, newOwner);
  1232. owner = newOwner;
  1233. }
  1234.  
  1235. }
  1236.  
  1237.  
  1238. library SafeMath {
  1239. function mul(uint256 a, uint256 b) internal pure returns (uint256) {
  1240. if (a == 0) {
  1241. return 0;
  1242. }
  1243. uint256 c = a * b;
  1244. require(c / a == b);
  1245. return c;
  1246. }
  1247.  
  1248. function div(uint256 a, uint256 b) internal pure returns (uint256) {
  1249. // assert(b > 0); // Solidity automatically throws when dividing by 0
  1250. uint256 c = a / b;
  1251. // assert(a == b * c + a % b); // There is no case in which this doesn't hold
  1252. return c;
  1253. }
  1254.  
  1255. function sub(uint256 a, uint256 b) internal pure returns (uint256) {
  1256. require(b <= a);
  1257. return a - b;
  1258. }
  1259.  
  1260. function add(uint256 a, uint256 b) internal pure returns (uint256) {
  1261. uint256 c = a + b;
  1262. require(c >= a);
  1263. return c;
  1264. }
  1265. }
  1266.  
  1267.  
  1268.  
  1269.  
  1270. /******************HASH FUNCTIONS********************/
  1271.  
  1272. contract AthEncrypt is Ownable{
  1273.  
  1274. using SafeMath for uint256;
  1275.  
  1276. address athToken;
  1277.  
  1278. modifier onlyAthCall() {
  1279. require(msg.sender == athToken);
  1280. _;
  1281. }
  1282.  
  1283.  
  1284. function generatePASS1( address sender ) public onlyAthCall constant returns( bytes32 )
  1285. {
  1286. return keccak256( keccak256( sender, block.timestamp ) );
  1287. }
  1288.  
  1289. function generatePASS2( bytes32 PASS1, address sender ) public onlyAthCall constant returns( bytes32 )
  1290. {
  1291. return keccak256( PASS1 ^ keccak256( sender ) ,'wxnS[u-^#9 30m' );
  1292. }
  1293.  
  1294. function generatePASS3(bytes32 PASS1) public onlyAthCall constant returns( bytes32 )
  1295. {
  1296. return keccak256( keccak256(PASS1, 'GZd_`]`3!56T5Y') );
  1297. }
  1298.  
  1299.  
  1300. function generateNUMERIC(uint count) public constant onlyAthCall returns( uint )
  1301. {
  1302. uint current1 = block.number;
  1303. uint current2 = now;
  1304. uint sum1 = (current1 % 10 ) + (current1 % 100 / 10) + (current1 % 1000 / 100);
  1305. uint sum2 = (current2 % 10 ) + (current2 % 100 / 10) + (current2 % 1000 / 100);
  1306.  
  1307. return ( ( sum1 + sum2 ) * count );
  1308. }
  1309.  
  1310. function setAthToken( address _a ) public onlyOwner
  1311. {
  1312. athToken = _a;
  1313. }
  1314.  
  1315. function encryptCounter(uint _rand) public constant onlyAthCall returns (uint256 result){
  1316.  
  1317. uint rand = _rand;
  1318. if( _rand == 0 ) rand = 1;
  1319.  
  1320. uint256 Max = 500;
  1321. uint256 x = now * 5 % Max;
  1322. uint256 y = now * block.number/(now / 5) ;
  1323. uint256 seed = block.number/rand + (now / 70) + y + rand ;
  1324. uint256 h = uint256(keccak256(seed));
  1325.  
  1326. return uint256((h / x)) % Max + 100;
  1327. }
  1328.  
  1329. function encodeAmount(uint sercet, uint amount) public constant onlyAthCall returns( uint ){
  1330. return sercet * amount;
  1331. }
  1332.  
  1333. function decodeAmount(uint amount, uint secret) public constant onlyAthCall returns( uint ){
  1334. return amount / secret;
  1335. }
  1336.  
  1337. }
Add Comment
Please, Sign In to add comment