Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uni v3 Zap #1179

Merged
merged 34 commits into from
Oct 12, 2024
Merged

Uni v3 Zap #1179

merged 34 commits into from
Oct 12, 2024

Conversation

jalextowle
Copy link
Contributor

@jalextowle jalextowle commented Sep 25, 2024

Description

This PR adds a zap contract that supports generalized swapping between assets using Uniswap V3. Each Hyperdrive trading or LP function has a direct anologue in the zap contract that exposes all of the parameters as well as a few extra parameters for things like the Uniswap swap object (ISwapRouter.ExactInputParams) and special-case parameters to handle different edge-cases in the zap.

Extensive tests were added that should test the different paths through these functions. Special care was taken to verify that ETH, WETH, and rebasing tokens are properly handled by the zap contract. Since Uniswap v3 doesn't really support ETH as a first-class citizen in all situations, there are several flows within the zap contract where ETH will be converted to WETH or vice-versa. For the most part, this is unopinionated and will support all use-cases, but in the case of zapping funds out of the zap, WETH will always be unwrapped into ETH before sending it to the user.

Some notable things to watch out for are:

  • Users may receive funds in the zapped asset rather than their original asset as a result of openShortZap's lack of precision compared to the other flows. This is unavoidable because of the way that Hyperdrive's openShort logic functions.
  • Tokens can be "wrapped" before the Uniswap swap is executed. This makes it possible to support zaps from rebasing tokens like stETH and eETH into other assets.
  • This contract does not have any of its own events. When I talked to @ryangoree about the original requirements, he said that he didn't think events would be required. We can always revisit this if it turns out that we need them. For now, the only events will be the underlying Uniswap V3 and Hyperdrive events.

@coveralls
Copy link
Collaborator

coveralls commented Sep 25, 2024

Pull Request Test Coverage Report for Build 11282077538

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 150 of 168 (89.29%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 88.885%

Changes Missing Coverage Covered Lines Changed/Added Lines %
contracts/src/libraries/UniV3Path.sol 2 4 50.0%
contracts/src/zaps/UniV3Zap.sol 148 164 90.24%
Totals Coverage Status
Change from base Build 11261243207: 0.02%
Covered Lines: 2639
Relevant Lines: 2969

💛 - Coveralls

Copy link

github-actions bot commented Sep 25, 2024

Hyperdrive Gas Benchmark

Benchmark suite Current: 6777136 Previous: 540732a Deviation Status
addLiquidity: min 33812 gas 33812 gas 0% 🟰
addLiquidity: avg 193051 gas 193001 gas 0.0259% 🚨
addLiquidity: max 474677 gas 474677 gas 0% 🟰
checkpoint: min 40338 gas 40338 gas 0% 🟰
checkpoint: avg 147682 gas 147705 gas -0.0156%
checkpoint: max 259386 gas 259386 gas 0% 🟰
closeLong: min 31390 gas 31390 gas 0% 🟰
closeLong: avg 129896 gas 130031 gas -0.1038%
closeLong: max 2539405 gas 2539405 gas 0% 🟰
closeShort: min 31378 gas 31378 gas 0% 🟰
closeShort: avg 124783 gas 124916 gas -0.1065%
closeShort: max 277335 gas 277335 gas 0% 🟰
initialize: min 31356 gas 31356 gas 0% 🟰
initialize: avg 355841 gas 355865 gas -0.0067%
initialize: max 424801 gas 424801 gas 0% 🟰
openLong: min 33370 gas 33370 gas 0% 🟰
openLong: avg 173786 gas 173869 gas -0.0477%
openLong: max 339778 gas 339778 gas 0% 🟰
openShort: min 33936 gas 33936 gas 0% 🟰
openShort: avg 172587 gas 172411 gas 0.1021% 🚨
openShort: max 414941 gas 414861 gas 0.0193% 🚨
redeemWithdrawalShares: min 31240 gas 31240 gas 0% 🟰
redeemWithdrawalShares: avg 74247 gas 74244 gas 0.0040% 🚨
redeemWithdrawalShares: max 311225 gas 311225 gas 0% 🟰
removeLiquidity: min 31246 gas 31246 gas 0% 🟰
removeLiquidity: avg 216956 gas 217006 gas -0.0230%
removeLiquidity: max 403402 gas 403671 gas -0.0666%

This comment was automatically generated by workflow using github-action-benchmark.

Copy link
Contributor

@jrhea jrhea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! I just had a few qs and some nits

Copy link
Contributor

@mcclurejt mcclurejt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks awesome, really great work on the documentation... super digestable

contracts/src/zaps/UniV3Zap.sol Outdated Show resolved Hide resolved
@jalextowle jalextowle enabled auto-merge October 12, 2024 00:43
@jalextowle jalextowle added this pull request to the merge queue Oct 12, 2024
Merged via the queue into main with commit ba08c2f Oct 12, 2024
30 of 34 checks passed
@jalextowle jalextowle deleted the jalextowle/zaps/uni-v3-zap branch October 12, 2024 01:52
jalextowle added a commit that referenced this pull request Oct 15, 2024
* forge install: v3-periphery

v1.3.0

* Added a basic Uniswap v3 zap contract

* Added a Uni v3 zap for `closeLong` and improved the zap for `openLong`

* Added a zap for `addLiquidity`

* Cleaned up the validation logic for Uni v3 zaps

* Adds zaps for `removeLiquidity` and `redeemWithdrawalShares`

* Added the remaining zaps

* Started writing tests for `addLiquidityZap`

* Updated the zap to use multi-hop routing

* Wrote some more tests

* Refactored the `addLiquidityZap` tests

* Added tests for `openLongZap`

* Added a full test suite for `openLongZap`

* Broke out the zap tests and added test for `openShortZap`

* Added support for zaps out starting with ETH

* Added tests for `removeLiquidity`

* Added tests for `redeemWithdrawalSharesZap`

* Added tests for `redeemWithdrawalSharesZap`

* Added tests for `closeLongZap`

* Added tests for `closeShortZap`

* Cleaned up the tests

* Bump the version

* Remaining cleanup

* Fixed the UniV3Zap

* Added wrapping tests

* Some cleanup

* Some cleanup

* Addressed review feedback from @jrhea

* Addressed remaining review feedback from @jrhea

* Appeased the linter gods

* Addressed review feedback from @mcclurejt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants