Skip to content

Add a reconciliation view comparing the live token balance against outstanding liabilities #463

Description

@mikewheeleer

Add a reconciliation view comparing the live token balance against outstanding liabilities

Description

The contract exposes get_token_balance(env) (the live SEP-41 balance held by the contract) and get_distributed_principal(env) (principal already returned), but offers no single view that tells an operator whether the contract is solvent for its remaining obligations. Reconciliation tooling must fetch the balance, the funded amount, the distributed principal, and the settlement state separately and compute the surplus/deficit off-chain, duplicating the exact liability arithmetic that sweep_terminal_dust already encodes internally.

This issue adds a read-only view returning the contract's reconciliation position: live balance, outstanding investor liability, and the resulting surplus (sweepable dust) or deficit.

Requirements and context

  • Repository scope: Liquifact/Liquifact-contracts only.
  • Add a ReconciliationView struct (token_balance, outstanding_liability, surplus) and get_reconciliation(env) -> ReconciliationView.
  • Compute outstanding_liability using the same formula sweep_terminal_dust relies on (funded_amount - distributed_principal, floored at zero), so the two never disagree.
  • Use saturating/checked arithmetic; the view must never panic on extreme values.
  • Keep it a pure read with no auth and no storage writes.
  • Cross-reference sweep_terminal_dust's liability floor in the doc comment.

Suggested execution

  • Fork the repo and create a branch
  • git checkout -b feature/contracts-reconciliation-view
  • Implement changes
    • Write code in: contracts/escrow/src/lib.rs — add the struct and get_reconciliation reusing the liability formula.
    • Write comprehensive tests in: contracts/escrow/src/tests/external_calls.rs — assert surplus equals sweepable dust before and after partial refunds.
    • Add documentation: add the view to the read-API surface and reconciliation guide in README.md and docs/.
    • Include NatSpec-style doc comments (///) on the struct fields and the surplus definition.
    • Validate security assumptions: surplus never exceeds what sweep_terminal_dust would permit.
  • Test and commit

Test and commit

  • Run cargo fmt --all -- --check, cargo build, and cargo test.
  • Cover edge cases and failure paths: zero balance, over-funded balance, fully-distributed, and partial-refund states.
  • Include the full cargo test output and a short security notes section in the PR description.

Example commit message

feat: add get_reconciliation view comparing token balance to outstanding liability

Guidelines

  • Minimum 95 percent test coverage for impacted modules.
  • Clear, reviewer-focused documentation.
  • Timeframe: 96 hours.

Community & contribution rewards

  • 💬 Join the Liquifact community on Discord for questions, reviews, and faster merges: https://discord.gg/JrGPH4V3
  • ⭐ This is a GrantFox OSS / Official Campaign task and may be rewarded. When your PR is merged you'll be prompted to rate the project — if this issue and the maintainers helped you ship, we'd be grateful for a 5-star rating. Clear questions in Discord and tidy, well-tested PRs are the fastest path to a merge and a reward.

Metadata

Metadata

Assignees

Fields

No fields configured for Feature.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions