SafeERC20.sol 852 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. pragma solidity ^0.4.24;
  2. import "./ERC20.sol";
  3. import "./IERC20.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(
  12. IERC20 _token,
  13. address _to,
  14. uint256 _value
  15. )
  16. internal
  17. {
  18. require(_token.transfer(_to, _value));
  19. }
  20. function safeTransferFrom(
  21. IERC20 _token,
  22. address _from,
  23. address _to,
  24. uint256 _value
  25. )
  26. internal
  27. {
  28. require(_token.transferFrom(_from, _to, _value));
  29. }
  30. function safeApprove(
  31. IERC20 _token,
  32. address _spender,
  33. uint256 _value
  34. )
  35. internal
  36. {
  37. require(_token.approve(_spender, _value));
  38. }
  39. }