Skip to content

Commit

Permalink
🐛 always normalize allocation for all distribution strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
stepandel committed Sep 27, 2024
1 parent ddf571c commit 0748bf0
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/app/api/common/ballots/ballotDistributionStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async function applyDistributionStrategyForAddress({
);

const max = 12.5;
const min = 0.125;
const min = 0.2;
const totalFunding = 100;

// Apply distribution strategy
Expand Down Expand Up @@ -105,11 +105,6 @@ async function applyDistributionStrategyForAddress({
});
}
});

console.log(
"total",
newProjectsAllocation.reduce((acc, p) => acc + (p.allocation ?? 0), 0)
);
}

if (strategy === DistributionStrategy.IMPACT_GROUPS) {
Expand Down Expand Up @@ -147,7 +142,7 @@ async function applyDistributionStrategyForAddress({

// Save projects allocations
await Promise.all(
newProjectsAllocation.map((p) =>
normalizeAllocation(newProjectsAllocation).map((p) =>
prisma.projectAllocations.update({
where: {
address_round_project_id: {
Expand Down Expand Up @@ -256,4 +251,17 @@ function impactGroups({
return (k: number) => Math.round(F[k] * 100) / 100; // return the amount of funding for the k-th impact group
}

function normalizeAllocation<T extends { allocation: number | null }>(
allocation: T[]
) {
const total = allocation.reduce((acc, p) => acc + (p.allocation ?? 0), 0);

return allocation.map((p) => ({
...p,
allocation: p.allocation
? Math.round((p.allocation / total) * 100 * 100) / 100
: null,
}));
}

export const applyDistributionStrategy = cache(applyDistributionStrategyApi);

0 comments on commit 0748bf0

Please sign in to comment.