Skip to content

Commit

Permalink
Merge pull request #147 from GeneralMagicio/addConfigsToDB
Browse files Browse the repository at this point in the history
Add configs to db
  • Loading branch information
lovelgeorge99 authored Dec 5, 2024
2 parents ea17622 + 0884297 commit 8173ef2
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 10 deletions.
1 change: 0 additions & 1 deletion config/example.env
Original file line number Diff line number Diff line change
Expand Up @@ -311,5 +311,4 @@ GITCOIN_PASSPORT_MIN_VALID_ANALYSIS_SCORE=
GITCOIN_PASSPORT_MIN_VALID_SCORER_SCORE=
# 1 day
GITCOIN_PASSPORT_EXPIRATION_PERIOD_MS=86400000
MAX_CONTRIBUTION_WITH_GITCOIN_PASSPORT_ONLY_USD=
ACTIVATE_GITCOIN_SCORE_CHECK=
17 changes: 17 additions & 0 deletions migration/1733350243725-addGitcoinCapToQfRound.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class AddGitcoinCapToQfRound1733350243725 implements MigrationInterface {
name = 'AddGitcoinCapToQfRound1733350243725';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "qf_round" ADD "roundUSDCapPerUserPerProjectWithGitcoinScoreOnly" integer`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "qf_round" DROP COLUMN "roundUSDCapPerUserPerProjectWithGitcoinScoreOnly"`,
);
}
}
3 changes: 0 additions & 3 deletions src/constants/gitcoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,3 @@ export const GITCOIN_PASSPORT_MIN_VALID_ANALYSIS_SCORE =
(+config.get('GITCOIN_PASSPORT_MIN_VALID_ANALYSIS_SCORE') as number) || 50;
export const GITCOIN_PASSPORT_MIN_VALID_SCORER_SCORE =
(+config.get('GITCOIN_PASSPORT_MIN_VALID_SCORER_SCORE') as number) || 15;
export const MAX_CONTRIBUTION_WITH_GITCOIN_PASSPORT_ONLY_USD =
(+config.get('MAX_CONTRIBUTION_WITH_GITCOIN_PASSPORT_ONLY_USD') as number) ||
1000;
4 changes: 4 additions & 0 deletions src/entities/qfRound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ export class QfRound extends BaseEntity {
@Column({ nullable: true })
roundUSDCapPerUserPerProject?: number;

@Field(() => Int, { nullable: true })
@Column({ nullable: true })
roundUSDCapPerUserPerProjectWithGitcoinScoreOnly?: number;

@Field(_type => Boolean)
@Column({ default: false })
isBatchMintingExecuted: boolean;
Expand Down
6 changes: 3 additions & 3 deletions src/resolvers/qAccResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import { EarlyAccessRound } from '../entities/earlyAccessRound';
import {
GITCOIN_PASSPORT_MIN_VALID_ANALYSIS_SCORE,
GITCOIN_PASSPORT_MIN_VALID_SCORER_SCORE,
MAX_CONTRIBUTION_WITH_GITCOIN_PASSPORT_ONLY_USD,
} from '../constants/gitcoin';
import { PrivadoAdapter } from '../adapters/privado/privadoAdapter';

Expand Down Expand Up @@ -268,6 +267,7 @@ function userCapsTestCases() {
endDate: new Date('2001-01-16'),
roundUSDCapPerProject: 10000,
roundUSDCapPerUserPerProject: 2500,
roundUSDCapPerUserPerProjectWithGitcoinScoreOnly: 1000,
tokenPrice: 0.5,
}).save();
sinon.useFakeTimers({
Expand Down Expand Up @@ -335,7 +335,7 @@ function userCapsTestCases() {
);
assert.equal(
response.data?.data.userCaps?.gitcoinPassport?.unusedCap,
MAX_CONTRIBUTION_WITH_GITCOIN_PASSPORT_ONLY_USD /
Number(qfRound1.roundUSDCapPerUserPerProjectWithGitcoinScoreOnly) /
Number(qfRound1.tokenPrice) -
donationAmount,
);
Expand Down Expand Up @@ -395,7 +395,7 @@ function userCapsTestCases() {
);
assert.equal(
response.data?.data.userCaps?.gitcoinPassport?.unusedCap,
MAX_CONTRIBUTION_WITH_GITCOIN_PASSPORT_ONLY_USD /
Number(qfRound1.roundUSDCapPerUserPerProjectWithGitcoinScoreOnly) /
Number(qfRound1.tokenPrice) -
donationAmount,
);
Expand Down
10 changes: 7 additions & 3 deletions src/services/qAccService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
GITCOIN_PASSPORT_EXPIRATION_PERIOD_MS,
GITCOIN_PASSPORT_MIN_VALID_ANALYSIS_SCORE,
GITCOIN_PASSPORT_MIN_VALID_SCORER_SCORE,
MAX_CONTRIBUTION_WITH_GITCOIN_PASSPORT_ONLY_USD,
} from '../constants/gitcoin';

const getEaProjectRoundRecord = async ({
Expand Down Expand Up @@ -237,9 +236,14 @@ const getUserRemainedCapBasedOnGitcoinScore = async ({
if (!activeQfRound?.tokenPrice) {
throw new Error('active qf round does not have token price!');
}
if (!activeQfRound?.roundUSDCapPerUserPerProjectWithGitcoinScoreOnly) {
throw new Error(
'active qf round does not have round USDCapPerUserPerProjectWithGitcoinScoreOnly!',
);
}
return (
MAX_CONTRIBUTION_WITH_GITCOIN_PASSPORT_ONLY_USD /
activeQfRound?.tokenPrice -
activeQfRound.roundUSDCapPerUserPerProjectWithGitcoinScoreOnly /
activeQfRound.tokenPrice -
qfTotalDonationAmount
);
};
Expand Down

0 comments on commit 8173ef2

Please sign in to comment.