Skip to content

Commit

Permalink
R5 API: all allocaitons are rounded to 2 decimals
Browse files Browse the repository at this point in the history
  • Loading branch information
stepandel committed Sep 26, 2024
1 parent 051b6b1 commit 97dfb40
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/app/api/common/ballots/ballotDistributionStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ function topToBottom({
}) {
const a = (2 * (total - n * min)) / (n * (n - 1));

return (i: number) => min + a * i; // return the amount of funding for the i-th project
return (i: number) => Math.round(min + a * i * 100) / 100; // return the amount of funding for the i-th project
}

function topWeighted({
Expand All @@ -202,7 +202,7 @@ function topWeighted({
0
);

return (i: number) => (total * w(i, c)) / W; // return the amount of funding for the i-th project
return (i: number) => Math.round((total * w(i, c)) / W) / 100; // return the amount of funding for the i-th project
}

// recursively find c that results in max allocation < top
Expand Down Expand Up @@ -253,7 +253,7 @@ function impactGroups({
// Distribution function
const F = nk.map((_, i) => (total * (i + 1)) / W);

return (k: number) => F[k]; // return the amount of funding for the k-th impact group
return (k: number) => Math.round(F[k]) / 100; // return the amount of funding for the k-th impact group
}

export const applyDistributionStrategy = cache(applyDistributionStrategyApi);
4 changes: 2 additions & 2 deletions src/app/api/common/ballots/updateBallotProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async function updateBallotProjectAllocationForAddress({
},
},
data: {
allocation,
allocation: Math.round(Number(allocation)) / 100,
updated_at: new Date(),
},
});
Expand Down Expand Up @@ -394,7 +394,7 @@ async function updateAllProjectsInBallotForAddress({
},
},
update: {
allocation: project.allocation,
allocation: Math.round(Number(project.allocation)) / 100,
updated_at: new Date(),
},
create: {
Expand Down

0 comments on commit 97dfb40

Please sign in to comment.