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.

Events (6) keyboard_arrow_up

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

name Constant

string help
Adshares Token

symbol Constant

string help
ADST

decimals Constant

uint help
0

tokenCreationMin Constant

uint help
10000000

tokenPriceMin Constant

uint help
0.0004 ether

tradeSpreadInvert Constant

uint help
50

crowdsaleEndLockTime Constant

uint help
1 weeks

fundingUnlockPeriod Constant

uint help
1 weeks

fundingUnlockFractionInvert Constant

uint help
100

crowdsaleStartBlock Variable

uint help

owner1 Variable

address help

owner2 Variable

address help

withdrawAddress Variable

address help

minFundingReached Variable

bool help

crowdsaleEndDeclarationTime Variable

uint help

fundingUnlockTime Variable

uint help

unlockedBalance Variable

uint help

withdrawnBalance Variable

uint help

isHalted Variable

bool help

totalSupply Variable

uint help

allowed Variable

mapping(address => mapping(address => uint)) help
Internal Variable

balances Variable

mapping(address => uint) help
Internal Variable

Functions Expand All Collapse All

Parameters help

Name Type
_owner
address help

Properties

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

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, uint256 _value) onlyPayloadSize(2 * 32) {
  balances[msg.sender] = balances[msg.sender].sub(_value);
  balances[_to] = balances[_to].add(_value);
  Transfer(msg.sender, _to, _value);
}

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 (uint256 remaining)
{
  return allowed[_owner][_spender];
}

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,
  uint256 _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);
}

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, uint256 _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(uint256 _bidValue)
  constant
  returns (uint256 tokenCount, uint256 purchaseValue)
{
  // Token price formula is twofold. We have flat pricing below tokenCreationMin,
  // and above that price linarly increases with supply.

  uint256 flatTokenCount;
  uint256 startSupply;
  uint256 linearBidValue;

  if (totalSupply < tokenCreationMin) {
    uint256 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
  uint256 currentPrice = tokenPriceMin.mul(startSupply).div(tokenCreationMin);
  uint256 delta = (2 * startSupply).mul(2 * startSupply).add(
    linearBidValue.mul(4 * 1 * 2 * startSupply).div(currentPrice)
  );

  uint256 linearTokenCount = delta.sqrt().sub(2 * startSupply).div(2);
  uint256 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(uint256 _askSizeTokens)
  constant
  returns (uint256 saleValue)
{
  uint256 flatTokenCount;
  uint256 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);
  }
  uint256 linearTokenCount = _askSizeTokens - flatTokenCount;

  uint256 minPrice = (linearTokenMin).mul(tokenPriceMin).div(tokenCreationMin);
  uint256 maxPrice = (totalSupply + 1).mul(tokenPriceMin).div(tokenCreationMin);

  uint256 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() external payable 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(uint256 _maxPrice) public payable fundingActive {
  require(msg.value >= tokenPriceMin);
  assert(!isHalted);

  uint256 boughtTokens;
  uint256 averagePrice;
  uint256 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(uint256 _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(uint256 _tokenCount, uint256 _minPrice)
  public
  fundingActive
{
  require(_tokenCount > 0);

  assert(balances[msg.sender] >= _tokenCount);

  uint256 saleValue = getSellPrice(_tokenCount);
  uint256 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);

  uint256 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(uint256 _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;
}

Internal Functions Expand All Collapse All

Internal functions are parts of the contract that can't be used directly, but instead are used by the public functions listed above.

internal AdsharesToken.getLockedBalance keyboard_arrow_up

Parameters help

This function has no parameters.

Properties

Visibility help private
Mutability help constant
Source Code
function getLockedBalance() private constant returns (uint256 lockedBalance) {
  return this.balance.sub(unlockedBalance);
}