Skip to content

Add accounting tests and expose total credit/debit balance queries#276

Closed
jordanschalm wants to merge 1 commit intomainfrom
claude/fix-tokenstate-accounting-Z8ETW
Closed

Add accounting tests and expose total credit/debit balance queries#276
jordanschalm wants to merge 1 commit intomainfrom
claude/fix-tokenstate-accounting-Z8ETW

Conversation

@jordanschalm
Copy link
Member

@jordanschalm jordanschalm commented Mar 17, 2026

Test demonstrating behaviour of total balance fields, result is documentation updates here: #277

totalCreditBalance/totalDebitBalance are updated with raw "true" amounts
at deposit/withdrawal time but never compounded with interest indices.
As interest accrues, individual position balances grow via
scaledBalance × interestIndex, but the totals remain stale sums of
point-in-time values.

Test 1 proves: after 1 year at 10% rate, a 100 FLOW position grows to
~110 but totalCreditBalance stays at 100. After withdrawing 100, the
position retains ~10 FLOW of accrued interest while totalCreditBalance
shows 0.

Test 2 proves: with multiple positions depositing at different times,
the gap compounds - sum of true balances (~210) exceeds
totalCreditBalance (200) by the untracked interest.

Also adds getTotalCreditBalance/getTotalDebitBalance public getters on
Pool, a query script, and a test helper to enable observability.

https://claude.ai/code/session_01Uad8KoZo93XPhndt8Aj14B
@jordanschalm jordanschalm requested a review from a team as a code owner March 17, 2026 20:31
@jordanschalm jordanschalm marked this pull request as draft March 17, 2026 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants