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,310 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // OpenZeppelin Contracts (last updated v5.8.0) (utils/RateLimiter.sol)
3
+ pragma solidity ^0.8.27;
4
+
5
+ import {Math} from "./math/Math.sol";
6
+ import {SafeCast} from "./math/SafeCast.sol";
7
+ import {Checkpoints} from "./structs/Checkpoints.sol";
8
+ import {Time} from "./types/Time.sol";
9
+
10
+ /**
11
+ * @dev This library provides primitives for limiting the rate at which an action can be performed.
12
+ *
13
+ * Two complementary strategies are available, each represented by a storage struct that the consumer keeps in its
14
+ * own storage:
15
+ *
16
+ * - {RefillingBucket}: a token bucket that refills linearly over time. The bucket starts full; each consumption
17
+ * draws from it, and it is refilled over time. Suitable when the protected resource regenerates continuously and bursts
18
+ * of size up to the bucket's capacity are allowed. Storage cost is constant regardless of consumption history.
19
+ *
20
+ * - {SlidingWindow}: a moving-window counter that caps the cumulative consumption over any `window`-second
21
+ * interval. Suitable when a strict cap on usage within a rolling window is required. Each successful consumption
22
+ * appends a checkpoint, making it a more expensive option with a larger storage footprint.
23
+ *
24
+ * === Limiter vs. entries
25
+ *
26
+ * Each storage struct is a _limiter_: it pairs a single, shared configuration (the `window`, together with the
27
+ * `capacity` of a {RefillingBucket} or the `limit` of a {SlidingWindow}) with a mapping of independent _entries_
28
+ * keyed by `bytes32`. Every operation takes a `key` and applies only to that entry.
29
+ *
30
+ * All entries in a limiter share the same configuration, but each entry tracks its own consumption independently:
31
+ * consuming from one `key` never affects the availability of another. This lets a single limiter enforce the same
32
+ * rate limit separately across many subjects--for example one entry per caller, per token, or per protected
33
+ * function--simply by choosing the `key` accordingly. Using a constant `key` (e.g. `bytes32(0)`) reduces the
34
+ * limiter to a single global rate limit.
35
+ *
36
+ * Configuration is changed for the whole limiter at once with {updateSettings}, whereas {state}, {used},
37
+ * {available}, {tryConsume}, {consume} and {reset} act on the individual entry identified by `key`.
38
+ *
39
+ * Example usage (one independent rate limit per caller, all sharing the same capacity and window):
40
+ *
41
+ * ```solidity
42
+ * using RateLimiter for RateLimiter.RefillingBucket;
43
+ *
44
+ * RateLimiter.RefillingBucket private _rateLimiter;
45
+ *
46
+ * function withdraw(uint256 amount) external {
47
+ * _rateLimiter.consume(bytes32(uint256(uint160(msg.sender))), amount);
48
+ * // ...
49
+ * }
50
+ * ```
51
+ */
52
+ library RateLimiter {
53
+ using Checkpoints for Checkpoints.Trace208;
54
+
55
+ /**
56
+ * @dev The requested quantity exceeds the currently available capacity.
57
+ */
58
+ error RateLimitExceeded();
59
+
60
+ // ================================================ RefillingBucket ================================================
61
+ /**
62
+ * @dev The per-`key` state of a {RefillingBucket} entry.
63
+ *
64
+ * `lastUsed` and `lastTimepoint` record the used quantity and the time it was recorded at the entry's last
65
+ * update. The current state is reconstructed lazily from these two fields on read (see {state}), keeping storage
66
+ * cost constant at one packed slot per entry regardless of how many times the entry has been consumed.
67
+ *
68
+ * WARNING: Manually updating any of the parameters may result in incorrect behavior. Only interact with the
69
+ * {RefillingBucket} through the dedicated functions.
70
+ */
71
+ struct RefillingBucketItem {
72
+ uint208 _lastUsed;
73
+ uint48 _lastTimepoint;
74
+ }
75
+
76
+ /**
77
+ * @dev A token-bucket limiter: shared configuration plus a mapping of independent per-`key` buckets.
78
+ *
79
+ * `capacity` and `window` are shared by every entry: each bucket has a maximum `capacity` and refills at a rate
80
+ * of `capacity / window` per second, so that an empty bucket fully refills in `window` seconds. `items` holds the
81
+ * individual buckets, each tracking its own consumption under its `key` (see {RefillingBucketItem}).
82
+ *
83
+ * WARNING: Manually updating any of the parameters may result in incorrect behavior. Only interact with the
84
+ * {RefillingBucket} through the dedicated functions.
85
+ */
86
+ struct RefillingBucket {
87
+ uint208 _capacity;
88
+ uint48 _window;
89
+ mapping(bytes32 key => RefillingBucketItem) _items;
90
+ }
91
+
92
+ /**
93
+ * @dev Returns the current `used` and `available` quantities for the `key` bucket, accounting for the time-based
94
+ * refill that has accrued since that entry's last update.
95
+ *
96
+ * NOTE: A `window` of 0 is treated as 1 second in the refill computation: the effective refill rate becomes
97
+ * `capacity` per second, and an uninitialized limiter (`capacity = window = 0`) reports as an empty bucket.
98
+ */
99
+ function state(
100
+ RefillingBucket storage self,
101
+ bytes32 key
102
+ ) internal view returns (uint256 used_, uint256 available_) {
103
+ uint208 capacity_ = self._capacity; // cache
104
+ RefillingBucketItem storage item_ = self._items[key]; // cache
105
+
106
+ used_ = Math.saturatingSub(
107
+ item_._lastUsed,
108
+ Math.mulDiv(Time.timestamp() - item_._lastTimepoint, capacity_, Math.max(self._window, 1))
109
+ );
110
+ available_ = Math.saturatingSub(capacity_, used_);
111
+ }
112
+
113
+ /**
114
+ * @dev Returns the currently used quantity. See {state-struct-RateLimiter-RefillingBucket-bytes32}.
115
+ */
116
+ function used(RefillingBucket storage self, bytes32 key) internal view returns (uint256 used_) {
117
+ (used_, ) = state(self, key);
118
+ }
119
+
120
+ /**
121
+ * @dev Returns the currently available quantity. See {state-struct-RateLimiter-RefillingBucket-bytes32}.
122
+ */
123
+ function available(RefillingBucket storage self, bytes32 key) internal view returns (uint256 available_) {
124
+ (, available_) = state(self, key);
125
+ }
126
+
127
+ /**
128
+ * @dev Attempts to consume `quantity` from the `key` bucket. Returns `true` on success, `false` if that entry's
129
+ * available quantity is insufficient.
130
+ *
131
+ * A `quantity` of 0 is always accepted and does not modify storage.
132
+ */
133
+ function tryConsume(RefillingBucket storage self, bytes32 key, uint256 quantity) internal returns (bool) {
134
+ if (quantity == 0) {
135
+ return true;
136
+ }
137
+ (uint256 used_, uint256 available_) = state(self, key);
138
+ if (quantity <= available_) {
139
+ self._items[key] = RefillingBucketItem({
140
+ _lastTimepoint: Time.timestamp(),
141
+ _lastUsed: SafeCast.toUint208(used_ + quantity)
142
+ });
143
+ return true;
144
+ } else {
145
+ return false;
146
+ }
147
+ }
148
+
149
+ /**
150
+ * @dev Consumes `quantity` from the `key` bucket. Reverts with {RateLimitExceeded} if that entry's available
151
+ * quantity is insufficient. See {tryConsume-struct-RateLimiter-RefillingBucket-bytes32-uint256}.
152
+ */
153
+ function consume(RefillingBucket storage self, bytes32 key, uint256 quantity) internal {
154
+ require(tryConsume(self, key, quantity), RateLimitExceeded());
155
+ }
156
+
157
+ /**
158
+ * @dev Resets the `key` bucket to a fully-available state. Other entries are unaffected.
159
+ */
160
+ function reset(RefillingBucket storage self, bytes32 key) internal {
161
+ delete self._items[key];
162
+ }
163
+
164
+ /**
165
+ * @dev Updates the shared `capacity` and `window` of the limiter, affecting every entry.
166
+ *
167
+ * NOTE: The new settings will retroactively affect all the keys. The new replenishing rate (capacity / window) is
168
+ * applied from the last update timepoint of each key. Therefore, if the new settings correspond to a faster
169
+ * replenishing rate, some quantity may become available immediately. Conversely, if the new settings correspond
170
+ * to a slower replenishing rate, some quantity that would otherwise be available immediately may become
171
+ * unavailable. This side effect can be mitigated by calling {sync} on the relevant keys before updating the
172
+ * settings. There is no mechanism to automatically sync all the keys in a single operation.
173
+ */
174
+ function updateSettings(RefillingBucket storage self, uint48 newWindow, uint208 newCapacity) internal {
175
+ self._capacity = newCapacity;
176
+ self._window = newWindow;
177
+ }
178
+
179
+ /**
180
+ * @dev Refreshes the `key` bucket by applying the accrued refill since its last update timepoint to `lastUsed`
181
+ * and `lastTimepoint`, effectively moving that entry's timepoint forward to now. This can be used to mitigate the
182
+ * side effect of {updateSettings-struct-RateLimiter-RefillingBucket-uint48-uint208} when the replenishing rate is
183
+ * modified. It must be called per key; there is no mechanism to sync all entries at once.
184
+ */
185
+ function sync(RefillingBucket storage self, bytes32 key) internal {
186
+ self._items[key] = RefillingBucketItem({_lastTimepoint: Time.timestamp(), _lastUsed: uint208(used(self, key))});
187
+ }
188
+
189
+ // ================================================= SlidingWindow =================================================
190
+ /**
191
+ * @dev A moving-window limiter: shared configuration plus a mapping of independent per-`key` counters.
192
+ *
193
+ * `limit` and `window` are shared by every entry, and cap the cumulative consumption of each entry within any
194
+ * `window`-second interval. `items` holds the individual counters: each entry keeps its own checkpoint history
195
+ * (a `Checkpoints.Trace208`) under its `key`, recording the running cumulative total. An entry's current `used`
196
+ * quantity is the difference between its cumulative total at `block.timestamp` and at `block.timestamp - window`.
197
+ *
198
+ * NOTE: The cumulative total of each entry is stored as a `uint208`. Once it reaches `2²⁰⁸ - 1`, further
199
+ * consumption of that entry will revert in {SafeCast}. This bound is unreachable for any realistic `limit`, but
200
+ * consumers should be aware of it.
201
+ *
202
+ * NOTE: An entry's checkpoint history is not a reliable log of past consumptions--previous entries may be
203
+ * overwritten in place. The storage footprint of an entry grows with the number of
204
+ * {tryConsume-struct-RateLimiter-SlidingWindow-bytes32-uint256} calls on that `key` that succeed with a non-zero
205
+ * `quantity`.
206
+ *
207
+ * WARNING: Manually updating any of the parameters may result in incorrect behavior. Only interact with the
208
+ * {SlidingWindow} through the dedicated functions.
209
+ */
210
+ struct SlidingWindow {
211
+ uint208 _limit;
212
+ uint48 _window;
213
+ mapping(bytes32 key => Checkpoints.Trace208) _items;
214
+ }
215
+
216
+ /**
217
+ * @dev Returns the current `used` and `available` quantities for the `key` counter, computed as that entry's
218
+ * cumulative consumption over the last `window` seconds.
219
+ *
220
+ * NOTE: A `window` of 0 is treated as 1 second in the rolling-window lookup, and an uninitialized limiter
221
+ * (`limit = window = 0`) reports as a counter with no available quantity.
222
+ */
223
+ function state(SlidingWindow storage self, bytes32 key) internal view returns (uint256 used_, uint256 available_) {
224
+ Checkpoints.Trace208 storage item_ = self._items[key]; // cache
225
+
226
+ used_ = Math.saturatingSub(
227
+ item_.latest(),
228
+ item_.upperLookupRecent(uint48(Math.saturatingSub(Time.timestamp(), Math.max(self._window, 1))))
229
+ );
230
+ available_ = Math.saturatingSub(self._limit, used_);
231
+ }
232
+
233
+ /**
234
+ * @dev Returns the quantity currently used by the `key` counter within the sliding window. See
235
+ * {state-struct-RateLimiter-SlidingWindow-bytes32}.
236
+ */
237
+ function used(SlidingWindow storage self, bytes32 key) internal view returns (uint256 used_) {
238
+ (used_, ) = state(self, key);
239
+ }
240
+
241
+ /**
242
+ * @dev Returns the quantity currently available to the `key` counter within the rolling window. See
243
+ * {state-struct-RateLimiter-SlidingWindow-bytes32}.
244
+ */
245
+ function available(SlidingWindow storage self, bytes32 key) internal view returns (uint256 available_) {
246
+ (, available_) = state(self, key);
247
+ }
248
+
249
+ /**
250
+ * @dev Attempts to record a consumption of `quantity` against the `key` counter. Returns `true` on success,
251
+ * `false` if that entry's available quantity within the current window is insufficient.
252
+ *
253
+ * A `quantity` of 0 is always accepted and does not modify storage.
254
+ */
255
+ function tryConsume(SlidingWindow storage self, bytes32 key, uint256 quantity) internal returns (bool) {
256
+ if (quantity == 0) {
257
+ return true;
258
+ }
259
+ (uint256 used_, uint256 available_) = state(self, key);
260
+ if (quantity <= available_) {
261
+ if (used_ == 0) {
262
+ reset(self, key);
263
+ }
264
+ Checkpoints.Trace208 storage item_ = self._items[key]; // cache
265
+ item_.push(Time.timestamp(), SafeCast.toUint208(item_.latest() + quantity));
266
+ return true;
267
+ } else {
268
+ return false;
269
+ }
270
+ }
271
+
272
+ /**
273
+ * @dev Records a consumption of `quantity` against the `key` counter. Reverts with {RateLimitExceeded} if that
274
+ * entry's available quantity within the current window is insufficient. See
275
+ * {tryConsume-struct-RateLimiter-SlidingWindow-bytes32-uint256}.
276
+ */
277
+ function consume(SlidingWindow storage self, bytes32 key, uint256 quantity) internal {
278
+ require(tryConsume(self, key, quantity), RateLimitExceeded());
279
+ }
280
+
281
+ /**
282
+ * @dev Resets the `key` counter to a fully-available state. Other entries are unaffected.
283
+ *
284
+ * NOTE: This will reset that entry's entire history, meaning it can also be used to recover from the cumulative
285
+ * total approaching the `uint208` ceiling. The underlying storage slots holding past checkpoints are not zeroed
286
+ * out. As a consequence, there is no gas refunded, but future
287
+ * {consume-struct-RateLimiter-SlidingWindow-bytes32-uint256} and
288
+ * {tryConsume-struct-RateLimiter-SlidingWindow-bytes32-uint256} operations are cheaper from reusing "dirty" slots.
289
+ */
290
+ function reset(SlidingWindow storage self, bytes32 key) internal {
291
+ Checkpoints.Checkpoint208[] storage trace = self._items[key]._checkpoints;
292
+ assembly ("memory-safe") {
293
+ sstore(trace.slot, 0)
294
+ }
295
+ }
296
+
297
+ /**
298
+ * @dev Updates the shared `limit` and `window` of the limiter, affecting every entry.
299
+ *
300
+ * NOTE: Changing the settings does not modify the recorded consumption history; it only changes how that
301
+ * history is interpreted. Increasing `window` acts on whatever history each key still has: a key that
302
+ * retained older consumptions has them brought back into the larger window, while a key whose history was
303
+ * reset before the update (incidentally or deliberately) is unaffected. Decreasing `window` conversely
304
+ * causes older consumptions to drop out sooner.
305
+ */
306
+ function updateSettings(SlidingWindow storage self, uint48 newWindow, uint208 newLimit) internal {
307
+ self._limit = newLimit;
308
+ self._window = newWindow;
309
+ }
310
+ }
@@ -0,0 +1,119 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // OpenZeppelin Contracts (last updated v5.5.0) (utils/ReentrancyGuard.sol)
3
+
4
+ pragma solidity ^0.8.20;
5
+
6
+ import {StorageSlot} from "./StorageSlot.sol";
7
+
8
+ /**
9
+ * @dev Contract module that helps prevent reentrant calls to a function.
10
+ *
11
+ * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
12
+ * available, which can be applied to functions to make sure there are no nested
13
+ * (reentrant) calls to them.
14
+ *
15
+ * Note that because there is a single `nonReentrant` guard, functions marked as
16
+ * `nonReentrant` may not call one another. This can be worked around by making
17
+ * those functions `private`, and then adding `external` `nonReentrant` entry
18
+ * points to them.
19
+ *
20
+ * TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,
21
+ * consider using {ReentrancyGuardTransient} instead.
22
+ *
23
+ * TIP: If you would like to learn more about reentrancy and alternative ways
24
+ * to protect against it, check out our blog post
25
+ * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
26
+ *
27
+ * IMPORTANT: Deprecated. This storage-based reentrancy guard will be removed and replaced
28
+ * by the {ReentrancyGuardTransient} variant in v6.0.
29
+ *
30
+ * @custom:stateless
31
+ */
32
+ abstract contract ReentrancyGuard {
33
+ using StorageSlot for bytes32;
34
+
35
+ // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ReentrancyGuard")) - 1)) & ~bytes32(uint256(0xff))
36
+ bytes32 private constant REENTRANCY_GUARD_STORAGE =
37
+ 0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00;
38
+
39
+ // Booleans are more expensive than uint256 or any type that takes up a full
40
+ // word because each write operation emits an extra SLOAD to first read the
41
+ // slot's contents, replace the bits taken up by the boolean, and then write
42
+ // back. This is the compiler's defense against contract upgrades and
43
+ // pointer aliasing, and it cannot be disabled.
44
+
45
+ // The values being non-zero value makes deployment a bit more expensive,
46
+ // but in exchange the refund on every call to nonReentrant will be lower in
47
+ // amount. Since refunds are capped to a percentage of the total
48
+ // transaction's gas, it is best to keep them low in cases like this one, to
49
+ // increase the likelihood of the full refund coming into effect.
50
+ uint256 private constant NOT_ENTERED = 1;
51
+ uint256 private constant ENTERED = 2;
52
+
53
+ /**
54
+ * @dev Unauthorized reentrant call.
55
+ */
56
+ error ReentrancyGuardReentrantCall();
57
+
58
+ constructor() {
59
+ _reentrancyGuardStorageSlot().getUint256Slot().value = NOT_ENTERED;
60
+ }
61
+
62
+ /**
63
+ * @dev Prevents a contract from calling itself, directly or indirectly.
64
+ * Calling a `nonReentrant` function from another `nonReentrant`
65
+ * function is not supported. It is possible to prevent this from happening
66
+ * by making the `nonReentrant` function external, and making it call a
67
+ * `private` function that does the actual work.
68
+ */
69
+ modifier nonReentrant() {
70
+ _nonReentrantBefore();
71
+ _;
72
+ _nonReentrantAfter();
73
+ }
74
+
75
+ /**
76
+ * @dev A `view` only version of {nonReentrant}. Use to block view functions
77
+ * from being called, preventing reading from inconsistent contract state.
78
+ *
79
+ * CAUTION: This is a "view" modifier and does not change the reentrancy
80
+ * status. Use it only on view functions. For payable or non-payable functions,
81
+ * use the standard {nonReentrant} modifier instead.
82
+ */
83
+ modifier nonReentrantView() {
84
+ _nonReentrantBeforeView();
85
+ _;
86
+ }
87
+
88
+ function _nonReentrantBeforeView() private view {
89
+ if (_reentrancyGuardEntered()) {
90
+ revert ReentrancyGuardReentrantCall();
91
+ }
92
+ }
93
+
94
+ function _nonReentrantBefore() private {
95
+ // On the first call to nonReentrant, _status will be NOT_ENTERED
96
+ _nonReentrantBeforeView();
97
+
98
+ // Any calls to nonReentrant after this point will fail
99
+ _reentrancyGuardStorageSlot().getUint256Slot().value = ENTERED;
100
+ }
101
+
102
+ function _nonReentrantAfter() private {
103
+ // By storing the original value once again, a refund is triggered (see
104
+ // https://eips.ethereum.org/EIPS/eip-2200)
105
+ _reentrancyGuardStorageSlot().getUint256Slot().value = NOT_ENTERED;
106
+ }
107
+
108
+ /**
109
+ * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
110
+ * `nonReentrant` function in the call stack.
111
+ */
112
+ function _reentrancyGuardEntered() internal view returns (bool) {
113
+ return _reentrancyGuardStorageSlot().getUint256Slot().value == ENTERED;
114
+ }
115
+
116
+ function _reentrancyGuardStorageSlot() internal pure virtual returns (bytes32) {
117
+ return REENTRANCY_GUARD_STORAGE;
118
+ }
119
+ }
@@ -0,0 +1,84 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // OpenZeppelin Contracts (last updated v5.5.0) (utils/ReentrancyGuardTransient.sol)
3
+
4
+ pragma solidity ^0.8.24;
5
+
6
+ import {TransientSlot} from "./TransientSlot.sol";
7
+
8
+ /**
9
+ * @dev Variant of {ReentrancyGuard} that uses transient storage.
10
+ *
11
+ * NOTE: This variant only works on networks where EIP-1153 is available.
12
+ *
13
+ * _Available since v5.1._
14
+ *
15
+ * @custom:stateless
16
+ */
17
+ abstract contract ReentrancyGuardTransient {
18
+ using TransientSlot for *;
19
+
20
+ // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ReentrancyGuard")) - 1)) & ~bytes32(uint256(0xff))
21
+ bytes32 private constant REENTRANCY_GUARD_STORAGE =
22
+ 0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00;
23
+
24
+ /**
25
+ * @dev Unauthorized reentrant call.
26
+ */
27
+ error ReentrancyGuardReentrantCall();
28
+
29
+ /**
30
+ * @dev Prevents a contract from calling itself, directly or indirectly.
31
+ * Calling a `nonReentrant` function from another `nonReentrant`
32
+ * function is not supported. It is possible to prevent this from happening
33
+ * by making the `nonReentrant` function external, and making it call a
34
+ * `private` function that does the actual work.
35
+ */
36
+ modifier nonReentrant() {
37
+ _nonReentrantBefore();
38
+ _;
39
+ _nonReentrantAfter();
40
+ }
41
+
42
+ /**
43
+ * @dev A `view` only version of {nonReentrant}. Use to block view functions
44
+ * from being called, preventing reading from inconsistent contract state.
45
+ *
46
+ * CAUTION: This is a "view" modifier and does not change the reentrancy
47
+ * status. Use it only on view functions. For payable or non-payable functions,
48
+ * use the standard {nonReentrant} modifier instead.
49
+ */
50
+ modifier nonReentrantView() {
51
+ _nonReentrantBeforeView();
52
+ _;
53
+ }
54
+
55
+ function _nonReentrantBeforeView() private view {
56
+ if (_reentrancyGuardEntered()) {
57
+ revert ReentrancyGuardReentrantCall();
58
+ }
59
+ }
60
+
61
+ function _nonReentrantBefore() private {
62
+ // On the first call to nonReentrant, REENTRANCY_GUARD_STORAGE.asBoolean().tload() will be false
63
+ _nonReentrantBeforeView();
64
+
65
+ // Any calls to nonReentrant after this point will fail
66
+ _reentrancyGuardStorageSlot().asBoolean().tstore(true);
67
+ }
68
+
69
+ function _nonReentrantAfter() private {
70
+ _reentrancyGuardStorageSlot().asBoolean().tstore(false);
71
+ }
72
+
73
+ /**
74
+ * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
75
+ * `nonReentrant` function in the call stack.
76
+ */
77
+ function _reentrancyGuardEntered() internal view returns (bool) {
78
+ return _reentrancyGuardStorageSlot().asBoolean().tload();
79
+ }
80
+
81
+ function _reentrancyGuardStorageSlot() internal pure virtual returns (bytes32) {
82
+ return REENTRANCY_GUARD_STORAGE;
83
+ }
84
+ }
@@ -0,0 +1,145 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // OpenZeppelin Contracts (last updated v5.7.0) (utils/RelayedCall.sol)
3
+
4
+ pragma solidity ^0.8.20;
5
+
6
+ /**
7
+ * @dev Library for performing external calls through dynamically deployed relay contracts that hide the original
8
+ * caller's address from the target contract. This pattern is used in ERC-4337's EntryPoint for account factory
9
+ * calls and ERC-6942 for safe factory interactions.
10
+ *
11
+ * When privileged contracts need to make arbitrary external calls based on user input, calling the target directly
12
+ * can be risky because the target sees the privileged contract as `msg.sender` and could exploit this trust
13
+ * relationship. This library solves this by deploying minimal relay contracts that act as intermediaries, ensuring
14
+ * the target only sees the unprivileged relay address as `msg.sender`.
15
+ *
16
+ * For example, instead of `target.call(data)` where the target sees this contract as `msg.sender`, use
17
+ * {relayCall} where the target sees a relay address as `msg.sender`.
18
+ *
19
+ * NOTE: This library uses the PUSH0 opcode that was introduced in the Shanghai hardfork. While this instruction is
20
+ * now widely supported, developers using the library on exotic chains should verify that their target chain has
21
+ * supports for EIP-3855.
22
+ */
23
+ library RelayedCall {
24
+ /// @dev Relays a call to the target contract through a dynamically deployed relay contract.
25
+ function relayCall(address target, bytes memory data) internal returns (bool success, bytes memory retData) {
26
+ return relayCall(target, 0, data, bytes32(0));
27
+ }
28
+
29
+ /// @dev Same as {relayCall-address-bytes} but with a value.
30
+ function relayCall(
31
+ address target,
32
+ uint256 value,
33
+ bytes memory data
34
+ ) internal returns (bool success, bytes memory retData) {
35
+ return relayCall(target, value, data, bytes32(0));
36
+ }
37
+
38
+ /// @dev Same as {relayCall-address-bytes} but with a salt.
39
+ function relayCall(
40
+ address target,
41
+ bytes memory data,
42
+ bytes32 salt
43
+ ) internal returns (bool success, bytes memory retData) {
44
+ return relayCall(target, 0, data, salt);
45
+ }
46
+
47
+ /// @dev Same as {relayCall-address-bytes} but with a salt and a value.
48
+ function relayCall(
49
+ address target,
50
+ uint256 value,
51
+ bytes memory data,
52
+ bytes32 salt
53
+ ) internal returns (bool success, bytes memory retData) {
54
+ return getRelayer(salt).call{value: value}(abi.encodePacked(target, data));
55
+ }
56
+
57
+ /// @dev Same as {getRelayer} but with a `bytes32(0)` default salt.
58
+ function getRelayer() internal returns (address) {
59
+ return getRelayer(bytes32(0));
60
+ }
61
+
62
+ /// @dev Returns the relayer address for a given salt.
63
+ function getRelayer(bytes32 salt) internal returns (address relayer) {
64
+ // [Relayer details]
65
+ //
66
+ // deployment prefix: 60475f8160095f39f3
67
+ // deployed bytecode: 73<addr>331460133611166022575f5ffd5b6014360360145f375f5f601436035f345f3560601c5af13d5f5f3e5f3d91604557fd5bf3
68
+ //
69
+ // offset | bytecode | opcode | stack
70
+ // -------|-------------|----------------|--------
71
+ // 0x0000 | 73<factory> | push20 <addr> | <factory>
72
+ // 0x0015 | 33 | address | <caller> <factory>
73
+ // 0x0016 | 14 | eq | access
74
+ // 0x0017 | 6013 | push1 0x13 | 0x13 access
75
+ // 0x0019 | 36 | calldatasize | cds 0x13 access
76
+ // 0x001a | 11 | gt | (cds>0x13) access
77
+ // 0x001b | 16 | and | (cds>0x13 && access)
78
+ // 0x001c | 6022 | push1 0x22 | 0x22 (cds>0x13 && access)
79
+ // 0x001e | 57 | jumpi |
80
+ // 0x001f | 5f | push0 | 0
81
+ // 0x0020 | 5f | push0 | 0 0
82
+ // 0x0021 | fd | revert |
83
+ // 0x0022 | 5b | jumpdest |
84
+ // 0x0023 | 6014 | push1 0x14 | 0x14
85
+ // 0x0025 | 36 | calldatasize | cds 0x14
86
+ // 0x0026 | 03 | sub | (cds-0x14)
87
+ // 0x0027 | 6014 | push1 0x14 | 0x14 (cds-0x14)
88
+ // 0x0029 | 5f | push0 | 0 0x14 (cds-0x14)
89
+ // 0x002a | 37 | calldatacopy |
90
+ // 0x002b | 5f | push0 | 0
91
+ // 0x002c | 5f | push0 | 0 0
92
+ // 0x002d | 6014 | push1 0x14 | 0x14 0 0
93
+ // 0x002f | 36 | calldatasize | cds 0x14 0 0
94
+ // 0x0030 | 03 | sub | (cds-0x14) 0 0
95
+ // 0x0031 | 5f | push0 | 0 (cds-0x14) 0 0
96
+ // 0x0032 | 34 | callvalue | value 0 (cds-0x14) 0 0
97
+ // 0x0033 | 5f | push0 | 0 value 0 (cds-0x14) 0 0
98
+ // 0x0034 | 35 | calldataload | cd[0] value 0 (cds-0x14) 0 0
99
+ // 0x0035 | 6060 | push1 0x60 | 0x60 cd[0] value 0 (cds-0x14) 0 0
100
+ // 0x0037 | 1c | shr | target value 0 (cds-0x14) 0 0
101
+ // 0x0038 | 5a | gas | gas target value 0 (cds-0x14) 0 0
102
+ // 0x0039 | f1 | call | suc
103
+ // 0x003a | 3d | returndatasize | rds suc
104
+ // 0x003b | 5f | push0 | 0 rds suc
105
+ // 0x003c | 5f | push0 | 0 0 rds suc
106
+ // 0x003d | 3e | returndatacopy | suc
107
+ // 0x003e | 5f | push0 | 0 suc
108
+ // 0x003f | 3d | returndatasize | rds 0 suc
109
+ // 0x0040 | 91 | swap2 | suc 0 rds
110
+ // 0x0041 | 6045 | push1 0x45 | 0x45 suc 0 rds
111
+ // 0x0043 | 57 | jumpi | 0 rds
112
+ // 0x0044 | fd | revert |
113
+ // 0x0045 | 5b | jumpdest | 0 rds
114
+ // 0x0046 | f3 | return |
115
+
116
+ assembly ("memory-safe") {
117
+ let fmp := mload(0x40)
118
+
119
+ // build initcode at FMP
120
+ mstore(add(fmp, 0x46), 0x60145f375f5f601436035f345f3560601c5af13d5f5f3e5f3d91604557fd5bf3)
121
+ mstore(add(fmp, 0x26), 0x331460133611166022575f5ffd5b60143603)
122
+ mstore(add(fmp, 0x14), address())
123
+ mstore(add(fmp, 0x00), 0x60475f8160095f39f373)
124
+ let initcodehash := keccak256(add(fmp, 0x16), 0x50)
125
+
126
+ // compute create2 address
127
+ mstore(0x40, initcodehash)
128
+ mstore(0x20, salt)
129
+ mstore(0x00, address())
130
+ mstore8(0x0b, 0xff)
131
+ relayer := and(keccak256(0x0b, 0x55), shr(96, not(0)))
132
+
133
+ // is relayer not yet deployed, deploy it
134
+ if iszero(extcodesize(relayer)) {
135
+ if iszero(create2(0, add(fmp, 0x16), 0x50, salt)) {
136
+ returndatacopy(fmp, 0x00, returndatasize())
137
+ revert(fmp, returndatasize())
138
+ }
139
+ }
140
+
141
+ // cleanup fmp space used as scratch
142
+ mstore(0x40, fmp)
143
+ }
144
+ }
145
+ }