SafeERC20Helper.sol 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.0;
  3. import "../utils/Context.sol";
  4. import "../token/ERC20/IERC20.sol";
  5. import "../token/ERC20/utils/SafeERC20.sol";
  6. contract ERC20ReturnFalseMock is Context {
  7. uint256 private _allowance;
  8. // IERC20's functions are not pure, but these mock implementations are: to prevent Solidity from issuing warnings,
  9. // we write to a dummy state variable.
  10. uint256 private _dummy;
  11. function transfer(address, uint256) public returns (bool) {
  12. _dummy = 0;
  13. return false;
  14. }
  15. function transferFrom(
  16. address,
  17. address,
  18. uint256
  19. ) public returns (bool) {
  20. _dummy = 0;
  21. return false;
  22. }
  23. function approve(address, uint256) public returns (bool) {
  24. _dummy = 0;
  25. return false;
  26. }
  27. function allowance(address, address) public view returns (uint256) {
  28. require(_dummy == 0); // Dummy read from a state variable so that the function is view
  29. return 0;
  30. }
  31. }
  32. contract ERC20ReturnTrueMock is Context {
  33. mapping(address => uint256) private _allowances;
  34. // IERC20's functions are not pure, but these mock implementations are: to prevent Solidity from issuing warnings,
  35. // we write to a dummy state variable.
  36. uint256 private _dummy;
  37. function transfer(address, uint256) public returns (bool) {
  38. _dummy = 0;
  39. return true;
  40. }
  41. function transferFrom(
  42. address,
  43. address,
  44. uint256
  45. ) public returns (bool) {
  46. _dummy = 0;
  47. return true;
  48. }
  49. function approve(address, uint256) public returns (bool) {
  50. _dummy = 0;
  51. return true;
  52. }
  53. function setAllowance(uint256 allowance_) public {
  54. _allowances[_msgSender()] = allowance_;
  55. }
  56. function allowance(address owner, address) public view returns (uint256) {
  57. return _allowances[owner];
  58. }
  59. }
  60. contract ERC20NoReturnMock is Context {
  61. mapping(address => uint256) private _allowances;
  62. // IERC20's functions are not pure, but these mock implementations are: to prevent Solidity from issuing warnings,
  63. // we write to a dummy state variable.
  64. uint256 private _dummy;
  65. function transfer(address, uint256) public {
  66. _dummy = 0;
  67. }
  68. function transferFrom(
  69. address,
  70. address,
  71. uint256
  72. ) public {
  73. _dummy = 0;
  74. }
  75. function approve(address, uint256) public {
  76. _dummy = 0;
  77. }
  78. function setAllowance(uint256 allowance_) public {
  79. _allowances[_msgSender()] = allowance_;
  80. }
  81. function allowance(address owner, address) public view returns (uint256) {
  82. return _allowances[owner];
  83. }
  84. }
  85. contract SafeERC20Wrapper is Context {
  86. using SafeERC20 for IERC20;
  87. IERC20 private _token;
  88. constructor(IERC20 token) {
  89. _token = token;
  90. }
  91. function transfer() public {
  92. _token.safeTransfer(address(0), 0);
  93. }
  94. function transferFrom() public {
  95. _token.safeTransferFrom(address(0), address(0), 0);
  96. }
  97. function approve(uint256 amount) public {
  98. _token.safeApprove(address(0), amount);
  99. }
  100. function increaseAllowance(uint256 amount) public {
  101. _token.safeIncreaseAllowance(address(0), amount);
  102. }
  103. function decreaseAllowance(uint256 amount) public {
  104. _token.safeDecreaseAllowance(address(0), amount);
  105. }
  106. function setAllowance(uint256 allowance_) public {
  107. ERC20ReturnTrueMock(address(_token)).setAllowance(allowance_);
  108. }
  109. function allowance() public view returns (uint256) {
  110. return _token.allowance(address(0), address(0));
  111. }
  112. }