Repository navigation
Conversation
- Introduced new module `superfluid.ts` to handle fetching and processing Superfluid streams. - Implemented `fetchSuperfluidIncomingStreams` and `fetchSuperfluidStreamsForAccount` functions for retrieving stream data. - Updated `worker.ts` to integrate Superfluid streams into the crediting process, replacing the previous inline implementation. - Refactored stream credit calculation logic into `stream-credits.ts` for better modularity and maintainability. - Adjusted tests in `worker.test.ts` to accommodate changes in the worker module and ensure proper functionality.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Period truncation can lose credits, and account-level aggregation can fund historical periods to the wrong buyer.
4 open findings
What changed in this PR
Updates stream-credit calculation to use exact Superfluid periods and extracts Worker helpers into focused modules.
Changes:
- Calculates credits from historical constant-rate periods.
- Consolidates account-level stream processing.
- Extracts funding, HTTP, analytics-cron, and Superfluid logic.
| File | Description |
|---|---|
backend/src/worker.ts |
Integrates period-based crediting and extracted helpers. |
backend/src/superfluid.ts |
Fetches streams and their periods. |
backend/src/stream-credits.ts |
Calculates and schedules stream credits. |
backend/src/http.ts |
Houses HTTP utilities. |
backend/src/funding.ts |
Houses funding lifecycle logic. |
backend/src/analytics-cron.ts |
Houses analytics cron utilities. |
backend/test/worker.test.ts |
Adds period-based regression coverage. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+131
to
+134
| current.periods.push(...stream.periods); | ||
| // Rows arrive newest-first, so the first buyer seen is the most recently declared one. | ||
| current.buyerAddress ??= stream.buyerAddress; | ||
| byAccount.set(account, current); |
Comment on lines
+146
to
+150
| streamPeriods(orderBy: startedAtTimestamp, orderDirection: desc, first: ${PERIOD_PAGE_SIZE}) { | ||
| startedAtTimestamp | ||
| stoppedAtTimestamp | ||
| flowRate | ||
| } |
Comment on lines
+355
to
+359
| const accountStreams = await fetchSuperfluidStreamsForAccount(event.account, cfg, true); | ||
| periodsByAccount.set( | ||
| streamCacheKey, | ||
| accountStreams.flatMap((accountStream) => accountStream.periods) | ||
| ); |
Comment on lines
+471
to
+476
| const buyerForOperatorCheck = streams[0]?.buyerAddress || account; | ||
| const hasOperatorConsent = antseedFundingVault.enabled ? (await antseedFundingVault.isBuyerOperator(buyerForOperatorCheck)).isOperator : true; | ||
| const isValidForBonus = !!rootAccount && hasOperatorConsent; | ||
| const isVerified = isValidForBonus; | ||
| const { gdAmountWei } = streamCreditAmount({ now, lastStreamCreditAt: profile.lastStreamCreditAt, stream, previousFlowRateWeiPerSecond }); | ||
| const stream = streams[0]; | ||
| const gdAmountWei = streamCreditFromPeriods(now, profile.lastStreamCreditAt, accountPeriods); |
Contributor
|
dup of #29 |
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.

Description
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
About # (link your issue here)
How Has This Been Tested?
Please describe the tests that you ran to verify your changes.
Checklist: