-
-
Save bhattnaval/2eea6398fab22e64140bef930243bacd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity 0.4.18; | |
/* TSSToken contract is based on the ERC20 token contract. Additional functionality has been integrated: | |
* Mintable , Max Limit, Dynamic rates/ Bonus */ | |
/** Math operations with safety checks | |
* safe math for over and under value attack. */ | |
library SafeMath { | |
function mul(uint a, uint b) internal constant returns (uint) { | |
uint c = a * b; | |
assert(a == 0 || c / a == b); | |
return c; | |
} | |
function div(uint a, uint b) internal constant returns (uint) { | |
// assert(b > 0); // Solidity automatically throws when dividing by 0 | |
uint c = a / b; | |
// assert(a == b * c + a % b); // There is no case in which this doesn't hold | |
return c; | |
} | |
function sub(uint a, uint b) internal constant returns (uint) { | |
assert(b <= a); | |
return a - b; | |
} | |
function add(uint a, uint b) internal constant returns (uint) { | |
uint c = a + b; | |
assert(c >= a); | |
return c; | |
} | |
} | |
/** | |
* @title ERC20Basic | |
* @dev Simpler version of ERC20 interface | |
* @dev see https://github.com/ethereum/EIPs/issues/179 | |
*/ | |
contract ERC20Basic { | |
uint256 public totalSupply; | |
function balanceOf(address who) public constant returns (uint256); | |
function transfer(address to, uint256 value) public returns (bool); | |
event Transfer(address indexed from, address indexed to, uint256 value); | |
} | |
/** | |
* @title ERC20 interface | |
* @dev see https://github.com/ethereum/EIPs/issues/20 | |
*/ | |
contract ERC20 is ERC20Basic { | |
function allowance(address owner, address spender) public constant returns (uint256); | |
function transferFrom(address from, address to, uint256 value) public returns (bool); | |
function approve(address spender, uint256 value) public returns (bool); | |
event Approval(address indexed owner, address indexed spender, uint256 value); | |
} | |
/** | |
* @title SafeERC20 | |
* @dev Wrappers around ERC20 operations that throw on failure. | |
* To use this library you can add a `using SafeERC20 for ERC20;` statement to your contract, | |
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc. | |
*/ | |
library SafeERC20 { | |
function safeTransfer(ERC20Basic token, address to, uint256 value) internal { | |
assert(token.transfer(to, value)); | |
} | |
function safeTransferFrom(ERC20 token, address from, address to, uint256 value) internal { | |
assert(token.transferFrom(from, to, value)); | |
} | |
function safeApprove(ERC20 token, address spender, uint256 value) internal { | |
assert(token.approve(spender, value)); | |
} | |
} | |
//----------------------------// | |
// NKToken implementation // | |
//----------------------------// | |
contract TSSToken is ERC20 { | |
using SafeERC20 for ERC20; | |
using SafeMath for uint256; | |
// SafeERC20 token; | |
string public constant symbol = "NKCoin"; | |
string public constant name = "TestCoinAudit01"; | |
uint8 public constant decimals = 18; | |
uint public constant maxLimit = 500000000; | |
uint constant multiDeci = (10 ** decimals); | |
uint256 tempMaxLimit = maxLimit.mul(multiDeci); | |
// Ether reciever | |
address public owner; | |
uint start; | |
uint firstSet; | |
uint secondSet; | |
uint thirdSet; | |
uint tokens; | |
uint checkTokens; | |
//Sale rates | |
uint256 constant public RATE_FOR_WEEK1 = 1150; | |
uint256 constant public RATE_FOR_WEEK2_3 = 1100; | |
uint256 constant public RATE_FOR_WEEK4 = 1050; | |
uint256 constant public RATE_NO_DISCOUNT = 1000; | |
/** | |
* @dev Fix for the ERC20 short address attack. | |
*/ | |
modifier onlyPayloadSize(uint size) { | |
assert(msg.data.length < size + 4); | |
_; | |
} | |
mapping(address=> uint256) balances; | |
mapping(address=>mapping(address=>uint256)) allowed; | |
// Fallback function | |
// The function without name is the default function that is called | |
// whenever anyone sends funds to a contract | |
function() payable{ | |
createTokens(); | |
} | |
function TSSToken(ERC20 token){ | |
owner = msg.sender; // get the owner of the token | |
start = now; // Get the current block time | |
firstSet = start + 30 minutes ; // Get the second block time | |
secondSet = start + 60 minutes; // Get the third block time | |
thirdSet = start + 90 minutes; // Get the fourth block time . | |
} | |
// Mint new tokens | |
function mint(uint noOfTokens) returns (bool){// returns (bool success) { | |
// To get the 18 decimals for TSS | |
noOfTokens = noOfTokens.mul(multiDeci); | |
checkTokens = totalSupply.add(noOfTokens); | |
// Check that the total tokens(total supply + New minting token) are less then the max limit | |
require(checkTokens < tempMaxLimit ); | |
balances[owner] = balances[owner].add(noOfTokens); | |
totalSupply = totalSupply.add(noOfTokens); | |
return true; | |
} | |
/* Get the RATE dynamically Minimum Amount: 0.01 ETH | |
Bonus of period: 15% (1 ETH = 1150 TSS) Week 1 from ICO Date | |
Bonus of period: 10% (1 ETH = 1100 TSS) Week 2 and Week 3 from ICO Date | |
Bonus of period: 5% (1ETH = 1050TSS) Week 4 from ICO Date | |
After Week 4 (1ETH = 1000TSS) */ | |
function getTokens(uint256 valueWei) internal constant returns(uint256) { | |
// First week RATE = 1150 | |
if (now <= firstSet && now > start) { | |
tokens = valueWei.mul(RATE_FOR_WEEK1); | |
return tokens; | |
} | |
// Second and third week RATE = 1100 | |
if (now <= secondSet && now > firstSet ) { | |
tokens = valueWei.mul(RATE_FOR_WEEK2_3); | |
return tokens; | |
} | |
// Fourth week RATE = 1050 | |
if (now <= thirdSet && now > secondSet ) { | |
tokens = valueWei.mul(RATE_FOR_WEEK4); | |
return tokens; | |
} | |
// After fourth week RATE = 1000 | |
if (now > thirdSet ) { | |
tokens = valueWei.mul(RATE_NO_DISCOUNT); | |
return tokens; | |
} | |
} | |
function createTokens() payable returns(bool){ | |
uint256 valueWei = msg.value; | |
// Minimum accepted 0.01 Ether | |
require(valueWei >= 0.01 ether); | |
tokens = getTokens(valueWei); | |
//Check that the total tokens are less than Max value | |
checkTokens = totalSupply.add(tokens); | |
require(checkTokens < tempMaxLimit); | |
balances[msg.sender] = balances[msg.sender].add(tokens); | |
totalSupply = totalSupply.add(tokens); | |
owner.transfer(msg.value); | |
return true; | |
} | |
function balanceOf(address _owner) constant returns (uint balance){ | |
return balances[_owner]; | |
} | |
//token.safeTransfer(_to,_value); | |
function transfer(ERC20 token, address _to, uint _value) onlyPayloadSize(2 * 32) returns (bool){ | |
require( balances[msg.sender] >= _value && _value > 0 ); | |
balances[msg.sender] = balances[msg.sender].sub(_value); | |
balances[_to] = balances[_to].add(_value); | |
token.safeTransfer(_to,_value); | |
return true; | |
} | |
/** | |
* @dev transfer token for a specified address | |
* @param _to The address to transfer to. | |
* @param _value The amount to be transferred. | |
*/ | |
function transferFrom(ERC20 token,address _from, address _to, uint _value) onlyPayloadSize(3 * 32) returns (bool) { | |
require( allowed[_from][msg.sender] >= _value && | |
balances[_from] >= _value && _value > 0 ); | |
balances[_from] = balances[_from].sub(_value); | |
balances[_to] = balances[_to].add(_value); | |
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); | |
token.safeTransferFrom(_from,_to,_value); | |
} | |
function approve(address _spender, uint _value) returns (bool success){ | |
allowed[msg.sender][_spender] = _value; | |
Approval(msg.sender,_spender,_value); | |
return true; | |
} | |
function allowance(address _owner, address _spender) constant returns (uint remaining){ | |
return allowed [_owner][_spender]; | |
} | |
//Transfer event for network . | |
event Transfer(address indexed _from, address indexed _to, uint _value); | |
event Approval(address indexed _owner, address indexed _spender, uint _value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment