Skip to content

Commit

Permalink
Ensure minimum prize is at least as much as the transfer fee (#6081)
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles authored Jul 22, 2024
1 parent 18c7ba4 commit 5ff1261
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion frontend/app/src/components/home/PrizeContentBuilder.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,31 @@
const scale = total / Number(fund);
const scaled = intermediate.map((p) => BigInt(Math.round(p / scale)));
return compensateRounding(scaled, fund);
const prizes = compensateRounding(scaled, fund);
return ensureMinPrizeAtLeastTransferFee(prizes);
}
function ensureMinPrizeAtLeastTransferFee(prizes: bigint[]): bigint[] {
let totalAdded = 0n;
let max = 0n;
let maxIndex = 0;
for (let i = 0; i < prizes.length; i++) {
const prize = prizes[i];
if (prize < transferFees) {
prizes[i] = transferFees;
totalAdded += transferFees - prize;
} else if (prize > max) {
max = prize;
maxIndex = i;
}
}
if (totalAdded > 0n) {
prizes[maxIndex] = max - totalAdded;
}
return prizes;
}
function random(min: number, max: number): number {
Expand Down

0 comments on commit 5ff1261

Please sign in to comment.