Skip to content
Verified contractPartial

Exchange

Address0x98ce5d5c74e3689c9745e1bdc0db5087dcbbb342
Balance

0 ETH

 

Transactions

5

 

Compiler

solc 0.4.24

 

Same code

Only this contract

 

Details

Compiler
solc 0.4.24+commit.e67f0147
Language
solidity
Optimization
Yes, 200 runs
License
Not stated
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
6,222,335
Creation transaction
0x14f7e96cd4…192574487b

Exchange.sol

pragma solidity ^0.4.24;

/**
 * @title ERC20Basic
 * @dev Simpler version of ERC20 interface
 * @dev see https://github.com/ethereum/EIPs/issues/179
 */
contract ERC20Basic {
  uint256 public totalSupply;
  uint8 public decimals;
  function balanceOf(address who) public constant returns (uint256);
  function transfer(address to, uint256 value) public returns (bool);
  function transferFrom(address _from, address _to, uint _value) returns (bool success);
  event Transfer(address indexed from, address indexed to, uint256 value);
  
}


/**
 * @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() {
    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) onlyOwner public {
    require(newOwner != address(0));
    OwnershipTransferred(owner, newOwner);
    owner = newOwner;
  }

}

contract Exchange is Ownable {
  mapping (address => bool) public supportedTokens;
  event ExchangeEvent(address tokenToSell, address tokenToBuy, uint256 value);
  
  function setSupportedTokens(address tokenAddress, bool op) onlyOwner public {
    supportedTokens[tokenAddress] = op;
  }
  
    /**
   *  exchange ERC20 tokens with 1:1.
   */
  function exchangeERC20(address _tokenToSell, address _tokenToBuy, uint256 _value) {
    require(supportedTokens[_tokenToSell]);
    require(supportedTokens[_tokenToBuy]);
    require(_tokenToSell != _tokenToBuy);
    
    ERC20Basic tokenToSell = ERC20Basic(_tokenToSell);
    ERC20Basic tokenToBuy = ERC20Basic(_tokenToBuy);

    require(_value > 0 && tokenToBuy.balanceOf(address(this)) >= _value);

    if (!tokenToSell.transferFrom(msg.sender, address(this), _value)) throw;
    tokenToBuy.transfer(msg.sender, _value);
  
    ExchangeEvent(_tokenToSell,_tokenToBuy,_value);
  }
}
Compiler settingsShow
{
  "optimizer": {
    "runs": 200,
    "enabled": true
  }
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.