@@ -14,6 +14,7 @@ import {
14
14
OverridesInvalidRowError ,
15
15
} from "./errors.js" ;
16
16
import { PotentialVote } from "../http/api/v1/matches.js" ;
17
+ import { ethers } from "ethers" ;
17
18
18
19
export {
19
20
CalculatorError ,
@@ -142,7 +143,7 @@ export default class Calculator {
142
143
143
144
#votesWithCoefficientToContribution(
144
145
votes : VoteWithCoefficient [ ]
145
- ) : Contribution [ ] {
146
+ ) : ( Contribution & { recipientAddress : string } ) [ ] {
146
147
return votes . flatMap ( ( vote ) => {
147
148
const scaleFactor = 10_000 ;
148
149
const coefficient = BigInt (
@@ -155,7 +156,8 @@ export default class Calculator {
155
156
return [
156
157
{
157
158
contributor : vote . voter ,
158
- recipient : vote . grantAddress ,
159
+ recipient : vote . applicationId ,
160
+ recipientAddress : vote . grantAddress ,
159
161
amount : multipliedAmount ,
160
162
} ,
161
163
] ;
@@ -346,7 +348,7 @@ export default class Calculator {
346
348
vote . amount
347
349
) ;
348
350
349
- const { amount : amountRoundToken , price } =
351
+ const { amount : amountRoundToken } =
350
352
await this . priceProvider . convertFromUSD (
351
353
this . chainId ,
352
354
round . token ,
@@ -392,11 +394,13 @@ export default class Calculator {
392
394
}
393
395
) ;
394
396
395
- const contributions : Array < Contribution > =
396
- this . #votesWithCoefficientToContribution( votesWithCoefficients ) ;
397
+ const contributions = this . #votesWithCoefficientToContribution(
398
+ votesWithCoefficients
399
+ ) ;
397
400
398
- const potentialContributions : Contribution [ ] =
399
- this . #votesWithCoefficientToContribution( potentialVotesWithCoefficients ) ;
401
+ const potentialContributions = this . #votesWithCoefficientToContribution(
402
+ potentialVotesWithCoefficients
403
+ ) ;
400
404
401
405
const contributionsWithPotentialVotes = [
402
406
...potentialContributions ,
@@ -431,7 +435,7 @@ export default class Calculator {
431
435
const potentialResult = potentialResults [ key ] ?? { } ;
432
436
const currentResult = currentResults [ key ] ?? { } ;
433
437
434
- /*Here, however, subtracting undefined from a bigint would fail,
438
+ /* Subtracting undefined from a bigint would fail,
435
439
* so we explicitly subtract 0 if it's undefined */
436
440
const difference =
437
441
potentialResult . matched - ( currentResult . matched ?? 0n ) ;
@@ -441,14 +445,18 @@ export default class Calculator {
441
445
difference
442
446
) ;
443
447
448
+ const recipient = potentialVotesWithCoefficients . find (
449
+ ( vote ) => vote . applicationId == key
450
+ ) ?. grantAddress ;
451
+
444
452
/** Can be undefined, but spreading an undefined is a no-op, so it's okay here */
445
453
finalResults . push ( {
446
454
...currentResult ,
447
455
...potentialResult ,
448
456
difference,
449
457
roundId : round . id ,
450
458
chainId : this . chainId ,
451
- recipient : key ,
459
+ recipient : recipient ?? ethers . constants . AddressZero ,
452
460
differenceInUSD : differenceInUSD . amount ,
453
461
} ) ;
454
462
}
0 commit comments