@1inch/solidity-utils 4.0.0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. package/README.md +9 -208
  2. package/contracts/interfaces/ICreate3Deployer.sol +16 -0
  3. package/contracts/interfaces/IDaiLikePermit.sol +13 -0
  4. package/contracts/interfaces/IERC20MetadataUppercase.sol +12 -0
  5. package/contracts/interfaces/IPermit2.sol +45 -12
  6. package/contracts/interfaces/IWETH.sol +17 -0
  7. package/contracts/libraries/AddressArray.sol +73 -25
  8. package/contracts/libraries/AddressLib.sol +2 -1
  9. package/contracts/libraries/AddressSet.sol +52 -14
  10. package/contracts/libraries/BytesMemory.sol +2 -1
  11. package/contracts/libraries/BytesStorage.sol +2 -1
  12. package/contracts/libraries/ECDSA.sol +111 -0
  13. package/contracts/libraries/RevertReasonForwarder.sol +13 -3
  14. package/contracts/libraries/RevertReasonParser.sol +11 -2
  15. package/contracts/libraries/StringUtil.sol +21 -3
  16. package/contracts/libraries/UniERC20.sol +57 -12
  17. package/contracts/mocks/ERC20PermitMock.sol +12 -0
  18. package/contracts/mocks/SelfdestructEthSenderMock.sol +17 -0
  19. package/contracts/mocks/TokenCustomDecimalsMock.sol +25 -4
  20. package/contracts/mocks/TokenMock.sol +19 -0
  21. package/dist/hardhat-setup/networks.d.ts +23 -0
  22. package/dist/hardhat-setup/networks.js +22 -0
  23. package/dist/hardhat-setup/networks.js.map +1 -1
  24. package/dist/src/expect.d.ts +12 -0
  25. package/dist/src/expect.js +12 -0
  26. package/dist/src/expect.js.map +1 -1
  27. package/dist/src/permit.d.ts +117 -0
  28. package/dist/src/permit.js +112 -7
  29. package/dist/src/permit.js.map +1 -1
  30. package/dist/src/prelude.d.ts +6 -0
  31. package/dist/src/prelude.js +6 -0
  32. package/dist/src/prelude.js.map +1 -1
  33. package/dist/src/profileEVM.d.ts +26 -0
  34. package/dist/src/profileEVM.js +30 -3
  35. package/dist/src/profileEVM.js.map +1 -1
  36. package/dist/src/utils.d.ts +79 -0
  37. package/dist/src/utils.js +92 -1
  38. package/dist/src/utils.js.map +1 -1
  39. package/dist/typechain-types/contracts/mixins/SelfdestructEthSender.d.ts +29 -0
  40. package/dist/typechain-types/contracts/mixins/SelfdestructEthSender.js +3 -0
  41. package/dist/typechain-types/contracts/mixins/SelfdestructEthSender.js.map +1 -0
  42. package/dist/typechain-types/contracts/mixins/index.d.ts +1 -0
  43. package/dist/typechain-types/contracts/mocks/SelfdestructEthSenderMock.d.ts +37 -0
  44. package/dist/typechain-types/contracts/mocks/SelfdestructEthSenderMock.js +3 -0
  45. package/dist/typechain-types/contracts/mocks/SelfdestructEthSenderMock.js.map +1 -0
  46. package/dist/typechain-types/contracts/mocks/TokenCustomDecimalsMock.d.ts +1 -5
  47. package/dist/typechain-types/contracts/mocks/index.d.ts +1 -0
  48. package/dist/typechain-types/factories/@openzeppelin/contracts/utils/Address__factory.d.ts +1 -1
  49. package/dist/typechain-types/factories/@openzeppelin/contracts/utils/Address__factory.js +1 -1
  50. package/dist/typechain-types/factories/@openzeppelin/contracts/utils/ShortStrings__factory.d.ts +1 -1
  51. package/dist/typechain-types/factories/@openzeppelin/contracts/utils/ShortStrings__factory.js +1 -1
  52. package/dist/typechain-types/factories/@openzeppelin/contracts/utils/Strings__factory.d.ts +1 -1
  53. package/dist/typechain-types/factories/@openzeppelin/contracts/utils/Strings__factory.js +1 -1
  54. package/dist/typechain-types/factories/@openzeppelin/contracts/utils/cryptography/ECDSA__factory.d.ts +1 -1
  55. package/dist/typechain-types/factories/@openzeppelin/contracts/utils/cryptography/ECDSA__factory.js +1 -1
  56. package/dist/typechain-types/factories/@openzeppelin/contracts/utils/math/Math__factory.d.ts +1 -1
  57. package/dist/typechain-types/factories/@openzeppelin/contracts/utils/math/Math__factory.js +1 -1
  58. package/dist/typechain-types/factories/contracts/libraries/AddressArray__factory.d.ts +1 -1
  59. package/dist/typechain-types/factories/contracts/libraries/AddressArray__factory.js +1 -1
  60. package/dist/typechain-types/factories/contracts/libraries/BySigTraits__factory.d.ts +1 -1
  61. package/dist/typechain-types/factories/contracts/libraries/BySigTraits__factory.js +1 -1
  62. package/dist/typechain-types/factories/contracts/libraries/BytesMemory__factory.d.ts +1 -1
  63. package/dist/typechain-types/factories/contracts/libraries/BytesMemory__factory.js +1 -1
  64. package/dist/typechain-types/factories/contracts/libraries/BytesStorage__factory.d.ts +1 -1
  65. package/dist/typechain-types/factories/contracts/libraries/BytesStorage__factory.js +1 -1
  66. package/dist/typechain-types/factories/contracts/libraries/RevertReasonParser__factory.d.ts +1 -1
  67. package/dist/typechain-types/factories/contracts/libraries/RevertReasonParser__factory.js +1 -1
  68. package/dist/typechain-types/factories/contracts/libraries/SafeERC20__factory.d.ts +1 -1
  69. package/dist/typechain-types/factories/contracts/libraries/SafeERC20__factory.js +1 -1
  70. package/dist/typechain-types/factories/contracts/libraries/UniERC20__factory.d.ts +1 -1
  71. package/dist/typechain-types/factories/contracts/libraries/UniERC20__factory.js +1 -1
  72. package/dist/typechain-types/factories/contracts/mixins/SelfdestructEthSender__factory.d.ts +17 -0
  73. package/dist/typechain-types/factories/contracts/mixins/SelfdestructEthSender__factory.js +33 -0
  74. package/dist/typechain-types/factories/contracts/mixins/SelfdestructEthSender__factory.js.map +1 -0
  75. package/dist/typechain-types/factories/contracts/mixins/index.d.ts +1 -0
  76. package/dist/typechain-types/factories/contracts/mixins/index.js +3 -1
  77. package/dist/typechain-types/factories/contracts/mixins/index.js.map +1 -1
  78. package/dist/typechain-types/factories/contracts/mocks/ERC20PermitMock__factory.d.ts +1 -1
  79. package/dist/typechain-types/factories/contracts/mocks/ERC20PermitMock__factory.js +1 -1
  80. package/dist/typechain-types/factories/contracts/mocks/ERC20PermitMock__factory.js.map +1 -1
  81. package/dist/typechain-types/factories/contracts/mocks/SelfdestructEthSenderMock__factory.d.ts +49 -0
  82. package/dist/typechain-types/factories/contracts/mocks/SelfdestructEthSenderMock__factory.js +75 -0
  83. package/dist/typechain-types/factories/contracts/mocks/SelfdestructEthSenderMock__factory.js.map +1 -0
  84. package/dist/typechain-types/factories/contracts/mocks/TokenCustomDecimalsMock__factory.d.ts +1 -11
  85. package/dist/typechain-types/factories/contracts/mocks/TokenCustomDecimalsMock__factory.js +1 -14
  86. package/dist/typechain-types/factories/contracts/mocks/TokenCustomDecimalsMock__factory.js.map +1 -1
  87. package/dist/typechain-types/factories/contracts/mocks/TokenMock__factory.d.ts +1 -1
  88. package/dist/typechain-types/factories/contracts/mocks/TokenMock__factory.js +1 -1
  89. package/dist/typechain-types/factories/contracts/mocks/TokenMock__factory.js.map +1 -1
  90. package/dist/typechain-types/factories/contracts/mocks/index.d.ts +1 -0
  91. package/dist/typechain-types/factories/contracts/mocks/index.js +3 -1
  92. package/dist/typechain-types/factories/contracts/mocks/index.js.map +1 -1
  93. package/dist/typechain-types/factories/contracts/tests/ECDSATest__factory.d.ts +1 -1
  94. package/dist/typechain-types/factories/contracts/tests/ECDSATest__factory.js +1 -1
  95. package/dist/typechain-types/factories/contracts/tests/ECDSATest__factory.js.map +1 -1
  96. package/dist/typechain-types/factories/contracts/tests/RevertReasonParserTest__factory.d.ts +1 -1
  97. package/dist/typechain-types/factories/contracts/tests/RevertReasonParserTest__factory.js +1 -1
  98. package/dist/typechain-types/factories/contracts/tests/RevertReasonParserTest__factory.js.map +1 -1
  99. package/dist/typechain-types/factories/contracts/tests/StringUtilTest__factory.d.ts +1 -1
  100. package/dist/typechain-types/factories/contracts/tests/StringUtilTest__factory.js +1 -1
  101. package/dist/typechain-types/factories/contracts/tests/StringUtilTest__factory.js.map +1 -1
  102. package/dist/typechain-types/factories/contracts/tests/mocks/AddressArrayMock__factory.d.ts +1 -1
  103. package/dist/typechain-types/factories/contracts/tests/mocks/AddressArrayMock__factory.js +1 -1
  104. package/dist/typechain-types/factories/contracts/tests/mocks/AddressArrayMock__factory.js.map +1 -1
  105. package/dist/typechain-types/factories/contracts/tests/mocks/AddressLibMock__factory.d.ts +1 -1
  106. package/dist/typechain-types/factories/contracts/tests/mocks/AddressLibMock__factory.js +1 -1
  107. package/dist/typechain-types/factories/contracts/tests/mocks/AddressLibMock__factory.js.map +1 -1
  108. package/dist/typechain-types/factories/contracts/tests/mocks/AddressSetMock__factory.d.ts +1 -1
  109. package/dist/typechain-types/factories/contracts/tests/mocks/AddressSetMock__factory.js +1 -1
  110. package/dist/typechain-types/factories/contracts/tests/mocks/AddressSetMock__factory.js.map +1 -1
  111. package/dist/typechain-types/factories/contracts/tests/mocks/BySigTraitsMock__factory.d.ts +1 -1
  112. package/dist/typechain-types/factories/contracts/tests/mocks/BySigTraitsMock__factory.js +1 -1
  113. package/dist/typechain-types/factories/contracts/tests/mocks/BySigTraitsMock__factory.js.map +1 -1
  114. package/dist/typechain-types/factories/contracts/tests/mocks/BytesMemoryMock__factory.d.ts +1 -1
  115. package/dist/typechain-types/factories/contracts/tests/mocks/BytesMemoryMock__factory.js +1 -1
  116. package/dist/typechain-types/factories/contracts/tests/mocks/BytesMemoryMock__factory.js.map +1 -1
  117. package/dist/typechain-types/factories/contracts/tests/mocks/BytesStorageMock__factory.d.ts +1 -1
  118. package/dist/typechain-types/factories/contracts/tests/mocks/BytesStorageMock__factory.js +1 -1
  119. package/dist/typechain-types/factories/contracts/tests/mocks/BytesStorageMock__factory.js.map +1 -1
  120. package/dist/typechain-types/factories/contracts/tests/mocks/DaiLikePermitMock__factory.d.ts +1 -1
  121. package/dist/typechain-types/factories/contracts/tests/mocks/DaiLikePermitMock__factory.js +1 -1
  122. package/dist/typechain-types/factories/contracts/tests/mocks/DaiLikePermitMock__factory.js.map +1 -1
  123. package/dist/typechain-types/factories/contracts/tests/mocks/ERC1271WalletMock__factory.d.ts +1 -1
  124. package/dist/typechain-types/factories/contracts/tests/mocks/ERC1271WalletMock__factory.js +1 -1
  125. package/dist/typechain-types/factories/contracts/tests/mocks/ERC1271WalletMock__factory.js.map +1 -1
  126. package/dist/typechain-types/factories/contracts/tests/mocks/EthReceiverMock__factory.d.ts +1 -1
  127. package/dist/typechain-types/factories/contracts/tests/mocks/EthReceiverMock__factory.js +1 -1
  128. package/dist/typechain-types/factories/contracts/tests/mocks/EthSenderMock__factory.d.ts +1 -1
  129. package/dist/typechain-types/factories/contracts/tests/mocks/EthSenderMock__factory.js +1 -1
  130. package/dist/typechain-types/factories/contracts/tests/mocks/EthSenderMock__factory.js.map +1 -1
  131. package/dist/typechain-types/factories/contracts/tests/mocks/PermitAndCallMock__factory.d.ts +1 -1
  132. package/dist/typechain-types/factories/contracts/tests/mocks/PermitAndCallMock__factory.js +1 -1
  133. package/dist/typechain-types/factories/contracts/tests/mocks/PermitAndCallMock__factory.js.map +1 -1
  134. package/dist/typechain-types/factories/contracts/tests/mocks/PermitableMock__factory.d.ts +1 -1
  135. package/dist/typechain-types/factories/contracts/tests/mocks/PermitableMock__factory.js +1 -1
  136. package/dist/typechain-types/factories/contracts/tests/mocks/PermitableMock__factory.js.map +1 -1
  137. package/dist/typechain-types/factories/contracts/tests/mocks/SafeERC20Helper.sol/ERC20NoReturnMock__factory.d.ts +1 -1
  138. package/dist/typechain-types/factories/contracts/tests/mocks/SafeERC20Helper.sol/ERC20NoReturnMock__factory.js +1 -1
  139. package/dist/typechain-types/factories/contracts/tests/mocks/SafeERC20Helper.sol/ERC20NoReturnMock__factory.js.map +1 -1
  140. package/dist/typechain-types/factories/contracts/tests/mocks/SafeERC20Helper.sol/ERC20PermitNoRevertMock__factory.d.ts +1 -1
  141. package/dist/typechain-types/factories/contracts/tests/mocks/SafeERC20Helper.sol/ERC20PermitNoRevertMock__factory.js +1 -1
  142. package/dist/typechain-types/factories/contracts/tests/mocks/SafeERC20Helper.sol/ERC20PermitNoRevertMock__factory.js.map +1 -1
  143. package/dist/typechain-types/factories/contracts/tests/mocks/SafeERC20Helper.sol/ERC20ReturnFalseMock__factory.d.ts +1 -1
  144. package/dist/typechain-types/factories/contracts/tests/mocks/SafeERC20Helper.sol/ERC20ReturnFalseMock__factory.js +1 -1
  145. package/dist/typechain-types/factories/contracts/tests/mocks/SafeERC20Helper.sol/ERC20ReturnFalseMock__factory.js.map +1 -1
  146. package/dist/typechain-types/factories/contracts/tests/mocks/SafeERC20Helper.sol/ERC20ReturnTrueMock__factory.d.ts +1 -1
  147. package/dist/typechain-types/factories/contracts/tests/mocks/SafeERC20Helper.sol/ERC20ReturnTrueMock__factory.js +1 -1
  148. package/dist/typechain-types/factories/contracts/tests/mocks/SafeERC20Helper.sol/ERC20ReturnTrueMock__factory.js.map +1 -1
  149. package/dist/typechain-types/factories/contracts/tests/mocks/SafeERC20Helper.sol/ERC20ThroughZeroApprove__factory.d.ts +1 -1
  150. package/dist/typechain-types/factories/contracts/tests/mocks/SafeERC20Helper.sol/ERC20ThroughZeroApprove__factory.js +1 -1
  151. package/dist/typechain-types/factories/contracts/tests/mocks/SafeERC20Helper.sol/ERC20ThroughZeroApprove__factory.js.map +1 -1
  152. package/dist/typechain-types/factories/contracts/tests/mocks/SafeERC20Helper.sol/ERC20WithSafeBalance__factory.d.ts +1 -1
  153. package/dist/typechain-types/factories/contracts/tests/mocks/SafeERC20Helper.sol/ERC20WithSafeBalance__factory.js +1 -1
  154. package/dist/typechain-types/factories/contracts/tests/mocks/SafeERC20Helper.sol/ERC20WithSafeBalance__factory.js.map +1 -1
  155. package/dist/typechain-types/factories/contracts/tests/mocks/SafeERC20Helper.sol/Permit2ReturnTrueMock__factory.d.ts +1 -1
  156. package/dist/typechain-types/factories/contracts/tests/mocks/SafeERC20Helper.sol/Permit2ReturnTrueMock__factory.js +1 -1
  157. package/dist/typechain-types/factories/contracts/tests/mocks/SafeERC20Helper.sol/Permit2ReturnTrueMock__factory.js.map +1 -1
  158. package/dist/typechain-types/factories/contracts/tests/mocks/SafeERC20Helper.sol/SafeERC20Wrapper__factory.d.ts +1 -1
  159. package/dist/typechain-types/factories/contracts/tests/mocks/SafeERC20Helper.sol/SafeERC20Wrapper__factory.js +1 -1
  160. package/dist/typechain-types/factories/contracts/tests/mocks/SafeERC20Helper.sol/SafeERC20Wrapper__factory.js.map +1 -1
  161. package/dist/typechain-types/factories/contracts/tests/mocks/SafeERC20Helper.sol/SafeWETHWrapper__factory.d.ts +1 -1
  162. package/dist/typechain-types/factories/contracts/tests/mocks/SafeERC20Helper.sol/SafeWETHWrapper__factory.js +1 -1
  163. package/dist/typechain-types/factories/contracts/tests/mocks/SafeERC20Helper.sol/SafeWETHWrapper__factory.js.map +1 -1
  164. package/dist/typechain-types/factories/contracts/tests/mocks/TokenWithBySig__factory.d.ts +1 -1
  165. package/dist/typechain-types/factories/contracts/tests/mocks/TokenWithBySig__factory.js +1 -1
  166. package/dist/typechain-types/factories/contracts/tests/mocks/TokenWithBySig__factory.js.map +1 -1
  167. package/dist/typechain-types/factories/contracts/tests/mocks/USDCLikePermitMock__factory.d.ts +1 -1
  168. package/dist/typechain-types/factories/contracts/tests/mocks/USDCLikePermitMock__factory.js +1 -1
  169. package/dist/typechain-types/factories/contracts/tests/mocks/USDCLikePermitMock__factory.js.map +1 -1
  170. package/dist/typechain-types/factories/contracts/tests/mocks/UniERC20Helper.sol/ERC20Capitals__factory.d.ts +1 -1
  171. package/dist/typechain-types/factories/contracts/tests/mocks/UniERC20Helper.sol/ERC20Capitals__factory.js +1 -1
  172. package/dist/typechain-types/factories/contracts/tests/mocks/UniERC20Helper.sol/ERC20Capitals__factory.js.map +1 -1
  173. package/dist/typechain-types/factories/contracts/tests/mocks/UniERC20Helper.sol/ERC20bytes32Capitals__factory.d.ts +1 -1
  174. package/dist/typechain-types/factories/contracts/tests/mocks/UniERC20Helper.sol/ERC20bytes32Capitals__factory.js +1 -1
  175. package/dist/typechain-types/factories/contracts/tests/mocks/UniERC20Helper.sol/ERC20bytes32Capitals__factory.js.map +1 -1
  176. package/dist/typechain-types/factories/contracts/tests/mocks/UniERC20Helper.sol/ERC20bytes32__factory.d.ts +1 -1
  177. package/dist/typechain-types/factories/contracts/tests/mocks/UniERC20Helper.sol/ERC20bytes32__factory.js +1 -1
  178. package/dist/typechain-types/factories/contracts/tests/mocks/UniERC20Helper.sol/ERC20bytes32__factory.js.map +1 -1
  179. package/dist/typechain-types/factories/contracts/tests/mocks/UniERC20Helper.sol/ETHBadReceiver__factory.d.ts +1 -1
  180. package/dist/typechain-types/factories/contracts/tests/mocks/UniERC20Helper.sol/ETHBadReceiver__factory.js +1 -1
  181. package/dist/typechain-types/factories/contracts/tests/mocks/UniERC20Helper.sol/ETHBadReceiver__factory.js.map +1 -1
  182. package/dist/typechain-types/factories/contracts/tests/mocks/UniERC20Helper.sol/UniERC20Wrapper__factory.d.ts +1 -1
  183. package/dist/typechain-types/factories/contracts/tests/mocks/UniERC20Helper.sol/UniERC20Wrapper__factory.js +1 -1
  184. package/dist/typechain-types/factories/contracts/tests/mocks/UniERC20Helper.sol/UniERC20Wrapper__factory.js.map +1 -1
  185. package/dist/typechain-types/factories/contracts/tests/mocks/WETH__factory.d.ts +1 -1
  186. package/dist/typechain-types/factories/contracts/tests/mocks/WETH__factory.js +1 -1
  187. package/dist/typechain-types/factories/contracts/tests/mocks/WETH__factory.js.map +1 -1
  188. package/dist/typechain-types/factories/contracts/tests/mocks/WethReceiverMock__factory.d.ts +1 -1
  189. package/dist/typechain-types/factories/contracts/tests/mocks/WethReceiverMock__factory.js +1 -1
  190. package/dist/typechain-types/factories/contracts/tests/mocks/WethReceiverMock__factory.js.map +1 -1
  191. package/dist/typechain-types/index.d.ts +4 -0
  192. package/dist/typechain-types/index.js +6 -2
  193. package/dist/typechain-types/index.js.map +1 -1
  194. package/package.json +23 -18
  195. package/utils/README.md +180 -0
  196. package/utils/docify.utils.js +3 -3
  197. package/utils/file-dependencies.js +0 -0
  198. package/utils/test-docgen.js +0 -0
@@ -4,50 +4,79 @@ pragma solidity ^0.8.0;
4
4
 
5
5
  import "./AddressArray.sol";
6
6
 
7
- /** @title Library that is using AddressArray library for AddressArray.Data
8
- * and allows Set operations on address storage data:
9
- * 1. add
10
- * 2. remove
11
- * 3. contains
7
+ /**
8
+ * @title AddressSet
9
+ * @notice Library for managing sets of addresses, allowing operations such as add, remove, and contains.
10
+ * Utilizes the AddressArray library for underlying data storage.
12
11
  */
13
12
  library AddressSet {
14
13
  using AddressArray for AddressArray.Data;
15
14
 
16
15
  uint256 internal constant _NULL_INDEX = type(uint256).max;
17
16
 
18
- /// @dev Data struct from AddressArray.Data items and lookup mapping address => index in data array.
17
+ /**
18
+ * @dev Data struct from AddressArray.Data items
19
+ * and lookup mapping address => index in data array.
20
+ */
19
21
  struct Data {
20
22
  AddressArray.Data items;
21
23
  mapping(address => uint256) lookup;
22
24
  }
23
25
 
24
- /// @dev Length of data storage.
26
+ /**
27
+ * @notice Determines the number of addresses in the set.
28
+ * @param s The set of addresses.
29
+ * @return The number of addresses in the set.
30
+ */
25
31
  function length(Data storage s) internal view returns (uint256) {
26
32
  return s.items.length();
27
33
  }
28
34
 
29
- /// @dev Returns data item from `s` storage at `index`.
35
+ /**
36
+ * @notice Retrieves the address at a specified index in the set.
37
+ * @param s The set of addresses.
38
+ * @param index The index of the address to retrieve.
39
+ * @return The address at the specified index.
40
+ */
30
41
  function at(Data storage s, uint256 index) internal view returns (address) {
31
42
  return s.items.at(index);
32
43
  }
33
44
 
34
- /// @dev Returns true if storage `s` has `item`.
45
+ /**
46
+ * @notice Checks if the set contains the specified address.
47
+ * @param s The set of addresses.
48
+ * @param item The address to check for.
49
+ * @return True if the set contains the address, false otherwise.
50
+ */
35
51
  function contains(Data storage s, address item) internal view returns (bool) {
36
52
  uint256 index = s.lookup[item];
37
53
  return index != 0 && index != _NULL_INDEX;
38
54
  }
39
55
 
40
- /// @dev Returns list of addresses from storage `s`.
56
+ /**
57
+ * @notice Returns list of addresses from storage `s`.
58
+ * @param s The set of addresses.
59
+ * @return The array of addresses stored in `s`.
60
+ */
41
61
  function get(Data storage s) internal view returns (address[] memory) {
42
62
  return s.items.get();
43
63
  }
44
64
 
45
- /// @dev Puts list of addresses from `s` storage into `output` array.
65
+ /**
66
+ * @notice Puts list of addresses from `s` storage into `output` array.
67
+ * @param s The set of addresses.
68
+ * @return The provided output array filled with addresses.
69
+ */
46
70
  function get(Data storage s, address[] memory input) internal view returns (address[] memory) {
47
71
  return s.items.get(input);
48
72
  }
49
73
 
50
- /// @dev Adds `item` into storage `s` and returns true if successful.
74
+ /**
75
+ * @notice Adds an address to the set if it is not already present.
76
+ * @param s The set of addresses.
77
+ * @param item The address to add.
78
+ * @return True if the address was added to the set, false if it was already present.
79
+ */
51
80
  function add(Data storage s, address item) internal returns (bool) {
52
81
  uint256 index = s.lookup[item];
53
82
  if (index != 0 && index != _NULL_INDEX) {
@@ -57,7 +86,12 @@ library AddressSet {
57
86
  return true;
58
87
  }
59
88
 
60
- /// @dev Removes `item` from storage `s` and returns true if successful.
89
+ /**
90
+ * @notice Removes an address from the set if it exists.
91
+ * @param s The set of addresses.
92
+ * @param item The address to remove.
93
+ * @return True if the address was removed from the set, false if it was not found.
94
+ */
61
95
  function remove(Data storage s, address item) internal returns (bool) {
62
96
  uint256 index = s.lookup[item];
63
97
  s.lookup[item] = _NULL_INDEX;
@@ -75,7 +109,11 @@ library AddressSet {
75
109
  return true;
76
110
  }
77
111
 
78
- /// @dev Erases set from storage `s` and returns all removed items
112
+ /**
113
+ * @notice Erases set from storage `s`.
114
+ * @param s The set of addresses.
115
+ * @return items All removed items.
116
+ */
79
117
  function erase(Data storage s) internal returns(address[] memory items) {
80
118
  items = s.items.get();
81
119
  uint256 len = items.length;
@@ -3,7 +3,8 @@
3
3
  pragma solidity ^0.8.0;
4
4
 
5
5
  /**
6
- * @title A library for operating on bytes memory slices without copying.
6
+ * @title BytesMemory
7
+ * @notice A library for operating on bytes memory slices without copying.
7
8
  */
8
9
  library BytesMemory {
9
10
  error OutOfBounds();
@@ -3,7 +3,8 @@
3
3
  pragma solidity ^0.8.0;
4
4
 
5
5
  /**
6
- * @title A library for operating on bytes storage slices.
6
+ * @title BytesStorage
7
+ * @notice A library for operating on bytes storage slices.
7
8
  */
8
9
  library BytesStorage {
9
10
  error OutOfBounds();
@@ -4,6 +4,10 @@ pragma solidity ^0.8.0;
4
4
 
5
5
  import "@openzeppelin/contracts/interfaces/IERC1271.sol";
6
6
 
7
+ /**
8
+ * @title ECDSA signature operations
9
+ * @notice Provides functions for recovering addresses from signatures and verifying signatures, including support for EIP-2098 compact signatures.
10
+ */
7
11
  library ECDSA {
8
12
  // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
9
13
  // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
@@ -18,6 +22,15 @@ library ECDSA {
18
22
  uint256 private constant _COMPACT_S_MASK = 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
19
23
  uint256 private constant _COMPACT_V_SHIFT = 255;
20
24
 
25
+ /**
26
+ * @notice Recovers the signer's address from the signature.
27
+ * @dev Recovers the address that has signed a hash with `(v, r, s)` signature.
28
+ * @param hash The keccak256 hash of the data signed.
29
+ * @param v The recovery byte of the signature.
30
+ * @param r The first 32 bytes of the signature.
31
+ * @param s The second 32 bytes of the signature.
32
+ * @return signer The address of the signer.
33
+ */
21
34
  function recover(
22
35
  bytes32 hash,
23
36
  uint8 v,
@@ -39,6 +52,14 @@ library ECDSA {
39
52
  }
40
53
  }
41
54
 
55
+ /**
56
+ * @notice Recovers the signer's address from the signature using `r` and `vs` components.
57
+ * @dev Recovers the address that has signed a hash with `r` and `vs`, where `vs` combines `v` and `s`.
58
+ * @param hash The keccak256 hash of the data signed.
59
+ * @param r The first 32 bytes of the signature.
60
+ * @param vs The combined `v` and `s` values of the signature.
61
+ * @return signer The address of the signer.
62
+ */
42
63
  function recover(
43
64
  bytes32 hash,
44
65
  bytes32 r,
@@ -60,6 +81,12 @@ library ECDSA {
60
81
  }
61
82
  }
62
83
 
84
+ /**
85
+ * @notice Recovers the signer's address from a hash and a signature.
86
+ * @param hash The keccak256 hash of the signed data.
87
+ * @param signature The full signature from which the signer will be recovered.
88
+ * @return signer The address of the signer.
89
+ */
63
90
  /// @dev WARNING!!!
64
91
  /// There is a known signature malleability issue with two representations of signatures!
65
92
  /// Even though this function is able to verify both standard 65-byte and compact 64-byte EIP-2098 signatures
@@ -102,6 +129,14 @@ library ECDSA {
102
129
  }
103
130
  }
104
131
 
132
+ /**
133
+ * @notice Verifies the signature for a hash, either by recovering the signer or using EIP-1271's `isValidSignature` function.
134
+ * @dev Attempts to recover the signer's address from the signature; if the address is non-zero, checks if it's valid according to EIP-1271.
135
+ * @param signer The address to validate the signature against.
136
+ * @param hash The hash of the signed data.
137
+ * @param signature The signature to verify.
138
+ * @return success True if the signature is verified, false otherwise.
139
+ */
105
140
  function recoverOrIsValidSignature(
106
141
  address signer,
107
142
  bytes32 hash,
@@ -114,6 +149,16 @@ library ECDSA {
114
149
  return isValidSignature(signer, hash, signature);
115
150
  }
116
151
 
152
+ /**
153
+ * @notice Verifies the signature for a hash, either by recovering the signer or using EIP-1271's `isValidSignature` function.
154
+ * @dev Attempts to recover the signer's address from the signature; if the address is non-zero, checks if it's valid according to EIP-1271.
155
+ * @param signer The address to validate the signature against.
156
+ * @param hash The hash of the signed data.
157
+ * @param v The recovery byte of the signature.
158
+ * @param r The first 32 bytes of the signature.
159
+ * @param s The second 32 bytes of the signature.
160
+ * @return success True if the signature is verified, false otherwise.
161
+ */
117
162
  function recoverOrIsValidSignature(
118
163
  address signer,
119
164
  bytes32 hash,
@@ -128,6 +173,15 @@ library ECDSA {
128
173
  return isValidSignature(signer, hash, v, r, s);
129
174
  }
130
175
 
176
+ /**
177
+ * @notice Verifies the signature for a hash, either by recovering the signer or using EIP-1271's `isValidSignature` function.
178
+ * @dev Attempts to recover the signer's address from the signature; if the address is non-zero, checks if it's valid according to EIP-1271.
179
+ * @param signer The address to validate the signature against.
180
+ * @param hash The hash of the signed data.
181
+ * @param r The first 32 bytes of the signature.
182
+ * @param vs The combined `v` and `s` values of the signature.
183
+ * @return success True if the signature is verified, false otherwise.
184
+ */
131
185
  function recoverOrIsValidSignature(
132
186
  address signer,
133
187
  bytes32 hash,
@@ -141,6 +195,15 @@ library ECDSA {
141
195
  return isValidSignature(signer, hash, r, vs);
142
196
  }
143
197
 
198
+ /**
199
+ * @notice Verifies the signature for a given hash, attempting to recover the signer's address or validates it using EIP-1271 for 65-byte signatures.
200
+ * @dev Attempts to recover the signer's address from the signature. If the address is a contract, checks if the signature is valid according to EIP-1271.
201
+ * @param signer The expected signer's address.
202
+ * @param hash The keccak256 hash of the signed data.
203
+ * @param r The first 32 bytes of the signature.
204
+ * @param vs The last 32 bytes of the signature, with the last byte being the recovery id.
205
+ * @return success True if the signature is valid, false otherwise.
206
+ */
144
207
  function recoverOrIsValidSignature65(
145
208
  address signer,
146
209
  bytes32 hash,
@@ -154,6 +217,14 @@ library ECDSA {
154
217
  return isValidSignature65(signer, hash, r, vs);
155
218
  }
156
219
 
220
+ /**
221
+ * @notice Validates a signature for a hash using EIP-1271, if `signer` is a contract.
222
+ * @dev Makes a static call to `signer` with `isValidSignature` function selector from EIP-1271.
223
+ * @param signer The address of the signer to validate against, which could be an EOA or a contract.
224
+ * @param hash The hash of the signed data.
225
+ * @param signature The signature to validate.
226
+ * @return success True if the signature is valid according to EIP-1271, false otherwise.
227
+ */
157
228
  function isValidSignature(
158
229
  address signer,
159
230
  bytes32 hash,
@@ -176,6 +247,16 @@ library ECDSA {
176
247
  }
177
248
  }
178
249
 
250
+ /**
251
+ * @notice Validates a signature for a hash using EIP-1271, if `signer` is a contract.
252
+ * @dev Makes a static call to `signer` with `isValidSignature` function selector from EIP-1271.
253
+ * @param signer The address of the signer to validate against, which could be an EOA or a contract.
254
+ * @param hash The hash of the signed data.
255
+ * @param v The recovery byte of the signature.
256
+ * @param r The first 32 bytes of the signature.
257
+ * @param s The second 32 bytes of the signature.
258
+ * @return success True if the signature is valid according to EIP-1271, false otherwise.
259
+ */
179
260
  function isValidSignature(
180
261
  address signer,
181
262
  bytes32 hash,
@@ -200,6 +281,15 @@ library ECDSA {
200
281
  }
201
282
  }
202
283
 
284
+ /**
285
+ * @notice Validates a signature for a hash using EIP-1271, if `signer` is a contract.
286
+ * @dev Makes a static call to `signer` with `isValidSignature` function selector from EIP-1271.
287
+ * @param signer The address of the signer to validate against, which could be an EOA or a contract.
288
+ * @param hash The hash of the signed data.
289
+ * @param r The first 32 bytes of the signature.
290
+ * @param vs The last 32 bytes of the signature, with the last byte being the recovery id.
291
+ * @return success True if the signature is valid according to EIP-1271, false otherwise.
292
+ */
203
293
  function isValidSignature(
204
294
  address signer,
205
295
  bytes32 hash,
@@ -224,6 +314,14 @@ library ECDSA {
224
314
  }
225
315
  }
226
316
 
317
+ /**
318
+ * @notice Verifies if a 65-byte signature is valid for a given hash, according to EIP-1271.
319
+ * @param signer The address of the signer to validate against, which could be an EOA or a contract.
320
+ * @param hash The hash of the signed data.
321
+ * @param r The first 32 bytes of the signature.
322
+ * @param vs The combined `v` (recovery id) and `s` component of the signature, packed into the last 32 bytes.
323
+ * @return success True if the signature is valid according to EIP-1271, false otherwise.
324
+ */
227
325
  function isValidSignature65(
228
326
  address signer,
229
327
  bytes32 hash,
@@ -249,6 +347,12 @@ library ECDSA {
249
347
  }
250
348
  }
251
349
 
350
+ /**
351
+ * @notice Generates a hash compatible with Ethereum's signed message format.
352
+ * @dev Prepends the hash with Ethereum's message prefix before hashing it.
353
+ * @param hash The hash of the data to sign.
354
+ * @return res The Ethereum signed message hash.
355
+ */
252
356
  function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32 res) {
253
357
  // 32 is the length in bytes of hash, enforced by the type signature above
254
358
  // return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
@@ -259,6 +363,13 @@ library ECDSA {
259
363
  }
260
364
  }
261
365
 
366
+ /**
367
+ * @notice Generates an EIP-712 compliant hash.
368
+ * @dev Encodes the domain separator and the struct hash according to EIP-712.
369
+ * @param domainSeparator The EIP-712 domain separator.
370
+ * @param structHash The EIP-712 struct hash.
371
+ * @return res The EIP-712 compliant hash.
372
+ */
262
373
  function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 res) {
263
374
  // return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
264
375
  assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
@@ -2,9 +2,15 @@
2
2
 
3
3
  pragma solidity ^0.8.0;
4
4
 
5
- /// @title Revert reason forwarder.
5
+ /**
6
+ * @title RevertReasonForwarder
7
+ * @notice Provides utilities for forwarding and retrieving revert reasons from failed external calls.
8
+ */
6
9
  library RevertReasonForwarder {
7
- /// @dev Forwards latest externall call revert.
10
+ /**
11
+ * @dev Forwards the revert reason from the latest external call.
12
+ * This method allows propagating the revert reason of a failed external call to the caller.
13
+ */
8
14
  function reRevert() internal pure {
9
15
  // bubble up revert reason from latest external call
10
16
  assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
@@ -14,7 +20,11 @@ library RevertReasonForwarder {
14
20
  }
15
21
  }
16
22
 
17
- /// @dev Returns latest external call revert reason.
23
+ /**
24
+ * @dev Retrieves the revert reason from the latest external call.
25
+ * This method enables capturing the revert reason of a failed external call for inspection or processing.
26
+ * @return reason The latest external call revert reason.
27
+ */
18
28
  function reReason() internal pure returns (bytes memory reason) {
19
29
  assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
20
30
  reason := mload(0x40)
@@ -4,7 +4,9 @@ pragma solidity ^0.8.0;
4
4
 
5
5
  import "./StringUtil.sol";
6
6
 
7
- /** @title Library that allows to parse unsuccessful arbitrary calls revert reasons.
7
+ /**
8
+ * @title RevertReasonParser
9
+ * @notice Library that allows to parse unsuccessful arbitrary calls revert reasons.
8
10
  * See https://solidity.readthedocs.io/en/latest/control-structures.html#revert for details.
9
11
  * Note that we assume revert reason being abi-encoded as Error(string) so it may fail to parse reason
10
12
  * if structured reverts appear in the future.
@@ -20,7 +22,14 @@ library RevertReasonParser {
20
22
  bytes4 private constant _ERROR_SELECTOR = bytes4(keccak256("Error(string)"));
21
23
  bytes4 private constant _PANIC_SELECTOR = bytes4(keccak256("Panic(uint256)"));
22
24
 
23
- /// @dev Parses error `data` and returns actual with `prefix`.
25
+ /**
26
+ * @dev Parses revert reason from failed calls, returning it with a `prefix`.
27
+ * Handles standard `Error(string)` and `Panic(uint256)` formats, defaulting to `Unknown(data)` for unrecognized patterns.
28
+ *
29
+ * @param data The revert data to parse.
30
+ * @param prefix String to add before the parsed reason for context.
31
+ * @return The formatted revert reason.
32
+ */
24
33
  function parse(bytes memory data, string memory prefix) internal pure returns (string memory) {
25
34
  // https://solidity.readthedocs.io/en/latest/control-structures.html#revert
26
35
  // We assume that revert reason is abi-encoded as Error(string)
@@ -2,18 +2,36 @@
2
2
 
3
3
  pragma solidity ^0.8.0;
4
4
 
5
- /// @title Library with gas-efficient string operations
5
+ /**
6
+ * @title StringUtil
7
+ * @dev Library with gas-efficient string operations.
8
+ */
6
9
  library StringUtil {
10
+ /**
11
+ * @notice Converts a uint256 value to its hexadecimal string representation.
12
+ * @param value The uint256 value to convert.
13
+ * @return The hexadecimal string representation of the input value.
14
+ */
7
15
  function toHex(uint256 value) internal pure returns (string memory) {
8
16
  return toHex(abi.encodePacked(value));
9
17
  }
10
18
 
19
+ /**
20
+ * @notice Converts an address to its hexadecimal string representation.
21
+ * @param value The address to convert.
22
+ * @return The hexadecimal string representation of the input address.
23
+ */
11
24
  function toHex(address value) internal pure returns (string memory) {
12
25
  return toHex(abi.encodePacked(value));
13
26
  }
14
27
 
15
- /// @dev this is the assembly adaptation of highly optimized toHex16 code from Mikhail Vladimirov
16
- /// https://stackoverflow.com/a/69266989
28
+ /**
29
+ * @dev Converts arbitrary bytes to their hexadecimal string representation.
30
+ * This is an assembly adaptation of highly optimized toHex16 code by Mikhail Vladimirov.
31
+ * Reference: https://stackoverflow.com/a/69266989
32
+ * @param data The bytes to be converted to hexadecimal string.
33
+ * @return result The hexadecimal string representation of the input bytes.
34
+ */
17
35
  function toHex(bytes memory data) internal pure returns (string memory result) {
18
36
  assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
19
37
  function _toHex16(input) -> output {
@@ -8,7 +8,11 @@ import "../interfaces/IERC20MetadataUppercase.sol";
8
8
  import "./SafeERC20.sol";
9
9
  import "./StringUtil.sol";
10
10
 
11
- /// @title Library, which allows usage of ETH as ERC20 and ERC20 itself. Uses SafeERC20 library for ERC20 interface.
11
+ /**
12
+ * @title UniERC20
13
+ * @dev Library to abstract the handling of ETH and ERC20 tokens, enabling unified interaction with both. It allows usage of ETH as ERC20.
14
+ * Utilizes SafeERC20 for ERC20 interactions and provides additional utility functions.
15
+ */
12
16
  library UniERC20 {
13
17
  using SafeERC20 for IERC20;
14
18
 
@@ -23,12 +27,21 @@ library UniERC20 {
23
27
  IERC20 private constant _ETH_ADDRESS = IERC20(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE);
24
28
  IERC20 private constant _ZERO_ADDRESS = IERC20(address(0));
25
29
 
26
- /// @dev Returns true if `token` is ETH.
30
+ /**
31
+ * @dev Determines if the specified token is ETH.
32
+ * @param token The token to check.
33
+ * @return bool True if the token is ETH, false otherwise.
34
+ */
27
35
  function isETH(IERC20 token) internal pure returns (bool) {
28
36
  return (token == _ZERO_ADDRESS || token == _ETH_ADDRESS);
29
37
  }
30
38
 
31
- /// @dev Returns `account` ERC20 `token` balance.
39
+ /**
40
+ * @dev Retrieves the balance of the specified token for an account.
41
+ * @param token The token to query the balance of.
42
+ * @param account The address of the account.
43
+ * @return uint256 The balance of the token for the specified account.
44
+ */
32
45
  function uniBalanceOf(IERC20 token, address account) internal view returns (uint256) {
33
46
  if (isETH(token)) {
34
47
  return account.balance;
@@ -37,8 +50,13 @@ library UniERC20 {
37
50
  }
38
51
  }
39
52
 
40
- /// @dev `token` transfer `to` `amount`.
41
- /// Note that this function does nothing in case of zero amount.
53
+ /**
54
+ * @dev Transfers a specified amount of the token to a given address.
55
+ * Note: Does nothing if the amount is zero.
56
+ * @param token The token to transfer.
57
+ * @param to The address to transfer the token to.
58
+ * @param amount The amount of the token to transfer.
59
+ */
42
60
  function uniTransfer(
43
61
  IERC20 token,
44
62
  address payable to,
@@ -56,8 +74,14 @@ library UniERC20 {
56
74
  }
57
75
  }
58
76
 
59
- /// @dev `token` transfer `from` `to` `amount`.
60
- /// Note that this function does nothing in case of zero amount.
77
+ /**
78
+ * @dev Transfers a specified amount of the token from one address to another.
79
+ * Note: Does nothing if the amount is zero.
80
+ * @param token The token to transfer.
81
+ * @param from The address to transfer the token from.
82
+ * @param to The address to transfer the token to.
83
+ * @param amount The amount of the token to transfer.
84
+ */
61
85
  function uniTransferFrom(
62
86
  IERC20 token,
63
87
  address payable from,
@@ -83,17 +107,31 @@ library UniERC20 {
83
107
  }
84
108
  }
85
109
 
86
- /// @dev Returns `token` symbol from ERC20 metadata.
110
+ /**
111
+ * @dev Retrieves the symbol from ERC20 metadata of the specified token.
112
+ * @param token The token to retrieve the symbol of.
113
+ * @return string The symbol of the token.
114
+ */
87
115
  function uniSymbol(IERC20 token) internal view returns (string memory) {
88
116
  return _uniDecode(token, IERC20Metadata.symbol.selector, IERC20MetadataUppercase.SYMBOL.selector);
89
117
  }
90
118
 
91
- /// @dev Returns `token` name from ERC20 metadata.
119
+ /**
120
+ * @dev Retrieves the name from ERC20 metadata of the specified token.
121
+ * @param token The token to retrieve the name of.
122
+ * @return string The name of the token.
123
+ */
92
124
  function uniName(IERC20 token) internal view returns (string memory) {
93
125
  return _uniDecode(token, IERC20Metadata.name.selector, IERC20MetadataUppercase.NAME.selector);
94
126
  }
95
127
 
96
- /// @dev Reverts if `token` is ETH, otherwise performs ERC20 forceApprove.
128
+ /**
129
+ * @dev forceApprove the specified amount of the token to a given address.
130
+ * Reverts if the token is ETH.
131
+ * @param token The token to approve.
132
+ * @param to The address to approve the token to.
133
+ * @param amount The amount of the token to approve.
134
+ */
97
135
  function uniApprove(
98
136
  IERC20 token,
99
137
  address to,
@@ -104,8 +142,15 @@ library UniERC20 {
104
142
  token.forceApprove(to, amount);
105
143
  }
106
144
 
107
- /// @dev 20K gas is provided to account for possible implementations of name/symbol
108
- /// (token implementation might be behind proxy or store the value in storage)
145
+ /**
146
+ * @dev Internal function to decode token metadata (name or symbol).
147
+ * 20K gas is provided to account for possible implementations of name/symbol
148
+ * (token implementation might be behind proxy or store the value in storage)
149
+ * @param token The token to decode metadata for.
150
+ * @param lowerCaseSelector The selector for the lowercase metadata function.
151
+ * @param upperCaseSelector The selector for the uppercase metadata function.
152
+ * @return result The decoded metadata value.
153
+ */
109
154
  function _uniDecode(
110
155
  IERC20 token,
111
156
  bytes4 lowerCaseSelector,
@@ -5,7 +5,19 @@ pragma solidity ^0.8.0;
5
5
  import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";
6
6
  import "./TokenMock.sol";
7
7
 
8
+ /**
9
+ * @title ERC20PermitMock
10
+ * @dev Extends ERC20Permit and TokenMock for testing purposes, incorporating permit functionality.
11
+ * This contract simplifies the testing of ERC20 tokens with permit capabilities by allowing easy setup of initial states.
12
+ */
8
13
  contract ERC20PermitMock is ERC20Permit, TokenMock {
14
+ /**
15
+ * @dev Creates an instance of `ERC20PermitMock` with specified token details and initial token distribution.
16
+ * @param name Name of the ERC20 token.
17
+ * @param symbol Symbol of the ERC20 token.
18
+ * @param initialAccount Address to receive the initial token supply.
19
+ * @param initialBalance Amount of tokens to mint to the `initialAccount`.
20
+ */
9
21
  constructor(
10
22
  string memory name,
11
23
  string memory symbol,
@@ -0,0 +1,17 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity ^0.8.25;
4
+
5
+ import "../mixins/SelfdestructEthSender.sol";
6
+
7
+ contract SelfdestructEthSenderMock is SelfdestructEthSender {
8
+ error ETHTransferFailed();
9
+
10
+ receive() external payable {}
11
+
12
+ function transferBalance(address payable receiver) external payable {
13
+ // solhint-disable-next-line avoid-low-level-calls
14
+ (bool success, ) = receiver.call{value: address(this).balance}("");
15
+ if (!success) revert ETHTransferFailed();
16
+ }
17
+ }
@@ -5,9 +5,20 @@ pragma solidity ^0.8.0;
5
5
  import "@openzeppelin/contracts/access/Ownable.sol";
6
6
  import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";
7
7
 
8
+ /**
9
+ * @title TokenCustomDecimalsMock
10
+ * @dev Extends ERC20Permit token with custom number of decimals and only owner access to `mint` and `burn` functionality.
11
+ */
8
12
  contract TokenCustomDecimalsMock is ERC20Permit, Ownable {
9
13
  uint8 internal immutable _DECIMALS;
10
14
 
15
+ /**
16
+ * @dev Sets up the ERC20 token with a name, symbol, initial amount to mint, and custom decimals.
17
+ * @param name Name of the token.
18
+ * @param symbol Symbol of the token.
19
+ * @param amount Initial amount of tokens to mint to the owner.
20
+ * @param decimals_ Custom number of decimal places for the token.
21
+ */
11
22
  constructor(
12
23
  string memory name,
13
24
  string memory symbol,
@@ -18,19 +29,29 @@ contract TokenCustomDecimalsMock is ERC20Permit, Ownable {
18
29
  _DECIMALS = decimals_;
19
30
  }
20
31
 
32
+ /**
33
+ * @notice Mints tokens to a specified account, callable only by the owner.
34
+ * @param account The address to mint tokens to.
35
+ * @param amount The amount of tokens to mint.
36
+ */
21
37
  function mint(address account, uint256 amount) external onlyOwner {
22
38
  _mint(account, amount);
23
39
  }
24
40
 
41
+ /**
42
+ * @notice Burns tokens from a specified account, callable only by the owner.
43
+ * @param account The address to burn tokens from.
44
+ * @param amount The amount of tokens to burn.
45
+ */
25
46
  function burn(address account, uint256 amount) external onlyOwner {
26
47
  _burn(account, amount);
27
48
  }
28
49
 
50
+ /**
51
+ * @dev Returns the number of decimal places of the token.
52
+ * @return Number of decimal places.
53
+ */
29
54
  function decimals() public view virtual override returns (uint8) {
30
55
  return _DECIMALS;
31
56
  }
32
-
33
- function getChainId() external view returns (uint256) {
34
- return block.chainid;
35
- }
36
57
  }