Description
When splitting an integer token amount across many recipients with non-divisible ratios, rounding discrepancies cause the sum of individual shares to differ from the invoice total by up to N-1 stroops. A defined rounding policy must ensure every stroop is accounted for.
Technical Context
Implement a distribute_with_remainder(total: i128, ratios: &[u32], denom: u64) -> Vec<i128> function in a new calc.rs module under contracts/split/src/. Apply the largest-remainder method: compute floor shares, compute remainders as (total * ratio % denom), sort recipients by remainder descending, and distribute leftover stroops to top-remainder recipients.
Acceptance Criteria
Description
When splitting an integer token amount across many recipients with non-divisible ratios, rounding discrepancies cause the sum of individual shares to differ from the invoice total by up to N-1 stroops. A defined rounding policy must ensure every stroop is accounted for.
Technical Context
Implement a
distribute_with_remainder(total: i128, ratios: &[u32], denom: u64) -> Vec<i128>function in a newcalc.rsmodule undercontracts/split/src/. Apply the largest-remainder method: compute floor shares, compute remainders as(total * ratio % denom), sort recipients by remainder descending, and distribute leftover stroops to top-remainder recipients.Acceptance Criteria
totalexactlycalc.rssum(distribute_with_remainder(...)) == totalfor random inputsrelease_paymentusesdistribute_with_remainderfor its calculations