/** * @dev We use a fixed version of Solidity */ pragma solidity 0.4.24; /** * @title ERC20Token Interface * @notice This is the interface to interact with ERC20 tokens * @dev As seen here https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md */ contract ERC20Token { function name() public view returns (string); function symbol() public view returns (string); function decimals() public view returns (uint); function totalSupply() public view returns (uint); function balanceOf(address account) public view returns (uint); function transfer(address to, uint amount) public returns (bool); function transferFrom(address from, address to, uint amount) public returns (bool); function approve(address spender, uint amount) public returns (bool); function allowance(address owner, address spender) public view returns (uint); } /** * @title ERC20TokenHandler * @notice This contract handles the interaction with ERC20 tokens */ contract ERC20TokenHandler { /** * @notice We create a new token object */ ERC20Token public token; /** * @notice Loads the contract from a specific address * @dev Modifies our token object * @param contractAddress The address of a specific contract */ function existing(address contractAddress) public { require(contractAddress != address(0)); token = ERC20Token(contractAddress); } /** * @notice Returns the name of the token * @return The name of the token as a string */ function getName() public view returns (string) { return token.name(); } /** * @notice Returns the symbol of the token * @return The symbol of the token as a string */ function getSymbol() public view returns (string) { return token.symbol(); } /** * @notice Returns the decimals of the token * @return The decimals of the token as an int */ function getDecimals() public view returns (uint) { return token.decimals(); } /** * @notice Returns the total supply of the token * @return The total supply of the token as an int */ function getTotalSupply() public view returns (uint) { return token.totalSupply(); } /** * @notice Returns the balance of an account * @param account The address of the account to check * @return The balance of an account as an int */ function getBalance(address account) public view returns (uint) { return token.balanceOf(account); } /** * @notice Transfers tokens to another address * @dev Beware: This function can only transfer tokens from this contract * @param to The address of the account who will receive the tokens * @return True if the transfer is successful */ function transferTo(address to, uint amount) public returns (bool) { return token.transfer(to, amount); } /** * @notice Transfers tokens from an address to another address * @dev Beware: The contract has to be approved to transfer the tokens * @param from The address of the account sending the tokens * @param to The address of the account receiving the tokens * @param amount The amount of tokens to transfer * @return True if the transfer is successful */ function transferFrom(address from, address to, uint amount) public returns (bool) { return token.transferFrom(from, to, amount); } /** * @notice Approves an address to transfer tokens on someone's behalf * @dev Beware: Useless in our case, this function has to be executed from the original account * @param spender The address of the account getting the right to transfer * @param amount The maximum amount that the spender can transfer * @return True if the approval was granted */ function approve(address spender, uint amount) public returns (bool) { return token.approve(spender, amount); } /** * @notice Returns the amount which a spender is still allowed to transfer * @dev Keep in mind that the value may vary * @param owner The address of the owner of the tokens * @param spender The address of the account with the approval * @return The amount that the spender can transfer as an int */ function getAllowance(address owner, address spender) public view returns (uint) { return token.allowance(owner, spender); } } contract TokenExchange is ERC20TokenHandler { /** * @notice Transfers tokens from an account to another * @dev An approval is required * @param tokenContractAddress The address of the token contract * @param tokenAmount The amount of tokens * @param from The address of the account sending the tokens * @param to The address of the account receiving the tokens * @return True if the transfer is successful */ function transferTokens(address tokenContractAddress, uint tokenAmount, address from, address to) public returns (bool) { existing(tokenContractAddress); return transferFrom(from, to, tokenAmount); } }
0.4.24