-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Summary
closeYieldVault can succeed while leaving a tiny non-zero FCM position (small residual debt/collateral).
Root cause: close flow relies on UFix64 (8 decimals) plus swap quote rounding, so exact repay amounts are not always representable in one pass.
This is separate from #152.
Why this matters
- A user expects "close" to mean fully closed.
- Current behavior can leave a small residual position after close.
- Residual is usually tiny, but this breaks close invariants and creates inconsistent behavior.
Expected behavior
On close, protocol should either:
- Fully unwind debt/collateral to zero (or a defined dust threshold), then burn; or
- Revert and keep vault open if full unwind cannot be guaranteed.
Acceptance criteria
- After
closeYieldVault, residual debt/collateral is zero (or <= explicit dust threshold). - No successful close that burns strategy while leaving non-zero position above threshold.
- Precision edge-case tests added around UFix64 minimum unit (
0.00000001).
Numerical example (what is happening)
Observed close flow (mainnet investigation):
-
Before close:
- Collateral:
0.00001000 WETH - Debt:
0.02038486 MOET getYieldVaultBalance():0.00000996 WETH(less than full collateral)
- Collateral:
-
During close:
0.01911391 tauUSDFvswapped to0.02030333 MOETfor repayment
-
After close:
- Residual debt:
0.00008153 MOET - Residual collateral:
0.00000004 WETH
- Residual debt:
Precision constraint:
- Price used:
3312.54037990 MOET/WETH - Exact collateral needed for residual debt:
~0.00000002461253 WETH - UFix64 step is
0.00000001, so exact amount is not representable0.00000002underpays0.00000003clears debt (with small overpayment)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels