feat(contracts): implement emergency pause and unpause mechanism for liquidity pool and creditline contracts - #105
Conversation
…liquidity pool and creditline contracts
EmeditWeb
left a comment
There was a problem hiding this comment.
✅ 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 🤖
Summary of Changes
Closes #85
Problem
Neither
liquidity-pool-contractnorcreditline-contractimplemented 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
Paused State Storage:
PAUSED_KEYin instance storage (storage::is_paused,storage::set_paused) for both contracts.Admin-Restricted Pause Control:
pause(env, admin)andunpause(env, admin)entry points in both contracts.admin.require_auth()as the literal first line and emitsPAUSED/UNPAUSEDevents with admin address and ledger timestamp.State Transition Protection:
deposit,withdraw,fund_loan,receive_guarantee,absorb_loss,distribute_interest,accumulate_interestinliquidity-pool-contract;create_loan,request_loan,approve_loan,cancel_loan,mark_defaulted,warn_grace_periodincreditline-contract) withrequire_not_paused(&env)helper.ContractPaused = 15variant toLiquidityPoolErrorandContractPaused = 33variant toCreditLineError.Repayment Exception Policy:
repay_loan,repay_installmentincreditline-contract, andreceive_repaymentinliquidity-pool-contract) intentionally bypass pause checks.Query Function Availability:
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.Documentation & Tracker:
context/progress-tracker.mdunder## Recently Fixed.Verification Results
cargo test -p liquidity-pool-contract: 109 passed; 0 failedcargo test -p creditline-contract: 142 passed; 0 failedcargo test(full workspace): 393 passed; 0 failed across all 6 contracts.