Browse Source

Reorganize repo and rename files. See commit body

In the interest of this repo being structured to support multiple token
types in the future, we have collapsed HumanStandardToken into
StandardToken, and renamed StandardToken to EIP20. In the future,
additional tokens can be added under their EIP/ERC names.
Mike Goldin 6 years ago
parent
commit
44c3a1e46d

+ 13 - 22
README.md

@@ -1,34 +1,25 @@
 # Tokens
 [ ![Codeship Status for ConsenSys/Tokens](https://app.codeship.com/projects/ccf33380-4dfa-0135-cfa1-72c4965f7f14/status?branch=master)](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.  
+This repo contains Solidity smart contract code for simple, standards-compliant tokens on Ethereum. Adhering to standards allows other contract developers to easily incorporate your token into their applications.
 
-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).  
+The repo currently implements [EIP20](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md) tokens, and more may be added in the future.
 
-[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:  
+## Initialize
+The only environmental dependency you need is Node. Presently we can guarantee this all works with Node 8.
+```
+npm install
+npm run compile
+```
 
-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.
+## Tests
+The repo has a comprehensive test suite. You can run it with `npm run test`.
 
 ## ethpm
-
-This is published under tokens at ethpm.
+The contracts in this repo are published under `tokens` on EPM. EPM is the recommended means of consuming token contracts in this repo. Copy-pasting code is highly discouraged.
 
 ## Contributing
+Pull requests are welcome! Please keep standards discussions to the EIP repos.
 
-**Pull requests are welcome! Please keep standards discussions to the EIP repos.**
+When submitting a pull request, please do so to the `staging` branch. For a pull request to be accepted, they must pass the test suite. If a pull request adds features, it should add test coverage for those features.
 
-When submitting a pull request, please do so to the `staging` branch. 

+ 0 - 45
contracts/HumanStandardToken.sol

@@ -1,45 +0,0 @@
-/*
-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
-    }
-}

+ 26 - 8
contracts/StandardToken.sol

@@ -1,19 +1,37 @@
 /*
-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
+Implements EIP20 token standard: https://github.com/ethereum/EIPs/issues/20
 .*/
 pragma solidity ^0.4.8;
 
-import "./Token.sol";
+import "./EIP20Interface.sol";
 
-contract StandardToken is Token {
+contract EIP20 is EIP20Interface {
 
     uint256 constant MAX_UINT256 = 2**256 - 1;
 
+    /*
+    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.
+    string public symbol;                 //An identifier: eg SBX
+
+     function EIP20(
+        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
+    }
+
     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.

+ 14 - 14
contracts/HumanStandardTokenFactory.sol

@@ -1,31 +1,31 @@
-import "./HumanStandardToken.sol";
+import "./EIP20.sol";
 
 pragma solidity ^0.4.8;
 
-contract HumanStandardTokenFactory {
+contract EIP20Factory {
 
     mapping(address => address[]) public created;
-    mapping(address => bool) public isHumanToken; //verify without having to do a bytecode check.
-    bytes public humanStandardByteCode;
+    mapping(address => bool) public isEIP20; //verify without having to do a bytecode check.
+    bytes public EIP20ByteCode;
 
-    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);
+    function EIP20Factory() public {
+      //upon creation of the factory, deploy a EIP20 (parameters are meaningless) and store the bytecode provably.
+      address verifiedToken = createEIP20(10000, "Verify Token", 3, "VTX");
+      EIP20ByteCode = 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 view returns (bool) {
+    function verifyEIP20(address _tokenContract) public view returns (bool) {
       bytes memory fetchedTokenByteCode = codeAt(_tokenContract);
 
-      if (fetchedTokenByteCode.length != humanStandardByteCode.length) {
+      if (fetchedTokenByteCode.length != EIP20ByteCode.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]) {
+        if (fetchedTokenByteCode[i] != EIP20ByteCode[i]) {
           return false;
         }
       }
@@ -51,11 +51,11 @@ contract HumanStandardTokenFactory {
       }
     }
 
-    function createHumanStandardToken(uint256 _initialAmount, string _name, uint8 _decimals, string _symbol) public returns (address) {
+    function createEIP20(uint256 _initialAmount, string _name, uint8 _decimals, string _symbol) public returns (address) {
 
-        HumanStandardToken newToken = (new HumanStandardToken(_initialAmount, _name, _decimals, _symbol));
+        EIP20 newToken = (new EIP20(_initialAmount, _name, _decimals, _symbol));
         created[msg.sender].push(address(newToken));
-        isHumanToken[address(newToken)] = true;
+        isEIP20[address(newToken)] = true;
         newToken.transfer(msg.sender, _initialAmount); //the factory will own the created tokens. You must transfer them.
         return address(newToken);
     }

+ 1 - 1
contracts/Token.sol

@@ -2,7 +2,7 @@
 // https://github.com/ethereum/EIPs/issues/20
 pragma solidity ^0.4.8;
 
-contract Token {
+contract EIP20Interface {
     /* This is a slight change to the ERC20 base standard.
     function totalSupply() constant returns (uint256 supply);
     is replaced with:

+ 2 - 2
migrations/2_deploy_tokens.js

@@ -1,5 +1,5 @@
-const HumanStandardToken = artifacts.require(`./HumanStandardToken.sol`)
+const EIP20 = artifacts.require(`./EIP20.sol`)
 
 module.exports = (deployer) => {
-  deployer.deploy(HumanStandardToken)
+  deployer.deploy(EIP20)
 }

+ 3 - 3
migrations/3_deploy_factory.js

@@ -1,6 +1,6 @@
-const HumanStandardTokenFactory =
-  artifacts.require(`./HumanStandardTokenFactory.sol`)
+const EIP20Factory =
+  artifacts.require(`./EIP20Factory.sol`)
 
 module.exports = (deployer) => {
-  deployer.deploy(HumanStandardTokenFactory)
+  deployer.deploy(EIP20Factory)
 }

+ 5 - 5
test/humanStandardToken.js

@@ -1,10 +1,10 @@
-const expectThrow = require('./utils').expectThrow
-const HumanStandardTokenAbstraction = artifacts.require('HumanStandardToken')
+const expectThrow = require('../utils').expectThrow
+const EIP20Abstraction = artifacts.require('EIP20')
 let HST
 
-contract('HumanStandardToken', function (accounts) {
+contract('EIP20', function (accounts) {
   beforeEach(async () => {
-    HST = await HumanStandardTokenAbstraction.new(10000, 'Simon Bucks', 1, 'SBX', {from: accounts[0]})
+    HST = await EIP20Abstraction.new(10000, 'Simon Bucks', 1, 'SBX', {from: accounts[0]})
   })
 
   it('creation: should create an initial balance of 10000 for the creator', async () => {
@@ -25,7 +25,7 @@ contract('HumanStandardToken', function (accounts) {
 
   it('creation: should succeed in creating over 2^256 - 1 (max) tokens', async () => {
     // 2^256 - 1
-    let HST2 = await HumanStandardTokenAbstraction.new('115792089237316195423570985008687907853269984665640564039457584007913129639935', 'Simon Bucks', 1, 'SBX', {from: accounts[0]})
+    let HST2 = await EIP20Abstraction.new('115792089237316195423570985008687907853269984665640564039457584007913129639935', 'Simon Bucks', 1, 'SBX', {from: accounts[0]})
     const totalSupply = await HST2.totalSupply()
     const match = totalSupply.equals('1.15792089237316195423570985008687907853269984665640564039457584007913129639935e+77')
     assert(match, 'result is not correct')

+ 11 - 0
test/eip20/eip20Factory.js

@@ -0,0 +1,11 @@
+const EIP20Factory = artifacts.require('EIP20Factory')
+
+contract('EIP20Factory', function (accounts) {
+  it('Verify a Human Standard Token once deployed using both verification functions.', async () => {
+    const factory = await EIP20Factory.new()
+    const newTokenAddr = await factory.createEIP20.call(100000, 'Simon Bucks', 2, 'SBX', {from: accounts[0]})
+    await factory.createEIP20(100000, 'Simon Bucks', 2, 'SBX', {from: accounts[0]})
+    const res = await factory.verifyEIP20.call(newTokenAddr, {from: accounts[0]})
+    assert(res, 'Could not verify the token.')
+  })
+})

+ 0 - 11
test/humanStandardTokenFactory.js

@@ -1,11 +0,0 @@
-const HumanStandardTokenFactory = artifacts.require('HumanStandardTokenFactory')
-
-contract('HumanStandardTokenFactory', function (accounts) {
-  it('Verify a Human Standard Token once deployed using both verification functions.', async () => {
-    const factory = await HumanStandardTokenFactory.new()
-    const newTokenAddr = await factory.createHumanStandardToken.call(100000, 'Simon Bucks', 2, 'SBX', {from: accounts[0]})
-    await factory.createHumanStandardToken(100000, 'Simon Bucks', 2, 'SBX', {from: accounts[0]})
-    const res = await factory.verifyHumanStandardToken.call(newTokenAddr, {from: accounts[0]})
-    assert(res, 'Could not verify the token.')
-  })
-})