SafeERC20.sol 831 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. }