Blockwell

Adshares Token

ERC20

This contract is an ERC20 token.

Name Adshares Token
Symbol ADST
Decimals 0
Total Supply 19,379,103 ADST

About

Stats

Public Functions 17
Event Types 6
Code Size 17,854 bytes

Library Use

Uses SafeMath for uint.

Approval Event

Parameters help
owner
address help
spender
address help
value
uint help

LogBuy Event

Parameters help
who
address help
tokens
uint help
purchaseValue
uint help
supplyAfter
uint help

LogCrowdsaleEnd Event

Parameters help
completed
bool help

LogSell Event

Parameters help
who
address help
tokens
uint help
saleValue
uint help
supplyAfter
uint help

LogWithdraw Event

Parameters help
amount
uint help

Transfer Event

Parameters help
from
address help
to
address help
value
uint help

Functions Expand All Collapse All

balanceOf keyboard_arrow_up

Parameters help

Name Type
_owner
address help

Properties

Visibility help public
Mutability help constant
Source Code
  function balanceOf(address _owner) constant returns (uint balance) {
    return balances[_owner];
  }

transfer keyboard_arrow_up

Parameters help

Name Type
_to
address help
_value
uint help

Properties

Visibility help public
Mutability help transaction

Modifiers help

Source Code
  function transfer(address _to, uint _value) onlyPayloadSize(2 * 32) {
    balances[msg.sender] = balances[msg.sender].sub(_value);
    balances[_to] = balances[_to].add(_value);
    Transfer(msg.sender, _to, _value);
  }

allowance keyboard_arrow_up

Parameters help

Name Type
_owner
address help
_spender
address help

Properties

Visibility help public
Mutability help constant
Source Code
  function allowance(address _owner, address _spender) constant returns (uint remaining) {
    return allowed[_owner][_spender];
  }

transferFrom keyboard_arrow_up

Parameters help

Name Type
_from
address help
_to
address help
_value
uint help

Properties

Visibility help public
Mutability help transaction

Modifiers help

Source Code
  function transferFrom(address _from, address _to, uint _value) onlyPayloadSize(3 * 32) {
    var _allowance = allowed[_from][msg.sender];

    // Check is not needed because sub(_allowance, _value) will already throw if this condition is not met
    // if (_value > _allowance) throw;

    balances[_to] = balances[_to].add(_value);
    balances[_from] = balances[_from].sub(_value);
    allowed[_from][msg.sender] = _allowance.sub(_value);
    Transfer(_from, _to, _value);
  }

approve keyboard_arrow_up

Parameters help

Name Type
_spender
address help
_value
uint help

Properties

Visibility help public
Mutability help transaction

Requirements help

One or more of the following:
Source Code
  function approve(address _spender, uint _value) {

    // To change the approve amount you first have to reduce the addresses`
    //  allowance to zero by calling `approve(_spender, 0)` if it is not
    //  already 0 to mitigate the race condition described here:
    //  https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
    if ((_value != 0) && (allowed[msg.sender][_spender] != 0)) throw;

    allowed[msg.sender][_spender] = _value;
    Approval(msg.sender, _spender, _value);
  }

getBuyPrice keyboard_arrow_up

Parameters help

Name Type
_bidValue
uint help

Properties

Visibility help public
Mutability help constant
Source Code
    function getBuyPrice(uint _bidValue) constant returns (uint tokenCount, uint purchaseValue) {

        // Token price formula is twofold. We have flat pricing below tokenCreationMin, 
        // and above that price linarly increases with supply. 

        uint flatTokenCount;
        uint startSupply;
        uint linearBidValue;
        
        if(totalSupply < tokenCreationMin) {
            uint maxFlatTokenCount = _bidValue.div(tokenPriceMin);
            // entire purchase in flat pricing
            if(totalSupply.add(maxFlatTokenCount) <= tokenCreationMin) {
                return (maxFlatTokenCount, maxFlatTokenCount.mul(tokenPriceMin));
            }
            flatTokenCount = tokenCreationMin.sub(totalSupply);
            linearBidValue = _bidValue.sub(flatTokenCount.mul(tokenPriceMin));
            startSupply = tokenCreationMin;
        } else {
            flatTokenCount = 0;
            linearBidValue = _bidValue;
            startSupply = totalSupply;
        }
        
        // Solves quadratic equation to calculate maximum token count that can be purchased
        uint currentPrice = tokenPriceMin.mul(startSupply).div(tokenCreationMin);
        uint delta = (2 * startSupply).mul(2 * startSupply).add(linearBidValue.mul(4 * 1 * 2 * startSupply).div(currentPrice));

        uint linearTokenCount = delta.sqrt().sub(2 * startSupply).div(2);
        uint linearAvgPrice = currentPrice.add((startSupply+linearTokenCount+1).mul(tokenPriceMin).div(tokenCreationMin)).div(2);
        
        // double check to eliminate rounding errors
        linearTokenCount = linearBidValue / linearAvgPrice;
        linearAvgPrice = currentPrice.add((startSupply+linearTokenCount+1).mul(tokenPriceMin).div(tokenCreationMin)).div(2);
        
        purchaseValue = linearTokenCount.mul(linearAvgPrice).add(flatTokenCount.mul(tokenPriceMin));
        return (
            flatTokenCount + linearTokenCount,
            purchaseValue
        );
     }

getSellPrice keyboard_arrow_up

Parameters help

Name Type
_askSizeTokens
uint help

Properties

Visibility help public
Mutability help constant
Source Code
    function getSellPrice(uint _askSizeTokens) constant returns (uint saleValue) {
        
        uint flatTokenCount;
        uint linearTokenMin;
        
        if(totalSupply <= tokenCreationMin) {
            return tokenPriceMin * _askSizeTokens;
        }
        if(totalSupply.sub(_askSizeTokens) < tokenCreationMin) {
            flatTokenCount = tokenCreationMin - totalSupply.sub(_askSizeTokens);
            linearTokenMin = tokenCreationMin;
        } else {
            flatTokenCount = 0;
            linearTokenMin = totalSupply.sub(_askSizeTokens);
        }
        uint linearTokenCount = _askSizeTokens - flatTokenCount;
        
        uint minPrice = (linearTokenMin).mul(tokenPriceMin).div(tokenCreationMin);
        uint maxPrice = (totalSupply+1).mul(tokenPriceMin).div(tokenCreationMin);
        
        uint linearAveragePrice = minPrice.add(maxPrice).div(2);
        return linearAveragePrice.mul(linearTokenCount).add(flatTokenCount.mul(tokenPriceMin));
    }

constructor keyboard_arrow_up

Parameters help

This function has no parameters.

Properties

Visibility help public
Mutability help payable
Source Code
    function() payable fundingActive
    {
        buyLimit(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
    }

buy keyboard_arrow_up

Parameters help

This function has no parameters.

Properties

Visibility help public
Mutability help payable
Source Code
    function buy() payable external fundingActive {
        buyLimit(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);    
    }

buyLimit keyboard_arrow_up

Parameters help

Name Type
_maxPrice
uint help

Properties

Visibility help public
Mutability help payable
Source Code
    function buyLimit(uint _maxPrice) payable public fundingActive {
        require(msg.value >= tokenPriceMin);
        assert(!isHalted);
        
        uint boughtTokens;
        uint averagePrice;
        uint purchaseValue;
        
        (boughtTokens, purchaseValue) = getBuyPrice(msg.value);
        if(boughtTokens == 0) { 
            // bid to small, return ether and abort
            msg.sender.transfer(msg.value);
            return; 
        }
        averagePrice = purchaseValue.div(boughtTokens);
        if(averagePrice > _maxPrice) { 
            // price too high, return ether and abort
            msg.sender.transfer(msg.value);
            return; 
        }
        assert(averagePrice >= tokenPriceMin);
        assert(purchaseValue <= msg.value);
        
        totalSupply = totalSupply.add(boughtTokens);
        balances[msg.sender] = balances[msg.sender].add(boughtTokens);
        
        if(!minFundingReached && totalSupply >= tokenCreationMin) {
            minFundingReached = true;
            fundingUnlockTime = block.timestamp;
            // this.balance contains ether sent in this message
            unlockedBalance += this.balance.sub(msg.value).div(tradeSpreadInvert);
        }
        if(minFundingReached) {
            unlockedBalance += purchaseValue.div(tradeSpreadInvert);
        }
        
        LogBuy(msg.sender, boughtTokens, purchaseValue, totalSupply);
        
        if(msg.value > purchaseValue) {
            msg.sender.transfer(msg.value.sub(purchaseValue));
        }
    }

sell keyboard_arrow_up

Parameters help

Name Type
_tokenCount
uint help

Properties

Visibility help public
Mutability help transaction
Source Code
    function sell(uint _tokenCount) external fundingActive {
        sellLimit(_tokenCount, 0);
    }

sellLimit keyboard_arrow_up

Parameters help

Name Type
_tokenCount
uint help
_minPrice
uint help

Properties

Visibility help public
Mutability help transaction
Source Code
    function sellLimit(uint _tokenCount, uint _minPrice) public fundingActive {
        require(_tokenCount > 0);

        assert(balances[msg.sender] >= _tokenCount);
        
        uint saleValue = getSellPrice(_tokenCount);
        uint averagePrice = saleValue.div(_tokenCount);
        assert(averagePrice >= tokenPriceMin);
        if(minFundingReached) {
            averagePrice -= averagePrice.div(tradeSpreadInvert);
            saleValue -= saleValue.div(tradeSpreadInvert);
        }
        
        if(averagePrice < _minPrice) {
            // price too high, abort
            return;
        }
        // not enough ether for buyback
        assert(saleValue <= this.balance);
          
        totalSupply = totalSupply.sub(_tokenCount);
        balances[msg.sender] = balances[msg.sender].sub(_tokenCount);
        
        LogSell(msg.sender, _tokenCount, saleValue, totalSupply);
        
        msg.sender.transfer(saleValue);
    }

unlockFunds keyboard_arrow_up

Parameters help

This function has no parameters.

Properties

Visibility help public
Mutability help transaction

Modifiers help

Source Code
    function unlockFunds() external onlyOwner fundingActive {
        assert(minFundingReached);
        assert(block.timestamp >= fundingUnlockTime);
        
        uint unlockedAmount = getLockedBalance().div(fundingUnlockFractionInvert);
        unlockedBalance += unlockedAmount;
        assert(getLockedBalance() > 0);
        
        fundingUnlockTime += fundingUnlockPeriod;
    }

withdrawFunds keyboard_arrow_up

Parameters help

Name Type
_value
uint help

Properties

Visibility help public
Mutability help transaction

Modifiers help

Source Code
    function withdrawFunds(uint _value) external onlyOwner fundingActive onlyPayloadSize(32) {
        require(_value <= unlockedBalance);
        assert(minFundingReached);
             
        unlockedBalance -= _value;
        withdrawnBalance += _value;
        LogWithdraw(_value);
        
        withdrawAddress.transfer(_value);
    }

declareCrowdsaleEnd keyboard_arrow_up

Parameters help

This function has no parameters.

Properties

Visibility help public
Mutability help transaction

Modifiers help

Source Code
    function declareCrowdsaleEnd() external onlyOwner fundingActive {
        assert(minFundingReached);
        assert(crowdsaleEndDeclarationTime == 0);
        
        crowdsaleEndDeclarationTime = block.timestamp;
        LogCrowdsaleEnd(false);
    }

confirmCrowdsaleEnd keyboard_arrow_up

Parameters help

This function has no parameters.

Properties

Visibility help public
Mutability help transaction
Source Code
    function confirmCrowdsaleEnd() external onlyOwner {
        assert(crowdsaleEndDeclarationTime > 0 && block.timestamp > crowdsaleEndDeclarationTime + crowdsaleEndLockTime);
        
        LogCrowdsaleEnd(true);
        withdrawAddress.transfer(this.balance);
    }

haltCrowdsale keyboard_arrow_up

Parameters help

This function has no parameters.

Properties

Visibility help public
Mutability help transaction

Modifiers help

Requirements help

Source Code
    function haltCrowdsale() external onlyOwner fundingActive {
        assert(!minFundingReached);
        isHalted = !isHalted;
    }