SafeERC20Helper.sol 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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(address, address, uint256) public returns (bool) {
  16. _dummy = 0;
  17. return false;
  18. }
  19. function approve(address, uint256) public returns (bool) {
  20. _dummy = 0;
  21. return false;
  22. }
  23. function allowance(address, address) public view returns (uint256) {
  24. require(_dummy == 0); // Duummy read from a state variable so that the function is view
  25. return 0;
  26. }
  27. }
  28. contract ERC20ReturnTrueMock is Context {
  29. mapping (address => uint256) private _allowances;
  30. // IERC20's functions are not pure, but these mock implementations are: to prevent Solidity from issuing warnings,
  31. // we write to a dummy state variable.
  32. uint256 private _dummy;
  33. function transfer(address, uint256) public returns (bool) {
  34. _dummy = 0;
  35. return true;
  36. }
  37. function transferFrom(address, address, uint256) public returns (bool) {
  38. _dummy = 0;
  39. return true;
  40. }
  41. function approve(address, uint256) public returns (bool) {
  42. _dummy = 0;
  43. return true;
  44. }
  45. function setAllowance(uint256 allowance_) public {
  46. _allowances[_msgSender()] = allowance_;
  47. }
  48. function allowance(address owner, address) public view returns (uint256) {
  49. return _allowances[owner];
  50. }
  51. }
  52. contract ERC20NoReturnMock is Context {
  53. mapping (address => uint256) private _allowances;
  54. // IERC20's functions are not pure, but these mock implementations are: to prevent Solidity from issuing warnings,
  55. // we write to a dummy state variable.
  56. uint256 private _dummy;
  57. function transfer(address, uint256) public {
  58. _dummy = 0;
  59. }
  60. function transferFrom(address, address, uint256) public {
  61. _dummy = 0;
  62. }
  63. function approve(address, uint256) public {
  64. _dummy = 0;
  65. }
  66. function setAllowance(uint256 allowance_) public {
  67. _allowances[_msgSender()] = allowance_;
  68. }
  69. function allowance(address owner, address) public view returns (uint256) {
  70. return _allowances[owner];
  71. }
  72. }
  73. contract SafeERC20Wrapper is Context {
  74. using SafeERC20 for IERC20;
  75. IERC20 private _token;
  76. constructor (IERC20 token) {
  77. _token = token;
  78. }
  79. function transfer() public {
  80. _token.safeTransfer(address(0), 0);
  81. }
  82. function transferFrom() public {
  83. _token.safeTransferFrom(address(0), address(0), 0);
  84. }
  85. function approve(uint256 amount) public {
  86. _token.safeApprove(address(0), amount);
  87. }
  88. function increaseAllowance(uint256 amount) public {
  89. _token.safeIncreaseAllowance(address(0), amount);
  90. }
  91. function decreaseAllowance(uint256 amount) public {
  92. _token.safeDecreaseAllowance(address(0), amount);
  93. }
  94. function setAllowance(uint256 allowance_) public {
  95. ERC20ReturnTrueMock(address(_token)).setAllowance(allowance_);
  96. }
  97. function allowance() public view returns (uint256) {
  98. return _token.allowance(address(0), address(0));
  99. }
  100. }