Skip to content

Enable MorphoV2 WithdrawAll#2783

Open
sparrowDom wants to merge 7 commits intomasterfrom
sparrowDom/morphoV2WithdrawAll
Open

Enable MorphoV2 WithdrawAll#2783
sparrowDom wants to merge 7 commits intomasterfrom
sparrowDom/morphoV2WithdrawAll

Conversation

@sparrowDom
Copy link
Member

@sparrowDom sparrowDom commented Feb 3, 2026

PR: Morpho V2 Liquidity Estimation + Safe WithdrawAll

Summary

This PR updates the Morpho V2 strategy to better estimate immediate liquidity and safely cap withdrawAll, while acknowledging that only Morpho V1 adapters are supported for extended liquidity checks.

Why

Morpho V2 vaults can configure a liquidity adapter. When that adapter points to a Morpho V1 vault, the strategy can query the V1 vault’s maxWithdraw to include additional immediately available liquidity. If the adapter is something else, the strategy intentionally does not assume additional liquidity. This avoids over‑estimating withdrawable amounts and prevents failed withdrawals.

Key Changes

  • Liquidity estimation: withdrawAll now accounts for adapter‑backed liquidity when the adapter is a Morpho V1 vault.
  • Safe withdraw cap: withdrawAll respects the actual available liquidity in the V2 vault and its adapter.
  • Adapter validation: Enforces that the adapter used for estimation is the expected Morpho V1 adapter.
  • Deployment: Adds a mainnet deployment file

Notes / Limitations

  • Extended liquidity estimation is only applied when the V2 vault’s adapter is a Morpho V1 vault. Other adapter types are intentionally ignored to avoid incorrect liquidity assumptions.

@codecov
Copy link

codecov bot commented Feb 3, 2026

Codecov Report

❌ Patch coverage is 88.88889% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 39.67%. Comparing base (766c645) to head (1f943d8).

Files with missing lines Patch % Lines
...ontracts/contracts/strategies/MorphoV2Strategy.sol 88.88% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2783      +/-   ##
==========================================
+ Coverage   39.02%   39.67%   +0.64%     
==========================================
  Files         126      127       +1     
  Lines        5825     5843      +18     
  Branches     1546     1550       +4     
==========================================
+ Hits         2273     2318      +45     
+ Misses       3550     3523      -27     
  Partials        2        2              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sparrowDom sparrowDom marked this pull request as ready for review February 5, 2026 12:16
clement-ux
clement-ux previously approved these changes Feb 6, 2026
Copy link
Collaborator

@clement-ux clement-ux left a comment

Choose a reason for hiding this comment

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

Everything looks good to me.

Note on withdrawAll():

When calling withdrawAll(), the strategy only withdraws what is currently liquid in the Morpho V2 vault (idle USDC + V1 adapter available liquidity). Under high utilization, some funds may remain in the strategy after the call. This is expected behavior, not a bug, but something to keep in mind operationally -- multiple calls or waiting for liquidity to free up may be needed to fully exit the position.

@sparrowDom
Copy link
Member Author

good point @clement-ux have expressed this more verbosely in the comment: 1f943d8

clement-ux
clement-ux previously approved these changes Feb 6, 2026
Copy link
Collaborator

@naddison36 naddison36 left a comment

Choose a reason for hiding this comment

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

I think we should also change withdrawAll on Generalized4626Strategy so it calls maxRedeem instead of balanceOf. This way it redeems what it can.

This doesn't work for Morpho v2 vaults as they just return zero for all their max functions. For for vaults that are ERC-4626 compliant, the change to Generalized4626Strategy will work.

@sparrowDom sparrowDom force-pushed the sparrowDom/morphoV2WithdrawAll branch from ef0a057 to 9ee8188 Compare February 10, 2026 14:40
@sparrowDom
Copy link
Member Author

@naddison36 good thinking thanks. Done here: 9ee8188

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.

3 participants