Skip to content

feat(vaultV2): include forcedeallocate capacity in maxWithdraw#526

Open
Foulks-Plb wants to merge 9 commits intomainfrom
feature/vmv1-4841-include-forcedeallocate-capacity-in-maxwithdraw-for-vaultv2
Open

feat(vaultV2): include forcedeallocate capacity in maxWithdraw#526
Foulks-Plb wants to merge 9 commits intomainfrom
feature/vmv1-4841-include-forcedeallocate-capacity-in-maxwithdraw-for-vaultv2

Conversation

@Foulks-Plb
Copy link
Contributor

@Foulks-Plb Foulks-Plb commented Mar 12, 2026

🟢 Include Force Deallocate Capacity in maxWithdraw for VaultV2

Summary

Adds a new maxForceWithdraw method to AccrualVaultV2 that computes the maximum withdrawable assets by including liquidity freed from force-deallocating adapters with zero penalty.

Logic

  1. Start with maxWithdraw: computes the standard withdrawable amount based on idle balance + liquidity adapter capacity.

  2. 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.

  3. Add force-deallocation liquidity: iterate over all adapters and sum maxWithdrawAvailable() for each adapter that:

    • is not the liquidityAdapter (already accounted for in step 1),
    • has a force-deallocate penalty of exactly 0 (to avoid asset losses).
  4. Return:

    • If the requested assets still exceed total liquidity → return the total liquidity with limiter VaultV2_ForceLiquidity.
    • Otherwise → return the full asset value of the shares with limiter VaultV2_ForceBalance.

@Foulks-Plb Foulks-Plb self-assigned this Mar 12, 2026
@linear
Copy link

linear bot commented Mar 12, 2026

@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@Foulks-Plb Foulks-Plb changed the base branch from main to feature/vmv1-4865-add-penality-for-vaultv2-adapter-in-core-sdk March 12, 2026 15:13
@Foulks-Plb
Copy link
Contributor Author

@codex review

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. You're on a roll.

ℹ️ 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".

@Foulks-Plb Foulks-Plb changed the title feat(vaultV2): include forcedeallocate capacity in maxwithdraw feat(vaultV2): include forcedeallocate capacity in maxWithdraw Mar 12, 2026
@Foulks-Plb
Copy link
Contributor Author

@codex review

@Foulks-Plb Foulks-Plb requested a review from Rubilmax March 16, 2026 11:37
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 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;

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's actually very relevant. One again, nice catch codex

Base automatically changed from feature/vmv1-4865-add-penality-for-vaultv2-adapter-in-core-sdk to main March 16, 2026 12:15
Comment on lines +9 to +10
VaultV2_ForceLiquidity = "VaultV2_ForceLiquidity",
VaultV2_ForceBalance = "VaultV2_ForceBalance",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
VaultV2_ForceLiquidity = "VaultV2_ForceLiquidity",
VaultV2_ForceBalance = "VaultV2_ForceBalance",
vaultV2_forceDeallocateLiquidity = "vaultV2_forceDeallocateLiquidity",
vaultV2_forceDeallocateBalance = "vaultV2_forceDeallocateBalance",

This is minor, just to match existing convention

Comment on lines -433 to -434
vaultV2Test(
"should withdraw full amount when liquidityAdapter is zero address",
Copy link
Collaborator

Choose a reason for hiding this comment

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

not sure to get why these tests are removed

let liquidity = value;

for (const adapter of this.accrualAdapters) {
if (adapter.address === this.liquidityAdapter) continue;
Copy link
Collaborator

Choose a reason for hiding this comment

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

That's actually very relevant. One again, nice catch codex

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.

2 participants