Advertisement
AleYalunin

token

Nov 19th, 2017
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. pragma solidity ^0.4.16;
  2.  
  3. /**
  4.  * @title SafeMath
  5.  * @dev Math operations with safety checks that throw on error
  6.  */
  7. library SafeMath {
  8.   function mul(uint256 a, uint256 b) internal constant returns (uint256) {
  9.     uint256 c = a * b;
  10.     assert(a == 0 || c / a == b);
  11.     return c;
  12.   }
  13.  
  14.   function div(uint256 a, uint256 b) internal constant returns (uint256) {
  15.     // assert(b > 0); // Solidity automatically throws when dividing by 0
  16.     uint256 c = a / b;
  17.     // assert(a == b * c + a % b); // There is no case in which this doesn't hold
  18.     return c;
  19.   }
  20.  
  21.   function sub(uint256 a, uint256 b) internal constant returns (uint256) {
  22.     assert(b <= a);
  23.     return a - b;
  24.   }
  25.  
  26.   function add(uint256 a, uint256 b) internal constant returns (uint256) {
  27.     uint256 c = a + b;
  28.     assert(c >= a);
  29.     return c;
  30.   }
  31. }
  32.  
  33. /**
  34.  * @title ERC20Basic
  35.  * @dev Simpler version of ERC20 interface
  36.  * @dev see https://github.com/ethereum/EIPs/issues/179
  37.  */
  38. contract ERC20Basic {
  39.   uint256 public totalSupply;
  40.   function balanceOf(address who) public constant returns (uint256);
  41.   function transfer(address to, uint256 value) public returns (bool);
  42.   event Transfer(address indexed from, address indexed to, uint256 value);
  43. }
  44.  
  45. /**
  46.  * @title ERC20 interface
  47.  * @dev see https://github.com/ethereum/EIPs/issues/20
  48.  */
  49. contract ERC20 is ERC20Basic {
  50.   function allowance(address owner, address spender) public constant returns (uint256);
  51.   function transferFrom(address from, address to, uint256 value) public returns (bool);
  52.   function approve(address spender, uint256 value) public returns (bool);
  53.   event Approval(address indexed owner, address indexed spender, uint256 value);
  54. }
  55.  
  56. /**
  57.  * @title Basic token
  58.  * @dev Basic version of StandardToken, with no allowances.
  59.  */
  60. contract BasicToken is ERC20Basic {
  61.   using SafeMath for uint256;
  62.  
  63.   mapping(address => uint256) balances;
  64.  
  65.   /**
  66.   * @dev transfer token for a specified address
  67.   * @param _to The address to transfer to.
  68.   * @param _value The amount to be transferred.
  69.   */
  70.   function transfer(address _to, uint256 _value) public returns (bool) {
  71.     require(_to != address(0));
  72.     require(_value <= balances[msg.sender]);
  73.  
  74.     // SafeMath.sub will throw if there is not enough balance.
  75.     balances[msg.sender] = balances[msg.sender].sub(_value);
  76.     balances[_to] = balances[_to].add(_value);
  77.     Transfer(msg.sender, _to, _value);
  78.     return true;
  79.   }
  80.  
  81.   /**
  82.   * @dev Gets the balance of the specified address.
  83.   * @param _owner The address to query the the balance of.
  84.   * @return An uint256 representing the amount owned by the passed address.
  85.   */
  86.   function balanceOf(address _owner) public constant returns (uint256 balance) {
  87.     return balances[_owner];
  88.   }
  89.  
  90. }
  91.  
  92. /**
  93.  * @title Standard ERC20 token
  94.  *
  95.  * @dev Implementation of the basic standard token.
  96.  * @dev https://github.com/ethereum/EIPs/issues/20
  97.  * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
  98.  */
  99. contract StandardToken is ERC20, BasicToken {
  100.  
  101.   mapping (address => mapping (address => uint256)) internal allowed;
  102.  
  103.  
  104.   /**
  105.    * @dev Transfer tokens from one address to another
  106.    * @param _from address The address which you want to send tokens from
  107.    * @param _to address The address which you want to transfer to
  108.    * @param _value uint256 the amount of tokens to be transferred
  109.    */
  110.   function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
  111.     require(_to != address(0));
  112.     require(_value <= balances[_from]);
  113.     require(_value <= allowed[_from][msg.sender]);
  114.  
  115.     balances[_from] = balances[_from].sub(_value);
  116.     balances[_to] = balances[_to].add(_value);
  117.     allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
  118.     Transfer(_from, _to, _value);
  119.     return true;
  120.   }
  121.  
  122.   /**
  123.    * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
  124.    *
  125.    * Beware that changing an allowance with this method brings the risk that someone may use both the old
  126.    * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
  127.    * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
  128.    * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
  129.    * @param _spender The address which will spend the funds.
  130.    * @param _value The amount of tokens to be spent.
  131.    */
  132.   function approve(address _spender, uint256 _value) public returns (bool) {
  133.     allowed[msg.sender][_spender] = _value;
  134.     Approval(msg.sender, _spender, _value);
  135.     return true;
  136.   }
  137.  
  138.   /**
  139.    * @dev Function to check the amount of tokens that an owner allowed to a spender.
  140.    * @param _owner address The address which owns the funds.
  141.    * @param _spender address The address which will spend the funds.
  142.    * @return A uint256 specifying the amount of tokens still available for the spender.
  143.    */
  144.   function allowance(address _owner, address _spender) public constant returns (uint256 remaining) {
  145.     return allowed[_owner][_spender];
  146.   }
  147.  
  148.   /**
  149.    * approve should be called when allowed[_spender] == 0. To increment
  150.    * allowed value is better to use this function to avoid 2 calls (and wait until
  151.    * the first transaction is mined)
  152.    * From MonolithDAO Token.sol
  153.    */
  154.   function increaseApproval (address _spender, uint _addedValue) public returns (bool success) {
  155.     allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
  156.     Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
  157.     return true;
  158.   }
  159.  
  160.   function decreaseApproval (address _spender, uint _subtractedValue) public returns (bool success) {
  161.     uint oldValue = allowed[msg.sender][_spender];
  162.     if (_subtractedValue > oldValue) {
  163.       allowed[msg.sender][_spender] = 0;
  164.     } else {
  165.       allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
  166.     }
  167.     Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
  168.     return true;
  169.   }
  170.  
  171. }
  172.  
  173.  
  174. /**
  175.  * @title Burnable Token
  176.  * @dev Token that can be irreversibly burned (destroyed).
  177.  */
  178. contract BurnableToken is StandardToken {
  179.  
  180.     event Burn(address indexed burner, uint256 value);
  181.  
  182.     /**
  183.      * @dev Burns a specific amount of tokens.
  184.      * @param _value The amount of token to be burned.
  185.      */
  186.     function burn(uint256 _value) public {
  187.         require(_value > 0);
  188.         require(_value <= balances[msg.sender]);
  189.         // no need to require value <= totalSupply, since that would imply the
  190.         // sender's balance is greater than the totalSupply, which *should* be an assertion failure
  191.  
  192.         address burner = msg.sender;
  193.         balances[burner] = balances[burner].sub(_value);
  194.         totalSupply = totalSupply.sub(_value);
  195.         Burn(burner, _value);
  196.     }
  197. }
  198.  
  199.  
  200.  
  201. /**
  202.  * @title SimpleToken
  203.  * @dev Very simple ERC20 Token example, where all tokens are pre-assigned to the creator.
  204.  * Note they can later distribute these tokens as they wish using `transfer` and other
  205.  * `StandardToken` functions.
  206.  */
  207. contract Paygine is BurnableToken {
  208.   event PaygineHasDeployed(uint time);
  209.  
  210.   string public constant name = "Paygine";
  211.   string public constant symbol = "PGC";
  212.   uint8 public constant decimals = 18;
  213.  
  214.   uint256 public constant INITIAL_SUPPLY = 129650000 * (10 ** uint256(decimals));
  215.  
  216.   /**
  217.    * @dev Constructor that gives msg.sender all of existing tokens.
  218.    */
  219.   function Paygine() {
  220.     totalSupply = INITIAL_SUPPLY;
  221.     balances[msg.sender] = INITIAL_SUPPLY;
  222.     PaygineHasDeployed(now);
  223.   }
  224. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement