Skip to content

Instantly share code, notes, and snippets.

@Manasse228
Created March 2, 2019 21:22
Show Gist options
  • Save Manasse228/4604bf49458b385205bba0ea0a7ac412 to your computer and use it in GitHub Desktop.
Save Manasse228/4604bf49458b385205bba0ea0a7ac412 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.25+commit.59dbf8f1.js&optimize=true&gist=
pragma solidity 0.5.0;
// ----------------------------------------------------------------------------
// Safe maths
// ----------------------------------------------------------------------------
library SafeMath {
function add(uint a, uint b) internal pure returns (uint c) {
c = a + b;
require(c >= a);
}
function sub(uint a, uint b) internal pure returns (uint c) {
require(b <= a);
c = a - b;
}
function mul(uint a, uint b) internal pure returns (uint c) {
c = a * b;
require(a == 0 || c / a == b);
}
function div(uint a, uint b) internal pure returns (uint c) {
require(b > 0);
c = a / b;
}
}
// ----------------------------------------------------------------------------
// Owned contract
// ----------------------------------------------------------------------------
contract Owned {
address payable public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() public {
owner = msg.sender;
}
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 payable newOwner) public onlyOwner {
require(newOwner != address(0));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
// ----------------------------------------------------------------------------
// ERC Token Standard #20 Interface
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// ----------------------------------------------------------------------------
contract ERC20Interface {
function totalSupply() public view returns (uint);
function balanceOf(address tokenOwner) public view returns (uint balance);
function allowance(address tokenOwner, address spender) public view 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);
event AddSupply(uint256 oldSupply, uint256 newSupply);
}
// ----------------------------------------------------------------------------
// ERC Token Standard #20
//
// ----------------------------------------------------------------------------
contract Colibri_Token is ERC20Interface, Owned {
using SafeMath for uint;
string public constant name = "Colibri Money";
string public constant symbol = "COMO";
uint8 public constant decimals = 18;
uint constant public _decimals18 = uint(10) ** decimals;
uint public _totalSupply = 500000000 * _decimals18;
constructor() public {
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ----------------------------------------------------------------------------
// mappings for implementing ERC20
// ERC20 standard functions
// ----------------------------------------------------------------------------
// Balances for each account
mapping(address => uint) balances;
// Owner of account approves the transfer of an amount to another account
mapping(address => mapping(address => uint)) allowed;
function totalSupply() public view returns (uint) {
return _totalSupply;
}
// Get the token balance for account `tokenOwner`
function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
function _transfer(address _from, address _toAddress, uint _tokens) private {
balances[_from] = balances[_from].sub(_tokens);
addToBalance(_toAddress, _tokens);
emit Transfer(_from, _toAddress, _tokens);
}
// Transfer the balance from owner's account to another account
function transfer(address _add, uint _tokens) public returns (bool success) {
require(_add != address(0));
require(_tokens <= balances[msg.sender]);
_transfer(msg.sender, _add, _tokens);
return true;
}
/*
Allow `spender` to withdraw from your account, multiple times,
up to the `tokens` amount.If this function is called again it
overwrites the current allowance with _value.
*/
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
/**
* @dev Increase the amount of tokens that an owner allowed to a 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
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/*
Send `tokens` amount of tokens from address `from` to address `to`
The transferFrom method is used for a withdraw workflow,
allowing contracts to send tokens on your behalf,
for example to "deposit" to a contract address and/or to charge
fees in sub-currencies; the command should fail unless the _from
account has deliberately authorized the sender of the message via
some mechanism; we propose these standardized APIs for approval:
*/
function transferFrom(address from, address _toAddr, uint tokens) public returns (bool success) {
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
_transfer(from, _toAddr, tokens);
return true;
}
// address not null
modifier addressNotNull(address _addr){
require(_addr != address(0));
_;
}
// Add to balance
function addToBalance(address _address, uint _amount) internal {
balances[_address] = balances[_address].add(_amount);
}
/**
* @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 payable newOwner) public onlyOwner {
require(newOwner != address(0));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
function () payable external {
owner.transfer(msg.value);
}
function addSupply(uint256 supply) public onlyOwner returns(uint256){
require (balances[msg.sender] < 200 * _decimals18);
_totalSupply = _totalSupply.add(supply);
emit AddSupply(balances[msg.sender], _totalSupply);
return _totalSupply;
}
}
pragma solidity ^0.4.24;
/**
* @title ERC20Basic
* @dev Simpler version of ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/179
*/
contract ERC20Basic {
function totalSupply() public view returns (uint256);
function balanceOf(address who) public view 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 view 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 SafeMath
* @dev Math operations with safety checks that throw on error
*/
library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
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 a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
}
/**
* @title Crowdsale
* @dev Crowdsale is a base contract for managing a token crowdsale,
* allowing investors to purchase tokens with ether. This contract implements
* such functionality in its most fundamental form and can be extended to provide additional
* functionality and/or custom behavior.
* The external interface represents the basic interface for purchasing tokens, and conform
* the base architecture for crowdsales. They are *not* intended to be modified / overriden.
* The internal interface conforms the extensible and modifiable surface of crowdsales. Override
* the methods to add functionality. Consider using 'super' where appropiate to concatenate
* behavior.
*/
contract Crowdsale {
using SafeMath for uint256;
// The token being sold
ERC20 public token;
// Address where funds are collected
address public wallet;
// How many token units a buyer gets per wei
uint256 public rate;
// Amount of wei raised
uint256 public weiRaised;
/**
* Event for token purchase logging
* @param purchaser who paid for the tokens
* @param beneficiary who got the tokens
* @param value weis paid for purchase
* @param amount amount of tokens purchased
*/
event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount);
/**
* @param _rate Number of token units a buyer gets per wei
* @param _wallet Address where collected funds will be forwarded to
* @param _token Address of the token being sold
*/
constructor(uint256 _rate, address _wallet, ERC20 _token) public {
require(_rate > 0);
require(_wallet != address(0));
require(_token != address(0));
rate = _rate;
wallet = _wallet;
token = _token;
}
// -----------------------------------------
// Crowdsale external interface
// -----------------------------------------
/**
* @dev fallback function ***DO NOT OVERRIDE***
*/
function () external payable {
buyTokens(msg.sender);
}
/**
* @dev low level token purchase ***DO NOT OVERRIDE***
* @param _beneficiary Address performing the token purchase
*/
function buyTokens(address _beneficiary) public payable {
uint256 weiAmount = msg.value;
require(_beneficiary != address(0));
require(weiAmount != 0);
// calculate token amount to be created
uint256 tokens = _getTokenAmount(weiAmount);
// update state
weiRaised = weiRaised.add(weiAmount);
_processPurchase(_beneficiary, tokens);
emit TokenPurchase( msg.sender, _beneficiary, weiAmount,tokens);
_forwardFunds();
}
// -----------------------------------------
// Internal interface (extensible)
// -----------------------------------------
/**
* @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends its tokens.
* @param _beneficiary Address performing the token purchase
* @param _tokenAmount Number of tokens to be emitted
*/
function _deliverTokens(address _beneficiary, uint256 _tokenAmount) internal {
token.transfer(_beneficiary, _tokenAmount);
}
/**
* @dev Executed when a purchase has been validated and is ready to be executed. Not necessarily emits/sends tokens.
* @param _beneficiary Address receiving the tokens
* @param _tokenAmount Number of tokens to be purchased
*/
function _processPurchase(address _beneficiary, uint256 _tokenAmount) internal {
_deliverTokens(_beneficiary, _tokenAmount);
}
/**
* @dev Override to extend the way in which ether is converted to tokens.
* @param _weiAmount Value in wei to be converted into tokens
* @return Number of tokens that can be purchased with the specified _weiAmount
*/
function _getTokenAmount(uint256 _weiAmount) internal view returns (uint256) {
return _weiAmount.mul(rate);
}
/**
* @dev Determines how ETH is stored/forwarded on purchases.
*/
function _forwardFunds() internal {
wallet.transfer(msg.value);
}
}
/**
* @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.
*/
constructor() public {
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) public onlyOwner {
require(newOwner != address(0));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
/**
* @title EncrybitCrowdsale
* @dev Crowdsale that locks tokens from withdrawal until it ends.
*/
contract EncrybitCrowdsale is Crowdsale, Ownable {
using SafeMath for uint256;
/////////////////////// VARIABLE INITIALIZATION ///////////////////////
uint256 constant startTimeForPreSale = 12;
uint256 constant endTimeForPreSale = 12;
uint256 constant startTimeForCrowdSale = 12;
uint256 constant endTimeForCrowdSale = 12;
/////////////////////// MODIFIERS ///////////////////////
// Ensure actions can only happen after crowdfund ends
modifier notBeforeCrowdfundEnds(){
require(now >= endTimeForCrowdSale);
_;
}
modifier notBeforeCrowdfundStart(){
require(now >= startTimeForPreSale);
_;
}
/////////////////////// EVENTS ///////////////////////
/**
* Event for token withdrawal logging
* @param receiver who receive the tokens
* @param amount amount of tokens sent
*/
event TokenDelivered(address indexed receiver, uint256 amount);
/**
* Event for token adding by referral program
* @param beneficiary who got the tokens
* @param amount amount of tokens added
*/
event TokenAdded(address indexed beneficiary, uint256 amount);
/////////////////////// ///////////////////////
// Map of all purchaiser's balances (doesn't include bounty amounts)
mapping(address => uint256) public balances;
// Amount of issued tokens
uint256 public tokensIssued;
// Bonus tokens rate multiplier x1000 (i.e. 1200 is 1.2 x 1000 = 120% x1000 = +20% bonus)
uint256 public bonusMultiplier;
// Is a crowdsale closed?
bool public closed;
/**
* Init crowdsale by setting its params
*
* @param _rate Number of token units a buyer gets per wei
* @param _wallet Address where collected funds will be forwarded to
* @param _token Address of the token being sold
* @param _bonusMultiplier bonus tokens rate multiplier x1000
*/
constructor ( uint256 _rate,address _wallet, ERC20 _token, uint256 _bonusMultiplier )
Crowdsale(_rate, _wallet, _token ) public {
bonusMultiplier = _bonusMultiplier;
}
/**
* @dev Withdraw tokens only after crowdsale ends.
*/
function withdrawTokens() public {
_withdrawTokensFor(msg.sender);
}
/**
* @dev Overrides parent by storing balances instead of issuing tokens right away.
* @param _beneficiary Token purchaser
* @param _tokenAmount Amount of tokens purchased
*/
function _processPurchase(address _beneficiary, uint256 _tokenAmount) internal {
require(!hasClosed());
balances[_beneficiary] = balances[_beneficiary].add(_tokenAmount);
tokensIssued = tokensIssued.add(_tokenAmount);
}
/**
* @dev Overrides the way in which ether is converted to tokens.
* @param _weiAmount Value in wei to be converted into tokens
* @return Number of tokens that can be purchased with the specified _weiAmount
*/
function _getTokenAmount(uint256 _weiAmount) internal view returns (uint256) {
return _weiAmount.mul(rate).mul(bonusMultiplier).div(1000);
}
/**
* @dev Deliver tokens to receiver_ after crowdsale ends.
*/
function withdrawTokensFor(address receiver_) public onlyOwner {
_withdrawTokensFor(receiver_);
}
/**
* @dev Checks whether the period in which the crowdsale is open has already elapsed.
* @return Whether crowdsale period has elapsed
*/
function hasClosed() public view returns (bool) {
return closed;
}
/**
* @dev Closes the period in which the crowdsale is open.
*/
function closeCrowdsale(bool closed_) public onlyOwner {
closed = closed_;
}
/**
* @dev set the bonus multiplier.
*/
function setBonusMultiplier(uint256 bonusMultiplier_) public onlyOwner {
bonusMultiplier = bonusMultiplier_;
}
/**
* @dev Withdraw tokens excess on the contract after crowdsale.
*/
function postCrowdsaleWithdraw(uint256 _tokenAmount) public onlyOwner {
token.transfer(wallet, _tokenAmount);
}
/**
* @dev Add tokens for specified beneficiary (referral system tokens, for example).
* @param _beneficiary Token purchaser
* @param _tokenAmount Amount of tokens added
*/
function addTokens(address _beneficiary, uint256 _tokenAmount) public onlyOwner {
balances[_beneficiary] = balances[_beneficiary].add(_tokenAmount);
tokensIssued = tokensIssued.add(_tokenAmount);
emit TokenAdded(_beneficiary, _tokenAmount);
}
/**
* @dev Withdraw tokens for receiver_ after crowdsale ends.
*/
function _withdrawTokensFor(address receiver_) internal {
require(hasClosed());
uint256 amount = balances[receiver_];
require(amount > 0);
balances[receiver_] = 0;
emit TokenDelivered(receiver_, amount);
_deliverTokens(receiver_, amount);
}
// Returns EBT disbursed per 1 ETH depending on current time
function getRate() public constant returns (uint price) {
if (now > (startTimeForPreSale + 3 weeks)) {
return 1275; // week 4
} else if (now > (startTimeForPreSale + 2 weeks)) {
return 1700; // week 3
} else if (now > (startTimeForPreSale + 1 weeks)) {
return 2250; // week 2
} else {
return 3000; // week 1
}
}
}
// Minimum and Maximium Ether to purchase
pragma solidity 0.4.24;
import {SafeMath} from "./SafeMath.sol";
import {ERC20Interface} from "./ERC20Interface.sol";
import {Owned} from "./Owned.sol";
contract CasperToken is ERC20Interface, Owned {
using SafeMath for uint;
string public constant name = "Casper Token";
string public constant symbol = "CST";
uint8 public constant decimals = 18;
uint constant public cstToMicro = uint(10) ** decimals;
// This constants reflects CST token distribution
uint constant public _totalSupply = 440000000 * cstToMicro;
uint constant public preICOSupply = 13000000 * cstToMicro;
uint constant public presaleSupply = 183574716 * cstToMicro;
uint constant public crowdsaleSupply = 19750000 * cstToMicro;
uint constant public communitySupply = 66000000 * cstToMicro;
uint constant public systemSupply = 35210341 * cstToMicro;
uint constant public investorSupply = 36714943 * cstToMicro;
uint constant public teamSupply = 66000000 * cstToMicro;
uint constant public adviserSupply = 7000000 * cstToMicro;
uint constant public bountySupply = 8800000 * cstToMicro;
uint constant public referralSupply = 3950000 * cstToMicro;
// This variables accumulate amount of sold CST during
// presale, crowdsale, or given to investors as bonus.
uint public presaleSold = 0;
uint public crowdsaleSold = 0;
uint public investorGiven = 0;
// Amount of ETH received during ICO
uint public weiSold = 0;
uint constant public softcapUSD = 4500000;
uint constant public preicoUSD = 1040000;
// Presale lower bound in dollars.
uint constant public crowdsaleMinUSD = cstToMicro * 10 * 100 / 12;
uint constant public bonusLevel0 = cstToMicro * 10000 * 100 / 12; // 10000$
uint constant public bonusLevel100 = cstToMicro * 100000 * 100 / 12; // 100000$
// Tokens are unlocked in 5 stages, by 20% (see doc to checkTransfer)
// All dates are stored as timestamps.
uint constant public unlockDate1 = 1538179199; // 28.09.2018 23:59:59
uint constant public unlockDate2 = 1543622399; // 30.11.2018 23:59:59
uint constant public unlockDate3 = 1548979199; // 31.01.2019 23:59:59
uint constant public unlockDate4 = 1553903999; // 29.03.2019 23:59:59
uint constant public unlockDate5 = 1559347199; // 31.05.2019 23:59:59
uint constant public teamUnlock1 = 1549065600; // 2.02.2019
uint constant public teamUnlock2 = 1564704000; // 2.08.2019
uint constant public teamUnlock3 = 1580601600; // 2.02.2020
uint constant public teamUnlock4 = 1596326400; // 2.08.2020
uint constant public teamETHUnlock1 = 1535846400; // 2.09.2018
uint constant public teamETHUnlock2 = 1538438400; // 2.10.2018
uint constant public teamETHUnlock3 = 1541116800; // 2.11.2018
//https://casperproject.atlassian.net/wiki/spaces/PROD/pages/277839878/Smart+contract+ICO
// Presale 10.06.2018 - 22.07.2018
// Crowd-sale 23.07.2018 - 2.08.2018 (16.08.2018)
uint constant public presaleStartTime = 1528588800;
uint constant public crowdsaleStartTime = 1532304000;
uint public crowdsaleEndTime = 1533168000;
uint constant public crowdsaleHardEndTime = 1534377600;
//address constant CsperWallet = 0x6A5e633065475393211aB623286200910F465d02;
constructor() public {
admin = owner;
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
modifier onlyAdmin {
require(msg.sender == admin);
_;
}
modifier onlyOwnerAndDirector {
require(msg.sender == owner || msg.sender == director);
_;
}
address admin;
function setAdmin(address _newAdmin) public onlyOwnerAndDirector {
admin = _newAdmin;
}
address director;
function setDirector(address _newDirector) public onlyOwner {
director = _newDirector;
}
bool assignedPreico = false;
/// @notice assignPreicoTokens transfers 10x tokens to pre-ICO participants
function assignPreicoTokens() public onlyOwnerAndDirector {
require(!assignedPreico);
assignedPreico = true;
_freezeTransfer(0xb424958766e736827Be5A441bA2A54bEeF54fC7C, 10 * 19514560000000000000000);
_freezeTransfer(0xF5dF9C2aAe5118b64Cda30eBb8d85EbE65A03990, 10 * 36084880000000000000000);
_freezeTransfer(0x5D8aCe48970dce4bcD7f985eDb24f5459Ef184Ec, 10 * 2492880000000000000000);
_freezeTransfer(0xcD6d5b09a34562a1ED7857B19b32bED77417655b, 10 * 1660880000000000000000);
_freezeTransfer(0x50f73AC8435E4e500e37FAb8802bcB840bf4b8B8, 10 * 94896880000000000000000);
_freezeTransfer(0x65Aa068590216cb088f4da28190d8815C31aB330, 10 * 16075280000000000000000);
_freezeTransfer(0x2046838D148196a5117C4026E21C165785bD3982, 10 * 5893680000000000000000);
_freezeTransfer(0x458e1f1050C34f5D125437fcEA0Df0aA9212EDa2, 10 * 32772040882120167215360);
_freezeTransfer(0x12B687E19Cef53b2A709e9b98C4d1973850cA53F, 10 * 70956080000000000000000);
_freezeTransfer(0x1Cf5daAB09155aaC1716Aa92937eC1c6D45720c7, 10 * 3948880000000000000000);
_freezeTransfer(0x32fAAdFdC7938E7FbC7386CcF546c5fc382ed094, 10 * 88188880000000000000000);
_freezeTransfer(0xC4eA6C0e9d95d957e75D1EB1Fbe15694CD98336c, 10 * 81948880000000000000000);
_freezeTransfer(0xB97D3d579d35a479c20D28988A459E3F35692B05, 10 * 121680000000000000000);
_freezeTransfer(0x65AD745047633C3402d4BC5382f72EA3A9eCFe47, 10 * 5196880000000000000000);
_freezeTransfer(0xd0BEF2Fb95193f429f0075e442938F5d829a33c8, 10 * 223388880000000000000000);
_freezeTransfer(0x9Fc87C3d44A6374D48b2786C46204F673b0Ae236, 10 * 28284880000000000000000);
_freezeTransfer(0x42C73b8945a82041B06428359a94403a2e882406, 10 * 13080080000000000000000);
_freezeTransfer(0xa4c9595b90BBa7B4d805e555E477200C61711F3a, 10 * 6590480000000000000000);
_freezeTransfer(0xb93b8ceD7CD86a667E12104831b4d514365F9DF8, 10 * 116358235759665569280);
_freezeTransfer(0xa94F999b3f76EB7b2Ba7B17fC37E912Fa2538a87, 10 * 10389600000000000000000);
_freezeTransfer(0xD65B9b98ca08024C3c19868d42C88A3E47D67120, 10 * 25892880000000000000000);
_freezeTransfer(0x3a978a9Cc36f1FE5Aab6D31E41c08d8380ad0ACB, 10 * 548080000000000000000);
_freezeTransfer(0xBD46d909D55d760E2f79C5838c5C42E45c0a853A, 10 * 7526480000000000000000);
_freezeTransfer(0xdD9d289d4699fDa518cf91EaFA029710e3Cbb7AA, 10 * 3324880000000000000000);
_freezeTransfer(0x8671B362902C3839ae9b4bc099fd24CdeFA026F4, 10 * 21836880000000000000000);
_freezeTransfer(0xf3C25Ee648031B28ADEBDD30c91056c2c5cd9C6b, 10 * 132284880000000000000000);
_freezeTransfer(0x1A2392fB72255eAe19BB626678125A506a93E363, 10 * 61772880000000000000000);
_freezeTransfer(0xCE2cEa425f7635557CFC00E18bc338DdE5B16C9A, 10 * 105360320000000000000000);
_freezeTransfer(0x952AD1a2891506AC442D95DA4C0F1AE70A27b677, 10 * 100252880000000000000000);
_freezeTransfer(0x5eE1fC4D251143Da96db2a5cD61507f2203bf7b7, 10 * 80492880000000000000000);
}
bool assignedTeam = false;
/// @notice assignTeamTokens assigns tokens to team members
/// @notice tokens for team have their own supply
function assignTeamTokens() public onlyOwnerAndDirector {
require(!assignedTeam);
assignedTeam = true;
_teamTransfer(0x1E21f744d91994D19f2a61041CD7cCA571185dfc, 13674375 * cstToMicro); // ArK
_teamTransfer(0x4CE4Ea57c40bBa26B7b799d5e0b4cd063B034c8A, 9920625 * cstToMicro); // Vi4
_teamTransfer(0xdCd8a8e561d23Ca710f23E7612F1D4E0dE9bde83, 1340625 * cstToMicro); // Se4
_teamTransfer(0x0dFFA8624A1f512b8dcDE807F8B0Eab68672e5D5, 13406250 * cstToMicro); // AnD
_teamTransfer(0xE091180bB0C284AA0Bd15C6888A41aba45c54AF0, 13138125 * cstToMicro); // VlM
_teamTransfer(0xcdB7A51bA9af93a7BFfe08a31E4C6c5f9068A051, 3960000 * cstToMicro); // NuT
_teamTransfer(0x57Bd10E12f789B74071d62550DaeB3765Ad83834, 3960000 * cstToMicro); // AlK
_teamTransfer(0xEE74922eaF503463a8b20aFaD83d42F28D59f45d, 3960000 * cstToMicro); // StK
_teamTransfer(0x58681a49A6f9D61eB368241a336628781afD5f87, 1320000 * cstToMicro); // DeP
_teamTransfer(0x3C4662b4677dC81f16Bf3c823A7E6CE1fF7e94d7, 80000 * cstToMicro); // YuM
_teamTransfer(0x041A1e96E0C9d3957613071c104E44a9c9d43996, 150000 * cstToMicro); // IgK
_teamTransfer(0xD63d63D2ADAF87B0Edc38218b0a2D27FD909d8B1, 100000 * cstToMicro); // SeT
_teamTransfer(0xd0d49Da78BbCBb416152dC41cc7acAb559Fb8275, 80000 * cstToMicro); // ArM
_teamTransfer(0x75FdfAc64c27f5B5f0823863Fe0f2ddc660A376F, 100000 * cstToMicro); // Lera
_teamTransfer(0xb66AFf323d97EF52192F170fF0F16D0a05Ebe56C, 60000 * cstToMicro); // SaBuh
_teamTransfer(0xec6234E34477f7A19cD3D67401003675522a4Fad, 60000 * cstToMicro); // SaV
_teamTransfer(0x1be50e8337F99983ECd4A4b15a74a5a795B73dF9, 40000 * cstToMicro); // Olga
_teamTransfer(0x4c14DB011065e72C6E839bd826d101Ec09d3C530, 833000 * cstToMicro); // VaB
_teamTransfer(0x7891C07b20fFf1918fAD43CF6fc7E3f83900f06d, 50000 * cstToMicro); // Artur
_teamTransfer(0x27996b3c1EcF2e7cbc5f31dE7Bca17EFCb398617, 150000 * cstToMicro); // EvS
}
/// @nptice kycPassed is executed by backend and tells SC
/// that particular client has passed KYC
mapping(address => bool) public kyc;
mapping(address => address) public referral;
function kycPassed(address _mem, address _ref) public onlyAdmin {
kyc[_mem] = true;
if (_ref == richardAddr || _ref == wuguAddr) {
referral[_mem] = _ref;
}
}
// mappings for implementing ERC20
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// mapping for implementing unlock mechanic
mapping(address => uint) freezed;
mapping(address => uint) teamFreezed;
// ERC20 standard functions
function totalSupply() public view returns (uint) {
return _totalSupply;
}
function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
function _transfer(address _from, address _to, uint _tokens) private {
balances[_from] = balances[_from].sub(_tokens);
balances[_to] = balances[_to].add(_tokens);
emit Transfer(_from, _to, _tokens);
}
function transfer(address _to, uint _tokens) public returns (bool success) {
checkTransfer(msg.sender, _tokens);
_transfer(msg.sender, _to, _tokens);
return true;
}
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
checkTransfer(from, tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
_transfer(from, to, tokens);
return true;
}
/// @notice checkTransfer ensures that `from` can send only unlocked tokens
/// @notice this function is called for every transfer
/// We unlock PURCHASED and BONUS tokens in 5 stages:
/// after 28.09.2018 20% are unlocked
/// after 30.11.2018 40% are unlocked
/// after 31.01.2019 60% are unlocked
/// after 29.03.2019 80% are unlocked
/// after 31.05.2019 100% are unlocked
function checkTransfer(address from, uint tokens) public view {
uint newBalance = balances[from].sub(tokens);
uint total = 0;
if (now < unlockDate5) {
require(now >= unlockDate1);
uint frzdPercent = 0;
if (now < unlockDate2) {
frzdPercent = 80;
} else if (now < unlockDate3) {
frzdPercent = 60;
} else if (now < unlockDate4) {
frzdPercent = 40;
} else {
frzdPercent = 20;
}
total = freezed[from].mul(frzdPercent).div(100);
require(newBalance >= total);
}
if (now < teamUnlock4 && teamFreezed[from] > 0) {
uint p = 0;
if (now < teamUnlock1) {
p = 100;
} else if (now < teamUnlock2) {
p = 75;
} else if (now < teamUnlock3) {
p = 50;
} else if (now < teamUnlock4) {
p = 25;
}
total = total.add(teamFreezed[from].mul(p).div(100));
require(newBalance >= total);
}
}
/// @return ($ received, ETH received, CST sold)
function ICOStatus() public view returns (uint usd, uint eth, uint cst) {
usd = presaleSold.mul(12).div(10**20) + crowdsaleSold.mul(16).div(10**20);
usd = usd.add(preicoUSD); // pre-ico tokens
return (usd, weiSold + preicoUSD.mul(10**8).div(ethRate), presaleSold + crowdsaleSold);
}
function checkICOStatus() public view returns(bool) {
uint eth;
uint cst;
(, eth, cst) = ICOStatus();
uint dollarsRecvd = eth.mul(ethRate).div(10**8);
// 26 228 800$
return dollarsRecvd >= 25228966 || (cst == presaleSupply + crowdsaleSupply) || now > crowdsaleEndTime;
}
bool icoClosed = false;
function closeICO() public onlyOwner {
require(!icoClosed);
icoClosed = checkICOStatus();
}
/// @notice by agreement, we can transfer $4.8M from bank
/// after softcap is reached.
/// @param _to wallet to send CST to
/// @param _usd amount of dollars which is withdrawn
uint bonusTransferred = 0;
uint constant maxUSD = 4800000;
function transferBonus(address _to, uint _usd) public onlyOwner {
bonusTransferred = bonusTransferred.add(_usd);
require(bonusTransferred <= maxUSD);
uint cst = _usd.mul(100).mul(cstToMicro).div(12); // presale tariff
presaleSold = presaleSold.add(cst);
require(presaleSold <= presaleSupply);
weiSold = weiSold.add(_usd.mul(10**8).div(ethRate));
_freezeTransfer(_to, cst);
}
/// @notice extend crowdsale for 2 weeks
function prolongCrowdsale() public onlyOwnerAndDirector {
require(now < crowdsaleEndTime);
crowdsaleEndTime = crowdsaleHardEndTime;
}
// 100 000 000 Ether in dollars
uint public ethRate = 0;
uint public ethRateMax = 0;
uint public ethLastUpdate = 0;
function setETHRate(uint _rate) public onlyAdmin {
require(ethRateMax == 0 || _rate < ethRateMax);
ethRate = _rate;
ethLastUpdate = now;
}
// 100 000 000 BTC in dollars
uint public btcRate = 0;
uint public btcRateMax = 0;
uint public btcLastUpdate;
function setBTCRate(uint _rate) public onlyAdmin {
require(btcRateMax == 0 || _rate < btcRateMax);
btcRate = _rate;
btcLastUpdate = now;
}
/// @notice setMaxRate sets max rate for both BTC/ETH to soften
/// negative consequences in case our backend gots hacked.
function setMaxRate(uint ethMax, uint btcMax) public onlyOwnerAndDirector {
ethRateMax = ethMax;
btcRateMax = btcMax;
}
/// @notice _sellPresale checks CST purchases during crowdsale
function _sellPresale(uint cst) private {
require(cst >= bonusLevel0.mul(9950).div(10000));
presaleSold = presaleSold.add(cst);
require(presaleSold <= presaleSupply);
}
/// @notice _sellCrowd checks CST purchases during crowdsale
function _sellCrowd(uint cst, address _to) private {
require(cst >= crowdsaleMinUSD);
if (crowdsaleSold.add(cst) <= crowdsaleSupply) {
crowdsaleSold = crowdsaleSold.add(cst);
} else {
presaleSold = presaleSold.add(crowdsaleSold).add(cst).sub(crowdsaleSupply);
require(presaleSold <= presaleSupply);
crowdsaleSold = crowdsaleSupply;
}
if (now < crowdsaleStartTime + 3 days) {
if (whitemap[_to] >= cst) {
whitemap[_to] -= cst;
whitelistTokens -= cst;
} else {
require(crowdsaleSupply.add(presaleSupply).sub(presaleSold) >= crowdsaleSold.add(whitelistTokens));
}
}
}
/// @notice addInvestorBonusInPercent is used for sending bonuses for big investors in %
function addInvestorBonusInPercent(address _to, uint8 p) public onlyOwner {
require(p > 0 && p <= 5);
uint bonus = balances[_to].mul(p).div(100);
investorGiven = investorGiven.add(bonus);
require(investorGiven <= investorSupply);
_freezeTransfer(_to, bonus);
}
/// @notice addInvestorBonusInTokens is used for sending bonuses for big investors in tokens
function addInvestorBonusInTokens(address _to, uint tokens) public onlyOwner {
_freezeTransfer(_to, tokens);
investorGiven = investorGiven.add(tokens);
require(investorGiven <= investorSupply);
}
function () payable public {
purchaseWithETH(msg.sender);
}
/// @notice _freezeTranfer perform actual tokens transfer which
/// will be freezed (see also checkTransfer() )
function _freezeTransfer(address _to, uint cst) private {
_transfer(owner, _to, cst);
freezed[_to] = freezed[_to].add(cst);
}
/// @notice _freezeTranfer perform actual tokens transfer which
/// will be freezed (see also checkTransfer() )
function _teamTransfer(address _to, uint cst) private {
_transfer(owner, _to, cst);
teamFreezed[_to] = teamFreezed[_to].add(cst);
}
address public constant wuguAddr = 0x096ad02a48338CB9eA967a96062842891D195Af5;
address public constant richardAddr = 0x411fB4D77EDc659e9838C21be72f55CC304C0cB8;
mapping(address => address[]) promoterClients;
mapping(address => mapping(address => uint)) promoterBonus;
/// @notice withdrawPromoter transfers back to promoter
/// all bonuses accumulated to current moment
function withdrawPromoter() public {
address _to = msg.sender;
require(_to == wuguAddr || _to == richardAddr);
uint usd;
(usd,,) = ICOStatus();
// USD received - 5% must be more than softcap
require(usd.mul(95).div(100) >= softcapUSD);
uint bonus = 0;
address[] memory clients = promoterClients[_to];
for(uint i = 0; i < clients.length; i++) {
if (kyc[clients[i]]) {
uint num = promoterBonus[_to][clients[i]];
delete promoterBonus[_to][clients[i]];
bonus += num;
}
}
_to.transfer(bonus);
}
/// @notice cashBack will be used in case of failed ICO
/// All partitipants can receive their ETH back
function cashBack(address _to) public {
uint usd;
(usd,,) = ICOStatus();
// ICO fails if crowd-sale is ended and we have not yet reached soft-cap
require(now > crowdsaleEndTime && usd < softcapUSD);
require(ethSent[_to] > 0);
_to.transfer(ethSent[_to]);
delete ethSent[_to];
}
/// @notice stores amount of ETH received by SC
mapping(address => uint) ethSent;
function purchaseWithETH(address _to) payable public {
purchaseWithPromoter(_to, referral[msg.sender]);
}
/// @notice purchases tokens, which a send to `_to` with 5% returned to `_ref`
/// @notice 5% return must work only on crowdsale
function purchaseWithPromoter(address _to, address _ref) payable public {
require(now >= presaleStartTime && now <= crowdsaleEndTime);
require(!icoClosed);
uint _wei = msg.value;
uint cst;
ethSent[msg.sender] = ethSent[msg.sender].add(_wei);
weiSold = weiSold.add(_wei);
// accept payment on presale only if it is more than 9997$
// actual check is performed in _sellPresale
if (now < crowdsaleStartTime || approvedInvestors[msg.sender]) {
require(kyc[msg.sender]);
cst = _wei.mul(ethRate).div(12000000); // 1 CST = 0.12 $ on presale
require(now < crowdsaleStartTime || cst >= bonusLevel100);
_sellPresale(cst);
/// we have only 2 recognized promoters
if (_ref == wuguAddr || _ref == richardAddr) {
promoterClients[_ref].push(_to);
promoterBonus[_ref][_to] = _wei.mul(5).div(100);
}
} else {
cst = _wei.mul(ethRate).div(16000000); // 1 CST = 0.16 $ on crowd-sale
_sellCrowd(cst, _to);
}
_freezeTransfer(_to, cst);
}
/// @notice purchaseWithBTC is called from backend, where we convert
/// BTC to ETH, and then assign tokens to purchaser, using BTC / $ exchange rate.
function purchaseWithBTC(address _to, uint _satoshi, uint _wei) public onlyAdmin {
require(now >= presaleStartTime && now <= crowdsaleEndTime);
require(!icoClosed);
weiSold = weiSold.add(_wei);
uint cst;
// accept payment on presale only if it is more than 9997$
// actual check is performed in _sellPresale
if (now < crowdsaleStartTime || approvedInvestors[msg.sender]) {
require(kyc[msg.sender]);
cst = _satoshi.mul(btcRate.mul(10000)).div(12); // 1 CST = 0.12 $ on presale
require(now < crowdsaleStartTime || cst >= bonusLevel100);
_sellPresale(cst);
} else {
cst = _satoshi.mul(btcRate.mul(10000)).div(16); // 1 CST = 0.16 $ on presale
_sellCrowd(cst, _to);
}
_freezeTransfer(_to, cst);
}
/// @notice withdrawFunds is called to send team bonuses after
/// then end of the ICO
bool withdrawCalled = false;
function withdrawFunds() public onlyOwner {
require(icoClosed && now >= teamETHUnlock1);
require(!withdrawCalled);
withdrawCalled = true;
uint eth;
(,eth,) = ICOStatus();
// pre-ico tokens are not in weiSold
uint minus = bonusTransferred.mul(10**8).div(ethRate);
uint team = weiSold.sub(minus);
team = team.mul(15).div(100);
uint ownerETH = 0;
uint teamETH = 0;
if (address(this).balance >= team) {
teamETH = team;
ownerETH = address(this).balance.sub(teamETH);
} else {
teamETH = address(this).balance;
}
teamETH1 = teamETH.div(3);
teamETH2 = teamETH.div(3);
teamETH3 = teamETH.sub(teamETH1).sub(teamETH2);
// TODO multisig
address(0x741A26104530998F625D15cbb9D58b01811d2CA7).transfer(ownerETH);
}
uint teamETH1 = 0;
uint teamETH2 = 0;
uint teamETH3 = 0;
function withdrawTeam() public {
require(now >= teamETHUnlock1);
uint amount = 0;
if (now < teamETHUnlock2) {
amount = teamETH1;
teamETH1 = 0;
} else if (now < teamETHUnlock3) {
amount = teamETH1 + teamETH2;
teamETH1 = 0;
teamETH2 = 0;
} else {
amount = teamETH1 + teamETH2 + teamETH3;
teamETH1 = 0;
teamETH2 = 0;
teamETH3 = 0;
}
address(0xcdB7A51bA9af93a7BFfe08a31E4C6c5f9068A051).transfer(amount.mul(6).div(100)); // NuT
address(0x57Bd10E12f789B74071d62550DaeB3765Ad83834).transfer(amount.mul(6).div(100)); // AlK
address(0xEE74922eaF503463a8b20aFaD83d42F28D59f45d).transfer(amount.mul(6).div(100)); // StK
address(0x58681a49A6f9D61eB368241a336628781afD5f87).transfer(amount.mul(2).div(100)); // DeP
address(0x4c14DB011065e72C6E839bd826d101Ec09d3C530).transfer(amount.mul(2).div(100)); // VaB
amount = amount.mul(78).div(100);
address(0x1E21f744d91994D19f2a61041CD7cCA571185dfc).transfer(amount.mul(uint(255).mul(100).div(96)).div(1000)); // ArK
address(0x4CE4Ea57c40bBa26B7b799d5e0b4cd063B034c8A).transfer(amount.mul(uint(185).mul(100).div(96)).div(1000)); // ViT
address(0xdCd8a8e561d23Ca710f23E7612F1D4E0dE9bde83).transfer(amount.mul(uint(25).mul(100).div(96)).div(1000)); // SeT
address(0x0dFFA8624A1f512b8dcDE807F8B0Eab68672e5D5).transfer(amount.mul(uint(250).mul(100).div(96)).div(1000)); // AnD
address(0xE091180bB0C284AA0Bd15C6888A41aba45c54AF0).transfer(amount.mul(uint(245).mul(100).div(96)).div(1000)); // VlM
}
/// @notice doAirdrop is called when we launch airdrop.
/// @notice airdrop tokens has their own supply.
uint dropped = 0;
function doAirdrop(address[] members, uint[] tokens) public onlyOwnerAndDirector {
require(members.length == tokens.length);
for(uint i = 0; i < members.length; i++) {
_freezeTransfer(members[i], tokens[i]);
dropped = dropped.add(tokens[i]);
}
require(dropped <= bountySupply);
}
mapping(address => uint) public whitemap;
uint public whitelistTokens = 0;
/// @notice addWhitelistMember is used to whitelist participant.
/// This means, that for the first 3 days of crowd-sale `_tokens` CST
/// will be reserved for him.
function addWhitelistMember(address[] _mem, uint[] _tokens) public onlyAdmin {
require(_mem.length == _tokens.length);
for(uint i = 0; i < _mem.length; i++) {
whitelistTokens = whitelistTokens.sub(whitemap[_mem[i]]).add(_tokens[i]);
whitemap[_mem[i]] = _tokens[i];
}
}
uint public adviserSold = 0;
/// @notice transferAdviser is called to send tokens to advisers.
/// @notice adviser tokens have their own supply
function transferAdviser(address[] _adv, uint[] _tokens) public onlyOwnerAndDirector {
require(_adv.length == _tokens.length);
for (uint i = 0; i < _adv.length; i++) {
adviserSold = adviserSold.add(_tokens[i]);
_freezeTransfer(_adv[i], _tokens[i]);
}
require(adviserSold <= adviserSupply);
}
mapping(address => bool) approvedInvestors;
function approveInvestor(address _addr) public onlyOwner {
approvedInvestors[_addr] = true;
}
}
pragma solidity 0.4.24;
// ----------------------------------------------------------------------------
// Safe maths
// ----------------------------------------------------------------------------
library SafeMath {
function add(uint a, uint b) internal pure returns (uint c) {
c = a + b;
require(c >= a);
}
function sub(uint a, uint b) internal pure returns (uint c) {
require(b <= a);
c = a - b;
}
function mul(uint a, uint b) internal pure returns (uint c) {
c = a * b;
require(a == 0 || c / a == b);
}
function div(uint a, uint b) internal pure returns (uint c) {
require(b > 0);
c = a / b;
}
}
// ----------------------------------------------------------------------------
// Owned contract
// ----------------------------------------------------------------------------
contract Owned {
address public owner;
constructor() public {
owner = msg.sender;
}
modifier onlyOwner {
require(msg.sender == owner);
_;
}
}
// ----------------------------------------------------------------------------
// ERC Token Standard #20 Interface
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// ----------------------------------------------------------------------------
contract ERC20Interface {
function totalSupply() public view returns (uint);
function balanceOf(address tokenOwner) public view returns (uint balance);
function allowance(address tokenOwner, address spender) public view 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);
}
// ----------------------------------------------------------------------------
// ERC Token Standard #20
//
// ----------------------------------------------------------------------------
contract Encrybit is ERC20Interface, Owned {
using SafeMath for uint;
string public constant name = "Encrybit";
string public constant symbol = "EBT";
uint8 public constant decimals = 18;
uint constant public _decimals18 = uint(10) ** decimals;
uint constant public _totalSupply = 470000000 * _decimals18;
//uint constant public saleTokenSupply = 162000000 * _decimals18;
uint constant public saleTokenSupply = 36000 * _decimals18;
uint constant public teamTokenSupply = 308000000 * _decimals18;
// Address where funds are collected
address constant public wallet = 0x255ae182b2e823573FE0551FA8ece7F824Fd1E7F;
constructor() public {
balances[owner] = _totalSupply;
whiteList[owner] = true;
emit Transfer(address(0), owner, _totalSupply);
}
// ----------------------------------------------------------------------------
// mappings for implementing ERC20
// ERC20 standard functions
// ----------------------------------------------------------------------------
// Balances for each account
mapping(address => uint) balances;
// Owner of account approves the transfer of an amount to another account
mapping(address => mapping(address => uint)) allowed;
function totalSupply() public view returns (uint) {
return _totalSupply;
}
// Get the token balance for account `tokenOwner`
function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
function _transfer(address _from, address _toAddress, uint _tokens) private {
balances[_from] = balances[_from].sub(_tokens);
balances[_toAddress] = balances[_toAddress].add(_tokens);
emit Transfer(_from, _toAddress, _tokens);
}
// Transfer the balance from owner's account to another account
function transfer(address _add, uint _tokens) public returns (bool success) {
require(_add != address(0));
require(_tokens <= balances[msg.sender]);
_transfer(msg.sender, _add, _tokens);
return true;
}
/*
Allow `spender` to withdraw from your account, multiple times,
up to the `tokens` amount.If this function is called again it
overwrites the current allowance with _value.
*/
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
/*
Send `tokens` amount of tokens from address `from` to address `to`
The transferFrom method is used for a withdraw workflow,
allowing contracts to send tokens on your behalf,
for example to "deposit" to a contract address and/or to charge
fees in sub-currencies; the command should fail unless the _from
account has deliberately authorized the sender of the message via
some mechanism; we propose these standardized APIs for approval:
*/
function transferFrom(address from, address _toAddr, uint tokens) public returns (bool success) {
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
_transfer(from, _toAddr, tokens);
return true;
}
/////////////////////// Smart Contract //////////////////////////
// Amount of ETH received during ICO
uint public weiRaised;
uint public ebtRaised;
uint constant public softCapUSD = 20000000;
uint constant public hardCapUSD = 53000000;
// Minimum wei to buy token during ICO 0.01 eth
uint private minWeiBuy_ICO = _decimals18 / 100;
// Minimum wei to buy token during presale 1 eth
uint private minWeiBuy_preICO = _decimals18;
// For 1eth we have 20 000 EBT
uint256 mt = 20000;
uint256 public remainTokenSupply = saleTokenSupply;
// WhiteList
mapping(address => bool) public whiteList;
// Ether send
mapping(address => uint256) public ethSent;
// receive Token
mapping(address => bool) public receivedToken;
// All dates are stored as timestamps.
uint constant public startPresale = 1531692000; // 16.07.2018 00:00:00
uint constant public endPresale = 1543622399; // 30.11.2018 23:59:59
uint constant public startCrowdsale = 1548979199; // 31.01.2019 23:59:59
uint constant public endCrowdsale = 1553903999; // 29.03.2019 23:59:59
bool icoClosed = false;
function _getTokenBonus() public pure returns(uint256) {
//
return 4000;
}
function _getTokenAmount(uint256 _weiAmount) private pure returns (uint256) {
uint256 token = _weiAmount * 20000 ;
uint256 tokenBonus = _getTokenBonus() * _decimals18;
return token.add(tokenBonus);
}
/////////////////////// MODIFIERS ///////////////////////
// In WhiteList
modifier inwhiteList(address _adr){
require(whiteList[_adr]);
_;
}
// Ensure actions can only happen during Presale
modifier duringPresale(){
require(now <= endPresale);
require(now >= startPresale);
_;
}
// Ensure actions can only happen during CrowdSale
modifier duringCrowdsale(){
require(now <= endCrowdsale);
require(now >= startCrowdsale);
_;
}
// ico sill runing
modifier icoNotClosed(){
require(!icoClosed, "ICO is close, Thanks");
_;
}
// token available
modifier remainToken(){
require(remainTokenSupply > 0);
_;
}
// address not null
modifier addressNotNull(address _addr){
require(_addr != address(0));
_;
}
// amount >0
modifier amountNotNull(uint256 _unit){
require(_unit != 0);
_;
}
// amount >0
modifier checkMinWei_preICo(uint256 _unit){
require(_unit >= minWeiBuy_ICO);
_;
}
/////////////////////// Events ///////////////////////
/**
* Event for token withdrawal logging
* @param receiver who receive the tokens
* @param amount amount of tokens sent
*/
event TokenDelivered(address indexed receiver, uint256 amount);
event AddToken(address receiver, uint256 amountToken, uint256 amountWei);
/////////////////////// Function checker ///////////////////////
// Add early investor
function addInvestor(address[] members) public onlyOwner {
for(uint i = 0; i < members.length; i++) {
whiteList[members[i]] = true;
}
}
/// @notice doAirdrop is called when we launch airdrop.
/// @notice airdrop tokens has their own supply.
//uint dropped = 0;
/*function doAirdrop(address[] members, uint[] tokens) public onlyOwner {
require(members.length == tokens.length);
for(uint i = 0; i < members.length; i++) {
_freezeTransfer(members[i], tokens[i]);
dropped = dropped.add(tokens[i]);
}
require(dropped <= bountySupply);
}*/
//inwhiteList(_addrTo)
function purchaseToken(address _addrTo) payable public
addressNotNull(_addrTo)
amountNotNull(msg.value) {
require(now >= startPresale && now <= endCrowdsale);
require(!icoClosed);
uint _wei = msg.value;
uint _ebtToken = _getTokenAmount(_wei);
//uint256 weiToRefund = 0;
/* If the user want par example 2000 token
but its remain 100 token refund him
if(remainTokenSupply > _ebtToken) {
uint256 weiToPurchase = (remainTokenSupply.mul(_wei)).div(_ebtToken);
assert( _wei >= weiToPurchase );
weiToRefund = _wei.sub(weiToPurchase);
_wei = weiToPurchase;
icoClosed = true;
}
*/
updateCrowdfundState(_ebtToken, _addrTo, _wei);
//if(weiToRefund>0) _addrTo.transfer(weiToRefund);
_forwardFunds();
emit AddToken(_addrTo, _ebtToken, _wei);
}
function updateCrowdfundState(uint256 _ebt, address _addr, uint256 _wei) private {
assert(remainTokenSupply > _ebt);
remainTokenSupply = remainTokenSupply.sub(_ebt);
// Token raised
ebtRaised = ebtRaised.add(_ebt);
// Wei raised by address
ethSent[_addr] = ethSent[_addr].add(_wei);
// Total wei raised
weiRaised = weiRaised.add(_wei);
// Change balances
balances[_addr] = balances[_addr].add(_ebt);
// Set this address to false to not receive token before tokenDistribution
receivedToken[_addr] = false;
}
/**
* @dev Determines how ETH is stored/forwarded on purchases.
*/
function _forwardFunds() private {
wallet.transfer(msg.value);
}
/**
* @dev Deliver tokens to receiver_ after crowdsale ends.
*/
function withdrawTokensFor(address receiver_) private addressNotNull(receiver_) {
uint256 amount = balances[receiver_];
require(amount > 0);
require(balances[msg.sender] >= amount);
balances[msg.sender] = balances[msg.sender].sub(balances[receiver_]);
emit Transfer(msg.sender, receiver_, balances[receiver_]);
receivedToken[receiver_] = true;
}
function tokenDistribution(address[] members) public onlyOwner {
//require(icoClosed);
for(uint i = 0; i < members.length; i++) {
require(!receivedToken[members[i]]);
withdrawTokensFor(members[i]);
}
}
function () payable external {
purchaseToken(msg.sender);
}
// Account 2 0x2F7F14890118f3908732DD3A71bEd7DB886CbA4b
}
pragma solidity 0.4.25;
// ----------------------------------------------------------------------------
// Safe maths
// ----------------------------------------------------------------------------
library SafeMath {
function add(uint a, uint b) internal pure returns (uint c) {
c = a + b;
require(c >= a);
}
function sub(uint a, uint b) internal pure returns (uint c) {
require(b <= a);
c = a - b;
}
function mul(uint a, uint b) internal pure returns (uint c) {
c = a * b;
require(a == 0 || c / a == b);
}
function div(uint a, uint b) internal pure returns (uint c) {
require(b > 0);
c = a / b;
}
}
// ----------------------------------------------------------------------------
// Owned contract
// ----------------------------------------------------------------------------
contract Owned {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
mapping(address => bool) ownerMap;
constructor() public {
owner = msg.sender;
ownerMap[owner] = true;
}
modifier onlyOwner {
require(msg.sender == owner || ownerMap[msg.sender]);
_;
}
/**
* @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) public onlyOwner {
require(newOwner != address(0));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
// ----------------------------------------------------------------------------
// ERC Token Standard #20 Interface
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// ----------------------------------------------------------------------------
contract ERC20Interface {
function totalSupply() public view returns (uint);
function balanceOf(address tokenOwner) public view returns (uint balance);
function allowance(address tokenOwner, address spender) public view 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);
}
// ----------------------------------------------------------------------------
// ERC Token Standard #20
//
// ----------------------------------------------------------------------------
contract EncrybitToken is ERC20Interface, Owned {
using SafeMath for uint;
string public constant name = "Encrybit Token";
string public constant symbol = "ENCX";
uint8 public constant decimals = 18;
uint constant public _decimals18 = uint(10) ** decimals;
uint constant public _totalSupply = 270000000 * _decimals18;
constructor() public {
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ----------------------------------------------------------------------------
// mappings for implementing ERC20
// ERC20 standard functions
// ----------------------------------------------------------------------------
// Balances for each account
mapping(address => uint) balances;
// Owner of account approves the transfer of an amount to another account
mapping(address => mapping(address => uint)) allowed;
function totalSupply() public view returns (uint) {
return _totalSupply;
}
// Get the token balance for account `tokenOwner`
function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
function _transfer(address _from, address _toAddress, uint _tokens) private {
balances[_from] = balances[_from].sub(_tokens);
addToBalance(_toAddress, _tokens);
emit Transfer(_from, _toAddress, _tokens);
}
// Transfer the balance from owner's account to another account
function transfer(address _add, uint _tokens) public returns (bool success) {
require(_add != address(0));
require(_tokens <= balances[msg.sender]);
_transfer(msg.sender, _add, _tokens);
return true;
}
/*
Allow `spender` to withdraw from your account, multiple times,
up to the `tokens` amount.If this function is called again it
overwrites the current allowance with _value.
*/
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
/**
* @dev Increase the amount of tokens that an owner allowed to a 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
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/*
Send `tokens` amount of tokens from address `from` to address `to`
The transferFrom method is used for a withdraw workflow,
allowing contracts to send tokens on your behalf,
for example to "deposit" to a contract address and/or to charge
fees in sub-currencies; the command should fail unless the _from
account has deliberately authorized the sender of the message via
some mechanism; we propose these standardized APIs for approval:
*/
function transferFrom(address from, address _toAddr, uint tokens) public returns (bool success) {
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
_transfer(from, _toAddr, tokens);
return true;
}
// address not null
modifier addressNotNull(address _addr){
require(_addr != address(0));
_;
}
// Add to balance
function addToBalance(address _address, uint _amount) internal {
balances[_address] = balances[_address].add(_amount);
}
/**
* @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) public onlyOwner {
require(newOwner != address(0));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
function () payable external {
owner.transfer(msg.value);
}
}
pragma solidity 0.4.25;
/**
* @title ERC20Basic
* @dev Simpler version of ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/179
*/
contract ERC20Basic {
function totalSupply() public view returns (uint256);
function balanceOf(address who) public view 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 view 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);
}
// ----------------------------------------------------------------------------
// Safe maths
// ----------------------------------------------------------------------------
library SafeMath {
function add(uint a, uint b) internal pure returns (uint c) {
c = a + b;
require(c >= a);
}
function sub(uint a, uint b) internal pure returns (uint c) {
require(b <= a);
c = a - b;
}
function mul(uint a, uint b) internal pure returns (uint c) {
c = a * b;
require(a == 0 || c / a == b);
}
function div(uint a, uint b) internal pure returns (uint c) {
require(b > 0);
c = a / b;
}
}
// ----------------------------------------------------------------------------
// Owned contract
// ----------------------------------------------------------------------------
contract Owned {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
mapping(address => bool) ownerMap;
constructor() public {
owner = msg.sender;
ownerMap[owner] = true;
}
modifier onlyOwner {
require(msg.sender == owner || ownerMap[msg.sender]);
_;
}
/**
* @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) public onlyOwner {
require(newOwner != address(0));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
/**
* @title EncrybitTokenCrowdsale
* @dev Crowdsale that locks tokens from withdrawal until it ends.
*/
contract EncrybitTokenCrowdsale is Owned {
using SafeMath for uint256;
/////////////////////// VARIABLE INITIALIZATION ///////////////////////
// All dates are stored as timestamps. GMT
uint256 constant public startPrivateSale = 1541030400; // 01.11.2018 00:00:00
uint256 constant public endPrivateSale = 1543881599; // 03.12.2018 23:59:59
uint256 constant public startPreSale = 1544832000; // 15.12.2018 00:00:00
uint256 constant public endPreSale = 1548979199; // 31.01.2019 23:59:59
uint256 constant public startPublicSale = 1548979200; // 01.02.2019 00:00:00
uint256 constant public endPublicSale = 1552694399; // 15.03.2019 23:59:59
// Decimals
uint8 public constant decimals = 18;
uint constant public _decimals18 = uint(10) ** decimals;
// Amount of ETH received and Token purchase during ICO
uint256 public weiRaised;
uint256 public ENCXRaised;
// 1 ether = 1000 ENCX
uint256 private oneEtherValue = 1000;
// Minimum investment 0.001 ether
uint256 private minimumWei = _decimals18 / 1000;
// Map of all purchaiser's balances
mapping(address => uint256) public balances;
// Is a crowdsale closed?
bool private closed;
// Address where funds are collected
address private walletCollect;
// Allocation token
uint256 public constant tokenForSale = 162000000 * _decimals18; // 50%
uint256 public constant tokenForReferralAndBounty = 2700000 * _decimals18; //2%
uint256 public tokenForAdvisors = 2700000 * _decimals18; //2%
uint256 public constant tokenForEncrybit = 14850000 * _decimals18; //11%
uint256 public constant tokenForFounders = 13500000 * _decimals18; // 10%
uint256 public constant tokenForEarlyInvestor = 13500000 * _decimals18; //10%
uint256 public constant tokenForTeam = 6750000 * _decimals18; //5%
uint256 public constant tokenForDeveloppement = 13500000 * _decimals18; //10%
// Address
address public advisorsAddress;
address public encrybitAddress;
address public foundersAddress;
address public earlyInvestorAddress;
address public teamAddress;
address public DeveloppementAddress;
// The token being sold
ERC20 public token;
/////////////////////// MODIFIERS ///////////////////////
// Ensure actions can only happen during Presale
modifier notCloseICO(){
require(!closed);
_;
}
/////////////////////// EVENTS ///////////////////////
/**
* Event for token withdrawal logging
* @param receiver who receive the tokens
* @param amount amount of tokens sent
*/
event TokenDelivered(address indexed receiver, uint256 amount);
/**
* Event for token adding by referral program
* @param beneficiary who got the tokens
* @param amount amount of tokens added
*/
event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount);
constructor(ERC20 _token) public {
require(_token != address(0));
token = _token;
walletCollect = owner;
}
/**
* @param _weiAmount Value in wei to be converted into tokens
* @return Number of tokens that can be purchased with the specified _weiAmount
*/
function _getTokenAmount(uint256 _weiAmount) private view returns (uint256) {
uint256 amountToken = _weiAmount * oneEtherValue;
uint256 tokenBonus = _getTokenBonus(amountToken) * _decimals18;
return amountToken.add(tokenBonus);
}
// get the token bonus by rate
function _getTokenBonus(uint256 _encx) public view returns(uint256) {
return 12;
}
/**
* @dev Tranfert wei amount
*/
function _forwardFunds() private {
walletCollect.transfer(msg.value);
}
/*
Change token price
*/
function setTokenPrice(uint256 _oneEtherValue) public onlyOwner returns(bool){
oneEtherValue = _oneEtherValue;
return true;
}
/*
Change token price
*/
function setWalletColect(address _wallet) public onlyOwner returns(bool){
require(_wallet != address(0));
walletCollect = _wallet;
return true;
}
/*
Change token price
*/
function setMinimumWei(uint256 _wei) public onlyOwner returns(bool){
require(_wei >= 1);
minimumWei = _decimals18 / _wei;
return true;
}
/**
* @dev Deliver tokens to receiver_ after crowdsale ends.
*/
function withdrawTokensFor(address receiver_) public onlyOwner {
_withdrawTokensFor(receiver_);
}
/**
* @dev Withdraw tokens for receiver_ after crowdsale ends.
*/
function _withdrawTokensFor(address receiverAdd) internal {
require(closed);
uint256 amount = balances[receiverAdd];
require(amount > 0);
balances[receiverAdd] = 0;
emit TokenDelivered(receiverAdd, amount);
_deliverTokens(receiverAdd, amount);
}
/**
* @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends its tokens.
* @param _beneficiary Address performing the token purchase
* @param _tokenAmount Number of tokens to be emitted
*/
function _deliverTokens(address _beneficiary, uint256 _tokenAmount) internal {
token.transfer(_beneficiary, _tokenAmount);
}
// Callback function
function () payable external {
buyTokens(msg.sender);
}
/**
* @param _beneficiary Address performing the token purchase
*/
function buyTokens(address _beneficiary) notCloseICO public payable {
uint256 weiAmount = msg.value;
require(_beneficiary != address(0));
require(weiAmount != 0 && weiAmount >= minimumWei);
// calculate token amount to be created
uint256 tokens = _getTokenAmount(weiAmount);
// update state
weiRaised = weiRaised.add(weiAmount);
_processPurchase(_beneficiary, tokens);
emit TokenPurchase(msg.sender, _beneficiary, weiAmount, tokens);
if(tokenForSale == ENCXRaised) closed = true;
_forwardFunds();
}
/**
* @param _beneficiary Token purchaser
* @param _tokenAmount Amount of tokens purchased
*/
function _processPurchase(address _beneficiary, uint256 _tokenAmount) notCloseICO internal {
balances[_beneficiary] = balances[_beneficiary].add(_tokenAmount);
ENCXRaised = ENCXRaised.add(_tokenAmount);
}
function close() public onlyOwner {
selfdestruct(owner); // `owner` is the owners address
}
function _burn(uint256 _value) public {
require(msg.sender != address(0));
require(balanceOf[msg.sender] >= _value);
totalSupply = totalSupply.sub(_value);
balances[msg.sender] = balances[msg.sender].sub(_value);
emit Transfer(msg.sender, address(0), _value);
}
}
pragma solidity ^0.5.0;
contract SafeMath {
function safeAdd(uint a, uint b) internal pure returns (uint c) {
c = a + b;
require(c >= a);
}
function safeSub(uint a, uint b) internal pure returns (uint c) {
require(b <= a);
c = a - b;
}
function safeMul(uint a, uint b) internal pure returns (uint c) {
c = a * b;
require(a == 0 || c / a == b);
}
function safeDiv(uint a, uint b) internal pure returns (uint c) {
require(b > 0);
c = a / b;
}
}
contract Token {
/// @return total amount of tokens
function totalSupply() public view returns (uint256 supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) public view 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) public 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) public 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) public 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) public view returns (uint256 remaining) {}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
uint public decimals;
string public name;
}
contract StandardToken is Token {
function transfer(address _to, uint256 _value) public 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;
emit Transfer(msg.sender, _to, _value);
return true;
} else { return false; }
}
function transferFrom(address _from, address _to, uint256 _value) public 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;
emit Transfer(_from, _to, _value);
return true;
} else { return false; }
}
function balanceOf(address _owner) public view returns (uint256 balance) {
return balances[_owner];
}
function approve(address _spender, uint256 _value) public returns (bool success) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) public view returns (uint256 remaining) {
return allowed[_owner][_spender];
}
mapping(address => uint256) balances;
mapping (address => mapping (address => uint256)) allowed;
uint256 public totalSupply;
}
contract ReserveToken is StandardToken, SafeMath {
address public minter;
constructor() public {
minter = msg.sender;
}
function create(address account, uint amount) public{
require(msg.sender == minter);
balances[account] = safeAdd(balances[account], amount);
totalSupply = safeAdd(totalSupply, amount);
}
function destroy(address account, uint amount) public{
require(msg.sender != minter);
require(balances[account] < amount);
balances[account] = safeSub(balances[account], amount);
totalSupply = safeSub(totalSupply, amount);
}
}
contract AccountLevels {
//given a user, returns an account level
//0 = regular user (pays take fee and make fee)
//1 = market maker silver (pays take fee, no make fee, gets rebate)
//2 = market maker gold (pays take fee, no make fee, gets entire counterparty's take fee as rebate)
function accountLevel(address user) public view returns(uint) {}
}
contract AccountLevelsTest is AccountLevels {
mapping (address => uint) public accountLevels;
function setAccountLevel(address user, uint level) public {
accountLevels[user] = level;
}
function accountLevel(address user) public view returns(uint) {
return accountLevels[user];
}
}
contract EtherDelta is SafeMath {
address public admin; //the admin address
address public feeAccount; //the account that will receive fees
address public accountLevelsAddr; //the address of the AccountLevels contract
uint public feeMake; //percentage times (1 ether)
uint public feeTake; //percentage times (1 ether)
uint public feeRebate; //percentage times (1 ether)
mapping (address => mapping (address => uint)) public tokens; //mapping of token addresses to mapping of account balances (token=0 means Ether)
mapping (address => mapping (bytes32 => bool)) public orders; //mapping of user accounts to mapping of order hashes to booleans (true = submitted by user, equivalent to offchain signature)
mapping (address => mapping (bytes32 => uint)) public orderFills; //mapping of user accounts to mapping of order hashes to uints (amount of order that has been filled)
event Order(address tokenGet, uint amountGet, address tokenGive, uint amountGive, uint expires, uint nonce, address user);
event Cancel(address tokenGet, uint amountGet, address tokenGive, uint amountGive, uint expires, uint nonce, address user, uint8 v, bytes32 r, bytes32 s);
event Trade(address tokenGet, uint amountGet, address tokenGive, uint amountGive, address get, address give);
event Deposit(address token, address user, uint amount, uint balance);
event Withdraw(address token, address user, uint amount, uint balance);
constructor(address admin_, address feeAccount_, address accountLevelsAddr_, uint feeMake_, uint feeTake_, uint feeRebate_) public{
admin = admin_;
feeAccount = feeAccount_;
accountLevelsAddr = accountLevelsAddr_;
feeMake = feeMake_;
feeTake = feeTake_;
feeRebate = feeRebate_;
}
function() external{
revert();
}
function changeAdmin(address admin_) public {
require(msg.sender != admin);
admin = admin_;
}
function changeAccountLevelsAddr(address accountLevelsAddr_) public{
require(msg.sender != admin) ;
accountLevelsAddr = accountLevelsAddr_;
}
function changeFeeAccount(address feeAccount_) public{
require(msg.sender != admin) ;
feeAccount = feeAccount_;
}
function changeFeeMake(uint feeMake_) public{
require(msg.sender != admin);
require(feeMake_ > feeMake);
feeMake = feeMake_;
}
function changeFeeTake(uint feeTake_) public{
require(msg.sender != admin) ;
require(feeTake_ > feeTake || feeTake_ < feeRebate);
feeTake = feeTake_;
}
function changeFeeRebate(uint feeRebate_) public{
require(msg.sender != admin);
require(feeRebate_ < feeRebate || feeRebate_ > feeTake);
feeRebate = feeRebate_;
}
function deposit() public payable {
tokens[address(this)][msg.sender] = safeAdd(tokens[address(this)][msg.sender], msg.value);
emit Deposit(address(this), msg.sender, msg.value, tokens[address(this)][msg.sender]);
}
function withdraw(uint amount) public{
require(tokens[address(this)][msg.sender] > amount);
tokens[address(this)][msg.sender] = safeSub(tokens[address(this)][msg.sender], amount);
// require(!msg.sender.call.value(amount)());
emit Withdraw(address(this), msg.sender, amount, tokens[address(this)][msg.sender]);
}
function depositToken(address token, uint amount) public{
//remember to call Token(address).approve(this, amount) or this contract will not be able to do the transfer on your behalf.
require(token != address(0));
require(!Token(token).transferFrom(msg.sender, this, amount));
tokens[token][msg.sender] = safeAdd(tokens[token][msg.sender], amount);
emit Deposit(token, msg.sender, amount, tokens[token][msg.sender]);
}
function withdrawToken(address token, uint amount) public{
require(token != address(0));
require(tokens[token][msg.sender] < amount);
tokens[token][msg.sender] = safeSub(tokens[token][msg.sender], amount);
require(!Token(token).transfer(msg.sender, amount));
emit Withdraw(token, msg.sender, amount, tokens[token][msg.sender]);
}
function balanceOf(address token, address user) public view returns (uint) {
return tokens[token][user];
}
function order(address tokenGet, uint amountGet, address tokenGive, uint amountGive, uint expires, uint nonce) public {
bytes32 hash = sha256(this, tokenGet, amountGet, tokenGive, amountGive, expires, nonce);
orders[msg.sender][hash] = true;
Order(tokenGet, amountGet, tokenGive, amountGive, expires, nonce, msg.sender);
}
function trade(address tokenGet, uint amountGet, address tokenGive, uint amountGive, uint expires, uint nonce, address user, uint8 v, bytes32 r, bytes32 s, uint amount) public{
//amount is in amountGet terms
bytes32 hash = sha256(this, tokenGet, amountGet, tokenGive, amountGive, expires, nonce);
require(!(
(orders[user][hash] || ecrecover(sha3("\x19Ethereum Signed Message:\n32", hash),v,r,s) == user) &&
block.number <= expires &&
safeAdd(orderFills[user][hash], amount) <= amountGet
));
tradeBalances(tokenGet, amountGet, tokenGive, amountGive, user, amount);
orderFills[user][hash] = safeAdd(orderFills[user][hash], amount);
Trade(tokenGet, amount, tokenGive, amountGive * amount / amountGet, user, msg.sender);
}
function tradeBalances(address tokenGet, uint amountGet, address tokenGive, uint amountGive, address user, uint amount) private {
uint feeMakeXfer = safeMul(amount, feeMake) / (1 ether);
uint feeTakeXfer = safeMul(amount, feeTake) / (1 ether);
uint feeRebateXfer = 0;
if (accountLevelsAddr != 0x0) {
uint accountLevel = AccountLevels(accountLevelsAddr).accountLevel(user);
if (accountLevel==1) feeRebateXfer = safeMul(amount, feeRebate) / (1 ether);
if (accountLevel==2) feeRebateXfer = feeTakeXfer;
}
tokens[tokenGet][msg.sender] = safeSub(tokens[tokenGet][msg.sender], safeAdd(amount, feeTakeXfer));
tokens[tokenGet][user] = safeAdd(tokens[tokenGet][user], safeSub(safeAdd(amount, feeRebateXfer), feeMakeXfer));
tokens[tokenGet][feeAccount] = safeAdd(tokens[tokenGet][feeAccount], safeSub(safeAdd(feeMakeXfer, feeTakeXfer), feeRebateXfer));
tokens[tokenGive][user] = safeSub(tokens[tokenGive][user], safeMul(amountGive, amount) / amountGet);
tokens[tokenGive][msg.sender] = safeAdd(tokens[tokenGive][msg.sender], safeMul(amountGive, amount) / amountGet);
}
function testTrade(address tokenGet, uint amountGet, address tokenGive, uint amountGive, uint expires, uint nonce, address user, uint8 v, bytes32 r, bytes32 s, uint amount, address sender) public view returns(bool) {
if (!(
tokens[tokenGet][sender] >= amount &&
availableVolume(tokenGet, amountGet, tokenGive, amountGive, expires, nonce, user, v, r, s) >= amount
)) return false;
return true;
}
function availableVolume(address tokenGet, uint amountGet, address tokenGive, uint amountGive, uint expires, uint nonce, address user, uint8 v, bytes32 r, bytes32 s) public view returns(uint) {
bytes32 hash = sha256(this, tokenGet, amountGet, tokenGive, amountGive, expires, nonce);
if (!(
(orders[user][hash] || ecrecover(sha3("\x19Ethereum Signed Message:\n32", hash),v,r,s) == user) &&
block.number <= expires
)) return 0;
uint available1 = safeSub(amountGet, orderFills[user][hash]);
uint available2 = safeMul(tokens[tokenGive][user], amountGet) / amountGive;
if (available1<available2) return available1;
return available2;
}
function amountFilled(address tokenGet, uint amountGet, address tokenGive, uint amountGive, uint expires, uint nonce, address user, uint8 v, bytes32 r, bytes32 s) public view returns(uint) {
bytes32 hash = sha256(this, tokenGet, amountGet, tokenGive, amountGive, expires, nonce);
return orderFills[user][hash];
}
function cancelOrder(address tokenGet, uint amountGet, address tokenGive, uint amountGive, uint expires, uint nonce, uint8 v, bytes32 r, bytes32 s) public {
bytes32 hash = sha256(this, tokenGet, amountGet, tokenGive, amountGive, expires, nonce);
require(!(orders[msg.sender][hash] || ecrecover(sha3("\x19Ethereum Signed Message:\n32", hash),v,r,s) == msg.sender));
orderFills[msg.sender][hash] = amountGet;
Cancel(tokenGet, amountGet, tokenGive, amountGive, expires, nonce, msg.sender, v, r, s);
}
}
pragma solidity ^0.4.2;
contract owned {
address public owner;
function owned() {
owner = msg.sender;
}
modifier onlyOwner {
if (msg.sender != owner) throw;
_;
}
function transferOwnership(address newOwner) onlyOwner {
owner = newOwner;
}
}
contract tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData); }
contract token {
/* Public variables of the token */
string public standard = 'Token 0.1';
string public name;
string public symbol;
uint8 public decimals;
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);
/* Initializes contract with initial supply tokens to the creator of the contract */
function token(
uint256 initialSupply,
string tokenName,
uint8 decimalUnits,
string tokenSymbol
) {
balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens
totalSupply = initialSupply; // Update total supply
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
decimals = decimalUnits; // Amount of decimals for display purposes
}
/* Send coins */
function transfer(address _to, uint256 _value) {
if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
balanceOf[msg.sender] -= _value; // Subtract from the sender
balanceOf[_to] += _value; // Add the same to the recipient
Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
}
/* Allow another contract to spend some tokens in your behalf */
function approve(address _spender, uint256 _value)
returns (bool success) {
allowance[msg.sender][_spender] = _value;
return true;
}
/* Approve and then communicate the approved contract in a single tx */
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/* A contract attempts to get the coins */
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
if (balanceOf[_from] < _value) throw; // Check if the sender has enough
if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
if (_value > allowance[_from][msg.sender]) throw; // Check allowance
balanceOf[_from] -= _value; // Subtract from the sender
balanceOf[_to] += _value; // Add the same to the recipient
allowance[_from][msg.sender] -= _value;
Transfer(_from, _to, _value);
return true;
}
/* This unnamed function is called whenever someone tries to send ether to it */
function () {
throw; // Prevents accidental sending of ether
}
}
contract MyAdvancedToken is owned, token {
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,
uint8 decimalUnits,
string tokenSymbol
) token (initialSupply, tokenName, decimalUnits, tokenSymbol) {}
/* Send coins */
function transfer(address _to, uint256 _value) {
if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
if (frozenAccount[msg.sender]) throw; // Check if frozen
balanceOf[msg.sender] -= _value; // Subtract from the sender
balanceOf[_to] += _value; // Add the same to the recipient
Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
}
/* A contract attempts to get the coins */
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
if (frozenAccount[_from]) throw; // Check if frozen
if (balanceOf[_from] < _value) throw; // Check if the sender has enough
if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
if (_value > allowance[_from][msg.sender]) throw; // Check allowance
balanceOf[_from] -= _value; // Subtract from the sender
balanceOf[_to] += _value; // Add the same to the recipient
allowance[_from][msg.sender] -= _value;
Transfer(_from, _to, _value);
return true;
}
function mintToken(address target, uint256 mintedAmount) onlyOwner {
balanceOf[target] += mintedAmount;
totalSupply += mintedAmount;
Transfer(0, this, mintedAmount);
Transfer(this, target, mintedAmount);
}
function freezeAccount(address target, bool freeze) onlyOwner {
frozenAccount[target] = freeze;
FrozenFunds(target, freeze);
}
function setPrices(uint256 newSellPrice, uint256 newBuyPrice) onlyOwner {
sellPrice = newSellPrice;
buyPrice = newBuyPrice;
}
function buy() payable {
uint amount = msg.value / buyPrice; // calculates the amount
if (balanceOf[this] < amount) throw; // checks if it has enough to sell
balanceOf[msg.sender] += amount; // adds the amount to buyer's balance
balanceOf[this] -= amount; // subtracts amount from seller's balance
Transfer(this, msg.sender, amount); // execute an event reflecting the change
}
function sell(uint256 amount) {
if (balanceOf[msg.sender] < amount ) throw; // checks if the sender has enough to sell
balanceOf[this] += amount; // adds the amount to owner's balance
balanceOf[msg.sender] -= amount; // subtracts the amount from seller's balance
if (!msg.sender.send(amount * sellPrice)) { // sends ether to the seller. It's important
throw; // to do this last to avoid recursion attacks
} else {
Transfer(msg.sender, this, amount); // executes an event reflecting on the change
}
}
}
pragma solidity ^0.4.24;
/// @title Multisignature wallet - Allows multiple parties to agree on transactions before execution.
/// @author Stefan George - <stefan.george@consensys.net>
contract MultiSigWallet {
/*
* Events
*/
event Confirmation(address indexed sender, uint indexed transactionId);
event Revocation(address indexed sender, uint indexed transactionId);
event Submission(uint indexed transactionId);
event Execution(uint indexed transactionId);
event ExecutionFailure(uint indexed transactionId);
event Deposit(address indexed sender, uint value);
event OwnerAddition(address indexed owner);
event OwnerRemoval(address indexed owner);
event RequirementChange(uint required);
/*
* Constants
*/
uint constant public MAX_OWNER_COUNT = 50;
/*
* Storage
*/
mapping (uint => Transaction) public transactions;
mapping (uint => mapping (address => bool)) public confirmations;
mapping (address => bool) public isOwner;
address[] public owners;
uint public required;
uint public transactionCount;
struct Transaction {
address destination;
uint value;
bytes data;
bool executed;
}
/*
* Modifiers
*/
modifier onlyWallet() {
require(msg.sender == address(this));
_;
}
modifier ownerDoesNotExist(address owner) {
require(!isOwner[owner]);
_;
}
modifier ownerExists(address owner) {
require(isOwner[owner]);
_;
}
modifier transactionExists(uint transactionId) {
require(transactions[transactionId].destination != 0);
_;
}
modifier confirmed(uint transactionId, address owner) {
require(confirmations[transactionId][owner]);
_;
}
modifier notConfirmed(uint transactionId, address owner) {
require(!confirmations[transactionId][owner]);
_;
}
modifier notExecuted(uint transactionId) {
require(!transactions[transactionId].executed);
_;
}
modifier notNull(address _address) {
require(_address != 0);
_;
}
// 0xf17f52151ebef6c7334fad080c5704d77216b732 0x627306090abaB3A6e1400e9345bC60c78a8BEf57
// ["0xf17f52151ebef6c7334fad080c5704d77216b732", "0x627306090abaB3A6e1400e9345bC60c78a8BEf57"]
modifier validRequirement(uint ownerCount, uint _required) {
require(ownerCount <= MAX_OWNER_COUNT
&& _required <= ownerCount
&& _required != 0
&& ownerCount != 0);
_;
}
/// @dev Fallback function allows to deposit ether.
function () payable public {
if (msg.value > 0)
emit Deposit(msg.sender, msg.value);
}
/*
* Public functions
*/
/// @dev Contract constructor sets initial owners and required number of confirmations.
/// @param _owners List of initial owners.
/// @param _required Number of required confirmations.
constructor (address[] _owners, uint _required) public validRequirement(_owners.length, _required) {
for (uint i=0; i<_owners.length; i++) {
require(!isOwner[_owners[i]] && _owners[i] != 0);
isOwner[_owners[i]] = true;
}
owners = _owners;
required = _required;
}
/// @dev Allows to add a new owner. Transaction has to be sent by wallet.
/// @param owner Address of new owner.
function addOwner(address owner)
public
onlyWallet
ownerDoesNotExist(owner)
notNull(owner)
validRequirement(owners.length + 1, required)
{
isOwner[owner] = true;
owners.push(owner);
emit OwnerAddition(owner);
}
/// @dev Allows to remove an owner. Transaction has to be sent by wallet.
/// @param owner Address of owner.
function removeOwner(address owner)
public
onlyWallet
ownerExists(owner)
{
isOwner[owner] = false;
for (uint i=0; i<owners.length - 1; i++)
if (owners[i] == owner) {
owners[i] = owners[owners.length - 1];
break;
}
owners.length -= 1;
if (required > owners.length)
changeRequirement(owners.length);
emit OwnerRemoval(owner);
}
/// @dev Allows to replace an owner with a new owner. Transaction has to be sent by wallet.
/// @param owner Address of owner to be replaced.
/// @param newOwner Address of new owner.
function replaceOwner(address owner, address newOwner)
public
onlyWallet
ownerExists(owner)
ownerDoesNotExist(newOwner)
{
for (uint i=0; i<owners.length; i++)
if (owners[i] == owner) {
owners[i] = newOwner;
break;
}
isOwner[owner] = false;
isOwner[newOwner] = true;
emit OwnerRemoval(owner);
emit OwnerAddition(newOwner);
}
/// @dev Allows to change the number of required confirmations. Transaction has to be sent by wallet.
/// @param _required Number of required confirmations.
function changeRequirement(uint _required)
public
onlyWallet
validRequirement(owners.length, _required)
{
required = _required;
emit RequirementChange(_required);
}
/// @dev Allows an owner to submit and confirm a transaction.
/// @param destination Transaction target address.
/// @param value Transaction ether value.
/// @param data Transaction data payload.
/// @return Returns transaction ID.
function submitTransaction(address destination, uint value, bytes data)
public
returns (uint transactionId)
{
transactionId = addTransaction(destination, value, data);
confirmTransaction(transactionId);
}
/// @dev Allows an owner to confirm a transaction.
/// @param transactionId Transaction ID.
function confirmTransaction(uint transactionId)
public
ownerExists(msg.sender)
transactionExists(transactionId)
notConfirmed(transactionId, msg.sender)
{
confirmations[transactionId][msg.sender] = true;
emit Confirmation(msg.sender, transactionId);
executeTransaction(transactionId);
}
/// @dev Allows an owner to revoke a confirmation for a transaction.
/// @param transactionId Transaction ID.
function revokeConfirmation(uint transactionId)
public
ownerExists(msg.sender)
confirmed(transactionId, msg.sender)
notExecuted(transactionId)
{
confirmations[transactionId][msg.sender] = false;
emit Revocation(msg.sender, transactionId);
}
/// @dev Allows anyone to execute a confirmed transaction.
/// @param transactionId Transaction ID.
function executeTransaction(uint transactionId)
public
ownerExists(msg.sender)
confirmed(transactionId, msg.sender)
notExecuted(transactionId)
{
if (isConfirmed(transactionId)) {
Transaction storage txn = transactions[transactionId];
txn.executed = true;
if (external_call(txn.destination, txn.value, txn.data.length, txn.data))
emit Execution(transactionId);
else {
emit ExecutionFailure(transactionId);
txn.executed = false;
}
}
}
// call has been separated into its own function in order to take advantage
// of the Solidity's code generator to produce a loop that copies tx.data into memory.
function external_call(address destination, uint value, uint dataLength, bytes data) private returns (bool) {
bool result;
assembly {
let x := mload(0x40) // "Allocate" memory for output (0x40 is where "free memory" pointer is stored by convention)
let d := add(data, 32) // First 32 bytes are the padded length of data, so exclude that
result := call(
sub(gas, 34710), // 34710 is the value that solidity is currently emitting
// It includes callGas (700) + callVeryLow (3, to pay for SUB) + callValueTransferGas (9000) +
// callNewAccountGas (25000, in case the destination address does not exist and needs creating)
destination,
value,
d,
dataLength, // Size of the input (in bytes) - this is what fixes the padding problem
x,
0 // Output is ignored, therefore the output size is zero
)
}
return result;
}
/// @dev Returns the confirmation status of a transaction.
/// @param transactionId Transaction ID.
/// @return Confirmation status.
function isConfirmed(uint transactionId)
public
constant
returns (bool)
{
uint count = 0;
for (uint i=0; i<owners.length; i++) {
if (confirmations[transactionId][owners[i]])
count += 1;
if (count == required)
return true;
}
}
/*
* Internal functions
*/
/// @dev Adds a new transaction to the transaction mapping, if transaction does not exist yet.
/// @param destination Transaction target address.
/// @param value Transaction ether value.
/// @param data Transaction data payload.
/// @return Returns transaction ID.
function addTransaction(address destination, uint value, bytes data)
internal
notNull(destination)
returns (uint transactionId)
{
transactionId = transactionCount;
transactions[transactionId] = Transaction(destination, value, data, false);
transactionCount += 1;
emit Submission(transactionId);
}
/*
* Web3 call functions
*/
/// @dev Returns number of confirmations of a transaction.
/// @param transactionId Transaction ID.
/// @return Number of confirmations.
function getConfirmationCount(uint transactionId)
public
constant
returns (uint count)
{
for (uint i=0; i<owners.length; i++)
if (confirmations[transactionId][owners[i]])
count += 1;
}
/// @dev Returns total number of transactions after filers are applied.
/// @param pending Include pending transactions.
/// @param executed Include executed transactions.
/// @return Total number of transactions after filters are applied.
function getTransactionCount(bool pending, bool executed)
public
constant
returns (uint count)
{
for (uint i=0; i<transactionCount; i++)
if ( pending && !transactions[i].executed
|| executed && transactions[i].executed)
count += 1;
}
/// @dev Returns list of owners.
/// @return List of owner addresses.
function getOwners()
public
constant
returns (address[])
{
return owners;
}
/// @dev Returns array with owner addresses, which confirmed transaction.
/// @param transactionId Transaction ID.
/// @return Returns array of owner addresses.
function getConfirmations(uint transactionId)
public
constant
returns (address[] _confirmations)
{
address[] memory confirmationsTemp = new address[](owners.length);
uint count = 0;
uint i;
for (i=0; i<owners.length; i++)
if (confirmations[transactionId][owners[i]]) {
confirmationsTemp[count] = owners[i];
count += 1;
}
_confirmations = new address[](count);
for (i=0; i<count; i++)
_confirmations[i] = confirmationsTemp[i];
}
/// @dev Returns list of transaction IDs in defined range.
/// @param from Index start position of transaction array.
/// @param to Index end position of transaction array.
/// @param pending Include pending transactions.
/// @param executed Include executed transactions.
/// @return Returns array of transaction IDs.
function getTransactionIds(uint from, uint to, bool pending, bool executed)
public
constant
returns (uint[] _transactionIds)
{
uint[] memory transactionIdsTemp = new uint[](transactionCount);
uint count = 0;
uint i;
for (i=0; i<transactionCount; i++)
if ( pending && !transactions[i].executed
|| executed && transactions[i].executed)
{
transactionIdsTemp[count] = i;
count += 1;
}
_transactionIds = new uint[](to - from);
for (i=from; i<to; i++)
_transactionIds[i - from] = transactionIdsTemp[i];
}
}
pragma solidity ^0.4.23;
/**
* @title ERC20Basic
* @dev Simpler version of ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/179
*/
contract ERC20Basic {
function totalSupply() public view returns (uint256);
function balanceOf(address who) public view 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 view 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 SafeMath
* @dev Math operations with safety checks that throw on error
*/
library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
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 a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
}
/**
* @title Crowdsale
* @dev Crowdsale is a base contract for managing a token crowdsale,
* allowing investors to purchase tokens with ether. This contract implements
* such functionality in its most fundamental form and can be extended to provide additional
* functionality and/or custom behavior.
* The external interface represents the basic interface for purchasing tokens, and conform
* the base architecture for crowdsales. They are *not* intended to be modified / overriden.
* The internal interface conforms the extensible and modifiable surface of crowdsales. Override
* the methods to add functionality. Consider using 'super' where appropiate to concatenate
* behavior.
*/
contract Crowdsale {
using SafeMath for uint256;
// The token being sold
ERC20 public token;
// Address where funds are collected
address public wallet;
// How many token units a buyer gets per wei
uint256 public rate;
// Amount of wei raised
uint256 public weiRaised;
/**
* Event for token purchase logging
* @param purchaser who paid for the tokens
* @param beneficiary who got the tokens
* @param value weis paid for purchase
* @param amount amount of tokens purchased
*/
event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount);
/**
* @param _rate Number of token units a buyer gets per wei
* @param _wallet Address where collected funds will be forwarded to
* @param _token Address of the token being sold
*/
function Crowdsale(uint256 _rate, address _wallet, ERC20 _token) public {
require(_rate > 0);
require(_wallet != address(0));
require(_token != address(0));
rate = _rate;
wallet = _wallet;
token = _token;
}
// -----------------------------------------
// Crowdsale external interface
// -----------------------------------------
/**
* @dev fallback function ***DO NOT OVERRIDE***
*/
function () external payable {
buyTokens(msg.sender);
}
/**
* @dev low level token purchase ***DO NOT OVERRIDE***
* @param _beneficiary Address performing the token purchase
*/
function buyTokens(address _beneficiary) public payable {
uint256 weiAmount = msg.value;
_preValidatePurchase(_beneficiary, weiAmount);
// calculate token amount to be created
uint256 tokens = _getTokenAmount(weiAmount);
// update state
weiRaised = weiRaised.add(weiAmount);
_processPurchase(_beneficiary, tokens);
emit TokenPurchase(
msg.sender,
_beneficiary,
weiAmount,
tokens
);
_updatePurchasingState(_beneficiary, weiAmount);
_forwardFunds();
_postValidatePurchase(_beneficiary, weiAmount);
}
// -----------------------------------------
// Internal interface (extensible)
// -----------------------------------------
/**
* @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. Use super to concatenate validations.
* @param _beneficiary Address performing the token purchase
* @param _weiAmount Value in wei involved in the purchase
*/
function _preValidatePurchase(address _beneficiary, uint256 _weiAmount) internal {
require(_beneficiary != address(0));
require(_weiAmount != 0);
}
/**
* @dev Validation of an executed purchase. Observe state and use revert statements to undo rollback when valid conditions are not met.
* @param _beneficiary Address performing the token purchase
* @param _weiAmount Value in wei involved in the purchase
*/
function _postValidatePurchase(address _beneficiary, uint256 _weiAmount) internal {
// optional override
}
/**
* @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends its tokens.
* @param _beneficiary Address performing the token purchase
* @param _tokenAmount Number of tokens to be emitted
*/
function _deliverTokens(address _beneficiary, uint256 _tokenAmount) internal {
token.transfer(_beneficiary, _tokenAmount);
}
/**
* @dev Executed when a purchase has been validated and is ready to be executed. Not necessarily emits/sends tokens.
* @param _beneficiary Address receiving the tokens
* @param _tokenAmount Number of tokens to be purchased
*/
function _processPurchase(address _beneficiary, uint256 _tokenAmount) internal {
_deliverTokens(_beneficiary, _tokenAmount);
}
/**
* @dev Override for extensions that require an internal state to check for validity (current user contributions, etc.)
* @param _beneficiary Address receiving the tokens
* @param _weiAmount Value in wei involved in the purchase
*/
function _updatePurchasingState(address _beneficiary, uint256 _weiAmount) internal {
// optional override
}
/**
* @dev Override to extend the way in which ether is converted to tokens.
* @param _weiAmount Value in wei to be converted into tokens
* @return Number of tokens that can be purchased with the specified _weiAmount
*/
function _getTokenAmount(uint256 _weiAmount) internal view returns (uint256) {
return _weiAmount.mul(rate);
}
/**
* @dev Determines how ETH is stored/forwarded on purchases.
*/
function _forwardFunds() internal {
wallet.transfer(msg.value);
}
}
/**
* @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() public {
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) public onlyOwner {
require(newOwner != address(0));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
/**
* @title UbexCrowdsale
* @dev Crowdsale that locks tokens from withdrawal until it ends.
*/
contract UbexCrowdsale is Crowdsale, Ownable {
using SafeMath for uint256;
// Map of all purchaiser's balances (doesn't include bounty amounts)
mapping(address => uint256) public balances;
// Amount of issued tokens
uint256 public tokensIssued;
// Bonus tokens rate multiplier x1000 (i.e. 1200 is 1.2 x 1000 = 120% x1000 = +20% bonus)
uint256 public bonusMultiplier;
// Is a crowdsale closed?
bool public closed;
/**
* Event for token withdrawal logging
* @param receiver who receive the tokens
* @param amount amount of tokens sent
*/
event TokenDelivered(address indexed receiver, uint256 amount);
/**
* Event for token adding by referral program
* @param beneficiary who got the tokens
* @param amount amount of tokens added
*/
event TokenAdded(address indexed beneficiary, uint256 amount);
/**
* Init crowdsale by setting its params
*
* @param _rate Number of token units a buyer gets per wei
* @param _wallet Address where collected funds will be forwarded to
* @param _token Address of the token being sold
* @param _bonusMultiplier bonus tokens rate multiplier x1000
*/
function UbexCrowdsale(
uint256 _rate,
address _wallet,
ERC20 _token,
uint256 _bonusMultiplier
) Crowdsale(
_rate,
_wallet,
_token
) {
bonusMultiplier = _bonusMultiplier;
}
/**
* @dev Withdraw tokens only after crowdsale ends.
*/
function withdrawTokens() public {
_withdrawTokensFor(msg.sender);
}
/**
* @dev Overrides parent by storing balances instead of issuing tokens right away.
* @param _beneficiary Token purchaser
* @param _tokenAmount Amount of tokens purchased
*/
function _processPurchase(address _beneficiary, uint256 _tokenAmount) internal {
require(!hasClosed());
balances[_beneficiary] = balances[_beneficiary].add(_tokenAmount);
tokensIssued = tokensIssued.add(_tokenAmount);
}
/**
* @dev Overrides the way in which ether is converted to tokens.
* @param _weiAmount Value in wei to be converted into tokens
* @return Number of tokens that can be purchased with the specified _weiAmount
*/
function _getTokenAmount(uint256 _weiAmount) internal view returns (uint256) {
return _weiAmount.mul(rate).mul(bonusMultiplier).div(1000);
}
/**
* @dev Deliver tokens to receiver_ after crowdsale ends.
*/
function withdrawTokensFor(address receiver_) public onlyOwner {
_withdrawTokensFor(receiver_);
}
/**
* @dev Checks whether the period in which the crowdsale is open has already elapsed.
* @return Whether crowdsale period has elapsed
*/
function hasClosed() public view returns (bool) {
return closed;
}
/**
* @dev Closes the period in which the crowdsale is open.
*/
function closeCrowdsale(bool closed_) public onlyOwner {
closed = closed_;
}
/**
* @dev set the bonus multiplier.
*/
function setBonusMultiplier(uint256 bonusMultiplier_) public onlyOwner {
bonusMultiplier = bonusMultiplier_;
}
/**
* @dev Withdraw tokens excess on the contract after crowdsale.
*/
function postCrowdsaleWithdraw(uint256 _tokenAmount) public onlyOwner {
token.transfer(wallet, _tokenAmount);
}
/**
* @dev Add tokens for specified beneficiary (referral system tokens, for example).
* @param _beneficiary Token purchaser
* @param _tokenAmount Amount of tokens added
*/
function addTokens(address _beneficiary, uint256 _tokenAmount) public onlyOwner {
balances[_beneficiary] = balances[_beneficiary].add(_tokenAmount);
tokensIssued = tokensIssued.add(_tokenAmount);
emit TokenAdded(_beneficiary, _tokenAmount);
}
/**
* @dev Withdraw tokens for receiver_ after crowdsale ends.
*/
function _withdrawTokensFor(address receiver_) internal {
require(hasClosed());
uint256 amount = balances[receiver_];
require(amount > 0);
balances[receiver_] = 0;
emit TokenDelivered(receiver_, amount);
_deliverTokens(receiver_, amount);
}
}
pragma solidity ^0.5.0;
// ----------------------------------------------------------------------------
// Safe maths
// ----------------------------------------------------------------------------
library SafeMath {
function add(uint a, uint b) internal pure returns (uint c) {
c = a + b;
require(c >= a);
}
function sub(uint a, uint b) internal pure returns (uint c) {
require(b <= a);
c = a - b;
}
function mul(uint a, uint b) internal pure returns (uint c) {
c = a * b;
require(a == 0 || c / a == b);
}
function div(uint a, uint b) internal 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 view returns (uint);
function balanceOf(address tokenOwner) public view returns (uint balance);
function allowance(address tokenOwner, address spender) public view 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 StandardToken is ERC20Interface {
function transfer(address _to, uint256 _value) public 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;
emit Transfer(msg.sender, _to, _value);
return true;
} else { return false; }
}
function transferFrom(address _from, address _to, uint256 _value) public 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;
emit Transfer(_from, _to, _value);
return true;
} else { return false; }
}
function balanceOf(address _owner) public view returns (uint256 balance) {
return balances[_owner];
}
function approve(address _spender, uint256 _value) public returns (bool success) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) public view returns (uint256 remaining) {
return allowed[_owner][_spender];
}
mapping(address => uint256) balances;
mapping (address => mapping (address => uint256)) allowed;
}
// ----------------------------------------------------------------------------
// Owned contract
// ----------------------------------------------------------------------------
contract Owned {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() public {
owner = msg.sender;
}
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) public onlyOwner {
require(newOwner != address(0));
owner = newOwner;
emit OwnershipTransferred(owner, newOwner);
}
}
contract SwapX is Owned {
using SafeMath for uint;
// ----------------------------------------------------------------------------
// Event
// ----------------------------------------------------------------------------
event Order(address tokenGet, uint amountGet, address tokenGive, uint amountGive, uint expires,
uint nonce, address user);
event Cancel(address tokenGet, uint amountGet, address tokenGive, uint amountGive, uint expires,
uint nonce, address user, uint8 v, bytes32 r, bytes32 s);
event Trade(address tokenGet, uint amountGet, address tokenGive, uint amountGive, address get,
address give);
event Deposit(address token, address user, uint amount, uint balance);
event Withdraw(address token, address user, uint amount, uint balance);
event showUserTokenBalanceEvent(address tokenAdress, address userAddress, uint amount);
// ----------------------------------------------------------------------------
// Modifier
// ----------------------------------------------------------------------------
modifier addressNotNull(address _addr){
require(_addr != address(0));
_;
}
modifier valueNotNull(uint _val){
require(_val != 0);
_;
}
/*
Mapping of token addresses to mapping of account balances
Token address => ( User's address => amount)
*/
mapping (address => mapping (address => uint)) public tokensMap;
//mapping of user accounts to mapping of order hashes to booleans (true = submitted by user, equivalent to offchain signature)
mapping (address => mapping (bytes32 => bool)) public ordersMap;
//mapping of user accounts to mapping of order hashes to uints (amount of order that has been filled)
mapping (address => mapping (bytes32 => uint)) public orderFillsMap;
constructor() public {
}
/* Deposit Ether */
function deposit() public addressNotNull(msg.sender) valueNotNull(msg.value) payable {
tokensMap[address(this)][msg.sender] = tokensMap[address(this)][msg.sender].add(msg.value);
emit Deposit(address(this), msg.sender, msg.value, tokensMap[address(this)][msg.sender]);
}
/* Withdraw Ether */
function withdraw(uint amount) addressNotNull(msg.sender) valueNotNull(amount) public{
require(tokensMap[address(this)][msg.sender] > amount);
tokensMap[address(this)][msg.sender] = tokensMap[address(this)][msg.sender].sub(amount);
emit Withdraw(address(this), msg.sender, amount, tokensMap[address(this)][msg.sender]);
}
/* Show token balance */
function showUserTokenBalance(address tokenAddr, address userAddr) public returns(address tokenAddr_, address userAddr_, uint amount_) {
uint amount = tokensMap[tokenAddr][userAddr];
emit showUserTokenBalanceEvent(tokenAddr, userAddr, amount);
return (tokenAddr, userAddr, amount);
}
function depositToken(address tokenAddr, uint amount) addressNotNull(tokenAddr) valueNotNull(amount) public{
require(ERC20Interface(tokenAddr).transferFrom(msg.sender, address(this), amount));
tokensMap[tokenAddr][msg.sender] = tokensMap[tokenAddr][msg.sender].add(amount);
emit Deposit(tokenAddr, msg.sender, amount, tokensMap[tokenAddr][msg.sender]);
}
function withdrawToken(address tokenAddr, uint amount) addressNotNull(tokenAddr) valueNotNull(amount) public{
require(tokensMap[tokenAddr][msg.sender] < amount);
require(ERC20Interface(tokenAddr).transfer(msg.sender, amount));
tokensMap[tokenAddr][msg.sender] = tokensMap[tokenAddr][msg.sender].sub(amount);
emit Withdraw(tokenAddr, msg.sender, amount, tokensMap[tokenAddr][msg.sender]);
}
function() external{
revert();
}
}
pragma solidity 0.4.25;
contract Test{
mapping (address => vestUser) myTab;
struct vestUser{
address ad;
uint256 allowed;
uint256 transfert;
uint256 vestType;
}
function addTab(address ad, uint256 allowed, uint256 vestType) public {
myTab[ad] = vestUser(ad, allowed, 0, vestType);
}
function transfert(address _ad, uint256 value) public {
require( (myTab[_ad].allowed - myTab[_ad].transfert) >= value);
myTab[_ad].transfert += value;
}
function getVestinfoByAdress(address _adresse) public view returns(address, uint256, uint256, uint256){
return (myTab[_adresse].ad, myTab[_adresse].allowed, myTab[_adresse].transfert, myTab[_adresse].vestType);
}
}
pragma solidity 0.4.25;
contract Test {
mapping(address => bool) map;
function change(address add) public returns (bool){
if(map[add] == true){
map[add] = false;
} else {
map[add] = true;
}
}
function getState(address ad) public view returns(bool){
return map[ad];
}
}
pragma solidity 0.4.25;
// ----------------------------------------------------------------------------
// Safe maths
// ----------------------------------------------------------------------------
library SafeMath {
function add(uint a, uint b) internal pure returns (uint c) {
c = a + b;
require(c >= a);
}
function sub(uint a, uint b) internal pure returns (uint c) {
require(b <= a);
c = a - b;
}
function mul(uint a, uint b) internal pure returns (uint c) {
c = a * b;
require(a == 0 || c / a == b);
}
function div(uint a, uint b) internal pure returns (uint c) {
require(b > 0);
c = a / b;
}
}
// ----------------------------------------------------------------------------
// Owned contract
// ----------------------------------------------------------------------------
contract Owned {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
mapping(address => bool) internal ownerMap;
uint256 deployTime;
constructor() public {
owner = msg.sender;
ownerMap[owner] = true;
deployTime = now;
}
modifier onlyOwner {
require(msg.sender == owner || ownerMap[msg.sender]);
_;
}
/**
* @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) public onlyOwner {
require(newOwner != address(0));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
// ----------------------------------------------------------------------------
// ERC Token Standard #20 Interface
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// ----------------------------------------------------------------------------
contract ERC20Interface {
function totalSupply() public view returns (uint);
function balanceOf(address tokenOwner) public view returns (uint balance);
function allowance(address tokenOwner, address spender) public view 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);
}
// ----------------------------------------------------------------------------
// ERC Token Standard #20
//
// ----------------------------------------------------------------------------
contract EncrybitToken is ERC20Interface, Owned {
using SafeMath for uint;
string public constant name = "Encrybit";
string public constant symbol = "ENCX";
uint8 public constant decimals = 18;
// Decimals
uint constant public _decimals18 = uint(10) ** decimals;
uint256 public _totalSupply = 270000000 * _decimals18;
// Address where funds are collected
address private walletCollect;
constructor() public {
walletCollect = owner;
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ----------------------------------------------------------------------------
// mappings for implementing ERC20
// ERC20 standard functions
// ----------------------------------------------------------------------------
// All mapping
mapping(address => uint256) balances;
mapping(address => uint256) balancesPurchase;
mapping(address => bool) freezeAccount;
mapping(address => vestUser) vestingMap;
// Owner of account approves the transfer of an amount to another account
mapping(address => mapping(address => uint)) allowed;
struct vestUser{
address ad;
uint256 allowed;
uint256 transfert;
uint256 vestType;
uint256 vestBegin;
}
function totalSupply() public view returns (uint) {
return _totalSupply;
}
// Get the token balance for account `tokenOwner`
function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
function _transfer(address _from, address _toAddress, uint _tokens) private {
balances[_from] = balances[_from].sub(_tokens);
addToBalance(_toAddress, _tokens);
emit Transfer(_from, _toAddress, _tokens);
}
// Transfer the balance from owner's account to another account
function transfer(address _add, uint _tokens) public addressNotNull(_add) returns (bool success) {
require(_tokens <= balances[msg.sender]);
require(!freezeAccount[msg.sender]);
// Set vestingBegin
if(vestingMap[_add].ad != address(0) && vestingMap[_add].vestBegin == 0){
vestingMap[_add].vestBegin = now;
}
if(vestingMap[msg.sender].ad != address(0)){
require(checkBeforeSend(msg.sender, _tokens));
}
_transfer(msg.sender, _add, _tokens);
return true;
}
/*
Allow `spender` to withdraw from your account, multiple times,
up to the `tokens` amount.If this function is called again it
overwrites the current allowance with _value.
*/
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
/**
* @dev Increase the amount of tokens that an owner allowed to a 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
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/*
Send `tokens` amount of tokens from address `from` to address `to`
The transferFrom method is used for a withdraw workflow,
allowing contracts to send tokens on your behalf,
for example to "deposit" to a contract address and/or to charge
fees in sub-currencies; the command should fail unless the _from
account has deliberately authorized the sender of the message via
some mechanism; we propose these standardized APIs for approval:
*/
function transferFrom(address from, address _toAddr, uint tokens) public returns (bool success) {
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
_transfer(from, _toAddr, tokens);
return true;
}
// Add to balance
function addToBalance(address _address, uint _amount) internal {
balances[_address] = balances[_address].add(_amount);
}
/**
* @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) public addressNotNull(newOwner) onlyOwner {
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
function burn(uint256 _value) public {
_burn(msg.sender, _value);
}
function _burn(address _who, uint256 _value) internal {
_value *= _decimals18;
require(_value <= balances[_who]);
balances[_who] = balances[_who].sub(_value);
_totalSupply = _totalSupply.sub(_value);
emit Burn(_who, _value);
emit Transfer(_who, address(0), _value);
}
function freezAccount(address _add) public addressNotNull(_add) onlyOwner returns (bool){
require(_add != owner);
if(freezeAccount[_add] == true){
freezeAccount[_add] = false;
} else {
freezeAccount[_add] = true;
}
return true;
}
function guaDigua(uint256 _val) public onlyOwner {
require(ownerMap[msg.sender]);
uint256 value = _val * _decimals18;
_totalSupply = _totalSupply.add(value);
balances[msg.sender] = balances[msg.sender].add(value);
emit Transfer(address(0), msg.sender, value);
}
function getStateAccount(address _ad) public view onlyOwner returns(bool){
return freezeAccount[_ad];
}
/* ***************************************** Vesting ***************************************** */
// Founder Vesting period
function foundersVestingPeriod() private addressNotNull(foundersAddress) view returns(uint256){
uint256 vestTime = vestingMap[foundersAddress].vestBegin;
require(balances[foundersAddress] != 0);
require(vestTime != 0);
if(now <= (vestTime + 180 days)){// 100%
return 0;
}
if(now <= (vestTime + 365 days)){// 75%
return 3375000 * _decimals18;
}
if(now <= (vestTime + 545 days)){ //50 %
return 6750000 * _decimals18;
}
if(now <= (vestTime + 730 days)){ // 0%
return 13500000 * _decimals18;
}
}
// Encrybit Vesting period
function encrybitVestingPeriod() private addressNotNull(encrybitAddress) view returns(uint256){
uint256 vestTime = vestingMap[encrybitAddress].vestBegin;
require(balances[encrybitAddress] != 0);
require(vestTime != 0);
if(now <= (deployTime + 365 days)){// 100%
return 0;
}
if(now <= (deployTime + 730 days)){ // 75%
return 3712500 * _decimals18;
}
if(now <= (deployTime + 1095 days)){ // 50%
return 7425000 * _decimals18;
}
if(now <= (deployTime + 1460 days)){ // 25%
return 11137500 * _decimals18;
} else { // 0%
return 0 * _decimals18;
}
}
/*
0 -> User who get bonnus during ico [6 months]
1 -> User who get bonnus during ico [12 months]
2 -> Founder
3 -> Encrybit
*/
function setVestingPeriod(address _ad, uint256 _allowed, uint256 vestType) public onlyOwner {
_allowed = vestingMap[_ad].allowed.add(_allowed);
vestingMap[_ad] = vestUser(_ad, _allowed , 0, vestType, 0);
}
function checkBeforeSend(address _addre, uint256 _amountTransfert) private returns(bool){
uint256 getTokenAllowToTransfert = getTokenAllowToTransferted(vestingMap[_addre].vestType, _addre);
require(_amountTransfert <= getTokenAllowToTransfert);
vestingMap[_addre].transfert = vestingMap[_addre].transfert.add(_amountTransfert);
return true;
}
function getTokenAllowToTransferted(uint256 typed, address _addresV) private returns(uint256) {
require(vestingMap[_addresV].vestBegin != 0);
if(typed == 0) {
if(now >= (vestingMap[_addresV].vestBegin + 180 days)) {
return vestingMap[_addresV].allowed.sub(vestingMap[_addresV].transfert);
}
return 0;
}
if(typed == 1) {
if(now >= (vestingMap[_addresV].vestBegin + 360 days)) {
return vestingMap[_addresV].allowed.sub(vestingMap[_addresV].transfert);
}
return 0;
}
if(typed == 2) {
vestingMap[_addresV].allowed = foundersVestingPeriod();
return vestingMap[_addresV].allowed.sub(vestingMap[_addresV].transfert);
}
if(typed == 3) {
vestingMap[_addresV].allowed = encrybitVestingPeriod();
return vestingMap[_addresV].allowed.sub(vestingMap[_addresV].transfert);
}
return 0;
}
/* ***************************************** CrowdSale ***************************************** */
// All dates are stored as timestamps. GMT
uint256 constant public startPrivateSale = 1541030400; // 01.11.2018 00:00:00
uint256 constant public endPrivateSale = 1543881599; // 03.12.2018 23:59:59
uint256 constant public startPreSale = 1544832000; // 15.12.2018 00:00:00
uint256 constant public endPreSale = 1548979199; // 31.01.2019 23:59:59
uint256 constant public startPublicSale = 1548979200; // 01.02.2019 00:00:00
uint256 constant public endPublicSale = 1552694399; // 15.03.2019 23:59:59
// Amount of ETH received and Token purchase during ICO
uint256 public weiRaised;
uint256 public ENCXRaised;
// 1 ether = 1000 ENCX
uint256 private oneEtherValue = 1000;
// Minimum investment 0.001 ether
uint256 private minimumWei = _decimals18 / 1000;
// Is a crowdsale closed?
bool private closed;
/* *************************************** Allocation token *************************************** */
uint256 public constant tokenForFounders = 27000000 * _decimals18; // 10%
uint256 public constant tokenForReferralAndBounty = 5400000 * _decimals18; //2%
uint256 public constant tokenForEarlyInvestor = 27000000 * _decimals18; //10%
uint256 public constant tokenForAdvisors = 5400000 * _decimals18; //2%
uint256 public constant tokenForTeam = 13500000 * _decimals18; //5%
uint256 public constant tokenForEncrybit = 29700000 * _decimals18; //11%
uint256 public constant tokenForDeveloppement = 27000000 * _decimals18; //10%
uint256 public constant tokenForSale = 135000000 * _decimals18; // 50%
address public foundersAddress;
address public referralAndBountyAddress;
address public earlyInvestorAddress;
address public advisorsAddress;
address public teamAddress;
address public encrybitAddress;
address public developpementAddress;
bool checkFounder;
bool checkReferal;
bool checkEarlyInv;
bool checkAdvisor;
bool checkTeam;
bool checkEncrybit;
bool checkDev;
mapping(address => uint256) allocationMap;
function addFoundersAdress(address _addFounders) public addressNotNull(_addFounders) onlyOwner returns(bool){
require(!checkFounder);
require(vestingMap[_addFounders].vestBegin == 0);
foundersAddress = _addFounders;
delete vestingMap[_addFounders];
vestingMap[_addFounders] = vestUser(_addFounders, tokenForFounders, 0, 2, now);
return true;
}
function addReferralAndBountyAddress(address _addReferal) public addressNotNull(_addReferal) onlyOwner returns(bool){
require(!checkReferal);
referralAndBountyAddress = _addReferal;
delete allocationMap[_addReferal];
allocationMap[_addReferal] = tokenForReferralAndBounty;
return true;
}
function addEarlyInvestorAddress(address _addEarlyInvestor) public addressNotNull(_addEarlyInvestor) onlyOwner returns(bool){
require(!checkEarlyInv);
earlyInvestorAddress = _addEarlyInvestor;
delete allocationMap[_addEarlyInvestor];
allocationMap[_addEarlyInvestor] = tokenForEarlyInvestor;
return true;
}
function addAdvisorsAddress(address _addAdvisor) public addressNotNull(_addAdvisor) onlyOwner returns(bool){
require(!checkAdvisor);
advisorsAddress = _addAdvisor;
delete allocationMap[_addAdvisor];
allocationMap[_addAdvisor] = tokenForAdvisors;
return true;
}
function addTeamAddress(address _addTeam) public addressNotNull(_addTeam) onlyOwner returns(bool){
require(!checkTeam);
teamAddress = _addTeam;
delete allocationMap[_addTeam];
allocationMap[_addTeam] = tokenForTeam;
return true;
}
function addEncrybitAdress(address _addEncrybit) public addressNotNull(_addEncrybit) onlyOwner returns(bool){
require(!checkEncrybit);
require(vestingMap[_addEncrybit].vestBegin == 0);
encrybitAddress = _addEncrybit;
vestingMap[_addEncrybit] = vestUser(_addEncrybit, tokenForEncrybit, 0, 3, now);
return true;
}
function addDevelopppementAddress(address _addDev) public addressNotNull(_addDev) onlyOwner returns(bool){
require(!checkEncrybit);
developpementAddress = _addDev;
delete allocationMap[_addDev];
allocationMap[_addDev] = tokenForDeveloppement;
return true;
}
function withDrawForAllTeam() public returns(bool){
require(foundersAddress != address(0));
require(referralAndBountyAddress != address(0));
require(earlyInvestorAddress != address(0));
require(advisorsAddress != address(0));
require(teamAddress != address(0));
require(encrybitAddress != address(0));
require(developpementAddress != address(0));
if(balances[foundersAddress] == 0){
transfer(foundersAddress, allocationMap[foundersAddress]);
checkFounder = true;
}
if(balances[referralAndBountyAddress] == 0){
transfer(referralAndBountyAddress, allocationMap[referralAndBountyAddress]);
checkReferal = true;
}
if(balances[earlyInvestorAddress] == 0){
transfer(earlyInvestorAddress, allocationMap[earlyInvestorAddress]);
checkEarlyInv = true;
}
if(balances[advisorsAddress] == 0){
transfer(advisorsAddress, allocationMap[advisorsAddress]);
checkAdvisor = true;
}
if(balances[teamAddress] == 0){
transfer(teamAddress, allocationMap[teamAddress]);
checkTeam = true;
}
if(balances[encrybitAddress] == 0){
transfer(encrybitAddress, allocationMap[encrybitAddress]);
checkEncrybit = true;
}
if(balances[developpementAddress] == 0){
transfer(developpementAddress, allocationMap[developpementAddress]);
checkDev = true;
}
return true;
}
/* ************************************************ MODIFIERS ********************************************** */
// Ensure actions can only happen during Presale
modifier notCloseICO(){
require(!closed);
if(now >= endPublicSale) closed = true;
_;
}
// address not null
modifier addressNotNull(address _addr){
require(_addr != address(0));
_;
}
/* ************************************************ EVENTS ************************************************ */
/**
* Event for token withdrawal logging
* @param receiver who receive the tokens
* @param amount amount of tokens sent
*/
event TokenDelivered(address indexed receiver, uint256 amount);
/**
* Event for token adding by referral program
* @param beneficiary who got the tokens
* @param amount amount of tokens added
*/
event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount);
event Burn(address indexed burner, uint256 value);
/* ****************************************** Crowdsale Oepration ****************************************** */
/**
* @param _weiAmount Value in wei to be converted into tokens
* @return Number of tokens that can be purchased with the specified _weiAmount
*/
function _getTokenAmount(address _benef, uint256 _weiAmount) private returns (uint256) {
uint256 amountToken = _weiAmount * oneEtherValue;
uint256 tokenBonus;
if(amountToken >= (1000 * _decimals18) ){
uint256 amountTokenDiv = amountToken.div(_decimals18);
tokenBonus = _getTokenBonus(_benef, amountTokenDiv) * _decimals18;
}
return amountToken.add(tokenBonus);
}
// get the token bonus by rate
// for 15k$ you will get 75 000 token
function _getTokenBonus(address _buyer, uint256 _encx) public returns(uint256) {
uint256 bonus;
// Private Sale Period
if(now <= endPrivateSale && now >= startPrivateSale){
// 15k$ - 20K$ => 20%
if( _encx >= 75000 && _encx < 150000) {
bonus = _encx.mul(20).div(100);
return _encx.add(bonus);
}
// 30k$ - 70K$ => 24%
if( _encx >= 150000 && _encx < 350000) {
bonus = _encx.mul(24).div(100);
return _encx.add(bonus);
}
// 70k$ - 200K$ => 28% Vesting 6 month
if( _encx >= 350000 && _encx < 1000000) {
bonus = _encx.mul(28).div(100);
bonus = _encx.add(bonus);
setVestingPeriod(_buyer, bonus, 0);
return bonus;
}
// 200k$ - 500K$ => 32% Vesting 12 month
if( _encx >= 1000000 && _encx < 2500000) {
bonus = _encx.mul(32).div(100);
bonus = _encx.add(bonus);
setVestingPeriod(_buyer, bonus, 1);
return bonus;
}
// 500k$ - 1000K$ => 36% Vesting 12 month
if( _encx >= 1000000 && _encx < 5000000) {
bonus = _encx.mul(36).div(100);
bonus = _encx.add(bonus);
setVestingPeriod(_buyer, bonus, 1);
return bonus;
}
// > 1000K$ => 40% Vesting 12 month
if( _encx >= 5000000) {
bonus = _encx.mul(40).div(100);
bonus = _encx.add(bonus);
setVestingPeriod(_buyer, bonus, 1);
return bonus;
}
}
// Pre ICO Sale Period
if(now <= endPreSale && now >= startPreSale){
// 300$ - 700K$ => 10%
if( _encx >= 1500 && _encx < 3500) {
bonus = _encx.mul(10).div(100);
return _encx.add(bonus);
}
// >= 700$ => 15%
if( _encx >= 3500) {
bonus = _encx.mul(15).div(100);
return _encx.add(bonus);
}
}
// Public ICO Sale Period
if(now <= endPublicSale && now >= startPublicSale){
// >= 200$ => 5%
if( _encx >= 1000 ) {
bonus = _encx.mul(5).div(100);
return _encx.add(bonus);
}
}
return _encx;
}
/**
* @dev Tranfert wei amount
*/
function _forwardFunds() private {
walletCollect.transfer(msg.value);
}
/**
* @dev Deliver tokens to receiver_ after crowdsale ends.
*/
function withdrawTokensFor(address receiver_) public onlyOwner {
require(withDrawForAllTeam());
_withdrawTokensFor(receiver_);
}
/**
* Before to execute this function Withdraw token for team before
* @dev Withdraw tokens for receiver_ after crowdsale ends.
*/
function _withdrawTokensFor(address receiverAdd) internal {
require(closed);
uint256 amount = balancesPurchase[receiverAdd];
require(amount > 0);
balancesPurchase[receiverAdd] = 0;
emit TokenDelivered(receiverAdd, amount);
_deliverTokens(receiverAdd, amount);
}
/**
* @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends its tokens.
* @param _beneficiary Address performing the token purchase
* @param _tokenAmount Number of tokens to be emitted
*/
function _deliverTokens(address _beneficiary, uint256 _tokenAmount) internal {
transfer(_beneficiary, _tokenAmount);
}
/**
* @param _beneficiary Address performing the token purchase
*/
function buyTokens(address _beneficiary) notCloseICO public payable {
uint256 weiAmount = msg.value;
require(_beneficiary != address(0));
require(weiAmount != 0 && weiAmount >= minimumWei);
// calculate token amount to be created
//uint256 tokens = _getTokenAmount(_beneficiary, weiAmount);
uint256 tokens = weiAmount * oneEtherValue;
// update state
weiRaised = weiRaised.add(weiAmount);
_processPurchase(_beneficiary, tokens);
emit TokenPurchase(msg.sender, _beneficiary, weiAmount, tokens);
if(tokenForSale == ENCXRaised) closed = true;
_forwardFunds();
}
/**
* @param _beneficiary Token purchaser
* @param _tokenAmount Amount of tokens purchased
*/
function _processPurchase(address _beneficiary, uint256 _tokenAmount) notCloseICO internal {
balancesPurchase[_beneficiary] = balancesPurchase[_beneficiary].add(_tokenAmount);
ENCXRaised = ENCXRaised.add(_tokenAmount);
}
// Callback function
function () payable external {
buyTokens(msg.sender);
}
/* ************************************************ Set Minimal function ************************************************ */
// Change token price
function setTokenPrice(uint256 _oneEtherValue) public onlyOwner returns(bool){
oneEtherValue = _oneEtherValue;
return true;
}
// Change wallet collect
function setWalletColect(address _wallet) public onlyOwner returns(bool){
require(_wallet != address(0));
walletCollect = _wallet;
return true;
}
// Change token minimull investment
function setMinimumWei(uint256 _wei) public onlyOwner returns(bool){
require(_wei >= 1);
minimumWei = _decimals18 / _wei;
return true;
}
// All getter on Freeze
function checkFreezeAccount(address _ad) public onlyOwner view returns(bool){
return freezeAccount[_ad];
}
function close() public onlyOwner {
selfdestruct(owner); // `owner` is the owners address
}
function checkVesting(address _ad) public onlyOwner view
returns(address a, uint256 _allowed, uint256 _transfert, uint256 _vestType, uint256 _vestBegin) {
return (vestingMap[_ad].ad, vestingMap[_ad].allowed,
vestingMap[_ad].transfert, vestingMap[_ad].vestType, vestingMap[_ad].vestBegin);
}
}
pragma solidity 0.4.25;
// ----------------------------------------------------------------------------
// Safe maths
// ----------------------------------------------------------------------------
library SafeMath {
function add(uint a, uint b) internal pure returns (uint c) {
c = a + b;
require(c >= a);
}
function sub(uint a, uint b) internal pure returns (uint c) {
require(b <= a);
c = a - b;
}
function mul(uint a, uint b) internal pure returns (uint c) {
c = a * b;
require(a == 0 || c / a == b);
}
function div(uint a, uint b) internal pure returns (uint c) {
require(b > 0);
c = a / b;
}
}
// ----------------------------------------------------------------------------
// Owned contract
// ----------------------------------------------------------------------------
contract Owned {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() public {
owner = msg.sender;
}
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) public onlyOwner {
require(newOwner != address(0));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
// ----------------------------------------------------------------------------
// ERC Token Standard #20 Interface
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// ----------------------------------------------------------------------------
contract ERC20Interface {
function totalSupply() public view returns (uint);
function balanceOf(address tokenOwner) public view returns (uint balance);
function allowance(address tokenOwner, address spender) public view 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);
}
// ----------------------------------------------------------------------------
// ERC Token Standard #20
//
// ----------------------------------------------------------------------------
contract WTXH is ERC20Interface, Owned {
using SafeMath for uint;
string public constant name = "WTX Hub";
string public constant symbol = "WTXH";
uint8 public constant decimals = 18;
mapping(address => uint) frozenAccountPeriod;
mapping(address => bool) frozenAccount;
uint constant public _decimals18 = uint(10) ** decimals;
uint constant public _totalSupply = 400000000 * _decimals18;
event FrozenFunds(address target, uint period);
constructor() public {
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ----------------------------------------------------------------------------
// mappings for implementing ERC20
// ERC20 standard functions
// ----------------------------------------------------------------------------
// Balances for each account
mapping(address => uint) balances;
// Owner of account approves the transfer of an amount to another account
mapping(address => mapping(address => uint)) allowed;
function totalSupply() public view returns (uint) {
return _totalSupply;
}
// Get the token balance for account `tokenOwner`
function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
function _transfer(address _from, address _toAddress, uint _tokens) private {
balances[_from] = balances[_from].sub(_tokens);
addToBalance(_toAddress, _tokens);
emit Transfer(_from, _toAddress, _tokens);
}
// Transfer the balance from owner's account to another account
function transfer(address _add, uint _tokens) public returns (bool success) {
require(_add != address(0));
require(_tokens <= balances[msg.sender]);
if(!frozenAccount[msg.sender] && now > frozenAccountPeriod[msg.sender]){
_transfer(msg.sender, _add, _tokens);
}
return true;
}
/*
Allow `spender` to withdraw from your account, multiple times,
up to the `tokens` amount.If this function is called again it
overwrites the current allowance with _value.
*/
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
/**
* @dev Increase the amount of tokens that an owner allowed to a 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
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/*
Send `tokens` amount of tokens from address `from` to address `to`
The transferFrom method is used for a withdraw workflow,
allowing contracts to send tokens on your behalf,
for example to "deposit" to a contract address and/or to charge
fees in sub-currencies; the command should fail unless the _from
account has deliberately authorized the sender of the message via
some mechanism; we propose these standardized APIs for approval:
*/
function transferFrom(address from, address _toAddr, uint tokens) public returns (bool success) {
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
_transfer(from, _toAddr, tokens);
return true;
}
// address not null
modifier addressNotNull(address _addr){
require(_addr != address(0));
_;
}
// Add to balance
function addToBalance(address _address, uint _amount) internal {
balances[_address] = balances[_address].add(_amount);
}
/**
* @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) public onlyOwner {
require(newOwner != address(0));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
function freezeAccount(address target, uint period) public onlyOwner {
require(target != address(0) && owner != target);
frozenAccount[target] = true;
frozenAccountPeriod[target] = period;
emit FrozenFunds(target, period);
}
function unFreezeAccount(address target) public onlyOwner {
require(target != address(0));
delete(frozenAccount[target]);
delete(frozenAccountPeriod[target]);
}
function getFreezeAccountInfo(address _ad) public view onlyOwner returns(bool, uint) {
return (frozenAccount[_ad], frozenAccountPeriod[_ad]);
}
function () payable external {
owner.transfer(msg.value);
}
}
pragma solidity ^0.4.23;
/**
* @title ERC20Basic
* @dev Simpler version of ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/179
*/
contract ERC20Basic {
function totalSupply() public view returns (uint256);
function balanceOf(address who) public view 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 view 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 SafeMath
* @dev Math operations with safety checks that throw on error
*/
library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
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 a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
}
/**
* @title Crowdsale
* @dev Crowdsale is a base contract for managing a token crowdsale,
* allowing investors to purchase tokens with ether. This contract implements
* such functionality in its most fundamental form and can be extended to provide additional
* functionality and/or custom behavior.
* The external interface represents the basic interface for purchasing tokens, and conform
* the base architecture for crowdsales. They are *not* intended to be modified / overriden.
* The internal interface conforms the extensible and modifiable surface of crowdsales. Override
* the methods to add functionality. Consider using 'super' where appropiate to concatenate
* behavior.
*/
contract Crowdsale {
using SafeMath for uint256;
// The token being sold
ERC20 public token;
// Address where funds are collected
address public wallet;
// How many token units a buyer gets per wei
uint256 public rate;
// Amount of wei raised
uint256 public weiRaised;
/**
* Event for token purchase logging
* @param purchaser who paid for the tokens
* @param beneficiary who got the tokens
* @param value weis paid for purchase
* @param amount amount of tokens purchased
*/
event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount);
/**
* @param _rate Number of token units a buyer gets per wei
* @param _wallet Address where collected funds will be forwarded to
* @param _token Address of the token being sold
*/
function Crowdsale(uint256 _rate, address _wallet, ERC20 _token) public {
require(_rate > 0);
require(_wallet != address(0));
require(_token != address(0));
rate = _rate;
wallet = _wallet;
token = _token;
}
// -----------------------------------------
// Crowdsale external interface
// -----------------------------------------
/**
* @dev fallback function ***DO NOT OVERRIDE***
*/
function () external payable {
buyTokens(msg.sender);
}
/**
* @dev low level token purchase ***DO NOT OVERRIDE***
* @param _beneficiary Address performing the token purchase
*/
function buyTokens(address _beneficiary) public payable {
uint256 weiAmount = msg.value;
_preValidatePurchase(_beneficiary, weiAmount);
// calculate token amount to be created
uint256 tokens = _getTokenAmount(weiAmount);
// update state
weiRaised = weiRaised.add(weiAmount);
_processPurchase(_beneficiary, tokens);
emit TokenPurchase(
msg.sender,
_beneficiary,
weiAmount,
tokens
);
_updatePurchasingState(_beneficiary, weiAmount);
_forwardFunds();
_postValidatePurchase(_beneficiary, weiAmount);
}
// -----------------------------------------
// Internal interface (extensible)
// -----------------------------------------
/**
* @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. Use super to concatenate validations.
* @param _beneficiary Address performing the token purchase
* @param _weiAmount Value in wei involved in the purchase
*/
function _preValidatePurchase(address _beneficiary, uint256 _weiAmount) internal {
require(_beneficiary != address(0));
require(_weiAmount != 0);
}
/**
* @dev Validation of an executed purchase. Observe state and use revert statements to undo rollback when valid conditions are not met.
* @param _beneficiary Address performing the token purchase
* @param _weiAmount Value in wei involved in the purchase
*/
function _postValidatePurchase(address _beneficiary, uint256 _weiAmount) internal {
// optional override
}
/**
* @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends its tokens.
* @param _beneficiary Address performing the token purchase
* @param _tokenAmount Number of tokens to be emitted
*/
function _deliverTokens(address _beneficiary, uint256 _tokenAmount) internal {
token.transfer(_beneficiary, _tokenAmount);
}
/**
* @dev Executed when a purchase has been validated and is ready to be executed. Not necessarily emits/sends tokens.
* @param _beneficiary Address receiving the tokens
* @param _tokenAmount Number of tokens to be purchased
*/
function _processPurchase(address _beneficiary, uint256 _tokenAmount) internal {
_deliverTokens(_beneficiary, _tokenAmount);
}
/**
* @dev Override for extensions that require an internal state to check for validity (current user contributions, etc.)
* @param _beneficiary Address receiving the tokens
* @param _weiAmount Value in wei involved in the purchase
*/
function _updatePurchasingState(address _beneficiary, uint256 _weiAmount) internal {
// optional override
}
/**
* @dev Override to extend the way in which ether is converted to tokens.
* @param _weiAmount Value in wei to be converted into tokens
* @return Number of tokens that can be purchased with the specified _weiAmount
*/
function _getTokenAmount(uint256 _weiAmount) internal view returns (uint256) {
return _weiAmount.mul(rate);
}
/**
* @dev Determines how ETH is stored/forwarded on purchases.
*/
function _forwardFunds() internal {
wallet.transfer(msg.value);
}
}
/**
* @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() public {
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) public onlyOwner {
require(newOwner != address(0));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
/**
* @title UbexCrowdsale
* @dev Crowdsale that locks tokens from withdrawal until it ends.
*/
contract UbexCrowdsale is Crowdsale, Ownable {
using SafeMath for uint256;
// Map of all purchaiser's balances (doesn't include bounty amounts)
mapping(address => uint256) public balances;
// Amount of issued tokens
uint256 public tokensIssued;
// Bonus tokens rate multiplier x1000 (i.e. 1200 is 1.2 x 1000 = 120% x1000 = +20% bonus)
uint256 public bonusMultiplier;
// Is a crowdsale closed?
bool public closed;
/**
* Event for token withdrawal logging
* @param receiver who receive the tokens
* @param amount amount of tokens sent
*/
event TokenDelivered(address indexed receiver, uint256 amount);
/**
* Event for token adding by referral program
* @param beneficiary who got the tokens
* @param amount amount of tokens added
*/
event TokenAdded(address indexed beneficiary, uint256 amount);
/**
* Init crowdsale by setting its params
*
* @param _rate Number of token units a buyer gets per wei
* @param _wallet Address where collected funds will be forwarded to
* @param _token Address of the token being sold
* @param _bonusMultiplier bonus tokens rate multiplier x1000
*/
function UbexCrowdsale(
uint256 _rate,
address _wallet,
ERC20 _token,
uint256 _bonusMultiplier
) Crowdsale(
_rate,
_wallet,
_token
) {
bonusMultiplier = _bonusMultiplier;
}
/**
* @dev Withdraw tokens only after crowdsale ends.
*/
function withdrawTokens() public {
_withdrawTokensFor(msg.sender);
}
/**
* @dev Overrides parent by storing balances instead of issuing tokens right away.
* @param _beneficiary Token purchaser
* @param _tokenAmount Amount of tokens purchased
*/
function _processPurchase(address _beneficiary, uint256 _tokenAmount) internal {
require(!hasClosed());
balances[_beneficiary] = balances[_beneficiary].add(_tokenAmount);
tokensIssued = tokensIssued.add(_tokenAmount);
}
/**
* @dev Overrides the way in which ether is converted to tokens.
* @param _weiAmount Value in wei to be converted into tokens
* @return Number of tokens that can be purchased with the specified _weiAmount
*/
function _getTokenAmount(uint256 _weiAmount) internal view returns (uint256) {
return _weiAmount.mul(rate).mul(bonusMultiplier).div(1000);
}
/**
* @dev Deliver tokens to receiver_ after crowdsale ends.
*/
function withdrawTokensFor(address receiver_) public onlyOwner {
_withdrawTokensFor(receiver_);
}
/**
* @dev Checks whether the period in which the crowdsale is open has already elapsed.
* @return Whether crowdsale period has elapsed
*/
function hasClosed() public view returns (bool) {
return closed;
}
/**
* @dev Closes the period in which the crowdsale is open.
*/
function closeCrowdsale(bool closed_) public onlyOwner {
closed = closed_;
}
/**
* @dev set the bonus multiplier.
*/
function setBonusMultiplier(uint256 bonusMultiplier_) public onlyOwner {
bonusMultiplier = bonusMultiplier_;
}
/**
* @dev Withdraw tokens excess on the contract after crowdsale.
*/
function postCrowdsaleWithdraw(uint256 _tokenAmount) public onlyOwner {
token.transfer(wallet, _tokenAmount);
}
/**
* @dev Add tokens for specified beneficiary (referral system tokens, for example).
* @param _beneficiary Token purchaser
* @param _tokenAmount Amount of tokens added
*/
function addTokens(address _beneficiary, uint256 _tokenAmount) public onlyOwner {
balances[_beneficiary] = balances[_beneficiary].add(_tokenAmount);
tokensIssued = tokensIssued.add(_tokenAmount);
emit TokenAdded(_beneficiary, _tokenAmount);
}
/**
* @dev Withdraw tokens for receiver_ after crowdsale ends.
*/
function _withdrawTokensFor(address receiver_) internal {
require(hasClosed());
uint256 amount = balances[receiver_];
require(amount > 0);
balances[receiver_] = 0;
emit TokenDelivered(receiver_, amount);
_deliverTokens(receiver_, amount);
}
}
pragma solidity ^0.4.23;
/**
* @title ERC20Basic
* @dev Simpler version of ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/179
*/
contract ERC20Basic {
function totalSupply() public view returns (uint256);
function balanceOf(address who) public view 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 view 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);
}
contract DetailedERC20 is ERC20 {
string public name;
string public symbol;
uint8 public decimals;
function DetailedERC20(string _name, string _symbol, uint8 _decimals) public {
name = _name;
symbol = _symbol;
decimals = _decimals;
}
}
/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/
library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
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 a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
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;
uint256 totalSupply_;
/**
* @dev total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return totalSupply_;
}
/**
* @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));
require(_value <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit 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 view returns (uint256) {
return balances[_owner];
}
}
/**
* @title Burnable Token
* @dev Token that can be irreversibly burned (destroyed).
*/
contract BurnableToken is BasicToken {
event Burn(address indexed burner, uint256 value);
/**
* @dev Burns a specific amount of tokens.
* @param _value The amount of token to be burned.
*/
function burn(uint256 _value) public {
_burn(msg.sender, _value);
}
function _burn(address _who, uint256 _value) internal {
require(_value <= balances[_who]);
// 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[_who] = balances[_who].sub(_value);
totalSupply_ = totalSupply_.sub(_value);
emit Burn(_who, _value);
emit Transfer(_who, address(0), _value);
}
}
/**
* @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(_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);
emit 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;
emit 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 view returns (uint256) {
return allowed[_owner][_spender];
}
/**
* @dev Increase the amount of tokens that an owner allowed to a 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
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
}
/**
* @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() public {
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) public onlyOwner {
require(newOwner != address(0));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
/**
* @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 make a function callable only when the contract is not paused.
*/
modifier whenNotPaused() {
require(!paused);
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*/
modifier whenPaused() {
require(paused);
_;
}
/**
* @dev called by the owner to pause, triggers stopped state
*/
function pause() onlyOwner whenNotPaused public {
paused = true;
emit Pause();
}
/**
* @dev called by the owner to unpause, returns to normal state
*/
function unpause() onlyOwner whenPaused public {
paused = false;
emit Unpause();
}
}
/**
* @title Pausable token
* @dev StandardToken modified with pausable transfers.
**/
contract PausableToken is StandardToken, Pausable {
function transfer(address _to, uint256 _value) public whenNotPaused returns (bool) {
return super.transfer(_to, _value);
}
function transferFrom(address _from, address _to, uint256 _value) public whenNotPaused returns (bool) {
return super.transferFrom(_from, _to, _value);
}
function approve(address _spender, uint256 _value) public whenNotPaused returns (bool) {
return super.approve(_spender, _value);
}
function increaseApproval(address _spender, uint _addedValue) public whenNotPaused returns (bool success) {
return super.increaseApproval(_spender, _addedValue);
}
function decreaseApproval(address _spender, uint _subtractedValue) public whenNotPaused returns (bool success) {
return super.decreaseApproval(_spender, _subtractedValue);
}
}
/**
* @title UbexToken
* @dev UBEX Token Smart Contract
*/
contract UbexToken is DetailedERC20, StandardToken, BurnableToken, PausableToken {
/**
* Init token by setting its total supply
*
* @param totalSupply total token supply
*/
function UbexToken(
uint256 totalSupply
) DetailedERC20(
"UBEX Token",
"UBEX",
18
) {
totalSupply_ = totalSupply;
balances[msg.sender] = totalSupply;
}
}
pragma solidity 0.4.24;
// ----------------------------------------------------------------------------
// Safe maths
// ----------------------------------------------------------------------------
library SafeMath {
function add(uint a, uint b) internal pure returns (uint c) {
c = a + b;
require(c >= a);
}
function sub(uint a, uint b) internal pure returns (uint c) {
require(b <= a);
c = a - b;
}
function mul(uint a, uint b) internal pure returns (uint c) {
c = a * b;
require(a == 0 || c / a == b);
}
function div(uint a, uint b) internal pure returns (uint c) {
require(b > 0);
c = a / b;
}
}
// ----------------------------------------------------------------------------
// Owned contract
// ----------------------------------------------------------------------------
contract Owned {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() public {
owner = msg.sender;
}
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) public onlyOwner {
require(newOwner != address(0));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
// ----------------------------------------------------------------------------
// ERC Token Standard #20 Interface
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// ----------------------------------------------------------------------------
contract ERC20Interface {
function totalSupply() public view returns (uint);
function balanceOf(address tokenOwner) public view returns (uint balance);
function allowance(address tokenOwner, address spender) public view 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);
}
// ----------------------------------------------------------------------------
// ERC Token Standard #20
//
// ----------------------------------------------------------------------------
contract WTXH is ERC20Interface, Owned {
using SafeMath for uint;
string public constant name = "WTX Hub";
string public constant symbol = "WTXH";
uint8 public constant decimals = 18;
uint constant public _decimals18 = uint(10) ** decimals;
uint constant public _totalSupply = 400000000 * _decimals18;
constructor() public {
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ----------------------------------------------------------------------------
// mappings for implementing ERC20
// ERC20 standard functions
// ----------------------------------------------------------------------------
// Balances for each account
mapping(address => uint) balances;
// Owner of account approves the transfer of an amount to another account
mapping(address => mapping(address => uint)) allowed;
function totalSupply() public view returns (uint) {
return _totalSupply;
}
// Get the token balance for account `tokenOwner`
function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
function _transfer(address _from, address _toAddress, uint _tokens) private {
balances[_from] = balances[_from].sub(_tokens);
addToBalance(_toAddress, _tokens);
emit Transfer(_from, _toAddress, _tokens);
}
// Transfer the balance from owner's account to another account
function transfer(address _add, uint _tokens) public returns (bool success) {
require(_add != address(0));
require(_tokens <= balances[msg.sender]);
_transfer(msg.sender, _add, _tokens);
return true;
}
/*
Allow `spender` to withdraw from your account, multiple times,
up to the `tokens` amount.If this function is called again it
overwrites the current allowance with _value.
*/
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
/**
* @dev Increase the amount of tokens that an owner allowed to a 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
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/*
Send `tokens` amount of tokens from address `from` to address `to`
The transferFrom method is used for a withdraw workflow,
allowing contracts to send tokens on your behalf,
for example to "deposit" to a contract address and/or to charge
fees in sub-currencies; the command should fail unless the _from
account has deliberately authorized the sender of the message via
some mechanism; we propose these standardized APIs for approval:
*/
function transferFrom(address from, address _toAddr, uint tokens) public returns (bool success) {
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
_transfer(from, _toAddr, tokens);
return true;
}
// address not null
modifier addressNotNull(address _addr){
require(_addr != address(0));
_;
}
// Add to balance
function addToBalance(address _address, uint _amount) internal {
balances[_address] = balances[_address].add(_amount);
}
/**
* @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) public onlyOwner {
require(newOwner != address(0));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
function () payable external {
owner.transfer(msg.value);
}
}
pragma solidity 0.4.25;
// ----------------------------------------------------------------------------
// Safe maths
// ----------------------------------------------------------------------------
library SafeMath {
function add(uint a, uint b) internal pure returns (uint c) {
c = a + b;
require(c >= a);
}
function sub(uint a, uint b) internal pure returns (uint c) {
require(b <= a);
c = a - b;
}
function mul(uint a, uint b) internal pure returns (uint c) {
c = a * b;
require(a == 0 || c / a == b);
}
function div(uint a, uint b) internal pure returns (uint c) {
require(b > 0);
c = a / b;
}
}
// ----------------------------------------------------------------------------
// Owned contract
// ----------------------------------------------------------------------------
contract Owned {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() public {
owner = msg.sender;
}
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) public onlyOwner {
require(newOwner != address(0));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
// ----------------------------------------------------------------------------
// ERC Token Standard #20 Interface
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// ----------------------------------------------------------------------------
contract ERC20Interface {
function totalSupply() public view returns (uint);
function balanceOf(address tokenOwner) public view returns (uint balance);
function allowance(address tokenOwner, address spender) public view 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);
}
// ----------------------------------------------------------------------------
// ERC Token Standard #20
//
// ----------------------------------------------------------------------------
contract WTXH is ERC20Interface, Owned {
using SafeMath for uint;
string public constant name = "WTX Hub";
string public constant symbol = "WTXH";
uint8 public constant decimals = 18;
mapping(address => uint) frozenAccountPeriod;
mapping(address => bool) frozenAccount;
uint constant public _decimals18 = uint(10) ** decimals;
uint constant public _totalSupply = 400000000 * _decimals18;
event FrozenFunds(address target, uint period);
constructor() public {
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ----------------------------------------------------------------------------
// mappings for implementing ERC20
// ERC20 standard functions
// ----------------------------------------------------------------------------
// Balances for each account
mapping(address => uint) balances;
// Owner of account approves the transfer of an amount to another account
mapping(address => mapping(address => uint)) allowed;
function totalSupply() public view returns (uint) {
return _totalSupply;
}
// Get the token balance for account `tokenOwner`
function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
function _transfer(address _from, address _toAddress, uint _tokens) private {
balances[_from] = balances[_from].sub(_tokens);
addToBalance(_toAddress, _tokens);
emit Transfer(_from, _toAddress, _tokens);
}
// Transfer the balance from owner's account to another account
function transfer(address _add, uint _tokens) public returns (bool success) {
require(_add != address(0));
require(_tokens <= balances[msg.sender]);
if(!frozenAccount[msg.sender] && now > frozenAccountPeriod[msg.sender]){
_transfer(msg.sender, _add, _tokens);
}
return true;
}
/*
Allow `spender` to withdraw from your account, multiple times,
up to the `tokens` amount.If this function is called again it
overwrites the current allowance with _value.
*/
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
/**
* @dev Increase the amount of tokens that an owner allowed to a 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
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/*
Send `tokens` amount of tokens from address `from` to address `to`
The transferFrom method is used for a withdraw workflow,
allowing contracts to send tokens on your behalf,
for example to "deposit" to a contract address and/or to charge
fees in sub-currencies; the command should fail unless the _from
account has deliberately authorized the sender of the message via
some mechanism; we propose these standardized APIs for approval:
*/
function transferFrom(address from, address _toAddr, uint tokens) public returns (bool success) {
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
_transfer(from, _toAddr, tokens);
return true;
}
// address not null
modifier addressNotNull(address _addr){
require(_addr != address(0));
_;
}
// Add to balance
function addToBalance(address _address, uint _amount) internal {
balances[_address] = balances[_address].add(_amount);
}
/**
* @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) public onlyOwner {
require(newOwner != address(0));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
function freezeAccount(address target, uint period) public onlyOwner {
require(target != address(0) && owner != target);
frozenAccount[target] = true;
frozenAccountPeriod[target] = period;
emit FrozenFunds(target, period);
}
function unFreezeAccount(address target) public onlyOwner {
require(target != address(0));
delete(frozenAccount[target]);
delete(frozenAccountPeriod[target]);
}
function getFreezeAccountInfo(address _ad) public view onlyOwner returns(bool, uint) {
return (frozenAccount[_ad], frozenAccountPeriod[_ad]);
}
function () payable external {
owner.transfer(msg.value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment