Skip to content

Commit 6ccb44d

Browse files
authored
Merge pull request #62 from GeneralMagicio/add-endpoints-to-get-farcaster-delegations
add endpoints to get farcaster delegations
2 parents 474ecf3 + 7ecb664 commit 6ccb44d

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

src/flow/flow.controller.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import {
5050
ProjectResponse,
5151
} from './dto/responses';
5252
import { InputJsonObject } from '@prisma/client/runtime/library';
53+
import { getDelegations } from '../neynar/utils';
5354

5455
type AgoraBallotPost = {
5556
projects: {
@@ -491,6 +492,40 @@ export class FlowController {
491492
};
492493
}
493494

495+
@ApiOperation({
496+
summary: 'Total farcaster delegations',
497+
})
498+
@Get('/delegate/farcaster')
499+
async getTotalFarcasterDelegations() {
500+
return await getDelegations(new Date('2022-01-01').getTime());
501+
}
502+
503+
@ApiOperation({
504+
summary: 'Daily farcaster delegations',
505+
})
506+
@Get('/delegate/farcaster/daily')
507+
async getDailyFarcasterDelegations() {
508+
const now = new Date();
509+
const gmt1830Today = new Date(
510+
Date.UTC(
511+
now.getUTCFullYear(),
512+
now.getUTCMonth(),
513+
now.getUTCDate(),
514+
18,
515+
30,
516+
0,
517+
),
518+
);
519+
if (now < gmt1830Today) {
520+
gmt1830Today.setUTCDate(gmt1830Today.getUTCDate() - 1);
521+
}
522+
const endTimestamp = gmt1830Today.getTime();
523+
return await getDelegations(
524+
endTimestamp - 24 * 60 * 60 * 1000,
525+
endTimestamp,
526+
);
527+
}
528+
494529
@UseGuards(AuthGuard)
495530
@ApiOperation({
496531
summary: 'Used to delegate a category to a farcaster account',

src/neynar/utils.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import neynarClient from './neynarClient';
88
* @param start starting time for the query. In milliseconds from epoch.
99
* @param end end time for the query. In milliseconds from epoch. If not specified, defaults to `now`.
1010
*/
11-
const getDelegations = async (start: number, end?: number) => {
11+
export const getDelegations = async (start: number, end?: number) => {
1212
const prisma = new PrismaClient({
1313
datasources: {
1414
db: {
@@ -78,8 +78,7 @@ const getDelegations = async (start: number, end?: number) => {
7878
};
7979

8080
export const sendDailyCasts = async () => {
81-
const currentTimestamp = new Date();
82-
const endTimestamp = new Date(currentTimestamp);
81+
const endTimestamp = new Date();
8382
endTimestamp.setMinutes(0, 0, 0); // set to xx:00:00
8483
const delegations = await getDelegations(
8584
endTimestamp.getTime() - 24 * 60 * 60 * 1000, // Get the timestamp for xx:00 of the previous day

0 commit comments

Comments
 (0)