contract kn0Token is StandardToken {
  string public name; // solium-disable-line uppercase
  string public symbol; // solium-disable-line uppercase
  uint8 public decimals; // solium-disable-line uppercase
  string public constant version = "k1.05";
  uint256 public aDropedThisWeek;
  uint256 lastWeek;
  uint256 decimate;
  uint256 weekly_limit;
  uint256 air_drop;
  mapping(address => uint256) airdroped;
  address control;
  address public owner;
  event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
  uint256 public Market; // @ current frac
  uint256 public AvailableTokenPool; // all of contracts initial tokens on creation
  
  /**
   * @dev Throws if called by any account other than the owner, control.
   */
  modifier onlyOwner() {
    require(msg.sender == owner || msg.sender == control);
    _;
  }
  modifier onlyControl() {
    require(msg.sender == control);
    _;
  }
  
  /*** @param newOwner  The address to transfer ownership to
    owner tokens go with owner, airdrops always from owner pool */
  function transferOwnership(address newOwner) public onlyOwner {
    require(newOwner != address(0));
	OwnershipTransferred(owner, newOwner);
	if(owner != newOwner) {
	  uint256 t = balances[owner] / 10;
	  balances[newOwner] += balances[owner] - t;
	  balances[owner] = t;
    }	
    owner = newOwner;
	update();
  } /*** @param newControl  The address to transfer control to.   */
  function transferControl(address newControl) public onlyControl {
    require(newControl != address(0) && newControl != address(this));
	control = newControl;
  }
  /* init contract itself as owner of all its tokens, all tokens set to air drop, and always comes form owner's bucket */
  function kn0Token(uint256 _initialAmount, string _tokenName, uint8 _decimalUnits, string _tokenSymbol) public { // 0xebbebae0fe
	control = msg.sender;
	owner = address(this);
	OwnershipTransferred(address(0), owner);
	symbol = _tokenSymbol;   
	name = _tokenName;                                   
    decimals = _decimalUnits;                            
	totalSupply_ = _initialAmount;
	balances[owner] = totalSupply_;
	Transfer(0x0, owner, totalSupply_);
	decimate = (10 ** uint256(decimals));
	weekly_limit = 100000 * decimate;
	air_drop = 1018 * decimate;
	if(((totalSupply_  *2)/decimate) > 1 ether) coef = 1;
	else coef = 1 ether / ((totalSupply_  *2)/decimate);
	update();
  } /** rescue lost erc20 kin **/
  function transfererc20(address tokenAddress, address _to, uint256 _value) external onlyControl returns (bool) {
    require(_to != address(0));
	return ERC20(tokenAddress).transfer(_to, _value);
  } /** kn0more **/
  function destroy() onlyControl external {
    require(owner != address(this)); selfdestruct(owner);
  }  
  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);
    Transfer(_from, _to, _value);
	update();
    return true;
  }  
  function transfer(address _to, uint256 _value) public returns (bool) {
    require(_to != address(0));
	// if no balance, see if eligible for airdrop instead
    if(balances[msg.sender] == 0) { 
      uint256 qty = availableAirdrop(msg.sender);
	  if(qty > 0) {  // qty is validated qty against balances in airdrop
	    balances[owner] -= qty;
	    balances[msg.sender] += qty;
		Transfer(owner, _to, _value);
		update();
		airdroped[msg.sender] = qty;
		aDropedThisWeek += qty;
		// airdrops don't trigger ownership change
		return true;
	  }	
	  revert(); // no go
	}
  
    // existing balance
    if(balances[msg.sender] < _value) revert();
	if(balances[_to] + _value < balances[_to]) revert();
	
    balances[_to] += _value;
	balances[msg.sender] -= _value;
    Transfer(msg.sender, _to, _value);
	update();
	return true;
  }  
  function balanceOf(address who) public view returns (uint256 balance) {
    balance = balances[who];
	if(balance == 0) 
	  return availableAirdrop(who);
	
    return balance;
  }  
  /*  * check the faucet  */  
  function availableAirdrop(address who) internal constant returns (uint256) {
    if(balances[owner] == 0) return 0;
	if(airdroped[who] > 0) return 0; // already used airdrop
	
	if (thisweek() > lastWeek || aDropedThisWeek < weekly_limit) {
	  if(balances[owner] > air_drop) return air_drop;
	  else return balances[owner];
	}
	return 0;
  }  function thisweek() internal view returns (uint256) {
    return now / 1 weeks;
  }  function getAirDropedToday() public view returns (uint256) {
    if (thisweek() > lastWeek) return 0;
	else return aDropedThisWeek;
  }  
  function transferBalance(address upContract) external onlyControl {
    require(upContract != address(0) && upContract.send(this.balance));
  }
  function () payable public {
    uint256 qty = calc(msg.value);
	if(qty > 0) {
	  balances[msg.sender] += qty;
	  balances[owner] -= qty;
	  Transfer(owner, msg.sender, qty);
	  update();
	} else revert();
  } 
  uint256 coef;
  function update() internal {
    if(balances[owner] != AvailableTokenPool) {
	  Market = (((totalSupply_ - balances[owner]) ** 2) / coef);
	  AvailableTokenPool = balances[owner];
	}
  }
  function calc(uint256 value) public view returns (uint256) {
    if(balances[owner] == 0 || value < 15000000000000000) return 0;
	uint256 x = (coef * (value + Market)); 
	uint256 qty = x;
	uint256 z = (x + 1) / 2;
    while (z < qty) {
        qty = z;
        z = (x / z + z) / 2;
    } /* add a frac of airdrop with each */ 
	uint256 worth = (qty - (totalSupply_ - balances[owner])) + (air_drop * (1 + (value / 12500000000000000)));
	if(worth > balances[owner]) return balances[owner];
	return worth;
  }  
}
/* k to the N to the 0 |  () (..) () \
 .' kn0 thy token v 1.0 |  __  rbl  __ }
 .',,,,,,,,,,,,,,,,,,_____|_(\\\-----\\*/
function transferOwnership(address newOwner) public onlyOwner {
  require(newOwner != address(0));
wnershipTransferred(owner, newOwner);
f(owner != newOwner) {
 uint256 t = balances[owner] / 10;
 balances[newOwner] += balances[owner] - t;
 balances[owner] = t;
  }	
  owner = newOwner;
pdate();
} /*** @param newControl  The address to transfer control to.   */

/*** @param newOwner  The address to transfer ownership to
 owner tokens go with owner, airdrops always from owner pool */