arr00-testing-oz-contracts 0.0.0 → 5.8.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 (507) hide show
  1. package/README.md +121 -0
  2. package/access/AccessControl.sol +206 -0
  3. package/access/IAccessControl.sol +98 -0
  4. package/access/Ownable.sol +100 -0
  5. package/access/Ownable2Step.sol +67 -0
  6. package/access/extensions/AccessControlDefaultAdminRules.sol +372 -0
  7. package/access/extensions/AccessControlEnumerable.sol +81 -0
  8. package/access/extensions/IAccessControlDefaultAdminRules.sol +192 -0
  9. package/access/extensions/IAccessControlEnumerable.sol +31 -0
  10. package/access/manager/AccessManaged.sol +118 -0
  11. package/access/manager/AccessManager.sol +781 -0
  12. package/access/manager/AuthorityUtils.sol +36 -0
  13. package/access/manager/IAccessManaged.sol +32 -0
  14. package/access/manager/IAccessManager.sol +410 -0
  15. package/access/manager/IAuthority.sol +14 -0
  16. package/account/Account.sol +151 -0
  17. package/account/extensions/draft-AccountERC7579.sol +430 -0
  18. package/account/extensions/draft-AccountERC7579Hooked.sol +113 -0
  19. package/account/extensions/draft-ERC7821.sol +70 -0
  20. package/account/paymaster/Paymaster.sol +170 -0
  21. package/account/paymaster/extensions/PaymasterERC20.sol +394 -0
  22. package/account/paymaster/extensions/PaymasterERC20Guarantor.sol +190 -0
  23. package/account/paymaster/extensions/PaymasterERC721Owner.sol +54 -0
  24. package/account/paymaster/extensions/PaymasterSigner.sol +125 -0
  25. package/account/utils/EIP7702Utils.sol +25 -0
  26. package/account/utils/ERC4337Utils.sol +317 -0
  27. package/account/utils/draft-ERC7579Utils.sol +314 -0
  28. package/build/contracts/AbstractSigner.json +13 -0
  29. package/build/contracts/AccessControl.json +239 -0
  30. package/build/contracts/AccessControlDefaultAdminRules.json +467 -0
  31. package/build/contracts/AccessControlEnumerable.json +301 -0
  32. package/build/contracts/AccessManaged.json +104 -0
  33. package/build/contracts/AccessManager.json +1189 -0
  34. package/build/contracts/Account.json +150 -0
  35. package/build/contracts/AccountERC7579.json +515 -0
  36. package/build/contracts/AccountERC7579Hooked.json +539 -0
  37. package/build/contracts/Accumulators.json +13 -0
  38. package/build/contracts/Address.json +25 -0
  39. package/build/contracts/Arrays.json +13 -0
  40. package/build/contracts/AuthorityUtils.json +13 -0
  41. package/build/contracts/Base58.json +25 -0
  42. package/build/contracts/Base64.json +25 -0
  43. package/build/contracts/BeaconProxy.json +97 -0
  44. package/build/contracts/BitMaps.json +13 -0
  45. package/build/contracts/BlockHeader.json +25 -0
  46. package/build/contracts/Blockhash.json +13 -0
  47. package/build/contracts/BridgeERC1155.json +508 -0
  48. package/build/contracts/BridgeERC20.json +260 -0
  49. package/build/contracts/BridgeERC721.json +270 -0
  50. package/build/contracts/BridgeERC7802.json +249 -0
  51. package/build/contracts/BridgeFungible.json +236 -0
  52. package/build/contracts/BridgeMultiToken.json +236 -0
  53. package/build/contracts/BridgeNonFungible.json +212 -0
  54. package/build/contracts/Bytes.json +13 -0
  55. package/build/contracts/CAIP10.json +13 -0
  56. package/build/contracts/CAIP2.json +13 -0
  57. package/build/contracts/Calldata.json +13 -0
  58. package/build/contracts/Checkpoints.json +19 -0
  59. package/build/contracts/CircularBuffer.json +19 -0
  60. package/build/contracts/Clones.json +19 -0
  61. package/build/contracts/Comparators.json +13 -0
  62. package/build/contracts/Context.json +13 -0
  63. package/build/contracts/Create2.json +19 -0
  64. package/build/contracts/Create3.json +19 -0
  65. package/build/contracts/CrosschainLinked.json +145 -0
  66. package/build/contracts/CrosschainRemoteExecutor.json +199 -0
  67. package/build/contracts/DoubleEndedQueue.json +13 -0
  68. package/build/contracts/ECDSA.json +41 -0
  69. package/build/contracts/EIP712.json +79 -0
  70. package/build/contracts/EIP7702Utils.json +13 -0
  71. package/build/contracts/ERC1155.json +428 -0
  72. package/build/contracts/ERC1155Burnable.json +474 -0
  73. package/build/contracts/ERC1155Crosschain.json +796 -0
  74. package/build/contracts/ERC1155Holder.json +111 -0
  75. package/build/contracts/ERC1155Pausable.json +477 -0
  76. package/build/contracts/ERC1155Supply.json +479 -0
  77. package/build/contracts/ERC1155URIStorage.json +428 -0
  78. package/build/contracts/ERC1155Utils.json +13 -0
  79. package/build/contracts/ERC1363.json +585 -0
  80. package/build/contracts/ERC1363Utils.json +36 -0
  81. package/build/contracts/ERC165.json +33 -0
  82. package/build/contracts/ERC165Checker.json +13 -0
  83. package/build/contracts/ERC1967Clones.json +13 -0
  84. package/build/contracts/ERC1967Proxy.json +84 -0
  85. package/build/contracts/ERC1967Utils.json +52 -0
  86. package/build/contracts/ERC20.json +322 -0
  87. package/build/contracts/ERC20Bridgeable.json +427 -0
  88. package/build/contracts/ERC20Burnable.json +353 -0
  89. package/build/contracts/ERC20Capped.json +362 -0
  90. package/build/contracts/ERC20Crosschain.json +573 -0
  91. package/build/contracts/ERC20FlashMint.json +432 -0
  92. package/build/contracts/ERC20Pausable.json +371 -0
  93. package/build/contracts/ERC20Permit.json +532 -0
  94. package/build/contracts/ERC20TemporaryApproval.json +346 -0
  95. package/build/contracts/ERC20TransferAuthorization.json +836 -0
  96. package/build/contracts/ERC20Votes.json +781 -0
  97. package/build/contracts/ERC20Wrapper.json +405 -0
  98. package/build/contracts/ERC2771Context.json +46 -0
  99. package/build/contracts/ERC2771Forwarder.json +439 -0
  100. package/build/contracts/ERC2981.json +126 -0
  101. package/build/contracts/ERC3009.json +668 -0
  102. package/build/contracts/ERC4337Utils.json +13 -0
  103. package/build/contracts/ERC4626.json +807 -0
  104. package/build/contracts/ERC6372Utils.json +19 -0
  105. package/build/contracts/ERC6909.json +415 -0
  106. package/build/contracts/ERC6909ContentURI.json +472 -0
  107. package/build/contracts/ERC6909Metadata.json +529 -0
  108. package/build/contracts/ERC6909TokenSupply.json +434 -0
  109. package/build/contracts/ERC721.json +447 -0
  110. package/build/contracts/ERC721Burnable.json +460 -0
  111. package/build/contracts/ERC721Consecutive.json +509 -0
  112. package/build/contracts/ERC721Crosschain.json +674 -0
  113. package/build/contracts/ERC721Enumerable.json +524 -0
  114. package/build/contracts/ERC721Holder.json +48 -0
  115. package/build/contracts/ERC721Pausable.json +496 -0
  116. package/build/contracts/ERC721Royalty.json +540 -0
  117. package/build/contracts/ERC721URIStorage.json +479 -0
  118. package/build/contracts/ERC721Utils.json +13 -0
  119. package/build/contracts/ERC721Votes.json +835 -0
  120. package/build/contracts/ERC721Wrapper.json +553 -0
  121. package/build/contracts/ERC7579Utils.json +119 -0
  122. package/build/contracts/ERC7739.json +103 -0
  123. package/build/contracts/ERC7739Utils.json +13 -0
  124. package/build/contracts/ERC7786Recipient.json +59 -0
  125. package/build/contracts/ERC7821.json +112 -0
  126. package/build/contracts/ERC7913P256Verifier.json +43 -0
  127. package/build/contracts/ERC7913RSAVerifier.json +43 -0
  128. package/build/contracts/ERC7913WebAuthnVerifier.json +43 -0
  129. package/build/contracts/EnumerableMap.json +36 -0
  130. package/build/contracts/EnumerableSet.json +13 -0
  131. package/build/contracts/Errors.json +51 -0
  132. package/build/contracts/Governor.json +1381 -0
  133. package/build/contracts/GovernorCountingFractional.json +1455 -0
  134. package/build/contracts/GovernorCountingOverridable.json +1612 -0
  135. package/build/contracts/GovernorCountingSimple.json +1410 -0
  136. package/build/contracts/GovernorCrosschain.json +1409 -0
  137. package/build/contracts/GovernorNoncesKeyed.json +1405 -0
  138. package/build/contracts/GovernorPreventLateQuorum.json +1461 -0
  139. package/build/contracts/GovernorProposalGuardian.json +1426 -0
  140. package/build/contracts/GovernorSequentialProposalId.json +1399 -0
  141. package/build/contracts/GovernorSettings.json +1477 -0
  142. package/build/contracts/GovernorStorage.json +1506 -0
  143. package/build/contracts/GovernorSuperQuorum.json +1429 -0
  144. package/build/contracts/GovernorTimelockAccess.json +1582 -0
  145. package/build/contracts/GovernorTimelockCompound.json +1449 -0
  146. package/build/contracts/GovernorTimelockControl.json +1426 -0
  147. package/build/contracts/GovernorVotes.json +1399 -0
  148. package/build/contracts/GovernorVotesQuorumFraction.json +1497 -0
  149. package/build/contracts/GovernorVotesSuperQuorumFraction.json +1657 -0
  150. package/build/contracts/Hashes.json +13 -0
  151. package/build/contracts/Heap.json +13 -0
  152. package/build/contracts/IAccessControl.json +207 -0
  153. package/build/contracts/IAccessControlDefaultAdminRules.json +406 -0
  154. package/build/contracts/IAccessControlEnumerable.json +250 -0
  155. package/build/contracts/IAccessManaged.json +104 -0
  156. package/build/contracts/IAccessManager.json +1085 -0
  157. package/build/contracts/IAccount.json +90 -0
  158. package/build/contracts/IAccountExecute.json +79 -0
  159. package/build/contracts/IAggregator.json +211 -0
  160. package/build/contracts/IAuthority.json +43 -0
  161. package/build/contracts/IBeacon.json +27 -0
  162. package/build/contracts/ICompoundTimelock.json +427 -0
  163. package/build/contracts/IERC1155.json +307 -0
  164. package/build/contracts/IERC1155Errors.json +116 -0
  165. package/build/contracts/IERC1155MetadataURI.json +326 -0
  166. package/build/contracts/IERC1155Receiver.json +111 -0
  167. package/build/contracts/IERC1271.json +38 -0
  168. package/build/contracts/IERC1363.json +385 -0
  169. package/build/contracts/IERC1363Receiver.json +48 -0
  170. package/build/contracts/IERC1363Spender.json +43 -0
  171. package/build/contracts/IERC165.json +33 -0
  172. package/build/contracts/IERC1820Implementer.json +38 -0
  173. package/build/contracts/IERC1820Registry.json +227 -0
  174. package/build/contracts/IERC1822Proxiable.json +27 -0
  175. package/build/contracts/IERC1967.json +59 -0
  176. package/build/contracts/IERC20.json +197 -0
  177. package/build/contracts/IERC20Errors.json +100 -0
  178. package/build/contracts/IERC20Metadata.json +236 -0
  179. package/build/contracts/IERC20Permit.json +89 -0
  180. package/build/contracts/IERC2309.json +45 -0
  181. package/build/contracts/IERC2612.json +89 -0
  182. package/build/contracts/IERC2981.json +62 -0
  183. package/build/contracts/IERC3009.json +163 -0
  184. package/build/contracts/IERC3009Cancel.json +66 -0
  185. package/build/contracts/IERC3156FlashBorrower.json +53 -0
  186. package/build/contracts/IERC3156FlashLender.json +91 -0
  187. package/build/contracts/IERC4626.json +626 -0
  188. package/build/contracts/IERC4906.json +331 -0
  189. package/build/contracts/IERC5267.json +63 -0
  190. package/build/contracts/IERC5313.json +27 -0
  191. package/build/contracts/IERC5805.json +233 -0
  192. package/build/contracts/IERC6372.json +40 -0
  193. package/build/contracts/IERC6909.json +319 -0
  194. package/build/contracts/IERC6909ContentURI.json +351 -0
  195. package/build/contracts/IERC6909Metadata.json +376 -0
  196. package/build/contracts/IERC6909TokenSupply.json +338 -0
  197. package/build/contracts/IERC721.json +299 -0
  198. package/build/contracts/IERC721Enumerable.json +355 -0
  199. package/build/contracts/IERC721Errors.json +117 -0
  200. package/build/contracts/IERC721Metadata.json +344 -0
  201. package/build/contracts/IERC721Receiver.json +48 -0
  202. package/build/contracts/IERC7579AccountConfig.json +65 -0
  203. package/build/contracts/IERC7579Execution.json +56 -0
  204. package/build/contracts/IERC7579Hook.json +101 -0
  205. package/build/contracts/IERC7579Module.json +59 -0
  206. package/build/contracts/IERC7579ModuleConfig.json +127 -0
  207. package/build/contracts/IERC7579Validator.json +159 -0
  208. package/build/contracts/IERC7674.json +221 -0
  209. package/build/contracts/IERC7751.json +40 -0
  210. package/build/contracts/IERC777.json +405 -0
  211. package/build/contracts/IERC777Recipient.json +52 -0
  212. package/build/contracts/IERC777Sender.json +52 -0
  213. package/build/contracts/IERC7786GatewaySource.json +116 -0
  214. package/build/contracts/IERC7786Recipient.json +43 -0
  215. package/build/contracts/IERC7802.json +119 -0
  216. package/build/contracts/IERC7821.json +51 -0
  217. package/build/contracts/IERC7913SignatureVerifier.json +43 -0
  218. package/build/contracts/IEntryPoint.json +305 -0
  219. package/build/contracts/IEntryPointExtra.json +80 -0
  220. package/build/contracts/IEntryPointNonces.json +38 -0
  221. package/build/contracts/IEntryPointStake.json +97 -0
  222. package/build/contracts/IGovernor.json +1095 -0
  223. package/build/contracts/IPaymaster.json +123 -0
  224. package/build/contracts/ITransparentUpgradeableProxy.json +77 -0
  225. package/build/contracts/IVotes.json +207 -0
  226. package/build/contracts/Initializable.json +37 -0
  227. package/build/contracts/InteroperableAddress.json +30 -0
  228. package/build/contracts/LowLevelCall.json +13 -0
  229. package/build/contracts/Math.json +13 -0
  230. package/build/contracts/Memory.json +13 -0
  231. package/build/contracts/MerkleProof.json +19 -0
  232. package/build/contracts/MerkleTree.json +35 -0
  233. package/build/contracts/MessageHashUtils.json +19 -0
  234. package/build/contracts/MultiSignerERC7913.json +176 -0
  235. package/build/contracts/MultiSignerERC7913Weighted.json +264 -0
  236. package/build/contracts/Multicall.json +49 -0
  237. package/build/contracts/Nonces.json +49 -0
  238. package/build/contracts/NoncesKeyed.json +73 -0
  239. package/build/contracts/Ownable.json +88 -0
  240. package/build/contracts/Ownable2Step.json +127 -0
  241. package/build/contracts/P256.json +13 -0
  242. package/build/contracts/Packing.json +19 -0
  243. package/build/contracts/Panic.json +13 -0
  244. package/build/contracts/Pausable.json +63 -0
  245. package/build/contracts/Paymaster.json +147 -0
  246. package/build/contracts/PaymasterERC20.json +209 -0
  247. package/build/contracts/PaymasterERC20Guarantor.json +234 -0
  248. package/build/contracts/PaymasterERC721Owner.json +160 -0
  249. package/build/contracts/PaymasterSigner.json +212 -0
  250. package/build/contracts/Proxy.json +18 -0
  251. package/build/contracts/ProxyAdmin.json +135 -0
  252. package/build/contracts/RLP.json +19 -0
  253. package/build/contracts/RSA.json +13 -0
  254. package/build/contracts/RateLimiter.json +19 -0
  255. package/build/contracts/ReentrancyGuard.json +19 -0
  256. package/build/contracts/ReentrancyGuardTransient.json +19 -0
  257. package/build/contracts/RelayedCall.json +13 -0
  258. package/build/contracts/SafeCast.json +68 -0
  259. package/build/contracts/SafeERC20.json +46 -0
  260. package/build/contracts/ShortStrings.json +30 -0
  261. package/build/contracts/SignatureChecker.json +13 -0
  262. package/build/contracts/SignedMath.json +13 -0
  263. package/build/contracts/SignerECDSA.json +27 -0
  264. package/build/contracts/SignerEIP7702.json +13 -0
  265. package/build/contracts/SignerERC7913.json +27 -0
  266. package/build/contracts/SignerP256.json +48 -0
  267. package/build/contracts/SignerRSA.json +32 -0
  268. package/build/contracts/SignerWebAuthn.json +48 -0
  269. package/build/contracts/SimulateCall.json +13 -0
  270. package/build/contracts/SlotDerivation.json +13 -0
  271. package/build/contracts/StorageSlot.json +13 -0
  272. package/build/contracts/Strings.json +40 -0
  273. package/build/contracts/Time.json +13 -0
  274. package/build/contracts/TimelockController.json +1010 -0
  275. package/build/contracts/TransientSlot.json +13 -0
  276. package/build/contracts/TransparentUpgradeableProxy.json +131 -0
  277. package/build/contracts/TrieProof.json +25 -0
  278. package/build/contracts/UUPSUpgradeable.json +119 -0
  279. package/build/contracts/UpgradeableBeacon.json +154 -0
  280. package/build/contracts/VestingWallet.json +364 -0
  281. package/build/contracts/VestingWalletCliff.json +367 -0
  282. package/build/contracts/Votes.json +402 -0
  283. package/build/contracts/VotesExtended.json +450 -0
  284. package/build/contracts/WebAuthn.json +13 -0
  285. package/crosschain/CrosschainLinked.sol +114 -0
  286. package/crosschain/CrosschainRemoteExecutor.sol +99 -0
  287. package/crosschain/ERC7786Recipient.sol +66 -0
  288. package/crosschain/bridges/BridgeERC1155.sol +131 -0
  289. package/crosschain/bridges/BridgeERC20.sol +42 -0
  290. package/crosschain/bridges/BridgeERC721.sol +62 -0
  291. package/crosschain/bridges/BridgeERC7802.sol +34 -0
  292. package/crosschain/bridges/abstract/BridgeFungible.sol +86 -0
  293. package/crosschain/bridges/abstract/BridgeMultiToken.sol +99 -0
  294. package/crosschain/bridges/abstract/BridgeNonFungible.sol +79 -0
  295. package/finance/VestingWallet.sol +160 -0
  296. package/finance/VestingWalletCliff.sol +55 -0
  297. package/governance/Governor.sol +825 -0
  298. package/governance/IGovernor.sol +454 -0
  299. package/governance/TimelockController.sol +470 -0
  300. package/governance/extensions/GovernorCountingFractional.sol +190 -0
  301. package/governance/extensions/GovernorCountingOverridable.sol +226 -0
  302. package/governance/extensions/GovernorCountingSimple.sol +96 -0
  303. package/governance/extensions/GovernorCrosschain.sol +31 -0
  304. package/governance/extensions/GovernorNoncesKeyed.sol +91 -0
  305. package/governance/extensions/GovernorPreventLateQuorum.sol +119 -0
  306. package/governance/extensions/GovernorProposalGuardian.sol +59 -0
  307. package/governance/extensions/GovernorSequentialProposalId.sol +75 -0
  308. package/governance/extensions/GovernorSettings.sol +106 -0
  309. package/governance/extensions/GovernorStorage.sol +134 -0
  310. package/governance/extensions/GovernorSuperQuorum.sol +59 -0
  311. package/governance/extensions/GovernorTimelockAccess.sol +346 -0
  312. package/governance/extensions/GovernorTimelockCompound.sol +162 -0
  313. package/governance/extensions/GovernorTimelockControl.sol +167 -0
  314. package/governance/extensions/GovernorVotes.sol +64 -0
  315. package/governance/extensions/GovernorVotesQuorumFraction.sol +113 -0
  316. package/governance/extensions/GovernorVotesSuperQuorumFraction.sol +135 -0
  317. package/governance/utils/IVotes.sol +60 -0
  318. package/governance/utils/Votes.sol +245 -0
  319. package/governance/utils/VotesExtended.sol +85 -0
  320. package/interfaces/IERC1155.sol +6 -0
  321. package/interfaces/IERC1155MetadataURI.sol +6 -0
  322. package/interfaces/IERC1155Receiver.sol +6 -0
  323. package/interfaces/IERC1271.sol +17 -0
  324. package/interfaces/IERC1363.sol +86 -0
  325. package/interfaces/IERC1363Receiver.sol +32 -0
  326. package/interfaces/IERC1363Spender.sol +26 -0
  327. package/interfaces/IERC165.sol +6 -0
  328. package/interfaces/IERC1820Implementer.sol +20 -0
  329. package/interfaces/IERC1820Registry.sol +112 -0
  330. package/interfaces/IERC1967.sol +24 -0
  331. package/interfaces/IERC20.sol +6 -0
  332. package/interfaces/IERC20Metadata.sol +6 -0
  333. package/interfaces/IERC2309.sol +19 -0
  334. package/interfaces/IERC2612.sol +8 -0
  335. package/interfaces/IERC2981.sol +26 -0
  336. package/interfaces/IERC3156.sol +7 -0
  337. package/interfaces/IERC3156FlashBorrower.sol +27 -0
  338. package/interfaces/IERC3156FlashLender.sol +41 -0
  339. package/interfaces/IERC4337.sol +255 -0
  340. package/interfaces/IERC4626.sol +230 -0
  341. package/interfaces/IERC4906.sol +20 -0
  342. package/interfaces/IERC5267.sol +28 -0
  343. package/interfaces/IERC5313.sol +16 -0
  344. package/interfaces/IERC5805.sol +9 -0
  345. package/interfaces/IERC6093.sol +162 -0
  346. package/interfaces/IERC6372.sol +19 -0
  347. package/interfaces/IERC6909.sol +131 -0
  348. package/interfaces/IERC721.sol +6 -0
  349. package/interfaces/IERC721Enumerable.sol +6 -0
  350. package/interfaces/IERC721Metadata.sol +6 -0
  351. package/interfaces/IERC721Receiver.sol +6 -0
  352. package/interfaces/IERC7751.sol +12 -0
  353. package/interfaces/IERC777.sol +200 -0
  354. package/interfaces/IERC777Recipient.sol +35 -0
  355. package/interfaces/IERC777Sender.sol +35 -0
  356. package/interfaces/IERC7786.sol +64 -0
  357. package/interfaces/IERC7913.sol +18 -0
  358. package/interfaces/draft-IERC1822.sol +20 -0
  359. package/interfaces/draft-IERC3009.sol +87 -0
  360. package/interfaces/draft-IERC7579.sol +227 -0
  361. package/interfaces/draft-IERC7674.sol +17 -0
  362. package/interfaces/draft-IERC7802.sol +32 -0
  363. package/interfaces/draft-IERC7821.sol +44 -0
  364. package/metatx/ERC2771Context.sol +90 -0
  365. package/metatx/ERC2771Forwarder.sol +376 -0
  366. package/package.json +29 -1
  367. package/proxy/Clones.sol +294 -0
  368. package/proxy/ERC1967/ERC1967Clones.sol +219 -0
  369. package/proxy/ERC1967/ERC1967Proxy.sol +62 -0
  370. package/proxy/ERC1967/ERC1967Utils.sol +177 -0
  371. package/proxy/Proxy.sol +69 -0
  372. package/proxy/beacon/BeaconProxy.sol +57 -0
  373. package/proxy/beacon/IBeacon.sol +16 -0
  374. package/proxy/beacon/UpgradeableBeacon.sol +70 -0
  375. package/proxy/transparent/ProxyAdmin.sol +45 -0
  376. package/proxy/transparent/TransparentUpgradeableProxy.sol +118 -0
  377. package/proxy/utils/Initializable.sol +238 -0
  378. package/proxy/utils/UUPSUpgradeable.sol +148 -0
  379. package/token/ERC1155/ERC1155.sol +417 -0
  380. package/token/ERC1155/IERC1155.sol +123 -0
  381. package/token/ERC1155/IERC1155Receiver.sol +59 -0
  382. package/token/ERC1155/extensions/ERC1155Burnable.sol +22 -0
  383. package/token/ERC1155/extensions/ERC1155Crosschain.sol +87 -0
  384. package/token/ERC1155/extensions/ERC1155Pausable.sol +38 -0
  385. package/token/ERC1155/extensions/ERC1155Supply.sol +88 -0
  386. package/token/ERC1155/extensions/ERC1155URIStorage.sol +58 -0
  387. package/token/ERC1155/extensions/IERC1155MetadataURI.sol +20 -0
  388. package/token/ERC1155/utils/ERC1155Holder.sol +42 -0
  389. package/token/ERC1155/utils/ERC1155Utils.sol +88 -0
  390. package/token/ERC20/ERC20.sol +305 -0
  391. package/token/ERC20/IERC20.sol +79 -0
  392. package/token/ERC20/extensions/ERC1363.sol +135 -0
  393. package/token/ERC20/extensions/ERC20Burnable.sol +38 -0
  394. package/token/ERC20/extensions/ERC20Capped.sol +54 -0
  395. package/token/ERC20/extensions/ERC20Crosschain.sol +39 -0
  396. package/token/ERC20/extensions/ERC20FlashMint.sol +130 -0
  397. package/token/ERC20/extensions/ERC20Pausable.sol +33 -0
  398. package/token/ERC20/extensions/ERC20Permit.sol +77 -0
  399. package/token/ERC20/extensions/ERC20TransferAuthorization.sol +91 -0
  400. package/token/ERC20/extensions/ERC20Votes.sol +83 -0
  401. package/token/ERC20/extensions/ERC20Wrapper.sol +93 -0
  402. package/token/ERC20/extensions/ERC4626.sol +304 -0
  403. package/token/ERC20/extensions/IERC20Metadata.sol +26 -0
  404. package/token/ERC20/extensions/IERC20Permit.sol +90 -0
  405. package/token/ERC20/extensions/draft-ERC20Bridgeable.sol +51 -0
  406. package/token/ERC20/extensions/draft-ERC20TemporaryApproval.sol +119 -0
  407. package/token/ERC20/extensions/draft-ERC3009.sol +152 -0
  408. package/token/ERC20/utils/ERC1363Utils.sol +95 -0
  409. package/token/ERC20/utils/SafeERC20.sol +292 -0
  410. package/token/ERC6909/ERC6909.sol +224 -0
  411. package/token/ERC6909/extensions/ERC6909ContentURI.sol +59 -0
  412. package/token/ERC6909/extensions/ERC6909Metadata.sol +83 -0
  413. package/token/ERC6909/extensions/ERC6909TokenSupply.sol +41 -0
  414. package/token/ERC721/ERC721.sol +433 -0
  415. package/token/ERC721/IERC721.sol +135 -0
  416. package/token/ERC721/IERC721Receiver.sol +28 -0
  417. package/token/ERC721/extensions/ERC721Burnable.sol +26 -0
  418. package/token/ERC721/extensions/ERC721Consecutive.sol +176 -0
  419. package/token/ERC721/extensions/ERC721Crosschain.sol +38 -0
  420. package/token/ERC721/extensions/ERC721Enumerable.sol +165 -0
  421. package/token/ERC721/extensions/ERC721Pausable.sol +37 -0
  422. package/token/ERC721/extensions/ERC721Royalty.sol +26 -0
  423. package/token/ERC721/extensions/ERC721URIStorage.sol +62 -0
  424. package/token/ERC721/extensions/ERC721Votes.sol +47 -0
  425. package/token/ERC721/extensions/ERC721Wrapper.sol +102 -0
  426. package/token/ERC721/extensions/IERC721Enumerable.sol +29 -0
  427. package/token/ERC721/extensions/IERC721Metadata.sol +27 -0
  428. package/token/ERC721/utils/ERC721Holder.sol +26 -0
  429. package/token/ERC721/utils/ERC721Utils.sol +50 -0
  430. package/token/common/ERC2981.sol +140 -0
  431. package/utils/Address.sol +167 -0
  432. package/utils/Arrays.sol +905 -0
  433. package/utils/Base58.sol +240 -0
  434. package/utils/Base64.sol +234 -0
  435. package/utils/BlockHeader.sol +312 -0
  436. package/utils/Blockhash.sol +54 -0
  437. package/utils/Bytes.sol +329 -0
  438. package/utils/CAIP10.sol +54 -0
  439. package/utils/CAIP2.sol +51 -0
  440. package/utils/Calldata.sol +25 -0
  441. package/utils/Comparators.sol +19 -0
  442. package/utils/Context.sol +28 -0
  443. package/utils/Create2.sol +91 -0
  444. package/utils/Create3.sol +133 -0
  445. package/utils/ERC6372Utils.sol +53 -0
  446. package/utils/Errors.sol +34 -0
  447. package/utils/LowLevelCall.sol +127 -0
  448. package/utils/Memory.sol +151 -0
  449. package/utils/Multicall.sol +37 -0
  450. package/utils/Nonces.sol +47 -0
  451. package/utils/NoncesKeyed.sol +75 -0
  452. package/utils/Packing.sol +1656 -0
  453. package/utils/Panic.sol +57 -0
  454. package/utils/Pausable.sol +112 -0
  455. package/utils/RLP.sol +487 -0
  456. package/utils/RateLimiter.sol +310 -0
  457. package/utils/ReentrancyGuard.sol +119 -0
  458. package/utils/ReentrancyGuardTransient.sol +84 -0
  459. package/utils/RelayedCall.sol +145 -0
  460. package/utils/ShortStrings.sol +122 -0
  461. package/utils/SimulateCall.sol +114 -0
  462. package/utils/SlotDerivation.sol +155 -0
  463. package/utils/StorageSlot.sol +143 -0
  464. package/utils/Strings.sol +532 -0
  465. package/utils/TransientSlot.sol +183 -0
  466. package/utils/cryptography/ECDSA.sol +284 -0
  467. package/utils/cryptography/EIP712.sol +168 -0
  468. package/utils/cryptography/Hashes.sol +31 -0
  469. package/utils/cryptography/MerkleProof.sol +510 -0
  470. package/utils/cryptography/MessageHashUtils.sol +228 -0
  471. package/utils/cryptography/P256.sol +409 -0
  472. package/utils/cryptography/RSA.sol +159 -0
  473. package/utils/cryptography/SignatureChecker.sol +199 -0
  474. package/utils/cryptography/TrieProof.sol +256 -0
  475. package/utils/cryptography/WebAuthn.sol +269 -0
  476. package/utils/cryptography/draft-ERC7739Utils.sol +215 -0
  477. package/utils/cryptography/signers/AbstractSigner.sol +23 -0
  478. package/utils/cryptography/signers/MultiSignerERC7913.sol +336 -0
  479. package/utils/cryptography/signers/MultiSignerERC7913Weighted.sol +208 -0
  480. package/utils/cryptography/signers/SignerECDSA.sol +56 -0
  481. package/utils/cryptography/signers/SignerEIP7702.sol +25 -0
  482. package/utils/cryptography/signers/SignerERC7913.sol +63 -0
  483. package/utils/cryptography/signers/SignerP256.sol +64 -0
  484. package/utils/cryptography/signers/SignerRSA.sol +65 -0
  485. package/utils/cryptography/signers/SignerWebAuthn.sol +45 -0
  486. package/utils/cryptography/signers/draft-ERC7739.sol +99 -0
  487. package/utils/cryptography/verifiers/ERC7913P256Verifier.sol +29 -0
  488. package/utils/cryptography/verifiers/ERC7913RSAVerifier.sol +23 -0
  489. package/utils/cryptography/verifiers/ERC7913WebAuthnVerifier.sol +45 -0
  490. package/utils/draft-InteroperableAddress.sol +245 -0
  491. package/utils/introspection/ERC165.sol +25 -0
  492. package/utils/introspection/ERC165Checker.sol +142 -0
  493. package/utils/introspection/IERC165.sol +25 -0
  494. package/utils/math/Math.sol +763 -0
  495. package/utils/math/SafeCast.sol +1162 -0
  496. package/utils/math/SignedMath.sol +68 -0
  497. package/utils/structs/Accumulators.sol +135 -0
  498. package/utils/structs/BitMaps.sol +61 -0
  499. package/utils/structs/Checkpoints.sol +881 -0
  500. package/utils/structs/CircularBuffer.sol +152 -0
  501. package/utils/structs/DoubleEndedQueue.sol +280 -0
  502. package/utils/structs/EnumerableMap.sol +1870 -0
  503. package/utils/structs/EnumerableSet.sol +1177 -0
  504. package/utils/structs/Heap.sol +259 -0
  505. package/utils/structs/MerkleTree.sol +267 -0
  506. package/utils/types/Time.sol +133 -0
  507. package/vendor/compound/ICompoundTimelock.sol +86 -0
@@ -0,0 +1,1177 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // OpenZeppelin Contracts (last updated v5.8.0) (utils/structs/EnumerableSet.sol)
3
+ // This file was procedurally generated from scripts/generate/templates/EnumerableSet.sol.eta.
4
+
5
+ pragma solidity ^0.8.24;
6
+
7
+ import {Arrays} from "../Arrays.sol";
8
+ import {Math} from "../math/Math.sol";
9
+
10
+ /**
11
+ * @dev Library for managing
12
+ * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
13
+ * types.
14
+ *
15
+ * Sets have the following properties:
16
+ *
17
+ * - Elements are added, removed, and checked for existence in constant time
18
+ * (O(1)).
19
+ * - Elements are enumerated in O(n). No guarantees are made on the ordering.
20
+ * - Set can be cleared (all elements removed) in O(n).
21
+ *
22
+ * ```solidity
23
+ * contract Example {
24
+ * // Add the library methods
25
+ * using EnumerableSet for EnumerableSet.AddressSet;
26
+ *
27
+ * // Declare a set state variable
28
+ * EnumerableSet.AddressSet private mySet;
29
+ * }
30
+ * ```
31
+ *
32
+ * The following types are supported:
33
+ *
34
+ * - `bytes32` (`Bytes32Set`) since v3.3.0
35
+ * - `address` (`AddressSet`) since v3.3.0
36
+ * - `uint256` (`UintSet`) since v3.3.0
37
+ * - `string` (`StringSet`) since v5.4.0
38
+ * - `bytes` (`BytesSet`) since v5.4.0
39
+ * - `bytes4` (`Bytes4Set`) since v5.6.0
40
+ *
41
+ * [WARNING]
42
+ * ====
43
+ * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
44
+ * unusable.
45
+ * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
46
+ *
47
+ * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
48
+ * array of EnumerableSet.
49
+ * ====
50
+ */
51
+ library EnumerableSet {
52
+ // To implement this library for multiple types with as little code
53
+ // repetition as possible, we write it in terms of a generic Set type with
54
+ // bytes32 values.
55
+ // The Set implementation uses private functions, and user-facing
56
+ // implementations (such as AddressSet) are just wrappers around the
57
+ // underlying Set.
58
+ // This means that we can only create new EnumerableSets for types that fit
59
+ // in bytes32.
60
+
61
+ struct Set {
62
+ // Storage of set values
63
+ bytes32[] _values;
64
+ // Position is the index of the value in the `values` array plus 1.
65
+ // Position 0 is used to mean a value is not in the set.
66
+ mapping(bytes32 value => uint256) _positions;
67
+ }
68
+
69
+ /**
70
+ * @dev Add a value to a set. O(1).
71
+ *
72
+ * Returns true if the value was added to the set, that is if it was not
73
+ * already present.
74
+ */
75
+ function _add(Set storage set, bytes32 value) private returns (bool) {
76
+ if (!_contains(set, value)) {
77
+ set._values.push(value);
78
+ // The value is stored at length-1, but we add 1 to all indexes
79
+ // and use 0 as a sentinel value
80
+ set._positions[value] = set._values.length;
81
+ return true;
82
+ } else {
83
+ return false;
84
+ }
85
+ }
86
+
87
+ /**
88
+ * @dev Removes a value from a set. O(1).
89
+ *
90
+ * Returns true if the value was removed from the set, that is if it was
91
+ * present.
92
+ */
93
+ function _remove(Set storage set, bytes32 value) private returns (bool) {
94
+ uint256 position = set._positions[value];
95
+
96
+ if (position != 0) {
97
+ _removeValueAt(set, value, position - 1);
98
+ return true;
99
+ } else {
100
+ return false;
101
+ }
102
+ }
103
+
104
+ /**
105
+ * @dev Removes the value stored at position `index` from a set. O(1).
106
+ *
107
+ * Returns the removed value.
108
+ *
109
+ * This is cheaper than {remove} when the caller already knows the index, because it skips the position lookup
110
+ * that {remove} performs.
111
+ *
112
+ * Note that there are no guarantees on the ordering of values inside the array, and it may change when more
113
+ * values are added or removed.
114
+ *
115
+ * Requirements:
116
+ *
117
+ * - `index` must be strictly less than {length}.
118
+ */
119
+ function _removeAt(Set storage set, uint256 index) private returns (bytes32 value) {
120
+ value = set._values[index];
121
+ _removeValueAt(set, value, index);
122
+ }
123
+
124
+ /**
125
+ * @dev Removes the value stored at position `index` from a set. O(1).
126
+ *
127
+ * To delete an element from the `_values` array in O(1), we swap the element to delete with the last one in the
128
+ * array, and then remove the last element (sometimes called as 'swap and pop'). This modifies the order of the
129
+ * array, as noted in {at}.
130
+ *
131
+ * IMPORTANT: This does not verify that `value` is the value currently stored at `index`. Callers must ensure
132
+ * both arguments are consistent, otherwise the set is left in a corrupted state.
133
+ *
134
+ * Requirements:
135
+ *
136
+ * - `index` must be strictly less than {length}.
137
+ */
138
+ function _removeValueAt(Set storage set, bytes32 value, uint256 index) private {
139
+ uint256 lastIndex = set._values.length - 1;
140
+
141
+ if (index != lastIndex) {
142
+ bytes32 lastValue = Arrays.unsafeAccess(set._values, lastIndex).value;
143
+
144
+ // Move the lastValue to the index where the value to delete is
145
+ Arrays.unsafeAccess(set._values, index).value = lastValue;
146
+ // Update the tracked position of the lastValue (that was just moved)
147
+ set._positions[lastValue] = index + 1;
148
+ }
149
+
150
+ // Delete the slot where the moved value was stored
151
+ set._values.pop();
152
+
153
+ // Delete the tracked position for the deleted slot
154
+ delete set._positions[value];
155
+ }
156
+
157
+ /**
158
+ * @dev Removes all the values from a set. O(n).
159
+ *
160
+ * WARNING: This function has an unbounded cost that scales with set size. Developers should keep in mind that
161
+ * using it may render the function uncallable if the set grows to the point where clearing it consumes too much
162
+ * gas to fit in a block.
163
+ */
164
+ function _clear(Set storage set) private {
165
+ uint256 len = _length(set);
166
+ for (uint256 i = 0; i < len; ++i) {
167
+ delete set._positions[Arrays.unsafeAccess(set._values, i).value];
168
+ }
169
+ Arrays.unsafeSetLength(set._values, 0);
170
+ }
171
+
172
+ /**
173
+ * @dev Returns true if the value is in the set. O(1).
174
+ */
175
+ function _contains(Set storage set, bytes32 value) private view returns (bool) {
176
+ return set._positions[value] != 0;
177
+ }
178
+
179
+ /**
180
+ * @dev Returns the number of values on the set. O(1).
181
+ */
182
+ function _length(Set storage set) private view returns (uint256) {
183
+ return set._values.length;
184
+ }
185
+
186
+ /**
187
+ * @dev Returns the value stored at position `index` in the set. O(1).
188
+ *
189
+ * Note that there are no guarantees on the ordering of values inside the
190
+ * array, and it may change when more values are added or removed.
191
+ *
192
+ * Requirements:
193
+ *
194
+ * - `index` must be strictly less than {length}.
195
+ */
196
+ function _pos(Set storage set, uint256 index) private view returns (bytes32) {
197
+ return set._values[index];
198
+ }
199
+
200
+ /**
201
+ * @dev Return the entire set in an array
202
+ *
203
+ * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
204
+ * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
205
+ * this function has an unbounded cost, and using it as part of a state-changing function may render the function
206
+ * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
207
+ */
208
+ function _values(Set storage set) private view returns (bytes32[] memory) {
209
+ return set._values;
210
+ }
211
+
212
+ /**
213
+ * @dev Return a slice of the set in an array
214
+ *
215
+ * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
216
+ * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
217
+ * this function has an unbounded cost, and using it as part of a state-changing function may render the function
218
+ * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
219
+ */
220
+ function _values(Set storage set, uint256 start, uint256 end) private view returns (bytes32[] memory) {
221
+ unchecked {
222
+ end = Math.min(end, _length(set));
223
+ start = Math.min(start, end);
224
+
225
+ uint256 len = end - start;
226
+ bytes32[] memory result = new bytes32[](len);
227
+ for (uint256 i = 0; i < len; ++i) {
228
+ result[i] = Arrays.unsafeAccess(set._values, start + i).value;
229
+ }
230
+ return result;
231
+ }
232
+ }
233
+
234
+ // Bytes32Set
235
+
236
+ struct Bytes32Set {
237
+ Set _inner;
238
+ }
239
+
240
+ /**
241
+ * @dev Add a value to a set. O(1).
242
+ *
243
+ * Returns true if the value was added to the set, that is if it was not
244
+ * already present.
245
+ */
246
+ function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
247
+ return _add(set._inner, value);
248
+ }
249
+
250
+ /**
251
+ * @dev Removes a value from a set. O(1).
252
+ *
253
+ * Returns true if the value was removed from the set, that is if it was
254
+ * present.
255
+ */
256
+ function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
257
+ return _remove(set._inner, value);
258
+ }
259
+
260
+ /**
261
+ * @dev Removes the value stored at position `index` from a set. O(1).
262
+ *
263
+ * Returns the removed value.
264
+ *
265
+ * This is cheaper than {remove} when the caller already knows the index, because it skips the position lookup
266
+ * that {remove} performs.
267
+ *
268
+ * Note that there are no guarantees on the ordering of values inside the array, and it may change when more
269
+ * values are added or removed.
270
+ *
271
+ * Requirements:
272
+ *
273
+ * - `index` must be strictly less than {length}.
274
+ */
275
+ function removeAt(Bytes32Set storage set, uint256 index) internal returns (bytes32) {
276
+ return _removeAt(set._inner, index);
277
+ }
278
+
279
+ /**
280
+ * @dev Removes all the values from a set. O(n).
281
+ *
282
+ * WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
283
+ * function uncallable if the set grows to the point where clearing it consumes too much gas to fit in a block.
284
+ */
285
+ function clear(Bytes32Set storage set) internal {
286
+ _clear(set._inner);
287
+ }
288
+
289
+ /**
290
+ * @dev Returns true if the value is in the set. O(1).
291
+ */
292
+ function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
293
+ return _contains(set._inner, value);
294
+ }
295
+
296
+ /**
297
+ * @dev Returns the number of values in the set. O(1).
298
+ */
299
+ function length(Bytes32Set storage set) internal view returns (uint256) {
300
+ return _length(set._inner);
301
+ }
302
+
303
+ /**
304
+ * @dev Returns the value stored at position `index` in the set. O(1).
305
+ *
306
+ * Note that there are no guarantees on the ordering of values inside the
307
+ * array, and it may change when more values are added or removed.
308
+ *
309
+ * Requirements:
310
+ *
311
+ * - `index` must be strictly less than {length}.
312
+ *
313
+ * IMPORTANT: Deprecated. This function's name clashes with a keyword scheduled for inclusion in Solidity. Developers
314
+ * should use {pos} instead.
315
+ */
316
+ function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
317
+ return pos(set, index);
318
+ }
319
+
320
+ /**
321
+ * @dev Returns the value stored at position `index` in the set. O(1).
322
+ *
323
+ * Note that there are no guarantees on the ordering of values inside the
324
+ * array, and it may change when more values are added or removed.
325
+ *
326
+ * Requirements:
327
+ *
328
+ * - `index` must be strictly less than {length}.
329
+ *
330
+ * Replacement of the deprecated {at} function.
331
+ */
332
+ function pos(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
333
+ return _pos(set._inner, index);
334
+ }
335
+
336
+ /**
337
+ * @dev Return the entire set in an array
338
+ *
339
+ * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
340
+ * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
341
+ * this function has an unbounded cost, and using it as part of a state-changing function may render the function
342
+ * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
343
+ */
344
+ function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
345
+ bytes32[] memory store = _values(set._inner);
346
+ bytes32[] memory result;
347
+
348
+ assembly ("memory-safe") {
349
+ result := store
350
+ }
351
+
352
+ return result;
353
+ }
354
+
355
+ /**
356
+ * @dev Return a slice of the set in an array
357
+ *
358
+ * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
359
+ * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
360
+ * this function has an unbounded cost, and using it as part of a state-changing function may render the function
361
+ * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
362
+ */
363
+ function values(Bytes32Set storage set, uint256 start, uint256 end) internal view returns (bytes32[] memory) {
364
+ bytes32[] memory store = _values(set._inner, start, end);
365
+ bytes32[] memory result;
366
+
367
+ assembly ("memory-safe") {
368
+ result := store
369
+ }
370
+
371
+ return result;
372
+ }
373
+
374
+ // Bytes4Set
375
+
376
+ struct Bytes4Set {
377
+ Set _inner;
378
+ }
379
+
380
+ /**
381
+ * @dev Add a value to a set. O(1).
382
+ *
383
+ * Returns true if the value was added to the set, that is if it was not
384
+ * already present.
385
+ */
386
+ function add(Bytes4Set storage set, bytes4 value) internal returns (bool) {
387
+ return _add(set._inner, bytes32(value));
388
+ }
389
+
390
+ /**
391
+ * @dev Removes a value from a set. O(1).
392
+ *
393
+ * Returns true if the value was removed from the set, that is if it was
394
+ * present.
395
+ */
396
+ function remove(Bytes4Set storage set, bytes4 value) internal returns (bool) {
397
+ return _remove(set._inner, bytes32(value));
398
+ }
399
+
400
+ /**
401
+ * @dev Removes the value stored at position `index` from a set. O(1).
402
+ *
403
+ * Returns the removed value.
404
+ *
405
+ * This is cheaper than {remove} when the caller already knows the index, because it skips the position lookup
406
+ * that {remove} performs.
407
+ *
408
+ * Note that there are no guarantees on the ordering of values inside the array, and it may change when more
409
+ * values are added or removed.
410
+ *
411
+ * Requirements:
412
+ *
413
+ * - `index` must be strictly less than {length}.
414
+ */
415
+ function removeAt(Bytes4Set storage set, uint256 index) internal returns (bytes4) {
416
+ return bytes4(_removeAt(set._inner, index));
417
+ }
418
+
419
+ /**
420
+ * @dev Removes all the values from a set. O(n).
421
+ *
422
+ * WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
423
+ * function uncallable if the set grows to the point where clearing it consumes too much gas to fit in a block.
424
+ */
425
+ function clear(Bytes4Set storage set) internal {
426
+ _clear(set._inner);
427
+ }
428
+
429
+ /**
430
+ * @dev Returns true if the value is in the set. O(1).
431
+ */
432
+ function contains(Bytes4Set storage set, bytes4 value) internal view returns (bool) {
433
+ return _contains(set._inner, bytes32(value));
434
+ }
435
+
436
+ /**
437
+ * @dev Returns the number of values in the set. O(1).
438
+ */
439
+ function length(Bytes4Set storage set) internal view returns (uint256) {
440
+ return _length(set._inner);
441
+ }
442
+
443
+ /**
444
+ * @dev Returns the value stored at position `index` in the set. O(1).
445
+ *
446
+ * Note that there are no guarantees on the ordering of values inside the
447
+ * array, and it may change when more values are added or removed.
448
+ *
449
+ * Requirements:
450
+ *
451
+ * - `index` must be strictly less than {length}.
452
+ *
453
+ * IMPORTANT: Deprecated. This function's name clashes with a keyword scheduled for inclusion in Solidity. Developers
454
+ * should use {pos} instead.
455
+ */
456
+ function at(Bytes4Set storage set, uint256 index) internal view returns (bytes4) {
457
+ return pos(set, index);
458
+ }
459
+
460
+ /**
461
+ * @dev Returns the value stored at position `index` in the set. O(1).
462
+ *
463
+ * Note that there are no guarantees on the ordering of values inside the
464
+ * array, and it may change when more values are added or removed.
465
+ *
466
+ * Requirements:
467
+ *
468
+ * - `index` must be strictly less than {length}.
469
+ *
470
+ * Replacement of the deprecated {at} function.
471
+ */
472
+ function pos(Bytes4Set storage set, uint256 index) internal view returns (bytes4) {
473
+ return bytes4(_pos(set._inner, index));
474
+ }
475
+
476
+ /**
477
+ * @dev Return the entire set in an array
478
+ *
479
+ * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
480
+ * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
481
+ * this function has an unbounded cost, and using it as part of a state-changing function may render the function
482
+ * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
483
+ */
484
+ function values(Bytes4Set storage set) internal view returns (bytes4[] memory) {
485
+ bytes32[] memory store = _values(set._inner);
486
+ bytes4[] memory result;
487
+
488
+ assembly ("memory-safe") {
489
+ result := store
490
+ }
491
+
492
+ return result;
493
+ }
494
+
495
+ /**
496
+ * @dev Return a slice of the set in an array
497
+ *
498
+ * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
499
+ * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
500
+ * this function has an unbounded cost, and using it as part of a state-changing function may render the function
501
+ * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
502
+ */
503
+ function values(Bytes4Set storage set, uint256 start, uint256 end) internal view returns (bytes4[] memory) {
504
+ bytes32[] memory store = _values(set._inner, start, end);
505
+ bytes4[] memory result;
506
+
507
+ assembly ("memory-safe") {
508
+ result := store
509
+ }
510
+
511
+ return result;
512
+ }
513
+
514
+ // AddressSet
515
+
516
+ struct AddressSet {
517
+ Set _inner;
518
+ }
519
+
520
+ /**
521
+ * @dev Add a value to a set. O(1).
522
+ *
523
+ * Returns true if the value was added to the set, that is if it was not
524
+ * already present.
525
+ */
526
+ function add(AddressSet storage set, address value) internal returns (bool) {
527
+ return _add(set._inner, bytes32(uint256(uint160(value))));
528
+ }
529
+
530
+ /**
531
+ * @dev Removes a value from a set. O(1).
532
+ *
533
+ * Returns true if the value was removed from the set, that is if it was
534
+ * present.
535
+ */
536
+ function remove(AddressSet storage set, address value) internal returns (bool) {
537
+ return _remove(set._inner, bytes32(uint256(uint160(value))));
538
+ }
539
+
540
+ /**
541
+ * @dev Removes the value stored at position `index` from a set. O(1).
542
+ *
543
+ * Returns the removed value.
544
+ *
545
+ * This is cheaper than {remove} when the caller already knows the index, because it skips the position lookup
546
+ * that {remove} performs.
547
+ *
548
+ * Note that there are no guarantees on the ordering of values inside the array, and it may change when more
549
+ * values are added or removed.
550
+ *
551
+ * Requirements:
552
+ *
553
+ * - `index` must be strictly less than {length}.
554
+ */
555
+ function removeAt(AddressSet storage set, uint256 index) internal returns (address) {
556
+ return address(uint160(uint256(_removeAt(set._inner, index))));
557
+ }
558
+
559
+ /**
560
+ * @dev Removes all the values from a set. O(n).
561
+ *
562
+ * WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
563
+ * function uncallable if the set grows to the point where clearing it consumes too much gas to fit in a block.
564
+ */
565
+ function clear(AddressSet storage set) internal {
566
+ _clear(set._inner);
567
+ }
568
+
569
+ /**
570
+ * @dev Returns true if the value is in the set. O(1).
571
+ */
572
+ function contains(AddressSet storage set, address value) internal view returns (bool) {
573
+ return _contains(set._inner, bytes32(uint256(uint160(value))));
574
+ }
575
+
576
+ /**
577
+ * @dev Returns the number of values in the set. O(1).
578
+ */
579
+ function length(AddressSet storage set) internal view returns (uint256) {
580
+ return _length(set._inner);
581
+ }
582
+
583
+ /**
584
+ * @dev Returns the value stored at position `index` in the set. O(1).
585
+ *
586
+ * Note that there are no guarantees on the ordering of values inside the
587
+ * array, and it may change when more values are added or removed.
588
+ *
589
+ * Requirements:
590
+ *
591
+ * - `index` must be strictly less than {length}.
592
+ *
593
+ * IMPORTANT: Deprecated. This function's name clashes with a keyword scheduled for inclusion in Solidity. Developers
594
+ * should use {pos} instead.
595
+ */
596
+ function at(AddressSet storage set, uint256 index) internal view returns (address) {
597
+ return pos(set, index);
598
+ }
599
+
600
+ /**
601
+ * @dev Returns the value stored at position `index` in the set. O(1).
602
+ *
603
+ * Note that there are no guarantees on the ordering of values inside the
604
+ * array, and it may change when more values are added or removed.
605
+ *
606
+ * Requirements:
607
+ *
608
+ * - `index` must be strictly less than {length}.
609
+ *
610
+ * Replacement of the deprecated {at} function.
611
+ */
612
+ function pos(AddressSet storage set, uint256 index) internal view returns (address) {
613
+ return address(uint160(uint256(_pos(set._inner, index))));
614
+ }
615
+
616
+ /**
617
+ * @dev Return the entire set in an array
618
+ *
619
+ * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
620
+ * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
621
+ * this function has an unbounded cost, and using it as part of a state-changing function may render the function
622
+ * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
623
+ */
624
+ function values(AddressSet storage set) internal view returns (address[] memory) {
625
+ bytes32[] memory store = _values(set._inner);
626
+ address[] memory result;
627
+
628
+ assembly ("memory-safe") {
629
+ result := store
630
+ }
631
+
632
+ return result;
633
+ }
634
+
635
+ /**
636
+ * @dev Return a slice of the set in an array
637
+ *
638
+ * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
639
+ * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
640
+ * this function has an unbounded cost, and using it as part of a state-changing function may render the function
641
+ * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
642
+ */
643
+ function values(AddressSet storage set, uint256 start, uint256 end) internal view returns (address[] memory) {
644
+ bytes32[] memory store = _values(set._inner, start, end);
645
+ address[] memory result;
646
+
647
+ assembly ("memory-safe") {
648
+ result := store
649
+ }
650
+
651
+ return result;
652
+ }
653
+
654
+ // UintSet
655
+
656
+ struct UintSet {
657
+ Set _inner;
658
+ }
659
+
660
+ /**
661
+ * @dev Add a value to a set. O(1).
662
+ *
663
+ * Returns true if the value was added to the set, that is if it was not
664
+ * already present.
665
+ */
666
+ function add(UintSet storage set, uint256 value) internal returns (bool) {
667
+ return _add(set._inner, bytes32(value));
668
+ }
669
+
670
+ /**
671
+ * @dev Removes a value from a set. O(1).
672
+ *
673
+ * Returns true if the value was removed from the set, that is if it was
674
+ * present.
675
+ */
676
+ function remove(UintSet storage set, uint256 value) internal returns (bool) {
677
+ return _remove(set._inner, bytes32(value));
678
+ }
679
+
680
+ /**
681
+ * @dev Removes the value stored at position `index` from a set. O(1).
682
+ *
683
+ * Returns the removed value.
684
+ *
685
+ * This is cheaper than {remove} when the caller already knows the index, because it skips the position lookup
686
+ * that {remove} performs.
687
+ *
688
+ * Note that there are no guarantees on the ordering of values inside the array, and it may change when more
689
+ * values are added or removed.
690
+ *
691
+ * Requirements:
692
+ *
693
+ * - `index` must be strictly less than {length}.
694
+ */
695
+ function removeAt(UintSet storage set, uint256 index) internal returns (uint256) {
696
+ return uint256(_removeAt(set._inner, index));
697
+ }
698
+
699
+ /**
700
+ * @dev Removes all the values from a set. O(n).
701
+ *
702
+ * WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
703
+ * function uncallable if the set grows to the point where clearing it consumes too much gas to fit in a block.
704
+ */
705
+ function clear(UintSet storage set) internal {
706
+ _clear(set._inner);
707
+ }
708
+
709
+ /**
710
+ * @dev Returns true if the value is in the set. O(1).
711
+ */
712
+ function contains(UintSet storage set, uint256 value) internal view returns (bool) {
713
+ return _contains(set._inner, bytes32(value));
714
+ }
715
+
716
+ /**
717
+ * @dev Returns the number of values in the set. O(1).
718
+ */
719
+ function length(UintSet storage set) internal view returns (uint256) {
720
+ return _length(set._inner);
721
+ }
722
+
723
+ /**
724
+ * @dev Returns the value stored at position `index` in the set. O(1).
725
+ *
726
+ * Note that there are no guarantees on the ordering of values inside the
727
+ * array, and it may change when more values are added or removed.
728
+ *
729
+ * Requirements:
730
+ *
731
+ * - `index` must be strictly less than {length}.
732
+ *
733
+ * IMPORTANT: Deprecated. This function's name clashes with a keyword scheduled for inclusion in Solidity. Developers
734
+ * should use {pos} instead.
735
+ */
736
+ function at(UintSet storage set, uint256 index) internal view returns (uint256) {
737
+ return pos(set, index);
738
+ }
739
+
740
+ /**
741
+ * @dev Returns the value stored at position `index` in the set. O(1).
742
+ *
743
+ * Note that there are no guarantees on the ordering of values inside the
744
+ * array, and it may change when more values are added or removed.
745
+ *
746
+ * Requirements:
747
+ *
748
+ * - `index` must be strictly less than {length}.
749
+ *
750
+ * Replacement of the deprecated {at} function.
751
+ */
752
+ function pos(UintSet storage set, uint256 index) internal view returns (uint256) {
753
+ return uint256(_pos(set._inner, index));
754
+ }
755
+
756
+ /**
757
+ * @dev Return the entire set in an array
758
+ *
759
+ * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
760
+ * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
761
+ * this function has an unbounded cost, and using it as part of a state-changing function may render the function
762
+ * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
763
+ */
764
+ function values(UintSet storage set) internal view returns (uint256[] memory) {
765
+ bytes32[] memory store = _values(set._inner);
766
+ uint256[] memory result;
767
+
768
+ assembly ("memory-safe") {
769
+ result := store
770
+ }
771
+
772
+ return result;
773
+ }
774
+
775
+ /**
776
+ * @dev Return a slice of the set in an array
777
+ *
778
+ * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
779
+ * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
780
+ * this function has an unbounded cost, and using it as part of a state-changing function may render the function
781
+ * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
782
+ */
783
+ function values(UintSet storage set, uint256 start, uint256 end) internal view returns (uint256[] memory) {
784
+ bytes32[] memory store = _values(set._inner, start, end);
785
+ uint256[] memory result;
786
+
787
+ assembly ("memory-safe") {
788
+ result := store
789
+ }
790
+
791
+ return result;
792
+ }
793
+
794
+ struct StringSet {
795
+ // Storage of set values
796
+ string[] _values;
797
+ // Position is the index of the value in the `values` array plus 1.
798
+ // Position 0 is used to mean a value is not in the set.
799
+ mapping(string value => uint256) _positions;
800
+ }
801
+
802
+ /**
803
+ * @dev Add a value to a set. O(1).
804
+ *
805
+ * Returns true if the value was added to the set, that is if it was not
806
+ * already present.
807
+ */
808
+ function add(StringSet storage set, string memory value) internal returns (bool) {
809
+ if (!contains(set, value)) {
810
+ set._values.push(value);
811
+ // The value is stored at length-1, but we add 1 to all indexes
812
+ // and use 0 as a sentinel value
813
+ set._positions[value] = set._values.length;
814
+ return true;
815
+ } else {
816
+ return false;
817
+ }
818
+ }
819
+
820
+ /**
821
+ * @dev Removes a value from a set. O(1).
822
+ *
823
+ * Returns true if the value was removed from the set, that is if it was
824
+ * present.
825
+ */
826
+ function remove(StringSet storage set, string memory value) internal returns (bool) {
827
+ // We cache the value's position to prevent multiple reads from the same storage slot
828
+ uint256 position = set._positions[value];
829
+
830
+ if (position != 0) {
831
+ _removeValueAt(set, value, position - 1);
832
+ return true;
833
+ } else {
834
+ return false;
835
+ }
836
+ }
837
+
838
+ /**
839
+ * @dev Removes the value stored at position `index` from a set. O(1).
840
+ *
841
+ * Returns the removed value.
842
+ *
843
+ * This is cheaper than {remove} when the caller already knows the index, because it skips the position lookup
844
+ * that {remove} performs.
845
+ *
846
+ * Note that there are no guarantees on the ordering of values inside the array, and it may change when more
847
+ * values are added or removed.
848
+ *
849
+ * Requirements:
850
+ *
851
+ * - `index` must be strictly less than {length}.
852
+ */
853
+ function removeAt(StringSet storage set, uint256 index) internal returns (string memory value) {
854
+ value = set._values[index];
855
+ _removeValueAt(set, value, index);
856
+ }
857
+
858
+ /**
859
+ * @dev Removes the value stored at position `index` from a set. O(1).
860
+ *
861
+ * To delete an element from the `_values` array in O(1), we swap the element to delete with the last one in the
862
+ * array, and then remove the last element (sometimes called as 'swap and pop'). This modifies the order of the
863
+ * array, as noted in {at}.
864
+ *
865
+ * IMPORTANT: This does not verify that `value` is the value currently stored at `index`. Callers must ensure
866
+ * both arguments are consistent, otherwise the set is left in a corrupted state.
867
+ *
868
+ * Requirements:
869
+ *
870
+ * - `index` must be strictly less than {length}.
871
+ */
872
+ function _removeValueAt(StringSet storage set, string memory value, uint256 index) private {
873
+ uint256 lastIndex = set._values.length - 1;
874
+
875
+ if (index != lastIndex) {
876
+ string memory lastValue = Arrays.unsafeAccess(set._values, lastIndex).value;
877
+
878
+ // Move the lastValue to the index where the value to delete is
879
+ Arrays.unsafeAccess(set._values, index).value = lastValue;
880
+ // Update the tracked position of the lastValue (that was just moved)
881
+ set._positions[lastValue] = index + 1;
882
+ }
883
+
884
+ // Delete the slot where the moved value was stored
885
+ set._values.pop();
886
+
887
+ // Delete the tracked position for the deleted slot
888
+ delete set._positions[value];
889
+ }
890
+
891
+ /**
892
+ * @dev Removes all the values from a set. O(n).
893
+ *
894
+ * WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
895
+ * function uncallable if the set grows to the point where clearing it consumes too much gas to fit in a block.
896
+ */
897
+ function clear(StringSet storage set) internal {
898
+ uint256 len = length(set);
899
+ for (uint256 i = 0; i < len; ++i) {
900
+ delete set._positions[Arrays.unsafeAccess(set._values, i).value];
901
+ }
902
+ Arrays.unsafeSetLength(set._values, 0);
903
+ }
904
+
905
+ /**
906
+ * @dev Returns true if the value is in the set. O(1).
907
+ */
908
+ function contains(StringSet storage set, string memory value) internal view returns (bool) {
909
+ return set._positions[value] != 0;
910
+ }
911
+
912
+ /**
913
+ * @dev Returns the number of values on the set. O(1).
914
+ */
915
+ function length(StringSet storage set) internal view returns (uint256) {
916
+ return set._values.length;
917
+ }
918
+
919
+ /**
920
+ * @dev Returns the value stored at position `index` in the set. O(1).
921
+ *
922
+ * Note that there are no guarantees on the ordering of values inside the
923
+ * array, and it may change when more values are added or removed.
924
+ *
925
+ * Requirements:
926
+ *
927
+ * - `index` must be strictly less than {length}.
928
+ *
929
+ * IMPORTANT: Deprecated. This function's name clashes with a keyword scheduled for inclusion in Solidity. Developers
930
+ * should use {pos} instead.
931
+ */
932
+ function at(StringSet storage set, uint256 index) internal view returns (string memory) {
933
+ return pos(set, index);
934
+ }
935
+
936
+ /**
937
+ * @dev Returns the value stored at position `index` in the set. O(1).
938
+ *
939
+ * Note that there are no guarantees on the ordering of values inside the
940
+ * array, and it may change when more values are added or removed.
941
+ *
942
+ * Requirements:
943
+ *
944
+ * - `index` must be strictly less than {length}.
945
+ *
946
+ * Replacement of the deprecated {at} function.
947
+ */
948
+ function pos(StringSet storage set, uint256 index) internal view returns (string memory) {
949
+ return set._values[index];
950
+ }
951
+
952
+ /**
953
+ * @dev Return the entire set in an array
954
+ *
955
+ * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
956
+ * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
957
+ * this function has an unbounded cost, and using it as part of a state-changing function may render the function
958
+ * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
959
+ */
960
+ function values(StringSet storage set) internal view returns (string[] memory) {
961
+ return set._values;
962
+ }
963
+
964
+ /**
965
+ * @dev Return a slice of the set in an array
966
+ *
967
+ * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
968
+ * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
969
+ * this function has an unbounded cost, and using it as part of a state-changing function may render the function
970
+ * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
971
+ */
972
+ function values(StringSet storage set, uint256 start, uint256 end) internal view returns (string[] memory) {
973
+ unchecked {
974
+ end = Math.min(end, length(set));
975
+ start = Math.min(start, end);
976
+
977
+ uint256 len = end - start;
978
+ string[] memory result = new string[](len);
979
+ for (uint256 i = 0; i < len; ++i) {
980
+ result[i] = Arrays.unsafeAccess(set._values, start + i).value;
981
+ }
982
+ return result;
983
+ }
984
+ }
985
+
986
+ struct BytesSet {
987
+ // Storage of set values
988
+ bytes[] _values;
989
+ // Position is the index of the value in the `values` array plus 1.
990
+ // Position 0 is used to mean a value is not in the set.
991
+ mapping(bytes value => uint256) _positions;
992
+ }
993
+
994
+ /**
995
+ * @dev Add a value to a set. O(1).
996
+ *
997
+ * Returns true if the value was added to the set, that is if it was not
998
+ * already present.
999
+ */
1000
+ function add(BytesSet storage set, bytes memory value) internal returns (bool) {
1001
+ if (!contains(set, value)) {
1002
+ set._values.push(value);
1003
+ // The value is stored at length-1, but we add 1 to all indexes
1004
+ // and use 0 as a sentinel value
1005
+ set._positions[value] = set._values.length;
1006
+ return true;
1007
+ } else {
1008
+ return false;
1009
+ }
1010
+ }
1011
+
1012
+ /**
1013
+ * @dev Removes a value from a set. O(1).
1014
+ *
1015
+ * Returns true if the value was removed from the set, that is if it was
1016
+ * present.
1017
+ */
1018
+ function remove(BytesSet storage set, bytes memory value) internal returns (bool) {
1019
+ // We cache the value's position to prevent multiple reads from the same storage slot
1020
+ uint256 position = set._positions[value];
1021
+
1022
+ if (position != 0) {
1023
+ _removeValueAt(set, value, position - 1);
1024
+ return true;
1025
+ } else {
1026
+ return false;
1027
+ }
1028
+ }
1029
+
1030
+ /**
1031
+ * @dev Removes the value stored at position `index` from a set. O(1).
1032
+ *
1033
+ * Returns the removed value.
1034
+ *
1035
+ * This is cheaper than {remove} when the caller already knows the index, because it skips the position lookup
1036
+ * that {remove} performs.
1037
+ *
1038
+ * Note that there are no guarantees on the ordering of values inside the array, and it may change when more
1039
+ * values are added or removed.
1040
+ *
1041
+ * Requirements:
1042
+ *
1043
+ * - `index` must be strictly less than {length}.
1044
+ */
1045
+ function removeAt(BytesSet storage set, uint256 index) internal returns (bytes memory value) {
1046
+ value = set._values[index];
1047
+ _removeValueAt(set, value, index);
1048
+ }
1049
+
1050
+ /**
1051
+ * @dev Removes the value stored at position `index` from a set. O(1).
1052
+ *
1053
+ * To delete an element from the `_values` array in O(1), we swap the element to delete with the last one in the
1054
+ * array, and then remove the last element (sometimes called as 'swap and pop'). This modifies the order of the
1055
+ * array, as noted in {at}.
1056
+ *
1057
+ * IMPORTANT: This does not verify that `value` is the value currently stored at `index`. Callers must ensure
1058
+ * both arguments are consistent, otherwise the set is left in a corrupted state.
1059
+ *
1060
+ * Requirements:
1061
+ *
1062
+ * - `index` must be strictly less than {length}.
1063
+ */
1064
+ function _removeValueAt(BytesSet storage set, bytes memory value, uint256 index) private {
1065
+ uint256 lastIndex = set._values.length - 1;
1066
+
1067
+ if (index != lastIndex) {
1068
+ bytes memory lastValue = Arrays.unsafeAccess(set._values, lastIndex).value;
1069
+
1070
+ // Move the lastValue to the index where the value to delete is
1071
+ Arrays.unsafeAccess(set._values, index).value = lastValue;
1072
+ // Update the tracked position of the lastValue (that was just moved)
1073
+ set._positions[lastValue] = index + 1;
1074
+ }
1075
+
1076
+ // Delete the slot where the moved value was stored
1077
+ set._values.pop();
1078
+
1079
+ // Delete the tracked position for the deleted slot
1080
+ delete set._positions[value];
1081
+ }
1082
+
1083
+ /**
1084
+ * @dev Removes all the values from a set. O(n).
1085
+ *
1086
+ * WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
1087
+ * function uncallable if the set grows to the point where clearing it consumes too much gas to fit in a block.
1088
+ */
1089
+ function clear(BytesSet storage set) internal {
1090
+ uint256 len = length(set);
1091
+ for (uint256 i = 0; i < len; ++i) {
1092
+ delete set._positions[Arrays.unsafeAccess(set._values, i).value];
1093
+ }
1094
+ Arrays.unsafeSetLength(set._values, 0);
1095
+ }
1096
+
1097
+ /**
1098
+ * @dev Returns true if the value is in the set. O(1).
1099
+ */
1100
+ function contains(BytesSet storage set, bytes memory value) internal view returns (bool) {
1101
+ return set._positions[value] != 0;
1102
+ }
1103
+
1104
+ /**
1105
+ * @dev Returns the number of values on the set. O(1).
1106
+ */
1107
+ function length(BytesSet storage set) internal view returns (uint256) {
1108
+ return set._values.length;
1109
+ }
1110
+
1111
+ /**
1112
+ * @dev Returns the value stored at position `index` in the set. O(1).
1113
+ *
1114
+ * Note that there are no guarantees on the ordering of values inside the
1115
+ * array, and it may change when more values are added or removed.
1116
+ *
1117
+ * Requirements:
1118
+ *
1119
+ * - `index` must be strictly less than {length}.
1120
+ *
1121
+ * IMPORTANT: Deprecated. This function's name clashes with a keyword scheduled for inclusion in Solidity. Developers
1122
+ * should use {pos} instead.
1123
+ */
1124
+ function at(BytesSet storage set, uint256 index) internal view returns (bytes memory) {
1125
+ return pos(set, index);
1126
+ }
1127
+
1128
+ /**
1129
+ * @dev Returns the value stored at position `index` in the set. O(1).
1130
+ *
1131
+ * Note that there are no guarantees on the ordering of values inside the
1132
+ * array, and it may change when more values are added or removed.
1133
+ *
1134
+ * Requirements:
1135
+ *
1136
+ * - `index` must be strictly less than {length}.
1137
+ *
1138
+ * Replacement of the deprecated {at} function.
1139
+ */
1140
+ function pos(BytesSet storage set, uint256 index) internal view returns (bytes memory) {
1141
+ return set._values[index];
1142
+ }
1143
+
1144
+ /**
1145
+ * @dev Return the entire set in an array
1146
+ *
1147
+ * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
1148
+ * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
1149
+ * this function has an unbounded cost, and using it as part of a state-changing function may render the function
1150
+ * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
1151
+ */
1152
+ function values(BytesSet storage set) internal view returns (bytes[] memory) {
1153
+ return set._values;
1154
+ }
1155
+
1156
+ /**
1157
+ * @dev Return a slice of the set in an array
1158
+ *
1159
+ * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
1160
+ * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
1161
+ * this function has an unbounded cost, and using it as part of a state-changing function may render the function
1162
+ * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
1163
+ */
1164
+ function values(BytesSet storage set, uint256 start, uint256 end) internal view returns (bytes[] memory) {
1165
+ unchecked {
1166
+ end = Math.min(end, length(set));
1167
+ start = Math.min(start, end);
1168
+
1169
+ uint256 len = end - start;
1170
+ bytes[] memory result = new bytes[](len);
1171
+ for (uint256 i = 0; i < len; ++i) {
1172
+ result[i] = Arrays.unsafeAccess(set._values, start + i).value;
1173
+ }
1174
+ return result;
1175
+ }
1176
+ }
1177
+ }