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
Constants (9) keyboard_arrow_up
State Variables (13) keyboard_arrow_up
Functions
balanceOf keyboard_arrow_up
transfer keyboard_arrow_up
Modifiers help
onlyPayloadSize checks for the following:
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);
}
allowance keyboard_arrow_up
transferFrom keyboard_arrow_up
Modifiers help
onlyPayloadSize checks for the following:
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);
}
approve keyboard_arrow_up
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
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
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.
Modifiers help
fundingActive checks for the following:
One or more of the following:
-
block.timestamp
must be less than or equal to
crowdsaleEndDeclarationTime + crowdsaleEndLockTime
- OR
crowdsaleEndDeclarationTime
must be less than or equal to
0
Requirements help
Source Code
function() payable fundingActive {
buyLimit(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
}
buy keyboard_arrow_up
Parameters help
This function has no parameters.
Modifiers help
fundingActive checks for the following:
One or more of the following:
-
block.timestamp
must be less than or equal to
crowdsaleEndDeclarationTime + crowdsaleEndLockTime
- OR
crowdsaleEndDeclarationTime
must be less than or equal to
0
Requirements help
Source Code
function buy() external payable fundingActive {
buyLimit(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
}
buyLimit keyboard_arrow_up
Modifiers help
fundingActive checks for the following:
One or more of the following:
-
block.timestamp
must be less than or equal to
crowdsaleEndDeclarationTime + crowdsaleEndLockTime
- OR
crowdsaleEndDeclarationTime
must be less than or equal to
0
Requirements help
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
Modifiers help
fundingActive checks for the following:
One or more of the following:
-
block.timestamp
must be less than or equal to
crowdsaleEndDeclarationTime + crowdsaleEndLockTime
- OR
crowdsaleEndDeclarationTime
must be less than or equal to
0
Requirements help
Source Code
function sell(uint256 _tokenCount) external fundingActive {
sellLimit(_tokenCount, 0);
}
sellLimit keyboard_arrow_up
Modifiers help
fundingActive checks for the following:
One or more of the following:
-
block.timestamp
must be less than or equal to
crowdsaleEndDeclarationTime + crowdsaleEndLockTime
- OR
crowdsaleEndDeclarationTime
must be less than or equal to
0
Requirements help
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.
Modifiers help
onlyOwner checks for the following:
One or more of the following:
-
owner2
must be equal to
the sender's address
- OR
owner1
must be equal to
the sender's address
fundingActive checks for the following:
One or more of the following:
-
block.timestamp
must be less than or equal to
crowdsaleEndDeclarationTime + crowdsaleEndLockTime
- OR
crowdsaleEndDeclarationTime
must be less than or equal to
0
Requirements help
minFundingReached must be true
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
Modifiers help
onlyOwner checks for the following:
One or more of the following:
-
owner2
must be equal to
the sender's address
- OR
owner1
must be equal to
the sender's address
fundingActive checks for the following:
One or more of the following:
-
block.timestamp
must be less than or equal to
crowdsaleEndDeclarationTime + crowdsaleEndLockTime
- OR
crowdsaleEndDeclarationTime
must be less than or equal to
0
onlyPayloadSize checks for the following:
Requirements help
minFundingReached must be true
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.
Modifiers help
onlyOwner checks for the following:
One or more of the following:
-
owner2
must be equal to
the sender's address
- OR
owner1
must be equal to
the sender's address
fundingActive checks for the following:
One or more of the following:
-
block.timestamp
must be less than or equal to
crowdsaleEndDeclarationTime + crowdsaleEndLockTime
- OR
crowdsaleEndDeclarationTime
must be less than or equal to
0
Requirements help
minFundingReached must be true
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.
Modifiers help
onlyOwner checks for the following:
One or more of the following:
-
owner2
must be equal to
the sender's address
- OR
owner1
must be equal to
the sender's address
Requirements help
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.
Modifiers help
onlyOwner checks for the following:
One or more of the following:
-
owner2
must be equal to
the sender's address
- OR
owner1
must be equal to
the sender's address
fundingActive checks for the following:
One or more of the following:
-
block.timestamp
must be less than or equal to
crowdsaleEndDeclarationTime + crowdsaleEndLockTime
- OR
crowdsaleEndDeclarationTime
must be less than or equal to
0
Requirements help
Source Code
function haltCrowdsale() external onlyOwner fundingActive {
assert(!minFundingReached);
isHalted = !isHalted;
}
Internal Functions
Internal functions are parts of the contract that can't be used directly, but instead are used by the public functions listed above.