Skip to content

Commit 3a21abb

Browse files
committed
chore: fixes
1 parent e9a79d8 commit 3a21abb

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/calculator/index.ts

+17-9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
OverridesInvalidRowError,
1515
} from "./errors.js";
1616
import { PotentialVote } from "../http/api/v1/matches.js";
17+
import { ethers } from "ethers";
1718

1819
export {
1920
CalculatorError,
@@ -142,7 +143,7 @@ export default class Calculator {
142143

143144
#votesWithCoefficientToContribution(
144145
votes: VoteWithCoefficient[]
145-
): Contribution[] {
146+
): (Contribution & { recipientAddress: string })[] {
146147
return votes.flatMap((vote) => {
147148
const scaleFactor = 10_000;
148149
const coefficient = BigInt(
@@ -155,7 +156,8 @@ export default class Calculator {
155156
return [
156157
{
157158
contributor: vote.voter,
158-
recipient: vote.grantAddress,
159+
recipient: vote.applicationId,
160+
recipientAddress: vote.grantAddress,
159161
amount: multipliedAmount,
160162
},
161163
];
@@ -346,7 +348,7 @@ export default class Calculator {
346348
vote.amount
347349
);
348350

349-
const { amount: amountRoundToken, price } =
351+
const { amount: amountRoundToken } =
350352
await this.priceProvider.convertFromUSD(
351353
this.chainId,
352354
round.token,
@@ -392,11 +394,13 @@ export default class Calculator {
392394
}
393395
);
394396

395-
const contributions: Array<Contribution> =
396-
this.#votesWithCoefficientToContribution(votesWithCoefficients);
397+
const contributions = this.#votesWithCoefficientToContribution(
398+
votesWithCoefficients
399+
);
397400

398-
const potentialContributions: Contribution[] =
399-
this.#votesWithCoefficientToContribution(potentialVotesWithCoefficients);
401+
const potentialContributions = this.#votesWithCoefficientToContribution(
402+
potentialVotesWithCoefficients
403+
);
400404

401405
const contributionsWithPotentialVotes = [
402406
...potentialContributions,
@@ -431,7 +435,7 @@ export default class Calculator {
431435
const potentialResult = potentialResults[key] ?? {};
432436
const currentResult = currentResults[key] ?? {};
433437

434-
/*Here, however, subtracting undefined from a bigint would fail,
438+
/* Subtracting undefined from a bigint would fail,
435439
* so we explicitly subtract 0 if it's undefined */
436440
const difference =
437441
potentialResult.matched - (currentResult.matched ?? 0n);
@@ -441,14 +445,18 @@ export default class Calculator {
441445
difference
442446
);
443447

448+
const recipient = potentialVotesWithCoefficients.find(
449+
(vote) => vote.applicationId == key
450+
)?.grantAddress;
451+
444452
/** Can be undefined, but spreading an undefined is a no-op, so it's okay here */
445453
finalResults.push({
446454
...currentResult,
447455
...potentialResult,
448456
difference,
449457
roundId: round.id,
450458
chainId: this.chainId,
451-
recipient: key,
459+
recipient: recipient ?? ethers.constants.AddressZero,
452460
differenceInUSD: differenceInUSD.amount,
453461
});
454462
}

0 commit comments

Comments
 (0)