-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add cluster matching entity * add cluster matching adapters * finish cocm adapter * improve error handling for cluster matching * comment broken contract tests by missing eth_getCode Method * add feedback to handle qf cases * add cluster matching job to bootstrap file * fix coderabbit feedback PR * termine worker if an exception is raised
- Loading branch information
Showing
17 changed files
with
411 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class AddEstimatedClusterMatching1728554628004 | ||
implements MigrationInterface | ||
{ | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
CREATE TABLE estimated_cluster_matching ( | ||
id SERIAL PRIMARY KEY, | ||
"projectId" INT NOT NULL, | ||
"qfRoundId" INT NOT NULL, | ||
matching DOUBLE PRECISION NOT NULL | ||
); | ||
`); | ||
|
||
// Create indexes on the new table | ||
await queryRunner.query(` | ||
CREATE INDEX estimated_cluster_matching_project_id_qfround_id | ||
ON estimated_cluster_matching ("projectId", "qfRoundId"); | ||
`); | ||
|
||
await queryRunner.query(` | ||
CREATE INDEX estimated_cluster_matching_matching | ||
ON estimated_cluster_matching (matching); | ||
`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
// Revert changes if necessary by dropping the table and restoring the view | ||
await queryRunner.query(` | ||
DROP TABLE IF EXISTS estimated_cluster_matching; | ||
`); | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import axios from 'axios'; | ||
import { | ||
CocmAdapterInterface, | ||
EstimatedMatchingInput, | ||
ProjectsEstimatedMatchings, | ||
} from './cocmAdapterInterface'; | ||
import { logger } from '../../utils/logger'; | ||
import { i18n, translationErrorMessagesKeys } from '../../utils/errorMessages'; | ||
|
||
export class CocmAdapter implements CocmAdapterInterface { | ||
private ClusterMatchingURL; | ||
|
||
constructor() { | ||
this.ClusterMatchingURL = | ||
process.env.CLUSTER_MATCHING_API_URL || 'localhost'; | ||
} | ||
|
||
async fetchEstimatedClusterMatchings( | ||
matchingDataInput: EstimatedMatchingInput, | ||
): Promise<ProjectsEstimatedMatchings> { | ||
try { | ||
const result = await axios.post( | ||
this.ClusterMatchingURL, | ||
matchingDataInput, | ||
{ | ||
headers: { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json', | ||
}, | ||
}, | ||
); | ||
if (result?.data?.error !== null) { | ||
logger.error('clusterMatchingApi error', result.data.error); | ||
throw new Error( | ||
i18n.__(translationErrorMessagesKeys.CLUSTER_MATCHING_API_ERROR), | ||
); | ||
} | ||
return result.data; | ||
} catch (e) { | ||
logger.error('clusterMatchingApi error', e); | ||
throw new Error( | ||
i18n.__(translationErrorMessagesKeys.CLUSTER_MATCHING_API_ERROR), | ||
); | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Example Data | ||
// { | ||
// "matching_data": [ | ||
// { | ||
// "matching_amount": 83.25, | ||
// "matching_percent": 50.0, | ||
// "project_name": "Test1", | ||
// "strategy": "COCM" | ||
// }, | ||
// { | ||
// "matching_amount": 83.25, | ||
// "matching_percent": 50.0, | ||
// "project_name": "Test3", | ||
// "strategy": "COCM" | ||
// } | ||
// ] | ||
// } | ||
|
||
export interface ProjectsEstimatedMatchings { | ||
matching_data: { | ||
matching_amount: number; | ||
matching_percent: number; | ||
project_name: string; | ||
strategy: string; | ||
}[]; | ||
} | ||
|
||
export interface EstimatedMatchingInput { | ||
votes_data: [ | ||
{ | ||
voter: string; | ||
payoutAddress: string; | ||
amountUSD: number; | ||
project_name: string; | ||
score: number; | ||
}, | ||
]; | ||
strategy: string; | ||
min_donation_threshold_amount: number; | ||
matching_cap_amount: number; | ||
matching_amount: number; | ||
passport_threshold: number; | ||
} | ||
|
||
export interface CocmAdapterInterface { | ||
fetchEstimatedClusterMatchings( | ||
matchingDataInput: EstimatedMatchingInput, | ||
): Promise<ProjectsEstimatedMatchings>; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { | ||
CocmAdapterInterface, | ||
ProjectsEstimatedMatchings, | ||
} from './cocmAdapterInterface'; | ||
|
||
export class CocmMockAdapter implements CocmAdapterInterface { | ||
async fetchEstimatedClusterMatchings( | ||
_matchingDataInput, | ||
): Promise<ProjectsEstimatedMatchings> { | ||
return { | ||
matching_data: [ | ||
{ | ||
matching_amount: 83.25, | ||
matching_percent: 50.0, | ||
project_name: 'Test1', | ||
strategy: 'COCM', | ||
}, | ||
{ | ||
matching_amount: 83.25, | ||
matching_percent: 50.0, | ||
project_name: 'Test3', | ||
strategy: 'COCM', | ||
}, | ||
], | ||
}; | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Field, ObjectType } from 'type-graphql'; | ||
import { | ||
Column, | ||
Index, | ||
PrimaryGeneratedColumn, | ||
BaseEntity, | ||
Entity, | ||
ManyToOne, | ||
JoinColumn, | ||
} from 'typeorm'; | ||
import { Project } from './project'; | ||
|
||
@Entity('estimated_cluster_matching') | ||
@Index('estimated_cluster_matching_project_id_qfround_id', [ | ||
'projectId', | ||
'qfRoundId', | ||
]) | ||
@Index('estimated_cluster_matching_matching', ['matching']) | ||
@ObjectType() | ||
export class EstimatedClusterMatching extends BaseEntity { | ||
@Field() | ||
@PrimaryGeneratedColumn() | ||
id: number; // New primary key | ||
|
||
@Field(_type => Project) | ||
@ManyToOne(_type => Project, project => project.projectEstimatedMatchingView) | ||
@JoinColumn({ referencedColumnName: 'id' }) | ||
project: Project; | ||
|
||
@Field() | ||
@Column() | ||
projectId: number; | ||
|
||
@Field() | ||
@Column() | ||
qfRoundId: number; | ||
|
||
@Field() | ||
@Column('double precision') | ||
matching: number; | ||
} |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.