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,64 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // OpenZeppelin Contracts (last updated v5.8.0) (governance/extensions/GovernorVotes.sol)
3
+
4
+ pragma solidity ^0.8.24;
5
+
6
+ import {IERC5805} from "../../interfaces/IERC5805.sol";
7
+ import {ERC6372Utils} from "../../utils/ERC6372Utils.sol";
8
+ import {Time} from "../../utils/types/Time.sol";
9
+ import {Governor} from "../Governor.sol";
10
+ import {IVotes} from "../utils/IVotes.sol";
11
+
12
+ /**
13
+ * @dev Extension of {Governor} for voting weight extraction from an {ERC20Votes} token, or since v4.5 an {ERC721Votes}
14
+ * token.
15
+ */
16
+ abstract contract GovernorVotes is Governor {
17
+ IERC5805 private immutable _token;
18
+
19
+ constructor(IVotes tokenAddress) {
20
+ _token = IERC5805(address(tokenAddress));
21
+ }
22
+
23
+ /**
24
+ * @dev The token that voting power is sourced from.
25
+ */
26
+ function token() public view virtual returns (IERC5805) {
27
+ return _token;
28
+ }
29
+
30
+ /**
31
+ * @dev Clock (as specified in ERC-6372) is set to match the token's clock. Fallback to block numbers if the token
32
+ * does not implement ERC-6372.
33
+ */
34
+ function clock() public view virtual override returns (uint48) {
35
+ try token().clock() returns (uint48 timepoint) {
36
+ return timepoint;
37
+ } catch {
38
+ return Time.blockNumber();
39
+ }
40
+ }
41
+
42
+ /**
43
+ * @dev Machine-readable description of the clock as specified in ERC-6372.
44
+ */
45
+ // solhint-disable-next-line func-name-mixedcase
46
+ function CLOCK_MODE() public view virtual override returns (string memory) {
47
+ try token().CLOCK_MODE() returns (string memory clockmode) {
48
+ return clockmode;
49
+ } catch {
50
+ return ERC6372Utils.blockNumberClockMode(clock);
51
+ }
52
+ }
53
+
54
+ /**
55
+ * Read the voting weight from the token's built in snapshot mechanism (see {Governor-_getVotes}).
56
+ */
57
+ function _getVotes(
58
+ address account,
59
+ uint256 timepoint,
60
+ bytes memory /*params*/
61
+ ) internal view virtual override returns (uint256) {
62
+ return token().getPastVotes(account, timepoint);
63
+ }
64
+ }
@@ -0,0 +1,113 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // OpenZeppelin Contracts (last updated v5.8.0) (governance/extensions/GovernorVotesQuorumFraction.sol)
3
+
4
+ pragma solidity ^0.8.24;
5
+
6
+ import {Math} from "../../utils/math/Math.sol";
7
+ import {SafeCast} from "../../utils/math/SafeCast.sol";
8
+ import {Checkpoints} from "../../utils/structs/Checkpoints.sol";
9
+ import {GovernorVotes} from "./GovernorVotes.sol";
10
+
11
+ /**
12
+ * @dev Extension of {Governor} for voting weight extraction from an {ERC20Votes} token and a quorum expressed as a
13
+ * fraction of the total supply.
14
+ */
15
+ abstract contract GovernorVotesQuorumFraction is GovernorVotes {
16
+ using Checkpoints for Checkpoints.Trace208;
17
+
18
+ Checkpoints.Trace208 private _quorumNumeratorHistory;
19
+
20
+ event QuorumNumeratorUpdated(uint256 oldQuorumNumerator, uint256 newQuorumNumerator);
21
+
22
+ /**
23
+ * @dev The quorum set is not a valid fraction.
24
+ */
25
+ error GovernorInvalidQuorumFraction(uint256 quorumNumerator, uint256 quorumDenominator);
26
+
27
+ /**
28
+ * @dev Initialize quorum as a fraction of the token's total supply.
29
+ *
30
+ * The fraction is specified as `numerator / denominator`. By default the denominator is 100, so quorum is
31
+ * specified as a percent: a numerator of 10 corresponds to quorum being 10% of total supply. The denominator can be
32
+ * customized by overriding {quorumDenominator}.
33
+ */
34
+ constructor(uint256 quorumNumeratorValue) {
35
+ _updateQuorumNumerator(quorumNumeratorValue);
36
+ }
37
+
38
+ /**
39
+ * @dev Returns the current quorum numerator. See {quorumDenominator}.
40
+ */
41
+ function quorumNumerator() public view virtual returns (uint256) {
42
+ return _quorumNumeratorHistory.latest();
43
+ }
44
+
45
+ /**
46
+ * @dev Returns the quorum numerator at a specific timepoint. See {quorumDenominator}.
47
+ */
48
+ function quorumNumerator(uint256 timepoint) public view virtual returns (uint256) {
49
+ return _optimisticUpperLookupRecent(_quorumNumeratorHistory, timepoint);
50
+ }
51
+
52
+ /**
53
+ * @dev Returns the quorum denominator. Defaults to 100, but may be overridden.
54
+ */
55
+ function quorumDenominator() public view virtual returns (uint256) {
56
+ return 100;
57
+ }
58
+
59
+ /**
60
+ * @dev Returns the quorum for a timepoint, in terms of number of votes: `supply * numerator / denominator`.
61
+ */
62
+ function quorum(uint256 timepoint) public view virtual override returns (uint256) {
63
+ return Math.mulDiv(token().getPastTotalSupply(timepoint), quorumNumerator(timepoint), quorumDenominator());
64
+ }
65
+
66
+ /**
67
+ * @dev Changes the quorum numerator.
68
+ *
69
+ * Emits a {QuorumNumeratorUpdated} event.
70
+ *
71
+ * Requirements:
72
+ *
73
+ * - Must be called through a governance proposal.
74
+ * - New numerator must be smaller or equal to the denominator.
75
+ */
76
+ function updateQuorumNumerator(uint256 newQuorumNumerator) public virtual onlyGovernance {
77
+ _updateQuorumNumerator(newQuorumNumerator);
78
+ }
79
+
80
+ /**
81
+ * @dev Changes the quorum numerator.
82
+ *
83
+ * Emits a {QuorumNumeratorUpdated} event.
84
+ *
85
+ * Requirements:
86
+ *
87
+ * - New numerator must be smaller or equal to the denominator.
88
+ */
89
+ function _updateQuorumNumerator(uint256 newQuorumNumerator) internal virtual {
90
+ uint256 denominator = quorumDenominator();
91
+ if (newQuorumNumerator > denominator) {
92
+ revert GovernorInvalidQuorumFraction(newQuorumNumerator, denominator);
93
+ }
94
+
95
+ uint256 oldQuorumNumerator = quorumNumerator();
96
+ _quorumNumeratorHistory.push(clock(), SafeCast.toUint208(newQuorumNumerator));
97
+
98
+ emit QuorumNumeratorUpdated(oldQuorumNumerator, newQuorumNumerator);
99
+ }
100
+
101
+ /**
102
+ * @dev Returns the numerator at a specific timepoint.
103
+ */
104
+ function _optimisticUpperLookupRecent(
105
+ Checkpoints.Trace208 storage ckpts,
106
+ uint256 timepoint
107
+ ) internal view returns (uint256) {
108
+ // If trace is empty, key and value are both equal to 0.
109
+ // In that case `key <= timepoint` is true, and it is ok to return 0.
110
+ (, uint48 key, uint208 value) = ckpts.latestCheckpoint();
111
+ return key <= timepoint ? value : ckpts.upperLookupRecent(SafeCast.toUint48(timepoint));
112
+ }
113
+ }
@@ -0,0 +1,135 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // OpenZeppelin Contracts (last updated v5.8.0) (governance/extensions/GovernorVotesSuperQuorumFraction.sol)
3
+
4
+ pragma solidity ^0.8.24;
5
+
6
+ import {Math} from "../../utils/math/Math.sol";
7
+ import {SafeCast} from "../../utils/math/SafeCast.sol";
8
+ import {Checkpoints} from "../../utils/structs/Checkpoints.sol";
9
+ import {Governor} from "../Governor.sol";
10
+ import {GovernorSuperQuorum} from "./GovernorSuperQuorum.sol";
11
+ import {GovernorVotesQuorumFraction} from "./GovernorVotesQuorumFraction.sol";
12
+
13
+ /**
14
+ * @dev Extension of {GovernorVotesQuorumFraction} with a super quorum expressed as a
15
+ * fraction of the total supply. Proposals that meet the super quorum (and have a majority of for votes) advance to
16
+ * the `Succeeded` state before the proposal deadline.
17
+ */
18
+ abstract contract GovernorVotesSuperQuorumFraction is GovernorVotesQuorumFraction, GovernorSuperQuorum {
19
+ using Checkpoints for Checkpoints.Trace208;
20
+
21
+ Checkpoints.Trace208 private _superQuorumNumeratorHistory;
22
+
23
+ event SuperQuorumNumeratorUpdated(uint256 oldSuperQuorumNumerator, uint256 newSuperQuorumNumerator);
24
+
25
+ /**
26
+ * @dev The super quorum set is not valid as it exceeds the quorum denominator.
27
+ */
28
+ error GovernorInvalidSuperQuorumFraction(uint256 superQuorumNumerator, uint256 denominator);
29
+
30
+ /**
31
+ * @dev The super quorum set is not valid as it is smaller than the quorum.
32
+ */
33
+ error GovernorInvalidSuperQuorumTooSmall(uint256 superQuorumNumerator, uint256 quorumNumerator);
34
+
35
+ /**
36
+ * @dev The quorum set is not valid as it exceeds the super quorum.
37
+ */
38
+ error GovernorInvalidQuorumTooLarge(uint256 quorumNumerator, uint256 superQuorumNumerator);
39
+
40
+ /**
41
+ * @dev Initialize super quorum as a fraction of the token's total supply.
42
+ *
43
+ * The super quorum is specified as a fraction of the token's total supply and has to
44
+ * be greater than or equal to the quorum.
45
+ */
46
+ constructor(uint256 superQuorumNumeratorValue) {
47
+ _updateSuperQuorumNumerator(superQuorumNumeratorValue);
48
+ }
49
+
50
+ /**
51
+ * @dev Returns the current super quorum numerator.
52
+ */
53
+ function superQuorumNumerator() public view virtual returns (uint256) {
54
+ return _superQuorumNumeratorHistory.latest();
55
+ }
56
+
57
+ /**
58
+ * @dev Returns the super quorum numerator at a specific `timepoint`.
59
+ */
60
+ function superQuorumNumerator(uint256 timepoint) public view virtual returns (uint256) {
61
+ return _optimisticUpperLookupRecent(_superQuorumNumeratorHistory, timepoint);
62
+ }
63
+
64
+ /**
65
+ * @dev Returns the super quorum for a `timepoint`, in terms of number of votes: `supply * numerator / denominator`.
66
+ * See {GovernorSuperQuorum-superQuorum} for more details.
67
+ */
68
+ function superQuorum(uint256 timepoint) public view virtual override returns (uint256) {
69
+ return Math.mulDiv(token().getPastTotalSupply(timepoint), superQuorumNumerator(timepoint), quorumDenominator());
70
+ }
71
+
72
+ /**
73
+ * @dev Changes the super quorum numerator.
74
+ *
75
+ * Emits a {SuperQuorumNumeratorUpdated} event.
76
+ *
77
+ * Requirements:
78
+ *
79
+ * - Must be called through a governance proposal.
80
+ * - New super quorum numerator must be smaller or equal to the denominator.
81
+ * - New super quorum numerator must be greater than or equal to the quorum numerator.
82
+ */
83
+ function updateSuperQuorumNumerator(uint256 newSuperQuorumNumerator) public virtual onlyGovernance {
84
+ _updateSuperQuorumNumerator(newSuperQuorumNumerator);
85
+ }
86
+
87
+ /**
88
+ * @dev Changes the super quorum numerator.
89
+ *
90
+ * Emits a {SuperQuorumNumeratorUpdated} event.
91
+ *
92
+ * Requirements:
93
+ *
94
+ * - New super quorum numerator must be smaller or equal to the denominator.
95
+ * - New super quorum numerator must be greater than or equal to the quorum numerator.
96
+ */
97
+ function _updateSuperQuorumNumerator(uint256 newSuperQuorumNumerator) internal virtual {
98
+ uint256 denominator = quorumDenominator();
99
+ if (newSuperQuorumNumerator > denominator) {
100
+ revert GovernorInvalidSuperQuorumFraction(newSuperQuorumNumerator, denominator);
101
+ }
102
+
103
+ uint256 quorumNumerator = quorumNumerator();
104
+ if (newSuperQuorumNumerator < quorumNumerator) {
105
+ revert GovernorInvalidSuperQuorumTooSmall(newSuperQuorumNumerator, quorumNumerator);
106
+ }
107
+
108
+ uint256 oldSuperQuorumNumerator = _superQuorumNumeratorHistory.latest();
109
+ _superQuorumNumeratorHistory.push(clock(), SafeCast.toUint208(newSuperQuorumNumerator));
110
+
111
+ emit SuperQuorumNumeratorUpdated(oldSuperQuorumNumerator, newSuperQuorumNumerator);
112
+ }
113
+
114
+ /**
115
+ * @dev Overrides {GovernorVotesQuorumFraction-_updateQuorumNumerator} to ensure the super
116
+ * quorum numerator is greater than or equal to the quorum numerator.
117
+ */
118
+ function _updateQuorumNumerator(uint256 newQuorumNumerator) internal virtual override {
119
+ // Ignoring check when the superQuorum was never set (construction sets quorum before superQuorum)
120
+ if (_superQuorumNumeratorHistory.length() > 0) {
121
+ uint256 superQuorumNumerator_ = superQuorumNumerator();
122
+ if (newQuorumNumerator > superQuorumNumerator_) {
123
+ revert GovernorInvalidQuorumTooLarge(newQuorumNumerator, superQuorumNumerator_);
124
+ }
125
+ }
126
+ super._updateQuorumNumerator(newQuorumNumerator);
127
+ }
128
+
129
+ /// @inheritdoc GovernorSuperQuorum
130
+ function state(
131
+ uint256 proposalId
132
+ ) public view virtual override(Governor, GovernorSuperQuorum) returns (ProposalState) {
133
+ return super.state(proposalId);
134
+ }
135
+ }
@@ -0,0 +1,60 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // OpenZeppelin Contracts (last updated v5.5.0) (governance/utils/IVotes.sol)
3
+
4
+ pragma solidity >=0.8.4;
5
+
6
+ /**
7
+ * @dev Common interface for {ERC20Votes}, {ERC721Votes}, and other {Votes}-enabled contracts.
8
+ */
9
+ interface IVotes {
10
+ /**
11
+ * @dev The signature used has expired.
12
+ */
13
+ error VotesExpiredSignature(uint256 expiry);
14
+
15
+ /**
16
+ * @dev Emitted when an account changes their delegate.
17
+ */
18
+ event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);
19
+
20
+ /**
21
+ * @dev Emitted when a token transfer or delegate change results in changes to a delegate's number of voting units.
22
+ */
23
+ event DelegateVotesChanged(address indexed delegate, uint256 previousVotes, uint256 newVotes);
24
+
25
+ /**
26
+ * @dev Returns the current amount of votes that `account` has.
27
+ */
28
+ function getVotes(address account) external view returns (uint256);
29
+
30
+ /**
31
+ * @dev Returns the amount of votes that `account` had at a specific moment in the past. If the `clock()` is
32
+ * configured to use block numbers, this will return the value at the end of the corresponding block.
33
+ */
34
+ function getPastVotes(address account, uint256 timepoint) external view returns (uint256);
35
+
36
+ /**
37
+ * @dev Returns the total supply of votes available at a specific moment in the past. If the `clock()` is
38
+ * configured to use block numbers, this will return the value at the end of the corresponding block.
39
+ *
40
+ * NOTE: This value is the sum of all available votes, which is not necessarily the sum of all delegated votes.
41
+ * Votes that have not been delegated are still part of total supply, even though they would not participate in a
42
+ * vote.
43
+ */
44
+ function getPastTotalSupply(uint256 timepoint) external view returns (uint256);
45
+
46
+ /**
47
+ * @dev Returns the delegate that `account` has chosen.
48
+ */
49
+ function delegates(address account) external view returns (address);
50
+
51
+ /**
52
+ * @dev Delegates votes from the sender to `delegatee`.
53
+ */
54
+ function delegate(address delegatee) external;
55
+
56
+ /**
57
+ * @dev Delegates votes from signer to `delegatee`.
58
+ */
59
+ function delegateBySig(address delegatee, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s) external;
60
+ }
@@ -0,0 +1,245 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // OpenZeppelin Contracts (last updated v5.8.0) (governance/utils/Votes.sol)
3
+
4
+ pragma solidity ^0.8.24;
5
+
6
+ import {IERC5805} from "../../interfaces/IERC5805.sol";
7
+ import {Context} from "../../utils/Context.sol";
8
+ import {ECDSA} from "../../utils/cryptography/ECDSA.sol";
9
+ import {EIP712} from "../../utils/cryptography/EIP712.sol";
10
+ import {ERC6372Utils} from "../../utils/ERC6372Utils.sol";
11
+ import {SafeCast} from "../../utils/math/SafeCast.sol";
12
+ import {Nonces} from "../../utils/Nonces.sol";
13
+ import {Checkpoints} from "../../utils/structs/Checkpoints.sol";
14
+ import {Time} from "../../utils/types/Time.sol";
15
+
16
+ /**
17
+ * @dev This is a base abstract contract that tracks voting units, which are a measure of voting power that can be
18
+ * transferred, and provides a system of vote delegation, where an account can delegate its voting units to a sort of
19
+ * "representative" that will pool delegated voting units from different accounts and can then use it to vote in
20
+ * decisions. In fact, voting units _must_ be delegated in order to count as actual votes, and an account has to
21
+ * delegate those votes to itself if it wishes to participate in decisions and does not have a trusted representative.
22
+ *
23
+ * This contract is often combined with a token contract such that voting units correspond to token units. For an
24
+ * example, see {ERC721Votes}.
25
+ *
26
+ * The full history of delegate votes is tracked on-chain so that governance protocols can consider votes as distributed
27
+ * at a particular block number to protect against flash loans and double voting. The opt-in delegate system makes the
28
+ * cost of this history tracking optional.
29
+ *
30
+ * When using this module the derived contract must implement {_getVotingUnits} (for example, make it return
31
+ * {ERC721-balanceOf}), and can use {_transferVotingUnits} to track a change in the distribution of those units (in the
32
+ * previous example, it would be included in {ERC721-_update}).
33
+ */
34
+ abstract contract Votes is Context, EIP712, Nonces, IERC5805 {
35
+ using Checkpoints for Checkpoints.Trace208;
36
+
37
+ bytes32 private constant DELEGATION_TYPEHASH =
38
+ keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
39
+
40
+ mapping(address account => address) private _delegatee;
41
+
42
+ mapping(address delegatee => Checkpoints.Trace208) private _delegateCheckpoints;
43
+
44
+ Checkpoints.Trace208 private _totalCheckpoints;
45
+
46
+ /**
47
+ * @dev Lookup to future votes is not available.
48
+ */
49
+ error ERC5805FutureLookup(uint256 timepoint, uint48 clock);
50
+
51
+ /**
52
+ * @dev Clock used for flagging checkpoints. Can be overridden to implement timestamp based
53
+ * checkpoints (and voting), in which case {CLOCK_MODE} should be overridden as well to match.
54
+ */
55
+ function clock() public view virtual returns (uint48) {
56
+ return Time.blockNumber();
57
+ }
58
+
59
+ /**
60
+ * @dev Machine-readable description of the clock as specified in ERC-6372.
61
+ */
62
+ // solhint-disable-next-line func-name-mixedcase
63
+ function CLOCK_MODE() public view virtual returns (string memory) {
64
+ return ERC6372Utils.blockNumberClockMode(clock);
65
+ }
66
+
67
+ /**
68
+ * @dev Validate that a timepoint is in the past, and return it as a uint48.
69
+ */
70
+ function _validateTimepoint(uint256 timepoint) internal view returns (uint48) {
71
+ uint48 currentTimepoint = clock();
72
+ if (timepoint >= currentTimepoint) revert ERC5805FutureLookup(timepoint, currentTimepoint);
73
+ return SafeCast.toUint48(timepoint);
74
+ }
75
+
76
+ /**
77
+ * @dev Returns the current amount of votes that `account` has.
78
+ */
79
+ function getVotes(address account) public view virtual returns (uint256) {
80
+ return _delegateCheckpoints[account].latest();
81
+ }
82
+
83
+ /**
84
+ * @dev Returns the amount of votes that `account` had at a specific moment in the past. If the `clock()` is
85
+ * configured to use block numbers, this will return the value at the end of the corresponding block.
86
+ *
87
+ * Requirements:
88
+ *
89
+ * - `timepoint` must be in the past. If operating using block numbers, the block must be already mined.
90
+ */
91
+ function getPastVotes(address account, uint256 timepoint) public view virtual returns (uint256) {
92
+ return _delegateCheckpoints[account].upperLookupRecent(_validateTimepoint(timepoint));
93
+ }
94
+
95
+ /**
96
+ * @dev Returns the total supply of votes available at a specific moment in the past. If the `clock()` is
97
+ * configured to use block numbers, this will return the value at the end of the corresponding block.
98
+ *
99
+ * NOTE: This value is the sum of all available votes, which is not necessarily the sum of all delegated votes.
100
+ * Votes that have not been delegated are still part of total supply, even though they would not participate in a
101
+ * vote.
102
+ *
103
+ * Requirements:
104
+ *
105
+ * - `timepoint` must be in the past. If operating using block numbers, the block must be already mined.
106
+ */
107
+ function getPastTotalSupply(uint256 timepoint) public view virtual returns (uint256) {
108
+ return _totalCheckpoints.upperLookupRecent(_validateTimepoint(timepoint));
109
+ }
110
+
111
+ /**
112
+ * @dev Returns the current total supply of votes.
113
+ */
114
+ function _getTotalSupply() internal view virtual returns (uint256) {
115
+ return _totalCheckpoints.latest();
116
+ }
117
+
118
+ /**
119
+ * @dev Returns the delegate that `account` has chosen.
120
+ */
121
+ function delegates(address account) public view virtual returns (address) {
122
+ return _delegatee[account];
123
+ }
124
+
125
+ /**
126
+ * @dev Delegates votes from the sender to `delegatee`.
127
+ */
128
+ function delegate(address delegatee) public virtual {
129
+ address account = _msgSender();
130
+ _delegate(account, delegatee);
131
+ }
132
+
133
+ /**
134
+ * @dev Delegates votes from signer to `delegatee`.
135
+ */
136
+ function delegateBySig(
137
+ address delegatee,
138
+ uint256 nonce,
139
+ uint256 expiry,
140
+ uint8 v,
141
+ bytes32 r,
142
+ bytes32 s
143
+ ) public virtual {
144
+ if (block.timestamp > expiry) {
145
+ revert VotesExpiredSignature(expiry);
146
+ }
147
+ address signer = ECDSA.recover(
148
+ _hashTypedDataV4(keccak256(abi.encode(DELEGATION_TYPEHASH, delegatee, nonce, expiry))),
149
+ v,
150
+ r,
151
+ s
152
+ );
153
+ _useCheckedNonce(signer, nonce);
154
+ _delegate(signer, delegatee);
155
+ }
156
+
157
+ /**
158
+ * @dev Delegate all of `account`'s voting units to `delegatee`.
159
+ *
160
+ * Emits events {IVotes-DelegateChanged} and {IVotes-DelegateVotesChanged}.
161
+ */
162
+ function _delegate(address account, address delegatee) internal virtual {
163
+ address oldDelegate = delegates(account);
164
+ _delegatee[account] = delegatee;
165
+
166
+ emit DelegateChanged(account, oldDelegate, delegatee);
167
+ _moveDelegateVotes(oldDelegate, delegatee, _getVotingUnits(account));
168
+ }
169
+
170
+ /**
171
+ * @dev Transfers, mints, or burns voting units. To register a mint, `from` should be zero. To register a burn, `to`
172
+ * should be zero. Total supply of voting units will be adjusted with mints and burns.
173
+ */
174
+ function _transferVotingUnits(address from, address to, uint256 amount) internal virtual {
175
+ if (from == address(0)) {
176
+ _push(_totalCheckpoints, _add, SafeCast.toUint208(amount));
177
+ }
178
+ if (to == address(0)) {
179
+ _push(_totalCheckpoints, _subtract, SafeCast.toUint208(amount));
180
+ }
181
+ _moveDelegateVotes(delegates(from), delegates(to), amount);
182
+ }
183
+
184
+ /**
185
+ * @dev Moves delegated votes from one delegate to another.
186
+ */
187
+ function _moveDelegateVotes(address from, address to, uint256 amount) internal virtual {
188
+ if (from != to && amount > 0) {
189
+ if (from != address(0)) {
190
+ (uint256 oldValue, uint256 newValue) = _push(
191
+ _delegateCheckpoints[from],
192
+ _subtract,
193
+ SafeCast.toUint208(amount)
194
+ );
195
+ emit DelegateVotesChanged(from, oldValue, newValue);
196
+ }
197
+ if (to != address(0)) {
198
+ (uint256 oldValue, uint256 newValue) = _push(
199
+ _delegateCheckpoints[to],
200
+ _add,
201
+ SafeCast.toUint208(amount)
202
+ );
203
+ emit DelegateVotesChanged(to, oldValue, newValue);
204
+ }
205
+ }
206
+ }
207
+
208
+ /**
209
+ * @dev Get number of checkpoints for `account`.
210
+ */
211
+ function _numCheckpoints(address account) internal view virtual returns (uint32) {
212
+ return SafeCast.toUint32(_delegateCheckpoints[account].length());
213
+ }
214
+
215
+ /**
216
+ * @dev Get the `index`-th checkpoint for `account`.
217
+ */
218
+ function _checkpoints(
219
+ address account,
220
+ uint32 index
221
+ ) internal view virtual returns (Checkpoints.Checkpoint208 memory) {
222
+ return _delegateCheckpoints[account].pos(index);
223
+ }
224
+
225
+ function _push(
226
+ Checkpoints.Trace208 storage store,
227
+ function(uint208, uint208) view returns (uint208) op,
228
+ uint208 delta
229
+ ) private returns (uint208 oldValue, uint208 newValue) {
230
+ return store.push(clock(), op(store.latest(), delta));
231
+ }
232
+
233
+ function _add(uint208 a, uint208 b) private pure returns (uint208) {
234
+ return a + b;
235
+ }
236
+
237
+ function _subtract(uint208 a, uint208 b) private pure returns (uint208) {
238
+ return a - b;
239
+ }
240
+
241
+ /**
242
+ * @dev Must return the voting units held by an account.
243
+ */
244
+ function _getVotingUnits(address) internal view virtual returns (uint256);
245
+ }