Skip to content

Conversation

@kgrgpg
Copy link
Contributor

@kgrgpg kgrgpg commented Sep 16, 2025

This PR aligns Tidal SC root tests and harness with the new Liquidation Mechanism implemented in onflow/TidalProtocol (Phases 1 & 2: core repay‑for‑seize and DEX liquidation), as proposed and merged in the upstream protocol PR:

Why:

  • Our root repo tests (Tidal SC) were still targeting pre‑liquidation semantics. This updates test scaffolding and configuration so liquidation flows match the upstream model and our LIQUIDATION_TEST_PLAN.md acceptance criteria:
    • Rebalancing recovers position health to ~1.3 when Yield top‑up is available
    • With Yield price forced to 0 (top‑up ineffective), liquidation executes to restore HF to ~1.05 target
    • DEX liquidation path uses oracle/slippage/allowlist guardrails

What changed (high‑level):

  • Test harness alignment
    • Add safeReset() in tests to avoid emulator rollback panics during multi‑step liquidations
    • Add getPositionHealth helper using UInt128 HF (cadence/scripts/tidal-protocol/position_health.cdc) to match protocol’s e24 fixed‑point health
    • Introduce ensurePoolFactoryAndCreatePool() so pool creation never fails due to missing factory in signer
  • DEX liquidation enablement (Phase 2)
    • Add MockDexSwapper to root flow.json; deploy in tests
    • Allowlist swapper with set_dex_liquidation_config and configure oracle deviation bps
    • Fund protocol MOET vault to source repay via mock swapper
  • Strategy/mocks cleanup
    • Update MockStrategy to conform to DeFiActions interfaces and use provided UniqueIdentifier
    • Keep mock oracle strict about the unit of account type in root tests
  • Test expectations
    • Rebalance‑to‑target tests assert HF ≈ 1.3e24 (with tolerance)
    • DEX liquidation asserts HF reaches target: h >= 1.05e24 - tol (allow equal or higher); this mirrors upstream behavior where rounding may yield slightly above target

Files of note:

  • flow.json: add MockDexSwapper entry
  • cadence/scripts/tidal-protocol/position_health.cdc: return UInt128 HF to match protocol
  • cadence/contracts/mocks/MockStrategy.cdc: interface conformance + UniqueIdentifier handling
  • cadence/tests/test_helpers.cdc: safeReset, getPositionHealth, ensurePoolFactoryAndCreatePool, deploy MockDexSwapper
  • cadence/tests/liquidation_rebalance_to_target_test.cdc: rebalance path to HF≈1.3e24
  • cadence/tests/liquidation_via_dex_yield_zero_test.cdc: DEX liquidation path, allowlist, protocol MOET liquidity, HF≥1.05e24
  • cadence/tests/liquidation_integration_test.cdc: end‑to‑end repay‑for‑seize flow; correct protocol signer address per root aliases

How this maps to TidalProtocol#41:

  • Phase 1 (core repay‑for‑seize): our integration test mirrors quoting and executing liquidate_repay_for_seize and validates post‑HF≈1.05e24
  • Phase 2 (DEX liquidation): our DEX test follows the protocol’s allowlisted swapper flow, enforces oracle deviation, and asserts post‑HF at/above the global liquidation target

Results:

  • All three liquidation tests pass locally:
    • liquidation_integration_test.cdc (repay‑for‑seize)
    • liquidation_rebalance_to_target_test.cdc (rebalance to 1.3)
    • liquidation_via_dex_yield_zero_test.cdc (DEX liquidation to ~1.05)
  • Broader suite runs green under our sequential test loop

Notes:

  • This PR does not alter core protocol logic; changes are in root test harness, mocks, and config to reflect upstream liquidation behavior.
  • The relaxed check HF ≥ target for DEX liquidation is intentional and consistent with upstream rounding and guardrails.

…echanism\n\n- Add MockDexSwapper to flow.json and deploy in tests\n- Fix MockStrategy to conform to DeFiActions and UniqueIdentifier usage\n- Switch position_health script to UInt128\n- Add safeReset to avoid emulator rollback issues\n- Allowlist DEX liquidation and fund MOET for swapper\n- Relax DEX post-health to >= target (1.05e24)\n- Create ensurePoolFactoryAndCreatePool helper and use correct signer addresses\n- All liquidation tests now green
@kgrgpg kgrgpg changed the title chore/liquidation tests alignment Liquidation test plan alignment with TidalProtocol (Phases 1 & 2) Sep 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants