Skip to content

Commit

Permalink
Merge pull request #121 from GeneralMagicio/fix/round-matching
Browse files Browse the repository at this point in the history
Fixed round matching issues
  • Loading branch information
aminlatifi authored Oct 31, 2024
2 parents bffdcda + 79ef1bb commit e7d08a3
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 30 deletions.
2 changes: 1 addition & 1 deletion config/example.env
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ BASE_SEPOLIA_NODE_HTTP_URL=


ZKEVM_MAINNET_SCAN_API_URL=https://api-zkevm.polygonscan.com/api
ZKEVM_MAINET_SCAN_API_KEY=0000000000000000000000000000000000
ZKEVM_MAINNET_SCAN_API_KEY=0000000000000000000000000000000000
ZKEVM_CARDONA_SCAN_API_URL=https://api-cardona-zkevm.polygonscan.com/api
ZKEVM_CARDONA_SCAN_API_KEY=0000000000000000000000000000000000

Expand Down
2 changes: 1 addition & 1 deletion src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ export function getBlockExplorerApiUrl(networkId: number): string {
break;
case NETWORK_IDS.ZKEVM_MAINNET:
apiUrl = config.get('ZKEVM_MAINNET_SCAN_API_URL');
apiKey = config.get('ZKEVM_MAINET_SCAN_API_KEY');
apiKey = config.get('ZKEVM_MAINNET_SCAN_API_KEY');
break;
case NETWORK_IDS.ZKEVM_CARDONA:
apiUrl = config.get('ZKEVM_CARDONA_SCAN_API_URL');
Expand Down
4 changes: 2 additions & 2 deletions src/repositories/earlyAccessRoundRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ export const findActiveEarlyAccessRound = async (
try {
const query = EarlyAccessRound.createQueryBuilder('earlyAccessRound')
.where('earlyAccessRound.startDate <= :date', {
date,
date: date.toISOString(),
})
.andWhere('earlyAccessRound.endDate >= :date', {
date,
date: date.toISOString(),
});

return query.getOne();
Expand Down
2 changes: 1 addition & 1 deletion src/repositories/qfRoundRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export const findActiveQfRound = async ({
const query = QfRound.createQueryBuilder('qfRound')
.where('"isActive" = true')
.andWhere(':date BETWEEN "qfRound"."beginDate" AND "qfRound"."endDate"', {
date,
date: date.toISOString(),
});
if (noCache) {
return query.getOne();
Expand Down
2 changes: 1 addition & 1 deletion src/resolvers/donationResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ export class DonationResolver {
isTokenEligibleForGivback,
isCustomToken,
isProjectVerified: project.verified,
createdAt: donateTime,
createdAt: donateTime.toISOString(),
earlyAccessRound: earlyAccessRound ?? undefined,
qfRound: qfRound ?? undefined,
segmentNotified: false,
Expand Down
9 changes: 5 additions & 4 deletions src/server/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,12 @@ export async function bootstrap() {

async function initializeCronJobs() {
logger.debug('initializeCronJobs() has been called', new Date());
if (process.env.ENABLE_ANKR_SYNC === 'true') {
runSyncWithAnkrTransfers();
}

runCheckPendingDonationsCronJob();

runNotifyMissingDonationsCronJob();

if (process.env.ENABLE_IMPORT_LOST_DONATIONS === 'true') {
Expand Down Expand Up @@ -209,10 +214,6 @@ export async function bootstrap() {
'initializeCronJobs() after runSyncDataWithInverter() ',
new Date(),
);

if (process.env.ENABLE_ANKR_SYNC === 'true') {
runSyncWithAnkrTransfers();
}
}

async function addQAccToken() {
Expand Down
42 changes: 22 additions & 20 deletions src/services/donationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,27 +294,29 @@ export const syncDonationStatusWithBlockchainNetwork = async (params: {

const transactionDate = new Date(transaction.timestamp * 1000);

const cap = await qAccService.getQAccDonationCap({
userId: donation.userId,
projectId: donation.projectId,
donateTime: transactionDate,
});
// Only double check if the donation is not already assigned to a round
if (!donation.earlyAccessRoundId && !donation.qfRoundId) {
const cap = await qAccService.getQAccDonationCap({
userId: donation.userId,
projectId: donation.projectId,
donateTime: transactionDate,
});

logger.debug(
`the available cap at time ${transaction.timestamp} is ${cap}, and donation amount is ${donation.amount}`,
);
if (cap >= donation.amount) {
const [earlyAccessRound, qfRound] = await Promise.all([
findActiveEarlyAccessRound(transactionDate),
findActiveQfRound({ date: transactionDate }),
]);
donation.earlyAccessRound = earlyAccessRound;
donation.qfRound = qfRound;
} else {
donation.earlyAccessRound = null;
donation.qfRound = null;
logger.debug(
`the available cap at time ${transaction.timestamp} is ${cap}, and donation amount is ${donation.amount}`,
);
if (cap >= donation.amount) {
const [earlyAccessRound, qfRound] = await Promise.all([
findActiveEarlyAccessRound(transactionDate),
findActiveQfRound({ date: transactionDate }),
]);
donation.earlyAccessRound = earlyAccessRound;
donation.qfRound = qfRound;
} else {
donation.earlyAccessRound = null;
donation.qfRound = null;
}
}

await donation.save();

// ONLY verified donations should be accumulated
Expand Down Expand Up @@ -675,7 +677,7 @@ const ankrTransferHandler = async (transfer: TokenTransfer) => {
},
{
status: DONATION_STATUS.PENDING,
createdAt: new Date(transfer.timestamp * 1000),
createdAt: new Date(transfer.timestamp * 1000).toISOString(),
},
);
} else {
Expand Down

0 comments on commit e7d08a3

Please sign in to comment.