feat: add PoRep statistics endpoints#245
Open
tmaciej-neti wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Adds PoRep market “dashboard”-style statistics and payments history endpoints, backed by a new PoRep service and a typed SQL query for daily payment aggregation.
Changes:
- Introduces
/po-rep/statisticsand/po-rep/payments-historyendpoints. - Adds
PoRepServiceto compute deal counts and daily/cumulative USD payment history (via a new typed SQL query). - Extends Filecoin epoch/date conversion utilities (testnet/mainnet + reverse conversion).
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils/utils.ts | Adds configurable Filecoin epoch↔date conversion helpers (incl. testnet support). |
| src/service/po-rep/po-rep.service.ts | Implements PoRep stats computation: daily payment history + deal counts. |
| src/service/po-rep-price-oracle/po-rep-price-oracle.service.ts | Adds a placeholder “USD exchange rate” service (currently returns 1). |
| src/controller/po-rep/types.po-rep.ts | Adds DTOs/types for PoRep dashboard statistics and payments history responses. |
| src/controller/po-rep/po-rep.controller.ts | Exposes new PoRep statistics and payments-history API endpoints. |
| src/app.module.ts | Registers PoRepService and PoRepPriceOracleService providers. |
| prisma/sql/getFilecoinPaymentsForDealsHistory.sql | Adds daily payment aggregation query for PoRep-related rails. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| .toUTC() | ||
| .startOf('day'); | ||
| const endDay = DateTime.utc().startOf('day'); | ||
| const entriesCount = endDay.diff(startDay, 'day').days; |
Comment on lines
+148
to
+155
| return [ | ||
| ...new Array(entriesCount), | ||
| ].reduce<PoRepDealsPaymentsSummaryHistory>((result, _, index) => { | ||
| const entryDay = startDay.plus({ day: index }); | ||
| const entryISODate = entryDay.toISODate(); | ||
| const matchingData = combinedDayData.find((item) => { | ||
| return item.day.toISODate() === entryISODate; | ||
| }); |
| // Should not happen but type safety | ||
| if (!tokenUSDExchangeRate || !tokenInfo) { | ||
| throw new Error( | ||
| `Exhange rate or info not found for token "${result.token}"`, |
Comment on lines
+123
to
+143
| .mul(tokenUSDExchangeRate) | ||
| .toDecimalPlaces(2) | ||
| .toNumber(); | ||
| const tokenCumulativeAmountUSD = result.cumulative_amount | ||
| .div(tokenExponent) | ||
| .mul(tokenUSDExchangeRate) | ||
| .toDecimalPlaces(2) | ||
| .toNumber(); | ||
|
|
||
| return [ | ||
| currentDailyAmountUSD + tokenDailyAmountUSD, | ||
| currentCumulativeAmountUSD + tokenCumulativeAmountUSD, | ||
| ]; | ||
| }, | ||
| [0, 0], | ||
| ); | ||
|
|
||
| return { | ||
| day: DateTime.fromISO(dateISOString), | ||
| dailyAmountUSD: dailyAmountUSD, | ||
| cumulativeAmountUSD: cumulativeAmountUSD, |
Comment on lines
+76
to
+78
| public async getStatistics( | ||
| @Query() query: GetAllocatorsStatisticsRequest, | ||
| ): Promise<PoRepDashboardStatistic[]> { |
Comment on lines
+93
to
+94
| const comparedPaymentsEntry = paymentsHistory.find((entry) => { | ||
| return entry.day.toJSDate().toDateString() === cutoffDate.toDateString(); |
| @Controller('po-rep') | ||
| export class PoRepController extends ControllerBase { | ||
| constructor( | ||
| @Inject(CACHE_MANAGER) private cacheManager: Cache, |
Comment on lines
+5
to
+10
| to_timestamp( | ||
| p."createdAtBlock" * 30 + | ||
| CASE | ||
| WHEN $1 IS TRUE THEN 1667326380 | ||
| ELSE 1598306400 | ||
| END |
| ); | ||
|
|
||
| return { | ||
| day: DateTime.fromISO(dateISOString), |
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.
No description provided.