Skip to content

fix: reconcile close-position residual vaults by type#198

Draft
liobrasil wants to merge 3 commits intomainfrom
lionel/fix-close-position-return-order
Draft

fix: reconcile close-position residual vaults by type#198
liobrasil wants to merge 3 commits intomainfrom
lionel/fix-close-position-return-order

Conversation

@liobrasil
Copy link
Contributor

@liobrasil liobrasil commented Mar 6, 2026

Problem

  • FlowALP.closePosition() returns one vault per token type, and the return order is not guaranteed.
  • FlowYieldVaultsStrategiesV2.FUSDEVStrategy.closePosition() previously assumed removeFirst() was always the collateral vault.
  • That meant a close could either return the wrong vault type and revert, or silently destroy positive-balance residual vaults such as MOET overpayment dust.
  • The strategy also stored per-vault swappers in contract config and did not remove them on burn.

What Changed

  • Added _extractCollateralFromClosedPosition() to reconcile all vaults returned by closePosition() by type instead of trusting array order.
  • Merged every returned vault of the requested collateral type into the final collateral vault.
  • Added and stored a MOET -> collateral swapper so MOET residuals are converted back into the requested collateral before returning from close.
  • Updated the mock strategy to use the same order-independent residual handling.
  • Updated close-path comments in FlowYieldVaults so the interface describes the actual behavior.
  • Extended burnCallback() to remove both stored swapper config entries when the strategy is destroyed.

Issues Solved

  • Fixes close-path failures caused by assuming the first vault returned by FlowALP.closePosition() is always collateral.
  • Prevents silent loss of MOET residuals / overpayment dust by converting them back into the requested collateral before returning from close.
  • Makes close handling deterministic with respect to returned vault ordering by reconciling all returned vaults by type.
  • Prevents contract config storage from leaking yieldToMoetSwapper_<id> and moetToCollateralSwapper_<id> entries after strategy burn.

@liobrasil liobrasil requested a review from a team as a code owner March 6, 2026 22:28
@liobrasil liobrasil marked this pull request as draft March 9, 2026 17:39
Base automatically changed from nialexsan/dust-debug-flowalp to main March 10, 2026 00:57
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.

1 participant