SafeERC20Helper.sol 3.4 KB

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