diff --git a/apps/distributor/src/distributorv2.ts b/apps/distributor/src/distributorv2.ts index 4dd1e5376..61fc82cc5 100644 --- a/apps/distributor/src/distributorv2.ts +++ b/apps/distributor/src/distributorv2.ts @@ -377,8 +377,7 @@ export class DistributorV2Worker { } // Calculate hodler pool share weights - // -500 to account for rounding errors - const hodlerPoolAvailableAmount = distAmt - fixedPoolAllocatedAmount - 500n + const hodlerPoolAvailableAmount = distAmt - fixedPoolAllocatedAmount let hodlerShares: { address: string; amount: bigint }[] = [] if (hodlerPoolAvailableAmount > 0n) { diff --git a/apps/distributor/src/weights.ts b/apps/distributor/src/weights.ts index 0b3b18ef1..9ef3b507e 100644 --- a/apps/distributor/src/weights.ts +++ b/apps/distributor/src/weights.ts @@ -66,6 +66,22 @@ export function calculateWeights( } } + //@todo: this is a hack to ensure the total distributed amount is equal to the amount + // We really should handle these rounding errors instead + let totalDistributed = 0n + for (const share of Object.values(weightedShares)) { + totalDistributed += share.amount + } + + if (totalDistributed !== amount) { + const difference = amount - totalDistributed + // Add or subtract the difference from the largest share + const largestShare = Object.values(weightedShares).reduce((a, b) => + a.amount > b.amount ? a : b + ) + largestShare.amount += difference + } + return { totalWeight, weightPerSend, poolWeights, weightedShares } }