Liquidation Mechanism: Phases 1 & 2 (core + DEX)#41
Conversation
…override, warm-up, no auction)
…oteLiquidation, liquidateRepayForSeize; add scripts and tests
- Update cadence/contracts/TidalProtocol.cdc - Update cadence/tests/liquidation_phase1_test.cdc - Update cadence/transactions/tidal-protocol/pool-management/liquidate_repay_for_seize.cdc - Update LIQUIDATION_MECHANISM_DESIGN.md
…ite and document failing liquidation tests
nialexsan
left a comment
There was a problem hiding this comment.
I've realized that I need these functions in the user initialized tide closure to capture loss
|
|
||
| /// Liquidation quote output | ||
| access(all) struct LiquidationQuote { | ||
| access(all) let requiredRepay: UFix64 |
There was a problem hiding this comment.
do we need a repay type, or is it safe to assume that the type is always MOET?
There was a problem hiding this comment.
@nialexsan Not always MOET — the repay token is whatever the position’s debt token is. We pass the debt type into both quote and execution, so the quote doesn’t need to repeat it (it would be redundant).
…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.
…on struct sinks/sources for CLI compat" This reverts commit 664e165.
…RSION=v2.7.2" This reverts commit d902ff4.
…od path issues" This reverts commit 950fb52.
…w/flow-cli/v2)" This reverts commit 2328f13.
This reverts commit 18ef6c9.
…ot available)" This reverts commit 8436f1c.
This reverts commit 48d4d07.
…re)" This reverts commit 472d6bb.
…ate collisions" This reverts commit eb30399.
…r; do not auto-run in deployContracts
…s and insolvency test; keep repay flow using withdraw path
…ToConsumer(); repay via sink.depositCapacity to avoid EParticipant
…rage path; all tests pass locally with flow test
…feature/liquidation-mechanism
…Participant+EPosition
cadence/contracts/TidalProtocol.cdc
Outdated
| newProtocolFee = protocolFeeBps! | ||
| } | ||
| emit LiquidationParamsUpdated(poolUUID: self.uuid) | ||
| emit LiquidationParamsUpdatedV2(poolUUID: self.uuid, targetHF: newTarget, warmupSec: newWarmup, protocolFeeBps: newProtocolFee) |
There was a problem hiding this comment.
We should consolidate these to a single event
cadence/contracts/TidalProtocol.cdc
Outdated
| access(all) event LiquidationParamsUpdated(poolUUID: UInt64) | ||
| // Backward-compatible v2 event including updated params for observability | ||
| access(all) event LiquidationParamsUpdatedV2( | ||
| poolUUID: UInt64, | ||
| targetHF: UInt128, | ||
| warmupSec: UInt64, | ||
| protocolFeeBps: UInt16 | ||
| ) |
There was a problem hiding this comment.
Same suggestion as elsewhere - we should consolidate these events.
cadence/contracts/TidalProtocol.cdc
Outdated
| access(self) fun internalRepayInferred(pid: UInt64, from: @{FungibleToken.Vault}): UFix64 { | ||
| let inferredType = from.getType() | ||
| return self.internalRepay(pid: pid, debtType: inferredType, from: <-from) | ||
| } |
There was a problem hiding this comment.
I would think based on the assertions in internalRepay we can just update internalRepay to this function signature to avoid this extra passthrough method.
cadence/contracts/TidalProtocol.cdc
Outdated
| access(EGovernance) fun addSupportedTokenWithLiquidationBonus( | ||
| tokenType: Type, | ||
| collateralFactor: UFix64, | ||
| borrowFactor: UFix64, | ||
| interestCurve: {InterestCurve}, | ||
| depositRate: UFix64, | ||
| depositCapacityCap: UFix64, | ||
| liquidationBonus: UFix64? | ||
| ) { | ||
| self.addSupportedToken( | ||
| tokenType: tokenType, | ||
| collateralFactor: collateralFactor, | ||
| borrowFactor: borrowFactor, | ||
| interestCurve: interestCurve, | ||
| depositRate: depositRate, | ||
| depositCapacityCap: depositCapacityCap | ||
| ) | ||
| if liquidationBonus != nil { | ||
| self.setTokenLiquidationBonus(tokenType: tokenType, bonus: liquidationBonus!) | ||
| } | ||
| } |
There was a problem hiding this comment.
This can be consolidated with addSupportedToken
sisyphusSmiling
left a comment
There was a problem hiding this comment.
Changes in this PR were quite hard to follow without conversation in or author resolution of the previous comments. I understand the desire to use AI tooling to address changes, but I don't think choice of tooling should drive PR practice. In future PRs, it would be helpful as a reviewer to use inline comments to track discussion and progress on the topics?
I left comments under outstanding items I think should be addressed before merging.
|
@sisyphusSmiling Thanks for the review. I will address the new items before merging. I understand the inconvenience faced by the reviewer if inline comments are not used. Indeed, using Github CLI via AI is not able to tap into the inline comments and code referencing. I have been actively looking for this soultion. In any case, I will ensure better reviewer experience in the future. |
…uidationParamsUpdated with params; simplify internalRepay to infer type and remove passthrough; remove addSupportedTokenWithLiquidationBonus in favor of addSupportedToken + setTokenLiquidationBonus; update design doc event signature.
|
Addressed the outstanding review items:
Search shows no scripts/txs referencing the removed event or helper names. All Cadence tests pass locally via ./run_tests.sh. Pushed to the PR head branch feature/liquidation-mechanism in commit 42c7c4a. |
Summary
This PR introduces the liquidation system to Tidal Protocol and now includes both Phase 1 (core repay‑for‑seize) and Phase 2 (DEX‑based liquidation). In plain terms: when a position becomes unsafe, a keeper can repay part of the borrower’s debt and take some collateral so the position is brought back to a safe level.
What’s new here compared to the main branch
Safety guardrails and behavior
Tests and status
./run_tests.sh.Note on PRs