Skip to content

DICE ‐ Etheroll

BokkyPooBah edited this page Jun 15, 2017 · 3 revisions

Table of contents



Token Contract Information



Market Making Information

Creating Your Trade Contract

If you want to list an DICE TokenTrader contract on https://cryptoderivatives.market, use the TokenTraderFactory contract.

Execute createTradeContract(address asset, uint256 buyPrice, uint256 sellPrice, uint256 units, bool buysTokens, bool sellsTokens) to create your DICE TokenTrader contract.

The formula for working out the buyPrice or sellPrice follows:

rate = price / units * 10^(tokenDecimals - etherDecimals)

which is:

rate = price / units * 10^(tokenDecimals - 18)

and tokenDecimals = 16, so:

rate = price / units * 10^-2

Watching Your Trade Contract

Find your newly created Trade contract on https://cryptoderivatives.market/tokenTraderContracts. Watch this contract address using the ABI at How To Watch A TokenTrader Contract In Ethereum Wallet / Mist.

Depositing Tokens

Use the DICE token contract to transfer your tokens to your newly created TokenTrader address.

Depositing Ethers

Execute your TokenTrader.makerDepositEther() function, sending the amount of ethers.



How To Watch The Token Contract In Ethereum Wallet / Mist

In Ethereum Wallet / Mist, select the CONTRACTS tab and click WATCH CONTRACT to open the Watch contract window. Then:

  • Under CONTRACT NAME, enter DICE

  • Under CONTRACT ADDRESS, enter 0x2e071d2966aa7d8decb1005885ba1977d6038a65

  • Copy the Application Binary Interface below and paste it into the JSON INTERFACE text box

    [{"constant":false,"inputs":[{"name":"_newPriviledgedAddress","type":"address"}],"name":"ownerSetPriviledgedAddress","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"updateTokenStatus","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"tokensFrozen","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"nextThaw","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"standard","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"priviledgedAddressBurnUnsoldCoins","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"crowdfundDeadline","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"nextFreeze","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"priviledgedAddress","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"ownerTransferOwnership","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[],"payable":false,"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_from","type":"address"},{"indexed":true,"name":"_to","type":"address"},{"indexed":false,"name":"_value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_owner","type":"address"},{"indexed":true,"name":"_spender","type":"address"},{"indexed":false,"name":"_value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"Frozen","type":"bool"}],"name":"LogTokensFrozen","type":"event"}]

  • Click OK



How To Watch The Token In Ethereum Wallet / Mist

In Ethereum Wallet / Mist, select the CONTRACTS tab and click WATCH TOKEN to open the Add token window. Then:

  • Under TOKEN CONTRACT ADDRESS, enter 0x2e071d2966aa7d8decb1005885ba1977d6038a65. The additional fields should automatically be filled in.

  • Click OK



How To Check Your Token Balance In Ethereum Wallet / Mist

Watch The Token Contract, then:

  • Click on the DICE contract
  • Click on SHOW CONTRACT INFO
  • In the READ FROM CONTRACT section and under Balance of:
  • Enter the address you want to check the token balance of
  • The token balance will be displayed in the Natural Units with 16 decimal places, e.g., 12300000000000000 is 12300000000000000 / 1e16 = 1.23 token units



How To Transfer Your Tokens In Ethereum Wallet / Mist

Watch The Token Contract, then:

  • Click on the DICE contract
  • Click on SHOW CONTRACT INFO
  • In the WRITE TO CONTRACT section and under Select function:
  • Select the Transfer function
  • Under to, enter the address you want to transfer the token to
  • Under value, enter the amount of tokens you want to transfer. This amount needs to be specified in the natural units with 16 decimal places, e.g., 12300000000000000 is 12300000000000000 / 1e16 = 1.23 token units
  • Under Execute from, select the account you want to transfer your tokens from
  • Click on Execute, then confirm your transaction



The Token Contract Source Code

The verified source code can be found at 0x2e071d2966aa7d8decb1005885ba1977d6038a65 and follows:

pragma solidity ^0.4.2;

/* 
`* is owned
*/
contract owned {

    address public owner;

    function owned() {
        owner = msg.sender;
    }

    modifier onlyOwner {
        if (msg.sender != owner) throw;
        _;
    }

    function ownerTransferOwnership(address newOwner)
        onlyOwner
    {
        owner = newOwner;
    }

}

/* 
* safe math
*/
contract DSSafeAddSub {

    function safeToAdd(uint a, uint b) internal returns (bool) {
        return (a + b >= a);
    }
    
    function safeAdd(uint a, uint b) internal returns (uint) {
        if (!safeToAdd(a, b)) throw;
        return a + b;
    }

    function safeToSubtract(uint a, uint b) internal returns (bool) {
        return (b <= a);
    }

    function safeSub(uint a, uint b) internal returns (uint) {
        if (!safeToSubtract(a, b)) throw;
        return a - b;
    } 

}


/**
 *
 * @title  EtherollToken
 * 
 * The official token powering etheroll.
 * EtherollToken is a ERC.20 standard token with some custom functionality
 *
 */ 


contract EtherollToken is owned, DSSafeAddSub {

    /* check address */
    modifier onlyBy(address _account) {
        if (msg.sender != _account) throw;
        _;
    }    

    /* vars */
    string public standard = 'Token 1.0';
    string public name = "DICE";
    string public symbol = "ROL";
    uint8 public decimals = 16;
    uint public totalSupply = 250000000000000000000000; 

    address public priviledgedAddress;  
    bool public tokensFrozen;
    uint public crowdfundDeadline = now + 2 * 1 weeks;       
    uint public nextFreeze = now + 12 * 1 weeks;
    uint public nextThaw = now + 13 * 1 weeks;
   

    /* map balances */
    mapping (address => uint) public balanceOf;
    mapping (address => mapping (address => uint)) public allowance;  

    /* events */
    event Transfer(address indexed _from, address indexed _to, uint256 _value);
    event Approval(address indexed _owner, address indexed _spender, uint256 _value);
    event LogTokensFrozen(bool indexed Frozen);    

    /*
    *  @notice sends all tokens to msg.sender on init    
    */  
    function EtherollToken(){
        /* send creator all initial tokens 25,000,000 */
        balanceOf[msg.sender] = 250000000000000000000000;
        /* tokens are not frozen */  
        tokensFrozen = false;                                      

    }  

    /*
    *  @notice public function    
    *  @param _to address to send tokens to   
    *  @param _value number of tokens to transfer 
    *  @returns boolean success         
    */     
    function transfer(address _to, uint _value) public
        returns (bool success)    
    {
        if(tokensFrozen && msg.sender != priviledgedAddress) return false;  /* transfer only by priviledgedAddress during crowdfund or reward phases */
        if (balanceOf[msg.sender] < _value) return false;                   /* check if the sender has enough */
        if (balanceOf[_to] + _value < balanceOf[_to]) return false;         /* check for overflows */              
        balanceOf[msg.sender] -=  _value;                                   /* subtract from the sender */
        balanceOf[_to] += _value;                                           /* add the same to the recipient */
        Transfer(msg.sender, _to, _value);                                  /* notify anyone listening that this transfer took place */
        return true;
    }      

    /*
    *  @notice public function    
    *  @param _from address to send tokens from 
    *  @param _to address to send tokens to   
    *  @param _value number of tokens to transfer     
    *  @returns boolean success      
    *  another contract attempts to spend tokens on your behalf
    */       
    function transferFrom(address _from, address _to, uint _value) public
        returns (bool success) 
    {                
        if(tokensFrozen && msg.sender != priviledgedAddress) return false;  /* transfer only by priviledgedAddress during crowdfund or reward phases */
        if (balanceOf[_from] < _value) return false;                        /* check if the sender has enough */
        if (balanceOf[_to] + _value < balanceOf[_to]) return false;         /* check for overflows */                
        if (_value > allowance[_from][msg.sender]) return false;            /* check allowance */
        balanceOf[_from] -= _value;                                         /* subtract from the sender */
        balanceOf[_to] += _value;                                           /* add the same to the recipient */
        allowance[_from][msg.sender] -= _value;                             /* reduce allowance */
        Transfer(_from, _to, _value);                                       /* notify anyone listening that this transfer took place */
        return true;
    }        
 
    /*
    *  @notice public function    
    *  @param _spender address being granted approval to spend on behalf of msg.sender
    *  @param _value number of tokens granted approval for _spender to spend on behalf of msg.sender    
    *  @returns boolean success      
    *  approves another contract to spend some tokens on your behalf
    */      
    function approve(address _spender, uint _value) public
        returns (bool success)
    {
        /* set allowance for _spender on behalf of msg.sender */
        allowance[msg.sender][_spender] = _value;

        /* log event about transaction */
        Approval(msg.sender, _spender, _value);        
        return true;
    } 
  
    /*
    *  @notice address restricted function 
    *  crowdfund contract calls this to burn its unsold coins 
    */     
    function priviledgedAddressBurnUnsoldCoins() public
        /* only crowdfund contract can call this */
        onlyBy(priviledgedAddress)
    {
        /* totalSupply should equal total tokens in circulation */
        totalSupply = safeSub(totalSupply, balanceOf[priviledgedAddress]); 
        /* burns unsold tokens from crowdfund address */
        balanceOf[priviledgedAddress] = 0;
    }

    /*
    *  @notice public function 
    *  locks/unlocks tokens on a recurring cycle
    */         
    function updateTokenStatus() public
    {
        
        /* locks tokens during initial crowdfund period */
        if(now < crowdfundDeadline){                       
            tokensFrozen = true;         
            LogTokensFrozen(tokensFrozen);  
        }  

        /* locks tokens */
        if(now >= nextFreeze){          
            tokensFrozen = true;
            LogTokensFrozen(tokensFrozen);  
        }

        /* unlocks tokens */
        if(now >= nextThaw){         
            tokensFrozen = false;
            nextFreeze = now + 12 * 1 weeks;
            nextThaw = now + 13 * 1 weeks;              
            LogTokensFrozen(tokensFrozen);  
        }        
      
    }                              

    /*
    *  @notice owner restricted function
    *  @param _newPriviledgedAddress the address
    *  only this address can burn unsold tokens
    *  transfer tokens only by priviledgedAddress during crowdfund or reward phases
    */      
    function ownerSetPriviledgedAddress(address _newPriviledgedAddress) public 
        onlyOwner
    {
        priviledgedAddress = _newPriviledgedAddress;
    }   
                    
    
}
Clone this wiki locally