feat(vaultV2): include forcedeallocate capacity in maxWithdraw#526
feat(vaultV2): include forcedeallocate capacity in maxWithdraw#526Foulks-Plb wants to merge 9 commits intomainfrom
Conversation
…ilable to adapters
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
…up code formatting
…nd clarify limit reasons
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 06f27eda78
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let liquidity = value; | ||
|
|
||
| for (const adapter of this.accrualAdapters) { | ||
| if (adapter.address === this.liquidityAdapter) continue; |
There was a problem hiding this comment.
Account for liquidity adapter in force-withdraw capacity
maxForceWithdraw unconditionally skips this.liquidityAdapter, but maxWithdraw only includes that adapter's capacity for the single liquidityData route; for Morpho market adapters, maxWithdraw(data) reads one market while maxDeallocatableAssets() sums all markets/positions. In vaults where the liquidity adapter has additional zero-penalty deallocatable positions, this underestimates withdrawable assets and can incorrectly return a liquidity-limited result even though a full force-withdraw is possible.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
That's actually very relevant. One again, nice catch codex
| VaultV2_ForceLiquidity = "VaultV2_ForceLiquidity", | ||
| VaultV2_ForceBalance = "VaultV2_ForceBalance", |
There was a problem hiding this comment.
| VaultV2_ForceLiquidity = "VaultV2_ForceLiquidity", | |
| VaultV2_ForceBalance = "VaultV2_ForceBalance", | |
| vaultV2_forceDeallocateLiquidity = "vaultV2_forceDeallocateLiquidity", | |
| vaultV2_forceDeallocateBalance = "vaultV2_forceDeallocateBalance", |
This is minor, just to match existing convention
| vaultV2Test( | ||
| "should withdraw full amount when liquidityAdapter is zero address", |
There was a problem hiding this comment.
not sure to get why these tests are removed
| let liquidity = value; | ||
|
|
||
| for (const adapter of this.accrualAdapters) { | ||
| if (adapter.address === this.liquidityAdapter) continue; |
There was a problem hiding this comment.
That's actually very relevant. One again, nice catch codex
🟢 Include Force Deallocate Capacity in
maxWithdrawfor VaultV2Summary
Adds a new
maxForceWithdrawmethod toAccrualVaultV2that computes the maximum withdrawable assets by including liquidity freed from force-deallocating adapters with zero penalty.Logic
Start with
maxWithdraw: computes the standard withdrawable amount based on idle balance + liquidity adapter capacity.Early return: if the limiter is not
Liquidity(i.e. the user's shares are the bottleneck, not the available liquidity), return immediately, force-deallocation is unnecessary.Add force-deallocation liquidity: iterate over all adapters and sum
maxWithdrawAvailable()for each adapter that:liquidityAdapter(already accounted for in step 1),Return:
VaultV2_ForceLiquidity.VaultV2_ForceBalance.