Liquidation Phase 2 (DEX): stacked on #41#43
Merged
kgrgpg merged 15 commits intofeature/liquidation-mechanismfrom Sep 3, 2025
Merged
Liquidation Phase 2 (DEX): stacked on #41#43kgrgpg merged 15 commits intofeature/liquidation-mechanismfrom
kgrgpg merged 15 commits intofeature/liquidation-mechanismfrom
Conversation
…n- Add allowedSwapperTypes + dexOracleDeviationBps with getters/governance setter\n- Implement liquidateViaDex with oracle dev guard + slippage minRepay\n- Add get_dex_liquidation_config script\n- Add set_dex_liquidation_config governance tx\n- Add liquidate_via_dex management tx
…hase2-merged for best Phase 2 solution
… + separate DEX test\n- Pool.liquidateViaDex takes Swapper, adds oracle/slippage/hops guards\n- Add Pool.internalSeize/internalRepay (resource)\n- Add MockDexSwapper + liquidate_via_mock_dex tx\n- Move DEX test into liquidation_phase2_dex_test.cdc; remove from phase1
…per deploy to avoid address lookup issues
…orts resolve in tests
…ting via governance
…iation guard (0.7 Flow oracle)
…StoragePath for swapper source
Tests: add snapshot-based safe reset and handle zero-quote insolvency/rounding edges. Docs: clarify repay-all redemption, partial-to-above-one, and insolvency scenarios. Contract: quoteLiquidation rounds up and avoids HF-worsening keeper steps with zero-quote/full-seize fallback.
…allback in quoteLiquidation Tests: add insolvency_redemption_test.cdc; update repay_and_close_position.cdc to repay then withdraw.\nContract: discrete bounded-search fallback (~16 steps) in quoteLiquidation when direct solve would worsen HF; preserves determinism and caps.
Contributor
Author
|
Merged 'feature/liquidation-phase2-merged' into base 'feature/liquidation-mechanism'. Reason: common Phase 1 liquidation edits were necessary in the base (HF-maximizing fallback, borrower insolvency redemption test, and related helpers). To minimize cherry-picking and keep history coherent, we merged the changes directly into the base branch. Status: base updated and tests pass locally (one pre-existing rounding-guard assertion remains unchanged). Phase 2 work stays on this branch as-is. |
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.
Stacked on #41 (base: feature/liquidation-mechanism).
What
cadence/contracts/TidalProtocol.cdc:liquidateViaDex(...)andLiquidationExecutedViaDexevent.allowedSwapperTypesallowlist (by Type)dexOracleDeviationBps(max DEX-implied vs oracle deviation)dexMaxSlippageBps,dexMaxRouteHopsgetDexLiquidationConfig()andsetDexLiquidationConfig(...)internalSeize,internalRepay.pool-management/liquidate_via_dex.cdcpool-management/liquidate_via_mock_dex.cdc(test-only convenience)pool-governance/set_dex_liquidation_config.cdcscripts/tidal-protocol/get_dex_liquidation_config.cdccontracts/mocks/MockDexSwapper.cdcfor testing; updatesflow.jsontesting alias.liquidation_phase2_dex_test.cdc+ updates totest_helpers.cdc,liquidation_phase1_test.cdc.How it works
maxSeizeAmount.seizeType/debtType.dexOracleDeviationBps.internalSeize) and swap viaDeFiActions.Swapper.slippageBps ≤ dexMaxSlippageBps.internalRepay) and emitLiquidationExecutedViaDex.Defaults
allowedSwapperTypes = {}(must be allowlisted by governance)dexOracleDeviationBps = 300(3%)dexMaxSlippageBps = 100(1%)dexMaxRouteHops = 3Diff vs base (#41)
cadence/contracts/TidalProtocol.cdc,cadence/tests/liquidation_phase1_test.cdc,cadence/tests/test_helpers.cdc,flow.jsoncadence/contracts/mocks/MockDexSwapper.cdc,cadence/tests/liquidation_phase2_dex_test.cdc,cadence/scripts/tidal-protocol/get_dex_liquidation_config.cdc,cadence/transactions/tidal-protocol/pool-governance/set_dex_liquidation_config.cdc,cadence/transactions/tidal-protocol/pool-management/liquidate_via_dex.cdc,cadence/transactions/tidal-protocol/pool-management/liquidate_via_mock_dex.cdcTesting notes
MockDexSwapper, setspriceRatioto satisfy the oracle deviation guard, funds the MOET vault for swap output, and liquidates via the DEX path.Risks and considerations
dexOracleDeviationBpsanddexMaxSlippageBpsto operational preferences.MockDexSwapperis test-only and should not be used in production.Stacking
feature/liquidation-mechanism). Merge Liquidation Mechanism: Phases 1 & 2 (core + DEX) #41 first; then this PR can be retargeted tomainif desired.