Last active
July 3, 2017 15:19
-
-
Save ggomagundan/1a405288c9f07694b1f2fcaf5e2b41e6 to your computer and use it in GitHub Desktop.
FleaMarket Token
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.11; | |
// Token standard API | |
// https://github.com/ethereum/EIPs/issues/20 | |
// And add Increase and Decrease | |
// https://github.com/ethereum/EIPs/pull/621 | |
contract SafeMath { | |
// Constrcut | |
function SafeMath() { | |
} | |
function safeAdd(uint256 x, uint256 y) internal returns(uint256) { | |
uint256 z = x + y; | |
assert((z >= x) && (z >= y)); | |
return z; | |
} | |
function safeSubtract(uint256 x, uint256 y) internal returns(uint256) { | |
assert(x >= y); | |
uint256 z = x - y; | |
return z; | |
} | |
function safeMult(uint256 x, uint256 y) internal returns(uint256) { | |
uint256 z = x * y; | |
assert((x == 0)||(z/x == y)); | |
return z; | |
} | |
function safeDivide(uint256 x, uint256 y) internal returns (uint256) { | |
assert(y != 0); | |
uint256 z = x / y; | |
return z; | |
} | |
} | |
contract ERC20 { | |
function balanceOf( address who ) constant returns (uint value); | |
function allowance( address owner, address spender ) constant returns (uint _allowance); | |
function transfer( address _to, uint _value) returns (bool ok); | |
function transferFrom( address _from, address _to, uint _value) returns (bool ok); | |
function approve( address spender, uint value ) returns (bool ok); | |
function mint(uint value, address from) returns (bool); | |
function burn(uint value, address from) returns (bool); | |
event Transfer( address from, address to, uint value); | |
event Approval( address owner, address spender, uint value); | |
event Mint(address from, uint value); | |
event Burn(address from, uint value); | |
} | |
contract Owned { | |
address public ownedAddress; // Owner Address | |
function Owned(){ | |
ownedAddress = msg.sender; | |
} | |
modifier ownerOnly{ | |
assert(msg.sender == ownedAddress); | |
_; | |
} | |
} | |
contract BaseToken is ERC20, SafeMath, Owned{ | |
mapping (address => uint256) balances; | |
mapping (address => mapping (address => uint256)) approvals; | |
uint256 public totalSupply; | |
uint256 public maxCap = 1000000000; | |
function transfer(address _to, uint _value) returns (bool success) { | |
assert(balances[msg.sender] >= _value); | |
balances[msg.sender] = safeSubtract(balances[msg.sender], _value); | |
balances[_to] = safeAdd(balances[_to], _value); | |
totalSupply = safeAdd(totalSupply, _value); | |
Transfer(msg.sender, _to, _value); | |
return true; | |
} | |
function balanceOf(address _owner) constant returns (uint256) { | |
return balances[_owner]; | |
} | |
function allowance(address _owner, address _spender) constant returns (uint256) { | |
return approvals[_owner][_spender]; | |
} | |
function transferFrom(address _from, address _to, uint _value) returns (bool) { | |
//assert(balances[_from] >= _value); | |
//assert(approvals[_from][msg.sender] >= _value); | |
approvals[_from][msg.sender] = safeSubtract(approvals[_from][msg.sender], _value); | |
balances[_from] = safeSubtract(balances[_from], _value); | |
balances[_to] = safeAdd(balances[_to], _value); | |
Transfer(_from, _to, _value); | |
return true; | |
} | |
function approve(address _spender, uint256 _value) returns (bool) { | |
approvals[msg.sender][_spender] = _value; | |
Approval(msg.sender, _spender, _value); | |
return true; | |
} | |
function mint(uint value, address from) ownerOnly returns (bool){ | |
maxCap = safeAdd(maxCap, value); | |
Mint(from, value); | |
return true; | |
} | |
function burn(uint value, address from) ownerOnly returns (bool){ | |
maxCap = safeSubtract(maxCap, value); | |
Burn(from, value); | |
return true; | |
} | |
} | |
contract FLToken is BaseToken{ | |
bytes32 public symbol = "FLT"; | |
bytes32 public name = "FleaMarketToken"; | |
uint256 public dev_balance = 0; | |
uint256 public decimals = 18; // standard token precision. override to customize | |
// crowdsale parameters | |
address public fundDeposit; | |
bool public isFinalized; // switched to true in operational state | |
uint256 public fundingStartBlock; | |
uint256 public fundingEndBlock; | |
uint256 public contributedToken; | |
uint256 public constant tokenExchangeRate = 100; // 100 FLT tokens per 1 ETH | |
// Total 10000 ETH | |
event CreateFLT(address _to, uint _maxCap, uint256 _value); | |
event LogRefund(address indexed _to, uint256 _value); | |
event ReceivedETH(address addr, uint256 value); | |
event DevETH(address addr, uint256 value); | |
event BlockLog(uint256 _blockNumber); | |
function FLToken(address _fundDeposit, | |
uint256 _fundingStartBlock, | |
uint256 _fundingEndBlock) { | |
//fundDeposit = 0xc0CAeC8B5cc304a4444D35559a802C25166B9df4; | |
fundDeposit = _fundDeposit; | |
isFinalized = false; | |
fundingStartBlock = _fundingStartBlock; | |
fundingEndBlock = _fundingEndBlock; | |
balances[msg.sender] = maxCap; | |
totalSupply = 0; | |
CreateFLT(_fundDeposit, maxCap, totalSupply); | |
} | |
modifier isOwned() { | |
require(msg.sender == fundDeposit || msg.sender == ownedAddress); | |
_; | |
} | |
modifier canTokenDistribute() { | |
require(!isFinalized && block.number < fundingEndBlock | |
&& block.number > fundingStartBlock); | |
_; | |
} | |
function finalize() external canTokenDistribute isOwned { | |
if (msg.sender != fundDeposit && msg.sender != ownedAddress ) throw; // locks finalize to the ultimate ETH owner | |
if(block.number <= fundingEndBlock) throw; | |
isFinalized = true; | |
} | |
// fallback | |
function () payable canTokenDistribute { | |
createToken(); | |
} | |
// Token Distribute | |
function createToken() canTokenDistribute { | |
BlockLog(block.number); | |
uint256 fltAmount = safeMult(msg.value, tokenExchangeRate); | |
ReceivedETH(msg.sender, msg.value); | |
fltAmount = safeAdd(fltAmount, 10); | |
dev_balance = safeAdd(dev_balance, fltAmount/10); | |
if(contributeToken >= totalSupply) | |
ReceivedETH(msg.sender, fltAmount); | |
DevETH(msg.sender, dev_balance); | |
// transfer(msg.sender, msg.value * 100 + 10); | |
contributed = safeAdd(fltAmount, dev_balance); | |
safeAdd(contributeToken, contributed); | |
} | |
} |
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.11; | |
/* taking ideas from FirstBlood token */ | |
contract SafeMath { | |
/* function assert(bool assertion) internal { */ | |
/* if (!assertion) { */ | |
/* throw; */ | |
/* } */ | |
/* } // assert no longer needed once solidity is on 0.4.10 */ | |
function safeAdd(uint256 x, uint256 y) internal returns(uint256) { | |
uint256 z = x + y; | |
assert((z >= x) && (z >= y)); | |
return z; | |
} | |
function safeSubtract(uint256 x, uint256 y) internal returns(uint256) { | |
assert(x >= y); | |
uint256 z = x - y; | |
return z; | |
} | |
function safeMult(uint256 x, uint256 y) internal returns(uint256) { | |
uint256 z = x * y; | |
assert((x == 0)||(z/x == y)); | |
return z; | |
} | |
function safeDivide(uint256 x, uint256 y) internal returns (uint256) { | |
assert(y != 0); | |
uint256 z = x / y; | |
return z; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment