Transaction Hash:
Block:
5980053 at Jul-17-2018 10:26:56 AM +UTC
Transaction Fee:
0.000045768 ETH
$0.12
Gas Used:
22,884 Gas / 2 Gwei
Emitted Events:
85 |
TokenERC20.Transfer( from=[Sender] 0x4eba4f0d7213a39cb518fab1b62fc490fe0ccf47, to=ETHERCExchange, value=100000000000000000000 )
|
Account State Difference:
Address | Before | After | State Difference | ||
---|---|---|---|---|---|
0x4Eba4F0d...0fE0Ccf47 |
0.000725791 Eth
Nonce: 2
|
0.000680023 Eth
Nonce: 3
| 0.000045768 | ||
0x5A0b54D5...D3E029c4c
Miner
| (Spark Pool) | 3,471.079106873572336635 Eth | 3,471.079152641572336635 Eth | 0.000045768 | |
0xa68920f6...d76150735 |
Execution Trace
TokenERC20.transfer( _to=0xd8d48e52F39Ab2D169c8b562C53589e6C71ac4d3, _value=100000000000000000000 )
transfer[TokenERC20 (ln:43)]
_transfer[TokenERC20 (ln:43)]
Transfer[TokenERC20 (ln:39)]
File 1 of 2: TokenERC20
File 2 of 2: ETHERCExchange
pragma solidity ^0.4.16; interface tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) public; } contract TokenERC20 { // Public variables of the token string public name; string public symbol; uint8 public decimals = 18; // 18 decimals is the strongly suggested default, avoid changing it uint256 public totalSupply; // This creates an array with all balances mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; // This generates a public event on the blockchain that will notify clients event Transfer(address indexed from, address indexed to, uint256 value); // This notifies clients about the amount burnt event Burn(address indexed from, uint256 value); /** * Constrctor function * * Initializes contract with initial supply tokens to the creator of the contract */ function TokenERC20( uint256 initialSupply, string tokenName, string tokenSymbol ) public { totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens name = tokenName; // Set the name for display purposes symbol = tokenSymbol; // Set the symbol for display purposes } /** * Internal transfer, only can be called by this contract */ function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != 0x0); // Check if the sender has enough require(balanceOf[_from] >= _value); // Check for overflows require(balanceOf[_to] + _value > balanceOf[_to]); // Save this for an assertion in the future uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; Transfer(_from, _to, _value); // Asserts are used to use static analysis to find bugs in your code. They should never fail assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } /** * Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */ function transfer(address _to, uint256 _value) public { _transfer(msg.sender, _to, _value); } /** * Transfer tokens from other address * * Send `_value` tokens to `_to` on behalf of `_from` * * @param _from The address of the sender * @param _to The address of the recipient * @param _value the amount to send */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { require(_value <= allowance[_from][msg.sender]); // Check allowance allowance[_from][msg.sender] -= _value; _transfer(_from, _to, _value); return true; } /** * Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens on your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */ function approve(address _spender, uint256 _value) public returns (bool success) { allowance[msg.sender][_spender] = _value; return true; } /** * Set allowance for other address and notify * * Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it * * @param _spender The address authorized to spend * @param _value the max amount they can spend * @param _extraData some extra information to send to the approved contract */ function approveAndCall(address _spender, uint256 _value, bytes _extraData) public returns (bool success) { tokenRecipient spender = tokenRecipient(_spender); if (approve(_spender, _value)) { spender.receiveApproval(msg.sender, _value, this, _extraData); return true; } } /** * Destroy tokens * * Remove `_value` tokens from the system irreversibly * * @param _value the amount of money to burn */ function burn(uint256 _value) public returns (bool success) { require(balanceOf[msg.sender] >= _value); // Check if the sender has enough balanceOf[msg.sender] -= _value; // Subtract from the sender totalSupply -= _value; // Updates totalSupply Burn(msg.sender, _value); return true; } /** * Destroy tokens from other account * * Remove `_value` tokens from the system irreversibly on behalf of `_from`. * * @param _from the address of the sender * @param _value the amount of money to burn */ function burnFrom(address _from, uint256 _value) public returns (bool success) { require(balanceOf[_from] >= _value); // Check if the targeted balance is enough require(_value <= allowance[_from][msg.sender]); // Check allowance balanceOf[_from] -= _value; // Subtract from the targeted balance allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance totalSupply -= _value; // Update totalSupply Burn(_from, _value); return true; } }
File 2 of 2: ETHERCExchange
pragma solidity ^0.4.19; /** * @title SafeMath * @dev Math operations with safety checks that throw on error */ library SafeMath { /** * @dev Multiplies two numbers, throws on overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0; } uint256 c = a * b; assert(c / a == b); return c; } /** * @dev Integer division of two numbers, truncating the quotient. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { // assert(b > 0); // Solidity automatically throws when dividing by 0 uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } /** * @dev Adds two numbers, throws on overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; assert(c >= a); return c; } } /** * @title Ownable * @dev The Ownable contract has an owner address, and provides basic authorization control * functions, this simplifies the implementation of "user permissions". */ contract Ownable { address public owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ function Ownable() public { owner = msg.sender; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(msg.sender == owner); _; } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferOwnership(address newOwner) public onlyOwner { require(newOwner != address(0)); OwnershipTransferred(owner, newOwner); owner = newOwner; } } /** * ERC-20 Token Standard * https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md */ contract Token { function totalSupply() public view returns (uint256); function balanceOf(address _owner) public view returns (uint256); function transfer(address _to, uint256 _value) public returns (bool); function transferFrom(address _from, address _to, uint256 _value) public returns (bool); function approve(address _spender, uint256 _value) public returns (bool); function allowance(address _owner, address _spender) public view returns (uint256); event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); } /** * Interface for trading discounts and rebates for specific accounts */ contract FeeModifiersInterface { function accountFeeModifiers(address _user) public view returns (uint256 feeDiscount, uint256 feeRebate); function tradingFeeModifiers(address _maker, address _taker) public view returns (uint256 feeMakeDiscount, uint256 feeTakeDiscount, uint256 feeRebate); } /** * Interface for trade tracker to handle trade event */ contract TradeTrackerInterface { function tradeEventHandler(address _tokenGet, uint256 _amountGet, address _tokenGive, uint256 _amountGive, address _maker, address _user, bytes32 _orderHash, uint256 _gasLimit) public; } contract ETHERCExchange is Ownable { using SafeMath for uint256; // the trade tracker address address public tradeTracker; // the contract which stores fee discounts/rebates address public feeModifiers; // the account that will receive fees address public feeAccount; // maker fee percentage times (1 ether) uint256 public feeMake; // taker fee percentage times (1 ether) uint256 public feeTake; // mapping of token addresses to mapping of account balances mapping (address => mapping (address => uint256)) public tokens; // mapping of order hash to status cancelled mapping (bytes32 => bool) public cancelledOrders; // mapping order hashes to uints (amount of order that has been filled) mapping (bytes32 => uint256) public orderFills; //Logging events event Deposit(address token, address user, uint256 amount, uint256 balance); event Withdraw(address token, address user, uint256 amount, uint256 balance); event Cancel(address tokenGet, uint256 amountGet, address tokenGive, uint256 amountGive, uint256 expires, uint256 nonce, address maker, uint8 v, bytes32 r, bytes32 s, bytes32 orderHash, uint256 amountFilled); event Trade(address tokenGet, uint256 amountGet, address tokenGive, uint256 amountGive, address maker, address taker, bytes32 orderHash); function ETHERCExchange() public { feeAccount = owner; } function() public { revert(); } //////////////////////////////////////////////////////////////////////////////// // Fee Discounts, Rebates //////////////////////////////////////////////////////////////////////////////// function getAccountFeeModifiers(address _user) public view returns(uint256 feeDiscount, uint256 feeRebate) { if (feeModifiers != address(0)) { (feeDiscount, feeRebate) = FeeModifiersInterface(feeModifiers).accountFeeModifiers(_user); } } //////////////////////////////////////////////////////////////////////////////// // Funds //////////////////////////////////////////////////////////////////////////////// function deposit() public payable { tokens[address(0)][msg.sender] = tokens[address(0)][msg.sender].add(msg.value); Deposit(address(0), msg.sender, msg.value, tokens[address(0)][msg.sender]); } function depositToken(address _token, uint256 _amount) public { require(_token != address(0)); if (!Token(_token).transferFrom(msg.sender, this, _amount)) revert(); tokens[_token][msg.sender] = tokens[_token][msg.sender].add(_amount); Deposit(_token, msg.sender, _amount, tokens[_token][msg.sender]); } function withdraw(uint256 _amount) public { require(tokens[address(0)][msg.sender] >= _amount); tokens[address(0)][msg.sender] = tokens[address(0)][msg.sender].sub(_amount); msg.sender.transfer(_amount); Withdraw(address(0), msg.sender, _amount, tokens[address(0)][msg.sender]); } function withdrawToken(address _token, uint256 _amount) public { require(_token != address(0)); require(tokens[_token][msg.sender] >= _amount); tokens[_token][msg.sender] = tokens[_token][msg.sender].sub(_amount); if (!Token(_token).transfer(msg.sender, _amount)) revert(); Withdraw(_token, msg.sender, _amount, tokens[_token][msg.sender]); } function balanceOf(address _token, address _user) public view returns (uint256) { return tokens[_token][_user]; } //////////////////////////////////////////////////////////////////////////////// // Trading & Order //////////////////////////////////////////////////////////////////////////////// function trade(address _tokenGet, uint256 _amountGet, address _tokenGive, uint256 _amountGive, uint256 _expires, uint256 _nonce, address _maker, uint8 _v, bytes32 _r, bytes32 _s, uint256 _amountTrade) public { uint256 executionGasLimit = msg.gas; bytes32 orderHash = getOrderHash(_tokenGet, _amountGet, _tokenGive, _amountGive, _expires, _nonce, _maker); if (ecrecover(keccak256("\x19Ethereum Signed Message:\n32", orderHash), _v, _r, _s) != _maker || cancelledOrders[orderHash] || block.number > _expires || orderFills[orderHash].add(_amountTrade) > _amountGet ) revert(); tradeBalances(_tokenGet, _amountGet, _tokenGive, _amountGive, _maker, _amountTrade); orderFills[orderHash] = orderFills[orderHash].add(_amountTrade); uint256 amountTradeGive = _amountGive.mul(_amountTrade) / _amountGet; if(tradeTracker != address(0)){ TradeTrackerInterface(tradeTracker).tradeEventHandler(_tokenGet, _amountTrade, _tokenGive, amountTradeGive, _maker, msg.sender, orderHash, executionGasLimit); } Trade(_tokenGet, _amountTrade, _tokenGive, amountTradeGive, _maker, msg.sender, orderHash); } function tradeBalances(address _tokenGet, uint256 _amountGet, address _tokenGive, uint256 _amountGive, address _maker, uint256 _amountTrade) private { uint256 feeMakeValue = _amountTrade.mul(feeMake) / (1 ether); uint256 feeTakeValue = _amountTrade.mul(feeTake) / (1 ether); uint256 feeRebateValue = 0; if (feeModifiers != address(0)) { uint256 feeMakeDiscount; uint256 feeTakeDiscount; uint256 feeRebate; (feeMakeDiscount, feeTakeDiscount, feeRebate) = FeeModifiersInterface(feeModifiers).tradingFeeModifiers(_maker, msg.sender); if (feeMakeValue > 0 && feeMakeDiscount > 0 && feeMakeDiscount <= 100 ) feeMakeValue = feeMakeValue.mul(100 - feeMakeDiscount) / 100; if (feeTakeValue > 0 && feeTakeDiscount > 0 && feeTakeDiscount <= 100 ) feeTakeValue = feeTakeValue.mul(100 - feeTakeDiscount) / 100; if (feeTakeValue > 0 && feeRebate > 0 && feeRebate <= 100) feeRebateValue = feeTakeValue.mul(feeRebate) / 100; } tokens[_tokenGet][msg.sender] = tokens[_tokenGet][msg.sender].sub(_amountTrade.add(feeTakeValue)); tokens[_tokenGet][_maker] = tokens[_tokenGet][_maker].add(_amountTrade.sub(feeMakeValue).add(feeRebateValue)); tokens[_tokenGive][msg.sender] = tokens[_tokenGive][msg.sender].add(_amountGive.mul(_amountTrade) / _amountGet); tokens[_tokenGive][_maker] = tokens[_tokenGive][_maker].sub(_amountGive.mul(_amountTrade) / _amountGet); tokens[_tokenGet][feeAccount] = tokens[_tokenGet][feeAccount].add(feeMakeValue.add(feeTakeValue).sub(feeRebateValue)); } function validateTrade(address _tokenGet, uint256 _amountGet, address _tokenGive, uint256 _amountGive, uint256 _expires, uint256 _nonce, address _maker, uint8 _v, bytes32 _r, bytes32 _s, uint256 _amountTrade, address _taker) public view returns (uint8) { uint256 feeTakeValue = calculateTakerFee(_taker, _amountTrade); if (_amountTrade.add(feeTakeValue) > tokens[_tokenGet][_taker]) return 1; if (availableVolume(_tokenGet, _amountGet, _tokenGive, _amountGive, _expires, _nonce, _maker, _v, _r, _s) < _amountTrade) return 2; return 0; } function calculateTakerFee(address _taker, uint256 _amountTrade) public view returns (uint256) { uint256 feeTakeValue = _amountTrade.mul(feeTake) / (1 ether); uint256 feeDiscount; uint256 feeRebate; (feeDiscount, feeRebate) = getAccountFeeModifiers(_taker); if (feeTakeValue > 0 && feeDiscount > 0 && feeDiscount <= 100 ) feeTakeValue = feeTakeValue.mul(100 - feeDiscount) / 100; return feeTakeValue; } function getOrderHash(address _tokenGet, uint256 _amountGet, address _tokenGive, uint256 _amountGive, uint256 _expires, uint256 _nonce, address _maker) public view returns (bytes32) { return keccak256(this, _tokenGet, _amountGet, _tokenGive, _amountGive, _expires, _nonce, _maker); } function availableVolume(address _tokenGet, uint256 _amountGet, address _tokenGive, uint256 _amountGive, uint256 _expires, uint256 _nonce, address _maker, uint8 _v, bytes32 _r, bytes32 _s) public view returns (uint256) { bytes32 orderHash = getOrderHash(_tokenGet, _amountGet, _tokenGive, _amountGive, _expires, _nonce, _maker); if (ecrecover(keccak256("\x19Ethereum Signed Message:\n32", orderHash), _v, _r, _s) != _maker || cancelledOrders[orderHash] || block.number > _expires || _amountGet <= orderFills[orderHash] ) return 0; uint256[2] memory available; available[0] = _amountGet.sub(orderFills[orderHash]); available[1] = tokens[_tokenGive][_maker].mul(_amountGet) / _amountGive; if (available[0] < available[1]) return available[0]; return available[1]; } function amountFilled(address _tokenGet, uint256 _amountGet, address _tokenGive, uint256 _amountGive, uint256 _expires, uint256 _nonce, address _maker) public view returns (uint256) { bytes32 orderHash = getOrderHash(_tokenGet, _amountGet, _tokenGive, _amountGive, _expires, _nonce, _maker); return orderFills[orderHash]; } function cancelOrder(address _tokenGet, uint256 _amountGet, address _tokenGive, uint256 _amountGive, uint256 _expires, uint256 _nonce, uint8 _v, bytes32 _r, bytes32 _s) public { bytes32 orderHash = getOrderHash(_tokenGet, _amountGet, _tokenGive, _amountGive, _expires, _nonce, msg.sender); if (ecrecover(keccak256("\x19Ethereum Signed Message:\n32", orderHash), _v, _r, _s) != msg.sender) revert(); cancelledOrders[orderHash] = true; Cancel(_tokenGet, _amountGet, _tokenGive, _amountGive, _expires, _nonce, msg.sender, _v, _r, _s, orderHash, orderFills[orderHash]); } //////////////////////////////////////////////////////////////////////////////// // Setting //////////////////////////////////////////////////////////////////////////////// function changeFeeAccount(address _feeAccount) public onlyOwner { require(_feeAccount != address(0)); feeAccount = _feeAccount; } function changeFeeMake(uint256 _feeMake) public onlyOwner { require(_feeMake != feeMake); feeMake = _feeMake; } function changeFeeTake(uint256 _feeTake) public onlyOwner { require(_feeTake != feeTake); feeTake = _feeTake; } function changeFeeModifiers(address _feeModifiers) public onlyOwner { require(feeModifiers != _feeModifiers); feeModifiers = _feeModifiers; } function changeTradeTracker(address _tradeTracker) public onlyOwner { require(tradeTracker != _tradeTracker); tradeTracker = _tradeTracker; } }