Skip to content

feat(treasury): implement internal balance tracking and atomic account#106

Closed
Amas-01 wants to merge 0 commit intoMissBlue00:mainfrom
Amas-01:feature/treasury-balance-tracking
Closed

feat(treasury): implement internal balance tracking and atomic account#106
Amas-01 wants to merge 0 commit intoMissBlue00:mainfrom
Amas-01:feature/treasury-balance-tracking

Conversation

@Amas-01
Copy link
Copy Markdown

@Amas-01 Amas-01 commented Mar 24, 2026

PR Description: Treasury Internal Balance Tracking (#26)

Summary

This PR implements a robust, atomic internal ledger for treasury balance tracking in the stellar-pay API. It introduces a serialised accounting system that prevents common vulnerabilities like double-spending and over-minting in the current in-memory architecture.

Changes

1. Atomic Accounting Core

  • Added **[TreasuryBalanceStore]
  • BigInt Integration: Switched to bigint (stroop-precision) for all balance calculations to eliminate floating-point precision risks.

2. Invariant Enforcement

  • Introduced [assertTreasuryInvariants]: A post-operation validation layer that ensures:
    • available_balance + reserved_balance == total_minted - total_burned
    • Neither balance component is ever negative.
    • Transactions are rollback-safe in case of validation failure.

3. Service & API Integration

  • Integrated [TreasuryBalanceStore]**.
  • Added Structured Logging for all treasury movements, providing clear audit trails of success/failure and resulting state.
  • Updated [TreasuryModule] to export the new accounting primitives.

4. Developer Experience

  • Husky Fix: Updated [.husky/pre-commit] to use npx pnpm for compatibility with environments where pnpm is not in the global PATH.

Verification Results

Automated Tests

  • Total Tests: 31 (All Passing)
  • Coverage:
    • [TreasuryBalanceStore]): 97.9%
    • [TreasuryService](: 95.9% (100% logic coverage)
    • TreasuryBalanceErrors: 95.8%

Key Scenarios Tested

  • Concurrency: 50 simultaneous mint/burn operations verified for absolute consistency.
  • Invariants: Verified that state remains consistent even after complex reserve/settle cycles.
  • Error Propagation: Confirmed that [InsufficientAvailableBalanceError] and other custom types are correctly thrown and logged.

Related Issues

Closes #26

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 24, 2026

@Amas-01 is attempting to deploy a commit to the missblue00's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 24, 2026

@Amas-01 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! 🚀

Learn more about application limits

@MissBlue00
Copy link
Copy Markdown
Owner

@Amas-01 the ci/cd checks failed, please resolve

@Amas-01 Amas-01 force-pushed the feature/treasury-balance-tracking branch 2 times, most recently from a607f80 to 9b3e0a8 Compare March 27, 2026 20:07
@Amas-01 Amas-01 closed this Mar 27, 2026
@Amas-01 Amas-01 force-pushed the feature/treasury-balance-tracking branch from 9b3e0a8 to cf8b8a5 Compare March 27, 2026 20:29
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.

Treasury: Implement internal balance tracking and accounting

2 participants