Repository navigation
fix(amounts): handle vault and milestone amounts as exact 7-decimal v… - #1763
Merged
1nonlypiece merged 2 commits intoOct 24, 2026
Merged
1nonlypiece merged 2 commits into
1nonlypiece merged 2 commits into
Conversation
…alues and enforce milestone sum
…icts Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1685
Summary
This PR introduces exact 7-decimal stroop parsing, storage, and formatting across the API and store layers, preventing floating-point precision loss and enforcing that milestone amounts sum exactly to the vault stake amount.
Changes
apilib/amount.mjs:parseAmount(input)to convert amounts (JSON strings or safe numbers) into exactbigintstroops (1 unit = 10,000,000 stroops).NaN,Infinity, non-numeric strings, and numbers with more than 7 decimal places.formatAmount(bigint)to output canonical decimal strings without redundant trailing zeros.api/index.mjs:POST /vaults, parsed vault and milestone amounts into exact stroops.> 0) andsum(milestones.amount) === vault.amount.GET /stats, aggregated totals usingbigintstroops instead of floating-point arithmetic and serialized totals (totalLocked,totalReleased,totalRedirected) as exact decimal strings.apilib/store.mjs:PgStore(rowToVaultandactRow) to read numeric values withoutNumber()casts, normalizing them withformatAmount(parseAmount(...)).apilib/openapi.mjs:Amountschema topattern: '^\d+(\.\d{1,7})?$'.CreateMilestoneRequestandCreateVaultRequestamount schemas to accept strings or numbers for backward compatibility.Statsamount schemas and examples to reflect string amounts.Tests:
apilib/__tests__/amount.test.mjs: Unit and property-based tests verifyingformatAmount(parseAmount(s)) === canonical(s)for random 0–7-decimal strings as well as boundary values.api/__tests__/vaults.amounts.test.mjs: HTTP tests verifying milestone sum invariant, 0 amount rejection, rejection table (1e3,-1,abc,"",null,Infinity), and/statsexact string sums.api/__tests__/postgres.amounts.test.mjs: Asserting exact round-trip preservation of boundary values ("922337203685.4775807"neari64::MAXin stroops) through PostgreSQLnumeric(36,7).