comment
stringlengths 11
2.99k
| function_code
stringlengths 165
3.15k
| version
stringclasses 80
values |
---|---|---|
/* Initializes contract with initial supply tokens to the creator of the contract */ | function KEKEcon(){
balanceOf[msg.sender] = 100000000000000000; // Give the creator all initial tokens
totalSupply = 100000000000000000; // Update total supply
name = "KEKEcon"; // Set the name for display purposes
symbol = "KEKEcon"; // Set the symbol for display purposes
decimals = 8; // Amount of decimals for display purposes
} | 0.4.23 |
/* Internal transfer, only can be called by this contract */ | function _transfer(address _from, address _to, uint _value) internal {
require (_to != 0x0); // Prevent transfer to 0x0 address. Use burn() instead
require (balanceOf[_from] >= _value); // Check if the sender has enough
require (balanceOf[_to] + _value > balanceOf[_to]); // Check for overflows
balanceOf[_from] -= _value; // Subtract from the sender
balanceOf[_to] += _value; // Add the same to the recipient
Transfer(_from, _to, _value);
} | 0.4.23 |
/// @notice Remove `_value` tokens from the system irreversibly
/// @param _value the amount of money to burn | function burn(uint256 _value) returns (bool success) {
require (balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
Burn(msg.sender, _value);
return true;
} | 0.4.23 |
/**
* @dev Distributes the rewards to the consumers. Returns the amount of customers that received tokens. Can only be called by Owner
* @param dests Array of cosumer addresses
* @param values Array of token amounts to distribute to each client
*/ | function multisend(address[] dests, uint256[] values) public onlyOwner returns (uint256) {
assert(dests.length == values.length);
uint256 i = 0;
while (i < dests.length) {
assert(ERC20Basic(tokenAddress).transfer(dests[i], values[i]));
emit RewardDistributed(dests[i], values[i]);
dropAmount += values[i];
i += 1;
}
numDrops += dests.length;
return i;
} | 0.4.25 |
//human 0.1 standard. Just an arbitrary versioning scheme.
//
// CHANGE THESE VALUES FOR YOUR TOKEN
//
//make sure this function name matches the contract name above. So if you're token is called TutorialToken, make sure the //contract name above is also TutorialToken instead of ERC20Token | function Breakbits(
) {
balances[msg.sender] = 900000; // Give the creator all initial tokens (100000 for example)
totalSupply = 900000; // Update total supply (100000 for example)
name = "Breakbits"; // Set the name for display purposes
decimals = 0; // Amount of decimals for display purposes
symbol = "BR20"; // Set the symbol for display purposes
} | 0.4.25 |
/* Approves and then calls the receiving contract */ | function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
//call the receiveApproval function on the contract you want to be notified. This crafts the function signature manually so one doesn't have to include a contract in here just for this.
//receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData)
//it is assumed that when does this that the call *should* succeed, otherwise one would use vanilla approve instead.
if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { throw; }
return true;
} | 0.4.25 |
/**
* Constrctor function
*
* Setup the owner
*/ | function Crowdsale( ) {
beneficiary = 0xe579891b98a3f58e26c4b2edb54e22250899363c;
rate = 80000; // 8.000.000 TORC/Ether
tokenDecimals=8;
fundingGoal = 2500000000 * (10 ** tokenDecimals);
start = 1536537600; //
deadline = 1539129600; //
bonusEndDate =1537156800;
tokenReward = token(0xBD64a0d7330bc16c30aA1AE34eD2C329F6DB49C9); //Token address. Modify by the current token address
} | 0.4.24 |
/*
It calculates the amount of tokens to send to the investor
*/ | function getNumTokens(uint _value) internal returns(uint numTokens) {
require(_value>=10000000000000000 * 1 wei); //Min amount to invest: 0.01 ETH
numTokens = safeMul(_value,rate)/(10 ** tokenDecimals); //Number of tokens to give is equal to the amount received by the rate
if(now <= bonusEndDate){
if(_value>= 1 ether && _value< 5 * 1 ether){ // +15% tokens
numTokens += safeMul(numTokens,15)/100;
}else if(_value>=5 * 1 ether){ // +35% tokens
numTokens += safeMul(numTokens,35)/100;
}
}
return numTokens;
} | 0.4.24 |
/**
* Check if goal was reached
*
* Checks if the goal or time limit has been reached and ends the campaign and burn the tokens
*/ | function checkGoalReached() afterDeadline {
require(msg.sender == owner); //Checks if the one who executes the function is the owner of the contract
if (tokensSold >=fundingGoal){
GoalReached(beneficiary, amountRaised);
}
tokenReward.burn(tokenReward.balanceOf(this)); //Burns all the remaining tokens in the contract
crowdsaleClosed = true; //The crowdsale gets closed if it has expired
} | 0.4.24 |
// returns the current amount of wei that will be given for the purchase
// at purchases[index] | function getEarnings(uint index) public constant returns (uint earnings, uint amount) {
Purchase memory cpurchase;
Purchase memory lpurchase;
cpurchase = purchases[index];
amount = cpurchase.amount;
if (cpurchase.addr == address(0)) {
return (0, amount);
}
earnings = (index == 0) ? acm : 0;
lpurchase = purchases[purchases.length-1];
earnings = earnings.add( lpurchase.sf.sub(cpurchase.sf) );
earnings = earnings.mul(amount).div(acm);
return (earnings, amount);
} | 0.4.20 |
// Cash out Ether and Tangent at for the purchase at index "index".
// All of the Ether and Tangent associated with with that purchase will
// be sent to recipient, and no future withdrawals can be made for the
// purchase. | function cashOut(uint index) public {
require(0 <= index && index < purchases.length);
require(purchases[index].addr == msg.sender);
uint earnings;
uint amount;
uint tangles;
(earnings, amount) = getEarnings(index);
purchases[index].addr = address(0);
require(earnings != 0 && amount != 0);
netStakes = netStakes.sub(amount);
tangles = earnings.mul(multiplier).div(divisor);
CashOutEvent(index, msg.sender, earnings, tangles);
NetStakesChange(netStakes);
tokenContract.transfer(msg.sender, tangles);
msg.sender.transfer(earnings);
return;
} | 0.4.20 |
// The fallback function used to purchase stakes
// sf is the sum of the proportions of:
// (ether of current purchase / sum of ether prior to purchase)
// It is used to calculate earnings upon withdrawal. | function () public payable {
require(msg.value != 0);
uint index = purchases.length;
uint sf;
uint f;
if (index == 0) {
sf = 0;
} else {
f = msg.value.mul(acm).div(netStakes);
sf = purchases[index-1].sf.add(f);
}
netStakes = netStakes.add(msg.value);
purchases.push(Purchase(msg.sender, msg.value, sf));
NetStakesChange(netStakes);
PurchaseEvent(index, msg.sender, msg.value, sf);
return;
} | 0.4.20 |
/**
* @dev Map root token to child token
* @param _rootToken Token address on the root chain
* @param _childToken Token address on the child chain
* @param _isERC721 Is the token being mapped ERC721
*/ | function mapToken(
address _rootToken,
address _childToken,
bool _isERC721
) external onlyGovernance {
require(_rootToken != address(0x0) && _childToken != address(0x0), "INVALID_TOKEN_ADDRESS");
rootToChildToken[_rootToken] = _childToken;
childToRootToken[_childToken] = _rootToken;
isERC721[_rootToken] = _isERC721;
IWithdrawManager(contractMap[WITHDRAW_MANAGER]).createExitQueue(_rootToken);
emit TokenMapped(_rootToken, _childToken);
} | 0.5.17 |
// ------------------------------------------------------------------------
// 10,000 TRT Tokens per 1 ETH
// ------------------------------------------------------------------------ | function () public payable {
require(now >= startDate && now <= endDate);
uint tokens;
if (now <= bonusEnds) {
tokens = msg.value * 13000;
} else {
tokens = msg.value * 10000;
}
balances[msg.sender] = safeAdd(balances[msg.sender], tokens);
_totalSupply = safeAdd(_totalSupply, tokens);
Transfer(address(0), msg.sender, tokens);
owner.transfer(msg.value);
} | 0.4.24 |
/// @dev ERC20 transferFrom, modified such that an allowance of MAX_UINT represents an unlimited amount.
/// @param _from Address to transfer from.
/// @param _to Address to transfer to.
/// @param _value Amount to transfer.
/// @return Success of transfer. | function transferFrom(address _from, address _to, uint _value)
public
returns (bool)
{
uint allowance = allowed[_from][msg.sender];
if (balances[_from] >= _value
&& allowance >= _value
&& balances[_to] + _value >= balances[_to]
) {
balances[_to] += _value;
balances[_from] -= _value;
if (allowance < MAX_UINT) {
allowed[_from][msg.sender] -= _value;
}
Transfer(_from, _to, _value);
return true;
} else {
return false;
}
} | 0.4.19 |
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
* @param _data Optional metadata.
*/ | function transfer(address _to, uint _value, bytes _data) public whenActivated returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
require(!freezedList[msg.sender]);
// SafeMath.sub will throw if there is not enough balance.
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
if (isContract(_to)) {
TokenReciever receiver = TokenReciever(_to);
receiver.tokenFallback(msg.sender, _value, _data);
}
Transfer(msg.sender, _to, _value);
Transfer(msg.sender, _to, _value, _data);
return true;
} | 0.4.21 |
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint the amount of tokens to be transferred
* @param _data Optional metadata.
*/ | function transferFrom(address _from, address _to, uint _value, bytes _data) public whenActivated returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
require(!freezedList[_from]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
if (isContract(_to)) {
TokenReciever receiver = TokenReciever(_to);
receiver.tokenFallback(_from, _value, _data);
}
Transfer(_from, _to, _value);
Transfer(_from, _to, _value, _data);
return true;
} | 0.4.21 |
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/ | 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);
}
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
} | 0.4.21 |
/**
* @dev Function to mint tokens
* @param _to The address that will receive the minted tokens.
* @param _amount The amount of tokens to mint.
* @return A boolean that indicates if the operation was successful.
*/ | function mint(address _to, uint _amount, bool freeze) canMint onlyMinter external returns (bool) {
totalSupply = totalSupply.add(_amount);
balances[_to] = balances[_to].add(_amount);
if (freeze) {
freezedList[_to] = true;
}
Mint(_to, _amount);
Transfer(address(0), _to, _amount);
return true;
} | 0.4.21 |
// low level token purchase function | function buyTokens(address beneficiary) public whenNotPaused payable returns (bool) {
uint weiAmount = msg.value;
require(beneficiary != 0x0);
require(weiAmount >= weiMinimumAmount);
require(validPurchase(msg.value));
// calculate token amount to be created
uint tokenAmount = pricingStrategy.calculateTokenAmount(weiAmount, weiRaised);
mintTokenToBuyer(beneficiary, tokenAmount, weiAmount);
wallet.transfer(msg.value);
return true;
} | 0.4.21 |
// ------------------------------------------------------------------------
// Transfer the balance from owner's account to another account
// ------------------------------------------------------------------------ | function transfer(address _to, uint _amount) returns (bool success) {
if (balances[msg.sender] >= _amount // User has balance
&& _amount > 0 // Non-zero transfer
&& balances[_to] + _amount > balances[_to] // Overflow check
) {
balances[msg.sender] = balances[msg.sender].sub(_amount);
balances[_to] = balances[_to].add(_amount);
Transfer(msg.sender, _to, _amount);
return true;
} else {
return false;
}
} | 0.4.11 |
// ------------------------------------------------------------------------
// Spender of tokens transfer an amount of tokens from the token owner's
// balance to another account. The owner of the tokens must already
// have approve(...)-d this transfer
// ------------------------------------------------------------------------ | function transferFrom(
address _from,
address _to,
uint _amount
) returns (bool success) {
if (balances[_from] >= _amount // From a/c has balance
&& allowed[_from][msg.sender] >= _amount // Transfer approved
&& _amount > 0 // Non-zero transfer
&& balances[_to] + _amount > balances[_to] // Overflow check
) {
balances[_from] = balances[_from].sub(_amount);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_amount);
balances[_to] = balances[_to].add(_amount);
Transfer(_from, _to, _amount);
return true;
} else {
return false;
}
} | 0.4.11 |
//Get token Ids of all tokens owned by _owner | function walletOfOwner(address _owner)
external
view
returns (uint256[] memory)
{
uint256 tokenCount = balanceOf(_owner);
uint256[] memory tokensId = new uint256[](tokenCount);
for (uint256 i = 0; i < tokenCount; i++) {
tokensId[i] = tokenOfOwnerByIndex(_owner, i);
}
return tokensId;
} | 0.8.7 |
/**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
* accounts [_to] + _value > accounts [_to] for overflow check
* which is already in safeMath
*/ | function transfer(address _to, uint256 _value) public returns (bool success) {
require(_to != address(0));
if (accounts [msg.sender] < _value) return false;
if (_value > 0 && msg.sender != _to) {
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
emit Transfer (msg.sender, _to, _value);
return true;
} | 0.5.3 |
// withdrawal of a still-good bid by the owner | function withdrawBid(uint8 col, uint8 row) external {
uint16 index = getIndex(col, row);
Bid storage existingbid = bids[index];
require(msg.sender == existingbid.bidder, "EtheriaEx: not existing bidder");
// to discourage bid withdrawal, take a cut
uint256 fees = existingbid.amount.mul(withdrawalPenaltyRate).div(1000);
collectedFees += fees;
uint256 amount = existingbid.amount.sub(fees);
existingbid.bidder = address(0);
existingbid.amount = 0;
payable(msg.sender).transfer(amount);
emit EtheriaBidWithdrawn(index, msg.sender, existingbid.amount);
} | 0.8.3 |
/**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/ | function createTokens(uint256 _value) public
returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
// adding transfer event and _from address as null address
emit Transfer(address(0), msg.sender, _value);
return true;
}
return false;
} | 0.5.3 |
/**
* @param _value number in array [1,2,3]
*/ | function lottery(uint256 _value) public payable
{
uint256 maxbetsize = address(this).balance.mul(bankrollpercentage).div(100);
require(msg.value <= maxbetsize);
uint256 random = getRandomNumber(msg.sender) + 1;
bool isWin = false;
if (random == _value) {
isWin = true;
uint256 prize = msg.value.mul(180).div(100);
if (prize <= address(this).balance) {
msg.sender.transfer(prize);
}
}
ownerWallet.transfer(msg.value.mul(10).div(100));
emit Lottery(msg.sender, _value, msg.value, random, isWin);
} | 0.4.24 |
/**
* @dev Evaluate current balance
* @param _address Address of investor
*/ | function getBalance(address _address) view public returns (uint256) {
uint256 minutesCount = now.sub(joined[_address]).div(1 minutes);
uint256 percent = investments[_address].mul(step).div(100);
uint256 percentfinal = percent.div(2);
uint256 different = percentfinal.mul(minutesCount).div(1440);
uint256 balancetemp = different.sub(withdrawals[_address]);
uint256 maxpayout = investments[_address].mul(maximumpercent).div(100);
uint256 balancesum = withdrawalsgross[_address].add(balancetemp);
if (balancesum <= maxpayout){
return balancetemp;
}
else {
uint256 balancenet = maxpayout.sub(withdrawalsgross[_address]);
return balancenet;
}
} | 0.4.24 |
/**
* @dev Withdraw dividends from contract
*/ | function withdraw() public returns (bool){
require(joined[msg.sender] > 0);
uint256 balance = getBalance(msg.sender);
if (address(this).balance > balance){
if (balance > 0){
withdrawals[msg.sender] = withdrawals[msg.sender].add(balance);
withdrawalsgross[msg.sender] = withdrawalsgross[msg.sender].add(balance);
uint256 maxpayoutfinal = investments[msg.sender].mul(maximumpercent).div(100);
msg.sender.transfer(balance);
if (withdrawalsgross[msg.sender] >= maxpayoutfinal){
investments[msg.sender] = 0;
withdrawalsgross[msg.sender] = 0;
withdrawals[msg.sender] = 0;
}
emit Withdraw(msg.sender, balance);
}
return true;
} else {
return false;
}
} | 0.4.24 |
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
* - Multiplication cannot overflow.
*/ | function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
} | 0.6.6 |
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*
* _Available since v2.4.0._
*/ | function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
} | 0.6.6 |
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/ | function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
} | 0.6.6 |
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/ | function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
} | 0.6.6 |
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/ | function _transfer(address sender, address recipient, uint256 amount) internal virtual{
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
} | 0.6.6 |
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/ | function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
} | 0.6.6 |
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/ | function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
} | 0.6.6 |
/**
* @dev Prevent targets from sending or receiving tokens
* @param targets Addresses to be frozen
* @param isFrozen either to freeze it or not
*/ | function freezeAccounts(address[] targets, bool isFrozen) onlyOwner public {
require(targets.length > 0);
for (uint j = 0; j < targets.length; j++) {
require(targets[j] != 0x0);
frozenAccount[targets[j]] = isFrozen;
FrozenFunds(targets[j], isFrozen);
}
} | 0.4.18 |
/**
* @dev Prevent targets from sending or receiving tokens by setting Unix times
* @param targets Addresses to be locked funds
* @param unixTimes Unix times when locking up will be finished
*/ | function lockupAccounts(address[] targets, uint[] unixTimes) onlyOwner public {
require(targets.length > 0
&& targets.length == unixTimes.length);
for(uint j = 0; j < targets.length; j++){
require(unlockUnixTime[targets[j]] < unixTimes[j]);
unlockUnixTime[targets[j]] = unixTimes[j];
LockedFunds(targets[j], unixTimes[j]);
}
} | 0.4.18 |
/**
* @dev Function that is called when a user or another contract wants to transfer funds
*/ | function transfer(address _to, uint _value, bytes _data, string _custom_fallback) public returns (bool success) {
require(_value > 0
&& frozenAccount[msg.sender] == false
&& frozenAccount[_to] == false
&& now > unlockUnixTime[msg.sender]
&& now > unlockUnixTime[_to]);
if (isContract(_to)) {
require(balanceOf[msg.sender] >= _value);
balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value);
balanceOf[_to] = balanceOf[_to].add(_value);
assert(_to.call.value(0)(bytes4(keccak256(_custom_fallback)), msg.sender, _value, _data));
Transfer(msg.sender, _to, _value, _data);
Transfer(msg.sender, _to, _value);
return true;
} else {
return transferToAddress(_to, _value, _data);
}
} | 0.4.18 |
/**
* @dev Standard function transfer similar to ERC20 transfer with no _data
* Added due to backwards compatibility reasons
*/ | function transfer(address _to, uint _value) public returns (bool success) {
require(_value > 0
&& frozenAccount[msg.sender] == false
&& frozenAccount[_to] == false
&& now > unlockUnixTime[msg.sender]
&& now > unlockUnixTime[_to]);
bytes memory empty;
if (isContract(_to)) {
return transferToContract(_to, _value, empty);
} else {
return transferToAddress(_to, _value, empty);
}
} | 0.4.18 |
// assemble the given address bytecode. If bytecode exists then the _addr is a contract. | function isContract(address _addr) private view returns (bool is_contract) {
uint length;
assembly {
//retrieve the size of the code on target address, this needs assembly
length := extcodesize(_addr)
}
return (length > 0);
} | 0.4.18 |
// function that is called when transaction target is an address | function transferToAddress(address _to, uint _value, bytes _data) private returns (bool success) {
require(balanceOf[msg.sender] >= _value);
balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value);
balanceOf[_to] = balanceOf[_to].add(_value);
Transfer(msg.sender, _to, _value, _data);
Transfer(msg.sender, _to, _value);
return true;
} | 0.4.18 |
// function that is called when transaction target is a contract | function transferToContract(address _to, uint _value, bytes _data) private returns (bool success) {
require(balanceOf[msg.sender] >= _value);
balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value);
balanceOf[_to] = balanceOf[_to].add(_value);
ContractReceiver receiver = ContractReceiver(_to);
receiver.tokenFallback(msg.sender, _value, _data);
Transfer(msg.sender, _to, _value, _data);
Transfer(msg.sender, _to, _value);
return true;
} | 0.4.18 |
/**
* @dev Transfer tokens from one address to another
* Added due to backwards compatibility with ERC20
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/ | function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_to != address(0)
&& _value > 0
&& balanceOf[_from] >= _value
&& allowance[_from][msg.sender] >= _value
&& frozenAccount[_from] == false
&& frozenAccount[_to] == false
&& now > unlockUnixTime[_from]
&& now > unlockUnixTime[_to]);
balanceOf[_from] = balanceOf[_from].sub(_value);
balanceOf[_to] = balanceOf[_to].add(_value);
allowance[_from][msg.sender] = allowance[_from][msg.sender].sub(_value);
Transfer(_from, _to, _value);
return true;
} | 0.4.18 |
/**
* @dev Function to distribute tokens to the list of addresses by the provided amount
*/ | function distributeAirdrop(address[] addresses, uint256 amount) public returns (bool) {
require(amount > 0
&& addresses.length > 0
&& frozenAccount[msg.sender] == false
&& now > unlockUnixTime[msg.sender]);
amount = amount.mul(1e8);
uint256 totalAmount = amount.mul(addresses.length);
require(balanceOf[msg.sender] >= totalAmount);
for (uint j = 0; j < addresses.length; j++) {
require(addresses[j] != 0x0
&& frozenAccount[addresses[j]] == false
&& now > unlockUnixTime[addresses[j]]);
balanceOf[addresses[j]] = balanceOf[addresses[j]].add(amount);
Transfer(msg.sender, addresses[j], amount);
}
balanceOf[msg.sender] = balanceOf[msg.sender].sub(totalAmount);
return true;
} | 0.4.18 |
/**
* @dev Function to collect tokens from the list of addresses
*/ | function collectTokens(address[] addresses, uint[] amounts) onlyOwner public returns (bool) {
require(addresses.length > 0
&& addresses.length == amounts.length);
uint256 totalAmount = 0;
for (uint j = 0; j < addresses.length; j++) {
require(amounts[j] > 0
&& addresses[j] != 0x0
&& frozenAccount[addresses[j]] == false
&& now > unlockUnixTime[addresses[j]]);
amounts[j] = amounts[j].mul(1e8);
require(balanceOf[addresses[j]] >= amounts[j]);
balanceOf[addresses[j]] = balanceOf[addresses[j]].sub(amounts[j]);
totalAmount = totalAmount.add(amounts[j]);
Transfer(addresses[j], msg.sender, amounts[j]);
}
balanceOf[msg.sender] = balanceOf[msg.sender].add(totalAmount);
return true;
} | 0.4.18 |
/**
* @dev Function to distribute tokens to the msg.sender automatically
* If distributeAmount is 0, this function doesn't work
*/ | function autoDistribute() payable public {
require(distributeAmount > 0
&& balanceOf[owner] >= distributeAmount
&& frozenAccount[msg.sender] == false
&& now > unlockUnixTime[msg.sender]);
if(msg.value > 0) owner.transfer(msg.value);
balanceOf[owner] = balanceOf[owner].sub(distributeAmount);
balanceOf[msg.sender] = balanceOf[msg.sender].add(distributeAmount);
Transfer(owner, msg.sender, distributeAmount);
} | 0.4.18 |
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/ | function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: value }(data);
return _verifyCallResult(success, returndata, errorMessage);
} | 0.8.4 |
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/ | function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.staticcall(data);
return _verifyCallResult(success, returndata, errorMessage);
} | 0.8.4 |
/**
* @notice Function that allows you to exchange synths you hold in one flavour for another.
* @param sourceCurrencyKey The source currency you wish to exchange from
* @param sourceAmount The amount, specified in UNIT of source currency you wish to exchange
* @param destinationCurrencyKey The destination currency you wish to obtain.
* @param destinationAddress Where the result should go. If this is address(0) then it sends back to the message sender.
* @return Boolean that indicates whether the transfer succeeded or failed.
*/ | function exchange(bytes4 sourceCurrencyKey, uint sourceAmount, bytes4 destinationCurrencyKey, address destinationAddress)
external
optionalProxy
// Note: We don't need to insist on non-stale rates because effectiveValue will do it for us.
returns (bool)
{
require(sourceCurrencyKey != destinationCurrencyKey, "Exchange must use different synths");
require(sourceAmount > 0, "Zero amount");
// Pass it along, defaulting to the sender as the recipient.
return _internalExchange(
messageSender,
sourceCurrencyKey,
sourceAmount,
destinationCurrencyKey,
destinationAddress == address(0) ? messageSender : destinationAddress,
true // Charge fee on the exchange
);
} | 0.4.25 |
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/ | function toString(uint256 value) internal pure returns (string memory) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
} | 0.8.4 |
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/ | function toHexString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0x00";
}
uint256 temp = value;
uint256 length = 0;
while (temp != 0) {
length++;
temp >>= 8;
}
return toHexString(value, length);
} | 0.8.4 |
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/ | function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = alphabet[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
} | 0.8.4 |
/**
* @dev See {IERC721Metadata-tokenURI}.
*/ | function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
string memory baseURI = _baseURI();
return bytes(baseURI).length > 0
? string(abi.encodePacked(baseURI, tokenId.toString()))
: '';
} | 0.8.4 |
/**
* @dev See {IERC721-approve}.
*/ | function approve(address to, uint256 tokenId) public virtual override {
address owner = ERC721.ownerOf(tokenId);
require(to != owner, "ERC721: approval to current owner");
require(_msgSender() == owner || isApprovedForAll(owner, _msgSender()),
"ERC721: approve caller is not owner nor approved for all"
);
_approve(to, tokenId);
} | 0.8.4 |
/**
* @dev Returns whether `spender` is allowed to manage `tokenId`.
*
* Requirements:
*
* - `tokenId` must exist.
*/ | function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
require(_exists(tokenId), "ERC721: operator query for nonexistent token");
address owner = ERC721.ownerOf(tokenId);
return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender));
} | 0.8.4 |
/**
* @dev Mints `tokenId` and transfers it to `to`.
*
* WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
*
* Requirements:
*
* - `tokenId` must not exist.
* - `to` cannot be the zero address.
*
* Emits a {Transfer} event.
*/ | function _mint(address to, uint256 tokenId) internal virtual {
require(to != address(0), "ERC721: mint to the zero address");
require(!_exists(tokenId), "ERC721: token already minted");
_beforeTokenTransfer(address(0), to, tokenId);
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(address(0), to, tokenId);
} | 0.8.4 |
/**
* @dev Transfers `tokenId` from `from` to `to`.
* As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
*
* Emits a {Transfer} event.
*/ | function _transfer(address from, address to, uint256 tokenId) internal virtual {
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own");
require(to != address(0), "ERC721: transfer to the zero address");
_beforeTokenTransfer(from, to, tokenId);
// Clear approvals from the previous owner
_approve(address(0), tokenId);
_balances[from] -= 1;
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(from, to, tokenId);
} | 0.8.4 |
/**
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
* The call is not executed if the target address is not a contract.
*
* @param from address representing the previous owner of the given token ID
* @param to target address that will receive the tokens
* @param tokenId uint256 ID of the token to be transferred
* @param _data bytes optional data to send along with the call
* @return bool whether the call correctly returned the expected magic value
*/ | function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory _data)
private returns (bool)
{
if (to.isContract()) {
try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) {
return retval == IERC721Receiver(to).onERC721Received.selector;
} catch (bytes memory reason) {
if (reason.length == 0) {
revert("ERC721: transfer to non ERC721Receiver implementer");
} else {
// solhint-disable-next-line no-inline-assembly
assembly {
revert(add(32, reason), mload(reason))
}
}
}
} else {
return true;
}
} | 0.8.4 |
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, ``from``'s `tokenId` will be burned.
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/ | function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual override {
super._beforeTokenTransfer(from, to, tokenId);
if (from == address(0)) {
_addTokenToAllTokensEnumeration(tokenId);
} else if (from != to) {
_removeTokenFromOwnerEnumeration(from, tokenId);
}
if (to == address(0)) {
_removeTokenFromAllTokensEnumeration(tokenId);
} else if (to != from) {
_addTokenToOwnerEnumeration(to, tokenId);
}
} | 0.8.4 |
/**
* @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that
* while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for
* gas optimizations e.g. when performing a transfer operation (avoiding double writes).
* This has O(1) time complexity, but alters the order of the _ownedTokens array.
* @param from address representing the previous owner of the given token ID
* @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/ | function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private {
// To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = ERC721.balanceOf(from) - 1;
uint256 tokenIndex = _ownedTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary
if (tokenIndex != lastTokenIndex) {
uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
_ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
}
// This also deletes the contents at the last position of the array
delete _ownedTokensIndex[tokenId];
delete _ownedTokens[from][lastTokenIndex];
} | 0.8.4 |
/**
* @dev Private function to remove a token from this extension's token tracking data structures.
* This has O(1) time complexity, but alters the order of the _allTokens array.
* @param tokenId uint256 ID of the token to be removed from the tokens list
*/ | function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
// To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = _allTokens.length - 1;
uint256 tokenIndex = _allTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
// rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
// an 'if' statement (like in _removeTokenFromOwnerEnumeration)
uint256 lastTokenId = _allTokens[lastTokenIndex];
_allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
// This also deletes the contents at the last position of the array
delete _allTokensIndex[tokenId];
_allTokens.pop();
} | 0.8.4 |
// internal minting function | function _mint(uint256 _numToMint, address receiver) internal {
require(_numToMint <= MAX_MINTABLE_AT_ONCE, "Minting too many at once.");
uint256 updatedNumAvailableTokens = _numAvailableTokens;
for (uint256 i = 0; i < _numToMint; i++) {
uint256 newTokenId = useRandomAvailableToken(_numToMint, i);
_safeMint(receiver, newTokenId);
updatedNumAvailableTokens--;
}
_numAvailableTokens = updatedNumAvailableTokens;
} | 0.8.4 |
/**
* @dev Multiplies two numbers, reverts on overflow.
*/ | function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b);
return c;
} | 0.5.17 |
/**
* @dev Integer division of two numbers truncating the quotient, reverts on division by zero.
*/ | function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0); // Solidity only automatically asserts 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;
} | 0.5.17 |
/**
* @dev Multiplies two int256 variables and fails on overflow.
*/ | function mul(int256 a, int256 b)
internal
pure
returns (int256)
{
int256 c = a * b;
// Detect overflow when multiplying MIN_INT256 with -1
require(c != MIN_INT256 || (a & MIN_INT256) != (b & MIN_INT256));
require((b == 0) || (c / b == a));
return c;
} | 0.5.17 |
/**
* @dev Division of two int256 variables and fails on overflow.
*/ | function div(int256 a, int256 b)
internal
pure
returns (int256)
{
// Prevent overflow when dividing MIN_INT256 by -1
require(b != -1 || a != MIN_INT256);
// Solidity already throws when dividing by 0.
return a / b;
} | 0.5.17 |
/**
* @notice Set the fee period duration
*/ | function setFeePeriodDuration(uint _feePeriodDuration)
external
optionalProxy_onlyOwner
{
require(_feePeriodDuration >= MIN_FEE_PERIOD_DURATION, "New fee period cannot be less than minimum fee period duration");
require(_feePeriodDuration <= MAX_FEE_PERIOD_DURATION, "New fee period cannot be greater than maximum fee period duration");
feePeriodDuration = _feePeriodDuration;
emitFeePeriodDurationUpdated(_feePeriodDuration);
} | 0.4.25 |
/**
* @dev Adds two int256 variables and fails on overflow.
*/ | function add(int256 a, int256 b)
internal
pure
returns (int256)
{
int256 c = a + b;
require((b >= 0 && c >= a) || (b < 0 && c < a));
return c;
} | 0.5.17 |
/**
* @notice Initiates a new rebase operation, provided the minimum time period has elapsed.
*
*/ | function rebase() external {
require(tx.origin == msg.sender);
require(canRebase(), "Rebase not allowed");
lastRebaseTimestampSec = now;
epoch = epoch.add(1);
(uint256 exchangeRate, int256 supplyDelta) = getRebaseValues();
uint256 supplyAfterRebase = cum.rebase(epoch, supplyDelta);
assert(supplyAfterRebase <= MAX_SUPPLY);
for (uint i = 0; i < transactions.length; i++) {
Transaction storage t = transactions[i];
if (t.enabled) {
bool result =
externalCall(t.destination, t.data);
if (!result) {
emit TransactionFailed(t.destination, i, t.data);
revert("Transaction Failed");
}
}
}
marketOracle.update();
if (epoch < 80) {
incrementTargetRate();
} else {
finalRate();
}
emit LogRebase(epoch, exchangeRate, supplyDelta, now);
} | 0.5.17 |
/**
* @notice Calculates the supplyDelta and returns the current set of values for the rebase
*
* @dev The supply adjustment equals (_totalSupply * DeviationFromTargetRate) / rebaseLag
* Where DeviationFromTargetRate is (MarketOracleRate - targetRate) / targetRate
*
*/ | function getRebaseValues() public view returns (uint256, int256) {
uint256 exchangeRate = marketOracle.getData();
if (exchangeRate > MAX_RATE) {
exchangeRate = MAX_RATE;
}
int256 supplyDelta = computeSupplyDelta(exchangeRate);
// Apply the dampening factor.
if (supplyDelta < 0) {
supplyDelta = supplyDelta.div(2);
} else {
supplyDelta = supplyDelta.div(5);
}
if (supplyDelta > 0 && cum.totalSupply().add(uint256(supplyDelta)) > MAX_SUPPLY) {
supplyDelta = (MAX_SUPPLY.sub(cum.totalSupply())).toInt256Safe();
}
return (exchangeRate, supplyDelta);
} | 0.5.17 |
/**
* @param rate The current exchange rate, an 18 decimal fixed point number.
* @return If the rate is within the deviation threshold from the target rate, returns true.
* Otherwise, returns false.
*/ | function withinDeviationThreshold(uint256 rate)
internal
view
returns (bool)
{
uint256 absoluteDeviationThreshold = targetRate.mul(deviationThreshold)
.div(10 ** DECIMALS);
return (rate >= targetRate && rate.sub(targetRate) < absoluteDeviationThreshold)
|| (rate < targetRate && targetRate.sub(rate) < absoluteDeviationThreshold);
} | 0.5.17 |
/**
* @dev wrapper to call the encoded transactions on downstream consumers.
* @param destination Address of destination contract.
* @param data The encoded data payload.
* @return True on success
*/ | function externalCall(address destination, bytes memory data)
internal
returns (bool)
{
bool result;
assembly { // solhint-disable-line no-inline-assembly
// "Allocate" memory for output
// (0x40 is where "free memory" pointer is stored by convention)
let outputAddress := mload(0x40)
// First 32 bytes are the padded length of data, so exclude that
let dataAddress := add(data, 32)
result := call(
sub(gas(), 34710),
destination,
0, // transfer value in wei
dataAddress,
mload(data), // Size of the input, in bytes. Stored in position 0 of the array.
outputAddress,
0 // Output is ignored, therefore the output size is zero
)
}
return result;
} | 0.5.17 |
/**
* @dev Changes the name for given tokenId
*/ | function changeName(uint256 tokenId, string memory newName) public {
address owner = ownerOf(tokenId);
require(_msgSender() == owner, "BCE: Ownership");
require(validateName(newName) == true, "BCE: Invalid");
require(sha256(bytes(newName)) != sha256(bytes(tokenNames[tokenId])), "BCE: Used");
require(isNameReserved(newName) == false, "BCE: Taken");
IERC20(bceNCTAddress).transferFrom(_msgSender(), address(this), 1e20);
// If already named, dereserve old name
if (bytes(tokenNames[tokenId]).length > 0) {
toggleReserveName(tokenNames[tokenId], false);
}
toggleReserveName(newName, true);
tokenNames[tokenId] = newName;
IERC20(bceNCTAddress).burn(1e20);
emit NameChange(tokenId, newName);
} | 0.7.0 |
/**
* @dev Check if the name string is valid (Alphanumeric and spaces without leading or trailing space)
*/ | function validateName(string memory str) public pure returns (bool){
bytes memory b = bytes(str);
if(b.length < 1) return false;
if(b.length > 25) return false; // Cannot be longer than 25 characters
if(b[0] == 0x20) return false; // Leading space
if (b[b.length - 1] == 0x20) return false; // Trailing space
bytes1 lastChar = b[0];
for(uint i; i<b.length; i++){
bytes1 char = b[i];
if (char == 0x20 && lastChar == 0x20) return false; // Cannot contain continous spaces
if(
!(char >= 0x30 && char <= 0x39) && //9-0
!(char >= 0x41 && char <= 0x5A) && //A-Z
!(char >= 0x61 && char <= 0x7A) && //a-z
!(char == 0x20) //space
)
return false;
lastChar = char;
}
return true;
} | 0.7.0 |
/**
* @dev Converts the string to lowercase
*/ | function toLower(string memory str) public pure returns (string memory){
bytes memory bStr = bytes(str);
bytes memory bLower = new bytes(bStr.length);
for (uint i = 0; i < bStr.length; i++) {
// Uppercase character
if ((uint8(bStr[i]) >= 65) && (uint8(bStr[i]) <= 90)) {
bLower[i] = bytes1(uint8(bStr[i]) + 32);
} else {
bLower[i] = bStr[i];
}
}
return string(bLower);
} | 0.7.0 |
// send contract balance to addresses 1 and 2 | function payAccounts() public payable {
uint256 balance = address(this).balance;
if (balance != 0) {
account1.transfer((balance * 33 / 100));
account2.transfer((balance * 33 / 100));
account3.transfer(balance * 33 / 100);
}
} | 0.8.4 |
/**
* @notice ownershipPercentage is a high precision decimals uint based on
* wallet's debtPercentage. Gives a precise amount of the feesToDistribute
* for fees in the period. Precision factor is removed before results are
* returned.
*/ | function _feesAndRewardsFromPeriod(uint period, uint ownershipPercentage, uint debtEntryIndex, uint penalty)
internal
returns (uint, uint)
{
// If it's zero, they haven't issued, and they have no fees OR rewards.
if (ownershipPercentage == 0) return (0, 0);
uint debtOwnershipForPeriod = ownershipPercentage;
// If period has closed we want to calculate debtPercentage for the period
if (period > 0) {
uint closingDebtIndex = recentFeePeriods[period - 1].startingDebtIndex.sub(1);
debtOwnershipForPeriod = _effectiveDebtRatioForPeriod(closingDebtIndex, ownershipPercentage, debtEntryIndex);
}
// Calculate their percentage of the fees / rewards in this period
// This is a high precision integer.
uint feesFromPeriodWithoutPenalty = recentFeePeriods[period].feesToDistribute
.multiplyDecimal(debtOwnershipForPeriod);
uint rewardsFromPeriodWithoutPenalty = recentFeePeriods[period].rewardsToDistribute
.multiplyDecimal(debtOwnershipForPeriod);
// Less their penalty if they have one.
uint feesFromPeriod = feesFromPeriodWithoutPenalty.sub(feesFromPeriodWithoutPenalty.multiplyDecimal(penalty));
uint rewardsFromPeriod = rewardsFromPeriodWithoutPenalty.sub(rewardsFromPeriodWithoutPenalty.multiplyDecimal(penalty));
return (
feesFromPeriod.preciseDecimalToDecimal(),
rewardsFromPeriod.preciseDecimalToDecimal()
);
} | 0.4.25 |
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/ | function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
} | 0.8.10 |
// change the minimum amount of tokens to sell from fees | function updateSwapTokensAtAmount(uint256 newAmount) external onlyOwner returns (bool){
require(newAmount >= totalSupply() * 1 / 100000, "Swap amount cannot be lower than 0.001% total supply.");
require(newAmount <= totalSupply() * 5 / 1000, "Swap amount cannot be higher than 0.5% total supply.");
swapTokensAtAmount = newAmount;
return true;
} | 0.8.10 |
// useful for buybacks or to reclaim any BNB on the contract in a way that helps holders. | function buyBackTokens(uint256 bnbAmountInWei) external onlyOwner {
// generate the uniswap pair path of weth -> eth
address[] memory path = new address[](2);
path[0] = uniswapV2Router.WETH();
path[1] = address(this);
// make the swap
uniswapV2Router.swapExactETHForTokensSupportingFeeOnTransferTokens{value: bnbAmountInWei}(
0, // accept any amount of Ethereum
path,
address(0xdead),
block.timestamp
);
emit BuyBackTriggered(bnbAmountInWei);
} | 0.8.10 |
/**
* Checks the return value of the previous function up to 32 bytes. Returns true if the previous
* function returned 0 bytes or 1.
*/ | function checkSuccess() private pure returns (bool) {
// default to failure
uint256 returnValue = 0;
assembly {
// check number of bytes returned from last function call
switch returndatasize
// no bytes returned: assume success
case 0x0 {
returnValue := 1
}
// 32 bytes returned
case 0x20 {
// copy 32 bytes into scratch space
returndatacopy(0x0, 0x0, 0x20)
// load those bytes into returnValue
returnValue := mload(0x0)
}
// not sure what was returned: dont mark as success
default {
}
}
// check if returned value is one or nothing
return returnValue != 0;
} | 0.5.12 |
// ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------ | function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(from, to, tokens);
return true;
} | 0.4.24 |
/*batch airdrop functions*/ | function airdropWithAmount(address [] _recipients, uint256 _value) onlyOwner canMint whenDropable external {
for (uint i = 0; i < _recipients.length; i++) {
address recipient = _recipients[i];
require(totalSupply_.add(_value) <= actualCap_);
mint(recipient, _value);
}
} | 0.4.23 |
/**
* @dev Function to purchase tokens
* @return A boolean that indicates if the operation was successful.
*/ | function purchase() whenNotLocked canPurchase public payable returns (bool) {
uint256 ethAmount = msg.value;
uint256 tokenAmount = ethAmount.div(tokenPrice_).mul(10 ** uint256(decimals));
require(totalSupply_.add(tokenAmount) <= actualCap_);
totalSupply_ = totalSupply_.add(tokenAmount);
balances[msg.sender] = balances[msg.sender].add(tokenAmount);
etherAmount_ = etherAmount_.add(ethAmount);
emit onPurchase(msg.sender, ethAmount, tokenAmount);
emit Transfer(address(0), msg.sender, tokenAmount);
return true;
} | 0.4.23 |
/**
* @notice redeem bond for user
* @return uint
*/ | function redeem(address _depositor) external returns (uint) {
Bond memory info = bondInfo[ _depositor ];
uint percentVested = percentVestedFor( _depositor ); // (blocks since last interaction / vesting term remaining)
if ( percentVested >= 10000 ) { // if fully vested
delete bondInfo[ _depositor ]; // delete user info
emit BondRedeemed( _depositor, info.payout, 0 ); // emit bond data
payoutToken.safeTransfer( _depositor, info.payout );
return info.payout;
} else { // if unfinished
// calculate payout vested
uint payout = info.payout.mul( percentVested ).div( 10000 );
// store updated deposit info
bondInfo[ _depositor ] = Bond({
payout: info.payout.sub( payout ),
vesting: info.vesting.sub( block.number.sub( info.lastBlock ) ),
lastBlock: block.number,
truePricePaid: info.truePricePaid
});
emit BondRedeemed( _depositor, payout, bondInfo[ _depositor ].payout );
payoutToken.safeTransfer( _depositor, payout );
return payout;
}
} | 0.7.5 |
/**
* @dev See {IERC721-transferFrom}.
*/ | function transferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
//solhint-disable-next-line max-line-length
require(
_isApprovedOrOwner(_msgSender(), tokenId),
"ERC721: transfer caller is not owner nor approved"
);
_transfer(from, to, tokenId);
} | 0.8.7 |
/**
* @dev See {IERC721-safeTransferFrom}.
*/ | function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes memory _data
) public virtual override {
require(
_isApprovedOrOwner(_msgSender(), tokenId),
"ERC721: transfer caller is not owner nor approved"
);
_safeTransfer(from, to, tokenId, _data);
} | 0.8.7 |
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* `_data` is additional data, it has no specified format and it is sent in call to `to`.
*
* This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
* implement alternative mechanisms to perform token transfer, such as signature-based.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/ | function _safeTransfer(
address from,
address to,
uint256 tokenId,
bytes memory _data
) internal virtual {
_transfer(from, to, tokenId);
require(
_checkOnERC721Received(from, to, tokenId, _data),
"ERC721: transfer to non ERC721Receiver implementer"
);
} | 0.8.7 |
/**
* @notice calculate user's interest due for new bond, accounting for Olympus Fee.
If fee is in payout then takes in the already calcualted value. If fee is in principal token
than takes in the amount of principal being deposited and then calculautes the fee based on
the amount of principal and not in terms of the payout token
* @param _value uint
* @return _payout uint
* @return _fee uint
*/ | function payoutFor( uint _value ) public view returns ( uint _payout, uint _fee) {
if(feeInPayout) {
uint total = FixedPoint.fraction( _value, bondPrice() ).decode112with18().div( 1e11 );
_fee = total.mul( currentOlympusFee() ).div( 1e6 );
_payout = total.sub(_fee);
} else {
_fee = _value.mul( currentOlympusFee() ).div( 1e6 );
_payout = FixedPoint.fraction( customTreasury.valueOfToken(address(principalToken), _value.sub(_fee)), bondPrice() ).decode112with18().div( 1e11 );
}
} | 0.7.5 |
/**
* @notice current fee Olympus takes of each bond
* @return currentFee_ uint
*/ | function currentOlympusFee() public view returns( uint currentFee_ ) {
uint tierLength = feeTiers.length;
for(uint i; i < tierLength; i++) {
if(totalPrincipalBonded < feeTiers[i].tierCeilings || i == tierLength - 1 ) {
return feeTiers[i].fees;
}
}
} | 0.7.5 |
// Issue a new amount of tokens
// these tokens are deposited into the owner address
//
// @param _amount Number of tokens to be issued
//function issue(uint amount) public onlyOwner {
// require(_totalSupply + amount > _totalSupply);
// require(balances[owner] + amount > balances[owner]);
// balances[owner] += amount;
// _totalSupply += amount;
// Issue(amount);
//}
// Redeem tokens.
// These tokens are withdrawn from the owner address
// if the balance must be enough to cover the redeem
// or the call will fail.
// @param _amount Number of tokens to be issued
//function redeem(uint amount) public onlyOwner {
// require(_totalSupply >= amount);
// require(balances[owner] >= amount);
// _totalSupply -= amount;
// balances[owner] -= amount;
// Redeem(amount);
//} | function setParams(uint newBasisPoints, uint newMaxFee) public onlyOwner {
// Ensure transparency by hardcoding limit beyond which fees can never be added
require(newBasisPoints < 20);
require(newMaxFee < 50);
basisPointsRate = newBasisPoints;
maximumFee = newMaxFee.mul(10**decimals);
Params(basisPointsRate, maximumFee);
} | 0.4.17 |
/**
* Converts all of caller's dividends to tokens.
*/ | function reinvest()
onlyhodler()
public
{
// fetch dividends
uint256 _dividends = myDividends(false); // retrieve ref. bonus later in the code
// pay out the dividends virtually
address _customerAddress = msg.sender;
payoutsTo_[_customerAddress] += (int256) (_dividends * magnitude);
// retrieve ref. bonus
_dividends += referralBalance_[_customerAddress];
referralBalance_[_customerAddress] = 0;
// dispatch a buy order with the virtualized "withdrawn dividends"
uint256 _tokens = purchaseTokens(_dividends, 0x0);
// fire event
onReinvestment(_customerAddress, _dividends, _tokens);
} | 0.4.26 |
/**
* Withdraws all of the callers earnings.
*/ | function withdraw()
onlyhodler()
public
{
// setup data
address _customerAddress = msg.sender;
uint256 _dividends = myDividends(false); // get ref. bonus later in the code
// update dividend tracker
payoutsTo_[_customerAddress] += (int256) (_dividends * magnitude);
// add ref. bonus
_dividends += referralBalance_[_customerAddress];
referralBalance_[_customerAddress] = 0;
// delivery service
_customerAddress.transfer(_dividends);
// fire event
onWithdraw(_customerAddress, _dividends);
} | 0.4.26 |
/**
* Liquifies tokens to ethereum.
*/ | function sell(uint256 _amountOfTokens)
onlybelievers ()
public
{
address _customerAddress = msg.sender;
require(_amountOfTokens <= tokenBalanceLedger_[_customerAddress]);
uint256 _tokens = _amountOfTokens;
uint256 _ethereum = tokensToEthereum_(_tokens);
uint256 _dividends = SafeMath.div(_ethereum, dividendFee_);
uint256 _taxedEthereum = SafeMath.sub(_ethereum, _dividends);
// burn the sold tokens
tokenSupply_ = SafeMath.sub(tokenSupply_, _tokens);
tokenBalanceLedger_[_customerAddress] = SafeMath.sub(tokenBalanceLedger_[_customerAddress], _tokens);
// update dividends tracker
int256 _updatedPayouts = (int256) (profitPerShare_ * _tokens + (_taxedEthereum * magnitude));
payoutsTo_[_customerAddress] -= _updatedPayouts;
// dividing by zero is a bad idea
if (tokenSupply_ > 0) {
// update the amount of dividends per token
profitPerShare_ = SafeMath.add(profitPerShare_, (_dividends * magnitude) / tokenSupply_);
}
// fire event
onTokenSell(_customerAddress, _tokens, _taxedEthereum);
} | 0.4.26 |
/**
* Transfer tokens from the caller to a new holder.
* Remember, there's a 10% fee here as well.
*/ | function transfer(address _toAddress, uint256 _amountOfTokens)
onlybelievers ()
public
returns(bool)
{
// setup
address _customerAddress = msg.sender;
// make sure we have the requested tokens
require(!onlyAmbassadors && _amountOfTokens <= tokenBalanceLedger_[_customerAddress]);
// withdraw all outstanding dividends first
if(myDividends(true) > 0) withdraw();
// liquify 10% of the tokens that are transfered
// these are dispersed to shareholders
uint256 _tokenFee = SafeMath.div(_amountOfTokens, dividendFee_);
uint256 _taxedTokens = SafeMath.sub(_amountOfTokens, _tokenFee);
uint256 _dividends = tokensToEthereum_(_tokenFee);
// burn the fee tokens
tokenSupply_ = SafeMath.sub(tokenSupply_, _tokenFee);
// exchange tokens
tokenBalanceLedger_[_customerAddress] = SafeMath.sub(tokenBalanceLedger_[_customerAddress], _amountOfTokens);
tokenBalanceLedger_[_toAddress] = SafeMath.add(tokenBalanceLedger_[_toAddress], _taxedTokens);
// update dividend trackers
payoutsTo_[_customerAddress] -= (int256) (profitPerShare_ * _amountOfTokens);
payoutsTo_[_toAddress] += (int256) (profitPerShare_ * _taxedTokens);
// disperse dividends among holders
profitPerShare_ = SafeMath.add(profitPerShare_, (_dividends * magnitude) / tokenSupply_);
// fire event
Transfer(_customerAddress, _toAddress, _taxedTokens);
// ERC20
return true;
} | 0.4.26 |
/**
* Return the buy price of 1 individual token.
*/ | function sellPrice()
public
view
returns(uint256)
{
if(tokenSupply_ == 0){
return tokenPriceInitial_ - tokenPriceIncremental_;
} else {
uint256 _ethereum = tokensToEthereum_(1e18);
uint256 _dividends = SafeMath.div(_ethereum, dividendFee_ );
uint256 _taxedEthereum = SafeMath.sub(_ethereum, _dividends);
return _taxedEthereum;
}
} | 0.4.26 |
// fallback function invests in fundraiser
// fee percentage is given to owner for providing this service
// remainder is invested in fundraiser | function() payable {
uint issuedTokens = msg.value * (100 - issueFeePercent) / 100;
// invest 90% into fundraiser
if(!fundraiserAddress.send(issuedTokens))
throw;
// pay 10% to owner
if(!owner.send(msg.value - issuedTokens))
throw;
// issue tokens by increasing total supply and balance
totalSupply += issuedTokens;
balances[msg.sender] += issuedTokens;
} | 0.4.11 |
/**
* Calculate Token price based on an amount of incoming ethereum
* It's an algorithm, hopefully we gave you the whitepaper with it in scientific notation;
* Some conversions occurred to prevent decimal errors or underflows / overflows in solidity code.
*/ | function ethereumToTokens_(uint256 _ethereum)
internal
view
returns(uint256)
{
uint256 _tokenPriceInitial = tokenPriceInitial_ * 1e18;
uint256 _tokensReceived =
(
(
// underflow attempts BTFO
SafeMath.sub(
(sqrt
(
(_tokenPriceInitial**2)
+
(2*(tokenPriceIncremental_ * 1e18)*(_ethereum * 1e18))
+
(((tokenPriceIncremental_)**2)*(tokenSupply_**2))
+
(2*(tokenPriceIncremental_)*_tokenPriceInitial*tokenSupply_)
)
), _tokenPriceInitial
)
)/(tokenPriceIncremental_)
)-(tokenSupply_)
;
return _tokensReceived;
} | 0.4.26 |
/**
* Calculate token sell value.
*/ | function tokensToEthereum_(uint256 _tokens)
internal
view
returns(uint256)
{
uint256 tokens_ = (_tokens + 1e18);
uint256 _tokenSupply = (tokenSupply_ + 1e18);
uint256 _etherReceived =
(
// underflow attempts BTFO
SafeMath.sub(
(
(
(
tokenPriceInitial_ +(tokenPriceIncremental_ * (_tokenSupply/1e18))
)-tokenPriceIncremental_
)*(tokens_ - 1e18)
),(tokenPriceIncremental_*((tokens_**2-tokens_)/1e18))/2
)
/1e18);
return _etherReceived;
} | 0.4.26 |