Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix minor batch minting issues #137

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading