From b808c2bcc090dc92fdc22449e1196e06112805e8 Mon Sep 17 00:00:00 2001 From: Gonzalo Othacehe Date: Mon, 11 Aug 2025 19:13:47 -0300 Subject: [PATCH 01/79] init hooks wizard --- packages/core/solidity/package.json | 1 + packages/core/uniswap-hooks/.gitignore | 4 + packages/core/uniswap-hooks/CHANGELOG.md | 6 + packages/core/uniswap-hooks/LICENSE | 661 ++++++++++++++++++ packages/core/uniswap-hooks/NOTICE | 8 + packages/core/uniswap-hooks/README.md | 86 +++ packages/core/uniswap-hooks/ava.config.js | 9 + packages/core/uniswap-hooks/package.json | 36 + packages/core/uniswap-hooks/src/api.ts | 36 + .../core/uniswap-hooks/src/build-generic.ts | 17 + .../src/generate/alternatives.ts | 32 + .../core/uniswap-hooks/src/generate/hooks.ts | 19 + packages/core/uniswap-hooks/src/hooks.ts | 56 ++ packages/core/uniswap-hooks/src/index.ts | 11 + packages/core/uniswap-hooks/src/kind.ts | 26 + .../core/uniswap-hooks/src/utils/version.ts | 4 + packages/core/uniswap-hooks/tsconfig.json | 16 + packages/ui/public/cairo.html | 1 + packages/ui/public/icons/uniswap-hooks.svg | 13 + .../ui/public/icons/uniswap-hooks_active.svg | 14 + packages/ui/public/index.html | 1 + packages/ui/public/stellar.html | 1 + packages/ui/public/stylus.html | 1 + packages/ui/public/uniswap-hooks.html | 87 +++ packages/ui/src/common/languages-types.ts | 6 +- packages/ui/src/main.ts | 14 +- packages/ui/src/standalone.css | 4 + .../uniswap-hooks/AccessControlSection.svelte | 62 ++ packages/ui/src/uniswap-hooks/App.svelte | 264 +++++++ .../ui/src/uniswap-hooks/HooksControls.svelte | 46 ++ .../ui/src/uniswap-hooks/InfoSection.svelte | 32 + packages/ui/src/uniswap-hooks/highlightjs.ts | 7 + .../ui/src/uniswap-hooks/inject-hyperlinks.ts | 18 + packages/ui/src/uniswap-hooks/remix.ts | 15 + yarn.lock | 4 + 35 files changed, 1615 insertions(+), 3 deletions(-) create mode 100644 packages/core/uniswap-hooks/.gitignore create mode 100644 packages/core/uniswap-hooks/CHANGELOG.md create mode 100644 packages/core/uniswap-hooks/LICENSE create mode 100644 packages/core/uniswap-hooks/NOTICE create mode 100644 packages/core/uniswap-hooks/README.md create mode 100644 packages/core/uniswap-hooks/ava.config.js create mode 100644 packages/core/uniswap-hooks/package.json create mode 100644 packages/core/uniswap-hooks/src/api.ts create mode 100644 packages/core/uniswap-hooks/src/build-generic.ts create mode 100644 packages/core/uniswap-hooks/src/generate/alternatives.ts create mode 100644 packages/core/uniswap-hooks/src/generate/hooks.ts create mode 100644 packages/core/uniswap-hooks/src/hooks.ts create mode 100644 packages/core/uniswap-hooks/src/index.ts create mode 100644 packages/core/uniswap-hooks/src/kind.ts create mode 100644 packages/core/uniswap-hooks/src/utils/version.ts create mode 100644 packages/core/uniswap-hooks/tsconfig.json create mode 100644 packages/ui/public/icons/uniswap-hooks.svg create mode 100644 packages/ui/public/icons/uniswap-hooks_active.svg create mode 100644 packages/ui/public/uniswap-hooks.html create mode 100644 packages/ui/src/uniswap-hooks/AccessControlSection.svelte create mode 100644 packages/ui/src/uniswap-hooks/App.svelte create mode 100644 packages/ui/src/uniswap-hooks/HooksControls.svelte create mode 100644 packages/ui/src/uniswap-hooks/InfoSection.svelte create mode 100644 packages/ui/src/uniswap-hooks/highlightjs.ts create mode 100644 packages/ui/src/uniswap-hooks/inject-hyperlinks.ts create mode 100644 packages/ui/src/uniswap-hooks/remix.ts diff --git a/packages/core/solidity/package.json b/packages/core/solidity/package.json index 804075fab..caee9a643 100644 --- a/packages/core/solidity/package.json +++ b/packages/core/solidity/package.json @@ -23,6 +23,7 @@ }, "devDependencies": { "@openzeppelin/community-contracts": "https://github.com/OpenZeppelin/openzeppelin-community-contracts", + "@openzeppelin/uniswap-hooks": "https://github.com/OpenZeppelin/uniswap-hooks", "@openzeppelin/contracts": "^5.3.0", "@openzeppelin/contracts-upgradeable": "^5.3.0", "@types/node": "^20.0.0", diff --git a/packages/core/uniswap-hooks/.gitignore b/packages/core/uniswap-hooks/.gitignore new file mode 100644 index 000000000..017fefa2d --- /dev/null +++ b/packages/core/uniswap-hooks/.gitignore @@ -0,0 +1,4 @@ +/cache +/artifacts +/contracts/generated +/openzeppelin-contracts.json diff --git a/packages/core/uniswap-hooks/CHANGELOG.md b/packages/core/uniswap-hooks/CHANGELOG.md new file mode 100644 index 000000000..6088f105e --- /dev/null +++ b/packages/core/uniswap-hooks/CHANGELOG.md @@ -0,0 +1,6 @@ +# Changelog + + +## 0.0.1 (2025-08-11) + +- Initial version. (PR link) diff --git a/packages/core/uniswap-hooks/LICENSE b/packages/core/uniswap-hooks/LICENSE new file mode 100644 index 000000000..be3f7b28e --- /dev/null +++ b/packages/core/uniswap-hooks/LICENSE @@ -0,0 +1,661 @@ + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU Affero General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU AGPL, see +. diff --git a/packages/core/uniswap-hooks/NOTICE b/packages/core/uniswap-hooks/NOTICE new file mode 100644 index 000000000..7a7686aaf --- /dev/null +++ b/packages/core/uniswap-hooks/NOTICE @@ -0,0 +1,8 @@ +OpenZeppelin Contracts Wizard +Copyright (C) 2021-2025 Zeppelin Group Ltd + +This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License along with this program. If not, see . diff --git a/packages/core/uniswap-hooks/README.md b/packages/core/uniswap-hooks/README.md new file mode 100644 index 000000000..2bb256f02 --- /dev/null +++ b/packages/core/uniswap-hooks/README.md @@ -0,0 +1,86 @@ +# OpenZeppelin Contracts Wizard for Stylus + +Interactively build a contract out of components from OpenZeppelin Contracts for Stylus. Provide parameters and desired features for the kind of contract that you want, and the Wizard will generate all of the code necessary. The resulting code is ready to be compiled and deployed, or it can serve as a starting point and customized further with application specific logic. + +This package provides a programmatic API. For a web interface, see https://wizard.openzeppelin.com/stylus + +### Installation + +`npm install @openzeppelin/wizard-stylus` + +### Contract types + +The following contract types are supported: +- `erc20` +- `erc721` +- `erc1155` + +Each contract type has functions/constants as defined below. + +### Functions + +#### `print` +```js +function print(opts?: ERC20Options): string +``` +```js +function print(opts?: ERC721Options): string +``` +```js +function print(opts?: ERC1155Options): string +``` +Returns a string representation of a contract generated using the provided options. If `opts` is not provided, uses [`defaults`](#defaults). + +#### `defaults` +```js +const defaults: Required +``` +```js +const defaults: Required +``` +```js +const defaults: Required +``` +The default options that are used for [`print`](#print). + +#### `isAccessControlRequired` +```js +function isAccessControlRequired(opts: Partial): boolean +``` +```js +function isAccessControlRequired(opts: Partial): boolean +``` +```js +function isAccessControlRequired(opts: Partial): boolean +``` +Whether any of the provided options require access control to be enabled. If this returns `true`, then calling `print` with the same options would cause the `access` option to default to `'ownable'` if it was `undefined` or `false`. + +### Examples + +Import the contract type(s) (for example, `erc20`) that you want to use from the `@openzeppelin/wizard-stylus` package: + +```js +import { erc20 } from '@openzeppelin/wizard-stylus'; +``` + +To generate the source code for an ERC20 contract with all of the default settings: +```js +const contract = erc20.print(); +``` + +To generate the source code for an ERC20 contract with some custom settings: +```js +const contract = erc20.print({ + name: 'ExampleToken', + flashmint: true, + permit: false, +}); +``` + +To generate the source code for an ERC20 contract with all of the defaults but is burnable: +```js +const contract = erc20.print({ + ...erc20.defaults, + burnable: true, +}); +``` diff --git a/packages/core/uniswap-hooks/ava.config.js b/packages/core/uniswap-hooks/ava.config.js new file mode 100644 index 000000000..e39146f7a --- /dev/null +++ b/packages/core/uniswap-hooks/ava.config.js @@ -0,0 +1,9 @@ +module.exports = { + extensions: ['ts'], + require: ['ts-node/register'], + watchmode: { + ignoreChanges: ['contracts', 'artifacts', 'cache'], + }, + timeout: '10m', + workerThreads: false, +}; diff --git a/packages/core/uniswap-hooks/package.json b/packages/core/uniswap-hooks/package.json new file mode 100644 index 000000000..9cb1c6b04 --- /dev/null +++ b/packages/core/uniswap-hooks/package.json @@ -0,0 +1,36 @@ +{ + "name": "@openzeppelin/wizard-uniswap-hooks", + "version": "0.0.1", + "description": "A boilerplate generator to get started with OpenZeppelin Contracts for Uniswap Hooks", + "license": "AGPL-3.0-only", + "repository": "https://github.com/OpenZeppelin/contracts-wizard", + "main": "dist/index.js", + "ts:main": "src/index.ts", + "files": [ + "LICENSE", + "NOTICE", + "/dist", + "/src", + "!**/*.test.*" + ], + "scripts": { + "prepare": "tsc", + "prepublish": "rimraf dist *.tsbuildinfo && hardhat clean", + "test": "ava", + "test:update-snapshots": "ava --update-snapshots", + "test:watch": "ava --watch" + }, + "devDependencies": { + "@openzeppelin/uniswap-hooks": "https://github.com/OpenZeppelin/uniswap-hooks", + "@openzeppelin/contracts": "^5.3.0", + "@types/node": "^20.0.0", + "@types/semver": "^7.5.7", + "ava": "^6.0.0", + "hardhat": "^2.22.11", + "rimraf": "^5.0.0", + "semver": "^7.6.0", + "solidity-ast": "^0.4.18", + "ts-node": "^10.4.0", + "typescript": "^5.0.0" + } +} \ No newline at end of file diff --git a/packages/core/uniswap-hooks/src/api.ts b/packages/core/uniswap-hooks/src/api.ts new file mode 100644 index 000000000..5e9b63f39 --- /dev/null +++ b/packages/core/uniswap-hooks/src/api.ts @@ -0,0 +1,36 @@ +import type { CommonOptions } from '@openzeppelin/wizard/src/common-options'; + +import { + printHooks, + defaults as hooksDefaults, + isAccessControlRequired as hooksIsAccessControlRequired, +} from './hooks'; +import type { HooksOptions } from './hooks'; + +export interface WizardContractAPI { + /** + * Returns a string representation of a contract generated using the provided options. If opts is not provided, uses `defaults`. + */ + print: (opts?: Options) => string; + + /** + * The default options that are used for `print`. + */ + defaults: Required; +} + +export interface AccessControlAPI { + /** + * Whether any of the provided options require access control to be enabled. If this returns `true`, then calling `print` with the + * same options would cause the `access` option to default to `'ownable'` if it was `undefined` or `false`. + */ + isAccessControlRequired: (opts: Partial) => boolean; +} + +export type Hooks = WizardContractAPI & AccessControlAPI; + +export const hooks: Hooks = { + print: printHooks, + defaults: hooksDefaults, + isAccessControlRequired: hooksIsAccessControlRequired, +}; diff --git a/packages/core/uniswap-hooks/src/build-generic.ts b/packages/core/uniswap-hooks/src/build-generic.ts new file mode 100644 index 000000000..1a81ec82a --- /dev/null +++ b/packages/core/uniswap-hooks/src/build-generic.ts @@ -0,0 +1,17 @@ +import type { Contract } from '@openzeppelin/wizard/src/contract'; + +import type { HooksOptions } from './hooks'; +import { buildHooks } from './hooks'; + +export interface KindedOptions { + Hooks: { kind: 'Hooks' } & HooksOptions; +} + +export type GenericOptions = KindedOptions[keyof KindedOptions]; + +export function buildGeneric(opts: GenericOptions): Contract { + switch (opts.kind) { + case 'Hooks': + return buildHooks(opts); + } +} diff --git a/packages/core/uniswap-hooks/src/generate/alternatives.ts b/packages/core/uniswap-hooks/src/generate/alternatives.ts new file mode 100644 index 000000000..b66e733cf --- /dev/null +++ b/packages/core/uniswap-hooks/src/generate/alternatives.ts @@ -0,0 +1,32 @@ +type Blueprint = Record; + +type Alternatives = { + [k in keyof B]: B[k][number]; +}; + +export function* generateAlternatives(blueprint: B): Generator> { + const entries = Object.entries(blueprint).map(([key, values]) => ({ + key, + values, + current: 0, + limit: values.length, + })); + + for (; !done(); advance()) { + yield Object.fromEntries(entries.map(e => [e.key, e.values[e.current % e.limit]])) as Alternatives; + } + + function done() { + const last = entries[entries.length - 1]; + return last?.current === last?.limit; + } + + function advance() { + for (const e of entries) { + e.current = (e.current % e.limit) + 1; + if (e.current < e.limit) { + break; + } + } + } +} diff --git a/packages/core/uniswap-hooks/src/generate/hooks.ts b/packages/core/uniswap-hooks/src/generate/hooks.ts new file mode 100644 index 000000000..4aab5877b --- /dev/null +++ b/packages/core/uniswap-hooks/src/generate/hooks.ts @@ -0,0 +1,19 @@ +import type { HooksOptions } from '../hooks'; +import { accessOptions } from '@openzeppelin/wizard/src/set-access-control'; +import { infoOptions } from '@openzeppelin/wizard/src/set-info'; +import { upgradeableOptions } from '@openzeppelin/wizard/src/set-upgradeable'; +import { generateAlternatives } from './alternatives'; + +const booleans = [true, false]; + +const blueprint = { + name: ['MyHook'], + pausable: booleans, + access: accessOptions, + upgradeable: upgradeableOptions, + info: infoOptions, +}; + +export function* generateHooksOptions(): Generator> { + yield* generateAlternatives(blueprint); +} diff --git a/packages/core/uniswap-hooks/src/hooks.ts b/packages/core/uniswap-hooks/src/hooks.ts new file mode 100644 index 000000000..678829249 --- /dev/null +++ b/packages/core/uniswap-hooks/src/hooks.ts @@ -0,0 +1,56 @@ +import type { Contract } from '@openzeppelin/wizard/src/contract'; +import { ContractBuilder } from '@openzeppelin/wizard/src/contract'; +import type { CommonOptions } from '@openzeppelin/wizard/src/common-options'; +import { withCommonDefaults, defaults as commonDefaults } from '@openzeppelin/wizard/src/common-options'; +import { setUpgradeable } from '@openzeppelin/wizard/src/set-upgradeable'; +import { setInfo } from '@openzeppelin/wizard/src/set-info'; +import { setAccessControl } from '@openzeppelin/wizard/src/set-access-control'; +import { addPausable } from '@openzeppelin/wizard/src/add-pausable'; +import { printContract } from '@openzeppelin/wizard/src/print'; + +export interface HooksOptions extends CommonOptions { + name: string; + pausable?: boolean; +} + +export const defaults: Required = { + name: 'MyHook', + pausable: false, + access: commonDefaults.access, + upgradeable: commonDefaults.upgradeable, + info: commonDefaults.info, +} as const; + +function withDefaults(opts: HooksOptions): Required { + return { + ...opts, + ...withCommonDefaults(opts), + pausable: opts.pausable ?? defaults.pausable, + }; +} + +export function printHooks(opts: HooksOptions = defaults): string { + return printContract(buildHooks(opts)); +} + +export function isAccessControlRequired(opts: Partial): boolean { + return !!opts.pausable; +} + +export function buildHooks(opts: HooksOptions): Contract { + const allOpts = withDefaults(opts); + + const c = new ContractBuilder(allOpts.name); + + const { access, upgradeable, info } = allOpts; + + if (allOpts.pausable) { + addPausable(c, access, []); + } + + setAccessControl(c, access); + setUpgradeable(c, upgradeable, access); + setInfo(c, info); + + return c; +} diff --git a/packages/core/uniswap-hooks/src/index.ts b/packages/core/uniswap-hooks/src/index.ts new file mode 100644 index 000000000..ca83851fd --- /dev/null +++ b/packages/core/uniswap-hooks/src/index.ts @@ -0,0 +1,11 @@ +export type { GenericOptions, KindedOptions } from './build-generic'; +export { buildGeneric } from './build-generic'; + +export type { Kind } from './kind'; +export { sanitizeKind } from './kind'; + +export { hooks } from './api'; + +export { compatibleContractsSemver } from './utils/version'; + +export type { HooksOptions } from './hooks'; diff --git a/packages/core/uniswap-hooks/src/kind.ts b/packages/core/uniswap-hooks/src/kind.ts new file mode 100644 index 000000000..6e6412d75 --- /dev/null +++ b/packages/core/uniswap-hooks/src/kind.ts @@ -0,0 +1,26 @@ +import type { GenericOptions } from './build-generic'; + +export type Kind = GenericOptions['kind']; + +export function sanitizeKind(kind: unknown): Kind { + if (typeof kind === 'string') { + const sanitized = kind.trim().toLowerCase().charAt(0).toUpperCase(); + if (isKind(sanitized)) { + return sanitized; + } + } + return 'Hooks'; +} + +function isKind(value: Kind | T): value is Kind { + switch (value) { + case 'Hooks': + return true; + + default: { + // Static assert that we've checked all kinds. + const _: T = value; + return false; + } + } +} diff --git a/packages/core/uniswap-hooks/src/utils/version.ts b/packages/core/uniswap-hooks/src/utils/version.ts new file mode 100644 index 000000000..c8d01ae1b --- /dev/null +++ b/packages/core/uniswap-hooks/src/utils/version.ts @@ -0,0 +1,4 @@ +/** + * Semantic version string representing of the minimum compatible version of Contracts to display in output. + */ +export const compatibleContractsSemver = '^0.0.0'; diff --git a/packages/core/uniswap-hooks/tsconfig.json b/packages/core/uniswap-hooks/tsconfig.json new file mode 100644 index 000000000..e51988c6e --- /dev/null +++ b/packages/core/uniswap-hooks/tsconfig.json @@ -0,0 +1,16 @@ +{ + "extends": "../../../tsconfig.base.json", + "compilerOptions": { + "incremental": true, + "module": "commonjs", + "sourceMap": true, + "declaration": true, + "declarationMap": true, + "skipLibCheck": true, + "rootDir": "src", + "outDir": "dist" + }, + "include": [ + "src/**/*" + ] +} diff --git a/packages/ui/public/cairo.html b/packages/ui/public/cairo.html index 01bcff71a..a85c1c3fe 100644 --- a/packages/ui/public/cairo.html +++ b/packages/ui/public/cairo.html @@ -75,6 +75,7 @@ stellarStellar stylusStylus + uniswap-hooksUniswap Hooks
diff --git a/packages/ui/public/icons/uniswap-hooks.svg b/packages/ui/public/icons/uniswap-hooks.svg new file mode 100644 index 000000000..3c5cc5d1d --- /dev/null +++ b/packages/ui/public/icons/uniswap-hooks.svg @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/ui/public/icons/uniswap-hooks_active.svg b/packages/ui/public/icons/uniswap-hooks_active.svg new file mode 100644 index 000000000..78675fc9b --- /dev/null +++ b/packages/ui/public/icons/uniswap-hooks_active.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/packages/ui/public/index.html b/packages/ui/public/index.html index 31c02c322..f7ee92e02 100644 --- a/packages/ui/public/index.html +++ b/packages/ui/public/index.html @@ -99,6 +99,7 @@ cairoCairo stellarStellar stylusStylus + uniswap-hooksUniswap Hooks
diff --git a/packages/ui/public/stellar.html b/packages/ui/public/stellar.html index c2d355f4f..33d841c1c 100644 --- a/packages/ui/public/stellar.html +++ b/packages/ui/public/stellar.html @@ -67,6 +67,7 @@ cairoCairo stellarStellar stylusStylus + uniswap-hooksUniswap Hooks
diff --git a/packages/ui/public/stylus.html b/packages/ui/public/stylus.html index 2c47c85c1..ec0a6c70d 100644 --- a/packages/ui/public/stylus.html +++ b/packages/ui/public/stylus.html @@ -67,6 +67,7 @@ cairoCairo stellarStellar stylusStylus + uniswap-hooksUniswap Hooks
diff --git a/packages/ui/public/uniswap-hooks.html b/packages/ui/public/uniswap-hooks.html new file mode 100644 index 000000000..2d6ddccea --- /dev/null +++ b/packages/ui/public/uniswap-hooks.html @@ -0,0 +1,87 @@ + + + + + + OpenZeppelin Contracts Wizard + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+
+ Forum + Docs + GitHub OpenZeppelin + Twitter/X +
+
+ + +
+ +
+ + + + + + + + + + diff --git a/packages/ui/src/common/languages-types.ts b/packages/ui/src/common/languages-types.ts index 0b155f02b..957d4a6ff 100644 --- a/packages/ui/src/common/languages-types.ts +++ b/packages/ui/src/common/languages-types.ts @@ -2,11 +2,13 @@ import type { GenericOptions as SolidityOptions } from '@openzeppelin/wizard'; import type { GenericOptions as CairoOptions } from '@openzeppelin/wizard-cairo'; import type { GenericOptions as StellarOptions } from '@openzeppelin/wizard-stellar'; import type { GenericOptions as StylusOptions } from '@openzeppelin/wizard-stylus'; +import type { GenericOptions as UniswapHooksOptions } from '@openzeppelin/wizard-uniswap-hooks'; export type LanguagesOptions = | Required | Required | Required - | Required; + | Required + | Required; -export type Language = 'solidity' | 'cairo' | 'stylus' | 'stellar'; +export type Language = 'solidity' | 'cairo' | 'stylus' | 'stellar' | 'uniswap-hooks'; diff --git a/packages/ui/src/main.ts b/packages/ui/src/main.ts index 0f9c07655..00df28aa2 100644 --- a/packages/ui/src/main.ts +++ b/packages/ui/src/main.ts @@ -5,6 +5,7 @@ import CairoApp from './cairo/App.svelte'; import CairoAlphaApp from './cairo_alpha/App.svelte'; import StellarApp from './stellar/App.svelte'; import StylusApp from './stylus/App.svelte'; +import UniswapHooksApp from './uniswap-hooks/App.svelte'; import VersionedApp from './common/VersionedApp.svelte'; import { postMessage } from './common/post-message'; import UnsupportedVersion from './common/UnsupportedVersion.svelte'; @@ -17,6 +18,7 @@ import { } from '@openzeppelin/wizard-cairo-alpha'; import { compatibleContractsSemver as stellarSemver } from '@openzeppelin/wizard-stellar'; import { compatibleContractsSemver as stylusSemver } from '@openzeppelin/wizard-stylus'; +import { compatibleContractsSemver as uniswapHooksSemver } from '@openzeppelin/wizard-uniswap-hooks'; import type { InitialOptions } from './common/initial-options'; function postResize() { @@ -43,7 +45,7 @@ const initialOpts: InitialOptions = { interface CompatibleSelection { compatible: true; - appType: 'solidity' | 'cairo' | 'cairo_alpha' | 'stellar' | 'stylus'; + appType: 'solidity' | 'cairo' | 'cairo_alpha' | 'stellar' | 'stylus' | 'uniswap-hooks'; } interface IncompatibleSelection { @@ -93,6 +95,13 @@ function evaluateSelection( return { compatible: false, compatibleVersionsSemver: stylusSemver }; } } + case 'uniswap-hooks': { + if (requestedVersion === undefined || semver.satisfies(requestedVersion, uniswapHooksSemver)) { + return { compatible: true, appType: 'uniswap-hooks' }; + } else { + return { compatible: false, compatibleVersionsSemver: uniswapHooksSemver }; + } + } case 'solidity': case undefined: default: { @@ -151,6 +160,9 @@ if (!selection.compatible) { case 'stylus': app = new StylusApp({ target: document.body, props: { initialTab, initialOpts } }); break; + case 'uniswap-hooks': + app = new UniswapHooksApp({ target: document.body, props: { initialTab, initialOpts } }); + break; case 'solidity': app = new SolidityApp({ target: document.body, diff --git a/packages/ui/src/standalone.css b/packages/ui/src/standalone.css index 117780946..68060b421 100644 --- a/packages/ui/src/standalone.css +++ b/packages/ui/src/standalone.css @@ -143,6 +143,10 @@ body { contrast(100%); } +.nav .switch.switch-uniswap-hooks.active { + --color-2: #f50eb4; +} + .nav-row { padding: 0 1rem 0; max-width: 100%; diff --git a/packages/ui/src/uniswap-hooks/AccessControlSection.svelte b/packages/ui/src/uniswap-hooks/AccessControlSection.svelte new file mode 100644 index 000000000..35ec01511 --- /dev/null +++ b/packages/ui/src/uniswap-hooks/AccessControlSection.svelte @@ -0,0 +1,62 @@ + + + +
+ + + +
+
diff --git a/packages/ui/src/uniswap-hooks/App.svelte b/packages/ui/src/uniswap-hooks/App.svelte new file mode 100644 index 000000000..cf08cf005 --- /dev/null +++ b/packages/ui/src/uniswap-hooks/App.svelte @@ -0,0 +1,264 @@ + + +
+
+
+ + + +
+ + {#if hasErrors} + + {:else} +
+ + + {#if showButtons.openInRemix} + + + + {/if} +
+ {/if} +
+ +
+
+
+ +
+
+ +
+
+        {#if showCode}
+          {@html highlightedCode}
+        {/if}
+      
+
+
+
+ + diff --git a/packages/ui/src/uniswap-hooks/HooksControls.svelte b/packages/ui/src/uniswap-hooks/HooksControls.svelte new file mode 100644 index 000000000..5b8bc2d67 --- /dev/null +++ b/packages/ui/src/uniswap-hooks/HooksControls.svelte @@ -0,0 +1,46 @@ + + +
+

Settings

+ + +
+ +
+

Features

+ +
+ +
+
+ + + + diff --git a/packages/ui/src/uniswap-hooks/InfoSection.svelte b/packages/ui/src/uniswap-hooks/InfoSection.svelte new file mode 100644 index 000000000..7b7052f68 --- /dev/null +++ b/packages/ui/src/uniswap-hooks/InfoSection.svelte @@ -0,0 +1,32 @@ + + +
+

+ + +

+ + + + +
diff --git a/packages/ui/src/uniswap-hooks/highlightjs.ts b/packages/ui/src/uniswap-hooks/highlightjs.ts new file mode 100644 index 000000000..5772decd1 --- /dev/null +++ b/packages/ui/src/uniswap-hooks/highlightjs.ts @@ -0,0 +1,7 @@ +import hljs from 'highlight.js/lib/core'; + +// @ts-expect-error missing type declaration file +import hljsDefineSolidity from 'highlightjs-solidity'; +hljsDefineSolidity(hljs); + +export default hljs; diff --git a/packages/ui/src/uniswap-hooks/inject-hyperlinks.ts b/packages/ui/src/uniswap-hooks/inject-hyperlinks.ts new file mode 100644 index 000000000..906b4a6ea --- /dev/null +++ b/packages/ui/src/uniswap-hooks/inject-hyperlinks.ts @@ -0,0 +1,18 @@ +import { version as contractsVersion } from '@openzeppelin/contracts/package.json'; + +export function injectHyperlinks(code: string) { + // We are modifying HTML, so use HTML escaped chars. The pattern excludes paths that include /../ in the URL. + const contractsRegex = + /"(@openzeppelin\/)(contracts-upgradeable\/|contracts\/)((?:(?!\.\.)[^/]+\/)*?[^/]*?)"/g; + const communityContractsRegex = /"(@openzeppelin\/)(community-contracts\/)((?:(?!\.\.)[^/]+\/)*?[^/]*?)"/g; + + return code + .replace( + contractsRegex, + `"$1$2$3"`, + ) + .replace( + communityContractsRegex, + `"$1$2$3"`, + ); +} diff --git a/packages/ui/src/uniswap-hooks/remix.ts b/packages/ui/src/uniswap-hooks/remix.ts new file mode 100644 index 000000000..d91542cd7 --- /dev/null +++ b/packages/ui/src/uniswap-hooks/remix.ts @@ -0,0 +1,15 @@ +export function remixURL(code: string, upgradeable = false): URL { + const remix = new URL('https://remix.ethereum.org'); + + const codeWithEscapedSpecialCharacters = Array.from(new TextEncoder().encode(code), b => String.fromCharCode(b)).join( + '', + ); + + remix.searchParams.set('code', btoa(codeWithEscapedSpecialCharacters).replace(/=*$/, '')); + + if (upgradeable) { + remix.searchParams.set('deployProxy', upgradeable.toString()); + } + + return remix; +} diff --git a/yarn.lock b/yarn.lock index 45734ca13..85e1a23bd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -832,6 +832,10 @@ resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-5.3.0.tgz#0a90ce16f5c855e3c8239691f1722cd4999ae741" integrity sha512-zj/KGoW7zxWUE8qOI++rUM18v+VeLTTzKs/DJFkSzHpQFPD/jKKF0TrMxBfGLl3kpdELCNccvB3zmofSzm4nlA== +"@openzeppelin/uniswap-hooks@https://github.com/OpenZeppelin/uniswap-hooks": + version "1.1.0" + resolved "https://github.com/OpenZeppelin/uniswap-hooks#99bda078a036fbe5acb1dfa6d00d6b7a3941ea1f" + "@pkgjs/parseargs@^0.11.0": version "0.11.0" resolved "https://registry.yarnpkg.com/@pkgjs/parseargs/-/parseargs-0.11.0.tgz#a77ea742fab25775145434eb1d2328cf5013ac33" From 1e007d72b86acaaa651dc8266841e2862068a7e5 Mon Sep 17 00:00:00 2001 From: Gonzalo Othacehe Date: Tue, 12 Aug 2025 17:04:13 -0300 Subject: [PATCH 02/79] add hook utilities --- packages/core/solidity/src/contract.ts | 10 ++ packages/core/solidity/src/print.ts | 18 +++ packages/core/uniswap-hooks/src/api.ts | 22 +--- .../core/uniswap-hooks/src/build-generic.ts | 1 - packages/core/uniswap-hooks/src/hooks.ts | 111 +++++++++++++++++- .../ui/src/uniswap-hooks/HooksControls.svelte | 35 +++++- 6 files changed, 169 insertions(+), 28 deletions(-) diff --git a/packages/core/solidity/src/contract.ts b/packages/core/solidity/src/contract.ts index 6ed276124..150fe9615 100644 --- a/packages/core/solidity/src/contract.ts +++ b/packages/core/solidity/src/contract.ts @@ -5,6 +5,7 @@ export interface Contract { license: string; parents: Parent[]; natspecTags: NatspecTag[]; + using: Using[]; imports: ImportContract[]; functions: ContractFunction[]; constructorCode: string[]; @@ -133,6 +134,15 @@ export class ContractBuilder implements Contract { return !present; } + addUsing(library: ImportContract, usingFor: string): boolean { + const exists = this.using.some(u => u.library.name === library.name && u.usingFor === usingFor); + if (!exists) { + this.using.push({ library, usingFor }); + return true; + } + return false; + } + addOverride(parent: ReferencedContract, baseFn: BaseFunction, mutability?: FunctionMutability) { const fn = this.addFunction(baseFn); fn.override.add(parent); diff --git a/packages/core/solidity/src/print.ts b/packages/core/solidity/src/print.ts index c9e85615a..d1cb174c7 100644 --- a/packages/core/solidity/src/print.ts +++ b/packages/core/solidity/src/print.ts @@ -40,6 +40,7 @@ export function printContract(contract: Contract, opts?: Options): string { [`contract ${contract.name}`, ...printInheritance(contract, helpers), '{'].join(' '), spaceBetween( + printUsing(contract, helpers), contract.variables, printConstructor(contract, helpers), ...fns.code, @@ -260,3 +261,20 @@ function printImports(imports: ImportContract[], helpers: Helpers): string[] { return lines; } + +function printUsing(contract: Contract, { transformName }: Helpers): string[] { + if (!contract.using || contract.using.length === 0) { + return []; + } + + // Emit in stable order by library then type to keep output deterministic + const entries = [...contract.using].sort((a, b) => { + if (a.library.name < b.library.name) return -1; + if (a.library.name > b.library.name) return 1; + if (a.usingFor < b.usingFor) return -1; + if (a.usingFor > b.usingFor) return 1; + return 0; + }); + + return entries.map(u => `using ${transformName(u.library)} for ${u.usingFor};`); +} diff --git a/packages/core/uniswap-hooks/src/api.ts b/packages/core/uniswap-hooks/src/api.ts index 5e9b63f39..860162f9b 100644 --- a/packages/core/uniswap-hooks/src/api.ts +++ b/packages/core/uniswap-hooks/src/api.ts @@ -1,4 +1,4 @@ -import type { CommonOptions } from '@openzeppelin/wizard/src/common-options'; +import type { WizardContractAPI, AccessControlAPI } from '@openzeppelin/wizard/src/api'; import { printHooks, @@ -7,26 +7,6 @@ import { } from './hooks'; import type { HooksOptions } from './hooks'; -export interface WizardContractAPI { - /** - * Returns a string representation of a contract generated using the provided options. If opts is not provided, uses `defaults`. - */ - print: (opts?: Options) => string; - - /** - * The default options that are used for `print`. - */ - defaults: Required; -} - -export interface AccessControlAPI { - /** - * Whether any of the provided options require access control to be enabled. If this returns `true`, then calling `print` with the - * same options would cause the `access` option to default to `'ownable'` if it was `undefined` or `false`. - */ - isAccessControlRequired: (opts: Partial) => boolean; -} - export type Hooks = WizardContractAPI & AccessControlAPI; export const hooks: Hooks = { diff --git a/packages/core/uniswap-hooks/src/build-generic.ts b/packages/core/uniswap-hooks/src/build-generic.ts index 1a81ec82a..337200cf4 100644 --- a/packages/core/uniswap-hooks/src/build-generic.ts +++ b/packages/core/uniswap-hooks/src/build-generic.ts @@ -1,5 +1,4 @@ import type { Contract } from '@openzeppelin/wizard/src/contract'; - import type { HooksOptions } from './hooks'; import { buildHooks } from './hooks'; diff --git a/packages/core/uniswap-hooks/src/hooks.ts b/packages/core/uniswap-hooks/src/hooks.ts index 678829249..97ee5e491 100644 --- a/packages/core/uniswap-hooks/src/hooks.ts +++ b/packages/core/uniswap-hooks/src/hooks.ts @@ -2,23 +2,35 @@ import type { Contract } from '@openzeppelin/wizard/src/contract'; import { ContractBuilder } from '@openzeppelin/wizard/src/contract'; import type { CommonOptions } from '@openzeppelin/wizard/src/common-options'; import { withCommonDefaults, defaults as commonDefaults } from '@openzeppelin/wizard/src/common-options'; -import { setUpgradeable } from '@openzeppelin/wizard/src/set-upgradeable'; import { setInfo } from '@openzeppelin/wizard/src/set-info'; import { setAccessControl } from '@openzeppelin/wizard/src/set-access-control'; import { addPausable } from '@openzeppelin/wizard/src/add-pausable'; import { printContract } from '@openzeppelin/wizard/src/print'; +type BaseHook = 'BaseHook' | 'BaseAsyncSwap' | 'BaseCustomAccounting' | 'BaseCustomCurve'; +type FeeHook = 'BaseDynamicFee' | 'BaseOverrideFee' | 'BaseDynamicAfterFee' | 'BaseHookFee'; +type GeneralHook = 'AntiSandwichHook' | 'LimitOrderHook' | 'LiquidityPenaltyHook'; +type Hook = BaseHook | FeeHook | GeneralHook; + export interface HooksOptions extends CommonOptions { + hook: Hook; name: string; pausable?: boolean; + currencySettler?: boolean; + safeCast?: boolean; + transientStorage?: boolean; } export const defaults: Required = { + hook: 'BaseHook', name: 'MyHook', pausable: false, access: commonDefaults.access, upgradeable: commonDefaults.upgradeable, info: commonDefaults.info, + currencySettler: false, + safeCast: false, + transientStorage: false, } as const; function withDefaults(opts: HooksOptions): Required { @@ -26,6 +38,9 @@ function withDefaults(opts: HooksOptions): Required { ...opts, ...withCommonDefaults(opts), pausable: opts.pausable ?? defaults.pausable, + currencySettler: opts.currencySettler ?? defaults.currencySettler, + safeCast: opts.safeCast ?? defaults.safeCast, + transientStorage: opts.transientStorage ?? defaults.transientStorage, }; } @@ -40,17 +55,103 @@ export function isAccessControlRequired(opts: Partial): boolean { export function buildHooks(opts: HooksOptions): Contract { const allOpts = withDefaults(opts); + allOpts.upgradeable = false; // Upgradeability is not yet available for Hooks + const c = new ContractBuilder(allOpts.name); - const { access, upgradeable, info } = allOpts; + const { access, info } = allOpts; + + addHook(c, allOpts); + + setInfo(c, info); + + if (access) { + setAccessControl(c, access); + } if (allOpts.pausable) { addPausable(c, access, []); } - setAccessControl(c, access); - setUpgradeable(c, upgradeable, access); - setInfo(c, info); + if (allOpts.currencySettler) { + addCurrencySettler(c, allOpts); + } + + if (allOpts.safeCast) { + addSafeCast(c, allOpts); + } + + if (allOpts.transientStorage) { + addTransientStorage(c, allOpts); + } return c; } + +function addHook(c: ContractBuilder, allOpts: HooksOptions) { + let path = ''; + + switch (allOpts.hook) { + case 'BaseHook': + case 'BaseAsyncSwap': + case 'BaseCustomAccounting': + case 'BaseCustomCurve': + path = `@openzeppelin/uniswap-hooks/src/base/${allOpts.hook}.sol`; + break; + case 'BaseDynamicFee': + case 'BaseOverrideFee': + case 'BaseDynamicAfterFee': + case 'BaseHookFee': + path = `@openzeppelin/uniswap-hooks/src/fee/${allOpts.hook}.sol`; + break; + case 'AntiSandwichHook': + case 'LimitOrderHook': + case 'LiquidityPenaltyHook': + path = `@openzeppelin/uniswap-hooks/src/general/${allOpts.hook}.sol`; + break; + default: + throw new Error(`Unknown hook: ${allOpts.hook}`); + } + + c.addParent({ + name: allOpts.hook, + path, + }); +} + +function addCurrencySettler(c: ContractBuilder, opts: HooksOptions) { + c.addUsing( + { + name: 'CurrencySettler', + path: `@openzeppelin/uniswap-hooks/src/utils/CurrencySettler.sol`, + }, + 'Currency', + ); +} + +function addSafeCast(c: ContractBuilder, opts: HooksOptions) { + c.addUsing( + { + name: 'SafeCast', + path: `@openzeppelin/contracts/utils/math/SafeCast.sol`, + }, + '*', + ); +} + +function addTransientStorage(c: ContractBuilder, opts: HooksOptions) { + c.addUsing( + { + name: 'TransientSlot', + path: `@openzeppelin/contracts/utils/TransientSlot.sol`, + }, + '*', + ); + c.addUsing( + { + name: 'SlotDerivation', + path: `@openzeppelin/contracts/utils/SlotDerivation.sol`, + }, + '*', + ); +} diff --git a/packages/ui/src/uniswap-hooks/HooksControls.svelte b/packages/ui/src/uniswap-hooks/HooksControls.svelte index 5b8bc2d67..1ad6f268c 100644 --- a/packages/ui/src/uniswap-hooks/HooksControls.svelte +++ b/packages/ui/src/uniswap-hooks/HooksControls.svelte @@ -1,7 +1,7 @@
@@ -27,59 +32,22 @@
-
-

Base Hooks

- -
- {#each ALL_HOOKS.slice(0, 4) as hookName} - - {/each} -
- -
- -
-

Fee Hooks

- -
- {#each ALL_HOOKS.slice(4, 8) as hookName} -
+
+{/each}

Features

@@ -100,7 +68,7 @@ label="Shares" bind:value={opts.shares.options} defaultValue="ERC20" - helpContent="Use ERC20 or ERC6909 to represent shares of a pool." + helpContent="Shares are useful to account for the ownership of a portion of a liquidity position or pending credit." helpLink="https://docs.openzeppelin.com/contracts/api/token/erc20" >
@@ -108,7 +76,7 @@ ERC-20 - ERC-20 is the standard for fungible tokens. + ERC-20 shares are useful for single-token accounting. @@ -116,7 +84,7 @@ ERC-6909 - ERC-6909 is a standard for non-fungible tokens. + ERC-6909 shares are useful for multi-token accounting.
@@ -143,27 +111,25 @@
From db952de704de6c8da0427a14e1b4291d3d47d38a Mon Sep 17 00:00:00 2001 From: Gonzalo Othacehe Date: Wed, 13 Aug 2025 16:06:58 -0300 Subject: [PATCH 08/79] add initial tooltips --- packages/core/uniswap-hooks/src/hooks.ts | 50 ++++++++++++++---------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/packages/core/uniswap-hooks/src/hooks.ts b/packages/core/uniswap-hooks/src/hooks.ts index d4f1e3152..216115267 100644 --- a/packages/core/uniswap-hooks/src/hooks.ts +++ b/packages/core/uniswap-hooks/src/hooks.ts @@ -33,63 +33,73 @@ export const Hooks: HookInfo[] = [ { name: 'BaseHook', category: 'Base', - tooltipText: 'BaseHook', - tooltipLink: 'https://docs.openzeppelin.com/contracts/api/utils#Pausable', + tooltipText: + 'Base hook implementation providing standard entry points, permission checks, and validation utilities for building hooks.', + tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/base#BaseHook', }, { name: 'BaseAsyncSwap', category: 'Base', - tooltipText: 'BaseAsyncSwap', - tooltipLink: 'https://docs.openzeppelin.com/contracts/api/utils#Pausable', + tooltipText: + 'Base implementation for asynchronous swaps that bypasses the default swap flow by netting the specified amount to zero, enabling custom execution and settlement.', + tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/base#BaseAsyncSwap', }, { name: 'BaseCustomAccounting', - tooltipText: 'BaseCustomAccounting', - tooltipLink: 'https://docs.openzeppelin.com/contracts/api/utils#Pausable', + tooltipText: + 'Base for custom accounting and hook-owned liquidity; implement how liquidity changes are computed and how shares are minted/burned. Intended for a single pool key per instance.', + tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/base#BaseCustomAccounting', category: 'Base', }, { name: 'BaseCustomCurve', - tooltipText: 'BaseCustomCurve', - tooltipLink: 'https://docs.openzeppelin.com/contracts/api/utils#Pausable', + tooltipText: + 'Base for custom swap curves overriding default pricing; define the unspecified amount during swaps. Builds on the custom accounting base.', + tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/base#BaseCustomCurve', category: 'Base', }, // Fee { name: 'BaseDynamicFee', - tooltipText: 'BaseDynamicFee', - tooltipLink: 'https://docs.openzeppelin.com/contracts/api/utils#Pausable', + tooltipText: + 'Applies a dynamic LP fee via the PoolManager; lets you update the fee over time based on your own logic.', + tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/fee#BaseDynamicFee', category: 'Fee', }, { name: 'BaseOverrideFee', - tooltipText: 'BaseOverrideFee', - tooltipLink: 'https://docs.openzeppelin.com/contracts/api/utils#Pausable', + tooltipText: + 'Automatically sets a dynamic fee before each swap, computed per trade according to your fee function.', + tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/fee#BaseOverrideFee', category: 'Fee', }, { name: 'BaseDynamicAfterFee', - tooltipText: 'BaseDynamicAfterFee', - tooltipLink: 'https://docs.openzeppelin.com/contracts/api/utils#Pausable', + tooltipText: + 'Enforces a post-swap target and captures any positive difference as a hook fee, then lets you handle or distribute it.', + tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/fee#BaseDynamicAfterFee', category: 'Fee', }, // General { name: 'AntiSandwichHook', - tooltipText: 'AntiSandwichHook', - tooltipLink: 'https://docs.openzeppelin.com/contracts/api/utils#Pausable', + tooltipText: + 'Sandwich‑resistant; constrains swaps to beginning‑of‑block pricing on one side to reduce intra‑block price manipulation.', + tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/general#AntiSandwichHook', category: 'General', }, { name: 'LimitOrderHook', - tooltipText: 'LimitOrderHook', - tooltipLink: 'https://docs.openzeppelin.com/contracts/api/utils#Pausable', + tooltipText: + 'Limit orders at specific ticks; adds out‑of‑range liquidity that fills when price crosses, with cancel and withdraw support.', + tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/general#LimitOrderHook', category: 'General', }, { name: 'LiquidityPenaltyHook', - tooltipText: 'LiquidityPenaltyHook', - tooltipLink: 'https://docs.openzeppelin.com/contracts/api/utils#Pausable', + tooltipText: + 'JIT-resistant; withholds and penalizes LP fees when liquidity is added then removed within a block window, donating penalties to in-range LPs.', + tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/general#LiquidityPenaltyHook', category: 'General', }, ]; From 0b5ae6462988f2d20678072bb6d6f864d72ab882 Mon Sep 17 00:00:00 2001 From: Gonzalo Othacehe Date: Wed, 13 Aug 2025 16:14:39 -0300 Subject: [PATCH 09/79] add uniswap deps --- packages/core/solidity/package.json | 1 - packages/core/uniswap-hooks/package.json | 6 ++++-- yarn.lock | 10 ++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/core/solidity/package.json b/packages/core/solidity/package.json index caee9a643..804075fab 100644 --- a/packages/core/solidity/package.json +++ b/packages/core/solidity/package.json @@ -23,7 +23,6 @@ }, "devDependencies": { "@openzeppelin/community-contracts": "https://github.com/OpenZeppelin/openzeppelin-community-contracts", - "@openzeppelin/uniswap-hooks": "https://github.com/OpenZeppelin/uniswap-hooks", "@openzeppelin/contracts": "^5.3.0", "@openzeppelin/contracts-upgradeable": "^5.3.0", "@types/node": "^20.0.0", diff --git a/packages/core/uniswap-hooks/package.json b/packages/core/uniswap-hooks/package.json index 9cb1c6b04..8ebbb793c 100644 --- a/packages/core/uniswap-hooks/package.json +++ b/packages/core/uniswap-hooks/package.json @@ -21,8 +21,10 @@ "test:watch": "ava --watch" }, "devDependencies": { - "@openzeppelin/uniswap-hooks": "https://github.com/OpenZeppelin/uniswap-hooks", "@openzeppelin/contracts": "^5.3.0", + "@openzeppelin/uniswap-hooks": "https://github.com/OpenZeppelin/uniswap-hooks", + "@uniswap/v4-core": "^1.0.2", + "@uniswap/v4-periphery": "^1.0.3", "@types/node": "^20.0.0", "@types/semver": "^7.5.7", "ava": "^6.0.0", @@ -33,4 +35,4 @@ "ts-node": "^10.4.0", "typescript": "^5.0.0" } -} \ No newline at end of file +} diff --git a/yarn.lock b/yarn.lock index 85e1a23bd..1aab3f784 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1359,6 +1359,16 @@ "@typescript-eslint/types" "8.29.1" eslint-visitor-keys "^4.2.0" +"@uniswap/v4-core@^1.0.2": + version "1.0.2" + resolved "https://registry.yarnpkg.com/@uniswap/v4-core/-/v4-core-1.0.2.tgz#5b5701267eea25e84221f7697d971fb4f66169f6" + integrity sha512-X15Tm2wWd+USAzEExMbo+g9naA6QN6mPgWm0MzDwRNlOfaNlepfUpSyt9RSrUfEODspwbyWbcLg6t5nwc/e7lg== + +"@uniswap/v4-periphery@^1.0.3": + version "1.0.3" + resolved "https://registry.yarnpkg.com/@uniswap/v4-periphery/-/v4-periphery-1.0.3.tgz#d931bc5d6f29703482ceb43ad1f9ad859293ee12" + integrity sha512-JxLL0Djv9XcMvI2PatEnWrCrxuEaYNVhHxstndBOP+aJfh1XLg5ec8SDZ0xyoVfg2ElJTvuKpBgnu90bNValsg== + "@upstash/redis@1.25.2": version "1.25.2" resolved "https://registry.yarnpkg.com/@upstash/redis/-/redis-1.25.2.tgz#c400caced6e05a4931823c4eb57eda6b73963db3" From 5dfb6472173239c2249a20157b3cc356b707e965 Mon Sep 17 00:00:00 2001 From: Gonzalo Othacehe Date: Wed, 13 Aug 2025 16:38:37 -0300 Subject: [PATCH 10/79] fix prepare error --- .../core/uniswap-hooks/src/generate/hooks.ts | 22 ++++++++++--------- packages/core/uniswap-hooks/src/hooks.ts | 10 ++++----- packages/core/uniswap-hooks/src/index.ts | 2 +- .../ui/src/uniswap-hooks/HooksControls.svelte | 4 ++-- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/packages/core/uniswap-hooks/src/generate/hooks.ts b/packages/core/uniswap-hooks/src/generate/hooks.ts index bc5e33aea..4eb17e5ab 100644 --- a/packages/core/uniswap-hooks/src/generate/hooks.ts +++ b/packages/core/uniswap-hooks/src/generate/hooks.ts @@ -1,29 +1,31 @@ -import type { HooksOptions } from '../hooks'; -import { ALL_HOOKS } from '../hooks'; +import type { HookName, HooksOptions } from '../hooks'; +import { Hooks } from '../hooks'; import { accessOptions } from '@openzeppelin/wizard/src/set-access-control'; import { infoOptions } from '@openzeppelin/wizard/src/set-info'; import { generateAlternatives } from '@openzeppelin/wizard/src/generate/alternatives'; -const booleans = [true, false]; +const booleanOptions = [true, false]; -const sharesVariants = [ +const sharesOptions = [ { options: false, name: 'MyShares', symbol: 'MSH' }, { options: 'ERC20', name: 'MyShares', symbol: 'MSH' }, { options: 'ERC6909', name: 'MyShares', symbol: 'MSH' }, ] as const; +const hooksOptions: HookName[] = Hooks.map(hook => hook.name); + const blueprint = { - hook: ALL_HOOKS as readonly HooksOptions['hook'][], + hook: hooksOptions as readonly HookName[], name: ['MyHook'] as const, - pausable: booleans, - currencySettler: booleans, - safeCast: booleans, - transientStorage: booleans, + pausable: booleanOptions, + currencySettler: booleanOptions, + safeCast: booleanOptions, + transientStorage: booleanOptions, access: accessOptions, // Hooks are not upgradeable yet; fix to false upgradeable: [false] as const, info: infoOptions, - shares: sharesVariants, + shares: sharesOptions, }; export function* generateHooksOptions(): Generator> { diff --git a/packages/core/uniswap-hooks/src/hooks.ts b/packages/core/uniswap-hooks/src/hooks.ts index 216115267..c99eb2571 100644 --- a/packages/core/uniswap-hooks/src/hooks.ts +++ b/packages/core/uniswap-hooks/src/hooks.ts @@ -9,7 +9,7 @@ import { printContract } from '@openzeppelin/wizard/src/print'; import type { Value } from '@openzeppelin/wizard/src/contract'; export type HookCategory = 'Base' | 'Fee' | 'General'; -export type Hook = +export type HookName = | 'BaseHook' | 'BaseAsyncSwap' | 'BaseCustomAccounting' @@ -21,14 +21,14 @@ export type Hook = | 'AntiSandwichHook' | 'LimitOrderHook' | 'LiquidityPenaltyHook'; -export type HookInfo = { - name: Hook; +export type Hook = { + name: HookName; category: HookCategory; tooltipText: string; tooltipLink: string; }; -export const Hooks: HookInfo[] = [ +export const Hooks: Hook[] = [ // Base { name: 'BaseHook', @@ -112,7 +112,7 @@ export type Shares = { }; export interface HooksOptions extends CommonOptions { - hook: Hook; + hook: HookName; name: string; pausable?: boolean; currencySettler?: boolean; diff --git a/packages/core/uniswap-hooks/src/index.ts b/packages/core/uniswap-hooks/src/index.ts index dbe25109e..1263948b8 100644 --- a/packages/core/uniswap-hooks/src/index.ts +++ b/packages/core/uniswap-hooks/src/index.ts @@ -5,6 +5,6 @@ export { sanitizeKind, type Kind } from './kind'; export { hooks } from './api'; export { Hooks } from './hooks'; -export type { Hook, HookInfo, HooksOptions, HookCategory, Shares } from './hooks'; +export type { Hook, HookName, HooksOptions, HookCategory, Shares } from './hooks'; export { compatibleContractsSemver } from './utils/version'; diff --git a/packages/ui/src/uniswap-hooks/HooksControls.svelte b/packages/ui/src/uniswap-hooks/HooksControls.svelte index f11d7414f..8542cea53 100644 --- a/packages/ui/src/uniswap-hooks/HooksControls.svelte +++ b/packages/ui/src/uniswap-hooks/HooksControls.svelte @@ -3,7 +3,7 @@ import { infoDefaults } from '@openzeppelin/wizard'; import { hooks, Hooks } from '@openzeppelin/wizard-uniswap-hooks/src'; - import type { HookCategory, HookInfo, KindedOptions } from '@openzeppelin/wizard-uniswap-hooks/src'; + import type { HookCategory, Hook, KindedOptions } from '@openzeppelin/wizard-uniswap-hooks/src'; import AccessControlSection from './AccessControlSection.svelte'; import InfoSection from './InfoSection.svelte'; @@ -19,7 +19,7 @@ // Keep a stable order and titles const CATEGORY_ORDER: HookCategory[] = ['Base', 'Fee', 'General']; - const hooksByCategory: Record = { Base: [], Fee: [], General: [] }; + const hooksByCategory: Record = { Base: [], Fee: [], General: [] }; for (const h of Hooks) hooksByCategory[h.category].push(h); From 45d7d64b1720d33ea0ea489c763aba0c796acafc Mon Sep 17 00:00:00 2001 From: Gonzalo Othacehe Date: Wed, 13 Aug 2025 16:55:17 -0300 Subject: [PATCH 11/79] add uniswap hooks hyperlinks --- packages/ui/src/uniswap-hooks/inject-hyperlinks.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/ui/src/uniswap-hooks/inject-hyperlinks.ts b/packages/ui/src/uniswap-hooks/inject-hyperlinks.ts index 906b4a6ea..21e1cb11d 100644 --- a/packages/ui/src/uniswap-hooks/inject-hyperlinks.ts +++ b/packages/ui/src/uniswap-hooks/inject-hyperlinks.ts @@ -5,6 +5,8 @@ export function injectHyperlinks(code: string) { const contractsRegex = /"(@openzeppelin\/)(contracts-upgradeable\/|contracts\/)((?:(?!\.\.)[^/]+\/)*?[^/]*?)"/g; const communityContractsRegex = /"(@openzeppelin\/)(community-contracts\/)((?:(?!\.\.)[^/]+\/)*?[^/]*?)"/g; + const uniswapV4CoreRegex = /"(@uniswap\/)(v4-core\/contracts\/)((?:(?!\.\.)[^/]+\/)*?[^/]*?)"/g; + const ozUniswapHooksRegex = /"(@openzeppelin\/)(uniswap-hooks\/src\/)((?:(?!\.\.)[^/]+\/)*?[^/]*?)"/g; return code .replace( @@ -14,5 +16,13 @@ export function injectHyperlinks(code: string) { .replace( communityContractsRegex, `"$1$2$3"`, + ) + .replace( + uniswapV4CoreRegex, + `"$1$2$3"`, + ) + .replace( + ozUniswapHooksRegex, + `"$1$2$3"`, ); } From 194b3559546ddc336b794e60a0bd056872843a0b Mon Sep 17 00:00:00 2001 From: Gonzalo Othacehe Date: Wed, 13 Aug 2025 17:26:27 -0300 Subject: [PATCH 12/79] iterate hooks tooltips --- packages/core/uniswap-hooks/src/hooks.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/core/uniswap-hooks/src/hooks.ts b/packages/core/uniswap-hooks/src/hooks.ts index c99eb2571..a99ef76e3 100644 --- a/packages/core/uniswap-hooks/src/hooks.ts +++ b/packages/core/uniswap-hooks/src/hooks.ts @@ -83,22 +83,21 @@ export const Hooks: Hook[] = [ // General { name: 'AntiSandwichHook', - tooltipText: - 'Sandwich‑resistant; constrains swaps to beginning‑of‑block pricing on one side to reduce intra‑block price manipulation.', + tooltipText: 'Anchors swap pricing to the beginning-of-block state to deter intra-block sandwich manipulation.', tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/general#AntiSandwichHook', category: 'General', }, { name: 'LimitOrderHook', tooltipText: - 'Limit orders at specific ticks; adds out‑of‑range liquidity that fills when price crosses, with cancel and withdraw support.', + 'Out‑of‑range limit orders that execute on tick cross; adds one currency, accrue fees to the order, and support cancel/withdraw.', tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/general#LimitOrderHook', category: 'General', }, { name: 'LiquidityPenaltyHook', tooltipText: - 'JIT-resistant; withholds and penalizes LP fees when liquidity is added then removed within a block window, donating penalties to in-range LPs.', + 'JIT‑resistant: withholds and penalizes LP fees when liquidity is added then removed within a block window; penalties are donated to in‑range LPs.', tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/general#LiquidityPenaltyHook', category: 'General', }, From b7be91cfa49d5715d801d8419eccb82e2e1f3456 Mon Sep 17 00:00:00 2001 From: Gonzalo Othacehe Date: Thu, 14 Aug 2025 10:58:05 -0300 Subject: [PATCH 13/79] fix kind sanitization --- packages/core/uniswap-hooks/src/kind.ts | 3 ++- packages/ui/src/uniswap-hooks/App.svelte | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/core/uniswap-hooks/src/kind.ts b/packages/core/uniswap-hooks/src/kind.ts index 6e6412d75..e623ef0fb 100644 --- a/packages/core/uniswap-hooks/src/kind.ts +++ b/packages/core/uniswap-hooks/src/kind.ts @@ -4,7 +4,8 @@ export type Kind = GenericOptions['kind']; export function sanitizeKind(kind: unknown): Kind { if (typeof kind === 'string') { - const sanitized = kind.trim().toLowerCase().charAt(0).toUpperCase(); + const lowered = kind.trim().toLowerCase(); + const sanitized = lowered.charAt(0).toUpperCase() + lowered.slice(1); if (isKind(sanitized)) { return sanitized; } diff --git a/packages/ui/src/uniswap-hooks/App.svelte b/packages/ui/src/uniswap-hooks/App.svelte index b3d51a9bb..a5951b734 100644 --- a/packages/ui/src/uniswap-hooks/App.svelte +++ b/packages/ui/src/uniswap-hooks/App.svelte @@ -46,7 +46,7 @@ let allOpts: { [k in Kind]?: Required } = {}; let errors: { [k in Kind]?: OptionsErrorMessages } = {}; - let contract: Contract = new ContractBuilder(initialOpts.name ?? 'MyToken'); + let contract: Contract = new ContractBuilder(initialOpts.name ?? 'MyHook'); let showCode = true; From c6509543a721b6608869089ab9e85b05bede4be4 Mon Sep 17 00:00:00 2001 From: Gonzalo Othacehe Date: Thu, 14 Aug 2025 11:10:45 -0300 Subject: [PATCH 14/79] up tooltip --- packages/core/uniswap-hooks/src/hooks.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/uniswap-hooks/src/hooks.ts b/packages/core/uniswap-hooks/src/hooks.ts index a99ef76e3..460193333 100644 --- a/packages/core/uniswap-hooks/src/hooks.ts +++ b/packages/core/uniswap-hooks/src/hooks.ts @@ -47,7 +47,7 @@ export const Hooks: Hook[] = [ { name: 'BaseCustomAccounting', tooltipText: - 'Base for custom accounting and hook-owned liquidity; implement how liquidity changes are computed and how shares are minted/burned. Intended for a single pool key per instance.', + 'Base for custom accounting and hook-owned liquidity; implement how liquidity changes are computed and how liquidiy positions shares are minted/burned. Intended for a single pool key per instance.', tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/base#BaseCustomAccounting', category: 'Base', }, From 762b5a1b04fe1262ccade5cc400018790e010c38 Mon Sep 17 00:00:00 2001 From: Gonzalo Othacehe Date: Mon, 18 Aug 2025 19:42:18 -0300 Subject: [PATCH 15/79] update remappings --- packages/core/uniswap-hooks/hardhat.config.js | 75 ++++ packages/core/uniswap-hooks/package.json | 9 +- packages/core/uniswap-hooks/remappings.txt | 4 + .../uniswap-hooks/src/.solidity-version.json | 1 + .../uniswap-hooks/src/generate/sources.ts | 84 +++++ packages/core/uniswap-hooks/src/hooks.test.ts | 40 ++ .../core/uniswap-hooks/src/hooks.test.ts.md | 356 ++++++++++++++++++ .../core/uniswap-hooks/src/hooks.test.ts.snap | Bin 0 -> 1321 bytes packages/core/uniswap-hooks/src/hooks.ts | 6 +- packages/core/uniswap-hooks/src/test.ts | 34 ++ .../ui/src/uniswap-hooks/inject-hyperlinks.ts | 4 +- yarn.lock | 4 +- 12 files changed, 607 insertions(+), 10 deletions(-) create mode 100644 packages/core/uniswap-hooks/hardhat.config.js create mode 100644 packages/core/uniswap-hooks/remappings.txt create mode 100644 packages/core/uniswap-hooks/src/.solidity-version.json create mode 100644 packages/core/uniswap-hooks/src/generate/sources.ts create mode 100644 packages/core/uniswap-hooks/src/hooks.test.ts create mode 100644 packages/core/uniswap-hooks/src/hooks.test.ts.md create mode 100644 packages/core/uniswap-hooks/src/hooks.test.ts.snap create mode 100644 packages/core/uniswap-hooks/src/test.ts diff --git a/packages/core/uniswap-hooks/hardhat.config.js b/packages/core/uniswap-hooks/hardhat.config.js new file mode 100644 index 000000000..aabd35a98 --- /dev/null +++ b/packages/core/uniswap-hooks/hardhat.config.js @@ -0,0 +1,75 @@ +const fs = require('fs'); +const { task } = require('hardhat/config'); +const { HardhatError } = require('hardhat/internal/core/errors'); +const { ERRORS } = require('hardhat/internal/core/errors-list'); +const { + TASK_COMPILE_SOLIDITY_CHECK_ERRORS, + TASK_COMPILE_SOLIDITY_LOG_COMPILATION_ERRORS, + TASK_COMPILE_SOLIDITY_MERGE_COMPILATION_JOBS, + TASK_COMPILE_GET_REMAPPINGS, +} = require('hardhat/builtin-tasks/task-names'); + +const SOLIDITY_VERSION = require('./src/.solidity-version.json'); + +// Keep parity with solidity package: treat warnings as errors except these codes. +const WARN_UNUSED_PARAMETER = '5667'; +const WARN_CODE_SIZE = '5574'; +const IGNORED_WARNINGS = [WARN_UNUSED_PARAMETER, WARN_CODE_SIZE]; + +// Overriding this task so that warnings are considered errors. +task(TASK_COMPILE_SOLIDITY_CHECK_ERRORS, async ({ output, quiet }, { run }) => { + const errors = (output.errors && output.errors.filter(e => !IGNORED_WARNINGS.includes(e.errorCode))) || []; + + await run(TASK_COMPILE_SOLIDITY_LOG_COMPILATION_ERRORS, { + output: { ...output, errors }, + quiet, + }); + + if (errors.length > 0) { + throw new HardhatError(ERRORS.BUILTIN_TASKS.COMPILE_FAILURE); + } +}); + +// Chunk merging to reduce memory pressure if you generate many files. +task(TASK_COMPILE_SOLIDITY_MERGE_COMPILATION_JOBS, async ({ compilationJobs }, _, runSuper) => { + const CHUNK_SIZE = 100; + const chunks = []; + for (let i = 0; i < compilationJobs.length - 1; i += CHUNK_SIZE) { + chunks.push(compilationJobs.slice(i, i + CHUNK_SIZE)); + } + const mergedChunks = await Promise.all(chunks.map(cj => runSuper({ compilationJobs: cj }))); + return mergedChunks.flat(); +}); + +// Optional remappings (guarded so file absence doesn’t crash) +task(TASK_COMPILE_GET_REMAPPINGS).setAction((_, __, runSuper) => + runSuper().then(remappings => + Object.assign( + remappings, + Object.fromEntries( + fs + .readFileSync('remappings.txt', 'utf-8') + .split('\n') + .filter(Boolean) + .map(line => line.trim().split('=')), + ), + ), + ), +); + +/** + * @type import('hardhat/config').HardhatUserConfig + */ +module.exports = { + solidity: { + compilers: [ + { + version: SOLIDITY_VERSION, + settings: { + evmVersion: 'cancun', + optimizer: { enabled: true, runs: 200 }, + }, + }, + ], + }, +}; diff --git a/packages/core/uniswap-hooks/package.json b/packages/core/uniswap-hooks/package.json index 8ebbb793c..c676d7801 100644 --- a/packages/core/uniswap-hooks/package.json +++ b/packages/core/uniswap-hooks/package.json @@ -22,11 +22,11 @@ }, "devDependencies": { "@openzeppelin/contracts": "^5.3.0", - "@openzeppelin/uniswap-hooks": "https://github.com/OpenZeppelin/uniswap-hooks", - "@uniswap/v4-core": "^1.0.2", - "@uniswap/v4-periphery": "^1.0.3", + "@openzeppelin/uniswap-hooks": "github:OpenZeppelin/uniswap-hooks#update-remappings", "@types/node": "^20.0.0", "@types/semver": "^7.5.7", + "@uniswap/v4-core": "^1.0.2", + "@uniswap/v4-periphery": "^1.0.3", "ava": "^6.0.0", "hardhat": "^2.22.11", "rimraf": "^5.0.0", @@ -34,5 +34,8 @@ "solidity-ast": "^0.4.18", "ts-node": "^10.4.0", "typescript": "^5.0.0" + }, + "dependencies": { + "@openzeppelin/uniswap-hooks": "github:OpenZeppelin/uniswap-hooks#update-remappings" } } diff --git a/packages/core/uniswap-hooks/remappings.txt b/packages/core/uniswap-hooks/remappings.txt new file mode 100644 index 000000000..2173b79a6 --- /dev/null +++ b/packages/core/uniswap-hooks/remappings.txt @@ -0,0 +1,4 @@ +@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/ +@uniswap/v4-core/=node_modules/@uniswap/v4-core/ +@uniswap/v4-periphery/=node_modules/@uniswap/v4-periphery/ +@openzeppelin/uniswap-hooks/=node_modules/@openzeppelin/uniswap-hooks/src/ \ No newline at end of file diff --git a/packages/core/uniswap-hooks/src/.solidity-version.json b/packages/core/uniswap-hooks/src/.solidity-version.json new file mode 100644 index 000000000..12b321f91 --- /dev/null +++ b/packages/core/uniswap-hooks/src/.solidity-version.json @@ -0,0 +1 @@ +"0.8.27" diff --git a/packages/core/uniswap-hooks/src/generate/sources.ts b/packages/core/uniswap-hooks/src/generate/sources.ts new file mode 100644 index 000000000..fb0e3e784 --- /dev/null +++ b/packages/core/uniswap-hooks/src/generate/sources.ts @@ -0,0 +1,84 @@ +import { promises as fs } from 'fs'; +import path from 'path'; +import crypto from 'crypto'; + +import { printContract } from '@openzeppelin/wizard/src/print'; +import type { Contract } from '@openzeppelin/wizard/src/contract'; +import { OptionsError } from '@openzeppelin/wizard/src/error'; +import { findCover } from '@openzeppelin/wizard/src/utils/find-cover'; + +import { generateHooksOptions } from './hooks'; +import type { GenericOptions, KindedOptions } from '../build-generic'; +import { buildGeneric } from '../build-generic'; + +type Subset = 'all' | 'minimal-cover'; + +type Kind = keyof KindedOptions; + +export function* generateOptions(kind?: Kind): Generator { + if (!kind || kind === 'Hooks') { + for (const kindOpts of generateHooksOptions()) { + yield { kind: 'Hooks', ...kindOpts }; + } + } +} + +interface GeneratedContract { + id: string; + options: GenericOptions; + contract: Contract; +} + +export interface GeneratedSource extends GeneratedContract { + source: string; +} + +function generateContractSubset(subset: Subset, kind?: Kind): GeneratedContract[] { + const contracts = []; + + for (const options of generateOptions(kind)) { + const id = crypto.createHash('sha1').update(JSON.stringify(options)).digest().toString('hex'); + + try { + const contract = buildGeneric(options); + contracts.push({ id, options, contract }); + } catch (e: unknown) { + if (e instanceof OptionsError) { + continue; + } else { + throw e; + } + } + } + + if (subset === 'all') { + return contracts; + } else { + const getParents = (c: GeneratedContract) => c.contract.parents.map(p => p.contract.path); + return [ + ...findCover( + contracts.filter(c => c.options.upgradeable), + getParents, + ), + ...findCover( + contracts.filter(c => !c.options.upgradeable), + getParents, + ), + ]; + } +} + +export function* generateSources(subset: Subset, kind?: Kind): Generator { + for (const c of generateContractSubset(subset, kind)) { + const source = printContract(c.contract); + yield { ...c, source }; + } +} + +export async function writeGeneratedSources(dir: string, subset: Subset, kind?: Kind): Promise { + await fs.mkdir(dir, { recursive: true }); + + for (const { id, source } of generateSources(subset, kind)) { + await fs.writeFile(path.format({ dir, name: id, ext: '.sol' }), source); + } +} diff --git a/packages/core/uniswap-hooks/src/hooks.test.ts b/packages/core/uniswap-hooks/src/hooks.test.ts new file mode 100644 index 000000000..7cc78d8bf --- /dev/null +++ b/packages/core/uniswap-hooks/src/hooks.test.ts @@ -0,0 +1,40 @@ +import test from 'ava'; +// import type { OptionsError } from '@openzeppelin/wizard/src/error'; +import { hooks } from './api'; + +import type { HooksOptions } from './hooks'; +import { buildHooks, Hooks } from './hooks'; +import { printContract } from '@openzeppelin/wizard/src/print'; + +function testHooks(title: string, opts: Partial) { + test(title, t => { + const c = buildHooks({ + ...hooks.defaults, + ...opts, + }); + t.snapshot(printContract(c)); + }); +} + +// test all hooks +for (const hook of Hooks) { + testHooks(`basic ${hook.name}`, { hook: hook.name }); +} + +testHooks('access control (ownable)', { access: 'ownable' }); + +testHooks('access control (roles)', { access: 'roles' }); + +testHooks('access control (managed)', { access: 'managed' }); + +testHooks('pausable', { pausable: true }); + +testHooks('currency settler', { currencySettler: true }); + +testHooks('safeCast', { safeCast: true }); + +testHooks('transient storage', { transientStorage: true }); + +testHooks('shares erc20', { shares: { options: 'ERC20', name: 'MyShares', symbol: 'MSH' } }); + +testHooks('shares erc6909', { shares: { options: 'ERC6909', name: 'MyShares', symbol: 'MSH' } }); diff --git a/packages/core/uniswap-hooks/src/hooks.test.ts.md b/packages/core/uniswap-hooks/src/hooks.test.ts.md new file mode 100644 index 000000000..925be936a --- /dev/null +++ b/packages/core/uniswap-hooks/src/hooks.test.ts.md @@ -0,0 +1,356 @@ +# Snapshot report for `src/hooks.test.ts` + +The actual snapshot is saved in `hooks.test.ts.snap`. + +Generated by [AVA](https://avajs.dev). + +## basic BaseHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseHook} from "src/base/BaseHook.sol";␊ + import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ + ␊ + contract MyHook is BaseHook {␊ + constructor(IPoolManager _poolManager) BaseHook(_poolManager) {}␊ + }␊ + ` + +## basic BaseAsyncSwap + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseAsyncSwap} from "src/base/BaseAsyncSwap.sol";␊ + import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ + ␊ + contract MyHook is BaseAsyncSwap {␊ + constructor(IPoolManager _poolManager) BaseAsyncSwap(_poolManager) {}␊ + }␊ + ` + +## basic BaseCustomAccounting + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseCustomAccounting} from "src/base/BaseCustomAccounting.sol";␊ + import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ + ␊ + contract MyHook is BaseCustomAccounting {␊ + constructor(IPoolManager _poolManager) BaseCustomAccounting(_poolManager) {}␊ + }␊ + ` + +## basic BaseCustomCurve + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseCustomCurve} from "src/base/BaseCustomCurve.sol";␊ + import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ + ␊ + contract MyHook is BaseCustomCurve {␊ + constructor(IPoolManager _poolManager) BaseCustomCurve(_poolManager) {}␊ + }␊ + ` + +## basic BaseDynamicFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseDynamicFee} from "src/fee/BaseDynamicFee.sol";␊ + import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ + ␊ + contract MyHook is BaseDynamicFee {␊ + constructor(IPoolManager _poolManager) BaseDynamicFee(_poolManager) {}␊ + }␊ + ` + +## basic BaseOverrideFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseOverrideFee} from "src/fee/BaseOverrideFee.sol";␊ + import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ + ␊ + contract MyHook is BaseOverrideFee {␊ + constructor(IPoolManager _poolManager) BaseOverrideFee(_poolManager) {}␊ + }␊ + ` + +## basic BaseDynamicAfterFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseDynamicAfterFee} from "src/fee/BaseDynamicAfterFee.sol";␊ + import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ + ␊ + contract MyHook is BaseDynamicAfterFee {␊ + constructor(IPoolManager _poolManager) BaseDynamicAfterFee(_poolManager) {}␊ + }␊ + ` + +## basic AntiSandwichHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AntiSandwichHook} from "src/general/AntiSandwichHook.sol";␊ + import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ + ␊ + contract MyHook is AntiSandwichHook {␊ + constructor(IPoolManager _poolManager) AntiSandwichHook(_poolManager) {}␊ + }␊ + ` + +## basic LimitOrderHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ + import {LimitOrderHook} from "src/general/LimitOrderHook.sol";␊ + ␊ + contract MyHook is LimitOrderHook {␊ + constructor(IPoolManager _poolManager) LimitOrderHook(_poolManager) {}␊ + }␊ + ` + +## basic LiquidityPenaltyHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ + import {LiquidityPenaltyHook} from "src/general/LiquidityPenaltyHook.sol";␊ + ␊ + contract MyHook is LiquidityPenaltyHook {␊ + constructor(IPoolManager _poolManager, uint48 _blockNumberOffset)␊ + LiquidityPenaltyHook(_poolManager, _blockNumberOffset)␊ + {}␊ + }␊ + ` + +## access control (ownable) + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseHook} from "src/base/BaseHook.sol";␊ + import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ + import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊ + ␊ + contract MyHook is BaseHook, Ownable {␊ + constructor(IPoolManager _poolManager, address initialOwner)␊ + BaseHook(_poolManager)␊ + Ownable(initialOwner)␊ + {}␊ + }␊ + ` + +## access control (roles) + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";␊ + import {BaseHook} from "src/base/BaseHook.sol";␊ + import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ + ␊ + contract MyHook is BaseHook, AccessControl {␊ + constructor(IPoolManager _poolManager, address defaultAdmin)␊ + BaseHook(_poolManager)␊ + {␊ + _grantRole(DEFAULT_ADMIN_ROLE, defaultAdmin);␊ + }␊ + }␊ + ` + +## access control (managed) + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AccessManaged} from "@openzeppelin/contracts/access/manager/AccessManaged.sol";␊ + import {BaseHook} from "src/base/BaseHook.sol";␊ + import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ + ␊ + contract MyHook is BaseHook, AccessManaged {␊ + constructor(IPoolManager _poolManager, address initialAuthority)␊ + BaseHook(_poolManager)␊ + AccessManaged(initialAuthority)␊ + {}␊ + }␊ + ` + +## pausable + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseHook} from "src/base/BaseHook.sol";␊ + import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ + import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊ + import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";␊ + ␊ + contract MyHook is BaseHook, Pausable, Ownable {␊ + constructor(IPoolManager _poolManager, address initialOwner)␊ + BaseHook(_poolManager)␊ + Ownable(initialOwner)␊ + {}␊ + ␊ + function pause() public onlyOwner {␊ + _pause();␊ + }␊ + ␊ + function unpause() public onlyOwner {␊ + _unpause();␊ + }␊ + }␊ + ` + +## currency settler + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseHook} from "src/base/BaseHook.sol";␊ + import {CurrencySettler} from "src/utils/CurrencySettler.sol";␊ + import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ + ␊ + contract MyHook is BaseHook {␊ + using CurrencySettler for Currency;␊ + ␊ + constructor(IPoolManager _poolManager) BaseHook(_poolManager) {}␊ + }␊ + ` + +## safeCast + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseHook} from "src/base/BaseHook.sol";␊ + import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ + import {SafeCast} from "openzeppelin/utils/math/SafeCast.sol";␊ + ␊ + contract MyHook is BaseHook {␊ + using SafeCast for *;␊ + ␊ + constructor(IPoolManager _poolManager) BaseHook(_poolManager) {}␊ + }␊ + ` + +## transient storage + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseHook} from "src/base/BaseHook.sol";␊ + import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ + import {SlotDerivation} from "openzeppelin/utils/SlotDerivation.sol";␊ + import {TransientSlot} from "openzeppelin/utils/TransientSlot.sol";␊ + ␊ + contract MyHook is BaseHook {␊ + using SlotDerivation for bytes32;␊ + using TransientSlot for bytes32;␊ + ␊ + constructor(IPoolManager _poolManager) BaseHook(_poolManager) {}␊ + }␊ + ` + +## shares erc20 + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseHook} from "src/base/BaseHook.sol";␊ + import {ERC20} from "openzeppelin/token/ERC20/ERC20.sol";␊ + import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ + ␊ + contract MyHook is BaseHook, ERC20 {␊ + constructor(IPoolManager _poolManager)␊ + BaseHook(_poolManager)␊ + ERC20("MyShares", "MSH")␊ + {}␊ + }␊ + ` + +## shares erc6909 + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseHook} from "src/base/BaseHook.sol";␊ + import {ERC6909} from "openzeppelin/token/ERC6909/draft-ERC6909.sol";␊ + import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ + ␊ + contract MyHook is BaseHook, ERC6909 {␊ + constructor(IPoolManager _poolManager)␊ + BaseHook(_poolManager)␊ + ERC6909("MyShares", "MSH")␊ + {}␊ + }␊ + ` diff --git a/packages/core/uniswap-hooks/src/hooks.test.ts.snap b/packages/core/uniswap-hooks/src/hooks.test.ts.snap new file mode 100644 index 0000000000000000000000000000000000000000..0613b54e874e9d2d721806a7d87d3d03f5d462c6 GIT binary patch literal 1321 zcmV+^1=jjORzV^TLVa z5U?wO#~+Ib00000000B!na^$`H5|v=t`JfoD5sS43?WAnl0*2mkG3iW(06uL;WyF`xQ9;!+~ ztR9wNr30IiyVdQne(!*Dw~ZO@gGg=8?{5$;z=~`sQy?5nKw4R8;-x~83{g9boFgj7 z>w_*T2q8o`lS%|caZ$^9Kqvm>%lg==rvH3#S-Gqv>n|tk-;^OE-68f35T0rfzFicA zaf(I~o2O+2pW;$mYo!+A8WRf)D$qdhhPbOY@KpEqr z?dhGV=cnl?5N1rzG)!W_4^f(E!IP9q=J`0KF>m}#r49>(wCYmVKa zhV1Dgkma+?^6CQvfn6)FdF89btpG2GkO?z?WO))Qdh-6Kq{k z07(~?L!{fza6;dwXFU)@UiML_NbLNF62Ga^-<-TSUw#ql#j;Gh`qpm0`Xs84o8B zYtzQs_L?sX!CjDsqF8%ND~fw-i`ZV{Tw9}5XN08L$>Od*s8F%cySclR7P)TW%SQN zPHAzrqm{5{EThqkgr(UoeK{q0zEsy~25P_sRpHE?M~huEyUF&TfsX?j^(sTT{H~SD z&x`0fcW*07eHkqBQf4K|CtyVIt?r2h3vr#eS1oQs8 zDUi{Hc`ga$a54UEyK>9_OARD;poOI}5dKvoe03KH-%c0nCTo&<&>GOFQar2%R;nvY zIJJw>zJKdX&y>JSQeX;6#Rcx0wy3%W_r3qm7S(mR+5th&anvdc5bMI6m!ouvBUOPD zO;@^3v<%{E>4gg92V2`2l@>x5-Ev{Ma)1R$1cGcemh; + +test.serial('hooks result compiles', async t => { + await testCompile(t, 'Hooks'); +}); + +async function testCompile(t: ExecutionContext, kind: keyof KindedOptions) { + const generatedSourcesPath = path.join(hre.config.paths.sources, `generated`); + await fs.rm(generatedSourcesPath, { force: true, recursive: true }); + await writeGeneratedSources(generatedSourcesPath, 'all', kind); + + // We only want to check that contracts compile and we don't care about any + // of the outputs. Setting empty outputSelection causes compilation to go a + // lot faster and not run out of memory. + for (const { settings } of hre.config.solidity.compilers) { + settings.outputSelection = {}; + } + + await hre.run('compile'); + t.pass(); +} diff --git a/packages/ui/src/uniswap-hooks/inject-hyperlinks.ts b/packages/ui/src/uniswap-hooks/inject-hyperlinks.ts index 21e1cb11d..7685cc105 100644 --- a/packages/ui/src/uniswap-hooks/inject-hyperlinks.ts +++ b/packages/ui/src/uniswap-hooks/inject-hyperlinks.ts @@ -5,8 +5,8 @@ export function injectHyperlinks(code: string) { const contractsRegex = /"(@openzeppelin\/)(contracts-upgradeable\/|contracts\/)((?:(?!\.\.)[^/]+\/)*?[^/]*?)"/g; const communityContractsRegex = /"(@openzeppelin\/)(community-contracts\/)((?:(?!\.\.)[^/]+\/)*?[^/]*?)"/g; - const uniswapV4CoreRegex = /"(@uniswap\/)(v4-core\/contracts\/)((?:(?!\.\.)[^/]+\/)*?[^/]*?)"/g; - const ozUniswapHooksRegex = /"(@openzeppelin\/)(uniswap-hooks\/src\/)((?:(?!\.\.)[^/]+\/)*?[^/]*?)"/g; + const ozUniswapHooksRegex = /"(@openzeppelin\/)(uniswap-hooks\/)((?:(?!\.\.)[^/]+\/)*?[^/]*?)"/g; + const uniswapV4CoreRegex = /"(@uniswap\/)(v4-core\/src\/)((?:(?!\.\.)[^/]+\/)*?[^/]*?)"/g; return code .replace( diff --git a/yarn.lock b/yarn.lock index 1aab3f784..6cb28efd4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -832,9 +832,9 @@ resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-5.3.0.tgz#0a90ce16f5c855e3c8239691f1722cd4999ae741" integrity sha512-zj/KGoW7zxWUE8qOI++rUM18v+VeLTTzKs/DJFkSzHpQFPD/jKKF0TrMxBfGLl3kpdELCNccvB3zmofSzm4nlA== -"@openzeppelin/uniswap-hooks@https://github.com/OpenZeppelin/uniswap-hooks": +"@openzeppelin/uniswap-hooks@github:OpenZeppelin/uniswap-hooks#update-remappings": version "1.1.0" - resolved "https://github.com/OpenZeppelin/uniswap-hooks#99bda078a036fbe5acb1dfa6d00d6b7a3941ea1f" + resolved "https://codeload.github.com/OpenZeppelin/uniswap-hooks/tar.gz/59647ab3432c12e4b157ae8defa3cc1db1735182" "@pkgjs/parseargs@^0.11.0": version "0.11.0" From 20c07d8b7f6604a9a4b9cc0c9275ea88cb1afa21 Mon Sep 17 00:00:00 2001 From: Gonzalo Othacehe Date: Tue, 19 Aug 2025 10:08:14 -0300 Subject: [PATCH 16/79] fix addUsing compilation via addImportOnly addition --- .../core/uniswap-hooks/src/hooks.test.ts.md | 94 +++++++++--------- .../core/uniswap-hooks/src/hooks.test.ts.snap | Bin 1321 -> 1353 bytes packages/core/uniswap-hooks/src/hooks.ts | 6 +- 3 files changed, 51 insertions(+), 49 deletions(-) diff --git a/packages/core/uniswap-hooks/src/hooks.test.ts.md b/packages/core/uniswap-hooks/src/hooks.test.ts.md index 925be936a..2878fa03f 100644 --- a/packages/core/uniswap-hooks/src/hooks.test.ts.md +++ b/packages/core/uniswap-hooks/src/hooks.test.ts.md @@ -12,8 +12,8 @@ Generated by [AVA](https://avajs.dev). // Compatible with OpenZeppelin Contracts ^5.0.0␊ pragma solidity ^0.8.27;␊ ␊ - import {BaseHook} from "src/base/BaseHook.sol";␊ - import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ + import {BaseHook} from "@openzeppelin/uniswap-hooks/base/BaseHook.sol";␊ + import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ ␊ contract MyHook is BaseHook {␊ constructor(IPoolManager _poolManager) BaseHook(_poolManager) {}␊ @@ -28,8 +28,8 @@ Generated by [AVA](https://avajs.dev). // Compatible with OpenZeppelin Contracts ^5.0.0␊ pragma solidity ^0.8.27;␊ ␊ - import {BaseAsyncSwap} from "src/base/BaseAsyncSwap.sol";␊ - import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ + import {BaseAsyncSwap} from "@openzeppelin/uniswap-hooks/base/BaseAsyncSwap.sol";␊ + import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ ␊ contract MyHook is BaseAsyncSwap {␊ constructor(IPoolManager _poolManager) BaseAsyncSwap(_poolManager) {}␊ @@ -44,8 +44,8 @@ Generated by [AVA](https://avajs.dev). // Compatible with OpenZeppelin Contracts ^5.0.0␊ pragma solidity ^0.8.27;␊ ␊ - import {BaseCustomAccounting} from "src/base/BaseCustomAccounting.sol";␊ - import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ + import {BaseCustomAccounting} from "@openzeppelin/uniswap-hooks/base/BaseCustomAccounting.sol";␊ + import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ ␊ contract MyHook is BaseCustomAccounting {␊ constructor(IPoolManager _poolManager) BaseCustomAccounting(_poolManager) {}␊ @@ -60,8 +60,8 @@ Generated by [AVA](https://avajs.dev). // Compatible with OpenZeppelin Contracts ^5.0.0␊ pragma solidity ^0.8.27;␊ ␊ - import {BaseCustomCurve} from "src/base/BaseCustomCurve.sol";␊ - import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ + import {BaseCustomCurve} from "@openzeppelin/uniswap-hooks/base/BaseCustomCurve.sol";␊ + import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ ␊ contract MyHook is BaseCustomCurve {␊ constructor(IPoolManager _poolManager) BaseCustomCurve(_poolManager) {}␊ @@ -76,8 +76,8 @@ Generated by [AVA](https://avajs.dev). // Compatible with OpenZeppelin Contracts ^5.0.0␊ pragma solidity ^0.8.27;␊ ␊ - import {BaseDynamicFee} from "src/fee/BaseDynamicFee.sol";␊ - import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ + import {BaseDynamicFee} from "@openzeppelin/uniswap-hooks/fee/BaseDynamicFee.sol";␊ + import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ ␊ contract MyHook is BaseDynamicFee {␊ constructor(IPoolManager _poolManager) BaseDynamicFee(_poolManager) {}␊ @@ -92,8 +92,8 @@ Generated by [AVA](https://avajs.dev). // Compatible with OpenZeppelin Contracts ^5.0.0␊ pragma solidity ^0.8.27;␊ ␊ - import {BaseOverrideFee} from "src/fee/BaseOverrideFee.sol";␊ - import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ + import {BaseOverrideFee} from "@openzeppelin/uniswap-hooks/fee/BaseOverrideFee.sol";␊ + import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ ␊ contract MyHook is BaseOverrideFee {␊ constructor(IPoolManager _poolManager) BaseOverrideFee(_poolManager) {}␊ @@ -108,8 +108,8 @@ Generated by [AVA](https://avajs.dev). // Compatible with OpenZeppelin Contracts ^5.0.0␊ pragma solidity ^0.8.27;␊ ␊ - import {BaseDynamicAfterFee} from "src/fee/BaseDynamicAfterFee.sol";␊ - import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ + import {BaseDynamicAfterFee} from "@openzeppelin/uniswap-hooks/fee/BaseDynamicAfterFee.sol";␊ + import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ ␊ contract MyHook is BaseDynamicAfterFee {␊ constructor(IPoolManager _poolManager) BaseDynamicAfterFee(_poolManager) {}␊ @@ -124,8 +124,8 @@ Generated by [AVA](https://avajs.dev). // Compatible with OpenZeppelin Contracts ^5.0.0␊ pragma solidity ^0.8.27;␊ ␊ - import {AntiSandwichHook} from "src/general/AntiSandwichHook.sol";␊ - import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ + import {AntiSandwichHook} from "@openzeppelin/uniswap-hooks/general/AntiSandwichHook.sol";␊ + import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ ␊ contract MyHook is AntiSandwichHook {␊ constructor(IPoolManager _poolManager) AntiSandwichHook(_poolManager) {}␊ @@ -140,8 +140,8 @@ Generated by [AVA](https://avajs.dev). // Compatible with OpenZeppelin Contracts ^5.0.0␊ pragma solidity ^0.8.27;␊ ␊ - import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ - import {LimitOrderHook} from "src/general/LimitOrderHook.sol";␊ + import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ + import {LimitOrderHook} from "@openzeppelin/uniswap-hooks/general/LimitOrderHook.sol";␊ ␊ contract MyHook is LimitOrderHook {␊ constructor(IPoolManager _poolManager) LimitOrderHook(_poolManager) {}␊ @@ -156,8 +156,8 @@ Generated by [AVA](https://avajs.dev). // Compatible with OpenZeppelin Contracts ^5.0.0␊ pragma solidity ^0.8.27;␊ ␊ - import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ - import {LiquidityPenaltyHook} from "src/general/LiquidityPenaltyHook.sol";␊ + import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ + import {LiquidityPenaltyHook} from "@openzeppelin/uniswap-hooks/general/LiquidityPenaltyHook.sol";␊ ␊ contract MyHook is LiquidityPenaltyHook {␊ constructor(IPoolManager _poolManager, uint48 _blockNumberOffset)␊ @@ -174,8 +174,8 @@ Generated by [AVA](https://avajs.dev). // Compatible with OpenZeppelin Contracts ^5.0.0␊ pragma solidity ^0.8.27;␊ ␊ - import {BaseHook} from "src/base/BaseHook.sol";␊ - import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ + import {BaseHook} from "@openzeppelin/uniswap-hooks/base/BaseHook.sol";␊ + import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊ ␊ contract MyHook is BaseHook, Ownable {␊ @@ -195,8 +195,8 @@ Generated by [AVA](https://avajs.dev). pragma solidity ^0.8.27;␊ ␊ import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";␊ - import {BaseHook} from "src/base/BaseHook.sol";␊ - import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ + import {BaseHook} from "@openzeppelin/uniswap-hooks/base/BaseHook.sol";␊ + import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ ␊ contract MyHook is BaseHook, AccessControl {␊ constructor(IPoolManager _poolManager, address defaultAdmin)␊ @@ -216,8 +216,8 @@ Generated by [AVA](https://avajs.dev). pragma solidity ^0.8.27;␊ ␊ import {AccessManaged} from "@openzeppelin/contracts/access/manager/AccessManaged.sol";␊ - import {BaseHook} from "src/base/BaseHook.sol";␊ - import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ + import {BaseHook} from "@openzeppelin/uniswap-hooks/base/BaseHook.sol";␊ + import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ ␊ contract MyHook is BaseHook, AccessManaged {␊ constructor(IPoolManager _poolManager, address initialAuthority)␊ @@ -235,8 +235,8 @@ Generated by [AVA](https://avajs.dev). // Compatible with OpenZeppelin Contracts ^5.0.0␊ pragma solidity ^0.8.27;␊ ␊ - import {BaseHook} from "src/base/BaseHook.sol";␊ - import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ + import {BaseHook} from "@openzeppelin/uniswap-hooks/base/BaseHook.sol";␊ + import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊ import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";␊ ␊ @@ -264,9 +264,10 @@ Generated by [AVA](https://avajs.dev). // Compatible with OpenZeppelin Contracts ^5.0.0␊ pragma solidity ^0.8.27;␊ ␊ - import {BaseHook} from "src/base/BaseHook.sol";␊ - import {CurrencySettler} from "src/utils/CurrencySettler.sol";␊ - import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ + import {BaseHook} from "@openzeppelin/uniswap-hooks/base/BaseHook.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {CurrencySettler} from "@openzeppelin/uniswap-hooks/utils/CurrencySettler.sol";␊ + import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ ␊ contract MyHook is BaseHook {␊ using CurrencySettler for Currency;␊ @@ -283,9 +284,9 @@ Generated by [AVA](https://avajs.dev). // Compatible with OpenZeppelin Contracts ^5.0.0␊ pragma solidity ^0.8.27;␊ ␊ - import {BaseHook} from "src/base/BaseHook.sol";␊ - import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ - import {SafeCast} from "openzeppelin/utils/math/SafeCast.sol";␊ + import {BaseHook} from "@openzeppelin/uniswap-hooks/base/BaseHook.sol";␊ + import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ + import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";␊ ␊ contract MyHook is BaseHook {␊ using SafeCast for *;␊ @@ -302,10 +303,10 @@ Generated by [AVA](https://avajs.dev). // Compatible with OpenZeppelin Contracts ^5.0.0␊ pragma solidity ^0.8.27;␊ ␊ - import {BaseHook} from "src/base/BaseHook.sol";␊ - import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ - import {SlotDerivation} from "openzeppelin/utils/SlotDerivation.sol";␊ - import {TransientSlot} from "openzeppelin/utils/TransientSlot.sol";␊ + import {BaseHook} from "@openzeppelin/uniswap-hooks/base/BaseHook.sol";␊ + import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ + import {SlotDerivation} from "@openzeppelin/contracts/utils/SlotDerivation.sol";␊ + import {TransientSlot} from "@openzeppelin/contracts/utils/TransientSlot.sol";␊ ␊ contract MyHook is BaseHook {␊ using SlotDerivation for bytes32;␊ @@ -323,9 +324,9 @@ Generated by [AVA](https://avajs.dev). // Compatible with OpenZeppelin Contracts ^5.0.0␊ pragma solidity ^0.8.27;␊ ␊ - import {BaseHook} from "src/base/BaseHook.sol";␊ - import {ERC20} from "openzeppelin/token/ERC20/ERC20.sol";␊ - import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ + import {BaseHook} from "@openzeppelin/uniswap-hooks/base/BaseHook.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ ␊ contract MyHook is BaseHook, ERC20 {␊ constructor(IPoolManager _poolManager)␊ @@ -343,14 +344,11 @@ Generated by [AVA](https://avajs.dev). // Compatible with OpenZeppelin Contracts ^5.0.0␊ pragma solidity ^0.8.27;␊ ␊ - import {BaseHook} from "src/base/BaseHook.sol";␊ - import {ERC6909} from "openzeppelin/token/ERC6909/draft-ERC6909.sol";␊ - import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";␊ + import {BaseHook} from "@openzeppelin/uniswap-hooks/base/BaseHook.sol";␊ + import {ERC6909} from "@openzeppelin/contracts/token/ERC6909/draft-ERC6909.sol";␊ + import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ ␊ contract MyHook is BaseHook, ERC6909 {␊ - constructor(IPoolManager _poolManager)␊ - BaseHook(_poolManager)␊ - ERC6909("MyShares", "MSH")␊ - {}␊ + constructor(IPoolManager _poolManager) BaseHook(_poolManager) {}␊ }␊ ` diff --git a/packages/core/uniswap-hooks/src/hooks.test.ts.snap b/packages/core/uniswap-hooks/src/hooks.test.ts.snap index 0613b54e874e9d2d721806a7d87d3d03f5d462c6..f9804d865d60a93c39e5fffa57a4ba581dee4d7c 100644 GIT binary patch literal 1353 zcmV-P1-AM@RzVe-x}%8TcqsIr0eu%rZih$TGa{FF+DT{+-Ne)Y^WvBICMj$T@M zbtU*(eP!jfwZW=kpzdMo^T>0~%2^Kphv@ zr{KC^Q-+$HDS?TS=og+(d z2US1dF0jv|goekc9AS5J!1<{(dRT%H3$`S;tGh{_{X@>}HfFdFBFPoWjp4mb!UY&o z5Q8!W!omckF|CQxRYhoA*xfD_en`AzB;$2ZaDJAs`c2tiHA z#`m3u@9VPgO*L7B-;`{*0H+EUCpaaZcZqys<^(n@1tOc{bB*Ig$;U8m^crU|mX>lL z00AUc*ML9K^bg0HM1H9gB^a?KmB zV?sbm6t08YsK!SO_iR|7b;jDunlt`+@hB)s*BNhGc2}`Qq%q!WBZ|)PIB5e#vBms@ zO;ZF=DWi&FyE9@SCf3P*>XiICs#u#9YnS-6Zv?kNX1V6B=9;(H%DBXby*9_K=7gka zQn+uJ3+FpXTgdf%WP*h~TQy9FvRpnoOM*`N0yA~QZK$>O9yC5WI6i5#+WU`AjyeZ> z8+zv5P&IctIbjtu%V!&!&)zD}XXBkPbNXz&B4KFS+wZq%A^&M^H9R%of+|1v?9yu2 zveQgYv4M*{8BDtjKmD%x>E|;1bi=qW;%XP?IE*&_swAGGwlw1CTn3DTZ`{Q*{AqcN zD9RZMtOvDq2o)Ex@k0dB%gUC1pJK7<* zbDIxAGg|H31E72tq!EW+lA$}^t~?Em?VA#o_OYZVgO5d0-5`sLf$XW{&xD1n)zz!Z{-3*67T)Dq1I z$G3UPEZPV*S1k~9h=Y-z&knjKmGC&m5k%$7r%4LiOKT=HS?{4o-MQJ7UpauKU zmIEw6A`oP|o-vdD)~xvFZJtScN6qc}RfrWo1!jbyAEF LsTNA}4JQBqLzk7J literal 1321 zcmV+^1=jjORzV^TLVa z5U?wO#~+Ib00000000B!na^$`H5|v=t`JfoD5sS43?WAnl0*2mkG3iW(06uL;WyF`xQ9;!+~ ztR9wNr30IiyVdQne(!*Dw~ZO@gGg=8?{5$;z=~`sQy?5nKw4R8;-x~83{g9boFgj7 z>w_*T2q8o`lS%|caZ$^9Kqvm>%lg==rvH3#S-Gqv>n|tk-;^OE-68f35T0rfzFicA zaf(I~o2O+2pW;$mYo!+A8WRf)D$qdhhPbOY@KpEqr z?dhGV=cnl?5N1rzG)!W_4^f(E!IP9q=J`0KF>m}#r49>(wCYmVKa zhV1Dgkma+?^6CQvfn6)FdF89btpG2GkO?z?WO))Qdh-6Kq{k z07(~?L!{fza6;dwXFU)@UiML_NbLNF62Ga^-<-TSUw#ql#j;Gh`qpm0`Xs84o8B zYtzQs_L?sX!CjDsqF8%ND~fw-i`ZV{Tw9}5XN08L$>Od*s8F%cySclR7P)TW%SQN zPHAzrqm{5{EThqkgr(UoeK{q0zEsy~25P_sRpHE?M~huEyUF&TfsX?j^(sTT{H~SD z&x`0fcW*07eHkqBQf4K|CtyVIt?r2h3vr#eS1oQs8 zDUi{Hc`ga$a54UEyK>9_OARD;poOI}5dKvoe03KH-%c0nCTo&<&>GOFQar2%R;nvY zIJJw>zJKdX&y>JSQeX;6#Rcx0wy3%W_r3qm7S(mR+5th&anvdc5bMI6m!ouvBUOPD zO;@^3v<%{E>4gg92V2`2l@>x5-Ev{Ma)1R$1cGcemh Date: Tue, 19 Aug 2025 10:38:11 -0300 Subject: [PATCH 17/79] add erc1155 shares --- packages/core/uniswap-hooks/src/hooks.ts | 34 ++++++++++++++----- .../ui/src/uniswap-hooks/HooksControls.svelte | 21 +++++++++++- 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/packages/core/uniswap-hooks/src/hooks.ts b/packages/core/uniswap-hooks/src/hooks.ts index 42ecdeaef..27809ceb3 100644 --- a/packages/core/uniswap-hooks/src/hooks.ts +++ b/packages/core/uniswap-hooks/src/hooks.ts @@ -103,21 +103,22 @@ export const Hooks: Hook[] = [ }, ]; -export const sharesOptions = [false, 'ERC20', 'ERC6909'] as const; +export const sharesOptions = [false, 'ERC20', 'ERC6909', 'ERC1155'] as const; export type Shares = { options: (typeof sharesOptions)[number]; - name: string; - symbol: string; + name?: string; + symbol?: string; + uri?: string; }; export interface HooksOptions extends CommonOptions { hook: HookName; name: string; - pausable?: boolean; - currencySettler?: boolean; - safeCast?: boolean; - transientStorage?: boolean; - shares?: Shares; + pausable: boolean; + currencySettler: boolean; + safeCast: boolean; + transientStorage: boolean; + shares: Shares; } export const defaults: Required = { @@ -134,6 +135,7 @@ export const defaults: Required = { options: false, name: 'MyShares', symbol: 'MSH', + uri: '', }, } as const; @@ -192,6 +194,9 @@ export function buildHooks(opts: HooksOptions): Contract { if (allOpts.shares.options === 'ERC20') { addERC20Shares(c, allOpts); } + if (allOpts.shares.options === 'ERC1155') { + addERC1155Shares(c, allOpts); + } if (allOpts.shares.options === 'ERC6909') { addERC6909Shares(c, allOpts); } @@ -287,9 +292,20 @@ function addERC20Shares(c: ContractBuilder, _allOpts: HooksOptions) { name: 'ERC20', path: `@openzeppelin/contracts/token/ERC20/ERC20.sol`, }, - [_allOpts.shares!.name, _allOpts.shares!.symbol], + [_allOpts.shares.name || '', _allOpts.shares.symbol || ''], ); } + +function addERC1155Shares(c: ContractBuilder, _allOpts: HooksOptions) { + c.addParent( + { + name: 'ERC1155', + path: `@openzeppelin/contracts/token/ERC1155/ERC1155.sol`, + }, + [_allOpts.shares.uri || ''], + ); +} + function addERC6909Shares(c: ContractBuilder, _allOpts: HooksOptions) { c.addParent( { diff --git a/packages/ui/src/uniswap-hooks/HooksControls.svelte b/packages/ui/src/uniswap-hooks/HooksControls.svelte index 8542cea53..88c13ab8f 100644 --- a/packages/ui/src/uniswap-hooks/HooksControls.svelte +++ b/packages/ui/src/uniswap-hooks/HooksControls.svelte @@ -80,15 +80,33 @@ + + +
+ + {#if opts.shares.options === 'ERC1155'} + + {/if} + + {#if opts.shares.options === 'ERC20'}
+ {/if} From 0b02d69a2d0641dce12f5d0f8e6b5045558f7d44 Mon Sep 17 00:00:00 2001 From: Gonzalo Othacehe Date: Tue, 19 Aug 2025 14:26:38 -0300 Subject: [PATCH 18/79] add optional override "compatibleSemver" to printContract --- packages/core/solidity/src/options.ts | 6 ++++++ packages/core/solidity/src/print.ts | 5 +++-- packages/core/solidity/src/utils/version.ts | 2 +- packages/core/uniswap-hooks/src/generate/sources.ts | 4 +++- packages/core/uniswap-hooks/src/hooks.test.ts | 3 ++- packages/core/uniswap-hooks/src/hooks.ts | 3 ++- packages/core/uniswap-hooks/src/utils/version.ts | 2 +- packages/ui/src/uniswap-hooks/App.svelte | 3 ++- 8 files changed, 20 insertions(+), 8 deletions(-) diff --git a/packages/core/solidity/src/options.ts b/packages/core/solidity/src/options.ts index 6e800715f..cfe775830 100644 --- a/packages/core/solidity/src/options.ts +++ b/packages/core/solidity/src/options.ts @@ -27,6 +27,11 @@ const upgradeableImport = (p: ImportContract): ImportContract => { export interface Options { transformImport?: (parent: ImportContract) => ImportContract; + /** + * Optional override for the compatibility banner printed at the top of the contract. + * If not provided, the default from this package will be used. (OpenZeppelin Contracts ^X.Y.Z) + */ + compatibleSemver?: string; } export interface Helpers extends Required { @@ -45,5 +50,6 @@ export function withHelpers(contract: Contract, opts: Options = {}): Helpers { const p2 = contractUpgradeable && inferTranspiled(p1) ? upgradeableImport(p1) : p1; return opts.transformImport?.(p2) ?? p2; }, + compatibleSemver: opts.compatibleSemver ?? '', }; } diff --git a/packages/core/solidity/src/print.ts b/packages/core/solidity/src/print.ts index d1cb174c7..811cd6cf3 100644 --- a/packages/core/solidity/src/print.ts +++ b/packages/core/solidity/src/print.ts @@ -15,11 +15,12 @@ import { formatLines, spaceBetween } from './utils/format-lines'; import { mapValues } from './utils/map-values'; import SOLIDITY_VERSION from './solidity-version.json'; import { inferTranspiled } from './infer-transpiled'; -import { compatibleContractsSemver } from './utils/version'; +import { compatibleContractsSemver as defaultCompatibleSemver } from './utils/version'; import { stringifyUnicodeSafe } from './utils/sanitize'; export function printContract(contract: Contract, opts?: Options): string { const helpers = withHelpers(contract, opts); + const compatibleSemver = opts?.compatibleSemver ?? defaultCompatibleSemver; const fns = mapValues(sortedFunctions(contract), fns => fns.map(fn => printFunction(fn, helpers))); @@ -29,7 +30,7 @@ export function printContract(contract: Contract, opts?: Options): string { ...spaceBetween( [ `// SPDX-License-Identifier: ${contract.license}`, - `// Compatible with OpenZeppelin Contracts ${compatibleContractsSemver}`, + `// Compatible with ${compatibleSemver}`, `pragma solidity ^${SOLIDITY_VERSION};`, ], diff --git a/packages/core/solidity/src/utils/version.ts b/packages/core/solidity/src/utils/version.ts index 3daddc218..bfbb1ba7f 100644 --- a/packages/core/solidity/src/utils/version.ts +++ b/packages/core/solidity/src/utils/version.ts @@ -1,4 +1,4 @@ /** * Semantic version string representing of the minimum compatible version of Contracts to display in output. */ -export const compatibleContractsSemver = '^5.0.0'; +export const compatibleContractsSemver = 'Openzeppelin Contracts ^5.0.0'; diff --git a/packages/core/uniswap-hooks/src/generate/sources.ts b/packages/core/uniswap-hooks/src/generate/sources.ts index fb0e3e784..9e594f795 100644 --- a/packages/core/uniswap-hooks/src/generate/sources.ts +++ b/packages/core/uniswap-hooks/src/generate/sources.ts @@ -11,6 +11,8 @@ import { generateHooksOptions } from './hooks'; import type { GenericOptions, KindedOptions } from '../build-generic'; import { buildGeneric } from '../build-generic'; +import { compatibleContractsSemver } from '../utils/version'; + type Subset = 'all' | 'minimal-cover'; type Kind = keyof KindedOptions; @@ -70,7 +72,7 @@ function generateContractSubset(subset: Subset, kind?: Kind): GeneratedContract[ export function* generateSources(subset: Subset, kind?: Kind): Generator { for (const c of generateContractSubset(subset, kind)) { - const source = printContract(c.contract); + const source = printContract(c.contract, { compatibleSemver: compatibleContractsSemver }); yield { ...c, source }; } } diff --git a/packages/core/uniswap-hooks/src/hooks.test.ts b/packages/core/uniswap-hooks/src/hooks.test.ts index 7cc78d8bf..ac7993eca 100644 --- a/packages/core/uniswap-hooks/src/hooks.test.ts +++ b/packages/core/uniswap-hooks/src/hooks.test.ts @@ -5,6 +5,7 @@ import { hooks } from './api'; import type { HooksOptions } from './hooks'; import { buildHooks, Hooks } from './hooks'; import { printContract } from '@openzeppelin/wizard/src/print'; +import { compatibleContractsSemver } from './utils/version'; function testHooks(title: string, opts: Partial) { test(title, t => { @@ -12,7 +13,7 @@ function testHooks(title: string, opts: Partial) { ...hooks.defaults, ...opts, }); - t.snapshot(printContract(c)); + t.snapshot(printContract(c, { compatibleSemver: compatibleContractsSemver })); }); } diff --git a/packages/core/uniswap-hooks/src/hooks.ts b/packages/core/uniswap-hooks/src/hooks.ts index 27809ceb3..c4f747cc8 100644 --- a/packages/core/uniswap-hooks/src/hooks.ts +++ b/packages/core/uniswap-hooks/src/hooks.ts @@ -6,6 +6,7 @@ import { setInfo } from '@openzeppelin/wizard/src/set-info'; import { setAccessControl } from '@openzeppelin/wizard/src/set-access-control'; import { addPausable } from '@openzeppelin/wizard/src/add-pausable'; import { printContract } from '@openzeppelin/wizard/src/print'; +import { compatibleContractsSemver } from './utils/version'; import type { Value } from '@openzeppelin/wizard/src/contract'; export type HookCategory = 'Base' | 'Fee' | 'General'; @@ -152,7 +153,7 @@ function withDefaults(opts: HooksOptions): Required { } export function printHooks(opts: HooksOptions = defaults): string { - return printContract(buildHooks(opts)); + return printContract(buildHooks(opts), { compatibleSemver: compatibleContractsSemver }); } export function isAccessControlRequired(opts: Partial): boolean { diff --git a/packages/core/uniswap-hooks/src/utils/version.ts b/packages/core/uniswap-hooks/src/utils/version.ts index c8d01ae1b..1116bb96c 100644 --- a/packages/core/uniswap-hooks/src/utils/version.ts +++ b/packages/core/uniswap-hooks/src/utils/version.ts @@ -1,4 +1,4 @@ /** * Semantic version string representing of the minimum compatible version of Contracts to display in output. */ -export const compatibleContractsSemver = '^0.0.0'; +export const compatibleContractsSemver = 'OpenZeppelin Uniswap Hooks ^1.0.0'; diff --git a/packages/ui/src/uniswap-hooks/App.svelte b/packages/ui/src/uniswap-hooks/App.svelte index a5951b734..02cb13eb8 100644 --- a/packages/ui/src/uniswap-hooks/App.svelte +++ b/packages/ui/src/uniswap-hooks/App.svelte @@ -22,6 +22,7 @@ import { injectHyperlinks } from './inject-hyperlinks'; import type { InitialOptions } from '../common/initial-options'; import ErrorDisabledActionButtons from '../common/ErrorDisabledActionButtons.svelte'; + import { compatibleContractsSemver } from '@openzeppelin/wizard-uniswap-hooks/src/utils/version'; const dispatch = createEventDispatcher(); @@ -75,7 +76,7 @@ } } - $: code = printContract(contract); + $: code = printContract(contract, { compatibleSemver: compatibleContractsSemver }); $: highlightedCode = injectHyperlinks(hljs.highlight('solidity', code).value); $: hasErrors = errors[tab] !== undefined; From 6d9ff54df7203b53beaec6cfaf6c70733b778e7c Mon Sep 17 00:00:00 2001 From: Gonzalo Othacehe Date: Tue, 19 Aug 2025 17:22:27 -0300 Subject: [PATCH 19/79] add a hooks folder containing each hook static data --- packages/core/uniswap-hooks/hardhat.config.js | 3 +- .../core/uniswap-hooks/src/generate/hooks.ts | 12 +- packages/core/uniswap-hooks/src/hooks.test.ts | 4 +- packages/core/uniswap-hooks/src/hooks.ts | 153 +++++++----------- .../src/hooks/AntiSandwichHook.ts | 14 ++ .../uniswap-hooks/src/hooks/BaseAsyncSwap.ts | 15 ++ .../src/hooks/BaseCustomAccounting.ts | 15 ++ .../src/hooks/BaseCustomCurve.ts | 15 ++ .../src/hooks/BaseDynamicAfterFee.ts | 15 ++ .../uniswap-hooks/src/hooks/BaseDynamicFee.ts | 15 ++ .../core/uniswap-hooks/src/hooks/BaseHook.ts | 137 ++++++++++++++++ .../src/hooks/BaseOverrideFee.ts | 14 ++ .../uniswap-hooks/src/hooks/LimitOrderHook.ts | 15 ++ .../src/hooks/LiquidityPenaltyHook.ts | 15 ++ .../core/uniswap-hooks/src/hooks/index.ts | 48 ++++++ packages/core/uniswap-hooks/src/index.ts | 5 +- 16 files changed, 388 insertions(+), 107 deletions(-) create mode 100644 packages/core/uniswap-hooks/src/hooks/AntiSandwichHook.ts create mode 100644 packages/core/uniswap-hooks/src/hooks/BaseAsyncSwap.ts create mode 100644 packages/core/uniswap-hooks/src/hooks/BaseCustomAccounting.ts create mode 100644 packages/core/uniswap-hooks/src/hooks/BaseCustomCurve.ts create mode 100644 packages/core/uniswap-hooks/src/hooks/BaseDynamicAfterFee.ts create mode 100644 packages/core/uniswap-hooks/src/hooks/BaseDynamicFee.ts create mode 100644 packages/core/uniswap-hooks/src/hooks/BaseHook.ts create mode 100644 packages/core/uniswap-hooks/src/hooks/BaseOverrideFee.ts create mode 100644 packages/core/uniswap-hooks/src/hooks/LimitOrderHook.ts create mode 100644 packages/core/uniswap-hooks/src/hooks/LiquidityPenaltyHook.ts create mode 100644 packages/core/uniswap-hooks/src/hooks/index.ts diff --git a/packages/core/uniswap-hooks/hardhat.config.js b/packages/core/uniswap-hooks/hardhat.config.js index aabd35a98..e456ab1e1 100644 --- a/packages/core/uniswap-hooks/hardhat.config.js +++ b/packages/core/uniswap-hooks/hardhat.config.js @@ -14,7 +14,8 @@ const SOLIDITY_VERSION = require('./src/.solidity-version.json'); // Keep parity with solidity package: treat warnings as errors except these codes. const WARN_UNUSED_PARAMETER = '5667'; const WARN_CODE_SIZE = '5574'; -const IGNORED_WARNINGS = [WARN_UNUSED_PARAMETER, WARN_CODE_SIZE]; +const WARN_TRANSIENT_STORAGE = '2394'; +const IGNORED_WARNINGS = [WARN_UNUSED_PARAMETER, WARN_CODE_SIZE, WARN_TRANSIENT_STORAGE]; // Overriding this task so that warnings are considered errors. task(TASK_COMPILE_SOLIDITY_CHECK_ERRORS, async ({ output, quiet }, { run }) => { diff --git a/packages/core/uniswap-hooks/src/generate/hooks.ts b/packages/core/uniswap-hooks/src/generate/hooks.ts index 4eb17e5ab..7342ef4b2 100644 --- a/packages/core/uniswap-hooks/src/generate/hooks.ts +++ b/packages/core/uniswap-hooks/src/generate/hooks.ts @@ -1,5 +1,5 @@ -import type { HookName, HooksOptions } from '../hooks'; -import { Hooks } from '../hooks'; +import type { HooksOptions } from '../hooks'; +import { Hooks, type HookName } from '../hooks/index'; import { accessOptions } from '@openzeppelin/wizard/src/set-access-control'; import { infoOptions } from '@openzeppelin/wizard/src/set-info'; import { generateAlternatives } from '@openzeppelin/wizard/src/generate/alternatives'; @@ -12,7 +12,9 @@ const sharesOptions = [ { options: 'ERC6909', name: 'MyShares', symbol: 'MSH' }, ] as const; -const hooksOptions: HookName[] = Hooks.map(hook => hook.name); +// Enable one by one until fixing all overrides +// const hooksOptions: HookName[] = Hooks.map(hook => hook.name); +const hooksOptions: HookName[] = ['BaseHook']; const blueprint = { hook: hooksOptions as readonly HookName[], @@ -21,7 +23,9 @@ const blueprint = { currencySettler: booleanOptions, safeCast: booleanOptions, transientStorage: booleanOptions, - access: accessOptions, + // re-enable access control + // access: accessOptions, + access: [false] as const, // Hooks are not upgradeable yet; fix to false upgradeable: [false] as const, info: infoOptions, diff --git a/packages/core/uniswap-hooks/src/hooks.test.ts b/packages/core/uniswap-hooks/src/hooks.test.ts index ac7993eca..3e4bd6bb9 100644 --- a/packages/core/uniswap-hooks/src/hooks.test.ts +++ b/packages/core/uniswap-hooks/src/hooks.test.ts @@ -2,8 +2,8 @@ import test from 'ava'; // import type { OptionsError } from '@openzeppelin/wizard/src/error'; import { hooks } from './api'; -import type { HooksOptions } from './hooks'; -import { buildHooks, Hooks } from './hooks'; +import { buildHooks, type HooksOptions } from './hooks'; +import { Hooks } from './hooks/'; import { printContract } from '@openzeppelin/wizard/src/print'; import { compatibleContractsSemver } from './utils/version'; diff --git a/packages/core/uniswap-hooks/src/hooks.ts b/packages/core/uniswap-hooks/src/hooks.ts index c4f747cc8..0cc2a83d5 100644 --- a/packages/core/uniswap-hooks/src/hooks.ts +++ b/packages/core/uniswap-hooks/src/hooks.ts @@ -5,104 +5,11 @@ import { withCommonDefaults, defaults as commonDefaults } from '@openzeppelin/wi import { setInfo } from '@openzeppelin/wizard/src/set-info'; import { setAccessControl } from '@openzeppelin/wizard/src/set-access-control'; import { addPausable } from '@openzeppelin/wizard/src/add-pausable'; -import { printContract } from '@openzeppelin/wizard/src/print'; -import { compatibleContractsSemver } from './utils/version'; +import { printContract } from '@openzeppelin/wizard/'; import type { Value } from '@openzeppelin/wizard/src/contract'; - -export type HookCategory = 'Base' | 'Fee' | 'General'; -export type HookName = - | 'BaseHook' - | 'BaseAsyncSwap' - | 'BaseCustomAccounting' - | 'BaseCustomCurve' - | 'BaseDynamicFee' - | 'BaseOverrideFee' - | 'BaseDynamicAfterFee' - | 'BaseHookFee' - | 'AntiSandwichHook' - | 'LimitOrderHook' - | 'LiquidityPenaltyHook'; -export type Hook = { - name: HookName; - category: HookCategory; - tooltipText: string; - tooltipLink: string; -}; - -export const Hooks: Hook[] = [ - // Base - { - name: 'BaseHook', - category: 'Base', - tooltipText: - 'Base hook implementation providing standard entry points, permission checks, and validation utilities for building hooks.', - tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/base#BaseHook', - }, - { - name: 'BaseAsyncSwap', - category: 'Base', - tooltipText: - 'Base implementation for asynchronous swaps that bypasses the default swap flow by netting the specified amount to zero, enabling custom execution and settlement.', - tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/base#BaseAsyncSwap', - }, - { - name: 'BaseCustomAccounting', - tooltipText: - 'Base for custom accounting and hook-owned liquidity; implement how liquidity changes are computed and how liquidiy positions shares are minted/burned. Intended for a single pool key per instance.', - tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/base#BaseCustomAccounting', - category: 'Base', - }, - { - name: 'BaseCustomCurve', - tooltipText: - 'Base for custom swap curves overriding default pricing; define the unspecified amount during swaps. Builds on the custom accounting base.', - tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/base#BaseCustomCurve', - category: 'Base', - }, - // Fee - { - name: 'BaseDynamicFee', - tooltipText: - 'Applies a dynamic LP fee via the PoolManager; lets you update the fee over time based on your own logic.', - tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/fee#BaseDynamicFee', - category: 'Fee', - }, - { - name: 'BaseOverrideFee', - tooltipText: - 'Automatically sets a dynamic fee before each swap, computed per trade according to your fee function.', - tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/fee#BaseOverrideFee', - category: 'Fee', - }, - { - name: 'BaseDynamicAfterFee', - tooltipText: - 'Enforces a post-swap target and captures any positive difference as a hook fee, then lets you handle or distribute it.', - tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/fee#BaseDynamicAfterFee', - category: 'Fee', - }, - // General - { - name: 'AntiSandwichHook', - tooltipText: 'Anchors swap pricing to the beginning-of-block state to deter intra-block sandwich manipulation.', - tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/general#AntiSandwichHook', - category: 'General', - }, - { - name: 'LimitOrderHook', - tooltipText: - 'Out‑of‑range limit orders that execute on tick cross; adds one currency, accrue fees to the order, and support cancel/withdraw.', - tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/general#LimitOrderHook', - category: 'General', - }, - { - name: 'LiquidityPenaltyHook', - tooltipText: - 'JIT‑resistant: withholds and penalizes LP fees when liquidity is added then removed within a block window; penalties are donated to in‑range LPs.', - tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/general#LiquidityPenaltyHook', - category: 'General', - }, -]; +import { compatibleContractsSemver } from './utils/version'; +import { Hooks, type HookName } from './hooks/'; +import { BaseHook } from './hooks/BaseHook'; export const sharesOptions = [false, 'ERC20', 'ERC6909', 'ERC1155'] as const; export type Shares = { @@ -138,7 +45,41 @@ export const defaults: Required = { symbol: 'MSH', uri: '', }, -} as const; +}; + +type Permissions = { + beforeInitialize: boolean; + afterInitialize: boolean; + beforeAddLiquidity: boolean; + beforeRemoveLiquidity: boolean; + afterAddLiquidity: boolean; + afterRemoveLiquidity: boolean; + beforeSwap: boolean; + afterSwap: boolean; + beforeDonate: boolean; + afterDonate: boolean; + beforeSwapReturnDelta: boolean; + afterSwapReturnDelta: boolean; + afterAddLiquidityReturnDelta: boolean; + afterRemoveLiquidityReturnDelta: boolean; +}; + +const defaultPermissions: Permissions = { + beforeInitialize: false, + afterInitialize: false, + beforeAddLiquidity: false, + beforeRemoveLiquidity: false, + afterAddLiquidity: false, + afterRemoveLiquidity: false, + beforeSwap: false, + afterSwap: false, + beforeDonate: false, + afterDonate: false, + beforeSwapReturnDelta: false, + afterSwapReturnDelta: false, + afterAddLiquidityReturnDelta: false, + afterRemoveLiquidityReturnDelta: false, +}; function withDefaults(opts: HooksOptions): Required { return { @@ -213,11 +154,18 @@ function addHook(c: ContractBuilder, allOpts: HooksOptions) { }); c.addConstructorArgument({ type: 'IPoolManager', name: '_poolManager' }); + c.addImportOnly({ + name: 'Hooks', + path: `@uniswap/v4-core/src/libraries/Hooks.sol`, + }); + const params: Value[] = []; params.push({ lit: '_poolManager' }); switch (allOpts.hook) { case 'BaseHook': + addDefaultHookPermissions(c, allOpts); + break; case 'BaseAsyncSwap': case 'BaseCustomAccounting': case 'BaseCustomCurve': @@ -316,3 +264,12 @@ function addERC6909Shares(c: ContractBuilder, _allOpts: HooksOptions) { [], ); } + +function addDefaultHookPermissions(c: ContractBuilder, _allOpts: HooksOptions) { + const entries = Object.entries(defaultPermissions); + const permissionLines = entries.map( + ([key, value], idx) => ` ${key}: ${value}${idx === entries.length - 1 ? '' : ','}`, + ); + c.addOverride({ name: 'BaseHook' }, BaseHook.functions.getHookPermissions!); + c.setFunctionBody(['return Hooks.Permissions({', ...permissionLines, '});'], BaseHook.functions.getHookPermissions!); +} diff --git a/packages/core/uniswap-hooks/src/hooks/AntiSandwichHook.ts b/packages/core/uniswap-hooks/src/hooks/AntiSandwichHook.ts new file mode 100644 index 000000000..d2daed116 --- /dev/null +++ b/packages/core/uniswap-hooks/src/hooks/AntiSandwichHook.ts @@ -0,0 +1,14 @@ +import type { Hook } from './index'; +import { defineFunctions } from '@openzeppelin/wizard/src/utils/define-functions'; + +const AntiSandwichHook: Hook = { + name: 'AntiSandwichHook', + category: 'General', + tooltipText: 'Anchors swap pricing to the beginning-of-block state to deter intra-block sandwich manipulation.', + tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/general#AntiSandwichHook', + functions: { + ...defineFunctions({}), + }, +}; + +export { AntiSandwichHook }; diff --git a/packages/core/uniswap-hooks/src/hooks/BaseAsyncSwap.ts b/packages/core/uniswap-hooks/src/hooks/BaseAsyncSwap.ts new file mode 100644 index 000000000..e841045de --- /dev/null +++ b/packages/core/uniswap-hooks/src/hooks/BaseAsyncSwap.ts @@ -0,0 +1,15 @@ +import type { Hook } from './index'; +import { defineFunctions } from '@openzeppelin/wizard/src/utils/define-functions'; + +const BaseAsyncSwap: Hook = { + name: 'BaseAsyncSwap', + category: 'Base', + tooltipText: + 'Base implementation for asynchronous swaps that bypasses the default swap flow by netting the specified amount to zero, enabling custom execution and settlement.', + tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/base#BaseAsyncSwap', + functions: { + ...defineFunctions({}), + }, +}; + +export { BaseAsyncSwap }; diff --git a/packages/core/uniswap-hooks/src/hooks/BaseCustomAccounting.ts b/packages/core/uniswap-hooks/src/hooks/BaseCustomAccounting.ts new file mode 100644 index 000000000..23850f8fd --- /dev/null +++ b/packages/core/uniswap-hooks/src/hooks/BaseCustomAccounting.ts @@ -0,0 +1,15 @@ +import type { Hook } from './index'; +import { defineFunctions } from '@openzeppelin/wizard/src/utils/define-functions'; + +const BaseCustomAccounting: Hook = { + name: 'BaseCustomAccounting', + category: 'Base', + tooltipText: + 'Base for custom accounting and hook-owned liquidity; implement how liquidity changes are computed and how liquidiy positions shares are minted/burned. Intended for a single pool key per instance.', + tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/base#BaseCustomAccounting', + functions: { + ...defineFunctions({}), + }, +}; + +export { BaseCustomAccounting }; diff --git a/packages/core/uniswap-hooks/src/hooks/BaseCustomCurve.ts b/packages/core/uniswap-hooks/src/hooks/BaseCustomCurve.ts new file mode 100644 index 000000000..b1ad00502 --- /dev/null +++ b/packages/core/uniswap-hooks/src/hooks/BaseCustomCurve.ts @@ -0,0 +1,15 @@ +import type { Hook } from './index'; +import { defineFunctions } from '@openzeppelin/wizard/src/utils/define-functions'; + +const BaseCustomCurve: Hook = { + name: 'BaseCustomCurve', + category: 'Base', + tooltipText: + 'Base for custom swap curves overriding default pricing; define the unspecified amount during swaps. Builds on the custom accounting base.', + tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/base#BaseCustomCurve', + functions: { + ...defineFunctions({}), + }, +}; + +export { BaseCustomCurve }; diff --git a/packages/core/uniswap-hooks/src/hooks/BaseDynamicAfterFee.ts b/packages/core/uniswap-hooks/src/hooks/BaseDynamicAfterFee.ts new file mode 100644 index 000000000..29f558b35 --- /dev/null +++ b/packages/core/uniswap-hooks/src/hooks/BaseDynamicAfterFee.ts @@ -0,0 +1,15 @@ +import type { Hook } from './index'; +import { defineFunctions } from '@openzeppelin/wizard/src/utils/define-functions'; + +const BaseDynamicAfterFee: Hook = { + name: 'BaseDynamicAfterFee', + category: 'Fee', + tooltipText: + 'Enforces a post-swap target and captures any positive difference as a hook fee, then lets you handle or distribute it.', + tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/fee#BaseDynamicAfterFee', + functions: { + ...defineFunctions({}), + }, +}; + +export { BaseDynamicAfterFee }; diff --git a/packages/core/uniswap-hooks/src/hooks/BaseDynamicFee.ts b/packages/core/uniswap-hooks/src/hooks/BaseDynamicFee.ts new file mode 100644 index 000000000..facafdc3c --- /dev/null +++ b/packages/core/uniswap-hooks/src/hooks/BaseDynamicFee.ts @@ -0,0 +1,15 @@ +import type { Hook } from './index'; +import { defineFunctions } from '@openzeppelin/wizard/src/utils/define-functions'; + +const BaseDynamicFee: Hook = { + name: 'BaseDynamicFee', + category: 'Fee', + tooltipText: + 'Applies a dynamic LP fee via the PoolManager; lets you update the fee over time based on your own logic.', + tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/fee#BaseDynamicFee', + functions: { + ...defineFunctions({}), + }, +}; + +export { BaseDynamicFee }; diff --git a/packages/core/uniswap-hooks/src/hooks/BaseHook.ts b/packages/core/uniswap-hooks/src/hooks/BaseHook.ts new file mode 100644 index 000000000..a4901282e --- /dev/null +++ b/packages/core/uniswap-hooks/src/hooks/BaseHook.ts @@ -0,0 +1,137 @@ +import type { Hook } from './index'; +import { defineFunctions } from '@openzeppelin/wizard/src/utils/define-functions'; + +const BaseHook: Hook = { + name: 'BaseHook', + category: 'Base', + tooltipText: + 'Base hook implementation providing standard entry points, permission checks, and validation utilities for building hooks.', + tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/base#BaseHook', + functions: { + ...defineFunctions({ + // Permissions descriptor that inheritors must implement + getHookPermissions: { + kind: 'public', + mutability: 'pure', + args: [], + returns: ['Hooks.Permissions memory'], + }, + + // Initialize + _beforeInitialize: { + kind: 'internal', + args: [ + { name: 'sender', type: 'address' }, + { name: 'key', type: 'PoolKey calldata' }, + { name: 'sqrtPriceX96', type: 'uint160' }, + ], + returns: ['bytes4'], + }, + _afterInitialize: { + kind: 'internal', + args: [ + { name: 'sender', type: 'address' }, + { name: 'key', type: 'PoolKey calldata' }, + { name: 'sqrtPriceX96', type: 'uint160' }, + { name: 'tick', type: 'int24' }, + ], + returns: ['bytes4'], + }, + + // Liquidity add/remove + _beforeAddLiquidity: { + kind: 'internal', + args: [ + { name: 'sender', type: 'address' }, + { name: 'key', type: 'PoolKey calldata' }, + { name: 'params', type: 'ModifyLiquidityParams calldata' }, + { name: 'hookData', type: 'bytes calldata' }, + ], + returns: ['bytes4'], + }, + _afterAddLiquidity: { + kind: 'internal', + args: [ + { name: 'sender', type: 'address' }, + { name: 'key', type: 'PoolKey calldata' }, + { name: 'params', type: 'ModifyLiquidityParams calldata' }, + { name: 'delta0', type: 'BalanceDelta' }, + { name: 'delta1', type: 'BalanceDelta' }, + { name: 'hookData', type: 'bytes calldata' }, + ], + returns: ['bytes4', 'BalanceDelta'], + }, + _beforeRemoveLiquidity: { + kind: 'internal', + args: [ + { name: 'sender', type: 'address' }, + { name: 'key', type: 'PoolKey calldata' }, + { name: 'params', type: 'ModifyLiquidityParams calldata' }, + { name: 'hookData', type: 'bytes calldata' }, + ], + returns: ['bytes4'], + }, + _afterRemoveLiquidity: { + kind: 'internal', + args: [ + { name: 'sender', type: 'address' }, + { name: 'key', type: 'PoolKey calldata' }, + { name: 'params', type: 'ModifyLiquidityParams calldata' }, + { name: 'delta0', type: 'BalanceDelta' }, + { name: 'delta1', type: 'BalanceDelta' }, + { name: 'hookData', type: 'bytes calldata' }, + ], + returns: ['bytes4', 'BalanceDelta'], + }, + + // Swap + _beforeSwap: { + kind: 'internal', + args: [ + { name: 'sender', type: 'address' }, + { name: 'key', type: 'PoolKey calldata' }, + { name: 'params', type: 'SwapParams calldata' }, + { name: 'hookData', type: 'bytes calldata' }, + ], + returns: ['bytes4', 'BeforeSwapDelta', 'uint24'], + }, + _afterSwap: { + kind: 'internal', + args: [ + { name: 'sender', type: 'address' }, + { name: 'key', type: 'PoolKey calldata' }, + { name: 'params', type: 'SwapParams calldata' }, + { name: 'delta', type: 'BalanceDelta' }, + { name: 'hookData', type: 'bytes calldata' }, + ], + returns: ['bytes4', 'int128'], + }, + + // Donate + _beforeDonate: { + kind: 'internal', + args: [ + { name: 'sender', type: 'address' }, + { name: 'key', type: 'PoolKey calldata' }, + { name: 'amount0', type: 'uint256' }, + { name: 'amount1', type: 'uint256' }, + { name: 'hookData', type: 'bytes calldata' }, + ], + returns: ['bytes4'], + }, + _afterDonate: { + kind: 'internal', + args: [ + { name: 'sender', type: 'address' }, + { name: 'key', type: 'PoolKey calldata' }, + { name: 'amount0', type: 'uint256' }, + { name: 'amount1', type: 'uint256' }, + { name: 'hookData', type: 'bytes calldata' }, + ], + returns: ['bytes4'], + }, + }), + }, +}; + +export { BaseHook }; diff --git a/packages/core/uniswap-hooks/src/hooks/BaseOverrideFee.ts b/packages/core/uniswap-hooks/src/hooks/BaseOverrideFee.ts new file mode 100644 index 000000000..25ec0f738 --- /dev/null +++ b/packages/core/uniswap-hooks/src/hooks/BaseOverrideFee.ts @@ -0,0 +1,14 @@ +import type { Hook } from './index'; +import { defineFunctions } from '@openzeppelin/wizard/src/utils/define-functions'; + +const BaseOverrideFee: Hook = { + name: 'BaseOverrideFee', + category: 'Fee', + tooltipText: 'Automatically sets a dynamic fee before each swap, computed per trade according to your fee function.', + tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/fee#BaseOverrideFee', + functions: { + ...defineFunctions({}), + }, +}; + +export { BaseOverrideFee }; diff --git a/packages/core/uniswap-hooks/src/hooks/LimitOrderHook.ts b/packages/core/uniswap-hooks/src/hooks/LimitOrderHook.ts new file mode 100644 index 000000000..fc403d705 --- /dev/null +++ b/packages/core/uniswap-hooks/src/hooks/LimitOrderHook.ts @@ -0,0 +1,15 @@ +import type { Hook } from './index'; +import { defineFunctions } from '@openzeppelin/wizard/src/utils/define-functions'; + +const LimitOrderHook: Hook = { + name: 'LimitOrderHook', + category: 'General', + tooltipText: + 'Out‑of‑range limit orders that execute on tick cross; adds one currency, accrue fees to the order, and support cancel/withdraw.', + tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/general#LimitOrderHook', + functions: { + ...defineFunctions({}), + }, +}; + +export { LimitOrderHook }; diff --git a/packages/core/uniswap-hooks/src/hooks/LiquidityPenaltyHook.ts b/packages/core/uniswap-hooks/src/hooks/LiquidityPenaltyHook.ts new file mode 100644 index 000000000..7e976c8f1 --- /dev/null +++ b/packages/core/uniswap-hooks/src/hooks/LiquidityPenaltyHook.ts @@ -0,0 +1,15 @@ +import type { Hook } from './index'; +import { defineFunctions } from '@openzeppelin/wizard/src/utils/define-functions'; + +const LiquidityPenaltyHook: Hook = { + name: 'LiquidityPenaltyHook', + category: 'General', + tooltipText: + 'JIT‑resistant: withholds and penalizes LP fees when liquidity is added then removed within a block window; penalties are donated to in‑range LPs.', + tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/general#LiquidityPenaltyHook', + functions: { + ...defineFunctions({}), + }, +}; + +export { LiquidityPenaltyHook }; diff --git a/packages/core/uniswap-hooks/src/hooks/index.ts b/packages/core/uniswap-hooks/src/hooks/index.ts new file mode 100644 index 000000000..c6ea1cd4e --- /dev/null +++ b/packages/core/uniswap-hooks/src/hooks/index.ts @@ -0,0 +1,48 @@ +import type { BaseFunction } from '@openzeppelin/wizard/src/contract'; + +import { BaseHook } from './BaseHook'; +import { BaseAsyncSwap } from './BaseAsyncSwap'; +import { BaseCustomAccounting } from './BaseCustomAccounting'; +import { BaseCustomCurve } from './BaseCustomCurve'; +import { BaseDynamicFee } from './BaseDynamicFee'; +import { BaseOverrideFee } from './BaseOverrideFee'; +import { BaseDynamicAfterFee } from './BaseDynamicAfterFee'; +import { AntiSandwichHook } from './AntiSandwichHook'; +import { LimitOrderHook } from './LimitOrderHook'; +import { LiquidityPenaltyHook } from './LiquidityPenaltyHook'; + +export type HookCategory = 'Base' | 'Fee' | 'General'; + +export type HookName = + | 'BaseHook' + | 'BaseAsyncSwap' + | 'BaseCustomAccounting' + | 'BaseCustomCurve' + | 'BaseDynamicFee' + | 'BaseOverrideFee' + | 'BaseDynamicAfterFee' + | 'BaseHookFee' + | 'AntiSandwichHook' + | 'LimitOrderHook' + | 'LiquidityPenaltyHook'; + +export type Hook = { + name: HookName; + category: HookCategory; + functions: Record; + tooltipText: string; + tooltipLink: string; +}; + +export const Hooks: Hook[] = [ + BaseHook, + BaseAsyncSwap, + BaseCustomAccounting, + BaseCustomCurve, + BaseDynamicFee, + BaseOverrideFee, + BaseDynamicAfterFee, + AntiSandwichHook, + LimitOrderHook, + LiquidityPenaltyHook, +]; diff --git a/packages/core/uniswap-hooks/src/index.ts b/packages/core/uniswap-hooks/src/index.ts index 1263948b8..5d1b599ca 100644 --- a/packages/core/uniswap-hooks/src/index.ts +++ b/packages/core/uniswap-hooks/src/index.ts @@ -4,7 +4,8 @@ export { sanitizeKind, type Kind } from './kind'; export { hooks } from './api'; -export { Hooks } from './hooks'; -export type { Hook, HookName, HooksOptions, HookCategory, Shares } from './hooks'; +export { Hooks, type Hook, type HookName, type HookCategory } from './hooks/'; + +export { type HooksOptions, type Shares } from './hooks'; export { compatibleContractsSemver } from './utils/version'; From d1b7b5183024ba67c5c24cb569bc7867d652c6e9 Mon Sep 17 00:00:00 2001 From: Gonzalo Othacehe Date: Tue, 19 Aug 2025 17:34:45 -0300 Subject: [PATCH 20/79] fix BaseHook compilation --- packages/core/uniswap-hooks/src/generate/hooks.ts | 4 +--- packages/core/uniswap-hooks/src/hooks.ts | 4 ++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/core/uniswap-hooks/src/generate/hooks.ts b/packages/core/uniswap-hooks/src/generate/hooks.ts index 7342ef4b2..85faa890f 100644 --- a/packages/core/uniswap-hooks/src/generate/hooks.ts +++ b/packages/core/uniswap-hooks/src/generate/hooks.ts @@ -23,9 +23,7 @@ const blueprint = { currencySettler: booleanOptions, safeCast: booleanOptions, transientStorage: booleanOptions, - // re-enable access control - // access: accessOptions, - access: [false] as const, + access: accessOptions, // Hooks are not upgradeable yet; fix to false upgradeable: [false] as const, info: infoOptions, diff --git a/packages/core/uniswap-hooks/src/hooks.ts b/packages/core/uniswap-hooks/src/hooks.ts index 0cc2a83d5..77504edf4 100644 --- a/packages/core/uniswap-hooks/src/hooks.ts +++ b/packages/core/uniswap-hooks/src/hooks.ts @@ -7,6 +7,8 @@ import { setAccessControl } from '@openzeppelin/wizard/src/set-access-control'; import { addPausable } from '@openzeppelin/wizard/src/add-pausable'; import { printContract } from '@openzeppelin/wizard/'; import type { Value } from '@openzeppelin/wizard/src/contract'; +import { supportsInterface } from '@openzeppelin/wizard/src/common-functions'; + import { compatibleContractsSemver } from './utils/version'; import { Hooks, type HookName } from './hooks/'; import { BaseHook } from './hooks/BaseHook'; @@ -253,6 +255,7 @@ function addERC1155Shares(c: ContractBuilder, _allOpts: HooksOptions) { }, [_allOpts.shares.uri || ''], ); + c.addOverride({ name: 'ERC1155' }, supportsInterface); } function addERC6909Shares(c: ContractBuilder, _allOpts: HooksOptions) { @@ -263,6 +266,7 @@ function addERC6909Shares(c: ContractBuilder, _allOpts: HooksOptions) { }, [], ); + c.addOverride({ name: 'ERC6909' }, supportsInterface); } function addDefaultHookPermissions(c: ContractBuilder, _allOpts: HooksOptions) { From c061c4fc129d0ee7e31a2b2b04d103ede573311d Mon Sep 17 00:00:00 2001 From: Gonzalo Othacehe Date: Tue, 19 Aug 2025 19:37:17 -0300 Subject: [PATCH 21/79] add base hook function overrides --- .../core/uniswap-hooks/src/generate/hooks.ts | 8 +- packages/core/uniswap-hooks/src/hooks.test.ts | 3 +- packages/core/uniswap-hooks/src/hooks.ts | 99 +++++++++++++------ .../src/hooks/BaseCustomAccounting.ts | 39 +++++++- .../src/hooks/BaseCustomCurve.ts | 33 ++++++- .../core/uniswap-hooks/src/hooks/index.ts | 7 +- .../ui/src/uniswap-hooks/HooksControls.svelte | 15 ++- 7 files changed, 166 insertions(+), 38 deletions(-) diff --git a/packages/core/uniswap-hooks/src/generate/hooks.ts b/packages/core/uniswap-hooks/src/generate/hooks.ts index 85faa890f..0228b4ed1 100644 --- a/packages/core/uniswap-hooks/src/generate/hooks.ts +++ b/packages/core/uniswap-hooks/src/generate/hooks.ts @@ -14,7 +14,13 @@ const sharesOptions = [ // Enable one by one until fixing all overrides // const hooksOptions: HookName[] = Hooks.map(hook => hook.name); -const hooksOptions: HookName[] = ['BaseHook']; +const hooksOptions: HookName[] = [ + // 'BaseHook', + // 'BaseAsyncSwap', + // 'BaseCustomAccounting', + // 'BaseCustomCurve', + 'BaseDynamicFee', +]; const blueprint = { hook: hooksOptions as readonly HookName[], diff --git a/packages/core/uniswap-hooks/src/hooks.test.ts b/packages/core/uniswap-hooks/src/hooks.test.ts index 3e4bd6bb9..a8e91ef04 100644 --- a/packages/core/uniswap-hooks/src/hooks.test.ts +++ b/packages/core/uniswap-hooks/src/hooks.test.ts @@ -18,7 +18,8 @@ function testHooks(title: string, opts: Partial) { } // test all hooks -for (const hook of Hooks) { +for (const key in Hooks) { + const hook = Hooks[key as keyof typeof Hooks]; testHooks(`basic ${hook.name}`, { hook: hook.name }); } diff --git a/packages/core/uniswap-hooks/src/hooks.ts b/packages/core/uniswap-hooks/src/hooks.ts index 77504edf4..de6caa1cf 100644 --- a/packages/core/uniswap-hooks/src/hooks.ts +++ b/packages/core/uniswap-hooks/src/hooks.ts @@ -11,7 +11,6 @@ import { supportsInterface } from '@openzeppelin/wizard/src/common-functions'; import { compatibleContractsSemver } from './utils/version'; import { Hooks, type HookName } from './hooks/'; -import { BaseHook } from './hooks/BaseHook'; export const sharesOptions = [false, 'ERC20', 'ERC6909', 'ERC1155'] as const; export type Shares = { @@ -150,50 +149,91 @@ export function buildHooks(opts: HooksOptions): Contract { } function addHook(c: ContractBuilder, allOpts: HooksOptions) { + // Add required Hook imports c.addImportOnly({ name: 'IPoolManager', path: `@uniswap/v4-core/src/interfaces/IPoolManager.sol`, }); - c.addConstructorArgument({ type: 'IPoolManager', name: '_poolManager' }); - c.addImportOnly({ name: 'Hooks', path: `@uniswap/v4-core/src/libraries/Hooks.sol`, }); - const params: Value[] = []; - params.push({ lit: '_poolManager' }); + c.addConstructorArgument({ type: 'IPoolManager', name: '_poolManager' }); + + // Add Constructor Params (default) + const constructorParams: Value[] = []; + constructorParams.push({ lit: '_poolManager' }); + // Add Constructor Params specific to the hook switch (allOpts.hook) { - case 'BaseHook': - addDefaultHookPermissions(c, allOpts); - break; - case 'BaseAsyncSwap': - case 'BaseCustomAccounting': - case 'BaseCustomCurve': - case 'BaseDynamicFee': - case 'BaseOverrideFee': - case 'BaseDynamicAfterFee': - case 'BaseHookFee': - case 'AntiSandwichHook': - case 'LimitOrderHook': - break; case 'LiquidityPenaltyHook': c.addConstructorArgument({ type: 'uint48', name: '_blockNumberOffset' }); - params.push({ lit: '_blockNumberOffset' }); + constructorParams.push({ lit: '_blockNumberOffset' }); break; default: - throw new Error(`Unknown hook: ${allOpts.hook}`); + break; } - const hookCategory = Hooks.find(hook => hook.name === allOpts.hook)!.category; + // Add Parent (Hook) + c.addParent( + { + name: allOpts.hook, + path: `@openzeppelin/uniswap-hooks/${Hooks[allOpts.hook].category.toLowerCase()}/${allOpts.hook}.sol`, + }, + constructorParams, + ); - const hook = { - name: allOpts.hook, - path: `@openzeppelin/uniswap-hooks/${hookCategory.toLowerCase()}/${allOpts.hook}.sol`, - }; + // Add Overrides + switch (allOpts.hook) { + case 'BaseCustomAccounting': + c.addOverride({ name: 'BaseCustomAccounting' }, Hooks.BaseCustomAccounting.functions._getAddLiquidity!); + c.setFunctionBody([`// Override _getAddLiquidity`], Hooks.BaseCustomAccounting.functions._getAddLiquidity!); + c.addOverride({ name: 'BaseCustomAccounting' }, Hooks.BaseCustomAccounting.functions._getRemoveLiquidity!); + c.setFunctionBody([`// Override _getRemoveLiquidity`], Hooks.BaseCustomAccounting.functions._getRemoveLiquidity!); + c.addOverride({ name: 'BaseCustomAccounting' }, Hooks.BaseCustomAccounting.functions._mint!); + c.setFunctionBody([`// Override _mint`], Hooks.BaseCustomAccounting.functions._mint!); + c.addOverride({ name: 'BaseCustomAccounting' }, Hooks.BaseCustomAccounting.functions._burn!); + c.setFunctionBody([`// Override _burn`], Hooks.BaseCustomAccounting.functions._burn!); + c.addImportOnly({ + name: 'BalanceDelta', + path: `@uniswap/v4-core/src/types/BalanceDelta.sol`, + }); + break; + case 'BaseCustomCurve': + c.addOverride({ name: 'BaseCustomCurve' }, Hooks.BaseCustomCurve.functions._getUnspecifiedAmount!); + c.setFunctionBody([`// Override _getUnspecifiedAmount`], Hooks.BaseCustomCurve.functions._getUnspecifiedAmount!); + c.addOverride({ name: 'BaseCustomCurve' }, Hooks.BaseCustomCurve.functions._getSwapFeeAmount!); + c.setFunctionBody([`// Override _getSwapFeeAmount`], Hooks.BaseCustomCurve.functions._getSwapFeeAmount!); + c.addOverride({ name: 'BaseCustomCurve' }, Hooks.BaseCustomCurve.functions._getAmountOut!); + c.setFunctionBody([`// Override _getAmountOut`], Hooks.BaseCustomCurve.functions._getAmountOut!); + c.addOverride({ name: 'BaseCustomCurve' }, Hooks.BaseCustomCurve.functions._getAmountIn!); + c.setFunctionBody([`// Override _getAmountIn`], Hooks.BaseCustomCurve.functions._getAmountIn!); + c.addOverride({ name: 'BaseCustomAccounting' }, Hooks.BaseCustomAccounting.functions._mint!); + c.setFunctionBody([`// Override _mint`], Hooks.BaseCustomAccounting.functions._mint!); + c.addOverride({ name: 'BaseCustomAccounting' }, Hooks.BaseCustomAccounting.functions._burn!); + c.setFunctionBody([`// Override _burn`], Hooks.BaseCustomAccounting.functions._burn!); + c.addImportOnly({ + name: 'BalanceDelta', + path: `@uniswap/v4-core/src/types/BalanceDelta.sol`, + }); + c.addImportOnly({ + name: 'SwapParams', + path: `@uniswap/v4-core/src/types/PoolOperation.sol`, + }); + break; + default: + break; + } - c.addParent(hook, params); + // Add Hook Permissions + switch (allOpts.hook) { + case 'BaseHook': + addDefaultHookPermissions(c, allOpts); + break; + default: + break; + } } function addCurrencySettler(c: ContractBuilder, _allOpts: HooksOptions) { @@ -274,6 +314,9 @@ function addDefaultHookPermissions(c: ContractBuilder, _allOpts: HooksOptions) { const permissionLines = entries.map( ([key, value], idx) => ` ${key}: ${value}${idx === entries.length - 1 ? '' : ','}`, ); - c.addOverride({ name: 'BaseHook' }, BaseHook.functions.getHookPermissions!); - c.setFunctionBody(['return Hooks.Permissions({', ...permissionLines, '});'], BaseHook.functions.getHookPermissions!); + c.addOverride({ name: 'BaseHook' }, Hooks.BaseHook.functions.getHookPermissions!); + c.setFunctionBody( + ['return Hooks.Permissions({', ...permissionLines, '});'], + Hooks.BaseHook.functions.getHookPermissions!, + ); } diff --git a/packages/core/uniswap-hooks/src/hooks/BaseCustomAccounting.ts b/packages/core/uniswap-hooks/src/hooks/BaseCustomAccounting.ts index 23850f8fd..b70469b32 100644 --- a/packages/core/uniswap-hooks/src/hooks/BaseCustomAccounting.ts +++ b/packages/core/uniswap-hooks/src/hooks/BaseCustomAccounting.ts @@ -8,7 +8,44 @@ const BaseCustomAccounting: Hook = { 'Base for custom accounting and hook-owned liquidity; implement how liquidity changes are computed and how liquidiy positions shares are minted/burned. Intended for a single pool key per instance.', tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/base#BaseCustomAccounting', functions: { - ...defineFunctions({}), + ...defineFunctions({ + // Liquidity modification (required) + _getAddLiquidity: { + kind: 'internal', + args: [ + { name: 'sqrtPriceX96', type: 'uint160' }, + { name: 'params', type: 'AddLiquidityParams memory' }, + ], + returns: ['bytes memory', 'uint256'], + }, + _getRemoveLiquidity: { + kind: 'internal', + args: [{ name: 'params', type: 'RemoveLiquidityParams memory' }], + returns: ['bytes memory', 'uint256'], + }, + + // Shares accounting (required) + _mint: { + kind: 'internal', + args: [ + { name: 'params', type: 'AddLiquidityParams memory' }, + { name: 'callerDelta', type: 'BalanceDelta' }, + { name: 'feesAccrued', type: 'BalanceDelta' }, + { name: 'shares', type: 'uint256' }, + ], + returns: [], + }, + _burn: { + kind: 'internal', + args: [ + { name: 'params', type: 'RemoveLiquidityParams memory' }, + { name: 'callerDelta', type: 'BalanceDelta' }, + { name: 'feesAccrued', type: 'BalanceDelta' }, + { name: 'shares', type: 'uint256' }, + ], + returns: [], + }, + }), }, }; diff --git a/packages/core/uniswap-hooks/src/hooks/BaseCustomCurve.ts b/packages/core/uniswap-hooks/src/hooks/BaseCustomCurve.ts index b1ad00502..028b48b94 100644 --- a/packages/core/uniswap-hooks/src/hooks/BaseCustomCurve.ts +++ b/packages/core/uniswap-hooks/src/hooks/BaseCustomCurve.ts @@ -8,7 +8,38 @@ const BaseCustomCurve: Hook = { 'Base for custom swap curves overriding default pricing; define the unspecified amount during swaps. Builds on the custom accounting base.', tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/base#BaseCustomCurve', functions: { - ...defineFunctions({}), + ...defineFunctions({ + // Calculate the amount of the unspecified currency taken/settled during swap (required) + _getUnspecifiedAmount: { + kind: 'internal', + args: [{ name: 'params', type: 'SwapParams calldata' }], + returns: ['uint256'], + }, + + // Calculate the total LP fees to be paid for the swap (required) + _getSwapFeeAmount: { + kind: 'internal', + args: [ + { name: 'params', type: 'SwapParams calldata' }, + { name: 'unspecifiedAmount', type: 'uint256' }, + ], + returns: ['uint256'], + }, + + // Amounts used and shares burned on remove liquidity (required) + _getAmountOut: { + kind: 'internal', + args: [{ name: 'params', type: 'RemoveLiquidityParams memory' }], + returns: ['uint256', 'uint256', 'uint256'], + }, + + // Amounts used and shares minted on add liquidity (required) + _getAmountIn: { + kind: 'internal', + args: [{ name: 'params', type: 'AddLiquidityParams memory' }], + returns: ['uint256', 'uint256', 'uint256'], + }, + }), }, }; diff --git a/packages/core/uniswap-hooks/src/hooks/index.ts b/packages/core/uniswap-hooks/src/hooks/index.ts index c6ea1cd4e..2faca999a 100644 --- a/packages/core/uniswap-hooks/src/hooks/index.ts +++ b/packages/core/uniswap-hooks/src/hooks/index.ts @@ -21,7 +21,6 @@ export type HookName = | 'BaseDynamicFee' | 'BaseOverrideFee' | 'BaseDynamicAfterFee' - | 'BaseHookFee' | 'AntiSandwichHook' | 'LimitOrderHook' | 'LiquidityPenaltyHook'; @@ -34,7 +33,9 @@ export type Hook = { tooltipLink: string; }; -export const Hooks: Hook[] = [ +export type HookDictionary = Record; + +export const Hooks: HookDictionary = { BaseHook, BaseAsyncSwap, BaseCustomAccounting, @@ -45,4 +46,4 @@ export const Hooks: Hook[] = [ AntiSandwichHook, LimitOrderHook, LiquidityPenaltyHook, -]; +}; diff --git a/packages/ui/src/uniswap-hooks/HooksControls.svelte b/packages/ui/src/uniswap-hooks/HooksControls.svelte index 88c13ab8f..1a2901387 100644 --- a/packages/ui/src/uniswap-hooks/HooksControls.svelte +++ b/packages/ui/src/uniswap-hooks/HooksControls.svelte @@ -2,8 +2,8 @@ import HelpTooltip from '../common/HelpTooltip.svelte'; import { infoDefaults } from '@openzeppelin/wizard'; - import { hooks, Hooks } from '@openzeppelin/wizard-uniswap-hooks/src'; - import type { HookCategory, Hook, KindedOptions } from '@openzeppelin/wizard-uniswap-hooks/src'; + import { hooks, Hooks} from '@openzeppelin/wizard-uniswap-hooks/src'; + import type { HookCategory, Hook, KindedOptions } from '@openzeppelin/wizard-uniswap-hooks'; import AccessControlSection from './AccessControlSection.svelte'; import InfoSection from './InfoSection.svelte'; @@ -20,7 +20,16 @@ // Keep a stable order and titles const CATEGORY_ORDER: HookCategory[] = ['Base', 'Fee', 'General']; const hooksByCategory: Record = { Base: [], Fee: [], General: [] }; - for (const h of Hooks) hooksByCategory[h.category].push(h); + console.log("HooksDict:", Hooks); + for (const key in Hooks) { + const hook = Hooks[key as keyof typeof Hooks]; + console.log('hook:', hook); + hooksByCategory[hook.category].push(hook); + } + $: console.log("hooksByCategory:", hooksByCategory); + + // Debug: Log opts changes + $: console.log('opts changed:', opts);
From 004965c8d2e74b0f91974d1429412703445d77dc Mon Sep 17 00:00:00 2001 From: Gonzalo Othacehe Date: Wed, 20 Aug 2025 14:49:30 -0300 Subject: [PATCH 22/79] add required overrides --- .../core/uniswap-hooks/src/generate/hooks.ts | 24 +++-- packages/core/uniswap-hooks/src/hooks.ts | 82 ++++++++++++-- .../src/hooks/AntiSandwichHook.ts | 25 ++++- .../uniswap-hooks/src/hooks/BaseAsyncSwap.ts | 4 +- .../src/hooks/BaseCustomAccounting.ts | 1 - .../src/hooks/BaseCustomCurve.ts | 3 - .../src/hooks/BaseDynamicAfterFee.ts | 25 ++++- .../uniswap-hooks/src/hooks/BaseDynamicFee.ts | 14 ++- .../core/uniswap-hooks/src/hooks/BaseHook.ts | 6 +- .../src/hooks/BaseOverrideFee.ts | 14 ++- .../uniswap-hooks/src/hooks/LimitOrderHook.ts | 100 +++++++++++++++++- .../src/hooks/LiquidityPenaltyHook.ts | 88 ++++++++++++++- 12 files changed, 355 insertions(+), 31 deletions(-) diff --git a/packages/core/uniswap-hooks/src/generate/hooks.ts b/packages/core/uniswap-hooks/src/generate/hooks.ts index 0228b4ed1..5081c4220 100644 --- a/packages/core/uniswap-hooks/src/generate/hooks.ts +++ b/packages/core/uniswap-hooks/src/generate/hooks.ts @@ -12,15 +12,21 @@ const sharesOptions = [ { options: 'ERC6909', name: 'MyShares', symbol: 'MSH' }, ] as const; -// Enable one by one until fixing all overrides -// const hooksOptions: HookName[] = Hooks.map(hook => hook.name); -const hooksOptions: HookName[] = [ - // 'BaseHook', - // 'BaseAsyncSwap', - // 'BaseCustomAccounting', - // 'BaseCustomCurve', - 'BaseDynamicFee', -]; +const hooksOptions: HookName[] = Object.keys(Hooks) as HookName[]; + +// @TODO: remove, faster to test compilation one by one. +// const hooksOptions: HookName[] = [ +// 'BaseHook', +// 'BaseAsyncSwap', +// 'BaseCustomAccounting', +// 'BaseCustomCurve', +// 'BaseDynamicAfterFee', +// 'BaseDynamicFee', +// 'BaseOverrideFee', +// 'AntiSandwichHook', +// 'LiquidityPenaltyHook', +// 'LimitOrderHook', +// ]; const blueprint = { hook: hooksOptions as readonly HookName[], diff --git a/packages/core/uniswap-hooks/src/hooks.ts b/packages/core/uniswap-hooks/src/hooks.ts index de6caa1cf..4d9a70255 100644 --- a/packages/core/uniswap-hooks/src/hooks.ts +++ b/packages/core/uniswap-hooks/src/hooks.ts @@ -154,18 +154,25 @@ function addHook(c: ContractBuilder, allOpts: HooksOptions) { name: 'IPoolManager', path: `@uniswap/v4-core/src/interfaces/IPoolManager.sol`, }); - c.addImportOnly({ - name: 'Hooks', - path: `@uniswap/v4-core/src/libraries/Hooks.sol`, - }); - c.addConstructorArgument({ type: 'IPoolManager', name: '_poolManager' }); + // @TODO: super calls to BaseHook are broken since it is reverting each internal hook function. + // // If the hook is not BaseHook, inherit from it. + // if (allOpts.hook !== 'BaseHook') { + // c.addParent( + // { + // name: 'BaseHook', + // path: `@openzeppelin/uniswap-hooks/BaseHook.sol`, + // }, + // [], + // ); + // } + // Add Constructor Params (default) const constructorParams: Value[] = []; constructorParams.push({ lit: '_poolManager' }); - // Add Constructor Params specific to the hook + // Add Constructor Params specific to each hook switch (allOpts.hook) { case 'LiquidityPenaltyHook': c.addConstructorArgument({ type: 'uint48', name: '_blockNumberOffset' }); @@ -222,6 +229,65 @@ function addHook(c: ContractBuilder, allOpts: HooksOptions) { path: `@uniswap/v4-core/src/types/PoolOperation.sol`, }); break; + case 'BaseDynamicFee': + c.addOverride({ name: 'BaseDynamicFee' }, Hooks.BaseDynamicFee.functions._getFee!); + c.setFunctionBody([`// Override _getFee`], Hooks.BaseDynamicFee.functions._getFee!); + c.addOverride({ name: 'BaseDynamicFee' }, Hooks.BaseDynamicFee.functions.poke!); + c.setFunctionBody([`// Override poke`], Hooks.BaseDynamicFee.functions.poke!); + c.addImportOnly({ + name: 'PoolKey', + path: `@uniswap/v4-core/src/types/PoolKey.sol`, + }); + break; + case 'BaseDynamicAfterFee': + c.addOverride({ name: 'BaseDynamicAfterFee' }, Hooks.BaseDynamicAfterFee.functions._getTargetUnspecified!); + c.setFunctionBody( + [`// Override _getTargetUnspecified`], + Hooks.BaseDynamicAfterFee.functions._getTargetUnspecified!, + ); + c.addOverride({ name: 'BaseDynamicAfterFee' }, Hooks.BaseDynamicAfterFee.functions._afterSwapHandler!); + c.setFunctionBody([`// Override _afterSwapHandler`], Hooks.BaseDynamicAfterFee.functions._afterSwapHandler!); + c.addImportOnly({ + name: 'PoolKey', + path: `@uniswap/v4-core/src/types/PoolKey.sol`, + }); + c.addImportOnly({ + name: 'SwapParams', + path: `@uniswap/v4-core/src/types/PoolOperation.sol`, + }); + c.addImportOnly({ + name: 'BalanceDelta', + path: `@uniswap/v4-core/src/types/BalanceDelta.sol`, + }); + break; + case 'BaseOverrideFee': + c.addOverride({ name: 'BaseOverrideFee' }, Hooks.BaseOverrideFee.functions._getFee!); + c.setFunctionBody([`// Override _getFee`], Hooks.BaseOverrideFee.functions._getFee!); + c.addImportOnly({ + name: 'PoolKey', + path: `@uniswap/v4-core/src/types/PoolKey.sol`, + }); + c.addImportOnly({ + name: 'SwapParams', + path: `@uniswap/v4-core/src/types/PoolOperation.sol`, + }); + break; + case 'AntiSandwichHook': + c.addOverride({ name: 'AntiSandwichHook' }, Hooks.AntiSandwichHook.functions._afterSwapHandler!); + c.setFunctionBody([`// Override _afterSwapHandler`], Hooks.AntiSandwichHook.functions._afterSwapHandler!); + c.addImportOnly({ + name: 'PoolKey', + path: `@uniswap/v4-core/src/types/PoolKey.sol`, + }); + c.addImportOnly({ + name: 'SwapParams', + path: `@uniswap/v4-core/src/types/PoolOperation.sol`, + }); + c.addImportOnly({ + name: 'BalanceDelta', + path: `@uniswap/v4-core/src/types/BalanceDelta.sol`, + }); + break; default: break; } @@ -230,6 +296,10 @@ function addHook(c: ContractBuilder, allOpts: HooksOptions) { switch (allOpts.hook) { case 'BaseHook': addDefaultHookPermissions(c, allOpts); + c.addImportOnly({ + name: 'Hooks', + path: `@uniswap/v4-core/src/libraries/Hooks.sol`, + }); break; default: break; diff --git a/packages/core/uniswap-hooks/src/hooks/AntiSandwichHook.ts b/packages/core/uniswap-hooks/src/hooks/AntiSandwichHook.ts index d2daed116..0fea507a4 100644 --- a/packages/core/uniswap-hooks/src/hooks/AntiSandwichHook.ts +++ b/packages/core/uniswap-hooks/src/hooks/AntiSandwichHook.ts @@ -7,7 +7,30 @@ const AntiSandwichHook: Hook = { tooltipText: 'Anchors swap pricing to the beginning-of-block state to deter intra-block sandwich manipulation.', tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/general#AntiSandwichHook', functions: { - ...defineFunctions({}), + ...defineFunctions({ + // handle the fee after the swap (required) + _afterSwapHandler: { + kind: 'internal', + args: [ + { name: 'key', type: 'PoolKey calldata' }, + { name: 'params', type: 'SwapParams calldata' }, + { name: 'delta', type: 'BalanceDelta' }, + { name: 'targetUnspecifiedAmount', type: 'uint256' }, + { name: 'feeAmount', type: 'uint256' }, + ], + }, + // determine the target unspecified amount (optional override) + _getTargetUnspecified: { + kind: 'internal', + args: [ + { name: 'sender', type: 'address' }, + { name: 'key', type: 'PoolKey calldata' }, + { name: 'params', type: 'SwapParams calldata' }, + { name: 'hookData', type: 'bytes calldata' }, + ], + returns: ['uint256', 'bool'], + }, + }), }, }; diff --git a/packages/core/uniswap-hooks/src/hooks/BaseAsyncSwap.ts b/packages/core/uniswap-hooks/src/hooks/BaseAsyncSwap.ts index e841045de..923635eb5 100644 --- a/packages/core/uniswap-hooks/src/hooks/BaseAsyncSwap.ts +++ b/packages/core/uniswap-hooks/src/hooks/BaseAsyncSwap.ts @@ -8,7 +8,9 @@ const BaseAsyncSwap: Hook = { 'Base implementation for asynchronous swaps that bypasses the default swap flow by netting the specified amount to zero, enabling custom execution and settlement.', tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/base#BaseAsyncSwap', functions: { - ...defineFunctions({}), + ...defineFunctions({ + // no required overrides. + }), }, }; diff --git a/packages/core/uniswap-hooks/src/hooks/BaseCustomAccounting.ts b/packages/core/uniswap-hooks/src/hooks/BaseCustomAccounting.ts index b70469b32..dd87eb729 100644 --- a/packages/core/uniswap-hooks/src/hooks/BaseCustomAccounting.ts +++ b/packages/core/uniswap-hooks/src/hooks/BaseCustomAccounting.ts @@ -23,7 +23,6 @@ const BaseCustomAccounting: Hook = { args: [{ name: 'params', type: 'RemoveLiquidityParams memory' }], returns: ['bytes memory', 'uint256'], }, - // Shares accounting (required) _mint: { kind: 'internal', diff --git a/packages/core/uniswap-hooks/src/hooks/BaseCustomCurve.ts b/packages/core/uniswap-hooks/src/hooks/BaseCustomCurve.ts index 028b48b94..bd59ea02a 100644 --- a/packages/core/uniswap-hooks/src/hooks/BaseCustomCurve.ts +++ b/packages/core/uniswap-hooks/src/hooks/BaseCustomCurve.ts @@ -15,7 +15,6 @@ const BaseCustomCurve: Hook = { args: [{ name: 'params', type: 'SwapParams calldata' }], returns: ['uint256'], }, - // Calculate the total LP fees to be paid for the swap (required) _getSwapFeeAmount: { kind: 'internal', @@ -25,14 +24,12 @@ const BaseCustomCurve: Hook = { ], returns: ['uint256'], }, - // Amounts used and shares burned on remove liquidity (required) _getAmountOut: { kind: 'internal', args: [{ name: 'params', type: 'RemoveLiquidityParams memory' }], returns: ['uint256', 'uint256', 'uint256'], }, - // Amounts used and shares minted on add liquidity (required) _getAmountIn: { kind: 'internal', diff --git a/packages/core/uniswap-hooks/src/hooks/BaseDynamicAfterFee.ts b/packages/core/uniswap-hooks/src/hooks/BaseDynamicAfterFee.ts index 29f558b35..ab252f28b 100644 --- a/packages/core/uniswap-hooks/src/hooks/BaseDynamicAfterFee.ts +++ b/packages/core/uniswap-hooks/src/hooks/BaseDynamicAfterFee.ts @@ -8,7 +8,30 @@ const BaseDynamicAfterFee: Hook = { 'Enforces a post-swap target and captures any positive difference as a hook fee, then lets you handle or distribute it.', tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/fee#BaseDynamicAfterFee', functions: { - ...defineFunctions({}), + ...defineFunctions({ + // determine the target unspecified amount (required) + _getTargetUnspecified: { + kind: 'internal', + args: [ + { name: 'sender', type: 'address' }, + { name: 'key', type: 'PoolKey calldata' }, + { name: 'params', type: 'SwapParams calldata' }, + { name: 'hookData', type: 'bytes calldata' }, + ], + returns: ['uint256', 'bool'], + }, + // handle the fee after the swap (required) + _afterSwapHandler: { + kind: 'internal', + args: [ + { name: 'key', type: 'PoolKey calldata' }, + { name: 'params', type: 'SwapParams calldata' }, + { name: 'delta', type: 'BalanceDelta' }, + { name: 'targetUnspecifiedAmount', type: 'uint256' }, + { name: 'feeAmount', type: 'uint256' }, + ], + }, + }), }, }; diff --git a/packages/core/uniswap-hooks/src/hooks/BaseDynamicFee.ts b/packages/core/uniswap-hooks/src/hooks/BaseDynamicFee.ts index facafdc3c..94ac0f221 100644 --- a/packages/core/uniswap-hooks/src/hooks/BaseDynamicFee.ts +++ b/packages/core/uniswap-hooks/src/hooks/BaseDynamicFee.ts @@ -8,7 +8,19 @@ const BaseDynamicFee: Hook = { 'Applies a dynamic LP fee via the PoolManager; lets you update the fee over time based on your own logic.', tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/fee#BaseDynamicFee', functions: { - ...defineFunctions({}), + ...defineFunctions({ + // dynamically override the fee (required) + _getFee: { + kind: 'internal', + args: [{ name: 'key', type: 'PoolKey calldata' }], + returns: ['uint24'], + }, + // poke the fee (required) + poke: { + kind: 'public', // external/public for our generator purposes + args: [{ name: 'key', type: 'PoolKey calldata' }], + }, + }), }, }; diff --git a/packages/core/uniswap-hooks/src/hooks/BaseHook.ts b/packages/core/uniswap-hooks/src/hooks/BaseHook.ts index a4901282e..910237a42 100644 --- a/packages/core/uniswap-hooks/src/hooks/BaseHook.ts +++ b/packages/core/uniswap-hooks/src/hooks/BaseHook.ts @@ -9,14 +9,13 @@ const BaseHook: Hook = { tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/base#BaseHook', functions: { ...defineFunctions({ - // Permissions descriptor that inheritors must implement + // Permissions descriptor that inheritors must implement (required) getHookPermissions: { kind: 'public', mutability: 'pure', args: [], returns: ['Hooks.Permissions memory'], }, - // Initialize _beforeInitialize: { kind: 'internal', @@ -37,7 +36,6 @@ const BaseHook: Hook = { ], returns: ['bytes4'], }, - // Liquidity add/remove _beforeAddLiquidity: { kind: 'internal', @@ -83,7 +81,6 @@ const BaseHook: Hook = { ], returns: ['bytes4', 'BalanceDelta'], }, - // Swap _beforeSwap: { kind: 'internal', @@ -106,7 +103,6 @@ const BaseHook: Hook = { ], returns: ['bytes4', 'int128'], }, - // Donate _beforeDonate: { kind: 'internal', diff --git a/packages/core/uniswap-hooks/src/hooks/BaseOverrideFee.ts b/packages/core/uniswap-hooks/src/hooks/BaseOverrideFee.ts index 25ec0f738..bac0e01eb 100644 --- a/packages/core/uniswap-hooks/src/hooks/BaseOverrideFee.ts +++ b/packages/core/uniswap-hooks/src/hooks/BaseOverrideFee.ts @@ -7,7 +7,19 @@ const BaseOverrideFee: Hook = { tooltipText: 'Automatically sets a dynamic fee before each swap, computed per trade according to your fee function.', tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/fee#BaseOverrideFee', functions: { - ...defineFunctions({}), + ...defineFunctions({ + // dynamically override the fee (required) + _getFee: { + kind: 'internal', + args: [ + { name: 'sender', type: 'address' }, + { name: 'key', type: 'PoolKey calldata' }, + { name: 'params', type: 'SwapParams calldata' }, + { name: 'hookData', type: 'bytes calldata' }, + ], + returns: ['uint24'], + }, + }), }, }; diff --git a/packages/core/uniswap-hooks/src/hooks/LimitOrderHook.ts b/packages/core/uniswap-hooks/src/hooks/LimitOrderHook.ts index fc403d705..d0d022048 100644 --- a/packages/core/uniswap-hooks/src/hooks/LimitOrderHook.ts +++ b/packages/core/uniswap-hooks/src/hooks/LimitOrderHook.ts @@ -8,7 +8,105 @@ const LimitOrderHook: Hook = { 'Out‑of‑range limit orders that execute on tick cross; adds one currency, accrue fees to the order, and support cancel/withdraw.', tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/general#LimitOrderHook', functions: { - ...defineFunctions({}), + ...defineFunctions({ + _afterInitialize: { + kind: 'internal', + args: [ + { name: 'sender', type: 'address' }, + { name: 'key', type: 'PoolKey calldata' }, + { name: 'sqrtPriceX96', type: 'uint160' }, + { name: 'tick', type: 'int24' }, + ], + returns: ['bytes4'], + }, + _afterSwap: { + kind: 'internal', + args: [ + { name: 'sender', type: 'address' }, + { name: 'key', type: 'PoolKey calldata' }, + { name: 'params', type: 'SwapParams calldata' }, + { name: 'delta', type: 'BalanceDelta' }, + { name: 'hookData', type: 'bytes calldata' }, + ], + returns: ['bytes4', 'int128'], + }, + placeOrder: { + kind: 'public', + args: [ + { name: 'key', type: 'PoolKey calldata' }, + { name: 'tick', type: 'int24' }, + { name: 'zeroForOne', type: 'bool' }, + { name: 'liquidity', type: 'uint128' }, + ], + }, + cancelOrder: { + kind: 'public', + args: [ + { name: 'key', type: 'PoolKey calldata' }, + { name: 'tickLower', type: 'int24' }, + { name: 'zeroForOne', type: 'bool' }, + { name: 'to', type: 'address' }, + ], + }, + withdraw: { + kind: 'public', + args: [ + { name: 'orderId', type: 'OrderIdLibrary.OrderId' }, + { name: 'to', type: 'address' }, + ], + returns: ['uint256', 'uint256'], + }, + unlockCallback: { + kind: 'public', + args: [{ name: 'rawData', type: 'bytes calldata' }], + returns: ['bytes memory'], + }, + getTickLowerLast: { + kind: 'public', + mutability: 'view', + args: [{ name: 'poolId', type: 'PoolId' }], + returns: ['int24'], + }, + getOrderId: { + kind: 'public', + mutability: 'view', + args: [ + { name: 'key', type: 'PoolKey memory' }, + { name: 'tickLower', type: 'int24' }, + { name: 'zeroForOne', type: 'bool' }, + ], + returns: ['OrderIdLibrary.OrderId'], + }, + getOrderLiquidity: { + kind: 'public', + mutability: 'view', + args: [ + { name: 'orderId', type: 'OrderIdLibrary.OrderId' }, + { name: 'owner', type: 'address' }, + ], + returns: ['uint256'], + }, + getHookPermissions: { + kind: 'public', + mutability: 'pure', + args: [], + returns: ['Hooks.Permissions memory'], + }, + _handlePlaceCallback: { + kind: 'internal', + args: [{ name: 'placeData', type: 'PlaceCallbackData memory' }], + returns: ['uint256', 'uint256'], + }, + _handleCancelCallback: { + kind: 'internal', + args: [{ name: 'cancelData', type: 'CancelCallbackData memory' }], + returns: ['uint256', 'uint256'], + }, + _handleWithdrawCallback: { + kind: 'internal', + args: [{ name: 'withdrawData', type: 'WithdrawCallbackData memory' }], + }, + }), }, }; diff --git a/packages/core/uniswap-hooks/src/hooks/LiquidityPenaltyHook.ts b/packages/core/uniswap-hooks/src/hooks/LiquidityPenaltyHook.ts index 7e976c8f1..58798ec61 100644 --- a/packages/core/uniswap-hooks/src/hooks/LiquidityPenaltyHook.ts +++ b/packages/core/uniswap-hooks/src/hooks/LiquidityPenaltyHook.ts @@ -8,7 +8,93 @@ const LiquidityPenaltyHook: Hook = { 'JIT‑resistant: withholds and penalizes LP fees when liquidity is added then removed within a block window; penalties are donated to in‑range LPs.', tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/general#LiquidityPenaltyHook', functions: { - ...defineFunctions({}), + ...defineFunctions({ + _afterAddLiquidity: { + kind: 'internal', + args: [ + { name: 'sender', type: 'address' }, + { name: 'key', type: 'PoolKey calldata' }, + { name: 'params', type: 'ModifyLiquidityParams calldata' }, + { name: 'delta', type: 'BalanceDelta' }, + { name: 'feeDelta', type: 'BalanceDelta' }, + { name: 'hookData', type: 'bytes calldata' }, + ], + returns: ['bytes4', 'BalanceDelta'], + }, + _afterRemoveLiquidity: { + kind: 'internal', + args: [ + { name: 'sender', type: 'address' }, + { name: 'key', type: 'PoolKey calldata' }, + { name: 'params', type: 'ModifyLiquidityParams calldata' }, + { name: 'delta', type: 'BalanceDelta' }, + { name: 'feeDelta', type: 'BalanceDelta' }, + { name: 'hookData', type: 'bytes calldata' }, + ], + returns: ['bytes4', 'BalanceDelta'], + }, + _getBlockNumber: { + kind: 'internal', + mutability: 'view', + args: [], + returns: ['uint48'], + }, + getBlockNumberOffset: { + kind: 'public', + mutability: 'view', + args: [], + returns: ['uint48'], + }, + getLastAddedLiquidityBlock: { + kind: 'public', + mutability: 'view', + args: [ + { name: 'poolId', type: 'PoolId' }, + { name: 'positionKey', type: 'bytes32' }, + ], + returns: ['uint48'], + }, + getWithheldFees: { + kind: 'public', + mutability: 'view', + args: [ + { name: 'poolId', type: 'PoolId' }, + { name: 'positionKey', type: 'bytes32' }, + ], + returns: ['BalanceDelta'], + }, + _updateLastAddedLiquidityBlock: { + kind: 'internal', + args: [ + { name: 'poolId', type: 'PoolId' }, + { name: 'positionKey', type: 'bytes32' }, + ], + }, + _takeFeesToHook: { + kind: 'internal', + args: [ + { name: 'key', type: 'PoolKey calldata' }, + { name: 'positionKey', type: 'bytes32' }, + { name: 'feeDelta', type: 'BalanceDelta' }, + ], + }, + _settleFeesFromHook: { + kind: 'internal', + args: [ + { name: 'key', type: 'PoolKey calldata' }, + { name: 'positionKey', type: 'bytes32' }, + ], + returns: ['BalanceDelta'], + }, + _calculateLiquidityPenalty: { + kind: 'internal', + args: [ + { name: 'feeDelta', type: 'BalanceDelta' }, + { name: 'lastAddedLiquidityBlock', type: 'uint48' }, + ], + returns: ['BalanceDelta'], + }, + }), }, }; From a0c05c59176bd1063943361932878ce427c21434 Mon Sep 17 00:00:00 2001 From: Gonzalo Othacehe Date: Wed, 20 Aug 2025 16:47:55 -0300 Subject: [PATCH 23/79] merge with origin, add printContract option for additional libraries --- .../core/uniswap-hooks/src/generate/hooks.ts | 26 +++++++++---------- .../uniswap-hooks/src/generate/sources.ts | 2 +- packages/core/uniswap-hooks/src/hooks.test.ts | 5 ++-- packages/core/uniswap-hooks/src/hooks.ts | 5 ++-- packages/core/uniswap-hooks/src/index.ts | 2 ++ packages/core/uniswap-hooks/src/print.ts | 14 ++++++++++ .../core/uniswap-hooks/src/utils/version.ts | 2 +- 7 files changed, 35 insertions(+), 21 deletions(-) create mode 100644 packages/core/uniswap-hooks/src/print.ts diff --git a/packages/core/uniswap-hooks/src/generate/hooks.ts b/packages/core/uniswap-hooks/src/generate/hooks.ts index 5081c4220..7fd9fb842 100644 --- a/packages/core/uniswap-hooks/src/generate/hooks.ts +++ b/packages/core/uniswap-hooks/src/generate/hooks.ts @@ -12,21 +12,21 @@ const sharesOptions = [ { options: 'ERC6909', name: 'MyShares', symbol: 'MSH' }, ] as const; -const hooksOptions: HookName[] = Object.keys(Hooks) as HookName[]; +// const hooksOptions: HookName[] = Object.keys(Hooks) as HookName[]; // @TODO: remove, faster to test compilation one by one. -// const hooksOptions: HookName[] = [ -// 'BaseHook', -// 'BaseAsyncSwap', -// 'BaseCustomAccounting', -// 'BaseCustomCurve', -// 'BaseDynamicAfterFee', -// 'BaseDynamicFee', -// 'BaseOverrideFee', -// 'AntiSandwichHook', -// 'LiquidityPenaltyHook', -// 'LimitOrderHook', -// ]; +const hooksOptions: HookName[] = [ + 'BaseHook', + 'BaseAsyncSwap', + // 'BaseCustomAccounting', + // 'BaseCustomCurve', + // 'BaseDynamicAfterFee', + // 'BaseDynamicFee', + // 'BaseOverrideFee', + // 'AntiSandwichHook', + // 'LiquidityPenaltyHook', + // 'LimitOrderHook', +]; const blueprint = { hook: hooksOptions as readonly HookName[], diff --git a/packages/core/uniswap-hooks/src/generate/sources.ts b/packages/core/uniswap-hooks/src/generate/sources.ts index 9e594f795..3047bacc7 100644 --- a/packages/core/uniswap-hooks/src/generate/sources.ts +++ b/packages/core/uniswap-hooks/src/generate/sources.ts @@ -72,7 +72,7 @@ function generateContractSubset(subset: Subset, kind?: Kind): GeneratedContract[ export function* generateSources(subset: Subset, kind?: Kind): Generator { for (const c of generateContractSubset(subset, kind)) { - const source = printContract(c.contract, { compatibleSemver: compatibleContractsSemver }); + const source = printContract(c.contract); yield { ...c, source }; } } diff --git a/packages/core/uniswap-hooks/src/hooks.test.ts b/packages/core/uniswap-hooks/src/hooks.test.ts index a8e91ef04..9e851877e 100644 --- a/packages/core/uniswap-hooks/src/hooks.test.ts +++ b/packages/core/uniswap-hooks/src/hooks.test.ts @@ -4,8 +4,7 @@ import { hooks } from './api'; import { buildHooks, type HooksOptions } from './hooks'; import { Hooks } from './hooks/'; -import { printContract } from '@openzeppelin/wizard/src/print'; -import { compatibleContractsSemver } from './utils/version'; +import { printContract } from './print'; function testHooks(title: string, opts: Partial) { test(title, t => { @@ -13,7 +12,7 @@ function testHooks(title: string, opts: Partial) { ...hooks.defaults, ...opts, }); - t.snapshot(printContract(c, { compatibleSemver: compatibleContractsSemver })); + t.snapshot(printContract(c)); }); } diff --git a/packages/core/uniswap-hooks/src/hooks.ts b/packages/core/uniswap-hooks/src/hooks.ts index 4d9a70255..1d09c4b12 100644 --- a/packages/core/uniswap-hooks/src/hooks.ts +++ b/packages/core/uniswap-hooks/src/hooks.ts @@ -5,11 +5,10 @@ import { withCommonDefaults, defaults as commonDefaults } from '@openzeppelin/wi import { setInfo } from '@openzeppelin/wizard/src/set-info'; import { setAccessControl } from '@openzeppelin/wizard/src/set-access-control'; import { addPausable } from '@openzeppelin/wizard/src/add-pausable'; -import { printContract } from '@openzeppelin/wizard/'; import type { Value } from '@openzeppelin/wizard/src/contract'; import { supportsInterface } from '@openzeppelin/wizard/src/common-functions'; -import { compatibleContractsSemver } from './utils/version'; +import { printContract } from './print'; import { Hooks, type HookName } from './hooks/'; export const sharesOptions = [false, 'ERC20', 'ERC6909', 'ERC1155'] as const; @@ -95,7 +94,7 @@ function withDefaults(opts: HooksOptions): Required { } export function printHooks(opts: HooksOptions = defaults): string { - return printContract(buildHooks(opts), { compatibleSemver: compatibleContractsSemver }); + return printContract(buildHooks(opts)); } export function isAccessControlRequired(opts: Partial): boolean { diff --git a/packages/core/uniswap-hooks/src/index.ts b/packages/core/uniswap-hooks/src/index.ts index 5d1b599ca..b21abad76 100644 --- a/packages/core/uniswap-hooks/src/index.ts +++ b/packages/core/uniswap-hooks/src/index.ts @@ -9,3 +9,5 @@ export { Hooks, type Hook, type HookName, type HookCategory } from './hooks/'; export { type HooksOptions, type Shares } from './hooks'; export { compatibleContractsSemver } from './utils/version'; + +export { printContract } from './print'; diff --git a/packages/core/uniswap-hooks/src/print.ts b/packages/core/uniswap-hooks/src/print.ts new file mode 100644 index 000000000..51556b267 --- /dev/null +++ b/packages/core/uniswap-hooks/src/print.ts @@ -0,0 +1,14 @@ +import { printContract as printSolidityContract } from '@openzeppelin/wizard/'; +import type { HooksOptions } from './hooks'; +import { compatibleContractsSemver } from './utils/version'; +import type { Contract } from '@openzeppelin/wizard/src/contract'; + +export function printContract(contract: Contract, opts?: HooksOptions): string { + return printSolidityContract(contract, { + ...opts, + additionalCompatibleLibraries: [ + { name: 'OpenZeppelin Uniswap Hooks', path: '@openzeppelin/uniswap-hooks', version: compatibleContractsSemver }, + // { name: 'UniswapV4 Core', path: '@uniswap/v4-core', version: '^1.0.0' }, + ], + }); +} diff --git a/packages/core/uniswap-hooks/src/utils/version.ts b/packages/core/uniswap-hooks/src/utils/version.ts index 1116bb96c..4e8ec0955 100644 --- a/packages/core/uniswap-hooks/src/utils/version.ts +++ b/packages/core/uniswap-hooks/src/utils/version.ts @@ -1,4 +1,4 @@ /** * Semantic version string representing of the minimum compatible version of Contracts to display in output. */ -export const compatibleContractsSemver = 'OpenZeppelin Uniswap Hooks ^1.0.0'; +export const compatibleContractsSemver = '^1.0.0'; From 71f3786866a31e07185e22ed2b595b72423c71b0 Mon Sep 17 00:00:00 2001 From: Gonzalo Othacehe Date: Wed, 20 Aug 2025 18:43:02 -0300 Subject: [PATCH 24/79] lint ui --- packages/core/uniswap-hooks/src/hooks.test.ts | 1 - .../uniswap-hooks/AccessControlSection.svelte | 2 +- packages/ui/src/uniswap-hooks/App.svelte | 23 ++++--------- .../ui/src/uniswap-hooks/HooksControls.svelte | 32 +++++++++---------- 4 files changed, 23 insertions(+), 35 deletions(-) diff --git a/packages/core/uniswap-hooks/src/hooks.test.ts b/packages/core/uniswap-hooks/src/hooks.test.ts index 9e851877e..0fa1cd683 100644 --- a/packages/core/uniswap-hooks/src/hooks.test.ts +++ b/packages/core/uniswap-hooks/src/hooks.test.ts @@ -1,5 +1,4 @@ import test from 'ava'; -// import type { OptionsError } from '@openzeppelin/wizard/src/error'; import { hooks } from './api'; import { buildHooks, type HooksOptions } from './hooks'; diff --git a/packages/ui/src/uniswap-hooks/AccessControlSection.svelte b/packages/ui/src/uniswap-hooks/AccessControlSection.svelte index c6169807e..35ec01511 100644 --- a/packages/ui/src/uniswap-hooks/AccessControlSection.svelte +++ b/packages/ui/src/uniswap-hooks/AccessControlSection.svelte @@ -59,4 +59,4 @@ - \ No newline at end of file + diff --git a/packages/ui/src/uniswap-hooks/App.svelte b/packages/ui/src/uniswap-hooks/App.svelte index 681d91735..4282528fc 100644 --- a/packages/ui/src/uniswap-hooks/App.svelte +++ b/packages/ui/src/uniswap-hooks/App.svelte @@ -88,9 +88,9 @@ } const getButtonVisibilities = (opts?: KindedOptions[Kind]): ButtonVisibilities => { - return { - openInRemix: true, - }; + return { + openInRemix: true, + }; }; const language = 'solidity'; @@ -142,17 +142,8 @@ {#if showButtons.openInRemix} - - @@ -243,9 +234,7 @@ background-color: var(--gray-2); } - &:active - - :global(.icon) { + &:active :global(.icon) { margin: 0 var(--size-1); } } diff --git a/packages/ui/src/uniswap-hooks/HooksControls.svelte b/packages/ui/src/uniswap-hooks/HooksControls.svelte index f9cfcd21f..a3e27df44 100644 --- a/packages/ui/src/uniswap-hooks/HooksControls.svelte +++ b/packages/ui/src/uniswap-hooks/HooksControls.svelte @@ -2,7 +2,7 @@ import HelpTooltip from '../common/HelpTooltip.svelte'; import { infoDefaults } from '@openzeppelin/wizard'; - import { hooks, Hooks} from '@openzeppelin/wizard-uniswap-hooks/src'; + import { hooks, Hooks } from '@openzeppelin/wizard-uniswap-hooks/src'; import type { HookCategory, Hook, KindedOptions } from '@openzeppelin/wizard-uniswap-hooks'; import AccessControlSection from './AccessControlSection.svelte'; @@ -103,24 +103,24 @@
{#if opts.shares.options === 'ERC1155'} - - {/if} - - {#if opts.shares.options === 'ERC20'} -
+ {/if} - -
+ {#if opts.shares.options === 'ERC20'} +
+ + + +
{/if} From e2784c3327e126a0eab32c40e6319af22384c94b Mon Sep 17 00:00:00 2001 From: Gonzalo Othacehe Date: Wed, 20 Aug 2025 18:46:27 -0300 Subject: [PATCH 25/79] update hooks snapshots --- packages/core/solidity/src/print.ts | 3 - .../core/uniswap-hooks/src/hooks.test.ts.md | 414 +++++++++++++++++- .../core/uniswap-hooks/src/hooks.test.ts.snap | Bin 1353 -> 2066 bytes 3 files changed, 395 insertions(+), 22 deletions(-) diff --git a/packages/core/solidity/src/print.ts b/packages/core/solidity/src/print.ts index 34ae62357..993877e7f 100644 --- a/packages/core/solidity/src/print.ts +++ b/packages/core/solidity/src/print.ts @@ -60,14 +60,12 @@ export function printContract(contract: Contract, opts?: Options): string { function printCompatibleLibraryVersions(contract: Contract, opts?: Options): string { const libraries: string[] = []; if (importsLibrary(contract, '@openzeppelin/contracts')) { - console.log('pushing', `OpenZeppelin Contracts ${compatibleContractsSemver}`); libraries.push(`OpenZeppelin Contracts ${compatibleContractsSemver}`); } if (importsLibrary(contract, '@openzeppelin/community-contracts')) { try { const commit = getCommunityContractsGitCommit(); libraries.push(`Community Contracts commit ${commit}`); - console.log('pushing', `Community Contracts commit ${commit}`); } catch (e) { console.error(e); } @@ -75,7 +73,6 @@ function printCompatibleLibraryVersions(contract: Contract, opts?: Options): str if (opts?.additionalCompatibleLibraries) { for (const library of opts.additionalCompatibleLibraries) { if (importsLibrary(contract, library.path)) { - console.log('pushing', `${library.name} ${library.version}`); libraries.push(`${library.name} ${library.version}`); } } diff --git a/packages/core/uniswap-hooks/src/hooks.test.ts.md b/packages/core/uniswap-hooks/src/hooks.test.ts.md index 2878fa03f..70ab7270e 100644 --- a/packages/core/uniswap-hooks/src/hooks.test.ts.md +++ b/packages/core/uniswap-hooks/src/hooks.test.ts.md @@ -9,14 +9,39 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.0.0␊ + // Compatible with OpenZeppelin Uniswap Hooks ^1.0.0␊ pragma solidity ^0.8.27;␊ ␊ import {BaseHook} from "@openzeppelin/uniswap-hooks/base/BaseHook.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ ␊ contract MyHook is BaseHook {␊ constructor(IPoolManager _poolManager) BaseHook(_poolManager) {}␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: false,␊ + beforeAddLiquidity: false,␊ + beforeRemoveLiquidity: false,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: false,␊ + afterSwap: false,␊ + beforeDonate: false,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: false,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ }␊ ` @@ -25,7 +50,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.0.0␊ + // Compatible with OpenZeppelin Uniswap Hooks ^1.0.0␊ pragma solidity ^0.8.27;␊ ␊ import {BaseAsyncSwap} from "@openzeppelin/uniswap-hooks/base/BaseAsyncSwap.sol";␊ @@ -41,14 +66,45 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.0.0␊ + // Compatible with OpenZeppelin Uniswap Hooks ^1.0.0␊ pragma solidity ^0.8.27;␊ ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ import {BaseCustomAccounting} from "@openzeppelin/uniswap-hooks/base/BaseCustomAccounting.sol";␊ import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ ␊ contract MyHook is BaseCustomAccounting {␊ constructor(IPoolManager _poolManager) BaseCustomAccounting(_poolManager) {}␊ + ␊ + function _getAddLiquidity(uint160 sqrtPriceX96, AddLiquidityParams memory params)␊ + internal␊ + override␊ + returns (bytes memory, uint256)␊ + {␊ + // Override _getAddLiquidity␊ + }␊ + ␊ + function _getRemoveLiquidity(RemoveLiquidityParams memory params)␊ + internal␊ + override␊ + returns (bytes memory, uint256)␊ + {␊ + // Override _getRemoveLiquidity␊ + }␊ + ␊ + function _mint(AddLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Override _mint␊ + }␊ + ␊ + function _burn(RemoveLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Override _burn␊ + }␊ }␊ ` @@ -57,14 +113,62 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.0.0␊ + // Compatible with OpenZeppelin Uniswap Hooks ^1.0.0␊ pragma solidity ^0.8.27;␊ ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ import {BaseCustomCurve} from "@openzeppelin/uniswap-hooks/base/BaseCustomCurve.sol";␊ import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ ␊ contract MyHook is BaseCustomCurve {␊ constructor(IPoolManager _poolManager) BaseCustomCurve(_poolManager) {}␊ + ␊ + function _getUnspecifiedAmount(SwapParams calldata params)␊ + internal␊ + override␊ + returns (uint256)␊ + {␊ + // Override _getUnspecifiedAmount␊ + }␊ + ␊ + function _getSwapFeeAmount(SwapParams calldata params, uint256 unspecifiedAmount)␊ + internal␊ + override␊ + returns (uint256)␊ + {␊ + // Override _getSwapFeeAmount␊ + }␊ + ␊ + function _getAmountOut(RemoveLiquidityParams memory params)␊ + internal␊ + override␊ + returns (uint256, uint256, uint256)␊ + {␊ + // Override _getAmountOut␊ + }␊ + ␊ + function _getAmountIn(AddLiquidityParams memory params)␊ + internal␊ + override␊ + returns (uint256, uint256, uint256)␊ + {␊ + // Override _getAmountIn␊ + }␊ + ␊ + function _mint(AddLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Override _mint␊ + }␊ + ␊ + function _burn(RemoveLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Override _burn␊ + }␊ }␊ ` @@ -73,14 +177,23 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.0.0␊ + // Compatible with OpenZeppelin Uniswap Hooks ^1.0.0␊ pragma solidity ^0.8.27;␊ ␊ import {BaseDynamicFee} from "@openzeppelin/uniswap-hooks/fee/BaseDynamicFee.sol";␊ import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ ␊ contract MyHook is BaseDynamicFee {␊ constructor(IPoolManager _poolManager) BaseDynamicFee(_poolManager) {}␊ + ␊ + function _getFee(PoolKey calldata key) internal override returns (uint24) {␊ + // Override _getFee␊ + }␊ + ␊ + function poke(PoolKey calldata key) public override {␊ + // Override poke␊ + }␊ }␊ ` @@ -89,14 +202,24 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.0.0␊ + // Compatible with OpenZeppelin Uniswap Hooks ^1.0.0␊ pragma solidity ^0.8.27;␊ ␊ import {BaseOverrideFee} from "@openzeppelin/uniswap-hooks/fee/BaseOverrideFee.sol";␊ import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ ␊ contract MyHook is BaseOverrideFee {␊ constructor(IPoolManager _poolManager) BaseOverrideFee(_poolManager) {}␊ + ␊ + function _getFee(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (uint24)␊ + {␊ + // Override _getFee␊ + }␊ }␊ ` @@ -105,14 +228,32 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.0.0␊ + // Compatible with OpenZeppelin Uniswap Hooks ^1.0.0␊ pragma solidity ^0.8.27;␊ ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ import {BaseDynamicAfterFee} from "@openzeppelin/uniswap-hooks/fee/BaseDynamicAfterFee.sol";␊ import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ ␊ contract MyHook is BaseDynamicAfterFee {␊ constructor(IPoolManager _poolManager) BaseDynamicAfterFee(_poolManager) {}␊ + ␊ + function _getTargetUnspecified(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (uint256, bool)␊ + {␊ + // Override _getTargetUnspecified␊ + }␊ + ␊ + function _afterSwapHandler(PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, uint256 targetUnspecifiedAmount, uint256 feeAmount)␊ + internal␊ + override␊ + {␊ + // Override _afterSwapHandler␊ + }␊ }␊ ` @@ -121,14 +262,24 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.0.0␊ + // Compatible with OpenZeppelin Uniswap Hooks ^1.0.0␊ pragma solidity ^0.8.27;␊ ␊ import {AntiSandwichHook} from "@openzeppelin/uniswap-hooks/general/AntiSandwichHook.sol";␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ ␊ contract MyHook is AntiSandwichHook {␊ constructor(IPoolManager _poolManager) AntiSandwichHook(_poolManager) {}␊ + ␊ + function _afterSwapHandler(PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, uint256 targetUnspecifiedAmount, uint256 feeAmount)␊ + internal␊ + override␊ + {␊ + // Override _afterSwapHandler␊ + }␊ }␊ ` @@ -137,7 +288,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.0.0␊ + // Compatible with OpenZeppelin Uniswap Hooks ^1.0.0␊ pragma solidity ^0.8.27;␊ ␊ import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ @@ -153,7 +304,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.0.0␊ + // Compatible with OpenZeppelin Uniswap Hooks ^1.0.0␊ pragma solidity ^0.8.27;␊ ␊ import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ @@ -171,10 +322,11 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.0.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ pragma solidity ^0.8.27;␊ ␊ import {BaseHook} from "@openzeppelin/uniswap-hooks/base/BaseHook.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊ ␊ @@ -183,6 +335,30 @@ Generated by [AVA](https://avajs.dev). BaseHook(_poolManager)␊ Ownable(initialOwner)␊ {}␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: false,␊ + beforeAddLiquidity: false,␊ + beforeRemoveLiquidity: false,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: false,␊ + afterSwap: false,␊ + beforeDonate: false,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: false,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ }␊ ` @@ -191,11 +367,12 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.0.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ pragma solidity ^0.8.27;␊ ␊ import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";␊ import {BaseHook} from "@openzeppelin/uniswap-hooks/base/BaseHook.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ ␊ contract MyHook is BaseHook, AccessControl {␊ @@ -204,6 +381,30 @@ Generated by [AVA](https://avajs.dev). {␊ _grantRole(DEFAULT_ADMIN_ROLE, defaultAdmin);␊ }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: false,␊ + beforeAddLiquidity: false,␊ + beforeRemoveLiquidity: false,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: false,␊ + afterSwap: false,␊ + beforeDonate: false,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: false,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ }␊ ` @@ -212,11 +413,12 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.0.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ pragma solidity ^0.8.27;␊ ␊ import {AccessManaged} from "@openzeppelin/contracts/access/manager/AccessManaged.sol";␊ import {BaseHook} from "@openzeppelin/uniswap-hooks/base/BaseHook.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ ␊ contract MyHook is BaseHook, AccessManaged {␊ @@ -224,6 +426,30 @@ Generated by [AVA](https://avajs.dev). BaseHook(_poolManager)␊ AccessManaged(initialAuthority)␊ {}␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: false,␊ + beforeAddLiquidity: false,␊ + beforeRemoveLiquidity: false,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: false,␊ + afterSwap: false,␊ + beforeDonate: false,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: false,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ }␊ ` @@ -232,10 +458,11 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.0.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ pragma solidity ^0.8.27;␊ ␊ import {BaseHook} from "@openzeppelin/uniswap-hooks/base/BaseHook.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊ import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";␊ @@ -245,6 +472,30 @@ Generated by [AVA](https://avajs.dev). BaseHook(_poolManager)␊ Ownable(initialOwner)␊ {}␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: false,␊ + beforeAddLiquidity: false,␊ + beforeRemoveLiquidity: false,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: false,␊ + afterSwap: false,␊ + beforeDonate: false,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: false,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ ␊ function pause() public onlyOwner {␊ _pause();␊ @@ -261,18 +512,43 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.0.0␊ + // Compatible with OpenZeppelin Uniswap Hooks ^1.0.0␊ pragma solidity ^0.8.27;␊ ␊ import {BaseHook} from "@openzeppelin/uniswap-hooks/base/BaseHook.sol";␊ import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ import {CurrencySettler} from "@openzeppelin/uniswap-hooks/utils/CurrencySettler.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ ␊ contract MyHook is BaseHook {␊ using CurrencySettler for Currency;␊ ␊ constructor(IPoolManager _poolManager) BaseHook(_poolManager) {}␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: false,␊ + beforeAddLiquidity: false,␊ + beforeRemoveLiquidity: false,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: false,␊ + afterSwap: false,␊ + beforeDonate: false,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: false,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ }␊ ` @@ -281,10 +557,11 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.0.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ pragma solidity ^0.8.27;␊ ␊ import {BaseHook} from "@openzeppelin/uniswap-hooks/base/BaseHook.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";␊ ␊ @@ -292,6 +569,30 @@ Generated by [AVA](https://avajs.dev). using SafeCast for *;␊ ␊ constructor(IPoolManager _poolManager) BaseHook(_poolManager) {}␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: false,␊ + beforeAddLiquidity: false,␊ + beforeRemoveLiquidity: false,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: false,␊ + afterSwap: false,␊ + beforeDonate: false,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: false,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ }␊ ` @@ -300,10 +601,11 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.0.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ pragma solidity ^0.8.27;␊ ␊ import {BaseHook} from "@openzeppelin/uniswap-hooks/base/BaseHook.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ import {SlotDerivation} from "@openzeppelin/contracts/utils/SlotDerivation.sol";␊ import {TransientSlot} from "@openzeppelin/contracts/utils/TransientSlot.sol";␊ @@ -313,6 +615,30 @@ Generated by [AVA](https://avajs.dev). using TransientSlot for bytes32;␊ ␊ constructor(IPoolManager _poolManager) BaseHook(_poolManager) {}␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: false,␊ + beforeAddLiquidity: false,␊ + beforeRemoveLiquidity: false,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: false,␊ + afterSwap: false,␊ + beforeDonate: false,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: false,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ }␊ ` @@ -321,11 +647,12 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.0.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ pragma solidity ^0.8.27;␊ ␊ import {BaseHook} from "@openzeppelin/uniswap-hooks/base/BaseHook.sol";␊ import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ ␊ contract MyHook is BaseHook, ERC20 {␊ @@ -333,6 +660,30 @@ Generated by [AVA](https://avajs.dev). BaseHook(_poolManager)␊ ERC20("MyShares", "MSH")␊ {}␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: false,␊ + beforeAddLiquidity: false,␊ + beforeRemoveLiquidity: false,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: false,␊ + afterSwap: false,␊ + beforeDonate: false,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: false,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ }␊ ` @@ -341,14 +692,39 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.0.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ pragma solidity ^0.8.27;␊ ␊ import {BaseHook} from "@openzeppelin/uniswap-hooks/base/BaseHook.sol";␊ import {ERC6909} from "@openzeppelin/contracts/token/ERC6909/draft-ERC6909.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";␊ ␊ contract MyHook is BaseHook, ERC6909 {␊ constructor(IPoolManager _poolManager) BaseHook(_poolManager) {}␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: false,␊ + beforeAddLiquidity: false,␊ + beforeRemoveLiquidity: false,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: false,␊ + afterSwap: false,␊ + beforeDonate: false,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: false,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ }␊ ` diff --git a/packages/core/uniswap-hooks/src/hooks.test.ts.snap b/packages/core/uniswap-hooks/src/hooks.test.ts.snap index f9804d865d60a93c39e5fffa57a4ba581dee4d7c..c2f9ab76011a18ecab344f5549ade96df0d29ee1 100644 GIT binary patch literal 2066 zcmV+t2<`VlRzV(Efmy{4A^ZLx<6~@U3T7ehe6+_B->Oz>eQ7FMP$GC_#XNA zdlW_WwcT}?c_4oM6C{xi&@L9lL=UilM~od1L9r+HnG`>~wk$01H&=hYa_PpU;4^jY z()*XcziJq0dvoRa>^d=l3YcB9fJ$N$;P=tS+S7(%pk?NISdy*-=!nRD)bW6R3!VoK zq39VU;s|>vXilJ=TXXYs^9_&VJr^Uv9AXjKLp$?xcjp#9Uuran>oG3TtHi@&WOL@C z=`WcF^kr<+@FSzM`+-rTiv<{o!kl2v^ipakY&JC#>lufOvnJzU2yPk<>2k~o2qTou z>91`v=4@b!_ka&IL#PC9V-tkYuM?YVn2bt}O^G&oK{JSmbP&+120{p#j0(wpQ!?J{ zw}5uN>|!R>YN}tqI&OqkY@eEvFpBm-24b7QT_OZwR5WKoiQwb;U5A)`mmJayb_kpk zEBk_j^f?u%8TC(}MdX6ZcrUX1DyM)7;>}DX_;kT$9M&k21Uuv<+($Nc1hf<(Y)jxH zWFkXt%UUNd{4k-0h;4z(4q>=t*yu=mp_GofsNwA+>gHbkV1RI#?c))Rx znOX=ABRDC2LuDQCKBK||Gsq3A?FPVZW?_XBA;_@P@JW+M1wRIYHSlj0V5GO%1oiW_ z&odCky@5eQKX-h2ZgnAcH|+)e>Xx`R!ud5ivN(*x@ikiRcU{fKT+L)w%~pC8yTn|D zl45rG52cv>a(Rrmb(xirLwHIxUWv!JP4-5=hoF#JQ`TVbv&wr0IpZgrG zlF)r>7c-;JeMQ#S1J&n7pR(@cz?Q{92qb`7z+0#+d0S}M+9$d#Our5WbOlR%@`}7T zs{CfNFWUMhAdoRGoFxXYL`YF-wCDPLWt4+I`zYB|753+C_;mBpnMEjW{9rObN~t=2OEJGo~% z<$H?mz0CiTVdlzVw z@62i_%4?70(7Q4r$BYOh|^B-j}|C*S=ECyd~NQ?SI2ev3)Wq6~xzIYeyh6jh9_-+??$F>FZ z&H1uMnyQsS>PmimgiSM8L4|QJ2Q}Fd#a#zxN}dUSp=5_~>Sw~sao-8Fb9-)aZXRK3 z)hCw*=W!<*n)0ZUL=;9eqDCyOar&u+V%ch0nk>FabTp`QM1f}sT7F0>{W)&2SyZl% zQPsz&CixiEVV=00IUve->ngn6xwyP-hY>AD0cqk%(J9%XnIL`-XRp!`CnK;0HufFa zwp>EB2%O<-caLK#x0nOXm4~bCXX{UQ+bbJuPjknJ1t&_wX1SSqYSt2rG& z8=BdfF6#8cDbRlt8q1U$@Trc8RH{%mJk#eKsM$jTq;!CnEabmZ%EyE8z3y~2#bG&) zSmQBkB09jrcGP7$4nS~bn+qoaBF#CeiYm!I{<2gqS3z> zvl0y7cMct|bhcM_S2?uYoZjedhsibFLem@DkEZL5<(jCIPgI%__0GNddnHVLPhskR wr+#bkZD4B971~q{gbj;hTh7K;Zz*2`*X#ekv4&<1%|X!oALqV5Yl2n)0K@?3H2?qr literal 1353 zcmV-P1-AM@RzVe-x}%8TcqsIr0eu%rZih$TGa{FF+DT{+-Ne)Y^WvBICMj$T@M zbtU*(eP!jfwZW=kpzdMo^T>0~%2^Kphv@ zr{KC^Q-+$HDS?TS=og+(d z2US1dF0jv|goekc9AS5J!1<{(dRT%H3$`S;tGh{_{X@>}HfFdFBFPoWjp4mb!UY&o z5Q8!W!omckF|CQxRYhoA*xfD_en`AzB;$2ZaDJAs`c2tiHA z#`m3u@9VPgO*L7B-;`{*0H+EUCpaaZcZqys<^(n@1tOc{bB*Ig$;U8m^crU|mX>lL z00AUc*ML9K^bg0HM1H9gB^a?KmB zV?sbm6t08YsK!SO_iR|7b;jDunlt`+@hB)s*BNhGc2}`Qq%q!WBZ|)PIB5e#vBms@ zO;ZF=DWi&FyE9@SCf3P*>XiICs#u#9YnS-6Zv?kNX1V6B=9;(H%DBXby*9_K=7gka zQn+uJ3+FpXTgdf%WP*h~TQy9FvRpnoOM*`N0yA~QZK$>O9yC5WI6i5#+WU`AjyeZ> z8+zv5P&IctIbjtu%V!&!&)zD}XXBkPbNXz&B4KFS+wZq%A^&M^H9R%of+|1v?9yu2 zveQgYv4M*{8BDtjKmD%x>E|;1bi=qW;%XP?IE*&_swAGGwlw1CTn3DTZ`{Q*{AqcN zD9RZMtOvDq2o)Ex@k0dB%gUC1pJK7<* zbDIxAGg|H31E72tq!EW+lA$}^t~?Em?VA#o_OYZVgO5d0-5`sLf$XW{&xD1n)zz!Z{-3*67T)Dq1I z$G3UPEZPV*S1k~9h=Y-z&knjKmGC&m5k%$7r%4LiOKT=HS?{4o-MQJ7UpauKU zmIEw6A`oP|o-vdD)~xvFZJtScN6qc}RfrWo1!jbyAEF LsTNA}4JQBqLzk7J From 88d1d53bb15dcc40832bcc83c6b85220b951b7a6 Mon Sep 17 00:00:00 2001 From: Gonzalo Othacehe Date: Wed, 20 Aug 2025 19:15:34 -0300 Subject: [PATCH 26/79] update snapshots --- .../core/solidity/src/contract.test.ts.md | 38 +++++++++--------- .../core/solidity/src/contract.test.ts.snap | Bin 1009 -> 951 bytes packages/core/solidity/src/custom.test.ts.md | 6 +-- .../core/solidity/src/custom.test.ts.snap | Bin 859 -> 858 bytes .../core/solidity/src/zip-foundry.test.ts.md | 2 +- .../solidity/src/zip-foundry.test.ts.snap | Bin 3951 -> 3952 bytes .../core/solidity/src/zip-hardhat.test.ts.md | 2 +- .../solidity/src/zip-hardhat.test.ts.snap | Bin 2824 -> 2827 bytes 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/packages/core/solidity/src/contract.test.ts.md b/packages/core/solidity/src/contract.test.ts.md index f0f01afb2..cc82a66d6 100644 --- a/packages/core/solidity/src/contract.test.ts.md +++ b/packages/core/solidity/src/contract.test.ts.md @@ -9,7 +9,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ contract Foo {␊ @@ -21,7 +21,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ contract Footec {␊ @@ -33,7 +33,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ import {Bar} from "./Bar.sol";␊ @@ -47,7 +47,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ import {Bar} from "./Bar.sol";␊ @@ -62,7 +62,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ import {Bar} from "./Bar.sol";␊ @@ -77,7 +77,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ import {Bar} from "./Bar.sol";␊ @@ -93,7 +93,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ contract Foo {␊ @@ -105,7 +105,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ contract Foo {␊ @@ -125,7 +125,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ contract Foo {␊ @@ -149,7 +149,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ contract Foo {␊ @@ -162,7 +162,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ contract Foo {␊ @@ -177,7 +177,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ contract Foo {␊ @@ -192,7 +192,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ import {Bar} from "./Bar.sol";␊ @@ -209,7 +209,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ contract Foo {␊ @@ -224,7 +224,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ contract Foo {␊ @@ -240,7 +240,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ contract Foo {␊ @@ -253,7 +253,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ contract Foo {␊ @@ -267,7 +267,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ contract FooBarBaz {␊ @@ -279,7 +279,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ /// @custom:security-contact security@example.com␊ diff --git a/packages/core/solidity/src/contract.test.ts.snap b/packages/core/solidity/src/contract.test.ts.snap index f14822349451cbe78deed32ceabf528d107894a1..29fafce04563aa902702b9c61eee6c916d130755 100644 GIT binary patch literal 951 zcmV;o14#TqRzV&0Zsa3;Wjro!x>(f&8Z$35%=Yb zk!1OQ?;nc@00000000B+m(5QTK^VqCV@!JU<_9rvnqW#SU1a(ua9Oj%|}ge4)x4h zCT3XaYxXeWBTxw;qc(SNj<}d4dSnnycZo=$-3nE0_SLAW0D*uAJ#K<#-Jp>NprL-i zg@SsCh&6Bp_aR%bN<(jx$g0L;=#*67w^E^VH_M)$oiT-oW@ ztq!{Kpf51gT}lsRyA=>Yd{ih>q<%1@zCA>#yCehvU~?vw2yMkhZa|;UWh3U{Y#z4% z6|)0SUuzLu+%-<%%v%M{@Xz9Z7~(%4+no35(RtG&Z3(ZU5Y$OoH;!N>yO7MR!IKQ< zK`$EV-0$rklJ?WGV7`Lja?j&6%9g+lnXM>i5{TF_N`k;=ArEigkN;!J z!?dcPn2DC7ZiLh(g6q*I;%083iPI4yiO@Doaz>nO-&1_@HU`B$Viwt6=|bGJr6r!-DwT(Ddo(HFb=$P4J$>y=c19vb%t;Et7U^8g{(y zvK{8`wj*cJr%dI1xm1wI929vN9s<=)~qR8b3TXQ>d`jg+5+nv8{ z+b}(K`ts0O>L8OiH0dH!)T1a)z`4npf^EY%4??17%|}?Esty-IWLGc@(WeZ?lldfE z9koWR;X)|LTtGl_pSn~n!PQ~wxK%keRwy)~O>hp&g_S~rd2yiG!$^QYB}9xm+{J0) zVVc21gTb91F;M8Vl9+Gy#WN5HiO@Jw=wG*@-|`~2iSTI?#qK z?4|u?u${hxYn;*U34gezQIuAP`2Z%t&j*3 zphA%$%@;$OPkkg!hXeosIGjl(B1dsi8r0WI#hBxfVi{I{Rf>bKywW02rDI%xGk*y< z!{3TEo8NAz^}UbO`nw=)P}F^2#xMFW49`%et_@8^3*LHlLf zFjGhHxbO1?%I3g}n4>6X5{OtcLW01X5f$h{Z3(86p{+tZM&l8xnNU_C=&6$_$Kt12!+0=lrb|5!<2u;I)-5^1*0296`;As?rxJQY82>MI5{lP(ofTUN55zq&6d9sJ zi4RVl=#evz{*MgC_j<*+N<@|1YCV?;(>TgJo<{%PK>unp(c88Sr<_PC9-NTqM1rcN fA&pr>Zd^EpizEnrv>YC!PoTd5=1kbuD-{3$zh&v2 diff --git a/packages/core/solidity/src/custom.test.ts.md b/packages/core/solidity/src/custom.test.ts.md index 7906d5648..d8ce01993 100644 --- a/packages/core/solidity/src/custom.test.ts.md +++ b/packages/core/solidity/src/custom.test.ts.md @@ -9,7 +9,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ contract MyContract {␊ @@ -21,7 +21,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ contract Contract {␊ @@ -106,7 +106,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ contract MyContract {␊ diff --git a/packages/core/solidity/src/custom.test.ts.snap b/packages/core/solidity/src/custom.test.ts.snap index 6e45868ebc43a0d3944a8fac1f9c3678ce4cad85..7a976e2dd1ca184442eee122b8b05ba0a4d17548 100644 GIT binary patch literal 858 zcmV-g1Eu^yRzVKna*eYZ2`)-{Jf!G;_A1QE1ZecYE7 zJi~FM#vh9a00000000B+R?lnOFcfZ9#=y7jy31Qn2{dsT8yn4Kq3s~hEM40`J6MBa z%ZZpQ2}y36gdTR?f6@JO`ww;={#naTn{I)oWlRAW@-Ywv0V57~ zF(~BWGOxbD>+^l^n#XD+P@vF&mKmH@e&;DX`BhoO!M0(C`vPe)pcuwPkDx0s`+|kQ zl&~zng0r`cH;t`ZI1^uRsbSU~vyj{+c#`|D@qr7>rb#?IElk|&vvQu;tWUi`2K?>W1Bq_`+004(GrDfn~F006OB~}UuBbp%E9WyLzDZXm1 z&MvKJzZWn^6V4#i1y^ezf&nECa7HH)G|3Y_{RGpDR*C@vwoHf&l?KTsV;qQ~L@ths z(-JWykPHPc4~jMh1+QXI+Hp6@bP1*Fxyo!I`NbsB-UzZ_01Rx>QQNlRLww4&`7}+V z>H!PScpXv7$N32jZ2~l%MxL!=Ex-SG6jK9WqsDEq0iU#|4E;MQ}nL4-X)7^ zAh{rgEWO^r(O;&>7g7jwmr=_MC%1nS3IQK}9!>8d8RiBPOf2adXP8nyDX|}ZH;uBH zLlugS(Kj&aqd(ZC_CAW2RAvtz{_)(^xV@vju*Rr6exCUPwJPTAAhT zGaf03H02bM?ztd17%%>{KmSb!>E3?TSxa@HrIJ%T$AK#+Mnl`H zXlN^9x)T#!vaQCR1g^x*Tf3e1r~YAg ze{a*=R{9GTN83jX4d)!T(@NV=VtaK;bYhB2DiIeXZDa3JiX_;@L*I%WQcr5;&T9F4 k{s>&ui#L$COUwG-t)_9EGnT+ zo|40k*B^@r00000000B+R!wUYK^RUfBJ54CUS4}jpve|dl;&b+D+C%-+6G#|hRN7UPal0L*)|;R?;O|mh=ZBJwU&#SCIf=y z7PMPOmTki}_XN_UPce*%9zjQ7_7Mw#DPge9nU=`W3Qk|wU)47)A<@u7pg1Ki(Gxh` ztiP?leABQjCx$|Ml0?DGy0GGw&!0y<14AALqQGaw;VuS+2DnJ%n?dAqB}C@Y7zyMn z)ThOkPs+cHo`06_uxH{4E;Y zs^+u66l#c4KF)4PVPmRUXihkscjOC*=(HmjBzP9}Z>atZH#A5HHeDdq+fj4kOJXP8nirq~PKn?~8l zpmL-m^bH;LkgrEvl4&xxv@wRqEl*JFVWv@lt)?Xi(^xV@(*u5nr6exCK1e(@Jeg(f zGg>JKHRTlI>ACmmj&qjdz$01a`~hAV9G=~`tHMoR-aq@drz6$5kxEYS9Lp{r8v|{v zVxY~i)9t9yCC6&SEEukV{lkb|JU~9xP1hsLFr=YGOdoKHD?7XIo87&mUUR42`p`S* z?CoxtVTIpjeziTs&~VPzc~Wi}N^Gr8iFVZDl1fB`q;145rAUljy!6e;QuU;2MplaN lv!B3uEq`T+rnIbKKHO&>?lTYfnLE4B{09HG<+iL5002FQl(zr? diff --git a/packages/core/solidity/src/zip-foundry.test.ts.md b/packages/core/solidity/src/zip-foundry.test.ts.md index 94009d407..4bf59d640 100644 --- a/packages/core/solidity/src/zip-foundry.test.ts.md +++ b/packages/core/solidity/src/zip-foundry.test.ts.md @@ -1252,7 +1252,7 @@ Generated by [AVA](https://avajs.dev). }␊ `, `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ contract MyContract {␊ diff --git a/packages/core/solidity/src/zip-foundry.test.ts.snap b/packages/core/solidity/src/zip-foundry.test.ts.snap index c21d462076ff18cf64ff105ff1a139b143171561..e484d2ef14ecdf2f3de9f3753fdc2a4a86d1f697 100644 GIT binary patch delta 3559 zcmVhJC(_z=NMjiH`#=wJyORucO zlUS*I<2`ci59A+<2mk;800003?Oe@|97h%JvE#&<#QDG=Aq7NvEMUf(>E7MMc4TL* ztaqJg!E3Mf1Clt&rnb9grsD3ZaaHxM$CeKqkPv?XAS9H39DxH!aDW>U;ve8I;KUtH z2nnI;uIlN}nc0uoowYlMc&F>tt5>gIy?*ukRreR|ZI{~j`A@z?0t**?j+i|+1KPgp zVoqR>cd6h%`oeLbfFFMCm#2*v4EbN>Y~}fP48yo-7{>c&4CAGR3!|0zkjPsS} zU$2~5U<~$uD;53MtFOLlRH{bhj8S>nIA1wse6@1gsGNEI)W4s*c){{Hv$ip@5ZM9S zkaw%qi(s*f?E3(>K?e(fIlzPq=(@|rk)3h0|*tMO?~2+U^&zjbe2tm^#SZaOw5{p?D`N3Fk5Zogc0w_uB=~ZNSm?_ z8e&S=KExP3K++(vju7Yy(c{-FYn#&hW(SFOC~ESq)j>jF(rIx4nLv)EY=Z(*l9|jp z5`HflsK@B%$QI!w?txZY8W}1U)N^a#ljIDR2^JW-_z@>$y-Mzz}pi1Ox?ehhhg{0k)A;M0XI|Wmt${ByR_--C9^$xn+8e`m04B znUgL88#4nRBcXMK{=VBoJ z%LBFeh}Qz4-Oz2+7d>Cp;x{*(z!D|MtW}ZAQFJX8jR3mR*?nydeuNyeCKsbhf|ZKS zg12uOKeA7e2#z(IWoa=e=s}5!7dhE0D*QL z=pce*X9sNe!M(&H2m|Glx=uHt2h6x@Oq+UEqX}RTgmS3>(S;&X-we_hRKXjzIjHB- zK2Hjo)#}A)EyfZ`wJH8Uq zGH`}Rz_I5C>kul>c!&sjGnh|^?iTv* zT6_@YQk51~`Wy5HXYgLkAAg9}=uix|3*?B$>~^j)#wc$nypiEBgp_Mp!Z z)4kNMA@UxUk2Ni?e&xukI}~OJVk0mQ2-?+`>(RWLe+f&Q%7UiStlXpH#igBkP1gcy zc_K$vE#Ky~rZ%Il$84zXf!k>>| z{c$90I&sxdnEAz=-)kQt>6$U=m zH&W0h@G%i{m#+Zm$-Q58oY=%0nVTgQsE&!@WKEK&EA;prK!$?tIg`~PVCaF5S-5Y| zRi>FTdCTuPP@u?ax%dac7@xxqbbT}kf4kr=5$Hx2^tko-${#HC!E#QACii=Ync9%h z06B0tV7{kGkbfep=`M+{nb6JA&mD|*3(VBXCd_984GamN5f18V_Gz2Lc4fLUCNx6Z zJ18NZ(&ibRC1am5S4j5 zO3v3+m8lTihh_-j(p~kK^!*-h0-I6J7rPLXn+!W0xzuf+3+iQI-f#XV59a;u3x@IE z7Y*aj=M3Y@8+(O$|NeXl^Oi902eiPvf%`XmlV%7>DYlPYXG=nXBSq0e!QfU1p@VsF z@8g<`C)h!^VW0Zqc z+UuA>a#CDOLP;*Cv(Jgesh;9F+}%CM`cb51R!O>K*j!!Tlh+9_f2y#FJwd~V6k?1r zut}gVx|GRnR9&-PmSur=Lp<^teH4{zEuV1MMlC2Sn>aO=p~@1Bhl2x$3~(gIi&&Py zGryi!2sN`MPBXWDN%I9U#VpO9Z3Uj)k`g&w-1W5JAS%KxIT9*1irRIAQ%0j#6zZ?ebTIUR7@%0kgEuq~K+AX2o651`H-4fa@q1_VN zeOjS^-3ukO`%FN)Q~f&53480N^4#&fb#rxY_Mq_P)wx+Kqv@#e%4g?2fTW-E5ANp! zpVNd_CYEOoDw#$kug=Ym14)i|I=u*RJYp~~ao#rv{<~emfBS*|3XX85;lE>i0v#u! z=OJd#&R)J8?jW*I-Yb`feX{+>Rm1q{%jGA3+e;|#iG9x~Yp0klU@-LwOt8zR5iL8~!{?@e=*8k=M6k~oyT}hAl#I+nI z0svG1=6w!2|GjgipkC8y!|VGDTaU5xB=&)4rM;fj@i@IzmWyR=xy}WX!RsN9vc8Oe zBcI{nZ{DhoN_5Ekkv|(51W(&HY)5Qn$6c`5P30!TW9}(^hQk--^Wr4^E!l7A?WJIl z@E&BrON+$^N8TQGaO8XE4C9Zll?O-4-R8;NZI%Z|p3R+Xd2pmWI8q)QDba-T;K=ys z!aL=`krJZV-@%cM!FFRbdlw(;DLzww^1;aEG&#uRpodE0NXk=ttYpj+A1NQ?9r<_) zPI$;!sv{mnK*PAFJdPfi>Xk<|j{c~|G3Wd}p5mAc;O2&_z34Q@OMfal&GE`v!}#Zm zhH<-Ep5`d=wUdjlm8UtT7Xy2mPjmdC#9vM}{&M8Fi%wZnb)e&Khrp;#_CSY!c3ZMi z9XK;ntm>vihD{1ljlqanI###TCwXilZ}VSSA9Y`c+}Ipvg2#E=o{x@}kKcDFam@Jcc2Z>S1CL8yC>zz%Y<1^-w6QADW! z??uD-^*O_Mt0dIRg8u{;{3W4({%me0N7^~w@F5?I2mk;800003?Oa=r97h%IvE#&<#JOOQkOHDS7BFMYbnk9rJF>G@ z)@uhXcP~YP)M@D(Tj1w;N(y6ZH7Zr3a>l5P4{FMfL-L+n|F5z#L%01$15HRB;b2al(lAWLMTNG^9;g z2MsYLY#(Bb9w2EDSVIVOh3N5XmbFFc1G9rfI}|l}*Xkf4FzK|ofJ`9AQno>XDalM` z4GF&&4b)@wGh~Z!68Ax?EsYEn3+lNw@NsemO9TrHUHll6PFjg+nzd>bfQ#TJv>*6A z@B{oZ7%~S4%A5MT&89s+^_xJ|JGumD>~Dx%wn?Jz7vFp{?oR&OudTE1<1j{2)b zADfdc0vj_!A0wf4g#NzQL*zr$>me5tut)mmHss0Wd zK+6NQ_=wj6p`Fle)E7Np)Z#ZcoWLzgkXfrDm!s%fDjETFrL+6m8vGbJW=$?el>{pl zodth?>LOT6hV+UG>FRnH^GKzGJW9A=P#_MVOqSS=y7(Lc8**fVrGH>{h=Uz0x&Q+0 zI?zD`$<7Yg>Vx}SAPD7B0ip{XHuR9OEGD`r${f{CKmD{SpFM!f zG->i~a7Ff6M_g!eJ%52vKFk%;7m@I-V7giH52z1pNC3y4AFM;DJmVoEp~h5!_}^rV>o# z;tJepMlpO!$M9EATNYSbx%GbQ4z>~DsI}xEB5)fcb`2~qt$$a040b#Sv}W+hjQO@X zclCO;ioG6X0z6p@Y}f^DMm_b=Y;oaO;dMFL+Vx1-ri4=$Wu;X^N?iF&i_5GVxiJu| zMyo_!4@Z^HeD&88nZ$fz2l2>}*yz<8pyzM7*alB_tMOLmlUQ4j8Z8T~-@A41ntTw; z9K#Ujh^tkEz<)Mm7;d?UgDvFJoo0|zflp+bk})D>+SGOFj=ZfL1>;-`HD3z;+4jsJ z^lvf>9UF2{Z(I)=)L?)i8~3nOHV@vBRtzp^kuGBBMzWWK+R%5!g5zPLJ0`9T>Dz-o zM@;upzlO+rSU%RYy!w?RukKKoA&8B@JRoRCU#>^NUL= zP|FiJa@X=rUTbPI>UzwE>K?eA_A*|-WK{v!t?ouk<+NTZGiOIF70UvP)ayZkw_Frv z@%$YN_~f$rmN_%V+FGz}#Cgz>x_T89J%?c+Y$f`n*3<3P#krYLdW5_kRv;SwKTpX` zpAi}Pdw)@e9tlJ^ri5Dw9eMiSb0P08V7pZVhIwegt-^zoWaU za`RSSApYi@PS`Rd2uK82S=d;+y}G%2@6K&74}TsY+lCM3E?=qFVhuI5-ivfBFWp_w z)e&ouI-*=8m~RWp>Y23N%+1NoRJLuVvS}kwEdL9pUau|pLEze26V#U1zgJ5Mgiecz zh3!uwsZFUjo@3``W@f-8FgpV-T>=iWu?JmV*ZDE%(qWK@RqCSpt=sP{Y}{GjT)4Ho zbbmLPd@@Pr_lo&jXYqW&m{U_}emC@R^oS0$3?9;yxc&4{jrgpUe7-WD>{VUVBVS?Q zV|^n9Z2}(?F?ab2fS#=Vvg5=i-pJf6sX%p13@7&_iG770p99EHP@XfnI|K|p^f3$T z2EEHPQzmcvJqHRDSuGd;AQCohU4>404 z5*i=}4hPKlGzs!gWHsF(@ih~=Ir_Pc(N2MxI@yHzY@mT5;WNTPUClmibJ(s-SH^@! zXnO}+i0AYc;)!AG{t=>ajuMXQ%7j9m+J%3YP zuFp1xZdJ9|T%%xDss-L`6l_Daz*|b-5cZqNIzbkXccB+c95TZ6)Hz2?+hsSw;pW(eWZ9rc*>{T^=un^DdeyAYF`3_BgU)NP*&>SbZxum2|x=Kb~y zhVkDQ4dYMe4CBfhdxd%b_IwHRmI*NLw7|T9`!{-%V+ctpmXBR$Q$m3wMbRU{;ARM+ zgL!cOqneB-*gDxcnyrLOLn zxHgPeVDwQR%txCzGhBTe8!KxovZ=1B>stIaHq}MAg-t|k>YzpFx^*ow$nQ;1k59cB zN8sWXHo{WAQOHT?`YkB)w(WSXtYX)Cn+uYGV_7f`$(% z#295@gFs(&DU)SXU9(=6Wr24?Jn|ZS9BtQHKH;#9T2St6;?!7%DoZdP4h|eLz>yd) zVp#^y{CeI-sF~g3G;{YaX}%z)n5EgX&A_vpQX+?oyPg&tL`B#oM?%F$QM-u0Nx(rR_GaM1e6(Adk-+#8*@iB5a`%&@ z3L$@VH#ZtLZ3#rL4{V8o(w0y(YeY<0$P#G&DQ1r}ITV(jiA}2k7}`cmWENnaAvs)T zxFtUj9hy;bh!ki>_fXn%;PJ>8D)OT72-;baNRF(pLg-;MT{*a*EehBENg`Xve8A*B zG^US@P1u~-eN336{oPS=w8w;lOn~T3ArX^A3l|o{kU|cbV@6%Xb6y7e%`leOJ7*Z* z*pqP!9Rbagj|)P7#>#hA7jEUgca>~CF5Vf}ADKr!ZL)RpvzPh87kA^<=IVBY7T^WQsH3hFhTHoU&i zu=NBxyRi>EEA92Hjwk6-SuU2Yj(moPzj>=VD$ybDNB(SN5Ik+) zupLp%j=Ny9Mdb#=W7d>D!{Lkad2y2dmh9Jbc_|nqya!qE(qi$!k++8(9Qp1!!}#NC z<-w7%+B~_{W_fVr*{o#CgCpg^k@Db3i6)c>N5)4N-YE}`ln}-K4vwr3%8k+NU3{#k z_)N)v`y-drn;Wk7qSG8N{j=ya$17(I;~y^?#%{Gd%~9fOCl_BUPjgH!2KF?c z=J-R2znpCR<;ZatowBCtK*wJXfl;08fe!6|w&YHA;LOZsRW}_nY*L773`We-vAU%` z$zv0_#s80tBP{-Nybqq_)kz;7ErGx9*vYANqKWOj+!+xT*;-+ZdPsCJ>EvK{@+se^ zJ_{4NM95MU{2QtyNHFjoB(Q^=Y=!WpzZWs^|9jCeetpg`-YOaRvO+k)6++3tKbzHm zN6EmK4E!W3z`v9g;K{B4kBxy(R)SMT!vFl)AmOK_tUTFlypmf8-;oymRR6*CLuK?6 zcWF-qPt-Gyy01?9n*@vtgoR*}l1qWg0Jj4T&l zWajj;?}LyY#lR=#mSENgI))J7zc_&*1o)JoLwh8{b5iaeKVLdEnRQe;JtSc4|N1!g IFteTj02PnMl>h($ diff --git a/packages/core/solidity/src/zip-hardhat.test.ts.md b/packages/core/solidity/src/zip-hardhat.test.ts.md index faf4023f1..8b475a705 100644 --- a/packages/core/solidity/src/zip-hardhat.test.ts.md +++ b/packages/core/solidity/src/zip-hardhat.test.ts.md @@ -491,7 +491,7 @@ Generated by [AVA](https://avajs.dev). [ `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ contract MyContract {␊ diff --git a/packages/core/solidity/src/zip-hardhat.test.ts.snap b/packages/core/solidity/src/zip-hardhat.test.ts.snap index 024a4cbe3787b3ce87fa0e039543d283a5a04466..1690797808318961557809a6438a0c7c95a4a083 100644 GIT binary patch literal 2827 zcmV+m3-t6sRzV|#O z%%T`cvJ+ysN8|vm$C&;S$1x5Gh0Baej(jQLv)kSeymme2s2?FHSV#gQhwxe3`=Qsp zyHKx_C}v#3gC*a`Lg;}kJcK>YBIta~VoYCH)Rv#3wvZNXjg9dH3!Q}w@4@5cZu>YK z$)01{(xT?yDv8ziNPA7@-!1#Rb%G&CudhyM%&?j_Whgi(XyHq!lKG#nPEYUEdK<*UIGIxSo_q8d=!INeCe znlK?$c5mN-C}Ihf<#}=oZZZn8lElnXlsHIme{4wIe0Ld+Z`7)zD(ue82J1{-!#_f^*=z4ZOrYs_U zk0mrf$_6bfIVTwlci6tVi0k?)f@bV|#Vm_@4Qa+PZ&$R7xrz<*&@mZ^)6~rZOG#*7 z%x4Q{u_O_Bp)#J4EwH}ZgLx=f|5&Rvo zi!kz1;cP~y37_P`+jy`|gRF@yPfg&qXZRq)JzS_CHbxG4CAHmeFJ-pF`!V)qW;TC- zNG^kdSPn23#j~tzW_)u8=k?8QGuK@HDu8cdbAI*WoF+tKNd1yzYLT?0c!*T;F@%c{ z?I9wq9$p{Ig2ZV0vE*fxuE0g;7BMzRpJJ|(gD35$p53^G+~~Zqj{)dZ0+{_dW@xu^ zsM*qEhJKVAnj1@Ww&&x_ZUt+30ggj9bWiA4_U<=ODYmDc9x}e7p_E&@sp*X~xdnN3 z@41bJCz*%8NKlwh>eK|vMb%$h2=9BQ5@vfg#ZHn~G@;L#5X%EZ=zUItzDg7PL`W8u ztL5+hxvE$?ElxCy{Nz5{@JYuaj=yn6xFvX1Cmai60ApP;gvOGcvQqBnfSS$Fjt)g9QEYf*t_C74}i}{5hyl0X@0mKacr~z!N!vbC|q{ zTbO%Q4Y(mN?PJ27nWx$Ca+GTh9Ap8w)oQ_yO<0^~FH(z(xr7ST!*fU#*m-uR#P*C8?E%pS$&9XZ zkLvQ3WHLFrAk%w$RDf5|NOtUcRmqzJ=0yT%TU&NpNmS5D3q`?^SC}Cc64o~+^`{RDD5702dcwr=52;_;QrqVWl^2`vdGh-yG?ZIi-)n z5c5Vx_Gl_4qfm1CD3y({vP^DS4ao5>=CX7Es}!lA!akC@8(BQF zh4s8_K8p8N70;mx1zm}sfN>i&q#BvC|83$6PZ(e-gU0JeD30k|%0AASX1sUaG-D<@ zmbs*IX%w|d$+w=4{OXORBacr^j~i6-2_^rL*M2pe=lZ1rG1r8tB2^S!fofAbWfQzJ zBHK>Of0pQ~bTyWzdZelZx1dB5J{eCfa|uH}^LnbUloN7SN*@+tFJyi9Gd(RdDqxiX z!S5dwaQav-*=(tC_?aTG>WTpR8CKe`D8e*=azNDEP^rR%0@=Y(XZe!BL|{XNwyec> zF(2*?Fvki7(E!Gr#h8afI6yQAu}S)cS2vsJ`AGT$*VV0-j~*>Tx7t2sgP1c_(0O>D z$YmBNb9W{%!~0V*!$&*dYt9jmrM53a6Q7i1uI7mI&N>BCd=%Y#_UGqSv%eg3|8BPf zb9Zu?;C<(JRRr(W6#)Kl6@X{g0Qll$PMl`- z#VPBH|JL51`eKR%zkRj|{>A6<5$1lUbNe>jL4x?@6#m-Zt5W!fmjH+^1Ms&i0DOIQ z+7$kOwTnsN)jCi7?Ya_9e^#f^C;V>_R{EGv*3~pwikf%x!sp%9FX1eJ>kOof#eAz3 z4HHgU2P8PmeXwoO-7>~OF_{xsZarRgh2)C2k8q?87{z-DCr7`Aumi2=?3>in=3=vN zQqLhxdhbp6Cbbw_rup#n-&2PFSo{`km0rQ*M#go*9i~rPw^NeJE d36gpH+(_ncPi8Tde@&Ze{2v}lW(d4S006>1cnkml literal 2824 zcmV+j3-|OvRzVOm!xQ&ek3~JNBfsa4 z6LBnkLLZ9=00000000B+Tg`7Aw-x95JDU$TNP1@%JQCiH<=Te;fO`Od-`xP<&u;(#-UQ&ow*Yvra_!y9)g{i+pi;?xyLs~_ zs8m7aDyX~#-m6>!?^iB^%GGx-wQe+N1Y^x=|P8gT)U?~W&5PBes4q=zG7}h>w38v32YBR`Cn@9^cN5=SqMYV+-@BWkJPU|=v z$(~`_)S~8J7s$PoQ?wJ|X~6Kl#8ePQMRNqhh5sNzqQ6F{Jk10-h--$&C>5t&L5AVP z$2=ydQr{rBuz$`Z7N>#M043x{j0VS}rjkUWX=E)xHS2|IgH1IlBm(Mb8gOKz?PF%O z1|0F#tXHqvK4?Ad@A+=RgDQj&?hGUrA9P@n?nESj0i!}9D&ga$t&RInwx6s&ybl-Q zGaLlyS?Bg0uU6=&)fbM$SX+Ix>BJ~>C=3mvNAWa}jC&{yITiwP9FT-yDjP6s3UL>u zkz5L6LWivhN(JV_=a^85d0hjmKYHn2ZEXOxX=@EwTig6utt4QKRuD7&2f5U?!u1MT zby}?!yan4WcPpDGelH)S!6vY`++d2IZ;h#Z_B*H&{xih08~{0kw^@jg+hb zQ$l6u_8o{~mQp!BPhsKpvCUEdcHqc#%_iLJW7uU;#P$g7 za2&#&0o<@b#xJS7ohBiYIM-So{-HA#*RYGC6c61_?-E5(-jL1f6;J-~s1J{G*)>I) zVD4v%7zNbCWw#$wQ4o1a7}C6^4q30#3JA%k+#P)#)#-ALPNaoe#M9`Z1_#IXw?)dHD z2rHmFI)3|(-_|-;4>O})&Wu_g`rb}TqHv9cX@qmHn>aP;QKB1SJwVjPH?n}I0+5bB z=CRg*UR;NZKY<78{HlvRF<8JZ<52c7%(Do@dufcR6mSPeOdVb0*0Iel z7GdmX!ugD~27FowZ==CB3$iA*d~5=@J;Mh%?%_i9us(FiE1B)SxRl!t?f!gWEJ+NfA4y(@=?YwgUKwM9^eE;kIe6Oo*tZ+EP#9e__Avl$CxF?XV}^E| zL(P^RGxUSP(85@vv%LW4b}L!S4{;K)fp;a$t%gL zd(W%aeaU?Md5WT9Ql}q(ZWI zyjuSLUtHDl-`)n`t(yS+^Lqez?@e1RleaIRTGkPLE9r3*;uBPMbLmiYyyz|9IO|_! zRo#0A6BeqokfW}gn>@u)wfNa;G70*~YW*BkaA6-+&!2+|4(Q1h|9Q+`2A;?XoWta0 z+|t~uDnCFGc|Pr&31|BQODBwgIBAI&Tv(BbqCF(qAi2?X z?%^(9NiI{M3v#`;hXuHUMzUkqT_tY;n3oBlZEe|YCE=ix7RrJ{uP{R#64o~+^=BU9 z=(m1idPWvBj-oxMtoFE^_M}OwxI(+Yql+Z@}6r-9-@z zN47DOC~8~ihl?Z9LmASAo_^cmtNMbH5H2plcB|-Y@Wm*-L#H=x2Ynno+Z^hWJ7s{P z2=jVQ_Gl_4r%(#|D3y({vP@xFb;$89=5p)+x)gEHaoQ_R$LNhgoFR)hhJ7S+H?(+e z3+s9Ld=&4kDxO0X3c3C8|yBluhu? zh-^D8|2aliWvj6~)nip9cqJto@abr3Sx6X)nb*hqN;x5SrSxGD_9NEwKGoAgqXJeL z5d7gm38#nUlFgRtho33}tEvc~UtpyTi(^bfDEmac4V5ZPD3Bctb(Sv~Oa(SXXwzDJ z7xTehA9Jiw5Dj6%S%P^qfPF;62%Dr|_*Juset=}q_dMNd`RL&ybgS)CHb^*A1)Y!g ziCku(GIx6dGrT_~GkmlIzTzD5NNW2cH1SDEW;aJ%bk-@D;-l!^vp+vCoBidO2X{Md zSh$nN3EnsV;39apt^n|-s{nj*9e}Uin3mwJT)7y6_im?sT8`^(r`;SwdfBYj>q9w> z+S$z!xtX0;iJloDDI9D|nQ6J(X`h5@IT;Z$iK4j3(sEXK%nFZL;o&Yk?#v1gojA?v zi&NGY|Eau2^~Dqke(P)#{EN@yW6Xng`}S?Pg9Hi2Q~2xuaHa4ME&&i<2H@{k0QlzW zv?=_5D;JZ(t973E+jS+J{dA|$C;V>_R{EGv*3~q5iduB@(&ydomv9!qtM#Q!#C)?E z4^mE=2P8Z!e6VfNy>X0#axy2d+(>O=>x|O!MLCzo!iUv!H*(N1Tr8`jjy~<-}`^#CX@e?}+x1AvGoi`>S8L zg8kP3fNv`RY+MFl@yfKp{yF{1qb;N`yun6cV3R(r;3y94I`Di_acmoENOGt@Iy`UP0& a?Q>(LzdM=5RQ@$>s_}mwQrqqAMgRb{m4E2~ From 1546b2437f5ce2e3ad848d428a5a4366bd8e5cb9 Mon Sep 17 00:00:00 2001 From: Gonzalo Othacehe Date: Thu, 21 Aug 2025 16:16:10 -0300 Subject: [PATCH 27/79] add permissions component --- .../core/uniswap-hooks/src/generate/hooks.ts | 24 +++++- packages/core/uniswap-hooks/src/hooks.ts | 83 +++++++++---------- .../src/hooks/AntiSandwichHook.ts | 16 ++++ .../uniswap-hooks/src/hooks/BaseAsyncSwap.ts | 16 ++++ .../src/hooks/BaseCustomAccounting.ts | 16 ++++ .../src/hooks/BaseCustomCurve.ts | 16 ++++ .../src/hooks/BaseDynamicAfterFee.ts | 16 ++++ .../uniswap-hooks/src/hooks/BaseDynamicFee.ts | 16 ++++ .../core/uniswap-hooks/src/hooks/BaseHook.ts | 16 ++++ .../src/hooks/BaseOverrideFee.ts | 16 ++++ .../uniswap-hooks/src/hooks/LimitOrderHook.ts | 16 ++++ .../src/hooks/LiquidityPenaltyHook.ts | 16 ++++ .../core/uniswap-hooks/src/hooks/index.ts | 2 + .../ui/src/uniswap-hooks/HooksControls.svelte | 28 ++++++- 14 files changed, 253 insertions(+), 44 deletions(-) diff --git a/packages/core/uniswap-hooks/src/generate/hooks.ts b/packages/core/uniswap-hooks/src/generate/hooks.ts index 5081c4220..b8ec4b1e3 100644 --- a/packages/core/uniswap-hooks/src/generate/hooks.ts +++ b/packages/core/uniswap-hooks/src/generate/hooks.ts @@ -3,15 +3,36 @@ import { Hooks, type HookName } from '../hooks/index'; import { accessOptions } from '@openzeppelin/wizard/src/set-access-control'; import { infoOptions } from '@openzeppelin/wizard/src/set-info'; import { generateAlternatives } from '@openzeppelin/wizard/src/generate/alternatives'; +import type { Shares, Permissions } from '../hooks'; const booleanOptions = [true, false]; -const sharesOptions = [ +const sharesOptions: Shares[] = [ { options: false, name: 'MyShares', symbol: 'MSH' }, { options: 'ERC20', name: 'MyShares', symbol: 'MSH' }, { options: 'ERC6909', name: 'MyShares', symbol: 'MSH' }, ] as const; +// Is not needed to generate all permutations, just the default one. +const permissionsOptions: Permissions[] = [ + { + beforeInitialize: false, + afterInitialize: false, + beforeAddLiquidity: false, + beforeRemoveLiquidity: false, + afterAddLiquidity: false, + afterRemoveLiquidity: false, + beforeSwap: false, + afterSwap: false, + beforeDonate: false, + afterDonate: false, + beforeSwapReturnDelta: false, + afterSwapReturnDelta: false, + afterAddLiquidityReturnDelta: false, + afterRemoveLiquidityReturnDelta: false, + }, +] as const; + const hooksOptions: HookName[] = Object.keys(Hooks) as HookName[]; // @TODO: remove, faster to test compilation one by one. @@ -40,6 +61,7 @@ const blueprint = { upgradeable: [false] as const, info: infoOptions, shares: sharesOptions, + permissions: permissionsOptions, }; export function* generateHooksOptions(): Generator> { diff --git a/packages/core/uniswap-hooks/src/hooks.ts b/packages/core/uniswap-hooks/src/hooks.ts index 1d09c4b12..f7463c0b8 100644 --- a/packages/core/uniswap-hooks/src/hooks.ts +++ b/packages/core/uniswap-hooks/src/hooks.ts @@ -11,9 +11,25 @@ import { supportsInterface } from '@openzeppelin/wizard/src/common-functions'; import { printContract } from './print'; import { Hooks, type HookName } from './hooks/'; -export const sharesOptions = [false, 'ERC20', 'ERC6909', 'ERC1155'] as const; +export type Permissions = { + beforeInitialize: boolean; + afterInitialize: boolean; + beforeAddLiquidity: boolean; + beforeRemoveLiquidity: boolean; + afterAddLiquidity: boolean; + afterRemoveLiquidity: boolean; + beforeSwap: boolean; + afterSwap: boolean; + beforeDonate: boolean; + afterDonate: boolean; + beforeSwapReturnDelta: boolean; + afterSwapReturnDelta: boolean; + afterAddLiquidityReturnDelta: boolean; + afterRemoveLiquidityReturnDelta: boolean; +}; + export type Shares = { - options: (typeof sharesOptions)[number]; + options: false | 'ERC20' | 'ERC6909' | 'ERC1155'; name?: string; symbol?: string; uri?: string; @@ -27,6 +43,7 @@ export interface HooksOptions extends CommonOptions { safeCast: boolean; transientStorage: boolean; shares: Shares; + permissions: Permissions; } export const defaults: Required = { @@ -45,40 +62,22 @@ export const defaults: Required = { symbol: 'MSH', uri: '', }, -}; - -type Permissions = { - beforeInitialize: boolean; - afterInitialize: boolean; - beforeAddLiquidity: boolean; - beforeRemoveLiquidity: boolean; - afterAddLiquidity: boolean; - afterRemoveLiquidity: boolean; - beforeSwap: boolean; - afterSwap: boolean; - beforeDonate: boolean; - afterDonate: boolean; - beforeSwapReturnDelta: boolean; - afterSwapReturnDelta: boolean; - afterAddLiquidityReturnDelta: boolean; - afterRemoveLiquidityReturnDelta: boolean; -}; - -const defaultPermissions: Permissions = { - beforeInitialize: false, - afterInitialize: false, - beforeAddLiquidity: false, - beforeRemoveLiquidity: false, - afterAddLiquidity: false, - afterRemoveLiquidity: false, - beforeSwap: false, - afterSwap: false, - beforeDonate: false, - afterDonate: false, - beforeSwapReturnDelta: false, - afterSwapReturnDelta: false, - afterAddLiquidityReturnDelta: false, - afterRemoveLiquidityReturnDelta: false, + permissions: { + beforeInitialize: false, + afterInitialize: false, + beforeAddLiquidity: false, + beforeRemoveLiquidity: false, + afterAddLiquidity: false, + afterRemoveLiquidity: false, + beforeSwap: false, + afterSwap: false, + beforeDonate: false, + afterDonate: false, + beforeSwapReturnDelta: false, + afterSwapReturnDelta: false, + afterAddLiquidityReturnDelta: false, + afterRemoveLiquidityReturnDelta: false, + }, }; function withDefaults(opts: HooksOptions): Required { @@ -293,15 +292,15 @@ function addHook(c: ContractBuilder, allOpts: HooksOptions) { // Add Hook Permissions switch (allOpts.hook) { - case 'BaseHook': - addDefaultHookPermissions(c, allOpts); + // case 'BaseHook': + // break; + default: + addHookPermissions(c, allOpts); c.addImportOnly({ name: 'Hooks', path: `@uniswap/v4-core/src/libraries/Hooks.sol`, }); break; - default: - break; } } @@ -378,8 +377,8 @@ function addERC6909Shares(c: ContractBuilder, _allOpts: HooksOptions) { c.addOverride({ name: 'ERC6909' }, supportsInterface); } -function addDefaultHookPermissions(c: ContractBuilder, _allOpts: HooksOptions) { - const entries = Object.entries(defaultPermissions); +function addHookPermissions(c: ContractBuilder, _allOpts: HooksOptions) { + const entries = Object.entries(_allOpts.permissions); const permissionLines = entries.map( ([key, value], idx) => ` ${key}: ${value}${idx === entries.length - 1 ? '' : ','}`, ); diff --git a/packages/core/uniswap-hooks/src/hooks/AntiSandwichHook.ts b/packages/core/uniswap-hooks/src/hooks/AntiSandwichHook.ts index 0fea507a4..8c21377e2 100644 --- a/packages/core/uniswap-hooks/src/hooks/AntiSandwichHook.ts +++ b/packages/core/uniswap-hooks/src/hooks/AntiSandwichHook.ts @@ -32,6 +32,22 @@ const AntiSandwichHook: Hook = { }, }), }, + permissions: { + beforeInitialize: false, + afterInitialize: false, + beforeAddLiquidity: false, + afterAddLiquidity: false, + beforeRemoveLiquidity: false, + afterRemoveLiquidity: false, + beforeSwap: true, + afterSwap: true, + beforeDonate: false, + afterDonate: false, + beforeSwapReturnDelta: false, + afterSwapReturnDelta: true, + afterAddLiquidityReturnDelta: false, + afterRemoveLiquidityReturnDelta: false, + }, }; export { AntiSandwichHook }; diff --git a/packages/core/uniswap-hooks/src/hooks/BaseAsyncSwap.ts b/packages/core/uniswap-hooks/src/hooks/BaseAsyncSwap.ts index 923635eb5..35dd78bfa 100644 --- a/packages/core/uniswap-hooks/src/hooks/BaseAsyncSwap.ts +++ b/packages/core/uniswap-hooks/src/hooks/BaseAsyncSwap.ts @@ -12,6 +12,22 @@ const BaseAsyncSwap: Hook = { // no required overrides. }), }, + permissions: { + beforeInitialize: false, + afterInitialize: false, + beforeAddLiquidity: false, + beforeRemoveLiquidity: false, + afterAddLiquidity: false, + afterRemoveLiquidity: false, + beforeSwap: true, + afterSwap: false, + beforeDonate: false, + afterDonate: false, + beforeSwapReturnDelta: true, + afterSwapReturnDelta: false, + afterAddLiquidityReturnDelta: false, + afterRemoveLiquidityReturnDelta: false, + }, }; export { BaseAsyncSwap }; diff --git a/packages/core/uniswap-hooks/src/hooks/BaseCustomAccounting.ts b/packages/core/uniswap-hooks/src/hooks/BaseCustomAccounting.ts index dd87eb729..b8d92d3cf 100644 --- a/packages/core/uniswap-hooks/src/hooks/BaseCustomAccounting.ts +++ b/packages/core/uniswap-hooks/src/hooks/BaseCustomAccounting.ts @@ -46,6 +46,22 @@ const BaseCustomAccounting: Hook = { }, }), }, + permissions: { + beforeInitialize: true, + afterInitialize: false, + beforeAddLiquidity: true, + beforeRemoveLiquidity: true, + afterAddLiquidity: false, + afterRemoveLiquidity: false, + beforeSwap: false, + afterSwap: false, + beforeDonate: false, + afterDonate: false, + beforeSwapReturnDelta: false, + afterSwapReturnDelta: false, + afterAddLiquidityReturnDelta: false, + afterRemoveLiquidityReturnDelta: false, + }, }; export { BaseCustomAccounting }; diff --git a/packages/core/uniswap-hooks/src/hooks/BaseCustomCurve.ts b/packages/core/uniswap-hooks/src/hooks/BaseCustomCurve.ts index bd59ea02a..552b16624 100644 --- a/packages/core/uniswap-hooks/src/hooks/BaseCustomCurve.ts +++ b/packages/core/uniswap-hooks/src/hooks/BaseCustomCurve.ts @@ -38,6 +38,22 @@ const BaseCustomCurve: Hook = { }, }), }, + permissions: { + beforeInitialize: true, + afterInitialize: false, + beforeAddLiquidity: true, + beforeRemoveLiquidity: true, + afterAddLiquidity: false, + afterRemoveLiquidity: false, + beforeSwap: true, + afterSwap: false, + beforeDonate: false, + afterDonate: false, + beforeSwapReturnDelta: true, + afterSwapReturnDelta: false, + afterAddLiquidityReturnDelta: false, + afterRemoveLiquidityReturnDelta: false, + }, }; export { BaseCustomCurve }; diff --git a/packages/core/uniswap-hooks/src/hooks/BaseDynamicAfterFee.ts b/packages/core/uniswap-hooks/src/hooks/BaseDynamicAfterFee.ts index ab252f28b..b4ae59658 100644 --- a/packages/core/uniswap-hooks/src/hooks/BaseDynamicAfterFee.ts +++ b/packages/core/uniswap-hooks/src/hooks/BaseDynamicAfterFee.ts @@ -33,6 +33,22 @@ const BaseDynamicAfterFee: Hook = { }, }), }, + permissions: { + beforeInitialize: false, + afterInitialize: false, + beforeAddLiquidity: false, + afterAddLiquidity: false, + beforeRemoveLiquidity: false, + afterRemoveLiquidity: false, + beforeSwap: true, + afterSwap: true, + beforeDonate: false, + afterDonate: false, + beforeSwapReturnDelta: false, + afterSwapReturnDelta: true, + afterAddLiquidityReturnDelta: false, + afterRemoveLiquidityReturnDelta: false, + }, }; export { BaseDynamicAfterFee }; diff --git a/packages/core/uniswap-hooks/src/hooks/BaseDynamicFee.ts b/packages/core/uniswap-hooks/src/hooks/BaseDynamicFee.ts index 94ac0f221..f9ab81516 100644 --- a/packages/core/uniswap-hooks/src/hooks/BaseDynamicFee.ts +++ b/packages/core/uniswap-hooks/src/hooks/BaseDynamicFee.ts @@ -22,6 +22,22 @@ const BaseDynamicFee: Hook = { }, }), }, + permissions: { + beforeInitialize: false, + afterInitialize: true, + beforeAddLiquidity: false, + afterAddLiquidity: false, + beforeRemoveLiquidity: false, + afterRemoveLiquidity: false, + beforeSwap: false, + afterSwap: false, + beforeDonate: false, + afterDonate: false, + beforeSwapReturnDelta: false, + afterSwapReturnDelta: false, + afterAddLiquidityReturnDelta: false, + afterRemoveLiquidityReturnDelta: false, + }, }; export { BaseDynamicFee }; diff --git a/packages/core/uniswap-hooks/src/hooks/BaseHook.ts b/packages/core/uniswap-hooks/src/hooks/BaseHook.ts index 910237a42..5ede252cd 100644 --- a/packages/core/uniswap-hooks/src/hooks/BaseHook.ts +++ b/packages/core/uniswap-hooks/src/hooks/BaseHook.ts @@ -128,6 +128,22 @@ const BaseHook: Hook = { }, }), }, + permissions: { + beforeInitialize: false, + afterInitialize: false, + beforeAddLiquidity: false, + afterAddLiquidity: false, + beforeRemoveLiquidity: false, + afterRemoveLiquidity: false, + beforeSwap: false, + afterSwap: false, + beforeDonate: false, + afterDonate: false, + beforeSwapReturnDelta: false, + afterSwapReturnDelta: false, + afterAddLiquidityReturnDelta: false, + afterRemoveLiquidityReturnDelta: false, + }, }; export { BaseHook }; diff --git a/packages/core/uniswap-hooks/src/hooks/BaseOverrideFee.ts b/packages/core/uniswap-hooks/src/hooks/BaseOverrideFee.ts index bac0e01eb..fb57694c3 100644 --- a/packages/core/uniswap-hooks/src/hooks/BaseOverrideFee.ts +++ b/packages/core/uniswap-hooks/src/hooks/BaseOverrideFee.ts @@ -21,6 +21,22 @@ const BaseOverrideFee: Hook = { }, }), }, + permissions: { + beforeInitialize: false, + afterInitialize: false, + beforeAddLiquidity: false, + afterAddLiquidity: false, + beforeRemoveLiquidity: false, + afterRemoveLiquidity: false, + beforeSwap: false, + afterSwap: false, + beforeDonate: false, + afterDonate: false, + beforeSwapReturnDelta: false, + afterSwapReturnDelta: false, + afterAddLiquidityReturnDelta: false, + afterRemoveLiquidityReturnDelta: false, + }, }; export { BaseOverrideFee }; diff --git a/packages/core/uniswap-hooks/src/hooks/LimitOrderHook.ts b/packages/core/uniswap-hooks/src/hooks/LimitOrderHook.ts index d0d022048..6acbadf11 100644 --- a/packages/core/uniswap-hooks/src/hooks/LimitOrderHook.ts +++ b/packages/core/uniswap-hooks/src/hooks/LimitOrderHook.ts @@ -108,6 +108,22 @@ const LimitOrderHook: Hook = { }, }), }, + permissions: { + beforeInitialize: false, + afterInitialize: true, + beforeAddLiquidity: false, + beforeRemoveLiquidity: false, + afterAddLiquidity: false, + afterRemoveLiquidity: false, + beforeSwap: false, + afterSwap: true, + beforeDonate: false, + afterDonate: false, + beforeSwapReturnDelta: false, + afterSwapReturnDelta: false, + afterAddLiquidityReturnDelta: false, + afterRemoveLiquidityReturnDelta: false, + }, }; export { LimitOrderHook }; diff --git a/packages/core/uniswap-hooks/src/hooks/LiquidityPenaltyHook.ts b/packages/core/uniswap-hooks/src/hooks/LiquidityPenaltyHook.ts index 58798ec61..407543c1d 100644 --- a/packages/core/uniswap-hooks/src/hooks/LiquidityPenaltyHook.ts +++ b/packages/core/uniswap-hooks/src/hooks/LiquidityPenaltyHook.ts @@ -96,6 +96,22 @@ const LiquidityPenaltyHook: Hook = { }, }), }, + permissions: { + beforeInitialize: false, + afterInitialize: false, + beforeAddLiquidity: false, + afterAddLiquidity: true, + beforeRemoveLiquidity: false, + afterRemoveLiquidity: true, + beforeSwap: false, + afterSwap: false, + beforeDonate: false, + afterDonate: false, + beforeSwapReturnDelta: false, + afterSwapReturnDelta: false, + afterAddLiquidityReturnDelta: true, + afterRemoveLiquidityReturnDelta: true, + }, }; export { LiquidityPenaltyHook }; diff --git a/packages/core/uniswap-hooks/src/hooks/index.ts b/packages/core/uniswap-hooks/src/hooks/index.ts index 2faca999a..370ecc8fd 100644 --- a/packages/core/uniswap-hooks/src/hooks/index.ts +++ b/packages/core/uniswap-hooks/src/hooks/index.ts @@ -10,6 +10,7 @@ import { BaseDynamicAfterFee } from './BaseDynamicAfterFee'; import { AntiSandwichHook } from './AntiSandwichHook'; import { LimitOrderHook } from './LimitOrderHook'; import { LiquidityPenaltyHook } from './LiquidityPenaltyHook'; +import type { Permissions } from '../hooks'; export type HookCategory = 'Base' | 'Fee' | 'General'; @@ -31,6 +32,7 @@ export type Hook = { functions: Record; tooltipText: string; tooltipLink: string; + permissions: Permissions; }; export type HookDictionary = Record; diff --git a/packages/ui/src/uniswap-hooks/HooksControls.svelte b/packages/ui/src/uniswap-hooks/HooksControls.svelte index a3e27df44..951fb8ff3 100644 --- a/packages/ui/src/uniswap-hooks/HooksControls.svelte +++ b/packages/ui/src/uniswap-hooks/HooksControls.svelte @@ -3,7 +3,7 @@ import { infoDefaults } from '@openzeppelin/wizard'; import { hooks, Hooks } from '@openzeppelin/wizard-uniswap-hooks/src'; - import type { HookCategory, Hook, KindedOptions } from '@openzeppelin/wizard-uniswap-hooks'; + import type { HookCategory, Hook, HookName, KindedOptions } from '@openzeppelin/wizard-uniswap-hooks'; import AccessControlSection from './AccessControlSection.svelte'; import InfoSection from './InfoSection.svelte'; @@ -24,6 +24,16 @@ const hook = Hooks[key as keyof typeof Hooks]; hooksByCategory[hook.category].push(hook); } + + type PermissionKey = keyof typeof hooks.defaults.permissions; + const permissionKeys = Object.keys(hooks.defaults.permissions) as PermissionKey[]; + + let lastHook: HookName; + $: if (opts.hook !== lastHook) { + const nextPermissions = { ...hooks.defaults.permissions, ...Hooks[opts.hook].permissions }; + opts = { ...opts, permissions: nextPermissions }; + lastHook = opts.hook; + }
@@ -157,4 +167,20 @@
+
+

Permissions

+ +
+ {#each permissionKeys as permission} + + {/each} +
+
+ From 344e8c407e5a0ad84cee3056190c843ddd81fa60 Mon Sep 17 00:00:00 2001 From: Gonzalo Othacehe Date: Thu, 21 Aug 2025 16:43:02 -0300 Subject: [PATCH 28/79] up hooks permissions --- packages/core/uniswap-hooks/src/hooks.ts | 2 +- packages/ui/src/uniswap-hooks/HooksControls.svelte | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/core/uniswap-hooks/src/hooks.ts b/packages/core/uniswap-hooks/src/hooks.ts index f7463c0b8..ae4f42a0c 100644 --- a/packages/core/uniswap-hooks/src/hooks.ts +++ b/packages/core/uniswap-hooks/src/hooks.ts @@ -53,7 +53,7 @@ export const defaults: Required = { access: commonDefaults.access, upgradeable: commonDefaults.upgradeable, info: commonDefaults.info, - currencySettler: false, + currencySettler: true, safeCast: false, transientStorage: false, shares: { diff --git a/packages/ui/src/uniswap-hooks/HooksControls.svelte b/packages/ui/src/uniswap-hooks/HooksControls.svelte index 951fb8ff3..aa227a95f 100644 --- a/packages/ui/src/uniswap-hooks/HooksControls.svelte +++ b/packages/ui/src/uniswap-hooks/HooksControls.svelte @@ -30,8 +30,7 @@ let lastHook: HookName; $: if (opts.hook !== lastHook) { - const nextPermissions = { ...hooks.defaults.permissions, ...Hooks[opts.hook].permissions }; - opts = { ...opts, permissions: nextPermissions }; + opts = { ...opts, permissions: { ...Hooks[opts.hook].permissions } }; lastHook = opts.hook; } @@ -168,15 +167,19 @@
-

Permissions

+

Hook Permissions

{#each permissionKeys as permission} {/each} From 8feecce35cf5961fc3d154f18fdbf0f406b0ae57 Mon Sep 17 00:00:00 2001 From: Gonzalo Othacehe Date: Thu, 21 Aug 2025 16:49:10 -0300 Subject: [PATCH 29/79] up --- packages/ui/src/uniswap-hooks/HooksControls.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ui/src/uniswap-hooks/HooksControls.svelte b/packages/ui/src/uniswap-hooks/HooksControls.svelte index aa227a95f..b96fdd798 100644 --- a/packages/ui/src/uniswap-hooks/HooksControls.svelte +++ b/packages/ui/src/uniswap-hooks/HooksControls.svelte @@ -168,7 +168,7 @@

Hook Permissions

- +
{#each permissionKeys as permission}
+ \ No newline at end of file + diff --git a/packages/ui/src/uniswap-hooks/SharesControlsSection.svelte b/packages/ui/src/uniswap-hooks/SharesControlsSection.svelte index e7e34f87c..3daf3d327 100644 --- a/packages/ui/src/uniswap-hooks/SharesControlsSection.svelte +++ b/packages/ui/src/uniswap-hooks/SharesControlsSection.svelte @@ -10,18 +10,20 @@ $: disabled = sharesConfig === 'required' || sharesConfig === 'disabled' || specificSharesType(sharesConfig); - $: disabledReason = sharesConfig === 'required' - ? `Shares are required by ${opts.hook}` - : sharesConfig === 'disabled' - ? `Shares are disabled for ${opts.hook}` - : specificSharesType(sharesConfig) - ? `${sharesConfig} Shares are required for ${opts.hook}` - : undefined; + $: disabledReason = + sharesConfig === 'required' + ? `Shares are required by ${opts.hook}` + : sharesConfig === 'disabled' + ? `Shares are disabled for ${opts.hook}` + : specificSharesType(sharesConfig) + ? `${sharesConfig} Shares are required for ${opts.hook}` + : undefined; $: isERC20Disabled = sharesConfig === 'disabled' || (specificSharesType(sharesConfig) && 'ERC20' !== sharesConfig); - $: isERC1155Disabled = sharesConfig === 'disabled' || (specificSharesType(sharesConfig) && 'ERC1155' !== sharesConfig); - $: isERC6909Disabled = sharesConfig === 'disabled' || (specificSharesType(sharesConfig) && 'ERC6909' !== sharesConfig); - + $: isERC1155Disabled = + sharesConfig === 'disabled' || (specificSharesType(sharesConfig) && 'ERC1155' !== sharesConfig); + $: isERC6909Disabled = + sharesConfig === 'disabled' || (specificSharesType(sharesConfig) && 'ERC6909' !== sharesConfig);
{/if} -
\ No newline at end of file +