Skip to content

Commit

Permalink
Merge pull request #137 from GeneralMagicio/FixMinorIssuesInBatchMinting
Browse files Browse the repository at this point in the history
Fix minor batch minting issues
  • Loading branch information
ae2079 authored Nov 5, 2024
2 parents fde1ff6 + a98964c commit 0225089
Showing 1 changed file with 61 additions and 47 deletions.
108 changes: 61 additions & 47 deletions src/scripts/syncDataWithJsonReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,63 +48,73 @@ async function processReportForDonations(
);

for (const donation of donations) {
const participantData =
lowerCasedParticipants[donation.fromWalletAddress.toLowerCase()];
try {
const participantData =
lowerCasedParticipants[donation.fromWalletAddress.toLowerCase()];

if (!participantData) {
console.error(`No participant data found for donation ${donation.id}`);
continue;
}

const totalValidContribution = ethers.BigNumber.from(
participantData.validContribution.inCollateral,
);
// if issuance allocation is not exist, that mean this user has not any valid contributions
let rewardAmount = 0;
if (participantData.issuanceAllocation) {
const issuanceAllocationRow = ethers.BigNumber.from(
participantData.issuanceAllocation,
);
const issuanceAllocation = parseFloat(
ethers.utils.formatUnits(issuanceAllocationRow, 18),
); // Assuming 18 decimal places

const donationTransaction = participantData.transactions.find(
(tx: any) =>
tx.transactionHash.toLowerCase() ===
donation.transactionId.toLowerCase(),
);

if (!donationTransaction) {
if (!participantData) {
console.error(
`No transaction data found for donation ${donation.id}`,
`No participant data found for donation ${donation.id}`,
);
continue;
}

const donationValidContribution = ethers.BigNumber.from(
donationTransaction.validContribution,
const totalValidContribution = ethers.BigNumber.from(
participantData.validContribution.inCollateral,
);
const contributionPercentage =
parseFloat(ethers.utils.formatUnits(donationValidContribution, 18)) /
parseFloat(ethers.utils.formatUnits(totalValidContribution, 18));
// if issuance allocation is not exist, that mean this user has not any valid contributions
let rewardAmount = 0;
if (participantData.issuanceAllocation) {
const issuanceAllocationRow = ethers.BigNumber.from(
participantData.issuanceAllocation,
);
const issuanceAllocation = parseFloat(
ethers.utils.formatUnits(issuanceAllocationRow, 18),
); // Assuming 18 decimal places

const donationTransaction = participantData.transactions.find(
(tx: any) =>
tx.transactionHash.toLowerCase() ===
donation.transactionId.toLowerCase(),
);

// Calculate the reward proportionally based on the valid contribution
rewardAmount = issuanceAllocation * contributionPercentage;
}
donation.rewardTokenAmount = rewardAmount || 0;
if (!donationTransaction) {
console.error(
`No transaction data found for donation ${donation.id}`,
);
continue;
}

const isEarlyAccessRound = reportData.batch.config.isEarlyAccess;
const vestingInfo = getStreamDetails(isEarlyAccessRound);
const donationValidContribution = ethers.BigNumber.from(
donationTransaction.validContribution,
);
const contributionPercentage =
parseFloat(
ethers.utils.formatUnits(donationValidContribution, 18),
) /
parseFloat(ethers.utils.formatUnits(totalValidContribution, 18));

// Calculate the reward proportionally based on the valid contribution
rewardAmount = issuanceAllocation * contributionPercentage;
}
donation.rewardTokenAmount = rewardAmount || 0;

donation.cliff = vestingInfo.CLIFF * 1000;
donation.rewardStreamStart = new Date(vestingInfo.START * 1000);
donation.rewardStreamEnd = new Date(vestingInfo.END * 1000);
const isEarlyAccessRound = reportData.batch.config.isEarlyAccess;
const vestingInfo = getStreamDetails(isEarlyAccessRound);

await donation.save();
console.debug(
`Reward data for donation ${donation.id} successfully updated`,
);
donation.cliff = vestingInfo.CLIFF * 1000;
donation.rewardStreamStart = new Date(vestingInfo.START * 1000);
donation.rewardStreamEnd = new Date(vestingInfo.END * 1000);

await donation.save();
console.debug(
`Reward data for donation ${donation.id} successfully updated`,
);
} catch (e) {
console.error(
`Failed to process donations rewards for project ${donations[0].projectId} and donation ${donation.id}: ${e.message}`,
);
}
}
} catch (error) {
console.error(
Expand Down Expand Up @@ -196,8 +206,12 @@ async function updateNumberOfBatchMintingTransactionsForProject(
if (transactions.length > 0) {
if (!project.batchNumbersWithSafeTransactions) {
project.batchNumbersWithSafeTransactions = [batchNumber];
} else {
} else if (
!project.batchNumbersWithSafeTransactions.includes(batchNumber)
) {
project.batchNumbersWithSafeTransactions.push(batchNumber);
} else {
return;
}
await project.save();
}
Expand Down

0 comments on commit 0225089

Please sign in to comment.