SafeERC20.sol 791 B

1234567891011121314151617181920212223242526272829303132
  1. pragma solidity ^0.4.18;
  2. import "./ERC20Basic.sol";
  3. import "./ERC20.sol";
  4. /**
  5. * @title SafeERC20
  6. * @dev Wrappers around ERC20 operations that throw on failure.
  7. * To use this library you can add a `using SafeERC20 for ERC20;` statement to your contract,
  8. * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
  9. */
  10. library SafeERC20 {
  11. function safeTransfer(ERC20Basic token, address to, uint256 value) internal {
  12. assert(token.transfer(to, value));
  13. }
  14. function safeTransferFrom(
  15. ERC20 token,
  16. address from,
  17. address to,
  18. uint256 value
  19. )
  20. internal
  21. {
  22. assert(token.transferFrom(from, to, value));
  23. }
  24. function safeApprove(ERC20 token, address spender, uint256 value) internal {
  25. assert(token.approve(spender, value));
  26. }
  27. }