Fix share valuation and NFT burn issues, add tests and polling fallba…#1120
Merged
ogazboiz merged 1 commit intoJun 27, 2026
Merged
Conversation
…ck - Fix LendingPool share valuation to include outstanding loans Share prices now account for both idle balance and deployed capital, preventing unfair losses during high pool utilization. - Fix check_default to handle burned borrower NFTs gracefully Loans can now be defaulted even if NFT was burned, preventing permanently stuck loans. Batch operations continue instead of aborting. - Add integration tests for remittance submit flow Covers all test cases: valid XDR submission, invalid XDR rejection, duplicate submission prevention, authorization checks, and Stellar network error handling. - Enhance SSE hook with polling fallback and status indicators SSE automatically falls back to 30s polling after connection failures. Live status indicator shows connection state to users.
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Fixes
Closes #1057: LendingPool share value excludes outstanding loan principal
Files Modified:
contracts/lending_pool/src/lib.rs
contracts/loan_manager/src/lib.rs
Changes:
Added TotalOutstanding tracking in LendingPool to track loans currently deployed
Created total_pool_assets() function that combines idle balance + outstanding loans
Updated share valuation functions to use total assets instead of just idle balance:
calc_shares_to_mint()
calc_assets_to_redeem()
get_share_price()
get_depositor_yield()
get_deposit()
Added liquidity check in redeem_shares() to prevent withdrawals exceeding idle balance
Added public methods get_total_outstanding() and adjust_outstanding() for LoanManager integration
Result: Share prices now accurately reflect the full pool value including deployed capital, preventing unfair losses for withdrawers during high utilization.
Closes #1058: check_default and check_defaults trap when borrower NFT is burned
Files Modified:
contracts/remittance_nft/src/lib.rs
Changes:
Modified decrease_score() to check if NFT exists before attempting to modify it (returns early if no NFT)
Modified record_default() to return Ok(()) instead of Err(NftError::NftNotFound) when NFT doesn't exist
Result: Loans can now be defaulted even if the borrower's NFT was previously burned, preventing permanently stuck loans. The batch check_defaults() operation continues processing other loans instead of aborting.
Closes #768: Write integration tests for remittance submit flow
Files Created:
backend/src/tests/integration/remittance.integration.test.ts
Test Cases Implemented:
✅ POST /remittances/:id/submit with valid signed XDR → 200 + txHash
✅ POST /remittances/:id/submit with invalid XDR → 400
✅ POST /remittances/:id/submit on already-completed remittance → 400
✅ POST /remittances/:id/submit from wrong sender → 403
✅ Stellar network rejection → 502 with error message
All tests mock the Stellar RPC service and verify database state changes.
Closes #577: Add polling fallback when SSE connection fails
Files Modified:
frontend/src/app/hooks/useSSE.ts
Changes:
Added configurable pollingInterval parameter (default: 30 seconds)
Implemented reconnection attempt counter with max attempts (3)
After max reconnection attempts, automatically falls back to polling mode
Enhanced status reporting: "connecting", "connected", "polling", "disconnected"
Polling automatically starts when SSE fails
UI Integration (already present in codebase):
Live indicator shows different states:
🟢 "Live" when SSE is connected
🟡 "Reconnecting…" when in polling fallback mode
🔴 "Offline" when disconnected
Visual feedback with color-coded badges and WiFi icons