From 99d79f22255feca8e4c92bbc427808116389079a Mon Sep 17 00:00:00 2001 From: kkatusic Date: Mon, 23 Sep 2024 16:59:15 +0200 Subject: [PATCH 01/23] added migration file --- .../1727098387189-addTokenPriceToRounds.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 migration/1727098387189-addTokenPriceToRounds.ts diff --git a/migration/1727098387189-addTokenPriceToRounds.ts b/migration/1727098387189-addTokenPriceToRounds.ts new file mode 100644 index 000000000..902ccae00 --- /dev/null +++ b/migration/1727098387189-addTokenPriceToRounds.ts @@ -0,0 +1,23 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class AddTokenPriceToRounds1727098387189 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + // Add `token_price` column to the `qf_round` table + await queryRunner.query( + `ALTER TABLE "qf_round" ADD "token_price" double precision DEFAULT NULL`, + ); + + // Add `token_price` column to the `early_access_round` table + await queryRunner.query( + `ALTER TABLE "early_access_round" ADD "token_price" double precision DEFAULT NULL`, + ); + } + + public async down(queryRunner: QueryRunner): Promise { + // Remove `token_price` column from both tables if needed + await queryRunner.query(`ALTER TABLE "qf_round" DROP COLUMN "price"`); + await queryRunner.query( + `ALTER TABLE "early_access_round" DROP COLUMN "price"`, + ); + } +} From d348d31506e40637142230c9563d21ad7898de45 Mon Sep 17 00:00:00 2001 From: kkatusic Date: Mon, 23 Sep 2024 17:01:29 +0200 Subject: [PATCH 02/23] deleted ds_store --- .DS_Store | Bin 10244 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 58d2ae234dbf26fd958abf4c7102880099651500..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 10244 zcmeHMYitx%6h3EK=!^q)T6wu3yQEr?M_CGm5`=8Gtx#UYZlMo^c6MiIN2W8&&TI=3 zOnrnOpeFuNF&ZB+1QqdzLeL+^#2A$r6A_6Ij3g%h(LcUOj7B|o?kvpqLHwfuo!iVk zbI;@6d%itq=G-X&U^1^Q28aQGNEf5ZB>Ax0OY37-yg>ODHB^Ns*SONs3@ zx>wi@(U?yYJ{{(iB-D_b66L1oA2E=d6F=tbC44%}DK`i74%*%Fw*ExO zfDIPxq&@Vtn0ChZj~*e&aH;vzYfP0e(nvQ0&Ir9jBs&(+n*=)S0Tl)yOMdC#c-Za+ zv)B#@JDeA=D}xQt0*%lNn;-?v#o9=#6lqH|KkXTEw317A4b@8Wm1`3wmsEv52aky%{xgow~dY3ZQD#2?$z{GLm%oU&%!V-ppLI=dY^=Qetibs983*Q#V|v}T#HvsKSIL?!9? z_0wm~xnr7Kn??^xe@wp^*Gl;x?@ItC5LNSk_>>ST0FGpxQXLx$$|cN4ajYwR@i zoFrA?f_6(C(9c#@DCIM5j6^!~X=8WZaQ7-zqR8ipL}QYuoVZIPXExdzv(!9EBoe(@ z6t^*cV@{`@v*pO#+sHs|cgQt=I}2+hNpaeD(GSf{<=Q2pq-a}AHLaUIYk57f)^`kY z&wS?8+eN99z7!77rX9|UBpO6fd4C66c!TP=ty$fowV4Zz(MY6=@f$Qv*O&(tN@Zki zWSyv-5xbp!HK(@@QS=q~n?%w36^YMgYSs+bz9ej8LdCEK4GL_+n#Z?Tl{j|V3#+Qc zJRV+Eg(&l|tV+cBcuIloQ&za#1aU~hI@m!;zZVX{WAF^T4kzFwybB+}Ik*7d!VmBx z`~(-_H!Q`;SdI!-U<7C4ES!z=aVgf}GECxn+<+Ug729z;?!X>YaVOfC#og%OUc4V4 zzz6XFK7x2DLsYw3-&cJ6B>EBbN|A8ea;&hB*HO48fS7QPjunC)S6K=*k zG3CW~5B6djGiahkF}@pfxDWT^y*P~b;X!-|ANJz>Fg}S-;nR2okK&8?6268f@FbqX zH}Fk-2S3D5@eBNBL_BXSj%WON?06nb-`bf$$VG@-BHofL`=%LpuyUX)ec=4;% zdl?5`t>fASi<;_1*#lQvBUs{`AMQPU^cSzh8F%hr!Si?YgXPbX51ys1Km|RmR4Qq9 zQQt>iFC=eSiL;AJmbf z^B*aYd~ZfX`((n=2^PSF(wOMruk`D^5cu_2?1U{uAVlCAN1%l7KgPcQH;@1S|7+aK zaQh(wAp%!I085)vP3)6f;XF7}nSE=I(bY>AYfNvLQ_qAtro#B%=Xe^h&+&78o_})o g Date: Mon, 23 Sep 2024 17:03:26 +0200 Subject: [PATCH 03/23] added field and price updating function --- src/entities/earlyAccessRound.ts | 4 +++ src/entities/qfRound.ts | 4 +++ src/repositories/qfRoundRepository.ts | 35 +++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/src/entities/earlyAccessRound.ts b/src/entities/earlyAccessRound.ts index babf6029f..6af85e1b8 100644 --- a/src/entities/earlyAccessRound.ts +++ b/src/entities/earlyAccessRound.ts @@ -34,4 +34,8 @@ export class EarlyAccessRound extends BaseEntity { @Field(() => Date) @UpdateDateColumn() updatedAt: Date; + + @Field({ nullable: true }) + @Column({ type: 'float', nullable: true }) + tokenPrice?: number; } diff --git a/src/entities/qfRound.ts b/src/entities/qfRound.ts index c71d0a263..ef1ad4f1d 100644 --- a/src/entities/qfRound.ts +++ b/src/entities/qfRound.ts @@ -101,6 +101,10 @@ export class QfRound extends BaseEntity { @Column({ default: false }) isDataAnalysisDone: boolean; + @Field({ nullable: true }) + @Column({ type: 'float', nullable: true }) + tokenPrice?: number; + @UpdateDateColumn() updatedAt: Date; diff --git a/src/repositories/qfRoundRepository.ts b/src/repositories/qfRoundRepository.ts index 26f8c516d..4d0280cde 100644 --- a/src/repositories/qfRoundRepository.ts +++ b/src/repositories/qfRoundRepository.ts @@ -10,6 +10,7 @@ import { Sybil } from '../entities/sybil'; import { ProjectFraud } from '../entities/projectFraud'; import config from '../config'; import { logger } from '../utils/logger'; +import { CoingeckoPriceAdapter } from '../adapters/price/CoingeckoPriceAdapter'; const qfRoundEstimatedMatchingParamsCacheDuration = Number( process.env.QF_ROUND_ESTIMATED_MATCHING_CACHE_DURATION || 60000, @@ -318,3 +319,37 @@ export const retrieveActiveQfRoundUserMBDScore = async ( return null; } }; + +export const fillMissingTokenPriceInQfRounds = async (): Promise< + void | number +> => { + const priceAdapter = new CoingeckoPriceAdapter(); + + // Find all QfRounds where token_price is NULL + const roundsToUpdate = await AppDataSource.getDataSource() + .getRepository(QfRound) + .createQueryBuilder('qfRound') + .where('qfRound.token_price IS NULL') + .getMany(); + + if (roundsToUpdate.length === 0) { + return; + } + + // Set the token price for all found rounds and save them + for (const round of roundsToUpdate) { + if (round.tokenPrice === null) { + const tokenPrice = await priceAdapter.getTokenPriceAtDate({ + symbol: 'POL', + date: round.beginDate.toISOString().split('T')[0], // Format date as 'YYYY-MM-DD' + }); + + if (tokenPrice) { + round.tokenPrice = tokenPrice; + await AppDataSource.getDataSource().getRepository(QfRound).save(round); + } + } + } + + return roundsToUpdate.length; +}; From 54969b72dc121c5fd8746c4b68e899a3fabc6119 Mon Sep 17 00:00:00 2001 From: kkatusic Date: Mon, 23 Sep 2024 23:58:08 +0200 Subject: [PATCH 04/23] added token_price update for early access round --- .../earlyAccessRoundRepository.ts | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/repositories/earlyAccessRoundRepository.ts b/src/repositories/earlyAccessRoundRepository.ts index e0cb57c3d..6f98a19bf 100644 --- a/src/repositories/earlyAccessRoundRepository.ts +++ b/src/repositories/earlyAccessRoundRepository.ts @@ -1,5 +1,7 @@ +import { CoingeckoPriceAdapter } from '../adapters/price/CoingeckoPriceAdapter'; import { EarlyAccessRound } from '../entities/earlyAccessRound'; import { logger } from '../utils/logger'; +import { AppDataSource } from '../orm'; export const findAllEarlyAccessRounds = async (): Promise< EarlyAccessRound[] @@ -30,3 +32,39 @@ export const findActiveEarlyAccessRound = throw new Error('Error fetching active Early Access round'); } }; + +export const fillMissingTokenPriceInQfRounds = async (): Promise< + void | number +> => { + const priceAdapter = new CoingeckoPriceAdapter(); + + // Find all EarlyAccessRound where token_price is NULL + const roundsToUpdate = await AppDataSource.getDataSource() + .getRepository(EarlyAccessRound) + .createQueryBuilder('earlyAccessRound') + .where('earlyAccessRound.token_price IS NULL') + .getMany(); + + if (roundsToUpdate.length === 0) { + return; + } + + // Set the token price for all found rounds and save them + for (const round of roundsToUpdate) { + if (round.tokenPrice === null) { + const tokenPrice = await priceAdapter.getTokenPriceAtDate({ + symbol: 'POL', + date: round.startDate.toISOString().split('T')[0], // Format date as 'YYYY-MM-DD' + }); + + if (tokenPrice) { + round.tokenPrice = tokenPrice; + await AppDataSource.getDataSource() + .getRepository(EarlyAccessRound) + .save(round); + } + } + } + + return roundsToUpdate.length; +}; From f1a15de3666fe9903fdba37430a04c536d9474d3 Mon Sep 17 00:00:00 2001 From: kkatusic Date: Tue, 24 Sep 2024 10:09:25 +0200 Subject: [PATCH 05/23] added test for q-round and early rounds --- .../earlyAccessRoundRepository.test.ts | 74 ++++++++++++++++ src/repositories/qfRoundRepository.test.ts | 84 +++++++++++++++++++ 2 files changed, 158 insertions(+) diff --git a/src/repositories/earlyAccessRoundRepository.test.ts b/src/repositories/earlyAccessRoundRepository.test.ts index 94009b7f2..633824f8a 100644 --- a/src/repositories/earlyAccessRoundRepository.test.ts +++ b/src/repositories/earlyAccessRoundRepository.test.ts @@ -1,20 +1,47 @@ import { expect } from 'chai'; +import moment from 'moment'; import { EarlyAccessRound } from '../entities/earlyAccessRound'; import { findAllEarlyAccessRounds, findActiveEarlyAccessRound, + fillMissingTokenPriceInQfRounds, } from './earlyAccessRoundRepository'; import { saveRoundDirectlyToDb } from '../../test/testUtils'; +import { CoingeckoPriceAdapter } from '../adapters/price/CoingeckoPriceAdapter'; + +class MockedCoingeckoPriceAdapter extends CoingeckoPriceAdapter { + async getTokenPriceAtDate({ + symbol: _symbol, + date: _date, + }: { + symbol: string; + date: string; + }): Promise { + return 100; + } +} describe('EarlyAccessRound Repository Test Cases', () => { + let originalPriceAdapter: any; + beforeEach(async () => { // Clean up data before each test case await EarlyAccessRound.delete({}); + + // Mock the CoingeckoPriceAdapter to return a fixed value + originalPriceAdapter = CoingeckoPriceAdapter; + + (global as any).CoingeckoPriceAdapter = MockedCoingeckoPriceAdapter; + + await EarlyAccessRound.update({}, { tokenPrice: undefined }); }); afterEach(async () => { // Clean up data after each test case await EarlyAccessRound.delete({}); + + // Restore the original CoingeckoPriceAdapter + (global as any).CoingeckoPriceAdapter = originalPriceAdapter; }); it('should save a new Early Access Round directly to the database', async () => { @@ -90,4 +117,51 @@ describe('EarlyAccessRound Repository Test Cases', () => { const activeRound = await findActiveEarlyAccessRound(); expect(activeRound).to.be.null; }); + + it('should update token price for rounds with null token_price', async () => { + // Create a EarlyAccessRound with null token price + const earlyAccessRound = EarlyAccessRound.create({ + roundNumber: Math.floor(Math.random() * 10000), + startDate: new Date(), + endDate: moment().add(10, 'days').toDate(), + tokenPrice: undefined, + }); + await EarlyAccessRound.save(earlyAccessRound); + + const updatedCount = await fillMissingTokenPriceInQfRounds(); + + const updatedEarlyAcccessRound = await EarlyAccessRound.findOne({ + where: { id: earlyAccessRound.id }, + }); + expect(updatedEarlyAcccessRound?.tokenPrice).to.equal(100); + expect(updatedCount).to.equal(1); + }); + + it('should not update token price for rounds with existing token_price', async () => { + // Create a EarlyAccessRound with an existing token price + const earlyAccessRound = EarlyAccessRound.create({ + roundNumber: Math.floor(Math.random() * 10000), + startDate: new Date(), + endDate: moment().add(10, 'days').toDate(), + tokenPrice: 50, + }); + await EarlyAccessRound.save(earlyAccessRound); + + const updatedCount = await fillMissingTokenPriceInQfRounds(); + + const updatedEarlyAcccessRound = await EarlyAccessRound.findOne({ + where: { id: earlyAccessRound.id }, + }); + expect(updatedEarlyAcccessRound?.tokenPrice).to.equal(50); + expect(updatedCount).to.equal(undefined); + }); + + it('should return zero if there are no rounds to update', async () => { + // Ensure no rounds with null token_price + await EarlyAccessRound.update({}, { tokenPrice: 100 }); + + const updatedCount = await fillMissingTokenPriceInQfRounds(); + + expect(updatedCount).to.equal(undefined); + }); }); diff --git a/src/repositories/qfRoundRepository.test.ts b/src/repositories/qfRoundRepository.test.ts index 1814d1a38..1af458409 100644 --- a/src/repositories/qfRoundRepository.test.ts +++ b/src/repositories/qfRoundRepository.test.ts @@ -21,6 +21,19 @@ import { import { Project } from '../entities/project'; import { refreshProjectEstimatedMatchingView } from '../services/projectViewsService'; import { getProjectQfRoundStats } from './donationRepository'; +import { CoingeckoPriceAdapter } from '../adapters/price/CoingeckoPriceAdapter'; + +class MockedCoingeckoPriceAdapter extends CoingeckoPriceAdapter { + async getTokenPriceAtDate({ + symbol: _symbol, + date: _date, + }: { + symbol: string; + date: string; + }): Promise { + return 100; + } +} describe( 'getProjectDonationsSqrtRootSum test cases', @@ -40,6 +53,10 @@ describe( ); describe('findQfRoundById test cases', findQfRoundByIdTestCases); describe('findQfRoundBySlug test cases', findQfRoundBySlugTestCases); +describe( + 'fillMissingTokenPriceInQfRounds test cases', + fillMissingTokenPriceInQfRounds, +); function getProjectDonationsSqrRootSumTests() { let qfRound: QfRound; @@ -464,3 +481,70 @@ function findQfRoundBySlugTestCases() { assert.isNull(result); }); } + +function fillMissingTokenPriceInQfRounds() { + let originalPriceAdapter: any; + + beforeEach(async () => { + originalPriceAdapter = CoingeckoPriceAdapter; + + (global as any).CoingeckoPriceAdapter = MockedCoingeckoPriceAdapter; + + await QfRound.update({}, { tokenPrice: undefined }); + }); + + afterEach(() => { + (global as any).CoingeckoPriceAdapter = originalPriceAdapter; + }); + + it('should update token price for rounds with null token_price', async () => { + // Create a QfRound with null token price + const qfRound = QfRound.create({ + isActive: true, + name: 'test', + allocatedFund: 100, + minimumPassportScore: 8, + slug: new Date().getTime().toString(), + beginDate: new Date(), + endDate: moment().add(10, 'days').toDate(), + tokenPrice: undefined, + }); + await qfRound.save(); + + const updatedCount = await fillMissingTokenPriceInQfRounds(); + + const updatedQfRound = await QfRound.findOne({ where: { id: qfRound.id } }); + expect(updatedQfRound?.tokenPrice).to.equal(100); + expect(updatedCount).to.equal(1); + }); + + it('should not update token price for rounds with existing token_price', async () => { + // Create a QfRound with an existing token price + const qfRound = QfRound.create({ + isActive: true, + name: 'test', + allocatedFund: 100, + minimumPassportScore: 8, + slug: new Date().getTime().toString(), + beginDate: new Date(), + endDate: moment().add(10, 'days').toDate(), + tokenPrice: 50, + }); + await qfRound.save(); + + const updatedCount = await fillMissingTokenPriceInQfRounds(); + + const updatedQfRound = await QfRound.findOne({ where: { id: qfRound.id } }); + expect(updatedQfRound?.tokenPrice).to.equal(50); + expect(updatedCount).to.equal(undefined); + }); + + it('should return zero if there are no rounds to update', async () => { + // Ensure no rounds with null token_price + await QfRound.update({}, { tokenPrice: 100 }); + + const updatedCount = await fillMissingTokenPriceInQfRounds(); + + expect(updatedCount).to.equal(undefined); + }); +} From 217fa76192615c63d89a7b429884dc9a7c4a8112 Mon Sep 17 00:00:00 2001 From: kkatusic Date: Tue, 24 Sep 2024 11:34:48 +0200 Subject: [PATCH 06/23] removed if condition in for loop --- .../earlyAccessRoundRepository.ts | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/repositories/earlyAccessRoundRepository.ts b/src/repositories/earlyAccessRoundRepository.ts index 6f98a19bf..42f6a066e 100644 --- a/src/repositories/earlyAccessRoundRepository.ts +++ b/src/repositories/earlyAccessRoundRepository.ts @@ -51,18 +51,16 @@ export const fillMissingTokenPriceInQfRounds = async (): Promise< // Set the token price for all found rounds and save them for (const round of roundsToUpdate) { - if (round.tokenPrice === null) { - const tokenPrice = await priceAdapter.getTokenPriceAtDate({ - symbol: 'POL', - date: round.startDate.toISOString().split('T')[0], // Format date as 'YYYY-MM-DD' - }); + const tokenPrice = await priceAdapter.getTokenPriceAtDate({ + symbol: 'POL', + date: round.startDate.toISOString().split('T')[0], // Format date as 'YYYY-MM-DD' + }); - if (tokenPrice) { - round.tokenPrice = tokenPrice; - await AppDataSource.getDataSource() - .getRepository(EarlyAccessRound) - .save(round); - } + if (tokenPrice) { + round.tokenPrice = tokenPrice; + await AppDataSource.getDataSource() + .getRepository(EarlyAccessRound) + .save(round); } } From ad57fb950dcc13f3416c71298cee96e85c584c48 Mon Sep 17 00:00:00 2001 From: kkatusic Date: Tue, 24 Sep 2024 11:41:01 +0200 Subject: [PATCH 07/23] added additional where condition to query --- src/repositories/earlyAccessRoundRepository.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/repositories/earlyAccessRoundRepository.ts b/src/repositories/earlyAccessRoundRepository.ts index 42f6a066e..be2002e4f 100644 --- a/src/repositories/earlyAccessRoundRepository.ts +++ b/src/repositories/earlyAccessRoundRepository.ts @@ -43,6 +43,7 @@ export const fillMissingTokenPriceInQfRounds = async (): Promise< .getRepository(EarlyAccessRound) .createQueryBuilder('earlyAccessRound') .where('earlyAccessRound.token_price IS NULL') + .andWhere('earlyAccessRound.startDate > :now', { now: new Date() }) .getMany(); if (roundsToUpdate.length === 0) { From 20db4d1e3a8a4683da689fec6b37ca7c21898caf Mon Sep 17 00:00:00 2001 From: kkatusic Date: Tue, 24 Sep 2024 11:45:51 +0200 Subject: [PATCH 08/23] added token constant and added same logic for qacc round --- .../earlyAccessRoundRepository.ts | 3 ++- src/repositories/qfRoundRepository.ts | 20 +++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/repositories/earlyAccessRoundRepository.ts b/src/repositories/earlyAccessRoundRepository.ts index be2002e4f..dc29eefdc 100644 --- a/src/repositories/earlyAccessRoundRepository.ts +++ b/src/repositories/earlyAccessRoundRepository.ts @@ -2,6 +2,7 @@ import { CoingeckoPriceAdapter } from '../adapters/price/CoingeckoPriceAdapter'; import { EarlyAccessRound } from '../entities/earlyAccessRound'; import { logger } from '../utils/logger'; import { AppDataSource } from '../orm'; +import { QACC_DONATION_TOKEN_SYMBOL } from '../utils/qacc'; export const findAllEarlyAccessRounds = async (): Promise< EarlyAccessRound[] @@ -53,7 +54,7 @@ export const fillMissingTokenPriceInQfRounds = async (): Promise< // Set the token price for all found rounds and save them for (const round of roundsToUpdate) { const tokenPrice = await priceAdapter.getTokenPriceAtDate({ - symbol: 'POL', + symbol: QACC_DONATION_TOKEN_SYMBOL, date: round.startDate.toISOString().split('T')[0], // Format date as 'YYYY-MM-DD' }); diff --git a/src/repositories/qfRoundRepository.ts b/src/repositories/qfRoundRepository.ts index 4d0280cde..b7d9fdb65 100644 --- a/src/repositories/qfRoundRepository.ts +++ b/src/repositories/qfRoundRepository.ts @@ -11,6 +11,7 @@ import { ProjectFraud } from '../entities/projectFraud'; import config from '../config'; import { logger } from '../utils/logger'; import { CoingeckoPriceAdapter } from '../adapters/price/CoingeckoPriceAdapter'; +import { QACC_DONATION_TOKEN_SYMBOL } from '../utils/qacc'; const qfRoundEstimatedMatchingParamsCacheDuration = Number( process.env.QF_ROUND_ESTIMATED_MATCHING_CACHE_DURATION || 60000, @@ -330,6 +331,7 @@ export const fillMissingTokenPriceInQfRounds = async (): Promise< .getRepository(QfRound) .createQueryBuilder('qfRound') .where('qfRound.token_price IS NULL') + .andWhere('qfRound.beginDate > :now', { now: new Date() }) .getMany(); if (roundsToUpdate.length === 0) { @@ -338,16 +340,14 @@ export const fillMissingTokenPriceInQfRounds = async (): Promise< // Set the token price for all found rounds and save them for (const round of roundsToUpdate) { - if (round.tokenPrice === null) { - const tokenPrice = await priceAdapter.getTokenPriceAtDate({ - symbol: 'POL', - date: round.beginDate.toISOString().split('T')[0], // Format date as 'YYYY-MM-DD' - }); - - if (tokenPrice) { - round.tokenPrice = tokenPrice; - await AppDataSource.getDataSource().getRepository(QfRound).save(round); - } + const tokenPrice = await priceAdapter.getTokenPriceAtDate({ + symbol: QACC_DONATION_TOKEN_SYMBOL, + date: round.beginDate.toISOString().split('T')[0], // Format date as 'YYYY-MM-DD' + }); + + if (tokenPrice) { + round.tokenPrice = tokenPrice; + await AppDataSource.getDataSource().getRepository(QfRound).save(round); } } From 61a2f7bb064dc7b0d4e80540f900405b02d0d3b7 Mon Sep 17 00:00:00 2001 From: kkatusic Date: Tue, 24 Sep 2024 17:08:08 +0200 Subject: [PATCH 09/23] changes to gecko timestamp and token name --- src/repositories/earlyAccessRoundRepository.ts | 9 ++++++--- src/repositories/qfRoundRepository.ts | 12 +++++++++--- src/utils/qacc.ts | 3 +++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/repositories/earlyAccessRoundRepository.ts b/src/repositories/earlyAccessRoundRepository.ts index dc29eefdc..6ba97b258 100644 --- a/src/repositories/earlyAccessRoundRepository.ts +++ b/src/repositories/earlyAccessRoundRepository.ts @@ -2,7 +2,7 @@ import { CoingeckoPriceAdapter } from '../adapters/price/CoingeckoPriceAdapter'; import { EarlyAccessRound } from '../entities/earlyAccessRound'; import { logger } from '../utils/logger'; import { AppDataSource } from '../orm'; -import { QACC_DONATION_TOKEN_SYMBOL } from '../utils/qacc'; +import { QACC_DONATION_TOKEN_COINGECKO_TOKEN_SLUG } from '../utils/qacc'; export const findAllEarlyAccessRounds = async (): Promise< EarlyAccessRound[] @@ -53,9 +53,12 @@ export const fillMissingTokenPriceInQfRounds = async (): Promise< // Set the token price for all found rounds and save them for (const round of roundsToUpdate) { + const beginDate = round.startDate.toISOString().split('T')[0]; // 'YYYY-MM-DD' + const formattedDate = beginDate.split('-').reverse().join('-'); // Converts to 'DD-MM-YYYY' + const tokenPrice = await priceAdapter.getTokenPriceAtDate({ - symbol: QACC_DONATION_TOKEN_SYMBOL, - date: round.startDate.toISOString().split('T')[0], // Format date as 'YYYY-MM-DD' + symbol: QACC_DONATION_TOKEN_COINGECKO_TOKEN_SLUG, + date: formattedDate, }); if (tokenPrice) { diff --git a/src/repositories/qfRoundRepository.ts b/src/repositories/qfRoundRepository.ts index b7d9fdb65..59814ef79 100644 --- a/src/repositories/qfRoundRepository.ts +++ b/src/repositories/qfRoundRepository.ts @@ -11,7 +11,7 @@ import { ProjectFraud } from '../entities/projectFraud'; import config from '../config'; import { logger } from '../utils/logger'; import { CoingeckoPriceAdapter } from '../adapters/price/CoingeckoPriceAdapter'; -import { QACC_DONATION_TOKEN_SYMBOL } from '../utils/qacc'; +import { QACC_DONATION_TOKEN_COINGECKO_TOKEN_SLUG } from '../utils/qacc'; const qfRoundEstimatedMatchingParamsCacheDuration = Number( process.env.QF_ROUND_ESTIMATED_MATCHING_CACHE_DURATION || 60000, @@ -340,9 +340,15 @@ export const fillMissingTokenPriceInQfRounds = async (): Promise< // Set the token price for all found rounds and save them for (const round of roundsToUpdate) { + const beginDate = round.beginDate.toISOString().split('T')[0]; // 'YYYY-MM-DD' + const formattedDate = beginDate.split('-').reverse().join('-'); // Converts to 'DD-MM-YYYY' + + //eslint-disable-next-line no-console + console.log(formattedDate); + const tokenPrice = await priceAdapter.getTokenPriceAtDate({ - symbol: QACC_DONATION_TOKEN_SYMBOL, - date: round.beginDate.toISOString().split('T')[0], // Format date as 'YYYY-MM-DD' + symbol: QACC_DONATION_TOKEN_COINGECKO_TOKEN_SLUG, + date: formattedDate, }); if (tokenPrice) { diff --git a/src/utils/qacc.ts b/src/utils/qacc.ts index 6dfbedcef..bc7e99f71 100644 --- a/src/utils/qacc.ts +++ b/src/utils/qacc.ts @@ -16,6 +16,9 @@ export const QACC_DONATION_TOKEN_DECIMALS = (+config.get('QACC_DONATION_TOKEN_DECIMALS') as number) || 18; export const QACC_DONATION_TOKEN_COINGECKO_ID = (config.get('QACC_DONATION_TOKEN_COINGECKO_ID') as string) || 'matic-network'; +export const QACC_DONATION_TOKEN_COINGECKO_TOKEN_SLUG = + (config.get('QACC_DONATION_TOKEN_COINGECKO_TOKEN_SLUG') as string) || + 'polygon-ecosystem-token'; const isEarlyAccessRound = async () => { const earlyAccessRound = await findActiveEarlyAccessRound(); From a99df26b5c0c7cf3a13e293218f897e69fdaa4f6 Mon Sep 17 00:00:00 2001 From: kkatusic Date: Wed, 25 Sep 2024 09:10:19 +0200 Subject: [PATCH 10/23] fixing test running errors --- .../1727098387189-addTokenPriceToRounds.ts | 4 ++-- .../earlyAccessRoundRepository.ts | 18 +++++++++------- src/repositories/qfRoundRepository.test.ts | 7 ++++--- src/repositories/qfRoundRepository.ts | 21 ++++++++++--------- src/utils/qacc.ts | 3 --- 5 files changed, 28 insertions(+), 25 deletions(-) diff --git a/migration/1727098387189-addTokenPriceToRounds.ts b/migration/1727098387189-addTokenPriceToRounds.ts index 902ccae00..6c80c6181 100644 --- a/migration/1727098387189-addTokenPriceToRounds.ts +++ b/migration/1727098387189-addTokenPriceToRounds.ts @@ -15,9 +15,9 @@ export class AddTokenPriceToRounds1727098387189 implements MigrationInterface { public async down(queryRunner: QueryRunner): Promise { // Remove `token_price` column from both tables if needed - await queryRunner.query(`ALTER TABLE "qf_round" DROP COLUMN "price"`); + await queryRunner.query(`ALTER TABLE "qf_round" DROP COLUMN "token_price"`); await queryRunner.query( - `ALTER TABLE "early_access_round" DROP COLUMN "price"`, + `ALTER TABLE "early_access_round" DROP COLUMN "token_price"`, ); } } diff --git a/src/repositories/earlyAccessRoundRepository.ts b/src/repositories/earlyAccessRoundRepository.ts index 6ba97b258..27be4e75a 100644 --- a/src/repositories/earlyAccessRoundRepository.ts +++ b/src/repositories/earlyAccessRoundRepository.ts @@ -2,7 +2,6 @@ import { CoingeckoPriceAdapter } from '../adapters/price/CoingeckoPriceAdapter'; import { EarlyAccessRound } from '../entities/earlyAccessRound'; import { logger } from '../utils/logger'; import { AppDataSource } from '../orm'; -import { QACC_DONATION_TOKEN_COINGECKO_TOKEN_SLUG } from '../utils/qacc'; export const findAllEarlyAccessRounds = async (): Promise< EarlyAccessRound[] @@ -42,9 +41,9 @@ export const fillMissingTokenPriceInQfRounds = async (): Promise< // Find all EarlyAccessRound where token_price is NULL const roundsToUpdate = await AppDataSource.getDataSource() .getRepository(EarlyAccessRound) - .createQueryBuilder('earlyAccessRound') - .where('earlyAccessRound.token_price IS NULL') - .andWhere('earlyAccessRound.startDate > :now', { now: new Date() }) + .createQueryBuilder('early_AccessRound') + .where('early_AccessRound.token_price IS NULL') + .andWhere('early_AccessRound.startDate > :now', { now: new Date() }) .getMany(); if (roundsToUpdate.length === 0) { @@ -53,11 +52,16 @@ export const fillMissingTokenPriceInQfRounds = async (): Promise< // Set the token price for all found rounds and save them for (const round of roundsToUpdate) { - const beginDate = round.startDate.toISOString().split('T')[0]; // 'YYYY-MM-DD' - const formattedDate = beginDate.split('-').reverse().join('-'); // Converts to 'DD-MM-YYYY' + const formattedDate = round.startDate + .toLocaleDateString('en-GB', { + day: '2-digit', + month: '2-digit', + year: 'numeric', + }) + .replace(/\//g, '-'); const tokenPrice = await priceAdapter.getTokenPriceAtDate({ - symbol: QACC_DONATION_TOKEN_COINGECKO_TOKEN_SLUG, + symbol: 'polygon-ecosystem-token', date: formattedDate, }); diff --git a/src/repositories/qfRoundRepository.test.ts b/src/repositories/qfRoundRepository.test.ts index 1af458409..d05251c16 100644 --- a/src/repositories/qfRoundRepository.test.ts +++ b/src/repositories/qfRoundRepository.test.ts @@ -17,6 +17,7 @@ import { getProjectDonationsSqrtRootSum, getQfRoundTotalSqrtRootSumSquared, getQfRoundStats, + fillMissingTokenPriceInQfRounds, } from './qfRoundRepository'; import { Project } from '../entities/project'; import { refreshProjectEstimatedMatchingView } from '../services/projectViewsService'; @@ -55,7 +56,7 @@ describe('findQfRoundById test cases', findQfRoundByIdTestCases); describe('findQfRoundBySlug test cases', findQfRoundBySlugTestCases); describe( 'fillMissingTokenPriceInQfRounds test cases', - fillMissingTokenPriceInQfRounds, + fillMissingTokenPriceInQfRoundsTestCase, ); function getProjectDonationsSqrRootSumTests() { @@ -482,7 +483,7 @@ function findQfRoundBySlugTestCases() { }); } -function fillMissingTokenPriceInQfRounds() { +function fillMissingTokenPriceInQfRoundsTestCase() { let originalPriceAdapter: any; beforeEach(async () => { @@ -505,7 +506,7 @@ function fillMissingTokenPriceInQfRounds() { allocatedFund: 100, minimumPassportScore: 8, slug: new Date().getTime().toString(), - beginDate: new Date(), + beginDate: moment().subtract(1, 'days').toDate(), endDate: moment().add(10, 'days').toDate(), tokenPrice: undefined, }); diff --git a/src/repositories/qfRoundRepository.ts b/src/repositories/qfRoundRepository.ts index 59814ef79..304a5cb9d 100644 --- a/src/repositories/qfRoundRepository.ts +++ b/src/repositories/qfRoundRepository.ts @@ -11,7 +11,6 @@ import { ProjectFraud } from '../entities/projectFraud'; import config from '../config'; import { logger } from '../utils/logger'; import { CoingeckoPriceAdapter } from '../adapters/price/CoingeckoPriceAdapter'; -import { QACC_DONATION_TOKEN_COINGECKO_TOKEN_SLUG } from '../utils/qacc'; const qfRoundEstimatedMatchingParamsCacheDuration = Number( process.env.QF_ROUND_ESTIMATED_MATCHING_CACHE_DURATION || 60000, @@ -329,9 +328,9 @@ export const fillMissingTokenPriceInQfRounds = async (): Promise< // Find all QfRounds where token_price is NULL const roundsToUpdate = await AppDataSource.getDataSource() .getRepository(QfRound) - .createQueryBuilder('qfRound') - .where('qfRound.token_price IS NULL') - .andWhere('qfRound.beginDate > :now', { now: new Date() }) + .createQueryBuilder('qf_round') + .where('qf_round.token_price IS NULL') + .andWhere('qf_round.beginDate > :now', { now: new Date() }) .getMany(); if (roundsToUpdate.length === 0) { @@ -340,14 +339,16 @@ export const fillMissingTokenPriceInQfRounds = async (): Promise< // Set the token price for all found rounds and save them for (const round of roundsToUpdate) { - const beginDate = round.beginDate.toISOString().split('T')[0]; // 'YYYY-MM-DD' - const formattedDate = beginDate.split('-').reverse().join('-'); // Converts to 'DD-MM-YYYY' - - //eslint-disable-next-line no-console - console.log(formattedDate); + const formattedDate = round.beginDate + .toLocaleDateString('en-GB', { + day: '2-digit', + month: '2-digit', + year: 'numeric', + }) + .replace(/\//g, '-'); const tokenPrice = await priceAdapter.getTokenPriceAtDate({ - symbol: QACC_DONATION_TOKEN_COINGECKO_TOKEN_SLUG, + symbol: 'polygon-ecosystem-token', date: formattedDate, }); diff --git a/src/utils/qacc.ts b/src/utils/qacc.ts index bc7e99f71..6dfbedcef 100644 --- a/src/utils/qacc.ts +++ b/src/utils/qacc.ts @@ -16,9 +16,6 @@ export const QACC_DONATION_TOKEN_DECIMALS = (+config.get('QACC_DONATION_TOKEN_DECIMALS') as number) || 18; export const QACC_DONATION_TOKEN_COINGECKO_ID = (config.get('QACC_DONATION_TOKEN_COINGECKO_ID') as string) || 'matic-network'; -export const QACC_DONATION_TOKEN_COINGECKO_TOKEN_SLUG = - (config.get('QACC_DONATION_TOKEN_COINGECKO_TOKEN_SLUG') as string) || - 'polygon-ecosystem-token'; const isEarlyAccessRound = async () => { const earlyAccessRound = await findActiveEarlyAccessRound(); From ebeaf98d080e009f14ca0b894f817f04928ad4a8 Mon Sep 17 00:00:00 2001 From: kkatusic Date: Wed, 25 Sep 2024 10:57:08 +0200 Subject: [PATCH 11/23] fixing test cases --- .../earlyAccessRoundRepository.test.ts | 34 +++++++----------- .../earlyAccessRoundRepository.ts | 3 +- src/repositories/qfRoundRepository.test.ts | 36 ++++++++----------- src/repositories/qfRoundRepository.ts | 3 +- 4 files changed, 28 insertions(+), 48 deletions(-) diff --git a/src/repositories/earlyAccessRoundRepository.test.ts b/src/repositories/earlyAccessRoundRepository.test.ts index 633824f8a..daf95a368 100644 --- a/src/repositories/earlyAccessRoundRepository.test.ts +++ b/src/repositories/earlyAccessRoundRepository.test.ts @@ -1,5 +1,6 @@ import { expect } from 'chai'; import moment from 'moment'; +import sinon from 'sinon'; import { EarlyAccessRound } from '../entities/earlyAccessRound'; import { findAllEarlyAccessRounds, @@ -9,30 +10,19 @@ import { import { saveRoundDirectlyToDb } from '../../test/testUtils'; import { CoingeckoPriceAdapter } from '../adapters/price/CoingeckoPriceAdapter'; -class MockedCoingeckoPriceAdapter extends CoingeckoPriceAdapter { - async getTokenPriceAtDate({ - symbol: _symbol, - date: _date, - }: { - symbol: string; - date: string; - }): Promise { - return 100; - } -} - describe('EarlyAccessRound Repository Test Cases', () => { - let originalPriceAdapter: any; + let priceAdapterStub: sinon.SinonStub; beforeEach(async () => { // Clean up data before each test case await EarlyAccessRound.delete({}); - // Mock the CoingeckoPriceAdapter to return a fixed value - originalPriceAdapter = CoingeckoPriceAdapter; - - (global as any).CoingeckoPriceAdapter = MockedCoingeckoPriceAdapter; + // Stub CoingeckoPriceAdapter to mock getTokenPriceAtDate + priceAdapterStub = sinon + .stub(CoingeckoPriceAdapter.prototype, 'getTokenPriceAtDate') + .resolves(100); + // Reset tokenPrice to undefined for test consistency await EarlyAccessRound.update({}, { tokenPrice: undefined }); }); @@ -40,8 +30,8 @@ describe('EarlyAccessRound Repository Test Cases', () => { // Clean up data after each test case await EarlyAccessRound.delete({}); - // Restore the original CoingeckoPriceAdapter - (global as any).CoingeckoPriceAdapter = originalPriceAdapter; + // Restore the stubbed method after each test + priceAdapterStub.restore(); }); it('should save a new Early Access Round directly to the database', async () => { @@ -118,11 +108,11 @@ describe('EarlyAccessRound Repository Test Cases', () => { expect(activeRound).to.be.null; }); - it('should update token price for rounds with null token_price', async () => { + it('should update token price for rounds with null tokenPrice', async () => { // Create a EarlyAccessRound with null token price const earlyAccessRound = EarlyAccessRound.create({ roundNumber: Math.floor(Math.random() * 10000), - startDate: new Date(), + startDate: moment().subtract(3, 'days').toDate(), endDate: moment().add(10, 'days').toDate(), tokenPrice: undefined, }); @@ -141,7 +131,7 @@ describe('EarlyAccessRound Repository Test Cases', () => { // Create a EarlyAccessRound with an existing token price const earlyAccessRound = EarlyAccessRound.create({ roundNumber: Math.floor(Math.random() * 10000), - startDate: new Date(), + startDate: moment().subtract(3, 'days').toDate(), endDate: moment().add(10, 'days').toDate(), tokenPrice: 50, }); diff --git a/src/repositories/earlyAccessRoundRepository.ts b/src/repositories/earlyAccessRoundRepository.ts index 27be4e75a..fae1459bd 100644 --- a/src/repositories/earlyAccessRoundRepository.ts +++ b/src/repositories/earlyAccessRoundRepository.ts @@ -42,8 +42,7 @@ export const fillMissingTokenPriceInQfRounds = async (): Promise< const roundsToUpdate = await AppDataSource.getDataSource() .getRepository(EarlyAccessRound) .createQueryBuilder('early_AccessRound') - .where('early_AccessRound.token_price IS NULL') - .andWhere('early_AccessRound.startDate > :now', { now: new Date() }) + .where('early_AccessRound.tokenPrice IS NULL') .getMany(); if (roundsToUpdate.length === 0) { diff --git a/src/repositories/qfRoundRepository.test.ts b/src/repositories/qfRoundRepository.test.ts index d05251c16..bdb22d98d 100644 --- a/src/repositories/qfRoundRepository.test.ts +++ b/src/repositories/qfRoundRepository.test.ts @@ -1,5 +1,6 @@ import { assert, expect } from 'chai'; import moment from 'moment'; +import sinon from 'sinon'; import { createDonationData, createProjectData, @@ -24,18 +25,6 @@ import { refreshProjectEstimatedMatchingView } from '../services/projectViewsSer import { getProjectQfRoundStats } from './donationRepository'; import { CoingeckoPriceAdapter } from '../adapters/price/CoingeckoPriceAdapter'; -class MockedCoingeckoPriceAdapter extends CoingeckoPriceAdapter { - async getTokenPriceAtDate({ - symbol: _symbol, - date: _date, - }: { - symbol: string; - date: string; - }): Promise { - return 100; - } -} - describe( 'getProjectDonationsSqrtRootSum test cases', getProjectDonationsSqrRootSumTests, @@ -484,21 +473,24 @@ function findQfRoundBySlugTestCases() { } function fillMissingTokenPriceInQfRoundsTestCase() { - let originalPriceAdapter: any; + let priceAdapterStub: sinon.SinonStub; beforeEach(async () => { - originalPriceAdapter = CoingeckoPriceAdapter; - - (global as any).CoingeckoPriceAdapter = MockedCoingeckoPriceAdapter; + // Stub CoingeckoPriceAdapter to mock getTokenPriceAtDate + priceAdapterStub = sinon + .stub(CoingeckoPriceAdapter.prototype, 'getTokenPriceAtDate') + .resolves(100); + // Reset tokenPrice to undefined for test consistency await QfRound.update({}, { tokenPrice: undefined }); }); afterEach(() => { - (global as any).CoingeckoPriceAdapter = originalPriceAdapter; + // Restore the stubbed method after each test + priceAdapterStub.restore(); }); - it('should update token price for rounds with null token_price', async () => { + it('should update token price for rounds with null tokenPrice', async () => { // Create a QfRound with null token price const qfRound = QfRound.create({ isActive: true, @@ -506,7 +498,7 @@ function fillMissingTokenPriceInQfRoundsTestCase() { allocatedFund: 100, minimumPassportScore: 8, slug: new Date().getTime().toString(), - beginDate: moment().subtract(1, 'days').toDate(), + beginDate: moment().subtract(3, 'days').toDate(), endDate: moment().add(10, 'days').toDate(), tokenPrice: undefined, }); @@ -519,7 +511,7 @@ function fillMissingTokenPriceInQfRoundsTestCase() { expect(updatedCount).to.equal(1); }); - it('should not update token price for rounds with existing token_price', async () => { + it('should not update token price for rounds with existing tokenPrice', async () => { // Create a QfRound with an existing token price const qfRound = QfRound.create({ isActive: true, @@ -527,7 +519,7 @@ function fillMissingTokenPriceInQfRoundsTestCase() { allocatedFund: 100, minimumPassportScore: 8, slug: new Date().getTime().toString(), - beginDate: new Date(), + beginDate: moment().subtract(3, 'days').toDate(), endDate: moment().add(10, 'days').toDate(), tokenPrice: 50, }); @@ -541,7 +533,7 @@ function fillMissingTokenPriceInQfRoundsTestCase() { }); it('should return zero if there are no rounds to update', async () => { - // Ensure no rounds with null token_price + // Ensure no rounds with null tokenPrice await QfRound.update({}, { tokenPrice: 100 }); const updatedCount = await fillMissingTokenPriceInQfRounds(); diff --git a/src/repositories/qfRoundRepository.ts b/src/repositories/qfRoundRepository.ts index 304a5cb9d..9f75fd4b5 100644 --- a/src/repositories/qfRoundRepository.ts +++ b/src/repositories/qfRoundRepository.ts @@ -329,8 +329,7 @@ export const fillMissingTokenPriceInQfRounds = async (): Promise< const roundsToUpdate = await AppDataSource.getDataSource() .getRepository(QfRound) .createQueryBuilder('qf_round') - .where('qf_round.token_price IS NULL') - .andWhere('qf_round.beginDate > :now', { now: new Date() }) + .where('qf_round.tokenPrice IS NULL') .getMany(); if (roundsToUpdate.length === 0) { From f5a6cc55dbac21cd87732cd0767316ff54670f43 Mon Sep 17 00:00:00 2001 From: kkatusic Date: Wed, 25 Sep 2024 15:05:28 +0200 Subject: [PATCH 12/23] removing condition --- src/repositories/earlyAccessRoundRepository.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/repositories/earlyAccessRoundRepository.ts b/src/repositories/earlyAccessRoundRepository.ts index fae1459bd..10c4704b9 100644 --- a/src/repositories/earlyAccessRoundRepository.ts +++ b/src/repositories/earlyAccessRoundRepository.ts @@ -45,10 +45,6 @@ export const fillMissingTokenPriceInQfRounds = async (): Promise< .where('early_AccessRound.tokenPrice IS NULL') .getMany(); - if (roundsToUpdate.length === 0) { - return; - } - // Set the token price for all found rounds and save them for (const round of roundsToUpdate) { const formattedDate = round.startDate From c1a4a398c52a48bf76f73e3246f1de36bf9ff91b Mon Sep 17 00:00:00 2001 From: kkatusic Date: Wed, 25 Sep 2024 15:06:33 +0200 Subject: [PATCH 13/23] removed another condition --- src/repositories/qfRoundRepository.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/repositories/qfRoundRepository.ts b/src/repositories/qfRoundRepository.ts index 9f75fd4b5..ef856d3ba 100644 --- a/src/repositories/qfRoundRepository.ts +++ b/src/repositories/qfRoundRepository.ts @@ -332,10 +332,6 @@ export const fillMissingTokenPriceInQfRounds = async (): Promise< .where('qf_round.tokenPrice IS NULL') .getMany(); - if (roundsToUpdate.length === 0) { - return; - } - // Set the token price for all found rounds and save them for (const round of roundsToUpdate) { const formattedDate = round.beginDate From 908bf3722cc64b7c01057eb648488650076fda38 Mon Sep 17 00:00:00 2001 From: kkatusic Date: Wed, 25 Sep 2024 15:18:29 +0200 Subject: [PATCH 14/23] pushed formatting date inside getTokenPriceAtDate method --- src/adapters/price/CoingeckoPriceAdapter.ts | 5 ++++- src/adapters/price/PriceAdapterInterface.ts | 2 +- src/repositories/earlyAccessRoundRepository.ts | 10 +--------- src/repositories/qfRoundRepository.ts | 10 +--------- src/server/adminJs/tabs/donationTab.ts | 3 +-- src/services/cronJobs/importLostDonationsJob.ts | 4 +--- 6 files changed, 9 insertions(+), 25 deletions(-) diff --git a/src/adapters/price/CoingeckoPriceAdapter.ts b/src/adapters/price/CoingeckoPriceAdapter.ts index 37f8aaa06..c79a4b193 100644 --- a/src/adapters/price/CoingeckoPriceAdapter.ts +++ b/src/adapters/price/CoingeckoPriceAdapter.ts @@ -1,4 +1,5 @@ import axios from 'axios'; +import moment from 'moment'; import { GetTokenPriceAtDateParams, GetTokenPriceParams, @@ -46,9 +47,11 @@ export class CoingeckoPriceAdapter implements PriceAdapterInterface { params: GetTokenPriceAtDateParams, ): Promise { try { + const formattedDate = moment(params.date).format('DD-MM-YYYY'); + const result = await axios.get( // symbol in here means coingecko id for instance - `https://api.coingecko.com/api/v3/coins/${params.symbol}/history?date=${params.date}`, + `https://api.coingecko.com/api/v3/coins/${params.symbol}/history?date=${formattedDate}`, ); const priceUsd = result?.data?.market_data?.current_price?.usd; diff --git a/src/adapters/price/PriceAdapterInterface.ts b/src/adapters/price/PriceAdapterInterface.ts index 685cdb1dc..568db3134 100644 --- a/src/adapters/price/PriceAdapterInterface.ts +++ b/src/adapters/price/PriceAdapterInterface.ts @@ -5,7 +5,7 @@ export interface GetTokenPriceParams { export interface GetTokenPriceAtDateParams { symbol: string; - date: string; + date: Date; } export interface PriceAdapterInterface { diff --git a/src/repositories/earlyAccessRoundRepository.ts b/src/repositories/earlyAccessRoundRepository.ts index 10c4704b9..3724e4983 100644 --- a/src/repositories/earlyAccessRoundRepository.ts +++ b/src/repositories/earlyAccessRoundRepository.ts @@ -47,17 +47,9 @@ export const fillMissingTokenPriceInQfRounds = async (): Promise< // Set the token price for all found rounds and save them for (const round of roundsToUpdate) { - const formattedDate = round.startDate - .toLocaleDateString('en-GB', { - day: '2-digit', - month: '2-digit', - year: 'numeric', - }) - .replace(/\//g, '-'); - const tokenPrice = await priceAdapter.getTokenPriceAtDate({ symbol: 'polygon-ecosystem-token', - date: formattedDate, + date: round.startDate, }); if (tokenPrice) { diff --git a/src/repositories/qfRoundRepository.ts b/src/repositories/qfRoundRepository.ts index ef856d3ba..39db2e0ec 100644 --- a/src/repositories/qfRoundRepository.ts +++ b/src/repositories/qfRoundRepository.ts @@ -334,17 +334,9 @@ export const fillMissingTokenPriceInQfRounds = async (): Promise< // Set the token price for all found rounds and save them for (const round of roundsToUpdate) { - const formattedDate = round.beginDate - .toLocaleDateString('en-GB', { - day: '2-digit', - month: '2-digit', - year: 'numeric', - }) - .replace(/\//g, '-'); - const tokenPrice = await priceAdapter.getTokenPriceAtDate({ symbol: 'polygon-ecosystem-token', - date: formattedDate, + date: round.beginDate, }); if (tokenPrice) { diff --git a/src/server/adminJs/tabs/donationTab.ts b/src/server/adminJs/tabs/donationTab.ts index 907c4f8be..0a7ebfb8e 100644 --- a/src/server/adminJs/tabs/donationTab.ts +++ b/src/server/adminJs/tabs/donationTab.ts @@ -1,6 +1,5 @@ import { SelectQueryBuilder } from 'typeorm'; import { ActionContext } from 'adminjs'; -import moment from 'moment'; import { Donation, DONATION_STATUS, @@ -279,7 +278,7 @@ export const FillPricesForDonationsWithoutPrice = async () => { const token = await Token.findOneBy({ symbol: donation.currency }); if (!token || !token.coingeckoId) continue; const price = await coingeckoAdapter.getTokenPriceAtDate({ - date: moment(donation.createdAt).format('DD-MM-YYYY'), + date: donation.createdAt, symbol: token.coingeckoId, }); donation.valueUsd = donation.amount * price; diff --git a/src/services/cronJobs/importLostDonationsJob.ts b/src/services/cronJobs/importLostDonationsJob.ts index 481816dac..29b7c9d0c 100644 --- a/src/services/cronJobs/importLostDonationsJob.ts +++ b/src/services/cronJobs/importLostDonationsJob.ts @@ -183,15 +183,13 @@ export const importLostDonations = async () => { const donationDateDbFormat = moment(donationDate).format( 'YYYY-MM-DD HH:mm:ss', ); - const donationDateCoingeckoFormat = - moment(donationDate).format('DD-MM-YYYY'); const coingeckoAdapter = new CoingeckoPriceAdapter(); let ethereumPriceAtDate; try { ethereumPriceAtDate = await coingeckoAdapter.getTokenPriceAtDate({ symbol: tokenInDB!.coingeckoId, - date: donationDateCoingeckoFormat, + date: donationDate, }); } catch (e) { logger.debug('CoingeckoPrice not found for tx: ', tx); From 3b01e0e6dd482f600f5aad4b76e099320b6e9ee2 Mon Sep 17 00:00:00 2001 From: kkatusic Date: Wed, 25 Sep 2024 15:56:33 +0200 Subject: [PATCH 15/23] fixing test after removing conditions --- src/repositories/earlyAccessRoundRepository.test.ts | 7 ++++--- src/repositories/qfRoundRepository.test.ts | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/repositories/earlyAccessRoundRepository.test.ts b/src/repositories/earlyAccessRoundRepository.test.ts index daf95a368..52a1e2095 100644 --- a/src/repositories/earlyAccessRoundRepository.test.ts +++ b/src/repositories/earlyAccessRoundRepository.test.ts @@ -127,7 +127,7 @@ describe('EarlyAccessRound Repository Test Cases', () => { expect(updatedCount).to.equal(1); }); - it('should not update token price for rounds with existing token_price', async () => { + it('should not update token price for rounds with existing tokenPrice', async () => { // Create a EarlyAccessRound with an existing token price const earlyAccessRound = EarlyAccessRound.create({ roundNumber: Math.floor(Math.random() * 10000), @@ -142,8 +142,9 @@ describe('EarlyAccessRound Repository Test Cases', () => { const updatedEarlyAcccessRound = await EarlyAccessRound.findOne({ where: { id: earlyAccessRound.id }, }); + expect(updatedEarlyAcccessRound?.tokenPrice).to.equal(50); - expect(updatedCount).to.equal(undefined); + expect(updatedCount).to.equal(0); }); it('should return zero if there are no rounds to update', async () => { @@ -152,6 +153,6 @@ describe('EarlyAccessRound Repository Test Cases', () => { const updatedCount = await fillMissingTokenPriceInQfRounds(); - expect(updatedCount).to.equal(undefined); + expect(updatedCount).to.equal(0); }); }); diff --git a/src/repositories/qfRoundRepository.test.ts b/src/repositories/qfRoundRepository.test.ts index bdb22d98d..953bd3546 100644 --- a/src/repositories/qfRoundRepository.test.ts +++ b/src/repositories/qfRoundRepository.test.ts @@ -529,7 +529,7 @@ function fillMissingTokenPriceInQfRoundsTestCase() { const updatedQfRound = await QfRound.findOne({ where: { id: qfRound.id } }); expect(updatedQfRound?.tokenPrice).to.equal(50); - expect(updatedCount).to.equal(undefined); + expect(updatedCount).to.equal(0); }); it('should return zero if there are no rounds to update', async () => { @@ -538,6 +538,6 @@ function fillMissingTokenPriceInQfRoundsTestCase() { const updatedCount = await fillMissingTokenPriceInQfRounds(); - expect(updatedCount).to.equal(undefined); + expect(updatedCount).to.equal(0); }); } From c3aff537f594883b9d909da6ae50957ebfa3db4c Mon Sep 17 00:00:00 2001 From: kkatusic Date: Wed, 25 Sep 2024 16:16:44 +0200 Subject: [PATCH 16/23] test updated --- src/repositories/earlyAccessRoundRepository.test.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/repositories/earlyAccessRoundRepository.test.ts b/src/repositories/earlyAccessRoundRepository.test.ts index 52a1e2095..2e2c25a3d 100644 --- a/src/repositories/earlyAccessRoundRepository.test.ts +++ b/src/repositories/earlyAccessRoundRepository.test.ts @@ -123,6 +123,13 @@ describe('EarlyAccessRound Repository Test Cases', () => { const updatedEarlyAcccessRound = await EarlyAccessRound.findOne({ where: { id: earlyAccessRound.id }, }); + + // Assert that the token price fetching method was called with the correct date + sinon.assert.calledWith(priceAdapterStub, { + symbol: 'polygon-ecosystem-token', + date: earlyAccessRound.startDate, + }); + expect(updatedEarlyAcccessRound?.tokenPrice).to.equal(100); expect(updatedCount).to.equal(1); }); From a01e9cc396aab75b6af522a98f7997a7e227099e Mon Sep 17 00:00:00 2001 From: kkatusic Date: Wed, 25 Sep 2024 16:19:13 +0200 Subject: [PATCH 17/23] fixing function naming issue --- src/repositories/earlyAccessRoundRepository.test.ts | 8 ++++---- src/repositories/earlyAccessRoundRepository.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/repositories/earlyAccessRoundRepository.test.ts b/src/repositories/earlyAccessRoundRepository.test.ts index 2e2c25a3d..4bb1a0983 100644 --- a/src/repositories/earlyAccessRoundRepository.test.ts +++ b/src/repositories/earlyAccessRoundRepository.test.ts @@ -5,7 +5,7 @@ import { EarlyAccessRound } from '../entities/earlyAccessRound'; import { findAllEarlyAccessRounds, findActiveEarlyAccessRound, - fillMissingTokenPriceInQfRounds, + fillMissingTokenPriceInEarlyAccessRounds, } from './earlyAccessRoundRepository'; import { saveRoundDirectlyToDb } from '../../test/testUtils'; import { CoingeckoPriceAdapter } from '../adapters/price/CoingeckoPriceAdapter'; @@ -118,7 +118,7 @@ describe('EarlyAccessRound Repository Test Cases', () => { }); await EarlyAccessRound.save(earlyAccessRound); - const updatedCount = await fillMissingTokenPriceInQfRounds(); + const updatedCount = await fillMissingTokenPriceInEarlyAccessRounds(); const updatedEarlyAcccessRound = await EarlyAccessRound.findOne({ where: { id: earlyAccessRound.id }, @@ -144,7 +144,7 @@ describe('EarlyAccessRound Repository Test Cases', () => { }); await EarlyAccessRound.save(earlyAccessRound); - const updatedCount = await fillMissingTokenPriceInQfRounds(); + const updatedCount = await fillMissingTokenPriceInEarlyAccessRounds(); const updatedEarlyAcccessRound = await EarlyAccessRound.findOne({ where: { id: earlyAccessRound.id }, @@ -158,7 +158,7 @@ describe('EarlyAccessRound Repository Test Cases', () => { // Ensure no rounds with null token_price await EarlyAccessRound.update({}, { tokenPrice: 100 }); - const updatedCount = await fillMissingTokenPriceInQfRounds(); + const updatedCount = await fillMissingTokenPriceInEarlyAccessRounds(); expect(updatedCount).to.equal(0); }); diff --git a/src/repositories/earlyAccessRoundRepository.ts b/src/repositories/earlyAccessRoundRepository.ts index 3724e4983..bf56531ac 100644 --- a/src/repositories/earlyAccessRoundRepository.ts +++ b/src/repositories/earlyAccessRoundRepository.ts @@ -33,7 +33,7 @@ export const findActiveEarlyAccessRound = } }; -export const fillMissingTokenPriceInQfRounds = async (): Promise< +export const fillMissingTokenPriceInEarlyAccessRounds = async (): Promise< void | number > => { const priceAdapter = new CoingeckoPriceAdapter(); From 5a7b2ea77dc7854f639a5e9d57e7b86925750cd3 Mon Sep 17 00:00:00 2001 From: kkatusic Date: Thu, 26 Sep 2024 14:55:08 +0200 Subject: [PATCH 18/23] adding starting date check in query for round token price --- src/repositories/earlyAccessRoundRepository.ts | 1 + src/repositories/qfRoundRepository.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/src/repositories/earlyAccessRoundRepository.ts b/src/repositories/earlyAccessRoundRepository.ts index bf56531ac..3364e5d12 100644 --- a/src/repositories/earlyAccessRoundRepository.ts +++ b/src/repositories/earlyAccessRoundRepository.ts @@ -43,6 +43,7 @@ export const fillMissingTokenPriceInEarlyAccessRounds = async (): Promise< .getRepository(EarlyAccessRound) .createQueryBuilder('early_AccessRound') .where('early_AccessRound.tokenPrice IS NULL') + .andWhere('early_AccessRound.startDate < :now', { now: new Date() }) .getMany(); // Set the token price for all found rounds and save them diff --git a/src/repositories/qfRoundRepository.ts b/src/repositories/qfRoundRepository.ts index 39db2e0ec..922ec868c 100644 --- a/src/repositories/qfRoundRepository.ts +++ b/src/repositories/qfRoundRepository.ts @@ -330,6 +330,7 @@ export const fillMissingTokenPriceInQfRounds = async (): Promise< .getRepository(QfRound) .createQueryBuilder('qf_round') .where('qf_round.tokenPrice IS NULL') + .andWhere('qf_round.beginDate < :now', { now: new Date() }) .getMany(); // Set the token price for all found rounds and save them From c042c67f2443616dde73d8911ad3fccad2388717 Mon Sep 17 00:00:00 2001 From: kkatusic Date: Thu, 26 Sep 2024 15:44:09 +0200 Subject: [PATCH 19/23] added constant for token name --- src/repositories/earlyAccessRoundRepository.test.ts | 3 ++- src/repositories/earlyAccessRoundRepository.ts | 3 ++- src/repositories/qfRoundRepository.ts | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/repositories/earlyAccessRoundRepository.test.ts b/src/repositories/earlyAccessRoundRepository.test.ts index 4bb1a0983..1c61d522a 100644 --- a/src/repositories/earlyAccessRoundRepository.test.ts +++ b/src/repositories/earlyAccessRoundRepository.test.ts @@ -9,6 +9,7 @@ import { } from './earlyAccessRoundRepository'; import { saveRoundDirectlyToDb } from '../../test/testUtils'; import { CoingeckoPriceAdapter } from '../adapters/price/CoingeckoPriceAdapter'; +import { QACC_DONATION_TOKEN_COINGECKO_ID } from '../utils/qacc'; describe('EarlyAccessRound Repository Test Cases', () => { let priceAdapterStub: sinon.SinonStub; @@ -126,7 +127,7 @@ describe('EarlyAccessRound Repository Test Cases', () => { // Assert that the token price fetching method was called with the correct date sinon.assert.calledWith(priceAdapterStub, { - symbol: 'polygon-ecosystem-token', + symbol: QACC_DONATION_TOKEN_COINGECKO_ID, date: earlyAccessRound.startDate, }); diff --git a/src/repositories/earlyAccessRoundRepository.ts b/src/repositories/earlyAccessRoundRepository.ts index 3364e5d12..9da99f5f4 100644 --- a/src/repositories/earlyAccessRoundRepository.ts +++ b/src/repositories/earlyAccessRoundRepository.ts @@ -2,6 +2,7 @@ import { CoingeckoPriceAdapter } from '../adapters/price/CoingeckoPriceAdapter'; import { EarlyAccessRound } from '../entities/earlyAccessRound'; import { logger } from '../utils/logger'; import { AppDataSource } from '../orm'; +import { QACC_DONATION_TOKEN_COINGECKO_ID } from '../utils/qacc'; export const findAllEarlyAccessRounds = async (): Promise< EarlyAccessRound[] @@ -49,7 +50,7 @@ export const fillMissingTokenPriceInEarlyAccessRounds = async (): Promise< // Set the token price for all found rounds and save them for (const round of roundsToUpdate) { const tokenPrice = await priceAdapter.getTokenPriceAtDate({ - symbol: 'polygon-ecosystem-token', + symbol: QACC_DONATION_TOKEN_COINGECKO_ID, date: round.startDate, }); diff --git a/src/repositories/qfRoundRepository.ts b/src/repositories/qfRoundRepository.ts index 922ec868c..032ec9d98 100644 --- a/src/repositories/qfRoundRepository.ts +++ b/src/repositories/qfRoundRepository.ts @@ -11,6 +11,7 @@ import { ProjectFraud } from '../entities/projectFraud'; import config from '../config'; import { logger } from '../utils/logger'; import { CoingeckoPriceAdapter } from '../adapters/price/CoingeckoPriceAdapter'; +import { QACC_DONATION_TOKEN_COINGECKO_ID } from '../utils/qacc'; const qfRoundEstimatedMatchingParamsCacheDuration = Number( process.env.QF_ROUND_ESTIMATED_MATCHING_CACHE_DURATION || 60000, @@ -336,7 +337,7 @@ export const fillMissingTokenPriceInQfRounds = async (): Promise< // Set the token price for all found rounds and save them for (const round of roundsToUpdate) { const tokenPrice = await priceAdapter.getTokenPriceAtDate({ - symbol: 'polygon-ecosystem-token', + symbol: QACC_DONATION_TOKEN_COINGECKO_ID, date: round.beginDate, }); From 61624c239aabf37f10ee17dd9a829482fcbde46b Mon Sep 17 00:00:00 2001 From: Amin Latifi Date: Thu, 26 Sep 2024 17:58:19 +0330 Subject: [PATCH 20/23] Moved qacc constants to separate file --- src/constants/qacc.ts | 13 +++++++++++++ .../earlyAccessRoundRepository.test.ts | 2 +- src/repositories/earlyAccessRoundRepository.ts | 2 +- src/repositories/qfRoundRepository.ts | 2 +- src/resolvers/donationResolver.test.ts | 3 ++- src/resolvers/projectResolver.ts | 2 +- src/server/bootstrap.ts | 2 +- src/utils/qacc.ts | 14 +------------- test/testUtils.ts | 2 +- 9 files changed, 22 insertions(+), 20 deletions(-) create mode 100644 src/constants/qacc.ts diff --git a/src/constants/qacc.ts b/src/constants/qacc.ts new file mode 100644 index 000000000..b2a5e469e --- /dev/null +++ b/src/constants/qacc.ts @@ -0,0 +1,13 @@ +import config from '../config'; + +export const QACC_DONATION_TOKEN_ADDRESS: string = + (config.get('QACC_DONATION_TOKEN_ADDRESS') as string) || + '0xa2036f0538221a77a3937f1379699f44945018d0'; //https://zkevm.polygonscan.com/token/0xa2036f0538221a77a3937f1379699f44945018d0#readContract +export const QACC_DONATION_TOKEN_SYMBOL = + (config.get('QACC_DONATION_TOKEN_SYMBOL') as string) || 'MATIC'; +export const QACC_DONATION_TOKEN_NAME = + (config.get('QACC_DONATION_TOKEN_NAME') as string) || 'Matic token'; +export const QACC_DONATION_TOKEN_DECIMALS = + (+config.get('QACC_DONATION_TOKEN_DECIMALS') as number) || 18; +export const QACC_DONATION_TOKEN_COINGECKO_ID = + (config.get('QACC_DONATION_TOKEN_COINGECKO_ID') as string) || 'matic-network'; diff --git a/src/repositories/earlyAccessRoundRepository.test.ts b/src/repositories/earlyAccessRoundRepository.test.ts index 1c61d522a..8d61e34ac 100644 --- a/src/repositories/earlyAccessRoundRepository.test.ts +++ b/src/repositories/earlyAccessRoundRepository.test.ts @@ -9,7 +9,7 @@ import { } from './earlyAccessRoundRepository'; import { saveRoundDirectlyToDb } from '../../test/testUtils'; import { CoingeckoPriceAdapter } from '../adapters/price/CoingeckoPriceAdapter'; -import { QACC_DONATION_TOKEN_COINGECKO_ID } from '../utils/qacc'; +import { QACC_DONATION_TOKEN_COINGECKO_ID } from '../constants/qacc'; describe('EarlyAccessRound Repository Test Cases', () => { let priceAdapterStub: sinon.SinonStub; diff --git a/src/repositories/earlyAccessRoundRepository.ts b/src/repositories/earlyAccessRoundRepository.ts index 9da99f5f4..e08dc1a2d 100644 --- a/src/repositories/earlyAccessRoundRepository.ts +++ b/src/repositories/earlyAccessRoundRepository.ts @@ -2,7 +2,7 @@ import { CoingeckoPriceAdapter } from '../adapters/price/CoingeckoPriceAdapter'; import { EarlyAccessRound } from '../entities/earlyAccessRound'; import { logger } from '../utils/logger'; import { AppDataSource } from '../orm'; -import { QACC_DONATION_TOKEN_COINGECKO_ID } from '../utils/qacc'; +import { QACC_DONATION_TOKEN_COINGECKO_ID } from '../constants/qacc'; export const findAllEarlyAccessRounds = async (): Promise< EarlyAccessRound[] diff --git a/src/repositories/qfRoundRepository.ts b/src/repositories/qfRoundRepository.ts index 032ec9d98..a6a6325b6 100644 --- a/src/repositories/qfRoundRepository.ts +++ b/src/repositories/qfRoundRepository.ts @@ -11,7 +11,7 @@ import { ProjectFraud } from '../entities/projectFraud'; import config from '../config'; import { logger } from '../utils/logger'; import { CoingeckoPriceAdapter } from '../adapters/price/CoingeckoPriceAdapter'; -import { QACC_DONATION_TOKEN_COINGECKO_ID } from '../utils/qacc'; +import { QACC_DONATION_TOKEN_COINGECKO_ID } from '../constants/qacc'; const qfRoundEstimatedMatchingParamsCacheDuration = Number( process.env.QF_ROUND_ESTIMATED_MATCHING_CACHE_DURATION || 60000, diff --git a/src/resolvers/donationResolver.test.ts b/src/resolvers/donationResolver.test.ts index d3466da7c..f4e446d34 100644 --- a/src/resolvers/donationResolver.test.ts +++ b/src/resolvers/donationResolver.test.ts @@ -58,7 +58,8 @@ import { DRAFT_DONATION_STATUS, DraftDonation, } from '../entities/draftDonation'; -import qacc, { QACC_DONATION_TOKEN_SYMBOL } from '../utils/qacc'; +import qacc from '../utils/qacc'; +import { QACC_DONATION_TOKEN_SYMBOL } from '../constants/qacc'; // eslint-disable-next-line @typescript-eslint/no-var-requires const moment = require('moment'); diff --git a/src/resolvers/projectResolver.ts b/src/resolvers/projectResolver.ts index d84efe94c..c828e15d7 100644 --- a/src/resolvers/projectResolver.ts +++ b/src/resolvers/projectResolver.ts @@ -112,7 +112,7 @@ import { import { QACC_DONATION_TOKEN_ADDRESS, QACC_DONATION_TOKEN_SYMBOL, -} from '../utils/qacc'; +} from '../constants/qacc'; import { ProjectDonationSummary } from '../entities/projectDonationSummary'; import { getDonationSummary } from '../repositories/projectDonationSummaryRepository'; diff --git a/src/server/bootstrap.ts b/src/server/bootstrap.ts index 7b48a4e1e..16f7567e0 100644 --- a/src/server/bootstrap.ts +++ b/src/server/bootstrap.ts @@ -60,7 +60,7 @@ import { QACC_DONATION_TOKEN_DECIMALS, QACC_DONATION_TOKEN_NAME, QACC_DONATION_TOKEN_SYMBOL, -} from '../utils/qacc'; +} from '../constants/qacc'; import { QACC_NETWORK_ID } from '../provider'; import { Token } from '../entities/token'; import { ChainType } from '../types/network'; diff --git a/src/utils/qacc.ts b/src/utils/qacc.ts index 6dfbedcef..9fe10e9f2 100644 --- a/src/utils/qacc.ts +++ b/src/utils/qacc.ts @@ -1,21 +1,9 @@ import { getAbcLauncherAdapter } from '../adapters/adaptersFactory'; -import config from '../config'; import { Project } from '../entities/project'; import { i18n, translationErrorMessagesKeys } from './errorMessages'; import { QACC_NETWORK_ID } from '../provider'; import { findActiveEarlyAccessRound } from '../repositories/earlyAccessRoundRepository'; - -export const QACC_DONATION_TOKEN_ADDRESS: string = - (config.get('QACC_DONATION_TOKEN_ADDRESS') as string) || - '0xa2036f0538221a77a3937f1379699f44945018d0'; //https://zkevm.polygonscan.com/token/0xa2036f0538221a77a3937f1379699f44945018d0#readContract -export const QACC_DONATION_TOKEN_SYMBOL = - (config.get('QACC_DONATION_TOKEN_SYMBOL') as string) || 'MATIC'; -export const QACC_DONATION_TOKEN_NAME = - (config.get('QACC_DONATION_TOKEN_NAME') as string) || 'Matic token'; -export const QACC_DONATION_TOKEN_DECIMALS = - (+config.get('QACC_DONATION_TOKEN_DECIMALS') as number) || 18; -export const QACC_DONATION_TOKEN_COINGECKO_ID = - (config.get('QACC_DONATION_TOKEN_COINGECKO_ID') as string) || 'matic-network'; +import { QACC_DONATION_TOKEN_SYMBOL } from '../constants/qacc'; const isEarlyAccessRound = async () => { const earlyAccessRound = await findActiveEarlyAccessRound(); diff --git a/test/testUtils.ts b/test/testUtils.ts index daa1ac470..aff00918a 100644 --- a/test/testUtils.ts +++ b/test/testUtils.ts @@ -40,7 +40,7 @@ import { QACC_DONATION_TOKEN_DECIMALS, QACC_DONATION_TOKEN_NAME, QACC_DONATION_TOKEN_SYMBOL, -} from '../src/utils/qacc'; +} from '../src/constants/qacc'; import { EarlyAccessRound } from '../src/entities/earlyAccessRound'; // eslint-disable-next-line @typescript-eslint/no-var-requires From f9071cb90b35baeb2a222f7f055362e3330cb7c2 Mon Sep 17 00:00:00 2001 From: kkatusic Date: Thu, 26 Sep 2024 17:41:40 +0200 Subject: [PATCH 21/23] fixing build errors --- src/resolvers/projectResolver.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/resolvers/projectResolver.ts b/src/resolvers/projectResolver.ts index ce74cb268..40d959368 100644 --- a/src/resolvers/projectResolver.ts +++ b/src/resolvers/projectResolver.ts @@ -113,8 +113,8 @@ import { QACC_DONATION_TOKEN_ADDRESS, QACC_DONATION_TOKEN_SYMBOL, } from '../constants/qacc'; -import { ProjectDonationSummary } from '../entities/projectDonationSummary'; -import { getDonationSummary } from '../repositories/projectDonationSummaryRepository'; +import { ProjectRoundRecord } from '../entities/projectRoundRecord'; +import { getProjectRoundRecord } from '../repositories/projectRoundRecordRepository'; const projectUpdatsCacheDuration = 1000 * 60 * 60; From aee9d429a9f2dd750d78593402dfb9b63509bfa4 Mon Sep 17 00:00:00 2001 From: Amin Latifi Date: Fri, 27 Sep 2024 18:34:27 +0330 Subject: [PATCH 22/23] Fixed import issue --- src/resolvers/draftDonationResolver.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resolvers/draftDonationResolver.test.ts b/src/resolvers/draftDonationResolver.test.ts index 9fa87ef34..9b3eaf917 100644 --- a/src/resolvers/draftDonationResolver.test.ts +++ b/src/resolvers/draftDonationResolver.test.ts @@ -17,7 +17,7 @@ import { DRAFT_DONATION_STATUS, DraftDonation, } from '../entities/draftDonation'; -import { QACC_DONATION_TOKEN_SYMBOL } from '../utils/qacc'; +import { QACC_DONATION_TOKEN_SYMBOL } from '../constants/qacc'; describe('createDraftDonation() test cases', createDraftDonationTestCases); From 925850944cbb80d672dd8a2fd89bc3e72aa045c8 Mon Sep 17 00:00:00 2001 From: Amin Latifi Date: Fri, 27 Sep 2024 21:00:35 +0330 Subject: [PATCH 23/23] Added fix add token price to rounds --- .../1727458215571-fixAddTokenPriceToRounds.ts | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 migration/1727458215571-fixAddTokenPriceToRounds.ts diff --git a/migration/1727458215571-fixAddTokenPriceToRounds.ts b/migration/1727458215571-fixAddTokenPriceToRounds.ts new file mode 100644 index 000000000..8060ad8c7 --- /dev/null +++ b/migration/1727458215571-fixAddTokenPriceToRounds.ts @@ -0,0 +1,25 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class FixAddTokenPriceToRounds1727458215571 + implements MigrationInterface +{ + name = 'FixAddTokenPriceToRounds1727458215571'; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `ALTER TABLE "qf_round" RENAME COLUMN "token_price" TO "tokenPrice"`, + ); + await queryRunner.query( + `ALTER TABLE "early_access_round" RENAME COLUMN "token_price" TO "tokenPrice"`, + ); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `ALTER TABLE "early_access_round" RENAME COLUMN "tokenPrice" TO "token_price"`, + ); + await queryRunner.query( + `ALTER TABLE "qf_round" RENAME COLUMN "tokenPrice" TO "token_price"`, + ); + } +}