-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit eebec1d
Showing
19 changed files
with
728 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# System Cruft | ||
# ================================================ | ||
.DS_Store | ||
*.swp | ||
*.swo | ||
|
||
# secret stuff | ||
# ================================================ | ||
secrets.json | ||
|
||
# Generated stuff | ||
# ================================================ | ||
build | ||
node_modules | ||
contracts/Standard_Token/config/development/contracts.json | ||
contracts/Standard_Token/config/test/contracts.json | ||
contracts/Standard_Token_Factory/config/development/contracts.json | ||
contracts/Standard_Token_Factory/config/test/contracts.json | ||
Token_Contracts/environments/test/contracts/ | ||
secrets.json | ||
|
||
|
||
# Other | ||
# ================================================ | ||
bower_components |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
The MIT License (MIT) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Tokens | ||
[ ](https://app.codeship.com/projects/233433) | ||
|
||
This repo contains Solidity smart contract code to issue simple, standards-compliant tokens on Ethereum. It can be used to create any form of asset, currency, coin, hours, usage tokens, vunk, etc. | ||
|
||
The default is [StandardToken.sol](https://github.com/ConsenSys/Tokens/blob/master/contracts/StandardToken.sol) which ONLY implements the core ERC20 standard functionality [#20](https://github.com/ethereum/EIPs/issues/20). | ||
|
||
[HumanStandardToken.sol](https://github.com/ConsenSys/Tokens/blob/master/contracts/HumanStandardToken.sol) is an example of a token that has optional extras fit for your issuing your own tokens, to be mainly used by other humans. It includes: | ||
|
||
1. Initial Finite Supply (upon creation one specifies how much is minted). | ||
2. In the absence of a token registry: Optional Decimal, Symbol & Name. | ||
3. Optional approveAndCall() functionality to notify a contract if an approval() has occurred. | ||
|
||
There is a set of tests written for the HumanStandardToken.sol using the Truffle framework to do so. | ||
|
||
Standards allows other contract developers to easily incorporate your token into their application (governance, exchanges, games, etc). It will be updated as often as possible. | ||
|
||
## Testing | ||
|
||
```npm install``` | ||
|
||
For getting truffle-hdwallet-provider. Solidity tests have to still be written. | ||
|
||
Uses Truffle 3.x. | ||
|
||
## ethpm | ||
|
||
This is published under tokens at ethpm. | ||
|
||
## Contributing | ||
|
||
**Pull requests are welcome! Please keep standards discussions to the EIP repos.** | ||
|
||
When submitting a pull request, please do so to the `staging` branch. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
This Token Contract implements the standard token functionality (https://github.com/ethereum/EIPs/issues/20) as well as the following OPTIONAL extras intended for use by humans. | ||
In other words. This is intended for deployment in something like a Token Factory or Mist wallet, and then used by humans. | ||
Imagine coins, currencies, shares, voting weight, etc. | ||
Machine-based, rapid creation of many tokens would not necessarily need these extra features or will be minted in other manners. | ||
1) Initial Finite Supply (upon creation one specifies how much is minted). | ||
2) In the absence of a token registry: Optional Decimal, Symbol & Name. | ||
3) Optional approveAndCall() functionality to notify a contract if an approval() has occurred. | ||
.*/ | ||
|
||
import "./StandardToken.sol"; | ||
|
||
pragma solidity ^0.4.8; | ||
|
||
contract HumanStandardToken is StandardToken { | ||
|
||
/* Public variables of the token */ | ||
|
||
/* | ||
NOTE: | ||
The following variables are OPTIONAL vanities. One does not have to include them. | ||
They allow one to customise the token contract & in no way influences the core functionality. | ||
Some wallets/interfaces might not even bother to look at this information. | ||
*/ | ||
string public name; //fancy name: eg Simon Bucks | ||
uint8 public decimals; //How many decimals to show. ie. There could 1000 base units with 3 decimals. Meaning 0.980 SBX = 980 base units. It's like comparing 1 wei to 1 ether. | ||
string public symbol; //An identifier: eg SBX | ||
string public version = 'H0.1'; //human 0.1 standard. Just an arbitrary versioning scheme. | ||
|
||
function HumanStandardToken( | ||
uint256 _initialAmount, | ||
string _tokenName, | ||
uint8 _decimalUnits, | ||
string _tokenSymbol | ||
) public { | ||
balances[msg.sender] = _initialAmount; // Give the creator all initial tokens | ||
totalSupply = _initialAmount; // Update total supply | ||
name = _tokenName; // Set the name for display purposes | ||
decimals = _decimalUnits; // Amount of decimals for display purposes | ||
symbol = _tokenSymbol; // Set the symbol for display purposes | ||
} | ||
|
||
/* Approves and then calls the receiving contract */ | ||
function approveAndCall(address _spender, uint256 _value, bytes _extraData) public returns (bool success) { | ||
allowed[msg.sender][_spender] = _value; | ||
Approval(msg.sender, _spender, _value); | ||
|
||
//call the receiveApproval function on the contract you want to be notified. This crafts the function signature manually so one doesn't have to include a contract in here just for this. | ||
//receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData) | ||
//it is assumed when one does this that the call *should* succeed, otherwise one would use vanilla approve instead. | ||
require(_spender.call(bytes4(bytes32(keccak256("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)); | ||
return true; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import "./HumanStandardToken.sol"; | ||
|
||
pragma solidity ^0.4.8; | ||
|
||
contract HumanStandardTokenFactory { | ||
|
||
mapping(address => address[]) public created; | ||
mapping(address => bool) public isHumanToken; //verify without having to do a bytecode check. | ||
bytes public humanStandardByteCode; | ||
|
||
function HumanStandardTokenFactory() public { | ||
//upon creation of the factory, deploy a HumanStandardToken (parameters are meaningless) and store the bytecode provably. | ||
address verifiedToken = createHumanStandardToken(10000, "Verify Token", 3, "VTX"); | ||
humanStandardByteCode = codeAt(verifiedToken); | ||
} | ||
|
||
//verifies if a contract that has been deployed is a Human Standard Token. | ||
//NOTE: This is a very expensive function, and should only be used in an eth_call. ~800k gas | ||
function verifyHumanStandardToken(address _tokenContract) public constant returns (bool) { | ||
bytes memory fetchedTokenByteCode = codeAt(_tokenContract); | ||
|
||
if (fetchedTokenByteCode.length != humanStandardByteCode.length) { | ||
return false; //clear mismatch | ||
} | ||
|
||
//starting iterating through it if lengths match | ||
for (uint i = 0; i < fetchedTokenByteCode.length; i ++) { | ||
if (fetchedTokenByteCode[i] != humanStandardByteCode[i]) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
//for now, keeping this internal. Ideally there should also be a live version of this that any contract can use, lib-style. | ||
//retrieves the bytecode at a specific address. | ||
function codeAt(address _addr) internal constant returns (bytes o_code) { | ||
assembly { | ||
// retrieve the size of the code, this needs assembly | ||
let size := extcodesize(_addr) | ||
// allocate output byte array - this could also be done without assembly | ||
// by using o_code = new bytes(size) | ||
o_code := mload(0x40) | ||
// new "memory end" including padding | ||
mstore(0x40, add(o_code, and(add(add(size, 0x20), 0x1f), not(0x1f)))) | ||
// store length in memory | ||
mstore(o_code, size) | ||
// actually retrieve the code, this needs assembly | ||
extcodecopy(_addr, add(o_code, 0x20), 0, size) | ||
} | ||
} | ||
|
||
function createHumanStandardToken(uint256 _initialAmount, string _name, uint8 _decimals, string _symbol) public returns (address) { | ||
|
||
HumanStandardToken newToken = (new HumanStandardToken(_initialAmount, _name, _decimals, _symbol)); | ||
created[msg.sender].push(address(newToken)); | ||
isHumanToken[address(newToken)] = true; | ||
newToken.transfer(msg.sender, _initialAmount); //the factory will own the created tokens. You must transfer them. | ||
return address(newToken); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
pragma solidity ^0.4.4; | ||
|
||
contract Migrations { | ||
address public owner; | ||
uint public last_completed_migration; | ||
|
||
modifier restricted() { | ||
if (msg.sender == owner) _; | ||
} | ||
|
||
function Migrations() public { | ||
owner = msg.sender; | ||
} | ||
|
||
function setCompleted(uint completed) public restricted { | ||
last_completed_migration = completed; | ||
} | ||
|
||
function upgrade(address new_address) public restricted { | ||
Migrations upgraded = Migrations(new_address); | ||
upgraded.setCompleted(last_completed_migration); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
This is an example contract that helps test the functionality of the approveAndCall() functionality of HumanStandardToken.sol. | ||
This one assumes successful receival of approval. | ||
*/ | ||
pragma solidity ^0.4.8; | ||
|
||
contract SampleRecipientSuccess { | ||
/* A Generic receiving function for contracts that accept tokens */ | ||
address public from; | ||
uint256 public value; | ||
address public tokenContract; | ||
bytes public extraData; | ||
|
||
event ReceivedApproval(uint256 _value); | ||
|
||
function receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData) public { | ||
from = _from; | ||
value = _value; | ||
tokenContract = _tokenContract; | ||
extraData = _extraData; | ||
ReceivedApproval(_value); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
This is an example contract that helps test the functionality of the approveAndCall() functionality of HumanStandardToken.sol. | ||
This one will throw and thus needs to propagate the error up. | ||
*/ | ||
pragma solidity ^0.4.8; | ||
|
||
contract SampleRecipientThrow { | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
You should inherit from StandardToken or, for a token like you would want to | ||
deploy in something like Mist, see HumanStandardToken.sol. | ||
(This implements ONLY the standard functions and NOTHING else. | ||
If you deploy this, you won't have anything useful.) | ||
Implements ERC 20 Token standard: https://github.com/ethereum/EIPs/issues/20 | ||
.*/ | ||
pragma solidity ^0.4.8; | ||
|
||
import "./Token.sol"; | ||
|
||
contract StandardToken is Token { | ||
|
||
uint256 constant MAX_UINT256 = 2**256 - 1; | ||
|
||
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. | ||
//require(balances[msg.sender] >= _value && balances[_to] + _value > balances[_to]); | ||
require(balances[msg.sender] >= _value); | ||
balances[msg.sender] -= _value; | ||
balances[_to] += _value; | ||
Transfer(msg.sender, _to, _value); | ||
return true; | ||
} | ||
|
||
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. | ||
//require(balances[_from] >= _value && allowed[_from][msg.sender] >= _value && balances[_to] + _value > balances[_to]); | ||
uint256 allowance = allowed[_from][msg.sender]; | ||
require(balances[_from] >= _value && allowance >= _value); | ||
balances[_to] += _value; | ||
balances[_from] -= _value; | ||
if (allowance < MAX_UINT256) { | ||
allowed[_from][msg.sender] -= _value; | ||
} | ||
Transfer(_from, _to, _value); | ||
return true; | ||
} | ||
|
||
function balanceOf(address _owner) constant public returns (uint256 balance) { | ||
return balances[_owner]; | ||
} | ||
|
||
function approve(address _spender, uint256 _value) public returns (bool success) { | ||
allowed[msg.sender][_spender] = _value; | ||
Approval(msg.sender, _spender, _value); | ||
return true; | ||
} | ||
|
||
function allowance(address _owner, address _spender) public constant returns (uint256 remaining) { | ||
return allowed[_owner][_spender]; | ||
} | ||
|
||
mapping (address => uint256) balances; | ||
mapping (address => mapping (address => uint256)) allowed; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Abstract contract for the full ERC 20 Token standard | ||
// https://github.com/ethereum/EIPs/issues/20 | ||
pragma solidity ^0.4.8; | ||
|
||
contract Token { | ||
/* This is a slight change to the ERC20 base standard. | ||
function totalSupply() constant returns (uint256 supply); | ||
is replaced with: | ||
uint256 public totalSupply; | ||
This automatically creates a getter function for the totalSupply. | ||
This is moved to the base contract since public getter functions are not | ||
currently recognised as an implementation of the matching abstract | ||
function by the compiler. | ||
*/ | ||
/// total amount of tokens | ||
uint256 public totalSupply; | ||
|
||
/// @param _owner The address from which the balance will be retrieved | ||
/// @return The balance | ||
function balanceOf(address _owner) public constant returns (uint256 balance); | ||
|
||
/// @notice send `_value` token to `_to` from `msg.sender` | ||
/// @param _to The address of the recipient | ||
/// @param _value The amount of token to be transferred | ||
/// @return Whether the transfer was successful or not | ||
function transfer(address _to, uint256 _value) 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 `_spender` to spend `_value` tokens | ||
/// @param _spender The address of the account able to transfer the tokens | ||
/// @param _value The amount of tokens to be approved for transfer | ||
/// @return Whether the approval was successful or not | ||
function approve(address _spender, uint256 _value) 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 constant returns (uint256 remaining); | ||
|
||
event Transfer(address indexed _from, address indexed _to, uint256 _value); | ||
event Approval(address indexed _owner, address indexed _spender, uint256 _value); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"package_name": "tokens", | ||
"version": "0.0.3", | ||
"description": "Ethereum Token Contracts", | ||
"authors": [ | ||
"Simon de la Rouviere <[email protected]>", | ||
"Joseph Chow <[email protected]>" | ||
], | ||
"keywords": [ | ||
"tokens", | ||
"consensys" | ||
], | ||
"license": "MIT" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const Migrations = artifacts.require(`./Migrations.sol`) | ||
|
||
module.exports = (deployer) => { | ||
deployer.deploy(Migrations) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const HumanStandardToken = artifacts.require(`./HumanStandardToken.sol`) | ||
|
||
module.exports = (deployer) => { | ||
deployer.deploy(HumanStandardToken) | ||
} |
Oops, something went wrong.