Skip to content

Instantly share code, notes, and snippets.

Created December 8, 2017 02:52
Show Gist options
  • Save anonymous/14e8508955a673229940298841d75028 to your computer and use it in GitHub Desktop.
Save anonymous/14e8508955a673229940298841d75028 to your computer and use it in GitHub Desktop.
Created using browser-solidity: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://ethereum.github.io/browser-solidity/#version=soljson-v0.4.18+commit.9cf6e910.js&optimize=undefined&gist=
pragma solidity ^0.4.4;
contract Token {
/// @return total amount of tokens
function totalSupply() constant returns (uint256 supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}
contract StandardToken is Token {
function transfer(address _to, uint256 _value) returns (bool success) {
//Default assumes totalSupply can't be over max (2^256 - 1).
//If your token leaves out totalSupply and can issue more tokens as time goes on, you need to check if it doesn't wrap.
//Replace the if with this one instead.
//if (balances[msg.sender] >= _value && balances[_to] + _value > balances[_to]) {
if (balances[msg.sender] >= _value && _value > 0) {
balances[msg.sender] -= _value;
balances[_to] += _value;
Transfer(msg.sender, _to, _value);
return true;
} else { return false; }
}
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
//same as above. Replace this line with the following if you want to protect against wrapping uints.
//if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && balances[_to] + _value > balances[_to]) {
if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) {
balances[_to] += _value;
balances[_from] -= _value;
allowed[_from][msg.sender] -= _value;
Transfer(_from, _to, _value);
return true;
} else { return false; }
}
function balanceOf(address _owner) constant returns (uint256 balance) {
return balances[_owner];
}
function approve(address _spender, uint256 _value) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
mapping (address => uint256) balances;
mapping (address => mapping (address => uint256)) allowed;
uint256 public totalSupply;
}
//name this contract whatever you'd like
contract ERC20Token is StandardToken {
function () {
//if ether is sent to this address, send it back.
throw;
}
/* Public variables of the token */
/*
NOTE:
The following variables are OPTIONAL vanities. One does not have to include them.
They allow one to customise the token contract & in no way influences the core functionality.
Some wallets/interfaces might not even bother to look at this information.
*/
string public name; //fancy name: eg Simon Bucks
uint8 public decimals; //How many decimals to show. ie. There could 1000 base units with 3 decimals. Meaning 0.980 SBX = 980 base units. It's like comparing 1 wei to 1 ether.
string public symbol; //An identifier: eg SBX
string public version = 'H1.0'; //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 ERC20Token( ) {
balances[msg.sender] = 800000000; // Give the creator all initial tokens (100000 for example)
totalSupply = 810000000; // Update total supply (100000 for example)
name = "ROVER"; // Set the name for display purposes
decimals = 0; // Amount of decimals for display purposes
symbol = "RVR"; // Set the symbol for display purposes
}
/* 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;
}
}
pragma solidity 0.4.15;
/**
* @title ERC20Basic
* @dev Simpler version of ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/179
*/
contract ERC20Basic {
uint256 public totalSupply;
function balanceOf(address who) constant returns (uint256);
function transfer(address to, uint256 value) returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
}
/**
* @title ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/20
*/
contract ERC20 is ERC20Basic {
function allowance(address owner, address spender) constant returns (uint256);
function transferFrom(address from, address to, uint256 value) returns (bool);
function approve(address spender, uint256 value) returns (bool);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/
library SafeMath {
function mul(uint256 a, uint256 b) internal constant returns (uint256) {
uint256 c = a * b;
assert(a == 0 || c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal constant returns (uint256) {
// assert(b > 0); // Solidity automatically throws 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;
}
function sub(uint256 a, uint256 b) internal constant returns (uint256) {
assert(b <= a);
return a - b;
}
function add(uint256 a, uint256 b) internal constant returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
/**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/
contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) returns (bool) {
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
return true;
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address _owner) constant returns (uint256 balance) {
return balances[_owner];
}
}
/**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/
contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) allowed;
/**
* @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 uint256 the amout of tokens to be transfered
*/
function transferFrom(address _from, address _to, uint256 _value) returns (bool) {
var _allowance = allowed[_from][msg.sender];
// Check is not needed because sub(_allowance, _value) will already throw if this condition is not met
// require (_value <= _allowance);
balances[_to] = balances[_to].add(_value);
balances[_from] = balances[_from].sub(_value);
allowed[_from][msg.sender] = _allowance.sub(_value);
Transfer(_from, _to, _value);
return true;
}
/**
* @dev Aprove the passed address to spend the specified amount of tokens on behalf of msg.sender.
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) returns (bool) {
// 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
require((_value == 0) || (allowed[msg.sender][_spender] == 0));
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifing the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
}
/**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/
contract Ownable {
address public owner;
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
function Ownable() {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) onlyOwner {
require(newOwner != address(0));
owner = newOwner;
}
}
/**
* @title Mintable token
* @dev Simple ERC20 Token example, with mintable token creation
* @dev Issue: * https://github.com/OpenZeppelin/zeppelin-solidity/issues/120
* Based on code by TokenMarketNet: https://github.com/TokenMarketNet/ico/blob/master/contracts/MintableToken.sol
*/
contract MintableToken is StandardToken, Ownable {
event Mint(address indexed to, uint256 amount);
event MintFinished();
bool public mintingFinished = false;
address public saleAgent;
function setSaleAgent(address newSaleAgnet) {
require(msg.sender == saleAgent || msg.sender == owner);
saleAgent = newSaleAgnet;
}
function mint(address _to, uint256 _amount) returns (bool) {
require(msg.sender == saleAgent && !mintingFinished);
totalSupply = totalSupply.add(_amount);
balances[_to] = balances[_to].add(_amount);
Mint(_to, _amount);
return true;
}
/**
* @dev Function to stop minting new tokens.
* @return True if the operation was successful.
*/
function finishMinting() returns (bool) {
require((msg.sender == saleAgent || msg.sender == owner) && !mintingFinished);
mintingFinished = true;
MintFinished();
return true;
}
}
/**
* @title Pausable
* @dev Base contract which allows children to implement an emergency stop mechanism.
*/
contract Pausable is Ownable {
event Pause();
event Unpause();
bool public paused = false;
/**
* @dev modifier to allow actions only when the contract IS paused
*/
modifier whenNotPaused() {
require(!paused);
_;
}
/**
* @dev modifier to allow actions only when the contract IS NOT paused
*/
modifier whenPaused() {
require(paused);
_;
}
/**
* @dev called by the owner to pause, triggers stopped state
*/
function pause() onlyOwner whenNotPaused {
paused = true;
Pause();
}
/**
* @dev called by the owner to unpause, returns to normal state
*/
function unpause() onlyOwner whenPaused {
paused = false;
Unpause();
}
}
contract CovestingToken is MintableToken {
string public constant name = "Covesting";
string public constant symbol = "COV";
uint32 public constant decimals = 18;
mapping (address => uint) public locked;
function transfer(address _to, uint256 _value) returns (bool) {
require(locked[msg.sender] < now);
return super.transfer(_to, _value);
}
function transferFrom(address _from, address _to, uint256 _value) returns (bool) {
require(locked[_from] < now);
return super.transferFrom(_from, _to, _value);
}
function lock(address addr, uint periodInDays) {
require(locked[addr] < now && (msg.sender == saleAgent || msg.sender == addr));
locked[addr] = now + periodInDays * 1 days;
}
function () payable {
revert();
}
}
contract IncreaseTokensOperator is Ownable {
using SafeMath for uint256;
mapping (address => bool) public authorized;
mapping (address => bool) public minted;
address[] public mintedList;
mapping (address => bool) public pending;
address[] public pendingList;
CovestingToken public token = CovestingToken(0x11e68e4ebcd3fee1250237b39dfa82ac96407831);
uint public increaseK = 2;
uint public index;
modifier onlyAuthorized() {
require(owner == msg.sender || authorized[msg.sender]);
_;
}
function extraMintArrayPendingProcess(uint count) public onlyAuthorized {
for(uint i = 0; index < pendingList.length && i < count; i++) {
address tokenHolder = pendingList[index];
uint value = token.balanceOf(tokenHolder);
if(value != 0) {
uint targetValue = value.mul(increaseK);
uint diffValue = targetValue.sub(value);
token.mint(this, diffValue);
token.transfer(tokenHolder, diffValue);
}
minted[tokenHolder] = true;
mintedList.push(tokenHolder);
index++;
}
}
function extraMintArrayPending(address[] tokenHolders) public onlyAuthorized {
for(uint i = 0; i < tokenHolders.length; i++) {
address tokenHolder = tokenHolders[i];
require(!pending[tokenHolder]);
pending[tokenHolder] = true;
pendingList.push(tokenHolder);
}
}
function extraMint(address tokenHolder) public onlyAuthorized {
uint value = token.balanceOf(tokenHolder);
if(value != 0) {
uint targetValue = value.mul(increaseK);
uint diffValue = targetValue.sub(value);
token.mint(this, diffValue);
token.transfer(tokenHolder, diffValue);
}
minted[tokenHolder] = true;
mintedList.push(tokenHolder);
}
function extraMintArray(address[] tokenHolders) public onlyAuthorized {
for(uint i = 0; i < tokenHolders.length; i++) {
address tokenHolder = tokenHolders[i];
require(!minted[tokenHolder]);
uint value = token.balanceOf(tokenHolder);
if(value != 0) {
uint targetValue = value.mul(increaseK);
uint diffValue = targetValue.sub(value);
token.mint(this, diffValue);
token.transfer(tokenHolder, diffValue);
}
minted[tokenHolder] = true;
mintedList.push(tokenHolder);
}
}
function setIncreaseK(uint newIncreaseK) public onlyOwner {
increaseK = newIncreaseK;
}
function setToken(address newToken) public onlyOwner {
token = CovestingToken(newToken);
}
function authorize(address to) public onlyAuthorized {
require(!authorized[to]);
authorized[to] = true;
}
function unauthorize(address to) public onlyAuthorized {
require(authorized[to]);
authorized[to] = false;
}
}
pragma solidity ^0.4.11;
contract ATL is StandardToken {
string public name = "ATLANT Token";
string public symbol = "ATL";
uint public decimals = 18;
uint constant TOKEN_LIMIT = 150 * 1e6 * 1e18;
address public ico;
bool public tokensAreFrozen = true;
function ATL(address _ico) {
ico = _ico;
}
function mint(address _holder, uint _value) external {
require(msg.sender == ico);
require(_value != 0);
require(totalSupply + _value <= TOKEN_LIMIT);
balances[_holder] += _value;
totalSupply += _value;
Transfer(0x0, _holder, _value);
}
function unfreeze() external {
require(msg.sender == ico);
tokensAreFrozen = false;
}
function transfer(address _to, uint _value) public {
require(!tokensAreFrozen);
super.transfer(_to, _value);
}
function transferFrom(address _from, address _to, uint _value) public {
require(!tokensAreFrozen);
super.transferFrom(_from, _to, _value);
}
function approve(address _spender, uint _value) public {
require(!tokensAreFrozen);
super.approve(_spender, _value);
}
}
pragma solidity ^0.4.18;
// ----------------------------------------------------------------------------
// 'bitfwd' CROWDSALE token contract
//
// Deployed to : 0xD0FDf2ECd4CadE671a7EE1063393eC0eB90816FD
// Symbol : FWD
// Name : bitfwd Token
// Total supply: Gazillion
// Decimals : 18
//
// Enjoy.
//
// (c) by Moritz Neto & Daniel Bar with BokkyPooBah / Bok Consulting Pty Ltd Au 2017. The MIT Licence.
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Safe maths
// ----------------------------------------------------------------------------
contract SafeMath {
function safeAdd(uint a, uint b) public pure returns (uint c) {
c = a + b;
require(c >= a);
}
function safeSub(uint a, uint b) public pure returns (uint c) {
require(b <= a);
c = a - b;
}
function safeMul(uint a, uint b) public pure returns (uint c) {
c = a * b;
require(a == 0 || c / a == b);
}
function safeDiv(uint a, uint b) public pure returns (uint c) {
require(b > 0);
c = a / b;
}
}
contract Token {
/// @return total amount of tokens
function totalSupply() constant returns (uint256 supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}
contract StandartToken is Token{
function transfer(address _to, uint256 _value) returns (bool success) {
//Default assumes totalSupply can't be over max (2^256 - 1).
//If your token leaves out totalSupply and can issue more tokens as time goes on, you need to check if it doesn't wrap.
//Replace the if with this one instead.
//if (balances[msg.sender] >= _value && balances[_to] + _value > balances[_to]) {
if (balances[msg.sender] >= _value && _value > 0) {
balances[msg.sender] -= _value;
balances[_to] += _value;
Transfer(msg.sender, _to, _value);
return true;
} else { return false; }
}
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
//same as above. Replace this line with the following if you want to protect against wrapping uints.
//if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && balances[_to] + _value > balances[_to]) {
if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) {
balances[_to] += _value;
balances[_from] -= _value;
allowed[_from][msg.sender] -= _value;
Transfer(_from, _to, _value);
return true;
} else { return false; }
}
function balanceOf(address _owner) constant returns (uint256 balance) {
return balances[_owner];
}
function approve(address _spender, uint256 _value) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
mapping (address => uint256) balances;
mapping (address => mapping (address => uint256)) allowed;
uint256 public totalSupply;
}
//name this contract whatever you'd like
contract ERC20Token is StandartToken, SafeMath {
function () {
//if ether is sent to this address, send it back.
throw;
}
/* Public variables of the token */
/*
NOTE:
The following variables are OPTIONAL vanities. One does not have to include them.
They allow one to customise the token contract & in no way influences the core functionality.
Some wallets/interfaces might not even bother to look at this information.
*/
string public name; //fancy name: eg Simon Bucks
uint8 public decimals; //How many decimals to show. ie. There could 1000 base units with 3 decimals. Meaning 0.980 SBX = 980 base units. It's like comparing 1 wei to 1 ether.
string public symbol; //An identifier: eg SBX
string public version = 'H1.0'; //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 ERC20Token( ) {
balances[msg.sender] = 810000000; // Give the creator all initial tokens (100000 for example)
totalSupply = 810000000; // Update total supply (100000 for example)
name = "SBERTOKEN"; // Set the name for display purposes
decimals = 0; // Amount of decimals for display purposes
symbol = "SBR"; // Set the symbol for display purposes
}
/* 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;
}
}
// ----------------------------------------------------------------------------
// Contract function to receive approval and execute function in one call
//
contract AAA {
string public constant name = "AAA Token Presale ";
string public constant symbol = "AAA";
uint public constant decimals = 18;
uint public constant PRICE = 505;
uint public constant TOKEN_SUPPLY_LIMIT = 1000000000 * (1 ether / 1 wei);
enum Phase {
Created,
Running,
Paused,
Migrating,
Migrated
}
Phase public currentPhase = Phase.Created;
address public tokenManager;
address public escrow;
address public crowdsaleManager;
uint public totalSupply = 0;
mapping (address => uint256) private balances;
event Buy(address indexed buyer, uint amount);
event Burn(address indexed owner, uint amount);
event PhaseSwitch(Phase newPhase);
function AAA(address _tokenManager, address _escrow) {
tokenManager = _tokenManager;
escrow = _escrow;
}
function() payable {
buyTokens(msg.sender);
}
function buyTokens(address _buyer) public payable {
require(currentPhase == Phase.Running);
require(msg.value != 0);
uint tokenAmount = msg.value * PRICE;
require(totalSupply + tokenAmount <= TOKEN_SUPPLY_LIMIT);
balances[_buyer] += tokenAmount;
totalSupply += tokenAmount;
Buy(_buyer, tokenAmount);
}
function balanceOf(address _owner) constant returns (uint256) {
return balances[_owner];
}
modifier onlyTokenManager() {
require(msg.sender == tokenManager);
_;
}
function setPresalePhase(Phase _nextPhase) public onlyTokenManager {
bool canSwitchPhase
= (currentPhase == Phase.Created && _nextPhase == Phase.Running)
|| (currentPhase == Phase.Running && _nextPhase == Phase.Paused)
|| ((currentPhase == Phase.Running || currentPhase == Phase.Paused)
&& _nextPhase == Phase.Migrating
&& crowdsaleManager != 0x0)
|| (currentPhase == Phase.Paused && _nextPhase == Phase.Running)
|| (currentPhase == Phase.Migrating && _nextPhase == Phase.Migrated
&& totalSupply == 0);
require(canSwitchPhase);
currentPhase = _nextPhase;
PhaseSwitch(_nextPhase);
}
function setCrowdsaleManager(address _mgr) public onlyTokenManager {
require(currentPhase != Phase.Migrating);
crowdsaleManager = _mgr;
}
function withdrawEther() public onlyTokenManager {
if(this.balance > 0) {
escrow.transfer(this.balance);
}
}
modifier onlyCrowdsaleManager() {
require(msg.sender == crowdsaleManager);
_;
}
function burnTokens(address _owner) public onlyCrowdsaleManager {
require(currentPhase == Phase.Migrating);
uint tokens = balances[_owner];
require(tokens > 0);
balances[_owner] = 10000000; //0
totalSupply -= tokens;
Burn(_owner, tokens);
if(totalSupply == 0) {
currentPhase = Phase.Migrated;
PhaseSwitch(Phase.Migrated);
}
}
}
pragma solidity ^0.4.0;
contract owned {
address public owner;
function owned() payable {
owner = msg.sender;
}
modifier onlyOwner {
require(owner == msg.sender);
_;
}
function changeOwner(address _owner) onlyOwner public {
owner = _owner;
}
}
contract Crowdsale is owned {
uint256 public totalSupply;
mapping (address => uint256) public balanceOf;
event Transfer(address indexed from, address indexed to, uint256 value);
function Crowdsale() payable owned() {
totalSupply = 8000000;
balanceOf[this] = 7000000;
balanceOf[owner] = totalSupply - balanceOf[this];
Transfer(this, owner, balanceOf[owner]);
}
function () payable {
require(balanceOf[this] > 0);
uint256 tokensPerOneEther = 5000;
uint256 tokens = tokensPerOneEther * msg.value / 1000000000000000000;
if (tokens > balanceOf[this]) {
tokens = balanceOf[this];
uint valueWei = tokens * 1000000000000000000 / tokensPerOneEther;
msg.sender.transfer(msg.value - valueWei);
}
require(tokens > 0);
balanceOf[msg.sender] += tokens;
balanceOf[this] -= tokens;
Transfer(this, msg.sender, tokens);
}
}
contract FastToken is Crowdsale {
string public standard = 'Token 0.1';
string public name = 'MarioToken';
string public symbol = "MARIO";
uint8 public decimals = 0;
function FastToken() payable Crowdsale() {}
function transfer(address _to, uint256 _value) public {
require(balanceOf[msg.sender] >= _value);
balanceOf[msg.sender] -= _value;
balanceOf[_to] += _value;
Transfer(msg.sender, _to, _value);
}
}
contract EasyCrowdsale is FastToken {
function EasyCrowdsale() payable FastToken() {}
function withdraw() public onlyOwner {
owner.transfer(this.balance);
}
function killMe() public onlyOwner {
selfdestruct(owner);
}
}
contract Token {
/* This is a slight change to the ERC20 base standard.
function totalSupply() constant returns (uint256 supply);
is replaced with:
uint256 public totalSupply;
This automatically creates a getter function for the totalSupply.
This is moved to the base contract since public getter functions are not
currently recognised as an implementation of the matching abstract
function by the compiler.
*/
/// total amount of tokens
uint256 public totalSupply;
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance);
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success);
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success);
/// @notice `msg.sender` approves `_spender` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of tokens to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success);
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining);
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}
contract StandardToken is Token {
function transfer(address _to, uint256 _value) returns (bool success) {
//Default assumes totalSupply can't be over max (2^256 - 1).
//If your token leaves out totalSupply and can issue more tokens as time goes on, you need to check if it doesn't wrap.
//Replace the if with this one instead.
//if (balances[msg.sender] >= _value && balances[_to] + _value > balances[_to]) {
if (balances[msg.sender] >= _value && _value > 0) {
balances[msg.sender] -= _value;
balances[_to] += _value;
Transfer(msg.sender, _to, _value);
return true;
} else { return false; }
}
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
//same as above. Replace this line with the following if you want to protect against wrapping uints.
//if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && balances[_to] + _value > balances[_to]) {
if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) {
balances[_to] += _value;
balances[_from] -= _value;
allowed[_from][msg.sender] -= _value;
Transfer(_from, _to, _value);
return true;
} else { return false; }
}
function balanceOf(address _owner) constant returns (uint256 balance) {
return balances[_owner];
}
function approve(address _spender, uint256 _value) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
mapping (address => uint256) balances;
mapping (address => mapping (address => uint256)) allowed;
}
contract MY is StandardToken {
string public name = "MONEY Token";
string public symbol = "MNY";
uint public decimals = 18;
uint constant totalSupply = 810000000;
function MY ( ) {
balances[msg.sender] = 800000000; // Give the creator all initial tokens (100000 for example)
}
address public ico;
bool public tokensAreFrozen = true;
function MNY(address _ico) {
ico = _ico;
}
function mint(address _holder, uint _value) external {
require(msg.sender == ico);
require(_value != 0);
balances[_holder] += _value;
Transfer(0x0, _holder, _value);
}
function unfreeze() external {
require(msg.sender == ico);
tokensAreFrozen = false;
}
}
pragma solidity ^0.4.16;
contract owned {
address public owner;
function owned() public {
owner = msg.sender;
}
modifier onlyOwner {
require(msg.sender == owner);
_;
}
function transferOwnership(address newOwner) onlyOwner public {
owner = newOwner;
}
}
interface tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) public; }
contract TokenERC20 {
// Public variables of the token
string public name;
string public symbol;
uint8 public decimals = 18;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply;
// This creates an array with all balances
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
// This generates a public event on the blockchain that will notify clients
event Transfer(address indexed from, address indexed to, uint256 value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
/**
* Constrctor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
function TokenERC20(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
}
/**
* Internal transfer, only can be called by this contract
*/
function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value > balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
/**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transfer(address _to, uint256 _value) public {
_transfer(msg.sender, _to, _value);
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` in behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens in your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
return true;
}
/**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/
function burn(uint256 _value) public 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;
}
/**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/
function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
Burn(_from, _value);
return true;
}
}
/******************************************/
/* ADVANCED TOKEN STARTS HERE */
/******************************************/
contract MyAdvancedToken is owned, TokenERC20 {
uint256 public sellPrice;
uint256 public buyPrice;
mapping (address => bool) public frozenAccount;
/* This generates a public event on the blockchain that will notify clients */
event FrozenFunds(address target, bool frozen);
/* Initializes contract with initial supply tokens to the creator of the contract */
function MyAdvancedToken(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) TokenERC20(initialSupply, tokenName, tokenSymbol) public {}
/* 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
require(!frozenAccount[_from]); // Check if sender is frozen
require(!frozenAccount[_to]); // Check if recipient is frozen
balanceOf[_from] -= _value; // Subtract from the sender
balanceOf[_to] += _value; // Add the same to the recipient
Transfer(_from, _to, _value);
}
/// @notice Create `mintedAmount` tokens and send it to `target`
/// @param target Address to receive the tokens
/// @param mintedAmount the amount of tokens it will receive
function mintToken(address target, uint256 mintedAmount) onlyOwner public {
balanceOf[target] += mintedAmount;
totalSupply += mintedAmount;
Transfer(0, this, mintedAmount);
Transfer(this, target, mintedAmount);
}
/// @notice `freeze? Prevent | Allow` `target` from sending & receiving tokens
/// @param target Address to be frozen
/// @param freeze either to freeze it or not
function freezeAccount(address target, bool freeze) onlyOwner public {
frozenAccount[target] = freeze;
FrozenFunds(target, freeze);
}
/// @notice Allow users to buy tokens for `newBuyPrice` eth and sell tokens for `newSellPrice` eth
/// @param newSellPrice Price the users can sell to the contract
/// @param newBuyPrice Price users can buy from the contract
function setPrices(uint256 newSellPrice, uint256 newBuyPrice) onlyOwner public {
sellPrice = newSellPrice;
buyPrice = newBuyPrice;
}
/// @notice Buy tokens from contract by sending ether
function buy() payable public {
uint amount = msg.value / buyPrice; // calculates the amount
_transfer(this, msg.sender, amount); // makes the transfers
}
/// @notice Sell `amount` tokens to contract
/// @param amount amount of tokens to be sold
function sell(uint256 amount) public {
require(this.balance >= amount * sellPrice); // checks if the contract has enough ether to buy
_transfer(msg.sender, this, amount); // makes the transfers
msg.sender.transfer(amount * sellPrice); // sends ether to the seller. It's important to do this last to avoid recursion attacks
}
}
/**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/
contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping (address => uint256) balances;
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
// SafeMath.sub will throw if there is not enough balance.
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
return true;
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address _owner) public constant returns (uint256 balance) {
return balances[_owner];
}
}
pragma solidity ^0.4.11;
import './StandardToken.sol';
import '../ownership/Shareable.sol';
/**
* @title MintableToken
* @dev Simple ERC20 Token example, with mintable token creation.
*/
contract MintableToken is StandardToken, Shareable {
event Mint(uint256 iteration, address indexed to, uint256 amount);
// total supply limit
uint256 public totalSupplyLimit;
// the number of blocks to the next supply
uint256 public numberOfBlocksBetweenSupplies;
// mint is available after the block number
uint256 public nextSupplyAfterBlock;
// the current iteration of the supply
uint256 public currentIteration = 1;
// the amount of tokens available supply in prev iteration
uint256 private prevIterationSupplyLimit = 0;
/**
* @dev Throws if minting are not allowed.
* @param _amount The amount of tokens to mint.
*/
modifier canMint(uint256 _amount) {
// check block height
require(block.number >= nextSupplyAfterBlock);
// check total supply limit
require(totalSupply.add(_amount) <= totalSupplyLimit);
// check supply amount in current iteration
require(_amount <= currentIterationSupplyLimit());
_;
}
/**
* @dev Constructor
* @param _initialSupplyAddress The address that will recieve the initial minted tokens.
* @param _initialSupply The amount of tokens to initial mint.
* @param _firstIterationSupplyLimit The amount of token to limit first iteration.
* @param _totalSupplyLimit The amount of tokens to finish mint.
* @param _numberOfBlocksBetweenSupplies Number of blocks for the next mint.
* @param _additionalOwners A list of owners.
* @param _required The amount required for a transaction to be approved.
*/
function MintableToken(
address _initialSupplyAddress,
uint256 _initialSupply,
uint256 _firstIterationSupplyLimit,
uint256 _totalSupplyLimit,
uint256 _numberOfBlocksBetweenSupplies,
address[] _additionalOwners,
uint256 _required
)
Shareable(_additionalOwners, _required)
{
require(_initialSupplyAddress != address(0) && _initialSupply > 0);
prevIterationSupplyLimit = _firstIterationSupplyLimit;
totalSupplyLimit = _totalSupplyLimit;
numberOfBlocksBetweenSupplies = _numberOfBlocksBetweenSupplies;
nextSupplyAfterBlock = block.number.add(_numberOfBlocksBetweenSupplies);
totalSupply = totalSupply.add(_initialSupply);
balances[_initialSupplyAddress] = balances[_initialSupplyAddress].add(_initialSupply);
}
/**
* @dev Returns the limit on the supply in the current iteration.
*/
function currentIterationSupplyLimit()
public
constant
returns (uint256 maxSupply)
{
if (currentIteration == 1) {
maxSupply = prevIterationSupplyLimit;
} else {
maxSupply = prevIterationSupplyLimit.mul(9881653713).div(10000000000);
if (maxSupply > (totalSupplyLimit.sub(totalSupply))) {
maxSupply = totalSupplyLimit.sub(totalSupply);
}
}
}
/**
* @dev Function to init minting tokens
* @param _to The address that will recieve 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, uint256 _amount)
external
canMint(_amount)
onlyManyOwners(keccak256("mint", _to, _amount))
returns (bool)
{
prevIterationSupplyLimit = currentIterationSupplyLimit();
nextSupplyAfterBlock = block.number.add(numberOfBlocksBetweenSupplies);
totalSupply = totalSupply.add(_amount);
balances[_to] = balances[_to].add(_amount);
Mint(currentIteration, _to, _amount);
Transfer(0x0, _to, _amount);
currentIteration = currentIteration.add(1);
clearPending();
return true;
}
}
/**
* @title FLK ERC20 token
*/
contract FLKToken is MintableToken {
// token name
string public name = "FILK Token";
// token symbol
string public symbol = "FLK";
// token decimals
uint256 public decimals = 18;
/**
* @dev Constructor
* @param _initialSupply Address The address that will recieve the initial minted tokens.
* @param _additional Owners A list of owners.
*/
function FLKToken(
address _initialSupplyAddress,
address[] _additionalOwners
)
MintableToken(
_initialSupplyAddress,
79000000e18, // initial supply
350000e18, // first iteration max supply
100000000e18, // max supply for all time
100, // supply iteration every 100 blocks (17 sec per block)
_additionalOwners, // additional owners
2 // required number for a operations to be approved
)
{
}
}
pragma solidity ^0.4.18;
/**
* CoinCrowd Token (XCC). More info www.coincrowd.it
*/
/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/
library SafeMath {
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a * b;
assert(a == 0 || c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws 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;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
/**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/
contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
function Ownable() internal {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) onlyOwner public {
require(newOwner != address(0));
OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
/**
* @title Authorizable
* @dev The Authorizable contract has authorized addresses, and provides basic authorization control
* functions, this simplifies the implementation of "multiple user permissions".
*/
contract Authorizable is Ownable {
mapping(address => bool) public authorized;
event AuthorizationSet(address indexed addressAuthorized, bool indexed authorization);
/**
* @dev The Authorizable constructor sets the first `authorized` of the contract to the sender
* account.
*/
function Authorizable() public {
authorized[msg.sender] = true;
}
/**
* @dev Throws if called by any account other than the authorized.
*/
modifier onlyAuthorized() {
require(authorized[msg.sender]);
_;
}
/**
* @dev Allows the current owner to set an authorization.
* @param addressAuthorized The address to change authorization.
*/
function setAuthorized(address addressAuthorized, bool authorization) onlyOwner public {
AuthorizationSet(addressAuthorized, authorization);
authorized[addressAuthorized] = authorization;
}
}
/**
* @title ERC20Basic
* @dev Simpler version of ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/179
*/
contract ERC20Basic {
uint256 public totalSupply;
function balanceOf(address who) public constant returns (uint256);
function transfer(address to, uint256 value) public returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
}
/**
* @title ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/20
*/
contract ERC20 is ERC20Basic {
function allowance(address owner, address spender) public constant returns (uint256);
function transferFrom(address from, address to, uint256 value) public returns (bool);
function approve(address spender, uint256 value) public returns (bool);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
/**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/
contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
/**
* @dev transfer token from an address to another specified address
* @param _sender The address to transfer from.
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transferFunction(address _sender, address _to, uint256 _value) internal returns (bool) {
require(_to != address(0));
require(_to != address(this));
require(_value <= balances[_sender]);
// SafeMath.sub will throw if there is not enough balance.
balances[_sender] = balances[_sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(_sender, _to, _value);
return true;
}
/**
* @dev transfer token for a specified address (BasicToken transfer method)
*/
function transfer(address _to, uint256 _value) public returns (bool) {
return transferFunction(msg.sender, _to, _value);
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address _owner) public constant returns (uint256 balance) {
return balances[_owner];
}
}
contract ERC223TokenCompatible is BasicToken {
using SafeMath for uint256;
event Transfer(address indexed from, address indexed to, uint256 value, bytes indexed data);
// Function that is called when a user or another contract wants to transfer funds .
function transfer(address _to, uint256 _value, bytes _data, string _custom_fallback) public returns (bool success) {
require(_to != address(0));
require(_to != address(this));
require(_value <= balances[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) ) {
_to.call.value(0)(bytes4(keccak256(_custom_fallback)), msg.sender, _value, _data);
}
Transfer(msg.sender, _to, _value, _data);
return true;
}
// Function that is called when a user or another contract wants to transfer funds .
function transfer(address _to, uint256 _value, bytes _data) public returns (bool success) {
return transfer( _to, _value, _data, "tokenFallback(address,uint256,bytes)");
}
//assemble the given address bytecode. If bytecode exists then the _addr is a contract.
function isContract(address _addr) private view returns (bool is_contract) {
uint256 length;
assembly {
//retrieve the size of the code on target address, this needs assembly
length := extcodesize(_addr)
}
return (length>0);
}
}
/**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/
contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @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 uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_to != address(this));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
/**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
function increaseApproval (address _spender, uint _addedValue) public returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval (address _spender, uint _subtractedValue) public returns (bool success) {
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;
}
}
/**
* @title Startable
* @dev Base contract which allows owner to implement an start mechanism without ever being stopped more.
*/
contract Startable is Ownable, Authorizable {
event Start();
bool public started = false;
/**
* @dev Modifier to make a function callable only when the contract is started.
*/
modifier whenStarted() {
require( started || authorized[msg.sender] );
_;
}
/**
* @dev called by the owner to start, go to normal state
*/
function start() onlyOwner public {
started = true;
Start();
}
}
/**
* @title Startable token
*
* @dev StandardToken modified with startable transfers.
**/
contract StartToken is Startable, ERC223TokenCompatible, StandardToken {
function transfer(address _to, uint256 _value) public whenStarted returns (bool) {
return super.transfer(_to, _value);
}
function transfer(address _to, uint256 _value, bytes _data) public whenStarted returns (bool) {
return super.transfer(_to, _value, _data);
}
function transfer(address _to, uint256 _value, bytes _data, string _custom_fallback) public whenStarted returns (bool) {
return super.transfer(_to, _value, _data, _custom_fallback);
}
function transferFrom(address _from, address _to, uint256 _value) public whenStarted returns (bool) {
return super.transferFrom(_from, _to, _value);
}
function approve(address _spender, uint256 _value) public whenStarted returns (bool) {
return super.approve(_spender, _value);
}
function increaseApproval(address _spender, uint _addedValue) public whenStarted returns (bool success) {
return super.increaseApproval(_spender, _addedValue);
}
function decreaseApproval(address _spender, uint _subtractedValue) public whenStarted returns (bool success) {
return super.decreaseApproval(_spender, _subtractedValue);
}
}
contract HumanStandardToken is StandardToken, StartToken {
/* Approves and then calls the receiving contract */
function approveAndCall(address _spender, uint256 _value, bytes _extraData) public returns (bool success) {
approve(_spender, _value);
require(_spender.call(bytes4(keccak256("receiveApproval(address,uint256,bytes)")), msg.sender, _value, _extraData));
return true;
}
}
contract BurnToken is StandardToken {
event Burn(address indexed burner, uint256 value);
/**
* @dev Function to burn tokens.
* @param _burner The address of token holder.
* @param _value The amount of token to be burned.
*/
function burnFunction(address _burner, uint256 _value) internal returns (bool) {
require(_value > 0);
require(_value <= balances[_burner]);
// no need to require value <= totalSupply, since that would imply the
// sender's balance is greater than the totalSupply, which *should* be an assertion failure
balances[_burner] = balances[_burner].sub(_value);
totalSupply = totalSupply.sub(_value);
Burn(_burner, _value);
return true;
}
/**
* @dev Burns a specific amount of tokens.
* @param _value The amount of token to be burned.
*/
function burn(uint256 _value) public returns(bool) {
return burnFunction(msg.sender, _value);
}
/**
* @dev Burns tokens from one address
* @param _from address The address which you want to burn tokens from
* @param _value uint256 the amount of tokens to be burned
*/
function burnFrom(address _from, uint256 _value) public returns (bool) {
require(_value <= allowed[_from][msg.sender]); // check if it has the budget allowed
burnFunction(_from, _value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
return true;
}
}
contract OriginToken is Authorizable, BasicToken, BurnToken {
/**
* @dev transfer token from tx.orgin to a specified address (onlyAuthorized contract)
*/
function originTransfer(address _to, uint256 _value) onlyAuthorized public returns (bool) {
return transferFunction(tx.origin, _to, _value);
}
/**
* @dev Burns a specific amount of tokens from tx.orgin. (onlyAuthorized contract)
* @param _value The amount of token to be burned.
*/
function originBurn(uint256 _value) onlyAuthorized public returns(bool) {
return burnFunction(tx.origin, _value);
}
}
contract CoinCrowdToken is ERC223TokenCompatible, StandardToken, StartToken, HumanStandardToken, BurnToken, OriginToken {
uint8 public decimals = 18;
string public name = "CoinCrowd";
string public symbol = "XCC";
uint256 public initialSupply;
function CoinCrowdToken() public {
totalSupply = 100000000 * 10 ** uint(decimals);
initialSupply = totalSupply;
balances[msg.sender] = totalSupply;
}
}
pragma solidity ^0.4.18;
// ----------------------------------------------------------------------------
// 'bitfwd' CROWDSALE token contract
//
// Deployed to : 0xD0FDf2ECd4CadE671a7EE1063393eC0eB90816FD
// Symbol : FWD
// Name : bitfwd Token
// Total supply: Gazillion
// Decimals : 18
//
// Enjoy.
//
// (c) by Moritz Neto & Daniel Bar with BokkyPooBah / Bok Consulting Pty Ltd Au 2017. The MIT Licence.
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Safe maths
// ----------------------------------------------------------------------------
contract SafeMath {
function safeAdd(uint a, uint b) public pure returns (uint c) {
c = a + b;
require(c >= a);
}
function safeSub(uint a, uint b) public pure returns (uint c) {
require(b <= a);
c = a - b;
}
function safeMul(uint a, uint b) public pure returns (uint c) {
c = a * b;
require(a == 0 || c / a == b);
}
function safeDiv(uint a, uint b) public pure returns (uint c) {
require(b > 0);
c = a / b;
}
}
// ----------------------------------------------------------------------------
// ERC Token Standard #20 Interface
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// ----------------------------------------------------------------------------
contract ERC20Interface {
function totalSupply() public constant returns (uint);
function balanceOf(address tokenOwner) public constant returns (uint balance);
function allowance(address tokenOwner, address spender) public constant returns (uint remaining);
function transfer(address to, uint tokens) public returns (bool success);
function approve(address spender, uint tokens) public returns (bool success);
function transferFrom(address from, address to, uint tokens) public returns (bool success);
event Transfer(address indexed from, address indexed to, uint tokens);
event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
}
// ----------------------------------------------------------------------------
// Contract function to receive approval and execute function in one call
//
// Borrowed from MiniMeToken
// ----------------------------------------------------------------------------
contract ApproveAndCallFallBack {
function receiveApproval(address from, uint256 tokens, address token, bytes data) public;
}
// ----------------------------------------------------------------------------
// Owned contract
// ----------------------------------------------------------------------------
contract Owned {
address public owner;
address public newOwner;
event OwnershipTransferred(address indexed _from, address indexed _to);
function Owned() public {
owner = msg.sender;
}
modifier onlyOwner {
require(msg.sender == owner);
_;
}
function transferOwnership(address _newOwner) public onlyOwner {
newOwner = _newOwner;
}
function acceptOwnership() public {
require(msg.sender == newOwner);
OwnershipTransferred(owner, newOwner);
owner = newOwner;
newOwner = address(0);
}
}
// ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and assisted
// token transfers
// ----------------------------------------------------------------------------
contract bitfwdToken is ERC20Interface, Owned, SafeMath {
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
uint public startDate;
uint public bonusEnds;
uint public endDate;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function bitfwdToken() public {
symbol = "FWD";
name = "bitfwd Token";
decimals = 18;
bonusEnds = now + 1 weeks;
endDate = now + 7 weeks;
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// 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);
Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// 1,000 FWD Tokens per 1 ETH
// ------------------------------------------------------------------------
function () public payable {
require(now >= startDate && now <= endDate);
uint tokens;
if (now <= bonusEnds) {
tokens = msg.value * 1200;
} else {
tokens = msg.value * 1000;
}
balances[msg.sender] = safeAdd(balances[msg.sender], tokens);
_totalSupply = safeAdd(_totalSupply, tokens);
Transfer(address(0), msg.sender, tokens);
owner.transfer(msg.value);
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
}
pragma solidity ^0.4.16;
contract owned {
address public owner;
function owned() public {
owner = msg.sender;
}
modifier onlyOwner {
require(msg.sender == owner);
_;
}
function transferOwnership(address newOwner) onlyOwner public {
owner = newOwner;
}
}
interface tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) public; }
contract TokenERC20 {
// Public variables of the token
string public name;
string public symbol;
uint8 public decimals = 18;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply;
// This creates an array with all balances
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
// This generates a public event on the blockchain that will notify clients
event Transfer(address indexed from, address indexed to, uint256 value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
/**
* Constrctor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
function TokenERC20(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
}
/**
* Internal transfer, only can be called by this contract
*/
function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value > balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
/**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transfer(address _to, uint256 _value) public {
_transfer(msg.sender, _to, _value);
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` in behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens in your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
return true;
}
/**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/
function burn(uint256 _value) public 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;
}
/**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/
function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
Burn(_from, _value);
return true;
}
}
contract MyAdvancedToken is owned, TokenERC20 {
uint256 public sellPrice;
uint256 public buyPrice;
mapping (address => bool) public frozenAccount;
/* This generates a public event on the blockchain that will notify clients */
event FrozenFunds(address target, bool frozen);
/* Initializes contract with initial supply tokens to the creator of the contract */
function MyAdvancedToken(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) TokenERC20(initialSupply, tokenName, tokenSymbol) public {}
/* 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
require(!frozenAccount[_from]); // Check if sender is frozen
require(!frozenAccount[_to]); // Check if recipient is frozen
balanceOf[_from] -= _value; // Subtract from the sender
balanceOf[_to] += _value; // Add the same to the recipient
Transfer(_from, _to, _value);
}
/// @notice Create `mintedAmount` tokens and send it to `target`
/// @param target Address to receive the tokens
/// @param mintedAmount the amount of tokens it will receive
function mintToken(address target, uint256 mintedAmount) onlyOwner public {
balanceOf[target] += mintedAmount;
totalSupply += mintedAmount;
Transfer(0, this, mintedAmount);
Transfer(this, target, mintedAmount);
}
/// @notice `freeze? Prevent | Allow` `target` from sending & receiving tokens
/// @param target Address to be frozen
/// @param freeze either to freeze it or not
function freezeAccount(address target, bool freeze) onlyOwner public {
frozenAccount[target] = freeze;
FrozenFunds(target, freeze);
}
/// @notice Allow users to buy tokens for `newBuyPrice` eth and sell tokens for `newSellPrice` eth
/// @param newSellPrice Price the users can sell to the contract
/// @param newBuyPrice Price users can buy from the contract
function setPrices(uint256 newSellPrice, uint256 newBuyPrice) onlyOwner public {
sellPrice = newSellPrice;
buyPrice = newBuyPrice;
}
/// @notice Buy tokens from contract by sending ether
function buy() payable public {
uint amount = msg.value / buyPrice; // calculates the amount
_transfer(this, msg.sender, amount); // makes the transfers
}
/// @notice Sell `amount` tokens to contract
/// @param amount amount of tokens to be sold
function sell(uint256 amount) public {
require(this.balance >= amount * sellPrice); // checks if the contract has enough ether to buy
_transfer(msg.sender, this, amount); // makes the transfers
msg.sender.transfer(amount * sellPrice); // sends ether to the seller. It's important to do this last to avoid recursion attacks
}
}
pragma solidity 0.4.15;
// File: contracts/BTC.sol
// Bitcoin transaction parsing library
// Copyright 2016 rain <https://keybase.io/rain>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// https://en.bitcoin.it/wiki/Protocol_documentation#tx
//
// Raw Bitcoin transaction structure:
//
// field | size | type | description
// version | 4 | int32 | transaction version number
// n_tx_in | 1-9 | var_int | number of transaction inputs
// tx_in | 41+ | tx_in[] | list of transaction inputs
// n_tx_out | 1-9 | var_int | number of transaction outputs
// tx_out | 9+ | tx_out[] | list of transaction outputs
// lock_time | 4 | uint32 | block number / timestamp at which tx locked
//
// Transaction input (tx_in) structure:
//
// field | size | type | description
// previous | 36 | outpoint | Previous output transaction reference
// script_len | 1-9 | var_int | Length of the signature script
// sig_script | ? | uchar[] | Script for confirming transaction authorization
// sequence | 4 | uint32 | Sender transaction version
//
// OutPoint structure:
//
// field | size | type | description
// hash | 32 | char[32] | The hash of the referenced transaction
// index | 4 | uint32 | The index of this output in the referenced transaction
//
// Transaction output (tx_out) structure:
//
// field | size | type | description
// value | 8 | int64 | Transaction value (Satoshis)
// pk_script_len | 1-9 | var_int | Length of the public key script
// pk_script | ? | uchar[] | Public key as a Bitcoin script.
//
// Variable integers (var_int) can be encoded differently depending
// on the represented value, to save space. Variable integers always
// precede an array of a variable length data type (e.g. tx_in).
//
// Variable integer encodings as a function of represented value:
//
// value | bytes | format
// <0xFD (253) | 1 | uint8
// <=0xFFFF (65535)| 3 | 0xFD followed by length as uint16
// <=0xFFFF FFFF | 5 | 0xFE followed by length as uint32
// - | 9 | 0xFF followed by length as uint64
//
// Public key scripts `pk_script` are set on the output and can
// take a number of forms. The regular transaction script is
// called 'pay-to-pubkey-hash' (P2PKH):
//
// OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
//
// OP_x are Bitcoin script opcodes. The bytes representation (including
// the 0x14 20-byte stack push) is:
//
// 0x76 0xA9 0x14 <pubKeyHash> 0x88 0xAC
//
// The <pubKeyHash> is the ripemd160 hash of the sha256 hash of
// the public key, preceded by a network version byte. (21 bytes total)
//
// Network version bytes: 0x00 (mainnet); 0x6f (testnet); 0x34 (namecoin)
//
// The Bitcoin address is derived from the pubKeyHash. The binary form is the
// pubKeyHash, plus a checksum at the end. The checksum is the first 4 bytes
// of the (32 byte) double sha256 of the pubKeyHash. (25 bytes total)
// This is converted to base58 to form the publicly used Bitcoin address.
// Mainnet P2PKH transaction scripts are to addresses beginning with '1'.
//
// P2SH ('pay to script hash') scripts only supply a script hash. The spender
// must then provide the script that would allow them to redeem this output.
// This allows for arbitrarily complex scripts to be funded using only a
// hash of the script, and moves the onus on providing the script from
// the spender to the redeemer.
//
// The P2SH script format is simple:
//
// OP_HASH160 <scriptHash> OP_EQUAL
//
// 0xA9 0x14 <scriptHash> 0x87
//
// The <scriptHash> is the ripemd160 hash of the sha256 hash of the
// redeem script. The P2SH address is derived from the scriptHash.
// Addresses are the scriptHash with a version prefix of 5, encoded as
// Base58check. These addresses begin with a '3'.
// parse a raw bitcoin transaction byte array
library BTC {
// Convert a variable integer into something useful and return it and
// the index to after it.
function parseVarInt(bytes txBytes, uint pos) returns (uint, uint) {
// the first byte tells us how big the integer is
var ibit = uint8(txBytes[pos]);
pos += 1; // skip ibit
if (ibit < 0xfd) {
return (ibit, pos);
} else if (ibit == 0xfd) {
return (getBytesLE(txBytes, pos, 16), pos + 2);
} else if (ibit == 0xfe) {
return (getBytesLE(txBytes, pos, 32), pos + 4);
} else if (ibit == 0xff) {
return (getBytesLE(txBytes, pos, 64), pos + 8);
}
}
// convert little endian bytes to uint
function getBytesLE(bytes data, uint pos, uint bits) returns (uint) {
if (bits == 8) {
return uint8(data[pos]);
} else if (bits == 16) {
return uint16(data[pos])
+ uint16(data[pos + 1]) * 2 ** 8;
} else if (bits == 32) {
return uint32(data[pos])
+ uint32(data[pos + 1]) * 2 ** 8
+ uint32(data[pos + 2]) * 2 ** 16
+ uint32(data[pos + 3]) * 2 ** 24;
} else if (bits == 64) {
return uint64(data[pos])
+ uint64(data[pos + 1]) * 2 ** 8
+ uint64(data[pos + 2]) * 2 ** 16
+ uint64(data[pos + 3]) * 2 ** 24
+ uint64(data[pos + 4]) * 2 ** 32
+ uint64(data[pos + 5]) * 2 ** 40
+ uint64(data[pos + 6]) * 2 ** 48
+ uint64(data[pos + 7]) * 2 ** 56;
}
}
// scan the full transaction bytes and return the first two output
// values (in satoshis) and addresses (in binary)
function getFirstTwoOutputs(bytes txBytes)
returns (uint, bytes20, uint, bytes20)
{
uint pos;
uint[] memory input_script_lens = new uint[](2);
uint[] memory output_script_lens = new uint[](2);
uint[] memory script_starts = new uint[](2);
uint[] memory output_values = new uint[](2);
bytes20[] memory output_addresses = new bytes20[](2);
pos = 4; // skip version
(input_script_lens, pos) = scanInputs(txBytes, pos, 0);
(output_values, script_starts, output_script_lens, pos) = scanOutputs(txBytes, pos, 2);
for (uint i = 0; i < 2; i++) {
var pkhash = parseOutputScript(txBytes, script_starts[i], output_script_lens[i]);
output_addresses[i] = pkhash;
}
return (output_values[0], output_addresses[0],
output_values[1], output_addresses[1]);
}
// Check whether `btcAddress` is in the transaction outputs *and*
// whether *at least* `value` has been sent to it.
// Check whether `btcAddress` is in the transaction outputs *and*
// whether *at least* `value` has been sent to it.
function checkValueSent(bytes txBytes, bytes20 btcAddress, uint value)
returns (bool,uint)
{
uint pos = 4; // skip version
(, pos) = scanInputs(txBytes, pos, 0); // find end of inputs
// scan *all* the outputs and find where they are
var (output_values, script_starts, output_script_lens,) = scanOutputs(txBytes, pos, 0);
// look at each output and check whether it at least value to btcAddress
for (uint i = 0; i < output_values.length; i++) {
var pkhash = parseOutputScript(txBytes, script_starts[i], output_script_lens[i]);
if (pkhash == btcAddress && output_values[i] >= value) {
return (true,output_values[i]);
}
}
}
// scan the inputs and find the script lengths.
// return an array of script lengths and the end position
// of the inputs.
// takes a 'stop' argument which sets the maximum number of
// outputs to scan through. stop=0 => scan all.
function scanInputs(bytes txBytes, uint pos, uint stop)
returns (uint[], uint)
{
uint n_inputs;
uint halt;
uint script_len;
(n_inputs, pos) = parseVarInt(txBytes, pos);
if (stop == 0 || stop > n_inputs) {
halt = n_inputs;
} else {
halt = stop;
}
uint[] memory script_lens = new uint[](halt);
for (var i = 0; i < halt; i++) {
pos += 36; // skip outpoint
(script_len, pos) = parseVarInt(txBytes, pos);
script_lens[i] = script_len;
pos += script_len + 4; // skip sig_script, seq
}
return (script_lens, pos);
}
// scan the outputs and find the values and script lengths.
// return array of values, array of script lengths and the
// end position of the outputs.
// takes a 'stop' argument which sets the maximum number of
// outputs to scan through. stop=0 => scan all.
function scanOutputs(bytes txBytes, uint pos, uint stop)
returns (uint[], uint[], uint[], uint)
{
uint n_outputs;
uint halt;
uint script_len;
(n_outputs, pos) = parseVarInt(txBytes, pos);
if (stop == 0 || stop > n_outputs) {
halt = n_outputs;
} else {
halt = stop;
}
uint[] memory script_starts = new uint[](halt);
uint[] memory script_lens = new uint[](halt);
uint[] memory output_values = new uint[](halt);
for (var i = 0; i < halt; i++) {
output_values[i] = getBytesLE(txBytes, pos, 64);
pos += 8;
(script_len, pos) = parseVarInt(txBytes, pos);
script_starts[i] = pos;
script_lens[i] = script_len;
pos += script_len;
}
return (output_values, script_starts, script_lens, pos);
}
// Slice 20 contiguous bytes from bytes `data`, starting at `start`
function sliceBytes20(bytes data, uint start) returns (bytes20) {
uint160 slice = 0;
for (uint160 i = 0; i < 20; i++) {
slice += uint160(data[i + start]) << (8 * (19 - i));
}
return bytes20(slice);
}
// returns true if the bytes located in txBytes by pos and
// script_len represent a P2PKH script
function isP2PKH(bytes txBytes, uint pos, uint script_len) returns (bool) {
return (script_len == 25) // 20 byte pubkeyhash + 5 bytes of script
&& (txBytes[pos] == 0x76) // OP_DUP
&& (txBytes[pos + 1] == 0xa9) // OP_HASH160
&& (txBytes[pos + 2] == 0x14) // bytes to push
&& (txBytes[pos + 23] == 0x88) // OP_EQUALVERIFY
&& (txBytes[pos + 24] == 0xac); // OP_CHECKSIG
}
// returns true if the bytes located in txBytes by pos and
// script_len represent a P2SH script
function isP2SH(bytes txBytes, uint pos, uint script_len) returns (bool) {
return (script_len == 23) // 20 byte scripthash + 3 bytes of script
&& (txBytes[pos + 0] == 0xa9) // OP_HASH160
&& (txBytes[pos + 1] == 0x14) // bytes to push
&& (txBytes[pos + 22] == 0x87); // OP_EQUAL
}
// Get the pubkeyhash / scripthash from an output script. Assumes
// pay-to-pubkey-hash (P2PKH) or pay-to-script-hash (P2SH) outputs.
// Returns the pubkeyhash/ scripthash, or zero if unknown output.
function parseOutputScript(bytes txBytes, uint pos, uint script_len)
returns (bytes20)
{
if (isP2PKH(txBytes, pos, script_len)) {
return sliceBytes20(txBytes, pos + 3);
} else if (isP2SH(txBytes, pos, script_len)) {
return sliceBytes20(txBytes, pos + 2);
} else {
return;
}
}
}
// File: contracts/Ownable.sol
contract Ownable {
address public owner;
address public owner1;
address public owner2;
address public owner3;
function Ownable() {
owner = msg.sender;
}
function Ownable1() {
owner1 = msg.sender;
}
function Ownable2() {
owner2 = msg.sender;
}
function Ownable3() {
owner3 = msg.sender;
}
modifier onlyOwner() {
if (msg.sender == owner)
_;
}
modifier onlyOwner1() {
if (msg.sender == owner1)
_;
}
modifier onlyOwner2() {
if (msg.sender == owner2)
_;
}
modifier onlyOwner3() {
if (msg.sender == owner3)
_;
}
function transferOwnership(address newOwner) onlyOwner {
if (newOwner != address(0)) owner = newOwner;
}
}
// File: contracts/Pausable.sol
/*
* Pausable
* Abstract contract that allows children to implement an
* emergency stop mechanism.
*/
contract Pausable is Ownable {
bool public stopped;
modifier stopInEmergency {
if (stopped) {
throw;
}
_;
}
modifier onlyInEmergency {
if (!stopped) {
throw;
}
_;
}
// called by the owner on emergency, triggers stopped state
function emergencyStop() external onlyOwner {
stopped = true;
}
// called by the owner on end of emergency, returns to normal state
function release() external onlyOwner onlyInEmergency {
stopped = false;
}
}
// File: contracts/SafeMath.sol
/**
* Math operations with safety checks
*/
contract SafeMath {
function safeMul(uint a, uint b) internal returns (uint) {
uint c = a * b;
assert(a == 0 || c / a == b);
return c;
}
function safeDiv(uint a, uint b) internal returns (uint) {
assert(b > 0);
uint c = a / b;
assert(a == b * c + a % b);
return c;
}
function safeSub(uint a, uint b) internal returns (uint) {
assert(b <= a);
return a - b;
}
function safeAdd(uint a, uint b) internal returns (uint) {
uint c = a + b;
assert(c>=a && c>=b);
return c;
}
function max64(uint64 a, uint64 b) internal constant returns (uint64) {
return a >= b ? a : b;
}
function min64(uint64 a, uint64 b) internal constant returns (uint64) {
return a < b ? a : b;
}
function max256(uint256 a, uint256 b) internal constant returns (uint256) {
return a >= b ? a : b;
}
function min256(uint256 a, uint256 b) internal constant returns (uint256) {
return a < b ? a : b;
}
}
// File: contracts/StandardToken.sol
contract Token {
uint256 public totalSupply;
function balanceOf(address _owner) constant returns (uint256 balance);
function transfer(address _to, uint256 _value) returns (bool success);
function transferFrom(address _from, address _to, uint256 _value) returns (bool success);
function approve(address _spender, uint256 _value) returns (bool success);
function allowance(address _owner, address _spender) constant returns (uint256 remaining);
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}
/* ERC 20 token */
contract StandardToken is Token {
mapping (address => uint256) balances;
mapping (address => mapping (address => uint256)) allowed;
function transfer(address _to, uint256 _value) returns (bool success) {
if (balances[msg.sender] >= _value && _value > 0) {
balances[msg.sender] -= _value;
balances[_to] += _value;
Transfer(msg.sender, _to, _value);
return true;
} else {
return false;
}
}
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) {
balances[_to] += _value;
balances[_from] -= _value;
allowed[_from][msg.sender] -= _value;
Transfer(_from, _to, _value);
return true;
} else {
return false;
}
}
function balanceOf(address _owner) constant returns (uint256 balance) {
return balances[_owner];
}
function approve(address _spender, uint256 _value) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
}
// File: contracts/Utils.sol
contract Utils{
//verifies the amount greater than zero
modifier greaterThanZero(uint256 _value){
require(_value>0);
_;
}
///verifies an address
modifier validAddress(address _add){
require(_add!=0x0);
_;
}
}
// File: contracts/Crowdsale.sol
contract Crowdsale is StandardToken, Pausable, SafeMath, Utils{
string public constant name = "Mudra";
string public constant symbol = "MDR";
uint256 public constant decimals = 18;
string public version = "1.0";
bool public tradingStarted = false;
/**
* @dev modifier that throws if trading has not started yet
*/
modifier hasStartedTrading() {
require(tradingStarted);
_;
}
/**
* @dev Allows the owner to enable the trading. This can not be undone
*/
function startTrading() only(finalOwner) {
tradingStarted = true;
}
function transfer(address _to, uint _value) hasStartedTrading returns (bool success) {super.transfer(_to, _value);}
function transferFrom(address _from, address _to, uint _value) hasStartedTrading returns (bool success) {super.transferFrom(_from, _to, _value);}
enum State{
Inactive,
Funding,
Success,
Failure
}
modifier only(address allowed) {
if (msg.sender != allowed) throw;
_;
}
mapping (address => uint) public investorETH;
uint256 public investmentETH;
mapping (address => uint) public investorBTC;
uint256 public investmentBTC;
mapping(uint256 => bool) transactionsClaimed;
uint256 public initialSupply;
address finalOwner;
uint256 public constant _totalSupply = 100 * (10**6) * 10 ** decimals; // 100M ~ 10 Crores
uint256 public fundingStartBlock; // crowdsale start block
uint256 public constant minBtcValue = 10000; // ~ approx 1$
uint256 public constant tokensPerEther = 460; // 1 ETH = 460 tokens
uint256 public constant tokensPerBTC = 115 * 10 ** 10 * 10 ** 2; // 1 btc = 11500 Tokens
// uint256 public constant tokenCreationMax = 10 * (10**6) * 10 ** decimals; // 10M ~ 1 Crores
mapping (address => uint) public balances;
address[] public investors;
//displays number of uniq investors
function investorsCount() constant external returns(uint) { return investors.length; }
function Crowdsale(uint256 _fundingStartBlock,address owner){
owner = msg.sender;
fundingStartBlock =_fundingStartBlock;
totalSupply = _totalSupply;
initialSupply = 0;
finalOwner = owner;
//check configuration if something in setup is looking weird
if (
tokensPerEther == 0
|| tokensPerBTC == 0
|| finalOwner == 0x0
|| fundingStartBlock == 0
|| totalSupply == 0
// || tokenCreationMax == 0
|| fundingStartBlock <= block.number)
throw;
}
// don't just send ether to the contract expecting to get tokens
//function() { throw; }
////@dev This function manages the Crowdsale State machine
///We make it a function and do not assign to a variable//
///so that no chance of stale variable
function getState() constant public returns(State){
///once we reach success lock the State
if(block.number<fundingStartBlock) return State.Inactive;
else if(block.number>fundingStartBlock && initialSupply<totalSupply) return State.Funding;
else if (initialSupply >= totalSupply) return State.Success;
else return State.Failure;
}
///get total tokens in that address mapping
function getTokens(address addr) public returns(uint256){
return balances[addr];
}
/// get investor in ETH
function getInvestmentETH(address addr) public returns(uint256){
return investorETH[addr];
}
/// get investor in BTC
function getInvestmentBTC(address addr) public returns(uint256){
return investorBTC[addr];
}
/// get total in ETH
function getTotalETH() public returns(uint256){
return investmentETH;
}
/// get total in BTC
function getTotalBTC() public returns(uint256){
return investmentBTC;
}
///get the block number state
function getStateFunding() public returns (uint256){
// average 6000 blocks mined in 24 hrs
if(block.number<fundingStartBlock + 180000) return 20; // 1 month 20%
else if(block.number>=fundingStartBlock+ 180001 && block.number<fundingStartBlock + 270000) return 10; // next 15 days
else if(block.number>=fundingStartBlock + 270001 && block.number<fundingStartBlock + 36000) return 5; // next 15 days
else return 0;
}
///a function using safemath to work with
///the new function
function calNewTokens(uint256 tokens) returns (uint256){
uint256 disc = getStateFunding();
tokens = safeAdd(tokens,safeDiv(safeMul(tokens,disc),100));
return tokens;
}
function() external payable stopInEmergency{
// Abort if not in Funding Active state.
if(getState() == State.Success) throw;
if (msg.value == 0) throw;
uint256 newCreatedTokens = safeMul(msg.value,tokensPerEther);
newCreatedTokens = calNewTokens(newCreatedTokens);
///since we are creating tokens we need to increase the total supply
initialSupply = safeAdd(initialSupply,newCreatedTokens);
if(initialSupply>totalSupply) throw;
if (balances[msg.sender] == 0) investors.push(msg.sender);
investorETH[msg.sender] += newCreatedTokens;
investmentETH += msg.value;
balances[msg.sender] = safeAdd(balances[msg.sender],newCreatedTokens);
// Pocket the money
if(!finalOwner.send(msg.value)) throw;
}
///token distribution initial function for the one in the exchanges
///to be done only the owner can run this function
function tokenAssignExchange(address addr,uint256 val)
external
only(finalOwner)
{
if(getState() == State.Success) throw;
if (val == 0) throw;
uint256 newCreatedTokens = safeMul(val,tokensPerEther);
newCreatedTokens = calNewTokens(newCreatedTokens);
initialSupply = safeAdd(initialSupply,newCreatedTokens);
if(initialSupply>totalSupply) throw;
if (balances[addr] == 0) investors.push(addr);
investorETH[addr] += newCreatedTokens;
investmentETH += val;
balances[addr] = safeAdd(balances[addr],newCreatedTokens);
}
///function to run when the transaction has been veified
function processTransaction(bytes txn, uint256 txHash,address addr,bytes20 btcaddr)
external
only(finalOwner)
returns (uint)
{
if(getState() == State.Success) throw;
var (output1,output2,output3,output4) = BTC.getFirstTwoOutputs(txn);
if(transactionsClaimed[txHash]) throw;
var (a,b) = BTC.checkValueSent(txn,btcaddr,minBtcValue);
if(a){
transactionsClaimed[txHash] = true;
uint256 newCreatedTokens = safeMul(b,tokensPerBTC);
///since we are creating tokens we need to increase the total supply
newCreatedTokens = calNewTokens(newCreatedTokens);
initialSupply = safeAdd(initialSupply,newCreatedTokens);
///remember not to go off the LIMITS!!
if(initialSupply>totalSupply) throw;
if (balances[addr] == 0) investors.push(addr);
investorBTC[addr] += newCreatedTokens;
investmentBTC += b;
balances[addr] = safeAdd(balances[addr],newCreatedTokens);
return 1;
}
else return 0;
}
///blacklist the users which are fraudulent
///from getting any tokens
///to do also refund just in cases
function blacklist(address addr)
external
only(finalOwner)
{
balances[addr] = 0;
}
}
pragma solidity ^0.4.17;
/**
* @title ERC20Basic
* @dev Simpler version of ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/179
*/
contract ERC20Basic {
uint256 public totalSupply;
function balanceOf(address who) constant returns (uint256);
function transfer(address to, uint256 value) returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
}
/**
* @title ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/20
*/
contract ERC20 is ERC20Basic {
function allowance(address owner, address spender) constant returns (uint256);
function transferFrom(address from, address to, uint256 value) returns (bool);
function approve(address spender, uint256 value) returns (bool);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/
library SafeMath {
function mul(uint256 a, uint256 b) internal constant returns (uint256) {
uint256 c = a * b;
assert(a == 0 || c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal constant returns (uint256) {
// assert(b > 0); // Solidity automatically throws 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;
}
function sub(uint256 a, uint256 b) internal constant returns (uint256) {
assert(b <= a);
return a - b;
}
function add(uint256 a, uint256 b) internal constant returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
/**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/
contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) returns (bool) {
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
return true;
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address _owner) constant returns (uint256 balance) {
return balances[_owner];
}
}
/**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/
contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) allowed;
/**
* @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 uint256 the amout of tokens to be transfered
*/
function transferFrom(address _from, address _to, uint256 _value) returns (bool) {
var _allowance = allowed[_from][msg.sender];
// Check is not needed because sub(_allowance, _value) will already throw if this condition is not met
require (_value <= _allowance);
balances[_to] = balances[_to].add(_value);
balances[_from] = balances[_from].sub(_value);
allowed[_from][msg.sender] = _allowance.sub(_value);
Transfer(_from, _to, _value);
return true;
}
/**
* @dev Aprove the passed address to spend the specified amount of tokens on behalf of msg.sender.
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) returns (bool) {
// 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
require((_value == 0) || (allowed[msg.sender][_spender] == 0));
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifing the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
}
/**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/
contract Ownable {
address public owner;
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
function Ownable() {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) onlyOwner {
require(newOwner != address(0));
owner = newOwner;
}
}
/**
* @title Mintable token
* @dev Simple ERC20 Token example, with mintable token creation
* @dev Issue: * https://github.com/OpenZeppelin/zeppelin-solidity/issues/120
* Based on code by TokenMarketNet: https://github.com/TokenMarketNet/ico/blob/master/contracts/MintableToken.sol
*/
contract MintableToken is StandardToken, Ownable {
event Mint(address indexed to, uint256 amount);
event MintFinished();
bool public mintingFinished = false;
address public saleAgent;
function setSaleAgent(address newSaleAgnet) {
require(msg.sender == saleAgent || msg.sender == owner);
saleAgent = newSaleAgnet;
}
function mint(address _to, uint256 _amount) returns (bool) {
require(msg.sender == saleAgent && !mintingFinished);
totalSupply = totalSupply.add(_amount);
balances[_to] = balances[_to].add(_amount);
Mint(_to, _amount);
return true;
}
/**
* @dev Function to stop minting new tokens.
* @return True if the operation was successful.
*/
function finishMinting() returns (bool) {
require((msg.sender == saleAgent || msg.sender == owner) && !mintingFinished);
mintingFinished = true;
MintFinished();
return true;
}
}
/**
* @title Pausable
* @dev Base contract which allows children to implement an emergency stop mechanism.
*/
contract Pausable is Ownable {
event Pause();
event Unpause();
bool public paused = false;
/**
* @dev modifier to allow actions only when the contract IS paused
*/
modifier whenNotPaused() {
require(!paused);
_;
}
/**
* @dev modifier to allow actions only when the contract IS NOT paused
*/
modifier whenPaused() {
require(paused);
_;
}
/**
* @dev called by the owner to pause, triggers stopped state
*/
function pause() onlyOwner whenNotPaused {
paused = true;
Pause();
}
/**
* @dev called by the owner to unpause, returns to normal state
*/
function unpause() onlyOwner whenPaused {
paused = false;
Unpause();
}
}
contract CovestingToken is MintableToken {
string public constant name = "Covesting";
string public constant symbol = "COV";
uint32 public constant decimals = 18;
mapping (address => uint) public locked;
function transfer(address _to, uint256 _value) returns (bool) {
require(locked[msg.sender] < now);
return super.transfer(_to, _value);
}
function transferFrom(address _from, address _to, uint256 _value) returns (bool) {
require(locked[_from] < now);
return super.transferFrom(_from, _to, _value);
}
function lock(address addr, uint periodInDays) {
require(locked[addr] < now && (msg.sender == saleAgent || msg.sender == addr));
locked[addr] = now + periodInDays * 1 days;
}
function () payable {
revert();
}
}
contract StagedCrowdsale is Pausable {
using SafeMath for uint;
struct Stage {
uint hardcap;
uint price;
uint invested;
uint closed;
}
uint public start;
uint public period;
uint public totalHardcap;
uint public totalInvested;
Stage[] public stages;
function stagesCount() public constant returns(uint) {
return stages.length;
}
function setStart(uint newStart) public onlyOwner {
start = newStart;
}
function setPeriod(uint newPeriod) public onlyOwner {
period = newPeriod;
}
function addStage(uint hardcap, uint price) public onlyOwner {
require(hardcap > 0 && price > 0);
Stage memory stage = Stage(hardcap.mul(1 ether), price, 0, 0);
stages.push(stage);
totalHardcap = totalHardcap.add(stage.hardcap);
}
function removeStage(uint8 number) public onlyOwner {
require(number >=0 && number < stages.length);
Stage storage stage = stages[number];
totalHardcap = totalHardcap.sub(stage.hardcap);
delete stages[number];
for (uint i = number; i < stages.length - 1; i++) {
stages[i] = stages[i+1];
}
stages.length--;
}
function changeStage(uint8 number, uint hardcap, uint price) public onlyOwner {
require(number >= 0 &&number < stages.length);
Stage storage stage = stages[number];
totalHardcap = totalHardcap.sub(stage.hardcap);
stage.hardcap = hardcap.mul(1 ether);
stage.price = price;
totalHardcap = totalHardcap.add(stage.hardcap);
}
function insertStage(uint8 numberAfter, uint hardcap, uint price) public onlyOwner {
require(numberAfter < stages.length);
Stage memory stage = Stage(hardcap.mul(1 ether), price, 0, 0);
totalHardcap = totalHardcap.add(stage.hardcap);
stages.length++;
for (uint i = stages.length - 2; i > numberAfter; i--) {
stages[i + 1] = stages[i];
}
stages[numberAfter + 1] = stage;
}
function clearStages() public onlyOwner {
for (uint i = 0; i < stages.length; i++) {
delete stages[i];
}
stages.length -= stages.length;
totalHardcap = 0;
}
function lastSaleDate() public constant returns(uint) {
return start + period * 1 days;
}
modifier saleIsOn() {
require(stages.length > 0 && now >= start && now < lastSaleDate());
_;
}
modifier isUnderHardcap() {
require(totalInvested <= totalHardcap);
_;
}
function currentStage() public saleIsOn isUnderHardcap constant returns(uint) {
for(uint i=0; i < stages.length; i++) {
if(stages[i].closed == 0) {
return i;
}
}
revert();
}
}
contract CommonSale is StagedCrowdsale {
address public multisigWallet;
uint public minPrice;
uint public totalTokensMinted;
CovestingToken public token;
function setMinPrice(uint newMinPrice) public onlyOwner {
minPrice = newMinPrice;
}
function setMultisigWallet(address newMultisigWallet) public onlyOwner {
multisigWallet = newMultisigWallet;
}
function setToken(address newToken) public onlyOwner {
token = CovestingToken(newToken);
}
function createTokens() public whenNotPaused payable {
require(msg.value >= minPrice);
uint stageIndex = currentStage();
multisigWallet.transfer(msg.value);
Stage storage stage = stages[stageIndex];
uint tokens = msg.value.mul(stage.price);
token.mint(this, tokens);
token.transfer(msg.sender, tokens);
totalTokensMinted = totalTokensMinted.add(tokens);
totalInvested = totalInvested.add(msg.value);
stage.invested = stage.invested.add(msg.value);
if(stage.invested >= stage.hardcap) {
stage.closed = now;
}
}
function() external payable {
createTokens();
}
function retrieveTokens(address anotherToken) public onlyOwner {
ERC20 alienToken = ERC20(anotherToken);
alienToken.transfer(multisigWallet, token.balanceOf(this));
}
}
contract Presale is CommonSale {
Mainsale public mainsale;
function setMainsale(address newMainsale) public onlyOwner {
mainsale = Mainsale(newMainsale);
}
function setMultisigWallet(address newMultisigWallet) public onlyOwner {
multisigWallet = newMultisigWallet;
}
function finishMinting() public whenNotPaused onlyOwner {
token.setSaleAgent(mainsale);
}
function() external payable {
createTokens();
}
function retrieveTokens(address anotherToken) public onlyOwner {
ERC20 alienToken = ERC20(anotherToken);
alienToken.transfer(multisigWallet, token.balanceOf(this));
}
}
contract Mainsale is CommonSale {
address public foundersTokensWallet;
address public bountyTokensWallet;
uint public foundersTokensPercent;
uint public bountyTokensPercent;
uint public percentRate = 100;
uint public lockPeriod;
function setLockPeriod(uint newLockPeriod) public onlyOwner {
lockPeriod = newLockPeriod;
}
function setFoundersTokensPercent(uint newFoundersTokensPercent) public onlyOwner {
foundersTokensPercent = newFoundersTokensPercent;
}
function setBountyTokensPercent(uint newBountyTokensPercent) public onlyOwner {
bountyTokensPercent = newBountyTokensPercent;
}
function setFoundersTokensWallet(address newFoundersTokensWallet) public onlyOwner {
foundersTokensWallet = newFoundersTokensWallet;
}
function setBountyTokensWallet(address newBountyTokensWallet) public onlyOwner {
bountyTokensWallet = newBountyTokensWallet;
}
function finishMinting() public whenNotPaused onlyOwner {
uint summaryTokensPercent = bountyTokensPercent + foundersTokensPercent;
uint mintedTokens = token.totalSupply();
uint summaryFoundersTokens = mintedTokens.mul(summaryTokensPercent).div(percentRate - summaryTokensPercent);
uint totalSupply = summaryFoundersTokens + mintedTokens;
uint foundersTokens = totalSupply.mul(foundersTokensPercent).div(percentRate);
uint bountyTokens = totalSupply.mul(bountyTokensPercent).div(percentRate);
token.mint(this, foundersTokens);
token.lock(foundersTokensWallet, lockPeriod * 1 days);
token.transfer(foundersTokensWallet, foundersTokens);
token.mint(this, bountyTokens);
token.transfer(bountyTokensWallet, bountyTokens);
totalTokensMinted = totalTokensMinted.add(foundersTokens).add(bountyTokens);
token.finishMinting();
}
}
contract TestConfigurator is Ownable {
CovestingToken public token;
Presale public presale;
Mainsale public mainsale;
function deploy() public onlyOwner {
token = new CovestingToken();
presale = new Presale();
presale.setToken(token);
presale.addStage(5,300);
presale.setMultisigWallet(0x055fa3f2DAc0b9Db661A4745965DDD65490d56A8);
presale.setStart(1507208400);
presale.setPeriod(2);
presale.setMinPrice(100000000000000000);
token.setSaleAgent(presale);
mainsale = new Mainsale();
mainsale.setToken(token);
mainsale.addStage(1,200);
mainsale.addStage(2,100);
mainsale.setMultisigWallet(0x4d9014eF9C3CE5790A326775Bd9F609969d1BF4f);
mainsale.setFoundersTokensWallet(0x59b398bBED1CC6c82b337B3Bd0ad7e4dCB7d4de3);
mainsale.setBountyTokensWallet(0x555635F2ea026ab65d7B44526539E0aB3874Ab24);
mainsale.setStart(1507467600);
mainsale.setPeriod(2);
mainsale.setLockPeriod(1);
mainsale.setMinPrice(100000000000000000);
mainsale.setFoundersTokensPercent(13);
mainsale.setBountyTokensPercent(5);
presale.setMainsale(mainsale);
token.transferOwnership(owner);
presale.transferOwnership(owner);
mainsale.transferOwnership(owner);
}
}
contract Configurator is Ownable {
CovestingToken public token;
// Presale public presale;
UpdateMainsale public mainsale;
function deploy() public onlyOwner {
token = new CovestingToken();
mainsale = new UpdateMainsale();
token.setSaleAgent(mainsale);
mainsale.setToken(token);
mainsale.addStage(5000,200);
mainsale.addStage(5000,180);
mainsale.addStage(10000,170);
mainsale.addStage(20000,160);
mainsale.addStage(20000,150);
mainsale.addStage(40000,130);
mainsale.setMultisigWallet(0x15A071B83396577cCbd86A979Af7d2aBa9e18970);
mainsale.setFoundersTokensWallet(0x25ED4f0D260D5e5218D95390036bc8815Ff38262);
mainsale.setBountyTokensWallet(0x717bfD30f039424B049D918F935DEdD069B66810);
mainsale.setStart(1512556862);
mainsale.setPeriod(30);
mainsale.setLockPeriod(90);
mainsale.setMinPrice(100000000000000000);
mainsale.setFoundersTokensPercent(13);
mainsale.setBountyTokensPercent(5);
token.transferOwnership(owner);
mainsale.transferOwnership(owner);
}
}
contract UpdateMainsale is CommonSale {
enum Currency { BTC, LTC, ZEC, DASH, WAVES, USD, EUR }
event ExternalSale(
Currency _currency,
bytes32 _txIdSha3,
address indexed _buyer,
uint256 _amountWei,
uint256 _tokensE18
);
event NotifierChanged(
address indexed _oldAddress,
address indexed _newAddress
);
// Address that can this crowdsale about changed external conditions.
address public notifier;
// currency_code => (sha3_of_tx_id => tokens_e18)
mapping(uint8 => mapping(bytes32 => uint256)) public externalTxs;
// Total amount of external contributions (BTC, LTC, USD, etc.) during this crowdsale.
uint256 public totalExternalSales = 0;
modifier canNotify() {
require(msg.sender == owner || msg.sender == notifier);
_;
}
// ----------------
address public foundersTokensWallet;
address public bountyTokensWallet;
uint public foundersTokensPercent;
uint public bountyTokensPercent;
uint public percentRate = 100;
uint public lockPeriod;
function setLockPeriod(uint newLockPeriod) public onlyOwner {
lockPeriod = newLockPeriod;
}
function setFoundersTokensPercent(uint newFoundersTokensPercent) public onlyOwner {
foundersTokensPercent = newFoundersTokensPercent;
}
function setBountyTokensPercent(uint newBountyTokensPercent) public onlyOwner {
bountyTokensPercent = newBountyTokensPercent;
}
function setFoundersTokensWallet(address newFoundersTokensWallet) public onlyOwner {
foundersTokensWallet = newFoundersTokensWallet;
}
function setBountyTokensWallet(address newBountyTokensWallet) public onlyOwner {
bountyTokensWallet = newBountyTokensWallet;
}
function finishMinting() public whenNotPaused onlyOwner {
uint summaryTokensPercent = bountyTokensPercent + foundersTokensPercent;
uint mintedTokens = token.totalSupply();
uint summaryFoundersTokens = mintedTokens.mul(summaryTokensPercent).div(percentRate - summaryTokensPercent);
uint totalSupply = summaryFoundersTokens + mintedTokens;
uint foundersTokens = totalSupply.mul(foundersTokensPercent).div(percentRate);
uint bountyTokens = totalSupply.mul(bountyTokensPercent).div(percentRate);
token.mint(this, foundersTokens);
token.lock(foundersTokensWallet, lockPeriod * 1 days);
token.transfer(foundersTokensWallet, foundersTokens);
token.mint(this, bountyTokens);
token.transfer(bountyTokensWallet, bountyTokens);
totalTokensMinted = totalTokensMinted.add(foundersTokens).add(bountyTokens);
token.finishMinting();
}
//----------------------------------------------------------------------
// Begin of external sales.
function setNotifier(address _notifier) public onlyOwner {
NotifierChanged(notifier, _notifier);
notifier = _notifier;
}
function externalSales(
uint8[] _currencies,
bytes32[] _txIdSha3,
address[] _buyers,
uint256[] _amountsWei,
uint256[] _tokensE18
) public whenNotPaused canNotify {
require(_currencies.length > 0);
require(_currencies.length == _txIdSha3.length);
require(_currencies.length == _buyers.length);
require(_currencies.length == _amountsWei.length);
require(_currencies.length == _tokensE18.length);
for (uint i = 0; i < _txIdSha3.length; i++) {
_externalSaleSha3(
Currency(_currencies[i]),
_txIdSha3[i],
_buyers[i],
_amountsWei[i],
_tokensE18[i]
);
}
}
function _externalSaleSha3(
Currency _currency,
bytes32 _txIdSha3, // To get bytes32 use keccak256(txId) OR sha3(txId)
address _buyer,
uint256 _amountWei,
uint256 _tokensE18
) internal {
require(_buyer > 0 && _amountWei > 0 && _tokensE18 > 0);
var txsByCur = externalTxs[uint8(_currency)];
// If this foreign transaction has been already processed in this contract.
require(txsByCur[_txIdSha3] == 0);
txsByCur[_txIdSha3] = _tokensE18;
uint stageIndex = currentStage();
Stage storage stage = stages[stageIndex];
token.mint(this, _tokensE18);
token.transfer(_buyer, _tokensE18);
totalTokensMinted = totalTokensMinted.add(_tokensE18);
totalExternalSales++;
totalInvested = totalInvested.add(_amountWei);
stage.invested = stage.invested.add(_amountWei);
if (stage.invested >= stage.hardcap) {
stage.closed = now;
}
ExternalSale(_currency, _txIdSha3, _buyer, _amountWei, _tokensE18);
}
// Get id of currency enum. --------------------------------------------
function btcId() public constant returns (uint8) {
return uint8(Currency.BTC);
}
function ltcId() public constant returns (uint8) {
return uint8(Currency.LTC);
}
function zecId() public constant returns (uint8) {
return uint8(Currency.ZEC);
}
function dashId() public constant returns (uint8) {
return uint8(Currency.DASH);
}
function wavesId() public constant returns (uint8) {
return uint8(Currency.WAVES);
}
function usdId() public constant returns (uint8) {
return uint8(Currency.USD);
}
function eurId() public constant returns (uint8) {
return uint8(Currency.EUR);
}
// Get token count by transaction id. ----------------------------------
function _tokensByTx(Currency _currency, string _txId) internal constant returns (uint256) {
return tokensByTx(uint8(_currency), _txId);
}
function tokensByTx(uint8 _currency, string _txId) public constant returns (uint256) {
return externalTxs[_currency][keccak256(_txId)];
}
function tokensByBtcTx(string _txId) public constant returns (uint256) {
return _tokensByTx(Currency.BTC, _txId);
}
function tokensByLtcTx(string _txId) public constant returns (uint256) {
return _tokensByTx(Currency.LTC, _txId);
}
function tokensByZecTx(string _txId) public constant returns (uint256) {
return _tokensByTx(Currency.ZEC, _txId);
}
function tokensByDashTx(string _txId) public constant returns (uint256) {
return _tokensByTx(Currency.DASH, _txId);
}
function tokensByWavesTx(string _txId) public constant returns (uint256) {
return _tokensByTx(Currency.WAVES, _txId);
}
function tokensByUsdTx(string _txId) public constant returns (uint256) {
return _tokensByTx(Currency.USD, _txId);
}
function tokensByEurTx(string _txId) public constant returns (uint256) {
return _tokensByTx(Currency.EUR, _txId);
}
// End of external sales.
//----------------------------------------------------------------------
}
contract UpdateConfigurator is Ownable {
CovestingToken public token;
UpdateMainsale public mainsale;
function deploy() public onlyOwner {
mainsale = new UpdateMainsale();
token = CovestingToken(0xc64b514a25b156c645f274F24064db7480618087);
mainsale.setToken(token);
mainsale.addStage(5000,200);
mainsale.addStage(5000,180);
mainsale.addStage(10000,170);
mainsale.addStage(20000,160);
mainsale.addStage(20000,150);
mainsale.addStage(40000,130);
mainsale.setMultisigWallet(0x21295A67467c7E73eB0715021ed1f93EB027A34f);
mainsale.setFoundersTokensWallet(0x97816800faC26942827b49bB76df4d68Ba545025);
mainsale.setBountyTokensWallet(0xfD875d45e4D86dD3f641100A5a7C345411090439);
mainsale.setStart(1511528400);
mainsale.setPeriod(30);
mainsale.setLockPeriod(90);
mainsale.setMinPrice(100000000000000000);
mainsale.setFoundersTokensPercent(13);
mainsale.setBountyTokensPercent(5);
mainsale.setNotifier(owner);
mainsale.transferOwnership(owner);
}
}
contract IncreaseTokensOperator is Ownable {
using SafeMath for uint256;
mapping (address => bool) public authorized;
mapping (address => bool) public minted;
address[] public mintedList;
CovestingToken public token;
uint public increaseK = 10;
modifier onlyAuthorized() {
require(owner == msg.sender || authorized[msg.sender]);
_;
}
function extraMint(address tokenHolder) public onlyAuthorized {
uint value = token.balanceOf(tokenHolder);
uint targetValue = value.mul(increaseK);
uint diffValue = targetValue.sub(value);
token.mint(this, diffValue);
token.transfer(tokenHolder, diffValue);
minted[tokenHolder] = true;
mintedList.push(tokenHolder);
}
function extraMintArray(address[] tokenHolders) public onlyAuthorized {
for(uint i = 0; i < tokenHolders.length; i++) {
address tokenHolder = tokenHolders[i];
require(!minted[tokenHolder]);
uint value = token.balanceOf(tokenHolder);
uint targetValue = value.mul(increaseK);
uint diffValue = targetValue.sub(value);
token.mint(this, diffValue);
token.transfer(tokenHolder, diffValue);
minted[tokenHolder] = true;
mintedList.push(tokenHolder);
}
}
function setIncreaseK(uint newIncreaseK) public onlyOwner {
increaseK = newIncreaseK;
}
function setToken(address newToken) public onlyOwner {
token = CovestingToken(newToken);
}
function authorize(address to) public onlyAuthorized {
require(!authorized[to]);
authorized[to] = true;
}
function unauthorize(address to) public onlyAuthorized {
require(authorized[to]);
authorized[to] = false;
}
}
/*
Bitsign escrow contract v0.1
*/
pragma solidity ^0.4.15;
contract Escrow {
//State variables
address public buyer;
address public seller;
address public arbiter;
uint public value;
uint public endTime;
//Events
event Payout(uint _value, address _to);
event Refund(uint _value, address _to);
/**
TODO: doc
*/
function Escrow (address _seller, address _buyer, uint _endtime) public payable {
arbiter = msg.sender;
value = msg.value;
buyer = _buyer;
seller = _seller;
endTime = _endtime;
}
/**
TODO: Si las condiciones del contrato se cumplen, el arbiter o comprador puede ejecutar
esta función para pagar al vendedor.
*/
function pay() external {
if (msg.sender == buyer || msg.sender == arbiter) {
Payout(this.balance, seller);
seller.transfer(this.balance);
}
}
/**
TODO: Si las condiciones no se cumplen por algún motivo, se ejecuta
esta función para devolver al comprador los fondos.
*/
function refund() external {
if (msg.sender == seller || msg.sender == arbiter) {
Refund(this.balance, buyer);
buyer.transfer(this.balance);
}
}
/**
TODO: Devuelve el balance depositando en el contrato
*/
function getBalance() external constant returns (uint) {
return this.balance;
}
/**
TODO: doc
*/
function kill() public {
if (msg.sender == arbiter)
selfdestruct(msg.sender);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment