D6: Partial-unwind liquidation protection#230
Open
NnamdiCyber wants to merge 1 commit into
Open
Conversation
- Add orange_hf (trigger) and target_hf (restore-to) fields to Config - Replace compute_unwind_loops with compute_partial_unwind: closed-form minimal repay/withdraw to restore HF to target_hf in one atomic step - Add submit_partial_unwind to blend_pool: single [Withdraw, Repay] submit - rebalance() now triggers on HF < orange_hf and executes partial unwind - Tests: already_at_target, no_debt, single_loop (minimality), max_loops, unhealthy_position
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
Implements orange-zone partial unwind: when HF drops below a configurable
orange_hfthreshold, unwind the minimal amount needed to restoretarget_hfrather than forcing a full close.Changes
storage.rs— Two newConfigfields:orange_hf— trigger threshold (partial unwind fires when HF drops below this)target_hf— HF to restore to after unwindleverage.rs— Replacedcompute_unwind_loopswithcompute_partial_unwind:Closed-form solution for the minimal repay amount
x:Returns
(0, 0)if already at target or no debt.blend_pool.rs— Newsubmit_partial_unwind(repay, withdraw, config): single atomic[WithdrawCollateral, Repay]submit with exact amounts.lib.rs— Constructor acceptsorange_hf(arg 8) andtarget_hf(arg 9).rebalance()triggers onhf < orange_hf, permissionless (keeper- or user-callable).Tests
test_partial_unwind_already_at_target— returns (0, 0)test_partial_unwind_no_debt— returns (0, 0)test_partial_unwind_single_loop— correct amount, minimality verifiedtest_partial_unwind_max_loops— partial (not full) close restores HFtest_partial_unwind_unhealthy_position— HF restored to targetCloses #47