/** * @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 Returns the name of the token * @param tokenContractAddress The address of the token contract * @return The name of the token as a string */ function getName(address tokenContractAddress) public view returns (string) { ERC20Token token = ERC20Token(tokenContractAddress); return token.name(); } /** * @notice Returns the symbol of the token * @param tokenContractAddress The address of the token contract * @return The symbol of the token as a string */ function getSymbol(address tokenContractAddress) public view returns (string) { ERC20Token token = ERC20Token(tokenContractAddress); return token.symbol(); } /** * @notice Returns the decimals of the token * @param tokenContractAddress The address of the token contract * @return The decimals of the token as an int */ function getDecimals(address tokenContractAddress) public view returns (uint) { ERC20Token token = ERC20Token(tokenContractAddress); return token.decimals(); } /** * @notice Returns the total supply of the token * @param tokenContractAddress The address of the token contract * @return The total supply of the token as an int */ function getTotalSupply(address tokenContractAddress) public view returns (uint) { ERC20Token token = ERC20Token(tokenContractAddress); return token.totalSupply(); } /** * @notice Returns the balance of an account * @param tokenContractAddress The address of the token contract * @param account The address of the account to check * @return The balance of an account as an int */ function getBalance(address tokenContractAddress, address account) public view returns (uint) { ERC20Token token = ERC20Token(tokenContractAddress); return token.balanceOf(account); } /** * @notice Transfers tokens to another address * @dev Beware: This function can only transfer tokens from this contract * @param tokenContractAddress The address of the token contract * @param to The address of the account who will receive the tokens * @param amount The amount of tokens to transfer * @return True if the transfer is successful */ function transferTo(address tokenContractAddress, address to, uint amount) public returns (bool) { ERC20Token token = ERC20Token(tokenContractAddress); return token.transfer(to, amount); } /** * @notice Transfers tokens from an address to another address * @dev Beware: The contract has to be approved first to transfer the tokens * @param tokenContractAddress The address of the token contract * @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 tokenContractAddress, address from, address to, uint amount) public returns (bool) { ERC20Token token = ERC20Token(tokenContractAddress); 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 owner account * @param tokenContractAddress The address of the token contract * @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 tokenContractAddress, address spender, uint amount) public returns (bool) { ERC20Token token = ERC20Token(tokenContractAddress); 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 tokenContractAddress The address of the token contract * @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 tokenContractAddress, address owner, address spender) public view returns (uint) { ERC20Token token = ERC20Token(tokenContractAddress); return token.allowance(owner, spender); } }
0.4.24