Contract Overview
Balance: 0 Ether
Ether Value: $0
Transactions: 9 txns
Misc:
Address Watch: Add To Watch List
Contract Creator: 0xb7d2da6be86fa2ba1af36d09448f029e438fc419at txn 0xec67fe3ee10aa7cfa34a45ad80bbe1254e3ab7023741e094678587df7a334498
 Latest 9 txns

TxHash Age From To Value [TxFee]
0x79b80dcc8b8f504ba5e28a66b1abb30ec114c4a7c1d47a1587ecd7e88bc62f11775 days 12 hrs ago0xaff48892472254c3d67e8d56b807206d01df41fa  IN   0x3398080b81a1cff1429af347ce2b17fc28de39370 Ether0.012573
0xc95a6338e8ef02bfa9442c2f67f06ae514bd721defe9880dcb7bf171c1faad80792 days 11 hrs ago0xb7d2da6be86fa2ba1af36d09448f029e438fc419  IN   0x3398080b81a1cff1429af347ce2b17fc28de39370 Ether0.036969416
0x2a5fe0d2b88bb7b2e8c9b6b674c123421a25201e5db9c9015bff553db3d9a492831 days 13 hrs ago0xb7d2da6be86fa2ba1af36d09448f029e438fc419  IN   0x3398080b81a1cff1429af347ce2b17fc28de39370 Ether0.013884318
0x6d12435f5b6e88e4a96607039d0a9d17f84f9098fbf662314a497b9c5a3e6538832 days 11 hrs ago0xb7d2da6be86fa2ba1af36d09448f029e438fc419  IN   0x3398080b81a1cff1429af347ce2b17fc28de39370 Ether0.013620941602
0x5dd36e769c79489912ddc456f7f7dec851b12a0dbb8ee93bb86b60308a8a0e57832 days 12 hrs ago0xb7d2da6be86fa2ba1af36d09448f029e438fc419  IN   0x3398080b81a1cff1429af347ce2b17fc28de39370 Ether0.013620941602
0xce77d5a0202931712525cb3e3583bc2dc1539b8c732bfbd6d132a2ed6383253a832 days 12 hrs ago0xb7d2da6be86fa2ba1af36d09448f029e438fc419  IN   0x3398080b81a1cff1429af347ce2b17fc28de39370 Ether0.01361805406
0xb8cd181fc735690684159369e32a8aefadb28996102644613d101e741897c22c832 days 12 hrs ago0xb7d2da6be86fa2ba1af36d09448f029e438fc419  IN   0x3398080b81a1cff1429af347ce2b17fc28de39370 Ether0.01361805406
0xa83c34120091f36e21269ead18d231a9b7a8b8963c616a6cfcad81b5bda1660d832 days 12 hrs ago0xb7d2da6be86fa2ba1af36d09448f029e438fc419  IN   0x3398080b81a1cff1429af347ce2b17fc28de39370 Ether0.01411119209
0xec67fe3ee10aa7cfa34a45ad80bbe1254e3ab7023741e094678587df7a334498832 days 12 hrs ago0xb7d2da6be86fa2ba1af36d09448f029e438fc419  IN    Contract Creation0 Ether0.022374051392
[ Download CSV Export  ] 
 Internal Transactions as a result of Contract Execution
 Latest 8 Internal Transactions

ParentTxHash Block Age From To Value
0x79b80dcc8b8f504ba5e28a66b1abb30ec114c4a7c1d47a1587ecd7e88bc62f112737839775 days 12 hrs ago0x3398080b81a1cff1429af347ce2b17fc28de3937  Contract Creation0 Ether
0xc95a6338e8ef02bfa9442c2f67f06ae514bd721defe9880dcb7bf171c1faad802635787792 days 11 hrs ago0x3398080b81a1cff1429af347ce2b17fc28de3937  Contract Creation0 Ether
0x2a5fe0d2b88bb7b2e8c9b6b674c123421a25201e5db9c9015bff553db3d9a4922400087831 days 13 hrs ago0x3398080b81a1cff1429af347ce2b17fc28de3937  Contract Creation0 Ether
0x6d12435f5b6e88e4a96607039d0a9d17f84f9098fbf662314a497b9c5a3e65382394380832 days 11 hrs ago0x3398080b81a1cff1429af347ce2b17fc28de3937  Contract Creation0 Ether
0x5dd36e769c79489912ddc456f7f7dec851b12a0dbb8ee93bb86b60308a8a0e572394355832 days 12 hrs ago0x3398080b81a1cff1429af347ce2b17fc28de3937  Contract Creation0 Ether
0xce77d5a0202931712525cb3e3583bc2dc1539b8c732bfbd6d132a2ed6383253a2394330832 days 12 hrs ago0x3398080b81a1cff1429af347ce2b17fc28de3937  Contract Creation0 Ether
0xb8cd181fc735690684159369e32a8aefadb28996102644613d101e741897c22c2394299832 days 12 hrs ago0x3398080b81a1cff1429af347ce2b17fc28de3937  Contract Creation0 Ether
0xa83c34120091f36e21269ead18d231a9b7a8b8963c616a6cfcad81b5bda1660d2394219832 days 12 hrs ago0x3398080b81a1cff1429af347ce2b17fc28de3937  Contract Creation0 Ether
[ Download CSV Export  ] 
Contract Name: TokenTraderFactory
Compiler Text: v0.4.3-nightly.2016.9.30+commit.d5cfb17b
Optimization Enabled: Yes
Runs (Optimiser):  200



  Contract Source Code   Find Similiar Contracts

pragma solidity ^0.4.0;

//https://github.com/nexusdev/erc20/blob/master/contracts/erc20.sol

contract ERC20Constant {
    function totalSupply() constant returns (uint supply);
    function balanceOf( address who ) constant returns (uint value);
    function allowance(address owner, address spender) constant returns (uint _allowance);
}
contract ERC20Stateful {
    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);
}
contract ERC20Events {
    event Transfer(address indexed from, address indexed to, uint value);
    event Approval( address indexed owner, address indexed spender, uint value);
}
contract ERC20 is ERC20Constant, ERC20Stateful, ERC20Events {}

contract owned {
    address public owner;

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

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

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

// contract can buy or sell tokens for ETH
// prices are in amount of wei per batch of token units

contract TokenTrader is owned {

    address public asset;       // address of token
    uint256 public buyPrice;   // contact buys lots of token at this price
    uint256 public sellPrice;  // contract sells lots at this price
    uint256 public units;       // lot size (token-wei)

    bool public sellsTokens;    // is contract selling
    bool public buysTokens;     // is contract buying

    event ActivatedEvent(bool sells, bool buys);
    event UpdateEvent();

    function TokenTrader (
        address _asset, 
        uint256 _buyPrice, 
        uint256 _sellPrice, 
        uint256 _units,
        bool    _sellsTokens,
        bool    _buysTokens
        )
    {
          asset         = _asset; 
          buyPrice     = _buyPrice; 
          sellPrice    = _sellPrice;
          units         = _units; 
          sellsTokens   = _sellsTokens;
          buysTokens    = _buysTokens;

          ActivatedEvent(sellsTokens,buysTokens);
    }

    // modify trading behavior
    function activate (
        bool    _sellsTokens,
        bool    _buysTokens
        ) onlyOwner
    {
          sellsTokens   = _sellsTokens;
          buysTokens    = _buysTokens;

          ActivatedEvent(sellsTokens,buysTokens);
    }

    // allows owner to deposit ETH
    // deposit tokens by sending them directly to contract
    // buyers must not send tokens to the contract, use: sell(...)
    function deposit() payable onlyOwner {
        UpdateEvent();
    }

    // allow owner to remove trade token
    function withdrawAsset(uint256 _value) onlyOwner returns (bool ok)
    {
        return ERC20(asset).transfer(owner,_value);
        UpdateEvent();
    }

    // allow owner to remove arbitrary tokens
    // included just in case contract receives wrong token
    function withdrawToken(address _token, uint256 _value) onlyOwner returns (bool ok)
    {
        return ERC20(_token).transfer(owner,_value);
        UpdateEvent();
    }

    // allow owner to remove ETH
    function withdraw(uint256 _value) onlyOwner returns (bool ok)
    {
        if(this.balance >= _value) {
            return owner.send(_value);
        }
        UpdateEvent();
    }

    //user buys token with ETH
    function buy() payable {
        if(sellsTokens || msg.sender == owner) 
        {
            uint order   = msg.value / sellPrice; 
            uint can_sell = ERC20(asset).balanceOf(address(this)) / units;

            if(order > can_sell)
            {
                uint256 change = msg.value - (can_sell * sellPrice);
                order = can_sell;
                if(!msg.sender.send(change)) throw;
            }

            if(order > 0) {
                if(!ERC20(asset).transfer(msg.sender,order * units)) throw;
            }
            UpdateEvent();
        }
        else if(!msg.sender.send(msg.value)) throw;  // return user funds if the contract is not selling
    }

    // user sells token for ETH
    // user must set allowance for this contract before calling
    function sell(uint256 amount) {
        if (buysTokens || msg.sender == owner) {
            uint256 can_buy = this.balance / buyPrice;  // token lots contract can buy
            uint256 order = amount / units;             // token lots available

            if(order > can_buy) order = can_buy;        // adjust order for funds

            if (order > 0)
            { 
                // extract user tokens
                if(!ERC20(asset).transferFrom(msg.sender, address(this), amount)) throw;

                // pay user
                if(!msg.sender.send(order * buyPrice)) throw;
            }
            UpdateEvent();
        }
    }

    // sending ETH to contract sells ETH to user
    function () payable {
        buy();
    }
}

// This contract deploys TokenTrader contracts and logs the event
// trade pairs are identified with sha3(asset,units)

contract TokenTraderFactory {

    event TradeListing(bytes32 bookid, address owner, address addr);
    event NewBook(bytes32 bookid, address asset, uint256 units);

    mapping( address => bool ) _verify;
    mapping( bytes32 => bool ) pairExits;
    
    function verify(address tradeContract)  constant returns (
        bool valid,
        address asset, 
        uint256 buyPrice, 
        uint256 sellPrice, 
        uint256 units,
        bool    sellsTokens,
        bool    buysTokens       
        ) {
            
            valid = _verify[tradeContract];
            
            if(valid) {
                TokenTrader t = TokenTrader(tradeContract);
                
                asset = t.asset();
                buyPrice =t.buyPrice();
                sellPrice = t.sellPrice();
                units = t.units();
                sellsTokens = t.sellsTokens();
                buysTokens = t.buysTokens();
            }
        
    }

    function createTradeContract(       
        address _asset, 
        uint256 _buyPrice, 
        uint256 _sellPrice, 
        uint256 _units,
        bool    _sellsTokens,
        bool    _buysTokens
        ) returns (address) 
    {
        if(_buyPrice > _sellPrice) throw; // must make profit on spread
        if(_units == 0) throw;              // can't sell zero units

        address trader = new TokenTrader (
                     _asset, 
                     _buyPrice, 
                     _sellPrice, 
                     _units,
                     _sellsTokens,
                     _buysTokens);

        var bookid = sha3(_asset,_units);

        _verify[trader] = true; // record that this factory created the trader

        TokenTrader(trader).transferOwnership(msg.sender); // set the owner to whoever called the function

        if(pairExits[bookid] == false) {
            pairExits[bookid] = true;
            NewBook(bookid, _asset, _units);
        }

        TradeListing(bookid,msg.sender,trader);
    }

    function () {
        throw;     // Prevents accidental sending of ether to the factory
    }
}

    Contract ABI  
[{"constant":false,"inputs":[{"name":"_asset","type":"address"},{"name":"_buyPrice","type":"uint256"},{"name":"_sellPrice","type":"uint256"},{"name":"_units","type":"uint256"},{"name":"_sellsTokens","type":"bool"},{"name":"_buysTokens","type":"bool"}],"name":"createTradeContract","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"tradeContract","type":"address"}],"name":"verify","outputs":[{"name":"valid","type":"bool"},{"name":"asset","type":"address"},{"name":"buyPrice","type":"uint256"},{"name":"sellPrice","type":"uint256"},{"name":"units","type":"uint256"},{"name":"sellsTokens","type":"bool"},{"name":"buysTokens","type":"bool"}],"payable":false,"type":"function"},{"payable":false,"type":"fallback"},{"anonymous":false,"inputs":[{"indexed":false,"name":"bookid","type":"bytes32"},{"indexed":false,"name":"owner","type":"address"},{"indexed":false,"name":"addr","type":"address"}],"name":"TradeListing","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"bookid","type":"bytes32"},{"indexed":false,"name":"asset","type":"address"},{"indexed":false,"name":"units","type":"uint256"}],"name":"NewBook","type":"event"}]

  Contract Creation Code Switch To Opcodes View
6060604052610dd8806100126000396000f36060604052361561002a5760e060020a60003504633d6a32bd811461003757806363a9c3d714610064575b34610002576102b0610002565b34610002576102b260043560243560443560643560843560a4356000600060008688111561054557610002565b34610002576102cf600435600160a060020a03811660009081526020819052604081205460ff169080808080808087156102a45788905080600160a060020a03166338d52e0f6000604051602001526040518160e060020a028152600401809050602060405180830381600087803b156100025760325a03f11561000257505050604051805190602001509650865080600160a060020a0316638620410b6000604051602001526040518160e060020a028152600401809050602060405180830381600087803b156100025760325a03f11561000257505050604051805190602001509550855080600160a060020a0316634b7503346000604051602001526040518160e060020a028152600401809050602060405180830381600087803b156100025760325a03f11561000257505050604051805190602001509450845080600160a060020a031663976a84356000604051602001526040518160e060020a028152600401809050602060405180830381600087803b156100025760325a03f11561000257505050604051805190602001509350835080600160a060020a0316634ca50f596000604051602001526040518160e060020a028152600401809050602060405180830381600087803b156100025760325a03f11561000257505050604051805190602001509250825080600160a060020a031663b10993476000604051602001526040518160e060020a028152600401809050602060405180830381600087803b156100025760325a03f115610002575050604051519250505b50919395979092949650565b005b60408051600160a060020a03929092168252519081900360200190f35b604080519715158852600160a060020a039690961660208801528686019490945260608601929092526080850152151560a0840152151560c0830152519081900360e00190f35b888888888888604051610885806105538339018087600160a060020a03168152602001868152602001858152602001848152602001831515815260200182151581526020019650505050505050604051809103906000f0801561000257915088866040518083600160a060020a03166c01000000000000000000000000028152601401828152602001925050506040518091039020905060016000600050600084600160a060020a0316815260200190815260200160002060006101000a81548160ff0219169083021790555081600160a060020a031663f2fde38b336040518260e060020a0281526004018082600160a060020a03168152602001915050600060405180830381600087803b156100025760325a03f11561000257505050600160005060008260001916815260200190815260200160002060009054906101000a900460ff1615156000151514156104ef576001600160005060008360001916815260200190815260200160002060006101000a81548160ff021916908302179055507f242ddf37c1721f450a35afdb783ef36e84d032a300600da464ff17d600cceed7818a88604051808460001916815260200183600160a060020a03168152602001828152602001935050505060405180910390a15b6040805182815233600160a060020a03908116602083015284168183015290517f2d6a3482be690073d89f3c5420f70aca9f53be93321c5f45b5be55907b5f2b5b9181900360600190a150509695505050505050565b85600014156103165761000256606060405260405160c08061088583396101206040818152925160805160a051935160e051610100805160008054600160a060020a0319908116331790915560018054909116871790556002859055600388905560048490556005805460ff1916841761ff001916828402179081905560ff8082161515895292900490911615156101405293969295949193909290917ffa4f96c42c616d6fbda491095977a6af7c76ebd387177b72299180502cbeaa999190a15050505050506107be806100c76000396000f3606060405236156100b95760e060020a60003504632e1a7d4d81146100c457806338d52e0f146100ec5780634b750334146101035780634ca50f59146101115780638620410b146101225780638d92fdf3146101305780638da5cb5b14610158578063976a84351461016f5780639e281a981461017d578063a6f2ae3a146101a8578063a7abc124146102ae578063b1099347146102d8578063d0e30db0146102ee578063e4849b321461030d578063f2fde38b14610419575b6104406104426101ac565b346100025761044460043560008054600160a060020a03908116339091161461057d57610002565b3461000257610458600154600160a060020a031681565b346100025761047560035481565b346100025761044460055460ff1681565b346100025761047560025481565b346100025761044460043560008054600160a060020a0390811633909116146105ee57610002565b3461000257610458600054600160a060020a031681565b346100025761047560045481565b346100025761044460043560243560008054600160a060020a03908116339091161461066357610002565b6104405b6005546000908190819060ff16806101d2575060005433600160a060020a039081169116145b156104875760035434811561000257049250600460005054600160009054906101000a9004600160a060020a0316600160a060020a03166370a08231306000604051602001526040518260e060020a0281526004018082600160a060020a03168152602001915050602060405180830381600087803b156100025760325a03f115610002575050604051519050811561000257049150818311156104b657506040516003549192508291820234039033600160a060020a03169082156108fc029083906000818181858888f1935050505015156104b657610002565b3461000257610440600435602435600054600160a060020a0390811633909116146106d557610002565b3461000257610444600554610100900460ff1681565b610440600054600160a060020a03908116339091161461073d57610002565b34610002576104406004356005546000908190610100900460ff168061034157508054600160a060020a0390811633909116145b156105785760025430600160a060020a03163181156100025704915060046000505483811561000257049050818111156103785750805b600081111561054e57604080516001546000602092830181905283517f23b872dd000000000000000000000000000000000000000000000000000000008152600160a060020a033381166004830152308116602483015260448201899052945192909416936323b872dd93606482810194919391928390030190829087803b156100025760325a03f115610002575050604051511515905061076857610002565b3461000257610440600435600054600160a060020a03908116339091161461079c57610002565b005b565b604080519115158252519081900360200190f35b60408051600160a060020a03929092168252519081900360200190f35b60408051918252519081900360200190f35b60405133600160a060020a0316903480156108fc02916000818181858888f19350505050151561057857610002565b600083111561054e57600160009054906101000a9004600160a060020a0316600160a060020a031663a9059cbb3360046000505486026000604051602001526040518360e060020a0281526004018083600160a060020a0316815260200182815260200192505050602060405180830381600087803b156100025760325a03f115610002575050604051511515905061054e57610002565b6040517f36ff37f436d9a671f4776bd73e3be89800c29518da3abc0618ef2b18c707481f90600090a15b505050565b30600160a060020a0316318290106105bf5760008054604051600160a060020a03919091169184156108fc02918591818181858888f1935050505090506105e9565b6040517f36ff37f436d9a671f4776bd73e3be89800c29518da3abc0618ef2b18c707481f90600090a15b919050565b60008054604080516001546020918201859052825160e060020a63a9059cbb028152600160a060020a03948516600482015260248101889052925193169363a9059cbb936044848101949192918390030190829087803b156100025760325a03f1156100025750506040515191506105e99050565b60008054604080516020908101849052815160e060020a63a9059cbb028152600160a060020a0393841660048201526024810187905291519287169363a9059cbb936044848101949192918390030190829087803b156100025760325a03f11561000257505060405151949350505050565b6005805460ff1916831761ff00191661010083810291909117918290556040805160ff84811615158252929093049091161515602083015280517ffa4f96c42c616d6fbda491095977a6af7c76ebd387177b72299180502cbeaa999281900390910190a15050565b6040517f36ff37f436d9a671f4776bd73e3be89800c29518da3abc0618ef2b18c707481f90600090a1565b60405160025433600160a060020a03169190830280156108fc02916000818181858888f19350505050151561054e57610002565b6000805473ffffffffffffffffffffffffffffffffffffffff1916821790555056

 

View All
Block Age transaction Difficulty GasUsed Reward
View All
Block Age UncleNumber Difficulty GasUsed Reward
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.