Skip to content

fix: add explicit InsufficientPoolLiquidity checks#81

Open
Tranquil-Flow wants to merge 1 commit into
devfrom
30-liquidity-checks
Open

fix: add explicit InsufficientPoolLiquidity checks#81
Tranquil-Flow wants to merge 1 commit into
devfrom
30-liquidity-checks

Conversation

@Tranquil-Flow
Copy link
Copy Markdown

Summary

Adds explicit InsufficientPoolLiquidity error checks before pool balance decrements, replacing opaque Panic(0x11) arithmetic underflow reverts with a named, catchable error.

Changes

  • ISafetyNet.sol: New error InsufficientPoolLiquidity()
  • SafetyNet.sol: Two guard insertions:
    1. _withdraw() small path — before safetyNetBalance[_id] -= _withdrawAmount
    2. _deduct() large path — before safetyNetBalance[_safetyNetId] -= _amount

Why

Normal accounting keeps memberWithdrawableBalance ≤ safetyNetBalance, so these guards shouldn't fire in practice. But if a bug, admin action, or future upgrade ever de-synchronises the two balances, the contract would previously emit an opaque Panic(0x11). The explicit check makes on-chain debugging and client-side error handling straightforward.

Testing

3 new tests including 2 using vm.store to simulate de-synchronised accounting. All 100 tests pass.

Closes #30

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.

Liquidity‑aware epoch ratio

1 participant