Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 15 additions & 32 deletions src/controllers/evaluationController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,27 +108,13 @@ export const recreateEvaluationQuestions = async (
return;
}

const [errorReset] = await catchError(
evaluationQuestionService.resetEvaluationQuestions(
chainId,
alloPoolId,
evaluationQuestions
)
await evaluationQuestionService.resetEvaluationQuestions(
chainId,
alloPoolId,
evaluationQuestions
);

if (errorReset !== undefined) {
logger.error('Failed to reset evaluation questions', { errorReset });
res.status(500).json({ message: 'Failed to reset evaluation questions' });
return;
}

const [errorClean] = await catchError(evaluationService.cleanEvaluations());

if (errorClean !== undefined) {
logger.error('Failed to clean evaluations', { errorClean });
res.status(500).json({ message: 'Failed to clean evaluations' });
return;
}
await evaluationService.cleanEvaluations();

res.status(200).json(evaluationQuestions);
};
Expand Down Expand Up @@ -164,16 +150,14 @@ export const evaluateApplication = async (
summaryInput,
};

const [isAllowedError, isAllowed] = await catchError(
isPoolManager<CreateEvaluationParams>(
createEvaluationParams,
signature,
chainId,
alloPoolId
)
const isAllowed = await isPoolManager<CreateEvaluationParams>(
createEvaluationParams,
signature,
chainId,
alloPoolId
);

if (isAllowedError !== undefined || isAllowed === undefined) {
if (!isAllowed) {
logger.warn(
`User with address: ${evaluator} is not allowed to evaluate application`
);
Expand Down Expand Up @@ -317,17 +301,16 @@ export const triggerLLMEvaluation = async (
questions,
};

const [error] = await catchError(createLLMEvaluations([data]));
if (error !== undefined) {
try {
await createLLMEvaluations([data]);
res.status(200).json({ message: 'LLM evaluation triggered successfully' });
} catch (error) {
logger.error('Failed to create evaluations:', error);
res.status(500).json({
message: 'Failed to create evaluations',
error: error.message,
});
}

logger.info('LLM evaluation triggered successfully');
res.status(200).json({ message: 'LLM evaluation triggered successfully' });
};

const batchPromises = <T>(array: T[], batchSize: number): T[][] => {
Expand Down
22 changes: 8 additions & 14 deletions src/controllers/passportValidationController.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import type { Request, Response } from 'express';
import { catchError, validateRequest } from '@/utils';
import { validateRequest } from '@/utils';
import type { ProjectApplicationForManager } from '@/ext/passport/types';
import { isVerified } from '@/ext/passport/credentialverification';
import { createLogger } from '@/logger';

interface SocialCredentialBody {
application: Partial<ProjectApplicationForManager>;
}

const logger = createLogger();

export const validateSocialCredential = async (
req: Request,
res: Response
Expand All @@ -18,16 +15,13 @@ export const validateSocialCredential = async (

const { application } = req.body as SocialCredentialBody;

const [error, result] = await catchError(isVerified(application));
if (error !== undefined) {
logger.error('Failed to validate social credential:', error);
try {
const result = await isVerified(application);
res.json({
message: 'Social credential validated',
provider: result,
});
} catch (error) {
res.status(400).json({ message: 'Error validating social credential' });
return;
}

logger.info('Social credential validated', { result });
res.json({
message: 'Social credential validated',
provider: result,
});
};
12 changes: 3 additions & 9 deletions src/controllers/poolController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,11 @@ const handlePoolEvaluationQuestions = async (
pool: Pool,
poolMetadata: IndexerRoundMetadata
): Promise<PromptEvaluationQuestions> => {
const [error, questions] = await catchError(
evaluationQuestionService.getEvaluationQuestionsByAlloPoolId(
const questions =
await evaluationQuestionService.getEvaluationQuestionsByAlloPoolId(
pool.alloPoolId,
pool.chainId
)
);

if (error !== undefined || questions === undefined) {
logger.error('Failed to get evaluation questions:', error);
throw new Error('Failed to get evaluation questions');
}
);

if (questions.length > 0) {
return questions.map(question => question.question);
Expand Down
20 changes: 6 additions & 14 deletions src/ext/indexer/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class IndexerClient {
getRoundManager,
requestVariables
);

if (response.rounds.length === 0) {
this.logger.warn(
`No round found for poolId: ${alloPoolId} on chainId: ${chainId}`
Expand All @@ -96,15 +97,15 @@ class IndexerClient {

const round = response.rounds[0];

if (round.roundRoles.length === 0) {
if (round.roles.length === 0) {
this.logger.warn(
`No manager found for poolId: ${alloPoolId} on chainId: ${chainId}`
);
return [];
}

this.logger.info(`Successfully fetched round manager`);
return round.roundRoles.map(role => role.address);
return round.roles.map(role => role.address);
} catch (error) {
this.logger.error(`Failed to fetch round manager: ${error.message}`, {
error,
Expand Down Expand Up @@ -156,16 +157,7 @@ class IndexerClient {
return null;
}

const round = {
chainId: response.rounds[0].chainId,
id: response.rounds[0].id,
roundMetadata: response.rounds[0].roundMetadata,
roundMetadataCid: response.rounds[0].roundMetadataCid,
applications: response.rounds[0].applications.map(application => ({
...application,
project: application.projects[0],
})),
};
const round = response.rounds[0];

// Cache the result
this.cache.set(cacheKey, round);
Expand Down Expand Up @@ -205,15 +197,15 @@ class IndexerClient {
requestVariables
);

const application = response.applications[0];
const application = response.application;

if (application == null) {
this.logger.warn(
`No application found for applicationId: ${applicationId} in roundId: ${roundId} on chainId: ${chainId}`
);
return null;
}
return application;
return response.application;
} catch (error) {
this.logger.error(
`Failed to fetch round with single application: ${error.message}`,
Expand Down
20 changes: 9 additions & 11 deletions src/ext/indexer/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { gql } from 'graphql-request';

export const getRoundManager = gql`
query RoundManager($chainId: Int!, $alloPoolId: String!) {
rounds(where: { chainId: { _eq: $chainId }, id: { _eq: $alloPoolId } }) {
roundRoles {
rounds(
filter: { chainId: { equalTo: $chainId }, id: { equalTo: $alloPoolId } }
) {
roles {
address
}
}
Expand All @@ -12,7 +14,9 @@ export const getRoundManager = gql`

export const getRoundWithApplications = gql`
query RoundApplications($chainId: Int!, $roundId: String!) {
rounds(where: { chainId: { _eq: $chainId }, id: { _eq: $roundId } }) {
rounds(
filter: { chainId: { equalTo: $chainId }, id: { equalTo: $roundId } }
) {
chainId
id
roundMetadata
Expand All @@ -23,7 +27,7 @@ export const getRoundWithApplications = gql`
metadataCid
status
projectId
projects(where: { projectType: { _eq: "canonical" } }) {
project: canonicalProject {
metadata
metadataCid
}
Expand All @@ -38,13 +42,7 @@ export const getApplicationWithRound = gql`
$roundId: String!
$applicationId: String!
) {
applications(
where: {
chainId: { _eq: $chainId }
roundId: { _eq: $roundId }
id: { _eq: $applicationId }
}
) {
application(chainId: $chainId, roundId: $roundId, id: $applicationId) {
metadata
metadataCid
round {
Expand Down
38 changes: 11 additions & 27 deletions src/ext/indexer/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// 1. Basic Types & Enums
export type Address = `0x${string}`;

export enum Status {
Expand All @@ -7,7 +6,6 @@ export enum Status {
REJECTED = 'REJECTED',
}

// 2. Metadata & Supporting Interfaces
export interface ApplicationMetadata {
signature: string;
application: {
Expand Down Expand Up @@ -54,48 +52,34 @@ export interface ProjectMetadata {
projectTwitter?: string;
userGithub?: string;
projectGithub?: string;
// credentials: ProjectCredentials;
owners: Array<{ address: string }>;
createdAt: number;
lastUpdated: number;
}

// 3. Base Interfaces (Used in Multiple Places)
export interface BaseProject {
metadata: ProjectMetadata;
metadataCid: string;
}

export interface BaseApplication {
export interface Application {
id: string;
metadata: ApplicationMetadata;
metadataCid: string;
status: Status;
projectId: string;
project: {
metadata: ProjectMetadata;
metadataCid: string;
};
}

// 4. Extended Implementations
export interface Application extends BaseApplication {
project: BaseProject;
}

export interface ApplicationQuery extends BaseApplication {
projects: BaseProject[];
}

export interface BaseRound<T extends BaseApplication> {
export interface RoundWithApplications {
chainId: number;
id: string;
roundMetadata: RoundMetadata;
roundMetadataCid: string;
applications: T[];
applications: Application[];
}

export type RoundWithApplications = BaseRound<Application>;
export type RoundWithApplicationsQuery = BaseRound<ApplicationQuery>;

// 5. API Response Structures
export interface RoundApplicationsQueryResponse {
rounds: RoundWithApplicationsQuery[];
rounds: RoundWithApplications[];
}

export interface ApplicationWithRound {
Expand All @@ -110,12 +94,12 @@ export interface ApplicationWithRound {
}

export interface ApplicationRoundQueryResponse {
applications: ApplicationWithRound[];
application: ApplicationWithRound;
}

export interface ManagerRolesResponse {
rounds: Array<{
roundRoles: Array<{
roles: Array<{
address: string;
}>;
}>;
Expand Down
17 changes: 4 additions & 13 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,14 @@ export async function isPoolManager<T>(
chainId: number,
alloPoolId: string
): Promise<boolean> {
const [error, validAddresses] = await catchError(
indexerClient.getRoundManager({
chainId,
alloPoolId,
})
);

if (error !== undefined || validAddresses === undefined) {
logger.error('Failed to fetch pool manager', { error });
return false;
}

const validAddresses = await indexerClient.getRoundManager({
chainId,
alloPoolId,
});
if (env.NODE_ENV === 'development' && signature === '0xdeadbeef') {
logger.info('Skipping signature check in development mode');
return true;
}

try {
const address = await recoverSignerAddress(obj, signature);
logger.info(`Recovered address: ${address}`);
Expand Down