delvtech / hyperdrive

An automated market maker for fixed and variable yield with on-demand terms.
Apache License 2.0
33 stars 4 forks source link

Uni v3 Zap #1179

Closed jalextowle closed 1 month ago

jalextowle commented 2 months ago

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:

coveralls commented 2 months ago

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


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%
<!-- Total: 150 168 89.29% -->
Totals Coverage Status
Change from base Build 11261243207: 0.02%
Covered Lines: 2639
Relevant Lines: 2969

πŸ’› - Coveralls
github-actions[bot] commented 2 months ago

Hyperdrive Gas Benchmark

Benchmark suite Current: 6777136ba8076c68f5186f0d4ba4f152d5b74a54 Previous: 540732a98e843ec15a453bbeb63a80676580b11c 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.