Skip to content

fix(core): emit pool adjust event, align fuzz invariants, regenerate architecture docs, and preserve zero health factor (#2244, #2251, #2252, #2307) - #2336

Merged
K1NGD4VID merged 2 commits into
LabsCrypt:mainfrom
Hollujay:fix/issues-2244-2251-2252-2307
Nov 23, 2026
Merged

K1NGD4VID merged 2 commits into
LabsCrypt:mainfrom
Hollujay:fix/issues-2244-2251-2252-2307

Conversation

@Hollujay

@Hollujay Hollujay commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This pull request addresses and resolves four interrelated issues across the smart contract lending pool, fuzz testing invariant documentation, architecture reference documentation & CI contract synchronization, and frontend liquidation normalization:

Closes #2244
Closes #2251
Closes #2252
Closes #2307


Detailed Root Causes & Changes

1. Case #2244 — Lending Pool adjust_outstanding Event Emission

  • Root Cause: LendingPool::adjust_outstanding mutated TotalOutstanding (the primary input to pool utilization calculation) without emitting any event, causing off-chain indexers and risk monitors to silently desynchronize during loan repayments, liquidations, and defaults.
  • Fix: Added events::outstanding_adjusted(env, token, delta, new_total) emitting (OutstandingAdjusted, token) topics with (delta, new_total) data payload; added schema and event emission unit tests in contracts/lending_pool/src/events.rs and contracts/lending_pool/src/test.rs.

2. Case #2251 — Fuzz Invariant Set Alignment with v2 Accounting

3. Case #2252 — Architecture Document Regeneration & CI Contract Doc Sync Guard

  • Root Cause: ARCHITECTURE.md referenced deprecated structs (RemittanceNFT { id, ... }), non-existent entrypoints (mint_nft, allocate_funds, return_funds, lock_nft), and inaccurate access control rules.
  • Fix:
    • Regenerated communication flows, sequence diagrams, and data models to reflect the live contracts (RemittanceMetadata, 7-state LoanStatus, PoolStats, PendingTransfer, PendingUpgrade).
    • Aligned the Access Control section with actual #[contractimpl] entrypoints.
    • Implemented scripts/check-contract-doc-sync.mjs and unit tests in scripts/check-contract-doc-sync.test.mjs.
    • Added contract-doc-sync-check job to .github/workflows/ci.yml and script targets to scripts/package.json.

4. Case #2307 — Preservation of Zero Health Factor in Frontend Normalization

  • Root Cause: normalizeLiquidatableLoan in frontend/src/app/hooks/useApi.ts used logical OR (||) fallback (healthFactor || collateralRatio), causing healthFactor: 0 (the most liquidation-critical state) to be replaced by the collateral ratio.
  • Fix: Updated normalizer to explicitly check for nullish values with ??, ensuring numeric 0 is preserved. Added unit test suite in frontend/src/app/hooks/useApi.normalizeLiquidatableLoan.test.ts.

Verification

  • Lending Pool Unit & Event Tests: 72/72 tests passed (cargo test -p lending_pool).
  • Contract Doc Sync Check & Unit Tests: All 4 contracts in sync, 2/2 tests passed (node scripts/check-contract-doc-sync.mjs && node --test scripts/check-contract-doc-sync.test.mjs).
  • Frontend Liquidatable Loan Tests: 7/7 tests passed (npm test -- useApi.normalizeLiquidatableLoan.test.ts).

LabsCrypt#2307

- LabsCrypt#2244: [quality] Emit OutstandingAdjusted event from adjust_outstanding in lending pool
- LabsCrypt#2251: [quality] Rewrite fuzz_invariants.md against v2 share-based accounting and sync fuzz docs
- LabsCrypt#2252: [quality] Regenerate ARCHITECTURE.md contract data model, communication flow, and access control; add CI doc sync check
- LabsCrypt#2307: [quality] Fix || in normalizeLiquidatableLoan swallowing zero health factors
@grantfox-oss

grantfox-oss Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

✅ Thanks @Hollujay 🦊! This PR is now linked to #2244.

@github-actions github-actions Bot added the security:malware-suspected Automated malware indicator found in a pull request label Nov 23, 2026
@github-actions

Copy link
Copy Markdown

Malware detection scan flagged this pull request

The scan found 4 indicator(s) in the PR diff. This PR is blocked until a maintainer reviews the flagged files.

  • ARCHITECTURE.md — hidden-appended-config-payload (high)
  • contracts/fuzz_invariants.md — hidden-appended-config-payload (high)
  • frontend/src/app/hooks/useApi.ts — hidden-appended-config-payload (high)
  • scripts/check-contract-doc-sync.mjs — hidden-appended-config-payload (high)

This is an automated triage signal; maintainers must verify whether the finding is malicious or intentional.

}

return !hasError;
}
@K1NGD4VID
K1NGD4VID merged commit 0a3e6e7 into LabsCrypt:main Nov 23, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

security:malware-suspected Automated malware indicator found in a pull request

Projects

None yet

3 participants