Repository navigation
fix: capture per-milestone amounts and due dates with exact 7-decimal allocation - #1569
Conversation
|
@Yungmon22 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
47b7e86 to
4d4e017
Compare
|
Hi @Yungmon22, thanks for the PR. We can't merge it yet: our security scan found obfuscated malicious code in After the closing What to do before we can merge this PR
Thanks for your contribution, and sorry for the hassle. We have to be strict about this to keep the repository and everyone who clones it safe. |
Strips the payload this branch picked up (delete api.js, truncate eslint.config.js, unhook package.json). No functional change to the branch's own work.
|
@1nonlypiece — this PR is ready for another review. I resolved the merge conflicts with the main branch (pushed 1eaa2c1). |
Overview
This PR fixes a money-correctness bug in vault creation. Previously
apiCreateVaultsplit the vault total evenly across milestones using floating-point arithmetic (Number(per.toFixed(7))), so a 100 USDC vault over 3 milestones sent33.3333333 × 3 = 99.9999999— leaving 0.0000001 USDC unallocated — and spaced due dates evenly regardless of the creator's plan.This change adds a pure
bigint-stroop allocation utility, lets creators enter a per-milestone amount and due date, validates that tranches reconcile exactly to the vault total and fall before the deadline, and sends the user's tranches (or an exact even split) in the POST body instead of splitting in the API layer.Related Issue
Changes
🧮 Milestone Allocation Utility
src/utils/milestoneAllocation.tstoStroops(str)/fromStroops(bigint)— exact string ↔ integer stroop conversion (1 USDC = 10^7), rejecting more than 7 decimals and malformed inputs (1e3,0x10,-1,.5,1.).splitEvenly(total, n)— distributes the remainder so the sum is exact (firstrtranches get +1 stroop).validateAllocation(total, rows)— returns per-row and form-level errors for sum mismatch (with the difference shown), zero/negative tranches, due dates after the vault deadline or in the past, and non-ascending due dates.bigintstroops end to end; noNumbermath on amounts.📝 Vault Creation
[MODIFY]
src/services/api.tsapiCreateVaultno longer computesper = amount / nor appliestoFixed(7). It sends the user-entered (or evenly split) tranche amounts and due dates, serialised from exact stroop strings, so the tranche sum equals the vaultamount.[MODIFY]
src/components/CreateVaultReview.tsxVerification Results
splitEvenlyreturns n tranches summing exactly to the total (property test)bigintstroop distribution with remainder to firstrtranchesvalidateAllocationreports e.g. "Allocated 99.9999999 of 100 USDC"validateAllocation/vaultsbody carries user/split amounts and due dates summing toamountapiCreateVaultsends exact tranches, no even splitCloses #1504