Loading
fix: correct solvency calculation for streaming swaps
Summary
- Fixes double-counting bug in solvency calculation for streaming swaps
- Streaming swap amounts were being counted twice: once in swap queue (full deposit) and again in pool balance (processed amounts)
- This caused reported solvency to artificially decrease as streaming swaps processed
Root Cause
When a streaming swap processes sub-swaps:
- Each sub-swap adds to
pool.BalanceAsset(the asset goes into the pool) - But the swap queue still contained the full deposit amount
- Solvency calculation deducted both, causing double-counting
Fix
Modified calculateNetworkSolvency() to:
- Check if swap queue item is a streaming swap (
IsLegacyStreaming()orIsStreaming()) - If streaming, fetch the
StreamingSwapstate and deduct only the remaining amount (deposit - in) - Non-streaming swaps continue to deduct full amount as before
Test plan
-
Added
TestCalculateNetworkSolvencyWithStreamingSwapswith 4 test cases:- Non-streaming swap deducts full amount
- Legacy streaming swap (V1) with partial progress deducts only remaining
- Advanced streaming swap (V2) with partial progress deducts only remaining
- Streaming swap with no progress deducts full amount
- All 28 network manager tests pass
- All 8 solvency tests pass