flowfi icon indicating copy to clipboard operation
flowfi copied to clipboard

[Backend] Historical Stream Snapshot & Balance Time-Travel Reconstruction API

Open blurbeast opened this issue 3 months ago • 7 comments

Overview & Background

Auditors, accounting systems, and tax tracking tools require balance verification as of specific historical timestamps (e.g. fiscal year-end, end-of-month payroll cutoff). Currently, the backend only returns the real-time instantaneous claimable balance.


Detailed Problem Statement

  • Users cannot verify what their claimable or remaining streaming balance was at a historical date (e.g. Dec 31, 2025 at 23:59:59 UTC).
  • Bookkeepers cannot reconcile historical monthly statements.

Technical Specification & Architecture

1. Endpoint Specification

GET /api/v1/streams/:id/snapshot?timestamp=1735689599

2. Time-Travel Reconstruction Logic

  1. Fetch stream base parameters from database.
  2. Fetch all StreamEvent records for streamId where timestamp <= targetTimestamp ordered by timestamp ascending.
  3. Replay state changes:
    • Sum deposits and top-ups up to target timestamp.
    • Sum withdrawals executed prior to target timestamp.
    • Reconstruct active pause durations applicable at target timestamp.
    • Compute claimableAtTimestamp using historical accrual anchor.
  4. Return structured balance snapshot:
    {
      "streamId": "42",
      "timestamp": 1735689599,
      "depositedAmount": "50000000000",
      "withdrawnAmount": "20000000000",
      "claimableAmount": "15000000000",
      "unvestedAmount": "15000000000",
      "statusAtTimestamp": "ACTIVE"
    }
    

Target Files

  • backend/src/controllers/stream.controller.ts
  • backend/src/services/claimable.service.ts
  • backend/src/routes/v1/stream.routes.ts

Acceptance Criteria

  • [ ] Accurate reconstruction of historical claimable and unvested balances at any given Unix timestamp.
  • [ ] Replays top-up, withdrawal, and pause event histories correctly.
  • [ ] Comprehensive unit tests verifying snapshot math against live contract simulations.

blurbeast avatar Aug 29 '26 22:08 blurbeast

Please assign ETA is 4 hours

Hi @maintainers, I am ready to resolve this!

Execution Plan for [Backend] Historical Stream Snapshot & Balance Time-Travel Reconstruction API:

  • Backend Implementation: Structure [Backend] Historical Stream Snapshot & Balance Time-Travel Reconstruction API with strict input validation, idempotent handlers, and proper error codes.
  • Integration Tests: Provide automated tests covering both valid payloads and failure scenarios.

Why assign me?

  • Proven Proof-of-Work: #1 contributor on Mova Store (28 merged Web3 PRs) and official ElizaOS contributor.
  • Fast Turnaround: Dedicated to shipping a tested, production-grade PR within 12–24 hours.
  • Zero Maintainer Burden: Self-documenting code with green CI and tests included so you don't spend time debugging.

Excited to contribute—please assign this to me and I'll push a clean PR shortly!

Ranjeet2063 avatar Sep 06 '26 11:09 Ranjeet2063

@CARTEL-L has applied to work on this issue as part of the Stellar Wave Program's 9th wave.

Hi! I’m a full-stack developer with a strong blockchain background. I’d love to handle this issue and can deliver a clean, reliable solution. Kindly assign it to me.

ℹ️ Repo Maintainers: To accept this application, review their application or assign @CARTEL-L to this issue.

CARTEL-L avatar Sep 27 '26 15:09 CARTEL-L

@Marvellous805 has applied to work on this issue as part of the Stellar Wave Program's 9th wave.

Hi maintainer I can fix this

ℹ️ Repo Maintainers: To accept this application, review their application or assign @Marvellous805 to this issue.

Marvellous805 avatar Sep 27 '26 15:09 Marvellous805

Congratulations, @Marvellous805! 🎉 Your application was accepted by the repo's maintainers, and the issue is due on September 30, 2026.

🧑‍💻 @Marvellous805: Please resolve the issue such that the repo's maintainers have enough time to review your contribution before the due date. You'll earn Points for completing the issue on-time, which will make you eligible for a share of the Stellar Wave Program's reward pool.

[!WARNING] When opening a PR, please link it to this issue to ensure it gets tracked accurately. Points are awarded when this issue is marked as completed by the maintainer.

🤠 Repo maintainers: Please keep an eye on the contributor's progress and review their work before the due date. You can manage this issue, including adjusting its complexity and points, here.

🌊 Happy Wave 🌊

drips-wave[bot] avatar Sep 27 '26 15:09 drips-wave[bot]

🎉 This issue has been marked as completed on GrantFox!

@Marvellous805's PR #1529 was approved and merged by @K1NGD4VID.

🏆 @Marvellous805: You earned 35 FoxPoints for this contribution! Your current tier: Explorer (280 total points). Track your full progress on GrantFox.

👏 Great work, @Marvellous805! Keep contributing to LabsCrypt.

grantfox-oss[bot] avatar Oct 08 '26 06:10 grantfox-oss[bot]

This issue has been marked as completed by a Drips Wave moderator for @Marvellous805 as part of the Stellar Wave Program's 9th Wave 🥳

Moderator's reason: [Auto-assessed] The PR #1529 was merged by a maintainer (@K1NGD4VID) as confirmed by the GRANTFOX bot and GitHub pull request metadata (mergedAt: 2026-10-08T06:04:34Z). The implementation fully addresses the historical stream snapshot and balance time-travel reconstruction requirements specified in issue #1324.

😎 @Marvellous805: You earned 150 Points for completing this issue! Once the Wave's rewards are finalized, you'll be eligible for a percentage of the Wave's reward pool based on the percentage of total points you've earned. Learn more here.

🧑‍💻 Repo maintainers: How'd the contributor do? Leave a review to share your experience working with them.

ℹ️ Note: This issue was marked complete via moderation. Points were issued even though the GitHub issue remains open.

drips-wave[bot] avatar Oct 13 '26 00:10 drips-wave[bot]