Skip to content

feat(contracts): implement emergency pause and unpause mechanism for liquidity pool and creditline contracts - #105

Merged
EmeditWeb merged 1 commit into
StepFi-app:mainfrom
sublime247:feat/pause-unpause-emergency-stop
Aug 29, 2026
Merged

feat(contracts): implement emergency pause and unpause mechanism for liquidity pool and creditline contracts#105
EmeditWeb merged 1 commit into
StepFi-app:mainfrom
sublime247:feat/pause-unpause-emergency-stop

Conversation

@sublime247

Copy link
Copy Markdown
Contributor

Summary of Changes

Closes #85

Problem

Neither liquidity-pool-contract nor creditline-contract implemented a pause/unpause emergency stop mechanism. When an exploit, compromised dependency, or bad parameterization is discovered, there was no way to halt state transitions (deposits, withdrawals, loan funding, loan creation, defaults) without an emergency WASM upgrade.

Solution & Implementation Details

  1. Paused State Storage:

    • Implemented PAUSED_KEY in instance storage (storage::is_paused, storage::set_paused) for both contracts.
  2. Admin-Restricted Pause Control:

    • Added pause(env, admin) and unpause(env, admin) entry points in both contracts.
    • Enforces admin.require_auth() as the literal first line and emits PAUSED / UNPAUSED events with admin address and ledger timestamp.
  3. State Transition Protection:

    • Guarded all state-mutating entry points (deposit, withdraw, fund_loan, receive_guarantee, absorb_loss, distribute_interest, accumulate_interest in liquidity-pool-contract; create_loan, request_loan, approve_loan, cancel_loan, mark_defaulted, warn_grace_period in creditline-contract) with require_not_paused(&env) helper.
    • Added ContractPaused = 15 variant to LiquidityPoolError and ContractPaused = 33 variant to CreditLineError.
  4. Repayment Exception Policy:

    • Policy Decision: Loan repayments (repay_loan, repay_installment in creditline-contract, and receive_repayment in liquidity-pool-contract) intentionally bypass pause checks.
    • Rationale: Allows borrowers to fulfill repayment obligations and settle debt during a protocol pause, preventing borrowers from being penalized with accrued late fees or forced defaults during an administrative freeze. Documented in code comments and unit tests.
  5. Query Function Availability:

    • Read-only query functions (get_share_price, get_pool_stats, get_lp_shares, calculate_withdrawal, get_loan, get_user_loans, get_user_active_debt, get_version, get_admin, is_paused) remain 100% callable while paused so users and frontend clients can inspect balances and state during an incident.
  6. Documentation & Tracker:

    • Recorded architectural design and fix details in context/progress-tracker.md under ## Recently Fixed.

Verification Results

  • cargo test -p liquidity-pool-contract: 109 passed; 0 failed
  • cargo test -p creditline-contract: 142 passed; 0 failed
  • cargo test (full workspace): 393 passed; 0 failed across all 6 contracts.

@sublime247
sublime247 requested a review from EmeditWeb as a code owner August 29, 2026 22:56

@EmeditWeb EmeditWeb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Automated Audit: solves

@sublime247 Excellent work, thank you! 🎉

The PR comprehensively implements the pause/unpause mechanism for both contracts as specified in issue #85: storage state, admin-restricted pause/unpause functions with require_auth as first line, require_not_paused guards on all mutating entry points, ContractPaused error variants, documented repayment exception policy, query functions unaffected while paused, and comprehensive tests that pass (393/393). CI integrity is intact (no workflow/config modifications). PR title and description are substantive and well-scoped.


CI checks: ⏳ PENDING: Build and Test Contracts
Merge conflicts: ✅ none — but the PR is blocked (failing/missing required checks or reviews).

Audited by stepfi-audit-bot 🤖

@EmeditWeb
EmeditWeb merged commit d95749e into StepFi-app:main Aug 29, 2026
1 check passed
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.

hard: no pause/emergency-stop circuit breaker on liquidity-pool and creditline

2 participants