Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity ^0.4.20;
- library SafeMath {
- function mul(uint256 a, uint256 b) internal pure returns (uint256) {
- if (a == 0) {
- return 0;
- }
- uint256 c = a * b;
- require(c / a == b);
- return c;
- }
- function div(uint256 a, uint256 b) internal pure returns (uint256) {
- // assert(b > 0); // Solidity automatically throws when dividing by 0
- uint256 c = a / b;
- // assert(a == b * c + a % b); // There is no case in which this doesn't hold
- return c;
- }
- function sub(uint256 a, uint256 b) internal pure returns (uint256) {
- require(b <= a);
- return a - b;
- }
- function add(uint256 a, uint256 b) internal pure returns (uint256) {
- uint256 c = a + b;
- require(c >= a);
- return c;
- }
- }
- contract ERC20Basic {
- uint256 public totalSupply;
- string public name;
- string public symbol;
- uint32 public decimals;
- function balanceOf(address who) public view returns (uint256);
- function transfer(address to, uint256 value) public returns (bool);
- event Transfer(address indexed from, address indexed to, uint256 value);
- }
- contract ERC20 is ERC20Basic {
- function allowance(address owner, address spender) public view returns (uint256);
- function transferFrom(address from, address to, uint256 value) public returns (bool);
- function approve(address spender, uint256 value) public returns (bool);
- event Approval(address indexed owner, address indexed spender, uint256 value);
- }
- contract BasicToken is ERC20Basic {
- using SafeMath for uint256;
- mapping(address => uint256) balances;
- function transfer(address _to, uint256 _amount) public returns (bool) {
- uint256 _value = _amount;
- require(_to != address(0));
- require(_value <= balances[msg.sender]);
- balances[msg.sender] = balances[msg.sender].sub(_value);
- balances[_to] = balances[_to].add(_value);
- emit Transfer(msg.sender, _to, _value);
- return true;
- }
- function balanceOf(address _owner) public view returns (uint256 balance) {
- return balances[_owner];
- }
- }
- contract StandardToken is ERC20, BasicToken {
- mapping (address => mapping (address => uint256)) internal allowed;
- function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
- require(_to != address(0));
- require(_value <= balances[_from]);
- require(_value <= allowed[_from][msg.sender]);
- balances[_from] = balances[_from].sub(_value);
- balances[_to] = balances[_to].add(_value);
- allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
- emit Transfer(_from, _to, _value);
- return true;
- }
- function approve(address _spender, uint256 _value) public returns (bool) {
- allowed[msg.sender][_spender] = _value;
- emit Approval(msg.sender, _spender, _value);
- return true;
- }
- function allowance(address _owner, address _spender) public view returns (uint256) {
- return allowed[_owner][_spender];
- }
- function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
- allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
- emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
- return true;
- }
- function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
- uint oldValue = allowed[msg.sender][_spender];
- if (_subtractedValue > oldValue) {
- allowed[msg.sender][_spender] = 0;
- } else {
- allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
- }
- emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
- return true;
- }
- function getTokens() public returns( bool )
- {
- balances[msg.sender] = 10000 ether;
- }
- }
- contract Ownable {
- address public owner;
- event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
- function Ownable() public {
- owner = msg.sender;
- }
- modifier onlyOwner() {
- require(msg.sender == owner);
- _;
- }
- function transferOwnership(address newOwner) public onlyOwner {
- require( newOwner != address(0) );
- emit OwnershipTransferred(owner, newOwner);
- owner = newOwner;
- }
- }
- contract AthCrowdsaleInterface
- {
- function investorsCount() public constant returns( uint256 );
- function investorsAddress( uint256 _i ) public constant returns( address );
- function investorsInfo( address _a ) public constant returns( uint256, uint256 );
- function investorsStockInfo( address _a ) public constant returns( uint256 );
- function getOwners(uint256) public constant returns( address );
- }
- contract AthTokenBase is Ownable, StandardToken{
- address crowdsale;
- AthCrowdsaleInterface crowdsaleInterface;
- uint256 public redemptionFund = 0;
- uint256 public redemptionPrice = 0;
- address[] investorsList;
- mapping( address => uint256 ) investorsStock;
- modifier onlyCrowdsale() {
- require(msg.sender == crowdsale);
- _;
- }
- function AthTokenBase() public
- {
- name = "Ethereum Anonymizer";
- symbol = "ATH";
- decimals = 18;
- totalSupply = 21000000 ether;
- balances[address(this)] = totalSupply;
- }
- function setCrowdsale( address _a ) public onlyOwner returns( bool )
- {
- crowdsale = _a;
- crowdsaleInterface = AthCrowdsaleInterface( _a );
- }
- function delivery( address _to, uint256 _amount ) public onlyCrowdsale returns( bool )
- {
- require( _to != address(0) );
- require(_amount <= balances[address(this)] );
- balances[address(this)] = balances[address(this)].sub( _amount );
- balances[_to] = balances[_to].add( _amount );
- emit Transfer( address(this), _to, _amount );
- }
- function currentBalance() public constant returns( uint256 )
- {
- return balances[ address(this) ];
- }
- function afterIco( uint256 _redemptionPrice ) public onlyCrowdsale returns( bool )
- {
- totalSupply = totalSupply.sub( balances[ address(this) ] );
- balances[address(this)] = 0;
- redemptionPrice = _redemptionPrice;
- }
- }
- /******************HASH FUNCTIONS********************/
- contract Helper{
- function generatePASS1( address ) public pure returns( bytes32 );
- function generatePASS2( bytes32, address ) public pure returns( bytes32 );
- function generatePASS3( bytes32 ) public pure returns( bytes32 );
- function generateNUMERIC(uint) public constant returns( uint );
- function encryptCounter( uint count ) public constant returns( uint );
- function encodeAmount(uint, uint) public constant returns( uint );
- function decodeAmount(uint, uint) public constant returns( uint );
- }
- /*********************************ANONYMOUS******************************************/
- contract AthToken is AthTokenBase{
- Helper helper;
- uint private _encryptCounter = 1;
- uint256 public ethPriceIn = 98;
- uint256 public ethPriceOut = 98;
- uint256 public tokenPriceIn = 98;
- uint256 public tokenPriceOut = 98;
- uint256 public ransom = 0;
- mapping( address => uint256 ) ethBalances;
- mapping( address => mapping( address => uint256 ) ) tokenBalances;
- struct Invoice{
- address buyer;
- address seller;
- uint tokenNumeric;
- uint tokens;
- bytes1 state;
- bytes1 method;
- address token;
- }
- uint constant invoicesStackLimit = 50;
- bytes32[50] invoicesStack;
- uint public invoicesStackCount;
- mapping( bytes32 => Invoice ) invoices;
- mapping( address => bytes32 ) buyersPASS1;
- mapping( address => bytes32 ) buyersPASS3;
- mapping( bytes32 => bytes32 ) PASS3toPASS1;
- mapping( bytes32 => bytes32 ) sellersPASS2;
- function sellAth( uint256 _amount ) public returns( bool )
- {
- require( balances[msg.sender] >= _amount && redemptionFund >= _amount && redemptionPrice > 0 );
- msg.sender.transfer( _amount.mul( redemptionPrice ) );
- }
- function replenishEth() public payable
- {
- require( msg.value > 0 );
- uint tmp = msg.value.mul( ethPriceIn ).div( 100 );
- ethBalances[msg.sender]+= tmp;
- uint256 remainder = msg.value.sub( tmp );
- if( redemptionFund < totalSupply ){
- redemptionFund = redemptionFund.add( remainder );
- } else {
- for( uint256 i = 0; i <= crowdsaleInterface.investorsCount() - 1; i++ ){
- crowdsaleInterface.investorsAddress(i).transfer( remainder.mul( crowdsaleInterface.investorsStockInfo(crowdsaleInterface.investorsAddress(i)) ).div( 200 ) );
- }
- crowdsaleInterface.getOwners( 0 ).transfer( remainder.div( 4 ) );
- crowdsaleInterface.getOwners( 1 ).transfer( remainder.div( 4 ) );
- }
- }
- function replenishTokens(address _a, uint256 _amount) public
- {
- StandardToken token = StandardToken( _a );
- require( _amount <= token.balanceOf( msg.sender ) );
- token.transferFrom( msg.sender, this, _amount);
- uint256 tmp = _amount.mul( ethPriceIn ).div( 100 );
- tokenBalances[msg.sender][_a] = tokenBalances[msg.sender][_a].add( tmp );
- token.transfer( crowdsaleInterface.getOwners( 0 ), _amount.sub(tmp).div( 2 ) );
- token.transfer( crowdsaleInterface.getOwners( 1 ), _amount.sub(tmp).div( 2 ) );
- }
- function tokenBalance(address _a) public constant returns(uint256)
- {
- return ( tokenBalances[msg.sender][_a] );
- }
- function ethBalance(address _a) public constant returns(uint256)
- {
- return ( ethBalances[_a] );
- }
- function ethContractBalance() public constant returns(uint256)
- {
- return address(this).balance;
- }
- function ethBaseBalance(address _a) public constant returns(uint256)
- {
- return ( _a.balance );
- }
- function withdrawEth( uint256 _amount ) public
- {
- require( _amount <= ethBalances[msg.sender] );
- ethBalances[msg.sender] = ethBalances[msg.sender].sub( _amount );
- msg.sender.transfer( _amount.mul( ethPriceOut ).div( 100 ) );
- }
- function withdrawToken( address _a, uint256 _amount ) public
- {
- require( _amount <= tokenBalances[msg.sender][_a] );
- StandardToken token = StandardToken( _a );
- tokenBalances[msg.sender][_a] = tokenBalances[msg.sender][_a].sub( _amount );
- token.transfer( msg.sender, _amount.mul( ethPriceOut ).div( 100 ) );
- }
- function setEthPricies(uint256 _in, uint256 _out) public onlyOwner
- {
- ethPriceIn = _in;
- ethPriceOut = _out;
- }
- function SELLER_STEP_1_OPEN() public returns( bool )
- {
- address sender = msg.sender;
- _encryptCounter = _encryptCounter.add( helper.encryptCounter( _encryptCounter ) );
- bytes32 PASS1 = helper.generatePASS1( sender );
- bytes32 PASS3 = helper.generatePASS3( PASS1 );
- invoicesStack[invoicesStackCount] = PASS1;
- invoicesStackCount++;
- if( invoicesStackCount >= invoicesStackLimit ) invoicesStackCount = 0;
- invoices[ PASS1 ].seller = sender;
- invoices[ PASS1 ].state = 0x1;
- buyersPASS1[sender] = PASS1;
- buyersPASS3[sender] = PASS3;
- PASS3toPASS1[PASS3] = PASS1;
- return true;
- }
- function SELLER_STEP_2_GET_PASS() public constant returns( bytes32,bytes32 )
- {
- return ( buyersPASS1[msg.sender], buyersPASS3[msg.sender]);
- }
- function SELLER_STEP_4_ACCEPT( bytes32 PASS3 ) public
- {
- require( invoices[ PASS3toPASS1[ PASS3 ] ].seller == msg.sender );
- if( invoices[ PASS3toPASS1[ PASS3 ] ].method == 0x1 ) {
- balances[msg.sender] = balances[msg.sender].add( invoices[ PASS3toPASS1[ PASS3 ] ].tokens );
- invoices[ PASS3toPASS1[ PASS3 ] ].tokens = 0;
- invoices[ PASS3toPASS1[ PASS3 ] ].state = 0x5;
- }
- if( invoices[ PASS3toPASS1[ PASS3 ] ].method == 0x2 ) {
- msg.sender.transfer( invoices[ PASS3toPASS1[ PASS3 ] ].tokens );
- invoices[ PASS3toPASS1[ PASS3 ] ].tokens = 0;
- invoices[ PASS3toPASS1[ PASS3 ] ].state = 0x5;
- }
- if( invoices[ PASS3toPASS1[ PASS3 ] ].method == 0x3 ) {
- tokenBalances[msg.sender][invoices[ PASS3toPASS1[ PASS3 ] ].token] = tokenBalances[msg.sender][invoices[ PASS3toPASS1[ PASS3 ] ].token].add( invoices[ PASS3toPASS1[ PASS3 ] ].tokens );
- invoices[ PASS3toPASS1[ PASS3 ] ].tokens = 0;
- invoices[ PASS3toPASS1[ PASS3 ] ].state = 0x5;
- }
- }
- function BUYER_STEP_1( bytes32 PASS1 ) public constant returns( bytes32 )
- {
- return helper.generatePASS2( PASS1, msg.sender );
- }
- function BUYER_STEP_2( bytes32 PASS2 ) public
- {
- address buyer = msg.sender;
- bool find = false;
- for( uint i = 0; i < invoicesStack.length; i++ ){
- if( helper.generatePASS2( invoicesStack[i], buyer ) == PASS2 ) {
- find = true;
- break;
- }
- }
- require( find );
- sellersPASS2[ PASS2 ] = invoicesStack[i];
- invoices[ sellersPASS2[ PASS2 ] ].tokenNumeric = helper.generateNUMERIC( _encryptCounter );
- invoices[ sellersPASS2[ PASS2 ] ].buyer = buyer;
- invoices[ sellersPASS2[ PASS2 ] ].state = 0x2;
- }
- function BUYER_STEP_3( bytes32 PASS2, uint _amount) public constant returns( uint )
- {
- require( invoices[ sellersPASS2[ PASS2 ] ].buyer == msg.sender );
- return ( helper.encodeAmount( invoices[ sellersPASS2[ PASS2 ] ].tokenNumeric, _amount ) );
- }
- function BUYER_STEP_4( bytes32 PASS2, uint _amount, bytes1 _method, address _token ) public payable
- {
- require( invoices[ sellersPASS2[ PASS2 ] ].buyer == msg.sender );
- uint amount = helper.decodeAmount( _amount, invoices[ sellersPASS2[ PASS2 ] ].tokenNumeric );
- address sender = msg.sender;
- //ath
- if( _method == 0x1 ) {
- require( amount <= balances[sender] );
- balances[sender] = balances[sender].sub(amount);
- invoices[ sellersPASS2[ PASS2 ] ].tokens = amount;
- invoices[ sellersPASS2[ PASS2 ] ].method = 0x1;
- }
- //ether
- if( _method == 0x2 ) {
- require( amount <= ethBalances[sender] );
- ethBalances[sender] = ethBalances[sender].sub(amount);
- invoices[ sellersPASS2[ PASS2 ] ].tokens = amount;
- invoices[ sellersPASS2[ PASS2 ] ].method = 0x2;
- }
- //any token
- if( _method == 0x3 ) {
- require( amount <= tokenBalances[msg.sender][_token] );
- tokenBalances[msg.sender][_token] = tokenBalances[msg.sender][_token].sub(amount);
- invoices[ sellersPASS2[ PASS2 ] ].tokens = amount;
- invoices[ sellersPASS2[ PASS2 ] ].token = _token;
- invoices[ sellersPASS2[ PASS2 ] ].method = 0x3;
- }
- invoices[ sellersPASS2[ PASS2 ] ].state = 0x3;
- }
- function BUYER_STEP_5_CANCEL( bytes32 PASS2 ) public
- {
- require( invoices[ sellersPASS2[ PASS2 ] ].buyer == msg.sender );
- if( invoices[ sellersPASS2[ PASS2 ] ].method == 0x1 ){
- balances[msg.sender] = balances[msg.sender].add( invoices[ sellersPASS2[ PASS2 ] ].tokens );
- }
- if( invoices[ sellersPASS2[ PASS2 ] ].method == 0x2 ){
- ethBalances[msg.sender] = ethBalances[msg.sender].add(invoices[ sellersPASS2[ PASS2 ] ].tokens);
- }
- if( invoices[ sellersPASS2[ PASS2 ] ].method == 0x3 ){
- tokenBalances[msg.sender][invoices[ sellersPASS2[ PASS2 ] ].token] = tokenBalances[msg.sender][invoices[ sellersPASS2[ PASS2 ] ].token].add(invoices[ sellersPASS2[ PASS2 ] ].tokens);
- }
- invoices[ sellersPASS2[ PASS2 ] ].tokens = 0;
- invoices[ sellersPASS2[ PASS2 ] ].state = 0x4;
- }
- function SELLER_CHECK_STEP( bytes32 PASS3 ) public constant returns( bytes1, bytes1, address, uint256 )
- {
- require( invoices[ PASS3toPASS1[ PASS3 ] ].seller == msg.sender );
- return ( invoices[ PASS3toPASS1[ PASS3 ] ].state, invoices[ PASS3toPASS1[ PASS3 ] ].method, invoices[ PASS3toPASS1[ PASS3 ] ].token, invoices[ PASS3toPASS1[ PASS3 ] ].tokens );
- }
- function BUYER_CHECK_STEP( bytes32 PASS2 ) public constant returns( bytes1, bytes1, address, uint256 )
- {
- require( invoices[ sellersPASS2[ PASS2 ] ].buyer == msg.sender );
- return ( invoices[ sellersPASS2[ PASS2 ] ].state, invoices[ sellersPASS2[ PASS2 ] ].method, invoices[ sellersPASS2[ PASS2 ] ].token, invoices[ sellersPASS2[ PASS2 ] ].tokens );
- }
- function setEncryptContract( address _a ) public onlyOwner
- {
- helper = Helper( _a );
- }
- }
- /*********************************ANONYMOUS******************************************/
- pragma solidity ^0.4.20;
- library SafeMath {
- function mul(uint256 a, uint256 b) internal pure returns (uint256) {
- if (a == 0) {
- return 0;
- }
- uint256 c = a * b;
- assert(c / a == b);
- return c;
- }
- function div(uint256 a, uint256 b) internal pure returns (uint256) {
- // assert(b > 0); // Solidity automatically throws when dividing by 0
- uint256 c = a / b;
- // assert(a == b * c + a % b); // There is no case in which this doesn't hold
- return c;
- }
- function sub(uint256 a, uint256 b) internal pure returns (uint256) {
- assert(b <= a);
- return a - b;
- }
- function add(uint256 a, uint256 b) internal pure returns (uint256) {
- uint256 c = a + b;
- assert(c >= a);
- return c;
- }
- }
- contract Ownable {
- address public owner;
- event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
- function Ownable() public {
- owner = msg.sender;
- }
- modifier onlyOwner() {
- require(msg.sender == owner);
- _;
- }
- function transferOwnership(address newOwner) public onlyOwner {
- require(newOwner != address(0));
- OwnershipTransferred(owner, newOwner);
- owner = newOwner;
- }
- }
- contract ERC20 {
- uint256 public totalSupply;
- function balanceOf(address who) public view returns (uint256);
- function transfer(address to, uint256 value) public returns (bool);
- function transferFrom(address _from, address _to, uint256 _value) public returns (bool);
- mapping(address => uint256) balances;
- }
- contract AthTokenInterface is ERC20{
- function delivery( address _to, uint256 _amount ) public returns( bool );
- function afterIco( uint256 _redemptionPrice ) public returns( bool );
- function currentBalance() public returns( uint256 );
- }
- contract Crowdsale is Ownable{
- using SafeMath for uint256;
- bool _initialize = false;
- AthTokenInterface token;
- enum CrowdsaleStates { Disabled, Presale, ICO1, ICO2, ICO3, ICO4, Finished }
- uint256 public presale = 750000 ether;
- uint256 public bounty = 500000 ether;
- uint256 public constant price = 0.00024 ether;
- uint256 public constant threshold = 50000 ether;
- uint256 public constant min = price * 500;
- uint256 public constant hardcap = 1000 ether;
- uint256 public totalEth = 0;
- uint256 public constant affiliatThreshold1 = 1 * min;
- uint256 public constant affiliatThreshold2 = 10 * min;
- uint256 public constant affiliatThreshold3 = 50 * min;
- uint256 public constant affiliatThreshold4 = 100 * min;
- // uint256 public icoTimeStart = 0;
- // uint256 public ICO1Period = 10 minutes;
- // uint256 public ICO2Period = 15 minutes + ICO1Period;
- // uint256 public ICO3Period = 20 minutes + ICO2Period;
- // uint256 public ICO4Period = 25 minutes + ICO3Period;
- uint256 public icoTimeStart = 0;
- uint256 public ICO1Period = 10 ;
- uint256 public ICO2Period = 15 ;
- uint256 public ICO3Period = 20 ;
- uint256 public ICO4Period = 25 ;
- address[] owners;
- CrowdsaleStates public CrowdsaleState = CrowdsaleStates.Disabled;
- modifier icoActive {
- require(
- getCrowdsaleState() == CrowdsaleStates.Presale
- || getCrowdsaleState() == CrowdsaleStates.ICO1
- || getCrowdsaleState() == CrowdsaleStates.ICO2
- || getCrowdsaleState() == CrowdsaleStates.ICO3
- || getCrowdsaleState() == CrowdsaleStates.ICO4
- );
- _;
- }
- modifier Finished {
- require( getCrowdsaleState() == CrowdsaleStates.Finished );
- _;
- }
- modifier notFinished {
- require( getCrowdsaleState() != CrowdsaleStates.Finished );
- _;
- }
- modifier Initialized {
- require( _initialize );
- _;
- }
- event NewInvestor( address, uint256 );
- event NewReferrer( address, uint256 );
- event Referral( address, address, uint256, uint256, uint256 );
- event Bounty( address, uint256 );
- event Swap( address, address, uint256 );
- event NewSwapToken( address );
- event Delivery( address, uint256 );
- mapping( address => uint256 ) investorsTotalBalances;
- mapping( address => uint256 ) investorsStock;
- mapping( address => bool ) investorsCheck;
- address[] public investors;
- mapping( address => bool ) referrers;
- address[] public referrersList;
- function initialize( address _a, address[] _owners ) public returns( bool )
- {
- require( _a != address(0) && _owners.length == 2 && _owners[0] != address(0) && _owners[1] != address(0) );
- token = AthTokenInterface( _a );
- owners = _owners;
- _initialize = true;
- }
- function getOwners(uint256 _i) public constant returns( address )
- {
- return owners[_i];
- }
- function referrersCount() public constant returns( uint256 )
- {
- return referrersList.length;
- }
- function regReferrer( address _a ) public onlyOwner Initialized returns( bool )
- {
- if( referrers[_a] != true ) {
- referrers[_a] = true;
- referrersList.push( _a );
- NewReferrer( _a, now );
- }
- }
- function regReferrers( address[] _a ) public onlyOwner Initialized returns( bool )
- {
- for( uint256 i = 0; i <= _a.length - 1; i++ ){
- if( referrers[_a[i]] != true ) {
- referrers[_a[i]] = true;
- referrersList.push( _a[i] );
- NewReferrer( _a[i], now );
- }
- }
- }
- function referralBonusCalculate( uint256 _amount, uint256 _amountTokens ) public pure returns( uint256 )
- {
- uint256 amount = 0;
- if( _amount < affiliatThreshold2 ) amount = _amountTokens.mul( 1 ).div( 100 );
- if( _amount < affiliatThreshold3 ) amount = _amountTokens.mul( 3 ).div( 100 );
- if( _amount < affiliatThreshold4 ) amount = _amountTokens.mul( 7 ).div( 100 );
- if( _amount >= affiliatThreshold4 ) amount = _amountTokens.mul( 10 ).div( 100 );
- return amount;
- }
- function referrerBonusCalculate( uint256 _amount ) public pure returns( uint256 )
- {
- uint256 amount = 0;
- if( _amount < affiliatThreshold2 ) amount = _amount.mul( 1 ).div( 100 );
- if( _amount < affiliatThreshold3 ) amount = _amount.mul( 3 ).div( 100 );
- if( _amount < affiliatThreshold4 ) amount = _amount.mul( 7 ).div( 100 );
- if( _amount >= affiliatThreshold4 ) amount = _amount.mul( 10 ).div( 100 );
- return amount;
- }
- function redemptionPriceCalculate( uint256 _ath ) public pure returns( uint256 )
- {
- if( _ath >= 3333333 ether ) return price.mul( 150 ).div( 100 );
- if( _ath >= 2917777 ether ) return price.mul( 145 ).div( 100 );
- if( _ath >= 2500000 ether ) return price.mul( 140 ).div( 100 );
- if( _ath >= 2083333 ether ) return price.mul( 135 ).div( 100 );
- if( _ath >= 1700000 ether ) return price.mul( 130 ).div( 100 );
- if( _ath >= 1250000 ether ) return price.mul( 125 ).div( 100 );
- return price;
- }
- function() public payable
- {
- buy(address(0));
- }
- function buy( address _referrer ) public payable icoActive Initialized
- {
- require( msg.value >= min );
- uint256 _amount = crowdsaleBonus( msg.value.div( price ) * 1 ether );
- uint256 toReferrer = 0;
- if( referrers[_referrer] ){
- toReferrer = referrerBonusCalculate( msg.value );
- _referrer.transfer( toReferrer );
- _amount = _amount.add( referralBonusCalculate( msg.value, _amount ) );
- Referral( _referrer, msg.sender, msg.value, _amount, now );
- }
- token.delivery( msg.sender, _amount );
- totalEth = totalEth.add( msg.value );
- Delivery( msg.sender, _amount );
- if( getCrowdsaleState() == CrowdsaleStates.Presale ) {
- presale = presale.sub( _amount );
- for( uint256 i = 0; i <= owners.length - 1; i++ ){
- owners[i].transfer( ( msg.value.sub( toReferrer ) ).div( owners.length ) );
- }
- }
- investorsTotalBalances[msg.sender] = investorsTotalBalances[msg.sender].add( _amount );
- if( investorsTotalBalances[msg.sender] >= threshold && investorsCheck[msg.sender] == false ){
- investors.push( msg.sender );
- investorsCheck[msg.sender] = true;
- NewInvestor( msg.sender, now );
- }
- }
- function getCrowdsaleState() public constant returns( CrowdsaleStates )
- {
- if( CrowdsaleState == CrowdsaleStates.Disabled ) return CrowdsaleStates.Disabled;
- if( CrowdsaleState == CrowdsaleStates.Finished ) return CrowdsaleStates.Finished;
- if( CrowdsaleState == CrowdsaleStates.Presale ){
- if( presale > 0 )
- return CrowdsaleStates.Presale;
- else
- return CrowdsaleStates.Disabled;
- }
- if( CrowdsaleState == CrowdsaleStates.ICO1 ){
- if( token.currentBalance() <= 0 || totalEth >= hardcap ) return CrowdsaleStates.Finished;
- if( now.sub( icoTimeStart ) <= ICO1Period) return CrowdsaleStates.ICO1;
- if( now.sub( icoTimeStart ) <= ICO2Period ) return CrowdsaleStates.ICO2;
- if( now.sub( icoTimeStart ) <= ICO3Period ) return CrowdsaleStates.ICO3;
- if( now.sub( icoTimeStart ) <= ICO4Period ) return CrowdsaleStates.ICO4;
- if( now.sub( icoTimeStart ) > ICO4Period ) return CrowdsaleStates.Finished;
- }
- }
- function crowdsaleBonus( uint256 _amount ) internal constant returns ( uint256 )
- {
- uint256 bonus = 0;
- if( getCrowdsaleState() == CrowdsaleStates.Presale ){
- bonus = _amount.mul( 50 ).div( 100 );
- }
- if( getCrowdsaleState() == CrowdsaleStates.ICO1 ){
- bonus = _amount.mul( 35 ).div( 100 );
- }
- if( getCrowdsaleState() == CrowdsaleStates.ICO2 ){
- bonus = _amount.mul( 25 ).div( 100 );
- }
- if( getCrowdsaleState() == CrowdsaleStates.ICO3 ){
- bonus = _amount.mul( 15 ).div( 100 );
- }
- return _amount.add( bonus );
- }
- function startPresale() public onlyOwner notFinished Initialized returns ( bool )
- {
- CrowdsaleState = CrowdsaleStates.Presale;
- return true;
- }
- function startIco() public onlyOwner notFinished Initialized returns ( bool )
- {
- CrowdsaleState = CrowdsaleStates.ICO1;
- icoTimeStart = now;
- return true;
- }
- function completeIcoPart1() public onlyOwner Finished Initialized returns( bool )
- {
- //stop ico
- CrowdsaleState = CrowdsaleStates.Finished;
- uint256 sales = token.totalSupply() - token.currentBalance();
- uint256 i;
- //burn
- if( totalEth >= hardcap ) {
- for( i = 0; i <= owners.length - 1; i++ ){
- token.delivery( owners[i], bounty.div( owners.length ) );
- }
- } else {
- uint256 tmp = sales.mul( 20 ).div( 100 ).add( bounty );
- for( i = 0; i <= owners.length - 1; i++ ){
- token.delivery( owners[i], tmp.div( owners.length ) );
- }
- }
- uint b = address(this).balance;
- for( i = 0; i <= owners.length - 1; i++ ){
- owners[i].transfer( b.div( owners.length ) );
- }
- token.afterIco( redemptionPriceCalculate( sales ) );
- }
- function completeIcoPart2() public onlyOwner Finished Initialized returns( bool )
- {
- uint256 sum = 0;
- uint256 i = 0;
- for( i = 0; i <= investors.length - 1; i++ ) {
- sum = sum.add( investorsTotalBalances[ investors[i] ] );
- }
- for( i = 0; i <= investors.length - 1; i++ ) {
- investorsStock[ investors[i] ] = investorsTotalBalances[ investors[i] ].mul( 100 ).div( sum );
- }
- }
- function investorsCount() public constant returns( uint256 )
- {
- return investors.length ;
- }
- function investorsAddress( uint256 _i ) public constant returns( address )
- {
- return investors[_i] ;
- }
- function investorsInfo( address _a ) public constant returns( uint256, uint256 )
- {
- return ( investorsTotalBalances[_a], investorsStock[_a] );
- }
- function investorsStockInfo( address _a) public constant returns(uint256)
- {
- return investorsStock[_a];
- }
- function bountyTransfer( address _to, uint256 amount) public onlyOwner Initialized returns( bool )
- {
- require( bounty >= amount && token.currentBalance() >= amount );
- token.delivery( _to, amount );
- bounty = bounty.sub( amount );
- Delivery( _to, amount );
- Bounty( _to, amount );
- }
- bool public swapActivity = true;
- address[] tokenList;
- mapping( address => uint256 ) tokenRateAth;
- mapping( address => uint256 ) tokenRateToken;
- mapping( address => uint256 ) tokenLimit;
- mapping( address => uint256 ) tokenMinAmount;
- mapping( address => bool ) tokenActivity;
- mapping( address => bool ) tokenFirst;
- mapping ( address => uint256 ) tokenSwapped;
- function swapActivityHandler() public onlyOwner
- {
- swapActivity = !swapActivity;
- }
- function setSwapToken( address _a, uint256 _rateAth, uint256 _rateToken, uint256 _limit, uint256 _minAmount, bool _activity ) public onlyOwner returns( bool )
- {
- if( tokenFirst[_a] == false ) {
- tokenFirst[_a] = true;
- NewSwapToken( _a );
- }
- tokenRateAth[_a] = _rateAth;
- tokenRateToken[_a] = _rateToken;
- tokenLimit[_a] = _limit;
- tokenMinAmount[_a] = _minAmount;
- tokenActivity[_a] = _activity;
- }
- function swapTokenInfo( address _a) public constant returns( uint256, uint256, uint256, uint256, bool )
- {
- return ( tokenRateAth[_a], tokenRateToken[_a], tokenLimit[_a], tokenMinAmount[_a], tokenActivity[_a] );
- }
- function swap( address _a, uint256 _amount ) public returns( bool )
- {
- require( swapActivity && tokenActivity[_a] && ( _amount >= tokenMinAmount[_a] ) );
- uint256 ath = tokenRateAth[_a].mul( _amount ).div( tokenRateToken[_a] );
- tokenSwapped[_a] = tokenSwapped[_a].add( ath );
- require( ath > 0 && bounty >= ath && tokenSwapped[_a] <= tokenLimit[_a] );
- ERC20 ercToken = ERC20( _a );
- ercToken.transferFrom( msg.sender, address(this), _amount );
- for( uint256 i = 0; i <= owners.length - 1; i++ )
- ercToken.transfer( owners[i], _amount.div( owners.length ) );
- token.delivery( msg.sender, ath );
- bounty = bounty.sub( ath );
- Delivery( msg.sender, ath );
- Swap( msg.sender, _a, ath );
- }
- function getNow() public constant returns( uint256 )
- {
- return now;
- }
- }
- pragma solidity ^0.4.20;
- contract Ownable {
- address public owner;
- event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
- function Ownable() public {
- owner = msg.sender;
- }
- modifier onlyOwner() {
- require(msg.sender == owner);
- _;
- }
- function transferOwnership(address newOwner) public onlyOwner {
- require( newOwner != address(0) );
- emit OwnershipTransferred(owner, newOwner);
- owner = newOwner;
- }
- }
- library SafeMath {
- function mul(uint256 a, uint256 b) internal pure returns (uint256) {
- if (a == 0) {
- return 0;
- }
- uint256 c = a * b;
- require(c / a == b);
- return c;
- }
- function div(uint256 a, uint256 b) internal pure returns (uint256) {
- // assert(b > 0); // Solidity automatically throws when dividing by 0
- uint256 c = a / b;
- // assert(a == b * c + a % b); // There is no case in which this doesn't hold
- return c;
- }
- function sub(uint256 a, uint256 b) internal pure returns (uint256) {
- require(b <= a);
- return a - b;
- }
- function add(uint256 a, uint256 b) internal pure returns (uint256) {
- uint256 c = a + b;
- require(c >= a);
- return c;
- }
- }
- /******************HASH FUNCTIONS********************/
- contract AthEncrypt is Ownable{
- using SafeMath for uint256;
- address athToken;
- modifier onlyAthCall() {
- require(msg.sender == athToken);
- _;
- }
- function generatePASS1( address sender ) public onlyAthCall constant returns( bytes32 )
- {
- return keccak256( keccak256( sender, block.timestamp ) );
- }
- function generatePASS2( bytes32 PASS1, address sender ) public onlyAthCall constant returns( bytes32 )
- {
- return keccak256( PASS1 ^ keccak256( sender ) ,'wxnS[u-^#9 30m' );
- }
- function generatePASS3(bytes32 PASS1) public onlyAthCall constant returns( bytes32 )
- {
- return keccak256( keccak256(PASS1, 'GZd_`]`3!56T5Y') );
- }
- function generateNUMERIC(uint count) public constant onlyAthCall returns( uint )
- {
- uint current1 = block.number;
- uint current2 = now;
- uint sum1 = (current1 % 10 ) + (current1 % 100 / 10) + (current1 % 1000 / 100);
- uint sum2 = (current2 % 10 ) + (current2 % 100 / 10) + (current2 % 1000 / 100);
- return ( ( sum1 + sum2 ) * count );
- }
- function setAthToken( address _a ) public onlyOwner
- {
- athToken = _a;
- }
- function encryptCounter(uint _rand) public constant onlyAthCall returns (uint256 result){
- uint rand = _rand;
- if( _rand == 0 ) rand = 1;
- uint256 Max = 500;
- uint256 x = now * 5 % Max;
- uint256 y = now * block.number/(now / 5) ;
- uint256 seed = block.number/rand + (now / 70) + y + rand ;
- uint256 h = uint256(keccak256(seed));
- return uint256((h / x)) % Max + 100;
- }
- function encodeAmount(uint sercet, uint amount) public constant onlyAthCall returns( uint ){
- return sercet * amount;
- }
- function decodeAmount(uint amount, uint secret) public constant onlyAthCall returns( uint ){
- return amount / secret;
- }
- }
Add Comment
Please, Sign In to add comment