Clear phantom debt/collateral types after exact zeroing#199
Merged
nialexsan merged 2 commits intonialexsan/multi-debtfrom Mar 4, 2026
Merged
Clear phantom debt/collateral types after exact zeroing#199nialexsan merged 2 commits intonialexsan/multi-debtfrom
nialexsan merged 2 commits intonialexsan/multi-debtfrom
Conversation
6 tasks
nialexsan
approved these changes
Mar 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix phantom debt/collateral type retention after exact zeroing so one-type guardrails in PR #184 are released correctly when a type balance is fully cleared.
Previous behavior (bug example)
Example position lifecycle:
MOETFLOWAction sequence:
300 FLOW(debt type becomesFLOW).300 FLOW(debt balance reaches0).100 MOET.Before this fix:
FLOWeven at zero balance.validateDebtTypetreated position as still locked toFLOWdebt.MOETincorrectly failed due to a phantom/stale debt type.Equivalent issue also existed for collateral:
Why this fix is needed
PR #184 intentionally adds temporary one-collateral/one-debt constraints. Those constraints must track active non-zero balances, not stale zero balances. Otherwise users can get permanently constrained by phantom types after valid exact repay/withdraw flows.
What changed
FlowALPModels.cdc:getDebtTypes()now includes only types withscaledBalance > 0.0.getCollateralTypes()now includes only types withscaledBalance > 0.0.Tests
cadence/tests/debt_type_constraint_three_token_test.cdc:testExactRepayClearsDebtTypeConstrainttestExactFullWithdrawClearsCollateralTypeConstraintflow test cadence/tests/debt_type_constraint_three_token_test.cdcflow test cadence/tests/single_token_constraint_test.cdc