Skip to content

Fix share valuation and NFT burn issues, add tests and polling fallba…#1120

Merged
ogazboiz merged 1 commit into
LabsCrypt:mainfrom
Mosas2000:fix/security-and-integration-improvements
Jun 27, 2026
Merged

Fix share valuation and NFT burn issues, add tests and polling fallba…#1120
ogazboiz merged 1 commit into
LabsCrypt:mainfrom
Mosas2000:fix/security-and-integration-improvements

Conversation

@Mosas2000

Copy link
Copy Markdown

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

…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.
@ogazboiz ogazboiz merged commit 3c593e2 into LabsCrypt:main Jun 27, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment