SafeERC20HelperUpgradeable.sol 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.0;
  3. import "../utils/ContextUpgradeable.sol";
  4. import "../token/ERC20/IERC20Upgradeable.sol";
  5. import "../token/ERC20/utils/SafeERC20Upgradeable.sol";
  6. import "../proxy/utils/Initializable.sol";
  7. contract ERC20ReturnFalseMockUpgradeable is Initializable, ContextUpgradeable {
  8. function __ERC20ReturnFalseMock_init() internal onlyInitializing {
  9. }
  10. function __ERC20ReturnFalseMock_init_unchained() internal onlyInitializing {
  11. }
  12. uint256 private _allowance;
  13. // IERC20's functions are not pure, but these mock implementations are: to prevent Solidity from issuing warnings,
  14. // we write to a dummy state variable.
  15. uint256 private _dummy;
  16. function transfer(address, uint256) public returns (bool) {
  17. _dummy = 0;
  18. return false;
  19. }
  20. function transferFrom(
  21. address,
  22. address,
  23. uint256
  24. ) public returns (bool) {
  25. _dummy = 0;
  26. return false;
  27. }
  28. function approve(address, uint256) public returns (bool) {
  29. _dummy = 0;
  30. return false;
  31. }
  32. function allowance(address, address) public view returns (uint256) {
  33. require(_dummy == 0); // Dummy read from a state variable so that the function is view
  34. return 0;
  35. }
  36. /**
  37. * @dev This empty reserved space is put in place to allow future versions to add new
  38. * variables without shifting down storage in the inheritance chain.
  39. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
  40. */
  41. uint256[48] private __gap;
  42. }
  43. contract ERC20ReturnTrueMockUpgradeable is Initializable, ContextUpgradeable {
  44. function __ERC20ReturnTrueMock_init() internal onlyInitializing {
  45. }
  46. function __ERC20ReturnTrueMock_init_unchained() internal onlyInitializing {
  47. }
  48. mapping(address => uint256) private _allowances;
  49. // IERC20's functions are not pure, but these mock implementations are: to prevent Solidity from issuing warnings,
  50. // we write to a dummy state variable.
  51. uint256 private _dummy;
  52. function transfer(address, uint256) public returns (bool) {
  53. _dummy = 0;
  54. return true;
  55. }
  56. function transferFrom(
  57. address,
  58. address,
  59. uint256
  60. ) public returns (bool) {
  61. _dummy = 0;
  62. return true;
  63. }
  64. function approve(address, uint256) public returns (bool) {
  65. _dummy = 0;
  66. return true;
  67. }
  68. function setAllowance(uint256 allowance_) public {
  69. _allowances[_msgSender()] = allowance_;
  70. }
  71. function allowance(address owner, address) public view returns (uint256) {
  72. return _allowances[owner];
  73. }
  74. /**
  75. * @dev This empty reserved space is put in place to allow future versions to add new
  76. * variables without shifting down storage in the inheritance chain.
  77. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
  78. */
  79. uint256[48] private __gap;
  80. }
  81. contract ERC20NoReturnMockUpgradeable is Initializable, ContextUpgradeable {
  82. function __ERC20NoReturnMock_init() internal onlyInitializing {
  83. }
  84. function __ERC20NoReturnMock_init_unchained() internal onlyInitializing {
  85. }
  86. mapping(address => uint256) private _allowances;
  87. // IERC20's functions are not pure, but these mock implementations are: to prevent Solidity from issuing warnings,
  88. // we write to a dummy state variable.
  89. uint256 private _dummy;
  90. function transfer(address, uint256) public {
  91. _dummy = 0;
  92. }
  93. function transferFrom(
  94. address,
  95. address,
  96. uint256
  97. ) public {
  98. _dummy = 0;
  99. }
  100. function approve(address, uint256) public {
  101. _dummy = 0;
  102. }
  103. function setAllowance(uint256 allowance_) public {
  104. _allowances[_msgSender()] = allowance_;
  105. }
  106. function allowance(address owner, address) public view returns (uint256) {
  107. return _allowances[owner];
  108. }
  109. /**
  110. * @dev This empty reserved space is put in place to allow future versions to add new
  111. * variables without shifting down storage in the inheritance chain.
  112. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
  113. */
  114. uint256[48] private __gap;
  115. }
  116. contract SafeERC20WrapperUpgradeable is Initializable, ContextUpgradeable {
  117. using SafeERC20Upgradeable for IERC20Upgradeable;
  118. IERC20Upgradeable private _token;
  119. function __SafeERC20Wrapper_init(IERC20Upgradeable token) internal onlyInitializing {
  120. __SafeERC20Wrapper_init_unchained(token);
  121. }
  122. function __SafeERC20Wrapper_init_unchained(IERC20Upgradeable token) internal onlyInitializing {
  123. _token = token;
  124. }
  125. function transfer() public {
  126. _token.safeTransfer(address(0), 0);
  127. }
  128. function transferFrom() public {
  129. _token.safeTransferFrom(address(0), address(0), 0);
  130. }
  131. function approve(uint256 amount) public {
  132. _token.safeApprove(address(0), amount);
  133. }
  134. function increaseAllowance(uint256 amount) public {
  135. _token.safeIncreaseAllowance(address(0), amount);
  136. }
  137. function decreaseAllowance(uint256 amount) public {
  138. _token.safeDecreaseAllowance(address(0), amount);
  139. }
  140. function setAllowance(uint256 allowance_) public {
  141. ERC20ReturnTrueMockUpgradeable(address(_token)).setAllowance(allowance_);
  142. }
  143. function allowance() public view returns (uint256) {
  144. return _token.allowance(address(0), address(0));
  145. }
  146. /**
  147. * @dev This empty reserved space is put in place to allow future versions to add new
  148. * variables without shifting down storage in the inheritance chain.
  149. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
  150. */
  151. uint256[49] private __gap;
  152. }