feat: add get_reconciliation view comparing token balance to outstanding liability#589
Merged
mikewheeleer merged 3 commits intoJun 29, 2026
Conversation
|
@Spagero763 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
really nice — merging this 🙌 |
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.
feat: add get_reconciliation view comparing token balance to outstanding liability
Closes #463
Summary
Adds a single read-only view,
get_reconciliation, returning the contract'ssolvency position: the live funding-token balance, the outstanding investor
liability, and the resulting surplus (sweepable dust) or deficit. This removes the
need for off-chain tooling to fetch the balance, funded amount, distributed
principal, and settlement state separately and re-derive the liability arithmetic
that
sweep_terminal_dustalready encodes.Changes
escrow/src/lib.rs#[contracttype] ReconciliationView { token_balance, outstanding_liability, surplus }with///field docs.get_reconciliation(env) -> ReconciliationView:outstanding_liability = max(funded_amount - distributed_principal, 0)— the same floorsweep_terminal_dustenforces, so the two never disagree (cross-referenced in the doc comment).surplus = token_balance - outstanding_liability(negative = deficit).escrow/src/tests/external_calls.rs— tests assertingsurplusequals theamount
sweep_terminal_dustpermits, before and after a partial refund, plusedge cases: zero balance, over-funded, fully-distributed, and "one unit over
surplus panics".
README.md/docs/escrow-read-api.md— documents the view on the read-APIsurface and the reconciliation guide.
Security notes
outstanding_liabilityreusessweep_terminal_dust's exact floor, so the viewcan never report a larger sweepable surplus than the sweep guard would allow.
2) / withdrawn (3) statesdistributed_principalis0, so theview reports
outstanding_liability = funded_amountand is thereforeconservative relative to sweep (which only applies the floor in cancelled
state
4). It can never over-report sweepable funds.main(action needed)cargo build/cargo test/cargo fmt --all -- --checkcannot currently runto completion on
main, for reasons unrelated to this PR. A clean checkout ofmain(HEAD5de660f, "Merge branch 'pr-572'") with my changes reverted fails tocompile with the same 34 errors. The recent merge commits (
pr-570/571/572)left the
escrowcrate with, e.g.:rotate_beneficiary,BeneficiaryRotated,request_clear_legal_hold,get_legal_hold_clearable_at,get_attestation_digest_at;guard_status_in/guard_status_eqand anEscrowError::SweepNotTerminalvariant that are not defined (the enum has
DustSweepNotTerminal);AmountExceedsMax.I did not attempt to rewrite that merge: resolving dozens of errors spanning
settlement, claims, maturity, caps, and rotation in a financial contract would mean
guessing maintainer intent and risks introducing real bugs. It needs a maintainer
fix (or a clean re-merge of
pr-572).This PR is intentionally scoped to issue #463 and touches only three files. My
additions are isolated to the end of
lib.rs(afterget_distributed_principal)and the end of
external_calls.rs, arerustfmt-clean (verified:cargo fmtreports no diffs in the added ranges), and are type-correct against existing APIs
(
get_escrow,DataKey::DistributedPrincipal,funding_token_or_fail,TokenClient,escrow.funded_amount).Once
maincompiles, the included tests assertsurplus == sweepable dustacross the zero-balance, over-funded, partial-refund, and fully-distributed states.
I'm happy to rebase and paste full
cargo testoutput as soon as the tree builds.