Skip to content

feat: add PoRep statistics endpoints#245

Open
tmaciej-neti wants to merge 1 commit into
mainfrom
feature/fil-1520-po-rep-statistics-endpoint
Open

feat: add PoRep statistics endpoints#245
tmaciej-neti wants to merge 1 commit into
mainfrom
feature/fil-1520-po-rep-statistics-endpoint

Conversation

@tmaciej-neti
Copy link
Copy Markdown
Collaborator

No description provided.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/statistics and /po-rep/payments-history endpoints.
  • Adds PoRepService to 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),
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